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