16constexpr uint16_t LOW_BYTE_MASK = 0xFF;
19constexpr size_t PAYLOAD_LEN_HEADER = 4;
21constexpr size_t PAYLOAD_LEN_ONE_VALUE = 5;
26constexpr float DEGREES_TO_TENTHS = 10.0F;
28constexpr float HUNDREDTHS_PER_DEGREE = 100.0F;
34enum class HeatingValueKind : uint8_t {
44enum class HeatingAccess : uint8_t {
54struct HeatingFunctionDescriptor {
59 HeatingValueKind kind;
62constexpr HeatingFunctionDescriptor HEATING_FUNCTIONS[] = {
65 HeatingValueKind::TENTHS_U16},
69 HeatingValueKind::BINARY},
72 HeatingValueKind::HUNDREDTHS_S16},
82 for (
const auto &d : HEATING_FUNCTIONS) {
90void write_header(
const HeatingFunctionDescriptor &d, uint8_t direction, uint8_t *out) {
94 out[3] = d.register_low;
98size_t value_length(HeatingValueKind kind) {
100 case HeatingValueKind::NONE:
102 case HeatingValueKind::TENTHS_U16:
103 case HeatingValueKind::HUNDREDTHS_S16:
105 case HeatingValueKind::BINARY:
106 case HeatingValueKind::MODE:
107 case HeatingValueKind::ENUM_BYTE:
116 const HeatingFunctionDescriptor *d = descriptor_for(fn);
117 return d !=
nullptr ? d->name :
"unknown";
121 const HeatingFunctionDescriptor *d = descriptor_for(fn);
122 return d !=
nullptr && d->access != HeatingAccess::READ_ONLY;
126 const HeatingFunctionDescriptor *d = descriptor_for(fn);
127 return d !=
nullptr && d->access != HeatingAccess::WRITE_ONLY;
131 const HeatingFunctionDescriptor *d = descriptor_for(fn);
132 if (d ==
nullptr || d->access == HeatingAccess::WRITE_ONLY)
135 return PAYLOAD_LEN_HEADER;
139 const HeatingFunctionDescriptor *d = descriptor_for(fn);
142 if (d ==
nullptr || d->access == HeatingAccess::READ_ONLY)
146 case HeatingValueKind::TENTHS_U16: {
149 if (!std::isfinite(value) || value < HEATING_TEMP_MIN_C || value >
HEATING_TEMP_MAX_C)
158 const auto tenths =
static_cast<uint16_t
>(std::round(value * DEGREES_TO_TENTHS));
160 out[4] =
static_cast<uint8_t
>(tenths & LOW_BYTE_MASK);
161 out[PAYLOAD_LEN_TWO_VALUE - 1] =
static_cast<uint8_t
>(tenths >> BITS_PER_BYTE);
162 return PAYLOAD_LEN_TWO_VALUE;
165 case HeatingValueKind::MODE:
172 out[4] =
static_cast<uint8_t
>(value);
173 return PAYLOAD_LEN_ONE_VALUE;
175 case HeatingValueKind::BINARY:
176 if (value != 0.0F && value != 1.0F)
179 out[4] =
static_cast<uint8_t
>(value);
180 return PAYLOAD_LEN_ONE_VALUE;
182 case HeatingValueKind::NONE:
183 case HeatingValueKind::HUNDREDTHS_S16:
184 case HeatingValueKind::ENUM_BYTE:
191 const HeatingFunctionDescriptor *d = descriptor_for(fn);
198 const HeatingFunctionDescriptor *d = descriptor_for(fn);
199 if (d ==
nullptr || d->kind == HeatingValueKind::NONE || reply.
cmd != CMD_WRITE_PRIVATE_ACK)
202 const size_t value_len = value_length(d->kind);
203 if (reply.
data_len < PAYLOAD_LEN_HEADER + value_len)
205 const uint8_t *data = reply.
data;
211 const uint8_t *v = data + PAYLOAD_LEN_HEADER;
212 const auto raw16 =
static_cast<uint16_t
>(v[0] | (v[1] << BITS_PER_BYTE));
214 case HeatingValueKind::TENTHS_U16:
215 value =
static_cast<float>(raw16) / DEGREES_TO_TENTHS;
218 case HeatingValueKind::HUNDREDTHS_S16: {
219 const auto signed_raw =
static_cast<int16_t
>(raw16);
224 case HeatingValueKind::BINARY:
227 value =
static_cast<float>(v[0]);
230 case HeatingValueKind::MODE:
233 value =
static_cast<float>(v[0]);
236 case HeatingValueKind::ENUM_BYTE:
237 if (v[0] > REGULATOR_STATE_MAX)
239 value =
static_cast<float>(v[0]);
242 case HeatingValueKind::NONE:
260 this->
mode =
static_cast<int16_t
>(value);
263 this->
regulator =
static_cast<int16_t
>(value);
288 return this->
mode >= 0;
bool decode_heating_reply(const IoFrame &reply, HeatingFunction fn, float &value)
Decode the value a heater answered a register read or write with.
constexpr size_t HEATING_PAYLOAD_MAX_SIZE
Largest payload any function produces: a set of a 16-bit value (4-byte header + 2 value bytes).
@ HEATING
The element is heating.
size_t encode_heating_payload(HeatingFunction fn, float value, uint8_t out[HEATING_PAYLOAD_MAX_SIZE])
Encode the function the heating_control action runs: a read for a read-only register,...
HeatingFunction
Registers and functions of a 2W heater, one row of the descriptor table each.
@ MIDNIGHT_SYNC
Register 0x0130, read: the comfort/eco/auto setpoint block. Logged, never decoded.
@ ROOM_TEMPERATURE
Register 0x0115, read-only: measured room temperature, signed hundredths of a degree.
@ MAX_SETPOINT
Register 0x0102, read-only: highest setpoint the heater accepts, tenths of a degree.
@ POWER_ON
Register 0x012C, read: the paired-device list. Logged, never decoded.
@ SET_PRESENCE
Register 0x0110, write-only: someone is in the room (1) or not (0).
@ REGULATOR_STATE
Register 0x0117, read-only: 0 none, 1 standby, 2 heating.
@ WINDOW_OPEN
Register 0x010E, read-only: the heater's window sensor, 0 closed / 1 open.
@ SET_OPEN_WINDOW_DETECTION
Register 0x0106, read/write: open-window detection on (1) or off (0).
@ SET_TEMPERATURE
Register 0x0103, read/write: comfort setpoint, tenths of a degree.
@ SET_MODE
Register 0x0100, read/write: operating mode (HeatingMode).
constexpr uint8_t HEATING_REGISTER_HIGH_BYTE
Payload byte at index 2: the high byte of the 16-bit register number, constant 0x01.
bool heating_function_is_readable(HeatingFunction fn)
Whether the register behind a function can be read.
constexpr float HEATING_TEMP_MAX_C
Highest setpoint this codec will encode.
const char * heating_function_name(HeatingFunction fn)
Stable lowercase name for a heating function ("power_on", "set_temperature", ...).
constexpr uint8_t HEATING_DIRECTION_SET
Payload byte at index 1 of a write ("set") request.
size_t encode_heating_write(HeatingFunction fn, float value, uint8_t out[HEATING_PAYLOAD_MAX_SIZE])
Encode a write ("set") of one register into a CMD_WRITE_PRIVATE (0x20) payload.
@ PROG
Program mode; the device runs its own stored weekly schedule.
@ MANUAL
Manual mode; follows the last written setpoint.
@ AUTO
Automatic mode; the device manages the setpoint itself.
constexpr int16_t HEATING_SENSOR_FAULT_RAW
Measured value in a reading when the heater reports a sensor fault (raw -1).
constexpr uint8_t HEATING_PAYLOAD_PREFIX
Leading payload byte, common to every function.
bool heating_function_is_writable(HeatingFunction fn)
Whether the register behind a function can be written.
size_t encode_heating_read(HeatingFunction fn, uint8_t out[HEATING_PAYLOAD_MAX_SIZE])
Encode a read ("get") of one register into a CMD_WRITE_PRIVATE (0x20) payload.
constexpr uint8_t HEATING_DIRECTION_GET
Payload byte at index 1 of a read ("get") request.
@ NONE
target_fw is unknown, or its required bootloader matches bootloader_version.
IO-Homecontrol command IDs, result codes and protocol enumerations.
Pure codec for the private register protocol of 2W heaters (CMD_WRITE_PRIVATE 0x20).
Fundamental IO-Homecontrol frame and crypto size constants.
int16_t window_open
0 closed / 1 open; -1 until read.
int16_t open_window_detection
1 detection on / 0 off; -1 until read.
bool has(HeatingFunction fn) const
Has this register been read yet?
float setpoint_c
Comfort setpoint as the heater holds it; NaN until read.
float room_temperature_c
Measured room temperature; NaN until read or on a sensor fault.
float max_setpoint_c
Highest setpoint the heater accepts; NaN until read.
int16_t mode
HeatingMode value; -1 until read.
int16_t regulator
HeatingRegulatorState value; -1 until read.
bool store(HeatingFunction fn, float value)
Fold one decoded register value into the readings.
Parsed IO‑Homecontrol frame (CTRL0/1 + addresses + command + data).
uint8_t data[FRAME_MAX_DATA_SIZE]
Command parameters (0–23 bytes). Never includes mac.
uint8_t data_len
Actual length of data.