Esempio n. 1
0
void halLedBlinkBlink( uint8_t count, uint16_t blinkTime)
{
  ledBlinkTime = blinkTime;
  turnLedOff(activeLed);
  ledEventState = LED_BLINKING_OFF;
  emberEventControlSetDelayMS(emberAfPluginLedBlinkLedEventFunctionEventControl,
                              ledBlinkTime);
  ledBlinkCount = count;
}
Esempio n. 2
0
void halLedBlinkLedOff( uint8_t time )
{
  turnLedOff(activeLed);
  ledEventState = LED_OFF;

  if (time > 0) {
    emberEventControlSetDelayQS(emberAfPluginLedBlinkLedEventFunctionEventControl,
                                ((uint16_t) time) * 4);
  } else {
    emberEventControlSetInactive(emberAfPluginLedBlinkLedEventFunctionEventControl);
  }
}
Esempio n. 3
0
//*****************************************************************************
//
//!  \brief  Resets the State Machine
//!  
//!  \param  None
//!
//!  \return none
//!  
//
//*****************************************************************************
void resetCC3000StateMachine()
{
    cc3000state = CC3000_UNINIT;

    // Turn off all Board LEDs

    turnLedOff(CC3000_ON_IND);
    turnLedOff(CC3000_ASSOCIATED_IND);
    turnLedOff(CC3000_IP_ALLOC_IND);
    turnLedOff(CC3000_SERVER_INIT_IND);
    turnLedOff(CC3000_CLIENT_CONNECTED_IND);
    turnLedOff(CC3000_SENDING_DATA_IND);
    turnLedOff(CC3000_UNUSED1_IND);
    turnLedOff(CC3000_FTC_IND);
}
Esempio n. 4
0
void CC3000_AsyncEventCallback(long lEventType, char * data, unsigned char length)
{

	if (lEventType == HCI_EVNT_WLAN_KEEPALIVE)
		{
		__no_operation();
		}


	if (lEventType == HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE)
	{
		//uiSmartConfigFinished = 1;
	}

	if (lEventType == HCI_EVNT_WLAN_UNSOL_CONNECT)
	{
		uiCC3000Connected = 1;


		#ifdef WLAN_TEST_MODE
         turnLedOn(7);
		#endif
	}

	if (lEventType == HCI_EVNT_WLAN_UNSOL_DISCONNECT)
	{
		uiCC3000Connected = 0;

		#ifdef WLAN_TEST_MODE
           turnLedOff(7);
		#endif
	}

	if (lEventType == HCI_EVNT_WLAN_UNSOL_DHCP)
	{
		uiCC3000DHCP = 1;
		#ifdef WLAN_TEST_MODE
                turnLedOn(6);
		#endif
	}

	if (lEventType == HCI_EVENT_CC3000_CAN_SHUT_DOWN)
	{
		//OkToDoShutDown = 1;
		__no_operation();
	}

}
Esempio n. 5
0
/**
 * This function applies an operation on a LED.
 * It is assumed that the parameters are ordered as denoted below.
 * @param uLedParams Includes the LED parameters: LED number and LED action
 * @return no return value
 */
void HttpDynamicHandler_ActOnLED(inputParams uLedInParams, outputParams *uLedOutParams)
{
    switch(uLedInParams.uLedParam.uLedAction)
    {
      case OFF:
	  turnLedOff(uLedInParams.uLedParam.uLedNumber);
	  break;
     	case ON:
	  turnLedOn(uLedInParams.uLedParam.uLedNumber);
	  break;
       case toggle:
	  toggleLed(uLedInParams.uLedParam.uLedNumber);
	  break;
      default:
	  break;
    }
}
Esempio n. 6
0
void ExportService::startUSBExport()
{
//    Logger::instance()->writeRecord(Logger::severity_level::debug, "Exporter Module", Q_FUNC_INFO, "Starting Exporter Service");

    /*
     * Creates the object of the classes and then move these objects to execute as thread.
     * Make the connection between threads. Starts both threads.
     */

//    m_exporter->moveToThread(m_exportThread);
//    QObject::connect(m_exportThread, SIGNAL(started()), m_exporter, SLOT(startExport()));


    DeviceThread::instance()->moveToThread(m_daemonThread);
    QObject::connect(m_daemonThread, SIGNAL(started()), DeviceThread::instance(), SLOT(startListening()));
    QObject::connect(DeviceThread::instance(), SIGNAL(exportToDevice(QString)), m_exporter, SLOT(exportAction(QString)));
    QObject::connect(DeviceThread::instance(), SIGNAL(turnLedOff()), m_exporter, SLOT(turnOffLed()));

//    m_exportThread->start();
    m_daemonThread->start();
    m_exporter->startExport();
}
//*****************************************************************************
//
//!  \brief  Unsets a state from the state machine
//!  Also handles LEDs
//!  
//!  \param  None
//!
//!  \return none
//!  
//
//*****************************************************************************
void unsetCC3000MachineState(char stat)
{
    char bitmask = stat;
    cc3000state &= ~bitmask;
    
    int i = FIRST_STATE_LED_NUM;
    int k = NUM_STATES; // Set to last element in state list
    
    // Set all upper bits to 0 as well since state machine cannot have
    // those states.
    while(bitmask < 0x80)
    {
        cc3000state &= ~bitmask;
        bitmask = bitmask << 1;
        i++;
    }
    
    // Turn off all upper state LEDs
    for(; i > FIRST_STATE_LED_NUM; i--)
    {
        turnLedOff(k);
        k--;
    }    
}
Esempio n. 8
0
/************************************************************************************************
 * 		Execute_Mgr_Cmd()
 *
 *
 *
 *
 *****************************************************************************************************/
