Skip to content

Commit bdbb9d5

Browse files
committed
Use +UUSORD URC to determine GSMClient::available
1 parent 92dd9fe commit bdbb9d5

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

src/GSMClient.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ GSMClient::GSMClient(int socket, bool synch) :
4545
_port(0),
4646
_ssl(false),
4747
_writeSync(true),
48-
_peek(-1)
48+
_peek(-1),
49+
_available(0)
4950
{
50-
MODEM.addUrcHandler(this);
51+
MODEM.addUrcHandler(this);
5152
}
5253

5354
GSMClient::~GSMClient()
@@ -363,6 +364,9 @@ int GSMClient::read(uint8_t *buf, size_t size)
363364
buf[i] = (n1 << 4) | n2;
364365
}
365366

367+
_available = 0;
368+
MODEM.poll();
369+
366370
return size;
367371
}
368372

@@ -395,24 +399,9 @@ int GSMClient::available()
395399
return 0;
396400
}
397401

398-
String response;
399-
400-
MODEM.sendf("AT+USORD=%d,0", _socket, 0);
401-
if (MODEM.waitForResponse(10000, &response) == 1) {
402-
if (response.startsWith("+USORD: ")) {
403-
int commaIndex = response.indexOf(',');
404-
405-
if (commaIndex != -1) {
406-
response.remove(0, commaIndex + 1);
407-
408-
return response.toInt();
409-
}
410-
}
411-
} else {
412-
_socket = -1;
413-
}
402+
MODEM.poll();
414403

415-
return 0;
404+
return _available;
416405
}
417406

418407
int GSMClient::peek()
@@ -448,14 +437,23 @@ void GSMClient::handleUrc(const String& urc)
448437
if (socket == _socket) {
449438
// this socket closed
450439
_socket = -1;
440+
_available = 0;
451441
}
452-
} else if (urc.startsWith("+UUSORD: ") && urc.endsWith(",4294967295")) {
453-
// SSL disconnect
442+
} else if (urc.startsWith("+UUSORD: ")) {
454443
int socket = urc.charAt(9) - '0';
455444

456445
if (socket == _socket) {
457-
// this socket closed
458-
_socket = -1;
446+
if (urc.endsWith(",4294967295")) {
447+
// SSL disconnect
448+
// this socket closed
449+
_socket = -1;
450+
_available = 0;
451+
} else {
452+
int commaIndex = urc.indexOf(',');
453+
if (commaIndex != -1) {
454+
_available = urc.substring(commaIndex + 1).toInt();
455+
}
456+
}
459457
}
460458
}
461459
}

src/GSMClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include "Modem.h"
2626

27-
2827
class GSMClient : public Client, public ModemUrcHandler {
2928

3029
public:
@@ -146,6 +145,7 @@ class GSMClient : public Client, public ModemUrcHandler {
146145
bool _writeSync;
147146
String _response;
148147
int _peek;
148+
int _available;
149149
};
150150

151151
#endif

0 commit comments

Comments
 (0)