ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
canalsat_protocol.cpp
Go to the documentation of this file.
1#include "canalsat_protocol.h"
2#include "esphome/core/log.h"
3
4namespace esphome::remote_base {
5
6static const char *const CANALSAT_TAG = "remote.canalsat";
7static const char *const CANALSATLD_TAG = "remote.canalsatld";
8
9static constexpr uint16_t CANALSAT_FREQ = 55500;
10static constexpr uint16_t CANALSATLD_FREQ = 56000;
11static constexpr uint16_t CANALSAT_UNIT = 250;
12static constexpr uint16_t CANALSATLD_UNIT = 320;
13
15 this->frequency_ = CANALSAT_FREQ;
16 this->unit_ = CANALSAT_UNIT;
17 this->tag_ = CANALSAT_TAG;
18}
19
21 this->frequency_ = CANALSATLD_FREQ;
22 this->unit_ = CANALSATLD_UNIT;
23 this->tag_ = CANALSATLD_TAG;
24}
25
27 dst->reserve(48);
29
31 static_cast<uint32_t>((1 << 23) | (data.device << 16) | (data.address << 10) | (0 << 9) | (data.command << 1))};
32 bool was_high{true};
33
34 for (uint32_t mask = 0x800000; mask; mask >>= 1) {
35 if (raw & mask) {
36 if (was_high) {
37 dst->mark(this->unit_);
38 }
39 was_high = true;
40 if (raw & mask >> 1) {
41 dst->space(this->unit_);
42 } else {
43 dst->space(this->unit_ * 2);
44 }
45 } else {
46 if (!was_high) {
47 dst->space(this->unit_);
48 }
49 was_high = false;
50 if (raw & mask >> 1) {
51 dst->mark(this->unit_ * 2);
52 } else {
53 dst->mark(this->unit_);
54 }
55 }
56 }
57}
58
60 CanalSatData data{
61 .device = 0,
62 .address = 0,
63 .repeat = 0,
64 .command = 0,
65 };
66
67 // Check if initial mark and spaces match
68 if (!src.peek_mark(this->unit_) || !(src.peek_space(this->unit_, 1) || src.peek_space(this->unit_ * 2, 1))) {
69 return {};
70 }
71
72 uint8_t bit{1};
73 uint8_t offset{1};
74 uint32_t buffer{0};
75
76 while (offset < 24) {
77 buffer = buffer | (bit << (24 - offset++));
78 src.advance();
79 if (src.peek_mark(this->unit_) || src.peek_space(this->unit_)) {
80 src.advance();
81 } else if (src.peek_mark(this->unit_ * 2) || src.peek_space(this->unit_ * 2)) {
82 bit = !bit;
83 } else if (offset != 24 && bit != 1) { // If last bit is high, final space is indistinguishable
84 return {};
85 }
86 }
87
88 data.device = (0xFF0000 & buffer) >> 16;
89 data.address = (0x00FF00 & buffer) >> 10;
90 data.repeat = (0x00FF00 & buffer) >> 9;
91 data.command = (0x0000FF & buffer) >> 1;
92
93 return data;
94}
95
97 if (this->tag_ == CANALSATLD_TAG) {
98 ESP_LOGI(this->tag_, "Received CanalSatLD: device=0x%02X, address=0x%02X, command=0x%02X, repeat=0x%X", data.device,
99 data.address, data.command, data.repeat);
100 } else {
101 ESP_LOGI(this->tag_, "Received CanalSat: device=0x%02X, address=0x%02X, command=0x%02X, repeat=0x%X", data.device,
102 data.address, data.command, data.repeat);
103 }
104}
105
106} // namespace esphome::remote_base
uint8_t raw[35]
Definition bl0939.h:0
void dump(const CanalSatData &data) override
void encode(RemoteTransmitData *dst, const CanalSatData &data) override
optional< CanalSatData > decode(RemoteReceiveData src) override
void set_carrier_frequency(uint32_t carrier_frequency)
Definition remote_base.h:29
const void * src
Definition hal.h:64
static void uint32_t