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

Dependencies:   mbed-http

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