Skip to content

Commit

Permalink
Merge pull request #2 from cacke-r/fix_autothreshold
Browse files Browse the repository at this point in the history
Sniff15693: Autocalibrate: Detect error case
  • Loading branch information
cacke-r authored Feb 24, 2022
2 parents a212bbb + c47974e commit 14537ac
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions Firmware/Chameleon-Mini/Application/Sniff15693.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
{
Expand All @@ -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){
Expand Down

0 comments on commit 14537ac

Please sign in to comment.