12namespace remote_base {
14static const uint8_t MAX_DATA_LENGTH = 15;
15static const uint8_t DATA_LENGTH_MASK = 0x3f;
39 std::copy_n(
data.begin(), std::min(
data.size(), this->data_.size()), this->data_.begin());
43 std::copy_n(
data.begin(), std::min(
data.size(), this->data_.size()), this->data_.begin());
51 const uint8_t *
data()
const {
return this->
data_.data(); }
53 return std::min(
static_cast<uint8_t
>(6 + (2 * this->
get_address_length()) + (this->
data_[2] & DATA_LENGTH_MASK)),
54 static_cast<uint8_t
>(this->
data_.size()));
57 return this->
data_[0] == 0x55 && this->
data_[1] == 0xff &&
58 ((this->
data_[2] & DATA_LENGTH_MASK) <= MAX_DATA_LENGTH) &&
63 this->
data_[2] |= 0x80;
65 this->
data_[2] &= 0x7f;
72 if (three_byte_address) {
73 this->
data_[2] |= 0x40;
75 this->
data_[2] &= 0xbf;
84 this->
data_[4] = (address >> 8) & 0xff;
85 this->
data_[5] = address & 0xff;
87 this->
data_[4] = (address >> 16) & 0xff;
88 this->
data_[5] = (address >> 8) & 0xff;
89 this->
data_[6] = address & 0xff;
100 this->
data_[6] = (address >> 8) & 0xff;
101 this->
data_[7] = address & 0xff;
103 this->
data_[7] = (address >> 16) & 0xff;
104 this->
data_[8] = (address >> 8) & 0xff;
105 this->
data_[9] = address & 0xff;
110 return (this->
data_[6] << 8) + this->
data_[7];
112 return (this->
data_[7] << 16) + (this->
data_[8] << 8) + this->
data_[9];
117 uint8_t
size = std::min(MAX_DATA_LENGTH,
static_cast<uint8_t
>(
data.size()));
118 this->
data_[2] &= (0xff ^ DATA_LENGTH_MASK);
119 this->
data_[2] |= (size & DATA_LENGTH_MASK);
121 std::copy_n(
data.begin(),
size, this->data_.begin() + 5 + 2 * this->get_address_length());
124 std::vector<uint8_t>
data(this->
data_.begin() + 5 + 2 * this->get_address_length(),
125 this->data_.begin() + 5 + 2 * this->get_address_length() + this->get_data_size());
129 return std::min(MAX_DATA_LENGTH,
static_cast<uint8_t
>(this->
data_[2] & DATA_LENGTH_MASK));
135 this->
data_[0] = 0x55;
136 this->
data_[1] = 0xff;
139 std::string
to_string(uint8_t max_print_bytes = 255)
const {
143 :
"[%04" PRIX32
" %s %04" PRIX32
"] Type: %02X",
151 uint8_t print_bytes = std::min(this->
size(), max_print_bytes);
157 if (std::equal(this->
data_.begin(), this->data_.begin() + this->size(), rhs.
data_.begin()))
168 std::array<uint8_t, 12 + MAX_DATA_LENGTH>
data_;
188 return data.has_value() && data.value() == this->
data_;
210 TEMPLATABLE_VALUE(uint32_t, source_address)
211 TEMPLATABLE_VALUE(uint32_t, destination_address)
212 TEMPLATABLE_VALUE(
bool, retransmission)
213 TEMPLATABLE_VALUE(
bool, three_byte_address)
214 TEMPLATABLE_VALUE(uint8_t, message_type)
215 TEMPLATABLE_VALUE(uint8_t, message_id)
216 TEMPLATABLE_VALUE(
bool, auto_message_id)
217 void set_data_template(std::vector<uint8_t> (*func)(Ts...)) {
221 void set_data_static(
const uint8_t *data,
size_t len) {
234 std::vector<uint8_t> data_vec;
235 if (this->
len_ >= 0) {
237 data_vec.assign(this->
data_.
data, this->data_.data + this->len_);
250 std::vector<uint8_t> (*
func)(Ts...);
union esphome::remote_base::ABBWelcomeAction::Data data_
bool matches(RemoteReceiveData src) override
void set_retransmission(const bool retransmission)
void set_destination_address(const uint32_t destination_address)
void set_message_id(const uint8_t message_id)
void set_auto_message_id(const bool auto_message_id)
void set_message_type(const uint8_t message_type)
void set_data(const std::vector< uint8_t > &data)
void set_source_address(const uint32_t source_address)
void set_three_byte_address(const bool three_byte_address)
uint32_t get_destination_address() const
void set_data(std::vector< uint8_t > data)
bool operator==(const ABBWelcomeData &rhs) const
bool get_retransmission() const
uint8_t get_address_length() const
uint8_t get_three_byte_address() const
ABBWelcomeData(std::initializer_list< uint8_t > data)
uint8_t get_data_size() const
void set_message_id(uint8_t message_id)
void set_retransmission(bool retransmission)
uint8_t get_message_type() const
uint32_t get_source_address() const
void set_destination_address(uint32_t address)
void set_three_byte_address(bool three_byte_address)
const uint8_t * data() const
const uint8_t & operator[](size_t idx) const
std::array< uint8_t, 12+MAX_DATA_LENGTH > data_
uint8_t get_message_id() const
std::vector< uint8_t > get_data() const
void set_message_type(uint8_t message_type)
std::string to_string(uint8_t max_print_bytes=255) const
ABBWelcomeData(const ABBWelcomeData &)=default
void set_source_address(uint32_t address)
ABBWelcomeData(const std::vector< uint8_t > &data)
uint8_t & operator[](size_t idx)
void encode(RemoteTransmitData *dst, const ABBWelcomeData &src) override
void encode_byte_(RemoteTransmitData *dst, uint8_t data) const
void dump(const ABBWelcomeData &data) override
bool decode_byte_(RemoteReceiveData &src, bool &done, uint8_t &data)
optional< ABBWelcomeData > decode(RemoteReceiveData src) override
Providing packet encoding functions for exchanging data with a remote host.
uint32_t random_uint32()
Return a random 32-bit unsigned integer.
std::string format_hex_pretty(const uint8_t *data, size_t length, char separator, bool show_length)
Format a byte array in pretty-printed, human-readable hex format.
std::string str_sprintf(const char *fmt,...)
std::vector< uint8_t >(* func)(Ts...)