View Source Wiegand (wiegand v0.1.0)

Encodes and decodes various formats of Wiegand card data.

Most formats contain a facility code (though this is sometimes omitted) and a card/cardholder ID. Many formats provide provide error checking via parity bits. Even parity is calculated over the n-most-significant bits, and odd parity is calculated over the n-least-significant bits.

assumptions

Assumptions

This package does not currently support every type of Wiegand card format. For simplicity's sake, it currently makes the following assumptions:

  • The even parity bit, if present, is the most-significant bit
  • The facility code, if present, immediately follows the even parity bit
  • The card/cardholder ID immediately follows the facility code
  • The odd parity bit, if present, is the least-significant bit
  • Parity checking is the only type of error checking supported

Link to this section Summary

Functions

Encodes the card data according to the given format and returns the encoded value as an integer.

Link to this section Types

@type decode_error() :: :bit_count | :even_parity_mismatch | :odd_parity_mismatch

Link to this section Functions

@spec decode(Wiegand.CardFormat.t(), bitstring() | integer()) ::
  {:ok, Wiegand.CardData.t()} | {:error, decode_error()}
Link to this function

encode(format, card_data)

View Source

Encodes the card data according to the given format and returns the encoded value as an integer.