diff --git a/docs/source/Plugin/P008.rst b/docs/source/Plugin/P008.rst index a13e5f2b29..6393428317 100644 --- a/docs/source/Plugin/P008.rst +++ b/docs/source/Plugin/P008.rst @@ -1,4 +1,4 @@ -.. include:: ../Plugin/_plugin_substitutions_p00x.repl +.. include:: ../Plugin/_plugin_substitutions_p00x.repl .. _P008_page: |P008_typename| @@ -21,6 +21,18 @@ Maintainer: |P008_maintainer| Used libraries: |P008_usedlibraries| +Description +----------- + +The Wiegand plugin reads the Wiegand protocol, either the 26 or 34 bit variant, transmitted over a 2-wire serial connection. The RFID reader or keypad has to be connected to two GPIO pins on the ESP module. The plugin uses an interrupt routine to decode the bitstream. A RFID reader will send a message containing the unique RFID Tag ID. A keypad will send the input after pressing the #, or another configured, confirmation key. + +Data is transmitted in hexadecimal format. +For numeric keypads an option is provided to transform the hex value into a decimal representation, so that when entering value 1234# (# is the confirmation key here), not the result 4660 (0x1234) is made available, but actually 1234. This for easier processing/validating of the entered value. Any input of A-F is replaced by 0 when this option is enabled! It should not be enabled when using a RFID reader, as the Tag ID won't be correct. + +The value is placed in the Tag variable (this name can be changed). + +.. image:: P008_Settings.png + Supported hardware ------------------ diff --git a/docs/source/Plugin/P008_Settings.png b/docs/source/Plugin/P008_Settings.png new file mode 100644 index 0000000000..3f3671157d Binary files /dev/null and b/docs/source/Plugin/P008_Settings.png differ diff --git a/src/_P008_RFID.ino b/src/_P008_RFID.ino index 0f9045214f..d685eeb666 100644 --- a/src/_P008_RFID.ino +++ b/src/_P008_RFID.ino @@ -3,6 +3,16 @@ //################################# Plugin 008: Wiegand RFID Tag Reader ################################# //####################################################################################################### +/* +History: +2020-07-04 tonhuisman: Add checkbox for 'Present hex as decimal value' option (with note) so hexadecimal + value of f.e. a numeric keypad using the Wiegand protocol (hexadecimal data) will be cast to decimal. + When enabled entering 1234# will result in Tag = 1234 instead of 4660 (= 0x1234), any A-F + entered will result in a 0 in the output value. +------------- +No initial history available. +*/ + #include "_Plugin_Helper.h" #define PLUGIN_008 @@ -20,6 +30,26 @@ byte Plugin_008_WiegandSize = 26; // size of a tag via wiegand (26-bits boolean Plugin_008_init = false; +/** + * Convert/cast a hexadecimal input to a decimal representation, so 0x1234 (= 4660) comes out as 1234. + * + * //FIXME Move to a more global place to also be used elsewhere? + */ +uint64_t castHexAsDec(uint64_t hexValue) { + uint64_t result = 0; + uint8_t digit; + for (int i = 0; i < 8; i++) { + digit = (hexValue & 0x0000000F); + if (digit > 10) digit = 0; // Cast by dropping any non-decimal input + if (digit > 0) { // Avoid 'expensive' pow operation if not used + result += (digit * static_cast(pow(10, i))); + } + hexValue >>= 4; + if (hexValue == 0) break; // Stop when no more to process + } + return result; +} + boolean Plugin_008(byte function, struct EventStruct *event, String& string) { boolean success = false; @@ -125,6 +155,9 @@ boolean Plugin_008(byte function, struct EventStruct *event, String& string) unsigned long old_key = ((uint32_t) UserVar[event->BaseVarIndex]) | ((uint32_t) UserVar[event->BaseVarIndex + 1])<<16; bool new_key = false; + if (PCONFIG(1)) { + Plugin_008_keyBuffer = castHexAsDec(Plugin_008_keyBuffer); + } if (old_key != Plugin_008_keyBuffer) { UserVar[event->BaseVarIndex] = (Plugin_008_keyBuffer & 0xFFFF); @@ -152,6 +185,16 @@ boolean Plugin_008(byte function, struct EventStruct *event, String& string) if (new_key) sendData(event); setPluginTaskTimer(500, event->TaskIndex, event->Par1); + + // String info = ""; + // uint64_t invalue = 0x1234; + // uint64_t outvalue = castHexAsDec(invalue); + // info.reserve(40); + // info += F("Test castHexAsDec("); + // info += (double)invalue; + // info += F(") => "); + // info += (double)outvalue; + // addLog(LOG_LEVEL_INFO, info); } } break; @@ -166,14 +209,17 @@ boolean Plugin_008(byte function, struct EventStruct *event, String& string) optionValues[0] = 26; optionValues[1] = 34; addFormSelector(F("Wiegand Type"), F("p008_type"), 2, options, optionValues, choice); + bool presentHexToDec = PCONFIG(1); + addFormCheckBox(F("Present hex as decimal value"), F("p008_hexasdec"), presentHexToDec); + addFormNote(F("Useful only for numeric keypad input!")); success = true; break; } case PLUGIN_WEBFORM_SAVE: { - String plugin1 = web_server.arg(F("p008_type")); - PCONFIG(0) = plugin1.toInt(); + PCONFIG(0) = getFormItemInt(F("p008_type")); + PCONFIG(1) = getFormItemInt(F("p008_hexasdec")); success = true; break; }