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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Tue Jun 11 20:23:43 2019 +0000
Branch:
PassingRegression
Revision:
122:62166886db5f
Parent:
121:ac4f59839e4f
Child:
123:a49e9ffbaca6
added error handling for Cloud connection keep alive

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ocomeni 103:7b566b522427 1 #include "debug.h"
ocomeni 74:f26e846adfe9 2 #include "ATCmdManager.h"
ocomeni 79:a2187bbfa407 3 #include "common_types.h"
ocomeni 114:b11bb96c09f3 4 #include "main.h"
ocomeni 84:7c7add00f4bf 5 #include "http_request.h"
ocomeni 92:ec9550034276 6 #include "mbed_memory_status.h"
ocomeni 84:7c7add00f4bf 7 //#include "mbed_memory_status.h"
ocomeni 103:7b566b522427 8 #define FILE_CODE "atcmd"
ocomeni 74:f26e846adfe9 9
ocomeni 117:8fd05113efc1 10 ATCmdManager::ATCmdManager(PinName tx, PinName rx, uart_config_t *uart_config,
ocomeni 79:a2187bbfa407 11 events::EventQueue &event_queue, WiFiManager *wifi,
ocomeni 79:a2187bbfa407 12 MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool,
ocomeni 80:e8f0e92e3ac9 13 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue,
ocomeni 81:637a87eb8170 14 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool,
ocomeni 81:637a87eb8170 15 Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue,
ocomeni 87:99b37d26ff2a 16 MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool,
ocomeni 87:99b37d26ff2a 17 Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue,
ocomeni 87:99b37d26ff2a 18 MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool,
ocomeni 87:99b37d26ff2a 19 Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue,
ocomeni 118:8df0e9c2ee3f 20 MemoryPool<at_ble_msg_t, PQDSZ_BLE> *aT2BleDatamPool,
ocomeni 118:8df0e9c2ee3f 21 Queue<at_ble_msg_t, PQDSZ_BLE> *aT2BleDataQueue,
ocomeni 118:8df0e9c2ee3f 22 MemoryPool<ble_at_msg_t, PQDSZ_BLE> *ble2ATDatamPool,
ocomeni 118:8df0e9c2ee3f 23 Queue<ble_at_msg_t, PQDSZ_BLE> *ble2ATDataQueue,
ocomeni 121:ac4f59839e4f 24 startup_config_t *startup_config, bool debug)
ocomeni 74:f26e846adfe9 25 :
ocomeni 74:f26e846adfe9 26 _serial(tx, rx, DEFAULT_BAUD_RATE),
ocomeni 117:8fd05113efc1 27 uart_config(uart_config),
ocomeni 79:a2187bbfa407 28 _event_queue(event_queue),
ocomeni 79:a2187bbfa407 29 wiFiManager(wiFiManager),
ocomeni 79:a2187bbfa407 30 _aT2WiFimPool(aT2WiFimPool),
ocomeni 80:e8f0e92e3ac9 31 _aT2WiFiCmdQueue(aT2WiFiCmdQueue),
ocomeni 80:e8f0e92e3ac9 32
ocomeni 80:e8f0e92e3ac9 33 _wiFi2ATmPool(wiFi2ATmPool),
ocomeni 80:e8f0e92e3ac9 34 _wiFi2ATCmdQueue(wiFi2ATCmdQueue),
ocomeni 80:e8f0e92e3ac9 35
ocomeni 80:e8f0e92e3ac9 36 _aT2WiFiDatamPool(aT2WiFiDatamPool),
ocomeni 80:e8f0e92e3ac9 37 _aT2WiFiDataQueue(aT2WiFiDataQueue),
ocomeni 80:e8f0e92e3ac9 38
ocomeni 80:e8f0e92e3ac9 39 _wiFi2ATDatamPool(wiFi2ATDatamPool),
ocomeni 80:e8f0e92e3ac9 40 _wiFi2ATDataQueue(wiFi2ATDataQueue),
ocomeni 118:8df0e9c2ee3f 41 _aT2BleDatamPool(aT2BleDatamPool),
ocomeni 118:8df0e9c2ee3f 42 _aT2BleDataQueue(aT2BleDataQueue),
ocomeni 118:8df0e9c2ee3f 43 _ble2ATDatamPool(ble2ATDatamPool),
ocomeni 118:8df0e9c2ee3f 44 _ble2ATDataQueue(ble2ATDataQueue),
ocomeni 121:ac4f59839e4f 45 startup_config(startup_config),
ocomeni 118:8df0e9c2ee3f 46 _parser(&_serial)
ocomeni 80:e8f0e92e3ac9 47
ocomeni 74:f26e846adfe9 48
ocomeni 74:f26e846adfe9 49 {
ocomeni 74:f26e846adfe9 50 // constructor
ocomeni 117:8fd05113efc1 51 _serial.set_baud(uart_config->baudrate);
ocomeni 103:7b566b522427 52 //Flow flowCtrl = Flow::Disabled;
ocomeni 103:7b566b522427 53 //_serial.set_flow_control(mbed::SerialBase::Disabled);
ocomeni 74:f26e846adfe9 54 _parser.debug_on(debug);
ocomeni 74:f26e846adfe9 55 _parser.set_delimiter("\r\n");
ocomeni 103:7b566b522427 56 _parser.send("+STARTUP\r\n\r\n");
ocomeni 103:7b566b522427 57 _parser.oob("AT\r", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 75:08eff6258e1b 58 _parser.oob("ATE0", callback(this, &ATCmdManager::_oob_echo_off));
ocomeni 75:08eff6258e1b 59 _parser.oob("ATE1", callback(this, &ATCmdManager::_oob_echo_on));
ocomeni 118:8df0e9c2ee3f 60 _parser.oob("ATE2", callback(this, &ATCmdManager::_oob_debug_logs_on));
ocomeni 118:8df0e9c2ee3f 61 _parser.oob("ATE3", callback(this, &ATCmdManager::_oob_debug_logs_off));
ocomeni 75:08eff6258e1b 62 _parser.oob("AT+UMRS", callback(this, &ATCmdManager::_oob_uart_setup));
ocomeni 75:08eff6258e1b 63
ocomeni 75:08eff6258e1b 64 _parser.oob("ATO", callback(this, &ATCmdManager::_oob_data_mode));
ocomeni 75:08eff6258e1b 65 _parser.oob("AT+UMLA", callback(this, &ATCmdManager::_oob_get_mac_addr));
ocomeni 75:08eff6258e1b 66 _parser.oob("AT+UBTLE?", callback(this, &ATCmdManager::_oob_get_ble_role));
ocomeni 75:08eff6258e1b 67 _parser.oob("AT+UBTLE=2", callback(this, &ATCmdManager::_oob_ena_ble_peri));
ocomeni 75:08eff6258e1b 68 _parser.oob("AT+CPWROFF", callback(this, &ATCmdManager::_oob_reboot));
ocomeni 75:08eff6258e1b 69 _parser.oob("AT+CGMR", callback(this, &ATCmdManager::_oob_get_fw_ver));
ocomeni 82:10072c1794d3 70 _parser.oob("AT+UWSCAN", callback(this, &ATCmdManager::_oob_scanWiFiNetworks));
ocomeni 98:65c2333a38b6 71 _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_WiFiStationConfigAction));
ocomeni 102:9748f290a1a5 72
ocomeni 102:9748f290a1a5 73 _parser.oob("AT+UMLA=", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 102:9748f290a1a5 74 _parser.oob("AT+UBTLN", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 102:9748f290a1a5 75 _parser.oob("AT+UBTSM?", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 102:9748f290a1a5 76 _parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 102:9748f290a1a5 77
ocomeni 102:9748f290a1a5 78 _parser.oob("AT+UDSC=", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 121:ac4f59839e4f 79 _parser.oob("AT&W", callback(this, &ATCmdManager::_oob_saveSettings_hdlr));
ocomeni 102:9748f290a1a5 80 //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 102:9748f290a1a5 81 //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 95:290859010c8c 82 //_parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork));
ocomeni 81:637a87eb8170 83 _parser.oob("AT+UDDRP", callback(this, &ATCmdManager::_oob_setupInternetConnection));
ocomeni 114:b11bb96c09f3 84 _parser.oob("AT+UWSC=0,0,0", callback(this, &ATCmdManager::_oob_enable_wifi));
ocomeni 82:10072c1794d3 85 _parser.oob("AT+UWSC=0,2", callback(this, &ATCmdManager::_oob_setWiFiSSID));
ocomeni 82:10072c1794d3 86 _parser.oob("AT+UWSC=0,8", callback(this, &ATCmdManager::_oob_setWiFiPWD));
ocomeni 82:10072c1794d3 87 _parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_setWiFiSecurity));
ocomeni 95:290859010c8c 88 _parser.oob("AT+UNSTAT=", callback(this, &ATCmdManager::_oob_getNetworkStatus));
ocomeni 95:290859010c8c 89 _parser.oob("AT+UWSSTAT", callback(this, &ATCmdManager::_oob_WiFiNetworkStatus));
ocomeni 95:290859010c8c 90
ocomeni 121:ac4f59839e4f 91 _parser.oob("AT+UFACTORY", callback(this, &ATCmdManager::_oob_factoryReset));
ocomeni 121:ac4f59839e4f 92 _parser.oob("AT+UDELCFG=", callback(this, &ATCmdManager::_oob_deleteConfiguration));
ocomeni 121:ac4f59839e4f 93
ocomeni 84:7c7add00f4bf 94 //_parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_sendHttpMessage));
ocomeni 103:7b566b522427 95 //sendAtConfirmation("Testing:: +UBTLE:2\r\nOK\r\n");
ocomeni 103:7b566b522427 96 dbg_printf(LOG, "\n --- ATCmdManager constructor completed ---\n");
ocomeni 81:637a87eb8170 97 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 98 dataMode = AT_CMD_DATA_MODE;
ocomeni 98:65c2333a38b6 99 debug_flag = 0;
ocomeni 104:11e9605093c9 100 wifiStateControl = AT_RESP_NONE;
ocomeni 108:3c8fb2c6e7bf 101 //_event_queue.call_in(10, &print_heap_and_isr_stack_info);
ocomeni 98:65c2333a38b6 102 //print_heap_and_isr_stack_info();
ocomeni 108:3c8fb2c6e7bf 103 //_event_queue.call_every(3600000,&print_memory_info);
ocomeni 118:8df0e9c2ee3f 104 lastHttpRespTime = Kernel::get_ms_count();
ocomeni 118:8df0e9c2ee3f 105 lastCloudMsgType = 0x00;
ocomeni 108:3c8fb2c6e7bf 106 _event_queue.call_every(10000,&blinkLEDs);
ocomeni 103:7b566b522427 107 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 108 check_for_at_cmd = false;
ocomeni 103:7b566b522427 109 #endif
ocomeni 74:f26e846adfe9 110 }
ocomeni 74:f26e846adfe9 111
ocomeni 74:f26e846adfe9 112
ocomeni 74:f26e846adfe9 113 void ATCmdManager::runMain(){
ocomeni 103:7b566b522427 114 dbg_printf(LOG, "\r\n [ATCMD MAN] Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
ocomeni 74:f26e846adfe9 115 while(true){
ocomeni 74:f26e846adfe9 116 _process_oob(UBLOX_ODIN_W2_RECV_TIMEOUT, true);
ocomeni 81:637a87eb8170 117 wait_ms(MAIN_LOOP_WAIT_TIME_MS); // allow BTLE/WiFi some time
ocomeni 81:637a87eb8170 118 processResponses();
ocomeni 74:f26e846adfe9 119 }
ocomeni 74:f26e846adfe9 120
ocomeni 74:f26e846adfe9 121 }
ocomeni 74:f26e846adfe9 122
ocomeni 81:637a87eb8170 123 void ATCmdManager::processResponses(){
ocomeni 81:637a87eb8170 124 dequeueATresponse();
ocomeni 87:99b37d26ff2a 125 dequeueWiFidataResponse();
ocomeni 120:779b74689747 126 dequeueBleDataResponse();
ocomeni 104:11e9605093c9 127 updateWiFiMgrStatus();
ocomeni 95:290859010c8c 128 char * respStr;
ocomeni 81:637a87eb8170 129 switch(at_resp){
ocomeni 81:637a87eb8170 130 case AT_RESP_NONE:
ocomeni 81:637a87eb8170 131 // IDLE response state
ocomeni 81:637a87eb8170 132 break;
ocomeni 81:637a87eb8170 133 case AT_SCAN_RESP:
ocomeni 81:637a87eb8170 134 // AT_SCAN_RESP response state
ocomeni 103:7b566b522427 135 dbg_printf(LOG, "\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 136 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 137 sendAtConfirmationFreeMpool(respStr);
ocomeni 81:637a87eb8170 138 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 139 break;
ocomeni 81:637a87eb8170 140 case AT_DETAILED_SCAN_RESP:
ocomeni 81:637a87eb8170 141 // AT_DETAILED_SCAN_RESP response state
ocomeni 103:7b566b522427 142 dbg_printf(LOG, "\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 143 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 144 sendAtConfirmationFreeMpool(respStr);
ocomeni 81:637a87eb8170 145 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 146 break;
ocomeni 81:637a87eb8170 147 case AT_CONNECT_RESP:
ocomeni 99:05398b3184f8 148 {
ocomeni 81:637a87eb8170 149 // AT_CONNECT_RESP response state
ocomeni 103:7b566b522427 150 dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\r\n");
ocomeni 103:7b566b522427 151 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 95:290859010c8c 152 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 153 sendAtConfirmationFreeMpool(respStr);
ocomeni 99:05398b3184f8 154 char * urc = new char[20];
ocomeni 104:11e9605093c9 155 sprintf(urc, "\r\n%s:%d\r\n", NETWORK_UP_URC, WIFI_INTERFACE_ID);
ocomeni 99:05398b3184f8 156 sendAtEvent(urc);
ocomeni 99:05398b3184f8 157 delete urc;
ocomeni 81:637a87eb8170 158 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 159 break;
ocomeni 99:05398b3184f8 160 }
ocomeni 81:637a87eb8170 161 case AT_DISCONNECT_RESP:
ocomeni 81:637a87eb8170 162 // AT_DISCONNECT_RESP response state
ocomeni 103:7b566b522427 163 dbg_printf(LOG, "\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 164 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 165 sendAtConfirmationFreeMpool(respStr);
ocomeni 81:637a87eb8170 166 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 167 break;
ocomeni 82:10072c1794d3 168 case AT_CONFIG_RESP:
ocomeni 82:10072c1794d3 169 // AT_CONFIG_RESP response state
ocomeni 103:7b566b522427 170 dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 171 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 84:7c7add00f4bf 172 at_resp = AT_RESP_NONE;
ocomeni 84:7c7add00f4bf 173 break;
ocomeni 95:290859010c8c 174 case AT_NETWORK_STATUS_RESP:
ocomeni 95:290859010c8c 175 // AT_CONFIG_RESP response state
ocomeni 103:7b566b522427 176 dbg_printf(LOG, "\n [ATCMD MAN] NETWORK STATUS RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 177 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 178 sendAtConfirmationFreeMpool(respStr);
ocomeni 95:290859010c8c 179 at_resp = AT_RESP_NONE;
ocomeni 95:290859010c8c 180 break;
ocomeni 95:290859010c8c 181 case AT_WIFI_STATUS_RESP:
ocomeni 95:290859010c8c 182 // AT_CONFIG_RESP response state
ocomeni 103:7b566b522427 183 dbg_printf(LOG, "\n [ATCMD MAN] WIFI RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 184 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 185 sendAtConfirmationFreeMpool(respStr);
ocomeni 95:290859010c8c 186 at_resp = AT_RESP_NONE;
ocomeni 95:290859010c8c 187 break;
ocomeni 84:7c7add00f4bf 188 case AT_INTERNET_CONFIG_RESP:
ocomeni 84:7c7add00f4bf 189 // AT_CONFIG_RESP response state
ocomeni 103:7b566b522427 190 dbg_printf(LOG, "\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\r\n");
ocomeni 96:f5ed273881af 191 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 84:7c7add00f4bf 192 at_resp = AT_RESP_NONE;
ocomeni 84:7c7add00f4bf 193 break;
ocomeni 84:7c7add00f4bf 194 case AT_HTTPS_RESP:
ocomeni 84:7c7add00f4bf 195 // AT_HTTP_RESP response state
ocomeni 103:7b566b522427 196 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\r\n");
ocomeni 87:99b37d26ff2a 197 return_response();
ocomeni 95:290859010c8c 198 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 81:637a87eb8170 199 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 200 break;
ocomeni 89:45f6db09a76d 201 case AT_HTTPS_RESP_DOWNLOAD:
ocomeni 89:45f6db09a76d 202 // AT_HTTPS_RESP_DOWNLOAD response state
ocomeni 103:7b566b522427 203 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTPS DOWNLOAD RESPONSE RECEIVED!!\r\n");
ocomeni 89:45f6db09a76d 204 return_response(true); // set download paramter to true
ocomeni 89:45f6db09a76d 205 at_resp = AT_RESP_NONE;
ocomeni 89:45f6db09a76d 206 break;
ocomeni 81:637a87eb8170 207 case AT_HTTP_RESP:
ocomeni 81:637a87eb8170 208 // AT_HTTP_RESP response state
ocomeni 103:7b566b522427 209 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n");
ocomeni 89:45f6db09a76d 210 return_response();
ocomeni 89:45f6db09a76d 211 at_resp = AT_RESP_NONE;
ocomeni 89:45f6db09a76d 212 break;
ocomeni 89:45f6db09a76d 213 case AT_HTTP_RESP_DOWNLOAD:
ocomeni 89:45f6db09a76d 214 // AT_HTTP_RESP response state
ocomeni 103:7b566b522427 215 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n");
ocomeni 89:45f6db09a76d 216 return_response(true); // set download paramter to true
ocomeni 81:637a87eb8170 217 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 218 break;
ocomeni 99:05398b3184f8 219 case CONNECT_EVENT:
ocomeni 99:05398b3184f8 220 {
ocomeni 99:05398b3184f8 221 // Connect Event state
ocomeni 103:7b566b522427 222 dbg_printf(LOG, "\n [ATCMD MAN] CONNECT EVENT RECEIVED!!\r\n");
ocomeni 99:05398b3184f8 223 sendConnectEvent(resp_data->buffer, resp_data->dataLen);
ocomeni 99:05398b3184f8 224 at_resp = AT_RESP_NONE;
ocomeni 99:05398b3184f8 225 break;
ocomeni 99:05398b3184f8 226 }
ocomeni 100:80ef4bc31b7a 227 case AT_EVENT:
ocomeni 100:80ef4bc31b7a 228 {
ocomeni 100:80ef4bc31b7a 229 // AT Event state
ocomeni 103:7b566b522427 230 dbg_printf(LOG, "\n [ATCMD MAN] AT EVENT RECEIVED!!\r\n");
ocomeni 100:80ef4bc31b7a 231 respStr = (char *) resp_data->buffer;
ocomeni 100:80ef4bc31b7a 232 sendAtEvent(respStr);
ocomeni 100:80ef4bc31b7a 233 at_resp = AT_RESP_NONE;
ocomeni 100:80ef4bc31b7a 234 break;
ocomeni 100:80ef4bc31b7a 235 }
ocomeni 104:11e9605093c9 236 case WIFI_WATCH_DOG:
ocomeni 104:11e9605093c9 237 {
ocomeni 104:11e9605093c9 238 // AT_HTTP_RESP response state
ocomeni 104:11e9605093c9 239 dbg_printf(LOG, "\n [ATCMD MAN] WIFI Watchdog message!!\r\n");
ocomeni 104:11e9605093c9 240 respStr = (char *) resp_data->buffer;
ocomeni 104:11e9605093c9 241 sendConnectIndicationFreeMpool(respStr);
ocomeni 104:11e9605093c9 242 at_resp = AT_RESP_NONE;
ocomeni 104:11e9605093c9 243 break;
ocomeni 104:11e9605093c9 244 }
ocomeni 93:06e755a80187 245 case AT_COMMAND_FAILED:
ocomeni 98:65c2333a38b6 246 {
ocomeni 93:06e755a80187 247 // AT_HTTP_RESP response state
ocomeni 103:7b566b522427 248 dbg_printf(LOG, "\n [ATCMD MAN] WIFI COMMAND FAILED!!\r\n");
ocomeni 98:65c2333a38b6 249 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 250 sendAtConfirmationFreeMpool(respStr);
ocomeni 98:65c2333a38b6 251 at_resp = AT_RESP_NONE;
ocomeni 93:06e755a80187 252 break;
ocomeni 98:65c2333a38b6 253 }
ocomeni 119:8d939a902333 254 case BLE_CONNECT_EVENT:
ocomeni 119:8d939a902333 255 {
ocomeni 119:8d939a902333 256 // AT Event state
ocomeni 119:8d939a902333 257 dbg_printf(LOG, "\n [ATCMD MAN] BLE_CONNECT_EVENT RESPONSE RECEIVED!!\r\n");
ocomeni 119:8d939a902333 258 uint8_t * respBytes = ble_resp_data->buffer;
ocomeni 119:8d939a902333 259 sendBleConnectEvent((const char *)respBytes, ble_resp_data->dataLen);
ocomeni 119:8d939a902333 260 at_resp = AT_RESP_NONE;
ocomeni 119:8d939a902333 261 break;
ocomeni 119:8d939a902333 262 }
ocomeni 119:8d939a902333 263 case AT_BLE_EVENT:
ocomeni 119:8d939a902333 264 {
ocomeni 119:8d939a902333 265 // AT Event state
ocomeni 119:8d939a902333 266 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_EVENT RESPONSE RECEIVED!!\r\n");
ocomeni 121:ac4f59839e4f 267 respStr = (char *) ble_resp_data->buffer;
ocomeni 121:ac4f59839e4f 268 sendBleAtEvent(respStr, ble_resp_data->dataLen);
ocomeni 119:8d939a902333 269 at_resp = AT_RESP_NONE;
ocomeni 119:8d939a902333 270 break;
ocomeni 119:8d939a902333 271 }
ocomeni 118:8df0e9c2ee3f 272 case AT_BLE_RESPONSE:
ocomeni 118:8df0e9c2ee3f 273 {
ocomeni 118:8df0e9c2ee3f 274 // AT Event state
ocomeni 119:8d939a902333 275 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_RESPONSE RECEIVED!!\r\n");
ocomeni 119:8d939a902333 276 respStr = (char *) ble_resp_data->buffer;
ocomeni 121:ac4f59839e4f 277 ble_resp_data->buffer[ble_resp_data->dataLen] = NULL;
ocomeni 119:8d939a902333 278 sendBleDataEvent(respStr, ble_resp_data->dataLen);
ocomeni 119:8d939a902333 279 at_resp = AT_RESP_NONE;
ocomeni 119:8d939a902333 280 break;
ocomeni 119:8d939a902333 281 }
ocomeni 119:8d939a902333 282 case AT_SOCKET_KEEP_ALIVE_OK:
ocomeni 119:8d939a902333 283 {
ocomeni 119:8d939a902333 284 // AT Event state
ocomeni 119:8d939a902333 285 dbg_printf(LOG, "\n [ATCMD MAN] AT_SOCKET_KEEP_ALIVE OK RESPONSE RECEIVED!!\r\n");
ocomeni 122:62166886db5f 286 #ifdef SEND_CLOUD_OK_MSG
ocomeni 122:62166886db5f 287 sendAtConfirmation("\r\nCLOUD CONNECTION OK\r\n");
ocomeni 122:62166886db5f 288 #endif
ocomeni 119:8d939a902333 289 at_resp = AT_RESP_NONE;
ocomeni 119:8d939a902333 290 break;
ocomeni 119:8d939a902333 291 }
ocomeni 119:8d939a902333 292 case AT_SOCKET_KEEP_ALIVE_FAILED:
ocomeni 119:8d939a902333 293 {
ocomeni 119:8d939a902333 294 // AT Event state
ocomeni 119:8d939a902333 295 dbg_printf(LOG, "\n [ATCMD MAN] AT_SOCKET_KEEP_ALIVE FAILED RESPONSE RECEIVED!!\r\n");
ocomeni 122:62166886db5f 296 #ifdef SEND_CLOUD_OK_MSG
ocomeni 119:8d939a902333 297 sendAtEvent("\r\nCLOUD CONNECTION FAILED\r\n");
ocomeni 122:62166886db5f 298 #endif
ocomeni 118:8df0e9c2ee3f 299 at_resp = AT_RESP_NONE;
ocomeni 118:8df0e9c2ee3f 300 break;
ocomeni 118:8df0e9c2ee3f 301 }
ocomeni 120:779b74689747 302 case BLE_DISCONNECT_EVENT:
ocomeni 120:779b74689747 303 {
ocomeni 120:779b74689747 304 // AT Event state
ocomeni 120:779b74689747 305 dbg_printf(LOG, "\n [ATCMD MAN] BLE_DISCONNECT_EVENT RECEIVED!!\r\n");
ocomeni 120:779b74689747 306 sendBleDisconnectEvent();
ocomeni 120:779b74689747 307 at_resp = AT_RESP_NONE;
ocomeni 120:779b74689747 308 break;
ocomeni 120:779b74689747 309 }
ocomeni 100:80ef4bc31b7a 310 default:
ocomeni 100:80ef4bc31b7a 311 //UNKNOWN response state
ocomeni 103:7b566b522427 312 dbg_printf(LOG, "\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n");
ocomeni 100:80ef4bc31b7a 313 sendAtConfirmationFreeMpool(ERROR_RESP); //_parser.send(OK_RESP);
ocomeni 100:80ef4bc31b7a 314 at_resp = AT_RESP_NONE;
ocomeni 100:80ef4bc31b7a 315 break;
ocomeni 81:637a87eb8170 316 }
ocomeni 81:637a87eb8170 317 }
ocomeni 81:637a87eb8170 318
ocomeni 120:779b74689747 319 //
ocomeni 104:11e9605093c9 320 void ATCmdManager::updateWiFiMgrStatus()
ocomeni 104:11e9605093c9 321 {
ocomeni 104:11e9605093c9 322 static int wifiBusyMonitor = 0;
ocomeni 104:11e9605093c9 323 // if next response is the expected response,
ocomeni 104:11e9605093c9 324 // then last command complete, reset wifi status
ocomeni 104:11e9605093c9 325 // pass or fail!!
ocomeni 104:11e9605093c9 326 if(at_resp == wifiStateControl || at_resp == AT_COMMAND_FAILED)
ocomeni 104:11e9605093c9 327 {
ocomeni 104:11e9605093c9 328 wifiStateControl = AT_RESP_NONE;
ocomeni 104:11e9605093c9 329 }
ocomeni 104:11e9605093c9 330 if(at_resp == WIFI_WATCH_DOG && strstr((char *) resp_data->buffer, "WiFi Main Loop inActive") != NULL)
ocomeni 104:11e9605093c9 331 {
ocomeni 104:11e9605093c9 332 wifiBusyMonitor++;
ocomeni 104:11e9605093c9 333 if(wifiBusyMonitor >= 4)
ocomeni 104:11e9605093c9 334 {
ocomeni 104:11e9605093c9 335 wifiStateControl = AT_RESP_NONE;
ocomeni 104:11e9605093c9 336 wifiBusyMonitor = 0;
ocomeni 104:11e9605093c9 337 }
ocomeni 104:11e9605093c9 338 }
ocomeni 104:11e9605093c9 339 }
ocomeni 104:11e9605093c9 340 void ATCmdManager::sendConnectIndicationFreeMpool(const char *buf)
ocomeni 104:11e9605093c9 341 {
ocomeni 104:11e9605093c9 342 int len = strlen(buf);
ocomeni 105:e5ce023eee93 343 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL);
ocomeni 104:11e9605093c9 344 _wiFi2ATDatamPool->free(resp_data);
ocomeni 104:11e9605093c9 345 resp_data = NULL;
ocomeni 104:11e9605093c9 346 }
ocomeni 104:11e9605093c9 347
ocomeni 96:f5ed273881af 348 void ATCmdManager::sendAtConfirmationFreeMpool(const char *buf)
ocomeni 96:f5ed273881af 349 {
ocomeni 96:f5ed273881af 350 sendAtConfirmation(buf);
ocomeni 96:f5ed273881af 351 _wiFi2ATDatamPool->free(resp_data);
ocomeni 96:f5ed273881af 352 resp_data = NULL;
ocomeni 96:f5ed273881af 353 }
ocomeni 96:f5ed273881af 354
ocomeni 96:f5ed273881af 355
ocomeni 104:11e9605093c9 356 void ATCmdManager::printBufferInHex(const uint8_t *buf, int pLen)
ocomeni 89:45f6db09a76d 357 {
ocomeni 104:11e9605093c9 358 print_debug_hex(buf, pLen);
ocomeni 89:45f6db09a76d 359 }
ocomeni 81:637a87eb8170 360
ocomeni 83:9c271a50a70b 361 bool ATCmdManager::validate(edm_header_t edm_header)
ocomeni 83:9c271a50a70b 362 {
ocomeni 83:9c271a50a70b 363 if(edm_header.startByte != EDM_START_BYTE)return false; // unexpected start byte found!
ocomeni 99:05398b3184f8 364 if(edm_header.payloadID != CONNECT_EVENT_ID &&
ocomeni 99:05398b3184f8 365 edm_header.payloadID != DISCONNECT_EVENT_ID &&
ocomeni 99:05398b3184f8 366 edm_header.payloadID != DATA_EVENT_ID &&
ocomeni 99:05398b3184f8 367 edm_header.payloadID != DATA_COMMAND_ID &&
ocomeni 99:05398b3184f8 368 edm_header.payloadID != AT_REQUEST_ID &&
ocomeni 99:05398b3184f8 369 edm_header.payloadID != AT_CONFIRMATION_ID &&
ocomeni 99:05398b3184f8 370 edm_header.payloadID != AT_EVENT_ID
ocomeni 83:9c271a50a70b 371 )return false; // unexpected payload ID found!
ocomeni 83:9c271a50a70b 372 if(edm_header.payloadLen > MAX_EDM_PAYLOAD_LEN ||
ocomeni 83:9c271a50a70b 373 edm_header.payloadLen < MIN_EDM_PAYLOAD_LEN
ocomeni 83:9c271a50a70b 374 ) return false; // unexpected length received!
ocomeni 90:ed0267eca7b5 375 if(edm_header.channel_id != WIFI_CHANNEL &&
ocomeni 90:ed0267eca7b5 376 edm_header.channel_id != BLE_CHANNEL
ocomeni 90:ed0267eca7b5 377 ) return false; // unexpected channel_id received!
ocomeni 83:9c271a50a70b 378 return true;
ocomeni 83:9c271a50a70b 379 }
ocomeni 74:f26e846adfe9 380
ocomeni 84:7c7add00f4bf 381 http_method ATCmdManager::str2HttpMethod(const char * methodStr)
ocomeni 84:7c7add00f4bf 382 {
ocomeni 84:7c7add00f4bf 383 http_method _http_method;
ocomeni 84:7c7add00f4bf 384 if(strstr(methodStr, "POST")!= NULL){
ocomeni 84:7c7add00f4bf 385 _http_method = HTTP_POST;
ocomeni 84:7c7add00f4bf 386 }
ocomeni 84:7c7add00f4bf 387 else if(strstr(methodStr, "GET")!= NULL){
ocomeni 84:7c7add00f4bf 388 _http_method = HTTP_GET;
ocomeni 84:7c7add00f4bf 389 }
ocomeni 84:7c7add00f4bf 390 else{
ocomeni 84:7c7add00f4bf 391 _http_method = HTTP_DELETE; // unsupported method - set to HTTP_DELETE
ocomeni 84:7c7add00f4bf 392 }
ocomeni 84:7c7add00f4bf 393 return _http_method;
ocomeni 84:7c7add00f4bf 394 }
ocomeni 84:7c7add00f4bf 395 bool ATCmdManager::createHttpRequest()
ocomeni 84:7c7add00f4bf 396 {
ocomeni 110:c722dda4f2ff 397 #ifdef USE_WIFI_STATE_CONTROL
ocomeni 108:3c8fb2c6e7bf 398 static int wifiBusyTimeOut = 0;
ocomeni 108:3c8fb2c6e7bf 399 if(wifiStateControl != AT_RESP_NONE && wifiBusyTimeOut < 10) // wifi busy!
ocomeni 104:11e9605093c9 400 {
ocomeni 108:3c8fb2c6e7bf 401 wifiBusyTimeOut++;
ocomeni 108:3c8fb2c6e7bf 402 return false;
ocomeni 104:11e9605093c9 403 }
ocomeni 108:3c8fb2c6e7bf 404 wifiBusyTimeOut = 0;
ocomeni 110:c722dda4f2ff 405 #endif
ocomeni 90:ed0267eca7b5 406 http_request_t *http_req; // = new http_request_t;
ocomeni 90:ed0267eca7b5 407 wifi_data_msg_t data_msg;
ocomeni 90:ed0267eca7b5 408 http_req = (http_request_t *)data_msg.buffer;
ocomeni 84:7c7add00f4bf 409 char s1[32];
ocomeni 84:7c7add00f4bf 410 char s2[32];
ocomeni 84:7c7add00f4bf 411 char s3[32];
ocomeni 90:ed0267eca7b5 412 int len = 0;
ocomeni 90:ed0267eca7b5 413 int n;
ocomeni 90:ed0267eca7b5 414 char * strPtr = (char *)rx_buf_ptr;
ocomeni 84:7c7add00f4bf 415 char * p;
ocomeni 84:7c7add00f4bf 416 char * p2 = strstr(strPtr, "\r\n\r\n");
ocomeni 84:7c7add00f4bf 417 char * nxtPtr = strPtr;
ocomeni 90:ed0267eca7b5 418 char * outPtr;
ocomeni 84:7c7add00f4bf 419 char * bodyPtr = p2+4;
ocomeni 103:7b566b522427 420 dbg_printf(LOG, "\nstrPtr address= %x",strPtr);
ocomeni 103:7b566b522427 421 dbg_printf(LOG, "\np2 address= %x", p2);
ocomeni 84:7c7add00f4bf 422 for(int i = 0; i < 5; i++){
ocomeni 84:7c7add00f4bf 423 if(i == 0)// firstline scan method uri and http_ver
ocomeni 84:7c7add00f4bf 424 {
ocomeni 84:7c7add00f4bf 425 n = sscanf(nxtPtr,"%s %s %s", s1, s2, s3);
ocomeni 90:ed0267eca7b5 426 if(n!=3) return false; // error in input abort
ocomeni 105:e5ce023eee93 427 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 428 dbg_printf(LOG, "\nmethod = %s\nuri = %s\nhttp_ver = %s",s1, s2, s3 );
ocomeni 105:e5ce023eee93 429 #endif
ocomeni 84:7c7add00f4bf 430 //http_req.method = str2HttpMethod(s1.c_str());
ocomeni 90:ed0267eca7b5 431 http_req->method = str2HttpMethod(s1);
ocomeni 90:ed0267eca7b5 432 http_req->request_URI = (char *) http_req->buffer; // point 1st string to start of buffer
ocomeni 90:ed0267eca7b5 433 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 434 strncpy(http_req->request_URI, s2, len);
ocomeni 90:ed0267eca7b5 435 http_req->http_version = http_req->request_URI + len; // point 2nd string to after 1st
ocomeni 90:ed0267eca7b5 436 len = strlen(s3)+1;
ocomeni 90:ed0267eca7b5 437 strncpy(http_req->http_version, s3, len);
ocomeni 105:e5ce023eee93 438 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 439 dbg_printf(LOG, "\nhttp_request 1st line:\n method = %d\nuri = %s\nhttp_ver = %s",http_req->method,
ocomeni 90:ed0267eca7b5 440 http_req->request_URI,
ocomeni 90:ed0267eca7b5 441 http_req->http_version );
ocomeni 103:7b566b522427 442 dbg_printf(LOG, "\nhttp_request str ptrs\nuri = %X\nhttp_ver = %X",http_req->request_URI,
ocomeni 90:ed0267eca7b5 443 http_req->http_version );
ocomeni 105:e5ce023eee93 444 #endif
ocomeni 90:ed0267eca7b5 445 outPtr = http_req->http_version + len; // point output buffer ptr to after 2nd string
ocomeni 84:7c7add00f4bf 446 }
ocomeni 84:7c7add00f4bf 447 else{ // scan header pairs
ocomeni 84:7c7add00f4bf 448 n = sscanf(nxtPtr,"%s %s", s1, s2);
ocomeni 90:ed0267eca7b5 449 if(n!=2) return false; // error in input abort
ocomeni 84:7c7add00f4bf 450 p = strstr(s1,":");
ocomeni 84:7c7add00f4bf 451 *p = NULL;
ocomeni 105:e5ce023eee93 452 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 453 dbg_printf(LOG, "\nname = %s value = %s",s1, s2);
ocomeni 105:e5ce023eee93 454 #endif
ocomeni 86:04fc2fcda7ec 455 if(strstr(s1, "Host")!= NULL){
ocomeni 90:ed0267eca7b5 456 http_req->hostName = outPtr;
ocomeni 104:11e9605093c9 457 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 104:11e9605093c9 458 p = strstr(s2, "//");
ocomeni 104:11e9605093c9 459 if(p == NULL)
ocomeni 104:11e9605093c9 460 p = s2;
ocomeni 104:11e9605093c9 461 else
ocomeni 104:11e9605093c9 462 p+=2;
ocomeni 104:11e9605093c9 463 len = strlen(p)+1;
ocomeni 104:11e9605093c9 464 strncpy(outPtr, p, len);
ocomeni 104:11e9605093c9 465 #else
ocomeni 90:ed0267eca7b5 466 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 467 strncpy(outPtr, s2, len);
ocomeni 104:11e9605093c9 468 #endif
ocomeni 105:e5ce023eee93 469 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 470 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr);
ocomeni 105:e5ce023eee93 471 #endif
ocomeni 90:ed0267eca7b5 472 outPtr += len; // point output buffer ptr to after current string
ocomeni 86:04fc2fcda7ec 473 }
ocomeni 86:04fc2fcda7ec 474 else if(strstr(s1, "Accept")!= NULL){
ocomeni 90:ed0267eca7b5 475 http_req->AcceptVal = outPtr;
ocomeni 90:ed0267eca7b5 476 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 477 strncpy(outPtr, s2, len);
ocomeni 105:e5ce023eee93 478 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 479 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr);
ocomeni 105:e5ce023eee93 480 #endif
ocomeni 90:ed0267eca7b5 481 outPtr += len; // point output buffer ptr to after current string
ocomeni 86:04fc2fcda7ec 482 }
ocomeni 86:04fc2fcda7ec 483 else if(strstr(s1, "Content-Type")!= NULL){
ocomeni 90:ed0267eca7b5 484 http_req->contentType = outPtr;
ocomeni 90:ed0267eca7b5 485 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 486 strncpy(outPtr, s2, len);
ocomeni 105:e5ce023eee93 487 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 488 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr);
ocomeni 105:e5ce023eee93 489 #endif
ocomeni 90:ed0267eca7b5 490 outPtr += len; // point output buffer ptr to after current string
ocomeni 86:04fc2fcda7ec 491 }
ocomeni 86:04fc2fcda7ec 492 else if(strstr(s1, "Content-Length")!= NULL){
ocomeni 90:ed0267eca7b5 493 http_req->contentLen = outPtr;
ocomeni 90:ed0267eca7b5 494 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 495 strncpy(outPtr, s2, len);
ocomeni 105:e5ce023eee93 496 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 497 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr);
ocomeni 105:e5ce023eee93 498 #endif
ocomeni 90:ed0267eca7b5 499 outPtr += len; // point output buffer ptr to after current string
ocomeni 84:7c7add00f4bf 500 }
ocomeni 84:7c7add00f4bf 501
ocomeni 105:e5ce023eee93 502 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 503 dbg_printf(LOG, "\noutPtr = %X len = %d\n", outPtr, len);
ocomeni 105:e5ce023eee93 504 #endif
ocomeni 84:7c7add00f4bf 505 }
ocomeni 84:7c7add00f4bf 506 nxtPtr = strstr(nxtPtr, "\r\n")+2; // goto next line
ocomeni 84:7c7add00f4bf 507 if(nxtPtr >= p2) break;
ocomeni 84:7c7add00f4bf 508 }
ocomeni 90:ed0267eca7b5 509 // print header from http_req_struct
ocomeni 105:e5ce023eee93 510 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 511 dbg_printf(LOG, "\nhttp request header: \n %s\n", http_req->buffer);
ocomeni 105:e5ce023eee93 512 #endif
ocomeni 84:7c7add00f4bf 513 int bodyLen = edm_hdr.payloadLen -(p2+7-strPtr);
ocomeni 105:e5ce023eee93 514 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 515 dbg_printf(LOG, "\nLen = %d\n", bodyLen);
ocomeni 105:e5ce023eee93 516 #endif
ocomeni 118:8df0e9c2ee3f 517 uint32_t msecsSinceLastMsg = Kernel::get_ms_count() - lastHttpRespTime;
ocomeni 118:8df0e9c2ee3f 518 if((lastCloudMsgType == BAR_DB_MSGTYPE || lastCloudMsgType == REC_DB_MSGTYPE) &&
ocomeni 118:8df0e9c2ee3f 519 lastCloudMsgType == (uint8_t) bodyPtr[8] &&
ocomeni 118:8df0e9c2ee3f 520 (msecsSinceLastMsg < CLOUD_RETRY_TIME_MS ))
ocomeni 118:8df0e9c2ee3f 521 {
ocomeni 118:8df0e9c2ee3f 522 return false;
ocomeni 118:8df0e9c2ee3f 523 }
ocomeni 118:8df0e9c2ee3f 524 lastCloudMsgType = (uint8_t) bodyPtr[8]; // pick out the MSGTYPE byte from payload
ocomeni 90:ed0267eca7b5 525 http_req->body = (uint8_t *) outPtr;
ocomeni 90:ed0267eca7b5 526 memcpy(outPtr, bodyPtr, bodyLen);
ocomeni 90:ed0267eca7b5 527 if(bodyLen > 10){
ocomeni 103:7b566b522427 528 dbg_printf(LOG, "\n Message Body:\n");
ocomeni 90:ed0267eca7b5 529 printBufferInHex(http_req->body, bodyLen);
ocomeni 90:ed0267eca7b5 530 }
ocomeni 90:ed0267eca7b5 531 outPtr += bodyLen; // move output pointer to end output (header + body)
ocomeni 84:7c7add00f4bf 532 // package and send on wifi data queue
ocomeni 84:7c7add00f4bf 533 data_msg.wifi_cmd = WIFI_CMD_SEND_HTTPS_REQ;
ocomeni 105:e5ce023eee93 534 data_msg.dataLen = (uint8_t *)outPtr - http_req->buffer;//sizeof(http_request_t);
ocomeni 105:e5ce023eee93 535 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 536 dbg_printf(LOG, "\nsizeof(http_req) on population = %d\n", sizeof(*http_req));
ocomeni 103:7b566b522427 537 dbg_printf(LOG, "\ndata_msg.dataLen = %d\n", data_msg.dataLen);
ocomeni 105:e5ce023eee93 538 #endif
ocomeni 84:7c7add00f4bf 539 // queue next data request
ocomeni 104:11e9605093c9 540 if(queueWiFiDataRequest(data_msg) == true)
ocomeni 104:11e9605093c9 541 {
ocomeni 104:11e9605093c9 542 wifiStateControl = AT_HTTPS_RESP_DOWNLOAD;
ocomeni 110:c722dda4f2ff 543 return true;
ocomeni 104:11e9605093c9 544 }
ocomeni 118:8df0e9c2ee3f 545 return false;
ocomeni 84:7c7add00f4bf 546 }
ocomeni 74:f26e846adfe9 547 // OOB processing
ocomeni 74:f26e846adfe9 548 void ATCmdManager::_process_oob(uint32_t timeout, bool all){
ocomeni 74:f26e846adfe9 549 set_timeout(timeout);
ocomeni 84:7c7add00f4bf 550 int start;
ocomeni 83:9c271a50a70b 551 if(dataMode == AT_EXT_DATA_MODE)
ocomeni 83:9c271a50a70b 552 {
ocomeni 83:9c271a50a70b 553 int n;
ocomeni 84:7c7add00f4bf 554 uint8_t edm[EDM_HDR_LEN];
ocomeni 92:ec9550034276 555 char cmdType[16];
ocomeni 83:9c271a50a70b 556 // Poll for edm packets
ocomeni 83:9c271a50a70b 557 do{
ocomeni 92:ec9550034276 558 n = _parser.read((char *)edm, EDM_HDR_LEN-1);
ocomeni 84:7c7add00f4bf 559 edm_hdr.startByte = edm[0];
ocomeni 84:7c7add00f4bf 560 edm_hdr.payloadLen = edm[1]*256 + edm[2];
ocomeni 84:7c7add00f4bf 561 edm_hdr.payloadID = edm[3]*256 + edm[4];
ocomeni 92:ec9550034276 562 edm_hdr.channel_id = (channel_id_t) 0;
ocomeni 84:7c7add00f4bf 563 start = Kernel::get_ms_count();
ocomeni 83:9c271a50a70b 564 if(n == -1) break; // break if it times out
ocomeni 92:ec9550034276 565 int pT;
ocomeni 99:05398b3184f8 566 if(edm_hdr.payloadID < AT_REQUEST_ID) //
ocomeni 92:ec9550034276 567 {
ocomeni 92:ec9550034276 568 n += _parser.read((char *)edm, 1);
ocomeni 92:ec9550034276 569 edm_hdr.channel_id = (channel_id_t) edm[0];
ocomeni 92:ec9550034276 570 pT = 0;
ocomeni 92:ec9550034276 571 strcpy(cmdType, "DATA COMMAND");
ocomeni 92:ec9550034276 572 }
ocomeni 92:ec9550034276 573 else
ocomeni 92:ec9550034276 574 {
ocomeni 92:ec9550034276 575 pT = 1;
ocomeni 92:ec9550034276 576 strcpy(cmdType, "AT REQUEST");
ocomeni 92:ec9550034276 577 }
ocomeni 103:7b566b522427 578 dbg_printf(LOG, "%d bytes read! : CMD type = %s\n", n, cmdType);
ocomeni 92:ec9550034276 579 if(n==(EDM_HDR_LEN-pT))
ocomeni 103:7b566b522427 580 dbg_printf(LOG, "Start = %d, payloadID = %d len = %d chan_id = %d\n", edm_hdr.startByte,
ocomeni 90:ed0267eca7b5 581 edm_hdr.payloadID,
ocomeni 90:ed0267eca7b5 582 edm_hdr.payloadLen,
ocomeni 90:ed0267eca7b5 583 edm_hdr.channel_id);
ocomeni 92:ec9550034276 584 if(n == (EDM_HDR_LEN-pT) && validate(edm_hdr)) // if AT command use process oob to decode
ocomeni 83:9c271a50a70b 585 {
ocomeni 99:05398b3184f8 586 if(edm_hdr.payloadID == AT_REQUEST_ID)
ocomeni 83:9c271a50a70b 587 {
ocomeni 92:ec9550034276 588 while (_parser.process_oob() && all) {
ocomeni 92:ec9550034276 589 }
ocomeni 83:9c271a50a70b 590 break;
ocomeni 83:9c271a50a70b 591 }
ocomeni 83:9c271a50a70b 592 else
ocomeni 83:9c271a50a70b 593 {
ocomeni 92:ec9550034276 594 int pLen = edm_hdr.payloadLen-2-pT;
ocomeni 83:9c271a50a70b 595 rx_buf_ptr = (uint8_t *) malloc (pLen); // we already read 2 bytes from payload but expect 1 stop byte
ocomeni 83:9c271a50a70b 596 rx_buf_ptr[pLen-1] = 0x00; // clear last byte so the readback value is as expected
ocomeni 83:9c271a50a70b 597 n = _parser.read((char *)rx_buf_ptr, pLen);
ocomeni 118:8df0e9c2ee3f 598 if(n == -1)
ocomeni 118:8df0e9c2ee3f 599 {
ocomeni 118:8df0e9c2ee3f 600 dbg_printf(LOG, "Timeout while reading message payload bytes - expected %d!\r\n", pLen);
ocomeni 118:8df0e9c2ee3f 601 free(rx_buf_ptr); // make sure to free buffer
ocomeni 118:8df0e9c2ee3f 602 rx_buf_ptr = NULL;
ocomeni 119:8d939a902333 603 sendAtConfirmation(UART_TIMEOUT_ERROR);
ocomeni 118:8df0e9c2ee3f 604 break; // timeout!
ocomeni 118:8df0e9c2ee3f 605 }
ocomeni 103:7b566b522427 606 dbg_printf(LOG, "%d bytes read - expected %d!\n", n, pLen);
ocomeni 89:45f6db09a76d 607 printBufferInHex(rx_buf_ptr, pLen);
ocomeni 103:7b566b522427 608 dbg_printf(LOG, "rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]);
ocomeni 83:9c271a50a70b 609 if(rx_buf_ptr[pLen-1] != EDM_STOP_BYTE) {
ocomeni 90:ed0267eca7b5 610 _smutex.lock();
ocomeni 90:ed0267eca7b5 611 _parser.send("ERR");
ocomeni 90:ed0267eca7b5 612 _smutex.unlock();
ocomeni 97:0aa46e5ef15d 613 free(rx_buf_ptr); // make sure to free buffer
ocomeni 97:0aa46e5ef15d 614 rx_buf_ptr = NULL;
ocomeni 90:ed0267eca7b5 615 break; // exit if stop byte not found - possible data corruption!
ocomeni 83:9c271a50a70b 616 }
ocomeni 83:9c271a50a70b 617 switch(edm_hdr.payloadID)
ocomeni 83:9c271a50a70b 618 {
ocomeni 99:05398b3184f8 619 case CONNECT_EVENT_ID:
ocomeni 103:7b566b522427 620 dbg_printf(LOG, "Connection Event received!\n");
ocomeni 83:9c271a50a70b 621 break;
ocomeni 99:05398b3184f8 622 case DISCONNECT_EVENT_ID:
ocomeni 103:7b566b522427 623 dbg_printf(LOG, "DISCONNECT_EVENT received!\n");
ocomeni 83:9c271a50a70b 624 break;
ocomeni 99:05398b3184f8 625 case DATA_EVENT_ID:
ocomeni 103:7b566b522427 626 dbg_printf(LOG, "DATA_EVENT received!\n");
ocomeni 83:9c271a50a70b 627 break;
ocomeni 99:05398b3184f8 628 case DATA_COMMAND_ID:
ocomeni 98:65c2333a38b6 629 {
ocomeni 103:7b566b522427 630 dbg_printf(LOG, "DATA_COMMAND received!\n");
ocomeni 108:3c8fb2c6e7bf 631 if(createHttpRequest() == false)
ocomeni 108:3c8fb2c6e7bf 632 {
ocomeni 109:c274780ff609 633 #ifdef SEND_DEBUG_MESSAGES
ocomeni 104:11e9605093c9 634 sendAtConfirmation(WIFI_BUSY_RESP);
ocomeni 109:c274780ff609 635 #endif
ocomeni 84:7c7add00f4bf 636 }
ocomeni 92:ec9550034276 637 free(rx_buf_ptr);
ocomeni 96:f5ed273881af 638 rx_buf_ptr = NULL;
ocomeni 84:7c7add00f4bf 639 int stop = Kernel::get_ms_count();
ocomeni 103:7b566b522427 640 dbg_printf(LOG, "\n Time Elapsed = %d\n", stop-start);
ocomeni 83:9c271a50a70b 641 break;
ocomeni 98:65c2333a38b6 642 }
ocomeni 99:05398b3184f8 643 case AT_REQUEST_ID:
ocomeni 103:7b566b522427 644 dbg_printf(LOG, "AT_REQUEST received!\n");
ocomeni 83:9c271a50a70b 645 break;
ocomeni 99:05398b3184f8 646 case AT_CONFIRMATION_ID:
ocomeni 103:7b566b522427 647 dbg_printf(LOG, "AT_CONFIRMATION received!\n");
ocomeni 83:9c271a50a70b 648 break;
ocomeni 99:05398b3184f8 649 case AT_EVENT_ID:
ocomeni 103:7b566b522427 650 dbg_printf(LOG, "AT_EVENT received!\n");
ocomeni 83:9c271a50a70b 651 break;
ocomeni 83:9c271a50a70b 652 default:
ocomeni 103:7b566b522427 653 dbg_printf(LOG, "UNKNOWN MESSAGE received!\n");
ocomeni 83:9c271a50a70b 654 break;
ocomeni 83:9c271a50a70b 655 }
ocomeni 83:9c271a50a70b 656 }
ocomeni 83:9c271a50a70b 657 }
ocomeni 83:9c271a50a70b 658 else // incorrect # of bytes received abort!!
ocomeni 83:9c271a50a70b 659 {
ocomeni 83:9c271a50a70b 660 break;
ocomeni 83:9c271a50a70b 661 }
ocomeni 83:9c271a50a70b 662 }while (all); // continue to process until timeout
ocomeni 74:f26e846adfe9 663 }
ocomeni 83:9c271a50a70b 664 else
ocomeni 83:9c271a50a70b 665 {
ocomeni 83:9c271a50a70b 666 // Poll for inbound packets
ocomeni 112:a0999ea4ece0 667 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 668 static char * ATCMD = new char[32];
ocomeni 103:7b566b522427 669 int n = 0;
ocomeni 103:7b566b522427 670 if(check_for_at_cmd)
ocomeni 103:7b566b522427 671 {
ocomeni 103:7b566b522427 672 while (n>=0 && all) {
ocomeni 103:7b566b522427 673 n = readAtCommandString(ATCMD, 32);
ocomeni 103:7b566b522427 674 if(strstr(ATCMD,"AT\r") != NULL)
ocomeni 103:7b566b522427 675 {
ocomeni 103:7b566b522427 676 _oob_ok_hdlr();
ocomeni 103:7b566b522427 677 check_for_at_cmd = false;
ocomeni 103:7b566b522427 678 break;
ocomeni 103:7b566b522427 679 }
ocomeni 103:7b566b522427 680 }
ocomeni 103:7b566b522427 681 }
ocomeni 103:7b566b522427 682 else
ocomeni 103:7b566b522427 683 #endif
ocomeni 103:7b566b522427 684 {
ocomeni 83:9c271a50a70b 685 while (_parser.process_oob() && all) {
ocomeni 110:c722dda4f2ff 686 }
ocomeni 103:7b566b522427 687 }
ocomeni 83:9c271a50a70b 688 }
ocomeni 74:f26e846adfe9 689 set_timeout();
ocomeni 74:f26e846adfe9 690 }
ocomeni 74:f26e846adfe9 691
ocomeni 74:f26e846adfe9 692
ocomeni 103:7b566b522427 693 int ATCmdManager::readAtCommandString(char *strbuf, size_t bufLen)
ocomeni 103:7b566b522427 694 {
ocomeni 103:7b566b522427 695 int n;
ocomeni 103:7b566b522427 696 bool atstr_found = false;
ocomeni 103:7b566b522427 697 int i = 0;
ocomeni 103:7b566b522427 698 while(n != -1)
ocomeni 103:7b566b522427 699 {
ocomeni 103:7b566b522427 700 char c;
ocomeni 103:7b566b522427 701 n = _parser.read(&c, 1);
ocomeni 103:7b566b522427 702 if(n)
ocomeni 103:7b566b522427 703 strbuf[i++] = c;
ocomeni 103:7b566b522427 704 if(c=='\r')
ocomeni 103:7b566b522427 705 {
ocomeni 103:7b566b522427 706 strbuf[i++] = NULL; // terminate string and exit
ocomeni 103:7b566b522427 707 atstr_found = true;
ocomeni 103:7b566b522427 708 break;
ocomeni 103:7b566b522427 709 }
ocomeni 103:7b566b522427 710 }
ocomeni 103:7b566b522427 711 if(atstr_found)
ocomeni 103:7b566b522427 712 {
ocomeni 103:7b566b522427 713 return i;
ocomeni 103:7b566b522427 714 }
ocomeni 103:7b566b522427 715 else
ocomeni 103:7b566b522427 716 {
ocomeni 103:7b566b522427 717 return -1;
ocomeni 103:7b566b522427 718 }
ocomeni 103:7b566b522427 719 }
ocomeni 103:7b566b522427 720
ocomeni 74:f26e846adfe9 721 // OOB message handlers
ocomeni 74:f26e846adfe9 722 void ATCmdManager::_oob_startup_hdlr(){
ocomeni 74:f26e846adfe9 723 }
ocomeni 74:f26e846adfe9 724
ocomeni 81:637a87eb8170 725 void ATCmdManager::_oob_ok_hdlr(){
ocomeni 95:290859010c8c 726 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 81:637a87eb8170 727 }
ocomeni 81:637a87eb8170 728
ocomeni 74:f26e846adfe9 729
ocomeni 74:f26e846adfe9 730 void ATCmdManager::_oob_bleRole_hdlr(){
ocomeni 74:f26e846adfe9 731 }
ocomeni 74:f26e846adfe9 732
ocomeni 74:f26e846adfe9 733
ocomeni 74:f26e846adfe9 734 void ATCmdManager::_oob_wifiMode_err(){
ocomeni 74:f26e846adfe9 735 }
ocomeni 74:f26e846adfe9 736
ocomeni 74:f26e846adfe9 737
ocomeni 74:f26e846adfe9 738 void ATCmdManager::_oob_conn_already(){
ocomeni 74:f26e846adfe9 739 }
ocomeni 74:f26e846adfe9 740
ocomeni 114:b11bb96c09f3 741 void ATCmdManager::_oob_enable_wifi()
ocomeni 114:b11bb96c09f3 742 {
ocomeni 114:b11bb96c09f3 743 trigger_start_WiFi();
ocomeni 114:b11bb96c09f3 744 sendAtConfirmation(OK_RESP);
ocomeni 114:b11bb96c09f3 745 }
ocomeni 74:f26e846adfe9 746
ocomeni 74:f26e846adfe9 747 void ATCmdManager::_oob_err(){
ocomeni 74:f26e846adfe9 748 }
ocomeni 74:f26e846adfe9 749
ocomeni 79:a2187bbfa407 750 void ATCmdManager::_oob_get_fw_ver()
ocomeni 79:a2187bbfa407 751 {
ocomeni 102:9748f290a1a5 752 #ifdef MBED_MAJOR_VERSION
ocomeni 102:9748f290a1a5 753 char * fw_ver_str = new char[20];
ocomeni 102:9748f290a1a5 754 sprintf(fw_ver_str, "Mbed OS version %d.%d.%d.0\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
ocomeni 102:9748f290a1a5 755 sendAtConfirmation(fw_ver_str);
ocomeni 102:9748f290a1a5 756 delete fw_ver_str;
ocomeni 102:9748f290a1a5 757 #endif
ocomeni 79:a2187bbfa407 758 }
ocomeni 79:a2187bbfa407 759
ocomeni 103:7b566b522427 760 #define TTP_DEBUGGING
ocomeni 107:f1a83fd41b17 761 #define TTP_DEBUGGING_UART_NOCHANGE
ocomeni 75:08eff6258e1b 762 void ATCmdManager::_oob_uart_setup(){
ocomeni 75:08eff6258e1b 763 int uOpts[NUM_UART_OPTIONS];
ocomeni 75:08eff6258e1b 764 if(_parser.scanf("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5]) >0) {
ocomeni 103:7b566b522427 765 dbg_printf(LOG, "\nATCmdParser: Uart Options=%d,%d,%d,%d,%d,%d\n", uOpts[0], uOpts[1], uOpts[2], uOpts[3], uOpts[4], uOpts[5]);
ocomeni 103:7b566b522427 766 dbg_printf(LOG, "\n Changing Baud Rate to %d\n", uOpts[0]);
ocomeni 107:f1a83fd41b17 767 #ifdef TTP_DEBUGGING_UART_NOCHANGE
ocomeni 103:7b566b522427 768 sendAtConfirmation(OK_RESP);
ocomeni 103:7b566b522427 769 #else
ocomeni 81:637a87eb8170 770
ocomeni 95:290859010c8c 771 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 81:637a87eb8170 772 _serial.set_baud(uOpts[0]);
ocomeni 92:ec9550034276 773 wait(0.1);
ocomeni 103:7b566b522427 774 dbg_printf(LOG, "\n Baud Rate now %d\n", uOpts[0]);
ocomeni 103:7b566b522427 775 #endif
ocomeni 103:7b566b522427 776 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 777 check_for_at_cmd = true;
ocomeni 103:7b566b522427 778 #endif
ocomeni 81:637a87eb8170 779
ocomeni 75:08eff6258e1b 780 } else {
ocomeni 103:7b566b522427 781 dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed");
ocomeni 75:08eff6258e1b 782 }
ocomeni 75:08eff6258e1b 783 }
ocomeni 75:08eff6258e1b 784
ocomeni 74:f26e846adfe9 785 void ATCmdManager::set_timeout(uint32_t timeout_ms)
ocomeni 74:f26e846adfe9 786 {
ocomeni 74:f26e846adfe9 787 _parser.set_timeout(timeout_ms);
ocomeni 74:f26e846adfe9 788 }
ocomeni 74:f26e846adfe9 789
ocomeni 75:08eff6258e1b 790
ocomeni 75:08eff6258e1b 791 void ATCmdManager::_oob_echo_off()
ocomeni 75:08eff6258e1b 792 {
ocomeni 103:7b566b522427 793 dbg_printf(LOG, "\n Received ATEO OOB command!!\n");
ocomeni 103:7b566b522427 794 dbg_printf(LOG, "\n turning echo OFF!!\n");
ocomeni 75:08eff6258e1b 795 _parser.debug_on(false);
ocomeni 95:290859010c8c 796 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 797 }
ocomeni 75:08eff6258e1b 798
ocomeni 75:08eff6258e1b 799
ocomeni 75:08eff6258e1b 800 void ATCmdManager::_oob_echo_on()
ocomeni 75:08eff6258e1b 801 {
ocomeni 103:7b566b522427 802 dbg_printf(LOG, "\n Received ATE1 OOB command!!\n");
ocomeni 103:7b566b522427 803 dbg_printf(LOG, "\n turning echo ON!!\n");
ocomeni 75:08eff6258e1b 804 _parser.debug_on(true);
ocomeni 95:290859010c8c 805 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 806 }
ocomeni 75:08eff6258e1b 807
ocomeni 75:08eff6258e1b 808
ocomeni 118:8df0e9c2ee3f 809
ocomeni 118:8df0e9c2ee3f 810 void ATCmdManager::_oob_debug_logs_on()
ocomeni 118:8df0e9c2ee3f 811 {
ocomeni 118:8df0e9c2ee3f 812 initialise_debug(LOG | ERR | TXT | DBG);
ocomeni 118:8df0e9c2ee3f 813 dbg_printf(LOG, "\n Received ATE2 OOB command!!\n");
ocomeni 118:8df0e9c2ee3f 814 dbg_printf(LOG, "\n debug logs ON!!\n");
ocomeni 118:8df0e9c2ee3f 815 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 118:8df0e9c2ee3f 816 }
ocomeni 118:8df0e9c2ee3f 817
ocomeni 118:8df0e9c2ee3f 818 void ATCmdManager::_oob_debug_logs_off()
ocomeni 118:8df0e9c2ee3f 819 {
ocomeni 118:8df0e9c2ee3f 820 dbg_printf(LOG, "\n Received ATE3 OOB command!!\n");
ocomeni 118:8df0e9c2ee3f 821 dbg_printf(LOG, "\n turning debug logs OFF!!\n");
ocomeni 118:8df0e9c2ee3f 822 initialise_debug(NONE);
ocomeni 118:8df0e9c2ee3f 823 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 118:8df0e9c2ee3f 824 }
ocomeni 118:8df0e9c2ee3f 825
ocomeni 75:08eff6258e1b 826 void ATCmdManager::_oob_data_mode(){
ocomeni 103:7b566b522427 827 dbg_printf(LOG, "\n Received EDM mode command!!\n");
ocomeni 103:7b566b522427 828 int dmode;
ocomeni 103:7b566b522427 829 if(_parser.scanf("%d", &dmode) >0) {
ocomeni 103:7b566b522427 830 dbg_printf(LOG, "\nATCmdParser: Data mode=%d\r\n", dataMode);
ocomeni 96:f5ed273881af 831 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 103:7b566b522427 832 switch(dmode)
ocomeni 75:08eff6258e1b 833 {
ocomeni 75:08eff6258e1b 834 case 0:
ocomeni 103:7b566b522427 835 dbg_printf(LOG, "\nATCmdParser: Command Mode request received\n");
ocomeni 81:637a87eb8170 836 dataMode = AT_CMD_DATA_MODE;
ocomeni 75:08eff6258e1b 837 break;
ocomeni 75:08eff6258e1b 838 case 1:
ocomeni 103:7b566b522427 839 dbg_printf(LOG, "\nATCmdParser: Data Mode request received\n");
ocomeni 81:637a87eb8170 840 dataMode = AT_STD_DATA_MODE;
ocomeni 75:08eff6258e1b 841 break;
ocomeni 75:08eff6258e1b 842 case 2:
ocomeni 103:7b566b522427 843 dbg_printf(LOG, "\nATCmdParser: Extended data Mode request received\n");
ocomeni 81:637a87eb8170 844 dataMode = AT_EXT_DATA_MODE;
ocomeni 98:65c2333a38b6 845 _event_queue.call_in(10, &print_heap_and_isr_stack_info);
ocomeni 98:65c2333a38b6 846 //print_heap_and_isr_stack_info();
ocomeni 75:08eff6258e1b 847 break;
ocomeni 75:08eff6258e1b 848 default:
ocomeni 103:7b566b522427 849 dbg_printf(LOG, "\nATCmdParser: ERROR - UNKNOWN DATA MODE RECEIVED!!! \n");
ocomeni 75:08eff6258e1b 850 break;
ocomeni 75:08eff6258e1b 851 }
ocomeni 75:08eff6258e1b 852 } else {
ocomeni 103:7b566b522427 853 dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed\n");
ocomeni 75:08eff6258e1b 854 }
ocomeni 75:08eff6258e1b 855 }
ocomeni 75:08eff6258e1b 856
ocomeni 75:08eff6258e1b 857 void ATCmdManager::_oob_get_mac_addr(){
ocomeni 75:08eff6258e1b 858 int bleOrWifi;
ocomeni 75:08eff6258e1b 859 if(_parser.scanf("=%d", &bleOrWifi) >0) {
ocomeni 75:08eff6258e1b 860 switch(bleOrWifi)
ocomeni 75:08eff6258e1b 861 {
ocomeni 75:08eff6258e1b 862 case 1:
ocomeni 103:7b566b522427 863 dbg_printf(LOG, "\nATCmdParser: BLE MAC Address request received");
ocomeni 75:08eff6258e1b 864 break;
ocomeni 75:08eff6258e1b 865 case 2:
ocomeni 103:7b566b522427 866 dbg_printf(LOG, "\nATCmdParser: WiFi MAC Address request received");
ocomeni 75:08eff6258e1b 867 break;
ocomeni 75:08eff6258e1b 868 default:
ocomeni 103:7b566b522427 869 dbg_printf(LOG, "\nATCmdParser: ERROR - UNKNOWN MAC ADDRESS REQUEST RECEIVED!!! \n");
ocomeni 75:08eff6258e1b 870 break;
ocomeni 75:08eff6258e1b 871 }
ocomeni 75:08eff6258e1b 872 } else {
ocomeni 103:7b566b522427 873 dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed");
ocomeni 75:08eff6258e1b 874 }
ocomeni 95:290859010c8c 875 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 876 }
ocomeni 75:08eff6258e1b 877
ocomeni 75:08eff6258e1b 878 void ATCmdManager::_oob_get_ble_role(){
ocomeni 118:8df0e9c2ee3f 879 trigger_start_BLE();
ocomeni 103:7b566b522427 880 dbg_printf(LOG, "\n Received get BLE role command!!\n");
ocomeni 121:ac4f59839e4f 881 if(startup_config->ble_enable)
ocomeni 121:ac4f59839e4f 882 {
ocomeni 121:ac4f59839e4f 883 sendAtConfirmation("+UBTLE:2\r\nOK\r\n"); //_parser.send(OK_RESP);
ocomeni 121:ac4f59839e4f 884 }
ocomeni 121:ac4f59839e4f 885 else // disabled
ocomeni 121:ac4f59839e4f 886 {
ocomeni 121:ac4f59839e4f 887 sendAtConfirmation("+UBTLE:0\r\nOK\r\n"); //_parser.send(OK_RESP);
ocomeni 121:ac4f59839e4f 888 }
ocomeni 75:08eff6258e1b 889 }
ocomeni 75:08eff6258e1b 890
ocomeni 75:08eff6258e1b 891 void ATCmdManager::_oob_ena_ble_peri(){
ocomeni 103:7b566b522427 892 dbg_printf(LOG, "\n Received enable BLE Peripheral command!!\n");
ocomeni 121:ac4f59839e4f 893 startup_config->ble_enable = true;
ocomeni 95:290859010c8c 894 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 895 }
ocomeni 75:08eff6258e1b 896
ocomeni 75:08eff6258e1b 897 void ATCmdManager::_oob_reboot(){
ocomeni 103:7b566b522427 898 dbg_printf(LOG, "\n Received reboot command!!\n");
ocomeni 95:290859010c8c 899 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 900 system_reset();
ocomeni 75:08eff6258e1b 901 }
ocomeni 75:08eff6258e1b 902
ocomeni 121:ac4f59839e4f 903
ocomeni 121:ac4f59839e4f 904 void ATCmdManager::_oob_factoryReset(){
ocomeni 121:ac4f59839e4f 905 dbg_printf(LOG, "\n Received factory reset command!!\n");
ocomeni 121:ac4f59839e4f 906 resetConfiguration();
ocomeni 121:ac4f59839e4f 907 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 121:ac4f59839e4f 908 }
ocomeni 121:ac4f59839e4f 909
ocomeni 121:ac4f59839e4f 910
ocomeni 121:ac4f59839e4f 911 void ATCmdManager::_oob_deleteConfiguration(){
ocomeni 121:ac4f59839e4f 912 dbg_printf(LOG, "\n Received delete configuration command!!\n");
ocomeni 121:ac4f59839e4f 913 int configKey;
ocomeni 121:ac4f59839e4f 914 bool res = false;
ocomeni 121:ac4f59839e4f 915 if(_parser.scanf("%d", &configKey) >0)
ocomeni 121:ac4f59839e4f 916 {
ocomeni 121:ac4f59839e4f 917 res = deleteConfiguration((nvstore_key_t) configKey);
ocomeni 121:ac4f59839e4f 918 }
ocomeni 121:ac4f59839e4f 919 if(res)
ocomeni 121:ac4f59839e4f 920 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 121:ac4f59839e4f 921 }
ocomeni 121:ac4f59839e4f 922
ocomeni 121:ac4f59839e4f 923
ocomeni 121:ac4f59839e4f 924
ocomeni 121:ac4f59839e4f 925 void ATCmdManager::_oob_saveSettings_hdlr()
ocomeni 121:ac4f59839e4f 926 {
ocomeni 121:ac4f59839e4f 927 saveConfiguration(APP_CONFIG_0);
ocomeni 121:ac4f59839e4f 928 sendAtConfirmation(OK_RESP);
ocomeni 121:ac4f59839e4f 929 }
ocomeni 79:a2187bbfa407 930 const char * ATCmdManager::sec2str(nsapi_security_t sec)
ocomeni 79:a2187bbfa407 931 {
ocomeni 79:a2187bbfa407 932 switch (sec) {
ocomeni 79:a2187bbfa407 933 case NSAPI_SECURITY_NONE:
ocomeni 79:a2187bbfa407 934 return "None";
ocomeni 79:a2187bbfa407 935 case NSAPI_SECURITY_WEP:
ocomeni 79:a2187bbfa407 936 return "WEP";
ocomeni 79:a2187bbfa407 937 case NSAPI_SECURITY_WPA:
ocomeni 79:a2187bbfa407 938 return "WPA";
ocomeni 79:a2187bbfa407 939 case NSAPI_SECURITY_WPA2:
ocomeni 79:a2187bbfa407 940 return "WPA2";
ocomeni 79:a2187bbfa407 941 case NSAPI_SECURITY_WPA_WPA2:
ocomeni 79:a2187bbfa407 942 return "WPA/WPA2";
ocomeni 79:a2187bbfa407 943 case NSAPI_SECURITY_UNKNOWN:
ocomeni 79:a2187bbfa407 944 default:
ocomeni 79:a2187bbfa407 945 return "Unknown";
ocomeni 79:a2187bbfa407 946 }
ocomeni 79:a2187bbfa407 947 }
ocomeni 81:637a87eb8170 948
ocomeni 81:637a87eb8170 949 bool ATCmdManager::setNextResponse(at_cmd_resp_t resp)
ocomeni 81:637a87eb8170 950 {
ocomeni 81:637a87eb8170 951 if(at_resp == AT_RESP_NONE){
ocomeni 81:637a87eb8170 952 at_resp = resp;
ocomeni 81:637a87eb8170 953 return true; // success
ocomeni 81:637a87eb8170 954 }
ocomeni 81:637a87eb8170 955 return false; // wiFiManager busy
ocomeni 79:a2187bbfa407 956 }
ocomeni 79:a2187bbfa407 957
ocomeni 81:637a87eb8170 958
ocomeni 79:a2187bbfa407 959 void ATCmdManager::_oob_scanWiFiNetworks(){
ocomeni 103:7b566b522427 960 dbg_printf(LOG, "\n Received scanWiFiNetworks command!!\n");
ocomeni 95:290859010c8c 961 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 79:a2187bbfa407 962 wifi_cmd_t cmd = WIFI_CMD_SCAN;
ocomeni 79:a2187bbfa407 963 // queue next command
ocomeni 79:a2187bbfa407 964 queueWiFiCommand(cmd);
ocomeni 81:637a87eb8170 965 return;
ocomeni 75:08eff6258e1b 966 }
ocomeni 75:08eff6258e1b 967
ocomeni 95:290859010c8c 968
ocomeni 95:290859010c8c 969
ocomeni 98:65c2333a38b6 970 void ATCmdManager::_oob_WiFiStationConfigAction()
ocomeni 79:a2187bbfa407 971 {
ocomeni 98:65c2333a38b6 972 int if_id; // interface id for request
ocomeni 98:65c2333a38b6 973 int aId; // interface id for request
ocomeni 98:65c2333a38b6 974 _parser.recv("%d,%d", &if_id, &aId);
ocomeni 103:7b566b522427 975 dbg_printf(LOG, "\n Received WiFi Configuration Action command %d %d!!\r\n", if_id, aId);
ocomeni 98:65c2333a38b6 976 if(if_id == WIFI_CONFIG_ID && aId <5){
ocomeni 95:290859010c8c 977 wifi_cmd_t cmd;
ocomeni 98:65c2333a38b6 978 action_id_t action_id = (action_id_t) aId;
ocomeni 95:290859010c8c 979 switch(action_id){
ocomeni 95:290859010c8c 980 case WIFI_CONFIG_RESET:
ocomeni 95:290859010c8c 981 break;
ocomeni 95:290859010c8c 982 case WIFI_CONFIG_STORE:
ocomeni 95:290859010c8c 983 break;
ocomeni 95:290859010c8c 984 case WIFI_CONFIG_LOAD:
ocomeni 95:290859010c8c 985 break;
ocomeni 95:290859010c8c 986 case WIFI_CONFIG_ACTIVATE:
ocomeni 95:290859010c8c 987 cmd = WIFI_CMD_CONNECT;
ocomeni 103:7b566b522427 988 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd);
ocomeni 95:290859010c8c 989 queueWiFiCommand(cmd);
ocomeni 95:290859010c8c 990 break;
ocomeni 95:290859010c8c 991 case WIFI_CONFIG_DEACTIVATE:
ocomeni 95:290859010c8c 992 cmd = WIFI_CMD_DISCONNECT;
ocomeni 103:7b566b522427 993 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd);
ocomeni 95:290859010c8c 994 queueWiFiCommand(cmd);
ocomeni 95:290859010c8c 995 break;
ocomeni 95:290859010c8c 996 default:
ocomeni 95:290859010c8c 997 break;
ocomeni 95:290859010c8c 998 }
ocomeni 95:290859010c8c 999 }
ocomeni 81:637a87eb8170 1000 return;
ocomeni 79:a2187bbfa407 1001 }
ocomeni 79:a2187bbfa407 1002
ocomeni 79:a2187bbfa407 1003
ocomeni 79:a2187bbfa407 1004 void ATCmdManager::_oob_disconnectWiFiNetwork()
ocomeni 79:a2187bbfa407 1005 {
ocomeni 103:7b566b522427 1006 dbg_printf(LOG, "\n Received WiFi Disconnect command!!\n");
ocomeni 95:290859010c8c 1007 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 81:637a87eb8170 1008 wifi_cmd_t cmd = WIFI_CMD_DISCONNECT;
ocomeni 81:637a87eb8170 1009 queueWiFiCommand(cmd);
ocomeni 81:637a87eb8170 1010 return;
ocomeni 81:637a87eb8170 1011 }
ocomeni 81:637a87eb8170 1012
ocomeni 81:637a87eb8170 1013 void ATCmdManager::_oob_setupInternetConnection()
ocomeni 81:637a87eb8170 1014 {
ocomeni 90:ed0267eca7b5 1015 char str[MAX_URL_LEN];
ocomeni 90:ed0267eca7b5 1016 char url[MAX_URL_LEN];
ocomeni 81:637a87eb8170 1017 int n;
ocomeni 81:637a87eb8170 1018 internet_config_t internet_config;
ocomeni 103:7b566b522427 1019 dbg_printf(LOG, "sizeof internet_config_t = %d\n", sizeof(internet_config_t));
ocomeni 90:ed0267eca7b5 1020 n = ReadBytes((uint8_t *)str, MAX_URL_LEN);
ocomeni 84:7c7add00f4bf 1021 str[n]=NULL;
ocomeni 112:a0999ea4ece0 1022 int id;
ocomeni 112:a0999ea4ece0 1023 int scheme;
ocomeni 103:7b566b522427 1024 dbg_printf(LOG, "\n read string = %s , n = %d\n", str, n);
ocomeni 112:a0999ea4ece0 1025 n = sscanf(str, "=%1d,%99[^,],%1d", &id,
ocomeni 92:ec9550034276 1026 url, //internet_config.url,
ocomeni 112:a0999ea4ece0 1027 &scheme);
ocomeni 112:a0999ea4ece0 1028 internet_config.peer_id = (uint8_t) id;
ocomeni 112:a0999ea4ece0 1029 internet_config.connectionScheme = (conn_scheme_t) scheme;
ocomeni 103:7b566b522427 1030 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 1031 char *p = strstr(url,"/https:");
ocomeni 103:7b566b522427 1032 #else
ocomeni 92:ec9550034276 1033 char *p = strstr(url,"\"");
ocomeni 103:7b566b522427 1034 #endif
ocomeni 92:ec9550034276 1035 if(p!=NULL)
ocomeni 92:ec9550034276 1036 {
ocomeni 92:ec9550034276 1037 strncpy(internet_config.url, &p[1], strlen(url));
ocomeni 92:ec9550034276 1038 p = strstr(internet_config.url,"\"");
ocomeni 92:ec9550034276 1039 *p = NULL;
ocomeni 92:ec9550034276 1040 }
ocomeni 92:ec9550034276 1041 else
ocomeni 92:ec9550034276 1042 {
ocomeni 92:ec9550034276 1043 strncpy(internet_config.url, url, strlen(url)+1);
ocomeni 92:ec9550034276 1044 }
ocomeni 103:7b566b522427 1045 dbg_printf(LOG, "\n read string = %s , n = %d -- strlen(url) = %d\n", internet_config.url, n, strlen(internet_config.url));
ocomeni 81:637a87eb8170 1046 if(n>0)
ocomeni 81:637a87eb8170 1047 {
ocomeni 103:7b566b522427 1048 dbg_printf(LOG, "peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id,
ocomeni 90:ed0267eca7b5 1049 internet_config.url,
ocomeni 90:ed0267eca7b5 1050 internet_config.connectionScheme);
ocomeni 81:637a87eb8170 1051 // package and send on wifi data queue
ocomeni 90:ed0267eca7b5 1052 wifi_data_msg_t data_msg;
ocomeni 81:637a87eb8170 1053 data_msg.wifi_cmd = WIFI_CMD_INTERNET_CONFIG;
ocomeni 84:7c7add00f4bf 1054 data_msg.dataLen = sizeof(internet_config_t); // + strlen(internet_config.url);
ocomeni 103:7b566b522427 1055 dbg_printf(LOG, "\n url size = %d url str = %s\n",strlen(internet_config.url), internet_config.url );
ocomeni 81:637a87eb8170 1056 memcpy(data_msg.buffer,&internet_config, data_msg.dataLen);
ocomeni 82:10072c1794d3 1057 // queue next data request
ocomeni 81:637a87eb8170 1058 queueWiFiDataRequest(data_msg);
ocomeni 84:7c7add00f4bf 1059 print_memory_info();
ocomeni 81:637a87eb8170 1060 } else {
ocomeni 103:7b566b522427 1061 dbg_printf(LOG, "\n[ATCMD MAN]: internet configuration failed %d fields parsed \r\n", n);
ocomeni 82:10072c1794d3 1062 _parser.send("NAK\n");
ocomeni 82:10072c1794d3 1063 }
ocomeni 82:10072c1794d3 1064 }
ocomeni 82:10072c1794d3 1065
ocomeni 82:10072c1794d3 1066 wifi_config_t ATCmdManager::init_wifi_config()
ocomeni 82:10072c1794d3 1067 {
ocomeni 82:10072c1794d3 1068 wifi_config_t wifi_cfg;
ocomeni 82:10072c1794d3 1069 wifi_cfg.ssid[0] = NULL;
ocomeni 82:10072c1794d3 1070 wifi_cfg.pass[0] = NULL;
ocomeni 82:10072c1794d3 1071 wifi_cfg.security = NSAPI_SECURITY_UNKNOWN;
ocomeni 82:10072c1794d3 1072 return wifi_cfg;
ocomeni 82:10072c1794d3 1073 }
ocomeni 112:a0999ea4ece0 1074
ocomeni 83:9c271a50a70b 1075 /* read ASCII characters into buffer and null terminate */
ocomeni 83:9c271a50a70b 1076 int ATCmdManager::readStringBytes(uint8_t *buf, int maxBytes)
ocomeni 82:10072c1794d3 1077 {
ocomeni 82:10072c1794d3 1078 int c;
ocomeni 82:10072c1794d3 1079 int sptr = 0;
ocomeni 93:06e755a80187 1080 int quoteCnt = 0;
ocomeni 82:10072c1794d3 1081 for(int i=0;i<maxBytes;i++){
ocomeni 82:10072c1794d3 1082 c = _parser.getc();
ocomeni 93:06e755a80187 1083 if(c== '"')quoteCnt++;
ocomeni 93:06e755a80187 1084 if(c==-1 || quoteCnt==2){
ocomeni 83:9c271a50a70b 1085 buf[sptr] = NULL; // null terminate if string
ocomeni 82:10072c1794d3 1086 return i;
ocomeni 82:10072c1794d3 1087 }
ocomeni 82:10072c1794d3 1088 if(c != ',' && c!= '"'){
ocomeni 82:10072c1794d3 1089 buf[sptr++] = (uint8_t) c;
ocomeni 82:10072c1794d3 1090 }
ocomeni 81:637a87eb8170 1091 }
ocomeni 83:9c271a50a70b 1092 return maxBytes;
ocomeni 83:9c271a50a70b 1093 }
ocomeni 83:9c271a50a70b 1094
ocomeni 83:9c271a50a70b 1095 int ATCmdManager::ReadBytes(uint8_t *buf, int maxBytes)
ocomeni 83:9c271a50a70b 1096 {
ocomeni 83:9c271a50a70b 1097 int c;
ocomeni 83:9c271a50a70b 1098 int sptr = 0;
ocomeni 83:9c271a50a70b 1099 for(int i=0;i<maxBytes;i++){
ocomeni 83:9c271a50a70b 1100 c = _parser.getc();
ocomeni 83:9c271a50a70b 1101 if(c==-1){
ocomeni 83:9c271a50a70b 1102 return i;
ocomeni 83:9c271a50a70b 1103 }
ocomeni 83:9c271a50a70b 1104 buf[sptr++] = (uint8_t) c;
ocomeni 83:9c271a50a70b 1105 }
ocomeni 83:9c271a50a70b 1106 return maxBytes;
ocomeni 82:10072c1794d3 1107 }
ocomeni 82:10072c1794d3 1108
ocomeni 82:10072c1794d3 1109 void ATCmdManager::_oob_setWiFiSSID()
ocomeni 82:10072c1794d3 1110 {
ocomeni 82:10072c1794d3 1111 int n;
ocomeni 82:10072c1794d3 1112 wifi_config_t wifi_cfg = init_wifi_config();
ocomeni 83:9c271a50a70b 1113 n = readStringBytes((uint8_t *)wifi_cfg.ssid, 32);
ocomeni 103:7b566b522427 1114 dbg_printf(LOG, "[ATCMD MAN]: number of bytes read = %d\n", n);
ocomeni 82:10072c1794d3 1115 if(n>0)
ocomeni 82:10072c1794d3 1116 {
ocomeni 103:7b566b522427 1117 dbg_printf(LOG, "[ATCMD MAN]: wifi_cfg.ssid = %s\n", wifi_cfg.ssid);
ocomeni 82:10072c1794d3 1118 // package and send on wifi data queue
ocomeni 82:10072c1794d3 1119 wifi_data_msg_t data_msg;
ocomeni 82:10072c1794d3 1120 data_msg.wifi_cmd = WIFI_CMD_CONFIG;
ocomeni 82:10072c1794d3 1121 data_msg.dataLen = sizeof(wifi_config_t);
ocomeni 82:10072c1794d3 1122 memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
ocomeni 82:10072c1794d3 1123 queueWiFiDataRequest(data_msg);
ocomeni 82:10072c1794d3 1124 } else {
ocomeni 103:7b566b522427 1125 dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n");
ocomeni 82:10072c1794d3 1126 _parser.send("NAK\n");
ocomeni 82:10072c1794d3 1127 }
ocomeni 82:10072c1794d3 1128 }
ocomeni 82:10072c1794d3 1129
ocomeni 82:10072c1794d3 1130 void ATCmdManager::_oob_setWiFiPWD()
ocomeni 82:10072c1794d3 1131 {
ocomeni 82:10072c1794d3 1132 int n;
ocomeni 82:10072c1794d3 1133 wifi_config_t wifi_cfg = init_wifi_config();
ocomeni 83:9c271a50a70b 1134 n = readStringBytes((uint8_t *)wifi_cfg.pass, 32);
ocomeni 82:10072c1794d3 1135 if(n>0)
ocomeni 82:10072c1794d3 1136 {
ocomeni 103:7b566b522427 1137 dbg_printf(LOG, "ATCMD MAN]: wifi_cfg.pass = %s\n", "****************");
ocomeni 82:10072c1794d3 1138 // package and send on wifi data queue
ocomeni 82:10072c1794d3 1139 wifi_data_msg_t data_msg;
ocomeni 82:10072c1794d3 1140 data_msg.wifi_cmd = WIFI_CMD_CONFIG;
ocomeni 82:10072c1794d3 1141 data_msg.dataLen = sizeof(wifi_config_t);
ocomeni 82:10072c1794d3 1142 memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
ocomeni 82:10072c1794d3 1143 queueWiFiDataRequest(data_msg);
ocomeni 82:10072c1794d3 1144 } else {
ocomeni 103:7b566b522427 1145 dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n");
ocomeni 82:10072c1794d3 1146 _parser.send("NAK\n");
ocomeni 82:10072c1794d3 1147 }
ocomeni 82:10072c1794d3 1148 }
ocomeni 82:10072c1794d3 1149
ocomeni 82:10072c1794d3 1150 void ATCmdManager::_oob_setWiFiSecurity()
ocomeni 82:10072c1794d3 1151 {
ocomeni 82:10072c1794d3 1152 int n;
ocomeni 82:10072c1794d3 1153 wifi_config_t wifi_cfg = init_wifi_config();
ocomeni 112:a0999ea4ece0 1154 int security;
ocomeni 112:a0999ea4ece0 1155 n = _parser.scanf(",%d", &security);
ocomeni 82:10072c1794d3 1156 if(n>0)
ocomeni 82:10072c1794d3 1157 {
ocomeni 112:a0999ea4ece0 1158 wifi_cfg.security = (nsapi_security_t) security;
ocomeni 103:7b566b522427 1159 dbg_printf(LOG, "ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security));
ocomeni 82:10072c1794d3 1160 // package and send on wifi data queue
ocomeni 82:10072c1794d3 1161 wifi_data_msg_t data_msg;
ocomeni 82:10072c1794d3 1162 data_msg.wifi_cmd = WIFI_CMD_CONFIG;
ocomeni 82:10072c1794d3 1163 data_msg.dataLen = sizeof(wifi_config_t);
ocomeni 82:10072c1794d3 1164 memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
ocomeni 82:10072c1794d3 1165 queueWiFiDataRequest(data_msg);
ocomeni 82:10072c1794d3 1166 } else {
ocomeni 103:7b566b522427 1167 dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n");
ocomeni 90:ed0267eca7b5 1168 _smutex.lock();
ocomeni 82:10072c1794d3 1169 _parser.send("NAK\n");
ocomeni 90:ed0267eca7b5 1170 _smutex.unlock();
ocomeni 82:10072c1794d3 1171 }
ocomeni 79:a2187bbfa407 1172 }
ocomeni 81:637a87eb8170 1173
ocomeni 83:9c271a50a70b 1174
ocomeni 95:290859010c8c 1175
ocomeni 95:290859010c8c 1176 void ATCmdManager::_oob_getNetworkStatus()
ocomeni 95:290859010c8c 1177 {
ocomeni 112:a0999ea4ece0 1178 int if_id; // interface id for request
ocomeni 95:290859010c8c 1179 _parser.scanf(",%d", &if_id);
ocomeni 103:7b566b522427 1180 dbg_printf(LOG, "\n Received Get Network Status command!!\n");
ocomeni 95:290859010c8c 1181 if(if_id == WIFI_INTERFACE_ID){
ocomeni 95:290859010c8c 1182 wifi_cmd_t cmd = WIFI_CMD_NETWORK_STATUS;
ocomeni 103:7b566b522427 1183 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd);
ocomeni 95:290859010c8c 1184 queueWiFiCommand(cmd);
ocomeni 95:290859010c8c 1185 }
ocomeni 95:290859010c8c 1186 return;
ocomeni 95:290859010c8c 1187 }
ocomeni 95:290859010c8c 1188
ocomeni 95:290859010c8c 1189
ocomeni 95:290859010c8c 1190 void ATCmdManager::_oob_WiFiNetworkStatus()
ocomeni 95:290859010c8c 1191 {
ocomeni 103:7b566b522427 1192 dbg_printf(LOG, "\n Received Get WiFi Network Status command!!\n");
ocomeni 95:290859010c8c 1193 wifi_cmd_t cmd = WIFI_CMD_WIFI_STATUS;
ocomeni 103:7b566b522427 1194 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd);
ocomeni 95:290859010c8c 1195 // queue next command
ocomeni 95:290859010c8c 1196 queueWiFiCommand(cmd);
ocomeni 95:290859010c8c 1197 return;
ocomeni 95:290859010c8c 1198 }
ocomeni 95:290859010c8c 1199
ocomeni 83:9c271a50a70b 1200 void ATCmdManager::_oob_sendHttpMessage()
ocomeni 83:9c271a50a70b 1201 {
ocomeni 83:9c271a50a70b 1202 }
ocomeni 83:9c271a50a70b 1203
ocomeni 81:637a87eb8170 1204 bool ATCmdManager::queueWiFiCommand(wifi_cmd_t cmd){
ocomeni 103:7b566b522427 1205 dbg_printf(LOG, "[ATCMD MAN] about to be queued with wifi_cmd = %d\n", cmd);
ocomeni 92:ec9550034276 1206 #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL
ocomeni 81:637a87eb8170 1207 wifi_cmd_message_t *wifiCmd = _aT2WiFimPool->alloc();
ocomeni 92:ec9550034276 1208 if(wifiCmd == NULL){
ocomeni 103:7b566b522427 1209 dbg_printf(LOG, "[ATCMD MAN] queued memory allocation failed\n");
ocomeni 92:ec9550034276 1210 return false;
ocomeni 92:ec9550034276 1211 }
ocomeni 92:ec9550034276 1212 #else
ocomeni 92:ec9550034276 1213 wifi_cmd_message_t *wifiCmd = (wifi_cmd_message_t *) malloc(sizeof(wifi_cmd_message_t));
ocomeni 92:ec9550034276 1214 if(wifiCmd == NULL){
ocomeni 103:7b566b522427 1215 dbg_printf(LOG, "[ATCMD MAN] try malloc() : queued memory allocation failed\n");
ocomeni 92:ec9550034276 1216 return false;
ocomeni 92:ec9550034276 1217 }
ocomeni 92:ec9550034276 1218 #endif
ocomeni 81:637a87eb8170 1219 wifiCmd->wifi_cmd = cmd;
ocomeni 81:637a87eb8170 1220 _aT2WiFiCmdQueue->put(wifiCmd);
ocomeni 103:7b566b522427 1221 dbg_printf(LOG, "[ATCMD MAN] queued wifi_cmd = %d\n", wifiCmd->wifi_cmd);
ocomeni 98:65c2333a38b6 1222 if((int)cmd == 5)
ocomeni 98:65c2333a38b6 1223 debug_flag = 3;
ocomeni 81:637a87eb8170 1224 return true;
ocomeni 81:637a87eb8170 1225 }
ocomeni 81:637a87eb8170 1226
ocomeni 81:637a87eb8170 1227 bool ATCmdManager::dequeueATresponse(){
ocomeni 81:637a87eb8170 1228 if(at_resp != AT_RESP_NONE) return false; // busy
ocomeni 81:637a87eb8170 1229 osEvent evt = _wiFi2ATCmdQueue->get(0);
ocomeni 81:637a87eb8170 1230 if(evt.status == osEventMessage){
ocomeni 81:637a87eb8170 1231 at_resp_message_t *resp = (at_resp_message_t*)evt.value.p;
ocomeni 81:637a87eb8170 1232 setNextResponse(resp->at_resp);
ocomeni 103:7b566b522427 1233 dbg_printf(LOG, "[ATCMD MAN] dequeued AT CMD : at_resp = %d\n", resp->at_resp);
ocomeni 92:ec9550034276 1234 #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL
ocomeni 81:637a87eb8170 1235 _wiFi2ATmPool->free(resp);
ocomeni 96:f5ed273881af 1236 resp = NULL;
ocomeni 92:ec9550034276 1237 #else
ocomeni 92:ec9550034276 1238 free(resp);
ocomeni 96:f5ed273881af 1239 resp = NULL;
ocomeni 92:ec9550034276 1240 #endif
ocomeni 81:637a87eb8170 1241 }
ocomeni 81:637a87eb8170 1242 return true;
ocomeni 81:637a87eb8170 1243 }
ocomeni 81:637a87eb8170 1244
ocomeni 81:637a87eb8170 1245 bool ATCmdManager::queueWiFiDataRequest(wifi_data_msg_t data_req){
ocomeni 104:11e9605093c9 1246 static bool memFull = false;
ocomeni 81:637a87eb8170 1247 wifi_data_msg_t *wifiData = _aT2WiFiDatamPool->alloc();
ocomeni 104:11e9605093c9 1248 if(wifiData == NULL)
ocomeni 104:11e9605093c9 1249 {
ocomeni 109:c274780ff609 1250 #ifdef SEND_DEBUG_MESSAGES
ocomeni 104:11e9605093c9 1251 sendAtConfirmation("\r\nQUEUE MEMORY FULL\r\n");
ocomeni 109:c274780ff609 1252 #endif
ocomeni 104:11e9605093c9 1253 memFull = true;
ocomeni 104:11e9605093c9 1254 return false;
ocomeni 104:11e9605093c9 1255 }
ocomeni 104:11e9605093c9 1256 if(memFull)
ocomeni 104:11e9605093c9 1257 {
ocomeni 104:11e9605093c9 1258 memFull = false;
ocomeni 109:c274780ff609 1259 #ifdef SEND_DEBUG_MESSAGES
ocomeni 104:11e9605093c9 1260 sendAtConfirmation("\r\n[ATCMD-MAN] memory released...\r\n");
ocomeni 109:c274780ff609 1261 #endif
ocomeni 104:11e9605093c9 1262 }
ocomeni 81:637a87eb8170 1263 wifiData->wifi_cmd = data_req.wifi_cmd;
ocomeni 81:637a87eb8170 1264 wifiData->dataLen = data_req.dataLen;
ocomeni 81:637a87eb8170 1265 memcpy(wifiData->buffer, data_req.buffer, data_req.dataLen);
ocomeni 81:637a87eb8170 1266 _aT2WiFiDataQueue->put(wifiData);
ocomeni 103:7b566b522427 1267 dbg_printf(LOG, "[ATCMD MAN] queued data size = %d : wifi_cmd = %d\n", data_req.dataLen, data_req.wifi_cmd);
ocomeni 81:637a87eb8170 1268 return true;
ocomeni 81:637a87eb8170 1269 }
ocomeni 81:637a87eb8170 1270
ocomeni 87:99b37d26ff2a 1271 bool ATCmdManager::dequeueWiFidataResponse(){
ocomeni 81:637a87eb8170 1272 if(at_resp != AT_RESP_NONE) return false; // busy
ocomeni 81:637a87eb8170 1273 osEvent evt = _wiFi2ATDataQueue->get(0);
ocomeni 81:637a87eb8170 1274 if(evt.status == osEventMessage){
ocomeni 81:637a87eb8170 1275 resp_data = (at_data_msg_t*)evt.value.p;
ocomeni 81:637a87eb8170 1276 setNextResponse(resp_data->at_resp);
ocomeni 103:7b566b522427 1277 dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", resp_data->dataLen, resp_data->at_resp);
ocomeni 81:637a87eb8170 1278 }
ocomeni 81:637a87eb8170 1279 return true;
ocomeni 81:637a87eb8170 1280 }
ocomeni 81:637a87eb8170 1281
ocomeni 120:779b74689747 1282 bool ATCmdManager::queueBleDataRequest(at_ble_msg_t data_req){
ocomeni 120:779b74689747 1283 at_ble_msg_t *bleData = _aT2BleDatamPool->alloc();
ocomeni 120:779b74689747 1284 if(bleData == NULL)
ocomeni 120:779b74689747 1285 {
ocomeni 120:779b74689747 1286 #ifdef SEND_DEBUG_MESSAGES
ocomeni 120:779b74689747 1287 sendAtConfirmation("\r\nBLE QUEUE MEMORY FULL\r\n");
ocomeni 120:779b74689747 1288 #endif
ocomeni 120:779b74689747 1289 return false;
ocomeni 120:779b74689747 1290 }
ocomeni 120:779b74689747 1291 bleData->ble_cmd = data_req.ble_cmd;
ocomeni 120:779b74689747 1292 bleData->dataLen = data_req.dataLen;
ocomeni 120:779b74689747 1293 memcpy(bleData->buffer, data_req.buffer, data_req.dataLen);
ocomeni 120:779b74689747 1294 _aT2BleDataQueue->put(bleData);
ocomeni 120:779b74689747 1295 dbg_printf(LOG, "[ATCMD MAN] queued BLE data size = %d : wifi_cmd = %d\n", data_req.dataLen, data_req.ble_cmd);
ocomeni 120:779b74689747 1296 return true;
ocomeni 120:779b74689747 1297 }
ocomeni 120:779b74689747 1298
ocomeni 120:779b74689747 1299 bool ATCmdManager::dequeueBleDataResponse(){
ocomeni 120:779b74689747 1300 if(at_resp != AT_RESP_NONE) return false; // busy
ocomeni 120:779b74689747 1301 osEvent evt = _ble2ATDataQueue->get(0);
ocomeni 120:779b74689747 1302 if(evt.status == osEventMessage){
ocomeni 120:779b74689747 1303 ble_resp_data = (ble_at_msg_t*)evt.value.p;
ocomeni 120:779b74689747 1304 setNextResponse(ble_resp_data->at_resp);
ocomeni 121:ac4f59839e4f 1305 dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", ble_resp_data->dataLen, ble_resp_data->at_resp);
ocomeni 120:779b74689747 1306 }
ocomeni 120:779b74689747 1307 return true;
ocomeni 120:779b74689747 1308 }
ocomeni 120:779b74689747 1309
ocomeni 93:06e755a80187 1310
ocomeni 93:06e755a80187 1311 void ATCmdManager::sendAtConfirmation(const char *buf)
ocomeni 93:06e755a80187 1312 {
ocomeni 96:f5ed273881af 1313 _smutex.lock();
ocomeni 95:290859010c8c 1314 switch(dataMode){
ocomeni 95:290859010c8c 1315 case AT_CMD_DATA_MODE:
ocomeni 98:65c2333a38b6 1316 _parser.send("%s", buf);
ocomeni 95:290859010c8c 1317 break;
ocomeni 95:290859010c8c 1318 case AT_STD_DATA_MODE:
ocomeni 98:65c2333a38b6 1319 _parser.send("%s", buf);
ocomeni 95:290859010c8c 1320 break;
ocomeni 95:290859010c8c 1321 case AT_EXT_DATA_MODE:
ocomeni 98:65c2333a38b6 1322 {
ocomeni 96:f5ed273881af 1323 int len = strlen(buf);
ocomeni 95:290859010c8c 1324 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL);
ocomeni 95:290859010c8c 1325 break;
ocomeni 98:65c2333a38b6 1326 }
ocomeni 95:290859010c8c 1327 default:
ocomeni 98:65c2333a38b6 1328 _parser.send("%s", buf);
ocomeni 95:290859010c8c 1329 break;
ocomeni 95:290859010c8c 1330 }
ocomeni 96:f5ed273881af 1331 _smutex.unlock();
ocomeni 93:06e755a80187 1332 }
ocomeni 93:06e755a80187 1333 void ATCmdManager::sendAtEvent(const char *buf)
ocomeni 93:06e755a80187 1334 {
ocomeni 96:f5ed273881af 1335 _smutex.lock();
ocomeni 95:290859010c8c 1336 switch(dataMode){
ocomeni 95:290859010c8c 1337 case AT_CMD_DATA_MODE:
ocomeni 95:290859010c8c 1338 _parser.send(buf);
ocomeni 95:290859010c8c 1339 break;
ocomeni 95:290859010c8c 1340 case AT_STD_DATA_MODE:
ocomeni 95:290859010c8c 1341 _parser.send(buf);
ocomeni 95:290859010c8c 1342 break;
ocomeni 95:290859010c8c 1343 case AT_EXT_DATA_MODE:
ocomeni 99:05398b3184f8 1344 {
ocomeni 96:f5ed273881af 1345 int len = strlen(buf);
ocomeni 95:290859010c8c 1346 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL);
ocomeni 95:290859010c8c 1347 break;
ocomeni 99:05398b3184f8 1348 }
ocomeni 99:05398b3184f8 1349 default:
ocomeni 99:05398b3184f8 1350 _parser.send(buf);
ocomeni 99:05398b3184f8 1351 break;
ocomeni 95:290859010c8c 1352 }
ocomeni 96:f5ed273881af 1353 _smutex.unlock();
ocomeni 100:80ef4bc31b7a 1354 _wiFi2ATDatamPool->free(resp_data);
ocomeni 100:80ef4bc31b7a 1355 resp_data = NULL;
ocomeni 93:06e755a80187 1356 }
ocomeni 93:06e755a80187 1357
ocomeni 99:05398b3184f8 1358
ocomeni 118:8df0e9c2ee3f 1359 void ATCmdManager::sendBleDataEvent(const char *buf, int len)
ocomeni 118:8df0e9c2ee3f 1360 {
ocomeni 118:8df0e9c2ee3f 1361 _smutex.lock();
ocomeni 118:8df0e9c2ee3f 1362 switch(dataMode){
ocomeni 118:8df0e9c2ee3f 1363 case AT_CMD_DATA_MODE:
ocomeni 118:8df0e9c2ee3f 1364 _parser.send(buf);
ocomeni 118:8df0e9c2ee3f 1365 break;
ocomeni 118:8df0e9c2ee3f 1366 case AT_STD_DATA_MODE:
ocomeni 118:8df0e9c2ee3f 1367 _parser.send(buf);
ocomeni 118:8df0e9c2ee3f 1368 break;
ocomeni 118:8df0e9c2ee3f 1369 case AT_EXT_DATA_MODE:
ocomeni 118:8df0e9c2ee3f 1370 {
ocomeni 118:8df0e9c2ee3f 1371 outputEDMdata((const uint8_t *) buf, len, DATA_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL);
ocomeni 118:8df0e9c2ee3f 1372 break;
ocomeni 118:8df0e9c2ee3f 1373 }
ocomeni 118:8df0e9c2ee3f 1374 default:
ocomeni 118:8df0e9c2ee3f 1375 _parser.send(buf);
ocomeni 118:8df0e9c2ee3f 1376 break;
ocomeni 118:8df0e9c2ee3f 1377 }
ocomeni 118:8df0e9c2ee3f 1378 _smutex.unlock();
ocomeni 119:8d939a902333 1379 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 119:8d939a902333 1380 ble_resp_data = NULL;
ocomeni 119:8d939a902333 1381 }
ocomeni 119:8d939a902333 1382
ocomeni 119:8d939a902333 1383
ocomeni 119:8d939a902333 1384
ocomeni 119:8d939a902333 1385 void ATCmdManager::sendBleAtEvent(const char *buf, int len)
ocomeni 119:8d939a902333 1386 {
ocomeni 119:8d939a902333 1387 _smutex.lock();
ocomeni 119:8d939a902333 1388 switch(dataMode){
ocomeni 119:8d939a902333 1389 case AT_CMD_DATA_MODE:
ocomeni 119:8d939a902333 1390 _parser.send(buf);
ocomeni 119:8d939a902333 1391 break;
ocomeni 119:8d939a902333 1392 case AT_STD_DATA_MODE:
ocomeni 119:8d939a902333 1393 _parser.send(buf);
ocomeni 119:8d939a902333 1394 break;
ocomeni 119:8d939a902333 1395 case AT_EXT_DATA_MODE:
ocomeni 119:8d939a902333 1396 {
ocomeni 122:62166886db5f 1397 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL);
ocomeni 119:8d939a902333 1398 break;
ocomeni 119:8d939a902333 1399 }
ocomeni 119:8d939a902333 1400 default:
ocomeni 119:8d939a902333 1401 _parser.send(buf);
ocomeni 119:8d939a902333 1402 break;
ocomeni 119:8d939a902333 1403 }
ocomeni 119:8d939a902333 1404 _smutex.unlock();
ocomeni 119:8d939a902333 1405 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 119:8d939a902333 1406 ble_resp_data = NULL;
ocomeni 119:8d939a902333 1407 }
ocomeni 119:8d939a902333 1408
ocomeni 119:8d939a902333 1409 void ATCmdManager::sendBleConnectEvent(const char *buf, int len)
ocomeni 119:8d939a902333 1410 {
ocomeni 119:8d939a902333 1411 _smutex.lock();
ocomeni 119:8d939a902333 1412 switch(dataMode){
ocomeni 119:8d939a902333 1413 case AT_CMD_DATA_MODE:
ocomeni 119:8d939a902333 1414 _parser.send(buf);
ocomeni 119:8d939a902333 1415 break;
ocomeni 119:8d939a902333 1416 case AT_STD_DATA_MODE:
ocomeni 119:8d939a902333 1417 _parser.send(buf);
ocomeni 119:8d939a902333 1418 break;
ocomeni 119:8d939a902333 1419 case AT_EXT_DATA_MODE:
ocomeni 119:8d939a902333 1420 {
ocomeni 119:8d939a902333 1421 outputEDMdata((const uint8_t *) buf, len, CONNECT_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL);
ocomeni 119:8d939a902333 1422 break;
ocomeni 119:8d939a902333 1423 }
ocomeni 119:8d939a902333 1424 default:
ocomeni 119:8d939a902333 1425 _parser.send(buf);
ocomeni 119:8d939a902333 1426 break;
ocomeni 119:8d939a902333 1427 }
ocomeni 119:8d939a902333 1428 _smutex.unlock();
ocomeni 119:8d939a902333 1429 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 119:8d939a902333 1430 ble_resp_data = NULL;
ocomeni 118:8df0e9c2ee3f 1431 }
ocomeni 118:8df0e9c2ee3f 1432
ocomeni 120:779b74689747 1433 void ATCmdManager::sendBleDisconnectEvent()
ocomeni 120:779b74689747 1434 {
ocomeni 120:779b74689747 1435 _smutex.lock();
ocomeni 120:779b74689747 1436 outputEDMdata(NULL, 0, DISCONNECT_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL);
ocomeni 120:779b74689747 1437 _smutex.unlock();
ocomeni 120:779b74689747 1438 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 120:779b74689747 1439 ble_resp_data = NULL;
ocomeni 120:779b74689747 1440 }
ocomeni 120:779b74689747 1441
ocomeni 118:8df0e9c2ee3f 1442
ocomeni 99:05398b3184f8 1443 void ATCmdManager::sendConnectEvent(const uint8_t *buf, int len)
ocomeni 99:05398b3184f8 1444 {
ocomeni 99:05398b3184f8 1445 switch(dataMode){
ocomeni 99:05398b3184f8 1446 case AT_CMD_DATA_MODE:
ocomeni 99:05398b3184f8 1447 _parser.send((const char*) buf);
ocomeni 99:05398b3184f8 1448 break;
ocomeni 99:05398b3184f8 1449 case AT_STD_DATA_MODE:
ocomeni 99:05398b3184f8 1450 _parser.send((const char*)buf);
ocomeni 99:05398b3184f8 1451 break;
ocomeni 99:05398b3184f8 1452 case AT_EXT_DATA_MODE:
ocomeni 99:05398b3184f8 1453 outputEDMdata((const uint8_t *) buf, len, CONNECT_MSG_ID, EVENT_MSG_TYPE, WIFI_CHANNEL);
ocomeni 99:05398b3184f8 1454 break;
ocomeni 99:05398b3184f8 1455 }
ocomeni 100:80ef4bc31b7a 1456 _wiFi2ATDatamPool->free(resp_data);
ocomeni 100:80ef4bc31b7a 1457 resp_data = NULL;
ocomeni 100:80ef4bc31b7a 1458
ocomeni 99:05398b3184f8 1459 }
ocomeni 99:05398b3184f8 1460
ocomeni 99:05398b3184f8 1461
ocomeni 90:ed0267eca7b5 1462 void ATCmdManager::outputEDMdata(const uint8_t *buf, int pLen,
ocomeni 91:d6b6319ad681 1463 edm_msg_id_t identifier, edm_msg_type_t type,
ocomeni 91:d6b6319ad681 1464 channel_id_t channel_id)
ocomeni 90:ed0267eca7b5 1465 {
ocomeni 90:ed0267eca7b5 1466 int epLen = pLen + 2; // edm payload length = data length + 2
ocomeni 96:f5ed273881af 1467 if(channel_id != NO_CHANNEL)
ocomeni 96:f5ed273881af 1468 epLen += 1;
ocomeni 90:ed0267eca7b5 1469 _smutex.lock();
ocomeni 90:ed0267eca7b5 1470 // send EDM Message start byte
ocomeni 90:ed0267eca7b5 1471 _parser.putc(EDM_START_BYTE);
ocomeni 90:ed0267eca7b5 1472 // send EDM Message length
ocomeni 90:ed0267eca7b5 1473 _parser.putc(epLen>>8);
ocomeni 90:ed0267eca7b5 1474 _parser.putc(epLen%256);
ocomeni 90:ed0267eca7b5 1475 // send EDM Identifier + Type
ocomeni 90:ed0267eca7b5 1476 _parser.putc(identifier>>8);
ocomeni 90:ed0267eca7b5 1477 _parser.putc(identifier%256 | type);
ocomeni 93:06e755a80187 1478 // send channel id if valid
ocomeni 93:06e755a80187 1479 if(channel_id != NO_CHANNEL)
ocomeni 93:06e755a80187 1480 _parser.putc(channel_id);
ocomeni 90:ed0267eca7b5 1481 // send the data
ocomeni 120:779b74689747 1482 if(pLen > 0)
ocomeni 120:779b74689747 1483 {
ocomeni 120:779b74689747 1484 _parser.write((const char *)buf, pLen);
ocomeni 120:779b74689747 1485 }
ocomeni 90:ed0267eca7b5 1486 // send EDM Message stop byte
ocomeni 90:ed0267eca7b5 1487 _parser.putc(EDM_STOP_BYTE);
ocomeni 98:65c2333a38b6 1488 _smutex.unlock();
ocomeni 96:f5ed273881af 1489 int msWait = (pLen + 5+20)/20;
ocomeni 96:f5ed273881af 1490 wait_ms(msWait);
ocomeni 90:ed0267eca7b5 1491 }
ocomeni 122:62166886db5f 1492 void ATCmdManager::filterHttpResponse()
ocomeni 122:62166886db5f 1493 {
ocomeni 122:62166886db5f 1494 char * respbuf = (char *) resp_data->buffer;
ocomeni 122:62166886db5f 1495 char * strPtr;
ocomeni 122:62166886db5f 1496 char * strPtr2;
ocomeni 122:62166886db5f 1497 dbg_printf(LOG, "Header before trim:\r\n%s\r\n", respbuf);
ocomeni 122:62166886db5f 1498 strPtr = strstr(respbuf, "Date:"); // find start of the last required entry
ocomeni 122:62166886db5f 1499 if(strPtr == NULL) return;
ocomeni 122:62166886db5f 1500 strPtr2 = strstr(respbuf, "Connection:"); // find start of the last required entry
ocomeni 122:62166886db5f 1501 if(strPtr == NULL) return;
ocomeni 122:62166886db5f 1502 if(strPtr2 > strPtr)
ocomeni 122:62166886db5f 1503 {
ocomeni 122:62166886db5f 1504 strPtr = strPtr2;
ocomeni 122:62166886db5f 1505 }
ocomeni 122:62166886db5f 1506 strPtr2 = strstr(strPtr, "\r\n"); // find end of the last required entry
ocomeni 122:62166886db5f 1507 if(strPtr2 == NULL) return;
ocomeni 122:62166886db5f 1508 strPtr = strstr(strPtr2, "\r\n\r\n"); // find start of body
ocomeni 122:62166886db5f 1509 if(strPtr == NULL) return;
ocomeni 122:62166886db5f 1510 int hdrLen = (strPtr - respbuf);
ocomeni 122:62166886db5f 1511 int bytes2trim = (strPtr - strPtr2);
ocomeni 122:62166886db5f 1512 memmove(strPtr2, strPtr, (resp_data->dataLen-(hdrLen-bytes2trim)));
ocomeni 122:62166886db5f 1513 resp_data->dataLen -= bytes2trim; // reduce the length by bytes to trim
ocomeni 122:62166886db5f 1514 dbg_printf(LOG, "Header after trim:\r\n%s\r\n", respbuf);
ocomeni 122:62166886db5f 1515 }
ocomeni 89:45f6db09a76d 1516 void ATCmdManager::return_response(bool download) {
ocomeni 87:99b37d26ff2a 1517 char * resp = (char *) resp_data->buffer;
ocomeni 103:7b566b522427 1518 dbg_printf(LOG, "\n[ATCMD MAN] received response:\n");
ocomeni 89:45f6db09a76d 1519 if(download == false) // not download must be ascii header
ocomeni 89:45f6db09a76d 1520 {
ocomeni 103:7b566b522427 1521 dbg_printf(LOG, "%.*s\r\n", resp_data->dataLen, resp);
ocomeni 89:45f6db09a76d 1522 }
ocomeni 89:45f6db09a76d 1523 else // dump payload as hex
ocomeni 89:45f6db09a76d 1524 {
ocomeni 89:45f6db09a76d 1525 printBufferInHex((uint8_t *)resp, resp_data->dataLen);
ocomeni 89:45f6db09a76d 1526 }
ocomeni 122:62166886db5f 1527 #ifdef TRIM_AWS_HEADER_ENTRIES
ocomeni 122:62166886db5f 1528 int offset = resp - strstr(resp,"HTTP/1.1");
ocomeni 122:62166886db5f 1529 if(offset >=0 && offset < 2) // must be at start of header
ocomeni 122:62166886db5f 1530 {
ocomeni 122:62166886db5f 1531 filterHttpResponse();
ocomeni 122:62166886db5f 1532 }
ocomeni 122:62166886db5f 1533 #endif
ocomeni 91:d6b6319ad681 1534 outputEDMdata((const uint8_t *)resp, resp_data->dataLen, DATA_MSG_ID,
ocomeni 91:d6b6319ad681 1535 EVENT_MSG_TYPE, WIFI_CHANNEL);
ocomeni 87:99b37d26ff2a 1536 _wiFi2ATDatamPool->free(resp_data);
ocomeni 96:f5ed273881af 1537 resp_data = NULL;
ocomeni 118:8df0e9c2ee3f 1538 lastHttpRespTime = Kernel::get_ms_count();
ocomeni 87:99b37d26ff2a 1539 }