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 .
Revision 17:d8d3d2088cac, committed 2017-07-13
- Comitter:
- giovannivisentini
- Date:
- Thu Jul 13 09:41:01 2017 +0000
- Parent:
- 16:02611ca49f48
- Child:
- 18:d596eb3f575f
- Commit message:
- use the new X-NUCLEO-NFC01A1 api; update libs
Changed in this revision
--- a/NDefLib.lib Wed Aug 31 15:14:08 2016 +0000 +++ b/NDefLib.lib Thu Jul 13 09:41:01 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ST/code/NDefLib/#46899fa3d9f2 +http://developer.mbed.org/teams/ST/code/NDefLib/#31f727872290
--- a/Samples/MyRecord.h Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/MyRecord.h Thu Jul 13 09:41:01 2017 +0000
@@ -47,23 +47,23 @@
/**
* Convert the number in char and update the tag content.
*/
- void syncTextValue(){
- sprintf(nClickStringBuffer,"%d",nClick);
- setText(nClickStringBuffer);
+ void sync_text_value(){
+ sprintf(nClickStringBuffer,"%u",nClick);
+ set_text(nClickStringBuffer);
}
public:
MyRecord():nClick(0){
- syncTextValue();
+ sync_text_value();
}
/**
* Increment the stored number and update the racord content.
*/
- void incrementClick(){
+ void increment_click(){
nClick++;
- syncTextValue();
+ sync_text_value();
}
};
\ No newline at end of file
--- a/Samples/SampleAsync_countClick.cpp Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/SampleAsync_countClick.cpp Thu Jul 13 09:41:01 2017 +0000
@@ -36,7 +36,7 @@
#include "mbed.h"
-#include "X_NUCLEO_NFC01A1.h"
+#include "XNucleoNFC01A1.h"
#include "NDefLib/NDefNfcTag.h"
#include "MyRecord.h"
@@ -49,7 +49,7 @@
/**
* board where change the led status
*/
- X_NUCLEO_NFC01A1 *mNfcNucleo;
+ XNucleoNFC01A1 *mNfcNucleo;
/**
* message to write
@@ -74,23 +74,23 @@
* @param nfcNucleo board with the leds and nfc tag
* @param msg message to write
*/
- WriteMyRecordCallback(X_NUCLEO_NFC01A1 *nfcNucleo,NDefLib::Message &msg):
+ WriteMyRecordCallback(XNucleoNFC01A1 *nfcNucleo,NDefLib::Message &msg):
mNfcNucleo(nfcNucleo),mMsg(msg),mCommandFinish(true),
mRequestRefresh(false){}
/**
* start the write process
*/
- void updateMessage(){
+ void update_message(){
if(mCommandFinish){
- mNfcNucleo->getM24SR().getNDefTag().openSession();
+ mNfcNucleo->get_M24SR().get_NDef_tag().open_session();
}else// if it is doing something remember this request
mRequestRefresh=true;
}//updateMessage
private:
- void onError(){
+ void on_error(){
printf("Error updating the tag\r\n");
mCommandFinish=false;
}
@@ -98,10 +98,10 @@
/**
* when the session is open change the led status and ask to write the message
*/
- virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+ virtual void on_session_open(NDefLib::NDefNfcTag *tag,bool success){
if(!success)
- return onError();
- mNfcNucleo->getLed1()=!mNfcNucleo->getLed1();
+ return on_error();
+ mNfcNucleo->get_led1()=!mNfcNucleo->get_led1();
printf("Session opened\r\n");
tag->write(mMsg);
}
@@ -109,17 +109,17 @@
/**
* if the user ask to update the value it write again the message, otherwise close the session
*/
- virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
+ virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success,
const NDefLib::Message&){
if(!success)
- return onError();
- mNfcNucleo->getLed2()=!mNfcNucleo->getLed2();
+ return on_error();
+ mNfcNucleo->get_led2()=!mNfcNucleo->get_led2();
printf("Tag wrote\r\n");
if(mRequestRefresh){
mRequestRefresh=false;
tag->write(mMsg);
}else
- tag->closeSession();
+ tag->close_session();
//if-else
};
@@ -127,14 +127,14 @@
/**
* if the user ask to update the value it open a new session
*/
- virtual void onSessionClose(NDefLib::NDefNfcTag *tag,bool success){
+ virtual void on_session_close(NDefLib::NDefNfcTag *tag,bool success){
if(!success)
- return onError();
- mNfcNucleo->getLed3()=!mNfcNucleo->getLed3();
+ return on_error();
+ mNfcNucleo->get_led3()=!mNfcNucleo->get_led3();
printf("Session Close\r\n");
if(mRequestRefresh){
mRequestRefresh=false;
- tag->openSession();
+ tag->open_session();
}else
mCommandFinish=true;
//if-else
@@ -149,11 +149,11 @@
/**
* Call back called when the user press the button.
*/
-static void setButtonPress(){
+static void set_button_press(){
buttonPress=true;
}//if buttonPress
-static void setNfcEventCallback(){
+static void set_nfc_event_callback(){
nfcEvent=true;
}//if buttonPress
@@ -163,39 +163,44 @@
void sampleAsync_countClick() {
//instance the board with the default parameters
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&setNfcEventCallback);
+ I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
+ XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel,&set_nfc_event_callback);
//set the button interrupt
- InterruptIn userButton(USER_BUTTON);
- //InterruptIn userButton(SW1);
- userButton.fall(setButtonPress);
+ #if defined(TARGET_STM)
+ InterruptIn userButton(USER_BUTTON);
+ #else
+ InterruptIn userButton(SW2);
+ #endif
+ userButton.fall(set_button_press);
- //No call back needed since default behavior is sync
- //nfcNucleo->getM24SR().GetSession();
- //nfcNucleo->getM24SR().ManageI2CGPO(I2C_ANSWER_READY); //switch to async mode
+ M24SR &nfcTag =nfcNucleo->get_M24SR();
+
+ //No call back needed since default behavior is sync
+ if(nfcTag.get_session()==M24SR::M24SR_SUCCESS)
+ nfcTag.manage_I2C_GPO(M24SR::I2C_ANSWER_READY);//Set async mode
//create the NDef message and record
NDefLib::Message msg;
MyRecord rClickCount;
- msg.addRecord(&rClickCount);
+ msg.add_record(&rClickCount);
WriteMyRecordCallback writeMyRecordCallback(nfcNucleo,msg);
- nfcNucleo->getM24SR().getNDefTag().setCallback(&writeMyRecordCallback);
- writeMyRecordCallback.updateMessage();
+ nfcNucleo->get_M24SR().get_NDef_tag().set_callback(&writeMyRecordCallback);
+ writeMyRecordCallback.update_message();
while(true){
if(buttonPress){
buttonPress=false;
//change the record content
- rClickCount.incrementClick();
+ rClickCount.increment_click();
printf("upgade Ndef message\r\n");
- writeMyRecordCallback.updateMessage();
+ writeMyRecordCallback.update_message();
}//if
if(nfcEvent){
nfcEvent=false;
- nfcNucleo->getM24SR().ManageEvent();
+ nfcNucleo->get_M24SR().manage_event();
}//if
//wait next event
__WFE();
--- a/Samples/SampleAsync_writeAndChangeAll.cpp Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/SampleAsync_writeAndChangeAll.cpp Thu Jul 13 09:41:01 2017 +0000
@@ -46,13 +46,14 @@
#include "NDefLib/RecordType/RecordText.h"
#include "NDefLib/RecordType/RecordMimeType.h"
#include "NDefLib/RecordType/RecordVCard.h"
+#include "NDefLib/RecordType/RecordWifiConf.h"
-#include "X_NUCLEO_NFC01A1.h"
+#include "XNucleoNFC01A1.h"
/**
* Shift the led status between the 3 leds.
*/
-static void shiftLed(DigitalOut &led1,DigitalOut &led2,DigitalOut &led3){
+static void shift_led(DigitalOut &led1,DigitalOut &led2,DigitalOut &led3){
const uint8_t prevLed1=led1;
const uint8_t prevLed2=led2;
const uint8_t prevLed3=led3;
@@ -65,45 +66,45 @@
* Print in the console some data about the record.
* @param r Record to print.
*/
-static void printRecord(NDefLib::Record *const r){
+static void print_record(NDefLib::Record *const r){
using namespace NDefLib;
- switch(r->getType()){
+ switch(r->get_type()){
case Record::TYPE_TEXT: {
const RecordText *const temp = ( RecordText* )r;
- printf("Read Text: %s\r\n",temp->getText().c_str());
+ printf("Read Text: %s\r\n",temp->get_text().c_str());
break; }
case Record::TYPE_AAR:{
const RecordAAR *const temp = ( RecordAAR* )r;
- printf("Read ARR: %s\r\n",temp->getPackage().c_str());
+ printf("Read ARR: %s\r\n",temp->get_package().c_str());
break; }
case Record::TYPE_MIME:{
const RecordMimeType *const temp = ( RecordMimeType* )r;
- printf("Read mimeType: %s\r\n",temp->getMimeType().c_str());
+ printf("Read mimeType: %s\r\n",temp->get_mime_type().c_str());
printf("Read mimeData: %s\r\n",
- std::string((const char*)temp->getMimeData(),
- temp->getMimeDataLenght()).c_str());
+ std::string((const char*)temp->get_mime_data(),
+ temp->get_mime_data_lenght()).c_str());
break;}
case Record::TYPE_URI:{
RecordURI *const temp = (RecordURI*)r;
- printf("Read uriId: %d\r\n",temp->getUriId());
- printf("Read uriType: %s\r\n",temp->getUriType().c_str());
- printf("Read uriContent: %s\r\n",temp->getContent().c_str());
+ printf("Read uriId: %d\r\n",temp->get_uri_id());
+ printf("Read uriType: %s\r\n",temp->get_uri_type().c_str());
+ printf("Read uriContent: %s\r\n",temp->get_content().c_str());
break;}
case Record::TYPE_URI_MAIL:{
const RecordMail*const temp = (RecordMail*)r;
- printf("Read Dest: %s\r\n",temp->getToAddress().c_str());
- printf("Read Subject: %s\r\n",temp->getSubject().c_str());
- printf("Read Body: %s\r\n",temp->getBody().c_str());
+ printf("Read Dest: %s\r\n",temp->get_to_address().c_str());
+ printf("Read Subject: %s\r\n",temp->get_subject().c_str());
+ printf("Read Body: %s\r\n",temp->get_body().c_str());
break;}
case Record::TYPE_URI_SMS:{
const RecordSMS*const temp = (RecordSMS*)r;
- printf("Read number: %s\r\n",temp->getNumber().c_str());
- printf("Read message: %s\r\n",temp->getMessagge().c_str());
+ printf("Read number: %s\r\n",temp->get_number().c_str());
+ printf("Read message: %s\r\n",temp->get_messagge().c_str());
break;}
case Record::TYPE_URI_GEOLOCATION:{
const RecordGeo*const temp = (RecordGeo*)r;
- printf("Read lat: %f\r\n",temp->getLatitude());
- printf("Read long: %f\r\n",temp->getLongitude());
+ printf("Read lat: %f\r\n",temp->get_latitude());
+ printf("Read long: %f\r\n",temp->get_longitude());
break;}
case Record::TYPE_MIME_VCARD:{
const RecordVCard *const temp = (RecordVCard*)r;
@@ -111,6 +112,13 @@
printf("Read Mail: %s\r\n",(*temp)[RecordVCard::EMAIL_WORK].c_str());
printf("Read ORG: %s\r\n",(*temp)[RecordVCard::ORGANIZATION].c_str());
break;}
+ case Record::TYPE_WIFI_CONF:{
+ const RecordWifiConf *const temp = (RecordWifiConf*)r;
+ printf("Nework Name: %s\r\n",temp->get_network_ssid().c_str());
+ printf("Nework Key: %s\r\n",temp->get_network_key().c_str());
+ printf("Nework Auth: %X\r\n",temp->get_auth_type());
+ printf("Nework Enc: %X\r\n",temp->get_encryption());
+ break;}
case Record::TYPE_UNKNOWN:{
printf("Unknown record\r\n");
break;}
@@ -121,46 +129,53 @@
* Change the record content.
* @param r Record to change.
*/
-static void changeRecord(NDefLib::Record const* r){
+static void change_record(NDefLib::Record const* r){
using namespace NDefLib;
- switch(r->getType()){
+ switch(r->get_type()){
case Record::TYPE_TEXT: {
RecordText *temp = (RecordText*)r;
- temp->setText("Hello");
+ temp->set_text("Hello");
break; }
case Record::TYPE_AAR:{
RecordAAR *temp = (RecordAAR*)r;
- temp->setPackage("set Package Ok");
+ temp->set_package("set Package Ok");
break; }
case Record::TYPE_MIME:{
RecordMimeType *temp = (RecordMimeType*)r;
- temp->copyMimeData((const uint8_t *)"String2",sizeof("String2"));
+ temp->copy_mime_data((const uint8_t *)"String2",sizeof("String2"));
break;}
case Record::TYPE_URI:{
RecordURI *temp = (RecordURI*)r;
- temp->setContent("mbed.com");
+ temp->set_content("mbed.com");
break;}
case Record::TYPE_URI_MAIL:{
RecordMail *temp = (RecordMail*)r;
- temp->setToAddress("newMail@st.com");
- temp->setSubject("tag change");
- temp->setBody("read/change Works!");
+ temp->set_to_address("newMail@st.com");
+ temp->set_subject("tag change");
+ temp->set_body("read/change Works!");
break;}
case Record::TYPE_URI_SMS:{
RecordSMS *temp = (RecordSMS*)r;
- temp->setMessage("Message Change");
- temp->setNumber("0987654321");
+ temp->set_message("Message Change");
+ temp->set_number("0987654321");
break;}
case Record::TYPE_URI_GEOLOCATION:{
RecordGeo *temp = (RecordGeo*)r;
- temp->setLatitude(-temp->getLatitude());
- temp->setLongitude(-temp->getLongitude());
+ temp->set_latitude(-temp->get_latitude());
+ temp->set_longitude(-temp->get_longitude());
break;}
case Record::TYPE_MIME_VCARD:{
RecordVCard *temp = (RecordVCard*)r;
(*temp)[RecordVCard::NAME]="name change";
(*temp)[RecordVCard::NICKNAME]="nic change";
break;}
+ case Record::TYPE_WIFI_CONF:{
+ RecordWifiConf * temp = (RecordWifiConf*)r;
+ temp->set_network_ssid("hackMe");
+ temp->set_network_key("qwerty");
+ temp->set_auth_type(RecordWifiConf::AUTH_WPA2_PSK);
+ temp->set_encryption_type(RecordWifiConf::ENC_TYPE_AES_TKIP);
+ break;}
case Record::TYPE_UNKNOWN:{
printf("Unknown record\r\n");
break;}
@@ -177,7 +192,7 @@
NDefLib::Message *mMsg; /// Message where read
bool *mDisableButton; /// enable the user button
- void onFinish(char *msg){
+ void on_finish(const char *const msg){
printf(msg);
*mDisableButton=false;
}
@@ -193,9 +208,9 @@
/**
* Create the message and ask to read it
*/
- virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+ virtual void on_session_open(NDefLib::NDefNfcTag *tag,bool success){
if(!success){
- return onFinish("Error Opening Session\r\n");
+ return on_finish("Error Opening Session\r\n");
}//if
mMsg = new NDefLib::Message;
tag->read(mMsg);
@@ -204,31 +219,31 @@
/**
* Print all the record inside the message
*/
- virtual void onMessageRead(NDefLib::NDefNfcTag *tag,bool success,
+ virtual void on_message_read(NDefLib::NDefNfcTag *tag,bool success,
const NDefLib::Message *readMsg){
- if(!success || readMsg->getNRecords()==0){
+ if(!success || readMsg->get_N_records()==0){
delete mMsg;
- return onFinish("Error Reading\r\n");
+ return on_finish("Error Reading\r\n");
}else{
printf("Message Read\r\n\n");
- for(uint32_t i=0;i<readMsg->getNRecords();i++){
+ for(uint32_t i=0;i<readMsg->get_N_records();i++){
NDefLib::Record *r = (*readMsg)[i];
- printRecord(r);
+ print_record(r);
delete r;
}//for
delete mMsg;
}//if-else
- tag->closeSession();
+ tag->close_session();
}
/**
* Enable the button
*/
- virtual void onSessionClose(NDefLib::NDefNfcTag *,bool success){
+ virtual void on_session_close(NDefLib::NDefNfcTag *,bool success){
if(success)
- onFinish("Read Session close\r\n");
+ on_finish("Read Session close\r\n");
else
- onFinish("Read Session close Error\r\n");
+ on_finish("Read Session close Error\r\n");
}
};
@@ -245,17 +260,17 @@
* Change all the record in the message.
* @param readMsg Message to change.
*/
- static void changeContent(const NDefLib::Message *readMsg){
- for(uint32_t i=0;i<readMsg->getNRecords();i++){
- changeRecord((*readMsg)[i]);
+ static void change_content(const NDefLib::Message *readMsg){
+ for(uint32_t i=0;i<readMsg->get_N_records();i++){
+ change_record((*readMsg)[i]);
}//for
}//changeContent
/**
* Delete all the record and the message.
*/
- void deleteMessage(){
- for(uint32_t i=0;i<mMsg->getNRecords();i++){
+ void delete_message(){
+ for(uint32_t i=0;i<mMsg->get_N_records();i++){
delete (*mMsg)[i];
}//for
delete mMsg;
@@ -272,7 +287,7 @@
/**
* Ask to read the tag content
*/
- virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+ virtual void on_session_open(NDefLib::NDefNfcTag *tag,bool success){
if(!success){
printf("Error Opening the session");
return;
@@ -284,14 +299,14 @@
/**
* Change the message content and write it back
*/
- virtual void onMessageRead(NDefLib::NDefNfcTag *tag,bool success,
+ virtual void on_message_read(NDefLib::NDefNfcTag *tag,bool success,
const NDefLib::Message *readMsg){
- if(!success || readMsg->getNRecords()==0){
+ if(!success || readMsg->get_N_records()==0){
printf("Error Reading\r\n");
- deleteMessage();
+ delete_message();
}else{
printf("Message Read: change message content\r\n");
- changeContent(readMsg);
+ change_content(readMsg);
printf("Start write new message\r\n");
tag->write(*mMsg);
}//if-else
@@ -300,12 +315,12 @@
/**
* Delete the Message and close the session
*/
- virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
+ virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success,
const NDefLib::Message &){
- deleteMessage();
+ delete_message();
if(success){
printf("Message Wrote\r\n");
- tag->closeSession();
+ tag->close_session();
}else
printf("Error Writing\r\n");
}//onMessageWrite
@@ -313,11 +328,11 @@
/**
* Set the callback for print the tag content and open a new session
*/
- virtual void onSessionClose(NDefLib::NDefNfcTag *tag,bool success){
+ virtual void on_session_close(NDefLib::NDefNfcTag *tag,bool success){
if(success){
printf("Change Session close\r\n");
- tag->setCallback(mReadMessage);
- tag->openSession();
+ tag->set_callback(mReadMessage);
+ tag->open_session();
}else
printf("Change Session close Error\r\n");
}
@@ -343,7 +358,7 @@
/**
*
*/
- virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+ virtual void on_session_open(NDefLib::NDefNfcTag *tag,bool success){
if(!success){
printf("Error Opening the Session\r\n");
return;
@@ -355,25 +370,28 @@
NDefLib::Message msg;
NDefLib::RecordAAR rAAR("com.st.BlueMS");
- msg.addRecord(&rAAR);
+ msg.add_record(&rAAR);
NDefLib::RecordSMS rSMS("123456789","st.com.BlueMS");
- msg.addRecord(&rSMS);
+ msg.add_record(&rSMS);
NDefLib::RecordGeo rGeo(123.123,-456.789);
- msg.addRecord(&rGeo);
+ msg.add_record(&rGeo);
NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
- msg.addRecord(&rUri);
+ msg.add_record(&rUri);
NDefLib::RecordMail rMail("mail@st.com","ciao","da nfc tag");
- msg.addRecord(&rMail);
+ msg.add_record(&rMail);
NDefLib::RecordMimeType rText1("text/plain",(const uint8_t*)"Ciao",4);
- msg.addRecord(&rText1);
+ msg.add_record(&rText1);
NDefLib::RecordText rText3(NDefLib::RecordText::UTF8,"it","ciao");
- msg.addRecord(&rText3);
+ msg.add_record(&rText3);
+
+ NDefLib::RecordWifiConf rWifi("OpenNetwork");
+ msg.add_record(&rWifi);
NDefLib::RecordVCard::VCardInfo_t cardInfo;
cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova prova1";
@@ -394,7 +412,7 @@
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);
+ msg.add_record(&rVCard);
//write it
tag->write(msg);
@@ -404,23 +422,23 @@
/**
* Close the session
*/
- virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
+ virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success,
const NDefLib::Message &){
if(!success)
printf("Error Writing\r\n");
printf("Message wrote\r\n");
- tag->closeSession();
+ tag->close_session();
}
/**
* Set the callback to print the tag content and open a new session
*/
- virtual void onSessionClose(NDefLib::NDefNfcTag *tag,bool success){
+ virtual void on_session_close(NDefLib::NDefNfcTag *tag,bool success){
if(success){
printf("Write Session close\r\n");
- tag->setCallback(mReadMessage);
- tag->openSession();
+ tag->set_callback(mReadMessage);
+ tag->open_session();
}else
printf("Write Session close Error\r\n");
}//onSessionClose
@@ -433,7 +451,7 @@
/**
* Call back called when the user press the button
*/
-static void setButtonPress(){
+static void set_button_press(){
buttonPress=true;
}//if buttonPress
@@ -442,9 +460,9 @@
/**
* Call back called when the user press the button
*/
-static void setNfcEvent(){
+static void set_nfc_event(){
nfcEvent=true;
-}//if buttonPress
+}//
/**
* Write a message and when the user press the button it read the message, change it and update it.
@@ -453,45 +471,51 @@
DigitalOut nucleoLed(LED1);
//instance the board with the default parameters
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&setNfcEvent);
+ I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
+ XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel,&set_nfc_event);
//retrieve the Nfc component
- M24SR &nfc = nfcNucleo->getM24SR();
+ M24SR &nfc = nfcNucleo->get_M24SR();
//retrieve the NdefLib interface
- NDefLib::NDefNfcTag& tag = nfc.getNDefTag();
+ NDefLib::NDefNfcTag& tag = nfc.get_NDef_tag();
//switch on the first led
- nfcNucleo->getLed1()=1;
- nfcNucleo->getLed2()=0;
- nfcNucleo->getLed3()=0;
+ nfcNucleo->get_led1()=1;
+ nfcNucleo->get_led2()=0;
+ nfcNucleo->get_led3()=0;
ReadMessageCallback readMessageCallback(&buttonPress);
WriteMessageCallback writeBigMessageCallback(&readMessageCallback);
ChangeMessageCallback changeMessageCallback(&readMessageCallback);
//Enable async mode
- if(nfcNucleo->getM24SR().GetSession()!=NFC_SUCCESS)
- nfcNucleo->getM24SR().ManageI2CGPO(I2C_ANSWER_READY);
+ if(nfc.get_session()==M24SR::M24SR_SUCCESS)
+ nfc.manage_I2C_GPO(M24SR::I2C_ANSWER_READY);
//write the message
- tag.setCallback(&writeBigMessageCallback);
- tag.openSession();
+ tag.set_callback(&writeBigMessageCallback);
+ tag.open_session();
//enable the button
- InterruptIn mybutton(USER_BUTTON);
- mybutton.fall(setButtonPress);
+ #if defined(TARGET_STM)
+ InterruptIn userButton(USER_BUTTON);
+ #else
+ InterruptIn userButton(SW2);
+ #endif
+ userButton.fall(set_button_press);
+ printf("Start main loop\r\n");
while(true) {
if(buttonPress){
- shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
- tag.setCallback(&changeMessageCallback);
- tag.openSession();
+ buttonPress=false;
+ shift_led(nfcNucleo->get_led1(),nfcNucleo->get_led2(),nfcNucleo->get_led3());
+ tag.set_callback(&changeMessageCallback);
+ tag.open_session();
}else if (nfcEvent){
+ nfcEvent=false;
nucleoLed=!nucleoLed;
- nfcNucleo->getM24SR().ManageEvent();
+ nfcNucleo->get_M24SR().manage_event();
}//if-else
__WFE();
}//while
-}
-
+}
\ No newline at end of file
--- a/Samples/SampleAsync_writeUrl.cpp Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/SampleAsync_writeUrl.cpp Thu Jul 13 09:41:01 2017 +0000
@@ -35,7 +35,7 @@
#include "mbed.h"
-#include "X_NUCLEO_NFC01A1.h"
+#include "XNucleoNFC01A1.h"
#include "NDefLib/NDefNfcTag.h"
#include "NDefLib/RecordType/RecordURI.h"
@@ -66,7 +66,7 @@
* @param tag tag where write the message
* @param success true if the session correctly open
*/
- virtual void onSessionOpen(NDefLib::NDefNfcTag *tag,bool success){
+ virtual void on_session_open(NDefLib::NDefNfcTag *tag,bool success){
if(!success){
printf("Error OpenSession\n\r");
}//else
@@ -76,7 +76,7 @@
NDefLib::Message msg;
NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
- msg.addRecord(&rUri);
+ msg.add_record(&rUri);
tag->write(msg);
}
@@ -87,7 +87,7 @@
* @param success true if the message is correctly wrote
* @param message wrote
*/
- virtual void onMessageWrite(NDefLib::NDefNfcTag *tag,bool success,
+ virtual void on_message_write(NDefLib::NDefNfcTag *tag,bool success,
const NDefLib::Message&){
if(!success)
@@ -96,7 +96,7 @@
printf("Tag Wrote!\n\r");
mOnWrite=1;
}//if-else
- tag->closeSession();
+ tag->close_session();
}
/**
@@ -104,7 +104,7 @@
* @param tag where the session is closed
* @param success true if the session is correctly close
*/
- virtual void onSessionClose(NDefLib::NDefNfcTag*,bool success){
+ virtual void on_session_close(NDefLib::NDefNfcTag*,bool success){
if(success){
printf("Session closed\n\r");
mOnCloseSession=1;
@@ -125,34 +125,30 @@
void sampleAsync_writeUrl(){
//create the nfc component
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&nfcInterruptCallback,
- X_NUCLEO_NFC01A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC01A1::DEFAULT_RF_DISABLE_PIN,
- X_NUCLEO_NFC01A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC01A1::DEFAULT_LED2_PIN,
- X_NUCLEO_NFC01A1::DEFAULT_LED3_PIN);
+ I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
+ XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel,&nfcInterruptCallback);
+
+
+ M24SR &nfcTag =nfcNucleo->get_M24SR();
- //No call back needed since default behavior is sync
- nfcNucleo->getM24SR().GetSession();
- nfcNucleo->getM24SR().ManageI2CGPO(I2C_ANSWER_READY); //switch to async mode
+ //No call back needed since default behavior is sync
+ if(nfcTag.get_session()==M24SR::M24SR_SUCCESS)
+ nfcTag.manage_I2C_GPO(M24SR::I2C_ANSWER_READY);//Set async mode
- NDefLib::NDefNfcTag &tag = nfcNucleo->getM24SR().getNDefTag();
- printf("System Init done!\n\r");
+ NDefLib::NDefNfcTag &tag = nfcNucleo->get_M24SR().get_NDef_tag();
//crate the callback to use for write a tag
- WriteUriCallbacks NDefCallback(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
- tag.setCallback(&NDefCallback); //set the callback
- tag.openSession(); //start the callback chain
+ WriteUriCallbacks NDefCallback(nfcNucleo->get_led1(),nfcNucleo->get_led2(),nfcNucleo->get_led3());
+ tag.set_callback(&NDefCallback); //set the callback
+ tag.open_session(); //start the callback chain
printf("Start Main Loop\n\r");
while(true){
if(nfcInterruptFlag){
nfcInterruptFlag=false;
//manage an async event from the nfc component
- nfcNucleo->getM24SR().ManageEvent();
-
+ nfcTag.manage_event();
}//if
__WFE();
}//while
-
}
-
--- a/Samples/SampleSync_countClick.cpp Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/SampleSync_countClick.cpp Thu Jul 13 09:41:01 2017 +0000
@@ -36,7 +36,7 @@
#include "mbed.h"
-#include "X_NUCLEO_NFC01A1.h"
+#include "XNucleoNFC01A1.h"
#include "NDefLib/NDefNfcTag.h"
#include "MyRecord.h"
@@ -44,24 +44,24 @@
* @param nfcNucleo Board where write the data.
* @param msg Message to write.
*/
-static void writeMessage(X_NUCLEO_NFC01A1 *nfcNucleo,NDefLib::Message &msg){
- NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
+static void write_message(XNucleoNFC01A1 *nfcNucleo,NDefLib::Message &msg){
+ NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag();
//open the i2c session with the nfc chip
- if(tag.openSession()){
+ if(tag.open_session()){
printf("Session opened\r\n");
- nfcNucleo->getLed1()=! nfcNucleo->getLed1();
+ nfcNucleo->get_led1()=! nfcNucleo->get_led1();
//write the tag
if(tag.write(msg)){
- printf("message wriote\r\n");
- nfcNucleo->getLed2()=!nfcNucleo->getLed2();
+ printf("message wrote\r\n");
+ nfcNucleo->get_led2()=!nfcNucleo->get_led2();
}//if
//close the i2c session
- if(tag.closeSession()){
+ if(tag.close_session()){
printf("Session closed\r\n");
- nfcNucleo->getLed3()=!nfcNucleo->getLed3();
+ nfcNucleo->get_led3()=!nfcNucleo->get_led3();
}
}//if open session
}//writeMessage
@@ -72,7 +72,7 @@
/**
* Call back called when the user press the button.
*/
-static void setButtonPress(){
+static void set_button_press(){
buttonPress=true;
}//if buttonPress
@@ -82,34 +82,34 @@
void sampleSync_countClick() {
//instance the board with the default paramiters
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
-
- //retrieve the NdefLib interface
- NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
-
+ I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
+ XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel);
+
//set the button interrupt
- InterruptIn userButton(USER_BUTTON);
- //InterruptIn userButton(SW1);
- userButton.fall(setButtonPress);
+ #if defined(TARGET_STM)
+ InterruptIn userButton(USER_BUTTON);
+ #else
+ InterruptIn userButton(SW2);
+ #endif
+ userButton.fall(set_button_press);
printf("Init Done\r\n");
//create the NDef message and record
NDefLib::Message msg;
MyRecord rClickCount;
- msg.addRecord(&rClickCount);
+ msg.add_record(&rClickCount);
- writeMessage(nfcNucleo,msg);
+ write_message(nfcNucleo,msg);
printf("Start Main Loop\r\n");
while(true){
if(buttonPress){
//change the record content
- rClickCount.incrementClick();
+ rClickCount.increment_click();
//write the new record content
- writeMessage(nfcNucleo,msg);
+ write_message(nfcNucleo,msg);
//wait a new button press
buttonPress=false;
}//if
@@ -117,4 +117,4 @@
__WFE();
}//while
-}//sample_countClick
\ No newline at end of file
+}//sample_countClick
--- a/Samples/SampleSync_lockWriteTag.cpp Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/SampleSync_lockWriteTag.cpp Thu Jul 13 09:41:01 2017 +0000
@@ -36,11 +36,12 @@
#include "mbed.h"
-#include "X_NUCLEO_NFC01A1.h"
+#include "XNucleoNFC01A1.h"
static volatile bool buttonPress=false;
static void setButtonPress(){
+ printf("button\r\n");
buttonPress=true;
}//if buttonPress
@@ -49,8 +50,8 @@
* @param nfcNucleo board where the lead lives
* @return let to switch on if the tag is read only
*/
-static inline DigitalOut& getReadOnlyLed(X_NUCLEO_NFC01A1 *nfcNucleo){
- return nfcNucleo->getLed2();
+static inline DigitalOut& getReadOnlyLed(XNucleoNFC01A1 *nfcNucleo){
+ return nfcNucleo->get_led2();
}
/**
@@ -58,8 +59,8 @@
* @param nfcNucleo board where the lead lives
* @return let to switch on if the tag is write only
*/
-static inline DigitalOut& getWriteableLed(X_NUCLEO_NFC01A1 *nfcNucleo){
- return nfcNucleo->getLed3();
+static inline DigitalOut& getWriteableLed(XNucleoNFC01A1 *nfcNucleo){
+ return nfcNucleo->get_led3();
}
/**
@@ -68,15 +69,16 @@
* @param tag helper class to manage the nfc tag
* @return true if the change has effect
*/
-bool enableReadOnly( X_NUCLEO_NFC01A1 *nfcNucleo){
-
- if(nfcNucleo->getM24SR().EnableReadOnly(M24SR::DEFAULT_PASSWORD)){
+bool enableReadOnly( XNucleoNFC01A1 *nfcNucleo){
+ if(nfcNucleo->get_M24SR().enable_read_only(M24SR::DEFAULT_PASSWORD) == M24SR::M24SR_SUCCESS){
printf("Enable Read Only\r\n");
getReadOnlyLed(nfcNucleo)=true;
getWriteableLed(nfcNucleo)=false;
return true;
- }else
+ }else{
+ printf("Error: enabling Read Only\r\n");
return false;
+ }
}
/**
@@ -85,50 +87,67 @@
* @param tag helper class to manage the nfc tag
* @return true if the change has effect
*/
-bool disableReadOnly( X_NUCLEO_NFC01A1 *nfcNucleo){
+bool disableReadOnly( XNucleoNFC01A1 *nfcNucleo){
- if(nfcNucleo->getM24SR().DisableReadOnly(M24SR::DEFAULT_PASSWORD)){
+ if(nfcNucleo->get_M24SR().disable_read_only(M24SR::DEFAULT_PASSWORD)== M24SR::M24SR_SUCCESS){
printf("Disable Read Only\r\n");
getReadOnlyLed(nfcNucleo)=false;
getWriteableLed(nfcNucleo)=true;
return true;
- }else
+ }else{
+ printf("Error: Disabling Read Only\r\n");
return false;
+ }
}
void sampleSync_lockTagContent() {
- Serial console(SERIAL_TX, SERIAL_RX);
+
+ I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- i2cChannel.frequency(400000);
-
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
+ XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel);
- NDefLib::NDefNfcTag &tag = nfcNucleo->getM24SR().getNDefTag();
+ NDefLib::NDefNfcTag &tag = nfcNucleo->get_M24SR().get_NDef_tag();
//when the user press the button set buttonPress to true
- InterruptIn userButton(USER_BUTTON);
+
+ #if defined(TARGET_STM)
+ InterruptIn userButton(USER_BUTTON);
+ #else
+ InterruptIn userButton(SW2);
+ #endif
+
userButton.fall(setButtonPress);
printf("Init Done\r\n");
//restore the board as read/write
- tag.openSession(true);
- nfcNucleo->getM24SR().DisableAllPassword(M24SR::DEFAULT_PASSWORD);
- tag.closeSession();
+ if(!tag.open_session(true)){
+ printf("Error open session\r\n");
+ return;
+ }
+ if(nfcNucleo->get_M24SR().disable_all_password(M24SR::DEFAULT_PASSWORD)!= M24SR::M24SR_SUCCESS){
+ printf("Error disable_all_password\r\n");
+ return;
+ }
+ if(!tag.close_session()){
+ printf("Error close session\r\n");
+ return;
+ }
+
getReadOnlyLed(nfcNucleo)=false;
getWriteableLed(nfcNucleo)=true;
bool tagIsLock=false;
printf("All Protection removed\r\n");
- nfcNucleo->getLed1()=true;
+ nfcNucleo->get_led1()=true;
while(true){
if(buttonPress){
- if(tag.openSession()){
+ printf("button pressed\r\n");
+ if(tag.open_session()){
bool changeStatusResult;
-
+ printf("session open\r\n");
if(!tagIsLock)
changeStatusResult=enableReadOnly(nfcNucleo);
else
@@ -137,10 +156,10 @@
if(changeStatusResult)
tagIsLock=!tagIsLock;
else
- console.printf("Error change the tag status");
- tag.closeSession();
+ printf("Error change the tag status\r\n");
+ tag.close_session();
}else{
- console.printf("Error opening the session, tag is in use");
+ printf("Error opening the session, tag is in use\r\n");
}
buttonPress=false;
}//if
@@ -149,4 +168,4 @@
__WFE();
}//while
-}//sample_countClick
\ No newline at end of file
+}//sample_countClick
--- a/Samples/SampleSync_writeAndChangeAll.cpp Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/SampleSync_writeAndChangeAll.cpp Thu Jul 13 09:41:01 2017 +0000
@@ -46,13 +46,14 @@
#include "NDefLib/RecordType/RecordText.h"
#include "NDefLib/RecordType/RecordMimeType.h"
#include "NDefLib/RecordType/RecordVCard.h"
+#include "NDefLib/RecordType/RecordWifiConf.h"
-#include "X_NUCLEO_NFC01A1.h"
+#include "XNucleoNFC01A1.h"
/**
* Shift the led status between the 3 leds.
*/
-static void shiftLed(DigitalOut &led1,DigitalOut &led2,DigitalOut &led3){
+static void shift_led(DigitalOut &led1,DigitalOut &led2,DigitalOut &led3){
const uint8_t prevLed1=led1;
const uint8_t prevLed2=led2;
const uint8_t prevLed3=led3;
@@ -65,33 +66,37 @@
* Create a message that contains all the possible records, and write it in the tag.
* @param tag Nfc tag where write the message.
*/
-static void writeNFCTag(NDefLib::NDefNfcTag &tag){
+static void write_nfc_tag(NDefLib::NDefNfcTag &tag){
- bool writeStatus,closeStatus;
- if(tag.openSession()){
+ bool writeStatus=false;
+ bool closeStatus=false;
+ if(tag.open_session()){
printf("Open session\r\n");
NDefLib::Message msg;
NDefLib::RecordAAR rAAR("com.st.BlueMS");
- msg.addRecord(&rAAR);
+ msg.add_record(&rAAR);
NDefLib::RecordSMS rSMS("123456789","st.com.BlueMS");
- msg.addRecord(&rSMS);
+ msg.add_record(&rSMS);
NDefLib::RecordGeo rGeo(123.123,-456.789);
- msg.addRecord(&rGeo);
+ msg.add_record(&rGeo);
NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"http://www.st.com");
- msg.addRecord(&rUri);
+ msg.add_record(&rUri);
NDefLib::RecordMail rMail("mail@st.com","ciao","da nfc tag");
- msg.addRecord(&rMail);
+ msg.add_record(&rMail);
NDefLib::RecordMimeType rText1("text/plain",(const uint8_t*)"ciao",4);
- msg.addRecord(&rText1);
+ msg.add_record(&rText1);
NDefLib::RecordText rText3(NDefLib::RecordText::UTF8,"it","ciao");
- msg.addRecord(&rText3);
+ msg.add_record(&rText3);
+
+ NDefLib::RecordWifiConf rWifi("OpenNetworkd");
+ msg.add_record(&rWifi);
NDefLib::RecordVCard::VCardInfo_t cardInfo;
cardInfo[NDefLib::RecordVCard::FORMATTED_NAME]="prova prova1";
@@ -112,11 +117,11 @@
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);
+ msg.add_record(&rVCard);
writeStatus = tag.write(msg);
- closeStatus = tag.closeSession();
+ closeStatus = tag.close_session();
}else
printf("Error open Session\n\r");
@@ -136,45 +141,45 @@
* Print the record content.
* @param r Record to print.
*/
-static void printRecord(NDefLib::Record *const r){
+static void print_record(NDefLib::Record *const r){
using namespace NDefLib;
- switch(r->getType()){
+ switch(r->get_type()){
case Record::TYPE_TEXT: {
const RecordText *const temp = ( RecordText* )r;
- printf("Read Text: %s\r\n",temp->getText().c_str());
+ printf("Read Text: %s\r\n",temp->get_text().c_str());
break; }
case Record::TYPE_AAR:{
const RecordAAR *const temp = ( RecordAAR* )r;
- printf("Read ARR: %s\r\n",temp->getPackage().c_str());
+ printf("Read ARR: %s\r\n",temp->get_package().c_str());
break; }
case Record::TYPE_MIME:{
const RecordMimeType *const temp = ( RecordMimeType* )r;
- printf("Read mimeType: %s\r\n",temp->getMimeType().c_str());
+ printf("Read mimeType: %s\r\n",temp->get_mime_type().c_str());
printf("Read mimeData: %s\r\n",
- std::string((const char*)temp->getMimeData(),
- temp->getMimeDataLenght()).c_str());
+ std::string((const char*)temp->get_mime_data(),
+ temp->get_mime_data_lenght()).c_str());
break;}
case Record::TYPE_URI:{
RecordURI *const temp = (RecordURI*)r;
- printf("Read uriId: %d\r\n",temp->getUriId());
- printf("Read uriType: %s\r\n",temp->getUriType().c_str());
- printf("Read uriContent: %s\r\n",temp->getContent().c_str());
+ printf("Read uriId: %d\r\n",temp->get_uri_id());
+ printf("Read uriType: %s\r\n",temp->get_uri_type().c_str());
+ printf("Read uriContent: %s\r\n",temp->get_content().c_str());
break;}
case Record::TYPE_URI_MAIL:{
const RecordMail*const temp = (RecordMail*)r;
- printf("Read Dest: %s\r\n",temp->getToAddress().c_str());
- printf("Read Subject: %s\r\n",temp->getSubject().c_str());
- printf("Read Body: %s\r\n",temp->getBody().c_str());
+ printf("Read Dest: %s\r\n",temp->get_to_address().c_str());
+ printf("Read Subject: %s\r\n",temp->get_subject().c_str());
+ printf("Read Body: %s\r\n",temp->get_body().c_str());
break;}
case Record::TYPE_URI_SMS:{
const RecordSMS*const temp = (RecordSMS*)r;
- printf("Read number: %s\r\n",temp->getNumber().c_str());
- printf("Read message: %s\r\n",temp->getMessagge().c_str());
+ printf("Read number: %s\r\n",temp->get_number().c_str());
+ printf("Read message: %s\r\n",temp->get_messagge().c_str());
break;}
case Record::TYPE_URI_GEOLOCATION:{
const RecordGeo*const temp = (RecordGeo*)r;
- printf("Read lat: %f\r\n",temp->getLatitude());
- printf("Read long: %f\r\n",temp->getLongitude());
+ printf("Read lat: %f\r\n",temp->get_latitude());
+ printf("Read long: %f\r\n",temp->get_longitude());
break;}
case Record::TYPE_MIME_VCARD:{
const RecordVCard *const temp = (RecordVCard*)r;
@@ -182,6 +187,13 @@
printf("Read Mail: %s\r\n",(*temp)[RecordVCard::EMAIL_WORK].c_str());
printf("Read ORG: %s\r\n",(*temp)[RecordVCard::ORGANIZATION].c_str());
break;}
+ case Record::TYPE_WIFI_CONF:{
+ const RecordWifiConf *const temp = (RecordWifiConf*)r;
+ printf("Nework Name: %s\r\n",temp->get_network_ssid().c_str());
+ printf("Nework Key: %s\r\n",temp->get_network_key().c_str());
+ printf("Nework Auth: %X\r\n",temp->get_auth_type());
+ printf("Nework Enc: %X\r\n",temp->get_encryption());
+ break;}
case Record::TYPE_UNKNOWN:{
printf("Unknown record\r\n");
break;}
@@ -192,46 +204,53 @@
* Change the record content.
* @param r Record to change.
*/
-static void changeRecord(NDefLib::Record const* r){
+static void change_record(NDefLib::Record const* r){
using namespace NDefLib;
- switch(r->getType()){
+ switch(r->get_type()){
case Record::TYPE_TEXT: {
RecordText *temp = (RecordText*)r;
- temp->setText("Hello");
+ temp->set_text("Hello");
break; }
case Record::TYPE_AAR:{
RecordAAR *temp = (RecordAAR*)r;
- temp->setPackage("set Package Ok");
+ temp->set_package("set Package Ok");
break; }
case Record::TYPE_MIME:{
RecordMimeType *temp = (RecordMimeType*)r;
- temp->copyMimeData((const uint8_t *)"String2",sizeof("String2"));
+ temp->copy_mime_data((const uint8_t *)"String2",sizeof("String2"));
break;}
case Record::TYPE_URI:{
RecordURI *temp = (RecordURI*)r;
- temp->setContent("mbed.com");
+ temp->set_content("mbed.com");
break;}
case Record::TYPE_URI_MAIL:{
RecordMail *temp = (RecordMail*)r;
- temp->setToAddress("newMail@st.com");
- temp->setSubject("tag change");
- temp->setBody("read/change Works!");
+ temp->set_to_address("newMail@st.com");
+ temp->set_subject("tag change");
+ temp->set_body("read/change Works!");
break;}
case Record::TYPE_URI_SMS:{
RecordSMS *temp = (RecordSMS*)r;
- temp->setMessage("Message Change");
- temp->setNumber("0987654321");
+ temp->set_message("Message Change");
+ temp->set_number("0987654321");
break;}
case Record::TYPE_URI_GEOLOCATION:{
RecordGeo *temp = (RecordGeo*)r;
- temp->setLatitude(-temp->getLatitude());
- temp->setLongitude(-temp->getLongitude());
+ temp->set_latitude(-temp->get_latitude());
+ temp->set_longitude(-temp->get_longitude());
break;}
case Record::TYPE_MIME_VCARD:{
RecordVCard *temp = (RecordVCard*)r;
(*temp)[RecordVCard::NAME]="name change";
(*temp)[RecordVCard::NICKNAME]="nic change";
break;}
+ case Record::TYPE_WIFI_CONF:{
+ RecordWifiConf * temp = (RecordWifiConf*)r;
+ temp->set_network_ssid("hackMe");
+ temp->set_network_key("qwerty");
+ temp->set_auth_type(RecordWifiConf::AUTH_WPA2_PSK);
+ temp->set_encryption_type(RecordWifiConf::ENC_TYPE_AES_TKIP);
+ break;}
case Record::TYPE_UNKNOWN:{
printf("Unknown record\r\n");
break;}
@@ -242,27 +261,27 @@
* Read the nfc message and print the content on the serial console
* @param tag Nfc tag where read the content
*/
-static void readAndPrintNfcTag(NDefLib::NDefNfcTag &tag){
+static void read_and_print_nfc_tag(NDefLib::NDefNfcTag &tag){
using namespace NDefLib;
- if(tag.openSession()){
+ if(tag.open_session()){
printf("Open Session\r\n");
NDefLib::Message readMsg;
tag.read(&readMsg);
printf("Message Read\r\n");
- if(readMsg.getNRecords()==0){
+ if(readMsg.get_N_records()==0){
printf("Error Read\r\n");
}else{
- for(uint32_t i=0;i<readMsg.getNRecords();i++){
+ for(uint32_t i=0;i<readMsg.get_N_records();i++){
Record *r = readMsg[i];
- printRecord(r);
+ print_record(r);
delete r;
}//for
}//if-else
- tag.closeSession();
+ tag.close_session();
printf("Close session\r\n");
}else{
printf("Error open read Session\n\r");
@@ -273,29 +292,29 @@
* Read a nfc message, change the content of each record and write the new message.
* @param tag Tag where read and write the nfc message.
*/
-static void readAndChangeNfcTag(NDefLib::NDefNfcTag &tag){
+static void read_and_change_nfc_tag(NDefLib::NDefNfcTag &tag){
using NDefLib::Record;
using NDefLib::Message;
- if(tag.openSession()){
+ if(tag.open_session()){
printf("Open Session\r\n");
Message readMsg;
tag.read(&readMsg);
printf("Read Message\r\n");
- if(readMsg.getNRecords()==0){
+ if(readMsg.get_N_records()==0){
printf("Error Read\r\n");
}else{
- for(uint32_t i=0;i<readMsg.getNRecords();i++){
+ for(uint32_t i=0;i<readMsg.get_N_records();i++){
Record *r = readMsg[i];
- changeRecord(r);
+ change_record(r);
}//for
tag.write(readMsg);
printf("Message Wrote\r\n");
}//if-else
- tag.closeSession();
+ tag.close_session();
printf("Close Session\r\n");
}else{
printf("Error open SessionChange\n\r");
@@ -307,7 +326,7 @@
/**
* Call back called when the user press the button
*/
-static void setButtonPress(){
+static void set_button_press(){
buttonPress=true;
}//if buttonPress
@@ -317,38 +336,40 @@
void sampleSync_writeAndChangeAll() {
//instance the board with the default paramiters
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
+ I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
+ XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel);
//retrieve the NdefLib interface
- NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
+ NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag();
//switch on the first led
- nfcNucleo->getLed1()=1;
- nfcNucleo->getLed2()=0;
- nfcNucleo->getLed3()=0;
+ nfcNucleo->get_led1()=1;
+ nfcNucleo->get_led2()=0;
+ nfcNucleo->get_led3()=0;
printf("Init Done\r\n");
//write the message
- writeNFCTag(tag);
+ write_nfc_tag(tag);
//read the message and write it on console
- readAndPrintNfcTag(tag);
+ read_and_print_nfc_tag(tag);
//enable the button
- InterruptIn mybutton(USER_BUTTON);
- //InterruptIn mybutton(SW2);
- mybutton.fall(setButtonPress);
+ #if defined(TARGET_STM)
+ InterruptIn userButton(USER_BUTTON);
+ #else
+ InterruptIn userButton(SW2);
+ #endif
+ userButton.fall(set_button_press);
//each second change the led status and see if the user press the button
while(true) {
if(buttonPress){
//update the message content
- readAndChangeNfcTag(tag);
+ read_and_change_nfc_tag(tag);
//write the new message on console
- readAndPrintNfcTag(tag);
- shiftLed(nfcNucleo->getLed1(),nfcNucleo->getLed2(),nfcNucleo->getLed3());
+ read_and_print_nfc_tag(tag);
+ shift_led(nfcNucleo->get_led1(),nfcNucleo->get_led2(),nfcNucleo->get_led3());
buttonPress=false;
- }
- }
-
+ }//if
+ }//while
}
\ No newline at end of file
--- a/Samples/SampleSync_writeUrl.cpp Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/SampleSync_writeUrl.cpp Thu Jul 13 09:41:01 2017 +0000
@@ -35,7 +35,7 @@
#include "mbed.h"
-#include "X_NUCLEO_NFC01A1.h"
+#include "XNucleoNFC01A1.h"
#include "NDefLib/NDefNfcTag.h"
#include "NDefLib/RecordType/RecordURI.h"
@@ -43,33 +43,33 @@
* Write a Ndef linking the st.com site.
*/
void sampleSync_writeUrl() {
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel);
+ I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
+ XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel);
//retrieve the NdefLib interface
- NDefLib::NDefNfcTag& tag = nfcNucleo->getM24SR().getNDefTag();
+ NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag();
printf("System Init done: !\r\n");
//open the i2c session with the nfc chip
- if(tag.openSession()){
- nfcNucleo->getLed1()=1;
+ if(tag.open_session()){
+ nfcNucleo->get_led1()=1;
//create the NDef message and record
NDefLib::Message msg;
NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com");
- msg.addRecord(&rUri);
+ msg.add_record(&rUri);
//write the tag
if(tag.write(msg)){
printf("Tag writed \r\n");
- nfcNucleo->getLed2()=1;
+ nfcNucleo->get_led2()=1;
}
//close the i2c session
- if(!tag.closeSession()){
+ if(!tag.close_session()){
printf("Error Closing the session\r\n");
}else
- nfcNucleo->getLed3()=1;
+ nfcNucleo->get_led3()=1;
}else
printf("Error open Session\r\n");
}
--- a/Samples/sampleAsync_lockWriteTag.cpp Wed Aug 31 15:14:08 2016 +0000
+++ b/Samples/sampleAsync_lockWriteTag.cpp Thu Jul 13 09:41:01 2017 +0000
@@ -36,26 +36,26 @@
#include "mbed.h"
-#include "X_NUCLEO_NFC01A1.h"
+#include "XNucleoNFC01A1.h"
static volatile bool buttonPress=false; /// true when the user press the message
static volatile bool nfcEvent=false; /// true when the user press the message
-static void setNfcEventCallback(){
+static void set_nfc_event_callback(){
nfcEvent=true;
}//if buttonPress
/**
* Call back called when the user press the button.
*/
-static void setButtonPress(){
+static void set_button_press(){
buttonPress=true;
}//if buttonPress
/**
* Class with the command chain needed to remove all the read/write password
*/
-class RemoveAllPasswordStatusCallback : public Nfc::Callbacks {
+class RemoveAllPasswordStatusCallback : public M24SR::Callbacks {
public:
@@ -65,7 +65,7 @@
* True when the command chain finish, and the tag can now be read and write
* @return true if the command chain finish
*/
- bool isFinish(){
+ bool is_finish(){
return !mIsComamndRunning;
}
@@ -77,46 +77,46 @@
* end the command chain and print an error message
* @param status error code of the last command
*/
- void onError(const NFC_StatusTypeDef status){
+ void on_error(const M24SR::StatusTypeDef status){
mIsComamndRunning=false;
printf("Error Code: %X \r\n",status);
}
- virtual void onSessionOpen(Nfc *tag,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_session_open(M24SR *tag,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
mIsComamndRunning=true;
printf("Session Opened\r\n");
- tag->SelectApplication();
+ tag->select_application();
}
- virtual void onSelectedApplication(Nfc *tag,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_selected_application(M24SR *tag,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Select application\r\n");
- tag->SelectNDEFfile(0x0001);
+ tag->select_NDEF_file(0x0001);
}
- virtual void onSelectedNDEFFile(Nfc *tag,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_selected_NDEF_file(M24SR *tag,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Select NDef\r\n");
- tag->DisableAllPassword(M24SR::DEFAULT_PASSWORD);
+ tag->disable_all_password(M24SR::DEFAULT_PASSWORD);
}
- virtual void onDisableAllPassword(Nfc *tag, NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_disable_all_password(M24SR *tag, M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Disable all Password\r\n");
- tag->Deselect();
+ tag->deselect();
}
- virtual void onDeselect(Nfc *,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_deselect(M24SR *,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Close Application\r\n");
mIsComamndRunning=false;
@@ -127,7 +127,7 @@
/**
* Chain of call needed to change the tag status between read only and write/read
*/
-class ChangeTagStatusCallback : public Nfc::Callbacks {
+class ChangeTagStatusCallback : public M24SR::Callbacks {
M24SR &mNfcTag; /// object to change
DigitalOut& mReadOnlyLed; /// led to switch on when it is in read only mode
@@ -154,11 +154,11 @@
/**
* Change the tag status
*/
- void changeStatus(){
+ void change_status(){
mIsReadOnly=!mIsReadOnly;
//if it is not running a previous command
if(!mIsComamndRunning){
- mNfcTag.GetSession();
+ mNfcTag.get_session();
}//if
}//changeStatus;
@@ -168,68 +168,68 @@
* When an error happen switch on both the led and print the error code.
* @param status Error code.
*/
- void onError(const NFC_StatusTypeDef status){
+ void on_error(const M24SR::StatusTypeDef status){
mIsComamndRunning=false;
mReadOnlyLed=true;
mReadWriteWriteLed=true;
printf("Error %X changing the status\r\n",status);
}
- virtual void onSessionOpen(Nfc *,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_session_open(M24SR *,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Session Open\r\n");
- mNfcTag.SelectApplication();
+ mNfcTag.select_application();
}
- virtual void onSelectedApplication(Nfc *,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_selected_application(M24SR *,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Select Application\r\n");
- mNfcTag.SelectNDEFfile(0x0001);
+ mNfcTag.select_NDEF_file(0x0001);
}
- virtual void onSelectedNDEFFile(Nfc *,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_selected_NDEF_file(M24SR *,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Select NDef file\r\n");
if(mIsReadOnly){
- mNfcTag.EnableReadOnly(M24SR::DEFAULT_PASSWORD);
+ mNfcTag.enable_read_only(M24SR::DEFAULT_PASSWORD);
}else
- mNfcTag.DisableReadOnly(M24SR::DEFAULT_PASSWORD);
+ mNfcTag.disable_read_only(M24SR::DEFAULT_PASSWORD);
}
- virtual void onEnableReadOnly(Nfc *,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_enable_read_only(M24SR *,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Ready only Enabled\r\n");
if(!mIsReadOnly) //if in the meantime the status change
- mNfcTag.DisableReadOnly(M24SR::DEFAULT_PASSWORD);
+ mNfcTag.disable_read_only(M24SR::DEFAULT_PASSWORD);
else{
mReadOnlyLed=true;
mReadWriteWriteLed=false;
- mNfcTag.Deselect();
+ mNfcTag.deselect();
}
}
- virtual void onDisableReadOnly(Nfc *,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_disable_read_only(M24SR *,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Ready only Disabled\r\n");
if(mIsReadOnly) //if in the meantime the status change
- mNfcTag.EnableReadOnly(M24SR::DEFAULT_PASSWORD);
+ mNfcTag.enable_read_only(M24SR::DEFAULT_PASSWORD);
else{
mReadOnlyLed=false;
mReadWriteWriteLed=true;
- mNfcTag.Deselect();
+ mNfcTag.deselect();
}
}
- virtual void onDeselect(Nfc *,NFC_StatusTypeDef status){
- if(status!=NFC_SUCCESS)
- return onError(status);
+ virtual void on_deselect(M24SR *,M24SR::StatusTypeDef status){
+ if(status!=M24SR::M24SR_SUCCESS)
+ return on_error(status);
printf("Close Application\r\n");
mIsComamndRunning=false;
}
@@ -241,40 +241,44 @@
void sampleAsync_lockTagContent() {
//instance the board with the default parameters
- I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
- X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,&setNfcEventCallback);
+ I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
+ XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel,&set_nfc_event_callback);
//when the user press the button set buttonPress to true
- InterruptIn userButton(USER_BUTTON);
- userButton.fall(setButtonPress);
+ #if defined(TARGET_STM)
+ InterruptIn userButton(USER_BUTTON);
+ #else
+ InterruptIn userButton(SW2);
+ #endif
+ userButton.fall(set_button_press);
- M24SR &nfcTag =nfcNucleo->getM24SR();
+ M24SR &nfcTag =nfcNucleo->get_M24SR();
//set async mode
- if(nfcTag.GetSession()!=NFC_SUCCESS)
- nfcTag.ManageI2CGPO(I2C_ANSWER_READY);
+ if(nfcTag.get_session()==M24SR::M24SR_SUCCESS)
+ nfcTag.manage_I2C_GPO(M24SR::I2C_ANSWER_READY);
- ChangeTagStatusCallback changeTagStatus(nfcTag,nfcNucleo->getLed2(),nfcNucleo->getLed3());
+ ChangeTagStatusCallback changeTagStatus(nfcTag,nfcNucleo->get_led2(),nfcNucleo->get_led3());
RemoveAllPasswordStatusCallback removeAllPasswordStatusCallback;
- nfcTag.SetCallback(&removeAllPasswordStatusCallback);
- nfcTag.GetSession();
- nfcNucleo->getLed1()=true;
+ nfcTag.set_callback(&removeAllPasswordStatusCallback);
+ nfcTag.get_session();
+ nfcNucleo->get_led1()=true;
while(true){
- if(buttonPress && removeAllPasswordStatusCallback.isFinish()){
+ if(buttonPress && removeAllPasswordStatusCallback.is_finish()){
buttonPress=false;
- nfcTag.SetCallback(&changeTagStatus);
- changeTagStatus.changeStatus();
+ nfcTag.set_callback(&changeTagStatus);
+ changeTagStatus.change_status();
}//if
if(nfcEvent){
nfcEvent=false;
- nfcTag.ManageEvent();
+ nfcTag.manage_event();
}
//wait next event
__WFE();
}//while
-}//sampleAsync_lockTagContent
\ No newline at end of file
+}//sampleAsync_lockTagContent
--- a/X_NUCLEO_NFC01A1.lib Wed Aug 31 15:14:08 2016 +0000 +++ b/X_NUCLEO_NFC01A1.lib Thu Jul 13 09:41:01 2017 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ST/code/X_NUCLEO_NFC01A1/#2090378b0b51 +http://developer.mbed.org/teams/ST/code/X_NUCLEO_NFC01A1/#7b2b4dbed7ae
--- a/main.cpp Wed Aug 31 15:14:08 2016 +0000 +++ b/main.cpp Thu Jul 13 09:41:01 2017 +0000 @@ -34,10 +34,10 @@ #include "Samples/Samples.h" //choose the demo to compile -#define SAMPLE_WRITE_URL +//#define SAMPLE_WRITE_URL //#define SAMPLE_COUNT_CLICK //#define SAMPLE_WRITE_AND_CHANGE_ALL -//#define SAMPLE_LOCK_TAG_CONTENT +#define SAMPLE_LOCK_TAG_CONTENT //uncomment for the async example #define SYNC_MODE
--- a/mbed.bld Wed Aug 31 15:14:08 2016 +0000 +++ b/mbed.bld Thu Jul 13 09:41:01 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/2241e3a39974 \ No newline at end of file +https://mbed.org/users/mbed_official/code/mbed/builds/22da6e220af6 \ No newline at end of file
