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/llcp.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 | #ifndef __LLCP_H__ |
dotnfc | 0:db8030e71f55 | 3 | #define __LLCP_H__ |
dotnfc | 0:db8030e71f55 | 4 | |
dotnfc | 0:db8030e71f55 | 5 | #include "mac_link.h" |
dotnfc | 0:db8030e71f55 | 6 | |
dotnfc | 0:db8030e71f55 | 7 | #define LLCP_DEFAULT_TIMEOUT 20000 |
dotnfc | 0:db8030e71f55 | 8 | #define LLCP_DEFAULT_DSAP 0x04 |
dotnfc | 0:db8030e71f55 | 9 | #define LLCP_DEFAULT_SSAP 0x20 |
dotnfc | 0:db8030e71f55 | 10 | |
dotnfc | 0:db8030e71f55 | 11 | class LLCP { |
dotnfc | 0:db8030e71f55 | 12 | public: |
dotnfc | 0:db8030e71f55 | 13 | LLCP(PN532Interface &interface) : link(interface) { |
dotnfc | 0:db8030e71f55 | 14 | headerBuf = link.getHeaderBuffer(&headerBufLen); |
dotnfc | 0:db8030e71f55 | 15 | ns = 0; |
dotnfc | 0:db8030e71f55 | 16 | nr = 0; |
dotnfc | 0:db8030e71f55 | 17 | }; |
dotnfc | 0:db8030e71f55 | 18 | |
dotnfc | 0:db8030e71f55 | 19 | /** |
dotnfc | 0:db8030e71f55 | 20 | * @brief Actiave PN532 as a target |
dotnfc | 0:db8030e71f55 | 21 | * @param timeout max time to wait, 0 means no timeout |
dotnfc | 0:db8030e71f55 | 22 | * @return > 0 success |
dotnfc | 0:db8030e71f55 | 23 | * = 0 timeout |
dotnfc | 0:db8030e71f55 | 24 | * < 0 failed |
dotnfc | 0:db8030e71f55 | 25 | */ |
dotnfc | 0:db8030e71f55 | 26 | int8_t activate(uint16_t timeout = 0); |
dotnfc | 0:db8030e71f55 | 27 | |
dotnfc | 0:db8030e71f55 | 28 | int8_t waitForConnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
dotnfc | 0:db8030e71f55 | 29 | |
dotnfc | 0:db8030e71f55 | 30 | int8_t waitForDisconnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
dotnfc | 0:db8030e71f55 | 31 | |
dotnfc | 0:db8030e71f55 | 32 | int8_t connect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
dotnfc | 0:db8030e71f55 | 33 | |
dotnfc | 0:db8030e71f55 | 34 | int8_t disconnect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
dotnfc | 0:db8030e71f55 | 35 | |
dotnfc | 0:db8030e71f55 | 36 | /** |
dotnfc | 0:db8030e71f55 | 37 | * @brief write a packet, the packet should be less than (255 - 2) bytes |
dotnfc | 0:db8030e71f55 | 38 | * @param header packet header |
dotnfc | 0:db8030e71f55 | 39 | * @param hlen length of header |
dotnfc | 0:db8030e71f55 | 40 | * @param body packet body |
dotnfc | 0:db8030e71f55 | 41 | * @param blen length of body |
dotnfc | 0:db8030e71f55 | 42 | * @return true success |
dotnfc | 0:db8030e71f55 | 43 | * false failed |
dotnfc | 0:db8030e71f55 | 44 | */ |
dotnfc | 0:db8030e71f55 | 45 | bool write(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0); |
dotnfc | 0:db8030e71f55 | 46 | |
dotnfc | 0:db8030e71f55 | 47 | /** |
dotnfc | 0:db8030e71f55 | 48 | * @brief read a packet, the packet will be less than (255 - 2) bytes |
dotnfc | 0:db8030e71f55 | 49 | * @param buf the buffer to contain the packet |
dotnfc | 0:db8030e71f55 | 50 | * @param len lenght of the buffer |
dotnfc | 0:db8030e71f55 | 51 | * @return >=0 length of the packet |
dotnfc | 0:db8030e71f55 | 52 | * <0 failed |
dotnfc | 0:db8030e71f55 | 53 | */ |
dotnfc | 0:db8030e71f55 | 54 | int16_t read(uint8_t *buf, uint8_t len); |
dotnfc | 0:db8030e71f55 | 55 | |
dotnfc | 0:db8030e71f55 | 56 | uint8_t *getHeaderBuffer(uint8_t *len) { |
dotnfc | 0:db8030e71f55 | 57 | uint8_t *buf = link.getHeaderBuffer(len); |
dotnfc | 0:db8030e71f55 | 58 | len -= 3; // I PDU header has 3 bytes |
dotnfc | 0:db8030e71f55 | 59 | return buf; |
dotnfc | 0:db8030e71f55 | 60 | }; |
dotnfc | 0:db8030e71f55 | 61 | |
dotnfc | 0:db8030e71f55 | 62 | private: |
dotnfc | 0:db8030e71f55 | 63 | MACLink link; |
dotnfc | 0:db8030e71f55 | 64 | uint8_t mode; |
dotnfc | 0:db8030e71f55 | 65 | uint8_t ssap; |
dotnfc | 0:db8030e71f55 | 66 | uint8_t dsap; |
dotnfc | 0:db8030e71f55 | 67 | uint8_t *headerBuf; |
dotnfc | 0:db8030e71f55 | 68 | uint8_t headerBufLen; |
dotnfc | 0:db8030e71f55 | 69 | uint8_t ns; // Number of I PDU Sent |
dotnfc | 0:db8030e71f55 | 70 | uint8_t nr; // Number of I PDU Received |
dotnfc | 0:db8030e71f55 | 71 | |
dotnfc | 0:db8030e71f55 | 72 | static uint8_t SYMM_PDU[2]; |
dotnfc | 0:db8030e71f55 | 73 | }; |
dotnfc | 0:db8030e71f55 | 74 | |
dotnfc | 0:db8030e71f55 | 75 | #endif // __LLCP_H__ |