avoid too frequent SmartShunt data copies (#596)
currently the whole SmartShunt data structure is copied to the BatteryStats instance in every loop, even though the data cannot possibly have changed. this is quite an expensive task to do in every loop. this change tracks the last update timestamp and only does the copy operation if an actual updated data structure was received from the smart shunt.
This commit is contained in:
parent
2806b6db86
commit
a012d81427
@ -11,6 +11,7 @@ public:
|
|||||||
std::shared_ptr<BatteryStats> getStats() const final { return _stats; }
|
std::shared_ptr<BatteryStats> getStats() const final { return _stats; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
uint32_t _lastUpdate = 0;
|
||||||
std::shared_ptr<VictronSmartShuntStats> _stats =
|
std::shared_ptr<VictronSmartShuntStats> _stats =
|
||||||
std::make_shared<VictronSmartShuntStats>();
|
std::make_shared<VictronSmartShuntStats>();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -28,5 +28,9 @@ bool VictronSmartShunt::init(bool verboseLogging)
|
|||||||
void VictronSmartShunt::loop()
|
void VictronSmartShunt::loop()
|
||||||
{
|
{
|
||||||
VeDirectShunt.loop();
|
VeDirectShunt.loop();
|
||||||
|
|
||||||
|
if (VeDirectShunt.getLastUpdate() <= _lastUpdate) { return; }
|
||||||
|
|
||||||
_stats->updateFrom(VeDirectShunt.veFrame);
|
_stats->updateFrom(VeDirectShunt.veFrame);
|
||||||
|
_lastUpdate = VeDirectShunt.getLastUpdate();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user