7static const char *
const TAG =
"remote.abbwelcome";
9static const uint32_t BIT_ONE_SPACE_US = 102;
10static const uint32_t BIT_ZERO_MARK_US = 32;
11static const uint32_t BIT_ZERO_SPACE_US = BIT_ONE_SPACE_US - BIT_ZERO_MARK_US;
12static const uint16_t BYTE_SPACE_US = 210;
16 for (uint8_t i = 0; i < this->
size() - 1; i++) {
18 temp = temp ^ (uint16_t) (((uint32_t) temp << 0x11) >> 0x10) ^ (uint16_t) (((uint32_t) temp << 0x12) >> 0x10) ^
19 (uint16_t) (((uint32_t) temp << 0x13) >> 0x10) ^ (uint16_t) (((uint32_t) temp << 0x14) >> 0x10) ^
20 (uint16_t) (((uint32_t) temp << 0x15) >> 0x10) ^ (uint16_t) (((uint32_t) temp << 0x16) >> 0x10) ^
21 (uint16_t) (((uint32_t) temp << 0x17) >> 0x10);
22 checksum = (temp & 0xfe) ^ ((temp >> 8) & 1);
29 dst->
mark(BIT_ZERO_MARK_US);
30 uint32_t next_space = BIT_ZERO_SPACE_US;
31 for (uint8_t mask = 1 << 7; mask; mask >>= 1) {
33 next_space += BIT_ONE_SPACE_US;
35 dst->
space(next_space);
36 dst->
mark(BIT_ZERO_MARK_US);
37 next_space = BIT_ZERO_SPACE_US;
40 next_space += BYTE_SPACE_US;
41 dst->
space(next_space);
46 uint32_t reserve_count = 0;
47 for (
size_t i = 0; i < src.
size(); i++) {
48 reserve_count += 2 * (9 - (src[i] & 1) - ((src[i] >> 1) & 1) - ((src[i] >> 2) & 1) - ((src[i] >> 3) & 1) -
49 ((src[i] >> 4) & 1) - ((src[i] >> 5) & 1) - ((src[i] >> 6) & 1) - ((src[i] >> 7) & 1));
52 for (
size_t i = 0; i < src.
size(); i++)
55 ESP_LOGD(TAG,
"Transmitting: %s", src.
format_to(buf));
61 uint32_t next_space = BIT_ZERO_SPACE_US;
62 for (uint8_t mask = 1 << 7; mask; mask >>= 1) {
68 next_space = BIT_ZERO_SPACE_US;
71 next_space += BIT_ONE_SPACE_US;
74 next_space += BYTE_SPACE_US;
82 if (src.
expect_item(BIT_ZERO_MARK_US, BIT_ZERO_SPACE_US) &&
83 src.
expect_item(BIT_ZERO_MARK_US, BIT_ZERO_SPACE_US + BIT_ONE_SPACE_US) &&
84 src.
expect_item(BIT_ZERO_MARK_US, BIT_ZERO_SPACE_US + BIT_ONE_SPACE_US) &&
85 src.
expect_item(BIT_ZERO_MARK_US, BIT_ZERO_SPACE_US + BIT_ONE_SPACE_US) &&
86 src.
expect_item(BIT_ZERO_MARK_US, BIT_ZERO_SPACE_US + BIT_ONE_SPACE_US + BYTE_SPACE_US) &&
87 src.
expect_item(BIT_ZERO_MARK_US, BIT_ZERO_SPACE_US + 8 * BIT_ONE_SPACE_US + BYTE_SPACE_US)) {
88 ESP_LOGVV(TAG,
"Received Header: 0x55FF");
94 uint8_t received_bytes = 2;
95 for (; (received_bytes <
length) && !done; received_bytes++) {
99 ESP_LOGW(TAG,
"Received incomplete packet: %s", out.
format_to(buf, received_bytes));
102 if (received_bytes == 2) {
103 length += std::min(
static_cast<uint8_t
>(data & DATA_LENGTH_MASK), MAX_DATA_LENGTH);
108 ESP_LOGVV(TAG,
"Received Byte: 0x%02X", data);
109 out[received_bytes] = data;
113 ESP_LOGI(TAG,
"Received: %s", out.
format_to(buf));
116 ESP_LOGW(TAG,
"Received malformed packet: %s", out.
format_to(buf, received_bytes));
123 ESP_LOGD(TAG,
"Received ABBWelcome: %s", data.
format_to(buf));
static constexpr size_t FORMAT_BUFFER_SIZE
std::array< uint8_t, 12+MAX_DATA_LENGTH > data_
char * format_to(char(&buffer)[N], uint8_t max_print_bytes=255) const
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
bool expect_item(uint32_t mark, uint32_t space)
bool expect_space(uint32_t length)
bool expect_mark(uint32_t length)
void space(uint32_t length)
void set_carrier_frequency(uint32_t carrier_frequency)
void mark(uint32_t length)
void reserve(uint32_t len)
Providing packet encoding functions for exchanging data with a remote host.