From c1246a6f8c6d3c7467eba40d400128ec19aef546 Mon Sep 17 00:00:00 2001 From: Michael Heimpold Date: Mon, 17 Jun 2024 12:16:59 +0200 Subject: [PATCH] GenericPowermeter: log lost and restored communication This introduces a high-level/device specific logging in case communication with power meter is failing or communication is restored again. Signed-off-by: Michael Heimpold --- modules/GenericPowermeter/main/powermeterImpl.cpp | 13 +++++++++++++ modules/GenericPowermeter/main/powermeterImpl.hpp | 3 +++ 2 files changed, 16 insertions(+) diff --git a/modules/GenericPowermeter/main/powermeterImpl.cpp b/modules/GenericPowermeter/main/powermeterImpl.cpp index a821d2775..ca96d468d 100644 --- a/modules/GenericPowermeter/main/powermeterImpl.cpp +++ b/modules/GenericPowermeter/main/powermeterImpl.cpp @@ -376,6 +376,12 @@ void powermeterImpl::process_response(const RegisterData& register_data, const types::serial_comm_hub_requests::Result exponent_message) { if (register_message.status_code == types::serial_comm_hub_requests::StatusCodeEnum::Success) { + // in case the meter was unavailable before and now the query succeeded, + // we can tell the user about this good news and reset our flag + if (meter_is_unavailable) { + EVLOG_info << "Communication with power meter restored."; + meter_is_unavailable = false; + } int16_t exponent{0}; if (exponent_message.value.has_value()) { @@ -497,6 +503,13 @@ void powermeterImpl::process_response(const RegisterData& register_data, } else { // error: message sending failed output_error_with_content(register_message); + + // let's warn the user about the meter's unavailability once only + // (since we keep trying communicating an 'error' is not justified) + if (!meter_is_unavailable) { + EVLOG_warning << "Lost communication with power meter."; + meter_is_unavailable = true; + } } } diff --git a/modules/GenericPowermeter/main/powermeterImpl.hpp b/modules/GenericPowermeter/main/powermeterImpl.hpp index c22a7cd1f..ced77b5f2 100644 --- a/modules/GenericPowermeter/main/powermeterImpl.hpp +++ b/modules/GenericPowermeter/main/powermeterImpl.hpp @@ -108,6 +108,9 @@ class powermeterImpl : public powermeterImplBase { std::thread output_thread; + /// @brief Remember whether we already logged the meter's unavailability. + bool meter_is_unavailable{false}; + void init_default_values(); void init_register_assignments(const json& loaded_registers); int assign_register_data(const json& registers, const PowermeterRegisters register_type,