LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
logicalaccess::LibUSBReaderUnit Class Reference

The LibUSB reader unit class. More...

#include <libusbreaderunit.hpp>

Inheritance diagram for logicalaccess::LibUSBReaderUnit:
logicalaccess::ReaderUnit logicalaccess::XmlSerializable

Public Member Functions

 LibUSBReaderUnit (struct libusb_device *device)
 Constructor.
 
virtual ~LibUSBReaderUnit ()
 Destructor.
 
std::string getName () const override
 Get the reader unit name.
 
void setName (const std::string &name)
 
std::string getConnectedName () override
 Get the connected reader unit name.
 
void setCardType (std::string cardType) override
 Set the card type.
 
bool waitInsertion (unsigned int maxwait) override
 Wait for a card insertion.
 
bool waitRemoval (unsigned int maxwait) override
 Wait for a card removal.
 
std::shared_ptr< ChipcreateChip (std::string type) override
 Create the chip object from card type.
 
std::vector< unsigned char > getNumber (std::shared_ptr< Chip > chip) override
 Get the number from the embedded licensing configuration.
 
std::shared_ptr< ChipgetSingleChip () override
 Get the first and/or most accurate chip found.
 
std::vector< std::shared_ptr< Chip > > getChipList () override
 Get chip available in the RFID rang.
 
bool connect () override
 Connect to the card.
 
void disconnect () override
 Disconnect from the reader.
 
bool isConnected () override
 Check if the card is connected.
 
bool connectToReader () override
 Connect to the reader. Implicit connection on first command sent.
 
void disconnectFromReader () override
 Disconnect from reader.
 
std::string getReaderSerialNumber () override
 Get a string hexadecimal representation of the reader serial number.
 
virtual std::shared_ptr< LibUSBReaderCardAdaptergetDefaultLibUSBReaderCardAdapter ()
 Get the default LibUSB reader/card adapter.
 
void serialize (boost::property_tree::ptree &parentNode) override
 Serialize the current object to XML.
 
void unSerialize (boost::property_tree::ptree &node) override
 UnSerialize a XML node to the current object.
 
std::shared_ptr< LibUSBReaderUnitConfigurationgetLibUSBConfiguration ()
 Get the LibUSB reader unit configuration.
 
std::shared_ptr< LibUSBReaderProvidergetLibUSBReaderProvider () const
 Get the LibUSB reader provider.
 
struct libusb_device * getDevice () const
 Get the LibUSB device.
 
struct libusb_device_handle * getHandle () const
 
void setVendorID (uint16_t vendor_id)
 
- Public Member Functions inherited from logicalaccess::ReaderUnit
 ReaderUnit (std::string rpt)
 Constructor.
 
virtual ~ReaderUnit ()
 Destructor.
 
std::string getRPType () const
 Get the reader provider type.
 
virtual ByteVector getPingCommand () const
 Get the reader ping command.
 
virtual bool waitInsertion (unsigned int maxwait)=0
 Wait for a card insertion.
 
virtual bool waitInsertion (const ByteVector &identifier, unsigned int maxwait)
 Wait for a specific card insertion.
 
virtual bool waitRemoval (unsigned int maxwait)=0
 Wait for a card removal.
 
virtual bool isConnected ()=0
 Check if the card is connected.
 
std::string getCardType () const
 Get the forced card type.
 
virtual void setCardType (std::string cardType)=0
 Set the forced card type.
 
virtual std::shared_ptr< ChipcreateChip (std::string type)
 Create the chip object from card type.
 
virtual std::shared_ptr< ChipcreateChip (std::string type, const ByteVector &identifier)
 Create the chip object from card type with identifier.
 
virtual ByteVector getNumber (std::shared_ptr< Chip > chip)
 Get the number from the embedded licensing configuration.
 
virtual std::shared_ptr< ChipgetSingleChip ()=0
 Get the first and/or most accurate chip found.
 
