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:
Wed May 08 19:38:35 2019 +0000
Branch:
PassingRegression
Parent:
108:3c8fb2c6e7bf
Child:
110:c722dda4f2ff
Commit message:
1. updated HTTP packet state to monitor for multiple packets; 2. fixed bug causing crash (was canceling an active task on event queue); 2. updates to watchdog. added ticker.;

Changed in this revision

source/ATCmdManager.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	Mon May 06 20:18:02 2019 +0000
+++ b/source/ATCmdManager.cpp	Wed May 08 19:38:35 2019 +0000
@@ -593,7 +593,9 @@
                             //sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
                             if(createHttpRequest() == false)
                             {
+#ifdef SEND_DEBUG_MESSAGES
                                 sendAtConfirmation(WIFI_BUSY_RESP);
+#endif
                             }
                             free(rx_buf_ptr);
                             rx_buf_ptr = NULL;
@@ -1236,20 +1238,24 @@
 bool  ATCmdManager::queueWiFiDataRequest(wifi_data_msg_t data_req){
     static bool memFull = false;
     //print_memory_info();
-    _event_queue.call_in(10, &print_heap_and_isr_stack_info);
+    //_event_queue.call_in(10, &print_heap_and_isr_stack_info);
     //print_heap_and_isr_stack_info();
     wifi_data_msg_t *wifiData = _aT2WiFiDatamPool->alloc();
     if(wifiData == NULL)
     {
         //_parser.send("\r\nQUEUE MEMORY FULL\r\n");
+#ifdef SEND_DEBUG_MESSAGES
         sendAtConfirmation("\r\nQUEUE MEMORY FULL\r\n");
+#endif
         memFull = true;
         return false;
     }
     if(memFull)
     {
         memFull = false;
+#ifdef SEND_DEBUG_MESSAGES
         sendAtConfirmation("\r\n[ATCMD-MAN] memory released...\r\n");
+#endif
     }
     wifiData->wifi_cmd        = data_req.wifi_cmd;
     wifiData->dataLen        = data_req.dataLen;
--- a/source/WiFiManager.cpp	Mon May 06 20:18:02 2019 +0000
+++ b/source/WiFiManager.cpp	Wed May 08 19:38:35 2019 +0000
@@ -42,13 +42,19 @@
     wifiBusy = 0;
     wifiWatchdogTimer.start();
     watchdogCnt = 0;
-    _event_queue.call_every(10000, this, &WiFiManager::callWifiWatchDog);
+    //_event_queue.call_every(10000, this, &WiFiManager::callWifiWatchDog);
+    watchDogTick.attach(this, &WiFiManager::callWifiWatchDogIsr, 10000.0); // call flip function every 2 seconds
 }
 
 WiFiManager::~WiFiManager()
 {
 }
 //#define DISABLE_WATCHDOG
+
+void WiFiManager::callWifiWatchDogIsr()
+{
+    _event_queue.call(this, &WiFiManager::callWifiWatchDog);    
+}
 void WiFiManager::callWifiWatchDog()
 {
 #ifdef DISABLE_WATCHDOG
@@ -208,12 +214,14 @@
             case WIFI_CMD_SEND_HTTPS_REQ:
             {
                 wifiBusy = 1;
+#ifdef SEND_DEBUG_MESSAGES
                 if(responseString == NULL)
                 {
                     responseString = (char *) malloc(100);
                     sprintf(responseString, "\r\nHTTP REQUEST RECEIVED\r\n");
                     sendATresponseString(AT_EVENT);
                 }
+#endif
                 dbg_printf(LOG, "before call to send http request \n");
                 dbg_printf(LOG, "\r\n[WIFI-MAN] Received HTTPS request...\r\n");
                 print_memory_info();
@@ -225,19 +233,25 @@
                 int event_id = _event_queue.call(this, &WiFiManager::createSendHttpsRequest);
                 backgroundTaskCompleted = false;               
                 int msecCount = 0;
-                while(!backgroundTaskCompleted && msecCount < 1000)
+                int oldChunkNum = chunkNum;
+                while(!backgroundTaskCompleted && msecCount < 6000)
                 {
                     msecCount++;
                     wait_ms(10);
+                    if(oldChunkNum != chunkNum) // new payload received
+                    {
+                        oldChunkNum = chunkNum;
+                        msecCount = 0;
+                    }
                 }
                 if(backgroundTaskCompleted)
                 {
-                    queueATresponse(AT_INTERNET_CONFIG_RESP);
+                    //queueATresponse(AT_INTERNET_CONFIG_RESP);
                     result = true;
                 }
                 else
                 {
-                    _event_queue.cancel(event_id); 
+                    //_event_queue.cancel(event_id); 
                     result = false;
                 }
                 backgroundTaskCompleted = false;
@@ -961,7 +975,6 @@
         sprintf(responseString, "\r\nHTTPS BODY CALLBACK RECEIVED\r\n");
         sendATresponseString(AT_EVENT);
     }
-
     sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length);
 }
 
