NFC library using PN532 to read/write NDEF Messages to NFC tags
Dependents: Seeed_NFC_Shield_write Nucleo_test_nfc
Fork of PN532 by
llcp.h@3:4189a10038e6, 2013-11-21 (annotated)
- Committer:
- yihui
- Date:
- Thu Nov 21 04:30:49 2013 +0000
- Revision:
- 3:4189a10038e6
- Child:
- 5:418ee8924317
sync with https://github.com/Seeed-Studio/PN532/releases/tag/v0.9.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 3:4189a10038e6 | 1 | |
yihui | 3:4189a10038e6 | 2 | #ifndef __LLCP_H__ |
yihui | 3:4189a10038e6 | 3 | #define __LLCP_H__ |
yihui | 3:4189a10038e6 | 4 | |
yihui | 3:4189a10038e6 | 5 | #include "mac_link.h" |
yihui | 3:4189a10038e6 | 6 | |
yihui | 3:4189a10038e6 | 7 | #define LLCP_DEFAULT_TIMEOUT 20000 |
yihui | 3:4189a10038e6 | 8 | #define LLCP_DEFAULT_DSAP 0x04 |
yihui | 3:4189a10038e6 | 9 | #define LLCP_DEFAULT_SSAP 0x20 |
yihui | 3:4189a10038e6 | 10 | |
yihui | 3:4189a10038e6 | 11 | class LLCP { |
yihui | 3:4189a10038e6 | 12 | public: |
yihui | 3:4189a10038e6 | 13 | LLCP(PN532Interface &interface) : link(interface) { |
yihui | 3:4189a10038e6 | 14 | headerBuf = link.getHeaderBuffer(&headerBufLen); |
yihui | 3:4189a10038e6 | 15 | ns = 0; |
yihui | 3:4189a10038e6 | 16 | nr = 0; |
yihui | 3:4189a10038e6 | 17 | }; |
yihui | 3:4189a10038e6 | 18 | |
yihui | 3:4189a10038e6 | 19 | /** |
yihui | 3:4189a10038e6 | 20 | * @brief Actiave PN532 as a target |
yihui | 3:4189a10038e6 | 21 | * @param timeout max time to wait, 0 means no timeout |
yihui | 3:4189a10038e6 | 22 | * @return > 0 success |
yihui | 3:4189a10038e6 | 23 | * = 0 timeout |
yihui | 3:4189a10038e6 | 24 | * < 0 failed |
yihui | 3:4189a10038e6 | 25 | */ |
yihui | 3:4189a10038e6 | 26 | int8_t activate(uint16_t timeout = 0); |
yihui | 3:4189a10038e6 | 27 | |
yihui | 3:4189a10038e6 | 28 | int8_t waitForConnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 3:4189a10038e6 | 29 | |
yihui | 3:4189a10038e6 | 30 | int8_t waitForDisconnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 3:4189a10038e6 | 31 | |
yihui | 3:4189a10038e6 | 32 | int8_t connect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 3:4189a10038e6 | 33 | |
yihui | 3:4189a10038e6 | 34 | int8_t disconnect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 3:4189a10038e6 | 35 | |
yihui | 3:4189a10038e6 | 36 | /** |
yihui | 3:4189a10038e6 | 37 | * @brief write a packet, the packet should be less than (255 - 2) bytes |
yihui | 3:4189a10038e6 | 38 | * @param header packet header |
yihui | 3:4189a10038e6 | 39 | * @param hlen length of header |
yihui | 3:4189a10038e6 | 40 | * @param body packet body |
yihui | 3:4189a10038e6 | 41 | * @param blen length of body |
yihui | 3:4189a10038e6 | 42 | * @return true success |
yihui | 3:4189a10038e6 | 43 | * false failed |
yihui | 3:4189a10038e6 | 44 | */ |
yihui | 3:4189a10038e6 | 45 | bool write(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0); |
yihui | 3:4189a10038e6 | 46 | |
yihui | 3:4189a10038e6 | 47 | /** |
yihui | 3:4189a10038e6 | 48 | * @brief read a packet, the packet will be less than (255 - 2) bytes |
yihui | 3:4189a10038e6 | 49 | * @param buf the buffer to contain the packet |
yihui | 3:4189a10038e6 | 50 | * @param len lenght of the buffer |
yihui | 3:4189a10038e6 | 51 | * @return >=0 length of the packet |
yihui | 3:4189a10038e6 | 52 | * <0 failed |
yihui | 3:4189a10038e6 | 53 | */ |
yihui | 3:4189a10038e6 | 54 | int16_t read(uint8_t *buf, uint8_t len); |
yihui | 3:4189a10038e6 | 55 | |
yihui | 3:4189a10038e6 | 56 | uint8_t *getHeaderBuffer(uint8_t *len) { |
yihui | 3:4189a10038e6 | 57 | uint8_t *buf = link.getHeaderBuffer(len); |
yihui | 3:4189a10038e6 | 58 | len -= 3; // I PDU header has 3 bytes |
yihui | 3:4189a10038e6 | 59 | return buf; |
yihui | 3:4189a10038e6 | 60 | }; |
yihui | 3:4189a10038e6 | 61 | |
yihui | 3:4189a10038e6 | 62 | private: |
yihui | 3:4189a10038e6 | 63 | MACLink link; |
yihui | 3:4189a10038e6 | 64 | uint8_t ssap; |
yihui | 3:4189a10038e6 | 65 | uint8_t dsap; |
yihui | 3:4189a10038e6 | 66 | uint8_t *headerBuf; |
yihui | 3:4189a10038e6 | 67 | uint8_t headerBufLen; |
yihui | 3:4189a10038e6 | 68 | uint8_t ns; // Number of I PDU Sent |
yihui | 3:4189a10038e6 | 69 | uint8_t nr; // Number of I PDU Received |
yihui | 3:4189a10038e6 | 70 | |
yihui | 3:4189a10038e6 | 71 | static uint8_t SYMM_PDU[2]; |
yihui | 3:4189a10038e6 | 72 | }; |
yihui | 3:4189a10038e6 | 73 | |
yihui | 3:4189a10038e6 | 74 | #endif // __LLCP_H__ |