Skip to content

Commit

Permalink
GenericPowermeter: log lost and restored communication
Browse files Browse the repository at this point in the history
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 <michael.heimpold@chargebyte.com>
  • Loading branch information
mhei committed Jun 18, 2024
1 parent 51a91e7 commit c1246a6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions modules/GenericPowermeter/main/powermeterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions modules/GenericPowermeter/main/powermeterImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Check notice on line 112 in modules/GenericPowermeter/main/powermeterImpl.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

modules/GenericPowermeter/main/powermeterImpl.hpp#L112

class member 'powermeterImpl::meter_is_unavailable' is never used.

void init_default_values();
void init_register_assignments(const json& loaded_registers);
int assign_register_data(const json& registers, const PowermeterRegisters register_type,
Expand Down

0 comments on commit c1246a6

Please sign in to comment.