Utility library to read and write Ndef messages from/to a Type4 NFC tag
Dependents: NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more
Fork of NDefLib by
NDEF NFC library
This library provides an abstract API to create NDEF formatted messages and records and to read/write them from/to a Type4 NFC Tag.
Implementations
At the moment, the NDEF API is implemented by X_NUCLEO_NFC01A1 and X_NUCLEO_NFC02A1 Dynamic NFC Tag libraries respectively driving the X-NUCLEO-NFC01A1 and X-NUCLEO-NFC02A1 boards.
Diff: NDefNfcTag.h
- Revision:
- 16:030e7ffdf512
- Parent:
- 15:01fc5a4b8366
- Child:
- 19:13d84b136a62
--- a/NDefNfcTag.h Mon Feb 01 15:33:11 2016 +0000 +++ b/NDefNfcTag.h Tue Feb 02 16:04:15 2016 +0000 @@ -4,7 +4,7 @@ * @author ST / Central Labs * @version V1.0.0 * @date 21 Jan 2016 - * @brief Generic interface that a device must implement for use the NDefLib + * @brief Generic interface that a device must implement to use the NDefLib * with async communication ****************************************************************************** * @attention @@ -45,8 +45,8 @@ /** * Abstract class used to write/read NDef messages to/from a nfc tag. - * This class is made for handle also asynchronous communication with the nfc component. - * All the function in this class will return immediately, when a command end a proper callback function will + * This class is made to handle also asynchronous communication with the nfc component. + * All the functions in this class will return immediately, when a command ends a proper callback function will * be called. */ class NDefNfcTag { @@ -54,25 +54,25 @@ public: /** - * Class that contains all the function called when a command finish. + * Class that contains all the function called when a command finished. * The default implementation is an empty function. */ - class Callback { + class Callbacks { public: /** * Called when a session is open. - * @param tag tag where the session is open. - * @param success true if the operation has success. + * @param tag Tag where the session is open. + * @param success True if the operation has success. */ virtual void onSessionOpen(NDefNfcTag *tag,bool success){ (void)tag;(void)success; }; /** - * Called when a message is write. - * @param tag tag where the message is wrote. - * @param success true if the operation has success. + * Called when a message is written. + * @param tag Tag where the message is written. + * @param success True if the operation has success. */ virtual void onMessageWrite(NDefNfcTag *tag,bool success, const Message &msg){ @@ -82,8 +82,8 @@ /** * Called when a message is read. - * @param tag tag where the message is read. - * @param success true if the operation has success. + * @param tag Tag where the message is read. + * @param success True if the operation has success. */ virtual void onMessageRead(NDefNfcTag *tag,bool success, const Message *msg){ @@ -92,26 +92,28 @@ /** - * Called when a session is close. - * @param tag tag where the session is close. - * @param success true if the operation has success. + * Called when a session is closed. + * @param tag Tag where the session is closed. + * @param success True if the operation has success. */ virtual void onSessionClose(NDefNfcTag *tag,bool success){ (void)tag;(void)success; }; - virtual ~Callback(){}; + virtual ~Callbacks(){}; }; private: /** - * Data used for store the callback status. + * Data used to store the callback status during a read/write operation. */ struct CallbackStatus{ - /**object that start the callback */ + + /** Object that triggers the callback */ NDefNfcTag *callOwner; - /** message that the callback is manage */ + + /** Message that the callback is writing/reading */ Message *msg; }; @@ -120,11 +122,14 @@ NDefNfcTag():mCallBack(&mDefaultCallBack){} /** - * Set the callback. - * @param c object contains the callback. + * Set the callback object. + * @param c Object containing the callback. */ - void setCallback(Callback *c){ - mCallBack=c; + void setCallback(Callbacks *c){ + if(c!=NULL) + mCallBack=c; + else + mCallBack=&mDefaultCallBack; }//setCallBack @@ -203,23 +208,23 @@ typedef struct CallbackStatus CallbackStatus_t; /** - * Function that the component has to call when it finish a read/write operation - * @param interalState callback internal state data - * @param status true if the operation success - * @param buffer buffer write/read - * @param length number of byte read/write + * Function that the component will call when a read/write operation is completed + * @param internalState Callback internal state data. + * @param status True if the operation succeed. + * @param buffer Buffer to read/write. + * @param length Number of byte read/write. * @return true if the operation had success */ - typedef bool(*byteOperationCallback_t)(CallbackStatus_t *interalState, + typedef bool(*byteOperationCallback_t)(CallbackStatus_t *internalState, bool status,const uint8_t *buffer, uint16_t length); /** * Write a sequence of bytes to the NDEF file. - * @param buffer buffer to write - * @param length number of bytes to write - * @param offset offset where start to write - * @param callback function to call when the operation ended - * @param callbackStatus parameter to pass to the callback function + * @param buffer Buffer to write. + * @param length Number of bytes to write. + * @param offset Offset where start to write. + * @param callback Function to call when the operation ended. + * @param callbackStatus Parameter to pass to the callback function. * @return true if the operation has success */ virtual bool writeByte(const uint8_t *buffer, uint16_t length,uint16_t offset, @@ -230,29 +235,29 @@ * @param byteOffset Read offset in bytes. * @param byteLength Number of bytes to read. * @param[out] buffer Buffer to store the read data into. - * @param callback function to call when the operation ended - * @param callbackStatus parameter to pass to the callback function - * @return true if success + * @param callback Function to call when the operation ended. + * @param callbackStatus Parameter to pass to the callback function. + * @return true if the operation has success */ virtual bool readByte(const uint16_t byteOffset, const uint16_t byteLength, uint8_t *buffer, byteOperationCallback_t callback,CallbackStatus_t *callbackStatus)=0; /** object with the user callback */ - Callback *mCallBack; + Callbacks *mCallBack; private: /** object with the current callback status */ CallbackStatus_t mCallBackStatus; - /** default callback object, all the function are empty */ - Callback mDefaultCallBack; + /** default callback object, all the functions are empty */ + Callbacks mDefaultCallBack; /** - * Function that the user will call when a write end, it will invoke onMessageWrite - * @param internalState Object that invoke the write operation. + * Function called when a write operation completes, it will invoke onMessageWrite + * @param internalState Object that invokes the write operation. * @param status True if the operation had success. - * @param buffer Buffer wrote. - * @param length Number of byte wrote. + * @param buffer Buffer written. + * @param length Number of bytes written. * @return true if the write had success */ static bool onWriteMessageCallback(CallbackStatus_t *internalState, @@ -265,12 +270,12 @@ } /** - * Function that the use will call after a read operation. - * in this case we read the message length, this function will read all the message - * @param internalState Object that invoke the write operation. + * Function called when a read operation completes. + * In this case we read the message length, this function will read all the message + * @param internalState Object that invokes the write operation. * @param status true If the operation had success. * @param buffer Buffer read. - * @param length Number of byte read. + * @param length Number of bytes read. * @return true if the read had success */ static bool onReadMessageLength(CallbackStatus_t *internalState, @@ -297,13 +302,12 @@ return status; } - /** - * Function that the user will call when it read all the message - * @param internalState Object that invoke the write operation. + * Function called when all messages have been read + * @param internalState Object that invokes the write operation. * @param status True if the operation had success. * @param buffer Buffer read. - * @param length Number of byte read. + * @param length Number of bytes read. * @return true if the read had success */ static bool onReadMessageCallback(CallbackStatus_t *internalState,