File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 23
23
24
24
GSMUDP::GSMUDP () :
25
25
_socket(-1 ),
26
+ _packetReceived(false ),
26
27
_txIp((uint32_t )0),
27
28
_txHost(NULL ),
28
29
_txPort(0 ),
@@ -32,6 +33,12 @@ GSMUDP::GSMUDP() :
32
33
_rxSize(0 ),
33
34
_rxIndex(0 )
34
35
{
36
+ MODEM.addUrcHandler (this );
37
+ }
38
+
39
+ GSMUDP::~GSMUDP ()
40
+ {
41
+ MODEM.removeUrcHandler (this );
35
42
}
36
43
37
44
uint8_t GSMUDP::begin (uint16_t port)
@@ -161,6 +168,13 @@ size_t GSMUDP::write(const uint8_t *buffer, size_t size)
161
168
162
169
int GSMUDP::parsePacket ()
163
170
{
171
+ MODEM.poll ();
172
+
173
+ if (!_packetReceived) {
174
+ return 0 ;
175
+ }
176
+ _packetReceived = false ;
177
+
164
178
String response;
165
179
166
180
MODEM.sendf (" AT+USORF=%d,%d" , _socket, sizeof (_rxBuffer));
@@ -218,6 +232,8 @@ int GSMUDP::parsePacket()
218
232
_rxBuffer[i] = (n1 << 4 ) | n2;
219
233
}
220
234
235
+ MODEM.poll ();
236
+
221
237
return _rxSize;
222
238
}
223
239
@@ -274,3 +290,14 @@ uint16_t GSMUDP::remotePort()
274
290
{
275
291
return _rxPort;
276
292
}
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
+ }
Original file line number Diff line number Diff line change 22
22
23
23
#include < Udp.h>
24
24
25
- class GSMUDP : public UDP {
25
+ #include " Modem.h"
26
+
27
+ class GSMUDP : public UDP , public ModemUrcHandler {
26
28
27
29
public:
28
30
GSMUDP (); // Constructor
31
+ virtual ~GSMUDP ();
32
+
29
33
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
30
34
virtual void stop (); // Finish with the UDP socket
31
35
@@ -69,8 +73,11 @@ class GSMUDP : public UDP {
69
73
// Return the port of the host who sent the current incoming packet
70
74
virtual uint16_t remotePort ();
71
75
76
+ virtual void handleUrc (const String& urc);
77
+
72
78
private:
73
79
int _socket;
80
+ bool _packetReceived;
74
81
75
82
IPAddress _txIp;
76
83
const char * _txHost;
You can’t perform that action at this time.
0 commit comments