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:
19:13d84b136a62
Parent:
18:cf1dd5c931c2
Child:
20:31f727872290
--- a/RecordHeader.h	Thu Oct 27 07:39:26 2016 +0000
+++ b/RecordHeader.h	Fri Apr 28 12:13:51 2017 +0000
@@ -2,8 +2,8 @@
  ******************************************************************************
  * @file    RecordHeader.h
  * @author  ST / Central Labs
- * @version V1.0.0
- * @date    30 Nov 2015
+ * @version V2.0.0
+ * @date    28 Apr 2017
  * @brief   Record header class 
  ******************************************************************************
  * @attention
@@ -67,73 +67,73 @@
 
 	RecordHeader() :
 			headerFlags(0), typeLength(0), payloadLength(0) {
-		setSR(true);
+		set_SR(true);
 	}
 
 	/**
 	 * Set the 'message begin' flag.
 	 * @param value True if the record is the first within the message.
 	 */
-	void setMB(bool value) {
+	void set_MB(bool value) {
 		if (value)
 			headerFlags |= 0x80;
 		else
 			headerFlags &= ~0x80;
-	}//setMB
+	}//set_MB
 
 	/**
 	 * Check the 'message begin' flag.
 	 * @return true if it is the first record in the message
 	 */
-	bool getMB() const {
+	bool get_MB() const {
 		return (headerFlags & 0x80) != 0;
-	}//getMB
+	}//get_MB
 
 	/**
 	 * Set the 'message end' flag.
 	 * @param value True if it is the last record in the message.
 	 */
-	void setME(bool value) {
+	void set_ME(bool value) {
 		if (value)
 			headerFlags |= 0x40;
 		else
 			headerFlags &= ~0x40;
-	}//setME
+	}//set_ME
 
 	/**
 	 * Check the 'message end' flag.
 	 * @return true if it is the last record in the message
 	 */
-	bool getME() const {
+	bool get_ME() const {
 		return (headerFlags & 0x40) != 0;
-	}//getME
+	}//get_ME
 
 	/**
 	 * Set the 'Chunk' flag.
 	 * @param value True if the record is in the first record chunk or in a middle record
 	 * chunk of a chunked payload.
 	 */
-	void setCF(bool value) {
+	void set_CF(bool value) {
 		if (value)
 			headerFlags |= 0x20;
 		else
 			headerFlags &= ~0x20;
-	}//getCF
+	}//set_CF
 
 	/**
 	 * Check the 'Chunk' flag value.
 	 * @return true if the record is in the first record chunk or in a middle record
 	 * chunk of a chunked payload
 	 */
-	bool getCF() const {
+	bool get_CF() const {
 		return (headerFlags & 0x20) != 0;
-	}//getCF
+	}//get_CF
 
 	/**
 	 * Set the 'Short record' flag value.
 	 * @param value True if the record size can be encoded with 8 bits.
 	 */
