Skip to content

Commit

Permalink
meters-rct-power: Don't log checksum error, use error counter instead
Browse files Browse the repository at this point in the history
  • Loading branch information
photron committed Oct 29, 2024
1 parent dcb1b33 commit 900d6b9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
17 changes: 10 additions & 7 deletions software/src/modules/meters_rct_power/meter_rct_power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include "tools.h"

#if 0
#define debugfln(...) logger.printfln(__VA_ARGS__)
#define debugfln(fmt, ...) logger.printfln(fmt __VA_OPT__(,) __VA_ARGS__)
#else
#define debugfln(...) do {} while (0)
#define debugfln(fmt, ...) do {} while (0)
#endif

static const MeterValueID grid_value_ids[] = {
Expand Down Expand Up @@ -281,10 +281,13 @@ bool RCTPowerClient::receive_hook()
if (actual_checksum != expected_checksum) {
for (size_t i = 0; i < value_specs_length; ++i) {
if (value_specs[i].id == id) {
logger.printfln("Received response [%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x] for ID 0x%08x with checksum mismatch (actual=0x%04x expected=0x%04x), ignoring response",
pending_response[0], pending_response[1], pending_response[2], pending_response[3], pending_response[4], pending_response[5],
pending_response[6], pending_response[7], pending_response[8], pending_response[9], pending_response[10], pending_response[11],
id, actual_checksum, expected_checksum);
debugfln("Received response [%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x] for ID 0x%08x with checksum mismatch (actual=0x%04x expected=0x%04x), ignoring response",
pending_response[0], pending_response[1], pending_response[2], pending_response[3], pending_response[4], pending_response[5],
pending_response[6], pending_response[7], pending_response[8], pending_response[9], pending_response[10], pending_response[11],
id, actual_checksum, expected_checksum);

auto checksum_mismatch = errors->get("checksum_mismatch");
checksum_mismatch->updateUint(checksum_mismatch->asUint() + 1);
break;
}
}
Expand Down Expand Up @@ -313,7 +316,7 @@ bool RCTPowerClient::receive_hook()
value *= value_specs[i].scale_factor;
}

debugfln("Received response for ID 0x%08x with value %f", id, u.value, value);
debugfln("Received response for ID 0x%08x with value %f [%f]", id, u.value, value);

meters.update_value(slot, i, value);
meters.finish_update(slot);
Expand Down
6 changes: 4 additions & 2 deletions software/src/modules/meters_rct_power/meter_rct_power.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct RCTValueSpec
class RCTPowerClient final : public TFGenericTCPClient
{
public:
RCTPowerClient(uint32_t slot_) : slot(slot_) {}
RCTPowerClient(uint32_t slot_, Config *state_, Config *errors_) : slot(slot_), state(state_), errors(errors_) {}

void setup(const Config &ephemeral_config);
void read_next_value();
Expand All @@ -47,6 +47,8 @@ class RCTPowerClient final : public TFGenericTCPClient
bool receive_hook() override;

uint32_t slot;
Config *state;
Config *errors;
VirtualMeter virtual_meter = VirtualMeter::None;
const RCTValueSpec *value_specs = nullptr;
size_t value_specs_length = 0;
Expand All @@ -62,7 +64,7 @@ class RCTPowerClient final : public TFGenericTCPClient
class MeterRCTPower final : protected GenericTCPClientConnector, public IMeter
{
public:
MeterRCTPower(uint32_t slot) : GenericTCPClientConnector("meter_rct_power", &client, &shared_client), client(slot), shared_client(&client) {}
MeterRCTPower(uint32_t slot, Config *state, Config *errors) : GenericTCPClientConnector("meter_rct_power", &client, &shared_client), client(slot, state, errors), shared_client(&client) {}

[[gnu::const]] MeterClassID get_class() const override;
void setup(const Config &ephemeral_config) override;
Expand Down
10 changes: 7 additions & 3 deletions software/src/modules/meters_rct_power/meters_rct_power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ void MetersRCTPower::pre_setup()
{"virtual_meter", Config::Uint8(static_cast<uint8_t>(VirtualMeter::None))},
});

errors_prototype = Config::Object({
{"checksum_mismatch", Config::Uint32(0)},
});

meters.register_meter_generator(get_class(), this);
}

Expand All @@ -42,9 +46,9 @@ MeterClassID MetersRCTPower::get_class() const
return MeterClassID::RCTPower;
}

IMeter *MetersRCTPower::new_meter(uint32_t slot, Config * /*state*/, Config * /*errors*/)
IMeter *MetersRCTPower::new_meter(uint32_t slot, Config *state, Config *errors)
{
return new MeterRCTPower(slot);
return new MeterRCTPower(slot, state, errors);
}

const Config *MetersRCTPower::get_config_prototype()
Expand All @@ -59,5 +63,5 @@ const Config *MetersRCTPower::get_state_prototype()

const Config *MetersRCTPower::get_errors_prototype()
{
return Config::Null();
return &errors_prototype;
}
3 changes: 2 additions & 1 deletion software/src/modules/meters_rct_power/meters_rct_power.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class MetersRCTPower final : public IModule, public MeterGenerator
[[gnu::const]] virtual const Config *get_errors_prototype() override;

private:
ConfigRoot config_prototype;
Config config_prototype;
Config errors_prototype;
};

#if defined(__GNUC__)
Expand Down

0 comments on commit 900d6b9

Please sign in to comment.