This library controls the WNC. There is a derived class for usage from the K64F board.
Fork of WncControllerLibrary by
Revision 12:33290e9e6e5f, committed 2016-09-10
- Comitter:
- fkellermavnet
- Date:
- Sat Sep 10 00:49:34 2016 +0000
- Parent:
- 11:3ff6c1cb5b03
- Child:
- 13:73629a6e9122
- Commit message:
- Cleaned up the read loops a bit.
Changed in this revision
| WncController.cpp | Show annotated file Show diff for this revision Revisions of this file |
| WncController.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/WncController.cpp Fri Sep 09 23:58:12 2016 +0000
+++ b/WncController.cpp Sat Sep 10 00:49:34 2016 +0000
@@ -529,7 +529,7 @@
uint8_t i = m_sSock[numSock].readRetries;
uint16_t to = m_sSock[numSock].readRetryWaitMs;
bool foundData = false;
- size_t numRead;
+ uint16_t numRead;
do {
AtCmdErr_e cmdRes;
if (maxReadBufLen < MAX_WNC_READ_BYTES)
@@ -1482,39 +1482,36 @@
// Experimental: read should not need to check cell net status
result = at_send_wnc_cmd(cmd_str.c_str(), &pRespStr, m_sCmdTimeoutMs);
if (result == WNC_AT_CMD_OK) {
- pos_start = pRespStr->find("\"") + 1;
- pos_end = pRespStr->rfind("\"") - 1;
-
+ pos_start = pRespStr->find("\"");
+ pos_end = pRespStr->rfind("\"");
// Make sure search finds what it's looking for!
- if (pos_start != string::npos && pos_end != string::npos)
- i = (pos_end - pos_start + 1); // Num hex chars, 2 per byte
+ if (pos_start != string::npos && pos_end != string::npos) {
+ pos_start++;
+ i = pos_end - pos_start; // Num hex chars, 2 per byte
+ }
else
i = 0;
- if (i < 0)
+ if ((i < 0) || ((i % 2) == 1))
dbgPuts("Invalid READ string!");
- else if (i > 2*MAX_WNC_READ_BYTES) {
- // Bound the ill formated WNC read string!
+
+ if (i > 2*MAX_WNC_READ_BYTES) {
i = 2*MAX_WNC_READ_BYTES;
- dbgPuts("TRUNCATING read data!");
+ dbgPuts("DANGER WNC read data does not match length!");
}
// If data, convert the hex string into byte values
- if (i > 0)
- {
- string byte;
- while (pos_start < pos_end) {
- byte = pRespStr->substr(pos_start, 2);
- *pS += (uint8_t)strtol(byte.c_str(), NULL, 16);
- pos_start += 2;
- }
+ while (i > 0) {
+ i -= 2;
+ *pS += (uint8_t)strtol(pRespStr->substr(pos_start, 2).c_str(), NULL, 16);
+ pos_start += 2;
}
}
return (result);
}
-WncController::AtCmdErr_e WncController::at_sockread_wnc(uint8_t * pS, uint32_t * numRead, uint16_t n, uint16_t numSock, bool isTcp)
+WncController::AtCmdErr_e WncController::at_sockread_wnc(uint8_t * pS, uint16_t * numRead, uint16_t n, uint16_t numSock, bool isTcp)
{
AtCmdErr_e result = WNC_AT_CMD_OK;
*numRead = 0;
@@ -1537,33 +1534,31 @@
// Experimental: read should not need to check cell net status
result = at_send_wnc_cmd(cmd_str.c_str(), &pRespStr, m_sCmdTimeoutMs);
if (result == WNC_AT_CMD_OK) {
- pos_start = pRespStr->find("\"") + 1;
- pos_end = pRespStr->rfind("\"") - 1;
-
+ pos_start = pRespStr->find("\"");
+ pos_end = pRespStr->rfind("\"");
// Make sure search finds what it's looking for!
- if (pos_start != string::npos && pos_end != string::npos)
- i = (pos_end - pos_start + 1); // Num hex chars, 2 per byte
+ if (pos_start != string::npos && pos_end != string::npos) {
+ pos_start++;
+ i = pos_end - pos_start; // Num hex chars, 2 per byte
+ }
else
i = 0;
- if (i < 0)
+ if ((i < 0) || ((i % 2) == 1))
dbgPuts("Invalid READ string!");
- else if (i > 2*n) {
+
+ if (i > 2*n) {
// Bound the ill formated WNC read string!
i = 2*n;
dbgPuts("TRUNCATING read data!");
}
// If data, convert the hex string into byte values
- if (i > 0)
- {
- string byte;
- while (pos_start < pos_end) {
- byte = pRespStr->substr(pos_start, 2);
- *pS++ = (uint8_t)strtol(byte.c_str(), NULL, 16);
- pos_start += 2;
- (*numRead)++;
- }
+ *numRead = i / 2;
+ while (i > 0) {
+ i -= 2;
+ *pS++ = (uint8_t)strtol(pRespStr->substr(pos_start, 2).c_str(), NULL, 16);
+ pos_start += 2;
}
}
}
--- a/WncController.h Fri Sep 09 23:58:12 2016 +0000
+++ b/WncController.h Sat Sep 10 00:49:34 2016 +0000
@@ -353,7 +353,7 @@
bool at_sockclose_wnc(uint16_t numSock);
bool at_dnsresolve_wnc(const char * s, string * ipStr);
AtCmdErr_e at_sockwrite_wnc(const char * s, uint32_t n, uint16_t numSock, bool isTcp);
- AtCmdErr_e at_sockread_wnc(uint8_t * pS, uint32_t * numRead, uint16_t n, uint16_t numSock, bool isTcp);
+ AtCmdErr_e at_sockread_wnc(uint8_t * pS, uint16_t * numRead, uint16_t n, uint16_t numSock, bool isTcp);
AtCmdErr_e at_sockread_wnc(string * pS, uint16_t numSock, bool isTcp);
bool at_reinitialize_mdm(void);
AtCmdErr_e at_send_wnc_cmd(const char * s, string ** r, int ms_timeout);
