ESPHome 2025.5.0
Loading...
Searching...
No Matches
nfc_tag.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
6#include "esphome/core/log.h"
8#include "ndef_message.h"
9
10namespace esphome {
11namespace nfc {
12
13class NfcTag {
14 public:
16 this->uid_ = {};
17 this->tag_type_ = "Unknown";
18 };
19 NfcTag(std::vector<uint8_t> &uid) {
20 this->uid_ = uid;
21 this->tag_type_ = "Unknown";
22 };
23 NfcTag(std::vector<uint8_t> &uid, const std::string &tag_type) {
24 this->uid_ = uid;
25 this->tag_type_ = tag_type;
26 };
27 NfcTag(std::vector<uint8_t> &uid, const std::string &tag_type, std::unique_ptr<nfc::NdefMessage> ndef_message) {
28 this->uid_ = uid;
29 this->tag_type_ = tag_type;
30 this->ndef_message_ = std::move(ndef_message);
31 };
32 NfcTag(std::vector<uint8_t> &uid, const std::string &tag_type, std::vector<uint8_t> &ndef_data) {
33 this->uid_ = uid;
34 this->tag_type_ = tag_type;
35 this->ndef_message_ = make_unique<NdefMessage>(ndef_data);
36 };
37 NfcTag(const NfcTag &rhs) {
38 uid_ = rhs.uid_;
39 tag_type_ = rhs.tag_type_;
40 if (rhs.ndef_message_ != nullptr)
42 }
43
44 std::vector<uint8_t> &get_uid() { return this->uid_; };
45 const std::string &get_tag_type() { return this->tag_type_; };
46 bool has_ndef_message() { return this->ndef_message_ != nullptr; };
47 const std::shared_ptr<NdefMessage> &get_ndef_message() { return this->ndef_message_; };
48 void set_ndef_message(std::unique_ptr<NdefMessage> ndef_message) { this->ndef_message_ = std::move(ndef_message); };
49
50 protected:
51 std::vector<uint8_t> uid_;
52 std::string tag_type_;
53 std::shared_ptr<NdefMessage> ndef_message_;
54};
55
56} // namespace nfc
57} // namespace esphome
std::vector< uint8_t > & get_uid()
Definition nfc_tag.h:44
NfcTag(std::vector< uint8_t > &uid, const std::string &tag_type, std::vector< uint8_t > &ndef_data)
Definition nfc_tag.h:32
void set_ndef_message(std::unique_ptr< NdefMessage > ndef_message)
Definition nfc_tag.h:48
std::string tag_type_
Definition nfc_tag.h:52
NfcTag(std::vector< uint8_t > &uid, const std::string &tag_type, std::unique_ptr< nfc::NdefMessage > ndef_message)
Definition nfc_tag.h:27
NfcTag(const NfcTag &rhs)
Definition nfc_tag.h:37
std::vector< uint8_t > uid_
Definition nfc_tag.h:51
const std::shared_ptr< NdefMessage > & get_ndef_message()
Definition nfc_tag.h:47
const std::string & get_tag_type()
Definition nfc_tag.h:45
std::shared_ptr< NdefMessage > ndef_message_
Definition nfc_tag.h:53
bool has_ndef_message()
Definition nfc_tag.h:46
NfcTag(std::vector< uint8_t > &uid, const std::string &tag_type)
Definition nfc_tag.h:23
NfcTag(std::vector< uint8_t > &uid)
Definition nfc_tag.h:19
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::unique_ptr< T > make_unique(Args &&...args)
Definition helpers.h:85