forked from tbnobody/OpenDTU
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Support for second Victron MPPT charge controller
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.
- Loading branch information
1 parent
21c19f4
commit 7dcd4e2
Showing
28 changed files
with
458 additions
and
238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <memory> | ||
#include <mutex> | ||
#include <TaskSchedulerDeclarations.h> | ||
|
||
#include "BatteryStats.h" | ||
|
||
class BatteryProvider { | ||
public: | ||
// returns true if the provider is ready for use, false otherwise | ||
virtual bool init(bool verboseLogging) = 0; | ||
|
||
virtual void deinit() = 0; | ||
virtual void loop() = 0; | ||
virtual std::shared_ptr<BatteryStats> getStats() const = 0; | ||
public: | ||
// returns true if the provider is ready for use, false otherwise | ||
virtual bool init(bool verboseLogging) = 0; | ||
virtual void deinit() = 0; | ||
virtual void loop() = 0; | ||
virtual std::shared_ptr<BatteryStats> getStats() const = 0; | ||
virtual bool usesHwPort2() = 0; | ||
}; | ||
|
||
class BatteryClass { | ||
public: | ||
void init(Scheduler&); | ||
void updateSettings(); | ||
public: | ||
void init(Scheduler&); | ||
void updateSettings(); | ||
|
||
std::shared_ptr<BatteryStats const> getStats() const; | ||
private: | ||
void loop(); | ||
std::shared_ptr<BatteryStats const> getStats() const; | ||
|
||
Task _loopTask; | ||
private: | ||
void loop(); | ||
|
||
mutable std::mutex _mutex; | ||
std::unique_ptr<BatteryProvider> _upProvider = nullptr; | ||
Task _loopTask; | ||
mutable std::mutex _mutex; | ||
std::unique_ptr<BatteryProvider> _upProvider = nullptr; | ||
}; | ||
|
||
extern BatteryClass Battery; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <map> | ||
|
||
class SerialPortManager { | ||
public: | ||
bool allocateMpptPort(int port); | ||
bool allocateBatteryPort(int port); | ||
void invalidateBatteryPort(); | ||
void invalidateMpptPorts(); | ||
|
||
private: | ||
enum Owner { | ||
BATTERY, | ||
MPPT | ||
}; | ||
|
||
std::map<uint8_t, Owner> allocatedPorts; | ||
|
||
bool allocatePort(uint8_t port, Owner owner); | ||
void invalidate(Owner owner); | ||
|
||
static const char* print(Owner owner); | ||
}; | ||
|
||
extern SerialPortManager PortManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.