only in case of valid key do action. Issue#10585 and block very slow incoming signals

This commit is contained in:
sle 2021-01-17 11:39:21 +01:00
parent f52f26f566
commit ba12d8911e
1 changed files with 71 additions and 64 deletions

View File

@ -274,8 +274,15 @@ bool Wiegand::WiegandConversion ()
{ {
bool bRet = false; bool bRet = false;
unsigned long nowTick = millis(); unsigned long nowTick = millis();
if ((nowTick - lastFoundTime) > WIEGAND_BIT_TIMEOUT) //last bit found is WIEGAND_BIT_TIMEOUT ms ago //add a maximum wait time for new bits
{ unsigned long diffTicks = nowTick - lastFoundTime;
if ((diffTicks > WIEGAND_BIT_TIMEOUT) && (diffTicks >= 5000 )) { //max. 5 secs between 2 bits comming in
bitCount=0;
rfidBuffer=0;
lastFoundTime=nowTick;
return bRet;
}
if (diffTicks > WIEGAND_BIT_TIMEOUT) { //last bit found is WIEGAND_BIT_TIMEOUT ms ago
#if (DEV_WIEGAND_TEST_MODE)>0 #if (DEV_WIEGAND_TEST_MODE)>0
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: raw tag: %llu "), rfidBuffer); AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: raw tag: %llu "), rfidBuffer);
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bit count: %u "), bitCount); AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bit count: %u "), bitCount);
@ -363,20 +370,20 @@ void Wiegand::ScanForTag() {
#endif #endif
if (bitCount > 0) { if (bitCount > 0) {
uint64_t oldTag = rfid; uint64_t oldTag = rfid;
bool newKey = WiegandConversion(); bool validKey = WiegandConversion();
#if (DEV_WIEGAND_TEST_MODE)>0 #if (DEV_WIEGAND_TEST_MODE)>0
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: previous tag: %llu"), oldTag); AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: previous tag: %llu"), oldTag);
#endif #endif
if(newKey && (oldTag != rfid)) { // only in case of valid key do action. Issue#10585
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: new= %llu"), rfid); if(validKey) {
} if (oldTag != rfid) { AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: new= %llu"), rfid); }
else else { AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: prev= %llu"), rfid); }
{ AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: prev= %llu"), rfid);}
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bits= %u"), tagSize); AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bits= %u"), tagSize);
ResponseTime_P(PSTR(",\"Wiegand\":{\"UID\":\"%0llu\"}}"), rfid); ResponseTime_P(PSTR(",\"Wiegand\":{\"UID\":\"%0llu\"}}"), rfid);
MqttPublishTeleSensor(); MqttPublishTeleSensor();
} }
} }
}
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
void Wiegand::Show(void) { void Wiegand::Show(void) {