virtual std::vector< std::shared_ptr< Chip > > getChipList ()=0
 Get chip available in the RFID rang.
 
virtual ByteVector getNumber (std::shared_ptr< Chip > chip, std::shared_ptr< CardsFormatComposite > composite)
 Get the number from the reader format composite.
 
virtual bool connect ()=0
 Connect to the card.
 
virtual bool reconnect (int action=0)
 Reconnect to the card with the currently active share mode on the same reader.
 
virtual void disconnect ()=0
 Disconnect from the card.
 
virtual bool connectToReader ()=0
 Connect to the reader. Implicit connection on first command sent.
 
virtual void disconnectFromReader ()=0
 Disconnect from reader.
 
virtual std::string getName () const =0
 Get the reader unit name.
 
virtual std::string getConnectedName ()
 Get the connected reader unit name.
 
virtual std::shared_ptr< ReaderUnitConfigurationgetConfiguration ()
 Get the reader unit configuration.
 
virtual void setConfiguration (std::shared_ptr< ReaderUnitConfiguration > config)
 Set the reader unit configuration.
 
virtual std::shared_ptr< ReaderCardAdaptergetDefaultReaderCardAdapter ()
 Get the default reader/card adapter.
 
virtual void setDefaultReaderCardAdapter (std::shared_ptr< ReaderCardAdapter > defaultRca)
 Set the default reader/card adapter.
 
virtual std::shared_ptr< DataTransportgetDataTransport () const
 Get the data transport layer.
 
virtual void setDataTransport (std::shared_ptr< DataTransport > dataTransport)
 Set the data transport layer.
 
virtual std::string getReaderSerialNumber ()=0
 Get a string hexadecimal representation of the reader serial number.
 
std::string getDefaultXmlNodeName () const override
 Get the default Xml Node name for this object.
 
void serialize (boost::property_tree::ptree &node) override
 Serialize the current object to XML.
 
void unSerialize (boost::property_tree::ptree &node) override
 UnSerialize a XML node to the current object.
 
void unSerialize (boost::property_tree::ptree &node, const std::string &rootNode) override
 UnSerialize object from a Xml node.
 
std::shared_ptr< ReaderProvidergetReaderProvider () const
 Get the associated reader provider.
 
void setReaderProvider (std::weak_ptr< ReaderProvider > provider)
 Set the associated reader provider.
 
virtual std::shared_ptr< LCDDisplaygetLCDDisplay ()
 Get the LCD Display for this reader unit.
 
virtual void setLCDDisplay (std::shared_ptr< LCDDisplay > d)
 Get the LCD Display for this reader unit.
 
virtual std::shared_ptr< LEDBuzzerDisplaygetLEDBuzzerDisplay ()
 Get the LED/Buzzer Display for this reader unit.
 
virtual void setLEDBuzzerDisplay (std::shared_ptr< LEDBuzzerDisplay > lbd)
 Get the LCD Display for this reader unit.
 
virtual void setCardTechnologies (const TechnoBitset &bitset)
 
virtual TechnoBitset getCardTechnologies ()
 
virtual TechnoBitset getPossibleCardTechnologies ()
 
virtual ReaderServicePtr getService (const ReaderServiceType &type)
 
virtual std::string serialize ()
 Serialize object to Xml Node string.
 
virtual void serialize (boost::property_tree::ptree &parentNode)=0
 Serialize object to Xml Node.
 
virtual void unSerialize (boost::property_tree::ptree &node)=0
 UnSerialize object from a Xml Node.
 
virtual void unSerialize (const std::string &xmlstring, const std::string &rootNode)
 UnSerialize object from a Xml Node string.
 
virtual void unSerialize (std::istream &is, const std::string &rootNode)
 UnSerialize object from a Xml node.
 
virtual void unSerialize (boost::property_tree::ptree &node, const std::string &rootNode)
 UnSerialize object from a Xml node.
 
