PN532 NFC library for Seeed Studio's NFC Shield
Fork of PN532 by
snep.h@3:4189a10038e6, 2013-11-21 (annotated)
- Committer:
- yihui
- Date:
- Thu Nov 21 04:30:49 2013 +0000
- Revision:
- 3:4189a10038e6
- Child:
- 6: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 | |
yihui | 3:4189a10038e6 | 3 | #ifndef __SNEP_H__ |
yihui | 3:4189a10038e6 | 4 | #define __SNEP_H__ |
yihui | 3:4189a10038e6 | 5 | |
yihui | 3:4189a10038e6 | 6 | #include "llcp.h" |
yihui | 3:4189a10038e6 | 7 | |
yihui | 3:4189a10038e6 | 8 | #define SNEP_DEFAULT_VERSION 0x10 // Major: 1, Minor: 0 |
yihui | 3:4189a10038e6 | 9 | |
yihui | 3:4189a10038e6 | 10 | #define SNEP_REQUEST_PUT 0x02 |
yihui | 3:4189a10038e6 | 11 | #define SNEP_REQUEST_GET 0x01 |
yihui | 3:4189a10038e6 | 12 | |
yihui | 3:4189a10038e6 | 13 | #define SNEP_RESPONSE_SUCCESS 0x81 |
yihui | 3:4189a10038e6 | 14 | #define SNEP_RESPONSE_REJECT 0xFF |
yihui | 3:4189a10038e6 | 15 | |
yihui | 3:4189a10038e6 | 16 | class SNEP { |
yihui | 3:4189a10038e6 | 17 | public: |
yihui | 3:4189a10038e6 | 18 | SNEP(PN532Interface &interface) : llcp(interface) { |
yihui | 3:4189a10038e6 | 19 | headerBuf = llcp.getHeaderBuffer(&headerBufLen); |
yihui | 3:4189a10038e6 | 20 | }; |
yihui | 3:4189a10038e6 | 21 | |
yihui | 3:4189a10038e6 | 22 | /** |
yihui | 3:4189a10038e6 | 23 | * @brief write a SNEP packet, the packet should be less than (255 - 2 - 3) bytes |
yihui | 3:4189a10038e6 | 24 | * @param buf the buffer to contain the packet |
yihui | 3:4189a10038e6 | 25 | * @param len lenght of the buffer |
yihui | 3:4189a10038e6 | 26 | * @param timeout max time to wait, 0 means no timeout |
yihui | 3:4189a10038e6 | 27 | * @return >0 success |
yihui | 3:4189a10038e6 | 28 | * =0 timeout |
yihui | 3:4189a10038e6 | 29 | * <0 failed |
yihui | 3:4189a10038e6 | 30 | */ |
yihui | 3:4189a10038e6 | 31 | int8_t write(const uint8_t *buf, uint8_t len, uint16_t timeout = 0); |
yihui | 3:4189a10038e6 | 32 | |
yihui | 3:4189a10038e6 | 33 | /** |
yihui | 3:4189a10038e6 | 34 | * @brief read a SNEP packet, the packet will be less than (255 - 2 - 3) bytes |
yihui | 3:4189a10038e6 | 35 | * @param buf the buffer to contain the packet |
yihui | 3:4189a10038e6 | 36 | * @param len lenght of the buffer |
yihui | 3:4189a10038e6 | 37 | * @param timeout max time to wait, 0 means no timeout |
yihui | 3:4189a10038e6 | 38 | * @return >=0 length of the packet |
yihui | 3:4189a10038e6 | 39 | * <0 failed |
yihui | 3:4189a10038e6 | 40 | */ |
yihui | 3:4189a10038e6 | 41 | int16_t read(uint8_t *buf, uint8_t len, uint16_t timeout = 0); |
yihui | 3:4189a10038e6 | 42 | |
yihui | 3:4189a10038e6 | 43 | private: |
yihui | 3:4189a10038e6 | 44 | LLCP llcp; |
yihui | 3:4189a10038e6 | 45 | uint8_t *headerBuf; |
yihui | 3:4189a10038e6 | 46 | uint8_t headerBufLen; |
yihui | 3:4189a10038e6 | 47 | }; |
yihui | 3:4189a10038e6 | 48 | |
yihui | 3:4189a10038e6 | 49 | #endif // __SNEP_H__ |