e-register overworked

This commit is contained in:
Stoyan Zlatev
2025-04-10 14:58:40 +02:00
parent 92de25455a
commit b84e63fe35
22 changed files with 295 additions and 254 deletions
@@ -63,8 +63,17 @@
this.sirtStream.Open();
}
public SIRTChannel CreateChannel(uint requestAddress, uint responseAddress, SIRTChannel channel = null)
public SIRTChannel GetOrCreateChannel(uint requestAddress, uint responseAddress, SIRTChannel channel = null)
{
if (this.requestChannels.TryGetValue(requestAddress, out channel))
{
this.responseChannels.AddOrUpdate(responseAddress, channel, (_1, _2) => channel);
}
else if (this.responseChannels.TryGetValue(responseAddress, out channel))
{
this.requestChannels.AddOrUpdate(requestAddress, channel, (_1, _2) => channel);
}
if (channel is null)
{
channel = new SIRTChannel
@@ -73,10 +82,10 @@
ResponseAddress = responseAddress,
WriteHandler = this.Write
};
}
channel = this.requestChannels.GetOrAdd(requestAddress, channel);
channel = this.responseChannels.GetOrAdd(responseAddress, channel);
this.requestChannels.GetOrAdd(requestAddress, channel);
this.responseChannels.GetOrAdd(responseAddress, channel);
}
return channel;
}
@@ -652,7 +652,7 @@
waitHandle.Set();
};
var channel = sirtBroadcaster.CreateChannel(activationTask.RequestAddress, activationTask.ResponseAddress);
var channel = sirtBroadcaster.GetOrCreateChannel(activationTask.RequestAddress, activationTask.ResponseAddress);
for (var i = 0; i < 10 && !activationCompleted; i++)
{
@@ -727,7 +727,7 @@
}
};
channel = sirtBroadcaster.CreateChannel(task.RequestAddress, task.ResponseAddress);
channel = sirtBroadcaster.GetOrCreateChannel(task.RequestAddress, task.ResponseAddress);
channel.MessageReceived += messageReceived;
for (var i = 0; i < 10 && !done; i++)
@@ -765,7 +765,7 @@
}
};
channel = sirtBroadcaster.CreateChannel(task.RequestAddress, task.ResponseAddress);
channel = sirtBroadcaster.GetOrCreateChannel(task.RequestAddress, task.ResponseAddress);
channel.MessageReceived += messageReceived;
for (var i = 0; i < 10 && !done; i++)
@@ -50,7 +50,7 @@
}
}
public SIRTChannel CreateChannel(int frequency, uint requestAddress, uint responseAddress)
public SIRTChannel GetOrCreateChannel(int frequency, uint requestAddress, uint responseAddress)
{
var channel = default(SIRTChannel);
@@ -58,7 +58,7 @@
{
if (broadcaster.Frequency == frequency)
{
channel = broadcaster.CreateChannel(requestAddress, responseAddress, channel);
channel = broadcaster.GetOrCreateChannel(requestAddress, responseAddress);
}
}
@@ -86,8 +86,6 @@
set => this.bytes[this.bytes.Length - 1] = value;
}
public bool IsValid { get; private set; } = true;
public string SirtId { get; set; }
public int Frequency { get; set; }
@@ -106,10 +104,6 @@
this.Crc = crc;
this.End = MSG_END;
}
else
{
this.IsValid = this.Crc == crc;
}
return this.bytes;
}
@@ -2,6 +2,7 @@
{
using Common.Hardware.SIRT;
using Common.Hardware.SIRT.Tasks;
using Common.Hardware.WaterMeter.eRegister.Features;
using Common.Hardware.WaterMeter.eRegister.Models;
using System;
@@ -23,6 +24,10 @@
private string executionType;
public uint Adresse { get; set; }
public uint TempAdresse { get; set; }
public Eregister(EregisterProgrammingParameters parameters, SIRTChannel sirtChannel)
{
this.parameters = parameters;
@@ -32,10 +37,6 @@
this.runningTasks = new ConcurrentQueue<EregisterTask>();
}
public uint RequestAddress => this.parameters?.RequestAddress ?? 0;
public uint ResponseAddress => this.parameters?.RequestAddress ?? 0;
public void Clear()
{
while (this.runningTasks.TryDequeue(out var _)) ;
@@ -129,11 +130,11 @@
{
lastTask = task;
while (task.State != SIRTTaskState.Completed && !cancellationToken.IsCancellationRequested)
while (task.State != SIRTTaskState.Completed && task.State != SIRTTaskState.Cancelled && !cancellationToken.IsCancellationRequested)
{
this.sirtChannel.WriteHandler(task);
this.history.Push(task);
readEvent.Wait(5000);
readEvent.Wait(10_000);
readEvent.Reset();
if (firstTask && !task.AnyTelegramReceived)
@@ -141,14 +142,9 @@
var result = MessageBox.Show($"Das Rechenwerk an Ep: {task.SlotNr} mit Funkadresse: {task.RequestAddress}|{task.ResponseAddress} sendet nicht. "
+ $"Überprüfen Sie, ob alle SIRT's sind und oder die Funkfrequenz von dem Rechenwerk ist nicht verwechselt."
, "Achtung"
, MessageBoxButtons.RetryCancel);
, MessageBoxButtons.OK);
if (result == DialogResult.Cancel)
{
task.State = SIRTTaskState.Cancelled;
break;
}
break;
}
if (task.ErrorMessage != null)
@@ -181,34 +177,45 @@
firstTask = false;
if (task.State == SIRTTaskState.Completed)
if (task.FactoryState == FactoryState.Shipment)
{
var cultureInfo = CultureInfo.InvariantCulture;
var numberStyles = NumberStyles.HexNumber | NumberStyles.AllowHexSpecifier;
this.state.GeschlossenDatum = DateTime.Now;
foreach (var rtask in this.runningTasks.AsEnumerable())
break;
}
var cultureInfo = CultureInfo.InvariantCulture;
var numberStyles = NumberStyles.HexNumber | NumberStyles.AllowHexSpecifier;
foreach (var rtask in this.runningTasks.AsEnumerable())
{
if (rtask.State == SIRTTaskState.Completed)
{
if (rtask.State == SIRTTaskState.Completed)
{
continue;
}
rtask.FactoryState = task.FactoryState;
rtask.IsEncrypted = task.IsEncrypted;
rtask.RequestAddress = task.RequestAddress;
rtask.ResponseAddress = task.ResponseAddress;
if (task.DEBUG != null)
{
rtask.RadioFWHex = task.DEBUG.RadioFWVersion;
if (int.TryParse($"{rtask.RadioFWHex}", numberStyles, cultureInfo, out var radioFWVersion))
{
rtask.RadioFWVersion = radioFWVersion;
}
}
continue;
}
else if (task.State == SIRTTaskState.Cancelled)
{
rtask.State = SIRTTaskState.Cancelled;
}
rtask.RequestAddress = task.RequestAddress;
rtask.ResponseAddress = task.ResponseAddress;
rtask.FactoryState = task.FactoryState;
rtask.IsEncrypted = task.IsEncrypted;
if (task.DEBUGMessage != null)
{
rtask.RadioFWHex = task.DEBUGMessage.RadioFWVersion;
if (int.TryParse($"{rtask.RadioFWHex}", numberStyles, cultureInfo, out var radioFWVersion))
{
rtask.RadioFWVersion = radioFWVersion;
}
}
}
if (task.State == SIRTTaskState.Completed)
{
this.runningTasks.TryDequeue(out task);
this.runningTasks.TryPeek(out task);
}
@@ -220,17 +227,22 @@
this.sirtChannel.MessageReceived -= messageReceived;
this.state.Bemerkung = this.executionType;
this.state.BUP = (lastTask.LAT ?? lastTask.BUP)?.ToString()?.Replace('-', '\t');
this.state.DEBUG = lastTask.DEBUG?.ToString()?.Replace('-', '\t');
this.state.Fabrikationsnummer = lastTask.DEBUG?.PCBID;
this.state.SEMI = lastTask.SEMI?.ToString()?.Replace('-', '\t');
this.state.SemiDebugDatum = DateTime.Now;
this.state.Seriennummer = this.parameters.SerienNr;
this.state.TempAdresse = this.parameters.TempAdresse;
if (this.state.GeschlossenDatum != null)
{
return;
}
if (this.executionType == nameof(LoadInspectionFinalizationTasks))
{
this.state.ShouldUpdate = true;
this.state.Bemerkung = this.executionType;
this.state.BUP = (lastTask.LATMessage ?? lastTask.BUPMessage)?.ToString()?.Replace('-', '\t');
this.state.DEBUG = lastTask.DEBUGMessage?.ToString()?.Replace('-', '\t');
this.state.Fabrikationsnummer = lastTask.DEBUGMessage?.PCBID;
this.state.SEMI = lastTask.SEMIMessage?.ToString()?.Replace('-', '\t');
this.state.SemiDebugDatum = DateTime.Now;
this.state.Seriennummer = this.parameters.SerienNr;
this.state.TempAdresse = this.parameters.TempAdresse;
this.state.FunkadresseDatum = DateTime.Now;
this.state.GeschlossenDatum = DateTime.Now;
}
@@ -242,23 +254,20 @@
var frequency = this.parameters.Frequency;
// Determinates the radio address of the end point and the encryption status
this.runningTasks.Enqueue(new EregisterTask(frequency)
{
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
DelPamSemi = true,
WakeUpCmd = true,
DelPamSemi = true,
RequestAddress = features.RequestAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
Name = "Dummy PAM"
});
if (this.executionType == nameof(LoadInspectionInitializationTasks))
{
// Determinates the state of the endpoint
this.runningTasks.Enqueue(new EregisterCheckInitializationTask(this.parameters, frequency)
{
SlotNr = features.SlotNr,
@@ -24,7 +24,7 @@
foreach (var parameters in parametersList)
{
var channel = this.sirtHub.CreateChannel(parameters.Frequency, parameters.RequestAddress, parameters.ResponseAddress);
var channel = this.sirtHub.GetOrCreateChannel(parameters.Frequency, (uint)parameters.TempAdresse, (uint)parameters.Adresse);
var eregister = new Eregister(parameters, channel);
this.eregisters.Add(eregister);
@@ -39,7 +39,7 @@
foreach (var parameters in parametersList)
{
var channel = this.sirtHub.CreateChannel(parameters.Frequency, parameters.RequestAddress, parameters.ResponseAddress);
var channel = this.sirtHub.GetOrCreateChannel(parameters.Frequency, (uint)parameters.TempAdresse, (uint)parameters.Adresse);
var eregister = new Eregister(parameters, channel);
this.eregisters.Add(eregister);
@@ -48,23 +48,36 @@
}
}
public Task StartProgrammingAsync(CancellationToken cancellationToken)
public void StartProgrammingAsync(CancellationToken cancellationToken)
{
var tasks = new List<Task>();
foreach (var eregister in this.eregisters)
{
tasks.Add(Task.Run(() => eregister.StartProgrammingAsync(cancellationToken), cancellationToken));
var task = Task.Factory.StartNew(() =>
{
eregister.StartProgrammingAsync(cancellationToken);
}
, cancellationToken)
.ContinueWith(t =>
{
if (t.Exception != null)
{
// TODO: exception logging
}
});
tasks.Add(task);
}
return Task.WhenAll(tasks);
Task.WaitAll(tasks.ToArray(), cancellationToken);
}
public void StopProgramming()
{
foreach (var eregister in this.eregisters)
{
this.sirtHub.ClearChannels(eregister.RequestAddress, eregister.ResponseAddress);
this.sirtHub.ClearChannels(eregister.TempAdresse, eregister.Adresse);
eregister.Clear();
}
@@ -28,7 +28,6 @@
this.Data = meterTypeCmd
.Append(new ProvidePin { AuthLevel = AuthLevel.III })
.ToByteArray();
this.NotifyChanged();
return base.Run();
@@ -39,7 +39,7 @@
var errors = string.Empty;
if (this.DEBUG != null && this.SEMI != null)
if (this.DEBUGMessage != null && this.SEMIMessage != null)
{
var responseParameters = this.GetProgrammingParameters();
var comparebleProperties = typeof(EregisterProgrammingParameters)
@@ -89,31 +89,31 @@
private EregisterProgrammingParameters GetProgrammingParameters()
{
var alarms = new AlarmsMask(this.SEMI.AlarmActiveInformation);
var alarms = new AlarmsMask(this.SEMIMessage.AlarmActiveInformation);
var dataLogContent = new ChangeDataLoggerSettings();
dataLogContent.SetLogContent(this.SEMI.LogContent);
dataLogContent.SetLogContent(this.SEMIMessage.LogContent);
var fdrLogContent = new ChangeDataLoggerSettings();
fdrLogContent.SetLogContent(this.SEMI.FixedDateReadingContent);
fdrLogContent.SetLogContent(this.SEMIMessage.FixedDateReadingContent);
var leakage = this.SEMI.LeakageDetectionParameters;
var leakage = this.SEMIMessage.LeakageDetectionParameters;
var leakagePeriod = leakage.GetBitsLE().GetByteLE(0, 3);
var leakageTreshold = (leakage - leakagePeriod) / (int)Math.Pow(2, 3);
var brokenPipe = this.SEMI.BrokenPipeDetectionParameters;
var brokenPipe = this.SEMIMessage.BrokenPipeDetectionParameters;
var brokenPipePeriod = brokenPipe.GetBitsLE().GetByteLE(0, 3);
var brokenPipeTreshold = (brokenPipe - brokenPipePeriod) / (int)Math.Pow(2, 3);
var parameters = new EregisterProgrammingParameters
{
VolumePerLedPulse = this.DEBUG.VolumePerLedPulse,
VolumePerPulse = (uint)this.DEBUG.VolumePerPulse,
OffsetFactor = (byte)this.DEBUG.OffsetFactor,
OffsetTime = this.DEBUG.OffsetTime,
FactoryCalibration = (byte)(this.DEBUG.FactoryCalibration * 10),
UnitsOfMessureSEMI = (byte)this.SEMI.Units,
MeterSize = this.SEMI.MeterSize,
VolumePerLedPulse = this.DEBUGMessage.VolumePerLedPulse,
VolumePerPulse = (uint)this.DEBUGMessage.VolumePerPulse,
OffsetFactor = (byte)this.DEBUGMessage.OffsetFactor,
OffsetTime = this.DEBUGMessage.OffsetTime,
FactoryCalibration = (byte)(this.DEBUGMessage.FactoryCalibration * 10),
UnitsOfMessureSEMI = (byte)this.SEMIMessage.Units,
MeterSize = this.SEMIMessage.MeterSize,
Alarm_Backflow = alarms.Backflow,
Alarm_Broken_Pipe = alarms.BrokenPipe,
Alarm_Leakage = alarms.Leak,
@@ -122,8 +122,8 @@
Alarm_Medium_Absent = alarms.MediumAbsent,
Alarm_Metrology_Unavailable = alarms.MetrologyUnavailable,
Alarm_Specific_Error = alarms.SpecificError,
MeterId = this.SEMI.MeterID,
Data_Logging_Period = this.SEMI.LoggingInterval,
MeterId = this.SEMIMessage.MeterID,
Data_Logging_Period = this.SEMIMessage.LoggingInterval,
Data_Logging_Alarm_State = dataLogContent.AlarmState,
Data_Logging_Backward_Volume = dataLogContent.BackwardVolume,
Data_Logging_Broken_Pipe_Flow = dataLogContent.BrokenPipeFlow,
@@ -137,14 +137,14 @@
Data_Logging_Time_Of_Maximum_Flow = dataLogContent.TimeOfMaximumFlow,
Data_Logging_Time_Of_Minimum_Flow = dataLogContent.TimeOfMinimumFlow,
Data_Logging_Time_Of_Peak_Flow = dataLogContent.TimeOfPeakFlow,
History_Error_Limits_Days = this.SEMI.HistoricalErrorLimit,
CustomerSpecificText = this.SEMI.CustomerSpecificText,
DisplayVolume = this.SEMI.DisplayVolume,
History_Error_Limits_Days = this.SEMIMessage.HistoricalErrorLimit,
CustomerSpecificText = this.SEMIMessage.CustomerSpecificText,
DisplayVolume = this.SEMIMessage.DisplayVolume,
LeakagePeriod = leakagePeriod,
LeakageThreshold = (byte)leakageTreshold,
BrokenPipePeriod = brokenPipePeriod,
BrokenPipeThreshold = (byte)brokenPipeTreshold,
FDR_Day_Of_Data_Reading = this.SEMI.DayOfMonth,
FDR_Day_Of_Data_Reading = this.SEMIMessage.DayOfMonth,
FDR_Alarm_State = fdrLogContent.AlarmState,
FDR_Backward_Volume = fdrLogContent.BackwardVolume,
FDR_Broken_Pipe_Flow = fdrLogContent.BrokenPipeFlow,
@@ -158,10 +158,10 @@
FDR_Time_Of_Maximum_Flow = fdrLogContent.TimeOfMaximumFlow,
FDR_Time_Of_Minimum_Flow = fdrLogContent.TimeOfMinimumFlow,
FDR_Time_Of_Peak_Flow = fdrLogContent.TimeOfPeakFlow,
Transmission_Intervall = (byte)this.SEMI.TransmissionInterval,
LAT_Interval = this.SEMI.LATInterval,
MBusStatus = this.SEMI.MBusStatus,
Adresse = this.SEMI.Address,
Transmission_Intervall = (byte)this.SEMIMessage.TransmissionInterval,
LAT_Interval = this.SEMIMessage.LATInterval,
MBusStatus = this.SEMIMessage.MBusStatus,
Adresse = this.SEMIMessage.Address,
};
return parameters;
@@ -37,22 +37,22 @@
message.AppendLine();
message.AppendLine();
if (this.DEBUG != null && this.SEMI != null)
if (this.DEBUGMessage != null && this.SEMIMessage != null)
{
uint min = 0x02000000;
if (this.DEBUG.BatterySeconds > min)
if (this.DEBUGMessage.BatterySeconds > min)
{
var over = (this.DEBUG.BatterySeconds - min) / 60D / 60D / 24D;
var over = (this.DEBUGMessage.BatterySeconds - min) / 60D / 60D / 24D;
message.AppendLine();
message.AppendLine($"- Das Rechenwerk ist um {over:0.0000} Tage älter als erlaubt. Bitte informieren Sie die Linienleitung und QS.");
}
if (this.SEMI.BatteryRemainingYears <= this.parameters.MinBatteryRemainingYears)
if (this.SEMIMessage.BatteryRemainingYears <= this.parameters.MinBatteryRemainingYears)
{
message.AppendLine();
message.AppendLine($"- Die Batterielaufzeit ({this.SEMI.BatteryRemainingYears}) liegt unter dem angegebenen Minimum von ({this.parameters.MinBatteryRemainingYears}). ");
message.AppendLine($"- Die Batterielaufzeit ({this.SEMIMessage.BatteryRemainingYears}) liegt unter dem angegebenen Minimum von ({this.parameters.MinBatteryRemainingYears}). ");
}
// Min metrology FW version (>= 1108) CSD dependent
@@ -61,7 +61,7 @@
var culture = CultureInfo.CurrentCulture;
var numberStyle = NumberStyles.HexNumber | NumberStyles.AllowHexSpecifier;
var minParsed = int.TryParse(this.parameters.MinMetrologyFWVersion, numberStyle, culture, out var minFW);
var curParsed = int.TryParse(this.DEBUG.MetrologyFWVersion, numberStyle, culture, out var curFW);
var curParsed = int.TryParse(this.DEBUGMessage.MetrologyFWVersion, numberStyle, culture, out var curFW);
if (minFW > curFW)
{
@@ -73,20 +73,20 @@
// All, for production available radio & metrology FW versions.
if (!string.IsNullOrWhiteSpace(this.parameters.FWVersionsList))
{
if (!this.parameters.FWVersionsList.Contains(this.DEBUG.MetrologyFWVersion))
if (!this.parameters.FWVersionsList.Contains(this.DEBUGMessage.MetrologyFWVersion))
{
message.AppendLine();
message.AppendLine($"- Die Metrologische FW Version ({this.DEBUG.MetrologyFWVersion}) ist nicht für Produktion freigegeben. ");
message.AppendLine($"- Die Metrologische FW Version ({this.DEBUGMessage.MetrologyFWVersion}) ist nicht für Produktion freigegeben. ");
}
if (!this.parameters.FWVersionsList.Contains(this.DEBUG.RadioFWVersion))
if (!this.parameters.FWVersionsList.Contains(this.DEBUGMessage.RadioFWVersion))
{
message.AppendLine();
message.AppendLine($"- Die Radio FW Version ({this.DEBUG.RadioFWVersion}) ist nicht für Produktion freigegeben. ");
message.AppendLine($"- Die Radio FW Version ({this.DEBUGMessage.RadioFWVersion}) ist nicht für Produktion freigegeben. ");
}
}
if (this.DEBUG.RebootCount > this.parameters.MaxRebootCount)
if (this.DEBUGMessage.RebootCount > this.parameters.MaxRebootCount)
{
message.AppendLine();
message.AppendLine($"- Der rechenwerk wurde mehr als {this.parameters.MaxRebootCount} mal rebooted.");
@@ -42,13 +42,13 @@
public P12 P12 { get; private set; }
public BUP BUP { get; private set; }
public BUP BUPMessage { get; private set; }
public LAT LAT { get; private set; }
public LAT LATMessage { get; private set; }
public DEBUG DEBUG { get; private set; }
public DEBUG DEBUGMessage { get; private set; }
public SEMI SEMI { get; protected set; }
public SEMI SEMIMessage { get; protected set; }
public bool AnyTelegramReceived { get; private set; }
@@ -69,11 +69,11 @@
var payloadLength = this.request.Payload.Length;
this.payload = new byte[payloadLength];
Array.Copy(this.request.Payload, 0, this.payload, 0, payloadLength);
Array.Copy(this.request.Payload, 0, payload, 0, payloadLength);
if (this.FactoryState == FactoryState.Shipment)
{
this.payload = new EregisterAvailableParametersParser(payload);
this.payload = new EregisterAvailableParametersParser(this.payload);
}
if (this.IsEncrypted)
@@ -81,17 +81,27 @@
this.payload = payload.EncryptRequest(this.EncryptionKey, this.RequestAddress);
}
base.Run();
this.State = SIRTTaskState.Running;
this.Timestamp = DateTimeOffset.UtcNow;
this.P12 = default(P12);
this.BUPMessage = default(BUP);
this.LATMessage = default(LAT);
this.DEBUGMessage = default(DEBUG);
this.SEMIMessage = default(SEMI);
return new SIRTMessage
var bytes = new SIRTMessage
{
Direction = this.request.Direction,
Address = this.request.Address,
Command = this.request.Command,
Payload = this.payload,
Frequency = this.Frequency,
Payload = this.payload,
P1 = this.request.P1,
P2 = this.request.P2,
};
}
.GetBytes();
return bytes;
}
public override void Push(SIRTMessage response)
@@ -124,58 +134,76 @@
if (length > 0)
{
var type = data[0];
if (this.IsEncrypted)
{
data = data.DecryptResponse(this.EncryptionKey);
}
if (type == SIRTConstants.BUP)
if (type == SIRTConstants.BUP) // 13
{
this.Label = nameof(SIRTConstants.BUP);
this.IsEncrypted = this.DEBUG.Crc != 0;
this.BUP = new BUP(data, this.P11);
this.BUPMessage = new BUP(data, this.P11);
if (this.BUPMessage.Crc != 0)
{
data = data.DecryptResponse(this.EncryptionKey);
this.BUPMessage = new BUP(data, this.P11);
this.IsEncrypted = true;
}
}
else if (type == SIRTConstants.LAT)
else if (type == SIRTConstants.LAT) // 13
{
this.Label = nameof(SIRTConstants.LAT);
this.IsEncrypted = this.DEBUG.Crc != 0;
this.LAT = new LAT(data, this.P11);
}
else if (type == SIRTConstants.DEBUG)
{
this.Label = nameof(SIRTConstants.DEBUG);
this.DEBUG = new DEBUG(data, this.P11);
this.IsEncrypted = this.DEBUG.Crc != 0;
this.FactoryState = this.DEBUG.FactoryState;
}
else if (type == SIRTConstants.SEMI)
{
this.SEMI = new SEMI(data, this.Frequency, this.P11);
this.IsEncrypted = this.DEBUG.Crc != 0;
this.Label = default(string);
this.LATMessage = new LAT(data, this.P11);
if (this.SEMI.PAMStatus == PAMStatus.OK)
if (this.LATMessage.Crc != 0)
{
if (this.request.Length > 0 && this.request.Payload[0] == Pam.GetDebug && this.DEBUG == null)
data = data.DecryptResponse(this.EncryptionKey);
this.LATMessage = new LAT(data, this.P11);
this.IsEncrypted = true;
}
}
else if (type == SIRTConstants.DEBUG) // 52
{
if (data.Length > DEBUG.MIN_LENGTH)
{
data = data.DecryptResponse(this.EncryptionKey);
this.IsEncrypted = true;
}
this.Label = nameof(SIRTConstants.DEBUG);
this.DEBUGMessage = new DEBUG(data, this.P11);
this.FactoryState = this.DEBUGMessage.FactoryState;
}
else if (type == SIRTConstants.SEMI) // 93
{
if (data.Length > SEMI.MIN_LENGTH)
{
data = data.DecryptResponse(this.EncryptionKey);
this.IsEncrypted = true;
}
this.Label = default(string);
this.SEMIMessage = new SEMI(data, this.Frequency, this.P11);
var pamStatus = this.SEMIMessage.PAMStatus;
if (pamStatus == PAMStatus.OK)
{
if (this.request.Length > 0 && this.request.Payload[0] == Pam.GetDebug && this.DEBUGMessage == null)
{
this.Label = "!DEBUG";
}
else if (this.LAT is null)
else if (this.LATMessage is null)
{
this.Label = "!LAT";
}
else
{
this.State = SIRTTaskState.Completed;
this.Label = this.SEMI.PAMStatus.ToString();
this.Label = this.SEMIMessage.PAMStatus.ToString();
}
}
else
{
this.Label = this.SEMI.PAMStatus.ToString();
this.Label = "!SEMI";
if (++this.countFailures > 3 && this.SEMI.PAMStatus == PAMStatus.EXPIREDAUTH)
if (!pamStatus.EXPIRED_AUTH && ++this.countFailures > 3)
{
this.State = SIRTTaskState.Cancelled;
}
@@ -196,7 +224,7 @@
{
this.Label = "NA";
}
this.NotifyChanged();
this.MessageReceived?.Invoke(response);
}
@@ -204,7 +232,7 @@
protected void NotifyChanged() => this.Changed?.Invoke(this);
public static implicit operator byte[] (EregisterTask task)
public static implicit operator byte[](EregisterTask task)
=> task.payload ?? Array.Empty<byte>();
}
}
@@ -27,10 +27,20 @@
public int StatusFertigung { get; set; }
public long TempAdresse { get; set; }
private long tempAdresse;
public long TempAdresse
{
get => this.tempAdresse;
set => this.tempAdresse = value % 10_000_000_000L;
}
private long adresse;
[CompareProperty]
public long Adresse { get; set; }
public long Adresse
{
get => this.adresse;
set => this.adresse = value % 10_000_000_000L;
}
public string CSD { get; set; }
@@ -240,10 +250,6 @@
public bool IsValid { get; set; } = true;
public uint RequestAddress => (uint)(this.TempAdresse % 10_000_000_000);
public uint ResponseAddress => (uint)(this.Adresse % 10_000_000_000);
internal EregisterFeatures LoadInspectionFinalizationFeatures()
{
var features = new EregisterFeatures
@@ -251,8 +257,8 @@
SlotNr = this.SlotNr,
SerialNr = this.SerienNr,
PoNr = this.FertigungsauftragNr,
RequestAddress = this.RequestAddress,
ResponseAddress = this.ResponseAddress,
RequestAddress = (uint)this.TempAdresse,
ResponseAddress = (uint)this.Adresse,
Frequency = this.Frequency,
EncryptionKey = this.EncryptionKey.GetEncryptionKey(),
};
@@ -365,14 +371,17 @@
{
Mode = (OTAMode)this.DisableOTA
};
features.Debug.SetActivationByThreshold = new SetActivationByThreshold
{
Rotations = this.ActivationByThreshold
};
features.OpenMeteringTransmitionIntervalWMBus = new OpenMeteringTransmitionIntervalWMBus
{
Seconds = this.OMS_Interval
};
features.ChangeWakeUp = new ChangeWakeUp
{
Mode = this.Wake_Up_Interval
@@ -385,14 +394,20 @@
{
Seconds = this.Transmission_Intervall,
};
features.ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows
{
N = this.LAT_Interval
};
features.ChangeSensusRFEncryptionKey = new ChangeSensusRFEncryptionKey
if (!string.IsNullOrWhiteSpace(this.EncryptionKey))
{
HexKey = this.EncryptionKey
};
features.ChangeSensusRFEncryptionKey = new ChangeSensusRFEncryptionKey
{
HexKey = this.EncryptionKey
};
}
features.Debug.ChangeState = new ChangeFactoryState
{
Mode = FactoryState.Shipment
@@ -409,8 +424,8 @@
SlotNr = this.SlotNr,
SerialNr = this.SerienNr,
PoNr = this.FertigungsauftragNr,
RequestAddress = this.RequestAddress,
ResponseAddress = this.ResponseAddress,
RequestAddress = (uint)this.TempAdresse,
ResponseAddress = (uint)this.Adresse,
Frequency = this.Frequency,
EncryptionKey = this.EncryptionKey.GetEncryptionKey(),
};
@@ -420,7 +435,6 @@
features.ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows(this.LatWindowsInitialization);
features.ChangeMeterReading = new ChangeMeterReading(111_111_111);
features.WirelessMBusMode = new WirelessMBusMode(this.MBusStatus);
// features.ChangeRadioId = new ChangeRadioId(this.ResponseAddress);
features.SetMetrologyParameters = new SetMetrologyParameters
{
UseCandIRules = this.DisallowReverseVolume,
@@ -437,7 +451,7 @@
{
OpticalTelegram = new OpticalTelegram
{
Minutes = 240
Minutes = this.LED_ON_Minutes
}
};
@@ -23,5 +23,7 @@
public DateTime? FunkadresseDatum { get; set; }
public long Seriennummer { get; set; }
public bool ShouldUpdate { get; set; }
}
}
@@ -10,6 +10,7 @@
{
this.DisplayVolume = payload.ToUInt32BE(6);
this.Alarm = new AlarmsMask(payload[10]);
this.Crc = 0;
if (payload.Length >= 13)
{
@@ -6,6 +6,8 @@
public class DEBUG : Payload
{
public const int MIN_LENGTH = 52;
public DEBUG(byte[] payload, P11 p11) : base(payload, p11)
{
this.DebugType = payload[6];
@@ -36,7 +38,7 @@
this.OffsetTime = payload[50];
this.Crc = 0;
if (payload.Length > 52)
if (payload.Length > MIN_LENGTH)
{
this.Crc = payload.ToUInt16BE(51);
}
@@ -11,14 +11,14 @@
protected Payload(byte[] payload, P11 p11)
{
this.InfoP11 = p11;
this.P11 = p11;
this.hexBytes = BitConverter.ToString(payload);
this.AppCode = (AppCode)payload[0];
this.Counter = payload[1];
this.Address = payload.ToUInt32BE(2);
}
public string InfoP11 { get; }
public P11 P11 { get; }
public AppCode AppCode { get; }
@@ -9,6 +9,8 @@
public class SEMI : BUP
{
public const int MIN_LENGTH = 91;
public SEMI(byte[] payload, int mhz, P11 p11) : base(payload, p11)
{
this.PAMStatus = new PAMStatus(payload[11]);
@@ -53,12 +55,12 @@
this.MeterSize = payload[90];
this.Crc = 0;
if (payload.Length >= 93)
if (payload.Length > MIN_LENGTH)
{
this.Crc = payload.ToUInt16BE(91);
}
}
public uint ModuleAddress { get; }
public AlarmsMask Alarms { get; }