Okundu Omeni
/
wifi-https-ble-sm-uart-atcmd-5-13-1
this is using the mbed os version 5-13-1
Diff: source/ATCmdManager.cpp
- Revision:
- 95:290859010c8c
- Parent:
- 93:06e755a80187
- Child:
- 96:f5ed273881af
--- a/source/ATCmdManager.cpp Sun Apr 14 17:03:02 2019 +0000 +++ b/source/ATCmdManager.cpp Wed Apr 17 18:11:45 2019 +0000 @@ -54,12 +54,15 @@ _parser.oob("AT+CPWROFF", callback(this, &ATCmdManager::_oob_reboot)); _parser.oob("AT+CGMR", callback(this, &ATCmdManager::_oob_get_fw_ver)); _parser.oob("AT+UWSCAN", callback(this, &ATCmdManager::_oob_scanWiFiNetworks)); - _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_connect2WiFiNetwork)); - _parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork)); + _parser.oob("AT+UWSCA=", callback(this, &ATCmdManager::_oob_WiFiStationConfigurationAction)); + //_parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork)); _parser.oob("AT+UDDRP", callback(this, &ATCmdManager::_oob_setupInternetConnection)); _parser.oob("AT+UWSC=0,2", callback(this, &ATCmdManager::_oob_setWiFiSSID)); _parser.oob("AT+UWSC=0,8", callback(this, &ATCmdManager::_oob_setWiFiPWD)); _parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_setWiFiSecurity)); + _parser.oob("AT+UNSTAT=", callback(this, &ATCmdManager::_oob_getNetworkStatus)); + _parser.oob("AT+UWSSTAT", callback(this, &ATCmdManager::_oob_WiFiNetworkStatus)); + //_parser.oob("AT+UWSC=0,5", callback(this, &ATCmdManager::_oob_sendHttpMessage)); printf("\n --- ATCmdManager constructor completed ---\n"); @@ -83,6 +86,7 @@ void ATCmdManager::processResponses(){ dequeueATresponse(); dequeueWiFidataResponse(); + char * respStr; switch(at_resp){ case AT_RESP_NONE: // IDLE response state @@ -90,34 +94,42 @@ case AT_SCAN_RESP: // AT_SCAN_RESP response state printf("\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\n"); - _smutex.lock(); - _parser.send(OK_RESP); - _smutex.unlock(); + //_smutex.lock(); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //_smutex.unlock(); + respStr = (char *) resp_data->buffer; + sendAtConfirmation(respStr); at_resp = AT_RESP_NONE; break; case AT_DETAILED_SCAN_RESP: // AT_DETAILED_SCAN_RESP response state printf("\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\n"); - _smutex.lock(); - _parser.send(OK_RESP); - _smutex.unlock(); + //_smutex.lock(); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //_smutex.unlock(); + respStr = (char *) resp_data->buffer; + sendAtConfirmation(respStr); at_resp = AT_RESP_NONE; break; case AT_CONNECT_RESP: // AT_CONNECT_RESP response state printf("\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\n"); - _smutex.lock(); - _parser.send(OK_RESP); - _smutex.unlock(); + //_smutex.lock(); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + respStr = (char *) resp_data->buffer; + sendAtConfirmation(respStr); + //_smutex.unlock(); at_resp = AT_RESP_NONE; break; case AT_DISCONNECT_RESP: // AT_DISCONNECT_RESP response state //////_smutex.lock(); printf("\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\n"); - _smutex.lock(); - _parser.send(OK_RESP); - _smutex.unlock(); + //_smutex.lock(); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //_smutex.unlock(); + respStr = (char *) resp_data->buffer; + sendAtConfirmation(respStr); at_resp = AT_RESP_NONE; break; case AT_CONFIG_RESP: @@ -125,16 +137,34 @@ //////_smutex.lock(); printf("\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\n"); _smutex.lock(); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); at_resp = AT_RESP_NONE; break; + case AT_NETWORK_STATUS_RESP: + // AT_CONFIG_RESP response state + //////_smutex.lock(); + printf("\n [ATCMD MAN] NETWORK STATUS RESPONSE RECEIVED!!\n"); + respStr = (char *) resp_data->buffer; + sendAtConfirmation(respStr); + at_resp = AT_RESP_NONE; + break; + case AT_WIFI_STATUS_RESP: + // AT_CONFIG_RESP response state + //////_smutex.lock(); + printf("\n [ATCMD MAN] WIFI RESPONSE RECEIVED!!\n"); + respStr = (char *) resp_data->buffer; + sendAtConfirmation(respStr); + at_resp = AT_RESP_NONE; + break; case AT_INTERNET_CONFIG_RESP: // AT_CONFIG_RESP response state printf("\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\n"); - _smutex.lock(); - _parser.send(OK_RESP); - _smutex.unlock(); + //_smutex.lock(); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //_smutex.unlock(); + respStr = (char *) resp_data->buffer; + sendAtConfirmation(respStr); at_resp = AT_RESP_NONE; break; case AT_HTTPS_RESP: @@ -142,7 +172,7 @@ printf("\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\n"); return_response(); _smutex.lock(); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); at_resp = AT_RESP_NONE; break; @@ -151,7 +181,7 @@ printf("\n [ATCMD MAN] WIFI HTTPS DOWNLOAD RESPONSE RECEIVED!!\n"); return_response(true); // set download paramter to true _smutex.lock(); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); at_resp = AT_RESP_NONE; break; @@ -160,7 +190,7 @@ printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\n"); return_response(); _smutex.lock(); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); at_resp = AT_RESP_NONE; break; @@ -168,25 +198,27 @@ // AT_HTTP_RESP response state printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\n"); return_response(true); // set download paramter to true - _smutex.lock(); - _parser.send(OK_RESP); - _smutex.unlock(); + //_smutex.lock(); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //_smutex.unlock(); at_resp = AT_RESP_NONE; break; case AT_COMMAND_FAILED: // AT_HTTP_RESP response state printf("\n [ATCMD MAN] WIFI COMMAND FAILED!!\n"); - _smutex.lock(); - _parser.send("\r\nNACK\r\n"); - _smutex.unlock(); - at_resp = AT_RESP_NONE; + //_smutex.lock(); + //_parser.send("\r\nNACK\r\n"); + //_smutex.unlock(); + char * respStr = (char *) resp_data->buffer; + sendAtConfirmation(respStr); + AT_RESP_NONE; break; default: // UNKNOWN response state - _smutex.lock(); + //_smutex.lock(); printf("\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\n"); - _parser.send(OK_RESP); - _smutex.unlock(); + sendAtConfirmation(ERROR_RESP); //_parser.send(OK_RESP); + //_smutex.unlock(); at_resp = AT_RESP_NONE; break; } @@ -417,7 +449,7 @@ printf("DATA_COMMAND received!\n"); if(createHttpRequest() == true){ _smutex.lock(); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); } else{ @@ -467,7 +499,7 @@ void ATCmdManager::_oob_ok_hdlr(){ _smutex.lock(); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); } @@ -500,7 +532,7 @@ //AT+UMRS=230400,2,8,1,1,1 printf("\n Changing Baud Rate to %d\n", uOpts[0]); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); wait(0.1); _serial.set_baud(uOpts[0]); wait(0.1); @@ -523,7 +555,7 @@ printf("\n Received ATEO OOB command!!\n"); printf("\n turning echo OFF!!\n"); _parser.debug_on(false); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); } @@ -534,7 +566,7 @@ printf("\n Received ATE1 OOB command!!\n"); printf("\n turning echo ON!!\n"); _parser.debug_on(true); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); } @@ -566,7 +598,7 @@ } else { printf("\nATCmdParser: Retrieving Uart Options failed\n"); } - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); } @@ -589,28 +621,28 @@ } else { printf("\nATCmdParser: Retrieving Uart Options failed"); } - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); } void ATCmdManager::_oob_get_ble_role(){ _smutex.lock(); printf("\n Received get BLE role command!!\n"); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); } void ATCmdManager::_oob_ena_ble_peri(){ _smutex.lock(); printf("\n Received enable BLE Peripheral command!!\n"); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); } void ATCmdManager::_oob_reboot(){ _smutex.lock(); printf("\n Received reboot command!!\n"); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _parser.send("System Resetting....\n"); system_reset(); _smutex.unlock(); @@ -648,7 +680,7 @@ void ATCmdManager::_oob_scanWiFiNetworks(){ _smutex.lock(); printf("\n Received scanWiFiNetworks command!!\n"); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); _smutex.unlock(); wifi_cmd_t cmd = WIFI_CMD_SCAN; // queue next command @@ -656,16 +688,43 @@ return; } -void ATCmdManager::_oob_connect2WiFiNetwork() + + +void ATCmdManager::_oob_WiFiStationConfigurationAction() { + uint8_t if_id; // interface id for request + action_id_t action_id; // interface id for request + _parser.scanf("%d,%d", &if_id, &action_id); //_smutex.lock(); - printf("\n Received WiFi Connect command!!\n"); - _parser.send(OK_RESP); - wifi_cmd_t cmd = WIFI_CMD_CONNECT; - printf("\n About to Queue wifi cmd = %d!!\n", cmd); - //_smutex.unlock(); - // queue next command - queueWiFiCommand(cmd); + printf("\n Received WiFi Configuration Action command!!\n"); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + if(if_id == WIFI_CONFIG_ID && (uint8_t)action_id <5){ + wifi_cmd_t cmd; + switch(action_id){ + case WIFI_CONFIG_RESET: + break; + case WIFI_CONFIG_STORE: + break; + case WIFI_CONFIG_LOAD: + break; + case WIFI_CONFIG_ACTIVATE: + cmd = WIFI_CMD_CONNECT; + printf("\n About to Queue wifi cmd = %d!!\n", cmd); + //_smutex.unlock(); + // queue next command + queueWiFiCommand(cmd); + break; + case WIFI_CONFIG_DEACTIVATE: + cmd = WIFI_CMD_DISCONNECT; + printf("\n About to Queue wifi cmd = %d!!\n", cmd); + //_smutex.unlock(); + // queue next command + queueWiFiCommand(cmd); + break; + default: + break; + } + } return; } @@ -674,7 +733,7 @@ { _smutex.lock(); printf("\n Received WiFi Disconnect command!!\n"); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); wifi_cmd_t cmd = WIFI_CMD_DISCONNECT; _smutex.unlock(); // queue next command @@ -723,7 +782,7 @@ // queue next data request queueWiFiDataRequest(data_msg); print_memory_info(); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); } else { printf("\n[ATCMD MAN]: internet configuration failed %d fields parsed \n", n); _parser.send("NAK\n"); @@ -789,7 +848,7 @@ data_msg.dataLen = sizeof(wifi_config_t); memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); queueWiFiDataRequest(data_msg); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); } else { printf("\n[ATCMD MAN]: wifi configuration failed \n"); _parser.send("NAK\n"); @@ -813,7 +872,7 @@ data_msg.dataLen = sizeof(wifi_config_t); memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); queueWiFiDataRequest(data_msg); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); } else { printf("\n[ATCMD MAN]: wifi configuration failed \n"); _parser.send("NAK\n"); @@ -837,7 +896,7 @@ data_msg.dataLen = sizeof(wifi_config_t); memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); queueWiFiDataRequest(data_msg); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); } else { printf("\n[ATCMD MAN]: wifi configuration failed \n"); _smutex.lock(); @@ -848,6 +907,38 @@ } + +void ATCmdManager::_oob_getNetworkStatus() +{ + uint8_t if_id; // interface id for request + _parser.scanf(",%d", &if_id); + //_smutex.lock(); + printf("\n Received Get Network Status command!!\n"); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + if(if_id == WIFI_INTERFACE_ID){ + wifi_cmd_t cmd = WIFI_CMD_NETWORK_STATUS; + printf("\n About to Queue wifi cmd = %d!!\n", cmd); + //_smutex.unlock(); + // queue next command + queueWiFiCommand(cmd); + } + return; +} + + +void ATCmdManager::_oob_WiFiNetworkStatus() +{ + //_smutex.lock(); + printf("\n Received Get WiFi Network Status command!!\n"); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + wifi_cmd_t cmd = WIFI_CMD_WIFI_STATUS; + printf("\n About to Queue wifi cmd = %d!!\n", cmd); + //_smutex.unlock(); + // queue next command + queueWiFiCommand(cmd); + return; +} + void ATCmdManager::_oob_sendHttpMessage() { int n; @@ -864,7 +955,7 @@ data_msg.dataLen = sizeof(wifi_config_t); memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); queueWiFiDataRequest(data_msg); - _parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); } else { printf("\n[ATCMD MAN]: wifi configuration failed \n"); _parser.send("NAK\n"); @@ -927,12 +1018,10 @@ bool ATCmdManager::dequeueWiFidataResponse(){ if(at_resp != AT_RESP_NONE) return false; // busy - //print_memory_info(); osEvent evt = _wiFi2ATDataQueue->get(0); if(evt.status == osEventMessage){ resp_data = (at_data_msg_t*)evt.value.p; setNextResponse(resp_data->at_resp); - //_wiFi2ATDatamPool->free(resp_data); print_heap_and_isr_stack_info(); } return true; @@ -941,13 +1030,39 @@ void ATCmdManager::sendAtConfirmation(const char *buf) { - int len = strlen(buf); - outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL); + switch(dataMode){ + case AT_CMD_DATA_MODE: + _parser.send(buf); + break; + case AT_STD_DATA_MODE: + _parser.send(buf); + break; + case AT_EXT_DATA_MODE: + int len = strlen(buf) + 1; + outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, CONFIRMATION_MSG_TYPE, NO_CHANNEL); + break; + default: + _parser.send(buf); + break; + } } void ATCmdManager::sendAtEvent(const char *buf) { - int len = strlen(buf); - outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL); + switch(dataMode){ + case AT_CMD_DATA_MODE: + _parser.send(buf); + break; + case AT_STD_DATA_MODE: + _parser.send(buf); + break; + case AT_EXT_DATA_MODE: + int len = strlen(buf) + 1; + outputEDMdata((const uint8_t *) buf, len, AT_MSG_ID, EVENT_MSG_TYPE, NO_CHANNEL); + break; + default: + _parser.send(buf); + break; + } } void ATCmdManager::outputEDMdata(const uint8_t *buf, int pLen,