upm
1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
|
API for the SM130 RFID Reader Module. More...
This module defines the SM130 interface for the sm130 RFID library
This module was developed using an SM130 and a Sparkfun RFID Evaluation shield using a UART for communications. It should be fairly trivial to add support for I2C communication in the future, if you have the correct firmware on the SM130.
SM130 RFID Reader image provided by SparkFun* under CC BY 2.0.
Public Member Functions | |
SM130 (int uart=SM130_DEFAULT_UART, int reset=SM130_DEFAULT_RESET_PIN) | |
~SM130 () | |
mraa::Result | setBaudRate (int baud=19200) |
std::string | getFirmwareVersion () |
bool | reset () |
void | hardwareReset () |
bool | select () |
bool | waitForTag (uint32_t timeout) |
bool | authenticate (uint8_t block, KEY_TYPES_T keyType, std::string key="") |
std::string | readBlock16 (uint8_t block) |
int32_t | readValueBlock (uint8_t block) |
bool | writeBlock16 (uint8_t block, std::string contents) |
bool | writeValueBlock (uint8_t block, int32_t value) |
bool | writeBlock4 (uint8_t block, std::string contents) |
bool | writeKey (uint8_t eepromSector, KEY_TYPES_T keyType, std::string key) |
int32_t | adjustValueBlock (uint8_t block, int32_t value, bool incr) |
bool | setAntennaPower (bool on) |
uint8_t | readPorts () |
bool | writePorts (uint8_t val) |
bool | haltTag () |
bool | setSM130BaudRate (int baud) |
bool | sleep () |
char | getLastErrorCode () |
std::string | getLastErrorString () |
int | getUIDLen () |
std::string | getUID () |
TAG_TYPE_T | getTagType () |
std::string | tag2String (TAG_TYPE_T tag) |
std::string | string2HexString (std::string input) |
Protected Member Functions | |
std::string | sendCommand (CMD_T cmd, std::string data) |
void | initClock () |
uint32_t | getMillis () |
Protected Attributes | |
mraa::Uart | m_uart |
mraa::Gpio | m_gpioReset |
SM130 | ( | int | uart = SM130_DEFAULT_UART , |
int | reset = SM130_DEFAULT_RESET_PIN |
||
) |
Instantiates an SM130 object
uart | The UART port. Default is 0. |
reset | The Reset pin. Default is 13. |
mraa::Result setBaudRate | ( | int | baud = 19200 | ) |
Sets the baud rate for the device. The default is 19200.
baud | Desired baud rate, default 19200 |
string getFirmwareVersion | ( | ) |
Gets the firmware version string.
bool reset | ( | ) |
Issues a reset command to the device.
void hardwareReset | ( | ) |
Resets the device using the hardware RESET pin. This is required if the device has been put to sleep using the sleep() method.
bool select | ( | ) |
Checks to see if a tag is in the RF field, and selects it if one is present.
bool waitForTag | ( | uint32_t | timeout | ) |
Waits for a tag to enter the RF field for up to 'timeout' milliseconds. It will call select() every 100ms until 'timeout' has been exceeded.
timeout | The number of milliseconds to wait for a tag to appear |
bool authenticate | ( | uint8_t | block, |
KEY_TYPES_T | keyType, | ||
std::string | key = "" |
||
) |
Set the authentication key for a block. Depending on the permissions on the tag, the correct key must be authenticated for that block in order to perform read and write operations.
block | The block to authenticate for |
keyType | one of the KEY_TYPE_T values |
key | The 6 byte key to use for Type A and Type B keys |
string readBlock16 | ( | uint8_t | block | ) |
Read a 16 byte block. Depending on the tag, authentication of the block may be required for this method to succeed.
block | The block to read |
int32_t readValueBlock | ( | uint8_t | block | ) |
Read a 4 byte value block. Depending on the tag, authentication of the block may be required for this method to succeed.
block | The block to read |
bool writeBlock16 | ( | uint8_t | block, |
std::string | contents | ||
) |
Write 16 bytes to a block. Depending on the tag, authentication of the block may be required for this method to succeed.
block | The block to write |
contents | A 16 byte string containing the data to write |
bool writeValueBlock | ( | uint8_t | block, |
int32_t | value | ||
) |
Write to a 4 byte value block. Depending on the tag, authentication of the block may be required for this method to succeed.
block | The block to write |
value | the signed 4 byte integer to write to the value block |
bool writeBlock4 | ( | uint8_t | block, |
std::string | contents | ||
) |
Write 4 bytes to a block. This is typically used for Ultralight tags. Depending on the tag, authentication of the block may be required for this method to succeed.
block | The block to write |
contents | A 4 byte string containing the data to write |
bool writeKey | ( | uint8_t | eepromSector, |
KEY_TYPES_T | keyType, | ||
std::string | key | ||
) |
Write a key into one of the 16 EEPROM key slots. This can be a Type A or Type B key. It is not possible to read these keys once written. Once stored, the key can be used for authentication without having to send the key itself. You can then use the appropriate KEY_TYPE_EEPROM_* keyTypes in a call to authenticate().
eepromSector | A number between 0 and 15, indicating the EEPROM sector you want to store the key in |
keyType | Either KEY_TYPE_A or KEY_TYPE_B |
key | The 6 byte key to store in the EEPROM |
int32_t adjustValueBlock | ( | uint8_t | block, |
int32_t | value, | ||
bool | incr | ||
) |
Increment or decrement a value block.
block | The block to adjust |
value | The number to increment or decrement the value block by |
incr | true to increment, false to decrement |
bool setAntennaPower | ( | bool | on | ) |
Turn the antenna power on or off. The power is on by default after a reset. If you turn off the antenna, and methods used for interacting with tags will fail until power is re-enabled.
on | true to enable antenna power, false to disable |
uint8_t readPorts | ( | ) |
Read the status of the 2 onboard GPIO input pins. Bit 0 is for input 0, bit 1 for input 1. All other bits will be 0.
bool writePorts | ( | uint8_t | val | ) |
Set the output status of the 2 onboard gpio outputs. Bit 0 is for output 0, bit 1 for output 1. All other bits will be discarded.
val | bitmask of output status bits to write |
bool haltTag | ( | ) |
Halts a tag. Once a tag is halted, it cannot be accessed until it is removed and reinserted into the RF field and selected.
bool setSM130BaudRate | ( | int | baud | ) |
Changes the baud rate of the SM130. WARNING: This is a potentially dangerous command that could cause you to lose contact with the device. Once the command is validated and issued, the host baudrate will be changed to match, and this method will wait for a response at the new baudrate for up to 1 second.
If this response does not arrive, the old baudrate will be restored, though there is no way to know whether the SM130 actually succeessfully executed the baudrate change.
Once the SM130 has changed it's baudrate, the new value will be stored in it's EEPROM, and any further access to the device will need to use the new baudrate. This is true even after a power on reset.
baud | The new baud rate to set. Valid values are 9600, 19200, 38400, 57600, and 115200. |
bool sleep | ( | ) |
Put the SM130 to sleep. Once the device has been put to sleep, the only way to wake it is via hardwareReset() or a power cycle.
|
inline |
Get the last error that occurred. After a successful operation, this will be 0. See the datasheet for the various errors that can occur in various circumstances.
|
inline |
Get the text representation of the last error that occurred. The returned string is empty if the last operation completed successfully.
|
inline |
Get the UID length of the currently selected tag.
|
inline |
Get the UID of the currently selected tag.
|
inline |
Get the tag type of the currently selected tag.
string tag2String | ( | TAG_TYPE_T | tag | ) |
Convert the supplied tag type into a human readable string.
tag | One of the TAG_TYPE_T values |
string string2HexString | ( | std::string | input | ) |
This is a convenience function that converts a supplied string into a space separated hex formatted string. This can be useful for printing out binary data in a human readable format, like the UID.
input | The string to convert |