void Execute_Mgr_Cmd()
{
	uint8 ret;


	ret=receive_msg_from_Mgr(&gsm);
	if(!ret){
		_no_operation();
		return;
	}
	else{

		turnLedOn(SYSLED2);
		// 	__delay_cycles(22000000);


		//Execute Commands.
		feature_Interpreter(&gsm);

		turnLedOff(SYSLED2);

		return;
	}
}
Esempio n. 9
0
//*****************************************************************************
//
//!  \brief returns a pointer to the RX buffer at the specific position
//!
//!  \param  pos is the location in the RX buffer to which pointer will point
//!
//!  \return a pointer to the RX UART buffer
//
//*****************************************************************************
void runUARTTerminal()
{
    char validPos = 0;
    char * ftcPrefixptr;
    
    if(uartRXByte(bytesInUart()-1) != '\b' && uartRXByte(bytesInUart()-1) != 0x7F)
    {
            sendByte(uartRXByte(bytesInUart()-1));
    }
    else
    {
        // Do backspace only if it doesn't erase '>'
        // Note that the backspace is itself in the buffer
        if(bytesInUart() > 1)
        {  
            // Echo Backspace and remove latest byte
            sendByte(uartRXByte(bytesInUart()-1));
            
            // Erase Backspace from buffer
            removeLastByteinBuf();
            
            // Erase last character
            removeLastByteinBuf();           
        }
        else
        {
            // Erase Backspace from buffer
            removeLastByteinBuf();
        }
    }
    
    
    switch(uartRXByte(bytesInUart()-1)) 
    {
    case '\r':
    case '\n':
        
        // Erase \r or \n from buffer
        removeLastByteinBuf();
        
        // Skip all non characters
        validPos = 0;
        while(uartRXByte(validPos) < 'A' && validPos <= bytesInUart() )
            validPos++;
        
        // Process Command
        if(validPos <= bytesInUart())
        {
            sendString("\n");
            
            // help command
            if(checkCommand(uartRXBytePointer(validPos),"help") == 1)
            {
                printCommandList();
            }
            else if(checkCommand(uartRXBytePointer(validPos),"assoc") == 1)
            {                
                // Disable RX interrupt so it does not interfere
                // with GUI's command
                UCA0IE &= ~UCRXIE;
                
                validPos += strlen("assoc");
                while(uartRXByte(validPos) < 'A' && validPos <= bytesInUart())
                    validPos++;
                
                *ptrSSIDInd = FRAM_FLAG_SET;
                memset((char *)ptrSSID, 0, MAX_SSID_LEN);
                memcpy(ptrSSID,uartRXBytePointer(validPos),MAX_SSID_LEN);
                
                sendString("OK\r\n");
                
                // If server is running, accept is blocking us. We can
                // therefore just restart the MSP430. Since the SSID indicator
                // has been set, at startup it will attempt to associate to the
                // AP requested by the user.
                if(currentCC3000State() & CC3000_SERVER_INIT)
                {  
                     terminalPrint("Restarting MSP430...\r\n");                  
                    restartMSP430();
                }
                else
                {
                    // Associate command
                    ConnectUsingSSID((char *)ptrSSID);
                }
                UCA0IE |= UCRXIE;                         // Enable RX interrupt
            }
            else if(checkCommand(uartRXBytePointer(validPos),"stat") == 1)
            {
                #ifdef    SENSOR_APP_VERSION
                    terminalPrint("Sensor App Version: ");
                    terminalPrint(SENSOR_APP_VERSION);
                    terminalPrint("\r\n");
                #endif
//#ifndef CC3000_TINY_DRIVER
//                printConnectionInfo(getCC3000Info());
//#endif
            }
            else if(checkCommand(uartRXBytePointer(validPos),"prfx") == 1)
            {
                // parameter sent with prfx should be 3 letters
                // that are the prefix. If they're not, we issue an error
                
                validPos += strlen("prfx");
                while(uartRXByte(validPos) < 'A' && validPos <= bytesInUart() )
                    validPos++;
                
                if(validPos <= bytesInUart())
                {
                    // Verify letters
                    if(isUppercaseChar(uartRXByte(validPos)) && 
                       isUppercaseChar(uartRXByte(validPos+1)) && 
                       isUppercaseChar(uartRXByte(validPos+2)))
                    {
                        // Wait for 3 characters from UART
                        ftcPrefixptr = (char *)(&aucCC3000_prefix[0]);
                        *ftcPrefixptr = uartRXByte(validPos);
                        
                        ftcPrefixptr = (char *)(&aucCC3000_prefix[1]);
                        *ftcPrefixptr = uartRXByte(validPos+1);
                        
                        
                        ftcPrefixptr = (char *)(&aucCC3000_prefix[2]);
                        *ftcPrefixptr = uartRXByte(validPos+2);
                        
                        // Send new prefix to CC3000
                        wlan_smart_config_set_prefix((char *)aucCC3000_prefix);
                        
                        char prfStr[4];
                        prfStr[0] = aucCC3000_prefix[0];
                        prfStr[1] = aucCC3000_prefix[1];
                        prfStr[2] = aucCC3000_prefix[2];
                        prfStr[3] = '\0';
                        
                        turnLedOff(CC3000_UNUSED1_IND);
                        sendString("\r\nSmart Config Prefix changed to: ");
                        sendString (prfStr);
                        sendString("\r\n");
                    }
                    else
                    {
                        sendString("Prefix Error");
                    }
                    
                }
                else
                {
                    sendString("Prefix Error");   
                }                        
            }
            else
            {
                sendString("Invalid or incomplete command. Type help for command list");
            }
        }
        
        // Send '>'
        sendString("\r\n> ");
        resetUARTBuffer();
        break;
        
    }
}
void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length)
{
  
  
	if (lEventType == HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE)
	{
		ulSmartConfigFinished = 1;
		ucStopSmartConfig     = 1;  
	}
	
	if (lEventType == HCI_EVNT_WLAN_UNSOL_CONNECT)
	{
		ulCC3000Connected = 1;
		
		// Turn on the LED7
		turnLedOn(7);
	}
	
	if (lEventType == HCI_EVNT_WLAN_UNSOL_DISCONNECT)
	{		
		ulCC3000Connected = 0;
		ulCC3000DHCP      = 0;
		ulCC3000DHCP_configured = 0;
		printOnce = 1;
		
		// Turn off the LED7
		turnLedOff(7);
		
		// Turn off LED5
		turnLedOff(8);          
	}
	
	if (lEventType == HCI_EVNT_WLAN_UNSOL_DHCP)
	{
		// Notes: 
		// 1) IP config parameters are received swapped
		// 2) IP config parameters are valid only if status is OK, i.e. ulCC3000DHCP becomes 1
		
		// only if status is OK, the flag is set to 1 and the addresses are valid
		if ( *(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0)
		{
			sprintf( (char*)pucCC3000_Rx_Buffer,"IP:%d.%d.%d.%d\f\r", data[3],data[2], data[1], data[0] );

			ulCC3000DHCP = 1;

			turnLedOn(8);
		}
		else
		{
			ulCC3000DHCP = 0;

			turnLedOff(8);
		}
	}
	
	if (lEventType == HCI_EVENT_CC3000_CAN_SHUT_DOWN)
	{
		OkToDoShutDown = 1;
	}
	
}
Esempio n. 11
0
//*****************************************************************************
//
//!  main
//!
//!  \param  None
//!
//!  \return none
//!
//!  \brief   The main loop is executed here
//
//*****************************************************************************
void main(void)
{
  unsigned char loopCount = 0;
  int loop_time = 2000;

  ulCC3000Connected = 0;
  SendmDNSAdvertisment = 0;

  // Initialize hardware and interfaces
  board_init();
  initUart();
  sendString("System init : \r\n");

  // Must initialize one time for MAC address prepare..
  if (!Exosite_Init("exosite", "cc3000wifismartconfig", IF_WIFI, 0))
  {
    show_status();
    while(1);
  }

  // Main Loop
  while (1)
  {
    // Perform Smart Config if button pressed in current run or if flag set in FRAM
    // from previous MSP430 Run.
    if(runSmartConfig == 1 || *ptrFtcAtStartup == SMART_CONFIG_SET)
    {
      // Clear flag
      ClearFTCflag();
      unsetCC3000MachineState(CC3000_ASSOC);

      // Start the Smart Config Process
      StartSmartConfig();
      runSmartConfig = 0;
    }

    WDTCTL = WDTPW + WDTHOLD;
    // If connectivity is good, run the primary functionality
    if(checkWiFiConnected())
    {
      char * pbuf = exo_buffer;

      //unsolicicted_events_timer_disable();

      if (0 == cloud_status)
      { //check to see if we have a valid connection
        loop_time = 2000;

        loopCount = 1;

        while (loopCount++ <= (WRITE_INTERVAL+1))
        {
//          WDTCTL = WDT_ARST_1000;
          if (Exosite_Read("led7_ctrl", pbuf, EXO_BUFFER_SIZE))
          {
        	// Read success
        	turnLedOn(CC3000_CLIENT_CONNECTED_IND);

            if (!strncmp(pbuf, "0", 1))
              turnLedOff(LED7);
            else if (!strncmp(pbuf, "1", 1))
              turnLedOn(LED7);
          }
          else
          {
        	if (EXO_STATUS_NOAUTH == Exosite_StatusCode())
        	{
        		turnLedOff(CC3000_CLIENT_CONNECTED_IND);
        		// Activate device again
        		cloud_status = Exosite_Activate();
        	}
          }

          hci_unsolicited_event_handler();
          unsolicicted_events_timer_init();
          //sendString("== Exosite Read==\r\n");
          WDTCTL = WDTPW + WDTHOLD;
          busyWait(loop_time);        //delay before looping again
        }

        unsolicicted_events_timer_init();
    	if (EXO_STATUS_NOAUTH != Exosite_StatusCode())
    	{
          unsigned char sensorCount = 0;
          int value;
          char strRead[6]; //largest value of an int in ascii is 5 + null terminate
          WDTCTL = WDT_ARST_1000;
          for (sensorCount = 0; sensorCount < SENSOR_END; sensorCount++)
          {
            value = getSensorResult(sensorCount);                                       //get the sensor reading
            itoa(value, strRead, 10);                           //convert to a string
            unsolicicted_events_timer_init();
            //for each reading / data source (alias), we need to build the string "alias=value" (must be URL encoded)
            //this is all just an iteration of, for example, Exosite_Write("mydata=hello_world",18);
            memcpy(pbuf,&sensorNames[sensorCount][0],strlen(&sensorNames[sensorCount][0]));  //copy alias name into buffer
            pbuf += strlen(&sensorNames[sensorCount][0]);
            *pbuf++ = 0x3d;                                             //put an '=' into buffer
            memcpy(pbuf,strRead, strlen(strRead));                      //copy value into buffer
            pbuf += strlen(strRead);
            *pbuf++ = 0x26;                                             //put an '&' into buffer, the '&' ties successive alias=val pairs together
          }
          pbuf--;                                                                       //back out the last '&'
          WDTCTL = WDT_ARST_1000;
          Exosite_Write(exo_buffer,(pbuf - exo_buffer - 1));    //write all sensor values to the cloud

          if (EXO_STATUS_OK == Exosite_StatusCode())
          { // Write success
    	    turnLedOn(CC3000_CLIENT_CONNECTED_IND);
          }
    	}
      } else {
          //we don't have a good connection yet - we keep retrying to authenticate
    	  WDTCTL = WDTPW + WDTHOLD;
          //sendString("== Exosite Activate==\r\n");
          cloud_status = Exosite_Activate();
          if (0 != cloud_status) loop_time = 30000; //delay 30 seconds before retrying...
      }

        unsolicicted_events_timer_init();
      }
      WDTCTL = WDTPW + WDTHOLD;
      // TODO - make this a sleep instead of busy wait
      busyWait(loop_time);        //delay before looping again
    }
}
Esempio n. 12
0
//------------------------------------------------------------------------------
// Plugin event handlers
void emberAfPluginLedBlinkLedEventFunctionEventHandler( void )
{
  switch(ledEventState) {
  case LED_ON:
    // was on.  this must be time to turn it off.
    turnLedOff(activeLed);
    emberEventControlSetInactive(emberAfPluginLedBlinkLedEventFunctionEventControl);
    break;

  case LED_OFF:
    // was on.  this must be time to turn it off.
    turnLedOn(activeLed);
    emberEventControlSetInactive(emberAfPluginLedBlinkLedEventFunctionEventControl);
    break;

  case LED_BLINKING_ON:
    turnLedOff(activeLed);
    if (ledBlinkCount > 0) {
      if (ledBlinkCount != 255) { // blink forever if count is 255
        ledBlinkCount --;
      }
      if (ledBlinkCount > 0) {
        ledEventState = LED_BLINKING_OFF;
        emberEventControlSetDelayMS(emberAfPluginLedBlinkLedEventFunctionEventControl,
                                    ledBlinkTime);

      } else {
        ledEventState = LED_OFF;
        emberEventControlSetInactive(emberAfPluginLedBlinkLedEventFunctionEventControl);
      }
    } else {
      ledEventState = LED_BLINKING_OFF;
      emberEventControlSetDelayMS(emberAfPluginLedBlinkLedEventFunctionEventControl,
                                  ledBlinkTime);
    }
    break;
  case LED_BLINKING_OFF:
    turnLedOn(activeLed);
    ledEventState = LED_BLINKING_ON;
    emberEventControlSetDelayMS(emberAfPluginLedBlinkLedEventFunctionEventControl,
                                ledBlinkTime);
    break;
  case LED_BLINK_PATTERN:
    if (ledBlinkCount == 0) {
      turnLedOff(activeLed);

      ledEventState = LED_OFF;
      emberEventControlSetInactive(emberAfPluginLedBlinkLedEventFunctionEventControl);

      break;
    }

    if (blinkPatternPointer %2 == 1) {
      turnLedOff(activeLed);
    } else {
      turnLedOn(activeLed);
    }

    emberEventControlSetDelayMS(emberAfPluginLedBlinkLedEventFunctionEventControl,
                                blinkPattern[blinkPatternPointer]);

    blinkPatternPointer ++;

    if (blinkPatternPointer >= blinkPatternLength) {
      blinkPatternPointer = 0;
      if (ledBlinkCount != 255) { // blink forever if count is 255
        ledBlinkCount --;
      }
    }

  default:
    break;
  }
}
Esempio n. 13
0
/*********************************************************************************************
 * 					appMain()
 *
 *
 *
 *********************************************************************************************/
void
appMain()
{
	uint8  err, i,count;

		#ifdef 	FIRST_TIME_RUN		//this is temporary arrangement.
		Ist_run_config();			//FIRST_TIME_CONNECTION_SETTING_PROFILES
		#endif



		wait_for_connection();

		err=	open_txPort_Mgr();
				if(err)
				{
					//fatal error , failed to open socket with mgr.
					// restart .
					fatal();
				}


err=	open_rxPort_Mgr();
		if(err)
		{
			//fatal error , failed to open socket with mgr.
			// restart .
			fatal();
		}

		err= setsockopt_rcv_timeout( 10000 );
		if(err){
					fatal();
			}


		for( i=15;  i>0;i--)
		{
				if(i>10)
				count = 20;
				else
				count = 1*i;

			toggleLed(SYSLED1);
			while(count--)
	    	 __delay_cycles( 400000);
			//turnLedOn(SYSLED1);
			 //__delay_cycles( 30000000);
		}

		turnLedOn(SYSLED1);
    	 __delay_cycles(62000000);

    	 test_send_data_to(2);
    	// register_Me();
 		//TODO: this need to be substituted with registration related functions, which will be probably triggered  on button press.



    	 //Infinite loop.
    	 while(1) {

    		 	 turnLedOff(SYSLED1);

				#ifdef 	TEST_SOCKET_RECEIVE

    		 	 test_rcv_data();
    		 	 #else

    		 	 Execute_Mgr_Cmd();

    		 	 #endif

    		 	 turnLedOn(SYSLED1);
    		 	 __delay_cycles(22000000);
    	 }


//  return;
}
/*!
    \brief This function handles callback for the HTTP server events

    \param[in]      pEvent - Contains the relevant event information
    \param[in]      pResponse - Should be filled by the user with the
                    relevant response information

    \return         None

    \note

    \warning
*/
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pEvent,
                                  SlHttpServerResponse_t *pResponse)
{
    unsigned int ulSpeed, n;

    if(pEvent == NULL || pResponse == NULL)
        CLI_Write(" [HTTP EVENT] NULL Pointer Error \n\r");

    switch (pEvent->Event)
    {
        case SL_NETAPP_HTTPGETTOKENVALUE_EVENT:
        {
            _u8 status = 0;
            _u8 *ptr = 0;

            ptr = pResponse->ResponseData.token_value.data;
            pResponse->ResponseData.token_value.len = 0;

  /* Check if the token is for the original CC3100 demo    */
            if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token,
                                         pal_Strlen(GET_token)) == 0)
            {
                //status = GetLEDStatus();
                pal_Memcpy(ptr, "LED1_", pal_Strlen("LED1_"));
                ptr += 5;
                pResponse->ResponseData.token_value.len += 5;
                if(status & 0x01)
                {
                    pal_Memcpy(ptr, "ON", pal_Strlen("ON"));
                    ptr += 2;
                    pResponse->ResponseData.token_value.len += 2;
                }
                else
                {
                    pal_Memcpy(ptr, "OFF", pal_Strlen("OFF"));
                    ptr += 3;
                    pResponse->ResponseData.token_value.len += 3;
                }
                pal_Memcpy(ptr,",LED2_", pal_Strlen(",LED2_"));
                ptr += 6;
                pResponse->ResponseData.token_value.len += 6;
                if(status & 0x02)
                {
                    pal_Memcpy(ptr, "ON", pal_Strlen("ON"));
                    ptr += 2;
                    pResponse->ResponseData.token_value.len += 2;
                }
                else
                {
                    pal_Memcpy(ptr, "OFF", pal_Strlen("OFF"));
                    ptr += 3;
                    pResponse->ResponseData.token_value.len += 3;
                }

                *ptr = '\0';
            }


/* Check if the token is for the added MCU LED toggle demo    */

/* check if the get LED on event, return the LED on status  */
           if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token0,
                                                    pal_Strlen(GET_token0)) == 0)
           {
        	   if(g_ui32LED_Status)
        	   {
        		   pal_Memcpy(ptr, "checked", pal_Strlen("checked")); /* return the on status to update the "LED ON" button */
        		   ptr += 7;
        		   pResponse->ResponseData.token_value.len += 7;
        	   }
        	   else
        	   {
        		   pal_Memcpy(ptr, " ", pal_Strlen(" "));            /* do not update the "LED ON" button */
        	 	   ptr += 1;
        	       pResponse->ResponseData.token_value.len += 1;
        	   }
 			   *ptr = '\0';
           }

 /* check if the get LED off event, return the LED off status */
           else if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token1,
							   pal_Strlen(GET_token1)) == 0)
		  {
			   if(!g_ui32LED_Status)
			   {
				   pal_Memcpy(ptr, "checked", pal_Strlen("checked")); /* return the off status to update the "LED OFF" button */
				   ptr += 7;
				   pResponse->ResponseData.token_value.len += 7;
			   }
			   else
			   {
				   pal_Memcpy(ptr, " ", pal_Strlen(" "));            /* do not update the "LED OFF" button */
				   ptr += 1;
				   pResponse->ResponseData.token_value.len += 1;
			   }
		  	   *ptr = '\0';
		  }

