Skip to content

Commit f0ce153

Browse files
committed
Chunk GSMClient::write(buffer, size) into 256 byte pieces
1 parent 2b8b968 commit f0ce153

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

src/GSMClient.cpp

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -246,39 +246,49 @@ size_t GSMClient::write(const uint8_t* buf, size_t size)
246246
return 0;
247247
}
248248

249-
if (size > 512) {
250-
size = 512;
251-
}
252-
249+
size_t written = 0;
253250
String command;
254-
command.reserve(19 + size * 2);
255251

256-
command += "AT+USOWR=";
257-
command += _socket;
258-
command += ",";
259-
command += size;
260-
command += ",\"";
261252

262-
for (size_t i = 0; i < size; i++) {
263-
byte b = buf[i];
253+
while (size) {
254+
size_t chunkSize = size;
264255

265-
byte n1 = (b >> 4) & 0x0f;
266-
byte n2 = (b & 0x0f);
256+
if (chunkSize > 256) {
257+
chunkSize = 256;
258+
}
267259

268-
command += (char)(n1 > 9 ? 'A' + n1 - 10 : '0' + n1);
269-
command += (char)(n2 > 9 ? 'A' + n2 - 10 : '0' + n2);
270-
}
260+
command.reserve(19 + chunkSize * 2);
271261

272-
command += "\"";
273-
274-
MODEM.send(command);
275-
if (_writeSync) {
276-
if (MODEM.waitForResponse(10000) != 1) {
277-
return 0;
262+
command += "AT+USOWR=";
263+
command += _socket;
264+
command += ",";
265+
command += chunkSize;
266+
command += ",\"";
267+
268+
for (size_t i = 0; i < chunkSize; i++) {
269+
byte b = buf[i + written];
270+
271+
byte n1 = (b >> 4) & 0x0f;
272+
byte n2 = (b & 0x0f);
273+
274+
command += (char)(n1 > 9 ? 'A' + n1 - 10 : '0' + n1);
275+
command += (char)(n2 > 9 ? 'A' + n2 - 10 : '0' + n2);
276+
}
277+
278+
command += "\"";
279+
280+
MODEM.send(command);
281+
if (_writeSync) {
282+
if (MODEM.waitForResponse(10000) != 1) {
283+
break;
284+
}
278285
}
286+
287+
written += chunkSize;
288+
size -= chunkSize;
279289
}
280290

281-
return size;
291+
return written;
282292
}
283293

284294
void GSMClient::endWrite(bool /*sync*/)

0 commit comments

Comments
 (0)