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:
7:1ebd6049fa57
Parent:
6:739e3211749d
Child:
8:473f6e0b03df
--- a/RecordHeader.h	Thu Dec 03 14:56:01 2015 +0000
+++ b/RecordHeader.h	Thu Dec 10 14:58:43 2015 +0000
@@ -66,7 +66,8 @@
 
 
 	RecordHeader() :
-			headerFlags(0), typeLength(0), playloadLength(0) {
+			headerFlags(0), typeLength(0), payloadLength(0) {
+		setSR(true);
 	}
 
 	/**
@@ -77,7 +78,7 @@
 		if (value)
 			headerFlags |= 0x80;
 		else
-			headerFlags &= 0x7F;
+			headerFlags &= ~0x80;
 	}//setMB
 
 	/**
@@ -96,7 +97,7 @@
 		if (value)
 			headerFlags |= 0x40;
 		else
-			headerFlags &= 0xBF;
+			headerFlags &= ~0x40;
 	}//setME
 
 	/**
@@ -116,7 +117,7 @@
 		if (value)
 			headerFlags |= 0x20;
 		else
-			headerFlags &= 0xDF;
+			headerFlags &= ~0x20;
 	}//getCF
 
 	/**
@@ -136,7 +137,7 @@
 		if (value)
 			headerFlags |= 0x10;
 		else
-			headerFlags &= 0xCF;
+			headerFlags &= ~0x10;
 	}//setSR
 
 	/**
@@ -155,7 +156,7 @@
 		if (value)
 			headerFlags |= 0x08;
 		else
-			headerFlags &= 0xAF;
+			headerFlags &= ~0x08;
 	}//setIL
 
 	/**
@@ -186,21 +187,21 @@
 	}
 
 	/**
-	 * set the record playload length
+	 * set the record payload length
 	 * @par this function will update the SR field as needed
-	 * @param length playload length
+	 * @param length payload length
 	 */
-	void setPlayloadLength(uint32_t length) {
-		playloadLength = length;
-		setSR(playloadLength <= 255);
+	void setPayloadLength(uint32_t length) {
+		payloadLength = length;
+		setSR(payloadLength <= 255);
 	}
 
 	/**
-	 * get the playload length
-	 * @return playload length
+	 * get the payload length
+	 * @return payload length
 	 */
-	uint32_t getPlayloadLength() const {
-		return playloadLength;
+	uint32_t getPayloadLength() const {
+		return payloadLength;
 	}
 
 	/**
@@ -224,7 +225,7 @@
 	 * @return 3 or 6
 	 */
 	uint16_t getRecordLength() const {
-		return (getSR() ? 3 : 6) + typeLength + playloadLength;
+		return (getSR() ? 3 : 6) + typeLength + payloadLength;
 	}
 
 	/**
@@ -239,15 +240,15 @@
 		outBuffer[index++] = headerFlags;
 		outBuffer[index++] = typeLength;
 		if (getSR()) {
-			outBuffer[index++] = (uint8_t) playloadLength;
+			outBuffer[index++] = (uint8_t) payloadLength;
 		} else {
-			outBuffer[index++] = (uint8_t) ((playloadLength & 0xFF000000)
+			outBuffer[index++] = (uint8_t) ((payloadLength & 0xFF000000)
 					>> 24);
-			outBuffer[index++] = (uint8_t) ((playloadLength & 0x00FF0000)
+			outBuffer[index++] = (uint8_t) ((payloadLength & 0x00FF0000)
 					>> 16);
-			outBuffer[index++] = (uint8_t) ((playloadLength & 0x0000FF00)
+			outBuffer[index++] = (uint8_t) ((payloadLength & 0x0000FF00)
 					>> 8);
-			outBuffer[index++] = (uint8_t) (playloadLength & 0x000000FF);
+			outBuffer[index++] = (uint8_t) (payloadLength & 0x000000FF);
 		} //if-else
 		return index;
 	} //writeHeader
@@ -262,9 +263,9 @@
 		headerFlags = buffer[index++];
 		typeLength = buffer[index++];
 		if (getSR()) {
-			playloadLength = buffer[index++];
+			payloadLength = buffer[index++];
 		} else {
-			playloadLength = (((uint32_t) buffer[index + 0]) << 24)
+			payloadLength = (((uint32_t) buffer[index + 0]) << 24)
 					| (((uint32_t) buffer[index + 1]) << 16)
 					| (((uint32_t) buffer[index + 2]) << 8)
 					| ((uint32_t) buffer[index + 3]);
@@ -273,11 +274,25 @@
 		return index;
 	} //loadHeader
 
+	/**
+	 * equal operator
+	 * @param other other object to compare
+	 * @return true if the 2 record header are equals
+	 */
+	bool operator==(const RecordHeader &other) const{
+		return (headerFlags==other.headerFlags) &&
+				(typeLength==other.typeLength) &&
+				(payloadLength==other.payloadLength);
+	}
+
+	bool operator!=(const RecordHeader &other) const{
+		return !(*this==other);
+	}
 
 private:
 	uint8_t headerFlags;
 	uint8_t typeLength;
-	uint32_t playloadLength;
+	uint32_t payloadLength;
 };
 
 } /* namespace NDefLib */