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