Generic library for working with PN532-like chips
Fork of PN532 by
emulatetag.h@11:5b8afec8bee6, 2015-02-04 (annotated)
- Committer:
- r4z0r7o3
- Date:
- Wed Feb 04 19:26:03 2015 +0000
- Revision:
- 11:5b8afec8bee6
- Parent:
- 3:4189a10038e6
Fix missing space in tag print()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 3:4189a10038e6 | 1 | /**************************************************************************/ |
yihui | 3:4189a10038e6 | 2 | /*! |
yihui | 3:4189a10038e6 | 3 | @file emulatetag.h |
yihui | 3:4189a10038e6 | 4 | @author Armin Wieser |
yihui | 3:4189a10038e6 | 5 | @license BSD |
yihui | 3:4189a10038e6 | 6 | |
yihui | 3:4189a10038e6 | 7 | Implemented using NFC forum documents & library of libnfc |
yihui | 3:4189a10038e6 | 8 | */ |
yihui | 3:4189a10038e6 | 9 | /**************************************************************************/ |
yihui | 3:4189a10038e6 | 10 | |
yihui | 3:4189a10038e6 | 11 | |
yihui | 3:4189a10038e6 | 12 | #ifndef __EMULATETAG_H__ |
yihui | 3:4189a10038e6 | 13 | #define __EMULATETAG_H__ |
yihui | 3:4189a10038e6 | 14 | |
yihui | 3:4189a10038e6 | 15 | #include "PN532.h" |
yihui | 3:4189a10038e6 | 16 | |
yihui | 3:4189a10038e6 | 17 | #define NDEF_MAX_LENGTH 128 // altough ndef can handle up to 0xfffe in size, arduino cannot. |
yihui | 3:4189a10038e6 | 18 | typedef enum {COMMAND_COMPLETE, TAG_NOT_FOUND, FUNCTION_NOT_SUPPORTED, MEMORY_FAILURE, END_OF_FILE_BEFORE_REACHED_LE_BYTES} responseCommand; |
yihui | 3:4189a10038e6 | 19 | |
yihui | 3:4189a10038e6 | 20 | class EmulateTag{ |
yihui | 3:4189a10038e6 | 21 | |
yihui | 3:4189a10038e6 | 22 | public: |
yihui | 3:4189a10038e6 | 23 | EmulateTag(PN532Interface &interface) : pn532(interface), uidPtr(0), tagWrittenByInitiator(false) { } |
yihui | 3:4189a10038e6 | 24 | |
yihui | 3:4189a10038e6 | 25 | bool init(); |
yihui | 3:4189a10038e6 | 26 | |
yihui | 3:4189a10038e6 | 27 | bool emulate(const uint16_t tgInitAsTargetTimeout = 0); |
yihui | 3:4189a10038e6 | 28 | |
yihui | 3:4189a10038e6 | 29 | /* |
yihui | 3:4189a10038e6 | 30 | * @param uid pointer to byte array of length 3 (uid is 4 bytes - first byte is fixed) or zero for uid |
yihui | 3:4189a10038e6 | 31 | */ |
yihui | 3:4189a10038e6 | 32 | void setUid(uint8_t* uid = 0); |
yihui | 3:4189a10038e6 | 33 | |
yihui | 3:4189a10038e6 | 34 | void setNdefFile(const uint8_t* ndef, const int16_t ndefLength); |
yihui | 3:4189a10038e6 | 35 | |
yihui | 3:4189a10038e6 | 36 | void getContent(uint8_t** buf, uint16_t* length){ |
yihui | 3:4189a10038e6 | 37 | *buf = ndef_file + 2; // first 2 bytes = length |
yihui | 3:4189a10038e6 | 38 | *length = (ndef_file[1] << 8) + ndef_file[0]; |
yihui | 3:4189a10038e6 | 39 | } |
yihui | 3:4189a10038e6 | 40 | |
yihui | 3:4189a10038e6 | 41 | bool writeOccured(){ |
yihui | 3:4189a10038e6 | 42 | return tagWrittenByInitiator; |
yihui | 3:4189a10038e6 | 43 | } |
yihui | 3:4189a10038e6 | 44 | |
yihui | 3:4189a10038e6 | 45 | private: |
yihui | 3:4189a10038e6 | 46 | PN532 pn532; |
yihui | 3:4189a10038e6 | 47 | uint8_t ndef_file[NDEF_MAX_LENGTH]; |
yihui | 3:4189a10038e6 | 48 | uint8_t* uidPtr; |
yihui | 3:4189a10038e6 | 49 | void setResponse(responseCommand cmd, uint8_t* buf, uint8_t* sendlen, uint8_t sendlenOffset =0); |
yihui | 3:4189a10038e6 | 50 | bool tagWrittenByInitiator; |
yihui | 3:4189a10038e6 | 51 | }; |
yihui | 3:4189a10038e6 | 52 | |
yihui | 3:4189a10038e6 | 53 | #endif |