From d8c30c36d4210ae67f864313aef966b30e194732 Mon Sep 17 00:00:00 2001 From: bobh66 Date: Thu, 26 Dec 2013 15:02:59 -0600 Subject: [PATCH] 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. --- libraries/Bridge/src/FileIO.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/Bridge/src/FileIO.cpp b/libraries/Bridge/src/FileIO.cpp index 437ae2241..99a4c798c 100644 --- a/libraries/Bridge/src/FileIO.cpp +++ b/libraries/Bridge/src/FileIO.cpp @@ -119,12 +119,15 @@ void File::doBuffer() { // Try to buffer up to BUFFER_SIZE characters readPos = 0; 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 - if (buffered > 0) { - // Shift the reminder of buffer - for (uint8_t i = 0; i < buffered; i++) - buffer[i] = buffer[i + 1]; + if (BridgeClass::TRANSFER_TIMEOUT == buffered || 0 == buffered) { + // transfer failed to retrieve any data + buffered = 0; + } else { + // transfer retrieved at least one byte of data so skip the error code character + readPos++; + buffered--; } }