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