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