@@ -1157,9 +1170,11 @@
                                          http_req_cfg->method, 
                                          full_url,
                                          callback(this, &WiFiManager::body_callback));
+#ifdef SEND_DEBUG_MESSAGES
         responseString = (char *) malloc(100);
         sprintf(responseString, "\r\nHTTP REQUEST OBJECT CREATED\r\n");
         sendDebugMessage();
+#endif
 #else
         https_request = new HttpsRequest(network, 
                                          SSL_CA_PEM,
@@ -1188,6 +1203,7 @@
             //mbed_stats_heap_t heap_stats;
             //mbed_stats_heap_get(&heap_stats);
             dbg_printf(LOG, "Heap size: %lu / %lu bytes\r\n", heap_stats.current_size, heap_stats.reserved_size);
+#ifdef SEND_DEBUG_MESSAGES
             responseString = (char *) malloc(200);
             sprintf(responseString, "\r\nABOUT TO SEND HTTP REQUEST\r\n");
             sendDebugMessage();
@@ -1198,6 +1214,7 @@
             responseString = (char *) malloc(100);
             sprintf(responseString, "\r\nRETURNED FROM SENDING HTTP REQUEST\r\n");
             sendDebugMessage();
+#endif
         }
 #else
         setHttpsHeader("Host", http_req_cfg->hostName);
--- a/source/WiFiManager.h	Mon May 06 20:18:02 2019 +0000
+++ b/source/WiFiManager.h	Wed May 08 19:38:35 2019 +0000
@@ -77,6 +77,7 @@
     bool http_request_result;
     int  wifiBusy;
     Timer wifiWatchdogTimer;
+    Ticker watchDogTick;
     uint32_t watchdogCnt;
     http_result_t http_result;
     
@@ -125,6 +126,7 @@
     void                  updateRemotePeerDetails();
     void                  sendDebugMessage();
     void                  callWifiWatchDog();
+    void                  callWifiWatchDogIsr();
 
 
 
--- a/source/common_config.h	Mon May 06 20:18:02 2019 +0000
+++ b/source/common_config.h	Wed May 08 19:38:35 2019 +0000
@@ -42,7 +42,7 @@
 #define HTTP_HEADER_CONTENT_TYPE  "Content-Type:"
 #define HTTP_HEADER_CONTENT_LEN   "Content-Length:"
 //#define ENABLE_MEMORY_CHECKS
