/** * @brief This fonction prepare the NDEF message with the URI data given in the structure * @param pURI : pointer on structure that contain the URI information * @param pNDEFMessage : pointer on the NDEF message * @param size : to store the size of the NDEF message generated */ void NDEF_PrepareURIMessage ( sURI_Info *pURI, uint8_t *pNDEFMessage, uint16_t *size) { uint32_t uriSize, infoSize, totalSize, Offset = 0; char type; /* An URI can be included in a smart poster to add text to give instruction to user for instance */ /* URI (smart poster) Record Header */ /************************************/ /* 7 | 6 | 5 | 4 | 3 | 2 1 0 */ /*----------------------------------*/ /* MB ME CF SR IL TNF */ /* <---- CF=0, IL=0 and SR=1 TNF=1 NFC Forum Well-known type*/ /*----------------------------------*/ /* TYPE LENGTH */ /*----------------------------------*/ /* PAYLOAD LENGTH 3 */ /* <---- Used only if SR=0 */ /*----------------------------------*/ /* PAYLOAD LENGTH 2 */ /* <---- Used only if SR=0 */ /*----------------------------------*/ /* PAYLOAD LENGTH 1 */ /* <---- Used only if SR=0 */ /*----------------------------------*/ /* PAYLOAD LENGTH 0 */ /*----------------------------------*/ /* ID LENGTH */ /* <---- Not Used */ /*----------------------------------*/ /* TYPE */ /*----------------------------------*/ /* ID */ /* <---- Not Used */ /************************************/ /* We need to know the URI type in order to define if an abreviation is available */ type = getUriType(pURI->protocol); /* URI : 1+URI for abreviate protocol*/ if (type != URI_ID_0x00) uriSize = 1+strlen(pURI->URI_Message); else /*: 1+protocol+URI else*/ uriSize = 1+strlen(pURI->protocol)+strlen(pURI->URI_Message); /* Check if a Smart poster is needed */ if (pURI->Information[0] != '\0') { /* Info : 1+2+info */ infoSize = 1+ISO_ENGLISH_CODE_STRING_LENGTH+strlen(pURI->Information); /* Total */ totalSize = 4+uriSize+4+infoSize; if (uriSize > 255) totalSize+=3; /* Normal URI size */ if (infoSize > 255) totalSize+=3; /* Normal Info size */ /* SmartPoster header */ if (totalSize > 255) { pNDEFMessage[Offset++] = 0xC1; pNDEFMessage[Offset++] = SMART_POSTER_TYPE_STRING_LENGTH; pNDEFMessage[Offset++] = (totalSize & 0xFF000000)>>24; pNDEFMessage[Offset++] = (totalSize & 0x00FF0000)>>16; pNDEFMessage[Offset++] = (totalSize & 0x0000FF00)>>8; pNDEFMessage[Offset++] = (totalSize & 0x000000FF); }
int main() { pc.baud(115200); pc.format(8,SerialBase::None, 1); sURI_Info URIout; sURI_Info URIin; int BlinkLEDCounter = 0; memset(&URIin, 0x00, sizeof(URIin)); // All LEDs on NFC shield off nfcled1 = 0; nfcled2 = 0; nfcled3 = 0; pc.printf("NFC Example\n"); // Prepare URI NDEF message content pc.printf("Prepare URI NDEF message content\n"); strcpy(URIout.protocol,URI_ID_0x01_STRING); strcpy(URIout.URI_Message,""); strcpy(URIout.Information,"\0"); pc.printf("Done\n\n"); /*pc.printf("URIout contents:\n"); pc.printf("URIout.protocol=%s\n", URIout.protocol); pc.printf("URIout Type: %d\n", getUriType(URIout.protocol)); pc.printf("URIout.URI_Message=%s\n\n", URIout.URI_Message);*/ pc.printf("Initializing Tag Type 4 Access ... "); // LED1 (green) on NCF shield indicates progress // blinking = initialization in progress // solid = init successfull BlinkLEDCounter = 0; while(TT4_Init()!=SUCCESS) { if(BlinkLEDCounter < BLINK_LED_CYCLES) { BlinkLEDCounter++; } else { BlinkLEDCounter=0; nfcled1 = !nfcled1; } } // success nfcled1 = 1; pc.printf("SUCCESS\n\n"); while(1){ // Write URI // LED2 (blue) on NCF shield indicates progress // blinking = write URI in progress // solid = write URI successfull pc.printf("null uri writing"); BlinkLEDCounter = 0; while (TT4_WriteURI(&URIout) != SUCCESS) { if(BlinkLEDCounter < BLINK_LED_CYCLES) { BlinkLEDCounter++; } else { BlinkLEDCounter=0; nfcled2 = !nfcled2; } } // success nfcled2 = 1; pc.printf("writed\n\n"); // Read URI // LED3 (orange) on NCF shield indicates progress // blinking = read URI in progress // solid = read URI successfull pc.printf("Reading back URI ... "); BlinkLEDCounter = 0; wait_ms(3000); while(TT4_ReadURI(&URIin) != SUCCESS || strlen(URIin.URI_Message) == 0) { wait_ms(1000); if(BlinkLEDCounter < BLINK_LED_CYCLES) { BlinkLEDCounter++; } else { BlinkLEDCounter=0; nfcled3 = !nfcled3; } } // success nfcled3 = 1; pc.printf("SUCCESS\n\n"); // Display contents read back pc.printf("URIin contents:\n"); pc.printf("URIin.protocol=%s\n", URIin.protocol); pc.printf("URIin Type: %d\n", getUriType(URIin.protocol)); pc.printf("URIin.URI_Message=%s\n\n", URIin.URI_Message); // loop forever pc.printf("endLoop\n\n"); } while(1) { // blink LED on Nucleo board when done wait(0.5); myled = !myled; } }