From e8b65fdcfec5695597dd9a33aaa024ba5534cc8c Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 12 Feb 2023 10:15:02 +0100 Subject: [PATCH] Speed up communication by sending smaller frames. --- .gitignore | 2 ++ components/truma_inetbox/TrumaStatusFrame.cpp | 24 ++++++++++++------- components/truma_inetbox/TrumaStatusFrame.h | 18 +++++++------- components/truma_inetbox/TrumaiNetBoxApp.cpp | 18 +++++--------- components/truma_inetbox/TrumaiNetBoxApp.h | 2 +- 5 files changed, 33 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 8d6e68a..3a0c33c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /secrets.yaml **/__pycache__/** + +/local_* \ No newline at end of file diff --git a/components/truma_inetbox/TrumaStatusFrame.cpp b/components/truma_inetbox/TrumaStatusFrame.cpp index 5e6397d..567326d 100644 --- a/components/truma_inetbox/TrumaStatusFrame.cpp +++ b/components/truma_inetbox/TrumaStatusFrame.cpp @@ -24,14 +24,17 @@ void status_frame_calculate_checksum(StatusFrame *response) { response->inner.genericHeader.checksum = data_checksum(&response->raw[10], sizeof(StatusFrame) - 10, 0); } -void status_frame_create_init(StatusFrame *response, u_int8_t command_counter) { +void status_frame_create_init(StatusFrame *response, u_int8_t *response_len, u_int8_t command_counter) { status_frame_create_empty(response, STATUS_FRAME_RESPONSE_INIT_REQUEST, 0, command_counter); + // Init frame is empty. + status_frame_calculate_checksum(response); + (*response_len) = sizeof(StatusFrameHeader) + 0; } -void status_frame_create_update_clock(StatusFrame *response, u_int8_t command_counter, u_int8_t hour, u_int8_t minute, - u_int8_t second, ClockMode clockMode) { +void status_frame_create_update_clock(StatusFrame *response, u_int8_t *response_len, u_int8_t command_counter, + u_int8_t hour, u_int8_t minute, u_int8_t second, ClockMode clockMode) { status_frame_create_empty(response, STATUS_FRAME_CLOCK_RESPONSE, sizeof(StatusFrameClock), command_counter); response->inner.clock.clock_hour = hour; @@ -42,12 +45,13 @@ void status_frame_create_update_clock(StatusFrame *response, u_int8_t command_co response->inner.clock.clock_mode = clockMode; status_frame_calculate_checksum(response); + (*response_len) = sizeof(StatusFrameHeader) + sizeof(StatusFrameClock); } -void status_frame_create_update_timer(StatusFrame *response, u_int8_t command_counter, TimerActive active, - u_int8_t start_hour, u_int8_t start_minute, u_int8_t stop_hour, - u_int8_t stop_minute, TargetTemp room, TargetTemp water, HeatingMode mode, - EnergyMix energy, ElectricPowerLevel elPower) { +void status_frame_create_update_timer(StatusFrame *response, u_int8_t *response_len, u_int8_t command_counter, + TimerActive active, u_int8_t start_hour, u_int8_t start_minute, + u_int8_t stop_hour, u_int8_t stop_minute, TargetTemp room, TargetTemp water, + HeatingMode mode, EnergyMix energy, ElectricPowerLevel elPower) { status_frame_create_empty(response, STATUS_FRAME_TIMER_RESPONSE, sizeof(StatusFrameTimerResponse), command_counter); response->inner.timerResponse.timer_target_temp_room = room; @@ -64,10 +68,11 @@ void status_frame_create_update_timer(StatusFrame *response, u_int8_t command_co response->inner.timerResponse.timer_resp_stop_minutes = stop_minute; status_frame_calculate_checksum(response); + (*response_len) = sizeof(StatusFrameHeader) + sizeof(StatusFrameTimerResponse); } -void status_frame_create_update_heater(StatusFrame *response, u_int8_t command_counter, TargetTemp room, - TargetTemp water, HeatingMode mode, EnergyMix energy, +void status_frame_create_update_heater(StatusFrame *response, u_int8_t *response_len, u_int8_t command_counter, + TargetTemp room, TargetTemp water, HeatingMode mode, EnergyMix energy, ElectricPowerLevel elPower) { status_frame_create_empty(response, STATUS_FRAME_HEATER_RESPONSE, sizeof(StatusFrameHeaterResponse), command_counter); @@ -80,6 +85,7 @@ void status_frame_create_update_heater(StatusFrame *response, u_int8_t command_c response->inner.heaterResponse.el_power_level_b = elPower; status_frame_calculate_checksum(response); + (*response_len) = sizeof(StatusFrameHeader) + sizeof(StatusFrameHeaterResponse); } } // namespace truma_inetbox diff --git a/components/truma_inetbox/TrumaStatusFrame.h b/components/truma_inetbox/TrumaStatusFrame.h index 45873c8..b6f0c1d 100644 --- a/components/truma_inetbox/TrumaStatusFrame.h +++ b/components/truma_inetbox/TrumaStatusFrame.h @@ -10,18 +10,18 @@ void status_frame_create_empty(StatusFrame *response, u_int8_t message_type, u_i void status_frame_calculate_checksum(StatusFrame *response); -void status_frame_create_init(StatusFrame *response, u_int8_t command_counter); +void status_frame_create_init(StatusFrame *response, u_int8_t *response_len, u_int8_t command_counter); -void status_frame_create_update_clock(StatusFrame *response, u_int8_t command_counter, u_int8_t hour, u_int8_t minute, - u_int8_t second, ClockMode clockMode); +void status_frame_create_update_clock(StatusFrame *response, u_int8_t *response_len, u_int8_t command_counter, + u_int8_t hour, u_int8_t minute, u_int8_t second, ClockMode clockMode); -void status_frame_create_update_timer(StatusFrame *response, u_int8_t command_counter, TimerActive active, - u_int8_t start_hour, u_int8_t start_minute, u_int8_t stop_hour, - u_int8_t stop_minute, TargetTemp room, TargetTemp water, HeatingMode mode, - EnergyMix energy, ElectricPowerLevel elPower); +void status_frame_create_update_timer(StatusFrame *response, u_int8_t *response_len, u_int8_t command_counter, + TimerActive active, u_int8_t start_hour, u_int8_t start_minute, + u_int8_t stop_hour, u_int8_t stop_minute, TargetTemp room, TargetTemp water, + HeatingMode mode, EnergyMix energy, ElectricPowerLevel elPower); -void status_frame_create_update_heater(StatusFrame *response, u_int8_t command_counter, TargetTemp room, - TargetTemp water, HeatingMode mode, EnergyMix energy, +void status_frame_create_update_heater(StatusFrame *response, u_int8_t *response_len, u_int8_t command_counter, + TargetTemp room, TargetTemp water, HeatingMode mode, EnergyMix energy, ElectricPowerLevel elPower); } // namespace truma_inetbox diff --git a/components/truma_inetbox/TrumaiNetBoxApp.cpp b/components/truma_inetbox/TrumaiNetBoxApp.cpp index 9480f85..da46505 100644 --- a/components/truma_inetbox/TrumaiNetBoxApp.cpp +++ b/components/truma_inetbox/TrumaiNetBoxApp.cpp @@ -47,6 +47,7 @@ void TrumaiNetBoxApp::update() { } const std::array TrumaiNetBoxApp::lin_identifier() { + // Supplier Id: 0x4617 - Truma (Phone: +49 (0)89 4617-0) // Unkown: // 17.46.01.03 - Unkown more comms required for init. // 17.46.10.03 - Unkown more comms required for init. @@ -235,14 +236,12 @@ const u_int8_t *TrumaiNetBoxApp::lin_multiframe_recieved(const u_int8_t *message // The order must match with the method 'has_update_to_submit_'. if (this->init_recieved_ == 0) { - status_frame_create_init(response_frame, this->message_counter++); - // TODO: can I create a shorter (quicker) messsage here? - (*return_len) = sizeof(StatusFrame); + status_frame_create_init(response_frame, return_len, this->message_counter++); return response; } if (this->update_status_heater_unsubmitted_) { status_frame_create_update_heater( - response_frame, this->message_counter++, this->update_status_heater_.target_temp_room, + response_frame, return_len, this->message_counter++, this->update_status_heater_.target_temp_room, this->update_status_heater_.target_temp_water, this->update_status_heater_.heating_mode, this->update_status_heater_.energy_mix_a, this->update_status_heater_.el_power_level_a); @@ -250,14 +249,11 @@ const u_int8_t *TrumaiNetBoxApp::lin_multiframe_recieved(const u_int8_t *message this->update_status_heater_prepared_ = false; this->update_status_heater_unsubmitted_ = false; this->update_status_heater_stale_ = true; - // Remove last 12 bytes (2 Frames), because they are always 0. - // This cannot be done on the first message, but later messages it is fine. - (*return_len) = sizeof(StatusFrame); return response; } if (this->update_status_timer_unsubmitted_) { status_frame_create_update_timer( - response_frame, this->message_counter++, this->update_status_timer_.timer_resp_active, + response_frame, return_len, this->message_counter++, this->update_status_timer_.timer_resp_active, this->update_status_timer_.timer_resp_start_hours, this->update_status_timer_.timer_resp_start_minutes, this->update_status_timer_.timer_resp_stop_hours, this->update_status_timer_.timer_resp_stop_minutes, this->update_status_timer_.timer_target_temp_room, this->update_status_timer_.timer_target_temp_water, @@ -268,18 +264,16 @@ const u_int8_t *TrumaiNetBoxApp::lin_multiframe_recieved(const u_int8_t *message this->update_status_timer_prepared_ = false; this->update_status_timer_unsubmitted_ = false; this->update_status_timer_stale_ = true; - (*return_len) = sizeof(StatusFrame); return response; } if (this->update_status_clock_unsubmitted_) { // read time live auto now = this->time_->now(); - status_frame_create_update_clock(response_frame, this->message_counter++, now.hour, now.minute, now.second, - this->status_clock_.clock_mode); + status_frame_create_update_clock(response_frame, return_len, this->message_counter++, now.hour, now.minute, + now.second, this->status_clock_.clock_mode); this->update_status_clock_unsubmitted_ = false; - (*return_len) = sizeof(StatusFrame); return response; } } diff --git a/components/truma_inetbox/TrumaiNetBoxApp.h b/components/truma_inetbox/TrumaiNetBoxApp.h index e3a2735..030d53b 100644 --- a/components/truma_inetbox/TrumaiNetBoxApp.h +++ b/components/truma_inetbox/TrumaiNetBoxApp.h @@ -103,7 +103,7 @@ enum class OperatingStatus : u_int8_t { OPERATING_STATUS_OFF = 0x0, OPERATING_STATUS_WARNING = 0x1, OPERATING_STATUS_START_OR_COOL_DOWN = 0x4, - // ON - Heater off + // ? Gas Heating mode ? OPERATING_STATUS_ON_5 = 0x5, OPERATING_STATUS_ON_6 = 0x6, OPERATING_STATUS_ON_7 = 0x7,