* 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
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include "SerialPortManager.h"
|
|
#include "MessageOutput.h"
|
|
|
|
#define MAX_CONTROLLERS 3
|
|
|
|
SerialPortManagerClass SerialPortManager;
|
|
|
|
bool SerialPortManagerClass::allocateBatteryPort(int port)
|
|
{
|
|
return allocatePort(port, Owner::BATTERY);
|
|
}
|
|
|
|
bool SerialPortManagerClass::allocateMpptPort(int port)
|
|
{
|
|
return allocatePort(port, Owner::MPPT);
|
|
}
|
|
|
|
bool SerialPortManagerClass::allocatePort(uint8_t port, Owner owner)
|
|
{
|
|
if (port >= MAX_CONTROLLERS) {
|
|
MessageOutput.printf("[SerialPortManager] Invalid serial port = %d \r\n", port);
|
|
return false;
|
|
}
|
|
|
|
return allocatedPorts.insert({port, owner}).second;
|
|
}
|
|
|
|
void SerialPortManagerClass::invalidateBatteryPort()
|
|
{
|
|
invalidate(Owner::BATTERY);
|
|
}
|
|
|
|
void SerialPortManagerClass::invalidateMpptPorts()
|
|
{
|
|
invalidate(Owner::MPPT);
|
|
}
|
|
|
|
void SerialPortManagerClass::invalidate(Owner owner)
|
|
{
|
|
for (auto it = allocatedPorts.begin(); it != allocatedPorts.end();) {
|
|
if (it->second == owner) {
|
|
MessageOutput.printf("[SerialPortManager] Removing port = %d, owner = %s \r\n", it->first, print(owner));
|
|
it = allocatedPorts.erase(it);
|
|
} else {
|
|
++it;
|
|
}
|
|
}
|
|
}
|
|
|
|
const char* SerialPortManagerClass::print(Owner owner)
|
|
{
|
|
switch (owner) {
|
|
case BATTERY:
|
|
return "BATTERY";
|
|
case MPPT:
|
|
return "MPPT";
|
|
}
|
|
return "unknown";
|
|
}
|