Merge remote-tracking branch 'origin/main'

This commit is contained in:
Yinyin Liu 2024-07-11 09:32:21 +02:00
commit 18f30b9abb
7 changed files with 74 additions and 101 deletions

View File

@ -1,4 +1,4 @@
#undef Amax
#define Amax
#undef GridLimit
using System.Diagnostics;
@ -28,12 +28,12 @@ using InnovEnergy.Lib.Protocols.Modbus.Channels;
using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Utils;
using InnovEnergy.App.SaliMax.DataTypes;
using static System.Int32;
using static InnovEnergy.App.SaliMax.AggregationService.Aggregator;
using static InnovEnergy.App.SaliMax.MiddlewareClasses.MiddlewareAgent;
using static InnovEnergy.Lib.Devices.Trumpf.SystemControl.DataTypes.SystemConfig;
using DeviceState = InnovEnergy.App.SaliMax.Devices.DeviceState;
#pragma warning disable IL2026
namespace InnovEnergy.App.SaliMax;
@ -448,7 +448,7 @@ internal static class Program
? SalimaxAlarmState.Red
: _salimaxAlarmState; // this will be replaced by LedState
int.TryParse(s3Bucket?.Split("-")[0], out var installationId);
TryParse(s3Bucket?.Split("-")[0], out var installationId);
var returnedStatus = new StatusMessage
{
@ -685,7 +685,7 @@ internal static class Program
var csv = status.ToCsv().LogInfo();
await RestApiSavingfile(csv);
await RestApiSavingFile(csv);
var s3Config = status.Config.S3;
@ -744,28 +744,28 @@ internal static class Program
private static void Heartbit(DateTime timeStamp)
{
var s3Bucket = Config.Load().S3?.Bucket;
int.TryParse(s3Bucket?.Split("-")[0], out var installationId);
int.TryParse(timeStamp.ToUnixTime().ToString(), out var nameOfCsvFile);
var returnedStatus = new StatusMessage
{
InstallationId = installationId,
Product = 0,
Status = _salimaxAlarmState,
Type = MessageType.Heartbit,
Timestamp = nameOfCsvFile
};
var tryParse = TryParse(s3Bucket?.Split("-")[0], out var installationId);
var parse = TryParse(timeStamp.ToUnixTime().ToString(), out var nameOfCsvFile);
if (s3Bucket != null)
RabbitMqManager.InformMiddleware(returnedStatus);
if (tryParse)
{
var returnedStatus = new StatusMessage
{
InstallationId = installationId,
Product = 0, // Salimax is always 0
Status = _salimaxAlarmState,
Type = MessageType.Heartbit,
Timestamp = nameOfCsvFile
};
if (s3Bucket != null)
RabbitMqManager.InformMiddleware(returnedStatus);
}
}
private static Byte[] CompresseBytes(String csvToSend)
{
//Compress CSV data to a byte array
byte[] compressedBytes;
Byte[] compressedBytes;
using (var memoryStream = new MemoryStream())
{
//Create a zip directory and put the compressed file inside
@ -785,7 +785,7 @@ internal static class Program
return compressedBytes;
}
private static async Task RestApiSavingfile(String csv)
private static async Task RestApiSavingFile(String csv)
{
// This is for the Rest API
// Check if the directory exists, and create it if it doesn't

View File

@ -15,25 +15,26 @@ public static class Config
public static TimeSpan TcpTimeout { get; } = TimeSpan.FromSeconds(2);
private const UInt16 FactorKwToW = 1000;
public static readonly TimeSpan UpdatePeriod = TimeSpan.FromSeconds(1);
public static readonly IReadOnlyList<Signal> Signals = new List<Signal>
{
new Signal(s => s._CurrentL1, "/Ac/L1/Current", "0.0 A"),
new Signal(s => s._CurrentL2, "/Ac/L2/Current", "0.0 A"),
new Signal(s => s._CurrentL3, "/Ac/L3/Current", "0.0 A"),
new Signal(s => s._CurrentL1 + s._CurrentL2 + s._CurrentL3, "/Ac/Current", "0.0 A"),
new Signal(s => s.CurrentL1, "/Ac/L1/Current", "0.0 A"),
new Signal(s => s.CurrentL2, "/Ac/L2/Current", "0.0 A"),
new Signal(s => s.CurrentL3, "/Ac/L3/Current", "0.0 A"),
new Signal(s => s.CurrentL1 + s.CurrentL2 + s.CurrentL3, "/Ac/Current", "0.0 A"),
new Signal(s => s._VoltageL1N, "/Ac/L1/Voltage", "0.0 V"),
new Signal(s => s._VoltageL2N, "/Ac/L2/Voltage", "0.0 V"),
new Signal(s => s._VoltageL3N, "/Ac/L3/Voltage", "0.0 V"),
new Signal(s => (s._VoltageL1N + s._VoltageL2N + s._VoltageL3N) / 3.0f, "/Ac/Voltage", "0.0 V"),
new Signal(s => s.VoltageL1N, "/Ac/L1/Voltage", "0.0 V"),
new Signal(s => s.VoltageL2N, "/Ac/L2/Voltage", "0.0 V"),
new Signal(s => s.VoltageL3N, "/Ac/L3/Voltage", "0.0 V"),
new Signal(s => (s.VoltageL1N + s.VoltageL2N + s.VoltageL3N) / 3.0f, "/Ac/Voltage", "0.0 V"),
new Signal(s => s.ActivePowerL1, "/Ac/L1/Power", "0 W"),
new Signal(s => s.ActivePowerL2, "/Ac/L2/Power", "0 W"),
new Signal(s => s.ActivePowerL3, "/Ac/L3/Power", "0 W"),
new Signal(s => s.ActivePowerL1 + s.ActivePowerL2 + s.ActivePowerL3, "/Ac/Power", "0 W"),
new Signal(s => s.ActivePowerL1 * FactorKwToW, "/Ac/L1/Power", "0 W"),
new Signal(s => s.ActivePowerL2 * FactorKwToW, "/Ac/L2/Power", "0 W"),
new Signal(s => s.ActivePowerL3 * FactorKwToW, "/Ac/L3/Power", "0 W"),
new Signal(s => s.TotalActivePower * FactorKwToW, "/Ac/Power", "0 W"),
new Signal(s => s.TotalActiveImport, "Ac/Energy/Forward", "0.00 kWh"),

View File

@ -3,7 +3,6 @@ using InnovEnergy.Lib.Devices.IEM3kGridMeter;
using InnovEnergy.Lib.Protocols.DBus;
using InnovEnergy.Lib.Protocols.Modbus.Clients;
using InnovEnergy.Lib.Utils;
using InnovEnergy.Lib.Utils.Reflection;
using InnovEnergy.Lib.Victron.VeDBus;
namespace InnovEnergy.App.SchneiderDriver;
@ -43,11 +42,11 @@ public static class SchneiderMeterDriver
var property = signal.ToVeProperty(reading);
if (property == null)
{
Console.WriteLine($"Warning: Signal {signal} produced a null property.");
// Console.WriteLine($"Warning: Signal {signal} produced a null property.");
}
else
{
Console.WriteLine($"Transformed Signal to Property: {property}");
//Console.WriteLine($"Transformed Signal to Property: {property}");
}
return property;
})
@ -55,7 +54,7 @@ public static class SchneiderMeterDriver
.Merge()
.Do(p =>
{
Console.WriteLine($"Setting property: {p}");
// Console.WriteLine($"Setting property: {p}");
properties.Set(p);
});

View File

@ -1,5 +1,6 @@
#!/bin/bash
csproj="SchneiderMeterDriver.csproj"
exe="SchneiderMeterDriver"
remote="10.2.4.114"

View File

@ -16,13 +16,11 @@ public partial class Battery250UpRecord
public Dc_ Dc => new Dc_(this);
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 AuxBitInformation_ AuxBitInformation => new AuxBitInformation_(this);
public Boolean Eoc => ParseEocReached();//Leds is { Green: On, Amber: Off, Blue : Off }; // ParseEocReached(); //
public UInt16 IoStates => _IoStates;
public UInt16 LimpBitMap => _LimpBitMap;
public String BatteryState => ParseBatteryState();
@ -61,29 +59,16 @@ public partial class Battery250UpRecord
}
public readonly struct StringActive_
{
public Boolean String1Active => (Self._LimpBitMap & 1) == 0;
public Boolean String2Active => (Self._LimpBitMap & 2) == 0;
public Boolean String3Active => (Self._LimpBitMap & 4) == 0;
public Boolean String4Active => (Self._LimpBitMap & 8) == 0;
public Boolean String5Active => (Self._LimpBitMap & 16) == 0;
internal StringActive_(Battery250UpRecord self) => Self = self;
private Battery250UpRecord Self { get; }
}
public readonly struct IoStatus_
public readonly struct AuxBitInformation_
{
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_(Battery250UpRecord self) => Self = self;
public Boolean DischargeEnabled => ((Self._IoStates >> 0) & 1) == 1;
public Boolean ChargeEnabled => ((Self._IoStates >> 1) & 1) == 1;
public Boolean WarmUpActive => ((Self._IoStates >> 2) & 1) == 1;
public Boolean TOCRequested => ((Self._IoStates >> 3) & 1) == 1;
public Boolean EOCReached => ((Self._IoStates >> 4) & 1) == 1;
internal AuxBitInformation_(Battery250UpRecord self) => Self = self;
private Battery250UpRecord Self { get; }
}

View File

@ -39,7 +39,7 @@ public partial class Battery250UpRecord
[InputRegister(1056)] private UInt16 _SerialNum2;
[InputRegister(1057)] private UInt16 _SerialNum3;
[InputRegister(1058)] private UInt16 _SerialNum4;
[InputRegister(1059)] private UInt16 _LimpBitMap;
[InputRegister(1059)] private UInt16 _defined;
[InputRegister(1060)] private UInt16 _BatteryState1;
[InputRegister(1061)] private UInt16 _BatteryState2;
@ -55,7 +55,7 @@ public partial class Battery250UpRecord
//[InputRegister(1063)] private UInt16 _TotalBatteryCycle;
[InputRegister(1068)] private UInt16 _AuxBitInformation;
private LedState ParseLed(LedColor led) => (LedState)((_LedStates >> (Int32)led) & 3);

View File

@ -12,23 +12,24 @@ using Float32 = Single;
[AddressOffset(-2)] // why?
public class Iem3KGridMeterRegisters //: IAc3Meter
public class Iem3KGridMeterRegisters : IAc3Meter
{
private const Float32 ZeroBecauseReactivePowerNotSupported = 0;
// TODO
[HoldingRegister<Float32>(3054)] public Float32 ActivePowerL1;
[HoldingRegister<Float32>(3056)] public Float32 ActivePowerL2;
[HoldingRegister<Float32>(3058)] public Float32 ActivePowerL3;
[HoldingRegister<Float32>(3054)] public Float32 ActivePowerL1; // in Kw
[HoldingRegister<Float32>(3056)] public Float32 ActivePowerL2; // in Kw
[HoldingRegister<Float32>(3058)] public Float32 ActivePowerL3; // in Kw
[HoldingRegister<Float32>(3060)] public Float32 TotalActivePower; // in Kw
[HoldingRegister<Float32>(3000)] public Float32 _CurrentL1;
[HoldingRegister<Float32>(3002)] public Float32 _CurrentL2;
[HoldingRegister<Float32>(3004)] public Float32 _CurrentL3;
[HoldingRegister<Float32>(3000)] public Float32 CurrentL1;
[HoldingRegister<Float32>(3002)] public Float32 CurrentL2;
[HoldingRegister<Float32>(3004)] public Float32 CurrentL3;
//
[HoldingRegister<Float32>(3028)] public Float32 _VoltageL1N;
[HoldingRegister<Float32>(3030)] public Float32 _VoltageL2N;
[HoldingRegister<Float32>(3032)] public Float32 _VoltageL3N;
[HoldingRegister<Float32>(3028)] public Float32 VoltageL1N;
[HoldingRegister<Float32>(3030)] public Float32 VoltageL2N;
[HoldingRegister<Float32>(3032)] public Float32 VoltageL3N;
[HoldingRegister<Float32>(3518)] public Float32 ActiveEnergyImportL1;
[HoldingRegister<Float32>(3522)] public Float32 ActiveEnergyImportL2;
@ -37,45 +38,31 @@ public class Iem3KGridMeterRegisters //: IAc3Meter
[HoldingRegister<Float32>(45100)] public Float32 TotalActiveImport;
[HoldingRegister<Float32>(45102)] public Float32 TotalActiveExport;
[HoldingRegister<Float32>(3110)] private Float32 _frequency;
//
//[HoldingRegister<Float32>(3110)] private Float32 _Frequency;
//[HoldingRegister<Float32>(9012)] private Float32 _ReactivePowerL1;
//[HoldingRegister<Float32>(9014)] private Float32 _ReactivePowerL2;
//[HoldingRegister<Float32>(9016)] private Float32 _ReactivePowerL3;
//[HoldingRegister<Float32>(9022)] private Float32 _ApparentPowerL1;
//[HoldingRegister<Float32>(9024)] private Float32 _ApparentPowerL2;
//[HoldingRegister<Float32>(9026)] private Float32 _ApparentPowerL3;
/*public Ac3Bus Ac => new Ac3Bus
public Ac3Bus Ac => new Ac3Bus
{
L1 = new ()
{
Current = Abs(_CurrentL1),
Voltage = Abs(_VoltageL1N),
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, _ActivePowerL1)
Current = Abs(CurrentL1),
Voltage = Abs(VoltageL1N),
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, ActivePowerL1)
},
L2 = new ()
{
Current = Abs(_CurrentL2),
Voltage = Abs(_VoltageL2N),
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, _ActivePowerL2)
Current = Abs(CurrentL2),
Voltage = Abs(VoltageL2N),
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, ActivePowerL2)
},
L3 = new ()
{
Current = Abs(_CurrentL3),
Voltage = Abs(_VoltageL3N),
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, _ActivePowerL3)
Current = Abs(CurrentL3),
Voltage = Abs(VoltageL3N),
Phi = Atan2(ZeroBecauseReactivePowerNotSupported, ActivePowerL3)
},
Frequency = _Frequency
};*/
Frequency = _frequency
};
}