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