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