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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Wed Apr 17 18:11:45 2019 +0000
Revision:
95:290859010c8c
Parent:
93:06e755a80187
Child:
96:f5ed273881af
response format for the following command implemented:; - AT+UWSCA; - AT+UNSTAT=0; - AT+UWSSTAT

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