Пример #1
0
void fileManager::writeMask( const std::string& maskFilename, const std::vector<std::vector<std::vector<bool> > >& maskMatrix) const
{
    const size_t dimx = maskMatrix.size();
    const size_t dimy = maskMatrix[0].size();
    const size_t dimz = maskMatrix[0][0].size();
    std::vector<std::vector<std::vector<float> > > maskMatrixFloat( dimx, std::vector<std::vector<float> >( dimy, std::vector<float>( dimz, 0 ) ) );

    for (int i=0 ; i<dimx ; ++i)
    {
        for (int j=0 ; j<dimy ; ++j)
        {
            for (int k=0 ; k<dimz ; ++k)
            {
                maskMatrixFloat[i][j][k] = maskMatrix[i][j][k];
            }
        }
    }
    writeMask( maskFilename, maskMatrixFloat );
    return;
}// end fileManager::writeMask() -----------------------------------------------------------------
Пример #2
0
void netman_static_line(NetmanIfConfig *config, int lineno, char *line)
{
	char *cmd = strtok(line, SPACES);
	if (cmd == NULL)
	{
		return;
	};
	
	if (strcmp(cmd, "address") == 0)
	{
		IPNetIfAddr4 addr;
		char *cidr = strtok(NULL, SPACES);
		
		if (cidr == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected address in CIDR notation, not EOL\n", lineno);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		uint8_t *addrput = (uint8_t*) &addr.addr;
		unsigned int netsize;
		
		if (sscanf(cidr, "%hhu.%hhu.%hhu.%hhu/%u", &addrput[0], &addrput[1], &addrput[2], &addrput[3], &netsize) != 5)
		{
			fprintf(stderr, "static: if.conf line %d error: invalid CIDR address: %s\n", lineno, cidr);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		if (netsize > 32)
		{
			fprintf(stderr, "static: if.conf line %d error: maximum network size is 32, got %u\n", lineno, netsize);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		writeMask((uint8_t*)&addr.mask, netsize);
		addr.domain = _GLIDIX_DOM_GLOBAL;
		
		char *domname = strtok(NULL, SPACES);
		if (domname != NULL)
		{
			int domain = getDomainByName(domname);
			if (domain == -1)
			{
				fprintf(stderr, "static: if.conf line %d: invalid address domain '%s'\n", lineno, domname);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			addr.domain = domain;
		};
		
		StaticConfig *statconf = (StaticConfig*) config->data;
		statconf->addrs = realloc(statconf->addrs, sizeof(IPNetIfAddr4)*(statconf->addrcount+1));
		memcpy(&statconf->addrs[statconf->addrcount], &addr, sizeof(IPNetIfAddr4));
		statconf->addrcount++;
		
		statconf->routes = realloc(statconf->routes, sizeof(_glidix_gen_route)*(statconf->routecount+1));
		memset(&statconf->routes[statconf->routecount], 0, sizeof(_glidix_gen_route));
		_glidix_in_route *inroute = (_glidix_in_route*) &statconf->routes[statconf->routecount];
		statconf->routecount++;
		
		strcpy(inroute->ifname, config->ifname);
		uint32_t prefix = (*((uint32_t*)&addr.addr)) & (*((uint32_t*)&addr.mask));
		memcpy(&inroute->dest, &prefix, 4);
		memcpy(&inroute->mask, &addr.mask, 4);
		memset(&inroute->gateway, 0, 4);
		inroute->domain = addr.domain;
		inroute->flags = 0;
	}
	else if (strcmp(cmd, "route") == 0)
	{
		StaticConfig *statconf = (StaticConfig*) config->data;
		
		statconf->routes = realloc(statconf->routes, sizeof(_glidix_gen_route)*(statconf->routecount+1));
		memset(&statconf->routes[statconf->routecount], 0, sizeof(_glidix_gen_route));
		_glidix_in_route *inroute = (_glidix_in_route*) &statconf->routes[statconf->routecount];
		statconf->routecount++;
		
		strcpy(inroute->ifname, config->ifname);
		memset(&inroute->gateway, 0, 4);
		inroute->domain = _GLIDIX_DOM_GLOBAL;
		inroute->flags = 0;
		
		uint8_t *put = (uint8_t*) &inroute->dest;
		unsigned int netsize;
		
		char *cidr = strtok(NULL, SPACES);
		if (cidr == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected CIDR route destination, not EOL\n", lineno);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		if (strcmp(cidr, "default") == 0)
		{
			memset(&inroute->dest, 0, 4);
			memset(&inroute->mask, 0, 4);
		}
		else
		{
			if (sscanf(cidr, "%hhu.%hhu.%hhu.%hhu/%u", &put[0], &put[1], &put[2], &put[3], &netsize) != 5)
			{
				fprintf(stderr, "static: if.conf line %d error: invalid destination '%s'\n", lineno, cidr);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			if (netsize > 32)
			{
				fprintf(stderr, "static: if.conf line %d error: maximum prefix size is 32, got %u\n",
					lineno, netsize);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			writeMask((uint8_t*)&inroute->mask, netsize);
		};
		
		char *nextKeyword = strtok(NULL, SPACES);
		if (nextKeyword != NULL)
		{
			if (strcmp(nextKeyword, "via") == 0)
			{
				char *gateway = strtok(NULL, SPACES);
				if (gateway == NULL)
				{
					fprintf(stderr, "static: if.conf line %d error: expected gateway IP after 'via'"
							" keyword\n", lineno);
					config->status = NETMAN_STATUS_ERROR;
					return;
				};
				
				if (!inet_pton(AF_INET, gateway, &inroute->gateway))
				{
					fprintf(stderr, "static: if.conf line %d error: invalid gateway address '%s'\n",
							lineno, gateway);
					config->status = NETMAN_STATUS_ERROR;
					return;
				};
				
				nextKeyword = strtok(NULL, SPACES);
			};
		};
		
		if (nextKeyword != NULL)
		{
			if (strcmp(nextKeyword, "domain") != 0)
			{
				fprintf(stderr, "static: if.conf line %d error: expected 'via' or 'domain', not '%s'\n",
						lineno, nextKeyword);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			char *domname = strtok(NULL, SPACES);
			if (domname == NULL)
			{
				fprintf(stderr, "static: if.conf line %d error: expected domain name, not EOL\n", lineno);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			int domain = getDomainByName(domname);
			if (domain == -1)
			{
				fprintf(stderr, "static: if.conf line %d error: invalid route domain '%s'\n", lineno, domname);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			inroute->domain = domain;
		};
	}
	else if (strcmp(cmd, "nameserver") == 0)
	{
		StaticConfig *statconf = (StaticConfig*) config->data;
		
		char *nameserver = strtok(NULL, SPACES);
		if (nameserver == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected name server\n", lineno);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		statconf->dns = realloc(statconf->dns, 4*(++statconf->dnscount));
		if (!inet_pton(AF_INET, nameserver, &statconf->dns[statconf->dnscount-1]))
		{
			fprintf(stderr, "static: if.conf line %d error: invalid name server address '%s'\n", lineno, nameserver);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
	}
	else
	{
		fprintf(stderr, "static: if.conf line %d error: unknown command '%s'\n", lineno, cmd);
		config->status = NETMAN_STATUS_ERROR;
		return;
	};
};
Пример #3
0
void TaskUSBHID(void *pdata)
{
	//uint8_t InBuffer[8]={1,2,3,4,5,6,7,8};
	uint8_t wFlashBuffer[4]={0},rFlashBuffer[4];

	while(1)
	{
		//1,校准
		//2,japan,america,china
		//3,updata
		//4,数据上传
		//5,通道反相
		  if (HIDReceive_Buffer[0] == 0x01) //calibration
			{
				/* Create a new task to do the adc calibration */
        OSTaskCreateExt(RC_Channel_Calibrate_Process,
    					(void *)0,
    					&Task_Start_Stk[Task_Start_Size - 1],
    					Task_Start_Prio,
    					Task_Start_Prio,
    					Task_Start_Stk,
    					Task_Start_Size,
    					(void *)0,
    					OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
			}
			else if (HIDReceive_Buffer[0] == 0x02)//handStyle
			{
				RC_Profile_Cfg.amjp=HIDReceive_Buffer[1];
				if(writeMask(HIDmask_address_calibration,(uint8_t *)&RC_Profile_Cfg, sizeof(struct RC_Profile_Cfg_t)) ==0)
				{ 
					
				}

			}
			else if (HIDReceive_Buffer[0] == 0x03)//updata
			{
				if(writeMask(HIDmask_address_boot,HIDReceive_Buffer+1,4) ==0)
				{ 
					//
				}
				else
				{
					__set_FAULTMASK(1);      
					NVIC_SystemReset();// 
				}
			}
			else if (HIDReceive_Buffer[0] == 0x04)
			{
					//???????
					/*********
					UserToPMABufferCopy(InBuffer, GetEPTxAddr(ENDP1), 6);
					SetEPTxCount(ENDP1, 6);
					SetEPTxValid(ENDP1);
					*********/
			}
			else if (HIDReceive_Buffer[0] == 0x05)
			{
				//adc反向,1-4通道占一位0000xxxx
				RC_Profile_Cfg.chann_reverse=HIDReceive_Buffer[1];
				if(writeMask(HIDmask_address_calibration,(uint8_t *)&RC_Profile_Cfg, sizeof(struct RC_Profile_Cfg_t)) ==0)
				{ 
					
				}

			}

			HIDReceive_Buffer[0]=0;

		OSTimeDly(OS_TICKS_PER_SEC/10);
	}
}
Пример #4
0
void netman_static_line(NetmanIfConfig *config, int lineno, char *line)
{
	char *cmd = strtok(line, SPACES);
	if (cmd == NULL)
	{
		return;
	};
	
	if (strcmp(cmd, "address") == 0)
	{
		_glidix_ifaddr6 addr;

		char *cidr = strtok(NULL, SPACES);
		if (cidr == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected address in CIDR notation, not EOL\n", lineno);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		char *slashpos = strchr(cidr, '/');
		if (slashpos == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected address in CIDR notation, not '%s'\n",
					lineno, cidr);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		*slashpos = 0;
		unsigned int netsize;
		if (sscanf(slashpos+1, "%u", &netsize) != 1)
		{
			fprintf(stderr, "static: if.conf line %d error: invalid subnet size '%s'\n", lineno, slashpos+1);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		if (!inet_pton(AF_INET6, cidr, &addr.addr))
		{
			fprintf(stderr, "static: if.conf line %d error: invalid address '%s'\n", lineno, cidr);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		if (netsize > 128)
		{
			fprintf(stderr, "static: if.conf line %d error: maximum subnet size is 128, got %u\n", lineno, netsize);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		writeMask((uint8_t*)&addr.mask, netsize);
		addr.domain = _GLIDIX_DOM_GLOBAL;
		
		char *domname = strtok(NULL, SPACES);
		if (domname != NULL)
		{
			int domain = getDomainByName(domname);
			if (domain == -1)
			{
				fprintf(stderr, "static: if.conf line %d: invalid address domain '%s'\n", lineno, domname);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			addr.domain = domain;
		};
		
		StaticConfig *statconf = (StaticConfig*) config->data;
		statconf->addrs = realloc(statconf->addrs, sizeof(_glidix_ifaddr6)*(statconf->addrcount+1));
		memcpy(&statconf->addrs[statconf->addrcount], &addr, sizeof(_glidix_ifaddr6));
		statconf->addrcount++;
		
		statconf->routes = realloc(statconf->routes, sizeof(_glidix_gen_route)*(statconf->routecount+1));
		memset(&statconf->routes[statconf->routecount], 0, sizeof(_glidix_gen_route));
		_glidix_in6_route *inroute = (_glidix_in6_route*) &statconf->routes[statconf->routecount];
		statconf->routecount++;
		
		strcpy(inroute->ifname, config->ifname);
		memcpy_with_mask(&inroute->dest, &addr.addr, &addr.mask, 16);
		memcpy(&inroute->mask, &addr.mask, 16);
		memset(&inroute->gateway, 0, 16);
		inroute->domain = addr.domain;
		inroute->flags = 0;
	}
	else if (strcmp(cmd, "route") == 0)
	{
		StaticConfig *statconf = (StaticConfig*) config->data;
		
		statconf->routes = realloc(statconf->routes, sizeof(_glidix_gen_route)*(statconf->routecount+1));
		memset(&statconf->routes[statconf->routecount], 0, sizeof(_glidix_gen_route));
		_glidix_in6_route *inroute = (_glidix_in6_route*) &statconf->routes[statconf->routecount];
		statconf->routecount++;
		
		strcpy(inroute->ifname, config->ifname);
		memset(&inroute->gateway, 0, 16);
		inroute->domain = _GLIDIX_DOM_GLOBAL;
		inroute->flags = 0;
		
		char *cidr = strtok(NULL, SPACES);
		if (cidr == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected CIDR route destination, not EOL\n", lineno);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		if (strcmp(cidr, "default") == 0)
		{
			memset(&inroute->dest, 0, 16);
			memset(&inroute->mask, 0, 16);
		}
		else
		{
			char *slashpos = strchr(cidr, '/');
			if (slashpos == NULL)
			{
				fprintf(stderr, "static: if.conf line %d error: expected prefix in CIDR notation, not '%s'\n",
						lineno, cidr);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			*slashpos = 0;
			unsigned int netsize;
			if (sscanf(slashpos+1, "%u", &netsize) != 1)
			{
				fprintf(stderr, "static: if.conf line %d error: invalid subnet size '%s'\n", lineno, slashpos+1);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			if (!inet_pton(AF_INET6, cidr, &inroute->dest))
			{
				fprintf(stderr, "static: if.conf line %d error: invalid address '%s'\n", lineno, cidr);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			if (netsize > 128)
			{
				fprintf(stderr, "static: if.conf line %d error: maximum subnet size is 128, got %u\n",
					lineno, netsize);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
		
			writeMask((uint8_t*)&inroute->mask, netsize);
		};
		
		char *nextKeyword = strtok(NULL, SPACES);
		if (nextKeyword != NULL)
		{
			if (strcmp(nextKeyword, "via") == 0)
			{
				char *gateway = strtok(NULL, SPACES);
				if (gateway == NULL)
				{
					fprintf(stderr, "static: if.conf line %d error: expected gateway IP after 'via'"
							" keyword\n", lineno);
					config->status = NETMAN_STATUS_ERROR;
					return;
				};
				
				if (!inet_pton(AF_INET6, gateway, &inroute->gateway))
				{
					fprintf(stderr, "static: if.conf line %d error: invalid gateway address '%s'\n",
							lineno, gateway);
					config->status = NETMAN_STATUS_ERROR;
					return;
				};
				
				nextKeyword = strtok(NULL, SPACES);
			};
		};
		
		if (nextKeyword != NULL)
		{
			if (strcmp(nextKeyword, "domain") != 0)
			{
				fprintf(stderr, "static: if.conf line %d error: expected 'via' or 'domain', not '%s'\n",
						lineno, nextKeyword);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			char *domname = strtok(NULL, SPACES);
			if (domname == NULL)
			{
				fprintf(stderr, "static: if.conf line %d error: expected domain name, not EOL\n", lineno);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			int domain = getDomainByName(domname);
			if (domain == -1)
			{
				fprintf(stderr, "static: if.conf line %d error: invalid route domain '%s'\n", lineno, domname);
				config->status = NETMAN_STATUS_ERROR;
				return;
			};
			
			inroute->domain = domain;
		};
	}
	else if (strcmp(cmd, "nameserver") == 0)
	{
		StaticConfig *statconf = (StaticConfig*) config->data;
		
		char *nameserver = strtok(NULL, SPACES);
		if (nameserver == NULL)
		{
			fprintf(stderr, "static: if.conf line %d error: expected name server\n", lineno);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
		
		statconf->dns = realloc(statconf->dns, 16*(++statconf->dnscount));
		if (!inet_pton(AF_INET6, nameserver, &statconf->dns[statconf->dnscount-1]))
		{
			fprintf(stderr, "static: if.conf line %d error: invalid name server address '%s'\n", lineno, nameserver);
			config->status = NETMAN_STATUS_ERROR;
			return;
		};
	}
	else
	{
		fprintf(stderr, "static: if.conf line %d error: unknown command '%s'\n", lineno, cmd);
		config->status = NETMAN_STATUS_ERROR;
		return;
	};
};