Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ATCmdManager.cpp
00001 #include "debug.h" 00002 #include "ATCmdManager.h" 00003 #include "common_types.h" 00004 #include "main.h" 00005 #include "http_request.h" 00006 #include "mbed_memory_status.h" 00007 //#include "mbed_memory_status.h" 00008 #define FILE_CODE "atcmd" 00009 00010 ATCmdManager::ATCmdManager(PinName tx, PinName rx, uart_config_t *uart_config, 00011 events::EventQueue &event_queue, WiFiManager *wifi, 00012 MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool, 00013 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, 00014 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, 00015 Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue, 00016 MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool, 00017 Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue, 00018 MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool, 00019 Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue, 00020 MemoryPool<at_ble_msg_t, PQDSZ_BLE> *aT2BleDatamPool, 00021 Queue<at_ble_msg_t, PQDSZ_BLE> *aT2BleDataQueue, 00022 MemoryPool<ble_at_msg_t, PQDSZ_BLE> *ble2ATDatamPool, 00023 Queue<ble_at_msg_t, PQDSZ_BLE> *ble2ATDataQueue, 00024 startup_config_t *startup_config, bool debug) 00025 : 00026 _serial(tx, rx, DEFAULT_BAUD_RATE), 00027 uart_config(uart_config), 00028 _event_queue(event_queue), 00029 wiFiManager(wiFiManager), 00030 _aT2WiFimPool(aT2WiFimPool), 00031 _aT2WiFiCmdQueue(aT2WiFiCmdQueue), 00032 00033 _wiFi2ATmPool(wiFi2ATmPool), 00034 _wiFi2ATCmdQueue(wiFi2ATCmdQueue), 00035 00036 _aT2WiFiDatamPool(aT2WiFiDatamPool), 00037 _aT2WiFiDataQueue(aT2WiFiDataQueue), 00038 00039 _wiFi2ATDatamPool(wiFi2ATDatamPool), 00040 _wiFi2ATDataQueue(wiFi2ATDataQueue), 00041 _aT2BleDatamPool(aT2BleDatamPool), 00042 _aT2BleDataQueue(aT2BleDataQueue), 00043 _ble2ATDatamPool(ble2ATDatamPool), 00044 _ble2ATDataQueue(ble2ATDataQueue), 00045 startup_config(startup_config), 00046 _parser(&_serial) 00047 00048 00049 { 00050 // constructor 00051 _serial.set_baud(uart_config->baudrate); 00052 //Flow flowCtrl = Flow::Disabled; 00053 //_serial.set_flow_control(mbed::SerialBase::Disabled); 00054 _parser.debug_on(debug); 00055 _parser.set_delimiter("\r\n"); 00056 _parser.send("+STARTUP\r\n\r\n"); 00057 _parser.oob("AT\r", callback(this, &ATCmdManager::_oob_ok_hdlr)); 00058 _parser.oob("ATE0", callback(this, &ATCmdManager::_oob_echo_off)); 00059 _parser.oob("ATE1", callback(this, &ATCmdManager::_oob_echo_on)); 00060 _parser.oob("ATE2", callback(this, &ATCmdManager::_oob_debug_logs_on)); 00061 _parser.oob("ATE3", callback(this, &ATCmdManager::_oob_debug_logs_off)); 00062 _parser.oob("AT+UMRS", callback(this, &ATCmdManager::_oob_uart_setup)); 00063 00064 _parser.oob("ATO", callback(this, &ATCmdManager::_oob_data_mode)); 00065 _parser.oob("AT+UMLA", callback(this, &ATCmdManager::_oob_get_mac_addr)); 00066 _parser.oob("AT+UBTLE?", callback(this, &ATCmdManager::_oob_get_ble_role)); 00067 _parser.oob("AT+UBTLE=2", callback(this, &ATCmdManager::_oob_ena_ble_peri)); 00068 _parser.oob("AT+CPWROFF", callback(this, &ATCmdManager::_oob_reboot)); 00069 _parser.oob("AT+CGMR", callback(this, &ATCmdManager::_oob_get_fw_ver)); 00070 _parser.oob("AT+UWSCAN", callback(this, &ATCmdManager::_oob_scanWiFiNetworks)); 00071 _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_WiFiStationConfigAction)); 00072 00073 _parser.oob("AAT+UBTLN?", callback(this, &ATCmdManager::_oob_get_ble_name)); 00074 _parser.oob("AT+UBTLN=", callback(this, &ATCmdManager::_oob_ok_hdlr)); 00075 _parser.oob("AT+UBTSM?", callback(this, &ATCmdManager::_oob_ok_hdlr)); 00076 _parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr)); 00077 00078 _parser.oob("AT+UDSC=", callback(this, &ATCmdManager::_oob_ok_hdlr)); 00079 _parser.oob("AT&W", callback(this, &ATCmdManager::_oob_saveSettings_hdlr)); 00080 //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr)); 00081 //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr)); 00082 //_parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork)); 00083 _parser.oob("AT+UDDRP", callback(this, &ATCmdManager::_oob_setupInternetConnection)); 00084 _parser.oob("AT+UWSC=0,0,0", callback(this, &ATCmdManager::_oob_enable_wifi)); 00085 _parser.oob("AT+UWSC=0,2", callback(this, &ATCmdManager::_oob_setWiFiSSID)); 00086 _parser.oob("AT+UWSC=0,8", callback(this, &ATCmdManager::_oob_setWiFiPWD)); 00087 _parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_setWiFiSecurity)); 00088 _parser.oob("AT+UNSTAT=", callback(this, &ATCmdManager::_oob_getNetworkStatus)); 00089 _parser.oob("AT+UWSSTAT", callback(this, &ATCmdManager::_oob_WiFiNetworkStatus)); 00090 00091 _parser.oob("AT+UFACTORY", callback(this, &ATCmdManager::_oob_factoryReset)); 00092 _parser.oob("AT+UDELCFG=", callback(this, &ATCmdManager::_oob_deleteConfiguration)); 00093 _parser.oob("AT+SDBGFLG", callback(this, &ATCmdManager::_oob_set_debug_flag)); 00094 00095 //_parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_sendHttpMessage)); 00096 //sendAtConfirmation("Testing:: +UBTLE:2\r\nOK\r\n"); 00097 dbg_printf(LOG, "\n --- ATCmdManager constructor completed ---\n"); 00098 at_resp = AT_RESP_NONE; 00099 dataMode = AT_CMD_DATA_MODE; 00100 debug_flags_map = 0; 00101 wifiStateControl = AT_RESP_NONE; 00102 //_event_queue.call_in(10, &print_heap_and_isr_stack_info); 00103 //print_heap_and_isr_stack_info(); 00104 //_event_queue.call_every(3600000,&print_memory_info); 00105 lastHttpRespTime = Kernel::get_ms_count(); 00106 lastCloudMsgType = 0x00; 00107 _event_queue.call_every(10000,&blinkLEDs); 00108 #ifdef BOX_UBLOX_DEMO_TESTING 00109 check_for_at_cmd = false; 00110 #endif 00111 } 00112 00113 00114 void ATCmdManager::runMain(){ 00115 dbg_printf(LOG, "\r\n [ATCMD MAN] Thread Id = %X\r\n", (uint32_t)ThisThread::get_id()); 00116 while(true){ 00117 _process_oob(UBLOX_ODIN_W2_RECV_TIMEOUT, true); 00118 wait_ms(MAIN_LOOP_WAIT_TIME_MS); // allow BTLE/WiFi some time 00119 processResponses(); 00120 } 00121 00122 } 00123 00124 void ATCmdManager::processResponses(){ 00125 dequeueATresponse(); 00126 dequeueWiFidataResponse(); 00127 dequeueBleDataResponse(); 00128 updateWiFiMgrStatus(); 00129 char * respStr; 00130 switch(at_resp){ 00131 case AT_RESP_NONE: 00132 // IDLE response state 00133 break; 00134 case AT_SCAN_RESP: 00135 { 00136 // AT_SCAN_RESP response state 00137 dbg_printf(LOG, "\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\r\n"); 00138 respStr = (char *) resp_data->buffer; 00139 sendAtConfirmationFreeMpool(respStr); 00140 at_resp = AT_RESP_NONE; 00141 break; 00142 } 00143 case AT_DETAILED_SCAN_RESP: 00144 { 00145 // AT_DETAILED_SCAN_RESP response state 00146 dbg_printf(LOG, "\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\r\n"); 00147 respStr = (char *) resp_data->buffer; 00148 sendAtConfirmationFreeMpool(respStr); 00149 at_resp = AT_RESP_NONE; 00150 break; 00151 } 00152 case AT_CONNECT_RESP: 00153 case WIFI_RECONNECT_INFO: 00154 { 00155 // AT_CONNECT_RESP response state 00156 dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\r\n"); 00157 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00158 respStr = (char *) resp_data->buffer; 00159 sendAtConfirmationFreeMpool(respStr); 00160 char * urc = new char[20]; 00161 sprintf(urc, "\r\n%s:%d\r\n", NETWORK_UP_URC, WIFI_INTERFACE_ID); 00162 sendAtEvent(urc); 00163 delete[] urc; 00164 at_resp = AT_RESP_NONE; 00165 break; 00166 } 00167 case AT_DISCONNECT_RESP: 00168 { 00169 // AT_DISCONNECT_RESP response state 00170 dbg_printf(LOG, "\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\r\n"); 00171 respStr = (char *) resp_data->buffer; 00172 sendAtConfirmationFreeMpool(respStr); 00173 char * urc = new char[20]; 00174 sprintf(urc, "\r\n%s:%d\r\n", NETWORK_DOWN_URC, WIFI_INTERFACE_ID); 00175 sendAtEvent(urc); 00176 delete[] urc; 00177 at_resp = AT_RESP_NONE; 00178 break; 00179 } 00180 case AT_CONFIG_RESP: 00181 { 00182 // AT_CONFIG_RESP response state 00183 dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\r\n"); 00184 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00185 at_resp = AT_RESP_NONE; 00186 break; 00187 } 00188 case AT_NETWORK_STATUS_RESP: 00189 { 00190 // AT_CONFIG_RESP response state 00191 dbg_printf(LOG, "\n [ATCMD MAN] NETWORK STATUS RESPONSE RECEIVED!!\r\n"); 00192 respStr = (char *) resp_data->buffer; 00193 sendAtConfirmationFreeMpool(respStr); 00194 at_resp = AT_RESP_NONE; 00195 break; 00196 } 00197 case AT_WIFI_STATUS_RESP: 00198 { 00199 // AT_CONFIG_RESP response state 00200 dbg_printf(LOG, "\n [ATCMD MAN] WIFI RESPONSE RECEIVED!!\r\n"); 00201 respStr = (char *) resp_data->buffer; 00202 sendAtConfirmationFreeMpool(respStr); 00203 at_resp = AT_RESP_NONE; 00204 break; 00205 } 00206 case AT_INTERNET_CONFIG_RESP: 00207 // AT_CONFIG_RESP response state 00208 dbg_printf(LOG, "\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\r\n"); 00209 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00210 at_resp = AT_RESP_NONE; 00211 break; 00212 case AT_HTTPS_RESP: 00213 // AT_HTTP_RESP response state 00214 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\r\n"); 00215 return_response(); 00216 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00217 at_resp = AT_RESP_NONE; 00218 break; 00219 case AT_HTTPS_RESP_DOWNLOAD: 00220 // AT_HTTPS_RESP_DOWNLOAD response state 00221 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTPS DOWNLOAD RESPONSE RECEIVED!!\r\n"); 00222 return_response(true); // set download paramter to true 00223 at_resp = AT_RESP_NONE; 00224 break; 00225 case AT_HTTP_RESP: 00226 // AT_HTTP_RESP response state 00227 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n"); 00228 return_response(); 00229 at_resp = AT_RESP_NONE; 00230 break; 00231 case AT_HTTP_RESP_DOWNLOAD: 00232 // AT_HTTP_RESP response state 00233 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n"); 00234 return_response(true); // set download paramter to true 00235 at_resp = AT_RESP_NONE; 00236 break; 00237 case CONNECT_EVENT: 00238 { 00239 // Connect Event state 00240 dbg_printf(LOG, "\n [ATCMD MAN] CONNECT EVENT RECEIVED!!\r\n"); 00241 sendConnectEvent(resp_data->buffer, resp_data->dataLen); 00242 at_resp = AT_RESP_NONE; 00243 break; 00244 } 00245 case AT_EVENT: 00246 { 00247 // AT Event state 00248 dbg_printf(LOG, "\n [ATCMD MAN] AT EVENT RECEIVED!!\r\n"); 00249 respStr = (char *) resp_data->buffer; 00250 sendAtEvent(respStr); 00251 at_resp = AT_RESP_NONE; 00252 break; 00253 } 00254 case WIFI_WATCH_DOG: 00255 { 00256 // AT_HTTP_RESP response state 00257 dbg_printf(LOG, "\n [ATCMD MAN] WIFI Watchdog message!!\r\n"); 00258 respStr = (char *) resp_data->buffer; 00259 sendConnectIndicationFreeMpool(respStr); 00260 at_resp = AT_RESP_NONE; 00261 break; 00262 } 00263 case AT_COMMAND_FAILED: 00264 { 00265 // AT_HTTP_RESP response state 00266 dbg_printf(LOG, "\n [ATCMD MAN] WIFI COMMAND FAILED!!\r\n"); 00267 respStr = (char *) resp_data->buffer; 00268 sendAtConfirmationFreeMpool(respStr); 00269 at_resp = AT_RESP_NONE; 00270 break; 00271 } 00272 case BLE_CONNECT_EVENT: 00273 { 00274 // AT Event state 00275 dbg_printf(LOG, "\n [ATCMD MAN] BLE_CONNECT_EVENT RESPONSE RECEIVED!!\r\n"); 00276 uint8_t * respBytes = ble_resp_data->buffer; 00277 sendBleConnectEvent((const char *)respBytes, ble_resp_data->dataLen); 00278 at_resp = AT_RESP_NONE; 00279 break; 00280 } 00281 case AT_BLE_EVENT: 00282 { 00283 // AT Event state 00284 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_EVENT RESPONSE RECEIVED!!\r\n"); 00285 respStr = (char *) ble_resp_data->buffer; 00286 sendBleAtEvent(respStr, ble_resp_data->dataLen); 00287 at_resp = AT_RESP_NONE; 00288 break; 00289 } 00290 case AT_BLE_RESPONSE: 00291 { 00292 // AT Event state 00293 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_RESPONSE RECEIVED!!\r\n"); 00294 respStr = (char *) ble_resp_data->buffer; 00295 ble_resp_data->buffer[ble_resp_data->dataLen] = NULL; 00296 sendBleDataEvent(respStr, ble_resp_data->dataLen); 00297 at_resp = AT_RESP_NONE; 00298 break; 00299 } 00300 case AT_SOCKET_KEEP_ALIVE_OK: 00301 { 00302 // AT Event state 00303 dbg_printf(LOG, "\n [ATCMD MAN] AT_SOCKET_KEEP_ALIVE OK RESPONSE RECEIVED!!\r\n"); 00304 #ifdef SEND_CLOUD_OK_MSG 00305 sendAtConfirmation("\r\nCLOUD CONNECTION OK\r\n"); 00306 #endif 00307 at_resp = AT_RESP_NONE; 00308 break; 00309 } 00310 case AT_SOCKET_KEEP_ALIVE_FAILED: 00311 { 00312 // AT Event state 00313 dbg_printf(LOG, "\n [ATCMD MAN] AT_SOCKET_KEEP_ALIVE FAILED RESPONSE RECEIVED!!\r\n"); 00314 #ifdef SEND_CLOUD_OK_MSG 00315 sendAtEvent("\r\nCLOUD CONNECTION FAILED\r\n"); 00316 #endif 00317 at_resp = AT_RESP_NONE; 00318 break; 00319 } 00320 case BLE_DISCONNECT_EVENT: 00321 { 00322 // BLE_DISCONNECT_EVENT state 00323 dbg_printf(LOG, "\n [ATCMD MAN] BLE_DISCONNECT_EVENT RECEIVED!!\r\n"); 00324 sendBleDisconnectEvent(); 00325 at_resp = AT_RESP_NONE; 00326 break; 00327 } 00328 case AT_WIFI_MAC_RESP: 00329 // AT_WIFI_MAC_RESP response state 00330 dbg_printf(LOG, "\n [ATCMD MAN] AT_WIFI_MAC_RESP RESPONSE RECEIVED!!\r\n"); 00331 respStr = (char *) resp_data->buffer; 00332 sendAtConfirmationFreeMpool(respStr); 00333 at_resp = AT_RESP_NONE; 00334 break; 00335 case AT_BLE_MAC_RESP: 00336 { 00337 // AT_BLE_MAC_RESP response state 00338 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_MAC_RESP RESPONSE RECEIVED!!\r\n"); 00339 respStr = (char *) ble_resp_data->buffer; 00340 sendAtConfirmation(respStr); 00341 _ble2ATDatamPool->free(ble_resp_data); 00342 ble_resp_data = NULL; 00343 at_resp = AT_RESP_NONE; 00344 break; 00345 } 00346 case AT_BLE_NAME_RESP: 00347 { 00348 // AT_BLE_MAC_RESP response state 00349 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_NAME_RESP RESPONSE RECEIVED!!\r\n"); 00350 respStr = (char *) ble_resp_data->buffer; 00351 sendAtConfirmation(respStr); 00352 _ble2ATDatamPool->free(ble_resp_data); 00353 ble_resp_data = NULL; 00354 at_resp = AT_RESP_NONE; 00355 break; 00356 } 00357 case AT_ACCESS_TOKEN_SUCCESS: 00358 { 00359 // AT_ACCESS_TOKEN_SUCCESS response state 00360 dbg_printf(LOG, "\n [ATCMD MAN] AT_ACCESS_TOKEN_SUCCESS RESPONSE RECEIVED!!\r\n"); 00361 sendAtConfirmation("\r\nAWS ACCESS TOKEN ACQUIRED \r\n"); 00362 at_resp = AT_RESP_NONE; 00363 break; 00364 } 00365 case AT_ACCESS_TOKEN_FAILED: 00366 { 00367 // AT_ACCESS_TOKEN_FAILED response state 00368 dbg_printf(LOG, "\n [ATCMD MAN] AT_ACCESS_TOKEN_FAILED!!\r\n"); 00369 sendAtConfirmation("\r\nAWS ACCESS TOKEN ACQUISITION FAILURE!!\r\n"); 00370 at_resp = AT_RESP_NONE; 00371 break; 00372 } 00373 default: 00374 { 00375 //UNKNOWN response state 00376 dbg_printf(LOG, "\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n"); 00377 sendAtConfirmationFreeMpool(ERROR_RESP); //_parser.send(OK_RESP); 00378 at_resp = AT_RESP_NONE; 00379 break; 00380 } 00381 } 00382 } 00383 00384 // 00385 void ATCmdManager::updateWiFiMgrStatus() 00386 { 00387 static int wifiBusyMonitor = 0; 00388 // if next response is the expected response, 00389 // then last command complete, reset wifi status 00390 // pass or fail!! 00391 if(at_resp == wifiStateControl || at_resp == AT_COMMAND_FAILED) 00392 { 00393 wifiStateControl = AT_RESP_NONE; 00394 } 00395 if(at_resp == WIFI_WATCH_DOG && strstr((char *) resp_data->buffer, "WiFi Main Loop inActive") != NULL) 00396 { 00397 wifiBusyMonitor++; 00398 if(wifiBusyMonitor >= 4) 00399 { 00400 wifiStateControl = AT_RESP_NONE; 00401 wifiBusyMonitor = 0; 00402 } 00403 } 00404 } 00405 void ATCmdManager::sendConnectIndicationFreeMpool(const char *buf) 00406 { 00407 int len = strlen(buf); 00408 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL); 00409 _wiFi2ATDatamPool->free(resp_data); 00410 resp_data = NULL; 00411 } 00412 00413 void ATCmdManager::sendAtConfirmationFreeMpool(const char *buf) 00414 { 00415 sendAtConfirmation(buf); 00416 _wiFi2ATDatamPool->free(resp_data); 00417 resp_data = NULL; 00418 } 00419 00420 00421 void ATCmdManager::printBufferInHex(const uint8_t *buf, int pLen) 00422 { 00423 print_debug_hex(buf, pLen); 00424 } 00425 00426 bool ATCmdManager::validate(edm_header_t edm_header) 00427 { 00428 if(edm_header.startByte != EDM_START_BYTE)return false; // unexpected start byte found! 00429 if(edm_header.payloadID != CONNECT_EVENT_ID && 00430 edm_header.payloadID != DISCONNECT_EVENT_ID && 00431 edm_header.payloadID != DATA_EVENT_ID && 00432 edm_header.payloadID != DATA_COMMAND_ID && 00433 edm_header.payloadID != AT_REQUEST_ID && 00434 edm_header.payloadID != AT_CONFIRMATION_ID && 00435 edm_header.payloadID != AT_EVENT_ID 00436 )return false; // unexpected payload ID found! 00437 if(edm_header.payloadLen > MAX_EDM_PAYLOAD_LEN || 00438 edm_header.payloadLen < MIN_EDM_PAYLOAD_LEN 00439 ) return false; // unexpected length received! 00440 if(edm_header.channel_id != WIFI_CHANNEL && 00441 edm_header.channel_id != BLE_CHANNEL 00442 ) return false; // unexpected channel_id received! 00443 return true; 00444 } 00445 00446 http_method ATCmdManager::str2HttpMethod(const char * methodStr) 00447 { 00448 http_method _http_method; 00449 if(strstr(methodStr, "POST")!= NULL){ 00450 _http_method = HTTP_POST; 00451 } 00452 else if(strstr(methodStr, "GET")!= NULL){ 00453 _http_method = HTTP_GET; 00454 } 00455 else{ 00456 _http_method = HTTP_DELETE; // unsupported method - set to HTTP_DELETE 00457 } 00458 return _http_method; 00459 } 00460 bool ATCmdManager::createHttpRequest() 00461 { 00462 #ifdef USE_WIFI_STATE_CONTROL 00463 static int wifiBusyTimeOut = 0; 00464 if(wifiStateControl != AT_RESP_NONE && wifiBusyTimeOut < 10) // wifi busy! 00465 { 00466 wifiBusyTimeOut++; 00467 return false; 00468 } 00469 wifiBusyTimeOut = 0; 00470 #endif 00471 bool full_debug_ena = (debug_flags_map & ATCMD_MGR_FULL_DEBUG_ENA) != 0x00; 00472 http_request_t *http_req; // = new http_request_t; 00473 wifi_data_msg_t data_msg; 00474 http_req = (http_request_t *)data_msg.buffer; 00475 char s1[32]; 00476 char s2[32]; 00477 char s3[32]; 00478 int len = 0; 00479 int n; 00480 char * strPtr = (char *)rx_buf_ptr; 00481 char * p; 00482 char * p2 = strstr(strPtr, "\r\n\r\n"); 00483 char * nxtPtr = strPtr; 00484 char * outPtr; 00485 char * bodyPtr = p2+4; 00486 dbg_printf(LOG, "\nstrPtr address= %x",strPtr); 00487 dbg_printf(LOG, "\np2 address= %x", p2); 00488 for(int i = 0; i < 6; i++){ 00489 if(i == 0)// firstline scan method uri and http_ver 00490 { 00491 n = sscanf(nxtPtr,"%s %s %s", s1, s2, s3); 00492 if(n!=3) return false; // error in input abort 00493 if(full_debug_ena) 00494 { 00495 dbg_printf(LOG, "\nmethod = %s\nuri = %s\nhttp_ver = %s",s1, s2, s3 ); 00496 } 00497 //http_req.method = str2HttpMethod(s1.c_str()); 00498 http_req->method = str2HttpMethod(s1); 00499 http_req->request_URI = (char *) http_req->buffer; // point 1st string to start of buffer 00500 len = strlen(s2)+1; 00501 strncpy(http_req->request_URI, s2, len); 00502 http_req->http_version = http_req->request_URI + len; // point 2nd string to after 1st 00503 len = strlen(s3)+1; 00504 strncpy(http_req->http_version, s3, len); 00505 if(full_debug_ena) 00506 { 00507 dbg_printf(LOG, "\nhttp_request 1st line:\n method = %d\nuri = %s\nhttp_ver = %s",http_req->method, 00508 http_req->request_URI, 00509 http_req->http_version ); 00510 dbg_printf(LOG, "\nhttp_request str ptrs\nuri = %X\nhttp_ver = %X",http_req->request_URI, 00511 http_req->http_version ); 00512 } 00513 outPtr = http_req->http_version + len; // point output buffer ptr to after 2nd string 00514 } 00515 else{ // scan header pairs 00516 n = sscanf(nxtPtr,"%s %s", s1, s2); 00517 if(n!=2) return false; // error in input abort 00518 p = strstr(s1,":"); 00519 *p = NULL; 00520 if(full_debug_ena) 00521 { 00522 dbg_printf(LOG, "\nname = %s value = %s",s1, s2); 00523 } 00524 if(strstr(s1, "Host")!= NULL){ 00525 http_req->hostName = outPtr; 00526 #ifdef BOX_UBLOX_DEMO_TESTING 00527 p = strstr(s2, "//"); 00528 if(p == NULL) 00529 p = s2; 00530 else 00531 p+=2; 00532 len = strlen(p)+1; 00533 strncpy(outPtr, p, len); 00534 #else 00535 len = strlen(s2)+1; 00536 strncpy(outPtr, s2, len); 00537 #endif 00538 if(full_debug_ena) 00539 { 00540 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr); 00541 } 00542 outPtr += len; // point output buffer ptr to after current string 00543 } 00544 else if(strstr(s1, "Accept")!= NULL){ 00545 http_req->AcceptVal = outPtr; 00546 len = strlen(s2)+1; 00547 strncpy(outPtr, s2, len); 00548 if(full_debug_ena) 00549 { 00550 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr); 00551 } 00552 outPtr += len; // point output buffer ptr to after current string 00553 } 00554 else if(strstr(s1, "Content-Type")!= NULL){ 00555 http_req->contentType = outPtr; 00556 len = strlen(s2)+1; 00557 strncpy(outPtr, s2, len); 00558 if(full_debug_ena) 00559 { 00560 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr); 00561 } 00562 outPtr += len; // point output buffer ptr to after current string 00563 } 00564 else if(strstr(s1, "Content-Length")!= NULL){ 00565 http_req->contentLen = outPtr; 00566 len = strlen(s2)+1; 00567 strncpy(outPtr, s2, len); 00568 if(full_debug_ena) 00569 { 00570 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr); 00571 } 00572 outPtr += len; // point output buffer ptr to after current string 00573 } 00574 else if(strstr(s1, "X-Amz-Target")!= NULL){ 00575 http_req->X_Amz_Target = outPtr; 00576 len = strlen(s2)+1; 00577 strncpy(outPtr, s2, len); 00578 if(full_debug_ena) 00579 { 00580 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr); 00581 } 00582 outPtr += len; // point output buffer ptr to after current string 00583 } 00584 00585 00586 00587 if(full_debug_ena) 00588 { 00589 dbg_printf(LOG, "\noutPtr = %X len = %d\n", outPtr, len); 00590 } 00591 } 00592 nxtPtr = strstr(nxtPtr, "\r\n")+2; // goto next line 00593 if(nxtPtr >= p2) break; 00594 } 00595 // print header from http_req_struct 00596 if(full_debug_ena) 00597 { 00598 dbg_printf(LOG, "\nhttp request header: \n %s\n", http_req->buffer); 00599 } 00600 int bodyLen = edm_hdr.payloadLen -(p2+7-strPtr); 00601 if(full_debug_ena) 00602 { 00603 dbg_printf(LOG, "\nLen = %d\n", bodyLen); 00604 } 00605 00606 uint32_t msecsSinceLastMsg = Kernel::get_ms_count() - lastHttpRespTime; 00607 if((lastCloudMsgType == BAR_DB_MSGTYPE || lastCloudMsgType == REC_DB_MSGTYPE) && 00608 lastCloudMsgType == (uint8_t) bodyPtr[8] && 00609 (msecsSinceLastMsg < CLOUD_RETRY_TIME_MS )) 00610 { 00611 return false; 00612 } 00613 lastCloudMsgType = (uint8_t) bodyPtr[8]; // pick out the MSGTYPE byte from payload 00614 http_req->body = (uint8_t *) outPtr; 00615 memcpy(outPtr, bodyPtr, bodyLen); 00616 if(bodyLen > 10){ 00617 dbg_printf(LOG, "\n Message Body:\n"); 00618 printBufferInHex(http_req->body, bodyLen); 00619 } 00620 outPtr += bodyLen; // move output pointer to end output (header + body) 00621 // package and send on wifi data queue 00622 data_msg.wifi_cmd = WIFI_CMD_SEND_HTTPS_REQ; 00623 data_msg.dataLen = (uint8_t *)outPtr - http_req->buffer;//sizeof(http_request_t); 00624 if(full_debug_ena) 00625 { 00626 dbg_printf(LOG, "\nsizeof(http_req) on population = %d\n", sizeof(*http_req)); 00627 dbg_printf(LOG, "\ndata_msg.dataLen = %d\n", data_msg.dataLen); 00628 } 00629 // queue next data request 00630 if(queueWiFiDataRequest(data_msg) == true) 00631 { 00632 wifiStateControl = AT_HTTPS_RESP_DOWNLOAD; 00633 return true; 00634 } 00635 return false; 00636 } 00637 00638 int ATCmdManager::readEDMmodeBytes(uint8_t *rx_buf_ptr, int pLen){ 00639 int n, m=0,sz=0; 00640 do{ 00641 sz = (pLen-m); 00642 if(sz > 224) 00643 { 00644 sz = 224; 00645 } 00646 n = _parser.read((char *)rx_buf_ptr, sz); 00647 if(n == -1) 00648 { 00649 dbg_printf(LOG, "Timeout while reading message payload bytes - expected %d but %d read so far!\r\n", pLen, m); 00650 //free(rx_buf_ptr); // make sure to free buffer 00651 //rx_buf_ptr = NULL; 00652 //sendAtConfirmation(UART_TIMEOUT_ERROR); 00653 return n; 00654 } 00655 m+=n; 00656 }while(m < pLen); 00657 return n; 00658 } 00659 00660 // OOB processing 00661 void ATCmdManager::_process_oob(uint32_t timeout, bool all){ 00662 set_timeout(timeout); 00663 int start; 00664 if(dataMode == AT_EXT_DATA_MODE) 00665 { 00666 int n; 00667 uint8_t edm[EDM_HDR_LEN]; 00668 char cmdType[16]; 00669 // Poll for edm packets 00670 do{ 00671 n = _parser.read((char *)edm, EDM_HDR_LEN-1); 00672 edm_hdr.startByte = edm[0]; 00673 edm_hdr.payloadLen = edm[1]*256 + edm[2]; 00674 edm_hdr.payloadID = edm[3]*256 + edm[4]; 00675 edm_hdr.channel_id = (channel_id_t) 0; 00676 start = Kernel::get_ms_count(); 00677 if(n == -1) break; // break if it times out 00678 int pT; 00679 if(edm_hdr.payloadID < AT_REQUEST_ID) // 00680 { 00681 n += _parser.read((char *)edm, 1); 00682 edm_hdr.channel_id = (channel_id_t) edm[0]; 00683 pT = 0; 00684 strcpy(cmdType, "DATA COMMAND"); 00685 } 00686 else 00687 { 00688 pT = 1; 00689 strcpy(cmdType, "AT REQUEST"); 00690 } 00691 dbg_printf(LOG, "%d bytes read! : CMD type = %s\n", n, cmdType); 00692 if(n==(EDM_HDR_LEN-pT)) 00693 dbg_printf(LOG, "Start = %d, payloadID = %d len = %d chan_id = %d\n", edm_hdr.startByte, 00694 edm_hdr.payloadID, 00695 edm_hdr.payloadLen, 00696 edm_hdr.channel_id); 00697 if(n == (EDM_HDR_LEN-pT) && validate(edm_hdr)) // if AT command use process oob to decode 00698 { 00699 if(edm_hdr.payloadID == AT_REQUEST_ID) 00700 { 00701 while (_parser.process_oob() && all) { 00702 } 00703 break; 00704 } 00705 else 00706 { 00707 int pLen = edm_hdr.payloadLen-2-pT; 00708 rx_buf_ptr = (uint8_t *) malloc(pLen); // we already read 2 bytes from payload but expect 1 stop byte 00709 if(rx_buf_ptr == NULL) 00710 { 00711 dbg_printf(LOG, "Memory allocation failed!\r\n"); 00712 free(rx_buf_ptr); // make sure to free buffer 00713 rx_buf_ptr = NULL; 00714 sendAtConfirmation(MEMORY_ALLOCATION_ERROR); 00715 break; // timeout! 00716 } 00717 rx_buf_ptr[pLen-1] = 0x00; // clear last byte so the readback value is as expected 00718 // set timeout to 100 ms for large packet 00719 set_timeout(100); 00720 n = _parser.read((char *)rx_buf_ptr, pLen); 00721 //n = readEDMmodeBytes(rx_buf_ptr, pLen); 00722 // reset timeout 00723 set_timeout(timeout); 00724 if(n == -1) 00725 { 00726 //dbg_printf(LOG, "Timeout while reading message payload bytes - expected %d!\r\n", pLen); 00727 free(rx_buf_ptr); // make sure to free buffer 00728 rx_buf_ptr = NULL; 00729 sendAtConfirmation(UART_TIMEOUT_ERROR); 00730 break; // timeout! 00731 } 00732 dbg_printf(LOG, "%d bytes read - expected %d!\n", n, pLen); 00733 printBufferInHex(rx_buf_ptr, pLen); 00734 dbg_printf(LOG, "rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]); 00735 if(rx_buf_ptr[pLen-1] != EDM_STOP_BYTE) { 00736 sendAtConfirmation("ERR"); 00737 free(rx_buf_ptr); // make sure to free buffer 00738 rx_buf_ptr = NULL; 00739 break; // exit if stop byte not found - possible data corruption! 00740 } 00741 switch(edm_hdr.payloadID) 00742 { 00743 case CONNECT_EVENT_ID: 00744 dbg_printf(LOG, "Connection Event received!\n"); 00745 break; 00746 case DISCONNECT_EVENT_ID: 00747 dbg_printf(LOG, "DISCONNECT_EVENT received!\n"); 00748 break; 00749 case DATA_EVENT_ID: 00750 dbg_printf(LOG, "DATA_EVENT received!\n"); 00751 break; 00752 case DATA_COMMAND_ID: 00753 { 00754 dbg_printf(LOG, "DATA_COMMAND received!\n"); 00755 if(createHttpRequest() == false) 00756 { 00757 #ifdef SEND_DEBUG_MESSAGES 00758 sendAtConfirmation(WIFI_BUSY_RESP); 00759 #endif 00760 } 00761 free(rx_buf_ptr); 00762 rx_buf_ptr = NULL; 00763 int stop = Kernel::get_ms_count(); 00764 dbg_printf(LOG, "\n Time Elapsed = %d\n", stop-start); 00765 break; 00766 } 00767 case AT_REQUEST_ID: 00768 dbg_printf(LOG, "AT_REQUEST received!\n"); 00769 break; 00770 case AT_CONFIRMATION_ID: 00771 dbg_printf(LOG, "AT_CONFIRMATION received!\n"); 00772 break; 00773 case AT_EVENT_ID: 00774 dbg_printf(LOG, "AT_EVENT received!\n"); 00775 break; 00776 default: 00777 dbg_printf(LOG, "UNKNOWN MESSAGE received!\n"); 00778 break; 00779 } 00780 } 00781 } 00782 else // incorrect # of bytes received abort!! 00783 { 00784 break; 00785 } 00786 }while (all); // continue to process until timeout 00787 } 00788 else 00789 { 00790 // Poll for inbound packets 00791 #ifdef BOX_UBLOX_DEMO_TESTING 00792 static char * ATCMD = new char[32]; 00793 int n = 0; 00794 if(check_for_at_cmd) 00795 { 00796 while (n>=0 && all) { 00797 n = readAtCommandString(ATCMD, 32); 00798 if(strstr(ATCMD,"AT\r") != NULL) 00799 { 00800 _oob_ok_hdlr(); 00801 check_for_at_cmd = false; 00802 break; 00803 } 00804 } 00805 } 00806 else 00807 #endif 00808 { 00809 while (_parser.process_oob() && all) { 00810 } 00811 } 00812 } 00813 set_timeout(); 00814 } 00815 00816 00817 int ATCmdManager::readAtCommandString(char *strbuf, size_t bufLen) 00818 { 00819 int n; 00820 bool atstr_found = false; 00821 int i = 0; 00822 while(n != -1) 00823 { 00824 char c; 00825 n = _parser.read(&c, 1); 00826 if(n) 00827 strbuf[i++] = c; 00828 if(c=='\r') 00829 { 00830 strbuf[i++] = NULL; // terminate string and exit 00831 atstr_found = true; 00832 break; 00833 } 00834 } 00835 if(atstr_found) 00836 { 00837 return i; 00838 } 00839 else 00840 { 00841 return -1; 00842 } 00843 } 00844 00845 // OOB message handlers 00846 void ATCmdManager::_oob_startup_hdlr(){ 00847 } 00848 00849 void ATCmdManager::_oob_ok_hdlr(){ 00850 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00851 } 00852 00853 00854 void ATCmdManager::_oob_bleRole_hdlr(){ 00855 } 00856 00857 00858 void ATCmdManager::_oob_wifiMode_err(){ 00859 } 00860 00861 00862 void ATCmdManager::_oob_conn_already(){ 00863 } 00864 00865 void ATCmdManager::_oob_enable_wifi() 00866 { 00867 trigger_start_WiFi(); 00868 sendAtConfirmation(OK_RESP); 00869 } 00870 00871 void ATCmdManager::_oob_err(){ 00872 } 00873 00874 void ATCmdManager::_oob_get_fw_ver() 00875 { 00876 #ifdef MBED_MAJOR_VERSION 00877 char * fw_ver_str = new char[40]; 00878 sprintf(fw_ver_str, "API version:%d.%d.%d.%d.%d.%dOK\r\n", MBED_MAJOR_VERSION 00879 , MBED_MINOR_VERSION 00880 , MBED_PATCH_VERSION 00881 , API_MAJOR_VERSION 00882 , API_MINOR_VERSION 00883 , API_BUILD_NUMBER); 00884 sendAtConfirmation(fw_ver_str); 00885 delete fw_ver_str; 00886 #endif 00887 } 00888 00889 00890 void ATCmdManager::_oob_set_debug_flag() 00891 { 00892 int rdFlag; 00893 if(_parser.scanf("=%3d", &rdFlag) >0) 00894 { 00895 debug_flags_map = rdFlag; 00896 dbg_printf(LOG, "\n Changing debug_flags_map to %d %d\n", rdFlag, debug_flags_map); 00897 sendAtConfirmation(OK_RESP); 00898 } 00899 } 00900 #define TTP_DEBUGGING 00901 #define TTP_DEBUGGING_UART_NOCHANGE 00902 void ATCmdManager::_oob_uart_setup(){ 00903 int uOpts[NUM_UART_OPTIONS]; 00904 if(_parser.scanf("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5]) >0) { 00905 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]); 00906 dbg_printf(LOG, "\n Changing Baud Rate to %d\n", uOpts[0]); 00907 #ifdef TTP_DEBUGGING_UART_NOCHANGE 00908 sendAtConfirmation(OK_RESP); 00909 #else 00910 00911 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00912 _serial.set_baud(uOpts[0]); 00913 wait(0.1); 00914 dbg_printf(LOG, "\n Baud Rate now %d\n", uOpts[0]); 00915 #endif 00916 #ifdef BOX_UBLOX_DEMO_TESTING 00917 check_for_at_cmd = true; 00918 #endif 00919 00920 } else { 00921 dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed"); 00922 } 00923 } 00924 00925 void ATCmdManager::set_timeout(uint32_t timeout_ms) 00926 { 00927 _parser.set_timeout(timeout_ms); 00928 } 00929 00930 00931 void ATCmdManager::_oob_echo_off() 00932 { 00933 dbg_printf(LOG, "\n Received ATEO OOB command!!\n"); 00934 dbg_printf(LOG, "\n turning echo OFF!!\n"); 00935 _parser.debug_on(false); 00936 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00937 } 00938 00939 00940 void ATCmdManager::_oob_echo_on() 00941 { 00942 dbg_printf(LOG, "\n Received ATE1 OOB command!!\n"); 00943 dbg_printf(LOG, "\n turning echo ON!!\n"); 00944 _parser.debug_on(true); 00945 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00946 } 00947 00948 00949 00950 void ATCmdManager::_oob_debug_logs_on() 00951 { 00952 initialise_debug(LOG | ERR | TXT | DBG); 00953 dbg_printf(LOG, "\n Received ATE2 OOB command!!\n"); 00954 dbg_printf(LOG, "\n debug logs ON!!\n"); 00955 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00956 } 00957 00958 void ATCmdManager::_oob_debug_logs_off() 00959 { 00960 dbg_printf(LOG, "\n Received ATE3 OOB command!!\n"); 00961 dbg_printf(LOG, "\n turning debug logs OFF!!\n"); 00962 initialise_debug(NONE); 00963 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00964 } 00965 00966 void ATCmdManager::_oob_data_mode(){ 00967 dbg_printf(LOG, "\n Received EDM mode command!!\n"); 00968 int dmode; 00969 if(_parser.scanf("%d", &dmode) >0) { 00970 dbg_printf(LOG, "\nATCmdParser: Data mode=%d\r\n", dataMode); 00971 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 00972 switch(dmode) 00973 { 00974 case 0: 00975 dbg_printf(LOG, "\nATCmdParser: Command Mode request received\n"); 00976 dataMode = AT_CMD_DATA_MODE; 00977 break; 00978 case 1: 00979 dbg_printf(LOG, "\nATCmdParser: Data Mode request received\n"); 00980 dataMode = AT_STD_DATA_MODE; 00981 break; 00982 case 2: 00983 dbg_printf(LOG, "\nATCmdParser: Extended data Mode request received\n"); 00984 dataMode = AT_EXT_DATA_MODE; 00985 _event_queue.call_in(10, &print_heap_and_isr_stack_info); 00986 //print_heap_and_isr_stack_info(); 00987 break; 00988 default: 00989 dbg_printf(LOG, "\nATCmdParser: ERROR - UNKNOWN DATA MODE RECEIVED!!! \n"); 00990 break; 00991 } 00992 } else { 00993 dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed\n"); 00994 } 00995 } 00996 00997 void ATCmdManager::_oob_get_mac_addr(){ 00998 int bleOrWifi; 00999 if(_parser.scanf("=%d", &bleOrWifi) >0) { 01000 switch(bleOrWifi) 01001 { 01002 case 1: 01003 { 01004 dbg_printf(LOG, "\nATCmdParser: BLE MAC Address request received"); 01005 at_ble_msg_t data_req; 01006 data_req.ble_cmd = BLE_CMD_MAC_ADDR; 01007 // queue next BLE command 01008 queueBleDataRequest(data_req); 01009 break; 01010 } 01011 case 2: 01012 { 01013 dbg_printf(LOG, "\nATCmdParser: WiFi MAC Address request received"); 01014 wifi_cmd_t cmd = WIFI_CMD_WIFI_MAC_ADDR; 01015 // queue next command 01016 queueWiFiCommand(cmd); 01017 break; 01018 } 01019 default: 01020 { 01021 dbg_printf(LOG, "\nATCmdParser: ERROR - UNKNOWN MAC ADDRESS REQUEST RECEIVED!!! \n"); 01022 break; 01023 } 01024 } 01025 } else { 01026 dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed"); 01027 } 01028 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 01029 } 01030 01031 01032 void ATCmdManager::_oob_get_ble_name() 01033 { 01034 dbg_printf(LOG, "\nATCmdParser: BLE CMD DEVICE_NAME request received"); 01035 at_ble_msg_t data_req; 01036 data_req.ble_cmd = BLE_CMD_DEVICE_NAME; 01037 // queue next BLE command 01038 queueBleDataRequest(data_req); 01039 } 01040 01041 void ATCmdManager::_oob_get_ble_role(){ 01042 trigger_start_BLE(); 01043 dbg_printf(LOG, "\n Received get BLE role command!!\n"); 01044 if(startup_config->ble_enable) 01045 { 01046 sendAtConfirmation("+UBTLE:2\r\nOK\r\n"); //_parser.send(OK_RESP); 01047 } 01048 else // disabled 01049 { 01050 sendAtConfirmation("+UBTLE:0\r\nOK\r\n"); //_parser.send(OK_RESP); 01051 } 01052 } 01053 01054 void ATCmdManager::_oob_ena_ble_peri(){ 01055 dbg_printf(LOG, "\n Received enable BLE Peripheral command!!\n"); 01056 startup_config->ble_enable = true; 01057 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 01058 } 01059 01060 void ATCmdManager::_oob_reboot(){ 01061 dbg_printf(LOG, "\n Received reboot command!!\n"); 01062 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 01063 system_reset(); 01064 } 01065 01066 01067 void ATCmdManager::_oob_factoryReset(){ 01068 dbg_printf(LOG, "\n Received factory reset command!!\n"); 01069 resetConfiguration(); 01070 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 01071 } 01072 01073 01074 void ATCmdManager::_oob_deleteConfiguration(){ 01075 dbg_printf(LOG, "\n Received delete configuration command!!\n"); 01076 int configKey; 01077 bool res = false; 01078 if(_parser.scanf("%d", &configKey) >0) 01079 { 01080 res = deleteConfiguration((nvstore_key_t) configKey); 01081 } 01082 if(res) 01083 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 01084 } 01085 01086 01087 01088 void ATCmdManager::_oob_saveSettings_hdlr() 01089 { 01090 saveConfiguration(APP_CONFIG_0); 01091 sendAtConfirmation(OK_RESP); 01092 } 01093 const char * ATCmdManager::sec2str(nsapi_security_t sec) 01094 { 01095 switch (sec) { 01096 case NSAPI_SECURITY_NONE: 01097 return "None"; 01098 case NSAPI_SECURITY_WEP: 01099 return "WEP"; 01100 case NSAPI_SECURITY_WPA: 01101 return "WPA"; 01102 case NSAPI_SECURITY_WPA2: 01103 return "WPA2"; 01104 case NSAPI_SECURITY_WPA_WPA2: 01105 return "WPA/WPA2"; 01106 case NSAPI_SECURITY_UNKNOWN: 01107 default: 01108 return "Unknown"; 01109 } 01110 } 01111 01112 bool ATCmdManager::setNextResponse(at_cmd_resp_t resp) 01113 { 01114 if(at_resp == AT_RESP_NONE){ 01115 at_resp = resp; 01116 return true; // success 01117 } 01118 return false; // wiFiManager busy 01119 } 01120 01121 01122 void ATCmdManager::_oob_scanWiFiNetworks(){ 01123 dbg_printf(LOG, "\n Received scanWiFiNetworks command!!\n"); 01124 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 01125 wifi_cmd_t cmd = WIFI_CMD_SCAN; 01126 // queue next command 01127 queueWiFiCommand(cmd); 01128 return; 01129 } 01130 01131 01132 01133 void ATCmdManager::_oob_WiFiStationConfigAction() 01134 { 01135 int if_id; // interface id for request 01136 int aId; // interface id for request 01137 _parser.recv("%d,%d", &if_id, &aId); 01138 dbg_printf(LOG, "\n Received WiFi Configuration Action command %d %d!!\r\n", if_id, aId); 01139 if(if_id == WIFI_CONFIG_ID && aId <5){ 01140 wifi_cmd_t cmd; 01141 action_id_t action_id = (action_id_t) aId; 01142 switch(action_id){ 01143 case WIFI_CONFIG_RESET: 01144 break; 01145 case WIFI_CONFIG_STORE: 01146 break; 01147 case WIFI_CONFIG_LOAD: 01148 break; 01149 case WIFI_CONFIG_ACTIVATE: 01150 cmd = WIFI_CMD_CONNECT; 01151 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd); 01152 queueWiFiCommand(cmd); 01153 break; 01154 case WIFI_CONFIG_DEACTIVATE: 01155 cmd = WIFI_CMD_DISCONNECT; 01156 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd); 01157 queueWiFiCommand(cmd); 01158 break; 01159 default: 01160 break; 01161 } 01162 } 01163 return; 01164 } 01165 01166 01167 void ATCmdManager::_oob_disconnectWiFiNetwork() 01168 { 01169 dbg_printf(LOG, "\n Received WiFi Disconnect command!!\n"); 01170 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); 01171 wifi_cmd_t cmd = WIFI_CMD_DISCONNECT; 01172 queueWiFiCommand(cmd); 01173 return; 01174 } 01175 01176 void ATCmdManager::_oob_setupInternetConnection() 01177 { 01178 char str[MAX_URL_LEN]; 01179 char url[MAX_URL_LEN]; 01180 int n; 01181 internet_config_t internet_config; 01182 dbg_printf(LOG, "sizeof internet_config_t = %d\n", sizeof(internet_config_t)); 01183 n = ReadBytes((uint8_t *)str, MAX_URL_LEN); 01184 str[n]=NULL; 01185 int id; 01186 int scheme; 01187 dbg_printf(LOG, "\n read string = %s , n = %d\n", str, n); 01188 n = sscanf(str, "=%1d,%99[^,],%1d", &id, 01189 url, //internet_config.url, 01190 &scheme); 01191 internet_config.peer_id = (uint8_t) id; 01192 internet_config.connectionScheme = (conn_scheme_t) scheme; 01193 #ifdef BOX_UBLOX_DEMO_TESTING 01194 char *p = strstr(url,"/https:"); 01195 #else 01196 char *p = strstr(url,"\""); 01197 #endif 01198 if(p!=NULL) 01199 { 01200 strncpy(internet_config.url, &p[1], strlen(url)); 01201 p = strstr(internet_config.url,"\""); 01202 *p = NULL; 01203 } 01204 else 01205 { 01206 strncpy(internet_config.url, url, strlen(url)+1); 01207 } 01208 dbg_printf(LOG, "\n read string = %s , n = %d -- strlen(url) = %d\n", internet_config.url, n, strlen(internet_config.url)); 01209 if(n>0) 01210 { 01211 dbg_printf(LOG, "peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id, 01212 internet_config.url, 01213 internet_config.connectionScheme); 01214 // package and send on wifi data queue 01215 wifi_data_msg_t data_msg; 01216 data_msg.wifi_cmd = WIFI_CMD_INTERNET_CONFIG; 01217 data_msg.dataLen = sizeof(internet_config_t); // + strlen(internet_config.url); 01218 dbg_printf(LOG, "\n url size = %d url str = %s\n",strlen(internet_config.url), internet_config.url ); 01219 memcpy(data_msg.buffer,&internet_config, data_msg.dataLen); 01220 // queue next data request 01221 queueWiFiDataRequest(data_msg); 01222 print_memory_info(); 01223 } else { 01224 dbg_printf(LOG, "\n[ATCMD MAN]: internet configuration failed %d fields parsed \r\n", n); 01225 _parser.send("NAK\n"); 01226 } 01227 } 01228 01229 wifi_config_t ATCmdManager::init_wifi_config() 01230 { 01231 wifi_config_t wifi_cfg; 01232 wifi_cfg.ssid[0] = NULL; 01233 wifi_cfg.pass[0] = NULL; 01234 wifi_cfg.security = NSAPI_SECURITY_UNKNOWN; 01235 return wifi_cfg; 01236 } 01237 01238 /* read ASCII characters into buffer and null terminate */ 01239 int ATCmdManager::readStringBytes(uint8_t *buf, int maxBytes) 01240 { 01241 int c; 01242 int sptr = 0; 01243 int quoteCnt = 0; 01244 for(int i=0;i<maxBytes;i++){ 01245 c = _parser.getc(); 01246 if(c== '"')quoteCnt++; 01247 if(c==-1 || quoteCnt==2){ 01248 buf[sptr] = NULL; // null terminate if string 01249 return i; 01250 } 01251 if(c != ',' && c!= '"'){ 01252 buf[sptr++] = (uint8_t) c; 01253 } 01254 } 01255 return maxBytes; 01256 } 01257 01258 int ATCmdManager::ReadBytes(uint8_t *buf, int maxBytes) 01259 { 01260 int c; 01261 int sptr = 0; 01262 for(int i=0;i<maxBytes;i++){ 01263 c = _parser.getc(); 01264 if(c==-1){ 01265 return i; 01266 } 01267 buf[sptr++] = (uint8_t) c; 01268 } 01269 return maxBytes; 01270 } 01271 01272 void ATCmdManager::_oob_setWiFiSSID() 01273 { 01274 int n; 01275 wifi_config_t wifi_cfg = init_wifi_config(); 01276 n = readStringBytes((uint8_t *)wifi_cfg.ssid, 32); 01277 dbg_printf(LOG, "[ATCMD MAN]: number of bytes read = %d\n", n); 01278 if(n>0) 01279 { 01280 dbg_printf(LOG, "[ATCMD MAN]: wifi_cfg.ssid = %s\n", wifi_cfg.ssid); 01281 // package and send on wifi data queue 01282 wifi_data_msg_t data_msg; 01283 data_msg.wifi_cmd = WIFI_CMD_CONFIG; 01284 data_msg.dataLen = sizeof(wifi_config_t); 01285 memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); 01286 queueWiFiDataRequest(data_msg); 01287 } else { 01288 dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n"); 01289 _parser.send("NAK\n"); 01290 } 01291 } 01292 01293 void ATCmdManager::_oob_setWiFiPWD() 01294 { 01295 int n; 01296 wifi_config_t wifi_cfg = init_wifi_config(); 01297 n = readStringBytes((uint8_t *)wifi_cfg.pass, 32); 01298 if(n>0) 01299 { 01300 dbg_printf(LOG, "ATCMD MAN]: wifi_cfg.pass = %s\n", "****************"); 01301 // package and send on wifi data queue 01302 wifi_data_msg_t data_msg; 01303 data_msg.wifi_cmd = WIFI_CMD_CONFIG; 01304 data_msg.dataLen = sizeof(wifi_config_t); 01305 memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); 01306 queueWiFiDataRequest(data_msg); 01307 } else { 01308 dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n"); 01309 _parser.send("NAK\n"); 01310 } 01311 } 01312 01313 void ATCmdManager::_oob_setWiFiSecurity() 01314 { 01315 int n; 01316 wifi_config_t wifi_cfg = init_wifi_config(); 01317 int security; 01318 n = _parser.scanf(",%d", &security); 01319 if(n>0) 01320 { 01321 wifi_cfg.security = (nsapi_security_t) security; 01322 dbg_printf(LOG, "ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security)); 01323 // package and send on wifi data queue 01324 wifi_data_msg_t data_msg; 01325 data_msg.wifi_cmd = WIFI_CMD_CONFIG; 01326 data_msg.dataLen = sizeof(wifi_config_t); 01327 memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); 01328 queueWiFiDataRequest(data_msg); 01329 } else { 01330 dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n"); 01331 _smutex.lock(); 01332 _parser.send("NAK\n"); 01333 _smutex.unlock(); 01334 } 01335 } 01336 01337 01338 01339 void ATCmdManager::_oob_getNetworkStatus() 01340 { 01341 int if_id; // interface id for request 01342 _parser.scanf(",%d", &if_id); 01343 dbg_printf(LOG, "\n Received Get Network Status command!!\n"); 01344 if(if_id == WIFI_INTERFACE_ID){ 01345 wifi_cmd_t cmd = WIFI_CMD_NETWORK_STATUS; 01346 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd); 01347 queueWiFiCommand(cmd); 01348 } 01349 return; 01350 } 01351 01352 01353 void ATCmdManager::_oob_WiFiNetworkStatus() 01354 { 01355 dbg_printf(LOG, "\n Received Get WiFi Network Status command!!\n"); 01356 wifi_cmd_t cmd = WIFI_CMD_WIFI_STATUS; 01357 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd); 01358 // queue next command 01359 queueWiFiCommand(cmd); 01360 return; 01361 } 01362 01363 void ATCmdManager::_oob_sendHttpMessage() 01364 { 01365 } 01366 01367 bool ATCmdManager::queueWiFiCommand(wifi_cmd_t cmd){ 01368 dbg_printf(LOG, "[ATCMD MAN] about to be queued with wifi_cmd = %d\n", cmd); 01369 #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL 01370 wifi_cmd_message_t *wifiCmd = _aT2WiFimPool->alloc(); 01371 if(wifiCmd == NULL){ 01372 dbg_printf(LOG, "[ATCMD MAN] queued memory allocation failed\n"); 01373 return false; 01374 } 01375 #else 01376 wifi_cmd_message_t *wifiCmd = (wifi_cmd_message_t *) malloc(sizeof(wifi_cmd_message_t)); 01377 if(wifiCmd == NULL){ 01378 dbg_printf(LOG, "[ATCMD MAN] try malloc() : queued memory allocation failed\n"); 01379 return false; 01380 } 01381 #endif 01382 wifiCmd->wifi_cmd = cmd; 01383 _aT2WiFiCmdQueue->put(wifiCmd); 01384 dbg_printf(LOG, "[ATCMD MAN] queued wifi_cmd = %d\n", wifiCmd->wifi_cmd); 01385 return true; 01386 } 01387 01388 bool ATCmdManager::dequeueATresponse(){ 01389 if(at_resp != AT_RESP_NONE) return false; // busy 01390 osEvent evt = _wiFi2ATCmdQueue->get(0); 01391 if(evt.status == osEventMessage){ 01392 at_resp_message_t *resp = (at_resp_message_t*)evt.value.p; 01393 setNextResponse(resp->at_resp); 01394 dbg_printf(LOG, "[ATCMD MAN] dequeued AT CMD : at_resp = %d\n", resp->at_resp); 01395 #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL 01396 _wiFi2ATmPool->free(resp); 01397 resp = NULL; 01398 #else 01399 free(resp); 01400 resp = NULL; 01401 #endif 01402 } 01403 return true; 01404 } 01405 01406 bool ATCmdManager::queueWiFiDataRequest(wifi_data_msg_t data_req){ 01407 static bool memFull = false; 01408 wifi_data_msg_t *wifiData = _aT2WiFiDatamPool->alloc(); 01409 if(wifiData == NULL) 01410 { 01411 #ifdef SEND_DEBUG_MESSAGES 01412 sendAtConfirmation("\r\nQUEUE MEMORY FULL\r\n"); 01413 #endif 01414 memFull = true; 01415 return false; 01416 } 01417 if(memFull) 01418 { 01419 memFull = false; 01420 #ifdef SEND_DEBUG_MESSAGES 01421 sendAtConfirmation("\r\n[ATCMD-MAN] memory released...\r\n"); 01422 #endif 01423 } 01424 wifiData->wifi_cmd = data_req.wifi_cmd; 01425 wifiData->dataLen = data_req.dataLen; 01426 memcpy(wifiData->buffer, data_req.buffer, data_req.dataLen); 01427 _aT2WiFiDataQueue->put(wifiData); 01428 dbg_printf(LOG, "[ATCMD MAN] queued data size = %d : wifi_cmd = %d\n", data_req.dataLen, data_req.wifi_cmd); 01429 return true; 01430 } 01431 01432 bool ATCmdManager::dequeueWiFidataResponse(){ 01433 if(at_resp != AT_RESP_NONE) return false; // busy 01434 osEvent evt = _wiFi2ATDataQueue->get(0); 01435 if(evt.status == osEventMessage){ 01436 resp_data = (at_data_msg_t*)evt.value.p; 01437 setNextResponse(resp_data->at_resp); 01438 dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", resp_data->dataLen, resp_data->at_resp); 01439 } 01440 return true; 01441 } 01442 01443 bool ATCmdManager::queueBleDataRequest(at_ble_msg_t data_req){ 01444 at_ble_msg_t *bleData = _aT2BleDatamPool->alloc(); 01445 if(bleData == NULL) 01446 { 01447 #ifdef SEND_DEBUG_MESSAGES 01448 sendAtConfirmation("\r\nBLE QUEUE MEMORY FULL\r\n"); 01449 #endif 01450 return false; 01451 } 01452 bleData->ble_cmd = data_req.ble_cmd; 01453 bleData->dataLen = data_req.dataLen; 01454 memcpy(bleData->buffer, data_req.buffer, data_req.dataLen); 01455 _aT2BleDataQueue->put(bleData); 01456 dbg_printf(LOG, "[ATCMD MAN] queued BLE data size = %d : ble_cmd = %d\n", data_req.dataLen, data_req.ble_cmd); 01457 return true; 01458 } 01459 01460 bool ATCmdManager::dequeueBleDataResponse(){ 01461 if(at_resp != AT_RESP_NONE) return false; // busy 01462 osEvent evt = _ble2ATDataQueue->get(0); 01463 if(evt.status == osEventMessage){ 01464 ble_resp_data = (ble_at_msg_t*)evt.value.p; 01465 setNextResponse(ble_resp_data->at_resp); 01466 dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", ble_resp_data->dataLen, ble_resp_data->at_resp); 01467 } 01468 return true; 01469 } 01470 01471 01472 void ATCmdManager::sendAtConfirmation(const char *buf) 01473 { 01474 _smutex.lock(); 01475 switch(dataMode){ 01476 case AT_CMD_DATA_MODE: 01477 _parser.send("%s", buf); 01478 break; 01479 case AT_STD_DATA_MODE: 01480 _parser.send("%s", buf); 01481 break; 01482 case AT_EXT_DATA_MODE: 01483 { 01484 int len = strlen(buf); 01485 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL); 01486 break; 01487 } 01488 default: 01489 _parser.send("%s", buf); 01490 break; 01491 } 01492 _smutex.unlock(); 01493 } 01494 void ATCmdManager::sendAtEvent(const char *buf) 01495 { 01496 _smutex.lock(); 01497 switch(dataMode){ 01498 case AT_CMD_DATA_MODE: 01499 _parser.send(buf); 01500 break; 01501 case AT_STD_DATA_MODE: 01502 _parser.send(buf); 01503 break; 01504 case AT_EXT_DATA_MODE: 01505 { 01506 int len = strlen(buf); 01507 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL); 01508 break; 01509 } 01510 default: 01511 _parser.send(buf); 01512 break; 01513 } 01514 _smutex.unlock(); 01515 _wiFi2ATDatamPool->free(resp_data); 01516 resp_data = NULL; 01517 } 01518 01519 01520 void ATCmdManager::sendBleDataEvent(const char *buf, int len) 01521 { 01522 _smutex.lock(); 01523 switch(dataMode){ 01524 case AT_CMD_DATA_MODE: 01525 _parser.send(buf); 01526 break; 01527 case AT_STD_DATA_MODE: 01528 _parser.send(buf); 01529 break; 01530 case AT_EXT_DATA_MODE: 01531 { 01532 outputEDMdata((const uint8_t *) buf, len, DATA_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL); 01533 break; 01534 } 01535 default: 01536 _parser.send(buf); 01537 break; 01538 } 01539 _smutex.unlock(); 01540 _ble2ATDatamPool->free(ble_resp_data); 01541 ble_resp_data = NULL; 01542 } 01543 01544 01545 01546 void ATCmdManager::sendBleAtEvent(const char *buf, int len) 01547 { 01548 _smutex.lock(); 01549 switch(dataMode){ 01550 case AT_CMD_DATA_MODE: 01551 _parser.send(buf); 01552 break; 01553 case AT_STD_DATA_MODE: 01554 _parser.send(buf); 01555 break; 01556 case AT_EXT_DATA_MODE: 01557 { 01558 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL); 01559 break; 01560 } 01561 default: 01562 _parser.send(buf); 01563 break; 01564 } 01565 _smutex.unlock(); 01566 _ble2ATDatamPool->free(ble_resp_data); 01567 ble_resp_data = NULL; 01568 } 01569 01570 void ATCmdManager::sendBleConnectEvent(const char *buf, int len) 01571 { 01572 _smutex.lock(); 01573 switch(dataMode){ 01574 case AT_CMD_DATA_MODE: 01575 _parser.send(buf); 01576 break; 01577 case AT_STD_DATA_MODE: 01578 _parser.send(buf); 01579 break; 01580 case AT_EXT_DATA_MODE: 01581 { 01582 outputEDMdata((const uint8_t *) buf, len, CONNECT_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL); 01583 break; 01584 } 01585 default: 01586 _parser.send(buf); 01587 break; 01588 } 01589 _smutex.unlock(); 01590 _ble2ATDatamPool->free(ble_resp_data); 01591 ble_resp_data = NULL; 01592 } 01593 01594 void ATCmdManager::sendBleDisconnectEvent() 01595 { 01596 _smutex.lock(); 01597 outputEDMdata(NULL, 0, DISCONNECT_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL); 01598 _smutex.unlock(); 01599 _ble2ATDatamPool->free(ble_resp_data); 01600 ble_resp_data = NULL; 01601 } 01602 01603 01604 void ATCmdManager::sendConnectEvent(const uint8_t *buf, int len) 01605 { 01606 switch(dataMode){ 01607 case AT_CMD_DATA_MODE: 01608 _parser.send((const char*) buf); 01609 break; 01610 case AT_STD_DATA_MODE: 01611 _parser.send((const char*)buf); 01612 break; 01613 case AT_EXT_DATA_MODE: 01614 outputEDMdata((const uint8_t *) buf, len, CONNECT_MSG_ID, EVENT_MSG_TYPE, WIFI_CHANNEL); 01615 break; 01616 } 01617 _wiFi2ATDatamPool->free(resp_data); 01618 resp_data = NULL; 01619 01620 } 01621 01622 01623 void ATCmdManager::outputEDMdata(const uint8_t *buf, int pLen, 01624 edm_msg_id_t identifier, edm_msg_type_t type, 01625 channel_id_t channel_id) 01626 { 01627 int epLen = pLen + 2; // edm payload length = data length + 2 01628 if(channel_id != NO_CHANNEL) 01629 epLen += 1; 01630 _smutex.lock(); 01631 // send EDM Message start byte 01632 _parser.putc(EDM_START_BYTE); 01633 // send EDM Message length 01634 _parser.putc(epLen>>8); 01635 _parser.putc(epLen%256); 01636 // send EDM Identifier + Type 01637 _parser.putc(identifier>>8); 01638 _parser.putc(identifier%256 | type); 01639 // send channel id if valid 01640 if(channel_id != NO_CHANNEL) 01641 _parser.putc(channel_id); 01642 // send the data 01643 if(pLen > 0) 01644 { 01645 _parser.write((const char *)buf, pLen); 01646 } 01647 // send EDM Message stop byte 01648 _parser.putc(EDM_STOP_BYTE); 01649 _smutex.unlock(); 01650 int msWait = (pLen + 5+20)/20; 01651 wait_ms(msWait); 01652 } 01653 void ATCmdManager::filterHttpResponse() 01654 { 01655 char * respbuf = (char *) resp_data->buffer; 01656 char * strPtr; 01657 char * strPtr2; 01658 dbg_printf(LOG, "Header before trim:\r\n%s\r\n", respbuf); 01659 strPtr = strstr(respbuf, "Date:"); // find start of the last required entry 01660 if(strPtr == NULL) return; 01661 strPtr2 = strstr(respbuf, "Connection:"); // find start of the last required entry 01662 if(strPtr == NULL) return; 01663 if(strPtr2 > strPtr) 01664 { 01665 strPtr = strPtr2; 01666 } 01667 strPtr2 = strstr(strPtr, "\r\n"); // find end of the last required entry 01668 if(strPtr2 == NULL) return; 01669 strPtr = strstr(strPtr2, "\r\n\r\n"); // find start of body 01670 if(strPtr == NULL) return; 01671 int hdrLen = (strPtr - respbuf); 01672 int bytes2trim = (strPtr - strPtr2); 01673 memmove(strPtr2, strPtr, (resp_data->dataLen-(hdrLen-bytes2trim))); 01674 resp_data->dataLen -= bytes2trim; // reduce the length by bytes to trim 01675 dbg_printf(LOG, "Header after trim:\r\n%s\r\n", respbuf); 01676 } 01677 void ATCmdManager::return_response(bool download) { 01678 char * resp = (char *) resp_data->buffer; 01679 dbg_printf(LOG, "\n[ATCMD MAN] received response:\n"); 01680 if(download == false) // not download must be ascii header 01681 { 01682 dbg_printf(LOG, "%.*s\r\n", resp_data->dataLen, resp); 01683 } 01684 else // dump payload as hex 01685 { 01686 printBufferInHex((uint8_t *)resp, resp_data->dataLen); 01687 } 01688 #ifdef TRIM_AWS_HEADER_ENTRIES 01689 int offset = resp - strstr(resp,"HTTP/1.1"); 01690 if(offset >=0 && offset < 2) // must be at start of header 01691 { 01692 filterHttpResponse(); 01693 } 01694 #endif 01695 outputEDMdata((const uint8_t *)resp, resp_data->dataLen, DATA_MSG_ID, 01696 EVENT_MSG_TYPE, WIFI_CHANNEL); 01697 _wiFi2ATDatamPool->free(resp_data); 01698 resp_data = NULL; 01699 lastHttpRespTime = Kernel::get_ms_count(); 01700 }
Generated on Wed Jul 13 2022 05:40:26 by
1.7.2