to colorize a colorful pixel with a simple touch using nfc technology

Dependencies:   Chainable_RGB_LED mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers llcp.h Source File

llcp.h

00001 
00002 #ifndef __LLCP_H__
00003 #define __LLCP_H__
00004 
00005 #include "mac_link.h"
00006 
00007 #define LLCP_DEFAULT_TIMEOUT  20000
00008 #define LLCP_DEFAULT_DSAP     0x04
00009 #define LLCP_DEFAULT_SSAP     0x20
00010 
00011 class LLCP {
00012 public:
00013     LLCP(PN532Interface &interface) : link(interface) {
00014         headerBuf = link.getHeaderBuffer(&headerBufLen);
00015         ns = 0;
00016         nr = 0;
00017     };
00018 
00019     /**
00020     * @brief    Actiave PN532 as a target
00021     * @param    timeout max time to wait, 0 means no timeout
00022     * @return   > 0     success
00023     *           = 0     timeout
00024     *           < 0     failed
00025     */
00026     int8_t activate(uint16_t timeout = 0);
00027 
00028     int8_t waitForConnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT);
00029 
00030     int8_t waitForDisconnection(uint16_t timeout = LLCP_DEFAULT_TIMEOUT);
00031 
00032     int8_t connect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT);
00033 
00034     int8_t disconnect(uint16_t timeout = LLCP_DEFAULT_TIMEOUT);
00035 
00036     /**
00037     * @brief    write a packet, the packet should be less than (255 - 2) bytes
00038     * @param    header  packet header
00039     * @param    hlen    length of header
00040     * @param    body    packet body
00041     * @param    blen    length of body
00042     * @return   true    success
00043     *           false   failed
00044     */
00045     bool write(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0);
00046 
00047     /**
00048     * @brief    read a  packet, the packet will be less than (255 - 2) bytes
00049     * @param    buf     the buffer to contain the packet
00050     * @param    len     lenght of the buffer
00051     * @return   >=0     length of the packet 
00052     *           <0      failed
00053     */
00054     int16_t read(uint8_t *buf, uint8_t len);
00055 
00056     uint8_t *getHeaderBuffer(uint8_t *len) {
00057         uint8_t *buf = link.getHeaderBuffer(len);
00058         len -= 3;       // I PDU header has 3 bytes
00059         return buf;
00060     };
00061 
00062 private:
00063     MACLink link;
00064     uint8_t mode;
00065     uint8_t ssap;
00066     uint8_t dsap;
00067     uint8_t *headerBuf;
00068     uint8_t headerBufLen;
00069     uint8_t ns;         // Number of I PDU Sent
00070     uint8_t nr;         // Number of I PDU Received
00071 
00072     static uint8_t SYMM_PDU[2];
00073 };
00074 
00075 #endif // __LLCP_H__