this is using the mbed os version 5-13-1
Revision 102:9748f290a1a5, committed 2019-04-24
- Comitter:
- ocomeni
- Date:
- Wed Apr 24 17:34:17 2019 +0000
- Parent:
- 101:1cfd468e5009
- Child:
- 103:7b566b522427
- Commit message:
- added fix for response header issue.; passing regression tests.; known issue:; - UDDRP response incomplete
Changed in this revision
--- a/source/ATCmdManager.cpp Mon Apr 22 19:36:31 2019 +0000
+++ b/source/ATCmdManager.cpp Wed Apr 24 17:34:17 2019 +0000
@@ -55,6 +55,16 @@
_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_WiFiStationConfigAction));
+
+ _parser.oob("AT+UMLA=", callback(this, &ATCmdManager::_oob_ok_hdlr));
+ _parser.oob("AT+UBTLN", callback(this, &ATCmdManager::_oob_ok_hdlr));
+ _parser.oob("AT+UBTSM?", callback(this, &ATCmdManager::_oob_ok_hdlr));
+ _parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
+
+ _parser.oob("AT+UDSC=", callback(this, &ATCmdManager::_oob_ok_hdlr));
+ _parser.oob("AT&W", callback(this, &ATCmdManager::_oob_ok_hdlr));
+ //_parser.oob("AT+UBTPM", callback(this, &ATCmdManager::_oob_ok_hdlr));
+ //_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,2", callback(this, &ATCmdManager::_oob_setWiFiSSID));
@@ -581,6 +591,12 @@
void ATCmdManager::_oob_get_fw_ver()
{
+#ifdef MBED_MAJOR_VERSION
+ char * fw_ver_str = new char[20];
+ sprintf(fw_ver_str, "Mbed OS version %d.%d.%d.0\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
+ sendAtConfirmation(fw_ver_str);
+ delete fw_ver_str;
+#endif
}
--- a/source/WiFiManager.cpp Mon Apr 22 19:36:31 2019 +0000
+++ b/source/WiFiManager.cpp Wed Apr 24 17:34:17 2019 +0000
@@ -691,7 +691,7 @@
}
else {
if(http_response_hdr_sent == false && chunkNum==1){ // only do this for first chunk
- bool status = copyResponseHdr2Queue();
+ bool status = copyResponseHdr2Queue(buf);
if(status == true){
printf("[WIFI-MAN] Http Response header copied to response buffer [bytes = %d] \r\n",at_data_resp->dataLen);
hdrLen = at_data_resp->dataLen;
@@ -719,58 +719,40 @@
at_data_resp = NULL;
}
-bool WiFiManager::copyResponseHdr2Queue()
+bool WiFiManager::copyResponseHdr2Queue(const uint8_t * buf)
{
- int numChars = 0;
- // create message pointer for response header generation
- char * msgPtr = (char *)at_data_resp->buffer;
- // do status line
- int wait_cnt = 0;
- while(http_response == NULL && wait_cnt<100)
+ const char *arbPtr = (const char *)buf - MAX_HTTP_HDR_LEN;
+ const char *hdrPtr;
+ int len;
+ bool hdrFound = false;
+ int i;
+ for(i=0;i<(MAX_HTTP_HDR_LEN-50);i++)
{
- printf("[WIFI-MAN] response pointer NULL waiting for %dms so far!!\r\n", 10*wait_cnt++);
- wait_ms(10);
- //return false;
+ // get location of start of the http header string
+ hdrPtr = strstr(&arbPtr[i], HTTP_HEADER_START_LINE);
+ len = strlen(HTTP_HEADER_START_LINE);
+ // validate that header string
+ if((strstr(&arbPtr[i+len], HTTP_HEADER_START_LINE) == NULL ||
+ (strstr(&arbPtr[i+len], HTTP_HEADER_START_LINE) > (const char*)buf)) && //
+ strstr(&arbPtr[i+len], HTTP_HEADER_CONTENT_TYPE) != NULL &&
+ strstr(&arbPtr[i+len], HTTP_HEADER_CONTENT_LEN) != NULL &&
+ hdrPtr != NULL)
+ {
+ hdrFound = true;
+ break;
+ }
}
- if(http_response == NULL)
+ // calculate header length
+ int hdrLen = (const char*) buf -hdrPtr;
+ // copy header
+ memcpy(at_data_resp->buffer, (const uint8_t *) hdrPtr, hdrLen);
+ printf("[i = %d] This is the header\r\n%s\r\n", i, hdrPtr);
+ if(hdrFound == false)
{
- printf("[WIFI-MAN] copy failed: response pointer NULL!!\r\n");
+ printf("[WIFI-MAN] copy failed: HTTP header not found!!\r\n");
return false;
}
- printf("before getting HTTP status line http_response = 0x%08X\n", http_response);
- numChars = sprintf(msgPtr, "HTTP/1.1 %d %s\r\n", http_response->get_status_code(),
- http_response->get_status_message().c_str());
- msgPtr += numChars;
- printf("before getting HTTP headers length\n");
-
- int hdrsLen = http_response->get_headers_length();
- printf("after getting HTTP headers length = %d\n", hdrsLen);
- //print_memory_info();
- if(hdrsLen <= 1)
- {
- printf("copy failed: Header Line = [%s]", msgPtr);
- return false;
- }
- char * hdrField;
- char * hdrValue;
- for (size_t ix = 0; ix < hdrsLen; ix++) {
- int sLen = http_response->get_headers_fields()[ix]->size()+1;
- hdrField = new char [sLen];
- std::strcpy (hdrField, http_response->get_headers_fields()[ix]->c_str());
- hdrValue = new char [sLen];
- std::strcpy (hdrValue, http_response->get_headers_values()[ix]->c_str());
- numChars = sprintf(msgPtr, "%s: %s\r\n", hdrField, hdrValue);
- delete hdrField;
- delete hdrValue;
- msgPtr += numChars;
- }
- numChars = sprintf(msgPtr, "\r\n");
- msgPtr += numChars;
- // print out generated header
- printf("[WiFi MAN] generated response header:\n");
- printf("%s\r\n", (char *)at_data_resp->buffer);
- // calculate header length
- at_data_resp->dataLen = (msgPtr - (char *)at_data_resp->buffer);
+ at_data_resp->dataLen = hdrLen;
return true;
}
@@ -829,6 +811,14 @@
void WiFiManager::body_callback(const char *at, uint32_t length) {
printf("\n Chunked response: Chunk %d : Total Bytes = %d\n", chunkNum , length);
chunkNum++;
+ if(http_response == NULL)
+ {
+ printf("[WIFI-MAN] response pointer NULL!!\r\n");
+ }
+ else
+ {
+ printf("[WIFI-MAN] response pointer NULL not!!\r\n");
+ }
sendResponseDownloadData(AT_HTTPS_RESP_DOWNLOAD, (uint8_t *)at, length);
}
@@ -1021,6 +1011,7 @@
}
//_wmutex.lock();
http_response = https_request->send(http_req_cfg->body, bodyLen);
+ //https_request->send(http_req_cfg->body, bodyLen);
//_wmutex.unlock();
}
#else
--- a/source/WiFiManager.h Mon Apr 22 19:36:31 2019 +0000
+++ b/source/WiFiManager.h Wed Apr 24 17:34:17 2019 +0000
@@ -106,7 +106,7 @@
int bufLen);
bool createTLSconnection(const char *hostName);
void printBufferInHex(uint8_t *buf, int pLen);
- bool copyResponseHdr2Queue();
+ bool copyResponseHdr2Queue(const uint8_t * buf);
void sendATresponseString(at_cmd_resp_t);
void sendATresponseBytes(at_cmd_resp_t at_cmd, int len);
void getNetworkStatus();
--- a/source/common_config.h Mon Apr 22 19:36:31 2019 +0000
+++ b/source/common_config.h Wed Apr 24 17:34:17 2019 +0000
@@ -35,6 +35,10 @@
#define BTLE_PEER_HANDLE 0x01
#define DEFAULT_LOCAL_PORT 0
#define PQDSZ 2 // size of Pool/Queue data structures
+#define MAX_HTTP_HDR_LEN 512
+#define HTTP_HEADER_START_LINE "HTTP/1.1 "
+#define HTTP_HEADER_CONTENT_TYPE "Content-Type:"
+#define HTTP_HEADER_CONTENT_LEN "Content-Length:"
typedef enum
{