Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PN532 by
llcp.h@5:418ee8924317, 2014-03-25 (annotated)
- Committer:
- screamer
- Date:
- Tue Mar 25 16:00:44 2014 +0000
- Revision:
- 5:418ee8924317
- Parent:
- 3:4189a10038e6
Improved documentation
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 | |
screamer | 5:418ee8924317 | 11 | /** |
screamer | 5:418ee8924317 | 12 | * The LLCP class |
screamer | 5:418ee8924317 | 13 | */ |
yihui | 3:4189a10038e6 | 14 | class LLCP { |
yihui | 3:4189a10038e6 | 15 | public: |
yihui | 3:4189a10038e6 | 16 | LLCP(PN532Interface &interface) : link(interface) { |
yihui | 3:4189a10038e6 | 17 | headerBuf = link.getHeaderBuffer(&headerBufLen); |
yihui | 3:4189a10038e6 | 18 | ns = 0; |
yihui | 3:4189a10038e6 | 19 | nr = 0; |
yihui | 3:4189a10038e6 | 20 | }; |
yihui | 3:4189a10038e6 | 21 | |
yihui | 3:4189a10038e6 | 22 | /** |
screamer | 5:418ee8924317 | 23 | * @brief Actiave PN532 as a target |
screamer | 5:418ee8924317 | 24 | * @param timeout max time to wait, 0 means no timeout |
screamer | 5:418ee8924317 | 25 | * @return > 0 success |
screamer | 5:418ee8924317 | 26 | * = 0 timeout |
screamer | 5:418ee8924317 | 27 | * < 0 failed |
screamer | 5:418ee8924317 | 28 | */ |
yihui | 3:4189a10038e6 | 29 | int8_t activate(uint16_t timeout = 0); |
yihui | 3:4189a10038e6 | 30 | |
yihui | 3:4189a10038e6 | 31 | int8_t waitForConnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 3:4189a10038e6 | 32 | |
yihui | 3:4189a10038e6 | 33 | int8_t waitForDisconnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 3:4189a10038e6 | 34 | |
yihui | 3:4189a10038e6 | 35 | int8_t connect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 3:4189a10038e6 | 36 | |
yihui | 3:4189a10038e6 | 37 | int8_t disconnect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT); |
yihui | 3:4189a10038e6 | 38 | |
yihui | 3:4189a10038e6 | 39 | /** |
screamer | 5:418ee8924317 | 40 | * @brief write a packet, the packet should be less than (255 - 2) bytes |
screamer | 5:418ee8924317 | 41 | * @param header packet header |
screamer | 5:418ee8924317 | 42 | * @param hlen length of header |
screamer | 5:418ee8924317 | 43 | * @param body packet body |
screamer | 5:418ee8924317 | 44 | * @param blen length of body |
screamer | 5:418ee8924317 | 45 | * @return true success |
screamer | 5:418ee8924317 | 46 | * false failed |
screamer | 5:418ee8924317 | 47 | */ |
yihui | 3:4189a10038e6 | 48 | bool write(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0); |
yihui | 3:4189a10038e6 | 49 | |
yihui | 3:4189a10038e6 | 50 | /** |
screamer | 5:418ee8924317 | 51 | * @brief read a packet, the packet will be less than (255 - 2) bytes |
screamer | 5:418ee8924317 | 52 | * @param buf the buffer to contain the packet |
screamer | 5:418ee8924317 | 53 | * @param len lenght of the buffer |
screamer | 5:418ee8924317 | 54 | * @return >=0 length of the packet |
screamer | 5:418ee8924317 | 55 | * <0 failed |
screamer | 5:418ee8924317 | 56 | */ |
yihui | 3:4189a10038e6 | 57 | int16_t read(uint8_t *buf, uint8_t len); |
yihui | 3:4189a10038e6 | 58 | |
yihui | 3:4189a10038e6 | 59 | uint8_t *getHeaderBuffer(uint8_t *len) { |
yihui | 3:4189a10038e6 | 60 | uint8_t *buf = link.getHeaderBuffer(len); |
yihui | 3:4189a10038e6 | 61 | len -= 3; // I PDU header has 3 bytes |
yihui | 3:4189a10038e6 | 62 | return buf; |
yihui | 3:4189a10038e6 | 63 | }; |
yihui | 3:4189a10038e6 | 64 | |
yihui | 3:4189a10038e6 | 65 | private: |
yihui | 3:4189a10038e6 | 66 | MACLink link; |
yihui | 3:4189a10038e6 | 67 | uint8_t ssap; |
yihui | 3:4189a10038e6 | 68 | uint8_t dsap; |
yihui | 3:4189a10038e6 | 69 | uint8_t *headerBuf; |
yihui | 3:4189a10038e6 | 70 | uint8_t headerBufLen; |
yihui | 3:4189a10038e6 | 71 | uint8_t ns; // Number of I PDU Sent |
yihui | 3:4189a10038e6 | 72 | uint8_t nr; // Number of I PDU Received |
yihui | 3:4189a10038e6 | 73 | |
yihui | 3:4189a10038e6 | 74 | static uint8_t SYMM_PDU[2]; |
yihui | 3:4189a10038e6 | 75 | }; |
yihui | 3:4189a10038e6 | 76 | |
yihui | 3:4189a10038e6 | 77 | #endif // __LLCP_H__ |