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