ESPHome  2024.11.1
ndef_record_uri.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "esphome/core/log.h"
4 #include "esphome/core/helpers.h"
5 #include "ndef_record.h"
6 
7 #include <vector>
8 
9 namespace esphome {
10 namespace nfc {
11 
12 static const uint8_t PAYLOAD_IDENTIFIERS_COUNT = 0x23;
13 static 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 
50 class 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)
std::vector< uint8_t > get_encoded_payload() override
std::unique_ptr< NdefRecord > clone() const override
T id(T value)
Helper function to make id(var) known from lambdas work in custom components.
Definition: helpers.h:719
NdefRecordUri(const std::string &uri, const std::string &id)
void set_uri(const std::string &uri)
const std::string & get_payload() const override
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7