eregister for production ready

This commit is contained in:
Stoyan Zlatev
2025-10-20 12:23:42 +02:00
parent e025470341
commit 943d8458e1
33 changed files with 312 additions and 585 deletions
@@ -129,9 +129,9 @@
{
task.SirtId = this.Id;
this.tasks
.AddOrUpdate(task.ResponseAddress, addr => task, (addr, oldTask) => task);
.AddOrUpdate(task.RequestAddress, addr => task, (addr, oldTask) => task);
var bytes = this.tasks
.AddOrUpdate(address, addr => task, (addr, oldTask) => task)
.AddOrUpdate(task.ResponseAddress, addr => task, (addr, oldTask) => task)
.Start();
this.sirtStream.Write(bytes);
SIRTLogger.LogMessage($"{this.PortName}|TX: {BitConverter.ToString(bytes)}");
@@ -203,7 +203,13 @@
if (this.tasks.TryGetValue(message.Address, out var task))
{
task?.Push(message);
task.Push(message);
if (task.State == SIRTTaskState.Completed || task.State == SIRTTaskState.Cancelled)
{
this.tasks.TryRemove(task.RequestAddress, out _);
this.tasks.TryRemove(task.ResponseAddress, out _);
}
}
if (messageReceivedEvent != null)
@@ -66,7 +66,7 @@
}
}
public IEnumerable<byte[]> Read()
public IEnumerable<byte[]> ReadAsEnumerable()
{
var buffer = Array.Empty<byte>();
var length = default(int);
@@ -1,5 +1,6 @@
namespace Common.Hardware.SIRT
{
using System;
using System.Collections.Generic;
public sealed class SIRTStream
@@ -27,7 +28,7 @@
var messageLength = default(int);
var message = default(byte[]);
foreach (var bytes in this.sirtPort.Read())
foreach (var bytes in this.sirtPort.ReadAsEnumerable())
{
buffer.AddRange(bytes);
bufferLength = buffer.Count;
@@ -35,7 +36,6 @@
// until can parse messages from the buffer
while (bufferLength >= 12)
{
// reset the start index if needed
if (startIndex < 0)
{
startIndex = 0;
@@ -94,7 +94,6 @@
// in case there are more messages in the buffer
bufferLength = buffer.Count;
startIndex = 0;
}
}
}
@@ -87,8 +87,6 @@
public void SetPending()
{
this.State = SIRTTaskState.Pending;
this.awaiter.Set();
}
public void SetRunning()
@@ -110,8 +108,12 @@
public void Wait()
{
if (this.awaiter.IsSet)
{
this.awaiter.Reset();
}
this.awaiter.Wait(this.Timeout);
this.awaiter.Reset();
}
public override bool Equals(object other)
@@ -47,23 +47,26 @@
internal IEnumerable<EregisterTask> LoadInspectionInitializationTasks()
{
this.executionType = nameof(LoadInspectionInitializationTasks);
var features = parameters.LoadInspectionInitializationFeatures();
var features = this.parameters.LoadInspectionInitializationFeatures();
this.LoadProgrammingParameters(features);
if (this.runningTasks.Any())
if (features.RequestAddress > 0 && features.ResponseAddress > 0)
{
this.runningTasks.Enqueue(new EregisterChangeMeterTypeTask(features.Frequency)
this.LoadProgrammingParameters(features);
if (this.runningTasks.Any())
{
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
DelPamSemi = true,
RequestAddress = features.RequestAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
Name = "Change Meter Type"
});
this.runningTasks.Enqueue(new EregisterChangeMeterTypeTask(features.Frequency)
{
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
DelPamSemi = true,
RequestAddress = features.RequestAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
Name = "Change Meter Type"
});
}
}
return this.runningTasks.AsEnumerable();
@@ -72,39 +75,61 @@
internal IEnumerable<EregisterTask> LoadInspectionFinalizationTasks()
{
this.executionType = nameof(LoadInspectionFinalizationTasks);
var features = parameters.LoadInspectionFinalizationFeatures();
var features = this.parameters.LoadInspectionFinalizationFeatures();
this.LoadProgrammingParameters(features);
// Setting all transmision intervals at the end
this.runningTasks.Enqueue(new EregisterTask(features.Frequency)
if (features.RequestAddress > 0 && features.ResponseAddress > 0)
{
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
RequestAddress = features.ResponseAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
IsEncrypted = this.parameters.IsEncrypted,
Data = new ChangeWakeUp((WakeUpMode)this.parameters.Wake_Up_Interval)
.Append(new ChangeNumberOfLatWindows(this.parameters.LAT_Interval))
.Append(new ChangeTransmissionInterval(this.parameters.Transmission_Intervall))
.Append(new OpenMeteringTransmitionIntervalWMBus(this.parameters.OMS_Interval))
.Append(new ProvidePin(AuthLevel.II)),
Name = "0, 2, 16, 17",
});
this.LoadProgrammingParameters(features);
// The last checked DEBUG telegram
this.runningTasks.Enqueue(new EregisterCheckFinalizationTask(this.parameters, features.Frequency)
{
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
RequestAddress = features.ResponseAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
IsEncrypted = this.parameters.IsEncrypted,
});
if (this.parameters.StatusFertigung == 30)
{
// Setting all transmision intervals at the end
this.runningTasks.Enqueue(new EregisterTask(features.Frequency)
{
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
RequestAddress = features.RequestAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
IsEncrypted = this.parameters.IsEncrypted,
Data = new ChangeWakeUp((WakeUpMode)this.parameters.Wake_Up_Interval)
.Append(new ChangeNumberOfLatWindows(this.parameters.LAT_Interval))
.Append(new ChangeTransmissionInterval(this.parameters.Transmission_Intervall))
.Append(new OpenMeteringTransmitionIntervalWMBus(this.parameters.OMS_Interval))
.Append(new ProvidePin(AuthLevel.II)),
Name = "0, 2, 16, 17",
});
// The last checked DEBUG telegram
this.runningTasks.Enqueue(new EregisterCheckFinalizationTask(this.parameters, features.Frequency)
{
WakeUpModul = true,
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
RequestAddress = features.RequestAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
IsEncrypted = this.parameters.IsEncrypted,
});
// Setting all transmision intervals at the end
this.runningTasks.Enqueue(new EregisterTask(features.Frequency)
{
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
RequestAddress = features.RequestAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
IsEncrypted = this.parameters.IsEncrypted,
Data = new ChangeWakeUp((WakeUpMode)this.parameters.Wake_Up_Interval)
.Append(new ProvidePin(AuthLevel.II)),
Name = "Funk aus",
});
}
}
return this.runningTasks.AsEnumerable();
}
@@ -124,6 +149,7 @@
var lat = default(LAT);
var debug = default(DEBUG);
var semi = default(SEMI);
var awaiter = new ManualResetEventSlim(false);
while (this.runningTasks.TryPeek(out task) && task.State != SIRTTaskState.Cancelled && !cancellationToken.IsCancellationRequested)
{
@@ -131,9 +157,15 @@
while (task.State != SIRTTaskState.Completed && task.State != SIRTTaskState.Cancelled && !cancellationToken.IsCancellationRequested)
{
this.sirtHub.Start(task);
this.history.Push(task);
task.Wait();
if (this.sirtHub.Start(task))
{
this.history.Push(task);
task.Wait();
}
else
{
continue;
}
if (task.ErrorMessage != null)
{
@@ -175,14 +207,7 @@
semi = task.SEMIMessage;
}
if (!this.runningTasks.TryDequeue(out task))
{
MessageBox.Show($"Task an Ep: {task.SlotNr} mit Funkadresse: {task.RequestAddress}|{task.ResponseAddress} könnte nicht gelöscht werden."
, "Achtung"
, MessageBoxButtons.OK);
break;
}
this.runningTasks.TryDequeue(out task);
}
else if (task.State == SIRTTaskState.Cancelled)
{
@@ -197,17 +222,20 @@
return;
}
if (this.executionType == nameof(LoadInspectionFinalizationTasks))
this.state.ShouldUpdate = true; // task.FactoryState == FactoryState.Shipment;
this.state.Bemerkung = this.executionType;
this.state.Fabrikationsnummer = debug?.PCBID;
this.state.BUP = lat?.ToString()?.Replace('-', '\t');
this.state.DEBUG = debug?.ToString()?.Replace('-', '\t');
this.state.SEMI = semi?.ToString()?.Replace('-', '\t');
this.state.SemiDebugDatum = DateTime.Now;
this.state.Seriennummer = this.parameters.SerienNr;
this.state.TempAdresse = this.parameters.TempAdresse;
if (this.executionType == nameof(LoadInspectionFinalizationTasks)
&& task.FactoryState == FactoryState.Shipment
&& this.parameters.StatusFertigung == 30)
{
this.state.ShouldUpdate = true;
this.state.Bemerkung = this.executionType;
this.state.Fabrikationsnummer = debug?.PCBID;
this.state.BUP = lat?.ToString()?.Replace('-', '\t');
this.state.DEBUG = debug?.ToString()?.Replace('-', '\t');
this.state.SEMI = semi?.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;
}
@@ -255,10 +283,11 @@
this.runningTasks.Enqueue(new EregisterCheckInitializationTask(this.parameters, frequency)
{
WakeUpCmd = true,
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
RequestAddress = features.ResponseAddress,
RequestAddress = features.RequestAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
IsEncrypted = this.parameters.IsEncrypted,
@@ -271,7 +300,7 @@
SlotNr = features.SlotNr,
PoNr = features.PoNr,
SerialNr = features.SerialNr,
RequestAddress = features.ResponseAddress,
RequestAddress = features.RequestAddress,
ResponseAddress = features.ResponseAddress,
EncryptionKey = features.EncryptionKey,
IsEncrypted = this.parameters.IsEncrypted,
@@ -13,10 +13,10 @@
{
private byte[] payload;
private int countFailures;
private int runsCount = 1;
public EregisterTask(int frequency)
{
this.Timeout = 10_000;
this.DelPamSemi = true;
this.Frequency = frequency;
this.RSSI = new RSSI(0, frequency);
@@ -40,7 +40,7 @@
get => this.label;
set
{
this.label = value;
this.label = value; // $"({this.runsCount}) {value}";
var changeEvent = this.Changed;
@@ -75,12 +75,10 @@
public ErrorMessage ErrorMessage { get; protected set; }
public bool SkipWakeUpCommands { get; set; }
public override byte[] Start()
{
this.WakeUpCmd = !this.AnyTelegramReceived;
this.WakeUpModul = !this.AnyTelegramReceived;
//this.WakeUpCmd = !this.AnyTelegramReceived;
//this.WakeUpModul = !this.AnyTelegramReceived;
var payloadL = this.request.Payload.Length;
this.payload = new byte[payloadL];
@@ -103,6 +101,7 @@
this.DEBUGMessage = default(DEBUG);
this.SEMIMessage = default(SEMI);
this.AnyTelegramReceived = false;
this.runsCount++;
this.SetRunning();
@@ -240,11 +239,7 @@
{
this.P12 = new P12(response.P1);
this.Label = "AKN";
if (this.Label != "AKN")
{
this.SetPending();
}
this.SetPending();
}
else
{
@@ -219,7 +219,7 @@
public byte ActivationByThreshold { get; set; }
[CompareProperty]
// [CompareProperty]
public ushort OMS_Interval { get; set; }
public uint DisplayVolume { get; set; }
@@ -263,12 +263,11 @@
ResponseAddress = (uint)(this.IsEncrypted ? this.TempAdresse : this.Adresse),
Frequency = this.Frequency,
EncryptionKey = this.EncryptionKey.GetEncryptionKey(),
/////////////////////////////////////////////////////
ChangeMeterReading = this.DisplayVolume,
Debug = new EregisterDebugFeatures()
};
features.ChangeMeterReading = this.DisplayVolume;
features.Debug = new EregisterDebugFeatures();
if (!this.IsEbeling && !this.IsFuhzoe)
{
features.Debug.DisableOTAFirmwareUpdate = this.DisableOTA;
@@ -277,12 +276,13 @@
if (this.StatusFertigung != 30)
{
features.ChangeWakeUp = WakeUpMode.StayAwake;
features.ChangeMeterReading = 333_333_333;
features.Debug = new EregisterDebugFeatures
{
OpticalTelegram = 0
};
return features;
}
@@ -334,6 +334,7 @@
Counter = this.Data_Logging_Counter,
AlarmState = this.Data_Logging_Alarm_State,
};
features.ChangeWakeUp = WakeUpMode.SleepAutoOn;
features.ChangeFixedDateReadingSettings = new ChangeFixedDateReadingSettings
{
DayOfMonth = this.FDR_Day_Of_Data_Reading,
@@ -372,28 +373,28 @@
ResponseAddress = (uint)(this.IsEncrypted ? this.TempAdresse : this.Adresse),
Frequency = this.Frequency,
EncryptionKey = this.EncryptionKey.GetEncryptionKey(),
};
features.ChangeWakeUp = WakeUpMode.StayAwake;
features.ChangeTransmissionInterval = this.TransmissionIntervalInitialization;
features.ChangeNumberOfLatWindows = this.LatWindowsInitialization;
features.ChangeMeterReading = 111_111_111;
features.WirelessMBusMode = this.MBusStatus;
features.SetMetrologyParameters = new SetMetrologyParameters
{
UseCandIRules = this.DisallowReverseVolume,
DecimalPoint = (DecimalPointLocations)this.DecimalPoint,
FactoryCalibration = this.FactoryCalibration,
MeterSize = this.MeterSize,
OffsetFactor = this.OffsetFactor,
OffsetTime = this.OffsetTime,
Units = (MessurementUnits)this.UnitsOfMessure,
Vpp = (int)this.VolumePerPulse,
VppLED = this.VolumePerLedPulse
};
features.Debug = new EregisterDebugFeatures
{
OpticalTelegram = this.LED_ON_Minutes
/////////////////////////////////////////////////////
ChangeWakeUp = WakeUpMode.StayAwake,
ChangeTransmissionInterval = this.TransmissionIntervalInitialization,
ChangeNumberOfLatWindows = this.LatWindowsInitialization,
ChangeMeterReading = 111_111_111,
WirelessMBusMode = this.MBusStatus,
SetMetrologyParameters = new SetMetrologyParameters
{
UseCandIRules = this.DisallowReverseVolume,
DecimalPoint = (DecimalPointLocations)this.DecimalPoint,
FactoryCalibration = this.FactoryCalibration,
MeterSize = this.MeterSize,
OffsetFactor = this.OffsetFactor,
OffsetTime = this.OffsetTime,
Units = (MessurementUnits)this.UnitsOfMessure,
Vpp = (int)this.VolumePerPulse,
VppLED = this.VolumePerLedPulse
},
Debug = new EregisterDebugFeatures
{
OpticalTelegram = this.LED_ON_Minutes
}
};
return features;
@@ -23,7 +23,6 @@
public DateTime? FunkadresseDatum { get; set; }
public long Seriennummer { get; set; }
public bool ShouldUpdate { get; set; }
public Boolean ShouldUpdate { get; internal set; }
}
}