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:
- 21:086841abc3aa
- Parent:
- 20:ca2db38d6802
- Child:
- 23:aa2d716e234c
--- a/WncController.cpp Wed Sep 14 23:15:39 2016 +0000
+++ b/WncController.cpp Thu Sep 15 15:31:20 2016 +0000
@@ -198,7 +198,7 @@
m_sState = WNC_OFF;
}
- return (m_sState != WNC_ON_NO_CELL_LINK);
+ return ((m_sState == WNC_ON) || (m_sState == WNC_ON_NO_CELL_LINK));
}
size_t WncController::sendCustomCmd(const char * cmd, char * resp, size_t sizeRespBuf, int ms_timeout)
@@ -480,7 +480,7 @@
* \details DO NOT use the same string as is passed to the auto poll setup method!
*/
-int WncController::read(uint16_t numSock, const uint8_t ** readBuf)
+size_t 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) {
- int16_t i = m_sSock[numSock].readRetries;
+ uint8_t i = m_sSock[numSock].readRetries;
uint16_t to = m_sSock[numSock].readRetryWaitMs;
bool foundData = false;
do {
@@ -512,17 +512,13 @@
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) || (cmdRes == WNC_AT_CMD_ERRCME))
+ if (cmdRes == WNC_AT_CMD_ERREXT || cmdRes == WNC_AT_CMD_TIMEOUT)
{
// 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);
- // 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);
+ i = 0;
}
else
waitMs(to);
@@ -542,7 +538,7 @@
return (theBuf.size());
}
-int WncController::read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen)
+size_t WncController::read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen)
{
uint32_t numCopied = 0;
@@ -583,14 +579,13 @@
}
else {
dbgPuts("Sockread failed!");
- if ((cmdRes == WNC_AT_CMD_ERREXT) || (cmdRes == WNC_AT_CMD_TIMEOUT) || (cmdRes == WNC_AT_CMD_ERRCME))
+ if (cmdRes == WNC_AT_CMD_ERREXT || cmdRes == WNC_AT_CMD_TIMEOUT)
{
// 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);
- // Game over
- return (-1);
+ i = 0;
}
else
waitMs(to);
@@ -815,6 +810,13 @@
*r = &m_sWncStr; // Return a pointer to the static string
if (atResult != WNC_AT_CMD_TIMEOUT) {
+ // If a prior command timed out but a new one works then
+ // change the state back to ON. We don't know here in this
+ // method if the Cell Link is good so assume it is. When a command
+ // that depends on the cell link is made it will update the state.
+ if (m_sState == WNC_NO_RESPONSE)
+ m_sState = WNC_ON;
+
// Save some run-time!
if (m_sDebugEnabled)
{
@@ -835,6 +837,7 @@
}
}
else {
+ m_sState = WNC_NO_RESPONSE;
dbgPuts("AT Cmd TIMEOUT!");
dbgPuts("RX: ", false); dbgPutsNoTime(m_sWncStr.c_str());
}
@@ -2087,7 +2090,9 @@
dbgPuts("------------ WNC Ready ---------------->");
}
- m_sState = WNC_ON;
+ // If we made it this far and the WNC did respond, keep the ON state
+ if (m_sState != WNC_NO_RESPONSE)
+ m_sState = WNC_ON;
return (true);
}
