Okundu Omeni
/
wifi-https-ble-sm-uart-atcmd-5-13-1
this is using the mbed os version 5-13-1
Diff: source/ATCmdManager.cpp
- Branch:
- PassingRegression
- Revision:
- 126:9bc33f8b57d5
- Parent:
- 125:d2830421006c
- Child:
- 127:a21788227ca6
--- a/source/ATCmdManager.cpp Thu Jun 20 20:46:25 2019 +0000 +++ b/source/ATCmdManager.cpp Sun Jul 07 20:36:41 2019 +0000 @@ -131,19 +131,23 @@ // IDLE response state break; case AT_SCAN_RESP: + { // AT_SCAN_RESP response state dbg_printf(LOG, "\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\r\n"); respStr = (char *) resp_data->buffer; sendAtConfirmationFreeMpool(respStr); at_resp = AT_RESP_NONE; break; + } case AT_DETAILED_SCAN_RESP: + { // AT_DETAILED_SCAN_RESP response state dbg_printf(LOG, "\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\r\n"); respStr = (char *) resp_data->buffer; sendAtConfirmationFreeMpool(respStr); at_resp = AT_RESP_NONE; break; + } case AT_CONNECT_RESP: case WIFI_RECONNECT_INFO: { @@ -155,11 +159,12 @@ char * urc = new char[20]; sprintf(urc, "\r\n%s:%d\r\n", NETWORK_UP_URC, WIFI_INTERFACE_ID); sendAtEvent(urc); - delete urc; + delete[] urc; at_resp = AT_RESP_NONE; break; } - case AT_DISCONNECT_RESP: + case AT_DISCONNECT_RESP: + { // AT_DISCONNECT_RESP response state dbg_printf(LOG, "\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\r\n"); respStr = (char *) resp_data->buffer; @@ -167,29 +172,36 @@ char * urc = new char[20]; sprintf(urc, "\r\n%s:%d\r\n", NETWORK_DOWN_URC, WIFI_INTERFACE_ID); sendAtEvent(urc); - delete urc; + delete[] urc; at_resp = AT_RESP_NONE; break; - case AT_CONFIG_RESP: + } + case AT_CONFIG_RESP: + { // AT_CONFIG_RESP response state dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\r\n"); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); at_resp = AT_RESP_NONE; break; - case AT_NETWORK_STATUS_RESP: + } + case AT_NETWORK_STATUS_RESP: + { // AT_CONFIG_RESP response state dbg_printf(LOG, "\n [ATCMD MAN] NETWORK STATUS RESPONSE RECEIVED!!\r\n"); respStr = (char *) resp_data->buffer; sendAtConfirmationFreeMpool(respStr); at_resp = AT_RESP_NONE; break; + } case AT_WIFI_STATUS_RESP: + { // AT_CONFIG_RESP response state dbg_printf(LOG, "\n [ATCMD MAN] WIFI RESPONSE RECEIVED!!\r\n"); respStr = (char *) resp_data->buffer; sendAtConfirmationFreeMpool(respStr); at_resp = AT_RESP_NONE; break; + } case AT_INTERNET_CONFIG_RESP: // AT_CONFIG_RESP response state dbg_printf(LOG, "\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\r\n"); @@ -320,6 +332,7 @@ at_resp = AT_RESP_NONE; break; case AT_BLE_MAC_RESP: + { // AT_BLE_MAC_RESP response state dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_MAC_RESP RESPONSE RECEIVED!!\r\n"); respStr = (char *) ble_resp_data->buffer; @@ -328,7 +341,9 @@ ble_resp_data = NULL; at_resp = AT_RESP_NONE; break; + } case AT_BLE_NAME_RESP: + { // AT_BLE_MAC_RESP response state dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_NAME_RESP RESPONSE RECEIVED!!\r\n"); respStr = (char *) ble_resp_data->buffer; @@ -337,12 +352,15 @@ ble_resp_data = NULL; at_resp = AT_RESP_NONE; break; + } default: + { //UNKNOWN response state dbg_printf(LOG, "\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n"); sendAtConfirmationFreeMpool(ERROR_RESP); //_parser.send(OK_RESP); at_resp = AT_RESP_NONE; break; + } } } @@ -574,6 +592,29 @@ } return false; } + +int ATCmdManager::readEDMmodeBytes(uint8_t *rx_buf_ptr, int pLen){ + int n, m=0,sz=0; + do{ + sz = (pLen-m); + if(sz > 224) + { + sz = 224; + } + n = _parser.read((char *)rx_buf_ptr, sz); + if(n == -1) + { + dbg_printf(LOG, "Timeout while reading message payload bytes - expected %d but %d read so far!\r\n", pLen, m); + //free(rx_buf_ptr); // make sure to free buffer + //rx_buf_ptr = NULL; + //sendAtConfirmation(UART_TIMEOUT_ERROR); + return n; + } + m+=n; + }while(m < pLen); + return n; +} + // OOB processing void ATCmdManager::_process_oob(uint32_t timeout, bool all){ set_timeout(timeout); @@ -622,12 +663,25 @@ else { int pLen = edm_hdr.payloadLen-2-pT; - rx_buf_ptr = (uint8_t *) malloc (pLen); // we already read 2 bytes from payload but expect 1 stop byte + rx_buf_ptr = (uint8_t *) malloc(pLen); // we already read 2 bytes from payload but expect 1 stop byte + if(rx_buf_ptr == NULL) + { + dbg_printf(LOG, "Memory allocation failed!\r\n"); + free(rx_buf_ptr); // make sure to free buffer + rx_buf_ptr = NULL; + sendAtConfirmation(MEMORY_ALLOCATION_ERROR); + break; // timeout! + } rx_buf_ptr[pLen-1] = 0x00; // clear last byte so the readback value is as expected + // set timeout to 100 ms for large packet + set_timeout(100); n = _parser.read((char *)rx_buf_ptr, pLen); + //n = readEDMmodeBytes(rx_buf_ptr, pLen); + // reset timeout + set_timeout(timeout); if(n == -1) { - dbg_printf(LOG, "Timeout while reading message payload bytes - expected %d!\r\n", pLen); + //dbg_printf(LOG, "Timeout while reading message payload bytes - expected %d!\r\n", pLen); free(rx_buf_ptr); // make sure to free buffer rx_buf_ptr = NULL; sendAtConfirmation(UART_TIMEOUT_ERROR); @@ -637,9 +691,7 @@ printBufferInHex(rx_buf_ptr, pLen); dbg_printf(LOG, "rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]); if(rx_buf_ptr[pLen-1] != EDM_STOP_BYTE) { - _smutex.lock(); - _parser.send("ERR"); - _smutex.unlock(); + sendAtConfirmation("ERR"); free(rx_buf_ptr); // make sure to free buffer rx_buf_ptr = NULL; break; // exit if stop byte not found - possible data corruption! @@ -895,21 +947,27 @@ switch(bleOrWifi) { case 1: + { dbg_printf(LOG, "\nATCmdParser: BLE MAC Address request received"); at_ble_msg_t data_req; data_req.ble_cmd = BLE_CMD_MAC_ADDR; // queue next BLE command queueBleDataRequest(data_req); break; + } case 2: + { dbg_printf(LOG, "\nATCmdParser: WiFi MAC Address request received"); wifi_cmd_t cmd = WIFI_CMD_WIFI_MAC_ADDR; // queue next command queueWiFiCommand(cmd); break; + } default: + { dbg_printf(LOG, "\nATCmdParser: ERROR - UNKNOWN MAC ADDRESS REQUEST RECEIVED!!! \n"); break; + } } } else { dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed"); @@ -1228,7 +1286,7 @@ void ATCmdManager::_oob_getNetworkStatus() { int if_id; // interface id for request - _parser.scanf("%d", &if_id); + _parser.scanf(",%d", &if_id); dbg_printf(LOG, "\n Received Get Network Status command!!\n"); if(if_id == WIFI_INTERFACE_ID){ wifi_cmd_t cmd = WIFI_CMD_NETWORK_STATUS;