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