diff --git a/library.properties b/library.properties index 1f4202d..23ce5f4 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Blues Wireless Notecard -version=1.8.1 +version=1.8.2 author=Blues maintainer=Blues sentence=An easy to use Notecard Library for Arduino. diff --git a/src/NoteDefines.h b/src/NoteDefines.h index a6b138a..1ad17db 100644 --- a/src/NoteDefines.h +++ b/src/NoteDefines.h @@ -4,7 +4,7 @@ // Define the version of the `note-arduino` library #define NOTE_ARDUINO_VERSION_MAJOR 1 #define NOTE_ARDUINO_VERSION_MINOR 8 -#define NOTE_ARDUINO_VERSION_PATCH 1 +#define NOTE_ARDUINO_VERSION_PATCH 2 #define NOTE_ARDUINO_VERSION NOTE_C_STRINGIZE(NOTE_ARDUINO_VERSION_MAJOR) "." NOTE_C_STRINGIZE(NOTE_ARDUINO_VERSION_MINOR) "." NOTE_C_STRINGIZE(NOTE_ARDUINO_VERSION_PATCH) diff --git a/src/note-c/n_request.c b/src/note-c/n_request.c index e22fcac..c1e105b 100644 --- a/src/note-c/n_request.c +++ b/src/note-c/n_request.c @@ -116,7 +116,7 @@ void _noteSuspendTransactionDebug(void) */ NOTE_C_STATIC uint32_t _noteTransaction_calculateTimeoutMs(J *req, bool isReq) { - uint32_t result = (CARD_INTER_TRANSACTION_TIMEOUT_SEC * 1000); + uint32_t result = ((CARD_INTER_TRANSACTION_TIMEOUT_SEC - 1) * 1000); // Interrogate the request if (JContainsString(req, (isReq ? "req" : "cmd"), "note.add")) { @@ -137,13 +137,13 @@ NOTE_C_STATIC uint32_t _noteTransaction_calculateTimeoutMs(J *req, bool isReq) } else if (JIsPresent(req, "seconds")) { NOTE_C_LOG_DEBUG("Using `seconds` parameter value for timeout."); result = (JGetInt(req, "seconds") * 1000); - } else { - NOTE_C_LOG_DEBUG("No `milliseconds` or `seconds` parameter " - "provided. Defaulting to 90-second timeout."); - result = (90 * 1000); } } + // Add one second to the timeout, to provide time for the Notecard to + // timeout first, then report the timeout to the host, when applicable. + result += 1000; + return result; } @@ -436,9 +436,6 @@ J *_noteTransactionShouldLock(J *req, bool lockNotecard) // Serialize the JSON request char *json = JPrintUnformatted(req); // `json` allocated, must be freed if (json == NULL) { - if (lockNotecard) { - _UnlockNote(); - } _TransactionStop(); NOTE_C_LOG_ERROR(ERRSTR("failed to serialize JSON request", c_mem)); return NULL; @@ -492,28 +489,6 @@ J *_noteTransactionShouldLock(J *req, bool lockNotecard) } #endif - // If a reset of the I/O interface is required for any reason, do it now. - // We must do this before acquiring lock. - if (resetRequired) { - NOTE_C_LOG_DEBUG("Resetting Notecard I/O Interface..."); - if (!NoteReset()) { - _Free(json); - _TransactionStop(); - const char *errStr = ERRSTR("failed to reset Notecard interface {io}", c_iobad); - if (cmdFound) { - NOTE_C_LOG_ERROR(errStr); - return NULL; - } - return _errDoc(id, errStr); - } - } - - // Take the lock on the Notecard. This is required to ensure that we don't - // have multiple threads trying to access the Notecard at the same time. - if (lockNotecard) { - _LockNote(); - } - // Calculate the transaction timeout based on the parameters in the request. const uint32_t transactionTimeoutMs = _noteTransaction_calculateTimeoutMs(req, reqFound); @@ -547,6 +522,30 @@ J *_noteTransactionShouldLock(J *req, bool lockNotecard) } #endif // !NOTE_C_LOW_MEM + // Take the lock on the Notecard. This is required to ensure that we don't + // have multiple threads trying to access the Notecard at the same time. + if (lockNotecard) { + _LockNote(); + } + + // If a reset of the I/O interface is required for any reason, do it now. + if (resetRequired) { + NOTE_C_LOG_DEBUG("Resetting Notecard I/O Interface..."); + if ((resetRequired = !_Reset())) { + if (lockNotecard) { + _UnlockNote(); + } + _Free(json); + _TransactionStop(); + const char *errStr = ERRSTR("failed to reset Notecard interface {io}", c_iobad); + if (cmdFound) { + NOTE_C_LOG_ERROR(errStr); + return NULL; + } + return _errDoc(id, errStr); + } + } + // If we're performing retries, this is where we come back to // after a failed transaction. const char *errStr = NULL; diff --git a/src/note-c/note.h b/src/note-c/note.h index 143f59f..3960fa2 100644 --- a/src/note-c/note.h +++ b/src/note-c/note.h @@ -41,7 +41,7 @@ enum { #define NOTE_C_VERSION_MAJOR 2 #define NOTE_C_VERSION_MINOR 5 -#define NOTE_C_VERSION_PATCH 2 +#define NOTE_C_VERSION_PATCH 3 #define NOTE_C_VERSION NOTE_C_STRINGIZE(NOTE_C_VERSION_MAJOR) "." NOTE_C_STRINGIZE(NOTE_C_VERSION_MINOR) "." NOTE_C_STRINGIZE(NOTE_C_VERSION_PATCH)