Update program C for LED debug
This commit is contained in:
parent
c714382068
commit
546192cbab
|
@ -28,6 +28,7 @@ using InnovEnergy.Lib.Protocols.Modbus.Channels;
|
||||||
using InnovEnergy.Lib.Units;
|
using InnovEnergy.Lib.Units;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
using InnovEnergy.App.SaliMax.DataTypes;
|
using InnovEnergy.App.SaliMax.DataTypes;
|
||||||
|
using InnovEnergy.Lib.Utils.Net;
|
||||||
using static System.Int32;
|
using static System.Int32;
|
||||||
using static InnovEnergy.App.SaliMax.AggregationService.Aggregator;
|
using static InnovEnergy.App.SaliMax.AggregationService.Aggregator;
|
||||||
using static InnovEnergy.App.SaliMax.MiddlewareClasses.MiddlewareAgent;
|
using static InnovEnergy.App.SaliMax.MiddlewareClasses.MiddlewareAgent;
|
||||||
|
@ -52,6 +53,7 @@ internal static class Program
|
||||||
private static readonly Channel PvOnAcGrid;
|
private static readonly Channel PvOnAcGrid;
|
||||||
private static readonly Channel PvOnAcIsland;
|
private static readonly Channel PvOnAcIsland;
|
||||||
private static readonly Channel RelaysChannel;
|
private static readonly Channel RelaysChannel;
|
||||||
|
private static readonly Channel RelaysTsChannel;
|
||||||
private static readonly Channel BatteriesChannel;
|
private static readonly Channel BatteriesChannel;
|
||||||
|
|
||||||
private static Boolean _curtailFlag = false;
|
private static Boolean _curtailFlag = false;
|
||||||
|
@ -72,6 +74,7 @@ internal static class Program
|
||||||
? new NullChannel()
|
? new NullChannel()
|
||||||
: new TcpChannel(device);
|
: new TcpChannel(device);
|
||||||
|
|
||||||
|
|
||||||
TruConvertAcChannel = CreateChannel(d.TruConvertAcIp);
|
TruConvertAcChannel = CreateChannel(d.TruConvertAcIp);
|
||||||
TruConvertDcChannel = CreateChannel(d.TruConvertDcIp);
|
TruConvertDcChannel = CreateChannel(d.TruConvertDcIp);
|
||||||
GridMeterChannel = CreateChannel(d.GridMeterIp);
|
GridMeterChannel = CreateChannel(d.GridMeterIp);
|
||||||
|
@ -80,6 +83,7 @@ internal static class Program
|
||||||
PvOnAcGrid = CreateChannel(d.PvOnAcGrid);
|
PvOnAcGrid = CreateChannel(d.PvOnAcGrid);
|
||||||
PvOnAcIsland = CreateChannel(d.PvOnAcIsland);
|
PvOnAcIsland = CreateChannel(d.PvOnAcIsland);
|
||||||
RelaysChannel = CreateChannel(d.RelaysIp);
|
RelaysChannel = CreateChannel(d.RelaysIp);
|
||||||
|
RelaysTsChannel = CreateChannel(d.TsRelaysIp);
|
||||||
BatteriesChannel = CreateChannel(d.BatteryIp);
|
BatteriesChannel = CreateChannel(d.BatteryIp);
|
||||||
|
|
||||||
BatteryNodes = config
|
BatteryNodes = config
|
||||||
|
@ -126,19 +130,21 @@ internal static class Program
|
||||||
.Select(n => new Battery48TlDevice(BatteriesChannel, n))
|
.Select(n => new Battery48TlDevice(BatteriesChannel, n))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var batteryDevices = new Battery48TlDevices(battery48TlDevices);
|
var batteryDevices = new Battery48TlDevices(battery48TlDevices);
|
||||||
var acDcDevices = new TruConvertAcDcDevices(TruConvertAcChannel);
|
var acDcDevices = new TruConvertAcDcDevices(TruConvertAcChannel);
|
||||||
var dcDcDevices = new TruConvertDcDcDevices(TruConvertDcChannel);
|
var dcDcDevices = new TruConvertDcDcDevices(TruConvertDcChannel);
|
||||||
var gridMeterDevice = new EmuMeterDevice(GridMeterChannel);
|
var gridMeterDevice = new EmuMeterDevice(GridMeterChannel);
|
||||||
var acIslandLoadMeter = new EmuMeterDevice(IslandBusLoadChannel);
|
var acIslandLoadMeter = new EmuMeterDevice(IslandBusLoadChannel);
|
||||||
var pvOnDcDevice = new AmptDevices(PvOnDc);
|
var pvOnDcDevice = new AmptDevices(PvOnDc);
|
||||||
var pvOnAcGridDevice = new AmptDevices(PvOnAcGrid);
|
var pvOnAcGridDevice = new AmptDevices(PvOnAcGrid);
|
||||||
var pvOnAcIslandDevice = new AmptDevices(PvOnAcIsland);
|
var pvOnAcIslandDevice = new AmptDevices(PvOnAcIsland);
|
||||||
|
var saliMaxTsRelaysDevice = new RelaysDeviceAdam6060(RelaysTsChannel);
|
||||||
|
|
||||||
|
|
||||||
#if Amax
|
#if Amax
|
||||||
var saliMaxRelaysDevice = new RelaysDeviceAmax(RelaysChannel);
|
var saliMaxRelaysDevice = new RelaysDeviceAmax(RelaysChannel);
|
||||||
#else
|
#else
|
||||||
var saliMaxRelaysDevice = new RelaysDevice(RelaysChannel);
|
var saliMaxRelaysDevice = new RelaysDeviceAdam6360(RelaysChannel);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -149,6 +155,7 @@ internal static class Program
|
||||||
var acDc = acDcDevices.Read();
|
var acDc = acDcDevices.Read();
|
||||||
var dcDc = dcDcDevices.Read();
|
var dcDc = dcDcDevices.Read();
|
||||||
var relays = saliMaxRelaysDevice.Read();
|
var relays = saliMaxRelaysDevice.Read();
|
||||||
|
var tsRelays = saliMaxTsRelaysDevice.Read();
|
||||||
var loadOnAcIsland = acIslandLoadMeter.Read();
|
var loadOnAcIsland = acIslandLoadMeter.Read();
|
||||||
var gridMeter = gridMeterDevice.Read();
|
var gridMeter = gridMeterDevice.Read();
|
||||||
var pvOnDc = pvOnDcDevice.Read();
|
var pvOnDc = pvOnDcDevice.Read();
|
||||||
|
@ -169,14 +176,20 @@ internal static class Program
|
||||||
|
|
||||||
var acDcToDcLink = devices.LoadOnDc.DeviceState == DeviceState.Disabled ?
|
var acDcToDcLink = devices.LoadOnDc.DeviceState == DeviceState.Disabled ?
|
||||||
Topology.CalculateAcDcToDcLink(pvOnDc, dcDc, acDc)
|
Topology.CalculateAcDcToDcLink(pvOnDc, dcDc, acDc)
|
||||||
: new DcPowerDevice{ Power = acDc.Dc.Power};
|
: new DcPowerDevice{ Power = acDc.Dc.Power};
|
||||||
|
|
||||||
|
#if Amax
|
||||||
|
var combinedRelays = relays;
|
||||||
|
#else
|
||||||
|
var combinedRelays = new CombinedAdamRelaysRecord(tsRelays, relays);
|
||||||
|
#endif
|
||||||
|
|
||||||
return new StatusRecord
|
return new StatusRecord
|
||||||
{
|
{
|
||||||
AcDc = acDc,
|
AcDc = acDc,
|
||||||
DcDc = dcDc,
|
DcDc = dcDc,
|
||||||
Battery = battery,
|
Battery = battery,
|
||||||
Relays = relays,
|
Relays = combinedRelays,
|
||||||
GridMeter = gridMeter,
|
GridMeter = gridMeter,
|
||||||
PvOnAcGrid = pvOnAcGrid,
|
PvOnAcGrid = pvOnAcGrid,
|
||||||
PvOnAcIsland = pvOnAcIsland,
|
PvOnAcIsland = pvOnAcIsland,
|
||||||
|
@ -196,11 +209,19 @@ internal static class Program
|
||||||
void WriteControl(StatusRecord r)
|
void WriteControl(StatusRecord r)
|
||||||
{
|
{
|
||||||
if (r.Relays is not null)
|
if (r.Relays is not null)
|
||||||
|
{
|
||||||
#if Amax
|
#if Amax
|
||||||
saliMaxRelaysDevice.Write((RelaysRecordAmax)r.Relays);
|
saliMaxRelaysDevice.Write((RelaysRecordAmax)r.Relays);
|
||||||
#else
|
#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
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
acDcDevices.Write(r.AcDc);
|
acDcDevices.Write(r.AcDc);
|
||||||
dcDcDevices.Write(r.DcDc);
|
dcDcDevices.Write(r.DcDc);
|
||||||
}
|
}
|
||||||
|
@ -223,10 +244,36 @@ internal static class Program
|
||||||
Watchdog.NotifyAlive();
|
Watchdog.NotifyAlive();
|
||||||
|
|
||||||
var record = ReadStatus();
|
var record = ReadStatus();
|
||||||
|
/*
|
||||||
var currentSalimaxState = GetSalimaxStateAlarm(record);
|
if (record.Relays != null)
|
||||||
|
{
|
||||||
|
record.Relays.Do0StartPulse = true;
|
||||||
|
|
||||||
SendSalimaxStateAlarm(currentSalimaxState, record);
|
record.Relays.PulseOut0HighTime = 20000;
|
||||||
|
record.Relays.PulseOut0LowTime = 20000;
|
||||||
|
record.Relays.DigitalOutput0Mode = 2;
|
||||||
|
|
||||||
|
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.ControlConstants();
|
||||||
record.ControlSystemState();
|
record.ControlSystemState();
|
||||||
|
@ -241,7 +288,9 @@ internal static class Program
|
||||||
record.DcDc.SystemControl.ApplyDcDcDefaultSettings();
|
record.DcDc.SystemControl.ApplyDcDcDefaultSettings();
|
||||||
|
|
||||||
DistributePower(record, essControl);
|
DistributePower(record, essControl);
|
||||||
|
|
||||||
|
record.PerformLed();
|
||||||
|
|
||||||
WriteControl(record);
|
WriteControl(record);
|
||||||
|
|
||||||
$"{DateTime.Now.Round(UpdateInterval).ToUnixTime()} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine();
|
$"{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)
|
private static StatusMessage GetSalimaxStateAlarm(StatusRecord record)
|
||||||
{
|
{
|
||||||
var alarmCondition = record.DetectAlarmStates(); // this need to be emailed to support or customer
|
var alarmCondition = record.DetectAlarmStates(); // this need to be emailed to support or customer
|
||||||
|
@ -532,9 +582,11 @@ internal static class Program
|
||||||
r.AcDc.ResetAlarms();
|
r.AcDc.ResetAlarms();
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will be used for provider throttling, this example is only for either 100% or 0 %
|
// 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)
|
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)
|
if (r.GridMeter?.Ac.Power.Active == null)
|
||||||
{
|
{
|
||||||
Console.WriteLine(" No reading from Grid meter");
|
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)
|
private static Double IncreaseInverterUpperLimit(Double upperLimit, Double stepSize)
|
||||||
{
|
{
|
||||||
return upperLimit + stepSize;
|
return upperLimit + stepSize;
|
||||||
|
|
Loading…
Reference in New Issue