esphome/esphome/components/nfc/ndef_record_uri.h

79 lines
3.2 KiB
C
Raw Normal View History

#pragma once
#include "esphome/core/log.h"
#include "esphome/core/helpers.h"
#include "ndef_record.h"
2022-11-24 01:12:55 +01:00
#include <vector>
namespace esphome {
namespace nfc {
static const uint8_t PAYLOAD_IDENTIFIERS_COUNT = 0x23;
static const char *const PAYLOAD_IDENTIFIERS[] = {"",
"http://www.",
"https://www.",
"http://",
"https://",
"tel:",
"mailto:",
"ftp://anonymous:anonymous@",
"ftp://ftp.",
"ftps://",
"sftp://",
"smb://",
"nfs://",
"ftp://",
"dav://",
"news:",
"telnet://",
"imap:",
"rtsp://",
"urn:",
"pop:",
"sip:",
"sips:",
"tftp:",
"btspp://",
"btl2cap://",
"btgoep://",
"tcpobex://",
"irdaobex://",
"file://",
"urn:epc:id:",
"urn:epc:tag:",
"urn:epc:pat:",
"urn:epc:raw:",
"urn:epc:",
"urn:nfc:"};
class NdefRecordUri : public NdefRecord {
public:
NdefRecordUri(){};
NdefRecordUri(const std::vector<uint8_t> &payload);
2021-09-27 00:11:27 +02:00
NdefRecordUri(const std::string &uri) {
this->tnf_ = TNF_WELL_KNOWN;
this->type_ = "U";
2021-09-27 00:11:27 +02:00
this->uri_ = uri;
};
2021-09-27 00:11:27 +02:00
NdefRecordUri(const std::string &uri, const std::string &id) {
this->tnf_ = TNF_WELL_KNOWN;
this->type_ = "U";
2021-09-27 00:11:27 +02:00
this->uri_ = uri;
this->id_ = id;
};
NdefRecordUri(const NdefRecordUri &) = default;
std::unique_ptr<NdefRecord> clone() const override { return make_unique<NdefRecordUri>(*this); };
2021-09-27 00:11:27 +02:00
void set_uri(const std::string &uri) { this->uri_ = uri; };
std::vector<uint8_t> get_encoded_payload() override;
2021-09-27 00:11:27 +02:00
const std::string &get_payload() const override { return this->uri_; };
protected:
2021-09-27 00:11:27 +02:00
std::string uri_;
};
} // namespace nfc
} // namespace esphome