/* check if the get LED toggle on event */
           else if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token2,
		  		 							   pal_Strlen(GET_token2)) == 0)
		  {
			   if(g_ui32LED_Toggle_Status)
			   {
				   pal_Memcpy(ptr, "checked", pal_Strlen("checked"));    /* return the on status to update the "LED toggle on" button */
				   ptr += 7;
				   pResponse->ResponseData.token_value.len += 7;
			   }
			   else
			   {
				   pal_Memcpy(ptr, " ", pal_Strlen(" "));               /* do not update the "LED toggle on" button */
				   ptr += 1;
				   pResponse->ResponseData.token_value.len += 1;
			   }
			   *ptr = '\0';
		  }

/* check if the get LED toggle off event */
           else if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token3,
		 							   pal_Strlen(GET_token3)) == 0)
		  {
			   if(!g_ui32LED_Toggle_Status)
			   {
				   pal_Memcpy(ptr, "checked", pal_Strlen("checked"));   /* return the off status to update the "LED toggle off" button */
				   ptr += 7;
				   pResponse->ResponseData.token_value.len += 7;
			   }
			   else
			   {
				   pal_Memcpy(ptr, " ", pal_Strlen(" "));                /* do not update the "LED toggle off" button */
				   ptr += 1;
				   pResponse->ResponseData.token_value.len += 1;
			   }
			   *ptr = '\0';
		  }