-	void setSR(bool value) {
+	void set_SR(bool value) {
 		if (value)
 			headerFlags |= 0x10;
 		else
@@ -144,7 +144,7 @@
 	 * Check the 'Short record' flag.
 	 * @return true if the short range header format is set
 	 */
-	bool getSR() const {
+	bool get_SR() const {
 		return (headerFlags & 0x10) != 0;
 	}//getSR
 
@@ -152,7 +152,7 @@
 	 * Set the 'ID length' flag.
 	 * @param value True if the 'ID length' value is used.
 	 */
-	void setIL(bool value) {
+	void set_IL(bool value) {
 		if (value)
 			headerFlags |= 0x08;
 		else
@@ -163,7 +163,7 @@
 	 * Check the 'ID length' flag.
 	 * @param value True if 'ID length' is set.
 	 */
-	bool getIL() const {
+	bool get_IL() const {
 		return (headerFlags & 0x08) != 0;
 	}//getIL
 
@@ -171,7 +171,7 @@
 	 * Set the type name format field.
 	 * @param value Record type name format.
 	 */
-	void setFNT(const TypeNameFormat_t value) {
+	void set_FNT(const TypeNameFormat_t value) {
 		uint8_t temp = (uint8_t) value;
 		temp &= 0x07; //keep the first 3 bits
 		headerFlags &= 0xF8; //clean the fist 3 bits
@@ -182,7 +182,7 @@
 	 * Get the record type name.
 	 * @return type name format of the record
 	 */
-	TypeNameFormat_t getFNT() const {
+	TypeNameFormat_t get_FNT() const {
 		return (TypeNameFormat_t) (headerFlags & 0x07);
 	}
 
@@ -191,16 +191,16 @@
 	 * @par This function will update the SR field as needed.
 	 * @param length payload length
 	 */
-	void setPayloadLength(uint32_t length) {
+	void set_payload_length(uint32_t length) {
 		payloadLength = length;
-		setSR(payloadLength <= 255);
+		set_SR(payloadLength <= 255);
 	}
 
 	/**
 	 * Get the payload length.
 	 * @return payload length
 	 */
-	uint32_t getPayloadLength() const {
+	uint32_t get_payload_length() const {
 		return payloadLength;
 	}
 
@@ -208,7 +208,7 @@
 	 * Set the type length.
 	 * @param size.
 	 */
-	void setTypeLength(uint8_t size) {
+	void set_type_length(uint8_t size) {
 		typeLength = size;
 	}
 
@@ -216,7 +216,7 @@
 	 * Get the type length.
 	 * @return type length
 	 */
-	uint8_t getTypeLength() const {
+	uint8_t get_type_length() const {
 		return typeLength;
 	}
 
@@ -224,12 +224,12 @@
 	 * Set the id length.
 	 * @param size.
 	 */
-	void setIdLength(uint8_t size) {
+	void set_id_length(uint8_t size) {
 		if(size!=0){
 			idLength = size;
-			setIL(true);
+			set_IL(true);
 		}else
-			setIL(false);
+			set_IL(false);
 
 	}
 
@@ -237,7 +237,7 @@
 	 * Get the id length.
 	 * @return id length
 	 */
-	uint8_t getIdLength() const {
+	uint8_t get_id_length() const {
 		return idLength;
 	}
 
@@ -245,8 +245,8 @@
 	 * Get the number of bytes needed to store this record.
 	 * @return 3 or 6
 	 */
-	uint16_t getRecordLength() const {
-		return (getSR() ? 3 : 6) + (getIL() ? idLength : 0)+typeLength + payloadLength;
+	uint16_t get_record_length() const {
+		return (get_SR() ? 3 : 6) + (get_IL() ? idLength : 0)+typeLength + payloadLength;
 	}
 
 	/**
@@ -254,13 +254,13 @@
 	 * @param[out] outBuffer Buffer to write the header into.
 	 * @return number of write bytes
 	 */
-	uint8_t writeHeader(uint8_t *outBuffer) const {
+	uint8_t write_header(uint8_t *outBuffer) const {
 
 		uint32_t index = 0;
 
 		outBuffer[index++] = headerFlags;
 		outBuffer[index++] = typeLength;
-		if (getSR()) {
+		if (get_SR()) {
 			outBuffer[index++] = (uint8_t) payloadLength;
 		} else {
 			outBuffer[index++] = (uint8_t) ((payloadLength & 0xFF000000)
@@ -271,7 +271,7 @@
 					>> 8);
 			outBuffer[index++] = (uint8_t) (payloadLength & 0x000000FF);
 		} //if-else
-		if(getIL())
+		if(get_IL())
 			outBuffer[index++] =idLength;
 		return index;
 	} //writeHeader
@@ -281,11 +281,11 @@
 	 * @param buffer Buffer to load the header from.
 	 * @return number of read bytes
 	 */
-	uint16_t loadHeader(const uint8_t * const buffer) {
+	uint16_t load_header(const uint8_t * const buffer) {
 		uint32_t index = 0;
 		headerFlags = buffer[index++];
 		typeLength = buffer[index++];
-		if (getSR()) {
+		if (get_SR()) {
 			payloadLength = buffer[index++];
 		} else {
 			payloadLength = (((uint32_t) buffer[index + 0]) << 24)
@@ -294,7 +294,7 @@
 					| ((uint32_t) buffer[index + 3]);
 			index += 4;
 		} //if-else
-		if(getIL())
+		if(get_IL())
 			idLength=buffer[index++];
 		else
 			idLength=0;