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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Sun Apr 07 10:52:37 2019 +0000
Revision:
90:ed0267eca7b5
Parent:
89:45f6db09a76d
Child:
91:d6b6319ad681
https response format implemented and tested

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