/* check if the get toggle speed event  */
           else if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token4,
										   pal_Strlen(GET_token4)) == 0)
		  {
			   n = Decimal2String(ptr, g_ui32AnimSpeed); /* write speed to the buffer and update the string length */
			   ptr += n;
			   pResponse->ResponseData.token_value.len += n;
			   *ptr = '\0';
		  }

/* check if the get button 1 count event */
           else if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token5,
											   pal_Strlen(GET_token5)) == 0)
		  {
			   n = Decimal2String(ptr, g_ui32SW1Presses);  /* write number of button press to the buffer and update the string length */
			   ptr += n;
			   pResponse->ResponseData.token_value.len += n;
			   *ptr = '\0';
		  }

/* check if the get button 2 count event */
           else if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token6,
		  		  							   pal_Strlen(GET_token6)) == 0)
		  {
			   n = Decimal2String(ptr, g_ui32SW2Presses);  /* write number of button press to the buffer and update the string length */
  			   ptr += n;
  			   pResponse->ResponseData.token_value.len += n;
  			   *ptr = '\0';
  		  }


/* check if the get temperature event  */
           else if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token7,
		  							   pal_Strlen(GET_token7)) == 0)
		  {
			   if(!g_ui32Temperature_U)
			   {
				   n = Decimal2String(ptr, g_ui32InternalTempC); /* write temperature in C to the buffer and update the string length */
			   }
			   else
			   {
				   n = Decimal2String(ptr, g_ui32InternalTempF); /* write temperature in F to the buffer and update the string length */
			   }
			   ptr += n;
			   pResponse->ResponseData.token_value.len += n;
			   *ptr = '\0';
		  }

