PROGRAMA COMPLETO
Dependencies: PN532_MK20 USBDevice mbed
Revision 2:e2d9212cbca3, committed 2015-04-24
- Comitter:
- mauroar211
- Date:
- Fri Apr 24 20:31:21 2015 +0000
- Parent:
- 1:6d99a2efadc6
- Child:
- 3:74dccd92e7f2
- Commit message:
- PROGRAMA COMPLETO
Changed in this revision
--- a/Main.cpp Fri Apr 24 19:34:10 2015 +0000 +++ b/Main.cpp Fri Apr 24 20:31:21 2015 +0000 @@ -19,13 +19,14 @@ enum estados{ espera = 0x00, leerTagID = 0x01, - escribirTag = 0x02, + escribirTag = 0x02, + emularTag = 0x03 }; estados miestado; - - +uint8_t ndefBuf[128]; //EL MENSAJE NO PUEDE SUPERAR LOS 128 CARACTERES. +char buffertexto[15]; // configurando pines del led RGB como salida DigitalOut red (LED1); DigitalOut green (LED2); @@ -51,6 +52,9 @@ char bufferRecibido[10]; char bufferLeer[10] = "leer"; char bufferEscribir[10] = "escribir"; + char bufferEmular[10] = "emular"; + + @@ -66,7 +70,9 @@ { miestado = escribirTag; } - + else if(strcmp(bufferRecibido, bufferEmular) == 0){ + miestado = emularTag; + } } @@ -95,6 +101,18 @@ miestado = espera; } +void estadoEmular() +{ + + int valorRetorno1 = 0; + + while(valorRetorno1 == 0) + { + valorRetorno1 = emularTagNFC(); + + } + miestado = espera; +} /* -------------------------------------------------------------- ---- FUNCION MAIN PRINCIPAL @@ -110,6 +128,7 @@ switch(miestado) { case espera: + usb.printf("-----Esperando comando-----\r\n "); estadoEspera(); break; @@ -119,6 +138,13 @@ case escribirTag: estadoEscribir(); + break; + + case emularTag: + usb.printf("escriba una palabra \r\n"); + usb.scanf("%s", buffertexto);//LEE LOS DATOS DE ENTRADA POR CONSOLA + usb.printf("\r\nUsted Escribio - |%s| \r\n ", buffertexto);//MUESTRA LOS DATOS RECIBIDOS + estadoEmular(); break; }
--- a/UtilidadesNFC.cpp Fri Apr 24 19:34:10 2015 +0000 +++ b/UtilidadesNFC.cpp Fri Apr 24 20:31:21 2015 +0000 @@ -9,6 +9,8 @@ #include "PN532.h" #include "USBSerial.h" #include "UtilidadesNFC.h" +#include "snep.h" +#include "NdefMessage.h" /* -------------------------------------------------------------- @@ -19,6 +21,8 @@ extern DigitalOut red; extern DigitalOut green; extern DigitalOut blue; +extern uint8_t ndefBuf[128]; +extern char buffertexto[15]; /* -------------------------------------------------------------- @@ -105,4 +109,39 @@ wait(2); } -} \ No newline at end of file +} + +int emularTagNFC(){ + + uint8_t ndefBuf[128]; //EL MENSAJE NO PUEDE SUPERAR LOS 128 CARACTERES. + //Se inicializa el modulo de comunicacion SPI en los pines D11 (MOSI), D12 (MISO) y D13(CLK) + SPI spi(D11, D12, D13); + //se selecciona el pin SS (slave selector) + PN532_SPI pn532spi(spi, D10); + //configura el chip en modo emulacion de tarjeta + SNEP nfc(pn532spi); + + //uint8_t ndefBuf[128]; //EL MENSAJE NO PUEDE SUPERAR LOS 128 CARACTERES. + + while (1) { + usb.printf("\r ENVIANDO MENSAJE - \n\r "); + NdefMessage message = NdefMessage(); + message.addTextRecord(buffertexto);//COMANDO UTILIZADO PARA ENVIAR TEXTO PLANO + //message.addUriRecord("http://www.pizzaspiccolo.com.co/");//COMANDO UTILIZADO PARA ENVIAR UNA URL + int messageSize = message.getEncodedSize();//OBTIENE EL TAMAÑO TOTAL DEL MENSAJE (ENCABEZADO + TEXTO) + if (messageSize > sizeof(ndefBuf)) { + usb.printf("EL MENSAJE ES DEMASIADO GRANDE\r\n"); + + } + message.encode(ndefBuf);//ENCAPSULA EL ENCABEZADO Y EL MENSAJE EN EL BUFFER + if (0 >= nfc.write(ndefBuf, messageSize)) {//ESCRIBE EL MENSAJE EN UN DISPOSITIVO MOVIL COMPATIBLE + usb.printf("FALLO\r\n"); + } else { + usb.printf("MENSAJE ENVIADO\r\n"); + return 1; + } + + wait(1); + } + +} \ No newline at end of file
--- a/UtilidadesNFC.h Fri Apr 24 19:34:10 2015 +0000 +++ b/UtilidadesNFC.h Fri Apr 24 20:31:21 2015 +0000 @@ -17,4 +17,5 @@ */ NfcAdapter inicializarlector(); int LeerTagNFC(); -int escribirTagNFC(); \ No newline at end of file +int escribirTagNFC(); +int emularTagNFC(); \ No newline at end of file