//*****************************************************************************
//
//!  \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
                UCA1IE &= ~UCRXIE;
                
                validPos += strlen("assoc");
                while(uartRXByte(validPos) < 'A' && validPos <= bytesInUart())
                    validPos++;
                
                *ptrSSIDInd = FLASH_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, (unsigned char *)ptrPASSPHRASE, (long)ptrSECURITY); //ConnectUsingSSID((char *)ptrSSID, (unsigned char *)ptrPASSPHRASE, (unsigned long)ptrSECURITY);
                }
                UCA1IE |= 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;
        
    }
}
Beispiel #2
0
//*****************************************************************************
//
//!  checkWiFiConnected
//!
//!  \param  None
//!
//!  \return TRUE if connected, FALSE if not
//!
//!  \brief  Checks to see that WiFi is still connected.  If not associated
//!          with an AP for 5 consecutive retries, it will reset the board.
//
//*****************************************************************************
unsigned char
checkWiFiConnected(void)
{
  unsigned char ipInfoFlagSet = 0;

  if(!(currentCC3000State() & CC3000_ASSOC)) //try to associate with an Access Point
  {
    //
    // Check whether Smart Config was run previously. If it was, we
    // use it to connect to an access point. Otherwise, we connect to the
    // default.
    //

    if((isFTCSet() == 0)&&(ConnectUsingSmartConfig==0)&&(*SmartConfigProfilestored != SMART_CONFIG_SET))
    {
      // Smart Config not set, check whether we have an SSID
      // from the assoc terminal command. If not, use fixed SSID.
        //sendString("== ConnectUsingSSID==\r\n");
        ConnectUsingSSID(SSID);
    }
    unsolicicted_events_timer_init();
    // Wait until connection is finished
    //sendString("== Wait until connection is finished==\r\n");
    while (!(currentCC3000State() & CC3000_ASSOC))
    {
      WDTCTL = WDT_ARST_1000;
      __delay_cycles(100);

      // Handle any un-solicited event if required - the function will get triggered
      // few times in a second
      hci_unsolicited_event_handler();

      // Check if user pressed button to do Smart Config
      if(runSmartConfig == 1)
          break;
    }
  }

  // Handle un-solicited events - will be triggered few times per second
  hci_unsolicited_event_handler();
  WDTCTL = WDTPW + WDTHOLD;
  // Check if we are in a connected state.  If so, set flags and LED
  if(currentCC3000State() & CC3000_IP_ALLOC)
  {
    unsolicicted_events_timer_disable(); // Turn our timer off since isr-driven routines set LEDs too...

    if (obtainIpInfoFlag == FALSE)
    {
      //sendString("== CC3000_IP_ALLOC_IND==\r\n");
      obtainIpInfoFlag = TRUE;             // Set flag so we don't constantly turn the LED on
      turnLedOn(CC3000_IP_ALLOC_IND);
      ipInfoFlagSet = 1;
      unsolicicted_events_timer_init();
    }

    if (obtainIpInfoFlag == TRUE)
    {
    	WDTCTL = WDT_ARST_1000;
      //If Smart Config was performed, we need to send complete notification to the configure (Smart Phone App)
      if (ConnectUsingSmartConfig==1)
      {
        mdnsAdvertiser(1,DevServname, sizeof(DevServname));
        ConnectUsingSmartConfig = 0;
        *SmartConfigProfilestored = SMART_CONFIG_SET;
      }
      //Start mDNS timer in order to send mDNS Advertisement every 30 seconds
      mDNS_packet_trigger_timer_enable();

      unsolicicted_events_timer_init();
    }
    WDTCTL = WDTPW + WDTHOLD;
    if( ipInfoFlagSet == 1)
    {
      // Initialize an Exosite connection
      //sendString("== Exosite Activate ==\r\n");
      cloud_status = Exosite_Activate();
      ipInfoFlagSet = 0;
    }

    return TRUE;
  }

  return FALSE;

}