5 namespace remote_base {
7 static const char *
const TAG =
"remote.rc_switch";
20 uint32_t one_high, uint32_t one_low,
bool inverted)
21 : sync_high_(sync_high),
23 zero_high_(zero_high),
27 inverted_(inverted) {}
59 for (int16_t i = len - 1; i >= 0; i--) {
60 if (code & ((uint64_t) 1 << i)) {
121 for (*out_nbits = 0; *out_nbits < 64; *out_nbits += 1) {
129 return *out_nbits >= 8;
137 for (uint8_t i = 1; i <= 8; i++) {
140 if (protocol->
decode(src, &out.
code, &out_nbits) && out_nbits >= 3) {
150 for (int8_t i = nbits - 1; i >= 0; i--) {
152 if (code & (1 << i)) {
160 uint8_t *out_nbits) {
162 code = switch_group ^ 0b11111;
164 code |= switch_device ^ 0b11111;
166 code |= state ? 0b01 : 0b10;
171 uint8_t *out_nbits) {
173 code |= (address_code == 1) ? 0 : 0b1000;
174 code |= (address_code == 2) ? 0 : 0b0100;
175 code |= (address_code == 3) ? 0 : 0b0010;
176 code |= (address_code == 4) ? 0 : 0b0001;
178 code |= (channel_code == 1) ? 0 : 0b1000;
179 code |= (channel_code == 2) ? 0 : 0b0100;
180 code |= (channel_code == 3) ? 0 : 0b0010;
181 code |= (channel_code == 4) ? 0 : 0b0001;
184 code |= state ? 0b1 : 0b0;
189 uint8_t *out_nbits) {
191 code |= (family & 0b0001) ? 0b1000 : 0;
192 code |= (family & 0b0010) ? 0b0100 : 0;
193 code |= (family & 0b0100) ? 0b0010 : 0;
194 code |= (family & 0b1000) ? 0b0001 : 0;
196 code |= ((device - 1) & 0b01) ? 0b1000 : 0;
197 code |= ((device - 1) & 0b10) ? 0b0100 : 0;
198 code |= ((group - 1) & 0b01) ? 0b0010 : 0;
199 code |= ((group - 1) & 0b10) ? 0b0001 : 0;
202 code |= state ? 0b1 : 0b0;
208 *out_code |= (group == 0) ? 0b11000000 : 0b01000000;
209 *out_code |= (group == 1) ? 0b00110000 : 0b00010000;
210 *out_code |= (group == 2) ? 0b00001100 : 0b00000100;
211 *out_code |= (group == 3) ? 0b00000011 : 0b00000001;
213 *out_code |= (device == 1) ? 0b110000 : 0b010000;
214 *out_code |= (device == 2) ? 0b001100 : 0b000100;
215 *out_code |= (device == 3) ? 0b000011 : 0b000001;
217 *out_code |= 0b000000;
219 *out_code |= state ? 0b1100 : 0b0011;
225 for (
char c : data) {
234 for (
char c : data) {
242 uint64_t decoded_code;
243 uint8_t decoded_nbits;
244 if (!this->protocol_.decode(src, &decoded_code, &decoded_nbits))
247 return decoded_nbits == this->nbits_ && (decoded_code & this->mask_) == (this->code_ & this->mask_);
250 for (uint8_t i = 1; i <= 8; i++) {
255 if (protocol->
decode(src, &out_data, &out_nbits) && out_nbits >= 3) {
257 for (uint8_t j = 0; j < out_nbits; j++)
258 buffer[j] = (out_data & ((uint64_t) 1 << (out_nbits - j - 1))) ?
'1' :
'0';
260 buffer[out_nbits] =
'\0';
261 ESP_LOGI(TAG,
"Received RCSwitch Raw: protocol=%u data='%s'", i, buffer);
bool decode(RemoteReceiveData &src, uint64_t *out_data, uint8_t *out_nbits) const
void zero(RemoteTransmitData *dst) const
void set_carrier_frequency(uint32_t carrier_frequency)
bool peek_space(uint32_t length, uint32_t offset=0) const
bool expect_one(RemoteReceiveData &src) const
void transmit(RemoteTransmitData *dst, uint64_t code, uint8_t len) const
void sync(RemoteTransmitData *dst) const
static void type_d_code(uint8_t group, uint8_t device, bool state, uint64_t *out_code, uint8_t *out_nbits)
static void type_c_code(uint8_t family, uint8_t group, uint8_t device, bool state, uint64_t *out_code, uint8_t *out_nbits)
bool peek_mark(uint32_t length, uint32_t offset=0) const
bool expect_zero(RemoteReceiveData &src) const
static void type_a_code(uint8_t switch_group, uint8_t switch_device, bool state, uint64_t *out_code, uint8_t *out_nbits)
void mark(uint32_t length)
static void simple_code_to_tristate(uint16_t code, uint8_t nbits, uint64_t *out_code)
uint64_t decode_binary_string_mask(const std::string &data)
bool expect_sync(RemoteReceiveData &src) const
const RCSwitchBase RC_SWITCH_PROTOCOLS[9]
bool dump(RemoteReceiveData src) override
void one(RemoteTransmitData *dst) const
uint64_t decode_binary_string(const std::string &data)
static void type_b_code(uint8_t address_code, uint8_t channel_code, bool state, uint64_t *out_code, uint8_t *out_nbits)
void space(uint32_t length)
Implementation of SPI Controller mode.
bool matches(RemoteReceiveData src) override
void advance(uint32_t amount=1)