FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
devices::protocols::Wiegand Class Reference

Supporting class for the Wiegand 26 bits protocol (used by many access control devices). More...

#include <fastarduino/devices/wiegand.h>

Public Types

using DATA_TYPE = uint32_t
 The data type used to return data read from the access control device. More...
 

Public Member Functions

 Wiegand ()
 Construct a new Wiegand instance to be sued by an access control device. More...
 
void reset ()
 Reset current read state of this instance. More...
 
void reset_ ()
 Reset current read state of this instance. More...
 
bool available_ () const
 Check if data is available, i.e. More...
 
bool valid_ () const
 Check if current data is valid, i.e. More...
 
DATA_TYPE get_data_ () const
 Get data read from access control device. More...
 
void on_falling_data0 ()
 Your device shall call this method whenever DATA0 line level is falling to 0, which means a 0 bit must be added to read data. More...
 
void on_falling_data1 ()
 Your device shall call this method whenever DATA1 line level is falling to 0, which means a 1 bit must be added to read data. More...
 

Static Public Attributes

static constexpr uint8_t DATA_BITS = 24
 The actual number of bits of data in DATA_TYPE. More...
 

Detailed Description

Supporting class for the Wiegand 26 bits protocol (used by many access control devices).

To use Wiegand class, you just need to instantiate it in your own device class, ensure you call on_falling_data0() and on_falling_data1() when you detect (ISR preferred) that line DATA0 or DATA1 is falling to 0V.

Other API methods allow you to know the state of reading (finished, parity valid), get the read data (if available and valid) and reset the reading.

Note
only the "original" Wiegand interface standard (26-bits, including 2 parity bits) is supported here; there are many variations in terms of bits number and parity checks, developped by access control companies, but it is not clear if some have been standardized. If some needs occur for extended support in the future, it is probable this class will be refactored to support these extensions.

Definition at line 56 of file wiegand.h.

Member Typedef Documentation

◆ DATA_TYPE

The data type used to return data read from the access control device.

This may be larger than what is actually needed.

Definition at line 63 of file wiegand.h.

Constructor & Destructor Documentation

◆ Wiegand()

devices::protocols::Wiegand::Wiegand ( )
inline

Construct a new Wiegand instance to be sued by an access control device.

The instance is ready to be used for data reading.

Definition at line 77 of file wiegand.h.

Member Function Documentation

◆ reset()

void devices::protocols::Wiegand::reset ( )
inline

Reset current read state of this instance.

Any bits read will be lost. You should call this method after having read latest data with get_data_().

This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor reset_() instead.

See also
reset_()
get_data_()

Definition at line 93 of file wiegand.h.

◆ reset_()

void devices::protocols::Wiegand::reset_ ( )
inline

Reset current read state of this instance.

Any bits read will be lost. You should call this method after having read latest data with get_data_().

This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor reset_() instead.

See also
reset_()
get_data_()

Definition at line 109 of file wiegand.h.

◆ available_()

bool devices::protocols::Wiegand::available_ ( ) const
inline

Check if data is available, i.e.

all 26 bits have been received already.

Note
this method does not care about validity of received bits (parity check), for this you will need to also call valid_().

This method is not synchronized, hence you must ensure it is called from an interrupt-safe context.

See also
valid_()

Definition at line 127 of file wiegand.h.

◆ valid_()

bool devices::protocols::Wiegand::valid_ ( ) const
inline

Check if current data is valid, i.e.

parity has been checked against both even and odd parity bits (as per Wiegand 26 bits standard).

Note
this method does not care about availability of data (all 26 bits received or not yet), for this you will need to first call available_().

This method is not synchronized, hence you must ensure it is called from an interrupt-safe context.

See also
available_()

Definition at line 144 of file wiegand.h.

◆ get_data_()

DATA_TYPE devices::protocols::Wiegand::get_data_ ( ) const
inline

Get data read from access control device.

Note
this method does not care about availability or validity of data, it will just return the current state of data received so far. This is why you should first call available_() and valid_() before calling get_data_().

This method is not synchronized, hence you must ensure it is called from an interrupt-safe context.

See also
available_()
valid_()

Definition at line 170 of file wiegand.h.

◆ on_falling_data0()

void devices::protocols::Wiegand::on_falling_data0 ( )
inline

Your device shall call this method whenever DATA0 line level is falling to 0, which means a 0 bit must be added to read data.

It is expected to work with interrupts (EXT or PCI) for connecting the access control device DATA0 and DATA1 pins.

See also
on_falling_data1()

Definition at line 184 of file wiegand.h.

◆ on_falling_data1()

void devices::protocols::Wiegand::on_falling_data1 ( )
inline

Your device shall call this method whenever DATA1 line level is falling to 0, which means a 1 bit must be added to read data.

It is expected to work with interrupts (EXT or PCI) for connecting the access control device DATA0 and DATA1 pins.

See also
on_falling_data0()

Definition at line 217 of file wiegand.h.

Member Data Documentation

◆ DATA_BITS

constexpr uint8_t devices::protocols::Wiegand::DATA_BITS = 24
staticconstexpr

The actual number of bits of data in DATA_TYPE.

This does not include parity bits which do not hold any access control data. The actual bits are always the LSB in DATA_TYPE, other bits (HSB) are set to 0.

Definition at line 71 of file wiegand.h.

◆ buffer_

uint32_t devices::protocols::Wiegand::buffer_

Definition at line 273 of file wiegand.h.

◆ data_

uint8_t devices::protocols::Wiegand::data_[DATA_BYTES]

Definition at line 277 of file wiegand.h.

◆ count_

uint8_t devices::protocols::Wiegand::count_

Definition at line 279 of file wiegand.h.

◆ data24_

uint32_t devices::protocols::Wiegand::data24_

Definition at line 284 of file wiegand.h.

◆ __pad0__

uint32_t devices::protocols::Wiegand::__pad0__

Definition at line 285 of file wiegand.h.


The documentation for this class was generated from the following file: