M2M im2ag M2PGI

Dependencies:   mbed X_NUCLEO_NFC01A1 NDefLib

Revision:
4:47b9a09a74bf
Parent:
2:7183a6189b65
Child:
5:b75a06d210fd
--- a/main.cpp	Tue Mar 08 15:45:08 2016 +0000
+++ b/main.cpp	Tue Mar 15 14:49:45 2016 +0000
@@ -3,12 +3,22 @@
 
 #include "X_NUCLEO_NFC01A1.h"
 #include "NDefLib/NDefNfcTag.h"
+#include "NDefLib/Message.h"
 #include "NDefLib/RecordType/RecordURI.h"
-
+Serial pc(SERIAL_TX, SERIAL_RX);
+DigitalOut myled(LED1);
 /**
  * Write a Ndef URI message linking to st.com site.
  */
+void init(){
+    pc.baud(115200);
+    pc.format(8,SerialBase::None, 1);
+}
+ 
 int main(void){
+    init();
+    pc.printf("System Init now !\n");
+    myled = 0; // LED is OFF
     
     //use default board pinout
     I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN);
@@ -16,14 +26,17 @@
             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);
+     nfcNucleo->getLed1()=0;
+        
     
     //retrieve the NdefLib interface
     NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag();
-    printf("System Init done: !\n\r");
+    printf("System Init done: !\n");
     
     //open the i2c session with the nfc chip
     if(tag.openSession()){
-        printf("Session opened\n\r");
+        printf("Session opened\n");
+        
         nfcNucleo->getLed1()=1;
         
         //create the NDef message and record
@@ -33,20 +46,38 @@
 
         //write the tag
         if(tag.write(msg)){
-            printf("Tag written\n\r");
+            printf("Tag written\n");
             nfcNucleo->getLed2()=1;
+            
         }else{
-            printf("Error writing \n\r");
+            printf("Error writing \n");
         }//if-else
-
+        NDefLib::Message message;
+        while(!tag.read(&message)){
+        }
+        while(!tag.read(&message)){
+        }
+        
+        uint8_t buffer[64];
+        buffer[0]=0;
+        buffer[1]=3;
+        
+        message.write(buffer);
+        buffer[63]=0;
+        for(int i=0; i< 63; i++){
+            printf("%c",buffer[i]);
+        }
+        printf("\n");
         //close the i2c session
         if(tag.closeSession()){
-           printf("Session closed\n\r");
+           myled = 1; // LED is ON
+           printf("Session closed\n");
            nfcNucleo->getLed3()=1;
         }else{
-           printf("Error closing the session\n\r");
+           printf("Error closing the session\n");
         }//if-else
             
     }else
-        printf("Error opening the session\n\r");
+        printf("Error opening the session\n");
+    
 }
\ No newline at end of file