Пример #1
0
unsigned char ascii_to_char(char b1, char b2)
{
    unsigned char ucRes;

    ucRes = (atoc(b1)) << 4 | (atoc(b2));

    return ucRes;
}
Пример #2
0
unsigned short
atoshort(char b1, char b2)
{
	unsigned short usRes;
	
	usRes = (atoc(b1)) * 16 | atoc(b2);
	
	return usRes;
}
Пример #3
0
//*****************************************************************************
//
//! DemoHandleUartCommand
//!
//!  @param  buffer
//!
//!  @return none
//!
//!  @brief  The function handles commands arrived from CLI
//
//*****************************************************************************
void
DemoHandleUartCommand(unsigned char *usBuffer)
{
	char *pcSsid, *pcData, *pcSockAddrAscii;
	unsigned long ulSsidLen, ulDataLength;
	volatile signed long iReturnValue;
	sockaddr tSocketAddr;
	socklen_t tRxPacketLength;
	unsigned char pucIP_Addr[4];
	unsigned char pucIP_DefaultGWAddr[4];
	unsigned char pucSubnetMask[4];
	unsigned char pucDNS[4];
	
	// usBuffer[0] contains always 0
	// usBuffer[1] maps the command
	// usBuffer[2..end] optional parameters
	switch(usBuffer[1])
	{
		// Start a smart configuration process
	case UART_COMMAND_CC3000_SIMPLE_CONFIG_START:
		StartSmartConfig();
		break;
		
		// Start a WLAN Connect process
	case UART_COMMAND_CC3000_CONNECT:
		{
			ulSsidLen = atoc(usBuffer[2]);
			pcSsid = (char *)&usBuffer[3];
			
#ifndef CC3000_TINY_DRIVER 		
			wlan_connect(WLAN_SEC_UNSEC, pcSsid, ulSsidLen,NULL, NULL, 0);
#else
			
			wlan_connect(pcSsid,ulSsidLen);
#endif
		} 
		break;
		
		
		// Handle open socket command
	case UART_COMMAND_SOCKET_OPEN:
		// wait for DHCP process to finish. if you are using a static IP address 
		// please delete the wait for DHCP event - ulCC3000DHCP 
		while ((ulCC3000DHCP == 0) || (ulCC3000Connected == 0))
		{
			hci_unsolicited_event_handler();
			
			SysCtlDelay(1000);
		}
		ulSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
		break;
		
		// Handle close socket command
	case UART_COMMAND_SOCKET_CLOSE:
		closesocket(ulSocket);
		ulSocket = 0xFFFFFFFF;
		break;
		
		
		// Handle receive data command
	case UART_COMMAND_RCV_DATA:
		iReturnValue = recvfrom(ulSocket, pucCC3000_Rx_Buffer, 
														CC3000_APP_BUFFER_SIZE, 0, &tSocketAddr, 
														&tRxPacketLength);
		if (iReturnValue <= 0)
		{
			// No data received by device
			DispatcherUartSendPacket((unsigned char*)pucUARTNoDataString, 
															 sizeof(pucUARTNoDataString));
		}
		else
		{
			// Send data to UART...
			DispatcherUartSendPacket(pucCC3000_Rx_Buffer, CC3000_APP_BUFFER_SIZE);
		}
		break;
		
		// Handle send data command
	case UART_COMMAND_SEND_DATA:
		
		// data pointer
		pcData = (char *)&usBuffer[4];
		
		// data length to send
		ulDataLength = atoshort(usBuffer[2], usBuffer[3]);
		pcSockAddrAscii = (pcData + ulDataLength);
		
		// the family is always AF_INET
		tSocketAddr.sa_family = atoshort(pcSockAddrAscii[0], pcSockAddrAscii[1]);
		
		// the destination port
		tSocketAddr.sa_data[0] = ascii_to_char(pcSockAddrAscii[2], pcSockAddrAscii[3]);
		tSocketAddr.sa_data[1] = ascii_to_char(pcSockAddrAscii[4], pcSockAddrAscii[5]);
		
		// the destination IP address
		tSocketAddr.sa_data[2] = ascii_to_char(pcSockAddrAscii[6], pcSockAddrAscii[7]);
		tSocketAddr.sa_data[3] = ascii_to_char(pcSockAddrAscii[8], pcSockAddrAscii[9]);
		tSocketAddr.sa_data[4] = ascii_to_char(pcSockAddrAscii[10], pcSockAddrAscii[11]);
		tSocketAddr.sa_data[5] = ascii_to_char(pcSockAddrAscii[12], pcSockAddrAscii[13]);
		
		sendto(ulSocket, pcData, ulDataLength, 0, &tSocketAddr, sizeof(sockaddr));
		break;
		
		// Handle bind command
	case UART_COMMAND_BSD_BIND:
		tSocketAddr.sa_family = AF_INET;
		
		// the source port
		tSocketAddr.sa_data[0] = ascii_to_char(usBuffer[2], usBuffer[3]);
		tSocketAddr.sa_data[1] = ascii_to_char(usBuffer[4], usBuffer[5]);
		
		// all 0 IP address
		memset (&tSocketAddr.sa_data[2], 0, 4);
		
		bind(ulSocket, &tSocketAddr, sizeof(sockaddr));
		
		break;
		
		// Handle IP configuration command
	case UART_COMMAND_IP_CONFIG:
		
		// Network mask is assumed to be 255.255.255.0
		pucSubnetMask[0] = 0xFF;
		pucSubnetMask[1] = 0xFF;
		pucSubnetMask[2] = 0xFF;
		pucSubnetMask[3] = 0x0;
		
		pucIP_Addr[0] = ascii_to_char(usBuffer[2], usBuffer[3]);
		pucIP_Addr[1] = ascii_to_char(usBuffer[4], usBuffer[5]);
		pucIP_Addr[2] = ascii_to_char(usBuffer[6], usBuffer[7]);
		pucIP_Addr[3] = ascii_to_char(usBuffer[8], usBuffer[9]);
		
		pucIP_DefaultGWAddr[0] = ascii_to_char(usBuffer[10], usBuffer[11]);
		pucIP_DefaultGWAddr[1] = ascii_to_char(usBuffer[12], usBuffer[13]);
		pucIP_DefaultGWAddr[2] = ascii_to_char(usBuffer[14], usBuffer[15]);
		pucIP_DefaultGWAddr[3] = ascii_to_char(usBuffer[16], usBuffer[17]);
		
		pucDNS[0] = 0;
		pucDNS[1] = 0;
		pucDNS[2] = 0;
		pucDNS[3] = 0;
		
		netapp_dhcp((unsigned long *)pucIP_Addr, (unsigned long *)pucSubnetMask, 
								(unsigned long *)pucIP_DefaultGWAddr, (unsigned long *)pucDNS);
		
		break;
		
		// Handle WLAN disconnect command
	case UART_COMMAND_CC3000_DISCONNECT:
		wlan_disconnect();
		break;
		
		// Handle erase policy command
	case UART_COMMAND_CC3000_DEL_POLICY:
		wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE);
		break;
		
		// Handle send DNS Discovery command
	case UART_COMMAND_SEND_DNS_ADVERTIZE:
		if(ulCC3000DHCP)
		{
			mdnsAdvertiser(1,device_name,strlen(device_name));
		}
		
		break;
		
	default:
		DispatcherUartSendPacket((unsigned char*)pucUARTIllegalCommandString, 
														 sizeof(pucUARTIllegalCommandString));
		break;
		
	}
	
	// Send a response - the command handling has finished
	DispatcherUartSendPacket((unsigned char *)(pucUARTCommandDoneString), 
													 sizeof(pucUARTCommandDoneString));
}
Пример #4
0
Appearance *Option::parseAppearance(char *str)
{
	Appearance *app = 0;
	char *p;

	if (*str == '[') {
		char *tok;
		int mask = 0;
		int top, left, bottom, right;

		top = left = bottom = right = 0;

		p = strtok_r(str, "[] ,", &tok);
		app = parseAppearance(p);

		if (!(p = strtok_r(NULL, "[] ,", &tok))) goto err;
		top = strtol(p, 0, 10);
		if (strchr(p, '%'))
			mask |= PERPAD_TOP;

		if (!(p = strtok_r(NULL, "[] ,", &tok))) goto err;
		right = strtol(p, 0, 10);
		if (strchr(p, '%'))
			mask |= PERPAD_RIGHT;

		if ((p = strtok_r(NULL, "[] ,", &tok))) {
			bottom = strtol(p, 0, 10);
			if (strchr(p, '%'))
				mask |= PERPAD_BOT;

			if (!(p = strtok_r(NULL, "[] ,", &tok))) goto err;
			left = strtol(p, 0, 10);
			if (strchr(p, '%'))
				mask |= PERPAD_LEFT;
		}
		else {
			bottom = top;
			if (mask & PERPAD_TOP)
				mask |= PERPAD_BOT;

			right = left;
			if (mask & PERPAD_LEFT)
				mask |= PERPAD_RIGHT;
		}
		app->setPadding(Padding(mask, top, right, bottom, left));
	}
	else if ((p = strstr(str, "gradient"))) {
		int direction = 0;
		char *tok;
		p = strchr(p, '(');
		if (!p) goto err;
		p = strtok_r(p, ", ()", &tok);
		if (strcmp(p, "vert") == 0)
			direction = GRAD_VERT;
		else 
			direction = GRAD_HORZ;

		app = new GradientAppearance(direction);
		GradientAppearance *gapp = dynamic_cast<GradientAppearance *>(app);

		while((p = strtok_r(NULL, ", ()", &tok)) != NULL){
			gapp->addColor(atoc(p));
		}
	}
	else if ((p = strstr(str, "image"))) {
		char *tok;
		p = strchr(p, '(');
		if (!p) goto err;

		if (!(p = strtok_r(p, "(\")", &tok))) goto err;

		Setting *setting = Insune::getSingleton()->getSetting("style");
		const char *style = setting->getValue()->getString();
		char stylepath[256];
		snprintf(stylepath, 256, STYLEDIR "%s/%s", style, p);

		char *align = NULL;
		char *type = NULL;
		if ((p = strtok_r(NULL, "(\")", &tok))) {
			if (*p == '@') {
				align = p + 1;
				if ((p = strchr(p + 1, '!'))) {
					*p = '\0';
					type = p + 1;
				}
			} else if (*p == '!') {
				type = p + 1;
				if ((p = strchr(p + 1, '@'))) {
					*p = '\0';
					align = p + 1;
				}
			}
		}
		if (align && type)
			app = new ImageAppearance(stylepath, align, type);
		else if (align)
			app = new ImageAppearance(stylepath, align);
		else if (type)
			app = new ImageAppearance(stylepath, NULL, type);
		else
			app = new ImageAppearance(stylepath);

	}

	else {
		app = new SolidAppearance(atoc(str));
	}

	return app;
err:
	fprintf(stderr, "Error parsing appearances. Value:\n```%s'''\n", str);
	return NULL;
}