this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Files at this revision

API Documentation at this revision

Comitter:
ocomeni
Date:
Sat Jun 15 15:52:26 2019 +0000
Branch:
PassingRegression
Parent:
123:a49e9ffbaca6
Child:
125:d2830421006c
Commit message:
new features now tested.

Changed in this revision

source/ATCmdManager.cpp Show annotated file Show diff for this revision Revisions of this file
source/BleManager.cpp Show annotated file Show diff for this revision Revisions of this file
source/WiFiManager.cpp Show annotated file Show diff for this revision Revisions of this file
source/WiFiManager.h Show annotated file Show diff for this revision Revisions of this file
source/common_config.h Show annotated file Show diff for this revision Revisions of this file
source/main-https.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/source/ATCmdManager.cpp	Fri Jun 14 21:13:46 2019 +0000
+++ b/source/ATCmdManager.cpp	Sat Jun 15 15:52:26 2019 +0000
@@ -145,6 +145,7 @@
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_CONNECT_RESP:  
+            case WIFI_RECONNECT_INFO:  
             {
                 // AT_CONNECT_RESP response state 
                 dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\r\n");
@@ -163,6 +164,10 @@
                 dbg_printf(LOG, "\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\r\n");
                 respStr = (char *) resp_data->buffer;
                 sendAtConfirmationFreeMpool(respStr);
+                char * urc = new char[20];
+                sprintf(urc, "\r\n%s:%d\r\n", NETWORK_DOWN_URC, WIFI_INTERFACE_ID);
+                sendAtEvent(urc);
+                delete urc;
                 at_resp = AT_RESP_NONE;
                 break;
             case AT_CONFIG_RESP:  
@@ -776,7 +781,7 @@
 {
 #ifdef MBED_MAJOR_VERSION
     char * fw_ver_str = new char[40];
-    sprintf(fw_ver_str, "API version:%d.%d.%d.%d.%d.%d\n\n", MBED_MAJOR_VERSION 
+    sprintf(fw_ver_str, "API version:%d.%d.%d.%d.%d.%dOK\r\n", MBED_MAJOR_VERSION 
                                                            , MBED_MINOR_VERSION 
                                                            , MBED_PATCH_VERSION
                                                            , API_MAJOR_VERSION
--- a/source/BleManager.cpp	Fri Jun 14 21:13:46 2019 +0000
+++ b/source/BleManager.cpp	Sat Jun 15 15:52:26 2019 +0000
@@ -640,7 +640,7 @@
         _ble.gap().getAddress(&addr_type, addr);
         //dbg_printf(LOG, "Device address: %02x:%02x:%02x:%02x:%02x:%02x\r\n",
         //       addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
-        sprintf(respStr, "\r\n%s%d,%02X%02X%02X%02X%02X%02X\r\n", LOCAL_ADDRESS_RESP
+        sprintf(respStr, "\r\n%s%d,%02X%02X%02X%02X%02X%02XOK\r\n", LOCAL_ADDRESS_RESP
                                                                 , BLE_IF_ID
                                                                 , addr[5]
                                                                 , addr[4]
@@ -660,7 +660,7 @@
         _aT2BleDatamPool->free(data_msg);
         at_data_resp = new ble_at_msg_t;
         char * respStr = (char *)at_data_resp->buffer;
-        sprintf(respStr, "\r\n%s%s\r\n", BLE_DEVICE_NAME_RESP, ble_config->deviceName);
+        sprintf(respStr, "\r\n%s%sOK\r\n", BLE_DEVICE_NAME_RESP, ble_config->deviceName);
         at_data_resp->dataLen = strlen(respStr); // get bytes total
         sendATresponseBytes(AT_BLE_NAME_RESP);
         bleCmd = BLE_CMD_NONE;
--- a/source/WiFiManager.cpp	Fri Jun 14 21:13:46 2019 +0000
+++ b/source/WiFiManager.cpp	Sat Jun 15 15:52:26 2019 +0000
@@ -58,6 +58,9 @@
 WiFiManager::~WiFiManager()
 {
     delete network;
+    wifiWatchdogTimer.stop();
+    socket->close();
+    delete socket;
 }
 //#define DISABLE_WATCHDOG
 
@@ -262,6 +265,11 @@
             }
             case WIFI_CMD_CONNECT:
             {
+                if(is_connected) // already connected
+                {
+                    wifiCmd = WIFI_CMD_NONE;
+                    break;
+                }
                 wifiBusy = 1;
                 error = connect();
                 int secCount = 0;
@@ -287,12 +295,42 @@
                 break;
             }
             case WIFI_CMD_DISCONNECT:
+            {
+                if(!is_connected) // already disconnected
+                {
+                    wifiCmd = WIFI_CMD_NONE;
+                    break;
+                }
                 wifiBusy = 1;
                 error = disconnect();
                 wifiCmd = WIFI_CMD_NONE;
-                queueATresponse(AT_DISCONNECT_RESP);
+                if(error >= 0)
+                {
+                    int secCount = 0;
+                    while(secCount++ < WIFI_CONNECT_TIMEOUT_SECS && is_connected==true){
+                        wait(1); // wait 1 sec
+                    }
+                    if(!is_connected)
+                    {
+                        sendATresponseString(AT_DISCONNECT_RESP);
+                    }
+                    else
+                    {
+                        dbg_printf(LOG, "[WIFI MAN] +++ WIFI DISCONNECTION TIMEOUT +++ \r\n");
+                        //queueATresponse(AT_COMMAND_FAILED);
+                        responseString = (char *) malloc(100);
+                        sprintf(responseString, "\r\n+UUTIMEOUT\r\n");
+                        sendATresponseString(AT_COMMAND_FAILED);
+                    }
+                    // attempt reconnection if always connected scheme is set
+                    if(internet_config->connectionScheme == ALWAYS_CONNECTED)
+                    {
+                        setNextCommand(WIFI_CMD_CONNECT);
+                    }
+                }
                 wifiBusy = 0;
                 break;
+            }
             case WIFI_CMD_CONFIG:
                 wifiBusy = 1;
                 set_WIFI_CONFIG();
@@ -815,10 +853,14 @@
 
 void WiFiManager::getWiFiMACaddress()
 {
+    char * mp = new char[20];
+    sscanf(network->get_mac_address(),"%02s:%2s:%2s:%2s:%2s:%2s",&mp[0],&mp[2],&mp[4],&mp[6],&mp[8],&mp[10]);
     responseString = (char *) malloc(100);
-    sprintf(responseString, "\r\n%s%d,%s\r\n", LOCAL_ADDRESS_RESP, 
-                                           WIFI_IF_ID,
-                                           network->get_mac_address());
+    
+    sprintf(responseString, "\r\n%s%d,%sOK\r\n", LOCAL_ADDRESS_RESP, 
+                                                 WIFI_IF_ID,
+                                                 mp);
+    delete mp;
 }
 
 
@@ -898,22 +940,21 @@
                                                               network->get_mac_address(),
                                                               DEFAULT_WIFI_CHANNEL);
                 
+                wifiBusy = 0;
                 is_connected = true;
-                wifiBusy = 0;
             }
             break;
         case NSAPI_STATUS_DISCONNECTED:
             dbg_printf(LOG, "No connection to network!\r\n");
             dbg_printf(LOG, "\n [WIFI-MAN] No connection to network!\n");
-            is_connected = false;
-            // attempt reconnection if always connected scheme is set
-            if(internet_config->connectionScheme == ALWAYS_CONNECTED)
+            if(outputBuffersAvailable())
             {
-                wifiBusy = 1;
-                nsapi_error_t error;
-                error = connect();
-                queueATresponse(WIFI_RECONNECT_INFO);
+                responseString = (char *) malloc(100);
+                sprintf(responseString, "\r\n%s%d,5\r\n", WIFI_LINK_DISABLED, WIFI_CHANNEL);
+                //sendATresponseString(AT_EVENT);
             }
+            wifiBusy = 0;
+            is_connected = false;
             break;
         case NSAPI_STATUS_CONNECTING:
             dbg_printf(LOG, "Connecting to network!\r\n");
@@ -1043,6 +1084,12 @@
 {
     nsapi_error_t error;
     error = network->disconnect();
+    if(error < 0)
+    {
+        responseString = (char *) malloc(100); 
+        sprintf(responseString, "%s", UDDRP_ERROR);
+        sendATresponseString(AT_EVENT);
+    }
     return error;
 }
 
--- a/source/WiFiManager.h	Fri Jun 14 21:13:46 2019 +0000
+++ b/source/WiFiManager.h	Sat Jun 15 15:52:26 2019 +0000
@@ -81,20 +81,20 @@
     int         chunkNum;
     /*  Queue and memory pool for AT to Wifi commands */
     MemoryPool<wifi_cmd_message_t, 16> *_aT2WiFimPool;
-    Queue<wifi_cmd_message_t, 16> *_aT2WiFiCmdQueue;
+    Queue<wifi_cmd_message_t, 16>      *_aT2WiFiCmdQueue;
     
     /*  Queue and memory pool for WiFi to AT commands */
     MemoryPool<at_resp_message_t, 16> *_wiFi2ATmPool;
-    Queue<at_resp_message_t, 16> *_wiFi2ATCmdQueue;
+    Queue<at_resp_message_t, 16>      *_wiFi2ATCmdQueue;
     
     /*  Queue and memory pool for AT to WiFi data */
     MemoryPool<wifi_data_msg_t, PQDSZ> *_aT2WiFiDatamPool;
-    Queue<wifi_data_msg_t, PQDSZ> *_aT2WiFiDataQueue;
+    Queue<wifi_data_msg_t, PQDSZ>      *_aT2WiFiDataQueue;
     wifi_data_msg_t *data_msg;
     
     /*  Queue and memory pool for WiFi to AT data */
     MemoryPool<at_data_msg_t, PQDSZ> *_wiFi2ATDatamPool;
-    Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue;
+    Queue<at_data_msg_t, PQDSZ>      *_wiFi2ATDataQueue;
 
     bool is_connected;
     bool http_response_hdr_sent;
--- a/source/common_config.h	Fri Jun 14 21:13:46 2019 +0000
+++ b/source/common_config.h	Sat Jun 15 15:52:26 2019 +0000
@@ -19,8 +19,11 @@
 #define DEFAULT_WIFI_CHANNEL      0
 #define DEFAULT_BTLE_CHANNEL      1
 #define WIFI_LINK_ENABLED         "+UUWLE:"
+#define WIFI_LINK_DISABLED        "+UUWLD:"
 #define NETWORK_UP_URC            "+UUNU"
+#define NETWORK_DOWN_URC          "+UUND"
 #define PEER_CONNECTED_URC        "+UUDPC:"
+#define PEER_DISCONNECTED_URC     "+UUDPD:"
 #define NETWORK_STATUS            "+UNSTAT:"
 #define WIFI_NETWORK_STATUS       "+UWSSTAT:"
 #define UDDRP_ERROR               "\r\nERROR\r\n"
--- a/source/main-https.cpp	Fri Jun 14 21:13:46 2019 +0000
+++ b/source/main-https.cpp	Sat Jun 15 15:52:26 2019 +0000
@@ -346,6 +346,7 @@
 
 void stop_BLE()
 {
+    btle_thread.terminate();
     delete peripheral;
     ble_mgr_started = false;
     wait_ms(10);
@@ -374,6 +375,9 @@
 
 void stop_WiFi()
 {
+    wifi_evt_thread.terminate();
+    wifi_thread.terminate();
+    delete wiFiManager;
     delete network;
     wifi_mgr_started = false;
 }