Documentation ¶
Overview ¶
Package nxprd is the main package of the GO wrapper for NXP's reader library. All NFC functionality is included in this package.
Index ¶
Constants ¶
const ( LangEn Language = "en" LangDe = "de" LangIt = "it" LangNl = "nl" LangFr = "fr" LangRu = "ru" LangKr = "kr" LangCn = "cn" LangUk = "uk" LangCa = "ca" LangEs = "es" )
const ( // MifareULBlockLength defines the block length in bytes of a Mifare // Ultralight card, i.e. a block (page) of a Mifare Ultralight contains 4 // bytes. MifareULBlockLength = 4 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Device ¶
type Device struct { // Params holds general nfc parameters of the card/tag, such as SAK or UID. Params DeviceParams // Reader reads bytes from the card/tag. Can be nil if no specific // implementation exists for the card/tag. Reader Reader // Writer writes bytes to the card/tag. Can be nil if no specific // implementation exists for the card/tag. Writer Writer }
Device identifies a card/tag and contains parameters, such as the tag type or technology and Reader/Writer implementations for reading and writing bytes. Please note that Reader or Writer can be nil. This happens if an card/tag is identified for which no Reader/Writer implementation exists. Params will never be nil.
func Discover ¶
Discover selects a card/tag that is in the range of the breakout board and returns a pointer to a Device structure. If an error occurred while detecting and activating the card/tag, a NxpError along with a nil value for the Device is returned. Please note that not all cards/tags may be supported and thus the Reader or Writer variables within the Device struct may be nil. However, if a card/tag is found and no error occurred you'll always get a Device struct containing the card's/tag's parameters. Discover has an optional timeout parameter. The default value is 1000, which means Discover waits up to 1000ms to discover/detect a card/tag. During that time the caller will be blocked. The timeout value has to be of type int and will be interpreted as ms. So, if you want to give some more time for card/tag discovery, for instance 20s, you can call Discover(20000).
type DeviceParams ¶
type DeviceParams struct { // Select AcKnowledge. Can be -1 if not available. SAK int // Holds ATQA for Tech Type A and ATQB for Tech Type B // ATQA = Answer To reQuest for Type A // ATQB = Answer To reQuest for Type B // ATQ can be nil, if not available ATQ []byte // Unified IDentifier of the card/tag. Can be nil, if not available. UID []byte // TechType identifies the technology type, e.g. A, B, P2P, etc. TechType TechType // TagType identifies the tag type, i.e. 1, 2, etc. TagType TagType // DevType DevType DeviceType }
DeviceParams holds various parameters of a nfc card/tag.
type DeviceType ¶
type DeviceType int
DeviceType defines manufacturer specific cards/tags which are supported by this wrapper.
const ( // Mifare Ultralight card MifareUL DeviceType = 1 + iota Unknown )
All cards/tags which are supported by this wrapper.
func (DeviceType) String ¶
func (dt DeviceType) String() string
String returns the name of a DeviceType (emulating an enum).
type ExtendedErrorCode ¶
type ExtendedErrorCode int
ExtendedErrorCode defines errors of the wrapper. The C library has its own error codes.
const ( // TimeoutErr is used if a timeout occurred when using Discover(). TimeoutErr ExtendedErrorCode = 1 + iota // NoErr is used if no error occurred. NoErr )
All extended error codes of the wrapper.
func (ExtendedErrorCode) String ¶
func (ec ExtendedErrorCode) String() string
String returns the name of an ExtendedErrorCode (emulating an enum).
type Language ¶
type Language string
New type to represent Language if the payload type is "T"(text).
type MifareULReader ¶
type MifareULReader struct { }
MifareULReader implements the Reader interface for the Mifare Ultralight card.
func (*MifareULReader) ReadBlock ¶
func (r *MifareULReader) ReadBlock(idx int) ([]byte, error)
ReadBlock implements reading a block of bytes for a Mifare Ultralight card. idx defines the block to be read. See also the Reader interface.
func (*MifareULReader) ReadNdef ¶
func (r *MifareULReader) ReadNdef() (*Ndef, error)
This function reads the data from the card using the ReadBlock method and converts the read bytes into a NDEF struct.
type MifareULWriter ¶
type MifareULWriter struct { }
MifareULWriter implements the Writer interface for the Mifare Ultralight card.
func (*MifareULWriter) WriteBlock ¶
func (w *MifareULWriter) WriteBlock(idx int, data []byte) error
WriteBlock implements writing a block of bytes for the Mifare Ultralight card. idx defines the memory position / block number. See also the Writer interface.
func (*MifareULWriter) WriteNdef ¶
func (w *MifareULWriter) WriteNdef(ndef *Ndef) error
WriteNdef accepts a NDEF struct and converts the struct into bytes and writes it to a NFC tag or card
func (*MifareULWriter) WriteString ¶
func (w *MifareULWriter) WriteString(payload string, language Language) error
WriteString accepts a string and the language of the string and converts the string to a NDEF struct and writes it to the card
type Ndef ¶
type Ndef struct { MaxSize int IsReadOnly bool TotalMessageLength int NdefData []NdefRecord }
A struct which represents the NDEF message
type NdefRecord ¶
type NdefRecord struct { IsStartRecord bool IsEndRecord bool ChunkFlag bool IsShortRecord bool IsIdLengthFieldPresent bool PayloadLength int Payload []byte Tnf Tnf Type string RecordNumber int TypeLength int IdLength int Id string Language Language }
A struct which represents each NDEF message
type NxpError ¶
type NxpError struct { // Comp defines the component of the C library where the error occurred. // 0 stands for "no error". Comp int // Code defines the actual error that occurred in the C library. // 0 stands for "no error". Code int // ExtCode defines the extended error code of the wrapper. ExtCode will have // the NoErr value, if no extended error occurred. ExtCode ExtendedErrorCode // Msg describes the error. Msg string }
NxpError defines the error struct that is used to indicate an error of the C library or the GO wrapper.
type Reader ¶
type Reader interface { // ReadBlock reads a block of bytes from a nfc card/tag. idx defines the // block number or index. The memory layout, i.e. the number and the size of // blocks may differ between the various tags and cards. // If data can't be read, a NxpError is returned along with a nil slice. // If data could be read, error will be always nil. ReadBlock(idx int) ([]byte, error) //Returns the entire contents of a card or tag as a NDEF struct ReadNdef() (*Ndef, error) }
Reader defines an interface for reading data from a nfc capable card/tag.
type TagType ¶
type TagType int
TagType defines the nfc tag type, such as 1, 2, 3, 4A etc.
type TechType ¶
type TechType int
TechType defines the technology of the card/tag, e.g. A, B, etc..
Technology types which are supported by this wrapper.
type Writer ¶
type Writer interface { // WriteBlock writes a block (slice) of bytes to a nfc card/tag. // The position of the block is defined by idx and may vary between // different cards and tags. Also the length of the data slice depends on // the card/tag being used. // If the data can't be written, a NxpError is returned. If no error occurred, // nil is returned. WriteBlock(idx int, data []byte) error //Writes the NDEF struct to the tag or card WriteNdef(ndef *Ndef) error //Writes the string of a particular language to the card or tag WriteString(payload string, language Language) error }
Writer defines an interface for writing data to a nfc capable card/tag.