Skip to content

Commit

Permalink
JK BMS: updateFrom: skip data points with equal value
Browse files Browse the repository at this point in the history
this changes the interpretation of the timestamp in data containers that
are merely updated from other data containers: this is the oldest
timestamp known where the value was as recorded by the data point in its
respective container.

the data container constructed from an answer will -- naturally -- have
the timetamps of its data points set to the time they were constructed.
  • Loading branch information
schlimmchen committed Sep 10, 2023
1 parent b086bfa commit e697a89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/JkBmsDataPoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ class DataPoint {
std::string const& getUnitText() const { return _strUnit; }
uint32_t getTimestamp() const { return _timestamp; }

bool operator==(DataPoint const& other) const {
return _value == other._value;
}

private:
std::string _strLabel;
std::string _strValue;
Expand Down
9 changes: 8 additions & 1 deletion src/JkBmsDataPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ std::string dataPointValueToStr(tCells const& v) {
void DataPointContainer::updateFrom(DataPointContainer const& source)
{
for (auto iter = source.cbegin(); iter != source.cend(); ++iter) {
_dataPoints.erase(iter->first);
auto pos = _dataPoints.find(iter->first);

if (pos != _dataPoints.end()) {
// do not update existing data points with the same value
if (pos->second == iter->second) { continue; }

_dataPoints.erase(pos);
}
_dataPoints.insert(*iter);
}
}
Expand Down

0 comments on commit e697a89

Please sign in to comment.