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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Fri Apr 19 08:51:58 2019 +0000
Revision:
96:f5ed273881af
Parent:
95:290859010c8c
Child:
97:0aa46e5ef15d
response instability issues resolved. ; Able to run 10 consecutive hello cloud requests.

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