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:
- 103:7b566b522427
- Parent:
- 102:9748f290a1a5
- Child:
- 104:11e9605093c9
--- a/source/ATCmdManager.cpp Wed Apr 24 17:34:17 2019 +0000 +++ b/source/ATCmdManager.cpp Thu May 02 21:50:17 2019 +0000 @@ -1,9 +1,11 @@ +#include "debug.h" #include "ATCmdManager.h" #include "common_config.h" #include "common_types.h" #include "http_request.h" #include "mbed_memory_status.h" //#include "mbed_memory_status.h" +#define FILE_CODE "atcmd" ATCmdManager::ATCmdManager(PinName tx, PinName rx, SMDevicePeripheral *blePeripheral, events::EventQueue &event_queue, WiFiManager *wifi, @@ -38,11 +40,13 @@ { // constructor - _serial.set_baud(DEFAULT_BAUD_RATE); + _serial.set_baud(2*DEFAULT_BAUD_RATE); + //Flow flowCtrl = Flow::Disabled; + //_serial.set_flow_control(mbed::SerialBase::Disabled); _parser.debug_on(debug); _parser.set_delimiter("\r\n"); - _parser.send("+STARTUP\r\n"); - _parser.oob("AT\n", callback(this, &ATCmdManager::_oob_ok_hdlr)); + _parser.send("+STARTUP\r\n\r\n"); + _parser.oob("AT\r", callback(this, &ATCmdManager::_oob_ok_hdlr)); _parser.oob("ATE0", callback(this, &ATCmdManager::_oob_echo_off)); _parser.oob("ATE1", callback(this, &ATCmdManager::_oob_echo_on)); _parser.oob("AT+UMRS", callback(this, &ATCmdManager::_oob_uart_setup)); @@ -67,6 +71,7 @@ //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr)); //_parser.oob("AT+UWSCD=", callback(this, &ATCmdManager::_oob_disconnectWiFiNetwork)); _parser.oob("AT+UDDRP", callback(this, &ATCmdManager::_oob_setupInternetConnection)); + _parser.oob("AT+UWSC=0,0,0", callback(this, &ATCmdManager::_oob_ok_hdlr)); _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)); @@ -74,19 +79,22 @@ _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"); + //sendAtConfirmation("Testing:: +UBTLE:2\r\nOK\r\n"); + dbg_printf(LOG, "\n --- ATCmdManager constructor completed ---\n"); at_resp = AT_RESP_NONE; dataMode = AT_CMD_DATA_MODE; debug_flag = 0; _event_queue.call_in(10, &print_heap_and_isr_stack_info); //print_heap_and_isr_stack_info(); _event_queue.call_every(3600000,&print_memory_info); +#ifdef BOX_UBLOX_DEMO_TESTING + check_for_at_cmd = false; +#endif } void ATCmdManager::runMain(){ - printf("\r\n [ATCMD MAN] Thread Id = %X\r\n", (uint32_t)ThisThread::get_id()); + dbg_printf(LOG, "\r\n [ATCMD MAN] Thread Id = %X\r\n", (uint32_t)ThisThread::get_id()); while(true){ _process_oob(UBLOX_ODIN_W2_RECV_TIMEOUT, true); wait_ms(MAIN_LOOP_WAIT_TIME_MS); // allow BTLE/WiFi some time @@ -100,7 +108,7 @@ dequeueWiFidataResponse(); if(debug_flag>0){ //debug_flag--; - printf(" back to ProcessResponses in Main loop... at_resp = %d\r\n", at_resp); + dbg_printf(LOG, " back to ProcessResponses in Main loop... at_resp = %d\r\n", at_resp); } char * respStr; //if(at_resp > AT_COMMAND_FAILED) @@ -109,13 +117,13 @@ case AT_RESP_NONE: if(debug_flag>0){ debug_flag--; - printf(" In IDLE state \r\n"); + dbg_printf(LOG, " In IDLE state \r\n"); } // IDLE response state break; case AT_SCAN_RESP: // AT_SCAN_RESP response state - printf("\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI SCAN RESPONSE RECEIVED!!\r\n"); //_smutex.lock(); //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); @@ -125,7 +133,7 @@ break; case AT_DETAILED_SCAN_RESP: // AT_DETAILED_SCAN_RESP response state - printf("\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI DETAILED SCAN RESPONSE RECEIVED!!\r\n"); //_smutex.lock(); //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); @@ -136,9 +144,9 @@ case AT_CONNECT_RESP: { // AT_CONNECT_RESP response state - printf("\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONNECT RESPONSE RECEIVED!!\r\n"); //_smutex.lock(); - //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); respStr = (char *) resp_data->buffer; sendAtConfirmationFreeMpool(respStr); char * urc = new char[20]; @@ -152,7 +160,7 @@ case AT_DISCONNECT_RESP: // AT_DISCONNECT_RESP response state //////_smutex.lock(); - printf("\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI DISCONNECT RESPONSE RECEIVED!!\r\n"); //_smutex.lock(); //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); @@ -163,7 +171,7 @@ case AT_CONFIG_RESP: // AT_CONFIG_RESP response state //////_smutex.lock(); - printf("\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI CONFIG RESPONSE RECEIVED!!\r\n"); //_smutex.lock(); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); @@ -172,7 +180,7 @@ case AT_NETWORK_STATUS_RESP: // AT_CONFIG_RESP response state //////_smutex.lock(); - printf("\n [ATCMD MAN] NETWORK STATUS RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] NETWORK STATUS RESPONSE RECEIVED!!\r\n"); respStr = (char *) resp_data->buffer; sendAtConfirmationFreeMpool(respStr); at_resp = AT_RESP_NONE; @@ -180,14 +188,14 @@ case AT_WIFI_STATUS_RESP: // AT_CONFIG_RESP response state //////_smutex.lock(); - printf("\n [ATCMD MAN] WIFI RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI RESPONSE RECEIVED!!\r\n"); respStr = (char *) resp_data->buffer; sendAtConfirmationFreeMpool(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!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI INTERNET_CONFIG RESPONSE RECEIVED!!\r\n"); //_smutex.lock(); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); @@ -197,7 +205,7 @@ break; case AT_HTTPS_RESP: // AT_HTTP_RESP response state - printf("\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTPS RESPONSE RECEIVED!!\r\n"); return_response(); //_smutex.lock(); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); @@ -206,7 +214,7 @@ break; case AT_HTTPS_RESP_DOWNLOAD: // AT_HTTPS_RESP_DOWNLOAD response state - printf("\n [ATCMD MAN] WIFI HTTPS DOWNLOAD RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTPS DOWNLOAD RESPONSE RECEIVED!!\r\n"); return_response(true); // set download paramter to true //_smutex.lock(); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); @@ -215,16 +223,16 @@ break; case AT_HTTP_RESP: // AT_HTTP_RESP response state - printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n"); return_response(); //_smutex.lock(); - sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); at_resp = AT_RESP_NONE; break; case AT_HTTP_RESP_DOWNLOAD: // AT_HTTP_RESP response state - printf("\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI HTTP RESPONSE RECEIVED!!\r\n"); return_response(true); // set download paramter to true //_smutex.lock(); //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); @@ -234,7 +242,7 @@ case CONNECT_EVENT: { // Connect Event state - printf("\n [ATCMD MAN] CONNECT EVENT RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] CONNECT EVENT RECEIVED!!\r\n"); sendConnectEvent(resp_data->buffer, resp_data->dataLen); at_resp = AT_RESP_NONE; break; @@ -242,7 +250,7 @@ case AT_EVENT: { // AT Event state - printf("\n [ATCMD MAN] AT EVENT RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] AT EVENT RECEIVED!!\r\n"); respStr = (char *) resp_data->buffer; sendAtEvent(respStr); at_resp = AT_RESP_NONE; @@ -251,7 +259,7 @@ case AT_COMMAND_FAILED: { // AT_HTTP_RESP response state - printf("\n [ATCMD MAN] WIFI COMMAND FAILED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] WIFI COMMAND FAILED!!\r\n"); //_smutex.lock(); //_parser.send("\r\nNACK\r\n"); //_smutex.unlock(); @@ -263,7 +271,7 @@ default: //UNKNOWN response state //_smutex.lock(); - printf("\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n"); + dbg_printf(LOG, "\n [ATCMD MAN] UNKNOWN RESPONSE RECEIVED!!\r\n"); sendAtConfirmationFreeMpool(ERROR_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); at_resp = AT_RESP_NONE; @@ -283,10 +291,10 @@ void ATCmdManager::printBufferInHex(uint8_t *buf, int pLen) { for(int i =0;i<pLen;i++){ - if(i%8==0) printf("\n[%3d]",i); - printf("%02x ", buf[i]); + if(i%8==0) dbg_printf(LOG, "\n[%3d]",i); + dbg_printf(LOG, "%02x ", buf[i]); } - printf("\n"); + dbg_printf(LOG, "\n"); } bool ATCmdManager::validate(edm_header_t edm_header) @@ -339,14 +347,14 @@ char * nxtPtr = strPtr; char * outPtr; char * bodyPtr = p2+4; - printf("\nstrPtr address= %x",strPtr); - printf("\np2 address= %x", p2); + dbg_printf(LOG, "\nstrPtr address= %x",strPtr); + dbg_printf(LOG, "\np2 address= %x", p2); for(int i = 0; i < 5; i++){ if(i == 0)// firstline scan method uri and http_ver { n = sscanf(nxtPtr,"%s %s %s", s1, s2, s3); if(n!=3) return false; // error in input abort - printf("\nmethod = %s\nuri = %s\nhttp_ver = %s",s1, s2, s3 ); + dbg_printf(LOG, "\nmethod = %s\nuri = %s\nhttp_ver = %s",s1, s2, s3 ); //http_req.method = str2HttpMethod(s1.c_str()); http_req->method = str2HttpMethod(s1); http_req->request_URI = (char *) http_req->buffer; // point 1st string to start of buffer @@ -355,10 +363,10 @@ http_req->http_version = http_req->request_URI + len; // point 2nd string to after 1st len = strlen(s3)+1; strncpy(http_req->http_version, s3, len); - printf("\nhttp_request 1st line:\n method = %d\nuri = %s\nhttp_ver = %s",http_req->method, + dbg_printf(LOG, "\nhttp_request 1st line:\n method = %d\nuri = %s\nhttp_ver = %s",http_req->method, http_req->request_URI, http_req->http_version ); - printf("\nhttp_request str ptrs\nuri = %X\nhttp_ver = %X",http_req->request_URI, + dbg_printf(LOG, "\nhttp_request str ptrs\nuri = %X\nhttp_ver = %X",http_req->request_URI, http_req->http_version ); outPtr = http_req->http_version + len; // point output buffer ptr to after 2nd string } @@ -368,26 +376,26 @@ if(n!=2) return false; // error in input abort p = strstr(s1,":"); *p = NULL; - printf("\nname = %s value = %s",s1, s2); + dbg_printf(LOG, "\nname = %s value = %s",s1, s2); if(strstr(s1, "Host")!= NULL){ http_req->hostName = outPtr; len = strlen(s2)+1; strncpy(outPtr, s2, len); - printf("\nname = %s value = %s",s1, outPtr); + dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr); outPtr += len; // point output buffer ptr to after current string } else if(strstr(s1, "Accept")!= NULL){ http_req->AcceptVal = outPtr; len = strlen(s2)+1; strncpy(outPtr, s2, len); - printf("\nname = %s value = %s",s1, outPtr); + dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr); outPtr += len; // point output buffer ptr to after current string } else if(strstr(s1, "Content-Type")!= NULL){ http_req->contentType = outPtr; len = strlen(s2)+1; strncpy(outPtr, s2, len); - printf("\nname = %s value = %s",s1, outPtr); + dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr); outPtr += len; // point output buffer ptr to after current string } else if(strstr(s1, "Content-Length")!= NULL){ @@ -395,31 +403,31 @@ http_req->contentLen = outPtr; len = strlen(s2)+1; strncpy(outPtr, s2, len); - printf("\nname = %s value = %s",s1, outPtr); + dbg_printf(LOG, "\nname = %s value = %s",s1, outPtr); outPtr += len; // point output buffer ptr to after current string } - printf("\noutPtr = %X len = %d\n", outPtr, len); + dbg_printf(LOG, "\noutPtr = %X len = %d\n", outPtr, len); } nxtPtr = strstr(nxtPtr, "\r\n")+2; // goto next line if(nxtPtr >= p2) break; } // print header from http_req_struct - printf("\nhttp request header: \n %s\n", http_req->buffer); + dbg_printf(LOG, "\nhttp request header: \n %s\n", http_req->buffer); int bodyLen = edm_hdr.payloadLen -(p2+7-strPtr); - printf("\nLen = %d\n", bodyLen); + dbg_printf(LOG, "\nLen = %d\n", bodyLen); http_req->body = (uint8_t *) outPtr; memcpy(outPtr, bodyPtr, bodyLen); if(bodyLen > 10){ - printf("\n Message Body:\n"); + dbg_printf(LOG, "\n Message Body:\n"); printBufferInHex(http_req->body, bodyLen); } outPtr += bodyLen; // move output pointer to end output (header + body) // package and send on wifi data queue data_msg.wifi_cmd = WIFI_CMD_SEND_HTTPS_REQ; - printf("\nsizeof(http_req) on population = %d\n", sizeof(*http_req)); + dbg_printf(LOG, "\nsizeof(http_req) on population = %d\n", sizeof(*http_req)); data_msg.dataLen = (uint8_t *)outPtr - http_req->buffer;//sizeof(http_request_t); - printf("\ndata_msg.dataLen = %d\n", data_msg.dataLen); + dbg_printf(LOG, "\ndata_msg.dataLen = %d\n", data_msg.dataLen); // queue next data request queueWiFiDataRequest(data_msg); return true; @@ -433,7 +441,7 @@ if(dataMode == AT_EXT_DATA_MODE) { int n; - //if(cnt++ % 10 == 0)printf("In EDM mode\n"); + //if(cnt++ % 10 == 0)dbg_printf(LOG, "In EDM mode\n"); uint8_t edm[EDM_HDR_LEN]; char cmdType[16]; // Poll for edm packets @@ -458,10 +466,10 @@ pT = 1; strcpy(cmdType, "AT REQUEST"); } - //printf("%d bytes read! : type = %s\n", n, cmdType2str(edm_hdr.payloadID)); - printf("%d bytes read! : CMD type = %s\n", n, cmdType); + //dbg_printf(LOG, "%d bytes read! : type = %s\n", n, cmdType2str(edm_hdr.payloadID)); + dbg_printf(LOG, "%d bytes read! : CMD type = %s\n", n, cmdType); if(n==(EDM_HDR_LEN-pT)) - printf("Start = %d, payloadID = %d len = %d chan_id = %d\n", edm_hdr.startByte, + dbg_printf(LOG, "Start = %d, payloadID = %d len = %d chan_id = %d\n", edm_hdr.startByte, edm_hdr.payloadID, edm_hdr.payloadLen, edm_hdr.channel_id); @@ -472,7 +480,7 @@ //_parser.process_oob(); while (_parser.process_oob() && all) { if(debug_flag>0){ - printf("finished queuing WIFI CONNECT CMD -- back to process_oob loop \r\n"); + dbg_printf(LOG, "finished queuing WIFI CONNECT CMD -- back to process_oob loop \r\n"); } } break; @@ -484,9 +492,9 @@ rx_buf_ptr[pLen-1] = 0x00; // clear last byte so the readback value is as expected n = _parser.read((char *)rx_buf_ptr, pLen); if(n == -1) break; // timeout! - printf("%d bytes read - expected %d!\n", n, pLen); + dbg_printf(LOG, "%d bytes read - expected %d!\n", n, pLen); printBufferInHex(rx_buf_ptr, pLen); - printf("rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]); + dbg_printf(LOG, "rx_buf_ptr[pLen-1] = %0x\n",rx_buf_ptr[pLen-1]); if(rx_buf_ptr[pLen-1] != EDM_STOP_BYTE) { _smutex.lock(); _parser.send("ERR"); @@ -498,18 +506,18 @@ switch(edm_hdr.payloadID) { case CONNECT_EVENT_ID: - printf("Connection Event received!\n"); + dbg_printf(LOG, "Connection Event received!\n"); break; case DISCONNECT_EVENT_ID: - printf("DISCONNECT_EVENT received!\n"); + dbg_printf(LOG, "DISCONNECT_EVENT received!\n"); break; case DATA_EVENT_ID: - printf("DATA_EVENT received!\n"); + dbg_printf(LOG, "DATA_EVENT received!\n"); break; case DATA_COMMAND_ID: { - printf("DATA_COMMAND received!\n"); - sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + dbg_printf(LOG, "DATA_COMMAND received!\n"); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); if(createHttpRequest() == true){ //_smutex.lock(); //sendAtConfirmation(OK_RESP); //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); @@ -523,20 +531,20 @@ free(rx_buf_ptr); rx_buf_ptr = NULL; int stop = Kernel::get_ms_count(); - printf("\n Time Elapsed = %d\n", stop-start); + dbg_printf(LOG, "\n Time Elapsed = %d\n", stop-start); break; } case AT_REQUEST_ID: - printf("AT_REQUEST received!\n"); + dbg_printf(LOG, "AT_REQUEST received!\n"); break; case AT_CONFIRMATION_ID: - printf("AT_CONFIRMATION received!\n"); + dbg_printf(LOG, "AT_CONFIRMATION received!\n"); break; case AT_EVENT_ID: - printf("AT_EVENT received!\n"); + dbg_printf(LOG, "AT_EVENT received!\n"); break; default: - printf("UNKNOWN MESSAGE received!\n"); + dbg_printf(LOG, "UNKNOWN MESSAGE received!\n"); break; } } @@ -552,17 +560,64 @@ { // Poll for inbound packets static int msgCnt = 0; + static char * ATCMD = new char[32]; + int n = 0; +#ifdef BOX_UBLOX_DEMO_TESTING + if(check_for_at_cmd) + { + while (n>=0 && all) { + n = readAtCommandString(ATCMD, 32); + if(strstr(ATCMD,"AT\r") != NULL) + { + _oob_ok_hdlr(); + check_for_at_cmd = false; + break; + } + } + } + else +#endif + { while (_parser.process_oob() && all) { - printf("inbound message found... msgCnt = %d \r\n", ++msgCnt); + dbg_printf(LOG, "inbound message found... msgCnt = %d \r\n", ++msgCnt); if(debug_flag>0){ - printf("finished queuing WIFI CONNECT CMD -- back to process_oob loop \r\n"); + dbg_printf(LOG, "finished queuing WIFI CONNECT CMD -- back to process_oob loop \r\n"); } } + } } set_timeout(); } +int ATCmdManager::readAtCommandString(char *strbuf, size_t bufLen) +{ + int n; + bool atstr_found = false; + int i = 0; + while(n != -1) + { + char c; + n = _parser.read(&c, 1); + if(n) + strbuf[i++] = c; + if(c=='\r') + { + strbuf[i++] = NULL; // terminate string and exit + atstr_found = true; + break; + } + } + if(atstr_found) + { + return i; + } + else + { + return -1; + } +} + // OOB message handlers void ATCmdManager::_oob_startup_hdlr(){ } @@ -599,23 +654,31 @@ #endif } - +#define TTP_DEBUGGING void ATCmdManager::_oob_uart_setup(){ int uOpts[NUM_UART_OPTIONS]; //if(_parser.recv("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5])) { if(_parser.scanf("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5]) >0) { - printf("\nATCmdParser: Uart Options=%d,%d,%d,%d,%d,%d\n", uOpts[0], uOpts[1], uOpts[2], uOpts[3], uOpts[4], uOpts[5]); + 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]); + //printf("\nATCmdParser: Uart Options=%d,%d,%d,%d,%d,%d\n", uOpts[0], uOpts[1], uOpts[2], uOpts[3], uOpts[4], uOpts[5]); //AT+UMRS=230400,2,8,1,1,1 - printf("\n Changing Baud Rate to %d\n", uOpts[0]); + dbg_printf(LOG, "\n Changing Baud Rate to %d\n", uOpts[0]); +#ifdef TTP_DEBUGGING + sendAtConfirmation(OK_RESP); +#else sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); wait(0.1); _serial.set_baud(uOpts[0]); wait(0.1); - printf("\n Baud Rate now %d\n", uOpts[0]); + dbg_printf(LOG, "\n Baud Rate now %d\n", uOpts[0]); +#endif +#ifdef BOX_UBLOX_DEMO_TESTING + check_for_at_cmd = true; +#endif } else { - printf("\nATCmdParser: Retrieving Uart Options failed"); + dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed"); } } @@ -628,8 +691,9 @@ void ATCmdManager::_oob_echo_off() { //_smutex.lock(); - printf("\n Received ATEO OOB command!!\n"); - printf("\n turning echo OFF!!\n"); + dbg_printf(LOG, "\n Received ATEO OOB command!!\n"); + dbg_printf(LOG, "\n turning echo OFF!!\n"); + //printf("\n turning echo OFF!!\n"); _parser.debug_on(false); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); @@ -639,8 +703,8 @@ void ATCmdManager::_oob_echo_on() { //_smutex.lock(); - printf("\n Received ATE1 OOB command!!\n"); - printf("\n turning echo ON!!\n"); + dbg_printf(LOG, "\n Received ATE1 OOB command!!\n"); + dbg_printf(LOG, "\n turning echo ON!!\n"); _parser.debug_on(true); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); @@ -649,32 +713,33 @@ void ATCmdManager::_oob_data_mode(){ //_smutex.lock(); - printf("\n Received EDM mode command!!\n"); - if(_parser.scanf("%d", &dataMode) >0) { - printf("\nATCmdParser: Data mode=%d\r\n", dataMode); + dbg_printf(LOG, "\n Received EDM mode command!!\n"); + int dmode; + if(_parser.scanf("%d", &dmode) >0) { + dbg_printf(LOG, "\nATCmdParser: Data mode=%d\r\n", dataMode); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); - switch(dataMode) + switch(dmode) { case 0: - printf("\nATCmdParser: Command Mode request received\n"); + dbg_printf(LOG, "\nATCmdParser: Command Mode request received\n"); dataMode = AT_CMD_DATA_MODE; break; case 1: - printf("\nATCmdParser: Data Mode request received\n"); + dbg_printf(LOG, "\nATCmdParser: Data Mode request received\n"); dataMode = AT_STD_DATA_MODE; break; case 2: - printf("\nATCmdParser: Extended data Mode request received\n"); + dbg_printf(LOG, "\nATCmdParser: Extended data Mode request received\n"); dataMode = AT_EXT_DATA_MODE; _event_queue.call_in(10, &print_heap_and_isr_stack_info); //print_heap_and_isr_stack_info(); break; default: - printf("\nATCmdParser: ERROR - UNKNOWN DATA MODE RECEIVED!!! \n"); + dbg_printf(LOG, "\nATCmdParser: ERROR - UNKNOWN DATA MODE RECEIVED!!! \n"); break; } } else { - printf("\nATCmdParser: Retrieving Uart Options failed\n"); + dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed\n"); } //_smutex.unlock(); } @@ -686,17 +751,17 @@ switch(bleOrWifi) { case 1: - printf("\nATCmdParser: BLE MAC Address request received"); + dbg_printf(LOG, "\nATCmdParser: BLE MAC Address request received"); break; case 2: - printf("\nATCmdParser: WiFi MAC Address request received"); + dbg_printf(LOG, "\nATCmdParser: WiFi MAC Address request received"); break; default: - printf("\nATCmdParser: ERROR - UNKNOWN MAC ADDRESS REQUEST RECEIVED!!! \n"); + dbg_printf(LOG, "\nATCmdParser: ERROR - UNKNOWN MAC ADDRESS REQUEST RECEIVED!!! \n"); break; } } else { - printf("\nATCmdParser: Retrieving Uart Options failed"); + dbg_printf(LOG, "\nATCmdParser: Retrieving Uart Options failed"); } sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); @@ -704,23 +769,24 @@ void ATCmdManager::_oob_get_ble_role(){ //_smutex.lock(); - printf("\n Received get BLE role command!!\n"); - sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + dbg_printf(LOG, "\n Received get BLE role command!!\n"); + //printf("\n Received get BLE role command!!\n"); + sendAtConfirmation("+UBTLE:2\r\nOK\r\n"); //_parser.send(OK_RESP); //_smutex.unlock(); } void ATCmdManager::_oob_ena_ble_peri(){ //_smutex.lock(); - printf("\n Received enable BLE Peripheral command!!\n"); + dbg_printf(LOG, "\n Received enable BLE Peripheral command!!\n"); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); } void ATCmdManager::_oob_reboot(){ //_smutex.lock(); - printf("\n Received reboot command!!\n"); + dbg_printf(LOG, "\n Received reboot command!!\n"); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); - _parser.send("System Resetting....\n"); + //_parser.send("System Resetting....\n"); system_reset(); //_smutex.unlock(); } @@ -756,7 +822,7 @@ void ATCmdManager::_oob_scanWiFiNetworks(){ //_smutex.lock(); - printf("\n Received scanWiFiNetworks command!!\n"); + dbg_printf(LOG, "\n Received scanWiFiNetworks command!!\n"); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); //_smutex.unlock(); wifi_cmd_t cmd = WIFI_CMD_SCAN; @@ -773,8 +839,8 @@ int aId; // interface id for request _parser.recv("%d,%d", &if_id, &aId); //_smutex.lock(); - printf("\n Received WiFi Configuration Action command %d %d!!\r\n", if_id, aId); - sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + dbg_printf(LOG, "\n Received WiFi Configuration Action command %d %d!!\r\n", if_id, aId); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); if(if_id == WIFI_CONFIG_ID && aId <5){ wifi_cmd_t cmd; action_id_t action_id = (action_id_t) aId; @@ -787,14 +853,14 @@ break; case WIFI_CONFIG_ACTIVATE: cmd = WIFI_CMD_CONNECT; - printf("\n About to Queue wifi cmd = %d!!\n", cmd); + dbg_printf(LOG, "\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); + dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd); //_smutex.unlock(); // queue next command queueWiFiCommand(cmd); @@ -804,7 +870,7 @@ } } if(debug_flag>0){ - printf("finished queuing WIFI CONNECT CMD \r\n"); + dbg_printf(LOG, "finished queuing WIFI CONNECT CMD \r\n"); } return; } @@ -813,7 +879,7 @@ void ATCmdManager::_oob_disconnectWiFiNetwork() { //_smutex.lock(); - printf("\n Received WiFi Disconnect command!!\n"); + dbg_printf(LOG, "\n Received WiFi Disconnect command!!\n"); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); wifi_cmd_t cmd = WIFI_CMD_DISCONNECT; //_smutex.unlock(); @@ -829,15 +895,19 @@ int n; internet_config_t internet_config; //_smutex.lock(); - printf("sizeof internet_config_t = %d\n", sizeof(internet_config_t)); + dbg_printf(LOG, "sizeof internet_config_t = %d\n", sizeof(internet_config_t)); n = ReadBytes((uint8_t *)str, MAX_URL_LEN); str[n]=NULL; - printf("\n read string = %s , n = %d\n", str, n); + dbg_printf(LOG, "\n read string = %s , n = %d\n", str, n); //n = sscanf(str, "=%1d,%199[^,],%1d", &(uint8_t)internet_config.peer_id, n = sscanf(str, "=%1d,%99[^,],%1d", &internet_config.peer_id, url, //internet_config.url, &internet_config.connectionScheme); +#ifdef BOX_UBLOX_DEMO_TESTING + char *p = strstr(url,"/https:"); +#else char *p = strstr(url,"\""); +#endif if(p!=NULL) { strncpy(internet_config.url, &p[1], strlen(url)); @@ -848,24 +918,24 @@ { strncpy(internet_config.url, url, strlen(url)+1); } - printf("\n read string = %s , n = %d -- strlen(url) = %d\n", internet_config.url, n, strlen(internet_config.url)); + dbg_printf(LOG, "\n read string = %s , n = %d -- strlen(url) = %d\n", internet_config.url, n, strlen(internet_config.url)); if(n>0) { - printf("peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id, + dbg_printf(LOG, "peer_id = %1d, url = %s, connScheme = %1d\n", internet_config.peer_id, internet_config.url, internet_config.connectionScheme); // package and send on wifi data queue wifi_data_msg_t data_msg; data_msg.wifi_cmd = WIFI_CMD_INTERNET_CONFIG; data_msg.dataLen = sizeof(internet_config_t); // + strlen(internet_config.url); - printf("\n url size = %d url str = %s\n",strlen(internet_config.url), internet_config.url ); + dbg_printf(LOG, "\n url size = %d url str = %s\n",strlen(internet_config.url), internet_config.url ); memcpy(data_msg.buffer,&internet_config, data_msg.dataLen); - sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); // queue next data request queueWiFiDataRequest(data_msg); print_memory_info(); } else { - printf("\n[ATCMD MAN]: internet configuration failed %d fields parsed \r\n", n); + dbg_printf(LOG, "\n[ATCMD MAN]: internet configuration failed %d fields parsed \r\n", n); _parser.send("NAK\n"); } //_smutex.unlock(); @@ -919,19 +989,19 @@ wifi_config_t wifi_cfg = init_wifi_config(); //_smutex.lock(); n = readStringBytes((uint8_t *)wifi_cfg.ssid, 32); - printf("[ATCMD MAN]: number of bytes read = %d\n", n); + dbg_printf(LOG, "[ATCMD MAN]: number of bytes read = %d\n", n); if(n>0) { - printf("[ATCMD MAN]: wifi_cfg.ssid = %s\n", wifi_cfg.ssid); + dbg_printf(LOG, "[ATCMD MAN]: wifi_cfg.ssid = %s\n", wifi_cfg.ssid); // package and send on wifi data queue wifi_data_msg_t data_msg; data_msg.wifi_cmd = WIFI_CMD_CONFIG; data_msg.dataLen = sizeof(wifi_config_t); memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); - sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); queueWiFiDataRequest(data_msg); } else { - printf("\n[ATCMD MAN]: wifi configuration failed \n"); + dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n"); _parser.send("NAK\n"); } //_smutex.unlock(); @@ -946,16 +1016,16 @@ n = readStringBytes((uint8_t *)wifi_cfg.pass, 32); if(n>0) { - printf("ATCMD MAN]: wifi_cfg.pass = %s\n", "****************"); + dbg_printf(LOG, "ATCMD MAN]: wifi_cfg.pass = %s\n", "****************"); // package and send on wifi data queue wifi_data_msg_t data_msg; data_msg.wifi_cmd = WIFI_CMD_CONFIG; data_msg.dataLen = sizeof(wifi_config_t); memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); - sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); queueWiFiDataRequest(data_msg); } else { - printf("\n[ATCMD MAN]: wifi configuration failed \n"); + dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n"); _parser.send("NAK\n"); } //_smutex.unlock(); @@ -970,16 +1040,16 @@ _smutex.unlock(); if(n>0) { - printf("ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security)); + dbg_printf(LOG, "ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security)); // package and send on wifi data queue wifi_data_msg_t data_msg; data_msg.wifi_cmd = WIFI_CMD_CONFIG; data_msg.dataLen = sizeof(wifi_config_t); memcpy(data_msg.buffer,&wifi_cfg, data_msg.dataLen); - sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + //sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); queueWiFiDataRequest(data_msg); } else { - printf("\n[ATCMD MAN]: wifi configuration failed \n"); + dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n"); _smutex.lock(); _parser.send("NAK\n"); _smutex.unlock(); @@ -994,11 +1064,11 @@ 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); + dbg_printf(LOG, "\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); + dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd); //_smutex.unlock(); // queue next command queueWiFiCommand(cmd); @@ -1010,10 +1080,10 @@ void ATCmdManager::_oob_WiFiNetworkStatus() { //_smutex.lock(); - printf("\n Received Get WiFi Network Status command!!\n"); - sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); + dbg_printf(LOG, "\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); + dbg_printf(LOG, "\n About to Queue wifi cmd = %d!!\n", cmd); //_smutex.unlock(); // queue next command queueWiFiCommand(cmd); @@ -1029,7 +1099,7 @@ n = _parser.scanf(",%d", &wifi_cfg.security); if(n>0) { - printf("ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security)); + dbg_printf(LOG, "ATCMD MAN]: wifi_cfg.security = %s\n", sec2str(wifi_cfg.security)); // package and send on wifi data queue wifi_data_msg_t data_msg; data_msg.wifi_cmd = WIFI_CMD_CONFIG; @@ -1038,7 +1108,7 @@ queueWiFiDataRequest(data_msg); sendAtConfirmation(OK_RESP); //_parser.send(OK_RESP); } else { - printf("\n[ATCMD MAN]: wifi configuration failed \n"); + dbg_printf(LOG, "\n[ATCMD MAN]: wifi configuration failed \n"); _parser.send("NAK\n"); } */ @@ -1047,17 +1117,17 @@ } bool ATCmdManager::queueWiFiCommand(wifi_cmd_t cmd){ - printf("[ATCMD MAN] about to be queued with wifi_cmd = %d\n", cmd); + dbg_printf(LOG, "[ATCMD MAN] about to be queued with wifi_cmd = %d\n", cmd); #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL wifi_cmd_message_t *wifiCmd = _aT2WiFimPool->alloc(); if(wifiCmd == NULL){ - printf("[ATCMD MAN] queued memory allocation failed\n"); + dbg_printf(LOG, "[ATCMD MAN] queued memory allocation failed\n"); return false; } #else wifi_cmd_message_t *wifiCmd = (wifi_cmd_message_t *) malloc(sizeof(wifi_cmd_message_t)); if(wifiCmd == NULL){ - printf("[ATCMD MAN] try malloc() : queued memory allocation failed\n"); + dbg_printf(LOG, "[ATCMD MAN] try malloc() : queued memory allocation failed\n"); //_event_queue.call_in(10, &print_memory_info); _event_queue.call_in(10, &print_heap_and_isr_stack_info); //print_memory_info(); @@ -1067,7 +1137,7 @@ #endif wifiCmd->wifi_cmd = cmd; _aT2WiFiCmdQueue->put(wifiCmd); - printf("[ATCMD MAN] queued wifi_cmd = %d\n", wifiCmd->wifi_cmd); + dbg_printf(LOG, "[ATCMD MAN] queued wifi_cmd = %d\n", wifiCmd->wifi_cmd); if((int)cmd == 5) debug_flag = 3; return true; @@ -1076,14 +1146,14 @@ bool ATCmdManager::dequeueATresponse(){ if(debug_flag>0){ debug_flag--; - printf("Called dequeueATresponse after WIFI CONNECT CMD \r\n"); + dbg_printf(LOG, "Called dequeueATresponse after WIFI CONNECT CMD \r\n"); } if(at_resp != AT_RESP_NONE) return false; // busy osEvent evt = _wiFi2ATCmdQueue->get(0); if(evt.status == osEventMessage){ at_resp_message_t *resp = (at_resp_message_t*)evt.value.p; setNextResponse(resp->at_resp); - printf("[ATCMD MAN] dequeued AT CMD : at_resp = %d\n", resp->at_resp); + dbg_printf(LOG, "[ATCMD MAN] dequeued AT CMD : at_resp = %d\n", resp->at_resp); #ifndef USE_MALLOC_FOR_COMMAND_MEMORY_POOL _wiFi2ATmPool->free(resp); resp = NULL; @@ -1104,7 +1174,7 @@ wifiData->dataLen = data_req.dataLen; memcpy(wifiData->buffer, data_req.buffer, data_req.dataLen); _aT2WiFiDataQueue->put(wifiData); - printf("[ATCMD MAN] queued data size = %d : wifi_cmd = %d\n", data_req.dataLen, data_req.wifi_cmd); + dbg_printf(LOG, "[ATCMD MAN] queued data size = %d : wifi_cmd = %d\n", data_req.dataLen, data_req.wifi_cmd); //free(&data_req); return true; } @@ -1112,14 +1182,14 @@ bool ATCmdManager::dequeueWiFidataResponse(){ if(debug_flag>0){ debug_flag--; - printf("Called dequeueWiFidataResponse after WIFI CONNECT CMD \r\n"); + dbg_printf(LOG, "Called dequeueWiFidataResponse after WIFI CONNECT CMD \r\n"); } if(at_resp != AT_RESP_NONE) return false; // busy osEvent evt = _wiFi2ATDataQueue->get(0); if(evt.status == osEventMessage){ resp_data = (at_data_msg_t*)evt.value.p; setNextResponse(resp_data->at_resp); - printf("[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", resp_data->dataLen, resp_data->at_resp); + dbg_printf(LOG, "[ATCMD MAN] dequeued data size = %d : at_resp = %d\n", resp_data->dataLen, resp_data->at_resp); _event_queue.call_in(10, &print_heap_and_isr_stack_info); //print_heap_and_isr_stack_info(); } @@ -1227,10 +1297,10 @@ void ATCmdManager::return_response(bool download) { char * resp = (char *) resp_data->buffer; //_smutex.lock(); - printf("\n[ATCMD MAN] received response:\n"); + dbg_printf(LOG, "\n[ATCMD MAN] received response:\n"); if(download == false) // not download must be ascii header { - printf("%.*s\r\n", resp_data->dataLen, resp); + dbg_printf(LOG, "%.*s\r\n", resp_data->dataLen, resp); } else // dump payload as hex {