Skip to content

Commit a47762d

Browse files
committed
Use + UUSORF URC to determine GSMUDP::parsePacket
1 parent 2fc0980 commit a47762d

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/GSMUdp.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
GSMUDP::GSMUDP() :
2525
_socket(-1),
26+
_packetReceived(false),
2627
_txIp((uint32_t)0),
2728
_txHost(NULL),
2829
_txPort(0),
@@ -32,6 +33,12 @@ GSMUDP::GSMUDP() :
3233
_rxSize(0),
3334
_rxIndex(0)
3435
{
36+
MODEM.addUrcHandler(this);
37+
}
38+
39+
GSMUDP::~GSMUDP()
40+
{
41+
MODEM.removeUrcHandler(this);
3542
}
3643

3744
uint8_t GSMUDP::begin(uint16_t port)
@@ -161,6 +168,13 @@ size_t GSMUDP::write(const uint8_t *buffer, size_t size)
161168

162169
int GSMUDP::parsePacket()
163170
{
171+
MODEM.poll();
172+
173+
if (!_packetReceived) {
174+
return 0;
175+
}
176+
_packetReceived = false;
177+
164178
String response;
165179

166180
MODEM.sendf("AT+USORF=%d,%d", _socket, sizeof(_rxBuffer));
@@ -218,6 +232,8 @@ int GSMUDP::parsePacket()
218232
_rxBuffer[i] = (n1 << 4) | n2;
219233
}
220234

235+
MODEM.poll();
236+
221237
return _rxSize;
222238
}
223239

@@ -274,3 +290,14 @@ uint16_t GSMUDP::remotePort()
274290
{
275291
return _rxPort;
276292
}
293+
294+
void GSMUDP::handleUrc(const String& urc)
295+
{
296+
if (urc.startsWith("+UUSORF: ")) {
297+
int socket = urc.charAt(9) - '0';
298+
299+
if (socket == _socket) {
300+
_packetReceived = true;
301+
}
302+
}
303+
}

src/GSMUdp.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222

2323
#include <Udp.h>
2424

25-
class GSMUDP : public UDP {
25+
#include "Modem.h"
26+
27+
class GSMUDP : public UDP, public ModemUrcHandler {
2628

2729
public:
2830
GSMUDP(); // Constructor
31+
virtual ~GSMUDP();
32+
2933
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
3034
virtual void stop(); // Finish with the UDP socket
3135

@@ -69,8 +73,11 @@ class GSMUDP : public UDP {
6973
// Return the port of the host who sent the current incoming packet
7074
virtual uint16_t remotePort();
7175

76+
virtual void handleUrc(const String& urc);
77+
7278
private:
7379
int _socket;
80+
bool _packetReceived;
7481

7582
IPAddress _txIp;
7683
const char* _txHost;

0 commit comments

Comments
 (0)