this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Wed Apr 24 17:34:17 2019 +0000
Revision:
102:9748f290a1a5
Parent:
100:80ef4bc31b7a
Child:
103:7b566b522427
added fix for response header issue.; passing regression tests.; known issue:; - UDDRP response incomplete

Who changed what in which revision?

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