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