Leosac  0.8.0
Open Source Access Control
Leosac::Module::Wiegand::Strategy::Autodetect Class Reference

Variable strategy that tries to autodetect what it reads. More...

#include <Autodetect.hpp>

+ Inheritance diagram for Leosac::Module::Wiegand::Strategy::Autodetect:
+ Collaboration diagram for Leosac::Module::Wiegand::Strategy::Autodetect:

Public Member Functions

 Autodetect (WiegandReaderImpl *reader, std::chrono::milliseconds delay, char pin_key_end, bool nowait)
 Create a strategy that read whatever it can and tries its best to determine what is was that it read. More...
 
virtual void timeout () override
 This is called when the module detect a timeout. More...
 
virtual bool completed () const override
 Did the strategy gather needed data? If this function returns true, that means that the strategy implementation successfully retrieve data from wiegand bits. More...
 
virtual void signal (zmqpp::socket &sock) override
 Tells the strategy implementation to send a message to the application containing the received credentials. More...
 
virtual void set_reader (WiegandReaderImpl *new_ptr) override
 Update the pointer that points back to the associated reader. More...
 
- Public Member Functions inherited from Leosac::Module::Wiegand::Strategy::WiegandStrategy
 WiegandStrategy (WiegandReaderImpl *reader)
 
virtual ~WiegandStrategy ()=default
 

Private Types

using TimePoint = std::chrono::system_clock::time_point
 

Private Member Functions

void reset () override
 Reset self. More...
 
PinReadingUPtr build_strategy (int bits)
 Dynamically instanciate a new strategy based on the number of bits available. More...
 
void check_timeout ()
 Called when timeout() was called but nothing was read. More...
 

Private Attributes

CardReadingUPtr read_card_strategy_
 
PinReadingUPtr read_pin_strategy_
 
std::chrono::milliseconds delay_
 
TimePoint time_card_read_
 
TimePoint last_pin_read_
 
bool reading_pin_
 
bool reading_card_
 
bool ready_
 
char pin_key_end_
 
bool nowait_
 

Additional Inherited Members

- Protected Attributes inherited from Leosac::Module::Wiegand::Strategy::WiegandStrategy
WiegandReaderImplreader_
 

Detailed Description

Variable strategy that tries to autodetect what it reads.

It can credentials multiple type of credentials, based on what was detected.

We have 3 possible scenario:

  • User only swipes their card.
  • User swipes their card, and then input a PIN code.
  • User input a PIN code.

Definition at line 42 of file Autodetect.hpp.

Member Typedef Documentation

◆ TimePoint

using Leosac::Module::Wiegand::Strategy::Autodetect::TimePoint = std::chrono::system_clock::time_point
private

Definition at line 94 of file Autodetect.hpp.

Constructor & Destructor Documentation

◆ Autodetect()

Autodetect::Autodetect ( WiegandReaderImpl reader,
std::chrono::milliseconds  delay,
char  pin_key_end,
bool  nowait 
)

Create a strategy that read whatever it can and tries its best to determine what is was that it read.

Parameters
readerthe reader object we provide the strategy for.
delaymax nb of msec between reading the card and receiving pin code data.
pin_key_endwhat key on the reader signals the end of the pin code ?

Definition at line 27 of file Autodetect.cpp.

Member Function Documentation

◆ build_strategy()

PinReadingUPtr Autodetect::build_strategy ( int  bits)
private

Dynamically instanciate a new strategy based on the number of bits available.

This depends on the wiegand reader mode, and this class support either 4 or 8 bits.

Returns
a new strategy to handle 4 or 8 bits mode.
Note
Assert if !(bits == 4 || bits == 8);

Definition at line 178 of file Autodetect.cpp.

◆ check_timeout()

void Autodetect::check_timeout ( )
private

Called when timeout() was called but nothing was read.

Definition at line 87 of file Autodetect.cpp.

◆ completed()

bool Autodetect::completed ( ) const
overridevirtual

Did the strategy gather needed data? If this function returns true, that means that the strategy implementation successfully retrieve data from wiegand bits.

It successfully build a card_id, or a PIN code, etc. The reader implementation will call signal() if completed() returns true.

Implements Leosac::Module::Wiegand::Strategy::WiegandStrategy.

Definition at line 129 of file Autodetect.cpp.

◆ reset()

void Autodetect::reset ( )
overrideprivatevirtual

Reset self.

We create new strategy instance, reset the boolean flag to defaults and reset the underlying reader buffer.

Implements Leosac::Module::Wiegand::Strategy::WiegandStrategy.

Definition at line 166 of file Autodetect.cpp.

◆ set_reader()

void Autodetect::set_reader ( WiegandReaderImpl new_ptr)
overridevirtual

Update the pointer that points back to the associated reader.

Reimplemented from Leosac::Module::Wiegand::Strategy::WiegandStrategy.

Definition at line 158 of file Autodetect.cpp.

◆ signal()

void Autodetect::signal ( zmqpp::socket &  sock)
overridevirtual

Tells the strategy implementation to send a message to the application containing the received credentials.

It is up to the strategy to format a correct message. This is required because only the strategy knows what kind of credential it can generate.

Parameters
sockthe socket where we write the message containing credentials.

Implements Leosac::Module::Wiegand::Strategy::WiegandStrategy.

Definition at line 134 of file Autodetect.cpp.

◆ timeout()

void Autodetect::timeout ( )
overridevirtual

This is called when the module detect a timeout.

(2 ms of inactivity).

Implements Leosac::Module::Wiegand::Strategy::WiegandStrategy.

Definition at line 43 of file Autodetect.cpp.

Member Data Documentation

◆ delay_

std::chrono::milliseconds Leosac::Module::Wiegand::Strategy::Autodetect::delay_
private

Definition at line 93 of file Autodetect.hpp.

◆ last_pin_read_

TimePoint Leosac::Module::Wiegand::Strategy::Autodetect::last_pin_read_
private

Definition at line 96 of file Autodetect.hpp.

◆ nowait_

bool Leosac::Module::Wiegand::Strategy::Autodetect::nowait_
private

Definition at line 103 of file Autodetect.hpp.

◆ pin_key_end_

char Leosac::Module::Wiegand::Strategy::Autodetect::pin_key_end_
private

Definition at line 102 of file Autodetect.hpp.

◆ read_card_strategy_

CardReadingUPtr Leosac::Module::Wiegand::Strategy::Autodetect::read_card_strategy_
private

Definition at line 90 of file Autodetect.hpp.

◆ read_pin_strategy_

PinReadingUPtr Leosac::Module::Wiegand::Strategy::Autodetect::read_pin_strategy_
private

Definition at line 91 of file Autodetect.hpp.

◆ reading_card_

bool Leosac::Module::Wiegand::Strategy::Autodetect::reading_card_
private

Definition at line 99 of file Autodetect.hpp.

◆ reading_pin_

bool Leosac::Module::Wiegand::Strategy::Autodetect::reading_pin_
private

Definition at line 98 of file Autodetect.hpp.

◆ ready_

bool Leosac::Module::Wiegand::Strategy::Autodetect::ready_
private

Definition at line 100 of file Autodetect.hpp.

◆ time_card_read_

TimePoint Leosac::Module::Wiegand::Strategy::Autodetect::time_card_read_
private

Definition at line 95 of file Autodetect.hpp.


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