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.
Diff: Message.cpp
- Revision:
- 1:a0eeb478a45a
- Parent:
- 0:04b82ae7aa43
- Child:
- 4:eaf6c49a86e4
diff -r 04b82ae7aa43 -r a0eeb478a45a Message.cpp --- a/Message.cpp Thu Nov 19 08:49:47 2015 +0000 +++ b/Message.cpp Tue Nov 24 14:33:06 2015 +0000 @@ -9,6 +9,9 @@ #include "NDefLib/Message.h" #include "RecordType/EmptyRecord.h" #include "RecordType/RecordText.h" +#include "RecordType/RecordAAR.h" +#include "RecordType/RecordMimeType.h" +#include "RecordType/RecordURI.h" namespace NDefLib { @@ -28,7 +31,7 @@ return lenght; }//getByteLenght -uint16_t Message::write(uint8_t *buffer){ +uint16_t Message::write(uint8_t *buffer) const { const uint16_t length =getByteLenght()-2; uint16_t offset=0; @@ -57,23 +60,25 @@ return offset; }//write -void Message::parseMessage(uint8_t *rawNdefFile,std::vector<Record*> *parsedRecords){ +void Message::parseMessage(const uint8_t *const rawNdefFile, + const uint8_t length,Message *msg){ + uint16_t offset=0; + Record *r; - //const uint16_t length = (rawNdefFile[0]<<8 | rawNdefFile[1]); - //skip the message length info - uint16_t offset=2; - Record *r; + Record::RecordHeader header; do{ - r = RecordText::parse(rawNdefFile+offset); - if(r==NULL){ - - + const uint8_t headerLenght = header.loadHeader(rawNdefFile+offset); + r = RecordText::parse(header,rawNdefFile+offset+headerLenght); + if(r==NULL) + r = RecordAAR::parse(header,rawNdefFile+offset+headerLenght); + if(r==NULL) + r = RecordMimeType::parse(header,rawNdefFile+offset+headerLenght); + if(r==NULL) + r = RecordURI::parse(header,rawNdefFile+offset+headerLenght); - }//else - - offset += r->getByteLenght(); - parsedRecords->push_back(r); - }while(!r->isLastRecord()); + offset += header.getRecordLength(); + msg->addRecord(r); + }while(offset<length); }