ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
ndef_record.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/log.h"
5
6#include <vector>
7
8namespace esphome::nfc {
9
10static constexpr uint8_t TNF_EMPTY = 0x00;
11static constexpr uint8_t TNF_WELL_KNOWN = 0x01;
12static constexpr uint8_t TNF_MIME_MEDIA = 0x02;
13static constexpr uint8_t TNF_ABSOLUTE_URI = 0x03;
14static constexpr uint8_t TNF_EXTERNAL_TYPE = 0x04;
15static constexpr uint8_t TNF_UNKNOWN = 0x05;
16static constexpr uint8_t TNF_UNCHANGED = 0x06;
17static constexpr uint8_t TNF_RESERVED = 0x07;
18
20 public:
22 NdefRecord(std::vector<uint8_t> payload_data);
23 void set_tnf(uint8_t tnf) { this->tnf_ = tnf; };
24 void set_type(const std::string &type) { this->type_ = type; };
25 void set_payload(const std::string &payload) { this->payload_ = payload; };
26 void set_id(const std::string &id) { this->id_ = id; };
27 NdefRecord(const NdefRecord &) = default;
28 virtual ~NdefRecord() {}
29 virtual std::unique_ptr<NdefRecord> clone() const { // To allow copying polymorphic classes
30 return make_unique<NdefRecord>(*this);
31 };
32
34
35 std::vector<uint8_t> encode(bool first, bool last);
36
37 uint8_t create_flag_byte(bool first, bool last, size_t payload_size);
38
39 const std::string &get_type() const { return this->type_; };
40 const std::string &get_id() const { return this->id_; };
41 virtual const std::string &get_payload() const { return this->payload_; };
42
43 virtual std::vector<uint8_t> get_encoded_payload() {
44 std::vector<uint8_t> payload(this->payload_.begin(), this->payload_.end());
45 return payload;
46 };
47
48 protected:
49 uint8_t tnf_;
50 std::string type_;
51 std::string id_;
52 std::string payload_;
53};
54
55} // namespace esphome::nfc
virtual std::unique_ptr< NdefRecord > clone() const
Definition ndef_record.h:29
void set_id(const std::string &id)
Definition ndef_record.h:26
void set_type(const std::string &type)
Definition ndef_record.h:24
NdefRecord(const NdefRecord &)=default
const std::string & get_id() const
Definition ndef_record.h:40
void set_tnf(uint8_t tnf)
Definition ndef_record.h:23
std::vector< uint8_t > encode(bool first, bool last)
virtual std::vector< uint8_t > get_encoded_payload()
Definition ndef_record.h:43
uint8_t create_flag_byte(bool first, bool last, size_t payload_size)
virtual const std::string & get_payload() const
Definition ndef_record.h:41
const std::string & get_type() const
Definition ndef_record.h:39
void set_payload(const std::string &payload)
Definition ndef_record.h:25
uint16_t type
uint16_t id
static void uint32_t
uint32_t payload_size()