forked from omerfaruk-aran/esphome_samsung_hvac_bus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
protocol.h
157 lines (136 loc) · 5.17 KB
/
protocol.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#pragma once
#include <set>
#include "esphome/core/optional.h"
#include "util.h"
namespace esphome
{
namespace samsung_ac
{
extern bool debug_log_raw_bytes;
extern bool non_nasa_keepalive;
extern bool debug_log_undefined_messages;
extern bool debug_log_messages;
enum class DecodeResult
{
Ok = 0,
InvalidStartByte = 1,
InvalidEndByte = 2,
SizeDidNotMatch = 3,
UnexpectedSize = 4,
CrcError = 5
};
enum class Mode
{
Unknown = -1,
Auto = 0,
Cool = 1,
Dry = 2,
Fan = 3,
Heat = 4,
};
enum class WaterHeaterMode
{
Unknown = -1,
Eco = 0,
Standard = 1,
Power = 2,
Force = 3,
};
enum class FanMode
{
Unknown = -1,
Auto = 0,
Low = 1,
Mid = 2,
High = 3,
Turbo = 4,
Off = 5
};
typedef std::string AltModeName;
typedef uint8_t AltMode;
struct AltModeDesc
{
AltModeName name;
AltMode value;
};
enum class SwingMode : uint8_t
{
Fix = 0,
Vertical = 1,
Horizontal = 2,
All = 3
};
class MessageTarget
{
public:
virtual uint32_t get_miliseconds() = 0;
virtual void publish_data(std::vector<uint8_t> &data) = 0;
virtual void register_address(const std::string address) = 0;
virtual void set_power(const std::string address, bool value) = 0;
virtual void set_automatic_cleaning(const std::string address, bool value) = 0;
virtual void set_water_heater_power(const std::string address, bool value) = 0;
virtual void set_room_temperature(const std::string address, float value) = 0;
virtual void set_target_temperature(const std::string address, float value) = 0;
virtual void set_water_outlet_target(const std::string address, float value) = 0;
virtual void set_outdoor_temperature(const std::string address, float value) = 0;
virtual void set_indoor_eva_in_temperature(const std::string address, float value) = 0;
virtual void set_indoor_eva_out_temperature(const std::string address, float value) = 0;
virtual void set_target_water_temperature(const std::string address, float value) = 0;
virtual void set_mode(const std::string address, Mode mode) = 0;
virtual void set_water_heater_mode(const std::string address, WaterHeaterMode waterheatermode) = 0;
virtual void set_fanmode(const std::string address, FanMode fanmode) = 0;
virtual void set_altmode(const std::string address, AltMode altmode) = 0;
virtual void set_swing_vertical(const std::string address, bool vertical) = 0;
virtual void set_swing_horizontal(const std::string address, bool horizontal) = 0;
virtual void set_custom_sensor(const std::string address, uint16_t message_number, float value) = 0;
virtual void set_error_code(const std::string address, int error_code) = 0;
virtual void set_outdoor_instantaneous_power(const std::string &address, float value) = 0;
virtual void set_outdoor_cumulative_energy(const std::string &address, float value) = 0;
virtual void set_outdoor_current(const std::string &address, float value) = 0;
virtual void set_outdoor_voltage(const std::string &address, float value) = 0;
};
struct ProtocolRequest
{
public:
optional<bool> power;
optional<bool> automatic_cleaning;
optional<bool> water_heater_power;
optional<Mode> mode;
optional<WaterHeaterMode> waterheatermode;
optional<float> target_temp;
optional<float> water_outlet_target;
optional<float> target_water_temp;
optional<FanMode> fan_mode;
optional<SwingMode> swing_mode;
optional<AltMode> alt_mode;
};
class Protocol
{
public:
virtual void publish_request(MessageTarget *target, const std::string &address, ProtocolRequest &request) = 0;
virtual void protocol_update(MessageTarget *target) = 0;
};
enum class ProtocolProcessing
{
Auto = 0,
NASA = 1,
NonNASA = 2
};
extern ProtocolProcessing protocol_processing;
enum class DataResult
{
Fill = 0,
Clear = 1
};
DataResult process_data(std::vector<uint8_t> &data, MessageTarget *target);
Protocol *get_protocol(const std::string &address);
bool is_nasa_address(const std::string &address);
enum class AddressType
{
Outdoor = 0,
Indoor = 1,
Other = 2
};
AddressType get_address_type(const std::string &address);
} // namespace samsung_ac
} // namespace esphome