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:
4:eaf6c49a86e4
Parent:
2:760e36ba9c23
Child:
5:f2b7efcc5b6e
--- a/RecordType/RecordVCard.h	Fri Nov 27 15:09:55 2015 +0000
+++ b/RecordType/RecordVCard.h	Tue Dec 01 08:30:27 2015 +0000
@@ -16,72 +16,139 @@
 
 //https://en.wikipedia.org/wiki/VCard
 
+/**
+ * Specialize the mimeType record for store a VCard information.
+ * this record handle the VCard version 3 format
+ */
 class RecordVCard: public RecordMimeType {
 public:
-	typedef enum{
-		ADDRESS,
-		ADDRESS_HOME,
-		ADDRESS_WORK,
-		AGENT,
-		BIRDAY,
-		CATEGORIES,
-		EMAIL,
-		EMAIL_HOME,
-		EMAIL_WORK,
-		FORMATTED_NAME,
-		//latitude and longitude ; separated
-		GEO,
-		IMPP,
-		PGPKEY_URL,
-		PGPGKEY_BASE64,
-		LOGO,
-		LOGO_URI,
-		LOGO_BASE64, //add TYPE=XXXX:imagebyte
-		NAME,
-		NICKNAME,
-		NOTE,
-		ORGANIZATION,
-		PHOTO_URI,
-		PHOTO_BASE64, //add TYPE=XXXX:imagebyte
-		REVISION,
-		SOURCE_URL,
-		TEL_HOME,
-		TEL_WORK,
-		TEL_MOBILE,
-		TITLE,
-		URL,
-	}VCardField_t;
+	/**
+	 * type of information that you can store inside the tag
+	 */
+	typedef enum {
+		ADDRESS,       //!< ADDRESS
+		ADDRESS_HOME,  //!< ADDRESS_HOME
+		ADDRESS_WORK,  //!< ADDRESS_WORK
+		AGENT,         //!< AGENT
+		BIRDAY,        //!< BIRDAY
+		CATEGORIES,    //!< CATEGORIES
+		EMAIL,         //!< EMAIL
+		EMAIL_HOME,    //!< EMAIL_HOME
+		EMAIL_WORK,    //!< EMAIL_WORK
+		FORMATTED_NAME,//!< FORMATTED_NAME
+		GEO,           //!< GEO latitude and longitude ; separated
+		IMPP,          //!< IMPP
+		PGPKEY_URL,    //!< PGPKEY_URL
+		PGPGKEY_BASE64,//!< PGPGKEY_BASE64
+		LOGO,          //!< LOGO
+		LOGO_URI,      //!< LOGO_URI
+		LOGO_BASE64,   //!< generic hardcoded image add TYPE=XXXX:imagebyte
+		NAME,          //!< NAME
+		NICKNAME,      //!< NICKNAME
+		NOTE,          //!< NOTE
+		ORGANIZATION,  //!< ORGANIZATION
+		PHOTO_URI,     //!< PHOTO_URI
+		PHOTO_BASE64,  //!< generic hardcoded image add TYPE=XXXX:imagebyte
+		REVISION,      //!< REVISION
+		SOURCE_URL,    //!< SOURCE_URL
+		TEL,           //!< TEL
+		TEL_HOME,      //!< TEL_HOME
+		TEL_WORK,      //!< TEL_WORK
+		TEL_MOBILE,    //!< TEL_MOBILE
+		TITLE,         //!< TITLE
+		URL,           //!< URL
+	} VCardField_t;
 
-	typedef std::map<VCardField_t,std::string> VCardInfo_t;
+	/**
+	 * type used for store the vcard information
+	 */
+	typedef std::map<VCardField_t, std::string> VCardInfo_t;
 
-	static RecordVCard* parse(const Record::RecordHeader &header,
+	/**
+	 * create an RecordVCard reading the data from the buffer
+ 	 * @param header record header already read
+	 * @param buffer buffer where read the data
+	 * @return an object of type RecordVCard or NULL
+	 * @par free the pointer return by this function
+	 */
+	static RecordVCard* parse(const RecordHeader &header,
 			const uint8_t* buffer);
 
-	RecordVCard(const VCardInfo_t &info);
+	/**
+	 * create a record with the specific information
+	 * @param info optional information to store in the record
+	 */
+	RecordVCard(const VCardInfo_t &info=VCardInfo_t());
 
-	const std::string& operator[](const VCardField_t &type){
-		VCardInfo_t::const_iterator elem= mCardInfo.find(type);
-		if(elem == mCardInfo.end())
+	/**
+	 * get the specificic information stored in this record
+	 * @param type type of information to get
+	 * @return if present the information or an empty string
+	 */
+	const std::string& operator[](const VCardField_t &type)const {
+		VCardInfo_t::const_iterator elem = mCardInfo.find(type);
+		if (elem == mCardInfo.end())
 			return sEmptyTagContent;
 		//else
 		return elem->second;
 	}
 
-	virtual RecordType_t getType()const{
+	/**
+	 * get or set/change an information associated with this record
+	 * @param type type of information to change
+	 * @return reference to the string information
+	 */
+	std::string& operator[](const VCardField_t &type) {
+		mContentIsChange=true;
+		return mCardInfo[type];
+	}
+
+	virtual RecordType_t getType() const {
 		return TYPE_MIME_VCARD;
-	}//getType
+	} //getType
+
+
+	virtual uint16_t getByteLength() {
+		updateContentInfoString();
+		return RecordMimeType::getByteLength();
+	}
 
-	virtual ~RecordVCard(){}
+	virtual uint16_t write(uint8_t *buffer){
+		updateContentInfoString();
+		return RecordMimeType::write(buffer);
+	}
+
+	virtual ~RecordVCard() {
+	}
 
 private:
-	const VCardInfo_t mCardInfo;
+	VCardInfo_t mCardInfo;
+	//buffer containing the Vcard representation for this record
+	std::string mCardInfoString;
 
+	bool mContentIsChange;
+
+	void updateContentInfoString();
 
-	static std::string buildCardContent(const VCardInfo_t &info);
+	/**
+	 * check if in the string that start in position offset, is present a known
+	 * vcard file, if yes it return type index, otherwise a negative number
+	 * @param content string where search
+	 * @param offset offset where start to search
+	 * @return index of the field found or a negative number
+	 */
+	static int8_t findVCardFieldType(const std::string &content,
+			uint16_t offset);
 
-	static int8_t findVCardFieldType(const std::string &content,uint16_t offset);
-
-	static uint16_t findVCardFieldDataLenght(const std::string &content,uint16_t offset);
+	/**
+	 * search the end of a vcard field
+	 * @param content string where search
+	 * @param offset offset where start to search
+	 * @return field length
+	 * @par this function search the first sEndVCardTag appearance
+	 */
+	static uint16_t findVCardFieldDataLenght(const std::string &content,
+			uint16_t offset);
 
 	static const std::string sVcardMimeType;
 	static const std::string sStartFieldTag[];
@@ -94,4 +161,3 @@
 } /* namespace NDefLib */
 
 #endif /* NDEFLIB_RECORDTYPE_RECORDVCARD_H_ */
-