e-register check Püfungvorbereitung und -abschluss
This commit is contained in:
@@ -9,9 +9,10 @@
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Common.Hardware.Ports</RootNamespace>
|
||||
<AssemblyName>Common.Hardware.Ports</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -24,6 +25,7 @@
|
||||
<NoWarn>IDE0003;IDE0049;</NoWarn>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@@ -32,6 +34,7 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public static class SerialDataExtensions
|
||||
{
|
||||
@@ -483,6 +484,8 @@
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(hexString))
|
||||
{
|
||||
hexString = Regex.Replace(hexString, "[^a-fA-F0-9]*", string.Empty);
|
||||
|
||||
var first = true;
|
||||
var x = 0;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
public event Action Connected;
|
||||
public event Action Disconnected;
|
||||
public event Action<string> Log;
|
||||
public event Action<string> Logging;
|
||||
|
||||
public string COMPort { get; }
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Log?.Invoke(e.ToString());
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Log?.Invoke(e.ToString());
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Log?.Invoke(e.ToString());
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
|
||||
this.readAwaiter.Reset();
|
||||
@@ -129,7 +129,7 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Log?.Invoke(e.ToString());
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
|
||||
this.readAwaiter.Reset();
|
||||
@@ -138,12 +138,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Remove()
|
||||
{
|
||||
this.Close();
|
||||
|
||||
serialPorts.TryRemove(this.COMPort, out var _);
|
||||
}
|
||||
|
||||
public void Write(byte[] bytes)
|
||||
{
|
||||
@@ -155,7 +149,7 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Log?.Invoke(e.ToString());
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +163,7 @@
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Log?.Invoke(e.ToString());
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,17 +47,23 @@
|
||||
<Compile Include="Parameters\P11.cs" />
|
||||
<Compile Include="Parameters\P12.cs" />
|
||||
<Compile Include="Parameters\P811.cs" />
|
||||
<Compile Include="Parameters\P821.cs" />
|
||||
<Compile Include="Parameters\PAMStatus.cs" />
|
||||
<Compile Include="Parameters\PamTimeout.cs" />
|
||||
<Compile Include="Parameters\RFModuleOperating.cs" />
|
||||
<Compile Include="Parameters\RSSI.cs" />
|
||||
<Compile Include="Parameters\SirtOperating.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SIRTBroadcaster.Internal.cs" />
|
||||
<Compile Include="SIRTFactory.cs" />
|
||||
<Compile Include="SIRTBroadcaster.cs" />
|
||||
<Compile Include="SIRTBroadcaster.Public.cs" />
|
||||
<Compile Include="SIRTMessage.cs" />
|
||||
<Compile Include="SIRTTask.cs" />
|
||||
<Compile Include="SIRTTask.Public.cs" />
|
||||
<Compile Include="SIRTTaskState.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="SIRTTask.Internal.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Common.Hardware.Ports\Common.Hardware.Ports.csproj">
|
||||
<Project>{9ae071c0-db12-4e09-a3c7-43f6dcd518d6}</Project>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
using System;
|
||||
|
||||
using System.Text;
|
||||
|
||||
/// <summary>
|
||||
/// Parameter P11 is given at third position of "Telegram from Air" telegram and give more detailed information about the
|
||||
@@ -172,15 +173,22 @@
|
||||
set => this.bits[7] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
=> $"{nameof(P11)}: {string.Join(string.Empty, this.bits)}"
|
||||
+ $"{Environment.NewLine}{(this.SrcChannel ? "RF modul 2" : "RF modul 1")}"
|
||||
+ (this.BothValid ? Environment.NewLine + nameof(this.BothValid) : default(string))
|
||||
+ (this.InvalidMod1 ? Environment.NewLine + "RF modul 1 data invalid" : default(string))
|
||||
+ (this.InvalidMod2 ? Environment.NewLine + "RF modul 2 data invalid" : default(string))
|
||||
+ (this.LenOverflow ? Environment.NewLine + nameof(this.LenOverflow) : default(string))
|
||||
+ (this.Attention ? Environment.NewLine + "Will look in PAM pool" : default(string))
|
||||
+ $"{Environment.NewLine}{(this.ModeRF ? "Sensus RF" : "MBus")}";
|
||||
public override string ToString()
|
||||
{
|
||||
var infoBuilder = new StringBuilder();
|
||||
infoBuilder.AppendLine(string.Join(string.Empty, this.bits));
|
||||
infoBuilder.AppendLine(this.SrcChannel ? "Source RF modul 2" : "Source RF modul 1");
|
||||
infoBuilder.AppendLine(this.BothValid ? "Both RF modules data are valid" : "One RF module data is valid");
|
||||
infoBuilder.AppendLine(this.InvalidMod1 ? "RF modul 1 data is invalid" : "RF modul 1 data is valid");
|
||||
infoBuilder.AppendLine(this.InvalidMod2 ? "RF modul 2 data is invalid" : "RF modul 2 data is valid");
|
||||
infoBuilder.AppendLine(this.LenOverflow ? "Length overflow (> 128)" : "Data length is valid");
|
||||
infoBuilder.AppendLine(this.Attention ? "Will look in PAM/RAC pool" : "No attention of PAM/RAC pool");
|
||||
infoBuilder.AppendLine(this.ModeSensus ? "Mode Sensus RF" : "Mode MBus");
|
||||
infoBuilder.AppendLine(this.ModeRF ? (!this.ModeSensus ? "T1 mode" : "Receive at F2")
|
||||
: (!this.ModeSensus ? "S1 mode" : "Receive at F1"));
|
||||
|
||||
return infoBuilder.ToString().Trim();
|
||||
}
|
||||
|
||||
public static implicit operator byte(P11 p11)
|
||||
=> p11.bits.GetByteLE();
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
public class P821
|
||||
{
|
||||
private readonly byte[] bits;
|
||||
|
||||
public P821() => this.bits = new byte[8];
|
||||
|
||||
public P821(byte p12) => this.bits = p12.GetBitsLE();
|
||||
|
||||
public P821(byte[] bits) => this.bits = bits;
|
||||
|
||||
public bool PamStruct
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator byte(P821 p11)
|
||||
=> p11.bits.GetByteLE();
|
||||
|
||||
public static implicit operator string(P821 p11)
|
||||
=> p11.ToString();
|
||||
|
||||
public static implicit operator P821(byte _byte)
|
||||
=> new P821(_byte.GetBitsLE());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
public class PAMStatus
|
||||
{
|
||||
@@ -21,31 +23,39 @@
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var status = nameof(OK);
|
||||
var value = this.bits.GetByteLE();
|
||||
var statusBuilder = new StringBuilder();
|
||||
|
||||
if ((value & 1) == 1)
|
||||
if (this.CMD_UNKNOWN)
|
||||
{
|
||||
status = nameof(CMD_UNKNOWN);
|
||||
}
|
||||
else if ((value & 2) == 2)
|
||||
{
|
||||
status = nameof(WRONG_AUTH);
|
||||
}
|
||||
else if ((value & 4) == 4)
|
||||
{
|
||||
status = nameof(EXPIRED_AUTH);
|
||||
}
|
||||
else if ((value & 8) == 8)
|
||||
{
|
||||
status = nameof(MIXED_TYPES);
|
||||
}
|
||||
else if ((value & 16) == 16)
|
||||
{
|
||||
status = nameof(OUT_OF_RANGE);
|
||||
statusBuilder.AppendLine(nameof(this.CMD_UNKNOWN));
|
||||
}
|
||||
|
||||
return status;
|
||||
if (this.WRONG_AUTH)
|
||||
{
|
||||
statusBuilder.AppendLine(nameof(this.WRONG_AUTH));
|
||||
}
|
||||
|
||||
if (this.EXPIRED_AUTH)
|
||||
{
|
||||
statusBuilder.AppendLine(nameof(this.EXPIRED_AUTH));
|
||||
}
|
||||
|
||||
if (this.MIXED_TYPES)
|
||||
{
|
||||
statusBuilder.AppendLine(nameof(this.MIXED_TYPES));
|
||||
}
|
||||
|
||||
if (this.OUT_OF_RANGE)
|
||||
{
|
||||
statusBuilder.AppendLine(nameof(this.OUT_OF_RANGE));
|
||||
}
|
||||
|
||||
if (statusBuilder.Length == 0)
|
||||
{
|
||||
statusBuilder.AppendLine(nameof(OK));
|
||||
}
|
||||
|
||||
return statusBuilder.ToString().Trim('\n', '\r');
|
||||
}
|
||||
|
||||
public static byte OK = 0;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
public class RSSI
|
||||
{
|
||||
public RSSI(byte value, int mhz)
|
||||
{
|
||||
if (mhz == 433)
|
||||
{
|
||||
this.Dbm = value * 0.5 - 140;
|
||||
this.Percent = value * 0.7333 - 57.6667;
|
||||
}
|
||||
else if (mhz == 868)
|
||||
{
|
||||
this.Dbm = value * 0.5 - 131.3;
|
||||
this.Percent = value * 0.66 - 40.316;
|
||||
}
|
||||
|
||||
if (this.Percent > 100)
|
||||
{
|
||||
this.Percent = 100;
|
||||
}
|
||||
else if (this.Percent < 0)
|
||||
{
|
||||
this.Percent = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public double Dbm { get; }
|
||||
|
||||
public double Percent { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,313 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
public partial class SIRTBroadcaster
|
||||
{
|
||||
private readonly ConcurrentDictionary<uint, ConcurrentQueue<SIRTTask>> tasks;
|
||||
private readonly ManualResetEventSlim processingWaitHandle;
|
||||
private readonly SerialPort serialPort;
|
||||
|
||||
private CancellationTokenSource cancellationTokenSource;
|
||||
private CancellationToken cancellationToken;
|
||||
|
||||
private void ActivateSIRT()
|
||||
{
|
||||
if (this.TryRun(SIRTTask.ActivateSIRT, x => x.State == SIRTTaskState.Completed))
|
||||
{
|
||||
var response = this.TryRun(SIRTTask.IdentifySIRT, x => x.Last);
|
||||
|
||||
if (response?.Length == 8)
|
||||
{
|
||||
this.HexId = BitConverter.ToString(response);
|
||||
this.Frequency = this.HexId[10] == '0' ? 868 : 433;
|
||||
|
||||
this.Activated?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Logging?.Invoke($"SIRT on {this.COMPort} not identified.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Logging?.Invoke($"SIRT on {this.COMPort} not activated.");
|
||||
}
|
||||
}
|
||||
|
||||
private ICollection<uint> GetAddressesInPamPool()
|
||||
{
|
||||
var addresses = new List<uint>();
|
||||
var task = SIRTTask.ReadPamPool;
|
||||
|
||||
if (this.TryRun(task))
|
||||
{
|
||||
var payload = task.Last;
|
||||
|
||||
if (payload?.Length == 20)
|
||||
{
|
||||
var _address = 0U;
|
||||
|
||||
for (var i = 0; i < 20; i += 4)
|
||||
{
|
||||
_address = payload.ToUInt32BE(i);
|
||||
|
||||
if (_address != uint.MinValue && _address != uint.MaxValue)
|
||||
{
|
||||
addresses.Add(_address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return addresses;
|
||||
}
|
||||
|
||||
private void OnStateChanged(SIRTTask task)
|
||||
{
|
||||
if (task.State != SIRTTaskState.Cancelled)
|
||||
{
|
||||
this.TaskRemoveEventHandlers(task);
|
||||
|
||||
if (this.tasks.TryGetValue(task.RequestAddress, out var requestTasks))
|
||||
{
|
||||
requestTasks.TryDequeue(out var _);
|
||||
}
|
||||
else if (this.tasks.TryGetValue(task.ResponseAddress, out var responseTasks))
|
||||
{
|
||||
responseTasks.TryDequeue(out var _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTaskTimeout(SIRTTask task)
|
||||
{
|
||||
var deleteRequestAddress = SIRTTask.DeleteFromPamPool(task.RequestAddress);
|
||||
|
||||
this.TryRun(deleteRequestAddress);
|
||||
}
|
||||
|
||||
private void OnTaskUpdated(SIRTTask task)
|
||||
{
|
||||
if (this.tasks.TryGetValue(task.RequestAddress, out var tasksQueue))
|
||||
{
|
||||
foreach (var _task in tasksQueue.AsEnumerable())
|
||||
{
|
||||
if (_task.State != SIRTTaskState.Pending)
|
||||
{
|
||||
_task.P1 = task.P1;
|
||||
_task.P2 = task.P2;
|
||||
_task.RequestAddress = task.RequestAddress;
|
||||
_task.ResponseAddress = task.ResponseAddress;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SerialPort_Connected()
|
||||
{
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
this.cancellationToken = this.cancellationTokenSource.Token;
|
||||
|
||||
Task.Factory.StartNew((Action)this.StartReadingMessages, this.cancellationToken);
|
||||
Task.Factory.StartNew((Action)this.ActivateSIRT, this.cancellationToken);
|
||||
|
||||
this.Connected?.Invoke();
|
||||
}
|
||||
|
||||
private void SerialPort_Disconnected()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.cancellationTokenSource?.Cancel();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.SerialPort_Logging(e.ToString());
|
||||
}
|
||||
|
||||
this.Disconnected?.Invoke();
|
||||
}
|
||||
|
||||
private void SerialPort_Logging(string e)
|
||||
=> this.Logging?.Invoke(e);
|
||||
|
||||
private void SIRTConnection_MessageReceived(SIRTMessage message)
|
||||
{
|
||||
if (this.tasks.TryGetValue(message.Address, out var tasksQueue))
|
||||
{
|
||||
if (tasksQueue.TryPeek(out var task))
|
||||
{
|
||||
task.PushResponse(message);
|
||||
}
|
||||
}
|
||||
|
||||
this.Logging?.Invoke(message.ToString());
|
||||
}
|
||||
|
||||
private void StartProcessingTasksAsync()
|
||||
{
|
||||
Task.Factory.StartNew(async state =>
|
||||
{
|
||||
var connection = state as SIRTBroadcaster;
|
||||
var totalTasksCount = 0;
|
||||
|
||||
while (!connection.cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
totalTasksCount = 0;
|
||||
|
||||
foreach (var tasksQueue in connection.tasks.Values.ToArray())
|
||||
{
|
||||
if (tasksQueue.TryPeek(out var task))
|
||||
{
|
||||
if (task.State == SIRTTaskState.Pending)
|
||||
{
|
||||
connection.serialPort.Write(task.Start());
|
||||
this.Logging?.Invoke(task.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
totalTasksCount += tasksQueue.Count;
|
||||
|
||||
await Task.Delay(10);
|
||||
}
|
||||
|
||||
if (totalTasksCount <= 0)
|
||||
{
|
||||
this.processingWaitHandle.Wait();
|
||||
this.processingWaitHandle.Reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
}, this, this.cancellationToken);
|
||||
}
|
||||
|
||||
private void StartReadingMessages()
|
||||
{
|
||||
var buffer = new List<byte>();
|
||||
int bufferLength;
|
||||
int startIX;
|
||||
int lengthIX;
|
||||
int dataLength;
|
||||
int stopIX;
|
||||
int messageLength;
|
||||
byte[] message;
|
||||
|
||||
foreach (var bytes in this.serialPort.ReadBytes())
|
||||
{
|
||||
if (bytes?.Length > 0)
|
||||
{
|
||||
buffer.AddRange(bytes);
|
||||
}
|
||||
|
||||
bufferLength = buffer.Count;
|
||||
|
||||
while (bufferLength >= 13)
|
||||
{
|
||||
startIX = buffer.IndexOf(SIRTMessage.SIRT2PC);
|
||||
|
||||
if (startIX < 0)
|
||||
{
|
||||
buffer.Clear();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
lengthIX = startIX + 8;
|
||||
|
||||
if (lengthIX >= bufferLength)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
dataLength = buffer[lengthIX];
|
||||
stopIX = lengthIX + dataLength + 3;
|
||||
|
||||
if (stopIX >= bufferLength)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (buffer[stopIX] != SIRTMessage.STOP)
|
||||
{
|
||||
buffer.RemoveRange(0, stopIX + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
messageLength = stopIX - startIX + 1;
|
||||
message = new byte[messageLength];
|
||||
|
||||
buffer.CopyTo(startIX, message, 0, messageLength);
|
||||
buffer.RemoveRange(0, startIX + messageLength);
|
||||
|
||||
this.MessageReceived?.Invoke(new SIRTMessage(message));
|
||||
}
|
||||
|
||||
bufferLength = buffer.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TaskAddEventHandlers(SIRTTask task)
|
||||
{
|
||||
task.Cancelled += this.OnStateChanged;
|
||||
task.Completed += this.OnStateChanged;
|
||||
task.Timeouted += this.OnTaskTimeout;
|
||||
task.Updated += this.OnTaskUpdated;
|
||||
}
|
||||
|
||||
private void TaskRemoveEventHandlers(SIRTTask task)
|
||||
{
|
||||
task.Cancelled -= this.OnStateChanged;
|
||||
task.Completed -= this.OnStateChanged;
|
||||
task.Timeouted -= this.OnTaskTimeout;
|
||||
task.Updated -= this.OnTaskUpdated;
|
||||
}
|
||||
|
||||
private bool TryRun<TTask>(TTask task) where TTask : SIRTTask
|
||||
=> this.TryRun(task, x => x.State == SIRTTaskState.Completed);
|
||||
|
||||
private TResult TryRun<TTask, TResult>(TTask task, Func<TTask, TResult> result) where TTask : SIRTTask
|
||||
{
|
||||
var manualResetEventSlim = new ManualResetEventSlim();
|
||||
|
||||
void taskStateChanged(SIRTTask _)
|
||||
=> manualResetEventSlim.Set();
|
||||
|
||||
void messageReceived(SIRTMessage message)
|
||||
{
|
||||
if (message.Address == task.RequestAddress)
|
||||
{
|
||||
task.PushResponse(message);
|
||||
}
|
||||
}
|
||||
|
||||
this.MessageReceived += messageReceived;
|
||||
|
||||
task.Cancelled += taskStateChanged;
|
||||
task.Completed += taskStateChanged;
|
||||
|
||||
this.serialPort.Write(task.Start());
|
||||
this.Logging?.Invoke(task.ToString());
|
||||
manualResetEventSlim.Wait(task.Timeout);
|
||||
manualResetEventSlim.Reset();
|
||||
|
||||
task.Cancelled += taskStateChanged;
|
||||
task.Completed += taskStateChanged;
|
||||
|
||||
this.MessageReceived -= messageReceived;
|
||||
|
||||
return result(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
|
||||
using Parity = System.IO.Ports.Parity;
|
||||
using StopBits = System.IO.Ports.StopBits;
|
||||
|
||||
public partial class SIRTBroadcaster
|
||||
{
|
||||
public SIRTBroadcaster(string comPort)
|
||||
{
|
||||
this.serialPort = new SerialPort(comPort, 115200, Parity.None, 8, StopBits.One);
|
||||
this.tasks = new ConcurrentDictionary<uint, ConcurrentQueue<SIRTTask>>();
|
||||
this.processingWaitHandle = new ManualResetEventSlim();
|
||||
}
|
||||
|
||||
public event Action Activated;
|
||||
public event Action Connected;
|
||||
public event Action Disconnected;
|
||||
public event Action<string> Logging;
|
||||
public event Action<SIRTMessage> MessageReceived;
|
||||
|
||||
public string COMPort => this.serialPort.COMPort;
|
||||
|
||||
public string HexId { get; protected set; }
|
||||
|
||||
public int Frequency { get; protected set; }
|
||||
|
||||
public void Close()
|
||||
{
|
||||
this.serialPort.Close();
|
||||
|
||||
this.HexId = null;
|
||||
this.Frequency = 0;
|
||||
this.serialPort.Connected -= this.SerialPort_Connected;
|
||||
this.serialPort.Disconnected -= this.SerialPort_Disconnected;
|
||||
this.serialPort.Logging -= this.SerialPort_Logging;
|
||||
this.Activated -= this.StartProcessingTasksAsync;
|
||||
this.MessageReceived -= this.SIRTConnection_MessageReceived;
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
if (!this.serialPort.IsOpen)
|
||||
{
|
||||
this.serialPort.Connected += this.SerialPort_Connected;
|
||||
this.serialPort.Disconnected += this.SerialPort_Disconnected;
|
||||
this.serialPort.Logging += this.SerialPort_Logging;
|
||||
this.Activated += this.StartProcessingTasksAsync;
|
||||
this.MessageReceived += this.SIRTConnection_MessageReceived;
|
||||
|
||||
this.serialPort.Open();
|
||||
}
|
||||
}
|
||||
|
||||
public void DequeueTasks(uint address)
|
||||
{
|
||||
if (this.tasks.TryRemove(address, out var tasksQueue))
|
||||
{
|
||||
while (tasksQueue.TryDequeue(out var task))
|
||||
{
|
||||
this.TaskRemoveEventHandlers(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EnqueueTask(SIRTTask task)
|
||||
{
|
||||
if (this.Frequency == task.Frequency)
|
||||
{
|
||||
this.TaskAddEventHandlers(task);
|
||||
|
||||
var requestTasks = this.tasks.GetOrAdd(task.RequestAddress, new ConcurrentQueue<SIRTTask>());
|
||||
|
||||
requestTasks.Enqueue(task);
|
||||
|
||||
if (task.RequestAddress != task.ResponseAddress)
|
||||
{
|
||||
this.tasks.AddOrUpdate(task.ResponseAddress, requestTasks, (k, v) => requestTasks);
|
||||
}
|
||||
|
||||
if (!this.processingWaitHandle.IsSet)
|
||||
{
|
||||
this.processingWaitHandle.Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -298,9 +298,11 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
await Task.Delay(300);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
}, this, this.cancellationToken);
|
||||
|
||||
@@ -12,6 +12,14 @@
|
||||
|
||||
public event Action<string> Log;
|
||||
|
||||
public void CloseConnection(string portName)
|
||||
{
|
||||
if (this.connections.TryGetValue(portName, out var connection))
|
||||
{
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseConnections()
|
||||
{
|
||||
foreach (var connection in this.GetConnections())
|
||||
@@ -36,7 +44,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
public SIRTBroadcaster CreateConnection(string comPort)
|
||||
public SIRTBroadcaster ConnectSIRT(string comPort)
|
||||
{
|
||||
if (!this.connections.TryGetValue(comPort, out var connection))
|
||||
{
|
||||
@@ -44,7 +52,7 @@
|
||||
|
||||
if (this.connections.TryAdd(comPort, connection))
|
||||
{
|
||||
connection.Log += message => this.Log?.Invoke(message);
|
||||
connection.Logging += message => this.Log?.Invoke(message);
|
||||
connection.Open();
|
||||
}
|
||||
else
|
||||
@@ -64,28 +72,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetPortNames()
|
||||
=> this.connections.Keys.ToArray();
|
||||
public IEnumerable<string> GetPortNames() => this.connections.Keys.ToArray();
|
||||
|
||||
public void RemoveConnection(string portName)
|
||||
{
|
||||
if (this.connections.TryRemove(portName, out var connection))
|
||||
{
|
||||
connection.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveConnections()
|
||||
{
|
||||
foreach (var connection in this.GetConnections())
|
||||
{
|
||||
connection.Remove();
|
||||
}
|
||||
|
||||
this.connections.Clear();
|
||||
}
|
||||
|
||||
private IEnumerable<SIRTBroadcaster> GetConnections()
|
||||
=> this.connections.Values.ToArray();
|
||||
private IEnumerable<SIRTBroadcaster> GetConnections() => this.connections.Values.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
using Common.Hardware.SIRT.Parameters;
|
||||
|
||||
using System;
|
||||
|
||||
@@ -103,8 +104,5 @@
|
||||
|
||||
public override string ToString()
|
||||
=> BitConverter.ToString(this.ToByteArray());
|
||||
|
||||
public static implicit operator byte[](SIRTMessage message)
|
||||
=> message.ToByteArray() ?? new byte[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using Common.Hardware.SIRT.Parameters;
|
||||
|
||||
using System;
|
||||
|
||||
public partial class SIRTTask
|
||||
{
|
||||
internal byte[] Start()
|
||||
{
|
||||
if (this.State != SIRTTaskState.Cancelled)
|
||||
{
|
||||
this.State = SIRTTaskState.Running;
|
||||
|
||||
this.timeoutTimer.Stop();
|
||||
this.timeoutTimer.Start();
|
||||
|
||||
return this.ToByteArray();
|
||||
}
|
||||
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
internal class AnswerTask : SIRTTask
|
||||
{
|
||||
public AnswerTask() : base(0, 3000)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public byte[] Last { get; private set; }
|
||||
|
||||
protected override void ProcessResponse(SIRTMessage response)
|
||||
{
|
||||
this.Last = response.Data ?? new byte[] { };
|
||||
|
||||
base.ProcessResponse(response);
|
||||
}
|
||||
}
|
||||
|
||||
internal static readonly AnswerTask ActivateSIRT = new AnswerTask
|
||||
{
|
||||
Cmd = SIRTMessage.W_REG,
|
||||
RequestAddress = 0x20000000,
|
||||
P2 = 0x05,
|
||||
Data = new byte[]
|
||||
{
|
||||
new SirtOperating { /* default */ },
|
||||
new BluetoothOperating { BtOff = true },
|
||||
new RFModuleOperating { RfOff = true },
|
||||
new RFModuleOperating { OpMode = OperatingModes.ReceiveF1TransmitSensusRFF3 },
|
||||
new PamTimeout { Minutes = 1 }
|
||||
}
|
||||
};
|
||||
|
||||
internal static readonly AnswerTask IdentifySIRT = new AnswerTask
|
||||
{
|
||||
Cmd = SIRTMessage.R_REG,
|
||||
RequestAddress = 0x11001820,
|
||||
P2 = 0x08
|
||||
};
|
||||
|
||||
internal static readonly AnswerTask ReadPamPool = new AnswerTask
|
||||
{
|
||||
Cmd = SIRTMessage.R_PAM,
|
||||
RequestAddress = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
internal static AnswerTask DeleteFromPamPool(uint address) => new AnswerTask
|
||||
{
|
||||
Cmd = SIRTMessage.W_PAM,
|
||||
P1 = new P811 { DelPamAdr = true },
|
||||
RequestAddress = address
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Timers;
|
||||
|
||||
public partial class SIRTTask
|
||||
{
|
||||
protected readonly ConcurrentStack<SIRTMessage> responses;
|
||||
protected readonly SIRTMessage request;
|
||||
protected readonly Timer timeoutTimer;
|
||||
|
||||
public SIRTTask(int frequency, int timeout = 5_000)
|
||||
{
|
||||
this.Timeout = timeout;
|
||||
this.Frequency = frequency;
|
||||
this.responses = new ConcurrentStack<SIRTMessage>();
|
||||
this.request = new SIRTMessage();
|
||||
this.timeoutTimer = new Timer
|
||||
{
|
||||
AutoReset = false,
|
||||
Enabled = false,
|
||||
Interval = this.Timeout
|
||||
};
|
||||
this.timeoutTimer.Elapsed += this.OnTimeout;
|
||||
}
|
||||
|
||||
public event Action<SIRTTask> Completed;
|
||||
public event Action<SIRTTask> Cancelled;
|
||||
public event Action<SIRTTask> Timeouted;
|
||||
public event Action<SIRTTask> Updated;
|
||||
|
||||
public byte Cmd
|
||||
{
|
||||
get => this.request.Cmd;
|
||||
protected set => this.request.Cmd = value;
|
||||
}
|
||||
|
||||
public byte P1
|
||||
{
|
||||
get => this.request.P1;
|
||||
set => this.request.P1 = value;
|
||||
}
|
||||
|
||||
public byte P2
|
||||
{
|
||||
get => this.request.P2;
|
||||
set => this.request.P2 = value;
|
||||
}
|
||||
|
||||
public uint RequestAddress
|
||||
{
|
||||
get => this.request.Address;
|
||||
set
|
||||
{
|
||||
this.request.Address = value;
|
||||
this.ResponseAddress = value;
|
||||
}
|
||||
}
|
||||
|
||||
public uint ResponseAddress { get; set; }
|
||||
|
||||
public byte[] Data
|
||||
{
|
||||
get => this.request.Data;
|
||||
set => this.request.Data = value;
|
||||
}
|
||||
|
||||
public int Timeout { get; }
|
||||
|
||||
public int Frequency { get; }
|
||||
|
||||
public SIRTTaskState State { get; protected set; }
|
||||
|
||||
public void PushResponse(SIRTMessage response)
|
||||
{
|
||||
var address = response.Address;
|
||||
|
||||
if (address == this.RequestAddress || address == this.ResponseAddress)
|
||||
{
|
||||
this.responses.Push(response);
|
||||
|
||||
if (address == this.ResponseAddress)
|
||||
{
|
||||
this.RequestAddress = this.ResponseAddress;
|
||||
|
||||
this.NotifyUpdated();
|
||||
}
|
||||
|
||||
this.ProcessResponse(response);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual byte[] ToByteArray() => this.request.ToByteArray();
|
||||
|
||||
public override string ToString() => BitConverter.ToString(this.ToByteArray());
|
||||
|
||||
protected void NotifyCancelled() => this.Cancelled?.Invoke(this);
|
||||
|
||||
protected void NotifyCompleted() => this.Completed?.Invoke(this);
|
||||
|
||||
protected void NotifyTimeouted() => this.Timeouted?.Invoke(this);
|
||||
|
||||
protected void NotifyUpdated() => this.Updated?.Invoke(this);
|
||||
|
||||
protected virtual void OnTimeout(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
this.State = SIRTTaskState.Cancelled;
|
||||
|
||||
this.NotifyCancelled();
|
||||
}
|
||||
|
||||
protected virtual void ProcessResponse(SIRTMessage response)
|
||||
{
|
||||
if (this.State == SIRTTaskState.Running)
|
||||
{
|
||||
if (response.Cmd == SIRTMessage.ACKNANSW || (response.Data.Length > 0 && response.Data[0] == SIRTMessage.SEMI))
|
||||
{
|
||||
this.State = SIRTTaskState.Completed;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.State == SIRTTaskState.Completed)
|
||||
{
|
||||
this.timeoutTimer.Stop();
|
||||
this.NotifyCompleted();
|
||||
}
|
||||
else if (this.State == SIRTTaskState.Cancelled)
|
||||
{
|
||||
this.timeoutTimer.Stop();
|
||||
this.NotifyCancelled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,6 @@
|
||||
protected readonly SIRTMessage request;
|
||||
protected readonly ConcurrentStack<SIRTMessage> responses;
|
||||
|
||||
private SIRTTask head;
|
||||
private SIRTTask prev;
|
||||
private SIRTTask next;
|
||||
private SIRTTask curr;
|
||||
|
||||
/// <param name="timeout">The tiemout in milliseconds, after the task will be cancelled.</param>
|
||||
public SIRTTask(int timeout = 5_000)
|
||||
{
|
||||
@@ -118,6 +113,13 @@
|
||||
public override string ToString()
|
||||
=> BitConverter.ToString(this.ToByteArray());
|
||||
|
||||
protected void Cancel()
|
||||
{
|
||||
this.State = SIRTTaskState.Cancelled;
|
||||
|
||||
this.Cancelled?.Invoke(this);
|
||||
}
|
||||
|
||||
protected virtual void EndReceiveMessage(SIRTMessage _)
|
||||
{
|
||||
if (this.State == SIRTTaskState.Completed)
|
||||
@@ -182,26 +184,6 @@
|
||||
P1 = new P811 { DelPamAdr = true },
|
||||
RequestAddress = address
|
||||
};
|
||||
|
||||
public void Dequeue()
|
||||
{
|
||||
this.head.head = null;
|
||||
this.head = this.head.next;
|
||||
}
|
||||
|
||||
public void Enqueue(SIRTTask task)
|
||||
{
|
||||
task.head = this.head;
|
||||
task.prev = this;
|
||||
this.next = task;
|
||||
}
|
||||
|
||||
public bool TryPeek(out SIRTTask task)
|
||||
{
|
||||
task = this.head;
|
||||
|
||||
return task != null;
|
||||
}
|
||||
}
|
||||
|
||||
public class AnswerTask : SIRTTask
|
||||
|
||||
+6
-1
@@ -43,10 +43,12 @@
|
||||
<HintPath>..\..\..\..\packages\Newtonsoft.Json.13.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
@@ -56,6 +58,8 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Eregister.cs" />
|
||||
<Compile Include="EregisterBatch.cs" />
|
||||
<Compile Include="EregisterCheckFinalizationTask.cs" />
|
||||
<Compile Include="EregisterCheckInitializationTask.cs" />
|
||||
<Compile Include="EregisterExtensions.cs" />
|
||||
<Compile Include="EregisterTask.cs" />
|
||||
<Compile Include="Features\ActivateMetrologyTestMode.cs" />
|
||||
@@ -135,6 +139,7 @@
|
||||
<Compile Include="Features\SingleBytePam.cs" />
|
||||
<Compile Include="Features\WakeUpMode.cs" />
|
||||
<Compile Include="Features\WirelessMBusMode.cs" />
|
||||
<Compile Include="Models\ComparePropertyAttribute.cs" />
|
||||
<Compile Include="Models\EregisterDebugFeatures.cs" />
|
||||
<Compile Include="Models\EregisterFeatures.cs" />
|
||||
<Compile Include="Models\EregisterProgrammingParameters.cs" />
|
||||
@@ -155,7 +160,7 @@
|
||||
<Name>Common.Hardware.Ports</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Common.Hardware.SIRT\Common.Hardware.SIRT.csproj">
|
||||
<Project>{8DE8E742-EE0A-4004-AA49-3D08D748E5AC}</Project>
|
||||
<Project>{8de8e742-ee0a-4004-aa49-3d08d748e5ac}</Project>
|
||||
<Name>Common.Hardware.SIRT</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
+78
-31
@@ -1,8 +1,8 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.WaterMeter.eRegister.Models;
|
||||
using Common.Hardware.SIRT;
|
||||
using Common.Hardware.SIRT.Parameters;
|
||||
using Common.Hardware.WaterMeter.eRegister.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -24,7 +24,7 @@
|
||||
this.completedTasks = new Queue<EregisterTask>();
|
||||
}
|
||||
|
||||
public uint Address => this.features.RequestAddress;
|
||||
public uint Address => this.features?.RequestAddress ?? 4291189262;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
@@ -32,40 +32,56 @@
|
||||
this.completedTasks.Clear();
|
||||
}
|
||||
|
||||
internal IEnumerable<EregisterTask> LoadProgrammingParameters()
|
||||
internal IEnumerable<EregisterTask> LoadCustomTasks(EregisterProgrammingParameters parameters)
|
||||
{
|
||||
this.runningTasks.Clear();
|
||||
|
||||
var pams = this.features.BuildPams();
|
||||
var wakeUP = true;
|
||||
|
||||
foreach (var pam in pams)
|
||||
{
|
||||
this.runningTasks.Enqueue(new EregisterTask
|
||||
{
|
||||
SlotNr = this.features.SlotNr,
|
||||
PoNr = this.features.PoNr,
|
||||
SerialNr = this.features.SerialNr,
|
||||
Name = pam.Key,
|
||||
P1 = new P811
|
||||
{
|
||||
DelPamSemi = true,
|
||||
WakeUpCmd = wakeUP,
|
||||
},
|
||||
RequestAddress = this.features.RequestAddress,
|
||||
ResponseAddress = this.features.ResponseAddress,
|
||||
Frequency = this.features.Frequency,
|
||||
Data = pam.Value,
|
||||
EncryptionKey = this.features.EncryptionKey
|
||||
});
|
||||
|
||||
wakeUP = false;
|
||||
}
|
||||
this.LoadProgrammingParameters();
|
||||
|
||||
return this.runningTasks.AsEnumerable();
|
||||
}
|
||||
|
||||
public void StartProgramming()
|
||||
internal IEnumerable<EregisterTask> LoadInspectionFinalizationTasks(EregisterProgrammingParameters parameters)
|
||||
{
|
||||
this.LoadProgrammingParameters();
|
||||
|
||||
this.runningTasks.Enqueue(new EregisterCheckFinalizationTask(parameters, this.features.Frequency)
|
||||
{
|
||||
SlotNr = this.features.SlotNr,
|
||||
PoNr = this.features.PoNr,
|
||||
SerialNr = this.features.SerialNr,
|
||||
P1 = new P811
|
||||
{
|
||||
DelPamSemi = true,
|
||||
},
|
||||
RequestAddress = this.features.RequestAddress,
|
||||
ResponseAddress = this.features.ResponseAddress,
|
||||
EncryptionKey = this.features.EncryptionKey
|
||||
});
|
||||
|
||||
return this.runningTasks.AsEnumerable();
|
||||
}
|
||||
|
||||
internal IEnumerable<EregisterTask> LoadInspectionInitializationTasks(EregisterProgrammingParameters parameters)
|
||||
{
|
||||
this.LoadProgrammingParameters();
|
||||
|
||||
this.runningTasks.Enqueue(new EregisterCheckInitializationTask(parameters, this.features.Frequency)
|
||||
{
|
||||
SlotNr = this.features.SlotNr,
|
||||
PoNr = this.features.PoNr,
|
||||
SerialNr = this.features.SerialNr,
|
||||
P1 = new P811
|
||||
{
|
||||
DelPamSemi = true,
|
||||
},
|
||||
RequestAddress = this.features.RequestAddress,
|
||||
ResponseAddress = this.features.ResponseAddress,
|
||||
EncryptionKey = this.features.EncryptionKey
|
||||
});
|
||||
|
||||
return this.runningTasks.AsEnumerable();
|
||||
}
|
||||
|
||||
internal void StartProgramming()
|
||||
{
|
||||
var manualResetEventSlim = new ManualResetEventSlim();
|
||||
|
||||
@@ -112,5 +128,36 @@
|
||||
manualResetEventSlim.Wait();
|
||||
manualResetEventSlim.Reset();
|
||||
}
|
||||
|
||||
private void LoadProgrammingParameters()
|
||||
{
|
||||
this.runningTasks.Clear();
|
||||
|
||||
var frequency = this.features.Frequency;
|
||||
var pams = this.features.BuildPams();
|
||||
var wakeUP = true;
|
||||
|
||||
foreach (var pam in pams)
|
||||
{
|
||||
this.runningTasks.Enqueue(new EregisterTask(frequency)
|
||||
{
|
||||
SlotNr = this.features.SlotNr,
|
||||
PoNr = this.features.PoNr,
|
||||
SerialNr = this.features.SerialNr,
|
||||
Name = pam.Key,
|
||||
P1 = new P811
|
||||
{
|
||||
DelPamSemi = true,
|
||||
WakeUpCmd = wakeUP,
|
||||
},
|
||||
RequestAddress = this.features.RequestAddress,
|
||||
ResponseAddress = this.features.ResponseAddress,
|
||||
Data = pam.Value,
|
||||
EncryptionKey = this.features.EncryptionKey
|
||||
});
|
||||
|
||||
wakeUP = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+34
-20
@@ -19,40 +19,54 @@
|
||||
this.eregisters = new List<Eregister>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 319017346: E6C88800DEB868C0D6A84880CE982840
|
||||
/// </summary>
|
||||
/// <param name="parametersList"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<IEnumerable<EregisterTask>> LoadInspectionFinalization(EregisterProgrammingParametersList parametersList)
|
||||
public IEnumerable<IEnumerable<EregisterTask>> LoadCustomTasks(EregisterProgrammingParametersList parametersList)
|
||||
{
|
||||
this.eregisters.Clear();
|
||||
|
||||
foreach (var erFeatures in parametersList.LoadInspectionFinalizationFeatures())
|
||||
foreach (var parameters in parametersList)
|
||||
{
|
||||
this.broadcaster.DequeueTasks(erFeatures.RequestAddress);
|
||||
this.eregisters.Add(new Eregister(erFeatures, this.broadcaster.EnqueueTask));
|
||||
}
|
||||
var features = parameters.LoadCustomFeatures();
|
||||
var eregister = new Eregister(features, this.broadcaster.EnqueueTask);
|
||||
|
||||
foreach (var eregister in this.eregisters)
|
||||
{
|
||||
yield return eregister.LoadProgrammingParameters();
|
||||
this.broadcaster.DequeueTasks(features.RequestAddress);
|
||||
this.broadcaster.DequeueTasks(features.ResponseAddress);
|
||||
this.eregisters.Add(eregister);
|
||||
|
||||
yield return eregister.LoadCustomTasks(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IEnumerable<EregisterTask>> LoadInspectionInitialization(EregisterProgrammingParametersList parametersList)
|
||||
public IEnumerable<IEnumerable<EregisterTask>> LoadInspectionFinalizationTasks(EregisterProgrammingParametersList parametersList)
|
||||
{
|
||||
this.eregisters.Clear();
|
||||
|
||||
foreach (var erFeatures in parametersList.LoadInspectionInitializationFeatures())
|
||||
foreach (var parameters in parametersList)
|
||||
{
|
||||
this.broadcaster.DequeueTasks(erFeatures.RequestAddress);
|
||||
this.eregisters.Add(new Eregister(erFeatures, this.broadcaster.EnqueueTask));
|
||||
}
|
||||
var features = parameters.LoadInspectionFinalizationFeatures();
|
||||
var eregister = new Eregister(features, this.broadcaster.EnqueueTask);
|
||||
|
||||
foreach (var eregister in this.eregisters)
|
||||
this.broadcaster.DequeueTasks(features.RequestAddress);
|
||||
this.broadcaster.DequeueTasks(features.ResponseAddress);
|
||||
this.eregisters.Add(eregister);
|
||||
|
||||
yield return eregister.LoadInspectionFinalizationTasks(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IEnumerable<EregisterTask>> LoadInspectionInitializationTasks(EregisterProgrammingParametersList parametersList)
|
||||
{
|
||||
this.eregisters.Clear();
|
||||
|
||||
foreach (var parameters in parametersList)
|
||||
{
|
||||
yield return eregister.LoadProgrammingParameters();
|
||||
var features = parameters.LoadInspectionInitializationFeatures();
|
||||
var eregister = new Eregister(features, this.broadcaster.EnqueueTask);
|
||||
|
||||
this.broadcaster.DequeueTasks(features.RequestAddress);
|
||||
this.broadcaster.DequeueTasks(features.ResponseAddress);
|
||||
this.eregisters.Add(eregister);
|
||||
|
||||
yield return eregister.LoadInspectionInitializationTasks(parameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
using Common.Hardware.SIRT;
|
||||
using Common.Hardware.WaterMeter.eRegister.Features;
|
||||
using Common.Hardware.WaterMeter.eRegister.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
|
||||
public class EregisterCheckFinalizationTask : EregisterTask
|
||||
{
|
||||
private readonly EregisterProgrammingParameters requestParameters;
|
||||
|
||||
private SIRTTaskState pendingState;
|
||||
|
||||
public EregisterCheckFinalizationTask(EregisterProgrammingParameters requestParameters, int frequency) : base(frequency)
|
||||
{
|
||||
this.requestParameters = requestParameters;
|
||||
this.pendingState = SIRTTaskState.Completed;
|
||||
this.Name = "Final Check";
|
||||
this.Data = new RequestDebugTelegram();
|
||||
}
|
||||
|
||||
protected override void EndProcessResponse(SIRTMessage response)
|
||||
{
|
||||
this.timeoutTimer.Stop();
|
||||
|
||||
if (this.State == this.pendingState)
|
||||
{
|
||||
this.State = SIRTTaskState.Running;
|
||||
this.Name = "Final Check - ✓";
|
||||
|
||||
var errors = string.Empty;
|
||||
|
||||
if (this.DEBUG != null && this.SEMI != null)
|
||||
{
|
||||
var responseParameters = this.GetProgrammingParameters();
|
||||
var comparebleProperties = typeof(EregisterProgrammingParameters)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
.Where(x => x.GetCustomAttribute<ComparePropertyAttribute>() != null);
|
||||
|
||||
foreach (var property in comparebleProperties)
|
||||
{
|
||||
var requestValue = property.GetValue(this.requestParameters);
|
||||
var responseValue = property.GetValue(responseParameters);
|
||||
|
||||
if ($"{requestValue}".Trim('\0').Trim() != $"{responseValue}".Trim('\0').Trim())
|
||||
{
|
||||
errors += $"- {property.Name}: request value {requestValue} != response value {responseValue}{Environment.NewLine}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.Length > 0)
|
||||
{
|
||||
errors += $"{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}Möchten Sie mit der Prüfungsabschluss fortfahren (Ja), oder Abbrechen (Nein)?{Environment.NewLine}";
|
||||
errors = $"Am Einbauplatz: {this.SlotNr}, "
|
||||
+ $"eingebaute E-Register mit Funkadressen: {this.RequestAddress} | {this.ResponseAddress}, "
|
||||
+ $"sind folgenden Fehler aufgetreten:{Environment.NewLine}{Environment.NewLine}{Environment.NewLine}{errors}";
|
||||
|
||||
|
||||
var result = MessageBox.Show(errors, $"Fehler bei der Prüfungsabschluss", MessageBoxButtons.YesNo);
|
||||
|
||||
if (result == DialogResult.No)
|
||||
{
|
||||
this.pendingState = SIRTTaskState.Cancelled;
|
||||
this.Label = nameof(SIRTTaskState.Cancelled);
|
||||
this.Name = "Final Check ✘";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.State = this.pendingState;
|
||||
|
||||
this.timeoutTimer.Start();
|
||||
base.EndProcessResponse(response);
|
||||
}
|
||||
|
||||
private EregisterProgrammingParameters GetProgrammingParameters()
|
||||
{
|
||||
var alarms = new AlarmsMask(this.SEMI.AlarmActiveInformation);
|
||||
var dataLogContent = new ChangeDataLoggerSettings
|
||||
{
|
||||
LogContent = this.SEMI.LogContent
|
||||
};
|
||||
var fdrLogContent = new ChangeDataLoggerSettings
|
||||
{
|
||||
LogContent = this.SEMI.FixedDateReadingContent
|
||||
};
|
||||
|
||||
var parameters = new EregisterProgrammingParameters
|
||||
{
|
||||
VolumePerLedPulse = this.DEBUG.VolumePerLedPulse,
|
||||
VolumePerPulse = this.DEBUG.VolumePerPulse,
|
||||
OffsetFactor = (byte)this.DEBUG.OffsetFactor, // TODO: normalize debug or parameter value
|
||||
OffsetTime = this.DEBUG.OffsetTime,
|
||||
FactoryCalibration = (byte)(this.DEBUG.FactoryCalibration * 10), // TODO: normalize debug or parameter value
|
||||
UnitsOfMessure = (byte)this.SEMI.Units, // TODO: normalize debug or parameter value
|
||||
MeterSize = this.SEMI.MeterSize,
|
||||
Alarm_Backflow = alarms.Backflow,
|
||||
Alarm_Broken_Pipe = alarms.BrokenPipe,
|
||||
Alarm_Leakage = alarms.Leak,
|
||||
Alarm_Low_Battery = alarms.LowBattery,
|
||||
Alarm_Magnetic_Tamper = alarms.MagneticTamper,
|
||||
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,
|
||||
Data_Logging_Alarm_State = dataLogContent.AlarmState,
|
||||
Data_Logging_Backward_Volume = dataLogContent.BackwardVolume,
|
||||
Data_Logging_Broken_Pipe_Flow = dataLogContent.BrokenPipeFlow,
|
||||
Data_Logging_Counter = dataLogContent.Counter,
|
||||
Data_Logging_Current_Flow = dataLogContent.CurrentFlow,
|
||||
Data_Logging_Forward_Counter = dataLogContent.ForwardCounter,
|
||||
Data_Logging_Maximum_Flow = dataLogContent.MaximumFlow,
|
||||
Data_Logging_Minimum_Flow = dataLogContent.MinimumFlow,
|
||||
Data_Logging_Peak_Flow = dataLogContent.PeakFlow,
|
||||
Data_Logging_Time_Of_Broken_Pipe = dataLogContent.TimeOfBrokenPipe,
|
||||
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,
|
||||
LeakagePeriod = this.SEMI.LeakageDetectionParameters.GetBitsLE().GetByteLE(0, 3),
|
||||
// TODO: LeakageThreshold
|
||||
BrokenPipePeriod = this.SEMI.BrokenPipeDetectionParameters.GetBitsLE().GetByteLE(0, 3),
|
||||
// TODO: BrokenPipeThreshold
|
||||
FDR_Day_Of_Data_Reading = this.SEMI.DayOfMonth,
|
||||
FDR_Alarm_State = fdrLogContent.AlarmState,
|
||||
FDR_Backward_Volume = fdrLogContent.BackwardVolume,
|
||||
FDR_Broken_Pipe_Flow = fdrLogContent.BrokenPipeFlow,
|
||||
FDR_Counter = fdrLogContent.Counter,
|
||||
FDR_Current_Flow = fdrLogContent.CurrentFlow,
|
||||
FDR_Forward_Counter = fdrLogContent.ForwardCounter,
|
||||
FDR_Maximum_Flow = fdrLogContent.MaximumFlow,
|
||||
FDR_Minimum_Flow = fdrLogContent.MinimumFlow,
|
||||
FDR_Peak_Flow = fdrLogContent.PeakFlow,
|
||||
FDR_Time_Of_Broken_Pipe = fdrLogContent.TimeOfBrokenPipe,
|
||||
FDR_Time_Of_Maximum_Flow = fdrLogContent.TimeOfMaximumFlow,
|
||||
FDR_Time_Of_Minimum_Flow = fdrLogContent.TimeOfMinimumFlow,
|
||||
FDR_Time_Of_Peak_Flow = fdrLogContent.TimeOfPeakFlow,
|
||||
TransmissionIntervalFinalization = (byte)this.SEMI.TransmissionInterval, // TODO: normalize debug or parameter value
|
||||
LATWindowsFinalization = this.SEMI.LATInterval,
|
||||
MBusStatus = this.SEMI.MBusStatus,
|
||||
Adresse = this.SEMI.Address,
|
||||
};
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.SIRT;
|
||||
using Common.Hardware.WaterMeter.eRegister.Features;
|
||||
using Common.Hardware.WaterMeter.eRegister.Models;
|
||||
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
public class EregisterCheckInitializationTask : EregisterTask
|
||||
{
|
||||
private readonly EregisterProgrammingParameters parameters;
|
||||
|
||||
private SIRTTaskState pendingState;
|
||||
|
||||
public EregisterCheckInitializationTask(EregisterProgrammingParameters parameters, int frequency) : base(frequency)
|
||||
{
|
||||
this.parameters = parameters;
|
||||
this.pendingState = SIRTTaskState.Completed;
|
||||
this.Name = "Programming Check";
|
||||
this.Data = new OpticalTelegram
|
||||
{
|
||||
Minutes = 1
|
||||
};
|
||||
}
|
||||
|
||||
protected override void EndProcessResponse(SIRTMessage response)
|
||||
{
|
||||
this.timeoutTimer.Stop();
|
||||
|
||||
if (this.State == this.pendingState)
|
||||
{
|
||||
this.State = SIRTTaskState.Running;
|
||||
|
||||
var message = new StringBuilder();
|
||||
message.AppendLine();
|
||||
message.AppendLine();
|
||||
|
||||
if (this.DEBUG != null && this.SEMI != null)
|
||||
{
|
||||
if (this.DEBUG.BatteryVoltage <= this.parameters.MinBatteryVoltage)
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Die Batteriespannung ({this.DEBUG.BatteryVoltage}) liegt unter dem angegebenen Minimum von ({this.parameters.MinBatteryVoltage}). ");
|
||||
}
|
||||
|
||||
if (this.SEMI.BatteryRemainingYears <= this.parameters.MinBatteryRemainingYears)
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Die Batterielaufzeit ({this.SEMI.BatteryRemainingYears}) liegt unter dem angegebenen Minimum von ({this.parameters.MinBatteryRemainingYears}). ");
|
||||
}
|
||||
|
||||
// Min metrology FW version ( >= 1108) CSD dependent
|
||||
if (!string.IsNullOrWhiteSpace(this.parameters.MinMetrologyFWVersion))
|
||||
{
|
||||
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);
|
||||
|
||||
if (minFW > curFW)
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Die Metrologische FW Version ({curFW}) liegt unter dem angegebenen Minimum von ({minFW}).");
|
||||
}
|
||||
}
|
||||
|
||||
// All, for production available radio & metrology FW versions.
|
||||
if (!string.IsNullOrWhiteSpace(this.parameters.FWVersionsList))
|
||||
{
|
||||
if (!this.parameters.FWVersionsList.Contains(this.DEBUG.MetrologyFWVersion))
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Die Metrologische FW Version ({this.DEBUG.MetrologyFWVersion}) ist nicht für Produktion freigegeben. ");
|
||||
}
|
||||
|
||||
if (!this.parameters.FWVersionsList.Contains(this.DEBUG.RadioFWVersion))
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Die Radio FW Version ({this.DEBUG.RadioFWVersion}) ist nicht für Produktion freigegeben. ");
|
||||
}
|
||||
}
|
||||
|
||||
if (this.DEBUG.RebootCount > this.parameters.MaxRebootCount)
|
||||
{
|
||||
message.AppendLine();
|
||||
message.AppendLine($"- Der rechenwerk wurde mehr als {this.parameters.MaxRebootCount} mal rebooted.");
|
||||
}
|
||||
}
|
||||
|
||||
if (message.Length > 10)
|
||||
{
|
||||
message.Insert(0, $"Am Einbauplatz: {this.SlotNr}, "
|
||||
+ $"eingebaute E-Register mit Funkadressen: {this.RequestAddress} | {this.ResponseAddress}, "
|
||||
+ $"sind folgenden Fehler sind aufgetreten:");
|
||||
message.AppendLine();
|
||||
message.AppendLine("Qualitätssicherung informieren!");
|
||||
message.AppendLine();
|
||||
message.AppendLine("Möchten Sie mit die Prüfung fortfahren (Yes), oder Abbrechen (No)?");
|
||||
|
||||
var result = MessageBox.Show(
|
||||
message.ToString()
|
||||
, $"Fehler bei der Prüfungsinitialisierung"
|
||||
, MessageBoxButtons.YesNo);
|
||||
|
||||
if (result == DialogResult.No)
|
||||
{
|
||||
this.State = SIRTTaskState.Pending;
|
||||
this.pendingState = SIRTTaskState.Cancelled;
|
||||
this.Label = nameof(SIRTTaskState.Cancelled);
|
||||
this.Data = new OpticalTelegram
|
||||
{
|
||||
Minutes = 0
|
||||
};
|
||||
|
||||
this.NotifyTimeouted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.State = this.pendingState;
|
||||
|
||||
this.timeoutTimer.Start();
|
||||
base.EndProcessResponse(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-12
@@ -92,9 +92,9 @@
|
||||
? isSingle.Value
|
||||
.Select(auth => new
|
||||
{
|
||||
Name = $"PAM {string.Join(", ", auth.Value.OrderBy(x => x[0]).Select(x => x[0]))}",
|
||||
Name = $"{string.Join(", ", auth.Value.OrderBy(x => x[0]).Select(x => $"{x[0]}"))}",
|
||||
Cmd = auth.Value.OrderBy(x => x[0]).SelectMany(x => x).ToList(),
|
||||
AuthLvl = BitConverter.GetBytes((long)auth.Key).Take(6)
|
||||
AuthLvl = auth.Key.AuthBytes()
|
||||
})
|
||||
// Single pams
|
||||
: isSingle.Value
|
||||
@@ -102,9 +102,9 @@
|
||||
.OrderByDescending(x => x[0])
|
||||
.Select(x => new
|
||||
{
|
||||
Name = $"PAM {x[0]}{(x[0] == 31 ? $"-{x[2]}" : "")}",
|
||||
Name = $"{x[0]}{(x[0] == 31 ? $"-{x[2]}" : "")}",
|
||||
Cmd = x.ToList(),
|
||||
AuthLvl = BitConverter.GetBytes((long)auth.Key).Take(6)
|
||||
AuthLvl = auth.Key.AuthBytes()
|
||||
})))
|
||||
.Select(x =>
|
||||
{
|
||||
@@ -114,6 +114,21 @@
|
||||
});
|
||||
}
|
||||
|
||||
public static byte[] AuthBytes(this AuthLevel authLevel)
|
||||
{
|
||||
var bytes = new byte[] { };
|
||||
|
||||
if (authLevel != AuthLevel.O)
|
||||
{
|
||||
var _bytes = ((long)authLevel).GetBytesLE();
|
||||
|
||||
Array.Resize(ref bytes, 6);
|
||||
Array.Copy(_bytes, 0, bytes, 0, 6);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] DecryptResponse(this byte[] encryptedData, byte[] encryptionKey)
|
||||
{
|
||||
if (encryptionKey?.Length != 16)
|
||||
@@ -146,14 +161,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
var crc = decryptedData.CRCCCITT(5, length - 2);
|
||||
|
||||
if (crc == 0 || crc == ushort.MaxValue)
|
||||
{
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
return encryptedData;
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
public static byte[] EncryptRequest(this byte[] plainData, byte[] encryptionKey, uint address)
|
||||
|
||||
+82
-77
@@ -1,18 +1,17 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
using Common.Hardware.SIRT;
|
||||
using Common.Hardware.SIRT.Parameters;
|
||||
using Common.Hardware.WaterMeter.eRegister.Telegrams;
|
||||
using Common.Hardware.WaterMeter.eRegister.Telegrams;
|
||||
|
||||
using System;
|
||||
using System.Timers;
|
||||
|
||||
public class EregisterTask : SIRTTask
|
||||
{
|
||||
private int latsCount;
|
||||
private bool tryEncrypted;
|
||||
|
||||
public EregisterTask(int timeout = 3000)
|
||||
: base(timeout)
|
||||
public EregisterTask(int frequency, int timeout = 5_000)
|
||||
: base(frequency, timeout)
|
||||
=> this.Cmd = SIRTMessage.W_PAM;
|
||||
|
||||
public event Action<EregisterTask> Changed;
|
||||
@@ -25,12 +24,16 @@
|
||||
|
||||
public string Name { get; internal set; }
|
||||
|
||||
public string Label { get; private set; }
|
||||
public string Label { get; protected set; }
|
||||
|
||||
public string Info { get; private set; }
|
||||
|
||||
public string RSSI { get; private set; }
|
||||
|
||||
public P11 P11 { get; private set; }
|
||||
|
||||
public P12 P12 { get; private set; }
|
||||
|
||||
public BUP BUP { get; private set; }
|
||||
|
||||
public LAT LAT { get; private set; }
|
||||
@@ -39,118 +42,120 @@
|
||||
|
||||
public SEMI SEMI { get; private set; }
|
||||
|
||||
public bool Encrypted { get; /* encrypted private*/ set; }
|
||||
public bool IsEncrypted { get; set; }
|
||||
|
||||
public byte[] EncryptionKey { get; /* todo: make internal */ set; }
|
||||
public byte[] EncryptionKey { get; set; }
|
||||
|
||||
public override void BeginReceiveMessage(SIRTMessage response)
|
||||
public override byte[] ToByteArray()
|
||||
{
|
||||
this.RSSI = default(string);
|
||||
this.Info = default(string);
|
||||
this.Label = default(string);
|
||||
var data = this.request.Data;
|
||||
|
||||
if (this.IsEncrypted)
|
||||
{
|
||||
data = data.EncryptRequest(this.EncryptionKey, this.RequestAddress);
|
||||
}
|
||||
|
||||
return new SIRTMessage
|
||||
{
|
||||
Address = this.request.Address,
|
||||
Cmd = this.request.Cmd,
|
||||
Data = data,
|
||||
P1 = this.request.P1,
|
||||
P2 = this.request.P2,
|
||||
|
||||
}.ToByteArray();
|
||||
}
|
||||
|
||||
protected override void OnTimeout(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
this.NotifyTimeouted();
|
||||
|
||||
this.State = SIRTTaskState.Pending;
|
||||
}
|
||||
|
||||
protected override void ProcessResponse(SIRTMessage response)
|
||||
{
|
||||
if (this.State == SIRTTaskState.Cancelled)
|
||||
{
|
||||
this.Label = nameof(SIRTTaskState.Cancelled);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.Cmd == SIRTMessage.FROMAIR)
|
||||
{
|
||||
var data = response.Data;
|
||||
var dataLength = data?.Length ?? 0;
|
||||
|
||||
if (this.tryEncrypted)
|
||||
{
|
||||
data = data.DecryptResponse(this.EncryptionKey);
|
||||
}
|
||||
|
||||
var responseData = data;
|
||||
var dataLength = responseData?.Length ?? 0;
|
||||
var p11 = new P11(response.P1);
|
||||
var resetTimer = false;
|
||||
|
||||
this.Info = p11;
|
||||
this.P11 = new P11(response.P1);
|
||||
this.RSSI = SEMI.CalculateRSSI(response.P2, (ushort)this.Frequency);
|
||||
|
||||
if (dataLength > 0)
|
||||
{
|
||||
var type = responseData[0];
|
||||
var type = data[0];
|
||||
var crc = data.ToInt16BE(dataLength - 2);
|
||||
|
||||
if (type == SIRTMessage.BUP )
|
||||
if (!this.IsEncrypted)
|
||||
{
|
||||
this.IsEncrypted = (type <= SIRTMessage.LAT && crc != 0)
|
||||
|| (type == SIRTMessage.DEBUG && dataLength >= 53)
|
||||
|| (type == SIRTMessage.SEMI && dataLength >= 93);
|
||||
|
||||
this.NotifyUpdated();
|
||||
}
|
||||
|
||||
if (this.IsEncrypted)
|
||||
{
|
||||
data = data.DecryptResponse(this.EncryptionKey);
|
||||
}
|
||||
|
||||
if (type == SIRTMessage.BUP)
|
||||
{
|
||||
this.Label = nameof(SIRTMessage.BUP);
|
||||
this.BUP = new BUP(responseData, p11);
|
||||
this.BUP = new BUP(data, this.P11);
|
||||
}
|
||||
else if (type == SIRTMessage.LAT)
|
||||
{
|
||||
this.latsCount++;
|
||||
|
||||
this.Label = nameof(SIRTMessage.LAT);
|
||||
this.LAT = new LAT(responseData, p11);
|
||||
this.LAT = new LAT(data, this.P11);
|
||||
}
|
||||
else if (type == SIRTMessage.DEBUG)
|
||||
{
|
||||
resetTimer = true;
|
||||
|
||||
this.Label = nameof(SIRTMessage.DEBUG);
|
||||
this.DEBUG = new DEBUG(responseData, p11);
|
||||
this.DEBUG = new DEBUG(data, this.P11);
|
||||
}
|
||||
else if (type == SIRTMessage.SEMI)
|
||||
{
|
||||
this.SEMI = new SEMI(responseData, this.Frequency, p11);
|
||||
this.SEMI = new SEMI(data, this.Frequency, this.P11);
|
||||
this.Label = this.SEMI.PAMStatus.ToString();
|
||||
|
||||
if (this.SEMI.PAMStatus == PAMStatus.OK)
|
||||
{
|
||||
this.State = SIRTTaskState.Completed;
|
||||
|
||||
if (this.RequestAddress != this.SEMI.Address)
|
||||
{
|
||||
this.RequestAddress = this.SEMI.Address;
|
||||
|
||||
this.NotifyUpdated();
|
||||
}
|
||||
|
||||
this.EndReceiveMessage(response);
|
||||
this.EndProcessResponse(response);
|
||||
}
|
||||
|
||||
this.tryEncrypted = this.SEMI.PAMStatus.CMD_UNKNOWN
|
||||
|| this.SEMI.PAMStatus.MIXED_TYPES
|
||||
|| this.SEMI.PAMStatus.WRONG_AUTH
|
||||
|| this.SEMI.PAMStatus.EXPIRED_AUTH;
|
||||
}
|
||||
}
|
||||
|
||||
if (resetTimer || this.latsCount % 2 != 0)
|
||||
{
|
||||
this.timer.Stop();
|
||||
this.timer.Start();
|
||||
else
|
||||
{
|
||||
this.Label = "NA";
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (response.Cmd == SIRTMessage.ACKNANSW)
|
||||
{
|
||||
this.Info = new P12(response.P1);
|
||||
this.Label = this.Info;
|
||||
|
||||
this.EndReceiveMessage(response);
|
||||
this.P12 = new P12(response.P1);
|
||||
this.Label = "ACKN";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Label = "NA";
|
||||
}
|
||||
|
||||
this.Changed?.Invoke(this);
|
||||
}
|
||||
|
||||
public override byte[] ToByteArray()
|
||||
{
|
||||
if (this.tryEncrypted)
|
||||
{
|
||||
var request = new SIRTMessage
|
||||
{
|
||||
Address = this.request.Address,
|
||||
Cmd = this.request.Cmd,
|
||||
Data = this.request.Data.EncryptRequest(this.EncryptionKey, this.RequestAddress),
|
||||
P1 = this.request.P1,
|
||||
P2 = this.request.P2
|
||||
};
|
||||
|
||||
return request.ToByteArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
protected virtual void EndProcessResponse(SIRTMessage response)
|
||||
=> base.ProcessResponse(response);
|
||||
}
|
||||
}
|
||||
+84
-6
@@ -8,16 +8,94 @@
|
||||
{
|
||||
}
|
||||
|
||||
public ushort TimeInterval
|
||||
public ushort TimeInterval { get; set; }
|
||||
|
||||
public ushort LogContent { get; set; }
|
||||
|
||||
public byte ForwardCounter
|
||||
{
|
||||
get => this.bytes.ToUInt16BE(1);
|
||||
set => value.GetBytesBE().CopyTo(this.bytes, 1);
|
||||
get => (byte)(this.LogContent >> 12 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 12);
|
||||
}
|
||||
|
||||
public ushort LogContent
|
||||
public byte TimeOfMinimumFlow
|
||||
{
|
||||
get => this.bytes.ToUInt16BE(3);
|
||||
set => value.GetBytesBE().CopyTo(this.bytes, 3);
|
||||
get => (byte)(this.LogContent >> 11 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 11);
|
||||
}
|
||||
|
||||
public byte MinimumFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 10 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 10);
|
||||
}
|
||||
|
||||
public byte TimeOfBrokenPipe
|
||||
{
|
||||
get => (byte)(this.LogContent >> 9 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 9);
|
||||
}
|
||||
|
||||
public byte BrokenPipeFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 8 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 8);
|
||||
}
|
||||
|
||||
public byte CurrentFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 7 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 7);
|
||||
}
|
||||
|
||||
public byte TimeOfPeakFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 6 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 6);
|
||||
}
|
||||
|
||||
public byte PeakFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 5 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 5);
|
||||
}
|
||||
|
||||
public byte TimeOfMaximumFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 4 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 4);
|
||||
}
|
||||
|
||||
public byte MaximumFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 3 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 3);
|
||||
}
|
||||
|
||||
public byte BackwardVolume
|
||||
{
|
||||
get => (byte)(this.LogContent >> 2 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 2);
|
||||
}
|
||||
|
||||
public byte Counter
|
||||
{
|
||||
get => (byte)(this.LogContent >> 1 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 1);
|
||||
}
|
||||
|
||||
public byte AlarmState
|
||||
{
|
||||
get => (byte)(this.LogContent >> 0 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 0);
|
||||
}
|
||||
|
||||
public override byte[] ToByteArray()
|
||||
{
|
||||
this.TimeInterval.GetBytesBE().CopyTo(this.bytes, 1);
|
||||
this.LogContent.GetBytesBE().CopyTo(this.bytes, 3);
|
||||
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+78
@@ -19,5 +19,83 @@
|
||||
get => this.bytes.ToUInt16BE(2);
|
||||
set => value.GetBytesBE().CopyTo(this.bytes, 2);
|
||||
}
|
||||
|
||||
public byte ForwardCounter
|
||||
{
|
||||
get => (byte)(this.LogContent >> 12 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 12);
|
||||
}
|
||||
|
||||
public byte TimeOfMinimumFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 11 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 11);
|
||||
}
|
||||
|
||||
public byte MinimumFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 10 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 10);
|
||||
}
|
||||
|
||||
public byte TimeOfBrokenPipe
|
||||
{
|
||||
get => (byte)(this.LogContent >> 9 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 9);
|
||||
}
|
||||
|
||||
public byte BrokenPipeFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 8 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 8);
|
||||
}
|
||||
|
||||
public byte CurrentFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 7 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 7);
|
||||
}
|
||||
|
||||
public byte TimeOfPeakFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 6 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 6);
|
||||
}
|
||||
|
||||
public byte PeakFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 5 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 5);
|
||||
}
|
||||
|
||||
public byte TimeOfMaximumFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 4 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 4);
|
||||
}
|
||||
|
||||
public byte MaximumFlow
|
||||
{
|
||||
get => (byte)(this.LogContent >> 3 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 3);
|
||||
}
|
||||
|
||||
public byte BackwardVolume
|
||||
{
|
||||
get => (byte)(this.LogContent >> 2 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 2);
|
||||
}
|
||||
|
||||
public byte Counter
|
||||
{
|
||||
get => (byte)(this.LogContent >> 1 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 1);
|
||||
}
|
||||
|
||||
public byte AlarmState
|
||||
{
|
||||
get => (byte)(this.LogContent >> 0 & 1);
|
||||
set => this.LogContent ^= (ushort)(value << 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -1,7 +1,5 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using System;
|
||||
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
public class ChangeMeterId : Pam
|
||||
@@ -16,7 +14,7 @@
|
||||
public uint MeterId
|
||||
{
|
||||
get => this.bytes.ToUInt32BE(1);
|
||||
set => BitConverter.GetBytes(value).CopyTo(this.bytes, 1);
|
||||
set => value.GetBytesBE().CopyTo(this.bytes, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@
|
||||
|
||||
public MeterTypes Type
|
||||
{
|
||||
get => (MeterTypes)this.bytes[0];
|
||||
set => this.bytes[0] = (byte)value;
|
||||
get => (MeterTypes)this.bytes[1];
|
||||
set => this.bytes[1] = (byte)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Models
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
public class ComparePropertyAttribute : ValidationAttribute
|
||||
{
|
||||
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
|
||||
{
|
||||
return base.IsValid(value, validationContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
+302
-20
@@ -1,5 +1,10 @@
|
||||
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))]
|
||||
@@ -24,129 +29,179 @@
|
||||
|
||||
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; }
|
||||
|
||||
public byte Metersize { get; set; }
|
||||
[CompareProperty]
|
||||
public byte MeterSize { get; set; }
|
||||
|
||||
[CompareProperty]
|
||||
public int VolumePerPulse { get; set; }
|
||||
|
||||
public uint VolumePerLedPulse { 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; }
|
||||
|
||||
[XmlAttribute("TransmissionIntervall")]
|
||||
public byte Transmission_Interval_Init { get; set; }
|
||||
public byte TransmissionIntervalInitialization { get; set; }
|
||||
|
||||
[CompareProperty]
|
||||
public byte TransmissionIntervalFinalization { get; set; }
|
||||
|
||||
[CompareProperty]
|
||||
public byte MBusStatus { get; set; }
|
||||
|
||||
public byte LatWindows { 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; }
|
||||
|
||||
public byte Alarm_Low_Battery { get; set; }
|
||||
[CompareProperty]
|
||||
public bool Alarm_Low_Battery { get; set; }
|
||||
|
||||
public byte Alarm_Leakage { get; set; }
|
||||
[CompareProperty]
|
||||
public bool Alarm_Leakage { get; set; }
|
||||
|
||||
public byte Alarm_Magnetic_Tamper { get; set; }
|
||||
[CompareProperty]
|
||||
public bool Alarm_Magnetic_Tamper { get; set; }
|
||||
|
||||
public byte Alarm_Metrology_Unavailable { get; set; }
|
||||
[CompareProperty]
|
||||
public bool Alarm_Metrology_Unavailable { get; set; }
|
||||
|
||||
public byte Alarm_Backflow { get; set; }
|
||||
[CompareProperty]
|
||||
public bool Alarm_Backflow { get; set; }
|
||||
|
||||
public byte Alarm_Broken_Pipe { get; set; }
|
||||
[CompareProperty]
|
||||
public bool Alarm_Broken_Pipe { get; set; }
|
||||
|
||||
public byte Alarm_Medium_Absent { get; set; }
|
||||
[CompareProperty]
|
||||
public bool Alarm_Medium_Absent { get; set; }
|
||||
|
||||
public byte Alarm_Specific_Error { 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 Transmission_Intervall { get; set; }
|
||||
|
||||
public byte PowerLevelHex { get; set; }
|
||||
|
||||
public byte DisableOTA { get; set; }
|
||||
|
||||
public byte LAT_Interval { get; set; }
|
||||
|
||||
public byte ActivationByThreshold { get; set; }
|
||||
|
||||
public ushort OpenMeteringTransmissionIntervalSeconds { get; set; }
|
||||
@@ -155,14 +210,241 @@
|
||||
|
||||
public byte Wake_Up_Interval { get; set; }
|
||||
|
||||
public int DisplayVolume { get; set; }
|
||||
[CompareProperty]
|
||||
public uint DisplayVolume { get; set; }
|
||||
|
||||
public bool Encrypted { get; set; }
|
||||
|
||||
public byte Lat_Windows_Before { 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-228
@@ -1,10 +1,5 @@
|
||||
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.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
@@ -13,240 +8,26 @@
|
||||
{
|
||||
public IEnumerable<EregisterFeatures> LoadInspectionInitializationFeatures()
|
||||
{
|
||||
var featuresList = new List<EregisterFeatures>();
|
||||
|
||||
foreach (var parameters in this)
|
||||
{
|
||||
var address = (uint)(parameters.Adresse % 10_000_000_000);
|
||||
var tempAddress = (uint)(parameters.TempAdresse % 10_000_000_000);
|
||||
var features = new EregisterFeatures
|
||||
{
|
||||
SlotNr = parameters.Slotno,
|
||||
SerialNr = parameters.SerienNr,
|
||||
PoNr = parameters.FertigungsauftragNr,
|
||||
RequestAddress = tempAddress,
|
||||
ResponseAddress = address,
|
||||
Frequency = parameters.Frequency,
|
||||
EncryptionKey = parameters.EncryptionKey.GetEncryptionKey(),
|
||||
ChangeWakeUp = new ChangeWakeUp(WakeUpMode.StayAwake),
|
||||
ChangeTransmissionInterval = new ChangeTransmissionInterval(parameters.LAT_Interval),
|
||||
ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows(parameters.Lat_Windows_Before),
|
||||
WirelessMBusMode = new WirelessMBusMode(parameters.MBusStatus),
|
||||
Debug = new EregisterDebugFeatures
|
||||
{
|
||||
OpticalTelegram = new OpticalTelegram(1),
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Production mode only:
|
||||
features.SetPowerLevelFlexNet0
|
||||
features.SetRebootCount
|
||||
features.ChangeMeterReading
|
||||
features.ChangeMeterId
|
||||
features.SetPcbId
|
||||
features.SetMetrologyParameters
|
||||
*/
|
||||
|
||||
if (parameters.Encrypted == false)
|
||||
{
|
||||
features.ChangeMeterReading = new ChangeMeterReading(111111111);
|
||||
features.SetMetrologyParameters = new SetMetrologyParameters
|
||||
{
|
||||
UseCandIRules = parameters.Use_CandI_Rules == 1,
|
||||
DecimalPoint = (DecimalPointLocations)parameters.DecimalPoint,
|
||||
FactoryCalibration = parameters.FactoryCalibration,
|
||||
MeterSize = parameters.Metersize,
|
||||
OffsetFactor = parameters.OffsetFactor,
|
||||
OffsetTime = parameters.OffsetTime,
|
||||
Units = (MessurementUnits)parameters.UnitsOfMessure,
|
||||
Vpp = parameters.VolumePerPulse,
|
||||
VppLED = parameters.VolumePerLedPulse
|
||||
};
|
||||
}
|
||||
|
||||
featuresList.Add(features);
|
||||
yield return parameters.LoadInspectionInitializationFeatures();
|
||||
}
|
||||
}
|
||||
|
||||
return featuresList;
|
||||
internal IEnumerable<EregisterFeatures> LoadCustomFeatures()
|
||||
{
|
||||
foreach (var parameters in this)
|
||||
{
|
||||
yield return parameters.LoadCustomFeatures();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<EregisterFeatures> LoadInspectionFinalizationFeatures()
|
||||
{
|
||||
var featuresList = new List<EregisterFeatures>();
|
||||
var utc = DateTime.UtcNow;
|
||||
|
||||
foreach (var parameters in this)
|
||||
{
|
||||
var address = (uint)(parameters.Adresse % 10_000_000_000);
|
||||
var tempAddress = (uint)(parameters.TempAdresse % 10_000_000_000);
|
||||
|
||||
var features = new EregisterFeatures
|
||||
{
|
||||
SlotNr = parameters.Slotno,
|
||||
SerialNr = parameters.SerienNr,
|
||||
PoNr = parameters.FertigungsauftragNr,
|
||||
RequestAddress = tempAddress,
|
||||
ResponseAddress = address,
|
||||
Frequency = parameters.Frequency,
|
||||
Sealed = parameters.Encrypted,
|
||||
EncryptionKey = parameters.EncryptionKey.GetEncryptionKey(),
|
||||
};
|
||||
|
||||
if (parameters.StatusFertigung < 30)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
Production mode only:
|
||||
features.SetPowerLevelFlexNet0
|
||||
features.SetRebootCount
|
||||
features.ChangeMeterReading
|
||||
features.ChangeMeterId
|
||||
features.SetPcbId
|
||||
features.SetMetrologyParameters
|
||||
*/
|
||||
|
||||
if (parameters.Encrypted == false)
|
||||
{
|
||||
features.ChangeMeterId = new ChangeMeterId(parameters.MeterId);
|
||||
features.ChangeMeterReading = new ChangeMeterReading((uint)parameters.DisplayVolume);
|
||||
features.SetPowerLevelSensusRF0 = new SetPowerLevel
|
||||
{
|
||||
Value = (byte)(parameters.PowerLevelHex & 127)
|
||||
};
|
||||
|
||||
features.SetPowerLevelFlexNet0 = new SetPowerLevel
|
||||
{
|
||||
Value = (byte)(parameters.PowerLevelHex | 128)
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
features.SetPowerLevelFlexNetIII = new SetPowerLevel
|
||||
{
|
||||
Value = (byte)(parameters.PowerLevelHex | 128)
|
||||
};
|
||||
}
|
||||
|
||||
features.ChangeRadioId = new ChangeRadioId(address);
|
||||
features.DeactivateAlarms = new DeactivateAlarms
|
||||
{
|
||||
Backflow = parameters.Alarm_Backflow > 0,
|
||||
BrokenPipe = parameters.Alarm_Broken_Pipe > 0,
|
||||
Leak = parameters.Alarm_Leakage > 0,
|
||||
LowBattery = parameters.Alarm_Low_Battery > 0,
|
||||
MagneticTamper = parameters.Alarm_Magnetic_Tamper > 0,
|
||||
MediumAbsent = parameters.Alarm_Medium_Absent > 0,
|
||||
MetrologyUnavailable = parameters.Alarm_Metrology_Unavailable > 0,
|
||||
SpecificError = parameters.Alarm_Specific_Error > 0,
|
||||
};
|
||||
features.ResetAlarms = new ResetAlarms(0xFF);
|
||||
features.ChangeCustomerText = new ChangeCustomerText();
|
||||
features.ParameterizeLeakageDetection = new ParameterizeLeakageDetection
|
||||
{
|
||||
Value = (byte)(parameters.LeakagePeriod | (parameters.LeakageThreshold * (byte)Math.Pow(2, 3)))
|
||||
};
|
||||
features.ParameterizeBrokenPipeDetection = new ParameterizeBrokenPipeDetection
|
||||
{
|
||||
Value = (byte)(parameters.BrokenPipePeriod | (parameters.BrokenPipeThreshold * (byte)Math.Pow(2, 3)))
|
||||
};
|
||||
features.SetHistoricalErrorLimit = new SetHistoricalErrorLimit
|
||||
{
|
||||
Value = parameters.History_Error_Limits_Days
|
||||
};
|
||||
|
||||
var logContent = default(ushort);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Forward_Counter << 12);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Time_Of_Minimum_Flow << 11);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Minimum_Flow << 10);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Time_Of_Broken_Pipe << 9);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Broken_Pipe_Flow << 8);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Current_Flow << 7);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Time_Of_Peak_Flow << 6);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Peak_Flow << 5);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Time_Of_Maximum_Flow << 4);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Maximum_Flow << 3);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Backward_Volume << 2);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Counter << 1);
|
||||
logContent ^= (ushort)(parameters.Data_Logging_Alarm_State << 0);
|
||||
|
||||
features.ChangeDataLoggerSettings = new ChangeDataLoggerSettings
|
||||
{
|
||||
TimeInterval = parameters.Data_Logging_Period,
|
||||
LogContent = logContent,
|
||||
};
|
||||
|
||||
logContent = default(ushort);
|
||||
logContent ^= (ushort)(parameters.FDR_Forward_Counter << 12);
|
||||
logContent ^= (ushort)(parameters.FDR_Time_Of_Minimum_Flow << 11);
|
||||
logContent ^= (ushort)(parameters.FDR_Minimum_Flow << 10);
|
||||
logContent ^= (ushort)(parameters.FDR_Time_Of_Broken_Pipe << 9);
|
||||
logContent ^= (ushort)(parameters.FDR_Broken_Pipe_Flow << 8);
|
||||
logContent ^= (ushort)(parameters.FDR_Current_Flow << 7);
|
||||
logContent ^= (ushort)(parameters.FDR_Time_Of_Peak_Flow << 6);
|
||||
logContent ^= (ushort)(parameters.FDR_Peak_Flow << 5);
|
||||
logContent ^= (ushort)(parameters.FDR_Time_Of_Maximum_Flow << 4);
|
||||
logContent ^= (ushort)(parameters.FDR_Maximum_Flow << 3);
|
||||
logContent ^= (ushort)(parameters.FDR_Backward_Volume << 2);
|
||||
logContent ^= (ushort)(parameters.FDR_Counter << 1);
|
||||
logContent ^= (ushort)(parameters.FDR_Alarm_State << 0);
|
||||
|
||||
features.ChangeFixedDateReadingSettings = new ChangeFixedDateReadingSettings
|
||||
{
|
||||
DayOfMonth = parameters.FDR_Day_Of_Data_Reading,
|
||||
LogContent = logContent
|
||||
};
|
||||
|
||||
features.SetDateAndTime = new SetDateAndTime
|
||||
{
|
||||
SecondsSince20000101 = new Epoch20000101
|
||||
{
|
||||
DateTime = utc.AddHours(parameters.UTC_Offset)
|
||||
}
|
||||
};
|
||||
|
||||
features.WirelessMBusMode = new WirelessMBusMode(parameters.MBusStatus);
|
||||
|
||||
features.Debug = new EregisterDebugFeatures
|
||||
{
|
||||
DisableOTAFirmwareUpdate = new DisableOTAFirmwareUpdate
|
||||
{
|
||||
Mode = (OTAMode)parameters.DisableOTA
|
||||
},
|
||||
SetActivationByThreshold = new SetActivationByThreshold
|
||||
{
|
||||
Rotations = parameters.ActivationByThreshold
|
||||
},
|
||||
ChangeState = new ChangeState
|
||||
{
|
||||
Mode = StateModes.Shipment
|
||||
}
|
||||
};
|
||||
features.OpenMeteringTransmitionIntervalWMBus = new OpenMeteringTransmitionIntervalWMBus
|
||||
{
|
||||
Seconds = parameters.OpenMeteringTransmissionIntervalSeconds
|
||||
};
|
||||
features.ChangeSensusRFEncryptionKey = new ChangeSensusRFEncryptionKey
|
||||
{
|
||||
HexKey = parameters.EncryptionKey
|
||||
};
|
||||
features.ChangeTransmissionInterval = new ChangeTransmissionInterval
|
||||
{
|
||||
Seconds = 1 // parameters.Transmission_Intervall,
|
||||
};
|
||||
features.ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows
|
||||
{
|
||||
N = 1 // parameters.LAT_Interval
|
||||
};
|
||||
|
||||
// TODO: change to customer mode
|
||||
|
||||
featuresList.Add(features);
|
||||
yield return parameters.LoadInspectionFinalizationFeatures();
|
||||
}
|
||||
|
||||
return featuresList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-6
@@ -8,15 +8,17 @@
|
||||
{
|
||||
public BUP(byte[] payload, P11 p11) : base(payload, p11)
|
||||
{
|
||||
this.Reading = payload.ToUInt32BE(6);
|
||||
this.Alarm = new AlarmsMask(payload[7]);
|
||||
this.Crc = payload.ToUInt16LE(8);
|
||||
this.DisplayVolume = payload.ToUInt32BE(6);
|
||||
this.Alarm = new AlarmsMask(payload[10]);
|
||||
|
||||
if (payload.Length >= 13)
|
||||
{
|
||||
this.Crc = payload.ToUInt16LE(11);
|
||||
}
|
||||
}
|
||||
|
||||
public uint Reading { get; }
|
||||
public uint DisplayVolume { get; }
|
||||
|
||||
public AlarmsMask Alarm { get; }
|
||||
|
||||
public ushort Crc { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
||||
+11
-58
@@ -9,9 +9,8 @@
|
||||
{
|
||||
this.DebugType = payload[6];
|
||||
this.MeterType = payload[7];
|
||||
this.RadioFirmwareVersion = payload[8].ToString();
|
||||
this.MetrologyFirmwareVersion = payload[9].ToString();
|
||||
this.FirmwareVersion = this.VersionString(payload[10], payload[11]);
|
||||
this.RadioFWVersion = $"{payload[8]:X2}{payload[9]:X2}";
|
||||
this.MetrologyFWVersion = $"{payload[10]:X2}{payload[11]:X2}";
|
||||
this.HardwareVersion = payload[12].ToString();
|
||||
this.FactoryState = payload[13];
|
||||
this.PCBID = payload.ToUInt32BE(14);
|
||||
@@ -30,9 +29,9 @@
|
||||
this.HistorySize = payload[35];
|
||||
this.FactoryCalibration = payload[36] / 10F;
|
||||
this.MeterSize = payload[37];
|
||||
this.VolumePerLedPulse = payload.ToUInt32BE(38);
|
||||
this.VolumePerPulse = payload.ToUInt32BE(42);
|
||||
this.OffsetFactor = payload.ToUInt32BE(46);
|
||||
this.VolumePerLedPulse = payload.ToInt32BE(38);
|
||||
this.VolumePerPulse = payload.ToInt32BE(42);
|
||||
this.OffsetFactor = payload.ToInt32BE(46);
|
||||
this.OffsetTime = payload[50];
|
||||
this.Crc = 0;
|
||||
|
||||
@@ -49,23 +48,18 @@
|
||||
/// </summary>
|
||||
public byte MeterType { get; }
|
||||
|
||||
public string RadioFirmwareVersion { get; }
|
||||
|
||||
public string FirmwareVersion { get; }
|
||||
public string RadioFWVersion { get; }
|
||||
|
||||
public string HardwareVersion { get; }
|
||||
|
||||
public string MetrologyFirmwareVersion { get; }
|
||||
public string MetrologyFWVersion { get; }
|
||||
|
||||
public byte FactoryState { get; }
|
||||
|
||||
public uint PCBID { get; }
|
||||
|
||||
public byte BoardTemperature { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Min: 3.565
|
||||
/// </summary>
|
||||
|
||||
public double BatteryVoltage { get; }
|
||||
|
||||
public byte WakeupInterval { get; }
|
||||
@@ -94,53 +88,12 @@
|
||||
|
||||
public byte MeterSize { get; }
|
||||
|
||||
public uint VolumePerLedPulse { get; }
|
||||
public int VolumePerLedPulse { get; }
|
||||
|
||||
public uint VolumePerPulse { get; }
|
||||
public int VolumePerPulse { get; }
|
||||
|
||||
public uint OffsetFactor { get; }
|
||||
public int OffsetFactor { get; }
|
||||
|
||||
public byte OffsetTime { get; }
|
||||
|
||||
public ushort Crc { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Bit 15 – Beta or Release
|
||||
/// Bits 12-14 – Major Version
|
||||
/// Bits 8-11 – Minor Version
|
||||
/// Bits 0-7 – Patch Version
|
||||
/// </summary>
|
||||
private string VersionString(byte patch, byte param)
|
||||
{
|
||||
var bits = param.GetBitsBE();
|
||||
var type = bits[7] == 0 ? 'B' : 'R';
|
||||
|
||||
var majorBits = new byte[8];
|
||||
majorBits[0] = bits[6];
|
||||
majorBits[1] = bits[5];
|
||||
majorBits[2] = bits[4];
|
||||
|
||||
var major = 0;
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
major |= majorBits[i] << i;
|
||||
}
|
||||
|
||||
var minorBits = new byte[8];
|
||||
majorBits[0] = bits[3];
|
||||
majorBits[1] = bits[2];
|
||||
majorBits[2] = bits[1];
|
||||
majorBits[3] = bits[0];
|
||||
|
||||
var minor = 0;
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
minor |= minorBits[i] << i;
|
||||
}
|
||||
|
||||
return $"{type}{major}.{minor}.{patch}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-5
@@ -7,18 +7,18 @@
|
||||
|
||||
public abstract class Payload
|
||||
{
|
||||
protected readonly string bytes;
|
||||
protected readonly string hexBytes;
|
||||
|
||||
protected Payload(byte[] payload, P11 p11)
|
||||
{
|
||||
this.P11 = p11;
|
||||
this.bytes = BitConverter.ToString(payload);
|
||||
this.InfoP11 = p11;
|
||||
this.hexBytes = BitConverter.ToString(payload);
|
||||
this.AppCode = (AppCode)payload[0];
|
||||
this.Counter = payload[1];
|
||||
this.Address = payload.ToUInt32BE(2);
|
||||
}
|
||||
|
||||
public P11 P11 { get; }
|
||||
public string InfoP11 { get; }
|
||||
|
||||
public AppCode AppCode { get; }
|
||||
|
||||
@@ -26,7 +26,9 @@
|
||||
|
||||
public uint Address { get; }
|
||||
|
||||
public override string ToString() => this.bytes;
|
||||
public ushort Crc { get; protected set; }
|
||||
|
||||
public override string ToString() => this.hexBytes;
|
||||
|
||||
public static implicit operator string(Payload payload) => payload?.ToString();
|
||||
}
|
||||
|
||||
+6
-32
@@ -2,6 +2,7 @@
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
using Common.Hardware.SIRT.Parameters;
|
||||
using Common.Hardware.WaterMeter.eRegister.Features;
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
@@ -25,7 +26,7 @@
|
||||
this.AlarmActiveInformation = payload[32];
|
||||
this.LeakageDetectionParameters = payload[33];
|
||||
this.BrokenPipeDetectionParameters = payload[34];
|
||||
this.BatteryRemaining = payload.ToUInt16BE(35) / (4D * 365);
|
||||
this.BatteryRemainingYears = payload.ToUInt16BE(35) / (4D * 365);
|
||||
this.BatteryEndDetected = payload.ToUInt16BE(37);
|
||||
this.MaximumFlow = payload.ToUInt16BE(39);
|
||||
this.TimeOfMaximumFlow = payload.ToUInt16BE(41);
|
||||
@@ -60,9 +61,7 @@
|
||||
|
||||
public uint ModuleAddress { get; }
|
||||
|
||||
public uint DisplayVolume { get; }
|
||||
|
||||
public byte Alarms { get; }
|
||||
public AlarmsMask Alarms { get; }
|
||||
|
||||
public PAMStatus PAMStatus { get; }
|
||||
|
||||
@@ -94,7 +93,7 @@
|
||||
|
||||
public byte BrokenPipeDetectionParameters { get; }
|
||||
|
||||
public double BatteryRemaining { get; }
|
||||
public double BatteryRemainingYears { get; }
|
||||
|
||||
public ushort BatteryEndDetected { get; }
|
||||
|
||||
@@ -146,34 +145,9 @@
|
||||
|
||||
public static string CalculateRSSI(byte value, int mhz)
|
||||
{
|
||||
var dbm = 0D;
|
||||
var per = 0D;
|
||||
var rssi = new RSSI(value, mhz);
|
||||
|
||||
if (mhz == 433)
|
||||
{
|
||||
dbm = value * 0.5 - 140;
|
||||
per = value * 0.7333 - 57.6667;
|
||||
}
|
||||
else if (mhz == 868)
|
||||
{
|
||||
dbm = value * 0.5 - 131.3;
|
||||
per = value * 0.66 - 40.316;
|
||||
}
|
||||
else
|
||||
{
|
||||
return value.ToString("X2");
|
||||
}
|
||||
|
||||
if (per > 100)
|
||||
{
|
||||
per = 100;
|
||||
}
|
||||
else if (per < 0)
|
||||
{
|
||||
per = 0;
|
||||
}
|
||||
|
||||
return $"{dbm:0}dBm({per:0.0}%)";
|
||||
return $"{rssi.Dbm:0}dBm ({rssi.Percent:0.0}%)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user