Feature: SML power meters: reset SML decoder
implement a function which allows to reset the SML decoder. this new function is used after a datagram ends. for the SML HTTP power meter this is simple: after all bytes from the request's answer have been decoded, we reset the decoder. for the SML serial power meter, we perform the reset after a datagram ended based on timing (no new bytes have been received for a specific amount of time).
This commit is contained in:
parent
ea454972b9
commit
6b09ca056e
@ -20,6 +20,7 @@ protected:
|
||||
explicit PowerMeterSml(char const* user)
|
||||
: _user(user) { }
|
||||
|
||||
void reset();
|
||||
void processSmlByte(uint8_t byte);
|
||||
|
||||
private:
|
||||
|
||||
@ -189,6 +189,12 @@ void checkMagicByte(unsigned char &byte)
|
||||
}
|
||||
}
|
||||
|
||||
void smlReset(void)
|
||||
{
|
||||
len = 4; // expect start sequence
|
||||
currentState = SML_START;
|
||||
}
|
||||
|
||||
sml_states_t smlState(unsigned char currentByte)
|
||||
{
|
||||
unsigned char size;
|
||||
|
||||
@ -92,6 +92,7 @@ typedef enum {
|
||||
SML_COUNT = 255
|
||||
} sml_units_t;
|
||||
|
||||
void smlReset(void);
|
||||
sml_states_t smlState(unsigned char byte);
|
||||
bool smlOBISCheck(const unsigned char *obis);
|
||||
void smlOBISManufacturer(unsigned char *str, int maxSize);
|
||||
|
||||
@ -107,5 +107,7 @@ String PowerMeterHttpSml::poll()
|
||||
processSmlByte(pStream->read());
|
||||
}
|
||||
|
||||
PowerMeterSml::reset();
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -110,6 +110,8 @@ void PowerMeterSerialSml::pollingLoop()
|
||||
|
||||
lastAvailable = 0;
|
||||
|
||||
PowerMeterSml::reset();
|
||||
|
||||
lock.lock();
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,6 +30,12 @@ void PowerMeterSml::doMqttPublish() const
|
||||
#undef PUB
|
||||
}
|
||||
|
||||
void PowerMeterSml::reset()
|
||||
{
|
||||
smlReset();
|
||||
_cache = { std::nullopt };
|
||||
}
|
||||
|
||||
void PowerMeterSml::processSmlByte(uint8_t byte)
|
||||
{
|
||||
switch (smlState(byte)) {
|
||||
@ -52,12 +58,12 @@ void PowerMeterSml::processSmlByte(uint8_t byte)
|
||||
case SML_FINAL:
|
||||
gotUpdate();
|
||||
_values = _cache;
|
||||
_cache = { std::nullopt };
|
||||
reset();
|
||||
MessageOutput.printf("[%s] TotalPower: %5.2f\r\n",
|
||||
_user.c_str(), getPowerTotal());
|
||||
break;
|
||||
case SML_CHECKSUM_ERROR:
|
||||
_cache = { std::nullopt };
|
||||
reset();
|
||||
MessageOutput.printf("[%s] checksum verification failed\r\n",
|
||||
_user.c_str());
|
||||
break;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user