1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2018 grauerfuchs
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // Weigand card format packing/unpacking support functions
9 //-----------------------------------------------------------------------------
11 #ifndef WIEGAND_FORMATUTILS_H__
12 #define WIEGAND_FORMATUTILS_H__
18 // Structure for packed wiegand messages
19 // Always align lowest value (last transmitted) bit to ordinal position 0 (lowest valued bit bottom)
21 uint8_t Length
; // Number of encoded bits in wiegand message (excluding headers and preamble)
22 uint32_t Top
; // Bits in x<<64 positions
23 uint32_t Mid
; // Bits in x<<32 positions
24 uint32_t Bot
; // Lowest ordinal positions
27 // Structure for unpacked wiegand card, like HID prox
29 uint32_t FacilityCode
;
33 bool ParityValid
; // Only valid for responses
36 uint8_t get_bit_by_position(wiegand_message_t
*data
, uint8_t pos
);
37 bool set_bit_by_position(wiegand_message_t
*data
, bool value
, uint8_t pos
);
39 uint64_t get_linear_field(wiegand_message_t
*data
, uint8_t firstBit
, uint8_t length
);
40 bool set_linear_field(wiegand_message_t
*data
, uint64_t value
, uint8_t firstBit
, uint8_t length
);
42 uint64_t get_nonlinear_field(wiegand_message_t
*data
, uint8_t numBits
, uint8_t *bits
);
43 bool set_nonlinear_field(wiegand_message_t
*data
, uint64_t value
, uint8_t numBits
, uint8_t *bits
);
45 wiegand_message_t
initialize_message_object(uint32_t top
, uint32_t mid
, uint32_t bot
, int n
);
47 bool add_HID_header(wiegand_message_t
*data
);