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:
- 19:13d84b136a62
- Parent:
- 16:030e7ffdf512
- Child:
- 20:31f727872290
--- a/NDefNfcTag.h Thu Oct 27 07:39:26 2016 +0000 +++ b/NDefNfcTag.h Fri Apr 28 12:13:51 2017 +0000 @@ -2,8 +2,8 @@ ****************************************************************************** * @file NDefNfcTag.h * @author ST / Central Labs - * @version V1.0.0 - * @date 21 Jan 2016 + * @version V2.0.0 + * @date 28 Apr 2017 * @brief Generic interface that a device must implement to use the NDefLib * with async communication ****************************************************************************** @@ -65,7 +65,7 @@ * @param tag Tag where the session is open. * @param success True if the operation has success. */ - virtual void onSessionOpen(NDefNfcTag *tag,bool success){ + virtual void on_session_open(NDefNfcTag *tag,bool success){ (void)tag;(void)success; }; @@ -74,7 +74,7 @@ * @param tag Tag where the message is written. * @param success True if the operation has success. */ - virtual void onMessageWrite(NDefNfcTag *tag,bool success, + virtual void on_message_write(NDefNfcTag *tag,bool success, const Message &msg){ (void)tag;(void)success; (void)msg; @@ -85,7 +85,7 @@ * @param tag Tag where the message is read. * @param success True if the operation has success. */ - virtual void onMessageRead(NDefNfcTag *tag,bool success, + virtual void on_message_read(NDefNfcTag *tag,bool success, const Message *msg){ (void)tag;(void)success; (void)msg; }; @@ -96,7 +96,7 @@ * @param tag Tag where the session is closed. * @param success True if the operation has success. */ - virtual void onSessionClose(NDefNfcTag *tag,bool success){ + virtual void on_session_close(NDefNfcTag *tag,bool success){ (void)tag;(void)success; }; @@ -125,7 +125,7 @@ * Set the callback object. * @param c Object containing the callback. */ - void setCallback(Callbacks *c){ + void set_callback(Callbacks *c){ if(c!=NULL) mCallBack=c; else @@ -138,19 +138,19 @@ * @param force Force to open a communication. * @return true if success */ - virtual bool openSession(bool force = false)=0; + virtual bool open_session(bool force = false)=0; /** * Close the communication with the nfc tag. * @return true if success */ - virtual bool closeSession()=0; + virtual bool close_session()=0; /** * Returns true if a communication with the nfc tag is open. * @return true if a communication with the nfc tag is open */ - virtual bool isSessionOpen()=0; + virtual bool is_session_open()=0; /** * Write a message in the nfc tag. @@ -159,15 +159,15 @@ * @return true if success */ virtual bool write(Message &msg) { - if(!isSessionOpen()){ - mCallBack->onMessageWrite(this,false,msg); + if(!is_session_open()){ + mCallBack->on_message_write(this,false,msg); return false; } - const uint16_t length = msg.getByteLength(); + const uint16_t length = msg.get_byte_length(); uint8_t *buffer = new uint8_t[length]; if(buffer==NULL){ //impossible to allocate the buffer - mCallBack->onMessageWrite(this,false,msg); + mCallBack->on_message_write(this,false,msg); return false; } @@ -185,14 +185,14 @@ * @return true if success */ virtual bool read(Message *msg) { - if(!isSessionOpen()){ - mCallBack->onMessageRead(this,false,msg); + if(!is_session_open()){ + mCallBack->on_message_read(this,false,msg); return false; } uint8_t *buffer = new uint8_t[2]; if(buffer==NULL){ - mCallBack->onMessageRead(this,false,msg); + mCallBack->on_message_read(this,false,msg); return false; } @@ -253,7 +253,7 @@ Callbacks mDefaultCallBack; /** - * Function called when a write operation completes, it will invoke onMessageWrite + * Function called when a write operation completes, it will invoke on_message_write * @param internalState Object that invokes the write operation. * @param status True if the operation had success. * @param buffer Buffer written. @@ -265,7 +265,7 @@ delete [] buffer; internalState->callOwner->mCallBack-> - onMessageWrite(internalState->callOwner,status,*internalState->msg); + on_message_write(internalState->callOwner,status,*internalState->msg); return status; } @@ -283,7 +283,7 @@ if(!status || length!=2){ internalState->callOwner->mCallBack-> - onMessageRead(internalState->callOwner,false,internalState->msg); + on_message_read(internalState->callOwner,false,internalState->msg); return false; }//if @@ -293,7 +293,7 @@ uint8_t *readBuffer = new uint8_t[length]; if(readBuffer==NULL){ internalState->callOwner->mCallBack-> - onMessageRead(internalState->callOwner,false,internalState->msg); + on_message_read(internalState->callOwner,false,internalState->msg); return false; }//readBuffer @@ -314,13 +314,13 @@ bool status,const uint8_t *buffer, uint16_t length){ if(!status){ internalState->callOwner->mCallBack-> - onMessageRead(internalState->callOwner,false,internalState->msg); + on_message_read(internalState->callOwner,false,internalState->msg); return false; } - Message::parseMessage(buffer, length, internalState->msg); + Message::parse_message(buffer, length, internalState->msg); delete [] buffer; internalState->callOwner->mCallBack-> - onMessageRead(internalState->callOwner,true,internalState->msg); + on_message_read(internalState->callOwner,true,internalState->msg); return status ; }