- Public Member Functions inherited from logicalaccess::XmlSerializable
virtual ~XmlSerializable ()=default
 
virtual std::string serialize ()
 Serialize object to Xml Node string.
 
virtual std::string serializeWithHeaders ()
 Serialize object to Xml Node string, with xml headers.
 
virtual void serialize (boost::property_tree::ptree &parentNode)=0
 Serialize object to Xml Node.
 
virtual void serializeToFile (const std::string &filename)
 Serialize object to a Xml file.
 
virtual void unSerialize (boost::property_tree::ptree &node)=0
 UnSerialize object from a Xml Node.
 
virtual void unSerialize (const std::string &xmlstring, const std::string &rootNode)
 UnSerialize object from a Xml Node string.
 
virtual void unSerialize (std::istream &is, const std::string &rootNode)
 UnSerialize object from a Xml node.
 
virtual void unSerialize (boost::property_tree::ptree &node, const std::string &rootNode)
 UnSerialize object from a Xml node.
 
virtual void unSerializeFromFile (const std::string &filename)
 UnSerialize object from a Xml file.
 
virtual std::string getDefaultXmlNodeName () const =0
 Get the default Xml Node name for this object.
 

Protected Member Functions

libusb_device * look_for_device (uint16_t vendor_id, uint16_t product_id)
 
- Protected Member Functions inherited from logicalaccess::ReaderUnit
virtual std::shared_ptr< ResultCheckercreateDefaultResultChecker () const
 
virtual std::shared_ptr< CardProbecreateCardProbe ()
 

Protected Attributes

struct libusb_device * d_device
 The LibUSB device.
 
struct libusb_device * d_tmp_device
 
struct libusb_device_handle * d_device_handle
 
uint16_t d_vendor_id
 
uint16_t d_product_id
 
std::string d_serial_number
 
std::string d_product
 
std::string d_name
 
- Protected Attributes inherited from logicalaccess::ReaderUnit
std::string d_readerProviderType
 The associated reader provider type for the reader unit configuration.
 
std::string d_card_type
 The forced card type.
 
std::weak_ptr< ReaderProviderd_readerProvider
 The associated reader provider for the reader unit.
 
std::shared_ptr< ReaderUnitConfigurationd_readerUnitConfig
 The reader unit configuration.
 
std::shared_ptr< Chipd_insertedChip
 The inserted chip.
 
std::shared_ptr< LCDDisplayd_lcdDisplay
 The inserted chip.
 
std::shared_ptr< LEDBuzzerDisplayd_ledBuzzerDisplay
 The inserted chip.
 

Private Member Functions

template<typename TargetFunction , typename... Args>
int libusb_safe_call (TargetFunction fct, Args... arg)
 

Additional Inherited Members

- Static Public Member Functions inherited from logicalaccess::ReaderUnit
static uint64_t getFormatedNumber (const ByteVector &number, int padding)
 Get the number as decimal a number.
 
static std::string getFormatedNumber (const ByteVector &number)
 Get a string hexadecimal representation of the number.
 
- Static Public Member Functions inherited from logicalaccess::XmlSerializable
static std::string removeXmlDeclaration (const std::string &xmlstring)
 Remove Xml declaration from a xml string.
 
static ByteVector formatHexString (std::string hexstr)
 Format hex string to hex string with space.
 
- Static Protected Member Functions inherited from logicalaccess::XmlSerializable
static unsigned long long atoull (const std::string &str)
 

Detailed Description

The LibUSB reader unit class.

Constructor & Destructor Documentation

◆ LibUSBReaderUnit()

logicalaccess::LibUSBReaderUnit::LibUSBReaderUnit ( struct libusb_device *  device)

Constructor.

◆ ~LibUSBReaderUnit()

logicalaccess::LibUSBReaderUnit::~LibUSBReaderUnit ( )
virtual

Destructor.

Member Function Documentation

