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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Sun Jul 07 20:36:41 2019 +0000
Branch:
PassingRegression
Revision:
126:9bc33f8b57d5
Parent:
125:d2830421006c
Child:
127:a21788227ca6
added some initial error handling:; - on an mbed os crash, the system now resets.; currently testing

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