Damien Frost / WiflyInterface

Dependents:   IoT_Ex BatteryModelTester BatteryModelTester

Fork of WiflyInterface by Components

Files at this revision

API Documentation at this revision

Comitter:
defrost
Date:
Fri Aug 05 13:31:37 2016 +0000
Parent:
34:a22a6343e3d4
Child:
36:8774837f5a78
Commit message:
- Added baudrate variable to Wifly so that after a reset, the baud rate is updated to the previously baud rate; - Debug messages on

Changed in this revision

Wifly/Wifly.cpp Show annotated file Show diff for this revision Revisions of this file
Wifly/Wifly.h Show annotated file Show diff for this revision Revisions of this file
WiflyInterface.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Wifly/Wifly.cpp	Sun Jul 10 11:13:33 2016 +0000
+++ b/Wifly/Wifly.cpp	Fri Aug 05 13:31:37 2016 +0000
@@ -21,7 +21,7 @@
 #include <string>
 #include <algorithm>
 
-//#define DEBUG
+#define DEBUG
 #define INFOMESSAGES
 #define WARNMESSAGES
 #define ERRMESSAGES
@@ -35,6 +35,9 @@
 Wifly::Wifly(   PinName tx, PinName rx, PinName _reset, PinName tcp_status, const char * ssid, const char * phrase, Security sec):
     wifi(tx, rx), reset_pin(_reset), tcp_status(tcp_status), buf_wifly(1024)
 {
+    // Set the default baud rate:
+    serial_baudrate = 9600;
+    
     memset(&state, 0, sizeof(state));
     state.sec = sec;
 
@@ -53,21 +56,25 @@
     inst = this;
     attach_rx(false);
     state.cmd_mode = false;
+    DBG("Wifly Constructed");
 }
 
-
 void Wifly::setBaud(int baudrate)
 {
     char cmd[28];
+    // Save the baudrate:
+    if(baudrate > 0){
+        serial_baudrate = baudrate;
+    }
     // This sets the baud rate 'instantly'
-    sprintf(cmd, "set u i %d\r", baudrate);
+    sprintf(cmd, "set u i %d\r", serial_baudrate);
     // This one sets it some other way that does not work
     //sprintf(cmd, "set u b %d\r", baudrate);
     // Set baud rate of wifly:
     sendCommand(cmd, NULL);
     wait(0.5);
     // Set baud rate of UART:
-    wifi.baud(baudrate);
+    wifi.baud(serial_baudrate);
     wait(0.5);
     exit();
 }
@@ -371,9 +378,12 @@
 void Wifly::reset()
 {
     reset_pin = 0;
-    wait(0.2);
+    wait(0.5);
     reset_pin = 1;
-    wait(0.2);
+    wait(0.5);
+    DBG("Wifi Shield Reset");
+    setBaud(-1);
+    DBG("Baud Rate updated from Reset.");
 }
 
 bool Wifly::reboot()
--- a/Wifly/Wifly.h	Sun Jul 10 11:13:33 2016 +0000
+++ b/Wifly/Wifly.h	Fri Aug 05 13:31:37 2016 +0000
@@ -250,6 +250,8 @@
 
     void attach_rx(bool null);
     void handler_rx(void);
+    
+    int serial_baudrate;
 
 
     typedef struct STATE {
--- a/WiflyInterface.cpp	Sun Jul 10 11:13:33 2016 +0000
+++ b/WiflyInterface.cpp	Fri Aug 05 13:31:37 2016 +0000
@@ -1,6 +1,6 @@
 #include "WiflyInterface.h"
 
-//#define DEBUG
+#define DEBUG
 #define INFOMESSAGES
 #define WARNMESSAGES
 #define ERRMESSAGES
@@ -13,6 +13,7 @@
     Wifly(tx, rx, reset, tcp_status, ssid, phrase, sec)
 {
     ip_set = false;
+    DBG("WiflyInterface Constructed");
 }
 
 int WiflyInterface::init()