◆ connect()

bool logicalaccess::LibUSBReaderUnit::connect ( )
overridevirtual

Connect to the card.

Returns
True if the card was connected without error, false otherwise.

If the card handle was already connected, connect() first call disconnect(). If you intend to do a reconnection, call reconnect() instead.

Implements logicalaccess::ReaderUnit.

◆ connectToReader()

bool logicalaccess::LibUSBReaderUnit::connectToReader ( )
overridevirtual

Connect to the reader. Implicit connection on first command sent.

Returns
True if the connection successed.

Implements logicalaccess::ReaderUnit.

◆ createChip()

std::shared_ptr< Chip > logicalaccess::LibUSBReaderUnit::createChip ( std::string  type)
overridevirtual

Create the chip object from card type.

Parameters
typeThe card type.
Returns
The chip.

Reimplemented from logicalaccess::ReaderUnit.

◆ disconnect()

void logicalaccess::LibUSBReaderUnit::disconnect ( )
overridevirtual

Disconnect from the reader.

See also
connect

Calling this method on a disconnected reader has no effect.

Implements logicalaccess::ReaderUnit.

◆ disconnectFromReader()

void logicalaccess::LibUSBReaderUnit::disconnectFromReader ( )
overridevirtual

Disconnect from reader.

Implements logicalaccess::ReaderUnit.

◆ getChipList()

std::vector< std::shared_ptr< Chip > > logicalaccess::LibUSBReaderUnit::getChipList ( )
overridevirtual

Get chip available in the RFID rang.

Returns
The chip list.

Implements logicalaccess::ReaderUnit.

◆ getConnectedName()

std::string logicalaccess::LibUSBReaderUnit::getConnectedName ( )
overridevirtual

Get the connected reader unit name.

Returns
The connected reader unit name.

Reimplemented from logicalaccess::ReaderUnit.

◆ getDefaultLibUSBReaderCardAdapter()

std::shared_ptr< LibUSBReaderCardAdapter > logicalaccess::LibUSBReaderUnit::getDefaultLibUSBReaderCardAdapter ( )
virtual

Get the default LibUSB reader/card adapter.

Returns
The default LibUSB reader/card adapter.

◆ getDevice()

struct libusb_device * logicalaccess::LibUSBReaderUnit::getDevice ( ) const
inline

Get the LibUSB device.

Returns
The LibUSB device.

◆ getHandle()

struct libusb_device_handle * logicalaccess::LibUSBReaderUnit::getHandle ( ) const
inline

◆ getLibUSBConfiguration()

std::shared_ptr< LibUSBReaderUnitConfiguration > logicalaccess::LibUSBReaderUnit::getLibUSBConfiguration ( )
inline

Get the LibUSB reader unit configuration.

Returns
The LibUSB reader unit configuration.

◆ getLibUSBReaderProvider()

std::shared_ptr< LibUSBReaderProvider > logicalaccess::LibUSBReaderUnit::getLibUSBReaderProvider ( ) const

Get the LibUSB reader provider.

Returns
The LibUSB reader provider.

◆ getName()

std::string logicalaccess::LibUSBReaderUnit::getName ( ) const
overridevirtual

Get the reader unit name.

Returns
The reader unit name.

Implements logicalaccess::ReaderUnit.

◆ getNumber()

std::vector< unsigned char > logicalaccess::LibUSBReaderUnit::getNumber ( std::shared_ptr< Chip chip)
overridevirtual

Get the number from the embedded licensing configuration.

Parameters
chipThe chip object.
Returns
The identifier number.

Reimplemented from logicalaccess::ReaderUnit.

◆ getReaderSerialNumber()

std::string logicalaccess::LibUSBReaderUnit::getReaderSerialNumber ( )
overridevirtual

Get a string hexadecimal representation of the reader serial number.

Returns
The reader serial number or an empty string on error.

Implements logicalaccess::ReaderUnit.

