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

Dependencies:   mbed-http

Branch:
PassingRegression
Revision:
121:ac4f59839e4f
Parent:
120:779b74689747
Child:
122:62166886db5f
--- a/source/ATCmdManager.cpp	Mon May 27 17:00:43 2019 +0000
+++ b/source/ATCmdManager.cpp	Sat Jun 01 15:29:03 2019 +0000
@@ -21,7 +21,7 @@
                            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)
+                           startup_config_t *startup_config, bool debug)
     :
     _serial(tx, rx, DEFAULT_BAUD_RATE),
     uart_config(uart_config),
@@ -42,6 +42,7 @@
     _aT2BleDataQueue(aT2BleDataQueue),
     _ble2ATDatamPool(ble2ATDatamPool),
     _ble2ATDataQueue(ble2ATDataQueue),
+    startup_config(startup_config),
      _parser(&_serial)
     
 
@@ -75,7 +76,7 @@
     _parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
     
     _parser.oob("AT+UDSC=", callback(this, &ATCmdManager::_oob_ok_hdlr));
-    _parser.oob("AT&W", callback(this, &ATCmdManager::_oob_ok_hdlr));
+    _parser.oob("AT&W", callback(this, &ATCmdManager::_oob_saveSettings_hdlr));
     //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
     //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
     //_parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork));
@@ -87,6 +88,9 @@
     _parser.oob("AT+UNSTAT=", callback(this, &ATCmdManager::_oob_getNetworkStatus));
     _parser.oob("AT+UWSSTAT", callback(this, &ATCmdManager::_oob_WiFiNetworkStatus));
     
+    _parser.oob("AT+UFACTORY", callback(this, &ATCmdManager::_oob_factoryReset));
+    _parser.oob("AT+UDELCFG=", callback(this, &ATCmdManager::_oob_deleteConfiguration));
+
     //_parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_sendHttpMessage));
     //sendAtConfirmation("Testing:: +UBTLE:2\r\nOK\r\n");
     dbg_printf(LOG, "\n --- ATCmdManager constructor completed ---\n");
@@ -260,8 +264,8 @@
             {
                 // AT Event state 
                 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_EVENT RESPONSE RECEIVED!!\r\n");
-                respStr = (char *) resp_data->buffer;
-                sendBleAtEvent(respStr, resp_data->dataLen);
+                respStr = (char *) ble_resp_data->buffer;
+                sendBleAtEvent(respStr, ble_resp_data->dataLen);
                 at_resp = AT_RESP_NONE;
                 break;
             }
@@ -270,6 +274,7 @@
                 // AT Event state 
                 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_RESPONSE RECEIVED!!\r\n");
                 respStr = (char *) ble_resp_data->buffer;
+                ble_resp_data->buffer[ble_resp_data->dataLen] = NULL;
                 sendBleDataEvent(respStr, ble_resp_data->dataLen);
                 at_resp = AT_RESP_NONE;
                 break;
@@ -869,11 +874,19 @@
 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);
+    if(startup_config->ble_enable)
+    {
+        sendAtConfirmation("+UBTLE:2\r\nOK\r\n");   //_parser.send(OK_RESP);
+    }
+    else // disabled
+    {
+        sendAtConfirmation("+UBTLE:0\r\nOK\r\n");   //_parser.send(OK_RESP);
+    }
 }
 
 void ATCmdManager::_oob_ena_ble_peri(){
     dbg_printf(LOG, "\n Received enable BLE Peripheral command!!\n");
+    startup_config->ble_enable = true;
     sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
 }
 
@@ -883,6 +896,33 @@
     system_reset();
 }
 
+
+void ATCmdManager::_oob_factoryReset(){
+    dbg_printf(LOG, "\n Received factory reset command!!\n");
+    resetConfiguration();
+    sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
+}
+
+
+void ATCmdManager::_oob_deleteConfiguration(){
+    dbg_printf(LOG, "\n Received delete configuration command!!\n");
+    int configKey;
+    bool res = false;
+    if(_parser.scanf("%d", &configKey) >0)
+    {
+        res = deleteConfiguration((nvstore_key_t) configKey);
+    }
+    if(res)
+    sendAtConfirmation(OK_RESP);   //_parser.send(OK_RESP);
+}
+
+
+
+void ATCmdManager::_oob_saveSettings_hdlr()
+{
+    saveConfiguration(APP_CONFIG_0);
+    sendAtConfirmation(OK_RESP);    
+}
 const char * ATCmdManager::sec2str(nsapi_security_t sec)
 {
     switch (sec) {
@@ -1258,7 +1298,7 @@
     if(evt.status == osEventMessage){
         ble_resp_data = (ble_at_msg_t*)evt.value.p;
         setNextResponse(ble_resp_data->at_resp);
-        dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", resp_data->dataLen, resp_data->at_resp);
+        dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", ble_resp_data->dataLen, ble_resp_data->at_resp);
     }
     return true;
 }