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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Sat Apr 13 14:17:29 2019 +0000
Revision:
92:ec9550034276
Parent:
91:d6b6319ad681
Child:
93:06e755a80187
implemented DEFINE switch to resolve mbed memory pool allocation failure

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