This library controls the WNC. There is a derived class for usage from the K64F board.
Fork of WncControllerLibrary by
Revision 6:a656e820d7ff, committed 2016-09-08
- Comitter:
- fkellermavnet
- Date:
- Thu Sep 08 18:57:56 2016 +0000
- Parent:
- 5:20207cc5502e
- Child:
- 7:e6f22159ef23
- Commit message:
- Fixed write to stop looking for null and use the length.
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 06 19:11:14 2016 +0000
+++ b/WncController.cpp Thu Sep 08 18:57:56 2016 +0000
@@ -320,6 +320,11 @@
}
}
+void WncController::setWncCmdTimeout(uint16_t toMs)
+{
+ m_sCmdTimeoutMs = toMs;
+}
+
/**
* \brief Opens a WNC socket.
*
@@ -963,12 +968,12 @@
return (false);
}
-size_t WncController::readSMSText(const char ** log)
+size_t WncController::readSMSText(const char n, const char ** msg)
{
- size_t n;
+ size_t i;
- n = at_readSMStext_wnc(log);
- if (n == 0)
+ i = at_readSMStext_wnc(n,msg);
+ if (i == 0)
dbgPuts("readSMSText: Failed!");
return (n);
@@ -1173,7 +1178,6 @@
bool WncController::at_saveSMStext_wnc(const char * const phoneNum, const char * const text, char * msgIdx)
{
string respStr;
- string * pRespStr;
size_t l = strlen(text);
if (l <= MAX_WNC_SMS_LENGTH)
@@ -1181,8 +1185,6 @@
// Check to see if the SMS service is available
checkCellLink();
if (m_sReadyForSMS == true) {
- at_send_wnc_cmd("AT+CMGF=1", &pRespStr, m_sCmdTimeoutMs);
- at_send_wnc_cmd("AT+CPMS=\"SM\",\"SM\",\"SM\"", &pRespStr, m_sCmdTimeoutMs);
string cmdStr("AT+CMGW=\"");
cmdStr += phoneNum;
cmdStr += "\"";
@@ -1222,19 +1224,27 @@
size_t WncController::at_readSMSlog_wnc(const char ** log)
{
string * pRespStr;
+ static string smsLogStr;
+
+ smsLogStr.erase();
if (at_send_wnc_cmd("AT+CMGL", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK)
- *log = pRespStr->c_str();
- else
- *log = "\0";
+ smsLogStr = *pRespStr;
+ *log = smsLogStr.c_str();
+
return (pRespStr->size());
}
-size_t WncController::at_readSMStext_wnc(const char ** log)
+size_t WncController::at_readSMStext_wnc(const char n, const char ** log)
{
+ static string smsReadTxtStr;
string * pRespStr;
-
+ string cmdStr;
+
+ smsReadTxtStr.erase();
+ cmdStr = "AT+CMGR";
+ cmdStr += '1';
if (at_send_wnc_cmd("AT+CMGR", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK)
*log = pRespStr->c_str();
else
@@ -1267,6 +1277,11 @@
// Quick commands below do not need to check cellular connectivity
at_send_wnc_cmd("ATE0", &pRespStr, WNC_QUICK_CMD_TIMEOUT_MS); // Echo Off
at_send_wnc_cmd("AT+CMEE=2", &pRespStr, m_sCmdTimeoutMs); // 2 - verbose error, 1 - numeric error, 0 - just ERROR
+
+ // Setup 3 memory slots in the WNC SIM for SMS usage.
+ at_send_wnc_cmd("AT+CMGF=1", &pRespStr, m_sCmdTimeoutMs);
+ at_send_wnc_cmd("AT+CPMS=\"SM\",\"SM\",\"SM\"", &pRespStr, m_sCmdTimeoutMs);
+
cmdRes = at_send_wnc_cmd("AT", &pRespStr, WNC_QUICK_CMD_TIMEOUT_MS); // Heartbeat?
// If the simple commands are not working, no chance of more complex.
@@ -1401,9 +1416,9 @@
cmd_str += _to_string(numSock + 1);
cmd_str += ",";
cmd_str += _to_string(n);
- cmd_str += num2str;
cmd_str += ",\"";
- while(*s != '\0') {
+ while(n > 0) {
+ n--;
num2str = _to_hex_string((uint8_t)*s++);
// Always 2-digit ascii hex:
if (strlen(num2str) == 1)
--- a/WncController.h Tue Sep 06 19:11:14 2016 +0000
+++ b/WncController.h Thu Sep 08 18:57:56 2016 +0000
@@ -47,6 +47,13 @@
static const uint8_t MAX_LEN_IP_STR = 16; // Length includes room for the extra NULL
+static const uint16_t WNC_MAX_SMS_MSG_SLOTS = 3; // How many SMS messages the WNC can store and receive at a time.
+
+struct WncSmsInfo
+{
+ char idx[WNC_MAX_SMS_MSG_SLOTS];
+ string msgText[WNC_MAX_SMS_MSG_SLOTS];
+};
/**
@@ -252,10 +259,8 @@
*/
bool closeSocket(uint16_t numSock);
- void setWncCmdTimeout(uint16_t toMs) {
- m_sCmdTimeoutMs = toMs;
- };
-
+ void setWncCmdTimeout(uint16_t toMs);
+
bool getIpAddr(uint16_t numSock, char myIpAddr[MAX_LEN_IP_STR]);
void enableDebug(bool on, bool moreDebugOn);
@@ -274,7 +279,9 @@
bool deleteSMSTextFromMem(char msgIdx);
- size_t readSMSText(const char ** log);
+ size_t readSMSText(const char n, const char ** msg);
+
+ bool readUnreadSMSText(WncSmsInfo * w);
///////////////////////////////////////////
// Neighborhood Cell Info
@@ -355,6 +362,7 @@
bool at_get_wnc_net_stats(WncIpStats * s);
size_t at_readSMSlog_wnc(const char ** log);
size_t at_readSMStext_wnc(const char ** log);
+ size_t at_readSMStext_wnc(const char n, const char ** log);
bool at_getrssiber_wnc(int16_t * dBm, int16_t * ber3g);
void closeOpenSocket(uint16_t numSock);
bool sockWrite(const char * const s, uint32_t n, uint16_t numSock, bool isTcp);
@@ -373,21 +381,21 @@
}
// Important constants
- static const uint16_t MAX_WNC_READ_BYTES = 1500; // This bounds the largest amount of data that the WNC read from a socket will return, careful here large chunks come out of the heap
- static const uint16_t MAX_WNC_WRITE_BYTES = MAX_WNC_READ_BYTES;
- static const uint16_t MAX_LEN_WNC_CMD_RESPONSE = (MAX_WNC_READ_BYTES * 2 + 100); // Max number of text characters in a WNC AT response
- static const uint16_t WNC_AUTO_POLL_MS = 250; // Sets default (may be overriden with method) poll interval
- static const uint16_t WNC_CMD_TIMEOUT_MS = 40000; // Sets default (may be overriden) time that the software waits for an AT response from the WNC
- static const uint16_t WNC_QUICK_CMD_TIMEOUT_MS = 2000; // Used for simple commands that should immediately respond such as "AT"
- static const uint16_t WNC_WAIT_FOR_AT_CMD_MS = 0; // 40; // Wait this much between AT commands, this is what WNC advises (they said 20mS, I added margin).
- static const uint16_t MAX_WNC_SMS_LENGTH = 150;
- static const uint16_t WNC_SOFT_INIT_RETRY_COUNT = 10;
- static const uint16_t WNC_DNS_RESOLVE_WAIT_MS = 60000;
- static const uint16_t WNC_TRUNC_DEBUG_LENGTH = 80; // Always make this an even number
- static const uint16_t WNC_APNSET_TIMEOUT_MS = 60000;
- static const uint16_t WNC_PING_CMD_TIMEOUT_MS = 60000; // Amount of time to wait for AT@PINGREQ with default params to timeout
- static const int WNC_REINIT_MAX_TIME_MS = 60000;
- static const char * const INVALID_IP_STR;
+ static const uint16_t MAX_WNC_READ_BYTES = 1500; // This bounds the largest amount of data that the WNC read from a socket will return
+ static const uint16_t MAX_WNC_WRITE_BYTES = MAX_WNC_READ_BYTES; // This is the largest amount of data that the WNC can write per sockwrite.
+ static const uint16_t MAX_LEN_WNC_CMD_RESPONSE = (MAX_WNC_READ_BYTES * 2 + 100); // Max number of text characters in a WNC AT response *2 because bytes are converted into 2 hex-digits +100 for other AT@ chars.
+ static const uint16_t WNC_AUTO_POLL_MS = 250; // Sets default (may be overriden with method) poll interval (currently not used, future possible feature.
+ static const uint16_t WNC_CMD_TIMEOUT_MS = 40000; // Sets default (may be overriden) time that the software waits for an AT response from the WNC.
+ static const uint16_t WNC_QUICK_CMD_TIMEOUT_MS = 2000; // Used for simple commands that should immediately respond such as "AT", cmds that are quicker than WNC_CMD_TIMEOUT_MS.
+ static const uint16_t WNC_WAIT_FOR_AT_CMD_MS = 0; // Wait this much between multiple in a row AT commands to the WNC.
+ static const uint16_t MAX_WNC_SMS_LENGTH = 150; // The maximum length of an SMS message the WNC can send and receive.
+ static const uint16_t WNC_SOFT_INIT_RETRY_COUNT = 10; // How many times the WNC will be tried to revive if it stops responding.
+ static const uint16_t WNC_DNS_RESOLVE_WAIT_MS = 60000; // How much time to wait for the WNC to respond to a DNS resolve/lookup.
+ static const uint16_t WNC_TRUNC_DEBUG_LENGTH = 80; // Always make this an even number, how many chars for the debug output before shortening the debug ouput, this is used when moreDebug = false.
+ static const uint16_t WNC_APNSET_TIMEOUT_MS = 60000; // How long to wait for the WNC to respond to setting the APN string.
+ static const uint16_t WNC_PING_CMD_TIMEOUT_MS = 60000; // Amount of time to wait for the WNC to respond to AT@PINGREQ (with cmd default params for timeout, does not change WNC cmd's timeout)
+ static const int WNC_REINIT_MAX_TIME_MS = 60000; // How long to wait for the WNC to reset after it was already up and running after power-up.
+ static const char * const INVALID_IP_STR; // Just a string set to an IP address when DNS resolve fails.
struct WncSocketInfo_s {
bool open;
