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

Dependencies:   mbed-http

Branch:
PassingRegression
Revision:
118:8df0e9c2ee3f
Parent:
117:8fd05113efc1
Child:
119:8d939a902333
--- a/source/ATCmdManager.cpp	Sun May 19 16:22:59 2019 +0000
+++ b/source/ATCmdManager.cpp	Sat May 25 16:25:42 2019 +0000
@@ -1,6 +1,5 @@
 #include "debug.h"
 #include "ATCmdManager.h"
-#include "common_config.h"
 #include "common_types.h"
 #include "main.h"
 #include "http_request.h"
@@ -18,6 +17,10 @@
                            Queue<wifi_data_msg_t, PQDSZ>          *aT2WiFiDataQueue, 
                            MemoryPool<at_data_msg_t, PQDSZ>       *wiFi2ATDatamPool, 
                            Queue<at_data_msg_t, PQDSZ>            *wiFi2ATDataQueue, 
+                           MemoryPool<at_ble_msg_t, PQDSZ_BLE>    *aT2BleDatamPool, 
+                           Queue<at_ble_msg_t, PQDSZ_BLE>         *aT2BleDataQueue, 
+                           MemoryPool<ble_at_msg_t, PQDSZ_BLE>    *ble2ATDatamPool, 
+                           Queue<ble_at_msg_t, PQDSZ_BLE>         *ble2ATDataQueue, 
                            bool debug)
     :
     _serial(tx, rx, DEFAULT_BAUD_RATE),
@@ -35,8 +38,11 @@
     
     _wiFi2ATDatamPool(wiFi2ATDatamPool),
     _wiFi2ATDataQueue(wiFi2ATDataQueue),
-    
-    _parser(&_serial)
+    _aT2BleDatamPool(aT2BleDatamPool),
+    _aT2BleDataQueue(aT2BleDataQueue),
+    _ble2ATDatamPool(ble2ATDatamPool),
+    _ble2ATDataQueue(ble2ATDataQueue),
+     _parser(&_serial)
     
 
 { 
@@ -50,6 +56,8 @@
     _parser.oob("AT\r", callback(this, &ATCmdManager::_oob_ok_hdlr));
     _parser.oob("ATE0", callback(this, &ATCmdManager::_oob_echo_off));
     _parser.oob("ATE1", callback(this, &ATCmdManager::_oob_echo_on));
+    _parser.oob("ATE2", callback(this, &ATCmdManager::_oob_debug_logs_on));
+    _parser.oob("ATE3", callback(this, &ATCmdManager::_oob_debug_logs_off));
     _parser.oob("AT+UMRS", callback(this, &ATCmdManager::_oob_uart_setup));
     
     _parser.oob("ATO", callback(this, &ATCmdManager::_oob_data_mode));
@@ -89,6 +97,8 @@
     //_event_queue.call_in(10, &print_heap_and_isr_stack_info);
     //print_heap_and_isr_stack_info();
     //_event_queue.call_every(3600000,&print_memory_info);
+    lastHttpRespTime = Kernel::get_ms_count();
+    lastCloudMsgType = 0x00;
     _event_queue.call_every(10000,&blinkLEDs);
 #ifdef BOX_UBLOX_DEMO_TESTING
     check_for_at_cmd = false;
@@ -236,6 +246,15 @@
                 at_resp = AT_RESP_NONE;
                 break;
             }
+            case AT_BLE_RESPONSE:  
+            {
+                // AT Event state 
+                dbg_printf(LOG, "\n [ATCMD MAN] BLE RESPONSE RECEIVED!!\r\n");
+                respStr = (char *) resp_data->buffer;
+                sendBleDataEvent(respStr, resp_data->dataLen);
+                at_resp = AT_RESP_NONE;
+                break;
+            }
             default:
                  //UNKNOWN response state
                 dbg_printf(LOG, "\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n");
@@ -443,6 +462,14 @@
 #ifdef FULL_DEBUG_ENABLED
     dbg_printf(LOG, "\nLen = %d\n", bodyLen);
 #endif
