This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.

Dependencies:   NDefLib X_NUCLEO_NFC01A1 mbed

Fork of X-MBED-NFC1 by Giovanni Visentini

This application provides a set of demos with X-NUCLEO-NFC01A1 expansion board.

The available demos are:

  • SAMPLE_WRITE_URL: write a tag with the ST home page URL
  • SAMPLE_COUNT_CLICK: create a custom tag to count and report the user button clicks.
  • SAMPLE_WRITE_AND_CHANGE_ALL: write a tag with all the supported records and update the tag contents when the user button is pressed.
  • SAMPLE_LOCK_TAG_CONTENT: use the M24SR component API to set the NFC tag as read-only.

To enable the different demos comment/uncomment the SAMPLE_* macros provided in main.cpp .

Revision:
1:6d202b62ed68
Parent:
0:674813bd5ec9
Child:
2:0648c1561eb2
--- a/main.cpp	Thu Nov 19 08:50:18 2015 +0000
+++ b/main.cpp	Fri Nov 27 15:10:25 2015 +0000
@@ -9,10 +9,11 @@
 #include "NDefLib/RecordType/RecordAAR.h"
 #include "NDefLib/RecordType/RecordSMS.h"
 #include "NDefLib/RecordType/RecordGeo.h"
-#include "NDefLib/RecordType/RecordUri.h"
+#include "NDefLib/RecordType/RecordURI.h"
 #include "NDefLib/RecordType/RecordMail.h"
 #include "NDefLib/RecordType/RecordText.h"
 #include "NDefLib/RecordType/RecordMimeType.h"
+#include "NDefLib/RecordType/RecordVCard.h"
 
 #include "X_NUCLEO_NFC01A1.h"
 
@@ -33,7 +34,7 @@
 static const PinName M24SR_SDA=D14;
 static const PinName M24SR_SDL=D15;
 
-static const uint32_t MAX_WRITE_TRY=5;
+static const uint32_t MAX_WRITE_TRY=1;
 
 I2C i2cChannel(M24SR_SDA,M24SR_SDL);
 M24SR *m24srDrv;
@@ -54,21 +55,40 @@
 		NDefLib::RecordGeo rGeo("123.123","456.789");
 		msg.addRecord(&rGeo);
 
-		NDefLib::RecordUri rUri(NDefLib::RecordUri::HTTP_WWW,"http://www.st.com");
+		NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
 		msg.addRecord(&rUri);
 
 		NDefLib::RecordMail rMail("mail@st.com","ciao","da nfc tag");
 		msg.addRecord(&rMail);
 
-		NDefLib::RecordMimeType rText1("text/plain",(const uint8_t*)"ciao",4);
+		NDefLib::RecordMimeType rText1("text/plain","ciao");
 		msg.addRecord(&rText1);
 
-		NDefLib::RecordText rText2("ciao");
-		msg.addRecord(&rText2);
-
 		NDefLib::RecordText rText3(NDefLib::RecordText::UTF8,"it","ciao");
 		msg.addRecord(&rText3);
 
+
+		NDefLib::RecordVCard::VCardInfo_t cardInfo;
+		cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova2 prova1";
+		cardInfo[NDefLib::RecordVCard::ADDRESS_HOME]=";;1 Main St.;Springfield;IL;12345;USA";
+		cardInfo[NDefLib::RecordVCard::ADDRESS_WORK]=";;2 Main St.;Springfield;IL;12345;USA";
+		cardInfo[NDefLib::RecordVCard::EMAIL_WORK]="workmail@st.com";
+		cardInfo[NDefLib::RecordVCard::EMAIL_HOME]="homemail@st.com";
+		cardInfo[NDefLib::RecordVCard::GEO]="39.95;-75.1667";
+		cardInfo[NDefLib::RecordVCard::IMPP]="aim:johndoe@aol.com";
+		cardInfo[NDefLib::RecordVCard::NAME]="prova4;prova5";
+		cardInfo[NDefLib::RecordVCard::NICKNAME]="test";
+		cardInfo[NDefLib::RecordVCard::NOTE]="A good test";
+		cardInfo[NDefLib::RecordVCard::ORGANIZATION]="STM";
+		cardInfo[NDefLib::RecordVCard::TEL_HOME]="123";
+		cardInfo[NDefLib::RecordVCard::TEL_MOBILE]="456";
+		cardInfo[NDefLib::RecordVCard::TEL_WORK]="789";
+		cardInfo[NDefLib::RecordVCard::TITLE]="King";
+		cardInfo[NDefLib::RecordVCard::URL]="www.st.com";
+		cardInfo[NDefLib::RecordVCard::PHOTO_URI]="http://www.st.com/st-web-ui/static/active/en/fragment/multimedia/image/picture/customer_focus.jpg";
+		NDefLib::RecordVCard rVCard(cardInfo);
+		msg.addRecord(&rVCard);
+
 		uint32_t writeTry=0;
 		do{
 			writeStatus = tag.write(msg);
@@ -117,21 +137,101 @@
 */
 }
 
