Skip to content

Commit 2c8ae76

Browse files
authored
Add LoRaWAN and Wi-SUN drivers (Merge pull request #16 from okrasolar/master)
2 parents 11cb19d + cfd5811 commit 2c8ae76

File tree

14 files changed

+696
-23
lines changed

14 files changed

+696
-23
lines changed

cicada/circularbuffer.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ template <typename T> class CircularBuffer
186186
return _bufferSize;
187187
}
188188

189+
/*!
190+
* Rewinds the read head.
191+
* Useful to re-read old data which has been pulled before.
192+
* \param num number of entries to rewind the read head
193+
*/
194+
virtual void rewindReadHead(Size num)
195+
{
196+
if (num <= _readHead) {
197+
_readHead -= num;
198+
} else {
199+
_readHead = _bufferSize + _readHead - num;
200+
}
201+
_availableData += num;
202+
}
203+
189204
private:
190205
Size _writeHead;
191206
Size _readHead;

cicada/commdevices/cc1352p7.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,14 @@ void CC1352P7CommDevice::run()
156156
}
157157

158158
// If a modem reset is pending, handle it
159-
if (_stateBooleans & RESET_PENDING) {
159+
if (_stateBooleans & RESET_PENDING && _bytesToWrite == 0) {
160160
_serial.flushReceiveBuffers();
161161
_bytesToRead = 0;
162162
_bytesToReceive = 0;
163-
_bytesToWrite = 0;
164163
_sendState = sendCipclose;
165164
_replyState = okReply;
166165
_waitForReply = NULL;
167166
_stateBooleans &= ~RESET_PENDING;
168-
if (_connectState >= intermediate) {
169-
connect();
170-
}
171167
}
172168

173169
// Buffer data from the modem
@@ -180,8 +176,7 @@ void CC1352P7CommDevice::run()
180176
logStates(_sendState, _replyState);
181177

182178
// Handle error states
183-
if (strncmp(_lineBuffer, "ERROR", 5) == 0
184-
|| (_sendState >= connected && strncmp(_lineBuffer, "SEND FAIL", 9) == 0)) {
179+
if (strncmp(_lineBuffer, "ERROR", 5) == 0 ) {
185180
_stateBooleans |= RESET_PENDING;
186181
_connectState = generalError;
187182
_waitForReply = NULL;
@@ -230,7 +225,8 @@ void CC1352P7CommDevice::run()
230225
if (strncmp(_lineBuffer, "+IPD,", 4) == 0) {
231226
_bytesToReceive = strtol(_lineBuffer + 5, NULL, 10);
232227
_stateBooleans |= DATA_PENDING;
233-
} else if (strncmp(_lineBuffer, "CLOSED", 6) == 0) {
228+
} else if (strncmp(_lineBuffer, "CLOSED", 6) == 0 ||
229+
strncmp(_lineBuffer, "SEND FAIL", 9) == 0) {
234230
_stateBooleans &= ~IP_CONNECTED;
235231
}
236232
}
@@ -274,6 +270,8 @@ void CC1352P7CommDevice::run()
274270
break;
275271

276272
case connecting:
273+
if (handleDisconnect(notConnected))
274+
break;
277275
_connectState = IPCommDevice::intermediate;
278276
_stateBooleans |= LINE_READ;
279277
_waitForReply = _okStr;

cicada/commdevices/espressif.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,7 @@ void EspressifDevice::run()
179179
// If a modem reset is pending, handle it
180180
if (_stateBooleans & RESET_PENDING) {
181181
_serial.flushReceiveBuffers();
182-
if (_sendState >= connecting && _sendState <= receiving
183-
&& !(_stateBooleans & DISCONNECT_PENDING)) {
184-
_sendState = connecting;
185-
} else {
186-
_sendState = notConnected;
187-
}
182+
_sendState = notConnected;
188183
_stateBooleans = LINE_READ;
189184
_bytesToRead = 0;
190185
_bytesToReceive = 0;
@@ -328,6 +323,8 @@ void EspressifDevice::run()
328323
break;
329324

330325
case connecting:
326+
if (handleDisconnect(notConnected))
327+
break;
331328
setDelay(10);
332329
_connectState = IPCommDevice::intermediate;
333330
_stateBooleans |= LINE_READ;

cicada/commdevices/espressif.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class EspressifDevice : public ATCommDevice
5555

5656
/*!
5757
* Set's the wifi network SSID.
58-
* \param ssid The network SSID
58+
* \param ssid The network SSID Note: The ssid is *not* copied, the string
59+
* needs to be valid during the lifetime of EspressifDevice object!
5960
*/
6061
virtual void setSSID(const char* ssid);
6162

cicada/commdevices/ipcommdevice.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ bool IPCommDevice::connect()
5959
if (_host == NULL || _port == 0)
6060
return false;
6161

62+
_stateBooleans &= ~DISCONNECT_PENDING;
6263
_stateBooleans |= CONNECT_PENDING;
6364

6465
return true;
@@ -69,6 +70,7 @@ void IPCommDevice::disconnect()
6970
if (isIdle())
7071
return;
7172

73+
_stateBooleans &= ~CONNECT_PENDING;
7274
_stateBooleans |= DISCONNECT_PENDING;
7375
}
7476

0 commit comments

Comments
 (0)