mirror of
https://github.com/brmlab/brmdoor_libnfc.git
synced 2025-06-09 17:04:08 +02:00
Documentation
This commit is contained in:
parent
821f394602
commit
7de37d5822
1 changed files with 50 additions and 0 deletions
|
@ -7,53 +7,103 @@
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
#include <nfc/nfc-types.h>
|
#include <nfc/nfc-types.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception class for reader related errors.
|
||||||
|
*/
|
||||||
class NFCError: public std::exception
|
class NFCError: public std::exception
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/** Constructor with human-readable reason message */
|
||||||
NFCError(const std::string& msg);
|
NFCError(const std::string& msg);
|
||||||
|
|
||||||
|
/** Returns reason why this was thrown. */
|
||||||
const char *what() const throw() {return _msg.c_str();}
|
const char *what() const throw() {return _msg.c_str();}
|
||||||
|
|
||||||
~NFCError() throw() {}
|
~NFCError() throw() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
/** Reason message */
|
||||||
std::string _msg;
|
std::string _msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents one PN532 reader device. Config is taken from default
|
||||||
|
* libnfc-specified location. That usually means first device found is used.
|
||||||
|
*
|
||||||
|
* Config resides in /etc/nfc/libnfc.conf if installed from packages or
|
||||||
|
* /usr/local/etc/nfc/libnfc.conf if installed from source.
|
||||||
|
*
|
||||||
|
* A device is specified like this:
|
||||||
|
*
|
||||||
|
* device.connstring = pn532_uart:/dev/ttyACM0
|
||||||
|
* device.connstring = "pn532_spi:/dev/spidev0.0"
|
||||||
|
*
|
||||||
|
* Refer to libnfc documentation for setting up devices.
|
||||||
|
*/
|
||||||
class NFCDevice
|
class NFCDevice
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes PN53x libnfc device and opens it, so you don't need to call
|
||||||
|
* open() after constructor.
|
||||||
|
*
|
||||||
|
* @throws NFCError if no device found or communication failed
|
||||||
|
*/
|
||||||
NFCDevice() throw(NFCError);
|
NFCDevice() throw(NFCError);
|
||||||
|
|
||||||
|
/** Destructor frees internal libnfc structures */
|
||||||
virtual ~NFCDevice();
|
virtual ~NFCDevice();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Poll until a ISO14443A card is in the field and returns its UID.
|
||||||
|
*
|
||||||
|
* @returns binary string containing UID or empty if non-supported card
|
||||||
|
* present in reader field
|
||||||
|
* @throws NFCError if polling failed
|
||||||
|
*/
|
||||||
std::string scanUID() throw(NFCError);
|
std::string scanUID() throw(NFCError);
|
||||||
|
|
||||||
|
/** Open device explicitly. May be useful after explicit close */
|
||||||
void open() throw(NFCError);
|
void open() throw(NFCError);
|
||||||
|
|
||||||
|
/** Returns true iff device was opened */
|
||||||
bool opened() const {return _opened;}
|
bool opened() const {return _opened;}
|
||||||
|
|
||||||
|
/** Close reader. You need to reopen before reading again */
|
||||||
void close();
|
void close();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies the number of polling (0x01 – 0xFE: 1 up to 254 polling, 0xFF:
|
||||||
|
* Endless polling)
|
||||||
|
*/
|
||||||
uint8_t pollNr;
|
uint8_t pollNr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Polling period when waiting for card in multiples of 150 ms.
|
||||||
|
* (0x01 – 0x0F: 150ms – 2.25s)
|
||||||
|
*/
|
||||||
uint8_t pollPeriod;
|
uint8_t pollPeriod;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
/** Modulations that specify cards accepted by reader */
|
||||||
static const nfc_modulation _modulations[5];
|
static const nfc_modulation _modulations[5];
|
||||||
|
|
||||||
|
/** Number of modulations in _modulations array */
|
||||||
static const size_t _modulationsLen = 5;
|
static const size_t _modulationsLen = 5;
|
||||||
|
|
||||||
|
/** libnfc-specific opaque context */
|
||||||
nfc_context *_nfcContext;
|
nfc_context *_nfcContext;
|
||||||
|
|
||||||
|
/** Device opened by libnfc functions, may be NULL */
|
||||||
nfc_device *_nfcDevice;
|
nfc_device *_nfcDevice;
|
||||||
|
|
||||||
|
/** Whether device has been successfully opened */
|
||||||
bool _opened;
|
bool _opened;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue