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