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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Fri Jun 14 21:13:46 2019 +0000
Branch:
PassingRegression
Revision:
123:a49e9ffbaca6
Parent:
122:62166886db5f
Child:
124:eae4512b131b
Implemented the following features:; 1. FW version; 2. BLE MAC address; 3. BLE name; 4. WiFi MAC address; Not fully tested

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ocomeni 103:7b566b522427 1 #include "debug.h"
ocomeni 74:f26e846adfe9 2 #include "ATCmdManager.h"
ocomeni 79:a2187bbfa407 3 #include "common_types.h"
ocomeni 114:b11bb96c09f3 4 #include "main.h"
ocomeni 84:7c7add00f4bf 5 #include "http_request.h"
ocomeni 92:ec9550034276 6 #include "mbed_memory_status.h"
ocomeni 84:7c7add00f4bf 7 //#include "mbed_memory_status.h"
ocomeni 103:7b566b522427 8 #define FILE_CODE "atcmd"
ocomeni 74:f26e846adfe9 9
ocomeni 117:8fd05113efc1 10 ATCmdManager::ATCmdManager(PinName tx, PinName rx, uart_config_t *uart_config,
ocomeni 79:a2187bbfa407 11 events::EventQueue &event_queue, WiFiManager *wifi,
ocomeni 79:a2187bbfa407 12 MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool,
ocomeni 80:e8f0e92e3ac9 13 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue,
ocomeni 81:637a87eb8170 14 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool,
ocomeni 81:637a87eb8170 15 Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue,
ocomeni 87:99b37d26ff2a 16 MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool,
ocomeni 87:99b37d26ff2a 17 Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue,
ocomeni 87:99b37d26ff2a 18 MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool,
ocomeni 87:99b37d26ff2a 19 Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue,
ocomeni 118:8df0e9c2ee3f 20 MemoryPool<at_ble_msg_t, PQDSZ_BLE> *aT2BleDatamPool,
ocomeni 118:8df0e9c2ee3f 21 Queue<at_ble_msg_t, PQDSZ_BLE> *aT2BleDataQueue,
ocomeni 118:8df0e9c2ee3f 22 MemoryPool<ble_at_msg_t, PQDSZ_BLE> *ble2ATDatamPool,
ocomeni 118:8df0e9c2ee3f 23 Queue<ble_at_msg_t, PQDSZ_BLE> *ble2ATDataQueue,
ocomeni 121:ac4f59839e4f 24 startup_config_t *startup_config, bool debug)
ocomeni 74:f26e846adfe9 25 :
ocomeni 74:f26e846adfe9 26 _serial(tx, rx, DEFAULT_BAUD_RATE),
ocomeni 117:8fd05113efc1 27 uart_config(uart_config),
ocomeni 79:a2187bbfa407 28 _event_queue(event_queue),
ocomeni 79:a2187bbfa407 29 wiFiManager(wiFiManager),
ocomeni 79:a2187bbfa407 30 _aT2WiFimPool(aT2WiFimPool),
ocomeni 80:e8f0e92e3ac9 31 _aT2WiFiCmdQueue(aT2WiFiCmdQueue),
ocomeni 80:e8f0e92e3ac9 32
ocomeni 80:e8f0e92e3ac9 33 _wiFi2ATmPool(wiFi2ATmPool),
ocomeni 80:e8f0e92e3ac9 34 _wiFi2ATCmdQueue(wiFi2ATCmdQueue),
ocomeni 80:e8f0e92e3ac9 35
ocomeni 80:e8f0e92e3ac9 36 _aT2WiFiDatamPool(aT2WiFiDatamPool),
ocomeni 80:e8f0e92e3ac9 37 _aT2WiFiDataQueue(aT2WiFiDataQueue),
ocomeni 80:e8f0e92e3ac9 38
ocomeni 80:e8f0e92e3ac9 39 _wiFi2ATDatamPool(wiFi2ATDatamPool),
ocomeni 80:e8f0e92e3ac9 40 _wiFi2ATDataQueue(wiFi2ATDataQueue),
ocomeni 118:8df0e9c2ee3f 41 _aT2BleDatamPool(aT2BleDatamPool),
ocomeni 118:8df0e9c2ee3f 42 _aT2BleDataQueue(aT2BleDataQueue),
ocomeni 118:8df0e9c2ee3f 43 _ble2ATDatamPool(ble2ATDatamPool),
ocomeni 118:8df0e9c2ee3f 44 _ble2ATDataQueue(ble2ATDataQueue),
ocomeni 121:ac4f59839e4f 45 startup_config(startup_config),
ocomeni 118:8df0e9c2ee3f 46 _parser(&_serial)
ocomeni 80:e8f0e92e3ac9 47
ocomeni 74:f26e846adfe9 48
ocomeni 74:f26e846adfe9 49 {
ocomeni 74:f26e846adfe9 50 // constructor
ocomeni 117:8fd05113efc1 51 _serial.set_baud(uart_config->baudrate);
ocomeni 103:7b566b522427 52 //Flow flowCtrl = Flow::Disabled;
ocomeni 103:7b566b522427 53 //_serial.set_flow_control(mbed::SerialBase::Disabled);
ocomeni 74:f26e846adfe9 54 _parser.debug_on(debug);
ocomeni 74:f26e846adfe9 55 _parser.set_delimiter("\r\n");
ocomeni 103:7b566b522427 56 _parser.send("+STARTUP\r\n\r\n");
ocomeni 103:7b566b522427 57 _parser.oob("AT\r", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 75:08eff6258e1b 58 _parser.oob("ATE0", callback(this, &ATCmdManager::_oob_echo_off));
ocomeni 75:08eff6258e1b 59 _parser.oob("ATE1", callback(this, &ATCmdManager::_oob_echo_on));
ocomeni 118:8df0e9c2ee3f 60 _parser.oob("ATE2", callback(this, &ATCmdManager::_oob_debug_logs_on));
ocomeni 118:8df0e9c2ee3f 61 _parser.oob("ATE3", callback(this, &ATCmdManager::_oob_debug_logs_off));
ocomeni 75:08eff6258e1b 62 _parser.oob("AT+UMRS", callback(this, &ATCmdManager::_oob_uart_setup));
ocomeni 75:08eff6258e1b 63
ocomeni 75:08eff6258e1b 64 _parser.oob("ATO", callback(this, &ATCmdManager::_oob_data_mode));
ocomeni 75:08eff6258e1b 65 _parser.oob("AT+UMLA", callback(this, &ATCmdManager::_oob_get_mac_addr));
ocomeni 75:08eff6258e1b 66 _parser.oob("AT+UBTLE?", callback(this, &ATCmdManager::_oob_get_ble_role));
ocomeni 75:08eff6258e1b 67 _parser.oob("AT+UBTLE=2", callback(this, &ATCmdManager::_oob_ena_ble_peri));
ocomeni 75:08eff6258e1b 68 _parser.oob("AT+CPWROFF", callback(this, &ATCmdManager::_oob_reboot));
ocomeni 75:08eff6258e1b 69 _parser.oob("AT+CGMR", callback(this, &ATCmdManager::_oob_get_fw_ver));
ocomeni 82:10072c1794d3 70 _parser.oob("AT+UWSCAN", callback(this, &ATCmdManager::_oob_scanWiFiNetworks));
ocomeni 98:65c2333a38b6 71 _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_WiFiStationConfigAction));
ocomeni 102:9748f290a1a5 72
ocomeni 123:a49e9ffbaca6 73 _parser.oob("AAT+UBTLN?", callback(this, &ATCmdManager::_oob_get_ble_name));
ocomeni 123:a49e9ffbaca6 74 _parser.oob("AT+UBTLN=", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 102:9748f290a1a5 75 _parser.oob("AT+UBTSM?", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 102:9748f290a1a5 76 _parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 102:9748f290a1a5 77
ocomeni 102:9748f290a1a5 78 _parser.oob("AT+UDSC=", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 121:ac4f59839e4f 79 _parser.oob("AT&W", callback(this, &ATCmdManager::_oob_saveSettings_hdlr));
ocomeni 102:9748f290a1a5 80 //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 102:9748f290a1a5 81 //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
ocomeni 95:290859010c8c 82 //_parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork));
ocomeni 81:637a87eb8170 83 _parser.oob("AT+UDDRP", callback(this, &ATCmdManager::_oob_setupInternetConnection));
ocomeni 114:b11bb96c09f3 84 _parser.oob("AT+UWSC=0,0,0", callback(this, &ATCmdManager::_oob_enable_wifi));
ocomeni 82:10072c1794d3 85 _parser.oob("AT+UWSC=0,2", callback(this, &ATCmdManager::_oob_setWiFiSSID));
ocomeni 82:10072c1794d3 86 _parser.oob("AT+UWSC=0,8", callback(this, &ATCmdManager::_oob_setWiFiPWD));
ocomeni 82:10072c1794d3 87 _parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_setWiFiSecurity));
ocomeni 95:290859010c8c 88 _parser.oob("AT+UNSTAT=", callback(this, &ATCmdManager::_oob_getNetworkStatus));
ocomeni 95:290859010c8c 89 _parser.oob("AT+UWSSTAT", callback(this, &ATCmdManager::_oob_WiFiNetworkStatus));
ocomeni 95:290859010c8c 90
ocomeni 121:ac4f59839e4f 91 _parser.oob("AT+UFACTORY", callback(this, &ATCmdManager::_oob_factoryReset));
ocomeni 121:ac4f59839e4f 92 _parser.oob("AT+UDELCFG=", callback(this, &ATCmdManager::_oob_deleteConfiguration));
ocomeni 121:ac4f59839e4f 93
ocomeni 84:7c7add00f4bf 94 //_parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_sendHttpMessage));
ocomeni 103:7b566b522427 95 //sendAtConfirmation("Testing:: +UBTLE:2\r\nOK\r\n");
ocomeni 103:7b566b522427 96 dbg_printf(LOG, "\n --- ATCmdManager constructor completed ---\n");
ocomeni 81:637a87eb8170 97 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 98 dataMode = AT_CMD_DATA_MODE;
ocomeni 98:65c2333a38b6 99 debug_flag = 0;
ocomeni 104:11e9605093c9 100 wifiStateControl = AT_RESP_NONE;
ocomeni 108:3c8fb2c6e7bf 101 //_event_queue.call_in(10, &print_heap_and_isr_stack_info);
ocomeni 98:65c2333a38b6 102 //print_heap_and_isr_stack_info();
ocomeni 108:3c8fb2c6e7bf 103 //_event_queue.call_every(3600000,&print_memory_info);
ocomeni 118:8df0e9c2ee3f 104 lastHttpRespTime = Kernel::get_ms_count();
ocomeni 118:8df0e9c2ee3f 105 lastCloudMsgType = 0x00;
ocomeni 108:3c8fb2c6e7bf 106 _event_queue.call_every(10000,&blinkLEDs);
ocomeni 103:7b566b522427 107 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 108 check_for_at_cmd = false;
ocomeni 103:7b566b522427 109 #endif
ocomeni 74:f26e846adfe9 110 }
ocomeni 74:f26e846adfe9 111
ocomeni 74:f26e846adfe9 112
ocomeni 74:f26e846adfe9 113 void ATCmdManager::runMain(){
ocomeni 103:7b566b522427 114 dbg_printf(LOG, "\r\n [ATCMD MAN] Thread Id = %X\r\n", (uint32_t)ThisThread::get_id());
ocomeni 74:f26e846adfe9 115 while(true){
ocomeni 74:f26e846adfe9 116 _process_oob(UBLOX_ODIN_W2_RECV_TIMEOUT, true);
ocomeni 81:637a87eb8170 117 wait_ms(MAIN_LOOP_WAIT_TIME_MS); // allow BTLE/WiFi some time
ocomeni 81:637a87eb8170 118 processResponses();
ocomeni 74:f26e846adfe9 119 }
ocomeni 74:f26e846adfe9 120
ocomeni 74:f26e846adfe9 121 }
ocomeni 74:f26e846adfe9 122
ocomeni 81:637a87eb8170 123 void ATCmdManager::processResponses(){
ocomeni 81:637a87eb8170 124 dequeueATresponse();
ocomeni 87:99b37d26ff2a 125 dequeueWiFidataResponse();
ocomeni 120:779b74689747 126 dequeueBleDataResponse();
ocomeni 104:11e9605093c9 127 updateWiFiMgrStatus();
ocomeni 95:290859010c8c 128 char * respStr;
ocomeni 81:637a87eb8170 129 switch(at_resp){
ocomeni 81:637a87eb8170 130 case AT_RESP_NONE:
ocomeni 81:637a87eb8170 131 // IDLE response state
ocomeni 81:637a87eb8170 132 break;
ocomeni 81:637a87eb8170 133 case AT_SCAN_RESP:
ocomeni 81:637a87eb8170 134 // AT_SCAN_RESP response state
ocomeni 103:7b566b522427 135 dbg_printf(LOG, "\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 136 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 137 sendAtConfirmationFreeMpool(respStr);
ocomeni 81:637a87eb8170 138 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 139 break;
ocomeni 81:637a87eb8170 140 case AT_DETAILED_SCAN_RESP:
ocomeni 81:637a87eb8170 141 // AT_DETAILED_SCAN_RESP response state
ocomeni 103:7b566b522427 142 dbg_printf(LOG, "\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 143 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 144 sendAtConfirmationFreeMpool(respStr);
ocomeni 81:637a87eb8170 145 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 146 break;
ocomeni 81:637a87eb8170 147 case AT_CONNECT_RESP:
ocomeni 99:05398b3184f8 148 {
ocomeni 81:637a87eb8170 149 // AT_CONNECT_RESP response state
ocomeni 103:7b566b522427 150 dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\r\n");
ocomeni 103:7b566b522427 151 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 95:290859010c8c 152 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 153 sendAtConfirmationFreeMpool(respStr);
ocomeni 99:05398b3184f8 154 char * urc = new char[20];
ocomeni 104:11e9605093c9 155 sprintf(urc, "\r\n%s:%d\r\n", NETWORK_UP_URC, WIFI_INTERFACE_ID);
ocomeni 99:05398b3184f8 156 sendAtEvent(urc);
ocomeni 99:05398b3184f8 157 delete urc;
ocomeni 81:637a87eb8170 158 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 159 break;
ocomeni 99:05398b3184f8 160 }
ocomeni 81:637a87eb8170 161 case AT_DISCONNECT_RESP:
ocomeni 81:637a87eb8170 162 // AT_DISCONNECT_RESP response state
ocomeni 103:7b566b522427 163 dbg_printf(LOG, "\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 164 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 165 sendAtConfirmationFreeMpool(respStr);
ocomeni 81:637a87eb8170 166 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 167 break;
ocomeni 82:10072c1794d3 168 case AT_CONFIG_RESP:
ocomeni 82:10072c1794d3 169 // AT_CONFIG_RESP response state
ocomeni 103:7b566b522427 170 dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 171 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 84:7c7add00f4bf 172 at_resp = AT_RESP_NONE;
ocomeni 84:7c7add00f4bf 173 break;
ocomeni 95:290859010c8c 174 case AT_NETWORK_STATUS_RESP:
ocomeni 95:290859010c8c 175 // AT_CONFIG_RESP response state
ocomeni 103:7b566b522427 176 dbg_printf(LOG, "\n [ATCMD MAN] NETWORK STATUS RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 177 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 178 sendAtConfirmationFreeMpool(respStr);
ocomeni 95:290859010c8c 179 at_resp = AT_RESP_NONE;
ocomeni 95:290859010c8c 180 break;
ocomeni 95:290859010c8c 181 case AT_WIFI_STATUS_RESP:
ocomeni 95:290859010c8c 182 // AT_CONFIG_RESP response state
ocomeni 103:7b566b522427 183 dbg_printf(LOG, "\n [ATCMD MAN] WIFI RESPONSE RECEIVED!!\r\n");
ocomeni 95:290859010c8c 184 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 185 sendAtConfirmationFreeMpool(respStr);
ocomeni 95:290859010c8c 186 at_resp = AT_RESP_NONE;
ocomeni 95:290859010c8c 187 break;
ocomeni 84:7c7add00f4bf 188 case AT_INTERNET_CONFIG_RESP:
ocomeni 84:7c7add00f4bf 189 // AT_CONFIG_RESP response state
ocomeni 103:7b566b522427 190 dbg_printf(LOG, "\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\r\n");
ocomeni 96:f5ed273881af 191 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 84:7c7add00f4bf 192 at_resp = AT_RESP_NONE;
ocomeni 84:7c7add00f4bf 193 break;
ocomeni 84:7c7add00f4bf 194 case AT_HTTPS_RESP:
ocomeni 84:7c7add00f4bf 195 // AT_HTTP_RESP response state
ocomeni 103:7b566b522427 196 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\r\n");
ocomeni 87:99b37d26ff2a 197 return_response();
ocomeni 95:290859010c8c 198 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 81:637a87eb8170 199 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 200 break;
ocomeni 89:45f6db09a76d 201 case AT_HTTPS_RESP_DOWNLOAD:
ocomeni 89:45f6db09a76d 202 // AT_HTTPS_RESP_DOWNLOAD response state
ocomeni 103:7b566b522427 203 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTPS DOWNLOAD RESPONSE RECEIVED!!\r\n");
ocomeni 89:45f6db09a76d 204 return_response(true); // set download paramter to true
ocomeni 89:45f6db09a76d 205 at_resp = AT_RESP_NONE;
ocomeni 89:45f6db09a76d 206 break;
ocomeni 81:637a87eb8170 207 case AT_HTTP_RESP:
ocomeni 81:637a87eb8170 208 // AT_HTTP_RESP response state
ocomeni 103:7b566b522427 209 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n");
ocomeni 89:45f6db09a76d 210 return_response();
ocomeni 89:45f6db09a76d 211 at_resp = AT_RESP_NONE;
ocomeni 89:45f6db09a76d 212 break;
ocomeni 89:45f6db09a76d 213 case AT_HTTP_RESP_DOWNLOAD:
ocomeni 89:45f6db09a76d 214 // AT_HTTP_RESP response state
ocomeni 103:7b566b522427 215 dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n");
ocomeni 89:45f6db09a76d 216 return_response(true); // set download paramter to true
ocomeni 81:637a87eb8170 217 at_resp = AT_RESP_NONE;
ocomeni 81:637a87eb8170 218 break;
ocomeni 99:05398b3184f8 219 case CONNECT_EVENT:
ocomeni 99:05398b3184f8 220 {
ocomeni 99:05398b3184f8 221 // Connect Event state
ocomeni 103:7b566b522427 222 dbg_printf(LOG, "\n [ATCMD MAN] CONNECT EVENT RECEIVED!!\r\n");
ocomeni 99:05398b3184f8 223 sendConnectEvent(resp_data->buffer, resp_data->dataLen);
ocomeni 99:05398b3184f8 224 at_resp = AT_RESP_NONE;
ocomeni 99:05398b3184f8 225 break;
ocomeni 99:05398b3184f8 226 }
ocomeni 100:80ef4bc31b7a 227 case AT_EVENT:
ocomeni 100:80ef4bc31b7a 228 {
ocomeni 100:80ef4bc31b7a 229 // AT Event state
ocomeni 103:7b566b522427 230 dbg_printf(LOG, "\n [ATCMD MAN] AT EVENT RECEIVED!!\r\n");
ocomeni 100:80ef4bc31b7a 231 respStr = (char *) resp_data->buffer;
ocomeni 100:80ef4bc31b7a 232 sendAtEvent(respStr);
ocomeni 100:80ef4bc31b7a 233 at_resp = AT_RESP_NONE;
ocomeni 100:80ef4bc31b7a 234 break;
ocomeni 100:80ef4bc31b7a 235 }
ocomeni 104:11e9605093c9 236 case WIFI_WATCH_DOG:
ocomeni 104:11e9605093c9 237 {
ocomeni 104:11e9605093c9 238 // AT_HTTP_RESP response state
ocomeni 104:11e9605093c9 239 dbg_printf(LOG, "\n [ATCMD MAN] WIFI Watchdog message!!\r\n");
ocomeni 104:11e9605093c9 240 respStr = (char *) resp_data->buffer;
ocomeni 104:11e9605093c9 241 sendConnectIndicationFreeMpool(respStr);
ocomeni 104:11e9605093c9 242 at_resp = AT_RESP_NONE;
ocomeni 104:11e9605093c9 243 break;
ocomeni 104:11e9605093c9 244 }
ocomeni 93:06e755a80187 245 case AT_COMMAND_FAILED:
ocomeni 98:65c2333a38b6 246 {
ocomeni 93:06e755a80187 247 // AT_HTTP_RESP response state
ocomeni 103:7b566b522427 248 dbg_printf(LOG, "\n [ATCMD MAN] WIFI COMMAND FAILED!!\r\n");
ocomeni 98:65c2333a38b6 249 respStr = (char *) resp_data->buffer;
ocomeni 96:f5ed273881af 250 sendAtConfirmationFreeMpool(respStr);
ocomeni 98:65c2333a38b6 251 at_resp = AT_RESP_NONE;
ocomeni 93:06e755a80187 252 break;
ocomeni 98:65c2333a38b6 253 }
ocomeni 119:8d939a902333 254 case BLE_CONNECT_EVENT:
ocomeni 119:8d939a902333 255 {
ocomeni 119:8d939a902333 256 // AT Event state
ocomeni 119:8d939a902333 257 dbg_printf(LOG, "\n [ATCMD MAN] BLE_CONNECT_EVENT RESPONSE RECEIVED!!\r\n");
ocomeni 119:8d939a902333 258 uint8_t * respBytes = ble_resp_data->buffer;
ocomeni 119:8d939a902333 259 sendBleConnectEvent((const char *)respBytes, ble_resp_data->dataLen);
ocomeni 119:8d939a902333 260 at_resp = AT_RESP_NONE;
ocomeni 119:8d939a902333 261 break;
ocomeni 119:8d939a902333 262 }
ocomeni 119:8d939a902333 263 case AT_BLE_EVENT:
ocomeni 119:8d939a902333 264 {
ocomeni 119:8d939a902333 265 // AT Event state
ocomeni 119:8d939a902333 266 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_EVENT RESPONSE RECEIVED!!\r\n");
ocomeni 121:ac4f59839e4f 267 respStr = (char *) ble_resp_data->buffer;
ocomeni 121:ac4f59839e4f 268 sendBleAtEvent(respStr, ble_resp_data->dataLen);
ocomeni 119:8d939a902333 269 at_resp = AT_RESP_NONE;
ocomeni 119:8d939a902333 270 break;
ocomeni 119:8d939a902333 271 }
ocomeni 118:8df0e9c2ee3f 272 case AT_BLE_RESPONSE:
ocomeni 118:8df0e9c2ee3f 273 {
ocomeni 118:8df0e9c2ee3f 274 // AT Event state
ocomeni 119:8d939a902333 275 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_RESPONSE RECEIVED!!\r\n");
ocomeni 119:8d939a902333 276 respStr = (char *) ble_resp_data->buffer;
ocomeni 121:ac4f59839e4f 277 ble_resp_data->buffer[ble_resp_data->dataLen] = NULL;
ocomeni 119:8d939a902333 278 sendBleDataEvent(respStr, ble_resp_data->dataLen);
ocomeni 119:8d939a902333 279 at_resp = AT_RESP_NONE;
ocomeni 119:8d939a902333 280 break;
ocomeni 119:8d939a902333 281 }
ocomeni 119:8d939a902333 282 case AT_SOCKET_KEEP_ALIVE_OK:
ocomeni 119:8d939a902333 283 {
ocomeni 119:8d939a902333 284 // AT Event state
ocomeni 119:8d939a902333 285 dbg_printf(LOG, "\n [ATCMD MAN] AT_SOCKET_KEEP_ALIVE OK RESPONSE RECEIVED!!\r\n");
ocomeni 122:62166886db5f 286 #ifdef SEND_CLOUD_OK_MSG
ocomeni 122:62166886db5f 287 sendAtConfirmation("\r\nCLOUD CONNECTION OK\r\n");
ocomeni 122:62166886db5f 288 #endif
ocomeni 119:8d939a902333 289 at_resp = AT_RESP_NONE;
ocomeni 119:8d939a902333 290 break;
ocomeni 119:8d939a902333 291 }
ocomeni 119:8d939a902333 292 case AT_SOCKET_KEEP_ALIVE_FAILED:
ocomeni 119:8d939a902333 293 {
ocomeni 119:8d939a902333 294 // AT Event state
ocomeni 119:8d939a902333 295 dbg_printf(LOG, "\n [ATCMD MAN] AT_SOCKET_KEEP_ALIVE FAILED RESPONSE RECEIVED!!\r\n");
ocomeni 122:62166886db5f 296 #ifdef SEND_CLOUD_OK_MSG
ocomeni 119:8d939a902333 297 sendAtEvent("\r\nCLOUD CONNECTION FAILED\r\n");
ocomeni 122:62166886db5f 298 #endif
ocomeni 118:8df0e9c2ee3f 299 at_resp = AT_RESP_NONE;
ocomeni 118:8df0e9c2ee3f 300 break;
ocomeni 118:8df0e9c2ee3f 301 }
ocomeni 120:779b74689747 302 case BLE_DISCONNECT_EVENT:
ocomeni 120:779b74689747 303 {
ocomeni 123:a49e9ffbaca6 304 // BLE_DISCONNECT_EVENT state
ocomeni 120:779b74689747 305 dbg_printf(LOG, "\n [ATCMD MAN] BLE_DISCONNECT_EVENT RECEIVED!!\r\n");
ocomeni 120:779b74689747 306 sendBleDisconnectEvent();
ocomeni 120:779b74689747 307 at_resp = AT_RESP_NONE;
ocomeni 120:779b74689747 308 break;
ocomeni 120:779b74689747 309 }
ocomeni 123:a49e9ffbaca6 310 case AT_WIFI_MAC_RESP:
ocomeni 123:a49e9ffbaca6 311 // AT_WIFI_MAC_RESP response state
ocomeni 123:a49e9ffbaca6 312 dbg_printf(LOG, "\n [ATCMD MAN] AT_WIFI_MAC_RESP RESPONSE RECEIVED!!\r\n");
ocomeni 123:a49e9ffbaca6 313 respStr = (char *) resp_data->buffer;
ocomeni 123:a49e9ffbaca6 314 sendAtConfirmationFreeMpool(respStr);
ocomeni 123:a49e9ffbaca6 315 at_resp = AT_RESP_NONE;
ocomeni 123:a49e9ffbaca6 316 break;
ocomeni 123:a49e9ffbaca6 317 case AT_BLE_MAC_RESP:
ocomeni 123:a49e9ffbaca6 318 // AT_BLE_MAC_RESP response state
ocomeni 123:a49e9ffbaca6 319 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_MAC_RESP RESPONSE RECEIVED!!\r\n");
ocomeni 123:a49e9ffbaca6 320 respStr = (char *) ble_resp_data->buffer;
ocomeni 123:a49e9ffbaca6 321 sendAtConfirmation(respStr);
ocomeni 123:a49e9ffbaca6 322 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 123:a49e9ffbaca6 323 ble_resp_data = NULL;
ocomeni 123:a49e9ffbaca6 324 at_resp = AT_RESP_NONE;
ocomeni 123:a49e9ffbaca6 325 break;
ocomeni 123:a49e9ffbaca6 326 case AT_BLE_NAME_RESP:
ocomeni 123:a49e9ffbaca6 327 // AT_BLE_MAC_RESP response state
ocomeni 123:a49e9ffbaca6 328 dbg_printf(LOG, "\n [ATCMD MAN] AT_BLE_NAME_RESP RESPONSE RECEIVED!!\r\n");
ocomeni 123:a49e9ffbaca6 329 respStr = (char *) ble_resp_data->buffer;
ocomeni 123:a49e9ffbaca6 330 sendAtConfirmation(respStr);
ocomeni 123:a49e9ffbaca6 331 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 123:a49e9ffbaca6 332 ble_resp_data = NULL;
ocomeni 123:a49e9ffbaca6 333 at_resp = AT_RESP_NONE;
ocomeni 123:a49e9ffbaca6 334 break;
ocomeni 100:80ef4bc31b7a 335 default:
ocomeni 100:80ef4bc31b7a 336 //UNKNOWN response state
ocomeni 103:7b566b522427 337 dbg_printf(LOG, "\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n");
ocomeni 100:80ef4bc31b7a 338 sendAtConfirmationFreeMpool(ERROR_RESP); //_parser.send(OK_RESP);
ocomeni 100:80ef4bc31b7a 339 at_resp = AT_RESP_NONE;
ocomeni 100:80ef4bc31b7a 340 break;
ocomeni 81:637a87eb8170 341 }
ocomeni 81:637a87eb8170 342 }
ocomeni 81:637a87eb8170 343
ocomeni 120:779b74689747 344 //
ocomeni 104:11e9605093c9 345 void ATCmdManager::updateWiFiMgrStatus()
ocomeni 104:11e9605093c9 346 {
ocomeni 104:11e9605093c9 347 static int wifiBusyMonitor = 0;
ocomeni 104:11e9605093c9 348 // if next response is the expected response,
ocomeni 104:11e9605093c9 349 // then last command complete, reset wifi status
ocomeni 104:11e9605093c9 350 // pass or fail!!
ocomeni 104:11e9605093c9 351 if(at_resp == wifiStateControl || at_resp == AT_COMMAND_FAILED)
ocomeni 104:11e9605093c9 352 {
ocomeni 104:11e9605093c9 353 wifiStateControl = AT_RESP_NONE;
ocomeni 104:11e9605093c9 354 }
ocomeni 104:11e9605093c9 355 if(at_resp == WIFI_WATCH_DOG && strstr((char *) resp_data->buffer, "WiFi Main Loop inActive") != NULL)
ocomeni 104:11e9605093c9 356 {
ocomeni 104:11e9605093c9 357 wifiBusyMonitor++;
ocomeni 104:11e9605093c9 358 if(wifiBusyMonitor >= 4)
ocomeni 104:11e9605093c9 359 {
ocomeni 104:11e9605093c9 360 wifiStateControl = AT_RESP_NONE;
ocomeni 104:11e9605093c9 361 wifiBusyMonitor = 0;
ocomeni 104:11e9605093c9 362 }
ocomeni 104:11e9605093c9 363 }
ocomeni 104:11e9605093c9 364 }
ocomeni 104:11e9605093c9 365 void ATCmdManager::sendConnectIndicationFreeMpool(const char *buf)
ocomeni 104:11e9605093c9 366 {
ocomeni 104:11e9605093c9 367 int len = strlen(buf);
ocomeni 105:e5ce023eee93 368 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL);
ocomeni 104:11e9605093c9 369 _wiFi2ATDatamPool->free(resp_data);
ocomeni 104:11e9605093c9 370 resp_data = NULL;
ocomeni 104:11e9605093c9 371 }
ocomeni 104:11e9605093c9 372
ocomeni 96:f5ed273881af 373 void ATCmdManager::sendAtConfirmationFreeMpool(const char *buf)
ocomeni 96:f5ed273881af 374 {
ocomeni 96:f5ed273881af 375 sendAtConfirmation(buf);
ocomeni 96:f5ed273881af 376 _wiFi2ATDatamPool->free(resp_data);
ocomeni 96:f5ed273881af 377 resp_data = NULL;
ocomeni 96:f5ed273881af 378 }
ocomeni 96:f5ed273881af 379
ocomeni 96:f5ed273881af 380
ocomeni 104:11e9605093c9 381 void ATCmdManager::printBufferInHex(const uint8_t *buf, int pLen)
ocomeni 89:45f6db09a76d 382 {
ocomeni 104:11e9605093c9 383 print_debug_hex(buf, pLen);
ocomeni 89:45f6db09a76d 384 }
ocomeni 81:637a87eb8170 385
ocomeni 83:9c271a50a70b 386 bool ATCmdManager::validate(edm_header_t edm_header)
ocomeni 83:9c271a50a70b 387 {
ocomeni 83:9c271a50a70b 388 if(edm_header.startByte != EDM_START_BYTE)return false; // unexpected start byte found!
ocomeni 99:05398b3184f8 389 if(edm_header.payloadID != CONNECT_EVENT_ID &&
ocomeni 99:05398b3184f8 390 edm_header.payloadID != DISCONNECT_EVENT_ID &&
ocomeni 99:05398b3184f8 391 edm_header.payloadID != DATA_EVENT_ID &&
ocomeni 99:05398b3184f8 392 edm_header.payloadID != DATA_COMMAND_ID &&
ocomeni 99:05398b3184f8 393 edm_header.payloadID != AT_REQUEST_ID &&
ocomeni 99:05398b3184f8 394 edm_header.payloadID != AT_CONFIRMATION_ID &&
ocomeni 99:05398b3184f8 395 edm_header.payloadID != AT_EVENT_ID
ocomeni 83:9c271a50a70b 396 )return false; // unexpected payload ID found!
ocomeni 83:9c271a50a70b 397 if(edm_header.payloadLen > MAX_EDM_PAYLOAD_LEN ||
ocomeni 83:9c271a50a70b 398 edm_header.payloadLen < MIN_EDM_PAYLOAD_LEN
ocomeni 83:9c271a50a70b 399 ) return false; // unexpected length received!
ocomeni 90:ed0267eca7b5 400 if(edm_header.channel_id != WIFI_CHANNEL &&
ocomeni 90:ed0267eca7b5 401 edm_header.channel_id != BLE_CHANNEL
ocomeni 90:ed0267eca7b5 402 ) return false; // unexpected channel_id received!
ocomeni 83:9c271a50a70b 403 return true;
ocomeni 83:9c271a50a70b 404 }
ocomeni 74:f26e846adfe9 405
ocomeni 84:7c7add00f4bf 406 http_method ATCmdManager::str2HttpMethod(const char * methodStr)
ocomeni 84:7c7add00f4bf 407 {
ocomeni 84:7c7add00f4bf 408 http_method _http_method;
ocomeni 84:7c7add00f4bf 409 if(strstr(methodStr, "POST")!= NULL){
ocomeni 84:7c7add00f4bf 410 _http_method = HTTP_POST;
ocomeni 84:7c7add00f4bf 411 }
ocomeni 84:7c7add00f4bf 412 else if(strstr(methodStr, "GET")!= NULL){
ocomeni 84:7c7add00f4bf 413 _http_method = HTTP_GET;
ocomeni 84:7c7add00f4bf 414 }
ocomeni 84:7c7add00f4bf 415 else{
ocomeni 84:7c7add00f4bf 416 _http_method = HTTP_DELETE; // unsupported method - set to HTTP_DELETE
ocomeni 84:7c7add00f4bf 417 }
ocomeni 84:7c7add00f4bf 418 return _http_method;
ocomeni 84:7c7add00f4bf 419 }
ocomeni 84:7c7add00f4bf 420 bool ATCmdManager::createHttpRequest()
ocomeni 84:7c7add00f4bf 421 {
ocomeni 110:c722dda4f2ff 422 #ifdef USE_WIFI_STATE_CONTROL
ocomeni 108:3c8fb2c6e7bf 423 static int wifiBusyTimeOut = 0;
ocomeni 108:3c8fb2c6e7bf 424 if(wifiStateControl != AT_RESP_NONE && wifiBusyTimeOut < 10) // wifi busy!
ocomeni 104:11e9605093c9 425 {
ocomeni 108:3c8fb2c6e7bf 426 wifiBusyTimeOut++;
ocomeni 108:3c8fb2c6e7bf 427 return false;
ocomeni 104:11e9605093c9 428 }
ocomeni 108:3c8fb2c6e7bf 429 wifiBusyTimeOut = 0;
ocomeni 110:c722dda4f2ff 430 #endif
ocomeni 90:ed0267eca7b5 431 http_request_t *http_req; // = new http_request_t;
ocomeni 90:ed0267eca7b5 432 wifi_data_msg_t data_msg;
ocomeni 90:ed0267eca7b5 433 http_req = (http_request_t *)data_msg.buffer;
ocomeni 84:7c7add00f4bf 434 char s1[32];
ocomeni 84:7c7add00f4bf 435 char s2[32];
ocomeni 84:7c7add00f4bf 436 char s3[32];
ocomeni 90:ed0267eca7b5 437 int len = 0;
ocomeni 90:ed0267eca7b5 438 int n;
ocomeni 90:ed0267eca7b5 439 char * strPtr = (char *)rx_buf_ptr;
ocomeni 84:7c7add00f4bf 440 char * p;
ocomeni 84:7c7add00f4bf 441 char * p2 = strstr(strPtr, "\r\n\r\n");
ocomeni 84:7c7add00f4bf 442 char * nxtPtr = strPtr;
ocomeni 90:ed0267eca7b5 443 char * outPtr;
ocomeni 84:7c7add00f4bf 444 char * bodyPtr = p2+4;
ocomeni 103:7b566b522427 445 dbg_printf(LOG, "\nstrPtr address= %x",strPtr);
ocomeni 103:7b566b522427 446 dbg_printf(LOG, "\np2 address= %x", p2);
ocomeni 84:7c7add00f4bf 447 for(int i = 0; i < 5; i++){
ocomeni 84:7c7add00f4bf 448 if(i == 0)// firstline scan method uri and http_ver
ocomeni 84:7c7add00f4bf 449 {
ocomeni 84:7c7add00f4bf 450 n = sscanf(nxtPtr,"%s %s %s", s1, s2, s3);
ocomeni 90:ed0267eca7b5 451 if(n!=3) return false; // error in input abort
ocomeni 105:e5ce023eee93 452 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 453 dbg_printf(LOG, "\nmethod = %s\nuri = %s\nhttp_ver = %s",s1, s2, s3 );
ocomeni 105:e5ce023eee93 454 #endif
ocomeni 84:7c7add00f4bf 455 //http_req.method = str2HttpMethod(s1.c_str());
ocomeni 90:ed0267eca7b5 456 http_req->method = str2HttpMethod(s1);
ocomeni 90:ed0267eca7b5 457 http_req->request_URI = (char *) http_req->buffer; // point 1st string to start of buffer
ocomeni 90:ed0267eca7b5 458 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 459 strncpy(http_req->request_URI, s2, len);
ocomeni 90:ed0267eca7b5 460 http_req->http_version = http_req->request_URI + len; // point 2nd string to after 1st
ocomeni 90:ed0267eca7b5 461 len = strlen(s3)+1;
ocomeni 90:ed0267eca7b5 462 strncpy(http_req->http_version, s3, len);
ocomeni 105:e5ce023eee93 463 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 464 dbg_printf(LOG, "\nhttp_request 1st line:\n method = %d\nuri = %s\nhttp_ver = %s",http_req->method,
ocomeni 90:ed0267eca7b5 465 http_req->request_URI,
ocomeni 90:ed0267eca7b5 466 http_req->http_version );
ocomeni 103:7b566b522427 467 dbg_printf(LOG, "\nhttp_request str ptrs\nuri = %X\nhttp_ver = %X",http_req->request_URI,
ocomeni 90:ed0267eca7b5 468 http_req->http_version );
ocomeni 105:e5ce023eee93 469 #endif
ocomeni 90:ed0267eca7b5 470 outPtr = http_req->http_version + len; // point output buffer ptr to after 2nd string
ocomeni 84:7c7add00f4bf 471 }
ocomeni 84:7c7add00f4bf 472 else{ // scan header pairs
ocomeni 84:7c7add00f4bf 473 n = sscanf(nxtPtr,"%s %s", s1, s2);
ocomeni 90:ed0267eca7b5 474 if(n!=2) return false; // error in input abort
ocomeni 84:7c7add00f4bf 475 p = strstr(s1,":");
ocomeni 84:7c7add00f4bf 476 *p = NULL;
ocomeni 105:e5ce023eee93 477 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 478 dbg_printf(LOG, "\nname = %s value = %s",s1, s2);
ocomeni 105:e5ce023eee93 479 #endif
ocomeni 86:04fc2fcda7ec 480 if(strstr(s1, "Host")!= NULL){
ocomeni 90:ed0267eca7b5 481 http_req->hostName = outPtr;
ocomeni 104:11e9605093c9 482 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 104:11e9605093c9 483 p = strstr(s2, "//");
ocomeni 104:11e9605093c9 484 if(p == NULL)
ocomeni 104:11e9605093c9 485 p = s2;
ocomeni 104:11e9605093c9 486 else
ocomeni 104:11e9605093c9 487 p+=2;
ocomeni 104:11e9605093c9 488 len = strlen(p)+1;
ocomeni 104:11e9605093c9 489 strncpy(outPtr, p, len);
ocomeni 104:11e9605093c9 490 #else
ocomeni 90:ed0267eca7b5 491 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 492 strncpy(outPtr, s2, len);
ocomeni 104:11e9605093c9 493 #endif
ocomeni 105:e5ce023eee93 494 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 495 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr);
ocomeni 105:e5ce023eee93 496 #endif
ocomeni 90:ed0267eca7b5 497 outPtr += len; // point output buffer ptr to after current string
ocomeni 86:04fc2fcda7ec 498 }
ocomeni 86:04fc2fcda7ec 499 else if(strstr(s1, "Accept")!= NULL){
ocomeni 90:ed0267eca7b5 500 http_req->AcceptVal = outPtr;
ocomeni 90:ed0267eca7b5 501 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 502 strncpy(outPtr, s2, len);
ocomeni 105:e5ce023eee93 503 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 504 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr);
ocomeni 105:e5ce023eee93 505 #endif
ocomeni 90:ed0267eca7b5 506 outPtr += len; // point output buffer ptr to after current string
ocomeni 86:04fc2fcda7ec 507 }
ocomeni 86:04fc2fcda7ec 508 else if(strstr(s1, "Content-Type")!= NULL){
ocomeni 90:ed0267eca7b5 509 http_req->contentType = outPtr;
ocomeni 90:ed0267eca7b5 510 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 511 strncpy(outPtr, s2, len);
ocomeni 105:e5ce023eee93 512 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 513 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr);
ocomeni 105:e5ce023eee93 514 #endif
ocomeni 90:ed0267eca7b5 515 outPtr += len; // point output buffer ptr to after current string
ocomeni 86:04fc2fcda7ec 516 }
ocomeni 86:04fc2fcda7ec 517 else if(strstr(s1, "Content-Length")!= NULL){
ocomeni 90:ed0267eca7b5 518 http_req->contentLen = outPtr;
ocomeni 90:ed0267eca7b5 519 len = strlen(s2)+1;
ocomeni 90:ed0267eca7b5 520 strncpy(outPtr, s2, len);
ocomeni 105:e5ce023eee93 521 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 522 dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr);
ocomeni 105:e5ce023eee93 523 #endif
ocomeni 90:ed0267eca7b5 524 outPtr += len; // point output buffer ptr to after current string
ocomeni 84:7c7add00f4bf 525 }
ocomeni 84:7c7add00f4bf 526
ocomeni 105:e5ce023eee93 527 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 528 dbg_printf(LOG, "\noutPtr = %X len = %d\n", outPtr, len);
ocomeni 105:e5ce023eee93 529 #endif
ocomeni 84:7c7add00f4bf 530 }
ocomeni 84:7c7add00f4bf 531 nxtPtr = strstr(nxtPtr, "\r\n")+2; // goto next line
ocomeni 84:7c7add00f4bf 532 if(nxtPtr >= p2) break;
ocomeni 84:7c7add00f4bf 533 }
ocomeni 90:ed0267eca7b5 534 // print header from http_req_struct
ocomeni 105:e5ce023eee93 535 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 536 dbg_printf(LOG, "\nhttp request header: \n %s\n", http_req->buffer);
ocomeni 105:e5ce023eee93 537 #endif
ocomeni 84:7c7add00f4bf 538 int bodyLen = edm_hdr.payloadLen -(p2+7-strPtr);
ocomeni 105:e5ce023eee93 539 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 540 dbg_printf(LOG, "\nLen = %d\n", bodyLen);
ocomeni 105:e5ce023eee93 541 #endif
ocomeni 118:8df0e9c2ee3f 542 uint32_t msecsSinceLastMsg = Kernel::get_ms_count() - lastHttpRespTime;
ocomeni 118:8df0e9c2ee3f 543 if((lastCloudMsgType == BAR_DB_MSGTYPE || lastCloudMsgType == REC_DB_MSGTYPE) &&
ocomeni 118:8df0e9c2ee3f 544 lastCloudMsgType == (uint8_t) bodyPtr[8] &&
ocomeni 118:8df0e9c2ee3f 545 (msecsSinceLastMsg < CLOUD_RETRY_TIME_MS ))
ocomeni 118:8df0e9c2ee3f 546 {
ocomeni 118:8df0e9c2ee3f 547 return false;
ocomeni 118:8df0e9c2ee3f 548 }
ocomeni 118:8df0e9c2ee3f 549 lastCloudMsgType = (uint8_t) bodyPtr[8]; // pick out the MSGTYPE byte from payload
ocomeni 90:ed0267eca7b5 550 http_req->body = (uint8_t *) outPtr;
ocomeni 90:ed0267eca7b5 551 memcpy(outPtr, bodyPtr, bodyLen);
ocomeni 90:ed0267eca7b5 552 if(bodyLen > 10){
ocomeni 103:7b566b522427 553 dbg_printf(LOG, "\n Message Body:\n");
ocomeni 90:ed0267eca7b5 554 printBufferInHex(http_req->body, bodyLen);
ocomeni 90:ed0267eca7b5 555 }
ocomeni 90:ed0267eca7b5 556 outPtr += bodyLen; // move output pointer to end output (header + body)
ocomeni 84:7c7add00f4bf 557 // package and send on wifi data queue
ocomeni 84:7c7add00f4bf 558 data_msg.wifi_cmd = WIFI_CMD_SEND_HTTPS_REQ;
ocomeni 105:e5ce023eee93 559 data_msg.dataLen = (uint8_t *)outPtr - http_req->buffer;//sizeof(http_request_t);
ocomeni 105:e5ce023eee93 560 #ifdef FULL_DEBUG_ENABLED
ocomeni 103:7b566b522427 561 dbg_printf(LOG, "\nsizeof(http_req) on population = %d\n", sizeof(*http_req));
ocomeni 103:7b566b522427 562 dbg_printf(LOG, "\ndata_msg.dataLen = %d\n", data_msg.dataLen);
ocomeni 105:e5ce023eee93 563 #endif
ocomeni 84:7c7add00f4bf 564 // queue next data request
ocomeni 104:11e9605093c9 565 if(queueWiFiDataRequest(data_msg) == true)
ocomeni 104:11e9605093c9 566 {
ocomeni 104:11e9605093c9 567 wifiStateControl = AT_HTTPS_RESP_DOWNLOAD;
ocomeni 110:c722dda4f2ff 568 return true;
ocomeni 104:11e9605093c9 569 }
ocomeni 118:8df0e9c2ee3f 570 return false;
ocomeni 84:7c7add00f4bf 571 }
ocomeni 74:f26e846adfe9 572 // OOB processing
ocomeni 74:f26e846adfe9 573 void ATCmdManager::_process_oob(uint32_t timeout, bool all){
ocomeni 74:f26e846adfe9 574 set_timeout(timeout);
ocomeni 84:7c7add00f4bf 575 int start;
ocomeni 83:9c271a50a70b 576 if(dataMode == AT_EXT_DATA_MODE)
ocomeni 83:9c271a50a70b 577 {
ocomeni 83:9c271a50a70b 578 int n;
ocomeni 84:7c7add00f4bf 579 uint8_t edm[EDM_HDR_LEN];
ocomeni 92:ec9550034276 580 char cmdType[16];
ocomeni 83:9c271a50a70b 581 // Poll for edm packets
ocomeni 83:9c271a50a70b 582 do{
ocomeni 92:ec9550034276 583 n = _parser.read((char *)edm, EDM_HDR_LEN-1);
ocomeni 84:7c7add00f4bf 584 edm_hdr.startByte = edm[0];
ocomeni 84:7c7add00f4bf 585 edm_hdr.payloadLen = edm[1]*256 + edm[2];
ocomeni 84:7c7add00f4bf 586 edm_hdr.payloadID = edm[3]*256 + edm[4];
ocomeni 92:ec9550034276 587 edm_hdr.channel_id = (channel_id_t) 0;
ocomeni 84:7c7add00f4bf 588 start = Kernel::get_ms_count();
ocomeni 83:9c271a50a70b 589 if(n == -1) break; // break if it times out
ocomeni 92:ec9550034276 590 int pT;
ocomeni 99:05398b3184f8 591 if(edm_hdr.payloadID < AT_REQUEST_ID) //
ocomeni 92:ec9550034276 592 {
ocomeni 92:ec9550034276 593 n += _parser.read((char *)edm, 1);
ocomeni 92:ec9550034276 594 edm_hdr.channel_id = (channel_id_t) edm[0];
ocomeni 92:ec9550034276 595 pT = 0;
ocomeni 92:ec9550034276 596 strcpy(cmdType, "DATA COMMAND");
ocomeni 92:ec9550034276 597 }
ocomeni 92:ec9550034276 598 else
ocomeni 92:ec9550034276 599 {
ocomeni 92:ec9550034276 600 pT = 1;
ocomeni 92:ec9550034276 601 strcpy(cmdType, "AT REQUEST");
ocomeni 92:ec9550034276 602 }
ocomeni 103:7b566b522427 603 dbg_printf(LOG, "%d bytes read! : CMD type = %s\n", n, cmdType);
ocomeni 92:ec9550034276 604 if(n==(EDM_HDR_LEN-pT))
ocomeni 103:7b566b522427 605 dbg_printf(LOG, "Start = %d, payloadID = %d len = %d chan_id = %d\n", edm_hdr.startByte,
ocomeni 90:ed0267eca7b5 606 edm_hdr.payloadID,
ocomeni 90:ed0267eca7b5 607 edm_hdr.payloadLen,
ocomeni 90:ed0267eca7b5 608 edm_hdr.channel_id);
ocomeni 92:ec9550034276 609 if(n == (EDM_HDR_LEN-pT) && validate(edm_hdr)) // if AT command use process oob to decode
ocomeni 83:9c271a50a70b 610 {
ocomeni 99:05398b3184f8 611 if(edm_hdr.payloadID == AT_REQUEST_ID)
ocomeni 83:9c271a50a70b 612 {
ocomeni 92:ec9550034276 613 while (_parser.process_oob() && all) {
ocomeni 92:ec9550034276 614 }
ocomeni 83:9c271a50a70b 615 break;
ocomeni 83:9c271a50a70b 616 }
ocomeni 83:9c271a50a70b 617 else
ocomeni 83:9c271a50a70b 618 {
ocomeni 92:ec9550034276 619 int pLen = edm_hdr.payloadLen-2-pT;
ocomeni 83:9c271a50a70b 620 rx_buf_ptr = (uint8_t *) malloc (pLen); // we already read 2 bytes from payload but expect 1 stop byte
ocomeni 83:9c271a50a70b 621 rx_buf_ptr[pLen-1] = 0x00; // clear last byte so the readback value is as expected
ocomeni 83:9c271a50a70b 622 n = _parser.read((char *)rx_buf_ptr, pLen);
ocomeni 118:8df0e9c2ee3f 623 if(n == -1)
ocomeni 118:8df0e9c2ee3f 624 {
ocomeni 118:8df0e9c2ee3f 625 dbg_printf(LOG, "Timeout while reading message payload bytes - expected %d!\r\n", pLen);
ocomeni 118:8df0e9c2ee3f 626 free(rx_buf_ptr); // make sure to free buffer
ocomeni 118:8df0e9c2ee3f 627 rx_buf_ptr = NULL;
ocomeni 119:8d939a902333 628 sendAtConfirmation(UART_TIMEOUT_ERROR);
ocomeni 118:8df0e9c2ee3f 629 break; // timeout!
ocomeni 118:8df0e9c2ee3f 630 }
ocomeni 103:7b566b522427 631 dbg_printf(LOG, "%d bytes read - expected %d!\n", n, pLen);
ocomeni 89:45f6db09a76d 632 printBufferInHex(rx_buf_ptr, pLen);
ocomeni 103:7b566b522427 633 dbg_printf(LOG, "rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]);
ocomeni 83:9c271a50a70b 634 if(rx_buf_ptr[pLen-1] != EDM_STOP_BYTE) {
ocomeni 90:ed0267eca7b5 635 _smutex.lock();
ocomeni 90:ed0267eca7b5 636 _parser.send("ERR");
ocomeni 90:ed0267eca7b5 637 _smutex.unlock();
ocomeni 97:0aa46e5ef15d 638 free(rx_buf_ptr); // make sure to free buffer
ocomeni 97:0aa46e5ef15d 639 rx_buf_ptr = NULL;
ocomeni 90:ed0267eca7b5 640 break; // exit if stop byte not found - possible data corruption!
ocomeni 83:9c271a50a70b 641 }
ocomeni 83:9c271a50a70b 642 switch(edm_hdr.payloadID)
ocomeni 83:9c271a50a70b 643 {
ocomeni 99:05398b3184f8 644 case CONNECT_EVENT_ID:
ocomeni 103:7b566b522427 645 dbg_printf(LOG, "Connection Event received!\n");
ocomeni 83:9c271a50a70b 646 break;
ocomeni 99:05398b3184f8 647 case DISCONNECT_EVENT_ID:
ocomeni 103:7b566b522427 648 dbg_printf(LOG, "DISCONNECT_EVENT received!\n");
ocomeni 83:9c271a50a70b 649 break;
ocomeni 99:05398b3184f8 650 case DATA_EVENT_ID:
ocomeni 103:7b566b522427 651 dbg_printf(LOG, "DATA_EVENT received!\n");
ocomeni 83:9c271a50a70b 652 break;
ocomeni 99:05398b3184f8 653 case DATA_COMMAND_ID:
ocomeni 98:65c2333a38b6 654 {
ocomeni 103:7b566b522427 655 dbg_printf(LOG, "DATA_COMMAND received!\n");
ocomeni 108:3c8fb2c6e7bf 656 if(createHttpRequest() == false)
ocomeni 108:3c8fb2c6e7bf 657 {
ocomeni 109:c274780ff609 658 #ifdef SEND_DEBUG_MESSAGES
ocomeni 104:11e9605093c9 659 sendAtConfirmation(WIFI_BUSY_RESP);
ocomeni 109:c274780ff609 660 #endif
ocomeni 84:7c7add00f4bf 661 }
ocomeni 92:ec9550034276 662 free(rx_buf_ptr);
ocomeni 96:f5ed273881af 663 rx_buf_ptr = NULL;
ocomeni 84:7c7add00f4bf 664 int stop = Kernel::get_ms_count();
ocomeni 103:7b566b522427 665 dbg_printf(LOG, "\n Time Elapsed = %d\n", stop-start);
ocomeni 83:9c271a50a70b 666 break;
ocomeni 98:65c2333a38b6 667 }
ocomeni 99:05398b3184f8 668 case AT_REQUEST_ID:
ocomeni 103:7b566b522427 669 dbg_printf(LOG, "AT_REQUEST received!\n");
ocomeni 83:9c271a50a70b 670 break;
ocomeni 99:05398b3184f8 671 case AT_CONFIRMATION_ID:
ocomeni 103:7b566b522427 672 dbg_printf(LOG, "AT_CONFIRMATION received!\n");
ocomeni 83:9c271a50a70b 673 break;
ocomeni 99:05398b3184f8 674 case AT_EVENT_ID:
ocomeni 103:7b566b522427 675 dbg_printf(LOG, "AT_EVENT received!\n");
ocomeni 83:9c271a50a70b 676 break;
ocomeni 83:9c271a50a70b 677 default:
ocomeni 103:7b566b522427 678 dbg_printf(LOG, "UNKNOWN MESSAGE received!\n");
ocomeni 83:9c271a50a70b 679 break;
ocomeni 83:9c271a50a70b 680 }
ocomeni 83:9c271a50a70b 681 }
ocomeni 83:9c271a50a70b 682 }
ocomeni 83:9c271a50a70b 683 else // incorrect # of bytes received abort!!
ocomeni 83:9c271a50a70b 684 {
ocomeni 83:9c271a50a70b 685 break;
ocomeni 83:9c271a50a70b 686 }
ocomeni 83:9c271a50a70b 687 }while (all); // continue to process until timeout
ocomeni 74:f26e846adfe9 688 }
ocomeni 83:9c271a50a70b 689 else
ocomeni 83:9c271a50a70b 690 {
ocomeni 83:9c271a50a70b 691 // Poll for inbound packets
ocomeni 112:a0999ea4ece0 692 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 693 static char * ATCMD = new char[32];
ocomeni 103:7b566b522427 694 int n = 0;
ocomeni 103:7b566b522427 695 if(check_for_at_cmd)
ocomeni 103:7b566b522427 696 {
ocomeni 103:7b566b522427 697 while (n>=0 && all) {
ocomeni 103:7b566b522427 698 n = readAtCommandString(ATCMD, 32);
ocomeni 103:7b566b522427 699 if(strstr(ATCMD,"AT\r") != NULL)
ocomeni 103:7b566b522427 700 {
ocomeni 103:7b566b522427 701 _oob_ok_hdlr();
ocomeni 103:7b566b522427 702 check_for_at_cmd = false;
ocomeni 103:7b566b522427 703 break;
ocomeni 103:7b566b522427 704 }
ocomeni 103:7b566b522427 705 }
ocomeni 103:7b566b522427 706 }
ocomeni 103:7b566b522427 707 else
ocomeni 103:7b566b522427 708 #endif
ocomeni 103:7b566b522427 709 {
ocomeni 83:9c271a50a70b 710 while (_parser.process_oob() && all) {
ocomeni 110:c722dda4f2ff 711 }
ocomeni 103:7b566b522427 712 }
ocomeni 83:9c271a50a70b 713 }
ocomeni 74:f26e846adfe9 714 set_timeout();
ocomeni 74:f26e846adfe9 715 }
ocomeni 74:f26e846adfe9 716
ocomeni 74:f26e846adfe9 717
ocomeni 103:7b566b522427 718 int ATCmdManager::readAtCommandString(char *strbuf, size_t bufLen)
ocomeni 103:7b566b522427 719 {
ocomeni 103:7b566b522427 720 int n;
ocomeni 103:7b566b522427 721 bool atstr_found = false;
ocomeni 103:7b566b522427 722 int i = 0;
ocomeni 103:7b566b522427 723 while(n != -1)
ocomeni 103:7b566b522427 724 {
ocomeni 103:7b566b522427 725 char c;
ocomeni 103:7b566b522427 726 n = _parser.read(&c, 1);
ocomeni 103:7b566b522427 727 if(n)
ocomeni 103:7b566b522427 728 strbuf[i++] = c;
ocomeni 103:7b566b522427 729 if(c=='\r')
ocomeni 103:7b566b522427 730 {
ocomeni 103:7b566b522427 731 strbuf[i++] = NULL; // terminate string and exit
ocomeni 103:7b566b522427 732 atstr_found = true;
ocomeni 103:7b566b522427 733 break;
ocomeni 103:7b566b522427 734 }
ocomeni 103:7b566b522427 735 }
ocomeni 103:7b566b522427 736 if(atstr_found)
ocomeni 103:7b566b522427 737 {
ocomeni 103:7b566b522427 738 return i;
ocomeni 103:7b566b522427 739 }
ocomeni 103:7b566b522427 740 else
ocomeni 103:7b566b522427 741 {
ocomeni 103:7b566b522427 742 return -1;
ocomeni 103:7b566b522427 743 }
ocomeni 103:7b566b522427 744 }
ocomeni 103:7b566b522427 745
ocomeni 74:f26e846adfe9 746 // OOB message handlers
ocomeni 74:f26e846adfe9 747 void ATCmdManager::_oob_startup_hdlr(){
ocomeni 74:f26e846adfe9 748 }
ocomeni 74:f26e846adfe9 749
ocomeni 81:637a87eb8170 750 void ATCmdManager::_oob_ok_hdlr(){
ocomeni 95:290859010c8c 751 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 81:637a87eb8170 752 }
ocomeni 81:637a87eb8170 753
ocomeni 74:f26e846adfe9 754
ocomeni 74:f26e846adfe9 755 void ATCmdManager::_oob_bleRole_hdlr(){
ocomeni 74:f26e846adfe9 756 }
ocomeni 74:f26e846adfe9 757
ocomeni 74:f26e846adfe9 758
ocomeni 74:f26e846adfe9 759 void ATCmdManager::_oob_wifiMode_err(){
ocomeni 74:f26e846adfe9 760 }
ocomeni 74:f26e846adfe9 761
ocomeni 74:f26e846adfe9 762
ocomeni 74:f26e846adfe9 763 void ATCmdManager::_oob_conn_already(){
ocomeni 74:f26e846adfe9 764 }
ocomeni 74:f26e846adfe9 765
ocomeni 114:b11bb96c09f3 766 void ATCmdManager::_oob_enable_wifi()
ocomeni 114:b11bb96c09f3 767 {
ocomeni 114:b11bb96c09f3 768 trigger_start_WiFi();
ocomeni 114:b11bb96c09f3 769 sendAtConfirmation(OK_RESP);
ocomeni 114:b11bb96c09f3 770 }
ocomeni 74:f26e846adfe9 771
ocomeni 74:f26e846adfe9 772 void ATCmdManager::_oob_err(){
ocomeni 74:f26e846adfe9 773 }
ocomeni 74:f26e846adfe9 774
ocomeni 79:a2187bbfa407 775 void ATCmdManager::_oob_get_fw_ver()
ocomeni 79:a2187bbfa407 776 {
ocomeni 102:9748f290a1a5 777 #ifdef MBED_MAJOR_VERSION
ocomeni 123:a49e9ffbaca6 778 char * fw_ver_str = new char[40];
ocomeni 123:a49e9ffbaca6 779 sprintf(fw_ver_str, "API version:%d.%d.%d.%d.%d.%d\n\n", MBED_MAJOR_VERSION
ocomeni 123:a49e9ffbaca6 780 , MBED_MINOR_VERSION
ocomeni 123:a49e9ffbaca6 781 , MBED_PATCH_VERSION
ocomeni 123:a49e9ffbaca6 782 , API_MAJOR_VERSION
ocomeni 123:a49e9ffbaca6 783 , API_MINOR_VERSION
ocomeni 123:a49e9ffbaca6 784 , API_BUILD_NUMBER);
ocomeni 102:9748f290a1a5 785 sendAtConfirmation(fw_ver_str);
ocomeni 102:9748f290a1a5 786 delete fw_ver_str;
ocomeni 102:9748f290a1a5 787 #endif
ocomeni 79:a2187bbfa407 788 }
ocomeni 79:a2187bbfa407 789
ocomeni 103:7b566b522427 790 #define TTP_DEBUGGING
ocomeni 107:f1a83fd41b17 791 #define TTP_DEBUGGING_UART_NOCHANGE
ocomeni 75:08eff6258e1b 792 void ATCmdManager::_oob_uart_setup(){
ocomeni 75:08eff6258e1b 793 int uOpts[NUM_UART_OPTIONS];
ocomeni 75:08eff6258e1b 794 if(_parser.scanf("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5]) >0) {
ocomeni 103:7b566b522427 795 dbg_printf(LOG, "\nATCmdParser: Uart Options=%d,%d,%d,%d,%d,%d\n", uOpts[0], uOpts[1], uOpts[2], uOpts[3], uOpts[4], uOpts[5]);
ocomeni 103:7b566b522427 796 dbg_printf(LOG, "\n Changing Baud Rate to %d\n", uOpts[0]);
ocomeni 107:f1a83fd41b17 797 #ifdef TTP_DEBUGGING_UART_NOCHANGE
ocomeni 103:7b566b522427 798 sendAtConfirmation(OK_RESP);
ocomeni 103:7b566b522427 799 #else
ocomeni 81:637a87eb8170 800
ocomeni 95:290859010c8c 801 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 81:637a87eb8170 802 _serial.set_baud(uOpts[0]);
ocomeni 92:ec9550034276 803 wait(0.1);
ocomeni 103:7b566b522427 804 dbg_printf(LOG, "\n Baud Rate now %d\n", uOpts[0]);
ocomeni 103:7b566b522427 805 #endif
ocomeni 103:7b566b522427 806 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 807 check_for_at_cmd = true;
ocomeni 103:7b566b522427 808 #endif
ocomeni 81:637a87eb8170 809
ocomeni 75:08eff6258e1b 810 } else {
ocomeni 103:7b566b522427 811 dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed");
ocomeni 75:08eff6258e1b 812 }
ocomeni 75:08eff6258e1b 813 }
ocomeni 75:08eff6258e1b 814
ocomeni 74:f26e846adfe9 815 void ATCmdManager::set_timeout(uint32_t timeout_ms)
ocomeni 74:f26e846adfe9 816 {
ocomeni 74:f26e846adfe9 817 _parser.set_timeout(timeout_ms);
ocomeni 74:f26e846adfe9 818 }
ocomeni 74:f26e846adfe9 819
ocomeni 75:08eff6258e1b 820
ocomeni 75:08eff6258e1b 821 void ATCmdManager::_oob_echo_off()
ocomeni 75:08eff6258e1b 822 {
ocomeni 103:7b566b522427 823 dbg_printf(LOG, "\n Received ATEO OOB command!!\n");
ocomeni 103:7b566b522427 824 dbg_printf(LOG, "\n turning echo OFF!!\n");
ocomeni 75:08eff6258e1b 825 _parser.debug_on(false);
ocomeni 95:290859010c8c 826 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 827 }
ocomeni 75:08eff6258e1b 828
ocomeni 75:08eff6258e1b 829
ocomeni 75:08eff6258e1b 830 void ATCmdManager::_oob_echo_on()
ocomeni 75:08eff6258e1b 831 {
ocomeni 103:7b566b522427 832 dbg_printf(LOG, "\n Received ATE1 OOB command!!\n");
ocomeni 103:7b566b522427 833 dbg_printf(LOG, "\n turning echo ON!!\n");
ocomeni 75:08eff6258e1b 834 _parser.debug_on(true);
ocomeni 95:290859010c8c 835 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 836 }
ocomeni 75:08eff6258e1b 837
ocomeni 75:08eff6258e1b 838
ocomeni 118:8df0e9c2ee3f 839
ocomeni 118:8df0e9c2ee3f 840 void ATCmdManager::_oob_debug_logs_on()
ocomeni 118:8df0e9c2ee3f 841 {
ocomeni 118:8df0e9c2ee3f 842 initialise_debug(LOG | ERR | TXT | DBG);
ocomeni 118:8df0e9c2ee3f 843 dbg_printf(LOG, "\n Received ATE2 OOB command!!\n");
ocomeni 118:8df0e9c2ee3f 844 dbg_printf(LOG, "\n debug logs ON!!\n");
ocomeni 118:8df0e9c2ee3f 845 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 118:8df0e9c2ee3f 846 }
ocomeni 118:8df0e9c2ee3f 847
ocomeni 118:8df0e9c2ee3f 848 void ATCmdManager::_oob_debug_logs_off()
ocomeni 118:8df0e9c2ee3f 849 {
ocomeni 118:8df0e9c2ee3f 850 dbg_printf(LOG, "\n Received ATE3 OOB command!!\n");
ocomeni 118:8df0e9c2ee3f 851 dbg_printf(LOG, "\n turning debug logs OFF!!\n");
ocomeni 118:8df0e9c2ee3f 852 initialise_debug(NONE);
ocomeni 118:8df0e9c2ee3f 853 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 118:8df0e9c2ee3f 854 }
ocomeni 118:8df0e9c2ee3f 855
ocomeni 75:08eff6258e1b 856 void ATCmdManager::_oob_data_mode(){
ocomeni 103:7b566b522427 857 dbg_printf(LOG, "\n Received EDM mode command!!\n");
ocomeni 103:7b566b522427 858 int dmode;
ocomeni 103:7b566b522427 859 if(_parser.scanf("%d", &dmode) >0) {
ocomeni 103:7b566b522427 860 dbg_printf(LOG, "\nATCmdParser: Data mode=%d\r\n", dataMode);
ocomeni 96:f5ed273881af 861 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 103:7b566b522427 862 switch(dmode)
ocomeni 75:08eff6258e1b 863 {
ocomeni 75:08eff6258e1b 864 case 0:
ocomeni 103:7b566b522427 865 dbg_printf(LOG, "\nATCmdParser: Command Mode request received\n");
ocomeni 81:637a87eb8170 866 dataMode = AT_CMD_DATA_MODE;
ocomeni 75:08eff6258e1b 867 break;
ocomeni 75:08eff6258e1b 868 case 1:
ocomeni 103:7b566b522427 869 dbg_printf(LOG, "\nATCmdParser: Data Mode request received\n");
ocomeni 81:637a87eb8170 870 dataMode = AT_STD_DATA_MODE;
ocomeni 75:08eff6258e1b 871 break;
ocomeni 75:08eff6258e1b 872 case 2:
ocomeni 103:7b566b522427 873 dbg_printf(LOG, "\nATCmdParser: Extended data Mode request received\n");
ocomeni 81:637a87eb8170 874 dataMode = AT_EXT_DATA_MODE;
ocomeni 98:65c2333a38b6 875 _event_queue.call_in(10, &print_heap_and_isr_stack_info);
ocomeni 98:65c2333a38b6 876 //print_heap_and_isr_stack_info();
ocomeni 75:08eff6258e1b 877 break;
ocomeni 75:08eff6258e1b 878 default:
ocomeni 103:7b566b522427 879 dbg_printf(LOG, "\nATCmdParser: ERROR - UNKNOWN DATA MODE RECEIVED!!! \n");
ocomeni 75:08eff6258e1b 880 break;
ocomeni 75:08eff6258e1b 881 }
ocomeni 75:08eff6258e1b 882 } else {
ocomeni 103:7b566b522427 883 dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed\n");
ocomeni 75:08eff6258e1b 884 }
ocomeni 75:08eff6258e1b 885 }
ocomeni 75:08eff6258e1b 886
ocomeni 75:08eff6258e1b 887 void ATCmdManager::_oob_get_mac_addr(){
ocomeni 75:08eff6258e1b 888 int bleOrWifi;
ocomeni 75:08eff6258e1b 889 if(_parser.scanf("=%d", &bleOrWifi) >0) {
ocomeni 75:08eff6258e1b 890 switch(bleOrWifi)
ocomeni 75:08eff6258e1b 891 {
ocomeni 75:08eff6258e1b 892 case 1:
ocomeni 103:7b566b522427 893 dbg_printf(LOG, "\nATCmdParser: BLE MAC Address request received");
ocomeni 123:a49e9ffbaca6 894 at_ble_msg_t data_req;
ocomeni 123:a49e9ffbaca6 895 data_req.ble_cmd = BLE_CMD_MAC_ADDR;
ocomeni 123:a49e9ffbaca6 896 // queue next BLE command
ocomeni 123:a49e9ffbaca6 897 queueBleDataRequest(data_req);
ocomeni 75:08eff6258e1b 898 break;
ocomeni 75:08eff6258e1b 899 case 2:
ocomeni 123:a49e9ffbaca6 900 dbg_printf(LOG, "\nATCmdParser: WiFi MAC Address request received");
ocomeni 123:a49e9ffbaca6 901 wifi_cmd_t cmd = WIFI_CMD_WIFI_MAC_ADDR;
ocomeni 123:a49e9ffbaca6 902 // queue next command
ocomeni 123:a49e9ffbaca6 903 queueWiFiCommand(cmd);
ocomeni 75:08eff6258e1b 904 break;
ocomeni 75:08eff6258e1b 905 default:
ocomeni 103:7b566b522427 906 dbg_printf(LOG, "\nATCmdParser: ERROR - UNKNOWN MAC ADDRESS REQUEST RECEIVED!!! \n");
ocomeni 75:08eff6258e1b 907 break;
ocomeni 75:08eff6258e1b 908 }
ocomeni 75:08eff6258e1b 909 } else {
ocomeni 103:7b566b522427 910 dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed");
ocomeni 75:08eff6258e1b 911 }
ocomeni 95:290859010c8c 912 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 913 }
ocomeni 75:08eff6258e1b 914
ocomeni 123:a49e9ffbaca6 915
ocomeni 123:a49e9ffbaca6 916 void ATCmdManager::_oob_get_ble_name()
ocomeni 123:a49e9ffbaca6 917 {
ocomeni 123:a49e9ffbaca6 918 dbg_printf(LOG, "\nATCmdParser: BLE CMD DEVICE_NAME request received");
ocomeni 123:a49e9ffbaca6 919 at_ble_msg_t data_req;
ocomeni 123:a49e9ffbaca6 920 data_req.ble_cmd = BLE_CMD_DEVICE_NAME;
ocomeni 123:a49e9ffbaca6 921 // queue next BLE command
ocomeni 123:a49e9ffbaca6 922 queueBleDataRequest(data_req);
ocomeni 123:a49e9ffbaca6 923 }
ocomeni 123:a49e9ffbaca6 924
ocomeni 75:08eff6258e1b 925 void ATCmdManager::_oob_get_ble_role(){
ocomeni 118:8df0e9c2ee3f 926 trigger_start_BLE();
ocomeni 103:7b566b522427 927 dbg_printf(LOG, "\n Received get BLE role command!!\n");
ocomeni 121:ac4f59839e4f 928 if(startup_config->ble_enable)
ocomeni 121:ac4f59839e4f 929 {
ocomeni 121:ac4f59839e4f 930 sendAtConfirmation("+UBTLE:2\r\nOK\r\n"); //_parser.send(OK_RESP);
ocomeni 121:ac4f59839e4f 931 }
ocomeni 121:ac4f59839e4f 932 else // disabled
ocomeni 121:ac4f59839e4f 933 {
ocomeni 121:ac4f59839e4f 934 sendAtConfirmation("+UBTLE:0\r\nOK\r\n"); //_parser.send(OK_RESP);
ocomeni 121:ac4f59839e4f 935 }
ocomeni 75:08eff6258e1b 936 }
ocomeni 75:08eff6258e1b 937
ocomeni 75:08eff6258e1b 938 void ATCmdManager::_oob_ena_ble_peri(){
ocomeni 103:7b566b522427 939 dbg_printf(LOG, "\n Received enable BLE Peripheral command!!\n");
ocomeni 121:ac4f59839e4f 940 startup_config->ble_enable = true;
ocomeni 95:290859010c8c 941 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 942 }
ocomeni 75:08eff6258e1b 943
ocomeni 75:08eff6258e1b 944 void ATCmdManager::_oob_reboot(){
ocomeni 103:7b566b522427 945 dbg_printf(LOG, "\n Received reboot command!!\n");
ocomeni 95:290859010c8c 946 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 75:08eff6258e1b 947 system_reset();
ocomeni 75:08eff6258e1b 948 }
ocomeni 75:08eff6258e1b 949
ocomeni 121:ac4f59839e4f 950
ocomeni 121:ac4f59839e4f 951 void ATCmdManager::_oob_factoryReset(){
ocomeni 121:ac4f59839e4f 952 dbg_printf(LOG, "\n Received factory reset command!!\n");
ocomeni 121:ac4f59839e4f 953 resetConfiguration();
ocomeni 121:ac4f59839e4f 954 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 121:ac4f59839e4f 955 }
ocomeni 121:ac4f59839e4f 956
ocomeni 121:ac4f59839e4f 957
ocomeni 121:ac4f59839e4f 958 void ATCmdManager::_oob_deleteConfiguration(){
ocomeni 121:ac4f59839e4f 959 dbg_printf(LOG, "\n Received delete configuration command!!\n");
ocomeni 121:ac4f59839e4f 960 int configKey;
ocomeni 121:ac4f59839e4f 961 bool res = false;
ocomeni 121:ac4f59839e4f 962 if(_parser.scanf("%d", &configKey) >0)
ocomeni 121:ac4f59839e4f 963 {
ocomeni 121:ac4f59839e4f 964 res = deleteConfiguration((nvstore_key_t) configKey);
ocomeni 121:ac4f59839e4f 965 }
ocomeni 121:ac4f59839e4f 966 if(res)
ocomeni 121:ac4f59839e4f 967 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 121:ac4f59839e4f 968 }
ocomeni 121:ac4f59839e4f 969
ocomeni 121:ac4f59839e4f 970
ocomeni 121:ac4f59839e4f 971
ocomeni 121:ac4f59839e4f 972 void ATCmdManager::_oob_saveSettings_hdlr()
ocomeni 121:ac4f59839e4f 973 {
ocomeni 121:ac4f59839e4f 974 saveConfiguration(APP_CONFIG_0);
ocomeni 121:ac4f59839e4f 975 sendAtConfirmation(OK_RESP);
ocomeni 121:ac4f59839e4f 976 }
ocomeni 79:a2187bbfa407 977 const char * ATCmdManager::sec2str(nsapi_security_t sec)
ocomeni 79:a2187bbfa407 978 {
ocomeni 79:a2187bbfa407 979 switch (sec) {
ocomeni 79:a2187bbfa407 980 case NSAPI_SECURITY_NONE:
ocomeni 79:a2187bbfa407 981 return "None";
ocomeni 79:a2187bbfa407 982 case NSAPI_SECURITY_WEP:
ocomeni 79:a2187bbfa407 983 return "WEP";
ocomeni 79:a2187bbfa407 984 case NSAPI_SECURITY_WPA:
ocomeni 79:a2187bbfa407 985 return "WPA";
ocomeni 79:a2187bbfa407 986 case NSAPI_SECURITY_WPA2:
ocomeni 79:a2187bbfa407 987 return "WPA2";
ocomeni 79:a2187bbfa407 988 case NSAPI_SECURITY_WPA_WPA2:
ocomeni 79:a2187bbfa407 989 return "WPA/WPA2";
ocomeni 79:a2187bbfa407 990 case NSAPI_SECURITY_UNKNOWN:
ocomeni 79:a2187bbfa407 991 default:
ocomeni 79:a2187bbfa407 992 return "Unknown";
ocomeni 79:a2187bbfa407 993 }
ocomeni 79:a2187bbfa407 994 }
ocomeni 81:637a87eb8170 995
ocomeni 81:637a87eb8170 996 bool ATCmdManager::setNextResponse(at_cmd_resp_t resp)
ocomeni 81:637a87eb8170 997 {
ocomeni 81:637a87eb8170 998 if(at_resp == AT_RESP_NONE){
ocomeni 81:637a87eb8170 999 at_resp = resp;
ocomeni 81:637a87eb8170 1000 return true; // success
ocomeni 81:637a87eb8170 1001 }
ocomeni 81:637a87eb8170 1002 return false; // wiFiManager busy
ocomeni 79:a2187bbfa407 1003 }
ocomeni 79:a2187bbfa407 1004
ocomeni 81:637a87eb8170 1005
ocomeni 79:a2187bbfa407 1006 void ATCmdManager::_oob_scanWiFiNetworks(){
ocomeni 103:7b566b522427 1007 dbg_printf(LOG, "\n Received scanWiFiNetworks command!!\n");
ocomeni 95:290859010c8c 1008 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 79:a2187bbfa407 1009 wifi_cmd_t cmd = WIFI_CMD_SCAN;
ocomeni 79:a2187bbfa407 1010 // queue next command
ocomeni 79:a2187bbfa407 1011 queueWiFiCommand(cmd);
ocomeni 81:637a87eb8170 1012 return;
ocomeni 75:08eff6258e1b 1013 }
ocomeni 75:08eff6258e1b 1014
ocomeni 95:290859010c8c 1015
ocomeni 95:290859010c8c 1016
ocomeni 98:65c2333a38b6 1017 void ATCmdManager::_oob_WiFiStationConfigAction()
ocomeni 79:a2187bbfa407 1018 {
ocomeni 98:65c2333a38b6 1019 int if_id; // interface id for request
ocomeni 98:65c2333a38b6 1020 int aId; // interface id for request
ocomeni 98:65c2333a38b6 1021 _parser.recv("%d,%d", &if_id, &aId);
ocomeni 103:7b566b522427 1022 dbg_printf(LOG, "\n Received WiFi Configuration Action command %d %d!!\r\n", if_id, aId);
ocomeni 98:65c2333a38b6 1023 if(if_id == WIFI_CONFIG_ID && aId <5){
ocomeni 95:290859010c8c 1024 wifi_cmd_t cmd;
ocomeni 98:65c2333a38b6 1025 action_id_t action_id = (action_id_t) aId;
ocomeni 95:290859010c8c 1026 switch(action_id){
ocomeni 95:290859010c8c 1027 case WIFI_CONFIG_RESET:
ocomeni 95:290859010c8c 1028 break;
ocomeni 95:290859010c8c 1029 case WIFI_CONFIG_STORE:
ocomeni 95:290859010c8c 1030 break;
ocomeni 95:290859010c8c 1031 case WIFI_CONFIG_LOAD:
ocomeni 95:290859010c8c 1032 break;
ocomeni 95:290859010c8c 1033 case WIFI_CONFIG_ACTIVATE:
ocomeni 95:290859010c8c 1034 cmd = WIFI_CMD_CONNECT;
ocomeni 103:7b566b522427 1035 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd);
ocomeni 95:290859010c8c 1036 queueWiFiCommand(cmd);
ocomeni 95:290859010c8c 1037 break;
ocomeni 95:290859010c8c 1038 case WIFI_CONFIG_DEACTIVATE:
ocomeni 95:290859010c8c 1039 cmd = WIFI_CMD_DISCONNECT;
ocomeni 103:7b566b522427 1040 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd);
ocomeni 95:290859010c8c 1041 queueWiFiCommand(cmd);
ocomeni 95:290859010c8c 1042 break;
ocomeni 95:290859010c8c 1043 default:
ocomeni 95:290859010c8c 1044 break;
ocomeni 95:290859010c8c 1045 }
ocomeni 95:290859010c8c 1046 }
ocomeni 81:637a87eb8170 1047 return;
ocomeni 79:a2187bbfa407 1048 }
ocomeni 79:a2187bbfa407 1049
ocomeni 79:a2187bbfa407 1050
ocomeni 79:a2187bbfa407 1051 void ATCmdManager::_oob_disconnectWiFiNetwork()
ocomeni 79:a2187bbfa407 1052 {
ocomeni 103:7b566b522427 1053 dbg_printf(LOG, "\n Received WiFi Disconnect command!!\n");
ocomeni 95:290859010c8c 1054 sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP);
ocomeni 81:637a87eb8170 1055 wifi_cmd_t cmd = WIFI_CMD_DISCONNECT;
ocomeni 81:637a87eb8170 1056 queueWiFiCommand(cmd);
ocomeni 81:637a87eb8170 1057 return;
ocomeni 81:637a87eb8170 1058 }
ocomeni 81:637a87eb8170 1059
ocomeni 81:637a87eb8170 1060 void ATCmdManager::_oob_setupInternetConnection()
ocomeni 81:637a87eb8170 1061 {
ocomeni 90:ed0267eca7b5 1062 char str[MAX_URL_LEN];
ocomeni 90:ed0267eca7b5 1063 char url[MAX_URL_LEN];
ocomeni 81:637a87eb8170 1064 int n;
ocomeni 81:637a87eb8170 1065 internet_config_t internet_config;
ocomeni 103:7b566b522427 1066 dbg_printf(LOG, "sizeof internet_config_t = %d\n", sizeof(internet_config_t));
ocomeni 90:ed0267eca7b5 1067 n = ReadBytes((uint8_t *)str, MAX_URL_LEN);
ocomeni 84:7c7add00f4bf 1068 str[n]=NULL;
ocomeni 112:a0999ea4ece0 1069 int id;
ocomeni 112:a0999ea4ece0 1070 int scheme;
ocomeni 103:7b566b522427 1071 dbg_printf(LOG, "\n read string = %s , n = %d\n", str, n);
ocomeni 112:a0999ea4ece0 1072 n = sscanf(str, "=%1d,%99[^,],%1d", &id,
ocomeni 92:ec9550034276 1073 url, //internet_config.url,
ocomeni 112:a0999ea4ece0 1074 &scheme);
ocomeni 112:a0999ea4ece0 1075 internet_config.peer_id = (uint8_t) id;
ocomeni 112:a0999ea4ece0 1076 internet_config.connectionScheme = (conn_scheme_t) scheme;
ocomeni 103:7b566b522427 1077 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 1078 char *p = strstr(url,"/https:");
ocomeni 103:7b566b522427 1079 #else
ocomeni 92:ec9550034276 1080 char *p = strstr(url,"\"");
ocomeni 103:7b566b522427 1081 #endif
ocomeni 92:ec9550034276 1082 if(p!=NULL)
ocomeni 92:ec9550034276 1083 {
ocomeni 92:ec9550034276 1084 strncpy(internet_config.url, &p[1], strlen(url));
ocomeni 92:ec9550034276 1085 p = strstr(internet_config.url,"\"");
ocomeni 92:ec9550034276 1086 *p = NULL;
ocomeni 92:ec9550034276 1087 }
ocomeni 92:ec9550034276 1088 else
ocomeni 92:ec9550034276 1089 {
ocomeni 92:ec9550034276 1090 strncpy(internet_config.url, url, strlen(url)+1);
ocomeni 92:ec9550034276 1091 }
ocomeni 103:7b566b522427 1092 dbg_printf(LOG, "\n read string = %s , n = %d -- strlen(url) = %d\n", internet_config.url, n, strlen(internet_config.url));
ocomeni 81:637a87eb8170 1093 if(n>0)
ocomeni 81:637a87eb8170 1094 {
ocomeni 103:7b566b522427 1095 dbg_printf(LOG, "peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id,
ocomeni 90:ed0267eca7b5 1096 internet_config.url,
ocomeni 90:ed0267eca7b5 1097 internet_config.connectionScheme);
ocomeni 81:637a87eb8170 1098 // package and send on wifi data queue
ocomeni 90:ed0267eca7b5 1099 wifi_data_msg_t data_msg;
ocomeni 81:637a87eb8170 1100 data_msg.wifi_cmd = WIFI_CMD_INTERNET_CONFIG;
ocomeni 84:7c7add00f4bf 1101 data_msg.dataLen = sizeof(internet_config_t); // + strlen(internet_config.url);
ocomeni 103:7b566b522427 1102 dbg_printf(LOG, "\n url size = %d url str = %s\n",strlen(internet_config.url), internet_config.url );
ocomeni 81:637a87eb8170 1103 memcpy(data_msg.buffer,&internet_config, data_msg.dataLen);
ocomeni 82:10072c1794d3 1104 // queue next data request
ocomeni 81:637a87eb8170 1105 queueWiFiDataRequest(data_msg);
ocomeni 84:7c7add00f4bf 1106 print_memory_info();
ocomeni 81:637a87eb8170 1107 } else {
ocomeni 103:7b566b522427 1108 dbg_printf(LOG, "\n[ATCMD MAN]: internet configuration failed %d fields parsed \r\n", n);
ocomeni 82:10072c1794d3 1109 _parser.send("NAK\n");
ocomeni 82:10072c1794d3 1110 }
ocomeni 82:10072c1794d3 1111 }
ocomeni 82:10072c1794d3 1112
ocomeni 82:10072c1794d3 1113 wifi_config_t ATCmdManager::init_wifi_config()
ocomeni 82:10072c1794d3 1114 {
ocomeni 82:10072c1794d3 1115 wifi_config_t wifi_cfg;
ocomeni 82:10072c1794d3 1116 wifi_cfg.ssid[0] = NULL;
ocomeni 82:10072c1794d3 1117 wifi_cfg.pass[0] = NULL;
ocomeni 82:10072c1794d3 1118 wifi_cfg.security = NSAPI_SECURITY_UNKNOWN;
ocomeni 82:10072c1794d3 1119 return wifi_cfg;
ocomeni 82:10072c1794d3 1120 }
ocomeni 112:a0999ea4ece0 1121
ocomeni 83:9c271a50a70b 1122 /* read ASCII characters into buffer and null terminate */
ocomeni 83:9c271a50a70b 1123 int ATCmdManager::readStringBytes(uint8_t *buf, int maxBytes)
ocomeni 82:10072c1794d3 1124 {
ocomeni 82:10072c1794d3 1125 int c;
ocomeni 82:10072c1794d3 1126 int sptr = 0;
ocomeni 93:06e755a80187 1127 int quoteCnt = 0;
ocomeni 82:10072c1794d3 1128 for(int i=0;i<maxBytes;i++){
ocomeni 82:10072c1794d3 1129 c = _parser.getc();
ocomeni 93:06e755a80187 1130 if(c== '"')quoteCnt++;
ocomeni 93:06e755a80187 1131 if(c==-1 || quoteCnt==2){
ocomeni 83:9c271a50a70b 1132 buf[sptr] = NULL; // null terminate if string
ocomeni 82:10072c1794d3 1133 return i;
ocomeni 82:10072c1794d3 1134 }
ocomeni 82:10072c1794d3 1135 if(c != ',' && c!= '"'){
ocomeni 82:10072c1794d3 1136 buf[sptr++] = (uint8_t) c;
ocomeni 82:10072c1794d3 1137 }
ocomeni 81:637a87eb8170 1138 }
ocomeni 83:9c271a50a70b 1139 return maxBytes;
ocomeni 83:9c271a50a70b 1140 }
ocomeni 83:9c271a50a70b 1141
ocomeni 83:9c271a50a70b 1142 int ATCmdManager::ReadBytes(uint8_t *buf, int maxBytes)
ocomeni 83:9c271a50a70b 1143 {
ocomeni 83:9c271a50a70b 1144 int c;
ocomeni 83:9c271a50a70b 1145 int sptr = 0;
ocomeni 83:9c271a50a70b 1146 for(int i=0;i<maxBytes;i++){
ocomeni 83:9c271a50a70b 1147 c = _parser.getc();
ocomeni 83:9c271a50a70b 1148 if(c==-1){
ocomeni 83:9c271a50a70b 1149 return i;
ocomeni 83:9c271a50a70b 1150 }
ocomeni 83:9c271a50a70b 1151 buf[sptr++] = (uint8_t) c;
ocomeni 83:9c271a50a70b 1152 }
ocomeni 83:9c271a50a70b 1153 return maxBytes;
ocomeni 82:10072c1794d3 1154 }
ocomeni 82:10072c1794d3 1155
ocomeni 82:10072c1794d3 1156 void ATCmdManager::_oob_setWiFiSSID()
ocomeni 82:10072c1794d3 1157 {
ocomeni 82:10072c1794d3 1158 int n;
ocomeni 82:10072c1794d3 1159 wifi_config_t wifi_cfg = init_wifi_config();
ocomeni 83:9c271a50a70b 1160 n = readStringBytes((uint8_t *)wifi_cfg.ssid, 32);
ocomeni 103:7b566b522427 1161 dbg_printf(LOG, "[ATCMD MAN]: number of bytes read = %d\n", n);
ocomeni 82:10072c1794d3 1162 if(n>0)
ocomeni 82:10072c1794d3 1163 {
ocomeni 103:7b566b522427 1164 dbg_printf(LOG, "[ATCMD MAN]: wifi_cfg.ssid = %s\n", wifi_cfg.ssid);
ocomeni 82:10072c1794d3 1165 // package and send on wifi data queue
ocomeni 82:10072c1794d3 1166 wifi_data_msg_t data_msg;
ocomeni 82:10072c1794d3 1167 data_msg.wifi_cmd = WIFI_CMD_CONFIG;
ocomeni 82:10072c1794d3 1168 data_msg.dataLen = sizeof(wifi_config_t);
ocomeni 82:10072c1794d3 1169 memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
ocomeni 82:10072c1794d3 1170 queueWiFiDataRequest(data_msg);
ocomeni 82:10072c1794d3 1171 } else {
ocomeni 103:7b566b522427 1172 dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n");
ocomeni 82:10072c1794d3 1173 _parser.send("NAK\n");
ocomeni 82:10072c1794d3 1174 }
ocomeni 82:10072c1794d3 1175 }
ocomeni 82:10072c1794d3 1176
ocomeni 82:10072c1794d3 1177 void ATCmdManager::_oob_setWiFiPWD()
ocomeni 82:10072c1794d3 1178 {
ocomeni 82:10072c1794d3 1179 int n;
ocomeni 82:10072c1794d3 1180 wifi_config_t wifi_cfg = init_wifi_config();
ocomeni 83:9c271a50a70b 1181 n = readStringBytes((uint8_t *)wifi_cfg.pass, 32);
ocomeni 82:10072c1794d3 1182 if(n>0)
ocomeni 82:10072c1794d3 1183 {
ocomeni 103:7b566b522427 1184 dbg_printf(LOG, "ATCMD MAN]: wifi_cfg.pass = %s\n", "****************");
ocomeni 82:10072c1794d3 1185 // package and send on wifi data queue
ocomeni 82:10072c1794d3 1186 wifi_data_msg_t data_msg;
ocomeni 82:10072c1794d3 1187 data_msg.wifi_cmd = WIFI_CMD_CONFIG;
ocomeni 82:10072c1794d3 1188 data_msg.dataLen = sizeof(wifi_config_t);
ocomeni 82:10072c1794d3 1189 memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
ocomeni 82:10072c1794d3 1190 queueWiFiDataRequest(data_msg);
ocomeni 82:10072c1794d3 1191 } else {
ocomeni 103:7b566b522427 1192 dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n");
ocomeni 82:10072c1794d3 1193 _parser.send("NAK\n");
ocomeni 82:10072c1794d3 1194 }
ocomeni 82:10072c1794d3 1195 }
ocomeni 82:10072c1794d3 1196
ocomeni 82:10072c1794d3 1197 void ATCmdManager::_oob_setWiFiSecurity()
ocomeni 82:10072c1794d3 1198 {
ocomeni 82:10072c1794d3 1199 int n;
ocomeni 82:10072c1794d3 1200 wifi_config_t wifi_cfg = init_wifi_config();
ocomeni 112:a0999ea4ece0 1201 int security;
ocomeni 112:a0999ea4ece0 1202 n = _parser.scanf(",%d", &security);
ocomeni 82:10072c1794d3 1203 if(n>0)
ocomeni 82:10072c1794d3 1204 {
ocomeni 112:a0999ea4ece0 1205 wifi_cfg.security = (nsapi_security_t) security;
ocomeni 103:7b566b522427 1206 dbg_printf(LOG, "ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security));
ocomeni 82:10072c1794d3 1207 // package and send on wifi data queue
ocomeni 82:10072c1794d3 1208 wifi_data_msg_t data_msg;
ocomeni 82:10072c1794d3 1209 data_msg.wifi_cmd = WIFI_CMD_CONFIG;
ocomeni 82:10072c1794d3 1210 data_msg.dataLen = sizeof(wifi_config_t);
ocomeni 82:10072c1794d3 1211 memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen);
ocomeni 82:10072c1794d3 1212 queueWiFiDataRequest(data_msg);
ocomeni 82:10072c1794d3 1213 } else {
ocomeni 103:7b566b522427 1214 dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n");
ocomeni 90:ed0267eca7b5 1215 _smutex.lock();
ocomeni 82:10072c1794d3 1216 _parser.send("NAK\n");
ocomeni 90:ed0267eca7b5 1217 _smutex.unlock();
ocomeni 82:10072c1794d3 1218 }
ocomeni 79:a2187bbfa407 1219 }
ocomeni 81:637a87eb8170 1220
ocomeni 83:9c271a50a70b 1221
ocomeni 95:290859010c8c 1222
ocomeni 95:290859010c8c 1223 void ATCmdManager::_oob_getNetworkStatus()
ocomeni 95:290859010c8c 1224 {
ocomeni 112:a0999ea4ece0 1225 int if_id; // interface id for request
ocomeni 95:290859010c8c 1226 _parser.scanf(",%d", &if_id);
ocomeni 103:7b566b522427 1227 dbg_printf(LOG, "\n Received Get Network Status command!!\n");
ocomeni 95:290859010c8c 1228 if(if_id == WIFI_INTERFACE_ID){
ocomeni 95:290859010c8c 1229 wifi_cmd_t cmd = WIFI_CMD_NETWORK_STATUS;
ocomeni 103:7b566b522427 1230 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd);
ocomeni 95:290859010c8c 1231 queueWiFiCommand(cmd);
ocomeni 95:290859010c8c 1232 }
ocomeni 95:290859010c8c 1233 return;
ocomeni 95:290859010c8c 1234 }
ocomeni 95:290859010c8c 1235
ocomeni 95:290859010c8c 1236
ocomeni 95:290859010c8c 1237 void ATCmdManager::_oob_WiFiNetworkStatus()
ocomeni 95:290859010c8c 1238 {
ocomeni 103:7b566b522427 1239 dbg_printf(LOG, "\n Received Get WiFi Network Status command!!\n");
ocomeni 95:290859010c8c 1240 wifi_cmd_t cmd = WIFI_CMD_WIFI_STATUS;
ocomeni 103:7b566b522427 1241 dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd);
ocomeni 95:290859010c8c 1242 // queue next command
ocomeni 95:290859010c8c 1243 queueWiFiCommand(cmd);
ocomeni 95:290859010c8c 1244 return;
ocomeni 95:290859010c8c 1245 }
ocomeni 95:290859010c8c 1246
ocomeni 83:9c271a50a70b 1247 void ATCmdManager::_oob_sendHttpMessage()
ocomeni 83:9c271a50a70b 1248 {
ocomeni 83:9c271a50a70b 1249 }
ocomeni 83:9c271a50a70b 1250
ocomeni 81:637a87eb8170 1251 bool ATCmdManager::queueWiFiCommand(wifi_cmd_t cmd){
ocomeni 103:7b566b522427 1252 dbg_printf(LOG, "[ATCMD MAN] about to be queued with wifi_cmd = %d\n", cmd);
ocomeni 92:ec9550034276 1253 #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL
ocomeni 81:637a87eb8170 1254 wifi_cmd_message_t *wifiCmd = _aT2WiFimPool->alloc();
ocomeni 92:ec9550034276 1255 if(wifiCmd == NULL){
ocomeni 103:7b566b522427 1256 dbg_printf(LOG, "[ATCMD MAN] queued memory allocation failed\n");
ocomeni 92:ec9550034276 1257 return false;
ocomeni 92:ec9550034276 1258 }
ocomeni 92:ec9550034276 1259 #else
ocomeni 92:ec9550034276 1260 wifi_cmd_message_t *wifiCmd = (wifi_cmd_message_t *) malloc(sizeof(wifi_cmd_message_t));
ocomeni 92:ec9550034276 1261 if(wifiCmd == NULL){
ocomeni 103:7b566b522427 1262 dbg_printf(LOG, "[ATCMD MAN] try malloc() : queued memory allocation failed\n");
ocomeni 92:ec9550034276 1263 return false;
ocomeni 92:ec9550034276 1264 }
ocomeni 92:ec9550034276 1265 #endif
ocomeni 81:637a87eb8170 1266 wifiCmd->wifi_cmd = cmd;
ocomeni 81:637a87eb8170 1267 _aT2WiFiCmdQueue->put(wifiCmd);
ocomeni 103:7b566b522427 1268 dbg_printf(LOG, "[ATCMD MAN] queued wifi_cmd = %d\n", wifiCmd->wifi_cmd);
ocomeni 98:65c2333a38b6 1269 if((int)cmd == 5)
ocomeni 98:65c2333a38b6 1270 debug_flag = 3;
ocomeni 81:637a87eb8170 1271 return true;
ocomeni 81:637a87eb8170 1272 }
ocomeni 81:637a87eb8170 1273
ocomeni 81:637a87eb8170 1274 bool ATCmdManager::dequeueATresponse(){
ocomeni 81:637a87eb8170 1275 if(at_resp != AT_RESP_NONE) return false; // busy
ocomeni 81:637a87eb8170 1276 osEvent evt = _wiFi2ATCmdQueue->get(0);
ocomeni 81:637a87eb8170 1277 if(evt.status == osEventMessage){
ocomeni 81:637a87eb8170 1278 at_resp_message_t *resp = (at_resp_message_t*)evt.value.p;
ocomeni 81:637a87eb8170 1279 setNextResponse(resp->at_resp);
ocomeni 103:7b566b522427 1280 dbg_printf(LOG, "[ATCMD MAN] dequeued AT CMD : at_resp = %d\n", resp->at_resp);
ocomeni 92:ec9550034276 1281 #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL
ocomeni 81:637a87eb8170 1282 _wiFi2ATmPool->free(resp);
ocomeni 96:f5ed273881af 1283 resp = NULL;
ocomeni 92:ec9550034276 1284 #else
ocomeni 92:ec9550034276 1285 free(resp);
ocomeni 96:f5ed273881af 1286 resp = NULL;
ocomeni 92:ec9550034276 1287 #endif
ocomeni 81:637a87eb8170 1288 }
ocomeni 81:637a87eb8170 1289 return true;
ocomeni 81:637a87eb8170 1290 }
ocomeni 81:637a87eb8170 1291
ocomeni 81:637a87eb8170 1292 bool ATCmdManager::queueWiFiDataRequest(wifi_data_msg_t data_req){
ocomeni 104:11e9605093c9 1293 static bool memFull = false;
ocomeni 81:637a87eb8170 1294 wifi_data_msg_t *wifiData = _aT2WiFiDatamPool->alloc();
ocomeni 104:11e9605093c9 1295 if(wifiData == NULL)
ocomeni 104:11e9605093c9 1296 {
ocomeni 109:c274780ff609 1297 #ifdef SEND_DEBUG_MESSAGES
ocomeni 104:11e9605093c9 1298 sendAtConfirmation("\r\nQUEUE MEMORY FULL\r\n");
ocomeni 109:c274780ff609 1299 #endif
ocomeni 104:11e9605093c9 1300 memFull = true;
ocomeni 104:11e9605093c9 1301 return false;
ocomeni 104:11e9605093c9 1302 }
ocomeni 104:11e9605093c9 1303 if(memFull)
ocomeni 104:11e9605093c9 1304 {
ocomeni 104:11e9605093c9 1305 memFull = false;
ocomeni 109:c274780ff609 1306 #ifdef SEND_DEBUG_MESSAGES
ocomeni 104:11e9605093c9 1307 sendAtConfirmation("\r\n[ATCMD-MAN] memory released...\r\n");
ocomeni 109:c274780ff609 1308 #endif
ocomeni 104:11e9605093c9 1309 }
ocomeni 81:637a87eb8170 1310 wifiData->wifi_cmd = data_req.wifi_cmd;
ocomeni 81:637a87eb8170 1311 wifiData->dataLen = data_req.dataLen;
ocomeni 81:637a87eb8170 1312 memcpy(wifiData->buffer, data_req.buffer, data_req.dataLen);
ocomeni 81:637a87eb8170 1313 _aT2WiFiDataQueue->put(wifiData);
ocomeni 103:7b566b522427 1314 dbg_printf(LOG, "[ATCMD MAN] queued data size = %d : wifi_cmd = %d\n", data_req.dataLen, data_req.wifi_cmd);
ocomeni 81:637a87eb8170 1315 return true;
ocomeni 81:637a87eb8170 1316 }
ocomeni 81:637a87eb8170 1317
ocomeni 87:99b37d26ff2a 1318 bool ATCmdManager::dequeueWiFidataResponse(){
ocomeni 81:637a87eb8170 1319 if(at_resp != AT_RESP_NONE) return false; // busy
ocomeni 81:637a87eb8170 1320 osEvent evt = _wiFi2ATDataQueue->get(0);
ocomeni 81:637a87eb8170 1321 if(evt.status == osEventMessage){
ocomeni 81:637a87eb8170 1322 resp_data = (at_data_msg_t*)evt.value.p;
ocomeni 81:637a87eb8170 1323 setNextResponse(resp_data->at_resp);
ocomeni 103:7b566b522427 1324 dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", resp_data->dataLen, resp_data->at_resp);
ocomeni 81:637a87eb8170 1325 }
ocomeni 81:637a87eb8170 1326 return true;
ocomeni 81:637a87eb8170 1327 }
ocomeni 81:637a87eb8170 1328
ocomeni 120:779b74689747 1329 bool ATCmdManager::queueBleDataRequest(at_ble_msg_t data_req){
ocomeni 120:779b74689747 1330 at_ble_msg_t *bleData = _aT2BleDatamPool->alloc();
ocomeni 120:779b74689747 1331 if(bleData == NULL)
ocomeni 120:779b74689747 1332 {
ocomeni 120:779b74689747 1333 #ifdef SEND_DEBUG_MESSAGES
ocomeni 120:779b74689747 1334 sendAtConfirmation("\r\nBLE QUEUE MEMORY FULL\r\n");
ocomeni 120:779b74689747 1335 #endif
ocomeni 120:779b74689747 1336 return false;
ocomeni 120:779b74689747 1337 }
ocomeni 120:779b74689747 1338 bleData->ble_cmd = data_req.ble_cmd;
ocomeni 120:779b74689747 1339 bleData->dataLen = data_req.dataLen;
ocomeni 120:779b74689747 1340 memcpy(bleData->buffer, data_req.buffer, data_req.dataLen);
ocomeni 120:779b74689747 1341 _aT2BleDataQueue->put(bleData);
ocomeni 123:a49e9ffbaca6 1342 dbg_printf(LOG, "[ATCMD MAN] queued BLE data size = %d : ble_cmd = %d\n", data_req.dataLen, data_req.ble_cmd);
ocomeni 120:779b74689747 1343 return true;
ocomeni 120:779b74689747 1344 }
ocomeni 120:779b74689747 1345
ocomeni 120:779b74689747 1346 bool ATCmdManager::dequeueBleDataResponse(){
ocomeni 120:779b74689747 1347 if(at_resp != AT_RESP_NONE) return false; // busy
ocomeni 120:779b74689747 1348 osEvent evt = _ble2ATDataQueue->get(0);
ocomeni 120:779b74689747 1349 if(evt.status == osEventMessage){
ocomeni 120:779b74689747 1350 ble_resp_data = (ble_at_msg_t*)evt.value.p;
ocomeni 120:779b74689747 1351 setNextResponse(ble_resp_data->at_resp);
ocomeni 121:ac4f59839e4f 1352 dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", ble_resp_data->dataLen, ble_resp_data->at_resp);
ocomeni 120:779b74689747 1353 }
ocomeni 120:779b74689747 1354 return true;
ocomeni 120:779b74689747 1355 }
ocomeni 120:779b74689747 1356
ocomeni 93:06e755a80187 1357
ocomeni 93:06e755a80187 1358 void ATCmdManager::sendAtConfirmation(const char *buf)
ocomeni 93:06e755a80187 1359 {
ocomeni 96:f5ed273881af 1360 _smutex.lock();
ocomeni 95:290859010c8c 1361 switch(dataMode){
ocomeni 95:290859010c8c 1362 case AT_CMD_DATA_MODE:
ocomeni 98:65c2333a38b6 1363 _parser.send("%s", buf);
ocomeni 95:290859010c8c 1364 break;
ocomeni 95:290859010c8c 1365 case AT_STD_DATA_MODE:
ocomeni 98:65c2333a38b6 1366 _parser.send("%s", buf);
ocomeni 95:290859010c8c 1367 break;
ocomeni 95:290859010c8c 1368 case AT_EXT_DATA_MODE:
ocomeni 98:65c2333a38b6 1369 {
ocomeni 96:f5ed273881af 1370 int len = strlen(buf);
ocomeni 95:290859010c8c 1371 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL);
ocomeni 95:290859010c8c 1372 break;
ocomeni 98:65c2333a38b6 1373 }
ocomeni 95:290859010c8c 1374 default:
ocomeni 98:65c2333a38b6 1375 _parser.send("%s", buf);
ocomeni 95:290859010c8c 1376 break;
ocomeni 95:290859010c8c 1377 }
ocomeni 96:f5ed273881af 1378 _smutex.unlock();
ocomeni 93:06e755a80187 1379 }
ocomeni 93:06e755a80187 1380 void ATCmdManager::sendAtEvent(const char *buf)
ocomeni 93:06e755a80187 1381 {
ocomeni 96:f5ed273881af 1382 _smutex.lock();
ocomeni 95:290859010c8c 1383 switch(dataMode){
ocomeni 95:290859010c8c 1384 case AT_CMD_DATA_MODE:
ocomeni 95:290859010c8c 1385 _parser.send(buf);
ocomeni 95:290859010c8c 1386 break;
ocomeni 95:290859010c8c 1387 case AT_STD_DATA_MODE:
ocomeni 95:290859010c8c 1388 _parser.send(buf);
ocomeni 95:290859010c8c 1389 break;
ocomeni 95:290859010c8c 1390 case AT_EXT_DATA_MODE:
ocomeni 99:05398b3184f8 1391 {
ocomeni 96:f5ed273881af 1392 int len = strlen(buf);
ocomeni 95:290859010c8c 1393 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL);
ocomeni 95:290859010c8c 1394 break;
ocomeni 99:05398b3184f8 1395 }
ocomeni 99:05398b3184f8 1396 default:
ocomeni 99:05398b3184f8 1397 _parser.send(buf);
ocomeni 99:05398b3184f8 1398 break;
ocomeni 95:290859010c8c 1399 }
ocomeni 96:f5ed273881af 1400 _smutex.unlock();
ocomeni 100:80ef4bc31b7a 1401 _wiFi2ATDatamPool->free(resp_data);
ocomeni 100:80ef4bc31b7a 1402 resp_data = NULL;
ocomeni 93:06e755a80187 1403 }
ocomeni 93:06e755a80187 1404
ocomeni 99:05398b3184f8 1405
ocomeni 118:8df0e9c2ee3f 1406 void ATCmdManager::sendBleDataEvent(const char *buf, int len)
ocomeni 118:8df0e9c2ee3f 1407 {
ocomeni 118:8df0e9c2ee3f 1408 _smutex.lock();
ocomeni 118:8df0e9c2ee3f 1409 switch(dataMode){
ocomeni 118:8df0e9c2ee3f 1410 case AT_CMD_DATA_MODE:
ocomeni 118:8df0e9c2ee3f 1411 _parser.send(buf);
ocomeni 118:8df0e9c2ee3f 1412 break;
ocomeni 118:8df0e9c2ee3f 1413 case AT_STD_DATA_MODE:
ocomeni 118:8df0e9c2ee3f 1414 _parser.send(buf);
ocomeni 118:8df0e9c2ee3f 1415 break;
ocomeni 118:8df0e9c2ee3f 1416 case AT_EXT_DATA_MODE:
ocomeni 118:8df0e9c2ee3f 1417 {
ocomeni 118:8df0e9c2ee3f 1418 outputEDMdata((const uint8_t *) buf, len, DATA_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL);
ocomeni 118:8df0e9c2ee3f 1419 break;
ocomeni 118:8df0e9c2ee3f 1420 }
ocomeni 118:8df0e9c2ee3f 1421 default:
ocomeni 118:8df0e9c2ee3f 1422 _parser.send(buf);
ocomeni 118:8df0e9c2ee3f 1423 break;
ocomeni 118:8df0e9c2ee3f 1424 }
ocomeni 118:8df0e9c2ee3f 1425 _smutex.unlock();
ocomeni 119:8d939a902333 1426 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 119:8d939a902333 1427 ble_resp_data = NULL;
ocomeni 119:8d939a902333 1428 }
ocomeni 119:8d939a902333 1429
ocomeni 119:8d939a902333 1430
ocomeni 119:8d939a902333 1431
ocomeni 119:8d939a902333 1432 void ATCmdManager::sendBleAtEvent(const char *buf, int len)
ocomeni 119:8d939a902333 1433 {
ocomeni 119:8d939a902333 1434 _smutex.lock();
ocomeni 119:8d939a902333 1435 switch(dataMode){
ocomeni 119:8d939a902333 1436 case AT_CMD_DATA_MODE:
ocomeni 119:8d939a902333 1437 _parser.send(buf);
ocomeni 119:8d939a902333 1438 break;
ocomeni 119:8d939a902333 1439 case AT_STD_DATA_MODE:
ocomeni 119:8d939a902333 1440 _parser.send(buf);
ocomeni 119:8d939a902333 1441 break;
ocomeni 119:8d939a902333 1442 case AT_EXT_DATA_MODE:
ocomeni 119:8d939a902333 1443 {
ocomeni 122:62166886db5f 1444 outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL);
ocomeni 119:8d939a902333 1445 break;
ocomeni 119:8d939a902333 1446 }
ocomeni 119:8d939a902333 1447 default:
ocomeni 119:8d939a902333 1448 _parser.send(buf);
ocomeni 119:8d939a902333 1449 break;
ocomeni 119:8d939a902333 1450 }
ocomeni 119:8d939a902333 1451 _smutex.unlock();
ocomeni 119:8d939a902333 1452 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 119:8d939a902333 1453 ble_resp_data = NULL;
ocomeni 119:8d939a902333 1454 }
ocomeni 119:8d939a902333 1455
ocomeni 119:8d939a902333 1456 void ATCmdManager::sendBleConnectEvent(const char *buf, int len)
ocomeni 119:8d939a902333 1457 {
ocomeni 119:8d939a902333 1458 _smutex.lock();
ocomeni 119:8d939a902333 1459 switch(dataMode){
ocomeni 119:8d939a902333 1460 case AT_CMD_DATA_MODE:
ocomeni 119:8d939a902333 1461 _parser.send(buf);
ocomeni 119:8d939a902333 1462 break;
ocomeni 119:8d939a902333 1463 case AT_STD_DATA_MODE:
ocomeni 119:8d939a902333 1464 _parser.send(buf);
ocomeni 119:8d939a902333 1465 break;
ocomeni 119:8d939a902333 1466 case AT_EXT_DATA_MODE:
ocomeni 119:8d939a902333 1467 {
ocomeni 119:8d939a902333 1468 outputEDMdata((const uint8_t *) buf, len, CONNECT_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL);
ocomeni 119:8d939a902333 1469 break;
ocomeni 119:8d939a902333 1470 }
ocomeni 119:8d939a902333 1471 default:
ocomeni 119:8d939a902333 1472 _parser.send(buf);
ocomeni 119:8d939a902333 1473 break;
ocomeni 119:8d939a902333 1474 }
ocomeni 119:8d939a902333 1475 _smutex.unlock();
ocomeni 119:8d939a902333 1476 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 119:8d939a902333 1477 ble_resp_data = NULL;
ocomeni 118:8df0e9c2ee3f 1478 }
ocomeni 118:8df0e9c2ee3f 1479
ocomeni 120:779b74689747 1480 void ATCmdManager::sendBleDisconnectEvent()
ocomeni 120:779b74689747 1481 {
ocomeni 120:779b74689747 1482 _smutex.lock();
ocomeni 120:779b74689747 1483 outputEDMdata(NULL, 0, DISCONNECT_MSG_ID, EVENT_MSG_TYPE, BLE_CHANNEL);
ocomeni 120:779b74689747 1484 _smutex.unlock();
ocomeni 120:779b74689747 1485 _ble2ATDatamPool->free(ble_resp_data);
ocomeni 120:779b74689747 1486 ble_resp_data = NULL;
ocomeni 120:779b74689747 1487 }
ocomeni 120:779b74689747 1488
ocomeni 118:8df0e9c2ee3f 1489
ocomeni 99:05398b3184f8 1490 void ATCmdManager::sendConnectEvent(const uint8_t *buf, int len)
ocomeni 99:05398b3184f8 1491 {
ocomeni 99:05398b3184f8 1492 switch(dataMode){
ocomeni 99:05398b3184f8 1493 case AT_CMD_DATA_MODE:
ocomeni 99:05398b3184f8 1494 _parser.send((const char*) buf);
ocomeni 99:05398b3184f8 1495 break;
ocomeni 99:05398b3184f8 1496 case AT_STD_DATA_MODE:
ocomeni 99:05398b3184f8 1497 _parser.send((const char*)buf);
ocomeni 99:05398b3184f8 1498 break;
ocomeni 99:05398b3184f8 1499 case AT_EXT_DATA_MODE:
ocomeni 99:05398b3184f8 1500 outputEDMdata((const uint8_t *) buf, len, CONNECT_MSG_ID, EVENT_MSG_TYPE, WIFI_CHANNEL);
ocomeni 99:05398b3184f8 1501 break;
ocomeni 99:05398b3184f8 1502 }
ocomeni 100:80ef4bc31b7a 1503 _wiFi2ATDatamPool->free(resp_data);
ocomeni 100:80ef4bc31b7a 1504 resp_data = NULL;
ocomeni 100:80ef4bc31b7a 1505
ocomeni 99:05398b3184f8 1506 }
ocomeni 99:05398b3184f8 1507
ocomeni 99:05398b3184f8 1508
ocomeni 90:ed0267eca7b5 1509 void ATCmdManager::outputEDMdata(const uint8_t *buf, int pLen,
ocomeni 91:d6b6319ad681 1510 edm_msg_id_t identifier, edm_msg_type_t type,
ocomeni 91:d6b6319ad681 1511 channel_id_t channel_id)
ocomeni 90:ed0267eca7b5 1512 {
ocomeni 90:ed0267eca7b5 1513 int epLen = pLen + 2; // edm payload length = data length + 2
ocomeni 96:f5ed273881af 1514 if(channel_id != NO_CHANNEL)
ocomeni 96:f5ed273881af 1515 epLen += 1;
ocomeni 90:ed0267eca7b5 1516 _smutex.lock();
ocomeni 90:ed0267eca7b5 1517 // send EDM Message start byte
ocomeni 90:ed0267eca7b5 1518 _parser.putc(EDM_START_BYTE);
ocomeni 90:ed0267eca7b5 1519 // send EDM Message length
ocomeni 90:ed0267eca7b5 1520 _parser.putc(epLen>>8);
ocomeni 90:ed0267eca7b5 1521 _parser.putc(epLen%256);
ocomeni 90:ed0267eca7b5 1522 // send EDM Identifier + Type
ocomeni 90:ed0267eca7b5 1523 _parser.putc(identifier>>8);
ocomeni 90:ed0267eca7b5 1524 _parser.putc(identifier%256 | type);
ocomeni 93:06e755a80187 1525 // send channel id if valid
ocomeni 93:06e755a80187 1526 if(channel_id != NO_CHANNEL)
ocomeni 93:06e755a80187 1527 _parser.putc(channel_id);
ocomeni 90:ed0267eca7b5 1528 // send the data
ocomeni 120:779b74689747 1529 if(pLen > 0)
ocomeni 120:779b74689747 1530 {
ocomeni 120:779b74689747 1531 _parser.write((const char *)buf, pLen);
ocomeni 120:779b74689747 1532 }
ocomeni 90:ed0267eca7b5 1533 // send EDM Message stop byte
ocomeni 90:ed0267eca7b5 1534 _parser.putc(EDM_STOP_BYTE);
ocomeni 98:65c2333a38b6 1535 _smutex.unlock();
ocomeni 96:f5ed273881af 1536 int msWait = (pLen + 5+20)/20;
ocomeni 96:f5ed273881af 1537 wait_ms(msWait);
ocomeni 90:ed0267eca7b5 1538 }
ocomeni 122:62166886db5f 1539 void ATCmdManager::filterHttpResponse()
ocomeni 122:62166886db5f 1540 {
ocomeni 122:62166886db5f 1541 char * respbuf = (char *) resp_data->buffer;
ocomeni 122:62166886db5f 1542 char * strPtr;
ocomeni 122:62166886db5f 1543 char * strPtr2;
ocomeni 122:62166886db5f 1544 dbg_printf(LOG, "Header before trim:\r\n%s\r\n", respbuf);
ocomeni 122:62166886db5f 1545 strPtr = strstr(respbuf, "Date:"); // find start of the last required entry
ocomeni 122:62166886db5f 1546 if(strPtr == NULL) return;
ocomeni 122:62166886db5f 1547 strPtr2 = strstr(respbuf, "Connection:"); // find start of the last required entry
ocomeni 122:62166886db5f 1548 if(strPtr == NULL) return;
ocomeni 122:62166886db5f 1549 if(strPtr2 > strPtr)
ocomeni 122:62166886db5f 1550 {
ocomeni 122:62166886db5f 1551 strPtr = strPtr2;
ocomeni 122:62166886db5f 1552 }
ocomeni 122:62166886db5f 1553 strPtr2 = strstr(strPtr, "\r\n"); // find end of the last required entry
ocomeni 122:62166886db5f 1554 if(strPtr2 == NULL) return;
ocomeni 122:62166886db5f 1555 strPtr = strstr(strPtr2, "\r\n\r\n"); // find start of body
ocomeni 122:62166886db5f 1556 if(strPtr == NULL) return;
ocomeni 122:62166886db5f 1557 int hdrLen = (strPtr - respbuf);
ocomeni 122:62166886db5f 1558 int bytes2trim = (strPtr - strPtr2);
ocomeni 122:62166886db5f 1559 memmove(strPtr2, strPtr, (resp_data->dataLen-(hdrLen-bytes2trim)));
ocomeni 122:62166886db5f 1560 resp_data->dataLen -= bytes2trim; // reduce the length by bytes to trim
ocomeni 122:62166886db5f 1561 dbg_printf(LOG, "Header after trim:\r\n%s\r\n", respbuf);
ocomeni 122:62166886db5f 1562 }
ocomeni 89:45f6db09a76d 1563 void ATCmdManager::return_response(bool download) {
ocomeni 87:99b37d26ff2a 1564 char * resp = (char *) resp_data->buffer;
ocomeni 103:7b566b522427 1565 dbg_printf(LOG, "\n[ATCMD MAN] received response:\n");
ocomeni 89:45f6db09a76d 1566 if(download == false) // not download must be ascii header
ocomeni 89:45f6db09a76d 1567 {
ocomeni 103:7b566b522427 1568 dbg_printf(LOG, "%.*s\r\n", resp_data->dataLen, resp);
ocomeni 89:45f6db09a76d 1569 }
ocomeni 89:45f6db09a76d 1570 else // dump payload as hex
ocomeni 89:45f6db09a76d 1571 {
ocomeni 89:45f6db09a76d 1572 printBufferInHex((uint8_t *)resp, resp_data->dataLen);
ocomeni 89:45f6db09a76d 1573 }
ocomeni 122:62166886db5f 1574 #ifdef TRIM_AWS_HEADER_ENTRIES
ocomeni 122:62166886db5f 1575 int offset = resp - strstr(resp,"HTTP/1.1");
ocomeni 122:62166886db5f 1576 if(offset >=0 && offset < 2) // must be at start of header
ocomeni 122:62166886db5f 1577 {
ocomeni 122:62166886db5f 1578 filterHttpResponse();
ocomeni 122:62166886db5f 1579 }
ocomeni 122:62166886db5f 1580 #endif
ocomeni 91:d6b6319ad681 1581 outputEDMdata((const uint8_t *)resp, resp_data->dataLen, DATA_MSG_ID,
ocomeni 91:d6b6319ad681 1582 EVENT_MSG_TYPE, WIFI_CHANNEL);
ocomeni 87:99b37d26ff2a 1583 _wiFi2ATDatamPool->free(resp_data);
ocomeni 96:f5ed273881af 1584 resp_data = NULL;
ocomeni 118:8df0e9c2ee3f 1585 lastHttpRespTime = Kernel::get_ms_count();
ocomeni 87:99b37d26ff2a 1586 }