Update Battery IO Status

This commit is contained in:
atef 2024-02-06 15:22:24 +01:00
parent fa668716b3
commit 95489c1409
3 changed files with 27 additions and 22 deletions

View File

@ -106,7 +106,7 @@ public static class Controller
private static EssControl LimitDischargePower(this EssControl control, StatusRecord s)
{
var maxBatteryDischargeDelta = s.Battery?.Devices.Where(b => b.ConnectedToDcBus).Sum(b => b.MaxDischargePower) ?? 0;
var maxBatteryDischargeDelta = s.Battery?.Devices.Where(b => b.IoStatus.ConnectedToDcBus).Sum(b => b.MaxDischargePower) ?? 0;
var keepMinSocLimitDelta = s.ControlBatteryPower(s.HoldMinSocPower());
return control
@ -114,10 +114,6 @@ public static class Controller
.LimitDischargePower(keepMinSocLimitDelta , EssLimit.DischargeLimitedByMinSoc);
}
private static Double ComputePowerDelta(this StatusRecord s, EssMode mode)
{
var chargePower = s.AcDc.Devices.Sum(d => d.Status.Nominal.Power.Value);
@ -233,7 +229,7 @@ public static class Controller
private static Boolean CheckNextCalibrationTime(DateTime nextCalibrationTime)
{
var currentDateAndTime = DateTime.Now;
Console.WriteLine(" next 10 am is: " + nextCalibrationTime);
Console.WriteLine(" next 9 am is: " + nextCalibrationTime);
Console.WriteLine(" currentDateAndTime: " + currentDateAndTime);
// Check if the current time is greater than or equal to the original nextCalibrationTime
@ -250,7 +246,7 @@ public static class Controller
// Calculate the next 10 AM within the same day
var nextCalibrationTime = new DateTime(currentDateAndTime.Year, currentDateAndTime.Month, currentDateAndTime.Day, 9, 0, 0); // next 9am
// If the current time is already past 10 AM, move to the next day
// If the current time is already past 9 AM, move to the next day
if (currentDateAndTime.Hour >= 9)
{
nextCalibrationTime = nextCalibrationTime.AddDays(1);

View File

@ -464,7 +464,7 @@ internal static class Program
{
var numberOfBatteries = configFile.Devices.BatteryNodes.Length;
var dischargingCurrentByBattery = configFile.MaxBatteryDischargingCurrent / numberOfBatteries;
var numberOfConnectedBatteries = r.Battery.Devices.Where(d => d.ConnectedToDcBus).ToList().Count;
var numberOfConnectedBatteries = r.Battery.Devices.Where(d => d.IoStatus.ConnectedToDcBus).ToList().Count;
maxBatteryDischargingCurrentLive = dischargingCurrentByBattery * numberOfConnectedBatteries;
}

View File

@ -16,26 +16,21 @@ public partial class Battery48TlRecord
public Leds_ Leds => new Leds_(this);
public Temperatures_ Temperatures => new Temperatures_(this);
public StringActive_ BatteryStrings => new StringActive_(this);
public IoStatus_ IoStatus => new IoStatus_(this);
public Boolean ConnectedToDcBus => (_IoStates & 1) == 0;
public Boolean AlarmOutActive => (_IoStates & 2) == 0;
public Boolean InternalFanActive => (_IoStates & 4) == 1;
public Boolean VoltMeasurementAllowed => (_IoStates & 8) == 1;
public Boolean AuxRelayBus => (_IoStates & 16) == 0;
public Boolean RemoteStateActive => (_IoStates & 32) == 1;
public Boolean RiscActive => (_IoStates & 64) == 1;
public Boolean Eoc => Leds is { Green: On, Amber: Off, Blue : Off };
public UInt16 IoStates => _IoStates;
public String SerialNumber => $"{_SerialNum1:X4}{_SerialNum2:X4}{_SerialNum3:X4}{_SerialNum4:X4}".TrimEnd('0');
public String SerialNumber => $"{_SerialNum1:X4}{_SerialNum2:X4}{_SerialNum3:X4}{_SerialNum4:X4}".TrimEnd('0');
public String FwVersion => _FwVersion.ToString("X4");
public Strings Warnings => ParseWarnings().OrderBy(w => w).ToList();
public Strings Alarms => ParseAlarms() .OrderBy(w => w).ToList();
public String FwVersion => _FwVersion.ToString("X4");
public Strings Warnings => ParseWarnings().OrderBy(w => w).ToList();
public Strings Alarms => ParseAlarms() .OrderBy(w => w).ToList();
public Percent Soc => _Soc;
public Double SOCAh => _SOCAh;
public Percent Soc => _Soc;
public Double SOCAh => _SOCAh;
public Current BusCurrent => _BusCurrent;
//public UInt16 BusCurrentHex => _BusCurrentHex;
@ -75,6 +70,20 @@ public partial class Battery48TlRecord
private Battery48TlRecord Self { get; }
}
public readonly struct IoStatus_
{
public Boolean ConnectedToDcBus => ((Self._IoStates >> 0) & 1) == 0;
public Boolean AlarmOutActive => ((Self._IoStates >> 1) & 1) == 0;
public Boolean InternalFanActive => ((Self._IoStates >> 2) & 1) == 1;
public Boolean VoltMeasurementAllowed => ((Self._IoStates >> 3) & 1) == 1;
public Boolean AuxRelayBus => ((Self._IoStates >> 4) & 1) == 0;
public Boolean RemoteStateActive => ((Self._IoStates >> 5) & 1) == 1;
public Boolean RiscActive => ((Self._IoStates >> 6) & 1) == 1;
internal IoStatus_(Battery48TlRecord self) => Self = self;
private Battery48TlRecord Self { get; }
}
public readonly struct Temperatures_
{
public Boolean Heating => (Self._IoStates & 64) != 0;