9static const char *
const TAG =
"vbus";
12static constexpr size_t VBUS_MAX_LOG_BYTES = 64;
15 ESP_LOGCONFIG(TAG,
"VBus:");
19static void septet_spread(uint8_t *data,
int start,
int count, uint8_t septet) {
20 for (
int i = 0; i < count; i++, septet >>= 1) {
22 data[start + i] |= 0x80;
26static bool checksum(
const uint8_t *data,
int start,
int count) {
28 for (
int i = 0; i < count; i++)
29 csum = (csum - data[start + i]) & 0x7f;
55 if (this->
buffer_.size() == 7) {
64 ESP_LOGE(TAG,
"P2 checksum failed");
67 septet_spread(this->
buffer_.data(), 7, 6, this->buffer_[13]);
71 ESP_LOGV(TAG,
"P1 C%04x %04x->%04x: %04x %04" PRIx32
" (%" PRIu32
")", this->
command_, this->
source_,
72 this->
dest_,
id, value, value);
75 ESP_LOGE(TAG,
"P1 checksum failed");
87 ESP_LOGD(TAG,
"P1 empty message");
99 ESP_LOGE(TAG,
"frame checksum failed");
103 for (
int i = 0; i < 4; i++)
104 this->
buffer_.push_back(this->fbytes_[i]);
107#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERBOSE
125 if ((this->
dest_ != 0xffff) && (this->
dest_ != dest))
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
bool read_byte(uint8_t *data)
std::vector< VBusListener * > listeners_
std::vector< uint8_t > buffer_
void dump_config() override
void on_message(uint16_t command, uint16_t source, uint16_t dest, std::vector< uint8_t > &message)
virtual void handle_message(std::vector< uint8_t > &message)=0
Providing packet encoding functions for exchanging data with a remote host.
constexpr size_t format_hex_size(size_t byte_count)
Calculate buffer size needed for format_hex_to: "XXXXXXXX...\0" = bytes * 2 + 1.
char * format_hex_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length)
Format byte array as lowercase hex to buffer (base implementation).