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)
|
explicit PowerMeterSml(char const* user)
|
||||||
: _user(user) { }
|
: _user(user) { }
|
||||||
|
|
||||||
|
void reset();
|
||||||
void processSmlByte(uint8_t byte);
|
void processSmlByte(uint8_t byte);
|
||||||
|
|
||||||
private:
|
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)
|
sml_states_t smlState(unsigned char currentByte)
|
||||||
{
|
{
|
||||||
unsigned char size;
|
unsigned char size;
|
||||||
|
|||||||
@ -92,6 +92,7 @@ typedef enum {
|
|||||||
SML_COUNT = 255
|
SML_COUNT = 255
|
||||||
} sml_units_t;
|
} sml_units_t;
|
||||||
|
|
||||||
|
void smlReset(void);
|
||||||
sml_states_t smlState(unsigned char byte);
|
sml_states_t smlState(unsigned char byte);
|
||||||
bool smlOBISCheck(const unsigned char *obis);
|
bool smlOBISCheck(const unsigned char *obis);
|
||||||
void smlOBISManufacturer(unsigned char *str, int maxSize);
|
void smlOBISManufacturer(unsigned char *str, int maxSize);
|
||||||
|
|||||||
@ -107,5 +107,7 @@ String PowerMeterHttpSml::poll()
|
|||||||
processSmlByte(pStream->read());
|
processSmlByte(pStream->read());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PowerMeterSml::reset();
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,6 +110,8 @@ void PowerMeterSerialSml::pollingLoop()
|
|||||||
|
|
||||||
lastAvailable = 0;
|
lastAvailable = 0;
|
||||||
|
|
||||||
|
PowerMeterSml::reset();
|
||||||
|
|
||||||
lock.lock();
|
lock.lock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,12 @@ void PowerMeterSml::doMqttPublish() const
|
|||||||
#undef PUB
|
#undef PUB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PowerMeterSml::reset()
|
||||||
|
{
|
||||||
|
smlReset();
|
||||||
|
_cache = { std::nullopt };
|
||||||
|
}
|
||||||
|
|
||||||
void PowerMeterSml::processSmlByte(uint8_t byte)
|
void PowerMeterSml::processSmlByte(uint8_t byte)
|
||||||
{
|
{
|
||||||
switch (smlState(byte)) {
|
switch (smlState(byte)) {
|
||||||
@ -52,12 +58,12 @@ void PowerMeterSml::processSmlByte(uint8_t byte)
|
|||||||
case SML_FINAL:
|
case SML_FINAL:
|
||||||
gotUpdate();
|
gotUpdate();
|
||||||
_values = _cache;
|
_values = _cache;
|
||||||
_cache = { std::nullopt };
|
reset();
|
||||||
MessageOutput.printf("[%s] TotalPower: %5.2f\r\n",
|
MessageOutput.printf("[%s] TotalPower: %5.2f\r\n",
|
||||||
_user.c_str(), getPowerTotal());
|
_user.c_str(), getPowerTotal());
|
||||||
break;
|
break;
|
||||||
case SML_CHECKSUM_ERROR:
|
case SML_CHECKSUM_ERROR:
|
||||||
_cache = { std::nullopt };
|
reset();
|
||||||
MessageOutput.printf("[%s] checksum verification failed\r\n",
|
MessageOutput.printf("[%s] checksum verification failed\r\n",
|
||||||
_user.c_str());
|
_user.c_str());
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user