From c47974e44d5f7f6c4d3ab2672c4f20acf5f9d722 Mon Sep 17 00:00:00 2001 From: cacke-r Date: Wed, 23 Feb 2022 21:03:17 +0100 Subject: [PATCH] Sniff15693: Autocalibrate: Detect error case Detect the case, that we never receive a valid card frame. Restore original/recent threshold in this case. Signed-off-by: cacke-r --- .../Chameleon-Mini/Application/Sniff15693.c | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Firmware/Chameleon-Mini/Application/Sniff15693.c b/Firmware/Chameleon-Mini/Application/Sniff15693.c index cf4f87a3..db4e218a 100644 --- a/Firmware/Chameleon-Mini/Application/Sniff15693.c +++ b/Firmware/Chameleon-Mini/Application/Sniff15693.c @@ -61,10 +61,14 @@ static uint16_t max_th = 0xFFF; static uint16_t min_succ_th = 0; static uint16_t max_succ_th = 0xFFF; +/* to store the threshold which was used before we started AUTOCALIBRATION */ +static uint16_t recent_th = 0; + static bool last_cycle_successful = false; void SniffISO15693AppTimeout(void) { + CodecThresholdSet(recent_th); SniffISO15693AppReset(); } @@ -104,6 +108,10 @@ INLINE void SniffISO15693InitAutocalib(void){ min_succ_th = 0; max_succ_th = 0xFFF; + + /* store current threshold before we started AUTOCALIBRATION */ + recent_th = GlobalSettings.ActiveSettingPtr->ReaderThreshold; + last_cycle_successful = false; #ifdef ISO15693_DEBUG_LOG { @@ -119,18 +127,26 @@ INLINE void SniffISO15693InitAutocalib(void){ INLINE void SniffISO15693FinishAutocalib(void){ uint16_t new_th; - new_th = (min_succ_th + max_succ_th) >> 1; - CodecThresholdSet(new_th); + CommandStatusIdType ReturnStatusID = COMMAND_ERR_INVALID_USAGE_ID; + if(min_succ_th > 0) { + /* In this case AUTOCALIBRATION was successfull */ + new_th = (min_succ_th + max_succ_th) >> 1; + CodecThresholdSet(new_th); #ifdef ISO15693_DEBUG_LOG - { - char str[64]; - sprintf(str, "Sniff15693: Finished Autocalibration %d - %d --> % d", min_succ_th, max_succ_th, new_th); - LogEntry(LOG_INFO_GENERIC, str, strlen(str)); - } + { + char str[64]; + sprintf(str, "Sniff15693: Finished Autocalibration %d - %d --> % d", min_succ_th, max_succ_th, new_th); + LogEntry(LOG_INFO_GENERIC, str, strlen(str)); + } #endif /*#ifdef ISO15693_DEBUG_LOG*/ + ReturnStatusID = COMMAND_INFO_OK_WITH_TEXT_ID; + }else{ + /* This means we never received a valid frame - Error*/ + CodecThresholdSet(recent_th); + /* ReturnStatusID already set to error code */ + } SniffISO15693AppInit(); - CommandLinePendingTaskFinished(COMMAND_INFO_OK_WITH_TEXT_ID, NULL); - //CommandLinePendingTaskFinished(COMMAND_INFO_FALSE_ID, NULL); + CommandLinePendingTaskFinished(ReturnStatusID, NULL); } INLINE void SniffISO15693IncrementThreshold(void){