11 namespace remote_base {
13 static const uint8_t MAX_DATA_LENGTH = 15;
14 static const uint8_t DATA_LENGTH_MASK = 0x3f;
37 this->
data_[0] = 0x55;
38 this->
data_[1] = 0xff;
43 std::copy_n(data.begin(), std::min(data.size(), this->
data_.size()), this->
data_.begin());
48 std::copy_n(data.begin(), std::min(data.size(), this->
data_.size()), this->
data_.begin());
56 const uint8_t *
data()
const {
return this->
data_.data(); }
58 return std::min(static_cast<uint8_t>(6 + (2 * this->
get_address_length()) + (this->
data_[2] & DATA_LENGTH_MASK)),
59 static_cast<uint8_t>(this->
data_.size()));
62 return this->
data_[0] == 0x55 && this->
data_[1] == 0xff &&
63 ((this->
data_[2] & DATA_LENGTH_MASK) <= MAX_DATA_LENGTH) &&
68 this->
data_[2] |= 0x80;
70 this->
data_[2] &= 0x7f;
77 if (three_byte_address) {
78 this->
data_[2] |= 0x40;
80 this->
data_[2] &= 0xbf;
89 this->
data_[4] = (address >> 8) & 0xff;
90 this->
data_[5] = address & 0xff;
92 this->
data_[4] = (address >> 16) & 0xff;
93 this->
data_[5] = (address >> 8) & 0xff;
94 this->
data_[6] = address & 0xff;
101 return (this->
data_[4] << 16) + (this->
data_[5] << 8) + this->
data_[6];
105 this->
data_[6] = (address >> 8) & 0xff;
106 this->
data_[7] = address & 0xff;
108 this->
data_[7] = (address >> 16) & 0xff;
109 this->
data_[8] = (address >> 8) & 0xff;
110 this->
data_[9] = address & 0xff;
115 return (this->
data_[6] << 8) + this->
data_[7];
117 return (this->
data_[7] << 16) + (this->
data_[8] << 8) + this->
data_[9];
122 uint8_t
size = std::min(MAX_DATA_LENGTH, static_cast<uint8_t>(data.size()));
123 this->
data_[2] &= (0xff ^ DATA_LENGTH_MASK);
124 this->
data_[2] |= (size & DATA_LENGTH_MASK);
134 return std::min(MAX_DATA_LENGTH, static_cast<uint8_t>(this->
data_[2] & DATA_LENGTH_MASK));
140 this->
data_[0] = 0x55;
141 this->
data_[1] = 0xff;
144 std::string
to_string(uint8_t max_print_bytes = 255)
const {
155 uint8_t print_bytes = std::min(this->
size(), max_print_bytes);
161 if (std::equal(this->
data_.begin(), this->
data_.begin() + this->
size(), rhs.
data_.begin()))
172 std::array<uint8_t, 12 + MAX_DATA_LENGTH>
data_;
196 this->
data_.set_destination_address(destination_address);
214 TEMPLATABLE_VALUE(uint32_t, source_address)
215 TEMPLATABLE_VALUE(uint32_t, destination_address)
216 TEMPLATABLE_VALUE(
bool, retransmission)
217 TEMPLATABLE_VALUE(
bool, three_byte_address)
218 TEMPLATABLE_VALUE(uint8_t, message_type)
219 TEMPLATABLE_VALUE(uint8_t, message_id)
221 void set_data_static(std::vector<uint8_t>
data) { data_static_ = std::move(data); }
222 void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) {
223 this->data_func_ = func;
224 has_data_func_ =
true;
235 if (has_data_func_) {
245 std::function<std::vector<uint8_t>(Ts...)> data_func_{};
246 std::vector<uint8_t> data_static_{};
247 bool has_data_func_{
false};
bool operator==(const ABBWelcomeData &rhs) const
std::string format_hex_pretty(const uint8_t *data, size_t length)
Format the byte array data of length len in pretty-printed, human-readable hex.
optional< ABBWelcomeData > decode(RemoteReceiveData src) override
void set_message_type(const uint8_t message_type)
void set_message_id(const uint8_t message_id)
void set_data(const std::vector< uint8_t > &data)
const uint8_t * data() const
uint8_t get_message_id() const
uint32_t random_uint32()
Return a random 32-bit unsigned integer.
uint8_t get_address_length() const
bool matches(RemoteReceiveData src) override
std::array< uint8_t, 12+MAX_DATA_LENGTH > data_
std::string to_string(uint8_t max_print_bytes=255) const
bool get_retransmission() const
void set_destination_address(const uint32_t destination_address)
std::vector< uint8_t > get_data() const
uint8_t get_three_byte_address() const
void set_destination_address(uint32_t address)
void set_source_address(const uint32_t source_address)
void set_data(std::vector< uint8_t > data)
void set_retransmission(const bool retransmission)
uint32_t get_source_address() const
uint8_t & operator[](size_t idx)
void set_message_type(uint8_t message_type)
void set_message_id(uint8_t message_id)
std::string str_sprintf(const char *fmt,...)
void set_source_address(uint32_t address)
void set_three_byte_address(const bool three_byte_address)
uint8_t get_data_size() const
ABBWelcomeData(const std::vector< uint8_t > &data)
uint8_t get_message_type() const
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
void encode(RemoteTransmitData *dst, const ABBWelcomeData &src) override
void set_retransmission(bool retransmission)
void set_auto_message_id(const bool auto_message_id)
const uint8_t & operator[](size_t idx) const
ABBWelcomeData(std::initializer_list< uint8_t > data)
uint32_t get_destination_address() const
void set_three_byte_address(bool three_byte_address)