5 namespace remote_base {
7 static const char *
const TAG =
"remote.abbwelcome";
9 static const uint32_t BIT_ONE_SPACE_US = 102;
10 static const uint32_t BIT_ZERO_MARK_US = 32;
11 static const uint32_t BIT_ZERO_SPACE_US = BIT_ONE_SPACE_US - BIT_ZERO_MARK_US;
12 static const uint16_t BYTE_SPACE_US = 210;
16 for (uint8_t i = 0; i < this->
size() - 1; i++) {
17 uint16_t temp = checksum ^ (this->
data_[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++)
53 this->encode_byte_(dst, src[i]);
54 ESP_LOGD(TAG,
"Transmitting: %s", src.
to_string().c_str());
60 uint32_t next_space = BIT_ZERO_SPACE_US;
61 for (uint8_t mask = 1 << 7; mask; mask >>= 1) {
67 next_space = BIT_ZERO_SPACE_US;
70 next_space += BIT_ONE_SPACE_US;
73 next_space += BYTE_SPACE_US;
81 if (src.
expect_item(BIT_ZERO_MARK_US, BIT_ZERO_SPACE_US) &&
82 src.
expect_item(BIT_ZERO_MARK_US, BIT_ZERO_SPACE_US + BIT_ONE_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 + BYTE_SPACE_US) &&
86 src.
expect_item(BIT_ZERO_MARK_US, BIT_ZERO_SPACE_US + 8 * BIT_ONE_SPACE_US + BYTE_SPACE_US)) {
87 ESP_LOGVV(TAG,
"Received Header: 0x55FF");
93 uint8_t received_bytes = 2;
94 for (; (received_bytes <
length) && !done; received_bytes++) {
96 if (!this->decode_byte_(src, done, data)) {
97 ESP_LOGW(TAG,
"Received incomplete packet: %s", out.
to_string(received_bytes).c_str());
100 if (received_bytes == 2) {
101 length += std::min(static_cast<uint8_t>(data & DATA_LENGTH_MASK), MAX_DATA_LENGTH);
106 ESP_LOGVV(TAG,
"Received Byte: 0x%02X", data);
107 out[received_bytes] =
data;
110 ESP_LOGI(TAG,
"Received: %s", out.
to_string().c_str());
113 ESP_LOGW(TAG,
"Received malformed packet: %s", out.
to_string(received_bytes).c_str());
119 ESP_LOGD(TAG,
"Received ABBWelcome: %s", data.
to_string().c_str());
void encode_byte_(RemoteTransmitData *dst, uint8_t data) const
optional< ABBWelcomeData > decode(RemoteReceiveData src) override
void set_carrier_frequency(uint32_t carrier_frequency)
bool decode_byte_(RemoteReceiveData &src, bool &done, uint8_t &data)
std::array< uint8_t, 12+MAX_DATA_LENGTH > data_
bool expect_space(uint32_t length)
std::string to_string(uint8_t max_print_bytes=255) const
bool expect_mark(uint32_t length)
void mark(uint32_t length)
void space(uint32_t length)
Implementation of SPI Controller mode.
void encode(RemoteTransmitData *dst, const ABBWelcomeData &src) override
void reserve(uint32_t len)
bool expect_item(uint32_t mark, uint32_t space)
void dump(const ABBWelcomeData &data) override