centralize config
This commit is contained in:
parent
9049b3e4d5
commit
dd33744612
|
@ -35,35 +35,28 @@ internal static class Program
|
|||
|
||||
private static readonly Byte[] BatteryNodes = { 2, 3, 4, 5, 6 };
|
||||
|
||||
#if DEBUG
|
||||
private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001);
|
||||
private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002);
|
||||
private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003);
|
||||
private static readonly TcpChannel IslandBusLoadChannel = new TcpChannel("localhost", 5004);
|
||||
private static readonly TcpChannel AmptChannel = new TcpChannel("localhost", 5005);
|
||||
private static readonly TcpChannel RelaysChannel = new TcpChannel("localhost", 5006);
|
||||
private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007);
|
||||
#else
|
||||
private static readonly TcpChannel RelaysChannel = new TcpChannel("10.0.1.1", 502); // "192.168.1.242";
|
||||
private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("10.0.2.1", 502); // "192.168.1.2";
|
||||
private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("10.0.3.1", 502); // "192.168.1.3";
|
||||
private static readonly TcpChannel GridMeterChannel = new TcpChannel("10.0.4.1", 502); // "192.168.1.241";
|
||||
private static readonly TcpChannel IslandBusLoadChannel = new TcpChannel("10.0.4.2", 502); // "192.168.1.241";
|
||||
private static readonly TcpChannel AmptChannel = new TcpChannel("10.0.5.1", 502); // "192.168.1.249";
|
||||
private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007);
|
||||
#endif
|
||||
|
||||
private static readonly TcpChannel TruConvertAcChannel ;
|
||||
private static readonly TcpChannel TruConvertDcChannel ;
|
||||
private static readonly TcpChannel GridMeterChannel ;
|
||||
private static readonly TcpChannel IslandBusLoadChannel;
|
||||
private static readonly TcpChannel AmptChannel ;
|
||||
private static readonly TcpChannel RelaysChannel ;
|
||||
private static readonly TcpChannel BatteriesChannel ;
|
||||
|
||||
private static readonly S3Config S3Config = new S3Config
|
||||
static Program()
|
||||
{
|
||||
Bucket = "saliomameiringen",
|
||||
Region = "sos-ch-dk-2",
|
||||
Provider = "exo.io",
|
||||
ContentType = "text/plain; charset=utf-8",
|
||||
Key = "EXO2bf0cbd97fbfa75aa36ed46f",
|
||||
Secret = "Bn1CDPqOG-XpDSbYjfIJxojcHTm391vZTc8z8l_fEPs"
|
||||
};
|
||||
var config = Config.Load();
|
||||
var d = config.Devices;
|
||||
|
||||
TruConvertAcChannel = new TcpChannel(d.TruConvertAcIp);
|
||||
TruConvertDcChannel = new TcpChannel(d.TruConvertDcIp);
|
||||
GridMeterChannel = new TcpChannel(d.GridMeterIp);
|
||||
IslandBusLoadChannel = new TcpChannel(d.IslandBusLoadMeterIp);
|
||||
AmptChannel = new TcpChannel(d.AmptIp);
|
||||
RelaysChannel = new TcpChannel(d.RelaysIp);
|
||||
BatteriesChannel = new TcpChannel(d.BatteryIp);
|
||||
}
|
||||
|
||||
public static async Task Main(String[] args)
|
||||
{
|
||||
while (true)
|
||||
|
@ -211,9 +204,9 @@ internal static class Program
|
|||
private static void PrintTopology(StatusRecord s)
|
||||
{
|
||||
// Power Measurement Values
|
||||
var gridPower = s.GridMeter!.Ac.Power.Active;
|
||||
var gridPower = s.GridMeter is not null ? s.GridMeter!.Ac.Power.Active : 0;
|
||||
var inverterPower = s.AcDc.Ac.Power.Active;
|
||||
var islandLoadPower = s.LoadOnAcIsland is null ? 0 : s.LoadOnAcIsland.Ac.Power.Active;
|
||||
var islandLoadPower = s.LoadOnAcIsland is not null ? s.LoadOnAcIsland.Ac.Power.Active : 0;
|
||||
var dcBatteryPower = s.DcDc.Dc.Battery.Power;
|
||||
var dcdcPower = s.DcDc.Dc.Link.Power;
|
||||
var pvOnDcPower = s.PvOnDc.Dc!.Power.Value;
|
||||
|
@ -415,16 +408,15 @@ internal static class Program
|
|||
|
||||
private static async Task UploadCsv(StatusRecord status, UnixTime timeStamp)
|
||||
{
|
||||
timeStamp.WriteLine();
|
||||
|
||||
var s3Config = status.Config.S3;
|
||||
if (s3Config is null)
|
||||
return;
|
||||
|
||||
var csv = status.ToCsv();
|
||||
var s3Path = timeStamp + ".csv";
|
||||
var request = S3Config.CreatePutRequest(s3Path);
|
||||
var request = s3Config.CreatePutRequest(s3Path);
|
||||
var response = await request.PutAsync(new StringContent(csv));
|
||||
|
||||
//csv.WriteLine();
|
||||
//timeStamp.Ticks.WriteLine();
|
||||
|
||||
if (response.StatusCode != 200)
|
||||
{
|
||||
Console.WriteLine("ERROR: PUT");
|
||||
|
|
|
@ -14,30 +14,81 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
|
|||
|
||||
private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
|
||||
|
||||
public Double MinSoc { get; set; }
|
||||
public UnixTime LastEoc { get; set; }
|
||||
public Double PConstant { get; set; }
|
||||
public Double GridSetPoint { get; set; }
|
||||
public Double BatterySelfDischargePower { get; set; }
|
||||
public Double HoldSocZone { get; set; }
|
||||
public required Double MinSoc { get; set; }
|
||||
public required UnixTime LastEoc { get; set; }
|
||||
public required Double PConstant { get; set; }
|
||||
public required Double GridSetPoint { get; set; }
|
||||
public required Double BatterySelfDischargePower { get; set; }
|
||||
public required Double HoldSocZone { get; set; }
|
||||
|
||||
public required Double MaxDcBusVoltage { get; set; }
|
||||
public required Double MinDcBusVoltage { get; set; }
|
||||
public required Double ReferenceDcBusVoltage { get; set; }
|
||||
|
||||
public Double MaxDcBusVoltage { get; set; }
|
||||
public Double MinDcBusVoltage { get; set; }
|
||||
public Double ReferenceDcBusVoltage { get; set; }
|
||||
public required DeviceConfig Devices { get; set; }
|
||||
public required S3Config? S3 { get; set; }
|
||||
|
||||
|
||||
|
||||
#if DEBUG
|
||||
public static Config Default => new()
|
||||
{
|
||||
MinSoc = 20,
|
||||
LastEoc = UnixTime.Epoch,
|
||||
LastEoc = UnixTime.Epoch, // TODO: remove, use new LastEoc feature from BMS
|
||||
PConstant = .5,
|
||||
GridSetPoint = 0,
|
||||
BatterySelfDischargePower = 200, // TODO: multiple batteries // no need as we multiplied by the number of the batteries
|
||||
HoldSocZone = 1, // TODO: find better name,
|
||||
BatterySelfDischargePower = 200,
|
||||
HoldSocZone = 1, // TODO: find better name,
|
||||
MinDcBusVoltage = 690,
|
||||
ReferenceDcBusVoltage = 750,
|
||||
MaxDcBusVoltage = 810,
|
||||
Devices = new ()
|
||||
{
|
||||
TruConvertAcIp = new() { Host = "localhost", Port = 5001},
|
||||
TruConvertDcIp = new() { Host = "localhost", Port = 5002},
|
||||
GridMeterIp = new() { Host = "localhost", Port = 5003},
|
||||
IslandBusLoadMeterIp = new() { Host = "localhost", Port = 5004},
|
||||
AmptIp = new() { Host = "localhost", Port = 5005},
|
||||
RelaysIp = new() { Host = "localhost", Port = 5006},
|
||||
BatteryIp = new() { Host = "localhost", Port = 5007},
|
||||
BatteryNodes = new []{ 2, 3, 4, 5, 6 },
|
||||
},
|
||||
S3 = new()
|
||||
{
|
||||
Bucket = "saliomameiringen",
|
||||
Region = "sos-ch-dk-2",
|
||||
Provider = "exo.io",
|
||||
ContentType = "text/plain; charset=utf-8",
|
||||
Key = "EXO2bf0cbd97fbfa75aa36ed46f",
|
||||
Secret = "Bn1CDPqOG-XpDSbYjfIJxojcHTm391vZTc8z8l_fEPs"
|
||||
}
|
||||
};
|
||||
|
||||
#else
|
||||
public static Config Default => new()
|
||||
{
|
||||
MinSoc = 20,
|
||||
LastEoc = UnixTime.Epoch, // TODO: remove, use new LastEoc feature from BMS
|
||||
PConstant = .5,
|
||||
GridSetPoint = 0,
|
||||
BatterySelfDischargePower = 200,
|
||||
HoldSocZone = 1, // TODO: find better name,
|
||||
MinDcBusVoltage = 690,
|
||||
ReferenceDcBusVoltage = 750,
|
||||
MaxDcBusVoltage = 810,
|
||||
S3 = null, // TODO
|
||||
Devices = new ()
|
||||
{
|
||||
RelaysIp = new() { Address = "10.0.1.1", Port = 502},
|
||||
TruConvertAcIp = new() { Address = "10.0.2.1", Port = 502},
|
||||
TruConvertDcIp = new() { Address = "10.0.3.1", Port = 502},
|
||||
GridMeterIp = new() { Address = "10.0.4.1", Port = 502},
|
||||
InternalMeterIp = new() { Address = "10.0.4.2", Port = 502},
|
||||
AmptIp = new() { Address = "10.0.5.1", Port = 502},
|
||||
BatteryIp = new() { Address = "localhost", Port = 6855},
|
||||
BatteryNodes = new Byte[]{2},
|
||||
},
|
||||
};
|
||||
#endif
|
||||
|
||||
public void Save(String? path = null)
|
||||
{
|
||||
|
@ -66,7 +117,7 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
$"Failed to read config file {configFilePath}, using default config\n{e}".LogInfo();
|
||||
$"Failed to read config file {configFilePath}, using default config\n{e}".WriteLine();
|
||||
return Default;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@ namespace InnovEnergy.App.SaliMax.SystemConfig;
|
|||
|
||||
public class DeviceConfig
|
||||
{
|
||||
public required Ip4Address RelaysIp { get; init; }
|
||||
public required Ip4Address TruConvertAcIp { get; init; }
|
||||
public required Ip4Address TruConvertDcIp { get; init; }
|
||||
public required Ip4Address GridMeterIp { get; init; }
|
||||
public required Ip4Address InternalMeterIp { get; init; }
|
||||
public required Ip4Address AmptIp { get; init; }
|
||||
public required Ip4Address BatteryIp { get; init; }
|
||||
public required Byte[] BatteryNodes { get; init; }
|
||||
public required Ip4Address RelaysIp { get; init; }
|
||||
public required Ip4Address TruConvertAcIp { get; init; }
|
||||
public required Ip4Address TruConvertDcIp { get; init; }
|
||||
public required Ip4Address GridMeterIp { get; init; }
|
||||
public required Ip4Address IslandBusLoadMeterIp { get; init; }
|
||||
public required Ip4Address AmptIp { get; init; }
|
||||
public required Ip4Address BatteryIp { get; init; }
|
||||
public required Int32[] BatteryNodes { get; init; }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue