Okundu Omeni
/
wifi-https-ble-sm-uart-atcmd-5-13-1
this is using the mbed os version 5-13-1
source/ATCmdManager.cpp@87:99b37d26ff2a, 2019-03-29 (annotated)
- Committer:
- ocomeni
- Date:
- Fri Mar 29 22:18:33 2019 +0000
- Revision:
- 87:99b37d26ff2a
- Parent:
- 86:04fc2fcda7ec
- Child:
- 88:7ffa053be662
http/https request and response implemented
Who changed what in which revision?
User | Revision | Line number | New 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 | 84:7c7add00f4bf | 5 | //#include "mbed_memory_status.h" |
ocomeni | 74:f26e846adfe9 | 6 | |
ocomeni | 78:07bb86e3ce14 | 7 | ATCmdManager::ATCmdManager(PinName tx, PinName rx, SMDevicePeripheral *blePeripheral, |
ocomeni | 79:a2187bbfa407 | 8 | events::EventQueue &event_queue, WiFiManager *wifi, |
ocomeni | 79:a2187bbfa407 | 9 | MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool, |
ocomeni | 80:e8f0e92e3ac9 | 10 | Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, |
ocomeni | 81:637a87eb8170 | 11 | MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, |
ocomeni | 81:637a87eb8170 | 12 | Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue, |
ocomeni | 87:99b37d26ff2a | 13 | MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool, |
ocomeni | 87:99b37d26ff2a | 14 | Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue, |
ocomeni | 87:99b37d26ff2a | 15 | MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool, |
ocomeni | 87:99b37d26ff2a | 16 | Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue, |
ocomeni | 79:a2187bbfa407 | 17 | bool debug) |
ocomeni | 74:f26e846adfe9 | 18 | : |
ocomeni | 74:f26e846adfe9 | 19 | _serial(tx, rx, DEFAULT_BAUD_RATE), |
ocomeni | 78:07bb86e3ce14 | 20 | blePeripheral(blePeripheral), |
ocomeni | 79:a2187bbfa407 | 21 | _event_queue(event_queue), |
ocomeni | 79:a2187bbfa407 | 22 | wiFiManager(wiFiManager), |
ocomeni | 79:a2187bbfa407 | 23 | _aT2WiFimPool(aT2WiFimPool), |
ocomeni | 80:e8f0e92e3ac9 | 24 | _aT2WiFiCmdQueue(aT2WiFiCmdQueue), |
ocomeni | 80:e8f0e92e3ac9 | 25 | |
ocomeni | 80:e8f0e92e3ac9 | 26 | _wiFi2ATmPool(wiFi2ATmPool), |
ocomeni | 80:e8f0e92e3ac9 | 27 | _wiFi2ATCmdQueue(wiFi2ATCmdQueue), |
ocomeni | 80:e8f0e92e3ac9 | 28 | |
ocomeni | 80:e8f0e92e3ac9 | 29 | _aT2WiFiDatamPool(aT2WiFiDatamPool), |
ocomeni | 80:e8f0e92e3ac9 | 30 | _aT2WiFiDataQueue(aT2WiFiDataQueue), |
ocomeni | 80:e8f0e92e3ac9 | 31 | |
ocomeni | 80:e8f0e92e3ac9 | 32 | _wiFi2ATDatamPool(wiFi2ATDatamPool), |
ocomeni | 80:e8f0e92e3ac9 | 33 | _wiFi2ATDataQueue(wiFi2ATDataQueue), |
ocomeni | 80:e8f0e92e3ac9 | 34 | |
ocomeni | 80:e8f0e92e3ac9 | 35 | _parser(&_serial) |
ocomeni | 80:e8f0e92e3ac9 | 36 | |
ocomeni | 74:f26e846adfe9 | 37 | |
ocomeni | 74:f26e846adfe9 | 38 | { |
ocomeni | 74:f26e846adfe9 | 39 | // constructor |
ocomeni | 74:f26e846adfe9 | 40 | _serial.set_baud(DEFAULT_BAUD_RATE); |
ocomeni | 74:f26e846adfe9 | 41 | _parser.debug_on(debug); |
ocomeni | 74:f26e846adfe9 | 42 | _parser.set_delimiter("\r\n"); |
ocomeni | 75:08eff6258e1b | 43 | _parser.send("+STARTUP"); |
ocomeni | 81:637a87eb8170 | 44 | _parser.oob("AT\n", callback(this, &ATCmdManager::_oob_ok_hdlr)); |
ocomeni | 75:08eff6258e1b | 45 | _parser.oob("ATE0", callback(this, &ATCmdManager::_oob_echo_off)); |
ocomeni | 75:08eff6258e1b | 46 | _parser.oob("ATE1", callback(this, &ATCmdManager::_oob_echo_on)); |
ocomeni | 75:08eff6258e1b | 47 | _parser.oob("AT+UMRS", callback(this, &ATCmdManager::_oob_uart_setup)); |
ocomeni | 75:08eff6258e1b | 48 | |
ocomeni | 75:08eff6258e1b | 49 | _parser.oob("ATO", callback(this, &ATCmdManager::_oob_data_mode)); |
ocomeni | 75:08eff6258e1b | 50 | _parser.oob("AT+UMLA", callback(this, &ATCmdManager::_oob_get_mac_addr)); |
ocomeni | 75:08eff6258e1b | 51 | _parser.oob("AT+UBTLE?", callback(this, &ATCmdManager::_oob_get_ble_role)); |
ocomeni | 75:08eff6258e1b | 52 | _parser.oob("AT+UBTLE=2", callback(this, &ATCmdManager::_oob_ena_ble_peri)); |
ocomeni | 75:08eff6258e1b | 53 | _parser.oob("AT+CPWROFF", callback(this, &ATCmdManager::_oob_reboot)); |
ocomeni | 75:08eff6258e1b | 54 | _parser.oob("AT+CGMR", callback(this, &ATCmdManager::_oob_get_fw_ver)); |
ocomeni | 82:10072c1794d3 | 55 | _parser.oob("AT+UWSCAN", callback(this, &ATCmdManager::_oob_scanWiFiNetworks)); |
ocomeni | 79:a2187bbfa407 | 56 | _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_connect2WiFiNetwork)); |
ocomeni | 81:637a87eb8170 | 57 | _parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork)); |
ocomeni | 81:637a87eb8170 | 58 | _parser.oob("AT+UDDRP", callback(this, &ATCmdManager::_oob_setupInternetConnection)); |
ocomeni | 82:10072c1794d3 | 59 | _parser.oob("AT+UWSC=0,2", callback(this, &ATCmdManager::_oob_setWiFiSSID)); |
ocomeni | 82:10072c1794d3 | 60 | _parser.oob("AT+UWSC=0,8", callback(this, &ATCmdManager::_oob_setWiFiPWD)); |
ocomeni | 82:10072c1794d3 | 61 | _parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_setWiFiSecurity)); |
ocomeni | 84:7c7add00f4bf | 62 | //_parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_sendHttpMessage)); |
ocomeni | 81:637a87eb8170 | 63 | |
ocomeni | 82:10072c1794d3 | 64 | //AT+UWSC=0,2,<SSID> |
ocomeni | 82:10072c1794d3 | 65 | //AT+UWSC=0,8,<PWD> |
ocomeni | 82:10072c1794d3 | 66 | //AT+UWSC=0,5,2 (WPA) |
ocomeni | 75:08eff6258e1b | 67 | //_parser.oob("ATE0", callback(this, &ATCmdManager::_oob_startup_hdlr)); |
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 | 87:99b37d26ff2a | 71 | event_queue.call_every(120000,&print_memory_info); |
ocomeni | 75:08eff6258e1b | 72 | //AT+UMRS=230400,2,8,1,1,1 |
ocomeni | 74:f26e846adfe9 | 73 | // AT+UBTLE |
ocomeni | 74:f26e846adfe9 | 74 | } |
ocomeni | 74:f26e846adfe9 | 75 | |
ocomeni | 74:f26e846adfe9 | 76 | |
ocomeni | 74:f26e846adfe9 | 77 | void ATCmdManager::runMain(){ |
ocomeni | 87:99b37d26ff2a | 78 | printf("\r\n [ATCMD MAN] Thread Id = %d\r\n", Thread::gettid()); |
ocomeni | 74:f26e846adfe9 | 79 | while(true){ |
ocomeni | 74:f26e846adfe9 | 80 | _process_oob(UBLOX_ODIN_W2_RECV_TIMEOUT, true); |
ocomeni | 81:637a87eb8170 | 81 | wait_ms(MAIN_LOOP_WAIT_TIME_MS); // allow BTLE/WiFi some time |
ocomeni | 81:637a87eb8170 | 82 | processResponses(); |
ocomeni | 74:f26e846adfe9 | 83 | } |
ocomeni | 74:f26e846adfe9 | 84 | |
ocomeni | 74:f26e846adfe9 | 85 | } |
ocomeni | 74:f26e846adfe9 | 86 | |
ocomeni | 81:637a87eb8170 | 87 | void ATCmdManager::processResponses(){ |
ocomeni | 81:637a87eb8170 | 88 | dequeueATresponse(); |
ocomeni | 87:99b37d26ff2a | 89 | dequeueWiFidataResponse(); |
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 | 84:7c7add00f4bf | 96 | //////_smutex.lock(); |
ocomeni | 81:637a87eb8170 | 97 | printf("\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\n"); |
ocomeni | 81:637a87eb8170 | 98 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 99 | //////_smutex.unlock(); |
ocomeni | 81:637a87eb8170 | 100 | at_resp = AT_RESP_NONE; |
ocomeni | 81:637a87eb8170 | 101 | break; |
ocomeni | 81:637a87eb8170 | 102 | case AT_DETAILED_SCAN_RESP: |
ocomeni | 81:637a87eb8170 | 103 | // AT_DETAILED_SCAN_RESP response state |
ocomeni | 84:7c7add00f4bf | 104 | //////_smutex.lock(); |
ocomeni | 81:637a87eb8170 | 105 | printf("\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\n"); |
ocomeni | 81:637a87eb8170 | 106 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 107 | //////_smutex.unlock(); |
ocomeni | 81:637a87eb8170 | 108 | at_resp = AT_RESP_NONE; |
ocomeni | 81:637a87eb8170 | 109 | break; |
ocomeni | 81:637a87eb8170 | 110 | case AT_CONNECT_RESP: |
ocomeni | 81:637a87eb8170 | 111 | // AT_CONNECT_RESP response state |
ocomeni | 84:7c7add00f4bf | 112 | //////_smutex.lock(); |
ocomeni | 81:637a87eb8170 | 113 | printf("\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\n"); |
ocomeni | 81:637a87eb8170 | 114 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 115 | //////_smutex.unlock(); |
ocomeni | 81:637a87eb8170 | 116 | at_resp = AT_RESP_NONE; |
ocomeni | 81:637a87eb8170 | 117 | break; |
ocomeni | 81:637a87eb8170 | 118 | case AT_DISCONNECT_RESP: |
ocomeni | 81:637a87eb8170 | 119 | // AT_DISCONNECT_RESP response state |
ocomeni | 84:7c7add00f4bf | 120 | //////_smutex.lock(); |
ocomeni | 81:637a87eb8170 | 121 | printf("\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\n"); |
ocomeni | 81:637a87eb8170 | 122 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 123 | //////_smutex.unlock(); |
ocomeni | 81:637a87eb8170 | 124 | at_resp = AT_RESP_NONE; |
ocomeni | 81:637a87eb8170 | 125 | break; |
ocomeni | 82:10072c1794d3 | 126 | case AT_CONFIG_RESP: |
ocomeni | 82:10072c1794d3 | 127 | // AT_CONFIG_RESP response state |
ocomeni | 84:7c7add00f4bf | 128 | //////_smutex.lock(); |
ocomeni | 82:10072c1794d3 | 129 | printf("\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\n"); |
ocomeni | 81:637a87eb8170 | 130 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 131 | //////_smutex.unlock(); |
ocomeni | 84:7c7add00f4bf | 132 | at_resp = AT_RESP_NONE; |
ocomeni | 84:7c7add00f4bf | 133 | break; |
ocomeni | 84:7c7add00f4bf | 134 | case AT_INTERNET_CONFIG_RESP: |
ocomeni | 84:7c7add00f4bf | 135 | // AT_CONFIG_RESP response state |
ocomeni | 84:7c7add00f4bf | 136 | //////_smutex.lock(); |
ocomeni | 84:7c7add00f4bf | 137 | printf("\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\n"); |
ocomeni | 84:7c7add00f4bf | 138 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 139 | //////_smutex.unlock(); |
ocomeni | 84:7c7add00f4bf | 140 | at_resp = AT_RESP_NONE; |
ocomeni | 84:7c7add00f4bf | 141 | break; |
ocomeni | 84:7c7add00f4bf | 142 | case AT_HTTPS_RESP: |
ocomeni | 84:7c7add00f4bf | 143 | // AT_HTTP_RESP response state |
ocomeni | 84:7c7add00f4bf | 144 | //////_smutex.lock(); |
ocomeni | 84:7c7add00f4bf | 145 | printf("\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\n"); |
ocomeni | 87:99b37d26ff2a | 146 | return_response(); |
ocomeni | 84:7c7add00f4bf | 147 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 148 | //////_smutex.unlock(); |
ocomeni | 81:637a87eb8170 | 149 | at_resp = AT_RESP_NONE; |
ocomeni | 81:637a87eb8170 | 150 | break; |
ocomeni | 81:637a87eb8170 | 151 | case AT_HTTP_RESP: |
ocomeni | 81:637a87eb8170 | 152 | // AT_HTTP_RESP response state |
ocomeni | 84:7c7add00f4bf | 153 | //////_smutex.lock(); |
ocomeni | 81:637a87eb8170 | 154 | printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\n"); |
ocomeni | 81:637a87eb8170 | 155 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 156 | //////_smutex.unlock(); |
ocomeni | 81:637a87eb8170 | 157 | at_resp = AT_RESP_NONE; |
ocomeni | 81:637a87eb8170 | 158 | break; |
ocomeni | 81:637a87eb8170 | 159 | default: |
ocomeni | 81:637a87eb8170 | 160 | // UNKNOWN response state |
ocomeni | 84:7c7add00f4bf | 161 | //////_smutex.lock(); |
ocomeni | 82:10072c1794d3 | 162 | printf("\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\n"); |
ocomeni | 82:10072c1794d3 | 163 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 164 | //////_smutex.unlock(); |
ocomeni | 81:637a87eb8170 | 165 | at_resp = AT_RESP_NONE; |
ocomeni | 81:637a87eb8170 | 166 | break; |
ocomeni | 81:637a87eb8170 | 167 | } |
ocomeni | 81:637a87eb8170 | 168 | } |
ocomeni | 81:637a87eb8170 | 169 | |
ocomeni | 81:637a87eb8170 | 170 | |
ocomeni | 83:9c271a50a70b | 171 | bool ATCmdManager::validate(edm_header_t edm_header) |
ocomeni | 83:9c271a50a70b | 172 | { |
ocomeni | 83:9c271a50a70b | 173 | if(edm_header.startByte != EDM_START_BYTE)return false; // unexpected start byte found! |
ocomeni | 83:9c271a50a70b | 174 | if(edm_header.payloadID != CONNECT_EVENT && |
ocomeni | 83:9c271a50a70b | 175 | edm_header.payloadID != DISCONNECT_EVENT && |
ocomeni | 83:9c271a50a70b | 176 | edm_header.payloadID != DATA_EVENT && |
ocomeni | 83:9c271a50a70b | 177 | edm_header.payloadID != DATA_COMMAND && |
ocomeni | 83:9c271a50a70b | 178 | edm_header.payloadID != AT_REQUEST && |
ocomeni | 83:9c271a50a70b | 179 | edm_header.payloadID != AT_CONFIRMATION && |
ocomeni | 83:9c271a50a70b | 180 | edm_header.payloadID != AT_EVENT |
ocomeni | 83:9c271a50a70b | 181 | )return false; // unexpected payload ID found! |
ocomeni | 83:9c271a50a70b | 182 | if(edm_header.payloadLen > MAX_EDM_PAYLOAD_LEN || |
ocomeni | 83:9c271a50a70b | 183 | edm_header.payloadLen < MIN_EDM_PAYLOAD_LEN |
ocomeni | 83:9c271a50a70b | 184 | ) return false; // unexpected length received! |
ocomeni | 83:9c271a50a70b | 185 | return true; |
ocomeni | 83:9c271a50a70b | 186 | } |
ocomeni | 74:f26e846adfe9 | 187 | |
ocomeni | 84:7c7add00f4bf | 188 | http_method ATCmdManager::str2HttpMethod(const char * methodStr) |
ocomeni | 84:7c7add00f4bf | 189 | { |
ocomeni | 84:7c7add00f4bf | 190 | http_method _http_method; |
ocomeni | 84:7c7add00f4bf | 191 | if(strstr(methodStr, "POST")!= NULL){ |
ocomeni | 84:7c7add00f4bf | 192 | _http_method = HTTP_POST; |
ocomeni | 84:7c7add00f4bf | 193 | } |
ocomeni | 84:7c7add00f4bf | 194 | else if(strstr(methodStr, "GET")!= NULL){ |
ocomeni | 84:7c7add00f4bf | 195 | _http_method = HTTP_GET; |
ocomeni | 84:7c7add00f4bf | 196 | } |
ocomeni | 84:7c7add00f4bf | 197 | else{ |
ocomeni | 84:7c7add00f4bf | 198 | _http_method = HTTP_DELETE; // unsupported method - set to HTTP_DELETE |
ocomeni | 84:7c7add00f4bf | 199 | } |
ocomeni | 84:7c7add00f4bf | 200 | return _http_method; |
ocomeni | 84:7c7add00f4bf | 201 | } |
ocomeni | 84:7c7add00f4bf | 202 | bool ATCmdManager::createHttpRequest() |
ocomeni | 84:7c7add00f4bf | 203 | { |
ocomeni | 84:7c7add00f4bf | 204 | http_request_t http_req; |
ocomeni | 87:99b37d26ff2a | 205 | printf("\nsizeof(http_req) on creation = %d\n", sizeof(http_req)); |
ocomeni | 87:99b37d26ff2a | 206 | |
ocomeni | 84:7c7add00f4bf | 207 | char s1[32]; |
ocomeni | 84:7c7add00f4bf | 208 | char s2[32]; |
ocomeni | 84:7c7add00f4bf | 209 | char s3[32]; |
ocomeni | 84:7c7add00f4bf | 210 | int n = 0; |
ocomeni | 84:7c7add00f4bf | 211 | int pos = 0; |
ocomeni | 84:7c7add00f4bf | 212 | char * strPtr = (char *)&rx_buf_ptr[1]; |
ocomeni | 84:7c7add00f4bf | 213 | char * p; |
ocomeni | 84:7c7add00f4bf | 214 | char * p2 = strstr(strPtr, "\r\n\r\n"); |
ocomeni | 84:7c7add00f4bf | 215 | char * nxtPtr = strPtr; |
ocomeni | 84:7c7add00f4bf | 216 | char * bodyPtr = p2+4; |
ocomeni | 84:7c7add00f4bf | 217 | printf("\nstrPtr address= %x",strPtr); |
ocomeni | 84:7c7add00f4bf | 218 | printf("\np2 address= %x", p2); |
ocomeni | 84:7c7add00f4bf | 219 | for(int i = 0; i < 5; i++){ |
ocomeni | 84:7c7add00f4bf | 220 | if(i == 0)// firstline scan method uri and http_ver |
ocomeni | 84:7c7add00f4bf | 221 | { |
ocomeni | 84:7c7add00f4bf | 222 | //n = sscanf(nxtPtr,"%s %s %s", &s1[0], &s2[0], &s3[0]); |
ocomeni | 84:7c7add00f4bf | 223 | n = sscanf(nxtPtr,"%s %s %s", s1, s2, s3); |
ocomeni | 84:7c7add00f4bf | 224 | printf("\nmethod = %s\nuri = %s\nhttp_ver = %s",s1, s2, s3 ); |
ocomeni | 84:7c7add00f4bf | 225 | //http_req.method = str2HttpMethod(s1.c_str()); |
ocomeni | 84:7c7add00f4bf | 226 | http_req.method = str2HttpMethod(s1); |
ocomeni | 84:7c7add00f4bf | 227 | http_req.request_URI.assign(s2); |
ocomeni | 84:7c7add00f4bf | 228 | http_req.http_version.assign(s3); |
ocomeni | 84:7c7add00f4bf | 229 | } |
ocomeni | 84:7c7add00f4bf | 230 | else{ // scan header pairs |
ocomeni | 84:7c7add00f4bf | 231 | //n = sscanf(nxtPtr,"%s %s", &s1[0], &s2[0]); |
ocomeni | 84:7c7add00f4bf | 232 | n = sscanf(nxtPtr,"%s %s", s1, s2); |
ocomeni | 84:7c7add00f4bf | 233 | p = strstr(s1,":"); |
ocomeni | 84:7c7add00f4bf | 234 | *p = NULL; |
ocomeni | 84:7c7add00f4bf | 235 | //pos = s1.find(":"); |
ocomeni | 84:7c7add00f4bf | 236 | //s1.replace(pos,1,""); |
ocomeni | 84:7c7add00f4bf | 237 | printf("\nname = %s value = %s",s1, s2); |
ocomeni | 84:7c7add00f4bf | 238 | //if(s1.find("Host")!= string::npos){ |
ocomeni | 86:04fc2fcda7ec | 239 | if(strstr(s1, "Host")!= NULL){ |
ocomeni | 86:04fc2fcda7ec | 240 | http_req.hostName.assign(s2); |
ocomeni | 86:04fc2fcda7ec | 241 | } |
ocomeni | 86:04fc2fcda7ec | 242 | else if(strstr(s1, "Accept")!= NULL){ |
ocomeni | 86:04fc2fcda7ec | 243 | http_req.AcceptVal.assign(s2); |
ocomeni | 86:04fc2fcda7ec | 244 | } |
ocomeni | 86:04fc2fcda7ec | 245 | else if(strstr(s1, "Content-Type")!= NULL){ |
ocomeni | 86:04fc2fcda7ec | 246 | http_req.contentType.assign(s2); |
ocomeni | 86:04fc2fcda7ec | 247 | } |
ocomeni | 86:04fc2fcda7ec | 248 | else if(strstr(s1, "Content-Length")!= NULL){ |
ocomeni | 86:04fc2fcda7ec | 249 | http_req.contentLen.assign(s2); |
ocomeni | 84:7c7add00f4bf | 250 | } |
ocomeni | 84:7c7add00f4bf | 251 | |
ocomeni | 84:7c7add00f4bf | 252 | |
ocomeni | 84:7c7add00f4bf | 253 | } |
ocomeni | 84:7c7add00f4bf | 254 | nxtPtr = strstr(nxtPtr, "\r\n")+2; // goto next line |
ocomeni | 84:7c7add00f4bf | 255 | if(nxtPtr >= p2) break; |
ocomeni | 84:7c7add00f4bf | 256 | } |
ocomeni | 84:7c7add00f4bf | 257 | int bodyLen = edm_hdr.payloadLen -(p2+7-strPtr); |
ocomeni | 84:7c7add00f4bf | 258 | printf("\nLen = %d\n", bodyLen); |
ocomeni | 84:7c7add00f4bf | 259 | memcpy(http_req.body, bodyPtr, bodyLen); |
ocomeni | 84:7c7add00f4bf | 260 | // package and send on wifi data queue |
ocomeni | 84:7c7add00f4bf | 261 | wifi_data_msg_t data_msg; |
ocomeni | 84:7c7add00f4bf | 262 | data_msg.wifi_cmd = WIFI_CMD_SEND_HTTPS_REQ; |
ocomeni | 87:99b37d26ff2a | 263 | printf("\nsizeof(http_req) on population = %d\n", sizeof(http_req)); |
ocomeni | 87:99b37d26ff2a | 264 | /* |
ocomeni | 85:9f896e1e041c | 265 | data_msg.dataLen = sizeof(http_req.method) + |
ocomeni | 85:9f896e1e041c | 266 | sizeof(http_req.body) + |
ocomeni | 85:9f896e1e041c | 267 | http_req.request_URI.capacity() + |
ocomeni | 85:9f896e1e041c | 268 | http_req.http_version.capacity() + |
ocomeni | 85:9f896e1e041c | 269 | http_req.hostName.capacity() + |
ocomeni | 85:9f896e1e041c | 270 | http_req.AcceptVal.capacity() + |
ocomeni | 85:9f896e1e041c | 271 | http_req.contentType.capacity() + |
ocomeni | 85:9f896e1e041c | 272 | http_req.contentLen.capacity(); |
ocomeni | 87:99b37d26ff2a | 273 | */ |
ocomeni | 87:99b37d26ff2a | 274 | data_msg.dataLen = sizeof(http_req.method) + |
ocomeni | 87:99b37d26ff2a | 275 | sizeof(http_req.body) + |
ocomeni | 87:99b37d26ff2a | 276 | http_req.request_URI.size() + |
ocomeni | 87:99b37d26ff2a | 277 | http_req.http_version.size() + |
ocomeni | 87:99b37d26ff2a | 278 | http_req.hostName.size() + |
ocomeni | 87:99b37d26ff2a | 279 | http_req.AcceptVal.size() + |
ocomeni | 87:99b37d26ff2a | 280 | http_req.contentType.size() + |
ocomeni | 87:99b37d26ff2a | 281 | http_req.contentLen.size(); |
ocomeni | 84:7c7add00f4bf | 282 | memcpy(data_msg.buffer,&http_req, data_msg.dataLen); |
ocomeni | 84:7c7add00f4bf | 283 | // queue next data request |
ocomeni | 84:7c7add00f4bf | 284 | queueWiFiDataRequest(data_msg); |
ocomeni | 84:7c7add00f4bf | 285 | return true; |
ocomeni | 84:7c7add00f4bf | 286 | } |
ocomeni | 74:f26e846adfe9 | 287 | // OOB processing |
ocomeni | 74:f26e846adfe9 | 288 | void ATCmdManager::_process_oob(uint32_t timeout, bool all){ |
ocomeni | 74:f26e846adfe9 | 289 | set_timeout(timeout); |
ocomeni | 83:9c271a50a70b | 290 | static int cnt = 0; |
ocomeni | 84:7c7add00f4bf | 291 | int start; |
ocomeni | 83:9c271a50a70b | 292 | if(dataMode == AT_EXT_DATA_MODE) |
ocomeni | 83:9c271a50a70b | 293 | { |
ocomeni | 83:9c271a50a70b | 294 | int n; |
ocomeni | 87:99b37d26ff2a | 295 | //if(cnt++ % 10 == 0)printf("In EDM mode\n"); |
ocomeni | 84:7c7add00f4bf | 296 | uint8_t edm[EDM_HDR_LEN]; |
ocomeni | 84:7c7add00f4bf | 297 | |
ocomeni | 83:9c271a50a70b | 298 | // Poll for edm packets |
ocomeni | 83:9c271a50a70b | 299 | do{ |
ocomeni | 84:7c7add00f4bf | 300 | n = _parser.read((char *)edm, EDM_HDR_LEN); |
ocomeni | 84:7c7add00f4bf | 301 | edm_hdr.startByte = edm[0]; |
ocomeni | 84:7c7add00f4bf | 302 | edm_hdr.payloadLen = edm[1]*256 + edm[2]; |
ocomeni | 84:7c7add00f4bf | 303 | edm_hdr.payloadID = edm[3]*256 + edm[4]; |
ocomeni | 84:7c7add00f4bf | 304 | start = Kernel::get_ms_count(); |
ocomeni | 83:9c271a50a70b | 305 | if(n == -1) break; // break if it times out |
ocomeni | 83:9c271a50a70b | 306 | printf("%d bytes read!\n", n); |
ocomeni | 83:9c271a50a70b | 307 | if(n==5) |
ocomeni | 83:9c271a50a70b | 308 | printf("Start = %d, payloadID = %d len = %d\n", edm_hdr.startByte, |
ocomeni | 83:9c271a50a70b | 309 | edm_hdr.payloadID, |
ocomeni | 83:9c271a50a70b | 310 | edm_hdr.payloadLen); |
ocomeni | 83:9c271a50a70b | 311 | if(n == EDM_HDR_LEN && validate(edm_hdr)) // if AT command use process oob to decode |
ocomeni | 83:9c271a50a70b | 312 | { |
ocomeni | 83:9c271a50a70b | 313 | if(edm_hdr.payloadID == AT_REQUEST) |
ocomeni | 83:9c271a50a70b | 314 | { |
ocomeni | 83:9c271a50a70b | 315 | _parser.process_oob(); |
ocomeni | 83:9c271a50a70b | 316 | break; |
ocomeni | 83:9c271a50a70b | 317 | } |
ocomeni | 83:9c271a50a70b | 318 | else |
ocomeni | 83:9c271a50a70b | 319 | { |
ocomeni | 83:9c271a50a70b | 320 | int pLen = edm_hdr.payloadLen-1; |
ocomeni | 83:9c271a50a70b | 321 | rx_buf_ptr = (uint8_t *) malloc (pLen); // we already read 2 bytes from payload but expect 1 stop byte |
ocomeni | 83:9c271a50a70b | 322 | rx_buf_ptr[pLen-1] = 0x00; // clear last byte so the readback value is as expected |
ocomeni | 83:9c271a50a70b | 323 | n = _parser.read((char *)rx_buf_ptr, pLen); |
ocomeni | 83:9c271a50a70b | 324 | if(n == -1) break; // timeout! |
ocomeni | 83:9c271a50a70b | 325 | printf("%d bytes read - expected %d!\n", n, pLen); |
ocomeni | 83:9c271a50a70b | 326 | for(int i =0;i<pLen;i++){ |
ocomeni | 83:9c271a50a70b | 327 | if(i%8==0) printf("\n[%3d]",i/8); |
ocomeni | 87:99b37d26ff2a | 328 | printf("%02x ", rx_buf_ptr[i]); |
ocomeni | 83:9c271a50a70b | 329 | } |
ocomeni | 83:9c271a50a70b | 330 | printf("\n"); |
ocomeni | 83:9c271a50a70b | 331 | printf("rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]); |
ocomeni | 83:9c271a50a70b | 332 | if(rx_buf_ptr[pLen-1] != EDM_STOP_BYTE) { |
ocomeni | 83:9c271a50a70b | 333 | break; // exit if stop byte now found - possible data corruption! |
ocomeni | 83:9c271a50a70b | 334 | } |
ocomeni | 83:9c271a50a70b | 335 | switch(edm_hdr.payloadID) |
ocomeni | 83:9c271a50a70b | 336 | { |
ocomeni | 83:9c271a50a70b | 337 | case CONNECT_EVENT: |
ocomeni | 83:9c271a50a70b | 338 | printf("Connection Event received!\n"); |
ocomeni | 83:9c271a50a70b | 339 | break; |
ocomeni | 83:9c271a50a70b | 340 | case DISCONNECT_EVENT: |
ocomeni | 83:9c271a50a70b | 341 | printf("DISCONNECT_EVENT received!\n"); |
ocomeni | 83:9c271a50a70b | 342 | break; |
ocomeni | 83:9c271a50a70b | 343 | case DATA_EVENT: |
ocomeni | 83:9c271a50a70b | 344 | printf("DATA_EVENT received!\n"); |
ocomeni | 83:9c271a50a70b | 345 | break; |
ocomeni | 83:9c271a50a70b | 346 | case DATA_COMMAND: |
ocomeni | 83:9c271a50a70b | 347 | printf("DATA_COMMAND received!\n"); |
ocomeni | 84:7c7add00f4bf | 348 | if(createHttpRequest() == true){ |
ocomeni | 84:7c7add00f4bf | 349 | _parser.send("OK"); |
ocomeni | 83:9c271a50a70b | 350 | } |
ocomeni | 84:7c7add00f4bf | 351 | else{ |
ocomeni | 84:7c7add00f4bf | 352 | _parser.send("NACK"); |
ocomeni | 84:7c7add00f4bf | 353 | } |
ocomeni | 84:7c7add00f4bf | 354 | int stop = Kernel::get_ms_count(); |
ocomeni | 84:7c7add00f4bf | 355 | printf("\n Time Elapsed = %d\n", stop-start); |
ocomeni | 83:9c271a50a70b | 356 | break; |
ocomeni | 83:9c271a50a70b | 357 | case AT_REQUEST: |
ocomeni | 83:9c271a50a70b | 358 | printf("AT_REQUEST received!\n"); |
ocomeni | 83:9c271a50a70b | 359 | break; |
ocomeni | 83:9c271a50a70b | 360 | case AT_CONFIRMATION: |
ocomeni | 83:9c271a50a70b | 361 | printf("AT_CONFIRMATION received!\n"); |
ocomeni | 83:9c271a50a70b | 362 | break; |
ocomeni | 83:9c271a50a70b | 363 | case AT_EVENT: |
ocomeni | 83:9c271a50a70b | 364 | printf("AT_EVENT received!\n"); |
ocomeni | 83:9c271a50a70b | 365 | break; |
ocomeni | 83:9c271a50a70b | 366 | default: |
ocomeni | 83:9c271a50a70b | 367 | printf("UNKNOWN MESSAGE received!\n"); |
ocomeni | 83:9c271a50a70b | 368 | break; |
ocomeni | 83:9c271a50a70b | 369 | } |
ocomeni | 83:9c271a50a70b | 370 | } |
ocomeni | 83:9c271a50a70b | 371 | //_parser.process_oob(); |
ocomeni | 83:9c271a50a70b | 372 | } |
ocomeni | 83:9c271a50a70b | 373 | else // incorrect # of bytes received abort!! |
ocomeni | 83:9c271a50a70b | 374 | { |
ocomeni | 83:9c271a50a70b | 375 | break; |
ocomeni | 83:9c271a50a70b | 376 | } |
ocomeni | 83:9c271a50a70b | 377 | }while (all); // continue to process until timeout |
ocomeni | 74:f26e846adfe9 | 378 | } |
ocomeni | 83:9c271a50a70b | 379 | else |
ocomeni | 83:9c271a50a70b | 380 | { |
ocomeni | 83:9c271a50a70b | 381 | // Poll for inbound packets |
ocomeni | 83:9c271a50a70b | 382 | while (_parser.process_oob() && all) { |
ocomeni | 83:9c271a50a70b | 383 | } |
ocomeni | 83:9c271a50a70b | 384 | } |
ocomeni | 74:f26e846adfe9 | 385 | set_timeout(); |
ocomeni | 74:f26e846adfe9 | 386 | } |
ocomeni | 74:f26e846adfe9 | 387 | |
ocomeni | 74:f26e846adfe9 | 388 | |
ocomeni | 74:f26e846adfe9 | 389 | // OOB message handlers |
ocomeni | 74:f26e846adfe9 | 390 | void ATCmdManager::_oob_startup_hdlr(){ |
ocomeni | 74:f26e846adfe9 | 391 | } |
ocomeni | 74:f26e846adfe9 | 392 | |
ocomeni | 81:637a87eb8170 | 393 | void ATCmdManager::_oob_ok_hdlr(){ |
ocomeni | 84:7c7add00f4bf | 394 | //_smutex.lock(); |
ocomeni | 81:637a87eb8170 | 395 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 396 | //_smutex.unlock(); |
ocomeni | 81:637a87eb8170 | 397 | } |
ocomeni | 81:637a87eb8170 | 398 | |
ocomeni | 74:f26e846adfe9 | 399 | |
ocomeni | 74:f26e846adfe9 | 400 | void ATCmdManager::_oob_bleRole_hdlr(){ |
ocomeni | 74:f26e846adfe9 | 401 | } |
ocomeni | 74:f26e846adfe9 | 402 | |
ocomeni | 74:f26e846adfe9 | 403 | |
ocomeni | 74:f26e846adfe9 | 404 | void ATCmdManager::_oob_wifiMode_err(){ |
ocomeni | 74:f26e846adfe9 | 405 | } |
ocomeni | 74:f26e846adfe9 | 406 | |
ocomeni | 74:f26e846adfe9 | 407 | |
ocomeni | 74:f26e846adfe9 | 408 | void ATCmdManager::_oob_conn_already(){ |
ocomeni | 74:f26e846adfe9 | 409 | } |
ocomeni | 74:f26e846adfe9 | 410 | |
ocomeni | 74:f26e846adfe9 | 411 | |
ocomeni | 74:f26e846adfe9 | 412 | void ATCmdManager::_oob_err(){ |
ocomeni | 74:f26e846adfe9 | 413 | } |
ocomeni | 74:f26e846adfe9 | 414 | |
ocomeni | 79:a2187bbfa407 | 415 | void ATCmdManager::_oob_get_fw_ver() |
ocomeni | 79:a2187bbfa407 | 416 | { |
ocomeni | 79:a2187bbfa407 | 417 | } |
ocomeni | 79:a2187bbfa407 | 418 | |
ocomeni | 79:a2187bbfa407 | 419 | |
ocomeni | 75:08eff6258e1b | 420 | void ATCmdManager::_oob_uart_setup(){ |
ocomeni | 75:08eff6258e1b | 421 | int uOpts[NUM_UART_OPTIONS]; |
ocomeni | 75:08eff6258e1b | 422 | //if(_parser.recv("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5])) { |
ocomeni | 75:08eff6258e1b | 423 | 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 | 424 | 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 | 425 | //AT+UMRS=230400,2,8,1,1,1 |
ocomeni | 81:637a87eb8170 | 426 | printf("\n Changing Baud Rate to %d\n", uOpts[0]); |
ocomeni | 81:637a87eb8170 | 427 | |
ocomeni | 81:637a87eb8170 | 428 | _serial.set_baud(uOpts[0]); |
ocomeni | 81:637a87eb8170 | 429 | printf("\n Baud Rate now %d\n", uOpts[0]); |
ocomeni | 81:637a87eb8170 | 430 | |
ocomeni | 75:08eff6258e1b | 431 | } else { |
ocomeni | 75:08eff6258e1b | 432 | printf("\nATCmdParser: Retrieving Uart Options failed"); |
ocomeni | 75:08eff6258e1b | 433 | } |
ocomeni | 75:08eff6258e1b | 434 | } |
ocomeni | 75:08eff6258e1b | 435 | |
ocomeni | 74:f26e846adfe9 | 436 | void ATCmdManager::set_timeout(uint32_t timeout_ms) |
ocomeni | 74:f26e846adfe9 | 437 | { |
ocomeni | 74:f26e846adfe9 | 438 | _parser.set_timeout(timeout_ms); |
ocomeni | 74:f26e846adfe9 | 439 | } |
ocomeni | 74:f26e846adfe9 | 440 | |
ocomeni | 75:08eff6258e1b | 441 | |
ocomeni | 75:08eff6258e1b | 442 | void ATCmdManager::_oob_echo_off() |
ocomeni | 75:08eff6258e1b | 443 | { |
ocomeni | 84:7c7add00f4bf | 444 | //_smutex.lock(); |
ocomeni | 75:08eff6258e1b | 445 | printf("\n Received ATEO OOB command!!\n"); |
ocomeni | 75:08eff6258e1b | 446 | printf("\n turning echo OFF!!\n"); |
ocomeni | 75:08eff6258e1b | 447 | _parser.debug_on(false); |
ocomeni | 75:08eff6258e1b | 448 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 449 | //_smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 450 | } |
ocomeni | 75:08eff6258e1b | 451 | |
ocomeni | 75:08eff6258e1b | 452 | |
ocomeni | 75:08eff6258e1b | 453 | void ATCmdManager::_oob_echo_on() |
ocomeni | 75:08eff6258e1b | 454 | { |
ocomeni | 84:7c7add00f4bf | 455 | //_smutex.lock(); |
ocomeni | 75:08eff6258e1b | 456 | printf("\n Received ATE1 OOB command!!\n"); |
ocomeni | 75:08eff6258e1b | 457 | printf("\n turning echo ON!!\n"); |
ocomeni | 75:08eff6258e1b | 458 | _parser.debug_on(true); |
ocomeni | 75:08eff6258e1b | 459 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 460 | //_smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 461 | } |
ocomeni | 75:08eff6258e1b | 462 | |
ocomeni | 75:08eff6258e1b | 463 | |
ocomeni | 75:08eff6258e1b | 464 | void ATCmdManager::_oob_data_mode(){ |
ocomeni | 84:7c7add00f4bf | 465 | //_smutex.lock(); |
ocomeni | 75:08eff6258e1b | 466 | printf("\n Received EDM mode command!!\n"); |
ocomeni | 75:08eff6258e1b | 467 | if(_parser.scanf("%d", &dataMode) >0) { |
ocomeni | 75:08eff6258e1b | 468 | printf("\nATCmdParser: Data mode=%d\n", dataMode); |
ocomeni | 75:08eff6258e1b | 469 | switch(dataMode) |
ocomeni | 75:08eff6258e1b | 470 | { |
ocomeni | 75:08eff6258e1b | 471 | case 0: |
ocomeni | 83:9c271a50a70b | 472 | printf("\nATCmdParser: Command Mode request received\n"); |
ocomeni | 81:637a87eb8170 | 473 | dataMode = AT_CMD_DATA_MODE; |
ocomeni | 75:08eff6258e1b | 474 | break; |
ocomeni | 75:08eff6258e1b | 475 | case 1: |
ocomeni | 83:9c271a50a70b | 476 | printf("\nATCmdParser: Data Mode request received\n"); |
ocomeni | 81:637a87eb8170 | 477 | dataMode = AT_STD_DATA_MODE; |
ocomeni | 75:08eff6258e1b | 478 | break; |
ocomeni | 75:08eff6258e1b | 479 | case 2: |
ocomeni | 83:9c271a50a70b | 480 | printf("\nATCmdParser: Extended data Mode request received\n"); |
ocomeni | 81:637a87eb8170 | 481 | dataMode = AT_EXT_DATA_MODE; |
ocomeni | 75:08eff6258e1b | 482 | break; |
ocomeni | 75:08eff6258e1b | 483 | default: |
ocomeni | 75:08eff6258e1b | 484 | printf("\nATCmdParser: ERROR - UNKNOWN DATA MODE RECEIVED!!! \n"); |
ocomeni | 75:08eff6258e1b | 485 | break; |
ocomeni | 75:08eff6258e1b | 486 | } |
ocomeni | 75:08eff6258e1b | 487 | } else { |
ocomeni | 83:9c271a50a70b | 488 | printf("\nATCmdParser: Retrieving Uart Options failed\n"); |
ocomeni | 75:08eff6258e1b | 489 | } |
ocomeni | 75:08eff6258e1b | 490 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 491 | //_smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 492 | } |
ocomeni | 75:08eff6258e1b | 493 | |
ocomeni | 75:08eff6258e1b | 494 | void ATCmdManager::_oob_get_mac_addr(){ |
ocomeni | 75:08eff6258e1b | 495 | int bleOrWifi; |
ocomeni | 84:7c7add00f4bf | 496 | //_smutex.lock(); |
ocomeni | 75:08eff6258e1b | 497 | if(_parser.scanf("=%d", &bleOrWifi) >0) { |
ocomeni | 75:08eff6258e1b | 498 | switch(bleOrWifi) |
ocomeni | 75:08eff6258e1b | 499 | { |
ocomeni | 75:08eff6258e1b | 500 | case 1: |
ocomeni | 75:08eff6258e1b | 501 | printf("\nATCmdParser: BLE MAC Address request received"); |
ocomeni | 75:08eff6258e1b | 502 | break; |
ocomeni | 75:08eff6258e1b | 503 | case 2: |
ocomeni | 75:08eff6258e1b | 504 | printf("\nATCmdParser: WiFi MAC Address request received"); |
ocomeni | 75:08eff6258e1b | 505 | break; |
ocomeni | 75:08eff6258e1b | 506 | default: |
ocomeni | 75:08eff6258e1b | 507 | printf("\nATCmdParser: ERROR - UNKNOWN MAC ADDRESS REQUEST RECEIVED!!! \n"); |
ocomeni | 75:08eff6258e1b | 508 | break; |
ocomeni | 75:08eff6258e1b | 509 | } |
ocomeni | 75:08eff6258e1b | 510 | } else { |
ocomeni | 75:08eff6258e1b | 511 | printf("\nATCmdParser: Retrieving Uart Options failed"); |
ocomeni | 75:08eff6258e1b | 512 | } |
ocomeni | 75:08eff6258e1b | 513 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 514 | //_smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 515 | } |
ocomeni | 75:08eff6258e1b | 516 | |
ocomeni | 75:08eff6258e1b | 517 | void ATCmdManager::_oob_get_ble_role(){ |
ocomeni | 84:7c7add00f4bf | 518 | //_smutex.lock(); |
ocomeni | 75:08eff6258e1b | 519 | printf("\n Received get BLE role command!!\n"); |
ocomeni | 75:08eff6258e1b | 520 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 521 | //_smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 522 | } |
ocomeni | 75:08eff6258e1b | 523 | |
ocomeni | 75:08eff6258e1b | 524 | void ATCmdManager::_oob_ena_ble_peri(){ |
ocomeni | 84:7c7add00f4bf | 525 | //_smutex.lock(); |
ocomeni | 75:08eff6258e1b | 526 | printf("\n Received enable BLE Peripheral command!!\n"); |
ocomeni | 75:08eff6258e1b | 527 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 528 | //_smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 529 | } |
ocomeni | 75:08eff6258e1b | 530 | |
ocomeni | 75:08eff6258e1b | 531 | void ATCmdManager::_oob_reboot(){ |
ocomeni | 84:7c7add00f4bf | 532 | //_smutex.lock(); |
ocomeni | 75:08eff6258e1b | 533 | printf("\n Received reboot command!!\n"); |
ocomeni | 75:08eff6258e1b | 534 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 535 | _parser.send("System Resetting....\n"); |
ocomeni | 75:08eff6258e1b | 536 | system_reset(); |
ocomeni | 84:7c7add00f4bf | 537 | //_smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 538 | } |
ocomeni | 75:08eff6258e1b | 539 | |
ocomeni | 79:a2187bbfa407 | 540 | const char * ATCmdManager::sec2str(nsapi_security_t sec) |
ocomeni | 79:a2187bbfa407 | 541 | { |
ocomeni | 79:a2187bbfa407 | 542 | switch (sec) { |
ocomeni | 79:a2187bbfa407 | 543 | case NSAPI_SECURITY_NONE: |
ocomeni | 79:a2187bbfa407 | 544 | return "None"; |
ocomeni | 79:a2187bbfa407 | 545 | case NSAPI_SECURITY_WEP: |
ocomeni | 79:a2187bbfa407 | 546 | return "WEP"; |
ocomeni | 79:a2187bbfa407 | 547 | case NSAPI_SECURITY_WPA: |
ocomeni | 79:a2187bbfa407 | 548 | return "WPA"; |
ocomeni | 79:a2187bbfa407 | 549 | case NSAPI_SECURITY_WPA2: |
ocomeni | 79:a2187bbfa407 | 550 | return "WPA2"; |
ocomeni | 79:a2187bbfa407 | 551 | case NSAPI_SECURITY_WPA_WPA2: |
ocomeni | 79:a2187bbfa407 | 552 | return "WPA/WPA2"; |
ocomeni | 79:a2187bbfa407 | 553 | case NSAPI_SECURITY_UNKNOWN: |
ocomeni | 79:a2187bbfa407 | 554 | default: |
ocomeni | 79:a2187bbfa407 | 555 | return "Unknown"; |
ocomeni | 79:a2187bbfa407 | 556 | } |
ocomeni | 79:a2187bbfa407 | 557 | } |
ocomeni | 81:637a87eb8170 | 558 | |
ocomeni | 81:637a87eb8170 | 559 | bool ATCmdManager::setNextResponse(at_cmd_resp_t resp) |
ocomeni | 81:637a87eb8170 | 560 | { |
ocomeni | 81:637a87eb8170 | 561 | if(at_resp == AT_RESP_NONE){ |
ocomeni | 81:637a87eb8170 | 562 | at_resp = resp; |
ocomeni | 81:637a87eb8170 | 563 | return true; // success |
ocomeni | 81:637a87eb8170 | 564 | } |
ocomeni | 81:637a87eb8170 | 565 | return false; // wiFiManager busy |
ocomeni | 79:a2187bbfa407 | 566 | } |
ocomeni | 79:a2187bbfa407 | 567 | |
ocomeni | 81:637a87eb8170 | 568 | |
ocomeni | 79:a2187bbfa407 | 569 | void ATCmdManager::_oob_scanWiFiNetworks(){ |
ocomeni | 84:7c7add00f4bf | 570 | //_smutex.lock(); |
ocomeni | 79:a2187bbfa407 | 571 | printf("\n Received scanWiFiNetworks command!!\n"); |
ocomeni | 75:08eff6258e1b | 572 | _parser.send("OK\n"); |
ocomeni | 84:7c7add00f4bf | 573 | //_smutex.unlock(); |
ocomeni | 79:a2187bbfa407 | 574 | wifi_cmd_t cmd = WIFI_CMD_SCAN; |
ocomeni | 79:a2187bbfa407 | 575 | // queue next command |
ocomeni | 79:a2187bbfa407 | 576 | queueWiFiCommand(cmd); |
ocomeni | 81:637a87eb8170 | 577 | return; |
ocomeni | 75:08eff6258e1b | 578 | } |
ocomeni | 75:08eff6258e1b | 579 | |
ocomeni | 79:a2187bbfa407 | 580 | void ATCmdManager::_oob_connect2WiFiNetwork() |
ocomeni | 79:a2187bbfa407 | 581 | { |
ocomeni | 81:637a87eb8170 | 582 | wifi_cmd_t cmd = WIFI_CMD_CONNECT; |
ocomeni | 81:637a87eb8170 | 583 | // queue next command |
ocomeni | 81:637a87eb8170 | 584 | queueWiFiCommand(cmd); |
ocomeni | 81:637a87eb8170 | 585 | return; |
ocomeni | 79:a2187bbfa407 | 586 | } |
ocomeni | 79:a2187bbfa407 | 587 | |
ocomeni | 79:a2187bbfa407 | 588 | |
ocomeni | 79:a2187bbfa407 | 589 | void ATCmdManager::_oob_disconnectWiFiNetwork() |
ocomeni | 79:a2187bbfa407 | 590 | { |
ocomeni | 81:637a87eb8170 | 591 | wifi_cmd_t cmd = WIFI_CMD_DISCONNECT; |
ocomeni | 81:637a87eb8170 | 592 | // queue next command |
ocomeni | 81:637a87eb8170 | 593 | queueWiFiCommand(cmd); |
ocomeni | 81:637a87eb8170 | 594 | return; |
ocomeni | 81:637a87eb8170 | 595 | } |
ocomeni | 81:637a87eb8170 | 596 | |
ocomeni | 81:637a87eb8170 | 597 | void ATCmdManager::_oob_setupInternetConnection() |
ocomeni | 81:637a87eb8170 | 598 | { |
ocomeni | 85:9f896e1e041c | 599 | char str[200]; |
ocomeni | 85:9f896e1e041c | 600 | char url[60]; |
ocomeni | 81:637a87eb8170 | 601 | int n; |
ocomeni | 81:637a87eb8170 | 602 | internet_config_t internet_config; |
ocomeni | 85:9f896e1e041c | 603 | //_smutex.lock(); |
ocomeni | 84:7c7add00f4bf | 604 | printf("sizeof internet_config_t = %d\n", sizeof(internet_config_t)); |
ocomeni | 84:7c7add00f4bf | 605 | n = ReadBytes((uint8_t *)str, 199); |
ocomeni | 84:7c7add00f4bf | 606 | str[n]=NULL; |
ocomeni | 84:7c7add00f4bf | 607 | printf("\n read string = %s , n = %d\n", str, n); |
ocomeni | 84:7c7add00f4bf | 608 | n = sscanf(str, "=%1d,%199[^,],%1d", &internet_config.peer_id, |
ocomeni | 81:637a87eb8170 | 609 | url, |
ocomeni | 81:637a87eb8170 | 610 | &internet_config.connectionScheme); |
ocomeni | 84:7c7add00f4bf | 611 | strncpy(internet_config.url, url, strlen(url)+1); |
ocomeni | 84:7c7add00f4bf | 612 | printf("\n read string = %s , n = %d -- strlen(url) = %d\n", internet_config.url, n, strlen(url)); |
ocomeni | 81:637a87eb8170 | 613 | if(n>0) |
ocomeni | 81:637a87eb8170 | 614 | { |
ocomeni | 81:637a87eb8170 | 615 | printf("peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id, |
ocomeni | 84:7c7add00f4bf | 616 | internet_config.url, ///->c_str(), |
ocomeni | 81:637a87eb8170 | 617 | internet_config.connectionScheme); |
ocomeni | 81:637a87eb8170 | 618 | // package and send on wifi data queue |
ocomeni | 84:7c7add00f4bf | 619 | wifi_data_msg_t data_msg; // = (wifi_data_msg_t *) malloc(sizeof(wifi_data_msg_t)); |
ocomeni | 81:637a87eb8170 | 620 | data_msg.wifi_cmd = WIFI_CMD_INTERNET_CONFIG; |
ocomeni | 84:7c7add00f4bf | 621 | data_msg.dataLen = sizeof(internet_config_t); // + strlen(internet_config.url); |
ocomeni | 84:7c7add00f4bf | 622 | printf("\n url size = %d url str = %s\n",strlen(internet_config.url), internet_config.url ); |
ocomeni | 81:637a87eb8170 | 623 | memcpy(data_msg.buffer,&internet_config, data_msg.dataLen); |
ocomeni | 82:10072c1794d3 | 624 | // queue next data request |
ocomeni | 81:637a87eb8170 | 625 | queueWiFiDataRequest(data_msg); |
ocomeni | 84:7c7add00f4bf | 626 | print_memory_info(); |
ocomeni | 82:10072c1794d3 | 627 | _parser.send("OK\n"); |
ocomeni | 81:637a87eb8170 | 628 | } else { |
ocomeni | 81:637a87eb8170 | 629 | printf("\n[ATCMD MAN]: internet configuration failed %d fields parsed \n", n); |
ocomeni | 82:10072c1794d3 | 630 | _parser.send("NAK\n"); |
ocomeni | 82:10072c1794d3 | 631 | } |
ocomeni | 84:7c7add00f4bf | 632 | //_smutex.unlock(); |
ocomeni | 82:10072c1794d3 | 633 | } |
ocomeni | 82:10072c1794d3 | 634 | |
ocomeni | 82:10072c1794d3 | 635 | wifi_config_t ATCmdManager::init_wifi_config() |
ocomeni | 82:10072c1794d3 | 636 | { |
ocomeni | 82:10072c1794d3 | 637 | wifi_config_t wifi_cfg; |
ocomeni | 82:10072c1794d3 | 638 | wifi_cfg.ssid[0] = NULL; |
ocomeni | 82:10072c1794d3 | 639 | wifi_cfg.pass[0] = NULL; |
ocomeni | 82:10072c1794d3 | 640 | wifi_cfg.security = NSAPI_SECURITY_UNKNOWN; |
ocomeni | 82:10072c1794d3 | 641 | return wifi_cfg; |
ocomeni | 82:10072c1794d3 | 642 | } |
ocomeni | 83:9c271a50a70b | 643 | /* read ASCII characters into buffer and null terminate */ |
ocomeni | 83:9c271a50a70b | 644 | int ATCmdManager::readStringBytes(uint8_t *buf, int maxBytes) |
ocomeni | 82:10072c1794d3 | 645 | { |
ocomeni | 82:10072c1794d3 | 646 | int c; |
ocomeni | 82:10072c1794d3 | 647 | int sptr = 0; |
ocomeni | 82:10072c1794d3 | 648 | for(int i=0;i<maxBytes;i++){ |
ocomeni | 82:10072c1794d3 | 649 | c = _parser.getc(); |
ocomeni | 82:10072c1794d3 | 650 | if(c==-1){ |
ocomeni | 83:9c271a50a70b | 651 | buf[sptr] = NULL; // null terminate if string |
ocomeni | 82:10072c1794d3 | 652 | return i; |
ocomeni | 82:10072c1794d3 | 653 | } |
ocomeni | 82:10072c1794d3 | 654 | if(c != ',' && c!= '"'){ |
ocomeni | 82:10072c1794d3 | 655 | buf[sptr++] = (uint8_t) c; |
ocomeni | 82:10072c1794d3 | 656 | } |
ocomeni | 81:637a87eb8170 | 657 | } |
ocomeni | 83:9c271a50a70b | 658 | return maxBytes; |
ocomeni | 83:9c271a50a70b | 659 | } |
ocomeni | 83:9c271a50a70b | 660 | |
ocomeni | 83:9c271a50a70b | 661 | int ATCmdManager::ReadBytes(uint8_t *buf, int maxBytes) |
ocomeni | 83:9c271a50a70b | 662 | { |
ocomeni | 83:9c271a50a70b | 663 | int c; |
ocomeni | 83:9c271a50a70b | 664 | int sptr = 0; |
ocomeni | 83:9c271a50a70b | 665 | for(int i=0;i<maxBytes;i++){ |
ocomeni | 83:9c271a50a70b | 666 | c = _parser.getc(); |
ocomeni | 83:9c271a50a70b | 667 | if(c==-1){ |
ocomeni | 83:9c271a50a70b | 668 | return i; |
ocomeni | 83:9c271a50a70b | 669 | } |
ocomeni | 83:9c271a50a70b | 670 | buf[sptr++] = (uint8_t) c; |
ocomeni | 83:9c271a50a70b | 671 | } |
ocomeni | 83:9c271a50a70b | 672 | return maxBytes; |
ocomeni | 82:10072c1794d3 | 673 | } |
ocomeni | 82:10072c1794d3 | 674 | |
ocomeni | 82:10072c1794d3 | 675 | void ATCmdManager::_oob_setWiFiSSID() |
ocomeni | 82:10072c1794d3 | 676 | { |
ocomeni | 82:10072c1794d3 | 677 | int n; |
ocomeni | 82:10072c1794d3 | 678 | wifi_config_t wifi_cfg = init_wifi_config(); |
ocomeni | 84:7c7add00f4bf | 679 | //_smutex.lock(); |
ocomeni | 83:9c271a50a70b | 680 | n = readStringBytes((uint8_t *)wifi_cfg.ssid, 32); |
ocomeni | 82:10072c1794d3 | 681 | printf("[ATCMD MAN]: number of bytes read = %d\n", n); |
ocomeni | 82:10072c1794d3 | 682 | if(n>0) |
ocomeni | 82:10072c1794d3 | 683 | { |
ocomeni | 82:10072c1794d3 | 684 | printf("[ATCMD MAN]: wifi_cfg.ssid = %s\n", wifi_cfg.ssid); |
ocomeni | 82:10072c1794d3 | 685 | // package and send on wifi data queue |
ocomeni | 82:10072c1794d3 | 686 | wifi_data_msg_t data_msg; |
ocomeni | 82:10072c1794d3 | 687 | data_msg.wifi_cmd = WIFI_CMD_CONFIG; |
ocomeni | 82:10072c1794d3 | 688 | data_msg.dataLen = sizeof(wifi_config_t); |
ocomeni | 82:10072c1794d3 | 689 | memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); |
ocomeni | 82:10072c1794d3 | 690 | queueWiFiDataRequest(data_msg); |
ocomeni | 82:10072c1794d3 | 691 | _parser.send("OK\n"); |
ocomeni | 82:10072c1794d3 | 692 | } else { |
ocomeni | 82:10072c1794d3 | 693 | printf("\n[ATCMD MAN]: wifi configuration failed \n"); |
ocomeni | 82:10072c1794d3 | 694 | _parser.send("NAK\n"); |
ocomeni | 82:10072c1794d3 | 695 | } |
ocomeni | 84:7c7add00f4bf | 696 | //_smutex.unlock(); |
ocomeni | 82:10072c1794d3 | 697 | } |
ocomeni | 82:10072c1794d3 | 698 | |
ocomeni | 82:10072c1794d3 | 699 | void ATCmdManager::_oob_setWiFiPWD() |
ocomeni | 82:10072c1794d3 | 700 | { |
ocomeni | 82:10072c1794d3 | 701 | int n; |
ocomeni | 82:10072c1794d3 | 702 | wifi_config_t wifi_cfg = init_wifi_config(); |
ocomeni | 84:7c7add00f4bf | 703 | //_smutex.lock(); |
ocomeni | 82:10072c1794d3 | 704 | //n = _parser.scanf("%31[^\r\n]", wifi_cfg.pass); |
ocomeni | 83:9c271a50a70b | 705 | n = readStringBytes((uint8_t *)wifi_cfg.pass, 32); |
ocomeni | 82:10072c1794d3 | 706 | if(n>0) |
ocomeni | 82:10072c1794d3 | 707 | { |
ocomeni | 82:10072c1794d3 | 708 | printf("ATCMD MAN]: wifi_cfg.pass = %s\n", wifi_cfg.pass); |
ocomeni | 82:10072c1794d3 | 709 | // package and send on wifi data queue |
ocomeni | 82:10072c1794d3 | 710 | wifi_data_msg_t data_msg; |
ocomeni | 82:10072c1794d3 | 711 | data_msg.wifi_cmd = WIFI_CMD_CONFIG; |
ocomeni | 82:10072c1794d3 | 712 | data_msg.dataLen = sizeof(wifi_config_t); |
ocomeni | 82:10072c1794d3 | 713 | memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); |
ocomeni | 82:10072c1794d3 | 714 | queueWiFiDataRequest(data_msg); |
ocomeni | 82:10072c1794d3 | 715 | _parser.send("OK\n"); |
ocomeni | 82:10072c1794d3 | 716 | } else { |
ocomeni | 82:10072c1794d3 | 717 | printf("\n[ATCMD MAN]: wifi configuration failed \n"); |
ocomeni | 82:10072c1794d3 | 718 | _parser.send("NAK\n"); |
ocomeni | 82:10072c1794d3 | 719 | } |
ocomeni | 84:7c7add00f4bf | 720 | //_smutex.unlock(); |
ocomeni | 82:10072c1794d3 | 721 | } |
ocomeni | 82:10072c1794d3 | 722 | |
ocomeni | 82:10072c1794d3 | 723 | void ATCmdManager::_oob_setWiFiSecurity() |
ocomeni | 82:10072c1794d3 | 724 | { |
ocomeni | 82:10072c1794d3 | 725 | int n; |
ocomeni | 82:10072c1794d3 | 726 | wifi_config_t wifi_cfg = init_wifi_config(); |
ocomeni | 84:7c7add00f4bf | 727 | //_smutex.lock(); |
ocomeni | 82:10072c1794d3 | 728 | n = _parser.scanf(",%d", &wifi_cfg.security); |
ocomeni | 82:10072c1794d3 | 729 | if(n>0) |
ocomeni | 82:10072c1794d3 | 730 | { |
ocomeni | 82:10072c1794d3 | 731 | printf("ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security)); |
ocomeni | 82:10072c1794d3 | 732 | // package and send on wifi data queue |
ocomeni | 82:10072c1794d3 | 733 | wifi_data_msg_t data_msg; |
ocomeni | 82:10072c1794d3 | 734 | data_msg.wifi_cmd = WIFI_CMD_CONFIG; |
ocomeni | 82:10072c1794d3 | 735 | data_msg.dataLen = sizeof(wifi_config_t); |
ocomeni | 82:10072c1794d3 | 736 | memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); |
ocomeni | 82:10072c1794d3 | 737 | queueWiFiDataRequest(data_msg); |
ocomeni | 82:10072c1794d3 | 738 | _parser.send("OK\n"); |
ocomeni | 82:10072c1794d3 | 739 | } else { |
ocomeni | 82:10072c1794d3 | 740 | printf("\n[ATCMD MAN]: wifi configuration failed \n"); |
ocomeni | 82:10072c1794d3 | 741 | _parser.send("NAK\n"); |
ocomeni | 82:10072c1794d3 | 742 | } |
ocomeni | 84:7c7add00f4bf | 743 | //_smutex.unlock(); |
ocomeni | 79:a2187bbfa407 | 744 | } |
ocomeni | 81:637a87eb8170 | 745 | |
ocomeni | 83:9c271a50a70b | 746 | |
ocomeni | 83:9c271a50a70b | 747 | void ATCmdManager::_oob_sendHttpMessage() |
ocomeni | 83:9c271a50a70b | 748 | { |
ocomeni | 83:9c271a50a70b | 749 | int n; |
ocomeni | 84:7c7add00f4bf | 750 | http_request_t http_post_request; |
ocomeni | 84:7c7add00f4bf | 751 | //_smutex.lock(); |
ocomeni | 83:9c271a50a70b | 752 | /* |
ocomeni | 83:9c271a50a70b | 753 | n = _parser.scanf(",%d", &wifi_cfg.security); |
ocomeni | 83:9c271a50a70b | 754 | if(n>0) |
ocomeni | 83:9c271a50a70b | 755 | { |
ocomeni | 83:9c271a50a70b | 756 | printf("ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security)); |
ocomeni | 83:9c271a50a70b | 757 | // package and send on wifi data queue |
ocomeni | 83:9c271a50a70b | 758 | wifi_data_msg_t data_msg; |
ocomeni | 83:9c271a50a70b | 759 | data_msg.wifi_cmd = WIFI_CMD_CONFIG; |
ocomeni | 83:9c271a50a70b | 760 | data_msg.dataLen = sizeof(wifi_config_t); |
ocomeni | 83:9c271a50a70b | 761 | memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); |
ocomeni | 83:9c271a50a70b | 762 | queueWiFiDataRequest(data_msg); |
ocomeni | 83:9c271a50a70b | 763 | _parser.send("OK\n"); |
ocomeni | 83:9c271a50a70b | 764 | } else { |
ocomeni | 83:9c271a50a70b | 765 | printf("\n[ATCMD MAN]: wifi configuration failed \n"); |
ocomeni | 83:9c271a50a70b | 766 | _parser.send("NAK\n"); |
ocomeni | 83:9c271a50a70b | 767 | } |
ocomeni | 83:9c271a50a70b | 768 | */ |
ocomeni | 84:7c7add00f4bf | 769 | //_smutex.unlock(); |
ocomeni | 83:9c271a50a70b | 770 | |
ocomeni | 83:9c271a50a70b | 771 | } |
ocomeni | 83:9c271a50a70b | 772 | |
ocomeni | 81:637a87eb8170 | 773 | bool ATCmdManager::queueWiFiCommand(wifi_cmd_t cmd){ |
ocomeni | 81:637a87eb8170 | 774 | wifi_cmd_message_t *wifiCmd = _aT2WiFimPool->alloc(); |
ocomeni | 81:637a87eb8170 | 775 | wifiCmd->wifi_cmd = cmd; |
ocomeni | 81:637a87eb8170 | 776 | _aT2WiFiCmdQueue->put(wifiCmd); |
ocomeni | 81:637a87eb8170 | 777 | return true; |
ocomeni | 81:637a87eb8170 | 778 | } |
ocomeni | 81:637a87eb8170 | 779 | |
ocomeni | 81:637a87eb8170 | 780 | bool ATCmdManager::dequeueATresponse(){ |
ocomeni | 81:637a87eb8170 | 781 | if(at_resp != AT_RESP_NONE) return false; // busy |
ocomeni | 81:637a87eb8170 | 782 | osEvent evt = _wiFi2ATCmdQueue->get(0); |
ocomeni | 81:637a87eb8170 | 783 | if(evt.status == osEventMessage){ |
ocomeni | 81:637a87eb8170 | 784 | at_resp_message_t *resp = (at_resp_message_t*)evt.value.p; |
ocomeni | 81:637a87eb8170 | 785 | setNextResponse(resp->at_resp); |
ocomeni | 81:637a87eb8170 | 786 | _wiFi2ATmPool->free(resp); |
ocomeni | 81:637a87eb8170 | 787 | } |
ocomeni | 81:637a87eb8170 | 788 | return true; |
ocomeni | 81:637a87eb8170 | 789 | } |
ocomeni | 81:637a87eb8170 | 790 | |
ocomeni | 81:637a87eb8170 | 791 | bool ATCmdManager::queueWiFiDataRequest(wifi_data_msg_t data_req){ |
ocomeni | 81:637a87eb8170 | 792 | wifi_data_msg_t *wifiData = _aT2WiFiDatamPool->alloc(); |
ocomeni | 81:637a87eb8170 | 793 | wifiData->wifi_cmd = data_req.wifi_cmd; |
ocomeni | 81:637a87eb8170 | 794 | wifiData->dataLen = data_req.dataLen; |
ocomeni | 81:637a87eb8170 | 795 | memcpy(wifiData->buffer, data_req.buffer, data_req.dataLen); |
ocomeni | 81:637a87eb8170 | 796 | _aT2WiFiDataQueue->put(wifiData); |
ocomeni | 81:637a87eb8170 | 797 | printf("[ATCMD MAN] queued data size = %d : wifi_cmd = %d\n", data_req.dataLen, data_req.wifi_cmd); |
ocomeni | 84:7c7add00f4bf | 798 | //free(&data_req); |
ocomeni | 81:637a87eb8170 | 799 | return true; |
ocomeni | 81:637a87eb8170 | 800 | } |
ocomeni | 81:637a87eb8170 | 801 | |
ocomeni | 87:99b37d26ff2a | 802 | bool ATCmdManager::dequeueWiFidataResponse(){ |
ocomeni | 81:637a87eb8170 | 803 | if(at_resp != AT_RESP_NONE) return false; // busy |
ocomeni | 81:637a87eb8170 | 804 | osEvent evt = _wiFi2ATDataQueue->get(0); |
ocomeni | 81:637a87eb8170 | 805 | if(evt.status == osEventMessage){ |
ocomeni | 81:637a87eb8170 | 806 | resp_data = (at_data_msg_t*)evt.value.p; |
ocomeni | 81:637a87eb8170 | 807 | setNextResponse(resp_data->at_resp); |
ocomeni | 81:637a87eb8170 | 808 | //_wiFi2ATDatamPool->free(resp_data); |
ocomeni | 81:637a87eb8170 | 809 | } |
ocomeni | 81:637a87eb8170 | 810 | return true; |
ocomeni | 81:637a87eb8170 | 811 | } |
ocomeni | 81:637a87eb8170 | 812 | |
ocomeni | 81:637a87eb8170 | 813 | |
ocomeni | 87:99b37d26ff2a | 814 | void ATCmdManager::return_response() { |
ocomeni | 87:99b37d26ff2a | 815 | char * resp = (char *) resp_data->buffer; |
ocomeni | 87:99b37d26ff2a | 816 | printf("\n[ATCMD MAN] received response:\n"); |
ocomeni | 87:99b37d26ff2a | 817 | printf("%s\r\n", (char *)resp); |
ocomeni | 87:99b37d26ff2a | 818 | _wiFi2ATDatamPool->free(resp_data); |
ocomeni | 87:99b37d26ff2a | 819 | |
ocomeni | 87:99b37d26ff2a | 820 | } |