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 ST Expansion SW Team

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.

Revision:
20:31f727872290
Parent:
19:13d84b136a62
Child:
21:72c86cbd49be
--- a/NDefNfcTag.h	Fri Apr 28 12:13:51 2017 +0000
+++ b/NDefNfcTag.h	Wed Jul 12 12:33:42 2017 +0000
@@ -126,10 +126,11 @@
 	 * @param c Object containing the callback.
 	 */
 	void set_callback(Callbacks *c){
-		if(c!=NULL)
+		if (c!=NULL) {
 			mCallBack=c;
-		else
+		} else {
 			mCallBack=&mDefaultCallBack;
+		}
 	}//setCallBack
 
 
@@ -159,14 +160,14 @@
 	 * @return true if success
 	 */
 	virtual bool write(Message &msg) {
-		if(!is_session_open()){
+		if (!is_session_open()) {
 			mCallBack->on_message_write(this,false,msg);
 			return false;
 		}
 
 		const uint16_t length = msg.get_byte_length();
 		uint8_t *buffer = new uint8_t[length];
-		if(buffer==NULL){ //impossible to allocate the buffer
+		if (buffer==NULL){ //impossible to allocate the buffer
 			mCallBack->on_message_write(this,false,msg);
 			return false;
 		}
@@ -185,13 +186,13 @@
 	 * @return true if success
 	 */
 	virtual bool read(Message *msg) {
-		if(!is_session_open()){
+		if (!is_session_open()) {
 			mCallBack->on_message_read(this,false,msg);
 			return false;
 		}
 
 		uint8_t *buffer = new uint8_t[2];
-		if(buffer==NULL){
+		if (buffer==NULL) {
 			mCallBack->on_message_read(this,false,msg);
 			return false;
 		}
@@ -216,7 +217,7 @@
 	 * @return true if the operation had success
 	 */
 	typedef bool(*byteOperationCallback_t)(CallbackStatus_t *internalState,
-			bool status,const uint8_t *buffer, uint16_t length);
+		bool status,const uint8_t *buffer, uint16_t length);
 
 	/**
 	 * Write a sequence of bytes to the NDEF file.
@@ -228,7 +229,7 @@
 	 * @return true if the operation has success
 	 */
 	virtual bool writeByte(const uint8_t *buffer, uint16_t length,uint16_t offset,
-			byteOperationCallback_t callback,CallbackStatus_t *callbackStatus)=0;
+		byteOperationCallback_t callback,CallbackStatus_t *callbackStatus)=0;
 
 	/**
 	 * Read a sequence of bytes from the NDEF file.
@@ -240,7 +241,7 @@
 	 * @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;
+		uint8_t *buffer, byteOperationCallback_t callback,CallbackStatus_t *callbackStatus)=0;
 
 
 	/** object with the user callback */
@@ -261,11 +262,11 @@
 	 * @return true if the write had success
 	 */
 	static bool onWriteMessageCallback(CallbackStatus_t *internalState,
-			bool status,const uint8_t *buffer, uint16_t ){
+		bool status,const uint8_t *buffer, uint16_t ){
 		delete [] buffer;
 
-		internalState->callOwner->mCallBack->
-			on_message_write(internalState->callOwner,status,*internalState->msg);
+		internalState->callOwner->mCallBack->on_message_write(internalState->callOwner,status,*internalState->msg);
+
 		return status;
 	}
 
@@ -279,11 +280,10 @@
 	 * @return true if the read had success
 	 */
 	static bool onReadMessageLength(CallbackStatus_t *internalState,
-			bool status,const uint8_t *buffer, uint16_t length){
+		bool status,const uint8_t *buffer, uint16_t length){
 
-		if(!status || length!=2){
-			internalState->callOwner->mCallBack->
-					on_message_read(internalState->callOwner,false,internalState->msg);
+		if (!status || length!=2) {
+			internalState->callOwner->mCallBack->on_message_read(internalState->callOwner,false,internalState->msg);
 			return false;
 		}//if
 
@@ -291,14 +291,12 @@
 		delete [] buffer;
 
 		uint8_t *readBuffer = new uint8_t[length];
-		if(readBuffer==NULL){
-			internalState->callOwner->mCallBack->
-					on_message_read(internalState->callOwner,false,internalState->msg);
+		if (readBuffer==NULL) {
+			internalState->callOwner->mCallBack->on_message_read(internalState->callOwner,false,internalState->msg);
 			return false;
 		}//readBuffer
 
-		internalState->callOwner->readByte(2,length,readBuffer,
-				&NDefNfcTag::onReadMessageCallback,internalState);
+		internalState->callOwner->readByte(2,length,readBuffer, &NDefNfcTag::onReadMessageCallback,internalState);
 		return status;
 	}
 
@@ -311,16 +309,14 @@
 	 * @return true if the read had success
 	 */
 	static bool onReadMessageCallback(CallbackStatus_t *internalState,
-			bool status,const uint8_t *buffer, uint16_t length){
-		if(!status){
-			internalState->callOwner->mCallBack->
-					on_message_read(internalState->callOwner,false,internalState->msg);
+		bool status,const uint8_t *buffer, uint16_t length){
+		if(!status) {
+			internalState->callOwner->mCallBack->on_message_read(internalState->callOwner,false,internalState->msg);
 			return false;
 		}
 		Message::parse_message(buffer, length, internalState->msg);
 		delete [] buffer;
-		internalState->callOwner->mCallBack->
-			on_message_read(internalState->callOwner,true,internalState->msg);
+		internalState->callOwner->mCallBack-> on_message_read(internalState->callOwner,true,internalState->msg);
 		return status ;
 	}
 
@@ -329,3 +325,6 @@
 }// namespace NDefLib
 
 #endif /* NDEFLIB_NDEFNFCTAG_H_ */
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/