◆ getSingleChip()

std::shared_ptr< Chip > logicalaccess::LibUSBReaderUnit::getSingleChip ( )
overridevirtual

Get the first and/or most accurate chip found.

Returns
The single chip.

Implements logicalaccess::ReaderUnit.

◆ isConnected()

bool logicalaccess::LibUSBReaderUnit::isConnected ( )
overridevirtual

Check if the card is connected.

Returns
True if the card is connected, false otherwise.

Implements logicalaccess::ReaderUnit.

◆ libusb_safe_call()

template<typename TargetFunction , typename... Args>
int logicalaccess::LibUSBReaderUnit::libusb_safe_call ( TargetFunction  fct,
Args...  arg 
)
inlineprivate

Call a libusb function and throw an exception if the return code is less than zero.

◆ look_for_device()

struct libusb_device * logicalaccess::LibUSBReaderUnit::look_for_device ( uint16_t  vendor_id,
uint16_t  product_id 
)
protected

◆ serialize()

void logicalaccess::LibUSBReaderUnit::serialize ( boost::property_tree::ptree &  parentNode)
overridevirtual

Serialize the current object to XML.

Parameters
parentNodeThe parent node.

Reimplemented from logicalaccess::ReaderUnit.

◆ setCardType()

void logicalaccess::LibUSBReaderUnit::setCardType ( std::string  cardType)
overridevirtual

Set the card type.

Parameters
cardTypeThe card type.

Implements logicalaccess::ReaderUnit.

◆ setName()

void logicalaccess::LibUSBReaderUnit::setName ( const std::string &  name)

◆ setVendorID()

void logicalaccess::LibUSBReaderUnit::setVendorID ( uint16_t  vendor_id)

◆ unSerialize()

void logicalaccess::LibUSBReaderUnit::unSerialize ( boost::property_tree::ptree &  node)
overridevirtual

UnSerialize a XML node to the current object.

Parameters
nodeThe XML node.

Reimplemented from logicalaccess::ReaderUnit.

◆ waitInsertion()

bool logicalaccess::LibUSBReaderUnit::waitInsertion ( unsigned int  maxwait)
overridevirtual

Wait for a card insertion.

Parameters
maxwaitThe maximum time to wait for, in milliseconds. If maxwait is zero, then the call never times out.
Returns
True if a card was inserted, false otherwise. If a card was inserted, the name of the reader on which the insertion was detected is accessible with getReader().
Warning
If the card is already connected, then the method always fail.

Implements logicalaccess::ReaderUnit.

◆ waitRemoval()

bool logicalaccess::LibUSBReaderUnit::waitRemoval ( unsigned int  maxwait)
overridevirtual

Wait for a card removal.

Parameters
maxwaitThe maximum time to wait for, in milliseconds. If maxwait is zero, then the call never times out.
Returns
True if a card was removed, false otherwise. If a card was removed, the name of the reader on which the removal was detected is accessible with getReader().

Implements logicalaccess::ReaderUnit.

Member Data Documentation

◆ d_device

struct libusb_device* logicalaccess::LibUSBReaderUnit::d_device
protected

The LibUSB device.

◆ d_device_handle

struct libusb_device_handle* logicalaccess::LibUSBReaderUnit::d_device_handle
protected

◆ d_name

std::string logicalaccess::LibUSBReaderUnit::d_name
protected

◆ d_product

std::string logicalaccess::LibUSBReaderUnit::d_product
protected

◆ d_product_id

uint16_t logicalaccess::LibUSBReaderUnit::d_product_id
protected

◆ d_serial_number

std::string logicalaccess::LibUSBReaderUnit::d_serial_number
protected

◆ d_tmp_device

struct libusb_device* logicalaccess::LibUSBReaderUnit::d_tmp_device
protected

◆ d_vendor_id

uint16_t logicalaccess::LibUSBReaderUnit::d_vendor_id
protected

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