Example #1
0
boolean WiFlyDevice::waitForPrompt()
{
	if (!waitForResponse("<", 5000))
		return false;
	
	return findInResponse(" ", 2000);
}
Example #2
0
boolean WiFlyDevice::softwareReboot(boolean isAfterBoot = true) {
  /*

   */

  DEBUG_LOG(1, "Entered softwareReboot");

  for (int retryCount = 0;
       retryCount < SOFTWARE_REBOOT_RETRY_ATTEMPTS;
       retryCount++) {

    // TODO: Have the post-boot delay here rather than in enterCommandMode()?

    if (!enterCommandMode(isAfterBoot)) {
      return false; // If the included retries have failed we give up
    }

    uart->println(F("reboot"));

    // For some reason the full "*Reboot*" message doesn't always
    // seem to be received so we look for the later "*READY*" message instead.

    // TODO: Extract information from boot? e.g. version and MAC address

    if (findInResponse("*READY*", 2000)) {
      return true;
    }
  }

  return false;
}
Example #3
0
int8 setCommand(char* command)
{
    Uart_flush(wiflyUart);          // Empty buffers
    Uart_printf(wiflyUart, command);  // Send command
    Timer_delayMs(WIFLY_COMMAND_SETTLE_TIME);
    return findInResponse(WIFLY_SET_OK, WIFLY_RESPONSE_TIMEOUT);
}
Example #4
0
int8 WiFly_actionEnterCommandMode(uint8 isAfterReboot)
{
    uint8 retryCount;
    
    for (retryCount = 0; 
         retryCount < WIFLY_COMMAND_MODE_ENTER_RETRY_ATTEMPTS; 
         retryCount++)
    {
        if (isAfterReboot == 1)
        {
            Timer_delayMs(1000);  // This delay is so characters aren't missed after a reboot.
        }
        
        Timer_delayMs(WIFLY_COMMAND_MODE_GUARD_TIME);
    
        Uart_flush(wiflyUart);
        Uart_printf(wiflyUart, "%c%c%c",commChar,commChar,commChar);  // Print the command chars
        
        Timer_delayMs(WIFLY_COMMAND_MODE_GUARD_TIME);
        
        Uart_printf(wiflyUart, "\r\r");                               // Print 2 carriage return to make shure it has entered command mode

        // This is used to determine whether command mode has been entered
        // successfully.
        Uart_printf(wiflyUart, "ver\r");
        
        if (findInResponse("WiFly Ver ", 1000) == 0)
        {
            return findWiFlyVersion(1000);
        }
    }
    
    return -1;
}
/**
* @brief Get the version of the WiFly firmware
* @return Char with the version info
*/
const char* WiFlyDevice::getVersion()
{
  const int versionLength=64;
  // Allocate one extra space for the zero terminator.
  static char version[versionLength+1] = { 0 };

  enterCommandMode();
  sendCommand("ver", false, VER_RESPONSE);

  int offset = 0;
  int readVal = 0;
  while (offset < versionLength && readVal!='\n') {
    readVal = uart->read();
    if (readVal == -1) {
      // Data not available; try again after brief delay.
      delay(1);
      continue;
    }
    else {
      version[offset++] = readVal;
    }
  }

  waitForResponse("<"); // This char appears in the beginning of the prompt
  findInResponse(" ");  // And with this we ignore the rest of the prompt
  exitCommandMode();

  return version;
}
Example #6
0
int8 WiFly_actionReboot()
{
    uint8 retryCount;
    
    for (retryCount = 0; retryCount < WIFLY_SOFTWARE_REBOOT_RETRY_ATTEMPTS; retryCount++)
    {
        if (WiFly_actionEnterCommandMode(1) == -1)
        {
            return -1;  // If the included retries have failed we give up
        }
        
        Uart_printf(wiflyUart, "reboot\r");
            
        // For some reason the full "*Reboot*" message doesn't always
        // seem to be received so we look for the later "*READY*" message instead.
    
        if (findInResponse("*READY*", 2000))
        {
            wiFlyState = WiFly_State_Disconnected;    // Now it also should be disconnected
            return 0;
        }
    }
    
    return -1;
}
Example #7
0
boolean WiFlyDevice::sendCommand(const char *command,
                                 boolean isMultipartCommand = false,
                                 const char *expectedResponse = "AOK") {
  /*
   */
  DEBUG_LOG(1, "Entered sendCommand");
  DEBUG_LOG(2, "Command:");
  DEBUG_LOG(2, command);
  uart->print(command);
  delay(20);
  if (!isMultipartCommand) {
    uart->flush();
    uart->println();

    // TODO: Handle other responses
    //       (e.g. autoconnect message before it's turned off,
    //        DHCP messages, and/or ERR etc)
    if (!findInResponse(expectedResponse, 1000)) {
      return false;
    }
    //waitForResponse(expectedResponse);
  }
  DEBUG_LOG(2, "sendCommand exit True");

  return true;
}
Example #8
0
boolean WiFlyDevice::configure(byte option, unsigned long value) {
  /*
   */

  // TODO: Allow options to be supplied earlier?

  switch (option) {
    case WIFLY_BAUD:
      // TODO: Use more of standard command sending method?
      enterCommandMode();
      uart->print("set uart instant ");
      uart->println(value);
      delay(10); // If we don't have this here when we specify the
                 // baud as a number rather than a string it seems to
                 // fail. TODO: Find out why.
      SPIuart.begin(value);
      // For some reason the following check fails if it occurs before
      // the change of SPI UART serial rate above--even though the
      // documentation says the AOK is returned at the old baud
      // rate. TODO: Find out why
      if (!findInResponse("AOK", 100)) {
        return false;
      }
      break;
    default:
      return false;
      break;
  }
  return true;
}
Example #9
0
void WiFlyDevice::waitForResponse(const char *toMatch) {
  /*
   */
   // Note: Never exits if the correct response is never found
   findInResponse(toMatch);
 
}
Example #10
0
boolean WiFlyDevice::hardwareReboot() {
  /*
   */
  uart.ioSetDirection(0b00000010);
  uart.ioSetState(0b00000000);
  delay(1);
  uart.ioSetState(0b00000010);

  return findInResponse("*READY*", 2000);
}
Example #11
0
boolean WiFlyDevice::hardwareReboot() {
  /*
   */
  if (!bDifferentUart)
  {
    SPIuart.ioSetDirection(0b00000010);
    SPIuart.ioSetState(0b00000000);
    delay(1);
    SPIuart.ioSetState(0b00000010);
    return findInResponse("*READY*", 2000);
  }
  return softwareReboot();
}
Example #12
0
int8 WiFly_actionExitCommandMode()
{
    Uart_flush(wiflyUart);
    Uart_printf(wiflyUart, "exit\r");
    Timer_delayMs(WIFLY_COMMAND_SETTLE_TIME);
    
    if (findInResponse("EXIT", 1000) == 0)
    { 
        return 0;
    }

    return -1;
}
Example #13
0
void WiFlyDevice::reboot()
{
	#if USE_HARDWARE_RESET
		uart.ioSetDirection(0b00000010);
		uart.ioSetState(0b00000000);
		delay(10);
		uart.ioSetState(0b00000010);

		findInResponse("*READY*", 10000);
	#else
		while (true)
		{
			if (!enterCommandMode())
				continue;

			sendCommand("reboot", "");
			if (findInResponse("*READY*", 5000))
				break;
		}
	#endif

	delay(1000);
}
Example #14
0
long WiFlyDevice::getTime(){

	/*
	Returns the time based on the NTP settings and time zone.
	*/

	char newChar;
	byte offset = 0;
	char buffer[TIME_SIZE+1];

	enterCommandMode();

	//sendCommand("time"); // force update if it's not already updated with NTP server
	sendCommand(F("show t t"), false, "RTC=");

	// copy the time from the response into our buffer
	while (offset < TIME_SIZE) {
			newChar = uart->read();

			if (newChar != -1) {
				buffer[offset++] = newChar;
			}
	}
	buffer[offset]=0;
  // This should skip the remainder of the output.
  // TODO: Handle this better?
  waitForResponse("<");
  findInResponse(" ");

  // For some reason the "sendCommand" approach leaves the system
  // in a state where it misses the first/next connection so for
  // now we don't check the response.
  // TODO: Fix this
  uart->println(F("exit"));
  //sendCommand(F("exit"), false, "EXIT");


  return strtol(buffer, NULL, 0);
}
Example #15
0
void WiFlySerial::reboot() {
    char szCommand[SMALL_COMMAND_BUFFER_SIZE];
    
    DEBUG_LOG(1, "Entered softwareReboot");
    
	for (int retryCount = 0;
         retryCount < SOFTWARE_REBOOT_RETRY_ATTEMPTS;
         retryCount++) {
        
        // TODO: Have the post-boot delay here rather than in enterCommandMode()?
        
        if (!enterCommandMode(isAfterBoot)) {
            return false; // If the included retries have failed we give up
        }
        
        uart->println("reboot");
        
        // For some reason the full "*Reboot*" message doesn't always
        // seem to be received so we look for the later "*READY*" message instead.
        
        // TODO: Extract information from boot? e.g. version and MAC address
        
        if (findInResponse("*READY*", 2000)) {
            return true;
        }
    }
    
    return false;
    
    GetBuffer_P(STI_WIFLYDEVICE_REBOOT, szCommand, SMALL_COMMAND_BUFFER_SIZE);
    // DebugPrint(szCommand);
    
    if (!SendCommandSimple( szCommand ,   WiFlyFixedPrompts[WIFLY_MSG_AOK] )) {
        DebugPrint( GetBuffer_P(STI_WIFLYDEVICE_ERR_START_FAIL, szCommand, SMALL_COMMAND_BUFFER_SIZE));
        while (1) {}; // Hang. TODO: Handle differently?
    }
}
Example #16
0
int8 getCommand(char* command)
{
    Uart_flush(wiflyUart);          // Empty buffers
    Uart_printf(wiflyUart, command);  // Send command
    return findInResponse(wiFlyVersion, WIFLY_RESPONSE_TIMEOUT);
}
Example #17
0
void WiFlyDevice::skipRemainderOfResponse()
{
	findInResponse("\n", 2000);
}
Example #18
0
int8 otherCommand(char* command, char* awaitedResponse)
{
    Uart_flush(wiflyUart);          // Empty buffers
    Uart_printf(wiflyUart, command);  // Send command
    return findInResponse(awaitedResponse, WIFLY_RESPONSE_TIMEOUT);
}
Example #19
0
boolean WiFlyDevice::enterCommandMode(boolean isAfterBoot) {
  /*

   */

  DEBUG_LOG(1, "Entered enterCommandMode");

  // Note: We used to first try to exit command mode in case we were
  //       already in it. Doing this actually seems to be less
  //       reliable so instead we now just ignore the errors from
  //       sending the "$$$" in command mode.

  for (int retryCount = 0;
       retryCount < COMMAND_MODE_ENTER_RETRY_ATTEMPTS;
       retryCount++) {

    // At first I tried automatically performing the
    // wait-send-wait-send-send process twice before checking if it
    // succeeded. But I removed the automatic retransmission even
    // though it makes things  marginally less reliable because it speeds
    // up the (hopefully) more common case of it working after one
    // transmission. We also now have automatic-retries for the whole
    // process now so it's less important anyway.

    if (isAfterBoot) {
      delay(1000); // This delay is so characters aren't missed after a reboot.
    }

    delay(COMMAND_MODE_GUARD_TIME);

    uart->print(F("$$$"));

    delay(COMMAND_MODE_GUARD_TIME);

    // We could already be in command mode or not.
    // We could also have a half entered command.
    // If we have a half entered command the "$$$" we've just added
    // could succeed or it could trigger an error--there's a small
    // chance it could also screw something up (by being a valid
    // argument) but hopefully it's not a general issue.  Sending
    // these two newlines is intended to clear any partial commands if
    // we're in command mode and in either case trigger the display of
    // the version prompt (not that we actually check for it at the moment
    // (anymore)).

    // TODO: Determine if we need less boilerplate here.

    uart->println();
    uart->println();

    // TODO: Add flush with timeout here?

    // This is used to determine whether command mode has been entered
    // successfully.
    // TODO: Find alternate approach or only use this method after a (re)boot?
    uart->println(F("ver"));

    if (findInResponse("WiFly Ver", 1000)) {
      // TODO: Flush or leave remainder of output?
      return true;
    }
  }
  return false;
}