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.
Fork of WncControllerLibrary by
Diff: WncController.cpp
- Revision:
- 18:ca2899c353c2
- Parent:
- 17:59b1e9341188
- Child:
- 19:83a52353b97e
--- a/WncController.cpp Sat Sep 10 02:55:56 2016 +0000
+++ b/WncController.cpp Tue Sep 13 19:10:34 2016 +0000
@@ -207,10 +207,11 @@
if (sizeRespBuf > 0) {
AtCmdErr_e r = at_send_wnc_cmd(cmd, &respStr, ms_timeout);
- if (respStr->size() < sizeRespBuf) {
- strcpy(resp, respStr->c_str());
- return (respStr->size());
- }
+ strncpy(resp, respStr->c_str(), sizeRespBuf);
+ if (respStr->size() > sizeRespBuf)
+ dbgPuts("sendCustomCmd truncated!");
+
+ return (respStr->size());
}
dbgPuts("sendCustomCmd: would have overrun!");
@@ -855,6 +856,52 @@
} while (m_sSock[numSock].open == false);
}
+
+bool WncController::getICCID(string * iccid)
+{
+ string * respStr;
+
+ iccid->erase();
+
+ AtCmdErr_e r = at_send_wnc_cmd("AT%CCID", &respStr, m_sCmdTimeoutMs);
+
+ if (r != WNC_AT_CMD_OK || respStr->size() == 0)
+ return (false);
+
+ size_t pos = respStr->find("AT%CCID");
+ if (pos == string::npos)
+ return (false);
+
+ size_t posOK = respStr->rfind("OK");
+ if (posOK == string::npos)
+ return (false);
+
+ pos += 7; // Advanced to the number
+ *iccid = respStr->substr(pos, posOK - pos);
+
+ return (true);
+}
+
+bool WncController::convertICCIDtoMSISDN(const string & iccid, string * msisdn)
+{
+ msisdn->erase();
+
+ if (iccid.size() != 20 && iccid.size() != 19) {
+ dbgPuts("Invalid ICCID length!");
+ return (false);
+ }
+
+ *msisdn = "882350";
+
+ if (iccid.size() == 20)
+ *msisdn += iccid.substr(10,iccid.size() - 11);
+ else
+ *msisdn += iccid.substr(10,iccid.size() - 10);
+
+ return (true);
+}
+
+
bool WncController::sendSMSText(const char * const phoneNum, const char * const text)
{
if (at_sendSMStext_wnc(phoneNum, text) == true)
@@ -865,15 +912,113 @@
}
}
-size_t WncController::readSMSLog(const char ** log)
+bool WncController::readSMSLog(struct WncSmsList * log)
{
- size_t n;
+ string * logStr;
+ uint16_t i;
+
+ if (at_readSMSlog_wnc(&logStr) == false) {
+ dbgPuts("readSMSLog: Failed!");
+ return (false);
+ }
+
+ dbgPuts(logStr->c_str());
+
+ // Clean slate
+ log->msgCount = 0;
+
+ // Pick out the stuff from the string and convert to struct
+ string s;
+ size_t pos2;
+ size_t pos = logStr->find("+CMGL:");
- n = at_readSMSlog_wnc(log);
- if (n == 0)
- dbgPuts("readSMSLog: Failed!");
+ for(i=0; i<MAX_WNC_SMS_MSG_SLOTS; i++) {
+ if (pos == string::npos)
+ return (false);
+ pos = logStr->find(",\"");
+ if (pos == string::npos)
+ return (false);
+ pos += 3; // Advance to the text we want
+ pos2 = logStr->find("\",", pos);
+ if ((pos2 == string::npos) || (pos >= pos2))
+ return (false);
+
+ // Setup attributes
+ log->e[i].unread = false;
+ log->e[i].incoming = false;
+ log->e[i].unsent = false;
+
+ s = logStr->substr(pos, pos2 - pos);
+ if (s.find("READ") != string::npos)
+ log->e[i].incoming = true;
+ if (s.find("REC UNREAD") != string::npos)
+ log->e[i].unread = true;
+ if (s.find("STO UNSENT") != string::npos)
+ log->e[i].unsent = true;
+
+ // Tele number
+ pos2 += 3; // Advance to next field
+ pos = logStr->find("\",", pos2);
+ if ((pos == string::npos) || (pos2 > pos))
+ return (false);
+ if (pos == pos2)
+ log->e[i].number.erase();
+ 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
+ if ((pos2 == string::npos) || (pos > pos2))
+ return (false);
+ if (pos == pos2)
+ log->e[i].timestamp.erase();
+ else
+ log->e[i].timestamp = logStr->substr(pos, pos2 - pos);
- return (n);
+ // 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) {
+ dbgPuts("Strange SMS Log Ending!");
+ return (false);
+ }
+ i = MAX_WNC_SMS_MSG_SLOTS; // break
+ }
+ if (pos2 > pos)
+ return (false);
+ if (pos2 == pos)
+ log->e[log->msgCount].msg.erase();
+ else
+ log->e[log->msgCount].msg = logStr->substr(pos2, pos - pos2);
+
+ log->msgCount++; // Message complete
+ }
+
+ return (true);
+}
+
+bool WncController::readUnreadSMSText(struct WncSmsList * w)
+{
+ struct WncController::WncSmsList tmp;
+
+ if (readSMSLog(&tmp) == false)
+ return (false);
+
+ w->msgCount = 0;
+ for(uint16_t i = 0; i < tmp.msgCount; i++) {
+ if (tmp.e[i].unread == true) {
+ w->e[w->msgCount] = tmp.e[i];
+ w->msgCount++;
+ }
+ }
+
+ return (true);
}
size_t WncController::getSignalQuality(const char ** log)
@@ -998,17 +1143,6 @@
return (false);
}
-size_t WncController::readSMSText(const char n, const char ** msg)
-{
- size_t i;
-
- i = at_readSMStext_wnc(n,msg);
- if (i == 0)
- dbgPuts("readSMSText: Failed!");
-
- return (n);
-}
-
bool WncController::at_get_wnc_net_stats(WncIpStats * s)
{
string * pRespStr;
@@ -1243,7 +1377,7 @@
string * pRespStr;
size_t l = strlen(text);
- if (l <= MAX_WNC_SMS_LENGTH)
+ if (l <= MAX_WNC_SMS_MSG_SLOTS)
{
// Check to see if the SMS service is available
checkCellLink();
@@ -1331,20 +1465,9 @@
return (false);
}
-
-size_t WncController::at_readSMSlog_wnc(const char ** log)
+bool WncController::at_readSMSlog_wnc(string ** log)
{
- string * pRespStr;
- static string smsLogStr;
-
- smsLogStr.erase();
-
- if (at_send_wnc_cmd("AT+CMGL", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK)
- smsLogStr = *pRespStr;
-
- *log = smsLogStr.c_str();
-
- return (pRespStr->size());
+ return (at_send_wnc_cmd("AT+CMGL", log, m_sCmdTimeoutMs) == WNC_AT_CMD_OK);
}
size_t WncController::at_readSMStext_wnc(const char n, const char ** log)
