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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Sat May 11 11:55:29 2019 +0000
Branch:
PassingRegression
Revision:
112:a0999ea4ece0
Parent:
110:c722dda4f2ff
Child:
114:b11bb96c09f3
first pass code cleanup

Who changed what in which revision?

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