From 08c5217a9aa3d648352091b48c132e5d085ca758 Mon Sep 17 00:00:00 2001 From: Jeroen Mijnarends-Jansen Date: Fri, 25 Sep 2026 20:38:01 +0200 Subject: [PATCH] Ondersteun defrost in de ODU-simulator voor HIL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Voeg de defrost-parametersblokken toe (3270..3280, 3307..3315, 3336..3341, 3414..3427), een profielafhankelijke 3275-schrijfweg en handmatige 2103-frequentietelemetrie. Een 3999=4-verzoek lacht nu een eigen defrostcyclus die de ODU onafhankelijk van de defrost-injectieschakelaar actief houdt en na de modelduur zelf beëindigt, zodat de controller working_mode=4 kan waarnemen en de cyclus kan afronden. De injectieschakelaar mag een geforceerde cyclus niet meer annuleren; dat was de reden dat de handmatige trigger nooit ACTIVE werd. Voeg de nodige hosttests en registercontract bij en verhoog de simulator naar v0.4.1. --- README.md | 17 +-- .../quatt_odu_registers.generated.h | 9 +- .../quatt_odu_simulator/quatt_odu_simulator.h | 6 + .../quatt_odu_simulator_model.h | 110 +++++++++++++++--- data/odu/registers.yaml | 5 + docs/quatt-odu-register-contract.md | 5 + hcq_v1_system_simulator.yaml | 2 +- packages/quatt_odu_simulator.yaml | 91 +++++++++++++-- scripts/generate_odu_contract.py | 2 +- tests/quatt_odu_register_contract_test.cpp | 17 ++- tests/quatt_odu_simulator_model_test.cpp | 52 +++++++++ 11 files changed, 274 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 17ed42d..1e82cc9 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ can simultaneously simulate: Modbus addresses 1 and 2. The combined firmware publishes compatibility contract -`openquatt-modbus-opentherm-v2` and simulator version `v0.4.0`. HIL clients +`openquatt-modbus-opentherm-v2` and simulator version `v0.4.1`. HIL clients must verify the contract before changing controller or simulator state. The project has no runtime or source dependency on OpenQuatt. Its register, @@ -126,9 +126,11 @@ restore button. Legacy reads of the extension return recognizable poison values and increment `Legacy extension read violation`. The model implements actuator writes at `1999`, `2006`, `2010`, `2015` and -`3999`, every runtime register at `2099..2138`, core identity, customer/model -text, synthetic serial metadata and the EEPROM read range used by OpenQuatt. -The generated contract documents every supported address and its confidence: +`3999`, the defrost method write at `3275`, the defrost parameter blocks at +`3270..3280`, `3307..3315`, `3336..3341` and `3414..3427`, every runtime +register at `2099..2138`, core identity, customer/model text, synthetic serial +metadata and the EEPROM read range used by OpenQuatt. The generated contract +documents every supported address and its confidence: [docs/quatt-odu-register-contract.md](docs/quatt-odu-register-contract.md). ## Dynamic model @@ -158,9 +160,10 @@ The V2 snapshot uses the complete CiC 4.2.0 10 Hz × 17 ambient × 8 supply surface. Masked cells and inputs outside the V2 ambient/supply domain yield no synthetic performance output. For deterministic HIL fixtures, each ODU has an off-by-default `manual telemetry override`. It supplies only the documented -raw readbacks for `2099`, `2100`, `2101`, `2105`, `2108`, `2133`, `2134`, -`2137` and `2138`; it does not alter dynamic state or the independent defrost -register `2118`. +raw readbacks for `2099`, `2100`, `2101`, `2103`, `2105`, `2108`, `2133`, +`2134`, `2137` and `2138`; it does not alter dynamic state or the independent +defrost register `2118`. + Defrost can be injected per ODU. The defrost register and status bit are set, water-out temporarily falls, and `Hold physical level during defrost` controls diff --git a/components/quatt_odu_simulator/quatt_odu_registers.generated.h b/components/quatt_odu_simulator/quatt_odu_registers.generated.h index b1db30e..ad7e8de 100644 --- a/components/quatt_odu_simulator/quatt_odu_registers.generated.h +++ b/components/quatt_odu_simulator/quatt_odu_registers.generated.h @@ -30,7 +30,7 @@ struct RegisterRangeDescriptor { Confidence confidence; }; -inline constexpr std::array REGISTER_DESCRIPTORS = {{ +inline constexpr std::array REGISTER_DESCRIPTORS = {{ {1999U, 1U, "compressor_level", Access::READ_WRITE, 1.0f, 0.0f, 0x1EU, Confidence::CONTROLLER_CONTRACT, false}, {2006U, 1U, "silent_mode", Access::READ_WRITE, 1.0f, 0.0f, 0x1EU, Confidence::CONTROLLER_CONTRACT, false}, {2010U, 1U, "pump_mode", Access::READ_WRITE, 1.0f, 0.0f, 0x1EU, Confidence::CONTROLLER_CONTRACT, false}, @@ -76,6 +76,7 @@ inline constexpr std::array REGISTER_DESCRIPTORS = {{ {2137U, 1U, "pump_ipwm_feedback", Access::READ, 1.0f, 0.0f, 0x1EU, Confidence::CONTROLLER_CONTRACT, false}, {2138U, 1U, "water_flow", Access::READ, 0.618f, 0.0f, 0x1EU, Confidence::CONTROLLER_CONTRACT, false}, {3999U, 1U, "requested_working_mode", Access::READ_WRITE, 1.0f, 0.0f, 0x1EU, Confidence::CONTROLLER_CONTRACT, false}, + {3275U, 1U, "defrost_mode", Access::READ_WRITE, 1.0f, 0.0f, 0x1CU, Confidence::CONTROLLER_CONTRACT, false}, {11004U, 1U, "extended_metadata_11004", Access::READ, 1.0f, 0.0f, 0x1EU, Confidence::UNKNOWN, false}, {11005U, 1U, "extended_metadata_11005", Access::READ, 1.0f, 0.0f, 0x1EU, Confidence::UNKNOWN, false}, {11006U, 1U, "extended_metadata_11006", Access::READ, 1.0f, 0.0f, 0x1EU, Confidence::UNKNOWN, false}, @@ -86,7 +87,11 @@ inline constexpr std::array REGISTER_DESCRIPTORS = {{ {11161U, 1U, "customer_model_word_1", Access::READ, 1.0f, 0.0f, 0x1EU, Confidence::OBSERVED, false}, }}; -inline constexpr std::array REGISTER_RANGE_DESCRIPTORS = {{ +inline constexpr std::array REGISTER_RANGE_DESCRIPTORS = {{ + {3270U, 3280U, "defrost_base", Access::READ, 0x1EU, Confidence::SYNTHETIC}, + {3307U, 3315U, "defrost_timing", Access::READ, 0x1EU, Confidence::SYNTHETIC}, + {3336U, 3341U, "defrost_coil", Access::READ, 0x1EU, Confidence::SYNTHETIC}, + {3414U, 3427U, "defrost_delta", Access::READ, 0x1CU, Confidence::SYNTHETIC}, {2999U, 3510U, "eeprom_fixture", Access::READ, 0x1EU, Confidence::UNKNOWN}, {3000U, 3021U, "base_frequency_table", Access::READ_WRITE, 0x1EU, Confidence::OBSERVED}, {3050U, 3069U, "v2_frequency_extension", Access::READ_WRITE, 0x10U, Confidence::CONTROLLER_CONTRACT}, diff --git a/components/quatt_odu_simulator/quatt_odu_simulator.h b/components/quatt_odu_simulator/quatt_odu_simulator.h index eba67ca..a514785 100644 --- a/components/quatt_odu_simulator/quatt_odu_simulator.h +++ b/components/quatt_odu_simulator/quatt_odu_simulator.h @@ -227,6 +227,9 @@ class QuattOduSimulator final : public PollingComponent { void set_manual_working_mode(uint8_t index, uint16_t value) { this->model(index).set_manual_working_mode_raw(std::min(value, 2U)); } + void set_manual_compressor_frequency(uint8_t index, uint16_t value) { + this->model(index).set_manual_compressor_frequency_raw(std::min(value, 120U)); + } void set_manual_ac_voltage(uint8_t index, float value) { this->model(index).set_manual_ac_voltage_raw(encode_unsigned_(value)); } @@ -254,6 +257,9 @@ class QuattOduSimulator final : public PollingComponent { void set_hold_level_during_defrost(uint8_t index, bool value) { this->model(index).mutable_settings().hold_level_during_defrost = value; } + void set_forced_defrost_duration_s(uint8_t index, float value) { + this->model(index).mutable_settings().forced_defrost_duration_s = value; + } void restore_factory_tables(uint8_t index) { this->model(index).restore_factory_tables(); } diff --git a/components/quatt_odu_simulator/quatt_odu_simulator_model.h b/components/quatt_odu_simulator/quatt_odu_simulator_model.h index 3e05567..a384462 100644 --- a/components/quatt_odu_simulator/quatt_odu_simulator_model.h +++ b/components/quatt_odu_simulator/quatt_odu_simulator_model.h @@ -40,6 +40,8 @@ struct ProtocolDiagnostics { uint16_t last_write_value{0}; uint8_t highest_requested_level{0}; uint32_t last_request_ms{0}; + uint32_t forced_defrost_count{0}; // accepted writes of 3999=4 + uint16_t last_3999_value{0}; // most recent 3999 write value }; struct ModelSettings { @@ -56,6 +58,7 @@ struct ModelSettings { float power_factor{0.92f}; float demand_limiter{1.0f}; float maximum_frequency_hz{120.0f}; + float forced_defrost_duration_s{45.0f}; bool freeze_measured_frequency{false}; bool hold_level_during_defrost{true}; bool experimental_high_frequency_extrapolation{false}; @@ -64,6 +67,7 @@ struct ModelSettings { struct ManualTelemetry { bool enabled{false}; uint16_t working_mode_raw{0U}; + uint16_t compressor_frequency_raw{0U}; uint16_t ac_voltage_raw{0U}; uint16_t ac_current_raw{0U}; uint16_t fan_speed_raw{0U}; @@ -113,9 +117,16 @@ struct OduState { bool force_flow_without_relay{false}; bool force_flow_switch_off{false}; bool force_flow_switch_on{false}; - bool defrost{false}; + bool defrost{false}; // defrost injected via the ODU defrost switch + bool forced_defrost{false}; // defrost latched by a 3999=4 write (independent of the switch) + float forced_defrost_remaining_s{0.0f}; bool high_frequency_performance_synthetic{false}; ManualTelemetry manual_telemetry{}; + uint16_t defrost_mode{0U}; + std::array defrost_base{{45U, 0U, 0U, 0U, 1U, 0U, 27U, 47U, 8U, 30U, 61U}}; + std::array defrost_timing{{5U, 0U, 0U, 0U, 10U, 180U, 5U, 25U, 40U}}; + std::array defrost_coil{{27U, 25U, 18U, 10U, 55U, 1U}}; + std::array defrost_delta{{18U, 19U, 19U, 20U, 21U, 23U, 24U, 15U, 55U, 0U, 0U, 0U, 3U, 3U}}; std::array fault_words{}; std::array cooling_table{}; std::array heating_table{}; @@ -131,6 +142,11 @@ struct OduState { float pump_timer_s{0.0f}; ProtocolDiagnostics protocol{}; std::array actuator_writes{}; + + // Defrost is active when the ODU reports it: either the injection switch is on, + // or a forced (3999=4) request latched an active cycle. The two are independent: + // turning the injection switch off must not cancel a forced cycle. + bool defrost_active() const { return this->defrost || this->forced_defrost; } }; struct PerformancePoint { @@ -236,11 +252,12 @@ class QuattOduSimulatorModel { bool can_write_register(uint16_t address, uint16_t value) const { if (!this->enabled()) return false; + if (address == 3275U) return this->defrost_mode_supported_(value); if (address == 1999U) return true; if (address == 2006U) return value <= 1U; if (address == 2010U) return value == 0U || value == 4096U; if (address == 2015U) return value <= 1000U; - if (address == 3999U) return value <= 2U; + if (address == 3999U) return value <= 2U || value == 4U; if (address >= 3000U && address <= 3021U) return this->state_.table_write_enabled && value <= 120U; if (address >= 3050U && address <= 3069U) return this->state_.profile == Profile::V2_NEW && this->state_.table_write_enabled && value <= 120U; @@ -264,6 +281,10 @@ class QuattOduSimulatorModel { value = this->state_.pump_ipwm; return true; case 2099: + if (this->state_.forced_defrost) { + value = 4U; + return true; + } value = this->manual_or_(this->state_.manual_telemetry.working_mode_raw, static_cast(this->state_.active_mode)); return true; @@ -279,7 +300,8 @@ class QuattOduSimulatorModel { value = encode_unsigned_(this->state_.target_frequency_hz); return true; case 2103: - value = encode_unsigned_(this->state_.measured_frequency_hz); + value = this->manual_or_(this->state_.manual_telemetry.compressor_frequency_raw, + encode_unsigned_(this->state_.measured_frequency_hz)); return true; case 2104: value = encode_unsigned_(this->state_.fan_speed_max_rpm); @@ -325,7 +347,7 @@ class QuattOduSimulatorModel { value = encode_unsigned_(this->state_.condenser_pressure_bar * 10.0f); return true; case 2118: - value = this->state_.defrost ? 1U : 0U; + value = this->state_.defrost_active() ? 1U : 0U; return true; case 2119: value = this->state_.fault_words[0]; @@ -419,6 +441,22 @@ class QuattOduSimulatorModel { value = LEGACY_COOLING_EXTENSION[address - 3060U]; return true; } + if (address >= 3270U && address <= 3280U) { + value = this->state_.defrost_base[address - 3270U]; + return true; + } + if (address >= 3307U && address <= 3315U) { + value = this->state_.defrost_timing[address - 3307U]; + return true; + } + if (address >= 3336U && address <= 3341U) { + value = this->state_.defrost_coil[address - 3336U]; + return true; + } + if (address >= 3414U && address <= 3427U) { + value = this->state_.defrost_delta[address - 3414U]; + return true; + } if (address >= 2999U && address <= 3510U) { value = address == 2999U ? 0x51A1U : 0U; return true; @@ -445,6 +483,11 @@ class QuattOduSimulatorModel { this->state_.protocol.write_count++; this->state_.protocol.last_write_address = address; this->state_.protocol.last_write_value = value; + if (address == 3275U) { + this->state_.defrost_mode = value; + this->state_.defrost_base[5] = value; + return true; + } if (address >= 3000U && address <= 3069U) { uint8_t* target = nullptr; size_t index = 0U; @@ -481,7 +524,7 @@ class QuattOduSimulatorModel { this->state_.protocol.highest_requested_level, static_cast(std::min(value, 255U))); const uint8_t accepted = static_cast(std::min(value, this->maximum_level())); if (value > this->maximum_level()) this->state_.protocol.level_capability_violations++; - if (this->state_.defrost && this->settings_.hold_level_during_defrost) { + if (this->state_.defrost_active() && this->settings_.hold_level_during_defrost) { this->state_.deferred_defrost_level = accepted; this->state_.deferred_defrost_level_pending = true; } else { @@ -503,7 +546,18 @@ class QuattOduSimulatorModel { diagnostics.accepted_raw = value; return true; case 3999: - this->state_.requested_mode = static_cast(value); + this->state_.protocol.last_3999_value = value; + if (value == 4U) { + // A forced request latches an independent defrost cycle; the injection + // switch (set_defrost) must not clear it, and a normal-mode write is + // the only other way out. The cycle self-ends after the modelled duration. + this->state_.forced_defrost = true; + this->state_.forced_defrost_remaining_s = this->settings_.forced_defrost_duration_s; + this->state_.protocol.forced_defrost_count++; + } else { + this->state_.forced_defrost = false; + this->state_.requested_mode = static_cast(value); + } diagnostics.accepted_raw = value; return true; default: @@ -512,17 +566,39 @@ class QuattOduSimulatorModel { } } + // A forced defrost cycle runs for its modelled duration, then releases the + // ODU back to its requested working mode. + void update_forced_defrost_(float dt_s) { + if (!this->state_.forced_defrost) return; + this->state_.forced_defrost_remaining_s -= dt_s; + if (this->state_.forced_defrost_remaining_s > 0.0f) return; + this->state_.forced_defrost = false; + this->state_.forced_defrost_remaining_s = 0.0f; + this->update_deferred_defrost_level_(); + } + + // The compressor level is frozen for the duration of a defrost and restored + // once no defrost (injected or forced) is active any more. + void update_deferred_defrost_level_() { + if (this->state_.defrost_active()) return; + if (!this->state_.deferred_defrost_level_pending) return; + this->state_.accepted_physical_level = this->state_.deferred_defrost_level; + this->state_.deferred_defrost_level = 0U; + this->state_.deferred_defrost_level_pending = false; + } + void set_defrost(bool defrost) { - if (this->state_.defrost && !defrost && this->state_.deferred_defrost_level_pending) { - this->state_.accepted_physical_level = this->state_.deferred_defrost_level; - this->state_.deferred_defrost_level = 0U; - this->state_.deferred_defrost_level_pending = false; - } + // Only the injected switch is controlled here. A forced (3999=4) cycle is + // independent and must survive the switch being cleared. this->state_.defrost = defrost; + this->update_deferred_defrost_level_(); } void set_manual_telemetry_enabled(bool enabled) { this->state_.manual_telemetry.enabled = enabled; } void set_manual_working_mode_raw(uint16_t value) { this->state_.manual_telemetry.working_mode_raw = value; } + void set_manual_compressor_frequency_raw(uint16_t value) { + this->state_.manual_telemetry.compressor_frequency_raw = value; + } void set_manual_ac_voltage_raw(uint16_t value) { this->state_.manual_telemetry.ac_voltage_raw = value; } void set_manual_ac_current_raw(uint16_t value) { this->state_.manual_telemetry.ac_current_raw = value; } void set_manual_fan_speed_raw(uint16_t value) { this->state_.manual_telemetry.fan_speed_raw = value; } @@ -539,6 +615,7 @@ class QuattOduSimulatorModel { void update(float dt_s) { if (!this->enabled() || dt_s <= 0.0f) return; dt_s = std::min(dt_s, 2.0f); + this->update_forced_defrost_(dt_s); this->update_pump_(dt_s); this->update_compressor_(dt_s); this->update_thermodynamics_(dt_s); @@ -570,6 +647,11 @@ class QuattOduSimulatorModel { } private: + bool defrost_mode_supported_(uint16_t mode) const { + if (mode == 0U || mode == 1U || mode == 3U) return true; + return mode == 4U && this->state_.profile != Profile::V1; + } + static uint16_t encode_unsigned_(float value) { return static_cast(std::clamp(lroundf(value), 0L, 65535L)); } @@ -699,7 +781,7 @@ class QuattOduSimulatorModel { const float delta = this->state_.thermal_power_w / ((this->state_.flow_lph / 3600.0f) * 4180.0f); const float sign = this->state_.active_mode == WorkingMode::COOLING ? -1.0f : 1.0f; target_out += sign * delta; - if (this->state_.defrost) target_out -= 4.0f; + if (this->state_.defrost_active()) target_out -= 4.0f; } this->state_.water_out_temperature_c += (target_out - this->state_.water_out_temperature_c) * std::clamp(dt_s / this->settings_.water_response_tau_s, 0.0f, 1.0f); @@ -725,9 +807,9 @@ class QuattOduSimulatorModel { if (this->state_.fan_speed_rpm > 0.0f && this->state_.fan_speed_rpm < 400.0f) status |= 0x0001U; if (this->state_.outside_temperature_c < 2.0f) status |= 0x0004U; if (this->state_.outside_temperature_c < 5.0f) status |= 0x0008U; - if (this->state_.defrost) status |= 0x0010U; + if (this->state_.defrost_active()) status |= 0x0010U; if (this->state_.fan_speed_rpm > 700.0f) status |= 0x0020U; - if (this->state_.active_mode == WorkingMode::COOLING || this->state_.defrost) status |= 0x0040U; + if (this->state_.active_mode == WorkingMode::COOLING || this->state_.defrost_active()) status |= 0x0040U; if (this->state_.pump_request) status |= 0x0800U; return status; } diff --git a/data/odu/registers.yaml b/data/odu/registers.yaml index 7cd1f0f..3f27749 100644 --- a/data/odu/registers.yaml +++ b/data/odu/registers.yaml @@ -56,6 +56,7 @@ registers: - {address: 2137, name: pump_ipwm_feedback, access: read, unit: raw, scale: 1, value_source: state.pump_feedback_raw, persistence: derived, confidence: controller_contract} - {address: 2138, name: water_flow, access: read, unit: L/h, scale: 0.618, value_source: state.flow_lph, persistence: derived, confidence: controller_contract} - {address: 3999, name: requested_working_mode, access: read_write, unit: enum, scale: 1, value_source: state.requested_mode, allowed: [0, 1, 2], persistence: ram, confidence: controller_contract} + - {address: 3275, name: defrost_mode, access: read_write, unit: enum, scale: 1, value_source: state.defrost_mode, profiles: [v1_5, v2_old, v2_new], allowed: [0, 1, 3, 4], persistence: ram, confidence: controller_contract} - {address: 11004, name: extended_metadata_11004, access: read, unit: raw, scale: 1, value_source: 'fixture.extended_metadata[0]', persistence: fixed, confidence: unknown} - {address: 11005, name: extended_metadata_11005, access: read, unit: raw, scale: 1, value_source: 'fixture.extended_metadata[1]', persistence: fixed, confidence: unknown} - {address: 11006, name: extended_metadata_11006, access: read, unit: raw, scale: 1, value_source: 'fixture.extended_metadata[2]', persistence: fixed, confidence: unknown} @@ -66,6 +67,10 @@ registers: - {address: 11161, name: customer_model_word_1, access: read, unit: ASCII, scale: 1, value_source: 'profile.customer_model_words[1]', persistence: fixed, confidence: observed} ranges: + - {start: 3270, end: 3280, name: defrost_base, access: read, unit: raw, scale: 1, profiles: [v1, v1_5, v2_old, v2_new], value_source: fixture.defrost_base, persistence: ram, confidence: synthetic} + - {start: 3307, end: 3315, name: defrost_timing, access: read, unit: raw, scale: 1, profiles: [v1, v1_5, v2_old, v2_new], value_source: fixture.defrost_timing, persistence: ram, confidence: synthetic} + - {start: 3336, end: 3341, name: defrost_coil, access: read, unit: raw, scale: 1, profiles: [v1, v1_5, v2_old, v2_new], value_source: fixture.defrost_coil, persistence: ram, confidence: synthetic} + - {start: 3414, end: 3427, name: defrost_delta, access: read, unit: raw, scale: 1, profiles: [v1_5, v2_old, v2_new], value_source: fixture.defrost_delta, persistence: ram, confidence: synthetic} - {start: 2999, end: 3510, name: eeprom_fixture, access: read, unit: raw, scale: 1, profiles: [v1, v1_5, v2_old, v2_new], value_source: fixture.eeprom, persistence: fixture, confidence: unknown} - {start: 3000, end: 3021, name: base_frequency_table, access: read_write, unit: Hz, scale: 1, profiles: [v1, v1_5, v2_old, v2_new], value_source: state.runtime_frequency_table, allowed: 0..120, persistence: ram_or_explicit_apply, confidence: observed} - {start: 3050, end: 3069, name: v2_frequency_extension, access: read_write, unit: Hz, scale: 1, profiles: [v2_new], value_source: state.runtime_frequency_table, allowed: 0..120, persistence: ram_or_explicit_apply, confidence: controller_contract} diff --git a/docs/quatt-odu-register-contract.md b/docs/quatt-odu-register-contract.md index bf7021a..6c666a7 100644 --- a/docs/quatt-odu-register-contract.md +++ b/docs/quatt-odu-register-contract.md @@ -54,6 +54,7 @@ Modbus addresses below are zero-based. A spreadsheet address is therefore Modbus | 2137 | 2138 | `pump_ipwm_feedback` | read | raw | 1 | controller_contract | no | | 2138 | 2139 | `water_flow` | read | L/h | 0.618 | controller_contract | no | | 3999 | 4000 | `requested_working_mode` | read_write | enum | 1 | controller_contract | no | +| 3275 | 3276 | `defrost_mode` | read_write | enum | 1 | controller_contract | no | | 11004 | 11005 | `extended_metadata_11004` | read | raw | 1 | unknown | no | | 11005 | 11006 | `extended_metadata_11005` | read | raw | 1 | unknown | no | | 11006 | 11007 | `extended_metadata_11006` | read | raw | 1 | unknown | no | @@ -67,6 +68,10 @@ Modbus addresses below are zero-based. A spreadsheet address is therefore Modbus | Modbus | Sheet | Name | Access | Profiles | Confidence | |---|---|---|---|---|---| +| 3270..3280 | 3271..3281 | `defrost_base` | read | v1, v1_5, v2_old, v2_new | synthetic | +| 3307..3315 | 3308..3316 | `defrost_timing` | read | v1, v1_5, v2_old, v2_new | synthetic | +| 3336..3341 | 3337..3342 | `defrost_coil` | read | v1, v1_5, v2_old, v2_new | synthetic | +| 3414..3427 | 3415..3428 | `defrost_delta` | read | v1_5, v2_old, v2_new | synthetic | | 2999..3510 | 3000..3511 | `eeprom_fixture` | read | v1, v1_5, v2_old, v2_new | unknown | | 3000..3021 | 3001..3022 | `base_frequency_table` | read_write | v1, v1_5, v2_old, v2_new | observed | | 3050..3069 | 3051..3070 | `v2_frequency_extension` | read_write | v2_new | controller_contract | diff --git a/hcq_v1_system_simulator.yaml b/hcq_v1_system_simulator.yaml index 7807a3e..02dd7ca 100644 --- a/hcq_v1_system_simulator.yaml +++ b/hcq_v1_system_simulator.yaml @@ -2,7 +2,7 @@ substitutions: device_name: openquatt-simulator friendly_name: OpenQuatt Modbus and OpenTherm Simulator simulator_contract: openquatt-modbus-opentherm-v2 - simulator_version: v0.4.0 + simulator_version: v0.4.1 odu_1_address: "1" odu_2_address: "2" diff --git a/packages/quatt_odu_simulator.yaml b/packages/quatt_odu_simulator.yaml index e2adc48..a123354 100644 --- a/packages/quatt_odu_simulator.yaml +++ b/packages/quatt_odu_simulator.yaml @@ -315,6 +315,30 @@ binary_sensor: lambda: return id(odu_simulator)->model(1).state().table_dirty; number: + # Duration of a forced (3999=4) defrost cycle before the ODU returns to its + # requested working mode. Independent of the ODU defrost injection switch. + - platform: template + id: odu_1_forced_defrost_duration_s + name: "ODU 1 forced defrost duration s" + entity_category: config + optimistic: true + unit_of_measurement: "s" + min_value: 0 + max_value: 600 + step: 1 + initial_value: "45" + + - platform: template + id: odu_2_forced_defrost_duration_s + name: "ODU 2 forced defrost duration s" + entity_category: config + optimistic: true + unit_of_measurement: "s" + min_value: 0 + max_value: 600 + step: 1 + initial_value: "45" + - platform: template id: odu_1_pending_address name: "ODU 1 Modbus address (pending)" @@ -496,6 +520,32 @@ number: step: 1 mode: box + - platform: template + id: odu_1_manual_compressor_frequency + name: "ODU 1 manual compressor frequency 2103" + unit_of_measurement: Hz + entity_category: config + optimistic: true + restore_value: false + initial_value: 0 + min_value: 0 + max_value: 120 + step: 1 + mode: box + + - platform: template + id: odu_2_manual_compressor_frequency + name: "ODU 2 manual compressor frequency 2103" + unit_of_measurement: Hz + entity_category: config + optimistic: true + restore_value: false + initial_value: 0 + min_value: 0 + max_value: 120 + step: 1 + mode: box + - platform: template id: odu_1_manual_ac_voltage name: "ODU 1 manual AC voltage" @@ -944,7 +994,7 @@ text_sensor: lambda: |- const auto &s = id(odu_simulator)->model(0).state(); const uint32_t age = s.protocol.last_request_ms == 0 ? UINT32_MAX : millis() - s.protocol.last_request_ms; - char text[240]; + char text[320]; snprintf(text, sizeof(text), "addr=%u profile=%s mode=%u req=%lu read=%lu write=%lu drop=%lu exc=%lu bad_addr=%lu bad_write=%lu cap=%lu maxF=%u age_ms=%lu last=FC%u R%u/%u W%u=%u", static_cast(id(odu_simulator)->get_address(0)), esphome::quatt_odu_simulator::profile_definition(s.profile).label, @@ -958,10 +1008,16 @@ text_sensor: static_cast(s.protocol.highest_requested_level), static_cast(age), static_cast(s.protocol.last_function_code), static_cast(s.protocol.last_start_address), - static_cast(s.protocol.last_register_count), - static_cast(s.protocol.last_write_address), - static_cast(s.protocol.last_write_value)); - return {text}; + static_cast(s.protocol.last_register_count), + static_cast(s.protocol.last_write_address), + static_cast(s.protocol.last_write_value)); + char extra[64]; + snprintf(extra, sizeof(extra), " w3999=%u fdef=%u fdefcnt=%lu", + static_cast(s.protocol.last_3999_value), + static_cast(s.forced_defrost ? 1 : 0), + static_cast(s.protocol.forced_defrost_count)); + strncat(text, extra, sizeof(text) - strlen(text) - 1); + return {text}; - platform: template name: "ODU 2 diagnostics" entity_category: diagnostic @@ -969,7 +1025,7 @@ text_sensor: lambda: |- const auto &s = id(odu_simulator)->model(1).state(); const uint32_t age = s.protocol.last_request_ms == 0 ? UINT32_MAX : millis() - s.protocol.last_request_ms; - char text[240]; + char text[320]; snprintf(text, sizeof(text), "addr=%u profile=%s mode=%u req=%lu read=%lu write=%lu drop=%lu exc=%lu bad_addr=%lu bad_write=%lu cap=%lu maxF=%u age_ms=%lu last=FC%u R%u/%u W%u=%u", static_cast(id(odu_simulator)->get_address(1)), esphome::quatt_odu_simulator::profile_definition(s.profile).label, @@ -983,10 +1039,16 @@ text_sensor: static_cast(s.protocol.highest_requested_level), static_cast(age), static_cast(s.protocol.last_function_code), static_cast(s.protocol.last_start_address), - static_cast(s.protocol.last_register_count), - static_cast(s.protocol.last_write_address), - static_cast(s.protocol.last_write_value)); - return {text}; + static_cast(s.protocol.last_register_count), + static_cast(s.protocol.last_write_address), + static_cast(s.protocol.last_write_value)); + char extra[64]; + snprintf(extra, sizeof(extra), " w3999=%u fdef=%u fdefcnt=%lu", + static_cast(s.protocol.last_3999_value), + static_cast(s.forced_defrost ? 1 : 0), + static_cast(s.protocol.forced_defrost_count)); + strncat(text, extra, sizeof(text) - strlen(text) - 1); + return {text}; button: - platform: template @@ -1072,7 +1134,10 @@ interval: simulator.set_manual_telemetry_enabled(1, id(odu_2_manual_telemetry_override).state); simulator.set_manual_working_mode(0, lroundf(id(odu_1_manual_working_mode).state)); simulator.set_manual_working_mode(1, lroundf(id(odu_2_manual_working_mode).state)); + simulator.set_manual_compressor_frequency(0, lroundf(id(odu_1_manual_compressor_frequency).state)); + simulator.set_manual_compressor_frequency(1, lroundf(id(odu_2_manual_compressor_frequency).state)); simulator.set_manual_ac_voltage(0, id(odu_1_manual_ac_voltage).state); + simulator.set_manual_ac_voltage(1, id(odu_2_manual_ac_voltage).state); simulator.set_manual_ac_current(0, id(odu_1_manual_ac_current).state); simulator.set_manual_ac_current(1, id(odu_2_manual_ac_current).state); @@ -1100,8 +1165,10 @@ interval: id(odu_external_system_pump_flow).state; simulator.set_freeze_frequency(0, id(odu_1_freeze_frequency).state); simulator.set_freeze_frequency(1, id(odu_2_freeze_frequency).state); - simulator.set_hold_level_during_defrost(0, id(odu_1_hold_level_during_defrost).state); - simulator.set_hold_level_during_defrost(1, id(odu_2_hold_level_during_defrost).state); + simulator.set_hold_level_during_defrost(0, id(odu_1_hold_level_during_defrost).state); + simulator.set_hold_level_during_defrost(1, id(odu_2_hold_level_during_defrost).state); + simulator.set_forced_defrost_duration_s(0, id(odu_1_forced_defrost_duration_s).state); + simulator.set_forced_defrost_duration_s(1, id(odu_2_forced_defrost_duration_s).state); simulator.set_fault_word(0, 0, lroundf(id(odu_1_fault_word_1).state)); simulator.set_fault_word(0, 1, lroundf(id(odu_1_fault_word_2).state)); simulator.set_fault_word(0, 2, lroundf(id(odu_1_fault_word_3).state)); diff --git a/scripts/generate_odu_contract.py b/scripts/generate_odu_contract.py index c7323c5..cb44d35 100644 --- a/scripts/generate_odu_contract.py +++ b/scripts/generate_odu_contract.py @@ -82,7 +82,7 @@ def validate(registers: dict, profiles: dict, performance: dict) -> None: if missing_runtime: raise ValueError(f"runtime registers are not explicit: {missing_runtime}") - writable = {1999, 2006, 2010, 2015, 3999} + writable = {1999, 2006, 2010, 2015, 3275, 3999} for item in registers["registers"]: if "write" in item["access"] and item["address"] not in writable: raise ValueError(f"unexpected writable exact register {item['address']}") diff --git a/tests/quatt_odu_register_contract_test.cpp b/tests/quatt_odu_register_contract_test.cpp index f3761a9..b65ab9d 100644 --- a/tests/quatt_odu_register_contract_test.cpp +++ b/tests/quatt_odu_register_contract_test.cpp @@ -29,12 +29,12 @@ int main() { for (uint16_t address = 11120U; address <= 11139U; address++) assert(covered(address)); for (uint16_t address = 11160U; address <= 11179U; address++) assert(covered(address)); for (uint16_t address = 11219U; address <= 11238U; address++) assert(covered(address)); - for (uint16_t address : {1999U, 2006U, 2010U, 2015U, 3999U}) assert(covered(address)); + for (uint16_t address : {1999U, 2006U, 2010U, 2015U, 3275U, 3999U}) assert(covered(address)); for (const auto& descriptor : REGISTER_DESCRIPTORS) { const bool expected_write = descriptor.address == 1999U || descriptor.address == 2006U || descriptor.address == 2010U || descriptor.address == 2015U || - descriptor.address == 3999U; + descriptor.address == 3275U || descriptor.address == 3999U; assert(access_writable(descriptor.access) == expected_write); } @@ -61,8 +61,15 @@ int main() { assert((v15_runtime->cooling == std::array{0, 26, 28, 30, 32, 34, 36, 38, 40, 71, 74})); assert(runtime_modified_preset(Profile::V2_NEW) == nullptr); - const auto extension = REGISTER_RANGE_DESCRIPTORS[2]; - assert(extension.start == 3050U && extension.end == 3069U); - assert(extension.profile_mask == (1U << static_cast(Profile::V2_NEW))); + const RegisterRangeDescriptor *extension = nullptr; + for (const auto &candidate : REGISTER_RANGE_DESCRIPTORS) { + if (candidate.start == 3050U) { + extension = &candidate; + break; + } + } + assert(extension != nullptr); + assert(extension->start == 3050U && extension->end == 3069U); + assert(extension->profile_mask == (1U << static_cast(Profile::V2_NEW))); return 0; } diff --git a/tests/quatt_odu_simulator_model_test.cpp b/tests/quatt_odu_simulator_model_test.cpp index b074650..b9d489c 100644 --- a/tests/quatt_odu_simulator_model_test.cpp +++ b/tests/quatt_odu_simulator_model_test.cpp @@ -65,6 +65,7 @@ int main() { model.configure(Profile::V2_NEW); model.set_manual_working_mode_raw(2U); + model.set_manual_compressor_frequency_raw(50U); model.set_manual_ac_voltage_raw(230U); model.set_manual_ac_current_raw(13U); model.set_manual_fan_speed_raw(200U); @@ -77,6 +78,7 @@ int main() { model.set_defrost(true); for (int i = 0; i < 8; i++) model.update(0.25f); assert(read(model, 2099U) == 2U); + assert(read(model, 2103U) == 50U); assert(read(model, 2100U) == 230U); assert(read(model, 2101U) == 13U); assert(read(model, 2105U) == 200U); @@ -137,5 +139,55 @@ int main() { assert(!model.state().pump_request); assert(model.state().flow_lph > 750.0f); assert(model.state().flow_switch); + + model.configure(Profile::V1_5); + assert(read(model, 3275U) == 0U); + assert(read(model, 3270U) == 45U); + assert(read(model, 3275U) == 0U); + assert(model.write_register(3275U, 4U, 60U)); + assert(read(model, 3275U) == 4U); + assert(!model.write_register(3275U, 2U, 61U)); + assert(read(model, 3270U) == 45U); + assert(read(model, 3280U) == 61U); + assert(read(model, 3307U) == 5U); + assert(read(model, 3336U) == 27U); + assert(read(model, 3414U) == 18U); + assert(model.write_register(3999U, 4U, 63U)); + assert(read(model, 2099U) == 4U); + assert(read(model, 2118U) == 1U); + // Turning the injection switch off must NOT cancel a forced (3999=4) cycle. + model.set_defrost(false); + assert(read(model, 2099U) == 4U); + assert(read(model, 2118U) == 1U); + // A normal-mode write is the other way out of the forced cycle. + assert(model.write_register(3999U, 2U, 64U)); + assert(read(model, 2099U) != 4U); + assert(read(model, 2118U) == 0U); + model.configure(Profile::V1); + assert(!model.write_register(3275U, 4U, 62U)); + + // A forced defrost cycle self-ends after its modelled duration and returns the + // ODU to its requested working mode, without any switch or normal-mode write. + model.configure(Profile::V1_5); + model.mutable_settings().forced_defrost_duration_s = 5.0f; + model.mutable_settings().compressor_start_delay_s = 0.0f; + model.mutable_settings().minimum_runtime_s = 0.0f; + assert(model.write_register(1999U, 20U, 100U)); + assert(model.write_register(3999U, 2U, 101U)); // request heating + model.update(0.5f); + const uint16_t settled_mode = read(model, 2099U); + assert(settled_mode == 2U); + assert(model.write_register(3999U, 4U, 110U)); // force defrost + assert(read(model, 2099U) == 4U); + assert(read(model, 2118U) == 1U); + model.update(2.0f); + assert(read(model, 2099U) == 4U); // still inside the cycle + assert(read(model, 2118U) == 1U); + model.update(2.0f); + assert(read(model, 2099U) == 4U); // still inside the cycle + assert(read(model, 2118U) == 1U); + model.update(2.0f); // crosses the 5 s boundary + assert(read(model, 2118U) == 0U); // defrost bit cleared + assert(read(model, 2099U) == settled_mode); // back to heating on its own return 0; }