12 namespace remote_base {
14 static const uint8_t MAX_DATA_LENGTH = 15;
15 static const uint8_t DATA_LENGTH_MASK = 0x3f;
38 this->
data_[0] = 0x55;
39 this->
data_[1] = 0xff;
44 std::copy_n(data.begin(), std::min(data.size(), this->
data_.size()), this->
data_.begin());
49 std::copy_n(data.begin(), std::min(data.size(), this->
data_.size()), this->
data_.begin());
57 const uint8_t *
data()
const {
return this->
data_.data(); }
59 return std::min(static_cast<uint8_t>(6 + (2 * this->
get_address_length()) + (this->
data_[2] & DATA_LENGTH_MASK)),
60 static_cast<uint8_t>(this->
data_.size()));
63 return this->
data_[0] == 0x55 && this->
data_[1] == 0xff &&
64 ((this->
data_[2] & DATA_LENGTH_MASK) <= MAX_DATA_LENGTH) &&
69 this->
data_[2] |= 0x80;
71 this->
data_[2] &= 0x7f;
78 if (three_byte_address) {
79 this->
data_[2] |= 0x40;
81 this->
data_[2] &= 0xbf;
90 this->
data_[4] = (address >> 8) & 0xff;
91 this->
data_[5] = address & 0xff;
93 this->
data_[4] = (address >> 16) & 0xff;
94 this->
data_[5] = (address >> 8) & 0xff;
95 this->
data_[6] = address & 0xff;
100 return (this->
data_[4] << 8) + this->
data_[5];
102 return (this->
data_[4] << 16) + (this->
data_[5] << 8) + this->
data_[6];
106 this->
data_[6] = (address >> 8) & 0xff;
107 this->
data_[7] = address & 0xff;
109 this->
data_[7] = (address >> 16) & 0xff;
110 this->
data_[8] = (address >> 8) & 0xff;
111 this->
data_[9] = address & 0xff;
116 return (this->
data_[6] << 8) + this->
data_[7];
118 return (this->
data_[7] << 16) + (this->
data_[8] << 8) + this->
data_[9];
123 uint8_t
size = std::min(MAX_DATA_LENGTH, static_cast<uint8_t>(data.size()));
124 this->
data_[2] &= (0xff ^ DATA_LENGTH_MASK);
125 this->
data_[2] |= (size & DATA_LENGTH_MASK);
135 return std::min(MAX_DATA_LENGTH, static_cast<uint8_t>(this->
data_[2] & DATA_LENGTH_MASK));
141 this->
data_[0] = 0x55;
142 this->
data_[1] = 0xff;
145 std::string
to_string(uint8_t max_print_bytes = 255)
const {
149 :
"[%04" PRIX32
" %s %04" PRIX32
"] Type: %02X",
157 uint8_t print_bytes = std::min(this->
size(), max_print_bytes);
163 if (std::equal(this->
data_.begin(), this->
data_.begin() + this->
size(), rhs.
data_.begin()))
174 std::array<uint8_t, 12 + MAX_DATA_LENGTH>
data_;
198 this->
data_.set_destination_address(destination_address);
216 TEMPLATABLE_VALUE(uint32_t, source_address)
217 TEMPLATABLE_VALUE(uint32_t, destination_address)
218 TEMPLATABLE_VALUE(
bool, retransmission)
219 TEMPLATABLE_VALUE(
bool, three_byte_address)
220 TEMPLATABLE_VALUE(uint8_t, message_type)
221 TEMPLATABLE_VALUE(uint8_t, message_id)
223 void set_data_static(std::vector<uint8_t>
data) { data_static_ = std::move(data); }
224 void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) {
225 this->data_func_ = func;
226 has_data_func_ =
true;
237 if (has_data_func_) {
247 std::function<std::vector<uint8_t>(Ts...)> data_func_{};
248 std::vector<uint8_t> data_static_{};
249 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
Implementation of SPI Controller mode.
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)