2021-09-26 22:38:08 +02:00
|
|
|
#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>
|
|
|
|
|
2021-09-26 22:38:08 +02:00
|
|
|
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) {
|
2021-09-26 22:38:08 +02:00
|
|
|
this->tnf_ = TNF_WELL_KNOWN;
|
|
|
|
this->type_ = "U";
|
2021-09-27 00:11:27 +02:00
|
|
|
this->uri_ = uri;
|
2021-09-26 22:38:08 +02:00
|
|
|
};
|
2021-09-27 00:11:27 +02:00
|
|
|
NdefRecordUri(const std::string &uri, const std::string &id) {
|
2021-09-26 22:38:08 +02:00
|
|
|
this->tnf_ = TNF_WELL_KNOWN;
|
|
|
|
this->type_ = "U";
|
2021-09-27 00:11:27 +02:00
|
|
|
this->uri_ = uri;
|
2021-09-26 22:38:08 +02:00
|
|
|
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; };
|
2021-09-26 22:38:08 +02:00
|
|
|
|
|
|
|
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_; };
|
2021-09-26 22:38:08 +02:00
|
|
|
|
|
|
|
protected:
|
2021-09-27 00:11:27 +02:00
|
|
|
std::string uri_;
|
2021-09-26 22:38:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace nfc
|
|
|
|
} // namespace esphome
|