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
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 .
Diff: Samples/SampleAsync_writeAndChangeAll.cpp
- Revision:
- 20:ba95e0dc5975
- Parent:
- 18:d596eb3f575f
--- a/Samples/SampleAsync_writeAndChangeAll.cpp Tue Aug 08 13:34:00 2017 +0000 +++ b/Samples/SampleAsync_writeAndChangeAll.cpp Mon Aug 21 12:12:30 2017 +0000 @@ -270,9 +270,7 @@ * Delete all the record and the message. */ void delete_message(){ - for(uint32_t i=0;i<mMsg->get_N_records();i++){ - delete (*mMsg)[i]; - }//for + NDefLib::Message::remove_and_delete_all_record(*mMsg); delete mMsg; }//deleteMessage @@ -315,8 +313,7 @@ /** * Delete the Message and close the session */ - virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success, - const NDefLib::Message &){ + virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success){ delete_message(); if(success){ printf("Message Wrote\r\n"); @@ -345,6 +342,7 @@ class WriteMessageCallback : public NDefLib::NDefNfcTag::Callbacks{ ReadMessageCallback* mReadMessage; + NDefLib::Message mMsg; public: @@ -366,32 +364,37 @@ printf("Session open\r\n"); - //create the message - NDefLib::Message msg; + NDefLib::RecordAAR *rAAR = + new NDefLib::RecordAAR("com.st.BlueMS"); + mMsg.add_record(rAAR); - NDefLib::RecordAAR rAAR("com.st.BlueMS"); - msg.add_record(&rAAR); + NDefLib::RecordSMS *rSMS = + new NDefLib::RecordSMS("123456789","st.com.BlueMS"); + mMsg.add_record(rSMS); - NDefLib::RecordSMS rSMS("123456789","st.com.BlueMS"); - msg.add_record(&rSMS); + NDefLib::RecordGeo *rGeo = + new NDefLib::RecordGeo(123.123,-456.789); + mMsg.add_record(rGeo); - NDefLib::RecordGeo rGeo(123.123,-456.789); - msg.add_record(&rGeo); + NDefLib::RecordURI *rUri = + new NDefLib::RecordURI(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com"); + mMsg.add_record(rUri); - NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com"); - msg.add_record(&rUri); + NDefLib::RecordMail *rMail = + new NDefLib::RecordMail("mail@st.com","ciao","da nfc tag"); + mMsg.add_record(rMail); - NDefLib::RecordMail rMail("mail@st.com","ciao","da nfc tag"); - msg.add_record(&rMail); + NDefLib::RecordMimeType *rText1 = + new NDefLib::RecordMimeType("text/plain",(const uint8_t*)"Ciao",4); + mMsg.add_record(rText1); - NDefLib::RecordMimeType rText1("text/plain",(const uint8_t*)"Ciao",4); - msg.add_record(&rText1); + NDefLib::RecordText *rText2 = + new NDefLib::RecordText(NDefLib::RecordText::UTF8,"it","ciao"); + mMsg.add_record(rText2); - NDefLib::RecordText rText3(NDefLib::RecordText::UTF8,"it","ciao"); - msg.add_record(&rText3); - - NDefLib::RecordWifiConf rWifi("OpenNetwork"); - msg.add_record(&rWifi); + NDefLib::RecordWifiConf *rWifi = + new NDefLib::RecordWifiConf("OpenNetwork"); + mMsg.add_record(rWifi); NDefLib::RecordVCard::VCardInfo_t cardInfo; cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova prova1"; @@ -411,22 +414,23 @@ 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.add_record(&rVCard); + NDefLib::RecordVCard *rVCard = new NDefLib::RecordVCard(cardInfo); + mMsg.add_record(rVCard); //write it - tag->write(msg); + tag->write(mMsg); } /** * Close the session */ - virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success, - const NDefLib::Message &){ - if(!success) + virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success){ + NDefLib::Message::remove_and_delete_all_record(mMsg); + if(!success){ printf("Error Writing\r\n"); - + return; + } printf("Message wrote\r\n"); tag->close_session(); }