2022-07-15 18:05:58 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2022-04-10 16:57:24 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2023-12-07 12:46:38 +01:00
|
|
|
#include "PinMapping.h"
|
2024-10-17 21:46:32 +02:00
|
|
|
#include <TaskSchedulerDeclarations.h>
|
|
|
|
|
#include <condition_variable>
|
2025-02-07 22:57:01 +01:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <mutex>
|
2022-04-10 16:57:24 +02:00
|
|
|
|
2022-11-14 22:24:16 +01:00
|
|
|
#define CONFIG_FILENAME "/config.json"
|
2024-10-25 21:29:15 +02:00
|
|
|
#define CONFIG_VERSION 0x00011d00 // 0.1.29 // make sure to clean all after change
|
2022-04-10 16:57:24 +02:00
|
|
|
|
2023-02-27 14:32:55 +01:00
|
|
|
#define WIFI_MAX_SSID_STRLEN 32
|
2022-06-22 21:00:44 +02:00
|
|
|
#define WIFI_MAX_PASSWORD_STRLEN 64
|
2022-04-10 17:37:54 +02:00
|
|
|
#define WIFI_MAX_HOSTNAME_STRLEN 31
|
|
|
|
|
|
2022-04-17 23:13:36 +02:00
|
|
|
#define NTP_MAX_SERVER_STRLEN 31
|
|
|
|
|
#define NTP_MAX_TIMEZONE_STRLEN 50
|
2022-04-18 01:33:46 +02:00
|
|
|
#define NTP_MAX_TIMEZONEDESCR_STRLEN 50
|
2022-04-17 23:13:36 +02:00
|
|
|
|
2022-08-10 18:59:30 +02:00
|
|
|
#define MQTT_MAX_HOSTNAME_STRLEN 128
|
2024-06-29 00:28:21 +02:00
|
|
|
#define MQTT_MAX_CLIENTID_STRLEN 64
|
2022-11-14 22:32:24 +01:00
|
|
|
#define MQTT_MAX_USERNAME_STRLEN 64
|
|
|
|
|
#define MQTT_MAX_PASSWORD_STRLEN 64
|
2022-04-18 15:19:26 +02:00
|
|
|
#define MQTT_MAX_TOPIC_STRLEN 32
|
2022-04-21 23:43:44 +02:00
|
|
|
#define MQTT_MAX_LWTVALUE_STRLEN 20
|
2023-04-12 11:58:27 +02:00
|
|
|
#define MQTT_MAX_CERT_STRLEN 2560
|
2022-04-18 15:19:26 +02:00
|
|
|
|
2022-05-04 21:54:38 +02:00
|
|
|
#define INV_MAX_NAME_STRLEN 31
|
|
|
|
|
#define INV_MAX_COUNT 10
|
2023-03-08 22:59:14 +01:00
|
|
|
#define INV_MAX_CHAN_COUNT 6
|
2022-05-04 21:54:38 +02:00
|
|
|
|
2022-11-15 19:31:31 +01:00
|
|
|
#define CHAN_MAX_NAME_STRLEN 31
|
|
|
|
|
|
2023-01-20 17:50:13 +01:00
|
|
|
#define DEV_MAX_MAPPING_NAME_STRLEN 63
|
2024-10-25 21:29:15 +02:00
|
|
|
#define LOCALE_STRLEN 2
|
2023-01-16 21:09:24 +01:00
|
|
|
|
2022-11-15 19:31:31 +01:00
|
|
|
struct CHANNEL_CONFIG_T {
|
|
|
|
|
uint16_t MaxChannelPower;
|
|
|
|
|
char Name[CHAN_MAX_NAME_STRLEN];
|
2023-02-13 20:25:00 +01:00
|
|
|
float YieldTotalOffset;
|
2022-11-15 19:31:31 +01:00
|
|
|
};
|
|
|
|
|
|
2022-05-04 21:54:38 +02:00
|
|
|
struct INVERTER_CONFIG_T {
|
|
|
|
|
uint64_t Serial;
|
|
|
|
|
char Name[INV_MAX_NAME_STRLEN + 1];
|
2023-05-29 20:17:07 +02:00
|
|
|
uint8_t Order;
|
2023-02-18 19:44:16 +01:00
|
|
|
bool Poll_Enable;
|
|
|
|
|
bool Poll_Enable_Night;
|
|
|
|
|
bool Command_Enable;
|
|
|
|
|
bool Command_Enable_Night;
|
2023-09-01 19:17:12 +02:00
|
|
|
uint8_t ReachableThreshold;
|
2023-09-02 12:22:22 +02:00
|
|
|
bool ZeroRuntimeDataIfUnrechable;
|
2023-09-05 20:27:52 +02:00
|
|
|
bool ZeroYieldDayOnMidnight;
|
2024-05-31 00:07:28 +02:00
|
|
|
bool ClearEventlogOnMidnight;
|
2023-11-22 20:21:25 +01:00
|
|
|
bool YieldDayCorrection;
|
2022-11-15 19:31:31 +01:00
|
|
|
CHANNEL_CONFIG_T channel[INV_MAX_CHAN_COUNT];
|
2022-05-04 21:54:38 +02:00
|
|
|
};
|
|
|
|
|
|
2022-04-10 16:57:24 +02:00
|
|
|
struct CONFIG_T {
|
2023-11-19 14:53:26 +01:00
|
|
|
struct {
|
|
|
|
|
uint32_t Version;
|
|
|
|
|
uint32_t SaveCount;
|
|
|
|
|
} Cfg;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
char Ssid[WIFI_MAX_SSID_STRLEN + 1];
|
|
|
|
|
char Password[WIFI_MAX_PASSWORD_STRLEN + 1];
|
|
|
|
|
uint8_t Ip[4];
|
|
|
|
|
uint8_t Netmask[4];
|
|
|
|
|
uint8_t Gateway[4];
|
|
|
|
|
uint8_t Dns1[4];
|
|
|
|
|
uint8_t Dns2[4];
|
|
|
|
|
bool Dhcp;
|
|
|
|
|
char Hostname[WIFI_MAX_HOSTNAME_STRLEN + 1];
|
|
|
|
|
uint32_t ApTimeout;
|
|
|
|
|
} WiFi;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
bool Enabled;
|
|
|
|
|
} Mdns;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
char Server[NTP_MAX_SERVER_STRLEN + 1];
|
|
|
|
|
char Timezone[NTP_MAX_TIMEZONE_STRLEN + 1];
|
|
|
|
|
char TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1];
|
|
|
|
|
double Longitude;
|
|
|
|
|
double Latitude;
|
|
|
|
|
uint8_t SunsetType;
|
|
|
|
|
} Ntp;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
bool Enabled;
|
|
|
|
|
char Hostname[MQTT_MAX_HOSTNAME_STRLEN + 1];
|
|
|
|
|
uint32_t Port;
|
2024-06-29 00:28:21 +02:00
|
|
|
char ClientId[MQTT_MAX_CLIENTID_STRLEN + 1];
|
2023-11-19 14:53:26 +01:00
|
|
|
char Username[MQTT_MAX_USERNAME_STRLEN + 1];
|
|
|
|
|
char Password[MQTT_MAX_PASSWORD_STRLEN + 1];
|
|
|
|
|
char Topic[MQTT_MAX_TOPIC_STRLEN + 1];
|
|
|
|
|
bool Retain;
|
|
|
|
|
uint32_t PublishInterval;
|
|
|
|
|
bool CleanSession;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
char Topic[MQTT_MAX_TOPIC_STRLEN + 1];
|
|
|
|
|
char Value_Online[MQTT_MAX_LWTVALUE_STRLEN + 1];
|
|
|
|
|
char Value_Offline[MQTT_MAX_LWTVALUE_STRLEN + 1];
|
2023-11-19 16:17:10 +01:00
|
|
|
uint8_t Qos;
|
2023-11-19 14:53:26 +01:00
|
|
|
} Lwt;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
bool Enabled;
|
|
|
|
|
bool Retain;
|
|
|
|
|
char Topic[MQTT_MAX_TOPIC_STRLEN + 1];
|
|
|
|
|
bool IndividualPanels;
|
|
|
|
|
bool Expire;
|
|
|
|
|
} Hass;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
bool Enabled;
|
|
|
|
|
char RootCaCert[MQTT_MAX_CERT_STRLEN + 1];
|
|
|
|
|
bool CertLogin;
|
|
|
|
|
char ClientCert[MQTT_MAX_CERT_STRLEN + 1];
|
|
|
|
|
char ClientKey[MQTT_MAX_CERT_STRLEN + 1];
|
|
|
|
|
} Tls;
|
|
|
|
|
} Mqtt;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
uint64_t Serial;
|
|
|
|
|
uint32_t PollInterval;
|
|
|
|
|
struct {
|
|
|
|
|
uint8_t PaLevel;
|
|
|
|
|
} Nrf;
|
|
|
|
|
struct {
|
|
|
|
|
int8_t PaLevel;
|
|
|
|
|
uint32_t Frequency;
|
2024-01-14 00:16:43 +01:00
|
|
|
uint8_t CountryMode;
|
2023-11-19 14:53:26 +01:00
|
|
|
} Cmt;
|
|
|
|
|
} Dtu;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
char Password[WIFI_MAX_PASSWORD_STRLEN + 1];
|
|
|
|
|
bool AllowReadonly;
|
|
|
|
|
} Security;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
bool PowerSafe;
|
|
|
|
|
bool ScreenSaver;
|
|
|
|
|
uint8_t Rotation;
|
|
|
|
|
uint8_t Contrast;
|
2024-10-25 21:29:15 +02:00
|
|
|
char Locale[LOCALE_STRLEN + 1];
|
2024-01-08 14:19:26 +01:00
|
|
|
struct {
|
|
|
|
|
uint32_t Duration;
|
|
|
|
|
uint8_t Mode;
|
|
|
|
|
} Diagram;
|
2023-11-19 14:53:26 +01:00
|
|
|
} Display;
|
2022-08-10 18:59:30 +02:00
|
|
|
|
2023-12-07 12:46:38 +01:00
|
|
|
struct {
|
|
|
|
|
uint8_t Brightness;
|
|
|
|
|
} Led_Single[PINMAPPING_LED_COUNT];
|
|
|
|
|
|
2023-07-22 17:28:58 +02:00
|
|
|
INVERTER_CONFIG_T Inverter[INV_MAX_COUNT];
|
2023-01-16 21:09:24 +01:00
|
|
|
char Dev_PinMapping[DEV_MAX_MAPPING_NAME_STRLEN + 1];
|
2022-04-10 16:57:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ConfigurationClass {
|
|
|
|
|
public:
|
2024-10-17 21:46:32 +02:00
|
|
|
void init(Scheduler& scheduler);
|
2022-04-10 16:57:24 +02:00
|
|
|
bool read();
|
|
|
|
|
bool write();
|
|
|
|
|
void migrate();
|
2024-10-17 21:46:32 +02:00
|
|
|
CONFIG_T const& get();
|
|
|
|
|
|
|
|
|
|
class WriteGuard {
|
|
|
|
|
public:
|
|
|
|
|
WriteGuard();
|
|
|
|
|
CONFIG_T& getConfig();
|
|
|
|
|
~WriteGuard();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::unique_lock<std::mutex> _lock;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
WriteGuard getWriteGuard();
|
2022-05-04 21:54:38 +02:00
|
|
|
|
|
|
|
|
INVERTER_CONFIG_T* getFreeInverterSlot();
|
2023-12-12 00:21:14 +01:00
|
|
|
INVERTER_CONFIG_T* getInverterConfig(const uint64_t serial);
|
2024-03-13 18:47:28 +01:00
|
|
|
void deleteInverterById(const uint8_t id);
|
2024-10-17 21:46:32 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void loop();
|
|
|
|
|
|
|
|
|
|
Task _loopTask;
|
2022-04-10 16:57:24 +02:00
|
|
|
};
|
|
|
|
|
|
2024-01-08 14:19:26 +01:00
|
|
|
extern ConfigurationClass Configuration;
|