Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ArduinoAPI
Fork of WeeESP8266 by
Revision 15:5c5a85e984a8, committed 2015-02-07
- Comitter:
- itead
- Date:
- Sat Feb 07 08:12:23 2015 +0000
- Parent:
- 14:6a9414577daa
- Child:
- 16:80c08e69c31a
- Commit message:
- Fixed bugs: receive data +IPD
Changed in this revision
--- a/ESP8266.cpp Sat Feb 07 06:52:18 2015 +0000
+++ b/ESP8266.cpp Sat Feb 07 08:12:23 2015 +0000
@@ -19,6 +19,7 @@
* THE SOFTWARE.
*/
#include "ESP8266.h"
+#include "log.h"
ESP8266::ESP8266(ArduinoSerial &uart): m_puart(&uart)
{
@@ -253,16 +254,17 @@
/*----------------------------------------------------------------------------*/
-uint32_t ESP8266::recvPkg(uint8_t *buffer, uint8_t buffer_size, uint32_t *data_len, uint32_t timeout, uint8_t *coming_mux_id)
+uint32_t ESP8266::recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_len, uint32_t timeout, uint8_t *coming_mux_id)
{
String data;
char a;
int32_t index_PIPDcomma = -1;
int32_t index_colon = -1; /* : */
int32_t index_comma = -1; /* , */
- int32_t len;
- int8_t id;
+ int32_t len = -1;
+ int8_t id = -1;
bool has_data = false;
+ logDebug("start recv pkg");
unsigned long start = millis();
while (millis() - start < timeout) {
@@ -273,30 +275,45 @@
index_PIPDcomma = data.indexOf("+IPD,");
if (index_PIPDcomma != -1) {
+ logDebug("index_PIPDcomma found = %d", index_PIPDcomma);
index_colon = data.indexOf(':', index_PIPDcomma + 5);
if (index_colon != -1) {
+ logDebug("data1 = %s\r\n", data.c_str());
+ logDebug("index_colon found = %d", index_colon);
+
index_comma = data.indexOf(',', index_PIPDcomma + 5);
- if (index_comma != -1) { /* +IPD,id,len:data */
+ logDebug("index_comma found = %d", index_comma);
+
+ if (index_comma != -1 && index_comma < index_colon) { /* +IPD,id,len:data */
+ logDebug("id = %d", id);
id = data.substring(index_PIPDcomma + 5, index_comma).toInt();
+ logDebug("id = %d", id);
if (id < 0 || id > 4) {
return 0;
}
+ logDebug("len = %d", len);
len = data.substring(index_comma + 1, index_colon).toInt();
+ logDebug("len = %d", len);
if (len <= 0) {
return 0;
}
-
+ logDebug("has id");
} else { /* +IPD,len:data */
len = data.substring(index_PIPDcomma + 5, index_colon).toInt();
+ logDebug("len = %d", len);
if (len <= 0) {
return 0;
}
+ logDebug("no id");
}
has_data = true;
+ logDebug("has_data true");
break;
}
}
}
+ //logDebug("has_data = %u\r\n", has_data);
+ //logDebug("data2 = %s\r\n", data.c_str());
if (has_data) {
start = millis();
@@ -305,6 +322,7 @@
a = m_puart->readChr();
data += a;
}
+ //logDebug("data3 = %s\r\n", data.c_str());
if (data.length() >= index_colon + 1 + len) {
if (data_len) {
*data_len = len;
@@ -312,15 +330,19 @@
if (index_comma != -1 && coming_mux_id) {
*coming_mux_id = id;
}
+ //logDebug("len = %d", len);
+ //logDebug("buffer_size = %d", buffer_size);
uint32_t ret = len > buffer_size ? buffer_size : len;
+
memcpy(buffer,
data.substring(index_colon + 1, index_colon + 1 + len).c_str(),
ret);
+ logDebug("ret = %u\r\n", ret);
return ret;
}
}
}
-
+ logDebug("end recv pkg");
return 0;
}
--- a/ESP8266.h Sat Feb 07 06:52:18 2015 +0000
+++ b/ESP8266.h Sat Feb 07 08:12:23 2015 +0000
@@ -374,7 +374,7 @@
* @param timeout - the duration waitting data comming.
* @param coming_mux_id - in single connection mode, should be NULL and not NULL in multiple.
*/
- uint32_t recvPkg(uint8_t *buffer, uint8_t buffer_size, uint32_t *data_len, uint32_t timeout, uint8_t *coming_mux_id);
+ uint32_t recvPkg(uint8_t *buffer, uint32_t buffer_size, uint32_t *data_len, uint32_t timeout, uint8_t *coming_mux_id);
bool eAT(void);
--- a/log.h Sat Feb 07 06:52:18 2015 +0000 +++ b/log.h Sat Feb 07 08:12:23 2015 +0000 @@ -6,8 +6,8 @@ #define LOG_OUTPUT_ERROR (1) #define LOG_OUTPUT_WARN (1) #define LOG_OUTPUT_INFO (1) -#define LOG_OUTPUT_DEBUG (1) -#define LOG_OUTPUT_VERBOSE (1) +#define LOG_OUTPUT_DEBUG (0) +#define LOG_OUTPUT_VERBOSE (0) #define LOG_OUTPUT_ERROR_PREFIX (1) #define LOG_OUTPUT_WARN_PREFIX (1)
