This library controls the WNC. There is a derived class for usage from the K64F board.

Fork of WncControllerLibrary by Fred Kellerman

Files at this revision

API Documentation at this revision

Comitter:
fkellermavnet
Date:
Wed Sep 14 23:15:39 2016 +0000
Parent:
19:83a52353b97e
Child:
21:086841abc3aa
Commit message:
Changed read to return -1 when WNC fails.

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	Wed Sep 14 02:31:35 2016 +0000
+++ b/WncController.cpp	Wed Sep 14 23:15:39 2016 +0000
@@ -480,7 +480,7 @@
  *  \details DO NOT use the same string as is passed to the auto poll setup method!
  */
  
-size_t WncController::read(uint16_t numSock, const uint8_t ** readBuf)
+int WncController::read(uint16_t numSock, const uint8_t ** readBuf)
 {
     static string theBuf;
     string readStr;
@@ -489,7 +489,7 @@
 
     if (numSock < MAX_NUM_WNC_SOCKETS) {
         if (m_sSock[numSock].open == true) {
-            uint8_t   i = m_sSock[numSock].readRetries;
+            int16_t   i = m_sSock[numSock].readRetries;
             uint16_t to = m_sSock[numSock].readRetryWaitMs;
             bool foundData = false;
             do {
@@ -512,13 +512,17 @@
                 else {
                     theBuf += readStr; // Append what if any we got before it errored.
                     dbgPuts("Sockread failed!");
-                    if (cmdRes == WNC_AT_CMD_ERREXT || cmdRes == WNC_AT_CMD_TIMEOUT)
+                    if ((cmdRes == WNC_AT_CMD_ERREXT) || (cmdRes == WNC_AT_CMD_TIMEOUT) || (cmdRes == WNC_AT_CMD_ERRCME))
                     {
                         // This may throw away any data that hasn't been read out of the WNC
                         //  but at this point with the way the WNC currently works we have
                         //  no choice.
                         closeOpenSocket(numSock);
-                        i = 0;
+                        // Free the memory that was used
+                        theBuf.erase();
+                        *readBuf = (const uint8_t *)theBuf.c_str();
+                        // Game over no more data left to pull out!
+                        return (-1);
                     }
                     else
                         waitMs(to);
@@ -538,7 +542,7 @@
     return (theBuf.size());
 }
 
-size_t WncController::read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen)
+int WncController::read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen)
 {
     uint32_t numCopied = 0;
     
@@ -579,13 +583,14 @@
                 }
                 else {
                     dbgPuts("Sockread failed!");
-                    if (cmdRes == WNC_AT_CMD_ERREXT || cmdRes == WNC_AT_CMD_TIMEOUT)
+                    if ((cmdRes == WNC_AT_CMD_ERREXT) || (cmdRes == WNC_AT_CMD_TIMEOUT) || (cmdRes == WNC_AT_CMD_ERRCME))
                     {
                         // This may throw away any data that hasn't been read out of the WNC
                         //  but at this point with the way the WNC currently works we have
                         //  no choice.
                         closeOpenSocket(numSock);
-                        i = 0;
+                        // Game over
+                        return (-1);
                     }
                     else
                         waitMs(to);
@@ -971,7 +976,10 @@
             log->e[i].unsent = true;
             
         // Tele number
-        pos2 += 3;  // Advance to next field
+        pos2 = logStr->find(",\"", pos2);
+        if (pos2 == string::npos)
+            return (false);  
+        pos2 += 2;  // Advance to next field
         pos = logStr->find("\",", pos2);
         if ((pos == string::npos) || (pos2 > pos))
             return (false);
@@ -982,7 +990,10 @@
         
 
         // Date
-        pos += 4; // Beginning of date field
+        pos = logStr->find(",\"", pos);
+        if (pos == string::npos)
+            return (false);
+        pos += 2; // Beginning of date field
         pos2 = logStr->find(",", pos); // End of timestamp field
         if ((pos2 == string::npos) || (pos > pos2))
             return (false);
@@ -992,7 +1003,10 @@
             log->e[i].date = logStr->substr(pos, pos2 - pos);
 
         // Timestamp
-        pos2 += 1; // Beginning of time field
+        pos2 = logStr->find(",\"");
+        if (pos2 == string::npos)
+            return (false);
+        pos2 += 2; // Beginning of time field
         pos = logStr->find("\",", pos2); // End of timestamp field
         if ((pos == string::npos) || (pos2 > pos))
             return (false);
@@ -1005,6 +1019,9 @@
         
         // We don't know how many messages we have so the next search
         // could end with +CMGL or OK.
+        pos = logStr->find(",\"", pos);
+        if (pos == string::npos)
+            return (false);
         pos += 2;  // Advanced to message text
         pos2 = logStr->find("+CMGL", pos);
         if (pos2 == string::npos) {
@@ -1406,7 +1423,7 @@
     string * pRespStr;
     size_t l = strlen(text);
     
-    if (l <= MAX_WNC_SMS_MSG_SLOTS)
+    if (l <= MAX_WNC_SMS_LENGTH)
     {
         // Check to see if the SMS service is available
         checkCellLink();
--- a/WncController.h	Wed Sep 14 02:31:35 2016 +0000
+++ b/WncController.h	Wed Sep 14 23:15:39 2016 +0000
@@ -207,9 +207,9 @@
      *
      *  \details DO NOT use the same string as is passed to the auto poll setup method!
      */
-    size_t read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen);
+    int read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen);
     
-    size_t read(uint16_t numSock, const uint8_t ** readBuf);
+    int read(uint16_t numSock, const uint8_t ** readBuf);
 
     /**
      *  \brief Set how many times the above read method will retry if data is not returned.
@@ -257,7 +257,7 @@
     ///////////////////////////////////////////
 
     static const uint16_t MAX_WNC_SMS_MSG_SLOTS = 3;   // How many SMS messages the WNC can store and receive at a time.
-    static const uint16_t MAX_WNC_SMS_LENGTH    = 160; // The maximum length of an SMS message the WNC can send and receive.
+    static const uint16_t MAX_WNC_SMS_LENGTH    = 160; // The maximum length of a 7-bit SMS message the WNC can send and receive.
     
     struct WncSmsInfo
     {