this change adds support for a second Victron MPPT charge controller using a second serial connection. * Add device configuration for a second victron mppt * Update VedirectView for second victron mppt * Update MqttHandleVedirect for second victron mppt * Update MqttHandleVedirectHass for second victron mppt * Handle nonexisting victron controllers with optionals * Add bool-function to Battery and inherited classes, if uart port 2 is being used * Introduced a serial port manager. In order to prevent the battery and the Victron MPPT to use the same hw serial ports, this class keeps track of the used ports and their owners.
60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include <mutex>
|
|
#include <memory>
|
|
|
|
#include "VeDirectMpptController.h"
|
|
#include "Configuration.h"
|
|
#include <TaskSchedulerDeclarations.h>
|
|
|
|
class VictronMpptClass {
|
|
public:
|
|
VictronMpptClass() = default;
|
|
~VictronMpptClass() = default;
|
|
|
|
void init(Scheduler& scheduler);
|
|
void updateSettings();
|
|
|
|
bool isDataValid() const;
|
|
bool isDataValid(size_t idx) const;
|
|
|
|
// returns the data age of all controllers,
|
|
// i.e, the youngest data's age is returned.
|
|
uint32_t getDataAgeMillis() const;
|
|
|
|
std::optional<VeDirectMpptController::spData_t> getData(size_t idx = 0) const;
|
|
|
|
// total output of all MPPT charge controllers in Watts
|
|
int32_t getPowerOutputWatts() const;
|
|
|
|
// total panel input power of all MPPT charge controllers in Watts
|
|
int32_t getPanelPowerWatts() const;
|
|
|
|
// sum of total yield of all MPPT charge controllers in kWh
|
|
double getYieldTotal() const;
|
|
|
|
// sum of today's yield of all MPPT charge controllers in kWh
|
|
double getYieldDay() const;
|
|
|
|
// minimum of all MPPT charge controllers' output voltages in V
|
|
double getOutputVoltage() const;
|
|
|
|
private:
|
|
void loop();
|
|
VictronMpptClass(VictronMpptClass const& other) = delete;
|
|
VictronMpptClass(VictronMpptClass&& other) = delete;
|
|
VictronMpptClass& operator=(VictronMpptClass const& other) = delete;
|
|
VictronMpptClass& operator=(VictronMpptClass&& other) = delete;
|
|
|
|
Task _loopTask;
|
|
|
|
mutable std::mutex _mutex;
|
|
using controller_t = std::unique_ptr<VeDirectMpptController>;
|
|
std::vector<controller_t> _controllers;
|
|
|
|
bool initController(int8_t rx, int8_t tx, bool logging, int hwSerialPort);
|
|
};
|
|
|
|
extern VictronMpptClass VictronMppt;
|