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
--- a/Message.cpp	Fri Apr 28 12:13:51 2017 +0000
+++ b/Message.cpp	Wed Jul 12 12:33:42 2017 +0000
@@ -48,8 +48,9 @@
 uint16_t Message::get_byte_length() const {
 	uint16_t lenght = 2; //length size
 
-	if (mRecords.size() == 0)
+	if (mRecords.size() == 0) {
 		return lenght + EmptyRecord().get_byte_length();
+	}
 
 	std::vector<Record*>::const_iterator it = mRecords.begin();
 	const std::vector<Record*>::const_iterator end = mRecords.end();
@@ -79,10 +80,12 @@
 		Record *r = mRecords[i];
 
 		r->set_as_middle_record();
-		if (i == 0)
+		if (i == 0) {
 			r->set_as_first_record();
-		if (i == nRecord - 1)
+		}
+		if (i == nRecord - 1) {
 			r->set_as_last_record();
+		}
 
 		offset += r->write(buffer + offset);
 	} //for
@@ -90,8 +93,7 @@
 	return offset;
 } //write
 
-void Message::parse_message(const uint8_t * const rawNdefFile,
-		const uint16_t length, Message *msg) {
+void Message::parse_message(const uint8_t * const rawNdefFile, const uint16_t length, Message *msg) {
 	uint16_t offset = 0;
 	Record *r;
 
@@ -99,28 +101,32 @@
 	do {
 		const uint8_t headerLenght = header.load_header(rawNdefFile + offset);
 		r = RecordText::parse(header, rawNdefFile + offset + headerLenght);
-		if (r == NULL)
+		if (r == NULL) {
 			r = RecordAAR::parse(header, rawNdefFile + offset + headerLenght);
-		if (r == NULL)
+		}
+		if (r == NULL) {
 			r = RecordMimeType::parse(header,
-					rawNdefFile + offset + headerLenght);
-		if (r == NULL)
+			rawNdefFile + offset + headerLenght);
+		}
+		if (r == NULL) {
 			r = RecordURI::parse(header, rawNdefFile + offset + headerLenght);
+		}
 
 		offset += header.get_record_length();
 		msg->add_record(r);
 	} while (offset < length);
-
 }
 
 void Message::remove_and_delete_all_record(Message &msg){
     const uint32_t nRecords =msg.get_N_records();
-	for(uint32_t i =0 ;i<nRecords ;i++){
+	for (uint32_t i =0 ;i<nRecords ;i++) {
         NDefLib::Record *r = msg[i];
         delete r;
     }//for
     msg.mRecords.clear();
 }//removeAndDeleteAllRecord
 
+} /* namespace NDefLib */
 
-} /* namespace NDefLib */
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/