/* check if the temperature in C event */
           else if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token8,
										  pal_Strlen(GET_token8)) == 0)
		 {
			   if(!g_ui32Temperature_U)
			   {
				   pal_Memcpy(ptr, "checked", pal_Strlen("checked")); /* update the temperature in C button and update the string length */
				   ptr += 7;
				   pResponse->ResponseData.token_value.len += 7;
			   }
			   else
			   {
				   pal_Memcpy(ptr, " ", pal_Strlen(" "));
				   ptr += 1;
				   pResponse->ResponseData.token_value.len += 1;
			   }
			   *ptr = '\0';
		 }

/* check if the temperature in F event */
           else if(pal_Memcmp(pEvent->EventData.httpTokenName.data, GET_token9,
														  pal_Strlen(GET_token9)) == 0)
		 {
			   if(g_ui32Temperature_U)
			   {
				   pal_Memcpy(ptr, "checked", pal_Strlen("checked")); /* update the temperature in F button and update the string length */
				   ptr += 7;
				   pResponse->ResponseData.token_value.len += 7;
			   }
			   else
			   {
				   pal_Memcpy(ptr, " ", pal_Strlen(" "));
				   ptr += 1;
				   pResponse->ResponseData.token_value.len += 1;
			   }
			   *ptr = '\0';
		 }

        }
        break;

        case SL_NETAPP_HTTPPOSTTOKENVALUE_EVENT:
        {
            _u8 led = 0;
            _u8 *ptr = pEvent->EventData.httpPostData.token_name.data;

/* Check if the post command is for original CC310 demo  */
            if(pal_Memcmp(ptr, POST_token, pal_Strlen(POST_token)) == 0)
            {
                ptr = pEvent->EventData.httpPostData.token_value.data;
                if(pal_Memcmp(ptr, "LED", 3) != 0)
                    break;

                ptr += 3;
                led = *ptr;
                ptr += 2;
                if(led == '1')
                {
                    if(pal_Memcmp(ptr, "ON", 2) == 0)
                    {
                        turnLedOn(LED1);
                    }
                    else
                    {
                        turnLedOff(LED1);
                    }
                }
                else if(led == '2')
                {
                    if(pal_Memcmp(ptr, "ON", 2) == 0)
                    {
                        turnLedOn(LED2);
                    }
                    else
                    {
                        turnLedOff(LED2);
                    }
                }
            }

/* Check if the post command is for add MCU demo: LED on  */
			if(pal_Memcmp(ptr, POST_token0, pal_Strlen(POST_token0)) == 0)
			{
				g_ui32LED_Status =1;                           /* turn the LED on */
				turnLedOn(LED1);
				if(g_ui32LED_Toggle_Status)            /* reenable LED toggling */
				{
					IoSetTimer(g_ui32AnimSpeed);
				}
			}

/* Check if the post command is for add MCU demo: LED off  */
			else if(pal_Memcmp(ptr, POST_token1, pal_Strlen(POST_token1)) == 0)
			{
				g_ui32LED_Status =0;
				turnLedOff(LED1);
				if(g_ui32LED_Toggle_Status)
				{
					IoSetTimer(0);         /*reenable LED toggling */
				}
			}

/* Check if the post command is for add MCU demo: LED toggle on  */
			else if(pal_Memcmp(ptr, POST_token2, pal_Strlen(POST_token2)) == 0)
			{
				g_ui32LED_Toggle_Status = 1;
				if(g_ui32LED_Status)
				{
					IoSetTimer(g_ui32AnimSpeed);  /* enable LED toggling  */
				}
			}

/* Check if the post command is for add MCU demo: LED toggle off  */
			else if(pal_Memcmp(ptr, POST_token3, pal_Strlen(POST_token3)) == 0)
			{
				g_ui32LED_Toggle_Status = 0;
				IoSetTimer(0);               /* disable toggling */
				if(g_ui32LED_Status)
				{
					turnLedOn(LED1);
				}
				else
				{
					turnLedOff(LED1);
				}
			}

/* Check if the post command is for add MCU demo: set LED toggling speed  */
			else if(pal_Memcmp(ptr, POST_token4, pal_Strlen(POST_token4)) == 0)
			{
				ptr = pEvent->EventData.httpPostData.token_value.data;
				ulSpeed = String2Decimal(ptr);  /* get speed value from string */
				g_ui32AnimSpeed = ulSpeed;
				if (g_ui32LED_Toggle_Status && g_ui32LED_Status)
				{
					IoSetTimer(ulSpeed);
				}
			}

/* Check if the post command is for add MCU demo: Clear button 1 count  */
			else if(pal_Memcmp(ptr, POST_token5, pal_Strlen(POST_token5)) == 0)
			{
				g_ui32SW1Presses = 0;
			}

/* Check if the post command is for add MCU demo: Clear button 2 count  */
			else if(pal_Memcmp(ptr, POST_token6, pal_Strlen(POST_token6)) == 0)
			{
				g_ui32SW2Presses = 0;
			}

/* Check if the post command is for add MCU demo: temperature in C */
			else if(pal_Memcmp(ptr, POST_token8, pal_Strlen(POST_token8)) == 0)
			{
				g_ui32Temperature_U = 0;
			}

/* Check if the post command is for add MCU demo: temperature in F */
			else if(pal_Memcmp(ptr, POST_token9, pal_Strlen(POST_token9)) == 0)
			{
				g_ui32Temperature_U = 1;
			}

        }
        break;

        default:
        break;
    }
}
Esempio n. 15
0
void CC3000_UsynchCallback(long lEventType, char *data, unsigned char length)
{
	if (lEventType == HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE)
	{
		ulSmartConfigFinished = 1;
		ucStopSmartConfig     = 1;  
	}
	
	if (lEventType == HCI_EVNT_WLAN_UNSOL_CONNECT)
	{
		ulCC3000Connected = 1;

	}
	
	if (lEventType == HCI_EVNT_WLAN_UNSOL_DISCONNECT)
	{		
		ulCC3000Connected = 0;
		ulCC3000DHCP      = 0;
		ulCC3000DHCP_configured = 0;
		printOnce = 1;
		
		// Turn off the LED3 (Green)
		turnLedOff(3);  
		// Turn back on the LED 1 (RED) 
		turnLedOn(1);
		                              
	}
	
	if (lEventType == HCI_EVNT_WLAN_UNSOL_DHCP)
	{
		// Notes: 
		// 1) IP config parameters are received swapped
		// 2) IP config parameters are valid only if status is OK, i.e. ulCC3000DHCP becomes 1
		
		// only if status is OK, the flag is set to 1 and the addresses are valid
		if ( *(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0)
		{
			char *ccPtr;
			unsigned short ccLen;

			pucCC3000_Rx_Buffer[0] = 'I';
			pucCC3000_Rx_Buffer[1] = 'P';
			pucCC3000_Rx_Buffer[2] = ':';

			ccPtr = (char*)&pucCC3000_Rx_Buffer[3];

			ccLen = itoa(data[3], ccPtr);
			ccPtr += ccLen;
			*ccPtr++ = '.';
			ccLen = itoa(data[2], ccPtr);
			ccPtr += ccLen;
			*ccPtr++ = '.';
			ccLen = itoa(data[1], ccPtr);
			ccPtr += ccLen;
			*ccPtr++ = '.';
			ccLen = itoa(data[0], ccPtr);
			ccPtr += ccLen;
			*ccPtr++ = '\f';
			*ccPtr++ = '\r';
			*ccPtr++ = '\0';

			ulCC3000DHCP = 1;

			// Turn on the LED3 (Green)
			turnLedOn(3);  

		}
		else
			ulCC3000DHCP = 0;
		
	}
	
	if (lEventType == HCI_EVENT_CC3000_CAN_SHUT_DOWN)
	{
		OkToDoShutDown = 1;
	}
	
}
Esempio n. 16
0
void StartSmartConfig(void)
{

	// Reset all the previous configuration
	//
	wlan_ioctl_set_connection_policy(0, 0, 0);	
        wlan_ioctl_del_profile(255);
	
	//Wait until CC3000 is dissconected
	while (ulCC3000Connected == 1)
	{
	  __delay_cycles(100);
    }

	// Start blinking LED6 during Smart Configuration process
	turnLedOn(LED6);
	wlan_smart_config_set_prefix(aucCC3000_prefix);
	//wlan_first_time_config_set_prefix(aucCC3000_prefix);
	turnLedOff(LED6);
	
    // Start the SmartConfig start process
	wlan_smart_config_start(1);
    turnLedOn(LED6);
	
	//
	// Wait for Smart config finished
	// 
	while (ulSmartConfigFinished == 0)
	{
		__delay_cycles(6000000);
                                                                             
		turnLedOn(LED6);

		__delay_cycles(6000000);
                
		turnLedOff(LED6);
	}

	turnLedOff(LED6);

    // create new entry for AES encryption key
	nvmem_create_entry(NVMEM_AES128_KEY_FILEID,16);
	
	// write AES key to NVMEM
	aes_write_key((unsigned char *)(&smartconfigkey[0]));
	
	// Decrypt configuration information and add profile
	wlan_smart_config_process();
        
	//
	// Configure to connect automatically to the AP retrieved in the 
	// Smart config process
	//
	wlan_ioctl_set_connection_policy(0, 0, 1);
	
	//
	// reset the CC3000
	// 
	wlan_stop();
	__delay_cycles(600000);
	wlan_start(0);

	ConnectUsingSmartConfig = 1; 
        ulSmartConfigFinished = 0;
	//
	// Mask out all non-required events
	//
	wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|HCI_EVNT_WLAN_ASYNC_PING_REPORT);
}
Esempio n. 17
0
void StartSmartConfig(void)
{
	ulSmartConfigFinished = 0;
	ulCC3000Connected = 0;
	ulCC3000DHCP = 0;
	OkToDoShutDown=0;
	
	// Reset all the previous configuration
	wlan_ioctl_set_connection_policy(DISABLE, DISABLE, DISABLE);	
	wlan_ioctl_del_profile(255);
	
	//Wait until CC3000 is disconnected
	while (ulCC3000Connected == 1)
	{
		SysCtlDelay(100);
		hci_unsolicited_event_handler();
	}
	
	// Start blinking LED1 during Smart Configuration process
	turnLedOn(1);
	
	wlan_smart_config_set_prefix((char*)aucCC3000_prefix);
	turnLedOff(1);		
	
	// Start the SmartConfig start process
	wlan_smart_config_start(1);
	turnLedOn(1);       
	
	// Wait for Smart config to finish
	while (ulSmartConfigFinished == 0)
	{
		turnLedOff(1);
		SysCtlDelay(16500000);
		turnLedOn(1);		  
		SysCtlDelay(16500000);
	}
	turnLedOn(1);	
	// create new entry for AES encryption key
	nvmem_create_entry(NVMEM_AES128_KEY_FILEID,16);
	
	// write AES key to NVMEM
	aes_write_key((unsigned char *)(&smartconfigkey[0]));
	
	// Decrypt configuration information and add profile
	wlan_smart_config_process();
	
	// Configure to connect automatically to the AP retrieved in the 
	// Smart config process
	wlan_ioctl_set_connection_policy(DISABLE, DISABLE, ENABLE);
	
	
	// reset the CC3000
	wlan_stop();
	
	DispatcherUartSendPacket((unsigned char*)pucUARTCommandSmartConfigDoneString,
													 sizeof(pucUARTCommandSmartConfigDoneString));
	
	SysCtlDelay(100000);
	wlan_start(0);	
	
	// Mask out all non-required events
	wlan_set_event_mask(HCI_EVNT_WLAN_KEEPALIVE|HCI_EVNT_WLAN_UNSOL_INIT|
											HCI_EVNT_WLAN_ASYNC_PING_REPORT);
}
//*****************************************************************************
//	incomingPacketManager
//This function waits for an incoming message, and then extracts the
//value from the message. If the message is an config one, then it will assign
//the config info to a global variable. The function will return the next action
//to be taken.
// Packet Structure: <Command 1 Byte><Size of data 2 bytes><Missed Data 2 bytes><Data 2 bytes>
//*****************************************************************************
void incomingPacketManager(void){

	char requestBuffer[SERVER_RECV_BUF_SIZE] = {NULL};
	bytesRecvd = recv(clientDescriptor, requestBuffer, sizeof(requestBuffer), 0);

	switch(requestBuffer[0])
	{
	case Config:
		//RESET ADC and DMA:
		refresh_ADC();
		ADC_STATE = HALTED;
		//RESET DMA STATE.
		refresh_DMA();
		DMA_STATE = HALTED;

		//Extracts the required Data from config.
		confirmationPacket_ptr = &config_data;
		*confirmationPacket_ptr = requestBuffer[6];
		confirmationPacket_ptr++;
		*confirmationPacket_ptr = requestBuffer[5];

		generalConfirmationPacket[1] = 0;					//First Byte of Data Size
		generalConfirmationPacket[2] = 2;					//Second Byte of Data Size
		generalConfirmationPacket[3] = 0;					//First Byte of Data lost
		generalConfirmationPacket[4] = 0;					//Second Byte of Data Size
		confirmationPacket_ptr =  &ammount_packets_to_be_sent;
		generalConfirmationPacket[6] = *confirmationPacket_ptr;
		confirmationPacket_ptr++;
		generalConfirmationPacket[5] = *confirmationPacket_ptr;

		bytesSent = send(clientDescriptor, (unsigned char *)generalConfirmationPacket, sizeof(generalConfirmationPacket), 0);
		turnLedOff(CC3000_SENDING_DATA_IND);
		toggleLed(CC3000_SENDING_DATA_IND);
		__delay_cycles(100000);
		toggleLed(CC3000_SENDING_DATA_IND);
		if (bytesSent != sizeof(generalConfirmationPacket)){check_socket_connection();}
		deviceconfigured = FALSE;

		break;

	case Start:
		if(deviceconfigured == FALSE){
			configure_channel(&config_data);//This is where I configure the device to operate differently.
			deviceconfigured = TRUE;
		}

		if(DMA_STATE == HALTED){							//VIMP: The stop state must stop the DMA
			DMA0CTL += DMAEN;
			DMA_STATE = RUNNING;
			__delay_cycles(1000);
		}

		if(ADC_STATE == HALTED){
			ADC10CTL0 |= ADC10ENC + ADC10SC;
			ADC_STATE = RUNNING;							//VIMP: The stop state must stop the ADC
			__delay_cycles(100000);
		}


		for(i=0; i<ammount_packets_to_be_sent; i++){

			while(DMA0_State != DONE && DMA1_State != DONE); //Waits while buffers are populated

			//This checks which buffer is full, and toggles the operation.
			if(sendingBuffer_ptr == buffer0_ptr){		//Buffer0 is fill or done
				DMA0_State = NOT_DONE;					// Reset for next usage
				DMA1CTL += DMAEN;						// Start or enable DMA1 buffer filling process
			}
			else{										//Buffer1 is fill or done
				DMA1_State = NOT_DONE;					// Reset for next usage
				DMA0CTL += DMAEN;						// Start or enable DMA0 buffer filling process
			}
			//*********************************************************************************************
			//This is a pointer manipulation method to include the missed ADC cycles into the packet header.
			sendingBuffer_ptr +=4;
			temp_ptr = &missed_samples;
			*sendingBuffer_ptr = *temp_ptr;
			temp_ptr++;
			sendingBuffer_ptr--;
			*sendingBuffer_ptr = *temp_ptr;
			sendingBuffer_ptr -=3;
			missed_samples = 0;
			//*********************************************************************************************

			if(currentCC3000State() & CC3000_CLIENT_CONNECTED){
				bytesSent = send(clientDescriptor, sendingBuffer_ptr, ammount_of_samples_in_packet+packet_header_size, 0);
				toggleLed(CC3000_SENDING_DATA_IND);
				if (bytesSent != ammount_of_samples_in_packet+packet_header_size){
					check_socket_connection();

				}
			}
			if (clientDescriptor == -1){break;}

		}
		break;

	case Stop:
		//RESET ADC:
		refresh_ADC();
		ADC_STATE = HALTED;
		//RESET DMA.
		refresh_DMA();
		DMA_STATE = HALTED;

		// The confirmation packet being sent back contains no relevant information.
		generalConfirmationPacket[1] = 0;					//First Byte of Data Size
		generalConfirmationPacket[2] = 2;					//Second Byte of Data Size
		generalConfirmationPacket[3] = 0;					//First Byte of Data lost
		generalConfirmationPacket[4] = 0;					//Second Byte of Data Size
		generalConfirmationPacket[5] = 0;
		generalConfirmationPacket[6] = 0;

		bytesSent = send(clientDescriptor, (unsigned char *)generalConfirmationPacket, sizeof(generalConfirmationPacket), 0);
		turnLedOff(CC3000_SENDING_DATA_IND);
		toggleLed(CC3000_SENDING_DATA_IND);
		__delay_cycles(100000);
		toggleLed(CC3000_SENDING_DATA_IND);
		if (bytesSent != sizeof(generalConfirmationPacket)){check_socket_connection();}

		break;
	default:
		break;

	}

}