Ejemplo n.º 1
0
//------------------------------------------------Funktionen fuer das setzen von werten-----------------------------------------------------
int set()
{
  static const char set_help[] PROGMEM = "Usage: s\n\rt[hh:mm:ss] set time\n\r";
  if(uart_string[1] == 'h')
  {
    uart_send_pgm_string(set_help);
  }
#if rgb == 1
  if(uart_string[1] == 'c')
    set_rgb();
  else
#endif
#if time == 1
  if(uart_string[1] == 't')
  {
    stunde = ascii_to_char((char *) &uart_string[2]);
    minute = ascii_to_char((char *) &uart_string[5]);
    sekunde = ascii_to_char((char *) &uart_string[8]);
  }
  else
#endif
  {
    uart_send_pgm_string(set_help);
    return -1;
  }
  return 0;
}
Ejemplo n.º 2
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));
}
Ejemplo n.º 3
0
int dumpfilter(FILE *f)
{
    const int hexstart = 10;
    const int hexcount = 40;
    const int hexlen   = 32;
    int n;
    static char buf[BUFFER_SIZE];
    static char buf_new[BUFFER_SIZE];
    static int cpy_size = 0;

    while (fgets(buf, sizeof buf, f) != NULL) {
        n = strlen(buf);
        if (n > 0 && buf[n-1] == '\n')
        {
            buf[n-1] = '\0';
        }

        int status;
        status = regexec(&regTitle, buf, (size_t) 0, NULL, 0);
        if (status == 0)
        {
            if (cpy_size > 0)
            {
                // TODO process data;
                buf_new[cpy_size] = 0;
                parse_udp_buffer(buf_new, cpy_size);
            }

            // re-intial for next package
            cpy_size = 0;
            printf("T: %s\n", buf);
            continue;
        }

        status = regexec(&regData, buf, (size_t) 0, NULL, 0);
        if (status == 0)
        {
            int i = 0;
            for ( i = 0; i < hexcount; i ++)
            {
                if ((buf[hexstart + i] == ' ')
                        && (buf[hexstart + i + 1] == ' '))
                {
                    /* printf("break\n"); */
                    break;;
                }

                if (buf[hexstart + i] == ' ')
                {
                    /* printf("continue\n"); */
                    continue;
                }

                buf_new[cpy_size] = 
                    ascii_to_char(buf[hexstart + i]) * 0x10 +
                    ascii_to_char(buf[hexstart + i + 1]) ;

                /* printf("char: %2x.%2x:%02x\n",  */
                        /* buf[hexstart + i], */
                        /* buf[hexstart + 1 + i], */
                        /* (unsigned char) buf_new[cpy_size] */
                      /* ); */

                i++;
                cpy_size++;
            }
            buf_new[cpy_size] = 0;
            continue;
        }

    }
    /* printf("%s.\n", "mean package end"); */
    if (cpy_size > 0)
    {
        // TODO process data;
        buf_new[cpy_size] = 0;
        parse_udp_buffer(buf_new, cpy_size);
    }
    return 0;
}