PN532 Driver library This library provides an abstract API to drive the pn532 nfc chip, with I2C/HSU/SPI interface. Its based on the Seeed Studio's Arduino version.
Dependents: PN532_ReadUid Nfctest2
PN532/emulatetag.h@0:db8030e71f55, 2016-09-13 (annotated)
- Committer:
- dotnfc
- Date:
- Tue Sep 13 06:01:19 2016 +0000
- Revision:
- 0:db8030e71f55
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dotnfc | 0:db8030e71f55 | 1 | /**************************************************************************/ |
dotnfc | 0:db8030e71f55 | 2 | /*! |
dotnfc | 0:db8030e71f55 | 3 | @file emulatetag.h |
dotnfc | 0:db8030e71f55 | 4 | @author Armin Wieser |
dotnfc | 0:db8030e71f55 | 5 | @license BSD |
dotnfc | 0:db8030e71f55 | 6 | |
dotnfc | 0:db8030e71f55 | 7 | Implemented using NFC forum documents & library of libnfc |
dotnfc | 0:db8030e71f55 | 8 | */ |
dotnfc | 0:db8030e71f55 | 9 | /**************************************************************************/ |
dotnfc | 0:db8030e71f55 | 10 | |
dotnfc | 0:db8030e71f55 | 11 | #ifndef __EMULATETAG_H__ |
dotnfc | 0:db8030e71f55 | 12 | #define __EMULATETAG_H__ |
dotnfc | 0:db8030e71f55 | 13 | |
dotnfc | 0:db8030e71f55 | 14 | #include "PN532.h" |
dotnfc | 0:db8030e71f55 | 15 | |
dotnfc | 0:db8030e71f55 | 16 | #define NDEF_MAX_LENGTH 128 // altough ndef can handle up to 0xfffe in size, arduino cannot. |
dotnfc | 0:db8030e71f55 | 17 | typedef enum {COMMAND_COMPLETE, TAG_NOT_FOUND, FUNCTION_NOT_SUPPORTED, MEMORY_FAILURE, END_OF_FILE_BEFORE_REACHED_LE_BYTES} responseCommand; |
dotnfc | 0:db8030e71f55 | 18 | |
dotnfc | 0:db8030e71f55 | 19 | class EmulateTag{ |
dotnfc | 0:db8030e71f55 | 20 | |
dotnfc | 0:db8030e71f55 | 21 | public: |
dotnfc | 0:db8030e71f55 | 22 | EmulateTag(PN532Interface &interface) : pn532(interface), uidPtr(0), tagWrittenByInitiator(false), tagWriteable(true), updateNdefCallback(0) { } |
dotnfc | 0:db8030e71f55 | 23 | |
dotnfc | 0:db8030e71f55 | 24 | bool init(); |
dotnfc | 0:db8030e71f55 | 25 | |
dotnfc | 0:db8030e71f55 | 26 | bool emulate(const uint16_t tgInitAsTargetTimeout = 0); |
dotnfc | 0:db8030e71f55 | 27 | |
dotnfc | 0:db8030e71f55 | 28 | /* |
dotnfc | 0:db8030e71f55 | 29 | * @param uid pointer to byte array of length 3 (uid is 4 bytes - first byte is fixed) or zero for uid |
dotnfc | 0:db8030e71f55 | 30 | */ |
dotnfc | 0:db8030e71f55 | 31 | void setUid(uint8_t* uid = 0); |
dotnfc | 0:db8030e71f55 | 32 | |
dotnfc | 0:db8030e71f55 | 33 | void setNdefFile(const uint8_t* ndef, const int16_t ndefLength); |
dotnfc | 0:db8030e71f55 | 34 | |
dotnfc | 0:db8030e71f55 | 35 | void getContent(uint8_t** buf, uint16_t* length){ |
dotnfc | 0:db8030e71f55 | 36 | *buf = ndef_file + 2; // first 2 bytes = length |
dotnfc | 0:db8030e71f55 | 37 | *length = (ndef_file[0] << 8) + ndef_file[1]; |
dotnfc | 0:db8030e71f55 | 38 | } |
dotnfc | 0:db8030e71f55 | 39 | |
dotnfc | 0:db8030e71f55 | 40 | bool writeOccured(){ |
dotnfc | 0:db8030e71f55 | 41 | return tagWrittenByInitiator; |
dotnfc | 0:db8030e71f55 | 42 | } |
dotnfc | 0:db8030e71f55 | 43 | |
dotnfc | 0:db8030e71f55 | 44 | void setTagWriteable(bool setWriteable){ |
dotnfc | 0:db8030e71f55 | 45 | tagWriteable = setWriteable; |
dotnfc | 0:db8030e71f55 | 46 | } |
dotnfc | 0:db8030e71f55 | 47 | |
dotnfc | 0:db8030e71f55 | 48 | uint8_t* getNdefFilePtr(){ |
dotnfc | 0:db8030e71f55 | 49 | return ndef_file; |
dotnfc | 0:db8030e71f55 | 50 | } |
dotnfc | 0:db8030e71f55 | 51 | |
dotnfc | 0:db8030e71f55 | 52 | uint8_t getNdefMaxLength(){ |
dotnfc | 0:db8030e71f55 | 53 | return NDEF_MAX_LENGTH; |
dotnfc | 0:db8030e71f55 | 54 | } |
dotnfc | 0:db8030e71f55 | 55 | |
dotnfc | 0:db8030e71f55 | 56 | void attach(void (*func)(uint8_t *buf, uint16_t length)) { |
dotnfc | 0:db8030e71f55 | 57 | updateNdefCallback = func; |
dotnfc | 0:db8030e71f55 | 58 | }; |
dotnfc | 0:db8030e71f55 | 59 | |
dotnfc | 0:db8030e71f55 | 60 | private: |
dotnfc | 0:db8030e71f55 | 61 | PN532 pn532; |
dotnfc | 0:db8030e71f55 | 62 | uint8_t ndef_file[NDEF_MAX_LENGTH]; |
dotnfc | 0:db8030e71f55 | 63 | uint8_t* uidPtr; |
dotnfc | 0:db8030e71f55 | 64 | bool tagWrittenByInitiator; |
dotnfc | 0:db8030e71f55 | 65 | bool tagWriteable; |
dotnfc | 0:db8030e71f55 | 66 | void (*updateNdefCallback)(uint8_t *ndef, uint16_t length); |
dotnfc | 0:db8030e71f55 | 67 | |
dotnfc | 0:db8030e71f55 | 68 | void setResponse(responseCommand cmd, uint8_t* buf, uint8_t* sendlen, uint8_t sendlenOffset = 0); |
dotnfc | 0:db8030e71f55 | 69 | }; |
dotnfc | 0:db8030e71f55 | 70 | |
dotnfc | 0:db8030e71f55 | 71 | #endif |