-
+#define SEND_DEBUG_MESSAGES
 typedef enum
 {
   IF_HW_ADDRESS = 0,
--- a/source/main-https.cpp	Mon May 06 20:18:02 2019 +0000
+++ b/source/main-https.cpp	Wed May 08 19:38:35 2019 +0000
@@ -57,8 +57,8 @@
 uint8_t TxBuffer[TX_BUFFER_LEN];
 uint8_t RxBuffer[RX_BUFFER_LEN];
 #endif
-static EventQueue eventQueue(/* event count */ 32 * EVENTS_EVENT_SIZE);
-//static EventQueue eventQueue2(/* event count */ 10 * EVENTS_EVENT_SIZE);
+static EventQueue eventQueue_atcmd(/* event count */ 32 * EVENTS_EVENT_SIZE);
+static EventQueue eventQueue_wifi(/* event count */ 32 * EVENTS_EVENT_SIZE);
 
 LEDService *ledServicePtr;
 
@@ -103,14 +103,15 @@
 #else
 // using global heap
 Thread btle_thread(BTLE_THREAD_PRIORITY, 1024);
-Thread wifi_thread(WIFI_THREAD_PRIORITY, 6*1024);
+Thread wifi_thread(WIFI_THREAD_PRIORITY, 4*1024);
 Thread atcmd_thread(ATCMD_THREAD_PRIORITY, 4*1024);
 #endif
 
 /* create a semaphore to synchronize the threads */
 Semaphore sync_sema;
 
-Thread evt_thread;
+Thread atcmd_evt_thread(osPriorityNormal, 1024);
+Thread wifi_evt_thread;
 #include "network-helper.h"
 
 /* List of trusted root CA certificates
@@ -302,7 +303,7 @@
         dbg_printf(LOG, "%d", i);
         dbg_printf(LOG, "\n");
         wait(0.5);
-        eventQueue.dispatch(500);        // Dispatch time - 500msec
+        eventQueue_atcmd.dispatch(500);        // Dispatch time - 500msec
     }
 }
 
@@ -316,7 +317,7 @@
         sprintf(fmtstr, "BLE: loop # %d\n", i);
         peripheral->sendBLEUartData(fmtstr);
         wait(0.5);
-        eventQueue.dispatch(500);        // Dispatch time - 500msec
+        eventQueue_atcmd.dispatch(500);        // Dispatch time - 500msec
         if(device->readable()){
             dbg_printf(LOG, "keypress detected aborting....\n");
             device->getc();
@@ -437,7 +438,7 @@
         dbg_printf(LOG, "ERROR: No WiFiInterface found.\n");
     }
     wiFiManager = new WiFiManager(wifi_config, network, 
-                                  eventQueue,
+                                  eventQueue_wifi,
                                   &aT2WiFimPool, &aT2WiFiCmdQueue,
                                   &wiFi2ATmPool, &wiFi2ATCmdQueue,
                                   &aT2WiFiDatamPool, &aT2WiFiDataQueue,
@@ -448,8 +449,8 @@
     int stop = Kernel::get_ms_count();
     dbg_printf(LOG, "\n The Wifi Network scan took %d ms or %4.1f seconds\n", (stop - start), (float)((stop - start)/1000.0));
     // run on separate thread;
-    evt_thread.start(callback(wifi_demo, network));
-    evt_thread.join(); 
+    wifi_evt_thread.start(callback(wifi_demo, network));
+    wifi_evt_thread.join(); 
     network->disconnect(); 
     delete network;
     dbg_printf(LOG, "\n Wifi-Demo completed - restarting BLE  \n\n");
@@ -531,11 +532,12 @@
     print_memory_info();
     // dispatch event queue on event thread
     dbg_printf(LOG, "\r\n [MAIN THREAD]  Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
-    dbg_printf(LOG, "\r\n [EVENT THREAD]  Thread Id = %X\r\n", (uint32_t)evt_thread.get_id());
-    evt_thread.start(callback(&eventQueue, &EventQueue::dispatch_forever));
+    dbg_printf(LOG, "\r\n [EVENT THREAD]  Thread Id = %X\r\n", (uint32_t)wifi_evt_thread.get_id());
+    wifi_evt_thread.start(callback(&eventQueue_wifi, &EventQueue::dispatch_forever));
+    atcmd_evt_thread.start(callback(&eventQueue_atcmd, &EventQueue::dispatch_forever));
     dbg_printf(LOG, "\r\n++++++ Starting ATCmdmanager ++++++ \r\n");
     ATCmdManager *aTCmdManager = new ATCmdManager(USBTX, USBRX, peripheral, 
-                                                eventQueue, wiFiManager, 
+                                                eventQueue_atcmd, wiFiManager, 
                                                 &aT2WiFimPool, &aT2WiFiCmdQueue,
                                                 &wiFi2ATmPool, &wiFi2ATCmdQueue,
                                                 &aT2WiFiDatamPool, &aT2WiFiDataQueue,