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/RecordText.h@0:04b82ae7aa43, 2015-11-19 (annotated)
- Committer:
- giovannivisentini
- Date:
- Thu Nov 19 08:49:47 2015 +0000
- Revision:
- 0:04b82ae7aa43
- Child:
- 1:a0eeb478a45a
First Version, the tag is only write
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
giovannivisentini | 0:04b82ae7aa43 | 1 | /* |
giovannivisentini | 0:04b82ae7aa43 | 2 | * RecordText.h |
giovannivisentini | 0:04b82ae7aa43 | 3 | * |
giovannivisentini | 0:04b82ae7aa43 | 4 | * Created on: Nov 17, 2015 |
giovannivisentini | 0:04b82ae7aa43 | 5 | * Author: giovanni visentini |
giovannivisentini | 0:04b82ae7aa43 | 6 | */ |
giovannivisentini | 0:04b82ae7aa43 | 7 | |
giovannivisentini | 0:04b82ae7aa43 | 8 | #ifndef NDEFLIB_RECORDTYPE_RECORDTEXT_H_ |
giovannivisentini | 0:04b82ae7aa43 | 9 | #define NDEFLIB_RECORDTYPE_RECORDTEXT_H_ |
giovannivisentini | 0:04b82ae7aa43 | 10 | #include <string> |
giovannivisentini | 0:04b82ae7aa43 | 11 | #include <NDefLib/Record.h> |
giovannivisentini | 0:04b82ae7aa43 | 12 | |
giovannivisentini | 0:04b82ae7aa43 | 13 | namespace NDefLib { |
giovannivisentini | 0:04b82ae7aa43 | 14 | |
giovannivisentini | 0:04b82ae7aa43 | 15 | class RecordText: public Record { |
giovannivisentini | 0:04b82ae7aa43 | 16 | public: |
giovannivisentini | 0:04b82ae7aa43 | 17 | |
giovannivisentini | 0:04b82ae7aa43 | 18 | static RecordText* parse(uint8_t *buffer); |
giovannivisentini | 0:04b82ae7aa43 | 19 | |
giovannivisentini | 0:04b82ae7aa43 | 20 | typedef enum { |
giovannivisentini | 0:04b82ae7aa43 | 21 | UTF8, |
giovannivisentini | 0:04b82ae7aa43 | 22 | UTF16, |
giovannivisentini | 0:04b82ae7aa43 | 23 | }TextEncoding; |
giovannivisentini | 0:04b82ae7aa43 | 24 | |
giovannivisentini | 0:04b82ae7aa43 | 25 | /** |
giovannivisentini | 0:04b82ae7aa43 | 26 | * utf8 en message |
giovannivisentini | 0:04b82ae7aa43 | 27 | */ |
giovannivisentini | 0:04b82ae7aa43 | 28 | RecordText(const std::string &text); |
giovannivisentini | 0:04b82ae7aa43 | 29 | RecordText(const TextEncoding encoding,const std::string &language,const std::string &text); |
giovannivisentini | 0:04b82ae7aa43 | 30 | virtual uint16_t write(uint8_t *buffer); |
giovannivisentini | 0:04b82ae7aa43 | 31 | virtual ~RecordText(){}; |
giovannivisentini | 0:04b82ae7aa43 | 32 | private: |
giovannivisentini | 0:04b82ae7aa43 | 33 | |
giovannivisentini | 0:04b82ae7aa43 | 34 | void setRecordHeader(); |
giovannivisentini | 0:04b82ae7aa43 | 35 | |
giovannivisentini | 0:04b82ae7aa43 | 36 | static uint8_t getTextStatus(TextEncoding enc,const std::string &language){ |
giovannivisentini | 0:04b82ae7aa43 | 37 | uint8_t status = language.size(); |
giovannivisentini | 0:04b82ae7aa43 | 38 | if (enc == UTF16){ |
giovannivisentini | 0:04b82ae7aa43 | 39 | status &= 0x80; // set to 1 the bit 7 |
giovannivisentini | 0:04b82ae7aa43 | 40 | }//if |
giovannivisentini | 0:04b82ae7aa43 | 41 | return status; |
giovannivisentini | 0:04b82ae7aa43 | 42 | }//getTextStatus |
giovannivisentini | 0:04b82ae7aa43 | 43 | |
giovannivisentini | 0:04b82ae7aa43 | 44 | static TextEncoding getEncoding(const uint8_t textStatus){ |
giovannivisentini | 0:04b82ae7aa43 | 45 | if((textStatus & 0x80)==0) |
giovannivisentini | 0:04b82ae7aa43 | 46 | return UTF8; |
giovannivisentini | 0:04b82ae7aa43 | 47 | else |
giovannivisentini | 0:04b82ae7aa43 | 48 | return UTF16; |
giovannivisentini | 0:04b82ae7aa43 | 49 | } |
giovannivisentini | 0:04b82ae7aa43 | 50 | |
giovannivisentini | 0:04b82ae7aa43 | 51 | static uint8_t getLanguageLength(const uint8_t textStatus){ |
giovannivisentini | 0:04b82ae7aa43 | 52 | //take the fist 5 bits |
giovannivisentini | 0:04b82ae7aa43 | 53 | return textStatus & 0x1F; |
giovannivisentini | 0:04b82ae7aa43 | 54 | } |
giovannivisentini | 0:04b82ae7aa43 | 55 | |
giovannivisentini | 0:04b82ae7aa43 | 56 | const TextEncoding mEncode; |
giovannivisentini | 0:04b82ae7aa43 | 57 | const std::string mLanguage; |
giovannivisentini | 0:04b82ae7aa43 | 58 | const std::string mText; |
giovannivisentini | 0:04b82ae7aa43 | 59 | uint8_t mTextStatus; |
giovannivisentini | 0:04b82ae7aa43 | 60 | |
giovannivisentini | 0:04b82ae7aa43 | 61 | static const uint8_t NDEFTextIdCode; |
giovannivisentini | 0:04b82ae7aa43 | 62 | |
giovannivisentini | 0:04b82ae7aa43 | 63 | }; |
giovannivisentini | 0:04b82ae7aa43 | 64 | |
giovannivisentini | 0:04b82ae7aa43 | 65 | } /* namespace NDefLib */ |
giovannivisentini | 0:04b82ae7aa43 | 66 | |
giovannivisentini | 0:04b82ae7aa43 | 67 | #endif /* NDEFLIB_RECORDTYPE_RECORDTEXT_H_ */ |
giovannivisentini | 0:04b82ae7aa43 | 68 |