laatzen/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Models/EregisterProgrammingParameters.cs
2024-12-03 17:03:33 +01:00

451 lines
16 KiB
C#

namespace Common.Hardware.WaterMeter.eRegister.Models
{
using Common.Hardware.Ports;
using Common.Hardware.WaterMeter.eRegister.Features;
using Common.Hardware.WaterMeter.eRegister.Telegrams;
using System;
using System.Xml.Serialization;
[XmlRoot(nameof(EregisterProgrammingParameters))]
public class EregisterProgrammingParameters
{
[XmlAttribute("P2000_Shared_Id")]
public int SharedId { get; set; }
public int Slotno { get; set; }
public int FertigungsauftragNr { get; set; }
public int AuftragNr { get; set; }
public int PositionNr { get; set; }
public int SerienNr { get; set; }
public string KundeneigeneSerienNr { get; set; }
public int StatusFertigung { get; set; }
public long TempAdresse { get; set; }
[CompareProperty]
public long Adresse { get; set; }
public int Frequency { get; set; }
public string CSD { get; set; }
[CompareProperty]
public uint MeterId { get; set; }
[CompareProperty]
public byte MeterSize { get; set; }
[CompareProperty]
public int VolumePerPulse { get; set; }
[CompareProperty]
public int VolumePerLedPulse { get; set; }
[CompareProperty]
public byte OffsetFactor { get; set; }
[CompareProperty]
public byte OffsetTime { get; set; }
[CompareProperty]
public byte FactoryCalibration { get; set; }
public byte TransmissionIntervalInitialization { get; set; }
[CompareProperty]
public byte TransmissionIntervalFinalization { get; set; }
[CompareProperty]
public byte MBusStatus { get; set; }
public byte LatWindowsInitialization { get; set; }
[CompareProperty]
public byte LATWindowsFinalization { get; set; }
[CompareProperty]
public byte UnitsOfMessure { get; set; }
public byte DecimalPoint { get; set; }
public byte Use_CandI_Rules { get; set; }
[CompareProperty]
public bool Alarm_Low_Battery { get; set; }
[CompareProperty]
public bool Alarm_Leakage { get; set; }
[CompareProperty]
public bool Alarm_Magnetic_Tamper { get; set; }
[CompareProperty]
public bool Alarm_Metrology_Unavailable { get; set; }
[CompareProperty]
public bool Alarm_Backflow { get; set; }
[CompareProperty]
public bool Alarm_Broken_Pipe { get; set; }
[CompareProperty]
public bool Alarm_Medium_Absent { get; set; }
[CompareProperty]
public bool Alarm_Specific_Error { get; set; }
[CompareProperty]
public byte LeakagePeriod { get; set; }
public byte LeakageThreshold { get; set; }
[CompareProperty]
public byte BrokenPipePeriod { get; set; }
public byte BrokenPipeThreshold { get; set; }
[CompareProperty]
public byte History_Error_Limits_Days { get; set; }
[CompareProperty]
public ushort Data_Logging_Period { get; set; }
[CompareProperty]
public byte Data_Logging_Forward_Counter { get; set; }
[CompareProperty]
public byte Data_Logging_Time_Of_Minimum_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Minimum_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Time_Of_Broken_Pipe { get; set; }
[CompareProperty]
public byte Data_Logging_Broken_Pipe_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Current_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Time_Of_Peak_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Peak_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Time_Of_Maximum_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Maximum_Flow { get; set; }
[CompareProperty]
public byte Data_Logging_Backward_Volume { get; set; }
[CompareProperty]
public byte Data_Logging_Counter { get; set; }
[CompareProperty]
public byte Data_Logging_Alarm_State { get; set; }
[CompareProperty]
public byte FDR_Day_Of_Data_Reading { get; set; }
[CompareProperty]
public byte FDR_Forward_Counter { get; set; }
[CompareProperty]
public byte FDR_Time_Of_Minimum_Flow { get; set; }
[CompareProperty]
public byte FDR_Minimum_Flow { get; set; }
[CompareProperty]
public byte FDR_Time_Of_Broken_Pipe { get; set; }
[CompareProperty]
public byte FDR_Broken_Pipe_Flow { get; set; }
[CompareProperty]
public byte FDR_Current_Flow { get; set; }
[CompareProperty]
public byte FDR_Time_Of_Peak_Flow { get; set; }
[CompareProperty]
public byte FDR_Peak_Flow { get; set; }
[CompareProperty]
public byte FDR_Time_Of_Maximum_Flow { get; set; }
[CompareProperty]
public byte FDR_Maximum_Flow { get; set; }
[CompareProperty]
public byte FDR_Backward_Volume { get; set; }
[CompareProperty]
public byte FDR_Counter { get; set; }
[CompareProperty]
public byte FDR_Alarm_State { get; set; }
public byte PowerLevelHex { get; set; }
public byte DisableOTA { get; set; }
public byte ActivationByThreshold { get; set; }
public ushort OpenMeteringTransmissionIntervalSeconds { get; set; }
public float UTC_Offset { get; set; }
public byte Wake_Up_Interval { get; set; }
[CompareProperty]
public uint DisplayVolume { get; set; }
public bool Encrypted { get; set; }
public byte LED_On_Minutes { get; set; }
public string EncryptionKey { get; set; }
public string MinMetrologyFWVersion { get; set; }
public string FWVersionsList { get; set; }
public byte MaxRebootCount { get; set; }
public double MinBatteryRemainingYears { get; set; }
public double MinBatteryVoltage { get; set; }
[CompareProperty]
public string CustomerSpecificText { get; set; }
internal EregisterFeatures LoadCustomFeatures()
=> new EregisterFeatures
{
SlotNr = this.Slotno,
SerialNr = this.SerienNr,
PoNr = this.FertigungsauftragNr,
RequestAddress = (uint)(this.TempAdresse % 10_000_000_000),
ResponseAddress = (uint)(this.Adresse % 10_000_000_000),
Frequency = this.Frequency,
Sealed = this.Encrypted,
EncryptionKey = this.EncryptionKey.GetEncryptionKey(),
ActivateMetrologyTestMode = new ActivateMetrologyTestMode
{
Mode = 0
},
Reset = new Reset
{
Mode = 0
},
Debug = new EregisterDebugFeatures
{
RequestDebugTelegram = new RequestDebugTelegram
{
},
ChangeState = new ChangeState
{
Mode = StateModes.Production
},
OpticalTelegram = new OpticalTelegram
{
Minutes = 1
}
}
};
internal EregisterFeatures LoadInspectionFinalizationFeatures()
{
var features = new EregisterFeatures
{
SlotNr = this.Slotno,
SerialNr = this.SerienNr,
PoNr = this.FertigungsauftragNr,
RequestAddress = (uint)(this.TempAdresse % 10_000_000_000),
ResponseAddress = (uint)(this.Adresse % 10_000_000_000),
Frequency = this.Frequency,
Sealed = this.Encrypted,
EncryptionKey = this.EncryptionKey.GetEncryptionKey(),
};
if (this.StatusFertigung < 30)
{
return features;
}
features.ChangeMeterId = new ChangeMeterId(this.MeterId);
features.ChangeMeterReading = new ChangeMeterReading((uint)this.DisplayVolume);
features.SetPowerLevelSensusRF0 = new SetPowerLevel
{
Value = (byte)(this.PowerLevelHex & 127)
};
features.SetPowerLevelFlexNet0 = new SetPowerLevel
{
Value = (byte)(this.PowerLevelHex | 128)
};
features.SetPowerLevelFlexNetIII = new SetPowerLevel
{
Value = (byte)(this.PowerLevelHex | 128)
};
features.ChangeRadioId = new ChangeRadioId((uint)(this.Adresse % 10_000_000_000));
features.DeactivateAlarms = new DeactivateAlarms
{
Backflow = this.Alarm_Backflow,
BrokenPipe = this.Alarm_Broken_Pipe,
Leak = this.Alarm_Leakage,
LowBattery = this.Alarm_Low_Battery,
MagneticTamper = this.Alarm_Magnetic_Tamper,
MediumAbsent = this.Alarm_Medium_Absent,
MetrologyUnavailable = this.Alarm_Metrology_Unavailable,
SpecificError = this.Alarm_Specific_Error,
};
features.ResetAlarms = new ResetAlarms(0xFF);
features.ChangeCustomerText = new ChangeCustomerText();
features.ParameterizeLeakageDetection = new ParameterizeLeakageDetection
{
Value = (byte)(this.LeakagePeriod | (this.LeakageThreshold * (byte)Math.Pow(2, 3)))
};
features.ParameterizeBrokenPipeDetection = new ParameterizeBrokenPipeDetection
{
Value = (byte)(this.BrokenPipePeriod | (this.BrokenPipeThreshold * (byte)Math.Pow(2, 3)))
};
features.SetHistoricalErrorLimit = new SetHistoricalErrorLimit
{
Value = this.History_Error_Limits_Days
};
features.ChangeDataLoggerSettings = new ChangeDataLoggerSettings
{
TimeInterval = this.Data_Logging_Period,
ForwardCounter = this.Data_Logging_Forward_Counter,
TimeOfMinimumFlow = this.Data_Logging_Time_Of_Minimum_Flow,
MinimumFlow = this.Data_Logging_Minimum_Flow,
TimeOfBrokenPipe = this.Data_Logging_Time_Of_Broken_Pipe,
BrokenPipeFlow = this.Data_Logging_Broken_Pipe_Flow,
CurrentFlow = this.Data_Logging_Current_Flow,
TimeOfPeakFlow = this.Data_Logging_Time_Of_Peak_Flow,
PeakFlow = this.Data_Logging_Peak_Flow,
TimeOfMaximumFlow = this.Data_Logging_Time_Of_Maximum_Flow,
MaximumFlow = this.Data_Logging_Maximum_Flow,
BackwardVolume = this.Data_Logging_Backward_Volume,
Counter = this.Data_Logging_Counter,
AlarmState = this.Data_Logging_Alarm_State,
};
features.ChangeFixedDateReadingSettings = new ChangeFixedDateReadingSettings
{
DayOfMonth = this.FDR_Day_Of_Data_Reading,
ForwardCounter = this.FDR_Forward_Counter,
TimeOfMinimumFlow = this.FDR_Time_Of_Minimum_Flow,
MinimumFlow = this.FDR_Minimum_Flow,
TimeOfBrokenPipe = this.FDR_Time_Of_Broken_Pipe,
BrokenPipeFlow = this.FDR_Broken_Pipe_Flow,
CurrentFlow = this.FDR_Current_Flow,
TimeOfPeakFlow = this.FDR_Time_Of_Peak_Flow,
PeakFlow = this.FDR_Peak_Flow,
TimeOfMaximumFlow = this.FDR_Time_Of_Maximum_Flow,
MaximumFlow = this.FDR_Maximum_Flow,
BackwardVolume = this.FDR_Backward_Volume,
Counter = this.FDR_Counter,
AlarmState = this.FDR_Alarm_State,
};
features.SetDateAndTime = new SetDateAndTime
{
SecondsSince20000101 = new Epoch20000101
{
DateTime = DateTime.UtcNow.AddHours(this.UTC_Offset)
}
};
features.WirelessMBusMode = new WirelessMBusMode(this.MBusStatus);
features.Debug = new EregisterDebugFeatures
{
DisableOTAFirmwareUpdate = new DisableOTAFirmwareUpdate
{
Mode = (OTAMode)this.DisableOTA
},
//SetActivationByThreshold = new SetActivationByThreshold
//{
// Rotations = this.ActivationByThreshold
//},
//ChangeState = new ChangeState
//{
// Mode = StateModes.Shipment
//}
};
features.OpenMeteringTransmitionIntervalWMBus = new OpenMeteringTransmitionIntervalWMBus
{
Seconds = this.OpenMeteringTransmissionIntervalSeconds
};
features.ChangeSensusRFEncryptionKey = new ChangeSensusRFEncryptionKey
{
HexKey = this.EncryptionKey
};
features.ChangeTransmissionInterval = new ChangeTransmissionInterval
{
Seconds = this.TransmissionIntervalFinalization,
};
features.ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows
{
N = this.LATWindowsFinalization
};
return features;
}
internal EregisterFeatures LoadInspectionInitializationFeatures()
{
var address = (uint)(this.Adresse % 10_000_000_000);
var tempAddress = (uint)(this.TempAdresse % 10_000_000_000);
var features = new EregisterFeatures
{
SlotNr = this.Slotno,
SerialNr = this.SerienNr,
PoNr = this.FertigungsauftragNr,
RequestAddress = tempAddress,
ResponseAddress = address,
Frequency = this.Frequency,
EncryptionKey = this.EncryptionKey.GetEncryptionKey(),
ChangeWakeUp = new ChangeWakeUp(WakeUpMode.StayAwake),
ChangeTransmissionInterval = new ChangeTransmissionInterval(this.TransmissionIntervalInitialization),
ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows(this.LatWindowsInitialization),
WirelessMBusMode = new WirelessMBusMode(this.MBusStatus),
ChangeMeterReading = new ChangeMeterReading(111111111),
SetMetrologyParameters = new SetMetrologyParameters
{
UseCandIRules = this.Use_CandI_Rules == 1,
DecimalPoint = (DecimalPointLocations)this.DecimalPoint,
FactoryCalibration = this.FactoryCalibration,
MeterSize = this.MeterSize,
OffsetFactor = this.OffsetFactor,
OffsetTime = this.OffsetTime,
Units = (MessurementUnits)this.UnitsOfMessure,
Vpp = this.VolumePerPulse,
VppLED = (uint)this.VolumePerLedPulse
},
Debug = new EregisterDebugFeatures
{
SetMeterType = new SetMeterType
{
Type = (MeterTypes)this.Use_CandI_Rules
}
}
};
return features;
}
}
}