mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Add error handling and optimize FileIO::doBuffer() in the Bridge library
Update FileIO::doBuffer() to check for TRANSFER_TIMEOUT and set buffered to 0, and optimize by incrementing readPos instead of moving all of the data one byte to the left in the buffer to skip the error code byte.
This commit is contained in:
parent
660c7d86fd
commit
d8c30c36d4
@ -119,12 +119,15 @@ void File::doBuffer() {
|
|||||||
// Try to buffer up to BUFFER_SIZE characters
|
// Try to buffer up to BUFFER_SIZE characters
|
||||||
readPos = 0;
|
readPos = 0;
|
||||||
uint8_t cmd[] = {'G', handle, BUFFER_SIZE - 1};
|
uint8_t cmd[] = {'G', handle, BUFFER_SIZE - 1};
|
||||||
buffered = bridge.transfer(cmd, 3, buffer, BUFFER_SIZE) - 1;
|
buffered = bridge.transfer(cmd, 3, buffer, BUFFER_SIZE);
|
||||||
//err = buff[0]; // First byte is error code
|
//err = buff[0]; // First byte is error code
|
||||||
if (buffered > 0) {
|
if (BridgeClass::TRANSFER_TIMEOUT == buffered || 0 == buffered) {
|
||||||
// Shift the reminder of buffer
|
// transfer failed to retrieve any data
|
||||||
for (uint8_t i = 0; i < buffered; i++)
|
buffered = 0;
|
||||||
buffer[i] = buffer[i + 1];
|
} else {
|
||||||
|
// transfer retrieved at least one byte of data so skip the error code character
|
||||||
|
readPos++;
|
||||||
|
buffered--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user