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