219 size_t write(
const uint8_t* buffer,
size_t size)
221 uint8_t nextWriteSize;
222 uint16_t bytesWritten = 0;
223 uint32_t startTime = millis();
232 nextWriteSize = (uint8_t)size;
237 for (i = 0; i < nextWriteSize; ++i)
239 tx[4 + i] = buffer[i];
241 tx[3] = nextWriteSize;
243 int16_t sendResult = _sw.sendPacket(tx, rx);
246 return(bytesWritten);
248 bytesWritten += rx[3];
250 while ((size - bytesWritten) >= 7)
254 buffer[bytesWritten],
255 buffer[bytesWritten + 1],
256 buffer[bytesWritten + 2],
257 buffer[bytesWritten + 3],
258 buffer[bytesWritten + 4],
259 buffer[bytesWritten + 5],
260 buffer[bytesWritten + 6] };
263 int16_t sendResult = _sw.sendPacket(tx, rx);
266 return(bytesWritten);
268 bytesWritten += rx[3];
270 if (millis() > startTime + _timeout)
272 return(bytesWritten);
276 while (size - bytesWritten > 0)
279 if (size - bytesWritten >= 4)
285 nextWriteSize = (uint8_t)(size - bytesWritten);
290 for (i = 0; i < nextWriteSize; ++i)
292 tx[4 + i] = buffer[i + bytesWritten];
294 tx[3] = nextWriteSize;
296 int16_t sendResult = _sw.sendPacket(tx, rx);
299 return(bytesWritten);
301 bytesWritten += rx[3];
303 if (millis() > startTime + _timeout)
305 return(bytesWritten);
308 return (bytesWritten);
339 uint16_t bytesAvailable = 0;
340 uint32_t startTime = millis();
345 int16_t sendResult = _sw.sendPacket(tx, rx);
348 bytesAvailable = (rx[4] + 256 * rx[5]);
351 if (bytesAvailable <
length)
356 uint16_t bytesRead = 0;
357 while (bytesRead <
length)
360 uint8_t bytesToRead =(uint8_t)(
length - bytesRead);
367 int16_t sendResult = _sw.sendPacket(tx, rx);
371 for (i = 0; i < rx[1] && bytesRead <
length; ++i)
373 buffer[bytesRead] = rx[2 + i];
382 if (millis() > startTime + _timeout)
412 uint16_t bytesAvailable = 0;
416 int16_t sendResult = _sw.sendPacket(tx, rx);
419 bytesAvailable = (rx[4] + 256 * rx[5]);
421 uint16_t wordsAvailable = bytesAvailable /2;
422 if (wordsAvailable <
length)