ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
dish_protocol.cpp
Go to the documentation of this file.
1#include "dish_protocol.h"
2#include "esphome/core/log.h"
3
4namespace esphome::remote_base {
5
6static const char *const TAG = "remote.dish";
7
8static constexpr uint32_t HEADER_HIGH_US = 400;
9static constexpr uint32_t HEADER_LOW_US = 6100;
10static constexpr uint32_t BIT_HIGH_US = 400;
11static constexpr uint32_t BIT_ONE_LOW_US = 1700;
12static constexpr uint32_t BIT_ZERO_LOW_US = 2800;
13
15 dst->reserve(138);
16 dst->set_carrier_frequency(57600);
17
18 // HEADER
19 dst->item(HEADER_HIGH_US, HEADER_LOW_US);
20
21 // Typically a DISH device needs to get a command a total of
22 // at least 4 times to accept it.
23 for (uint i = 0; i < 4; i++) {
24 // COMMAND (function, in MSB)
25 for (uint8_t mask = 1UL << 5; mask; mask >>= 1) {
26 if (data.command & mask) {
27 dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
28 } else {
29 dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
30 }
31 }
32
33 // ADDRESS (unit code, in LSB)
34 for (uint8_t mask = 1UL; mask < 1UL << 4; mask <<= 1) {
35 if ((data.address - 1) & mask) {
36 dst->item(BIT_HIGH_US, BIT_ONE_LOW_US);
37 } else {
38 dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
39 }
40 }
41 // PADDING
42 for (uint j = 0; j < 6; j++)
43 dst->item(BIT_HIGH_US, BIT_ZERO_LOW_US);
44
45 // FOOTER
46 dst->item(HEADER_HIGH_US, HEADER_LOW_US);
47 }
48}
49optional<DishData> DishProtocol::decode(RemoteReceiveData src) {
50 DishData data{
51 .address = 0,
52 .command = 0,
53 };
54 if (!src.expect_item(HEADER_HIGH_US, HEADER_LOW_US))
55 return {};
56
57 for (uint8_t mask = 1UL << 5; mask != 0; mask >>= 1) {
58 if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
59 data.command |= mask;
60 } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
61 data.command &= ~mask;
62 } else {
63 return {};
64 }
65 }
66
67 for (uint8_t mask = 1UL; mask < 1UL << 5; mask <<= 1) {
68 if (src.expect_item(BIT_HIGH_US, BIT_ONE_LOW_US)) {
69 data.address |= mask;
70 } else if (src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
71 data.address &= ~mask;
72 } else {
73 return {};
74 }
75 }
76 for (uint j = 0; j < 6; j++) {
77 if (!src.expect_item(BIT_HIGH_US, BIT_ZERO_LOW_US)) {
78 return {};
79 }
80 }
81 data.address++;
82
83 src.expect_item(HEADER_HIGH_US, HEADER_LOW_US);
84
85 return data;
86}
87
88void DishProtocol::dump(const DishData &data) {
89 ESP_LOGI(TAG, "Received Dish: address=0x%02X, command=0x%02X", data.address, data.command);
90}
91
92} // namespace esphome::remote_base
void dump(const DishData &data) override
optional< DishData > decode(RemoteReceiveData src) override
void encode(RemoteTransmitData *dst, const DishData &data) override
bool expect_item(uint32_t mark, uint32_t space)
void set_carrier_frequency(uint32_t carrier_frequency)
Definition remote_base.h:29
void item(uint32_t mark, uint32_t space)
Definition remote_base.h:24
static void uint32_t