mirror of https://github.com/arendst/Tasmota.git
only in case of valid key do action. Issue#10585 and block very slow incoming signals
This commit is contained in:
parent
f52f26f566
commit
ba12d8911e
|
@ -274,65 +274,72 @@ 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 (DEV_WIEGAND_TEST_MODE)>0
|
if ((diffTicks > WIEGAND_BIT_TIMEOUT) && (diffTicks >= 5000 )) { //max. 5 secs between 2 bits comming in
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: raw tag: %llu "), rfidBuffer);
|
bitCount=0;
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bit count: %u "), bitCount);
|
rfidBuffer=0;
|
||||||
#endif
|
lastFoundTime=nowTick;
|
||||||
if ((bitCount==4)||(bitCount==8)||(bitCount==24)||(bitCount==26)||(bitCount==32)||(bitCount==34)) {
|
return bRet;
|
||||||
if ((bitCount==24)||(bitCount==26)||(bitCount==32)||(bitCount==34)) {
|
}
|
||||||
// 24,26,32,34-bit Wiegand codes
|
if (diffTicks > WIEGAND_BIT_TIMEOUT) { //last bit found is WIEGAND_BIT_TIMEOUT ms ago
|
||||||
rfid = CheckAndConvertRfid( rfidBuffer, bitCount);
|
#if (DEV_WIEGAND_TEST_MODE)>0
|
||||||
tagSize=bitCount;
|
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: raw tag: %llu "), rfidBuffer);
|
||||||
bitCount=0;
|
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: bit count: %u "), bitCount);
|
||||||
rfidBuffer=0;
|
#endif
|
||||||
bRet=true;
|
if ((bitCount==4)||(bitCount==8)||(bitCount==24)||(bitCount==26)||(bitCount==32)||(bitCount==34)) {
|
||||||
}
|
if ((bitCount==24)||(bitCount==26)||(bitCount==32)||(bitCount==34)) {
|
||||||
if (bitCount==4) {
|
// 24,26,32,34-bit Wiegand codes
|
||||||
// 4-bit Wiegand codes for keypads
|
rfid = CheckAndConvertRfid( rfidBuffer, bitCount);
|
||||||
rfid = (int)translateEnterEscapeKeyPress(rfidBuffer & 0x0000000F);
|
tagSize=bitCount;
|
||||||
tagSize = bitCount;
|
bitCount=0;
|
||||||
bitCount = 0;
|
rfidBuffer=0;
|
||||||
rfidBuffer = 0;
|
bRet=true;
|
||||||
bRet=true;
|
}
|
||||||
}
|
if (bitCount==4) {
|
||||||
if (bitCount==8){
|
// 4-bit Wiegand codes for keypads
|
||||||
// 8-bit Wiegand codes for keypads with integrity
|
rfid = (int)translateEnterEscapeKeyPress(rfidBuffer & 0x0000000F);
|
||||||
// 8-bit Wiegand keyboard data, high nibble is the "NOT" of low nibble
|
tagSize = bitCount;
|
||||||
// eg if key 1 pressed, data=E1 in binary 11100001 , high nibble=1110 , low nibble = 0001
|
bitCount = 0;
|
||||||
char highNibble = (rfidBuffer & 0xf0) >>4;
|
rfidBuffer = 0;
|
||||||
char lowNibble = (rfidBuffer & 0x0f);
|
bRet=true;
|
||||||
if (lowNibble == (~highNibble & 0x0f)) // check if low nibble matches the "NOT" of high nibble.
|
}
|
||||||
{
|
if (bitCount==8){
|
||||||
rfid = (int)translateEnterEscapeKeyPress(lowNibble);
|
// 8-bit Wiegand codes for keypads with integrity
|
||||||
bRet=true;
|
// 8-bit Wiegand keyboard data, high nibble is the "NOT" of low nibble
|
||||||
}
|
// eg if key 1 pressed, data=E1 in binary 11100001 , high nibble=1110 , low nibble = 0001
|
||||||
else {
|
char highNibble = (rfidBuffer & 0xf0) >>4;
|
||||||
lastFoundTime=nowTick;
|
char lowNibble = (rfidBuffer & 0x0f);
|
||||||
bRet=false;
|
if (lowNibble == (~highNibble & 0x0f)) // check if low nibble matches the "NOT" of high nibble.
|
||||||
}
|
{
|
||||||
tagSize=bitCount;
|
rfid = (int)translateEnterEscapeKeyPress(lowNibble);
|
||||||
bitCount=0;
|
bRet=true;
|
||||||
rfidBuffer=0;
|
}
|
||||||
}
|
else {
|
||||||
}
|
lastFoundTime=nowTick;
|
||||||
else {
|
bRet=false;
|
||||||
// time reached but unknown bitCount, clear and start again
|
}
|
||||||
lastFoundTime=nowTick;
|
tagSize=bitCount;
|
||||||
bitCount=0;
|
bitCount=0;
|
||||||
rfidBuffer=0;
|
rfidBuffer=0;
|
||||||
bRet=false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
bRet=false; // watching time not finished
|
// time reached but unknown bitCount, clear and start again
|
||||||
|
lastFoundTime=nowTick;
|
||||||
|
bitCount=0;
|
||||||
|
rfidBuffer=0;
|
||||||
|
bRet=false;
|
||||||
}
|
}
|
||||||
#if (DEV_WIEGAND_TEST_MODE)>0
|
}
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: tag out: %llu "), rfid);
|
else{
|
||||||
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: tag size: %u"), tagSize);
|
bRet=false; // watching time not finished
|
||||||
#endif
|
}
|
||||||
return bRet;
|
#if (DEV_WIEGAND_TEST_MODE)>0
|
||||||
|
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: tag out: %llu "), rfid);
|
||||||
|
AddLog_P(LOG_LEVEL_INFO, PSTR("WIE: tag size: %u"), tagSize);
|
||||||
|
#endif
|
||||||
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Wiegand::ScanForTag() {
|
void Wiegand::ScanForTag() {
|
||||||
|
@ -363,19 +370,19 @@ 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
|
||||||
|
|
Loading…
Reference in New Issue