ESPHome 2025.5.0
Loading...
Searching...
No Matches
ndef_record_text.cpp
Go to the documentation of this file.
1#include "ndef_record_text.h"
2#include "ndef_record.h"
3
4namespace esphome {
5namespace nfc {
6
7static const char *const TAG = "nfc.ndef_record_text";
8
9NdefRecordText::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
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
std::vector< uint8_t > get_encoded_payload() override
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7