+    uint32_t msecsSinceLastMsg = Kernel::get_ms_count() - lastHttpRespTime;
+    if((lastCloudMsgType == BAR_DB_MSGTYPE || lastCloudMsgType == REC_DB_MSGTYPE) && 
+       lastCloudMsgType == (uint8_t) bodyPtr[8] && 
+      (msecsSinceLastMsg < CLOUD_RETRY_TIME_MS ))
+    {
+        return false;
+    }
+    lastCloudMsgType = (uint8_t) bodyPtr[8]; // pick out the MSGTYPE byte from payload
     http_req->body = (uint8_t *) outPtr;
     memcpy(outPtr, bodyPtr, bodyLen);
     if(bodyLen > 10){
@@ -463,7 +490,7 @@
         wifiStateControl = AT_HTTPS_RESP_DOWNLOAD;
         return true;
     }
-    return true;
+    return false;
 }
 // OOB processing
 void ATCmdManager::_process_oob(uint32_t timeout, bool all){
@@ -516,7 +543,13 @@
                     rx_buf_ptr = (uint8_t *) malloc (pLen); // we already read 2 bytes from payload but expect 1 stop byte
                     rx_buf_ptr[pLen-1] = 0x00; // clear last byte so the readback value is as expected
                     n = _parser.read((char *)rx_buf_ptr, pLen);
-                    if(n == -1) break; // timeout!
+                    if(n == -1) 
+                    {
+                        dbg_printf(LOG, "Timeout while reading message payload bytes - expected %d!\r\n", pLen);
+                        free(rx_buf_ptr); // make sure to free buffer
+                        rx_buf_ptr = NULL;
+                        break; // timeout!
+                    }
                     dbg_printf(LOG, "%d bytes read - expected %d!\n", n, pLen);
                     printBufferInHex(rx_buf_ptr, pLen);
                     dbg_printf(LOG, "rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]);
@@ -720,6 +753,23 @@
 }
 
 
+
+void ATCmdManager::_oob_debug_logs_on()
+{
+    initialise_debug(LOG | ERR | TXT | DBG);
+    dbg_printf(LOG, "\n Received ATE2 OOB command!!\n");
+    dbg_printf(LOG, "\n debug logs ON!!\n");
+    sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
+}
+
+void ATCmdManager::_oob_debug_logs_off()
+{
+    dbg_printf(LOG, "\n Received ATE3 OOB command!!\n");
+    dbg_printf(LOG, "\n turning debug logs OFF!!\n");
+    initialise_debug(NONE);
+    sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
+}
+
 void ATCmdManager::_oob_data_mode(){
     dbg_printf(LOG, "\n Received EDM mode command!!\n");
     int dmode;
@@ -773,12 +823,12 @@
 }
 
 void ATCmdManager::_oob_get_ble_role(){
+    trigger_start_BLE();
     dbg_printf(LOG, "\n Received get BLE role command!!\n");
     sendAtConfirmation("+UBTLE:2\r\nOK\r\n");   //_parser.send(OK_RESP);
 }
 
 void ATCmdManager::_oob_ena_ble_peri(){
-    trigger_start_BLE();
     dbg_printf(LOG, "\n Received enable BLE Peripheral command!!\n");
     sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
 }
@@ -1190,6 +1240,31 @@
 }
 
 
+void ATCmdManager::sendBleDataEvent(const char *buf, int len)
+{
+    _smutex.lock();
+    switch(dataMode){
+        case AT_CMD_DATA_MODE:
+            _parser.send(buf);
+            break;
+        case AT_STD_DATA_MODE:
+            _parser.send(buf);
+            break;
+        case AT_EXT_DATA_MODE:
+        {
+            outputEDMdata((const uint8_t *) buf, len, DATA_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL);
+            break;
+        }
+        default:
+            _parser.send(buf);
+            break;
+    }
+    _smutex.unlock();
+    _wiFi2ATDatamPool->free(resp_data);
+    resp_data = NULL;
+}
+
+
 void ATCmdManager::sendConnectEvent(const uint8_t *buf, int len)
 {
     switch(dataMode){
@@ -1252,4 +1327,5 @@
                   EVENT_MSG_TYPE, WIFI_CHANNEL);
     _wiFi2ATDatamPool->free(resp_data);
     resp_data = NULL;
+    lastHttpRespTime = Kernel::get_ms_count();
 }