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/RecordSMS.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 | * RecordSMS.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 | #include <cstring> |
giovannivisentini | 0:04b82ae7aa43 | 9 | |
giovannivisentini | 0:04b82ae7aa43 | 10 | #include "RecordSMS.h" |
giovannivisentini | 0:04b82ae7aa43 | 11 | |
giovannivisentini | 0:04b82ae7aa43 | 12 | namespace NDefLib { |
giovannivisentini | 0:04b82ae7aa43 | 13 | |
giovannivisentini | 0:04b82ae7aa43 | 14 | |
giovannivisentini | 1:a0eeb478a45a | 15 | const std::string RecordSMS::sSmsTag("sms:"); |
giovannivisentini | 1:a0eeb478a45a | 16 | const std::string RecordSMS::sBodyTag("?body="); |
giovannivisentini | 0:04b82ae7aa43 | 17 | |
giovannivisentini | 0:04b82ae7aa43 | 18 | RecordSMS::RecordSMS(const std::string &number,const std::string &message, const std::string info): |
giovannivisentini | 1:a0eeb478a45a | 19 | RecordURI(sSmsTag,number+sBodyTag+message), |
giovannivisentini | 0:04b82ae7aa43 | 20 | mNumber(number),mMsg(message),mInfo(info){ |
giovannivisentini | 1:a0eeb478a45a | 21 | } |
giovannivisentini | 1:a0eeb478a45a | 22 | |
giovannivisentini | 1:a0eeb478a45a | 23 | RecordSMS* RecordSMS::parse(const Record::RecordHeader &header,const uint8_t *buffer){ |
giovannivisentini | 1:a0eeb478a45a | 24 | uint16_t offset=0; |
giovannivisentini | 1:a0eeb478a45a | 25 | if(buffer[offset++]!=RecordURI::sNDEFUriIdCode) |
giovannivisentini | 1:a0eeb478a45a | 26 | return NULL; |
giovannivisentini | 1:a0eeb478a45a | 27 | if(buffer[offset++]!=RecordURI::UNKNOWN) |
giovannivisentini | 1:a0eeb478a45a | 28 | return NULL; |
giovannivisentini | 1:a0eeb478a45a | 29 | if(sSmsTag.compare(0,sSmsTag.size(),(const char*)buffer+offset,sSmsTag.size())!=0) |
giovannivisentini | 1:a0eeb478a45a | 30 | return NULL; |
giovannivisentini | 1:a0eeb478a45a | 31 | offset+=sSmsTag.size(); |
giovannivisentini | 1:a0eeb478a45a | 32 | |
giovannivisentini | 1:a0eeb478a45a | 33 | const std::string uriContent((const char*)(buffer+offset),header.getPlayloadLenght()-offset); |
giovannivisentini | 1:a0eeb478a45a | 34 | |
giovannivisentini | 1:a0eeb478a45a | 35 | std::size_t numberEnd = uriContent.find(sBodyTag); |
giovannivisentini | 1:a0eeb478a45a | 36 | if(numberEnd == std::string::npos) |
giovannivisentini | 1:a0eeb478a45a | 37 | return NULL; |
giovannivisentini | 1:a0eeb478a45a | 38 | |
giovannivisentini | 1:a0eeb478a45a | 39 | return new RecordSMS(uriContent.substr(0,numberEnd), |
giovannivisentini | 1:a0eeb478a45a | 40 | uriContent.substr(numberEnd+sBodyTag.size())); |
giovannivisentini | 0:04b82ae7aa43 | 41 | |
giovannivisentini | 0:04b82ae7aa43 | 42 | } |
giovannivisentini | 0:04b82ae7aa43 | 43 | |
giovannivisentini | 0:04b82ae7aa43 | 44 | } /* namespace NDefLib */ |