Utility library to read and write Ndef messages from/to a Type4 NFC tag
Dependents: NFC M2M_2016_STM32 MyongjiElec_capstone1 IDW01M1_Cloud_IBM ... more
Fork of NDefLib by
NDEF NFC library
This library provides an abstract API to create NDEF formatted messages and records and to read/write them from/to a Type4 NFC Tag.
Implementations
At the moment, the NDEF API is implemented by X_NUCLEO_NFC01A1 and X_NUCLEO_NFC02A1 Dynamic NFC Tag libraries respectively driving the X-NUCLEO-NFC01A1 and X-NUCLEO-NFC02A1 boards.
RecordType/RecordAAR.cpp@1:a0eeb478a45a, 2015-11-24 (annotated)
- Committer:
- giovannivisentini
- Date:
- Tue Nov 24 14:33:06 2015 +0000
- Revision:
- 1:a0eeb478a45a
- Parent:
- 0:04b82ae7aa43
- Child:
- 4:eaf6c49a86e4
implement tag reading
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
giovannivisentini | 0:04b82ae7aa43 | 1 | /* |
giovannivisentini | 0:04b82ae7aa43 | 2 | * RecordAAR.cpp |
giovannivisentini | 0:04b82ae7aa43 | 3 | * |
giovannivisentini | 0:04b82ae7aa43 | 4 | * Created on: Nov 6, 2015 |
giovannivisentini | 0:04b82ae7aa43 | 5 | * Author: giovanni visentini |
giovannivisentini | 0:04b82ae7aa43 | 6 | */ |
giovannivisentini | 0:04b82ae7aa43 | 7 | |
giovannivisentini | 0:04b82ae7aa43 | 8 | |
giovannivisentini | 0:04b82ae7aa43 | 9 | #include <cstring> |
giovannivisentini | 1:a0eeb478a45a | 10 | #include "RecordAAR.h" |
giovannivisentini | 0:04b82ae7aa43 | 11 | |
giovannivisentini | 0:04b82ae7aa43 | 12 | namespace NDefLib { |
giovannivisentini | 0:04b82ae7aa43 | 13 | |
giovannivisentini | 1:a0eeb478a45a | 14 | const char RecordAAR::sRecordType[] = {'a','n','d','r','o','i','d','.','c','o','m',':','p','k','g'}; |
giovannivisentini | 0:04b82ae7aa43 | 15 | |
giovannivisentini | 0:04b82ae7aa43 | 16 | RecordAAR::RecordAAR(const std::string &packageName):mPackageName(packageName){ |
giovannivisentini | 1:a0eeb478a45a | 17 | mRecordHeader.setFNT(RecordHeader::NFC_external); |
giovannivisentini | 1:a0eeb478a45a | 18 | mRecordHeader.setTypeLength(sizeof(sRecordType)); |
giovannivisentini | 0:04b82ae7aa43 | 19 | mRecordHeader.setPlayloadLenght(mPackageName.size()); |
giovannivisentini | 0:04b82ae7aa43 | 20 | |
giovannivisentini | 0:04b82ae7aa43 | 21 | } |
giovannivisentini | 0:04b82ae7aa43 | 22 | |
giovannivisentini | 0:04b82ae7aa43 | 23 | |
giovannivisentini | 0:04b82ae7aa43 | 24 | uint16_t RecordAAR::write(uint8_t *buffer){ |
giovannivisentini | 0:04b82ae7aa43 | 25 | uint16_t offset=0; |
giovannivisentini | 0:04b82ae7aa43 | 26 | offset += mRecordHeader.writeHeader(buffer); |
giovannivisentini | 1:a0eeb478a45a | 27 | std::memcpy(buffer+offset,sRecordType,sizeof(sRecordType)); |
giovannivisentini | 1:a0eeb478a45a | 28 | offset +=sizeof(sRecordType); |
giovannivisentini | 0:04b82ae7aa43 | 29 | std::memcpy(buffer+offset,mPackageName.c_str(),mPackageName.size()); |
giovannivisentini | 0:04b82ae7aa43 | 30 | offset +=mPackageName.size(); |
giovannivisentini | 0:04b82ae7aa43 | 31 | return offset; |
giovannivisentini | 0:04b82ae7aa43 | 32 | } |
giovannivisentini | 0:04b82ae7aa43 | 33 | |
giovannivisentini | 1:a0eeb478a45a | 34 | RecordAAR* RecordAAR::parse(const Record::RecordHeader &header, |
giovannivisentini | 1:a0eeb478a45a | 35 | const uint8_t *buffer){ |
giovannivisentini | 1:a0eeb478a45a | 36 | uint8_t offset=0; |
giovannivisentini | 1:a0eeb478a45a | 37 | if( (header.getFNT()!=RecordHeader::NFC_external) && |
giovannivisentini | 1:a0eeb478a45a | 38 | (header.getTypeLenght()!=sizeof(sRecordType)) ){ |
giovannivisentini | 1:a0eeb478a45a | 39 | return NULL; |
giovannivisentini | 1:a0eeb478a45a | 40 | }//else |
giovannivisentini | 1:a0eeb478a45a | 41 | |
giovannivisentini | 1:a0eeb478a45a | 42 | if(std::memcmp(buffer+offset,sRecordType,sizeof(sRecordType))!=0){ |
giovannivisentini | 1:a0eeb478a45a | 43 | return NULL; |
giovannivisentini | 1:a0eeb478a45a | 44 | }//else tagType == android.com:pkg |
giovannivisentini | 1:a0eeb478a45a | 45 | |
giovannivisentini | 1:a0eeb478a45a | 46 | offset+=sizeof(sRecordType); |
giovannivisentini | 1:a0eeb478a45a | 47 | |
giovannivisentini | 1:a0eeb478a45a | 48 | return new RecordAAR(std::string((const char*)buffer+offset, |
giovannivisentini | 1:a0eeb478a45a | 49 | header.getPlayloadLenght())); |
giovannivisentini | 1:a0eeb478a45a | 50 | } |
giovannivisentini | 0:04b82ae7aa43 | 51 | |
giovannivisentini | 0:04b82ae7aa43 | 52 | } /* namespace NDefLib */ |