New AMPT paths are created in salimax

This commit is contained in:
atef 2025-06-26 11:47:40 +02:00
parent eeb949bdfa
commit 7510ee0ce2
5 changed files with 26 additions and 20 deletions

View File

@ -25,7 +25,7 @@ public record StatusRecord
public required DcPowerDevice? AcDcToDcLink { get; init; }
public required DcPowerDevice? LoadOnDc { get; init; }
public required IRelaysRecord? Relays { get; init; }
public required AmptStatus? PvOnDc { get; init; }
public required IReadOnlyList<AmptStatus?> PvOnDc { get; init; }
public required Config Config { get; set; }
public required SystemLog Log { get; init; } // TODO: init only

View File

@ -1,4 +1,4 @@
#undef Amax
#define Amax
#undef GridLimit
using System.IO.Compression;
@ -47,6 +47,7 @@ internal static class Program
private static readonly Channel GridMeterChannel;
private static readonly Channel IslandBusLoadChannel;
private static readonly Channel PvOnDc;
private static readonly Channel SecondPvOnDc;
private static readonly Channel PvOnAcGrid;
private static readonly Channel PvOnAcIsland;
private static readonly Channel RelaysChannel;
@ -77,6 +78,7 @@ internal static class Program
GridMeterChannel = CreateChannel(d.GridMeterIp);
IslandBusLoadChannel = CreateChannel(d.IslandBusLoadMeterIp);
PvOnDc = CreateChannel(d.PvOnDc);
SecondPvOnDc = CreateChannel(d.SecondPvOnDc);
PvOnAcGrid = CreateChannel(d.PvOnAcGrid);
PvOnAcIsland = CreateChannel(d.PvOnAcIsland);
RelaysChannel = CreateChannel(d.RelaysIp);
@ -133,6 +135,7 @@ internal static class Program
var gridMeterDevice = new EmuMeterDevice(GridMeterChannel);
var acIslandLoadMeter = new EmuMeterDevice(IslandBusLoadChannel);
var pvOnDcDevice = new AmptDevices(PvOnDc);
var secondPvOnDcDevice = new AmptDevices(SecondPvOnDc);
var pvOnAcGridDevice = new AmptDevices(PvOnAcGrid);
var pvOnAcIslandDevice = new AmptDevices(PvOnAcIsland);
var saliMaxTsRelaysDevice = new RelaysDeviceAdam6060(RelaysTsChannel);
@ -155,11 +158,14 @@ internal static class Program
var tsRelays = saliMaxTsRelaysDevice.Read();
var loadOnAcIsland = acIslandLoadMeter.Read();
var gridMeter = gridMeterDevice.Read();
var pvOnDc = pvOnDcDevice.Read();
var firstPvOnDc = pvOnDcDevice.Read();
var secondPvOnDc = secondPvOnDcDevice.Read();
var battery = batteryDevices.Read();
var pvOnAcGrid = pvOnAcGridDevice.Read();
var pvOnAcIsland = pvOnAcIslandDevice.Read();
IReadOnlyList<AmptStatus?> pvOnDc = new List<AmptStatus?> { firstPvOnDc, secondPvOnDc };
var gridBusToIslandBus = Topology.CalculateGridBusToIslandBusPower(pvOnAcIsland, loadOnAcIsland, acDc);
@ -289,8 +295,9 @@ internal static class Program
record.PerformLed();
WriteControl(record);
$"{DateTime.Now.Round(UpdateInterval).ToUnixTime()} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine();
$"{record.StateMachine.State}: {record.StateMachine.Message}".WriteLine();
$"{DateTime.Now.Round(UpdateInterval).ToUnixTime()} : {DateTime.Now.Round(UpdateInterval):dd/MM/yyyy HH:mm:ss}".WriteLine();
record.CreateTopologyTextBlock().WriteLine();
@ -856,7 +863,6 @@ internal static class Program
Dictionary<string, object> jsonData = new Dictionary<string, object>();
//Console.WriteLine(csv);
foreach (var line in csv.Split('\n'))
{
@ -877,7 +883,6 @@ internal static class Program
string jsonOutput = JsonConvert.SerializeObject(jsonData, Formatting.None);
jsonOutput.LogInfo();
await RestApiSavingFile(csv);
@ -909,7 +914,7 @@ internal static class Program
var compressedBytes = CompresseBytes(csvToSend);
// Encode the compressed byte array as a Base64 string
string base64String = Convert.ToBase64String(compressedBytes);
var base64String = Convert.ToBase64String(compressedBytes);
// Create StringContent from Base64 string
var stringContent = new StringContent(base64String, Encoding.UTF8, "application/base64");

View File

@ -113,7 +113,8 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
PvOnAcIsland = new() { Host = "true" , Port = 0 , DeviceState = DeviceState.Measured},
IslandBusLoadMeterIp = new() { Host = "localhost", Port = 5004, DeviceState = DeviceState.Measured},
TruConvertAcIp = new() { Host = "localhost", Port = 5001, DeviceState = DeviceState.Measured},
PvOnDc = new() { Host = "localhost", Port = 5005, DeviceState = DeviceState.Measured},
PvOnDc = new() { Host = "localhost", Port = 5005, DeviceState = DeviceState.Measured},
SecondPvOnDc = new() { Host = "localhost", Port = 5006, DeviceState = DeviceState.Measured},
LoadOnDc = new() { Host = "false" , Port = 0 , DeviceState = DeviceState.Measured},
TruConvertDcIp = new() { Host = "localhost", Port = 5002, DeviceState = DeviceState.Measured},
BatteryIp = new() { Host = "localhost", Port = 5007, DeviceState = DeviceState.Measured},
@ -213,7 +214,8 @@ public class Config //TODO: let IE choose from config files (Json) and connect t
PvOnAcIsland = new() { Host = "false" , Port = 0 , DeviceState = DeviceState.Measured},
IslandBusLoadMeterIp = new() { Host = "10.0.4.2", Port = 502, DeviceState = DeviceState.Measured},
TruConvertAcIp = new() { Host = "10.0.2.1", Port = 502, DeviceState = DeviceState.Measured},
PvOnDc = new() { Host = "10.0.5.1", Port = 502, DeviceState = DeviceState.Measured},
PvOnDc = new() { Host = "10.0.5.1", Port = 502, DeviceState = DeviceState.Measured},
SecondPvOnDc = new() { Host = "10.0.5.2", Port = 502, DeviceState = DeviceState.Measured},
LoadOnDc = new() { Host = "false" , Port = 0 , DeviceState = DeviceState.Measured},
TruConvertDcIp = new() { Host = "10.0.3.1", Port = 502, DeviceState = DeviceState.Measured},
BatteryIp = new() { Host = "localhost", Port = 6855, DeviceState = DeviceState.Measured },

View File

@ -14,6 +14,7 @@ public class DeviceConfig
public required SalimaxDevice IslandBusLoadMeterIp { get; init; }
public required SalimaxDevice TruConvertAcIp { get; init; }
public required SalimaxDevice PvOnDc { get; init; }
public required SalimaxDevice SecondPvOnDc { get; init; }
public required SalimaxDevice LoadOnDc { get; init; }
public required SalimaxDevice TruConvertDcIp { get; init; }
public required SalimaxDevice BatteryIp { get; init; }

View File

@ -71,7 +71,7 @@ public static class Topology
var f = status.LoadOnAcIsland?.Ac.Power.Active;
var g = status.AcDc.Dc.Power.Value;
var h = status.AcDcToDcLink?.Power.Value;
var i = status.PvOnDc?.Dc.Power.Value;
var i = status.PvOnDc?.Sum(p => p?.Dc.Power.Value);
var k = status.DcDc.Dc.Link.Power.Value;
var l = status.Battery is not null ? status.Battery.Dc.Power.Value : 0;
var j = status.LoadOnDc?.Power.Value;
@ -331,10 +331,8 @@ public static class Topology
/////////////////// top ///////////////////
var mppt = status.PvOnDc;
var nStrings = mppt is not null
? "x" + mppt.Strings.Count
: "?";
var totalStrings = mppt.Sum(p => p?.Strings.Count ?? 0); // or we can use mppt.Sum(p => p.NbrOfStrings)
var nStrings = "x" + totalStrings;
var pvBox = TextBlock.FromString($"PV {nStrings}").Box();
var pvToBus = Flow.Vertical(i);
@ -486,15 +484,15 @@ public static class Topology
}
//We are fake using the ampt instead of PvOnAc, We dont have a Pv on Ac at the moment and we don't have it classes :TODO
public static DcPowerDevice? CalculateAcDcToDcLink(AmptStatus? pvOnDc, DcDcDevicesRecord? dcDc, AcDcDevicesRecord acDc)
public static DcPowerDevice? CalculateAcDcToDcLink(IReadOnlyList<AmptStatus?> pvOnDc, DcDcDevicesRecord? dcDc, AcDcDevicesRecord acDc)
{
var i = pvOnDc?.Dc.Power;
var i = pvOnDc?.Sum(p => p?.Dc.Power ?? 0);
var k = dcDc?.Dc.Link.Power; // We don't check on the DcDc because this device is mandatory
var g = acDc?.Dc.Power;
if (i is null || k is null )
{
return new DcPowerDevice { Power = g };
return new DcPowerDevice { Power = g ?? 0 };
}
var h = -(i - k); // [eq4]
@ -517,10 +515,10 @@ public static class Topology
return new AcPowerDevice { Power = d };
}
public static DcPowerDevice? CalculateDcLoad(AcDcDevicesRecord? acDc, AmptStatus? pvOnDc, DcDcDevicesRecord? dcDc)
public static DcPowerDevice? CalculateDcLoad(AcDcDevicesRecord? acDc, IReadOnlyList<AmptStatus?> pvOnDc, DcDcDevicesRecord? dcDc)
{
var h = acDc?.Dc.Power; // We don't check on the AcDc because this device is mandatory
var i = pvOnDc is not null? pvOnDc?.Dc.Power: 0;
var i = pvOnDc?.Sum(p => p?.Dc.Power ?? 0);
var k = dcDc?.Dc.Link.Power; // We don't check on the DcDc because this device is mandatory
if (h is null || i is null || k is null)