ESPHome 2025.5.0
Loading...
Searching...
No Matches
ndef_record_uri.h
Go to the documentation of this file.
1#pragma once
2
3#include "esphome/core/log.h"
5#include "ndef_record.h"
6
7#include <vector>
8
9namespace esphome {
10namespace nfc {
11
12static const uint8_t PAYLOAD_IDENTIFIERS_COUNT = 0x23;
13static const char *const PAYLOAD_IDENTIFIERS[] = {"",
14 "http://www.",
15 "https://www.",
16 "http://",
17 "https://",
18 "tel:",
19 "mailto:",
20 "ftp://anonymous:anonymous@",
21 "ftp://ftp.",
22 "ftps://",
23 "sftp://",
24 "smb://",
25 "nfs://",
26 "ftp://",
27 "dav://",
28 "news:",
29 "telnet://",
30 "imap:",
31 "rtsp://",
32 "urn:",
33 "pop:",
34 "sip:",
35 "sips:",
36 "tftp:",
37 "btspp://",
38 "btl2cap://",
39 "btgoep://",
40 "tcpobex://",
41 "irdaobex://",
42 "file://",
43 "urn:epc:id:",
44 "urn:epc:tag:",
45 "urn:epc:pat:",
46 "urn:epc:raw:",
47 "urn:epc:",
48 "urn:nfc:"};
49
50class NdefRecordUri : public NdefRecord {
51 public:
53 NdefRecordUri(const std::vector<uint8_t> &payload);
54 NdefRecordUri(const std::string &uri) {
55 this->tnf_ = TNF_WELL_KNOWN;
56 this->type_ = "U";
57 this->uri_ = uri;
58 };
59 NdefRecordUri(const std::string &uri, const std::string &id) {
60 this->tnf_ = TNF_WELL_KNOWN;
61 this->type_ = "U";
62 this->uri_ = uri;
63 this->id_ = id;
64 };
65 NdefRecordUri(const NdefRecordUri &) = default;
66 std::unique_ptr<NdefRecord> clone() const override { return make_unique<NdefRecordUri>(*this); };
67
68 void set_uri(const std::string &uri) { this->uri_ = uri; };
69
70 std::vector<uint8_t> get_encoded_payload() override;
71 const std::string &get_payload() const override { return this->uri_; };
72
73 protected:
74 std::string uri_;
75};
76
77} // namespace nfc
78} // namespace esphome
NdefRecordUri(const std::string &uri, const std::string &id)
const std::string & get_payload() const override
NdefRecordUri(const std::string &uri)
NdefRecordUri(const NdefRecordUri &)=default
std::vector< uint8_t > get_encoded_payload() override
void set_uri(const std::string &uri)
std::unique_ptr< NdefRecord > clone() const override
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
T id(T value)
Helper function to make id(var) known from lambdas work in custom components.
Definition helpers.h:798