SML power meter: improve message output

* when printing a message, tell the name of the derived class.
* print total power only when state SML_FINAL reached.
* tell if a checksum verification error occurred.
This commit is contained in:
Bernhard Kirchen 2024-06-14 20:50:43 +02:00
parent 6c06e71fd0
commit fb7b710cb7
5 changed files with 19 additions and 4 deletions

View File

@ -14,7 +14,8 @@
class PowerMeterHttpSml : public PowerMeterSml {
public:
explicit PowerMeterHttpSml(PowerMeterHttpSmlConfig const& cfg)
: _cfg(cfg) { }
: PowerMeterSml("PowerMeterHttpSml")
, _cfg(cfg) { }
~PowerMeterHttpSml();

View File

@ -6,6 +6,9 @@
class PowerMeterSerialSml : public PowerMeterSml {
public:
PowerMeterSerialSml()
: PowerMeterSml("PowerMeterSerialSml") { }
~PowerMeterSerialSml();
bool init() final;

View File

@ -16,9 +16,13 @@ public:
void doMqttPublish() const final;
protected:
explicit PowerMeterSml(char const* user)
: _user(user) { }
void processSmlByte(uint8_t byte);
private:
std::string _user;
mutable std::mutex _mutex;
float _activePowerTotal = 0.0;

View File

@ -39,5 +39,4 @@ void PowerMeterSerialSml::loop()
processSmlByte(_upSmlSerial->read());
}
MessageOutput.printf("[PowerMeterSerialSml]: TotalPower: %5.2f\r\n", getPowerTotal());
}

View File

@ -37,11 +37,19 @@ void PowerMeterSml::processSmlByte(uint8_t byte)
handler.decoder(*handler.target);
if (_verboseLogging) {
MessageOutput.printf("[PowerMeterSml] decoded %s to %.2f\r\n",
handler.name, *handler.target);
MessageOutput.printf("[%s] decoded %s to %.2f\r\n",
_user.c_str(), handler.name, *handler.target);
}
}
break;
case SML_FINAL:
MessageOutput.printf("[%s] TotalPower: %5.2f\r\n",
_user.c_str(), getPowerTotal());
break;
case SML_CHECKSUM_ERROR:
MessageOutput.printf("[%s] checksum verification failed\r\n",
_user.c_str());
break;
default:
break;
}