From ed7f0153f01d003648ae2b95ef2070ee37d5c703 Mon Sep 17 00:00:00 2001 From: preble Date: Sun, 28 Mar 2010 14:23:07 -0400 Subject: [PATCH] Improved error reporting. PRGetEvents() now returns -1 if an error occurred. --- include/pinproc.h | 4 +++- src/PRDevice.cpp | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/pinproc.h b/include/pinproc.h index 35dab09..4515098 100644 --- a/include/pinproc.h +++ b/include/pinproc.h @@ -280,7 +280,9 @@ typedef struct PREvent { uint32_t time; /**< Time (in milliseconds) that this event occurred. */ } PREvent; -/** Get all of the available events that have been received. */ +/** Get all of the available events that have been received. + * \return Number of events returned; -1 if an error occurred. + */ PR_EXPORT int PRGetEvents(PRHandle handle, PREvent *eventsOut, int maxEvents); diff --git a/src/PRDevice.cpp b/src/PRDevice.cpp index 15a6fbf..a7a3567 100644 --- a/src/PRDevice.cpp +++ b/src/PRDevice.cpp @@ -145,7 +145,8 @@ PRResult PRDevice::Reset(uint32_t resetFlags) int PRDevice::GetEvents(PREvent *events, int maxEvents) { - SortReturningData(); + if (SortReturningData() != kPRSuccess) + return -1; // The unrequestedDataQueue only has unrequested switch event data. Pop // events out 1 at a time, interpret them, and populate the outgoing list with them. @@ -657,7 +658,8 @@ PRResult PRDevice::SwitchGetStates( PREventType * switchStates, uint16_t numSwit while (requestedDataQueue.size() < numWords && i++ < 10) { PRSleep (10); // 10 milliseconds should be plenty of time. - SortReturningData(); + if (SortReturningData() != kPRSuccess) + return kPRFailure; } // Make sure all of the requested words are available before processing them. @@ -916,7 +918,8 @@ PRResult PRDevice::VerifyChipID() while (requestedDataQueue.size() < 5 && max_count++ < 10) { PRSleep (10); // 10 milliseconds should be plenty of time. - SortReturningData(); + if (SortReturningData() != kPRSuccess) + return kPRFailure; } if (max_count != 11) { @@ -1061,7 +1064,8 @@ PRResult PRDevice::ReadDataRaw(uint32_t moduleSelect, uint32_t startingAddr, int while (requestedDataQueue.size() < (numReadWords + 1) && i++ < 10) { PRSleep (10); // 10 milliseconds should be plenty of time. - SortReturningData(); + if (SortReturningData() != kPRSuccess) + return kPRFailure; } // Make sure all of the requested words are available before processing them. @@ -1134,6 +1138,8 @@ int32_t PRDevice::CollectReadData() { int32_t rc,i; rc = PRHardwareRead(collect_buffer, FTDI_BUFFER_SIZE-num_collected_bytes); + if (rc < 0) + return rc; for (i=0; i= 2) {