* fix compiler warning in SerialPortManager.cpp: function must not return void * clean up and simplify implementation of usesHwPort2() * make const * overrides are final * default implementation returns false * implement in header, as the implementation is very simple * rename PortManager to SerialPortManager. as "PortManager" is too generic, the static instance of the serial port manager is renamed to "SerialPortManager". the class is therefore renamed to SerialPortManagerClass, which is in line with other (static) classes withing OpenDTU(-OnBattery). * implement separate data ages for MPPT charge controllers * make sure MPPT data and live data time out * do not use invalid data of MPPT controlers for calculations * add :key binding to v-for iterating over MPPT instances
78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <frozen/string.h>
|
|
|
|
#include "Battery.h"
|
|
#include "JkBmsSerialMessage.h"
|
|
|
|
class DataPointContainer;
|
|
|
|
namespace JkBms {
|
|
|
|
class Controller : public BatteryProvider {
|
|
public:
|
|
Controller() = default;
|
|
|
|
bool init(bool verboseLogging) final;
|
|
void deinit() final;
|
|
void loop() final;
|
|
std::shared_ptr<BatteryStats> getStats() const final { return _stats; }
|
|
bool usesHwPort2() const final { return true; }
|
|
|
|
private:
|
|
enum class Status : unsigned {
|
|
Initializing,
|
|
Timeout,
|
|
WaitingForPollInterval,
|
|
HwSerialNotAvailableForWrite,
|
|
BusyReading,
|
|
RequestSent,
|
|
FrameCompleted
|
|
};
|
|
|
|
frozen::string const& getStatusText(Status status);
|
|
void announceStatus(Status status);
|
|
void sendRequest(uint8_t pollInterval);
|
|
void rxData(uint8_t inbyte);
|
|
void reset();
|
|
void frameComplete();
|
|
void processDataPoints(DataPointContainer const& dataPoints);
|
|
|
|
enum class Interface : unsigned {
|
|
Invalid,
|
|
Uart,
|
|
Transceiver
|
|
};
|
|
|
|
Interface getInterface() const;
|
|
|
|
enum class ReadState : unsigned {
|
|
Idle,
|
|
WaitingForFrameStart,
|
|
FrameStartReceived,
|
|
StartMarkerReceived,
|
|
FrameLengthMsbReceived,
|
|
ReadingFrame
|
|
};
|
|
ReadState _readState;
|
|
void setReadState(ReadState state) {
|
|
_readState = state;
|
|
}
|
|
|
|
bool _verboseLogging = true;
|
|
int8_t _rxEnablePin = -1;
|
|
int8_t _txEnablePin = -1;
|
|
Status _lastStatus = Status::Initializing;
|
|
uint32_t _lastStatusPrinted = 0;
|
|
uint32_t _lastRequest = 0;
|
|
uint16_t _frameLength = 0;
|
|
uint8_t _protocolVersion = -1;
|
|
SerialResponse::tData _buffer = {};
|
|
std::shared_ptr<JkBmsBatteryStats> _stats =
|
|
std::make_shared<JkBmsBatteryStats>();
|
|
};
|
|
|
|
} /* namespace JkBms */
|