This library controls the WNC. There is a derived class for usage from the K64F board.
Fork of WncControllerLibrary by
Revision 21:086841abc3aa, committed 2016-09-15
- Comitter:
- fkellermavnet
- Date:
- Thu Sep 15 15:31:20 2016 +0000
- Parent:
- 20:ca2db38d6802
- Child:
- 22:db78f3e0d782
- Commit message:
- Added a no response to the state of the WNC
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 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);
}
--- a/WncController.h Wed Sep 14 23:15:39 2016 +0000
+++ b/WncController.h Thu Sep 15 15:31:20 2016 +0000
@@ -72,7 +72,8 @@
enum WncState_e {
WNC_OFF = 0,
WNC_ON, // This is intended to mean all systems go, including cell link up but socket may not be open
- WNC_ON_NO_CELL_LINK
+ WNC_ON_NO_CELL_LINK,
+ WNC_NO_RESPONSE
};
/**
@@ -207,9 +208,9 @@
*
* \details DO NOT use the same string as is passed to the auto poll setup method!
*/
- int read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen);
+ size_t read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen);
- int read(uint16_t numSock, const uint8_t ** readBuf);
+ size_t read(uint16_t numSock, const uint8_t ** readBuf);
/**
* \brief Set how many times the above read method will retry if data is not returned.