+void printRecord(NDefLib::Record *r){
+	using namespace NDefLib;
+	switch(r->getType()){
+		case Record::TYPE_TEXT:	{
+			RecordText *temp = (RecordText*)r;
+			pc.printf("Read Text: %s\r\n",temp->getText().c_str());
+			break; }
+		case Record::TYPE_AAR:{
+			RecordAAR *temp = (RecordAAR*)r;
+			pc.printf("Read ARR: %s\r\n",temp->getPackage().c_str());
+			break; }
+		case Record::TYPE_MIME:{
+			RecordMimeType *temp = (RecordMimeType*)r;
+			pc.printf("Read mimeType: %s\r\n",temp->getMimeType().c_str());
+			pc.printf("Read mimeData: %s\r\n",
+					std::string((const char*)temp->getMimeData(),
+							temp->getMimeDataLenght()).c_str());
+			break;}
+		case Record::TYPE_URI:{
+			RecordURI *temp = (RecordURI*)r;
+			pc.printf("Read uriId: %d\r\n",temp->getUriId());
+			pc.printf("Read uriType: %s\r\n",temp->getUriType().c_str());
+			pc.printf("Read uriContent: %s\r\n",temp->getContent().c_str());
+			break;}
+		case Record::TYPE_URI_MAIL:{
+			RecordMail *temp = (RecordMail*)r;
+			pc.printf("Read Dest: %s\r\n",temp->getDest().c_str());
+			pc.printf("Read Subject: %s\r\n",temp->getSubject().c_str());
+			pc.printf("Read Body: %s\r\n",temp->getBody().c_str());
+			break;}
+		case Record::TYPE_SMS:{
+			RecordSMS *temp = (RecordSMS*)r;
+			pc.printf("Read number: %s\r\n",temp->getNumber().c_str());
+			pc.printf("Read message: %s\r\n",temp->getMessagge().c_str());
+			break;}
+		case Record::TYPE_GEOLOCATION:{
+			RecordGeo *temp = (RecordGeo*)r;
+			pc.printf("Read lat: %s\r\n",temp->getLatitude().c_str());
+			pc.printf("Read long: %s\r\n",temp->getLongitude().c_str());
+			break;}
+		case Record::TYPE_MIME_VCARD:{
+			RecordVCard *temp = (RecordVCard*)r;
+			pc.printf("Read Name: %s\r\n",(*temp)[RecordVCard::NAME].c_str());
+			pc.printf("Read Mail: %s\r\n",(*temp)[RecordVCard::EMAIL_WORK].c_str());
+			pc.printf("Read org: %s\r\n",(*temp)[RecordVCard::ORGANIZATION].c_str());
+			break;}
+		case Record::TYPE_UNKNOWN:{
+			pc.printf("Unknown record\r\n");
+			break;}
+	}//switch
+}
+
+void readNfcTag(){
+	using namespace NDefLib;
+	Type4NfcTagSTM24SR tag(*m24srDrv);
+	if(tag.openSession()){
+		NDefLib::Message readMsg;
+
+		tag.read(&readMsg);
+
+		if(readMsg.getNRecords()==0){
+			pc.printf("Error Read\r\n");
+		}else{
+			for(uint32_t i=0;i<readMsg.getNRecords();i++){
+				Record *r = readMsg.getRecord(i);
+				printRecord(r);
+				delete r;
+			}//for
+		}//if-else
+
+		tag.closeSession();
+	}else{
+		pc.printf("Error open Session2\n\r");
+	}
+}
+
 int main() {
 	i2cChannel.frequency(400000);
 	X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
 	m24srDrv=&nfcNucleo->getM24SR();
 
-	pc.printf("Hello World !\n");
+	pc.printf("Hello World !\n\r");
 	nfcNucleo->getLed1()=1;
 	nfcNucleo->getLed2()=0;
 	nfcNucleo->getLed3()=0;
 
 	setNFCTag();
+	readNfcTag();
+	//pc.printf("2!\n\r");
+	//setNFCTag();
+	//readNfcTag();
 	while(1) {
 		wait(1);
 		myled = !myled;
 		shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
-  }
+	}
+
 }
-