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:
Bernhard Kirchen 2024-01-07 18:30:02 +01:00 committed by GitHub
parent 2806b6db86
commit a012d81427
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -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>();
}; };

View File

@ -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();
} }