Update program C for LED debug

This commit is contained in:
atef 2024-12-31 16:24:03 +01:00
parent c714382068
commit 546192cbab
1 changed files with 124 additions and 18 deletions

View File

@ -28,6 +28,7 @@ using InnovEnergy.Lib.Protocols.Modbus.Channels;
using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Utils;
using InnovEnergy.App.SaliMax.DataTypes;
using InnovEnergy.Lib.Utils.Net;
using static System.Int32;
using static InnovEnergy.App.SaliMax.AggregationService.Aggregator;
using static InnovEnergy.App.SaliMax.MiddlewareClasses.MiddlewareAgent;
@ -52,6 +53,7 @@ internal static class Program
private static readonly Channel PvOnAcGrid;
private static readonly Channel PvOnAcIsland;
private static readonly Channel RelaysChannel;
private static readonly Channel RelaysTsChannel;
private static readonly Channel BatteriesChannel;
private static Boolean _curtailFlag = false;
@ -72,6 +74,7 @@ internal static class Program
? new NullChannel()
: new TcpChannel(device);
TruConvertAcChannel = CreateChannel(d.TruConvertAcIp);
TruConvertDcChannel = CreateChannel(d.TruConvertDcIp);
GridMeterChannel = CreateChannel(d.GridMeterIp);
@ -80,6 +83,7 @@ internal static class Program
PvOnAcGrid = CreateChannel(d.PvOnAcGrid);
PvOnAcIsland = CreateChannel(d.PvOnAcIsland);
RelaysChannel = CreateChannel(d.RelaysIp);
RelaysTsChannel = CreateChannel(d.TsRelaysIp);
BatteriesChannel = CreateChannel(d.BatteryIp);
BatteryNodes = config
@ -134,11 +138,13 @@ internal static class Program
var pvOnDcDevice = new AmptDevices(PvOnDc);
var pvOnAcGridDevice = new AmptDevices(PvOnAcGrid);
var pvOnAcIslandDevice = new AmptDevices(PvOnAcIsland);
var saliMaxTsRelaysDevice = new RelaysDeviceAdam6060(RelaysTsChannel);
#if Amax
var saliMaxRelaysDevice = new RelaysDeviceAmax(RelaysChannel);
#else
var saliMaxRelaysDevice = new RelaysDevice(RelaysChannel);
var saliMaxRelaysDevice = new RelaysDeviceAdam6360(RelaysChannel);
#endif
@ -149,6 +155,7 @@ internal static class Program
var acDc = acDcDevices.Read();
var dcDc = dcDcDevices.Read();
var relays = saliMaxRelaysDevice.Read();
var tsRelays = saliMaxTsRelaysDevice.Read();
var loadOnAcIsland = acIslandLoadMeter.Read();
var gridMeter = gridMeterDevice.Read();
var pvOnDc = pvOnDcDevice.Read();
@ -171,12 +178,18 @@ internal static class Program
Topology.CalculateAcDcToDcLink(pvOnDc, dcDc, acDc)
: new DcPowerDevice{ Power = acDc.Dc.Power};
#if Amax
var combinedRelays = relays;
#else
var combinedRelays = new CombinedAdamRelaysRecord(tsRelays, relays);
#endif
return new StatusRecord
{
AcDc = acDc,
DcDc = dcDc,
Battery = battery,
Relays = relays,
Relays = combinedRelays,
GridMeter = gridMeter,
PvOnAcGrid = pvOnAcGrid,
PvOnAcIsland = pvOnAcIsland,
@ -196,11 +209,19 @@ internal static class Program
void WriteControl(StatusRecord r)
{
if (r.Relays is not null)
{
#if Amax
saliMaxRelaysDevice.Write((RelaysRecordAmax)r.Relays);
#else
((RelaysDevice)saliMaxRelaysDevice).Write((RelaysRecord)r.Relays);
if (r.Relays is CombinedAdamRelaysRecord adamRelays)
{
saliMaxRelaysDevice.Write(adamRelays.GetAdam6360DRecord() ?? throw new InvalidOperationException());
saliMaxTsRelaysDevice.Write(adamRelays.GetAdam6060Record() ?? throw new InvalidOperationException());
}
#endif
}
acDcDevices.Write(r.AcDc);
dcDcDevices.Write(r.DcDc);
}
@ -223,10 +244,36 @@ internal static class Program
Watchdog.NotifyAlive();
var record = ReadStatus();
/*
if (record.Relays != null)
{
record.Relays.Do0StartPulse = true;
var currentSalimaxState = GetSalimaxStateAlarm(record);
record.Relays.PulseOut0HighTime = 20000;
record.Relays.PulseOut0LowTime = 20000;
record.Relays.DigitalOutput0Mode = 2;
SendSalimaxStateAlarm(currentSalimaxState, record);
record.Relays.LedGreen = false;
record.Relays.Do0StartPulse.WriteLine(" = start pulse 0");
record.Relays.PulseOut0HighTime.WriteLine(" = PulseOut0HighTime");
record.Relays.PulseOut0LowTime.WriteLine(" = PulseOut0LowTime");
record.Relays.DigitalOutput0Mode.WriteLine(" = DigitalOutput0Mode");
record.Relays.LedGreen.WriteLine(" = LedGreen");
record.Relays.LedRed.WriteLine(" = LedRed");
}
else
{
" Relays are null".WriteLine();
}*/
SendSalimaxStateAlarm(GetSalimaxStateAlarm(record), record); // to improve
record.ControlConstants();
record.ControlSystemState();
@ -242,6 +289,8 @@ internal static class Program
DistributePower(record, essControl);
record.PerformLed();
WriteControl(record);
$"{DateTime.Now.Round(UpdateInterval).ToUnixTime()} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine();
@ -304,6 +353,7 @@ internal static class Program
}
}
// This preparing a message to send to salimax monitor
private static StatusMessage GetSalimaxStateAlarm(StatusRecord record)
{
var alarmCondition = record.DetectAlarmStates(); // this need to be emailed to support or customer
@ -535,6 +585,8 @@ internal static class Program
// This will be used for provider throttling, this example is only for either 100% or 0 %
private static void ControlPvPower(this StatusRecord r, UInt16 exportLimit = 0, UInt16 pvInstalledPower = 20)
{
// Maybe add a condition to do this only if we are in optimised Self consumption, this is not true
if (r.GridMeter?.Ac.Power.Active == null)
{
Console.WriteLine(" No reading from Grid meter");
@ -644,6 +696,60 @@ internal static class Program
});
}
private static void PerformLed(this StatusRecord record)
{
if (record.StateMachine.State == 23)
{
switch (record.EssControl.Mode)
{
case EssMode.CalibrationCharge:
record.Relays?.PerformSlowFlashingGreenLed();
break;
case EssMode.OptimizeSelfConsumption when !_curtailFlag:
record.Relays?.PerformSolidGreenLed();
break;
case EssMode.Off:
break;
case EssMode.OffGrid:
break;
case EssMode.HeatBatteries:
break;
case EssMode.ReachMinSoc:
break;
case EssMode.NoGridMeter:
break;
default:
{
if (_curtailFlag)
{
record.Relays?.PerformFastFlashingGreenLed();
}
break;
}
}
}
else if (record.Battery?.Soc != null && record.StateMachine.State != 23 && record.Battery.Soc > 50)
{
record.Relays?.PerformSolidOrangeLed();
}
else if (record.Battery?.Soc != null && record.StateMachine.State != 23 && record.Battery.Soc < 50 && record.Battery.Soc > 20)
{
record.Relays?.PerformSlowFlashingOrangeLed();
}
else if (record.Battery?.Soc != null && record.StateMachine.State != 23 && record.Battery.Soc < 20)
{
record.Relays?.PerformFastFlashingOrangeLed();
}
var criticalAlarm = record.DetectAlarmStates();
if (criticalAlarm is not null)
{
record.Relays?.PerformSolidRedLed();
}
}
private static Double IncreaseInverterUpperLimit(Double upperLimit, Double stepSize)
{
return upperLimit + stepSize;