ESPHome
2024.11.1
esphome
esphome
components
nfc
ndef_record_text.cpp
Go to the documentation of this file.
1
#include "
ndef_record_text.h
"
2
#include "
ndef_record.h
"
3
4
namespace
esphome
{
5
namespace
nfc {
6
7
static
const
char
*
const
TAG =
"nfc.ndef_record_text"
;
8
9
NdefRecordText::NdefRecordText
(
const
std::vector<uint8_t> &payload) {
10
if
(payload.empty()) {
11
ESP_LOGE(TAG,
"Record payload too short"
);
12
return
;
13
}
14
15
uint8_t language_code_length = payload[0] & 0b00111111;
// Todo, make use of encoding bit?
16
17
this->
language_code_
= std::string(payload.begin() + 1, payload.begin() + 1 + language_code_length);
18
19
this->
text_
= std::string(payload.begin() + 1 + language_code_length, payload.end());
20
21
this->
tnf_
= TNF_WELL_KNOWN;
22
23
this->
type_
=
"T"
;
24
}
25
26
std::vector<uint8_t>
NdefRecordText::get_encoded_payload
() {
27
std::vector<uint8_t> data;
28
29
uint8_t flag_byte = this->
language_code_
.length() & 0b00111111;
// UTF8 assumed
30
31
data.push_back(flag_byte);
32
33
data.insert(data.end(), this->
language_code_
.begin(), this->
language_code_
.end());
34
35
data.insert(data.end(), this->
text_
.begin(), this->
text_
.end());
36
return
data;
37
}
38
39
}
// namespace nfc
40
}
// namespace esphome
esphome::nfc::NdefRecordText::text_
std::string text_
Definition:
ndef_record_text.h:35
ndef_record_text.h
esphome::nfc::NdefRecord::type_
std::string type_
Definition:
ndef_record.h:51
ndef_record.h
esphome::nfc::NdefRecordText::get_encoded_payload
std::vector< uint8_t > get_encoded_payload() override
Definition:
ndef_record_text.cpp:26
esphome::nfc::NdefRecordText::language_code_
std::string language_code_
Definition:
ndef_record_text.h:39
esphome::nfc::NdefRecordText::NdefRecordText
NdefRecordText()
Definition:
ndef_record_text.h:14
esphome
Implementation of SPI Controller mode.
Definition:
a01nyub.cpp:7
esphome::nfc::NdefRecord::tnf_
uint8_t tnf_
Definition:
ndef_record.h:47
Generated by
1.8.13