diff --git a/include/BatteryStats.h b/include/BatteryStats.h index 9f5e533d3..cfce8ea88 100644 --- a/include/BatteryStats.h +++ b/include/BatteryStats.h @@ -6,6 +6,7 @@ #include "AsyncJson.h" #include "Arduino.h" #include "JkBmsDataPoints.h" +#include "JbdBmsDataPoints.h" #include "VeDirectShuntController.h" #include @@ -283,6 +284,35 @@ class JkBmsBatteryStats : public BatteryStats { uint32_t _cellVoltageTimestamp = 0; }; +class JbdBmsBatteryStats : public BatteryStats { + public: + void getLiveViewData(JsonVariant& root) const final { + getJsonData(root, false); + } + + void getInfoViewData(JsonVariant& root) const { + getJsonData(root, true); + } + + void mqttPublish() const final; + + uint32_t getMqttFullPublishIntervalMs() const final { return 60 * 1000; } + + void updateFrom(JbdBms::DataPointContainer const& dp); + + private: + void getJsonData(JsonVariant& root, bool verbose) const; + + JbdBms::DataPointContainer _dataPoints; + mutable uint32_t _lastMqttPublish = 0; + mutable uint32_t _lastFullMqttPublish = 0; + + uint16_t _cellMinMilliVolt = 0; + uint16_t _cellAvgMilliVolt = 0; + uint16_t _cellMaxMilliVolt = 0; + uint32_t _cellVoltageTimestamp = 0; +}; + class VictronSmartShuntStats : public BatteryStats { public: void getLiveViewData(JsonVariant& root) const final; diff --git a/include/DataPoints.h b/include/DataPoints.h new file mode 100644 index 000000000..91f19d92c --- /dev/null +++ b/include/DataPoints.h @@ -0,0 +1,119 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +using tCellVoltages = std::map; + +template +class DataPoint { + template class> + friend class DataPointContainer; + + public: + using tValue = std::variant; + + DataPoint() = delete; + + DataPoint(DataPoint const& other) + : _strLabel(other._strLabel) + , _strValue(other._strValue) + , _strUnit(other._strUnit) + , _value(other._value) + , _timestamp(other._timestamp) { } + + DataPoint(std::string const& strLabel, std::string const& strValue, + std::string const& strUnit, tValue value, uint32_t timestamp) + : _strLabel(strLabel) + , _strValue(strValue) + , _strUnit(strUnit) + , _value(std::move(value)) + , _timestamp(timestamp) { } + + std::string const& getLabelText() const { return _strLabel; } + std::string const& getValueText() const { return _strValue; } + 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; + std::string _strUnit; + tValue _value; + uint32_t _timestamp; +}; + +template std::string dataPointValueToStr(T const& v); + +template class Traits> +class DataPointContainer { + public: + DataPointContainer() = default; + + //template