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 02:31:35 2016 +0000
Parent:
18:ca2899c353c2
Child:
20:ca2db38d6802
Commit message:
SMS seems work pretty good now.; main() has some debug in it that needs to be removed next time.

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	Tue Sep 13 19:10:34 2016 +0000
+++ b/WncController.cpp	Wed Sep 14 02:31:35 2016 +0000
@@ -859,6 +859,16 @@
 
 bool WncController::getICCID(string * iccid)
 {
+    if (at_geticcid_wnc(iccid) == false) {
+        dbgPuts("getICCID error!");
+        return (false);
+    }
+    
+    return (true);
+}
+
+bool WncController::at_geticcid_wnc(string * iccid)
+{
     string * respStr;
     
     iccid->erase();
@@ -882,6 +892,7 @@
     return (true);
 }
 
+
 bool WncController::convertICCIDtoMSISDN(const string & iccid, string * msisdn)
 {
     msisdn->erase();
@@ -933,12 +944,13 @@
     size_t pos = logStr->find("+CMGL:");
 
     for(i=0; i<MAX_WNC_SMS_MSG_SLOTS; i++) {
+        log->e[i].idx = logStr->at(pos + 7);
         if (pos == string::npos)
             return (false);
-        pos = logStr->find(",\"");
+        pos = logStr->find(",\"", pos);
         if (pos == string::npos)
             return (false);
-        pos += 3;  // Advance to the text we want
+        pos += 2;  // Advance to the text we want
         pos2 = logStr->find("\",", pos);
         if ((pos2 == string::npos) || (pos >= pos2))
             return (false);
@@ -949,10 +961,12 @@
         log->e[i].unsent = false;
         
         s = logStr->substr(pos, pos2 - pos);
-        if (s.find("READ") != string::npos)
+        if (s.find("REC READ") != string::npos)
             log->e[i].incoming = true;
-        if (s.find("REC UNREAD") != string::npos)
+        if (s.find("REC UNREAD") != string::npos) {
             log->e[i].unread = true;
+            log->e[i].incoming = true;
+        }
         if (s.find("STO UNSENT") != string::npos)
             log->e[i].unsent = true;
             
@@ -966,36 +980,47 @@
         else    
             log->e[i].number = logStr->substr(pos2, pos - pos2);
         
-        // Timestamp
-        pos = pos2 + 4; // Beginning of timestamp field
-        pos2 = logStr->find("\",", pos); // End of timestamp field
+
+        // Date
+        pos += 4; // Beginning of date field
+        pos2 = logStr->find(",", pos); // End of timestamp field
         if ((pos2 == string::npos) || (pos > pos2))
             return (false);
         if (pos == pos2)
-            log->e[i].timestamp.erase();
+            log->e[i].date.erase();
         else
-            log->e[i].timestamp = logStr->substr(pos, pos2 - pos);
+            log->e[i].date = logStr->substr(pos, pos2 - pos);
+
+        // Timestamp
+        pos2 += 1; // Beginning of time field
+        pos = logStr->find("\",", pos2); // End of timestamp field
+        if ((pos == string::npos) || (pos2 > pos))
+            return (false);
+        if (pos == pos2)
+            log->e[i].time.erase();
+        else
+            log->e[i].time = logStr->substr(pos2, pos - pos2);
         
         // Message field
         
         // We don't know how many messages we have so the next search
         // could end with +CMGL or OK.
-        pos2 += 2;  // Advanced to message text
-        pos = logStr->find("+CMGL", pos2);
-        if (pos == string::npos) {
-            pos = logStr->find("OK", pos2);
-            if (pos == string::npos) {
+        pos += 2;  // Advanced to message text
+        pos2 = logStr->find("+CMGL", pos);
+        if (pos2 == string::npos) {
+            pos2 = logStr->find("OK", pos);
+            if (pos2 == string::npos) {
                 dbgPuts("Strange SMS Log Ending!");
                 return (false);
             }
             i = MAX_WNC_SMS_MSG_SLOTS; // break
         }
-        if (pos2 > pos)
+        if (pos > pos2)
             return (false);
-        if (pos2 == pos)
+        if (pos == pos2)
             log->e[log->msgCount].msg.erase();
         else
-            log->e[log->msgCount].msg = logStr->substr(pos2, pos - pos2);
+            log->e[log->msgCount].msg = logStr->substr(pos, pos2 - pos);
 
         log->msgCount++;  // Message complete
     }    
@@ -1003,7 +1028,7 @@
     return (true);
 }
 
-bool WncController::readUnreadSMSText(struct WncSmsList * w)
+bool WncController::readUnreadSMSText(struct WncSmsList * w, bool deleteRead)
 {
     struct WncController::WncSmsList tmp;
     
@@ -1015,10 +1040,14 @@
         if (tmp.e[i].unread == true) {
             w->e[w->msgCount] = tmp.e[i];
             w->msgCount++;
+            if (deleteRead == true) {
+                // Clean up message that was copied out and read
+                deleteSMSTextFromMem(w->e[i].idx);
+            }
         }
     }
     
-    return (true);
+    return (w->msgCount > 0);
 }
 
 size_t WncController::getSignalQuality(const char ** log)
--- a/WncController.h	Tue Sep 13 19:10:34 2016 +0000
+++ b/WncController.h	Wed Sep 14 02:31:35 2016 +0000
@@ -262,8 +262,10 @@
     struct WncSmsInfo
     {
         // Content
+        char   idx;
         string number;
-        string timestamp;
+        string date;
+        string time;
         string msg;
         
         // Attributes
@@ -282,7 +284,7 @@
 
     bool readSMSLog(struct WncSmsList * log);
 
-    bool readUnreadSMSText(struct WncSmsList * w);
+    bool readUnreadSMSText(struct WncSmsList * w, bool deleteRead = true);
     
     bool saveSMSText(const char * const phoneNum, const char * const text, char * msgIdx);
     
@@ -393,6 +395,7 @@
     size_t at_getSignalQuality_wnc(const char ** log);
     bool at_gettimedate_wnc(struct WncDateTime * tod);
     bool at_ping_wnc(const char * ip);
+    bool at_geticcid_wnc(string * iccid);
 
     // Utility methods
     void sendCmd(const char * cmd, bool crLf);