Hoymiles: Introduce init method to have a clean init on beginning

Constructor is not possible for obvious reasons
This commit is contained in:
Thomas Basler 2022-07-18 21:30:12 +02:00
parent db0e0c67ce
commit dcc7e47b19
3 changed files with 11 additions and 6 deletions

View File

@ -56,6 +56,7 @@ std::shared_ptr<InverterAbstract> HoymilesClass::addInverter(const char* name, u
if (i) { if (i) {
i->setName(name); i->setName(name);
i->init();
_inverters.push_back(std::move(i)); _inverters.push_back(std::move(i));
return _inverters.back(); return _inverters.back();
} }

View File

@ -9,6 +9,15 @@ InverterAbstract::InverterAbstract(uint64_t serial)
_statisticsParser.reset(new StatisticsParser()); _statisticsParser.reset(new StatisticsParser());
} }
void InverterAbstract::init()
{
// This has to be done here because:
// Not possible in constructor --> virtual function
// Not possible in verifyAllFragments --> Because no data if nothing is ever received
// It has to be executed because otherwise the getChannelCount method in stats always returns 0
_statisticsParser.get()->setByteAssignment(getByteAssignment(), getAssignmentCount());
}
uint64_t InverterAbstract::serial() uint64_t InverterAbstract::serial()
{ {
return _serial.u64; return _serial.u64;
@ -45,12 +54,6 @@ void InverterAbstract::clearRxFragmentBuffer()
_rxFragmentMaxPacketId = 0; _rxFragmentMaxPacketId = 0;
_rxFragmentLastPacketId = 0; _rxFragmentLastPacketId = 0;
_rxFragmentRetransmitCnt = 0; _rxFragmentRetransmitCnt = 0;
// This has to be done here because:
// Not possible in constructor --> virtual function
// Not possible in verifyAllFragments --> Because no data if nothing is ever received
// It has to be executed because otherwise the getChannelCount method in stats always returns 0
_statisticsParser.get()->setByteAssignment(getByteAssignment(), getAssignmentCount());
} }
void InverterAbstract::addRxFragment(uint8_t fragment[], uint8_t len) void InverterAbstract::addRxFragment(uint8_t fragment[], uint8_t len)

View File

@ -22,6 +22,7 @@ enum {
class InverterAbstract { class InverterAbstract {
public: public:
InverterAbstract(uint64_t serial); InverterAbstract(uint64_t serial);
void init();
uint64_t serial(); uint64_t serial();
void setName(const char* name); void setName(const char* name);
const char* name(); const char* name();