merge main
This commit is contained in:
+9
-4
@@ -7,11 +7,12 @@
|
||||
<ProjectGuid>{9AE071C0-DB12-4E09-A3C7-43F6DCD518D6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Common.Hardware.Interfaces.Ports</RootNamespace>
|
||||
<AssemblyName>Common.Hardware.Interfaces.Ports</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<RootNamespace>Common.Hardware.Ports</RootNamespace>
|
||||
<AssemblyName>Common.Hardware.Ports</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
@@ -22,7 +23,9 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn>IDE0003;IDE0049;</NoWarn>
|
||||
<DocumentationFile>bin\Debug\Common.Hardware.Interfaces.Ports.xml</DocumentationFile>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
@@ -31,6 +34,7 @@
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@@ -44,6 +48,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="IrdaSerialPort.cs" />
|
||||
<Compile Include="ISerialPort.cs" />
|
||||
<Compile Include="SerialDataExtensions.cs" />
|
||||
<Compile Include="SerialPort.cs" />
|
||||
<Compile Include="SerialPortBase.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
|
||||
@@ -13,41 +13,41 @@
|
||||
event Action<string, Exception> Exception;
|
||||
|
||||
/// <summary>
|
||||
/// Safely closes the serial port. Exceptions are thrown through the <see cref="Common.Hardware.Interfaces.Ports.ISerialPort.Exception"/> event.
|
||||
/// Safely closes the serial port. Exceptions are thrown through the <see cref="Common.Hardware.Ports.ISerialPort.Exception"/> event.
|
||||
/// </summary>
|
||||
void Close();
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether the serial port exists and is open. Exceptions are thrown through the <see cref="Common.Hardware.Interfaces.Ports.ISerialPort.Exception"/> event.
|
||||
/// Returns whether the serial port exists and is open. Exceptions are thrown through the <see cref="Common.Hardware.Ports.ISerialPort.Exception"/> event.
|
||||
/// </summary>
|
||||
bool IsOpen();
|
||||
|
||||
/// <summary>
|
||||
/// Safely opens the serial port. Exceptions are thrown through the <see cref="Common.Hardware.Interfaces.Ports.ISerialPort.Exception"/> event.
|
||||
/// Safely opens the serial port. Exceptions are thrown through the <see cref="Common.Hardware.Ports.ISerialPort.Exception"/> event.
|
||||
/// </summary>
|
||||
void Open();
|
||||
|
||||
/// <summary>
|
||||
/// Safely reads the incomming bytes into <see cref="System.Byte"/>[] if any, by default returns empty array.
|
||||
/// Exceptions are thrown through the <see cref="Common.Hardware.Interfaces.Ports.ISerialPort.Exception"/> event.
|
||||
/// Exceptions are thrown through the <see cref="Common.Hardware.Ports.ISerialPort.Exception"/> event.
|
||||
/// </summary>
|
||||
byte[] ReadBytes();
|
||||
|
||||
/// <summary>
|
||||
/// Safely reads a <see cref="System.String"/> if any, by default returns <see cref="System.String.Empty"/>.
|
||||
/// Exceptions are thrown through the <see cref="Common.Hardware.Interfaces.Ports.ISerialPort.Exception"/> event.
|
||||
/// Exceptions are thrown through the <see cref="Common.Hardware.Ports.ISerialPort.Exception"/> event.
|
||||
/// </summary>
|
||||
string ReadLine();
|
||||
|
||||
/// <summary>
|
||||
/// Safely writes the provided <see cref="System.Byte"/>[] to the serial port.
|
||||
/// Exceptions are thrown through the <see cref="Common.Hardware.Interfaces.Ports.ISerialPort.Exception"/> event.
|
||||
/// Exceptions are thrown through the <see cref="Common.Hardware.Ports.ISerialPort.Exception"/> event.
|
||||
/// </summary>
|
||||
void WriteBytes(params byte[] bytes);
|
||||
|
||||
/// <summary>
|
||||
/// Safely writes the provided <see cref="System.String"/> to the serial port.
|
||||
/// Exceptions are thrown through the <see cref="Common.Hardware.Interfaces.Ports.ISerialPort.Exception"/> event.
|
||||
/// Exceptions are thrown through the <see cref="Common.Hardware.Ports.ISerialPort.Exception"/> event.
|
||||
/// </summary>
|
||||
void WriteLine(string line);
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
|
||||
+2
-2
@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Common.Hardware.Interfaces.Ports")]
|
||||
[assembly: AssemblyTitle("Common.Hardware.Ports")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Common.Hardware.Interfaces.Ports")]
|
||||
[assembly: AssemblyProduct("Common.Hardware.Ports")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
@@ -0,0 +1,541 @@
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public static class SerialDataExtensions
|
||||
{
|
||||
public static byte[] GetBitsBE(this byte value)
|
||||
{
|
||||
var bytes = new byte[8];
|
||||
|
||||
for (int i = 7, x = 0; i >= 0; i--, x++)
|
||||
{
|
||||
bytes[x] = (byte)((value >> i) % 2);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBitsLE(this byte value)
|
||||
{
|
||||
var bytes = new byte[8];
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
bytes[i] = (byte)((value >> i) % 2);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte GetByteLE(this byte[] bits)
|
||||
{
|
||||
if (bits is null)
|
||||
{
|
||||
return default(byte);
|
||||
}
|
||||
|
||||
var value = default(byte);
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
value ^= (byte)(bits[i] << i);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static byte GetByteLE(this byte[] bits, int start = 0, int count = 0)
|
||||
{
|
||||
if (bits is null)
|
||||
{
|
||||
return default(byte);
|
||||
}
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
count = bits.Length;
|
||||
}
|
||||
|
||||
var length = start + count;
|
||||
var _byte = default(byte);
|
||||
|
||||
for (int i = start, x = 0; i < length; i++, x++)
|
||||
{
|
||||
_byte ^= (byte)(bits[i] << x);
|
||||
}
|
||||
|
||||
return _byte;
|
||||
}
|
||||
|
||||
public static void SetBitsLE(this byte value, byte[] bits, int start = 0, int count = 0)
|
||||
{
|
||||
if (bits is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (count == 0 || count > bits.Length)
|
||||
{
|
||||
count = bits.Length;
|
||||
}
|
||||
|
||||
for (int i = start, x = 0; i < count; i++, x++)
|
||||
{
|
||||
bits[i] = (byte)((value >> x) % 2);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] GetBytesBE(this sbyte value)
|
||||
{
|
||||
var bytes = new byte[2];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index] = (byte)value;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesBE(this short value)
|
||||
{
|
||||
var bytes = new byte[2];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index] = (byte)value;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesBE(this int value)
|
||||
{
|
||||
var bytes = new byte[4];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)(value >> 24);
|
||||
bytes[index++] = (byte)(value >> 16);
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index] = (byte)value;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesBE(this long value)
|
||||
{
|
||||
var bytes = new byte[8];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)(value >> 56);
|
||||
bytes[index++] = (byte)(value >> 48);
|
||||
bytes[index++] = (byte)(value >> 40);
|
||||
bytes[index++] = (byte)(value >> 32);
|
||||
bytes[index++] = (byte)(value >> 24);
|
||||
bytes[index++] = (byte)(value >> 16);
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index] = (byte)value;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesBE(this ushort value)
|
||||
{
|
||||
var bytes = new byte[2];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index] = (byte)value;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesBE(this uint value)
|
||||
{
|
||||
var bytes = new byte[4];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)(value >> 24);
|
||||
bytes[index++] = (byte)(value >> 16);
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index] = (byte)value;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesBE(this ulong value)
|
||||
{
|
||||
var bytes = new byte[8];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)(value >> 56);
|
||||
bytes[index++] = (byte)(value >> 48);
|
||||
bytes[index++] = (byte)(value >> 40);
|
||||
bytes[index++] = (byte)(value >> 32);
|
||||
bytes[index++] = (byte)(value >> 24);
|
||||
bytes[index++] = (byte)(value >> 16);
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index] = (byte)value;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesLE(this sbyte value)
|
||||
{
|
||||
var bytes = new byte[2];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)value;
|
||||
bytes[index] = (byte)(value >> 8);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesLE(this short value)
|
||||
{
|
||||
var bytes = new byte[2];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)value;
|
||||
bytes[index] = (byte)(value >> 8);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesLE(this int value)
|
||||
{
|
||||
var bytes = new byte[4];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)value;
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index++] = (byte)(value >> 16);
|
||||
bytes[index] = (byte)(value >> 24);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesLE(this long value)
|
||||
{
|
||||
var bytes = new byte[8];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)value;
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index++] = (byte)(value >> 16);
|
||||
bytes[index++] = (byte)(value >> 24);
|
||||
bytes[index++] = (byte)(value >> 32);
|
||||
bytes[index++] = (byte)(value >> 40);
|
||||
bytes[index++] = (byte)(value >> 48);
|
||||
bytes[index] = (byte)(value >> 56);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesLE(this ushort value)
|
||||
{
|
||||
var bytes = new byte[2];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)value;
|
||||
bytes[index] = (byte)(value >> 8);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesLE(this uint value)
|
||||
{
|
||||
var bytes = new byte[4];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)value;
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index++] = (byte)(value >> 16);
|
||||
bytes[index] = (byte)(value >> 24);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] GetBytesLE(this ulong value)
|
||||
{
|
||||
var bytes = new byte[8];
|
||||
var index = 0;
|
||||
|
||||
bytes[index++] = (byte)value;
|
||||
bytes[index++] = (byte)(value >> 8);
|
||||
bytes[index++] = (byte)(value >> 16);
|
||||
bytes[index++] = (byte)(value >> 24);
|
||||
bytes[index++] = (byte)(value >> 32);
|
||||
bytes[index++] = (byte)(value >> 40);
|
||||
bytes[index++] = (byte)(value >> 48);
|
||||
bytes[index] = (byte)(value >> 56);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static sbyte ToSByteBE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(sbyte);
|
||||
|
||||
value ^= (sbyte)(bytes[start++] << 8);
|
||||
value ^= (sbyte)bytes[start];
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static short ToInt16BE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(short);
|
||||
|
||||
value ^= (short)(bytes[start++] << 8);
|
||||
value ^= bytes[start];
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int ToInt32BE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(int);
|
||||
|
||||
value ^= bytes[start++] << 24;
|
||||
value ^= bytes[start++] << 16;
|
||||
value ^= bytes[start++] << 8;
|
||||
value ^= bytes[start];
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static long ToInt64BE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(long);
|
||||
|
||||
value ^= bytes[start++] << 56;
|
||||
value ^= bytes[start++] << 48;
|
||||
value ^= bytes[start++] << 40;
|
||||
value ^= bytes[start++] << 32;
|
||||
value ^= bytes[start++] << 24;
|
||||
value ^= bytes[start++] << 16;
|
||||
value ^= bytes[start++] << 8;
|
||||
value ^= bytes[start];
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static ushort ToUInt16BE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(ushort);
|
||||
|
||||
value ^= (ushort)(bytes[start++] << 8);
|
||||
value ^= bytes[start];
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static uint ToUInt32BE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(uint);
|
||||
|
||||
value ^= (uint)(bytes[start++] << 24);
|
||||
value ^= (uint)(bytes[start++] << 16);
|
||||
value ^= (uint)(bytes[start++] << 8);
|
||||
value ^= bytes[start];
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static ulong ToUInt64BE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(ulong);
|
||||
|
||||
value ^= (ulong)(bytes[start++] << 56);
|
||||
value ^= (ulong)(bytes[start++] << 48);
|
||||
value ^= (ulong)(bytes[start++] << 40);
|
||||
value ^= (ulong)(bytes[start++] << 32);
|
||||
value ^= (ulong)(bytes[start++] << 24);
|
||||
value ^= (ulong)(bytes[start++] << 16);
|
||||
value ^= (ulong)(bytes[start++] << 8);
|
||||
value ^= bytes[start];
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static sbyte ToSByteLE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(sbyte);
|
||||
|
||||
value ^= (sbyte)bytes[start++];
|
||||
value ^= (sbyte)(bytes[start] << 8);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static short ToInt16LE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(short);
|
||||
|
||||
value ^= bytes[start++];
|
||||
value ^= (short)(bytes[start] << 8);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int ToInt32LE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(int);
|
||||
|
||||
value ^= bytes[start++];
|
||||
value ^= bytes[start++] << 8;
|
||||
value ^= bytes[start++] << 16;
|
||||
value ^= bytes[start] << 24;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static long ToInt64LE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(long);
|
||||
|
||||
value ^= bytes[start++];
|
||||
value ^= bytes[start++] << 8;
|
||||
value ^= bytes[start++] << 16;
|
||||
value ^= bytes[start++] << 24;
|
||||
value ^= bytes[start++] << 32;
|
||||
value ^= bytes[start++] << 40;
|
||||
value ^= bytes[start++] << 48;
|
||||
value ^= bytes[start] << 56;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static ushort ToUInt16LE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(ushort);
|
||||
|
||||
value ^= bytes[start++];
|
||||
value ^= (ushort)(bytes[start] << 8);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static uint ToUInt32LE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(uint);
|
||||
|
||||
value ^= bytes[start++];
|
||||
value ^= (uint)(bytes[start++] << 8);
|
||||
value ^= (uint)(bytes[start++] << 16);
|
||||
value ^= (uint)(bytes[start] << 24);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static ulong ToUInt64LE(this byte[] bytes, int start = 0)
|
||||
{
|
||||
var value = default(ulong);
|
||||
|
||||
value ^= bytes[start++];
|
||||
value ^= (ulong)(bytes[start++] << 8);
|
||||
value ^= (ulong)(bytes[start++] << 16);
|
||||
value ^= (ulong)(bytes[start++] << 24);
|
||||
value ^= (ulong)(bytes[start++] << 32);
|
||||
value ^= (ulong)(bytes[start++] << 40);
|
||||
value ^= (ulong)(bytes[start++] << 48);
|
||||
value ^= (ulong)(bytes[start] << 56);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static ushort CRCCCITT(this byte[] bytes, int start = 0, int length = 0)
|
||||
{
|
||||
if (length == 0)
|
||||
{
|
||||
length = bytes.Length;
|
||||
}
|
||||
|
||||
var crc = (ushort)0xFFFF;
|
||||
|
||||
for (var b = start; b < length; b++)
|
||||
{
|
||||
var _byte = bytes[b];
|
||||
var token = (ushort)((_byte << 8) & 0xFF00);
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
if (0x8000 == ((crc ^ token) & 0x8000))
|
||||
{
|
||||
crc <<= 1;
|
||||
crc ^= 0x1021;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc <<= 1;
|
||||
}
|
||||
|
||||
token <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
public static byte[] GetBytes(this string hexString)
|
||||
{
|
||||
var bytes = new List<byte>();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(hexString))
|
||||
{
|
||||
hexString = Regex.Replace(hexString, "[^a-fA-F0-9]*", string.Empty);
|
||||
|
||||
var first = true;
|
||||
var x = 0;
|
||||
|
||||
foreach (var hex in hexString)
|
||||
{
|
||||
if ('0' <= hex && hex <= '9')
|
||||
{
|
||||
x += hex - '0';
|
||||
}
|
||||
else if ('A' <= hex && hex <= 'F')
|
||||
{
|
||||
x += hex - 'A' + 10;
|
||||
}
|
||||
else if ('a' <= hex && hex <= 'f')
|
||||
{
|
||||
x = hex - 'a' + 10;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (first)
|
||||
{
|
||||
x *= 16;
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes.Add((byte)x);
|
||||
|
||||
x = 0;
|
||||
}
|
||||
|
||||
first = !first;
|
||||
}
|
||||
}
|
||||
|
||||
return bytes.ToArray();
|
||||
}
|
||||
|
||||
public static byte[] GetEncryptionKey(this string hexString, int requiredLength = 16)
|
||||
{
|
||||
var bytes = hexString.GetBytes();
|
||||
|
||||
if (bytes?.Length != requiredLength)
|
||||
{
|
||||
return default(byte[]);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using System.Threading;
|
||||
|
||||
using SysSerialPort = System.IO.Ports.SerialPort;
|
||||
|
||||
public sealed class SerialPort
|
||||
{
|
||||
private static readonly ConcurrentDictionary<string, SysSerialPort> serialPorts
|
||||
= new ConcurrentDictionary<string, SysSerialPort>();
|
||||
|
||||
private readonly ManualResetEventSlim readAwaiter;
|
||||
private readonly ManualResetEventSlim closeAwaiter;
|
||||
|
||||
public SerialPort(string name, int baudRate, Parity parity, int dataBits, StopBits stopBits)
|
||||
{
|
||||
this.COMPort = name;
|
||||
this.readAwaiter = new ManualResetEventSlim();
|
||||
this.closeAwaiter = new ManualResetEventSlim();
|
||||
|
||||
var sp = new SysSerialPort(this.COMPort, baudRate, parity, dataBits, stopBits);
|
||||
|
||||
serialPorts.AddOrUpdate(
|
||||
key: this.COMPort,
|
||||
addValue: sp,
|
||||
updateValueFactory: (_1, _2) => sp);
|
||||
}
|
||||
|
||||
public event Action Connected;
|
||||
public event Action Disconnected;
|
||||
public event Action<string> Logging;
|
||||
|
||||
public string COMPort { get; }
|
||||
|
||||
public bool IsOpen
|
||||
=> serialPorts.TryGetValue(this.COMPort, out var sp)
|
||||
&& sp.IsOpen;
|
||||
|
||||
public void Close()
|
||||
{
|
||||
if (serialPorts.TryGetValue(this.COMPort, out var sp))
|
||||
{
|
||||
try
|
||||
{
|
||||
sp.Close();
|
||||
this.closeAwaiter.Wait(3000);
|
||||
this.closeAwaiter.Reset();
|
||||
|
||||
sp.DataReceived -= this.SP_DataReceived;
|
||||
sp.Disposed -= this.SP_Disposed;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
if (serialPorts.TryGetValue(this.COMPort, out var sp) && !sp.IsOpen)
|
||||
{
|
||||
try
|
||||
{
|
||||
sp.DataReceived += this.SP_DataReceived;
|
||||
sp.Disposed += this.SP_Disposed;
|
||||
|
||||
sp.Open();
|
||||
|
||||
this.Connected?.Invoke();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<byte[]> ReadBytes()
|
||||
{
|
||||
var sp = this.GetOpenSP();
|
||||
var size = sp.ReadBufferSize;
|
||||
var buffer = new byte[size];
|
||||
var length = 0;
|
||||
|
||||
using (sp)
|
||||
{
|
||||
while (sp.IsOpen)
|
||||
{
|
||||
this.readAwaiter.Wait();
|
||||
|
||||
try
|
||||
{
|
||||
buffer = new byte[size];
|
||||
length = sp.Read(buffer, 0, size);
|
||||
|
||||
Array.Resize(ref buffer, length);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
|
||||
this.readAwaiter.Reset();
|
||||
|
||||
yield return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> ReadLines()
|
||||
{
|
||||
var sp = this.GetOpenSP();
|
||||
var text = default(string);
|
||||
|
||||
using (sp)
|
||||
{
|
||||
while (sp.IsOpen)
|
||||
{
|
||||
this.readAwaiter.Wait();
|
||||
|
||||
try
|
||||
{
|
||||
text = sp.ReadLine();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
|
||||
this.readAwaiter.Reset();
|
||||
|
||||
yield return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveConnection()
|
||||
{
|
||||
this.Close();
|
||||
serialPorts.TryRemove(this.COMPort, out _);
|
||||
}
|
||||
|
||||
public void Write(byte[] bytes)
|
||||
{
|
||||
var sp = this.GetOpenSP();
|
||||
|
||||
try
|
||||
{
|
||||
sp.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void Write(string text)
|
||||
{
|
||||
var sp = this.GetOpenSP();
|
||||
|
||||
try
|
||||
{
|
||||
sp.Write(text);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Logging?.Invoke(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private SysSerialPort GetOpenSP()
|
||||
{
|
||||
if (!serialPorts.TryGetValue(this.COMPort, out var sp))
|
||||
{
|
||||
throw new InvalidOperationException($"{nameof(SerialPort)} on {this.COMPort} dose not exists!");
|
||||
}
|
||||
|
||||
if (!sp.IsOpen)
|
||||
{
|
||||
this.Open();
|
||||
}
|
||||
|
||||
return sp;
|
||||
}
|
||||
|
||||
private void SP_DataReceived(object _, SerialDataReceivedEventArgs args)
|
||||
=> this.readAwaiter.Set();
|
||||
|
||||
private void SP_Disposed(object _, EventArgs _1)
|
||||
{
|
||||
this.closeAwaiter.Set();
|
||||
this.Disconnected?.Invoke();
|
||||
}
|
||||
|
||||
public static string[] GetPortNames()
|
||||
=> SysSerialPort.GetPortNames();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
using System.IO.Ports;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
using System.IO.Ports;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
using System.Threading;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
namespace Common.Hardware.Ports
|
||||
{
|
||||
using System;
|
||||
|
||||
+21
-21
@@ -4,18 +4,16 @@
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}</ProjectGuid>
|
||||
<ProjectGuid>{8DE8E742-EE0A-4004-AA49-3D08D748E5AC}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Common.Hardware.Interfaces.Ports.SirtBroadcaster</RootNamespace>
|
||||
<AssemblyName>Common.Hardware.Interfaces.Ports.SirtBroadcaster</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Common.Hardware.SIRT</RootNamespace>
|
||||
<AssemblyName>Common.Hardware.SIRT</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
@@ -26,7 +24,6 @@
|
||||
<NoWarn>IDE0003;IDE0049;</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
@@ -34,41 +31,44 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="JustSirtBroadcaster.cs" />
|
||||
<Compile Include="JustSirtTask.cs" />
|
||||
<Compile Include="JustTaskStatus.cs" />
|
||||
<Compile Include="Parameters\BluetoothOperating.cs" />
|
||||
<Compile Include="Parameters\OperatingModes.cs" />
|
||||
<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.Public.cs" />
|
||||
<Compile Include="SIRTMessage.cs" />
|
||||
<Compile Include="SIRTTask.Public.cs" />
|
||||
<Compile Include="SIRTTaskState.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\Utils\Common.Utils.Extensions\Common.Utils.Extensions.csproj">
|
||||
<Project>{05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3}</Project>
|
||||
<Name>Common.Utils.Extensions</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common.Hardware.Interfaces.Ports.Sirt\Common.Hardware.Interfaces.Ports.Sirt.csproj">
|
||||
<Project>{B23BFAF9-08AE-4311-8C08-FB2BB49EA2AD}</Project>
|
||||
<Name>Common.Hardware.Interfaces.Ports.Sirt</Name>
|
||||
<Compile Include="SIRTTask.Internal.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Common.Hardware.Ports\Common.Hardware.Ports.csproj">
|
||||
<Project>{9ae071c0-db12-4e09-a3c7-43f6dcd518d6}</Project>
|
||||
<Name>Common.Hardware.Ports</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
+14
-16
@@ -1,21 +1,19 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
public class BluetoothOperating
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
private readonly byte[] bits;
|
||||
|
||||
public BluetoothOperating() => this.bits = new Byte[8];
|
||||
public BluetoothOperating() => this.bits = new byte[8];
|
||||
|
||||
private BluetoothOperating(Byte[] bits) => this.bits = bits;
|
||||
private BluetoothOperating(byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// 0 -> Transparent Mode at 115k2 Baud 8,n,1
|
||||
/// </summary>
|
||||
public Boolean BtOpMode
|
||||
public bool BtOpMode
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
}
|
||||
@@ -32,10 +30,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean BtPwrSave
|
||||
public bool BtPwrSave
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[6] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -50,16 +48,16 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean BtOff
|
||||
public bool BtOff
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[7] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(BluetoothOperating param)
|
||||
=> param.bits.ToByte();
|
||||
public static implicit operator byte(BluetoothOperating param)
|
||||
=> param.bits.GetByteLE();
|
||||
|
||||
public static implicit operator BluetoothOperating(Byte _byte)
|
||||
=> new BluetoothOperating(_byte.GetBits());
|
||||
public static implicit operator BluetoothOperating(byte _byte)
|
||||
=> new BluetoothOperating(_byte.GetBitsLE());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
public enum OperatingModes
|
||||
{
|
||||
+48
-26
@@ -1,8 +1,8 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
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
|
||||
@@ -11,11 +11,13 @@
|
||||
/// </summary>
|
||||
public class P11
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
private readonly byte[] bits;
|
||||
|
||||
public P11() => this.bits = new Byte[8];
|
||||
public P11() => this.bits = new byte[8];
|
||||
|
||||
private P11(Byte[] bits) => this.bits = bits;
|
||||
public P11(byte p11) => this.bits = p11.GetBitsLE();
|
||||
|
||||
public P11(byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
@@ -30,10 +32,10 @@
|
||||
/// </list>
|
||||
/// <para>only valid if both RF-Module programmed for Sensus RF</para>
|
||||
/// </summary>
|
||||
public Boolean SrcChannel
|
||||
public bool SrcChannel
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[0] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,10 +51,10 @@
|
||||
/// </list>
|
||||
/// <para>only valid if both RF-Module programmed for Sensus RF</para>
|
||||
/// </summary>
|
||||
public Boolean BothValid
|
||||
public bool BothValid
|
||||
{
|
||||
get => this.bits[1] == 1;
|
||||
set => this.bits[1] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[1] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -68,10 +70,10 @@
|
||||
/// </list>
|
||||
/// <para>i.e. radio checksum is wrong ...</para>
|
||||
/// </summary>
|
||||
public Boolean InvalidMod1
|
||||
public bool InvalidMod1
|
||||
{
|
||||
get => this.bits[2] == 1;
|
||||
set => this.bits[2] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[2] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,10 +89,10 @@
|
||||
/// </list>
|
||||
/// <para>i.e. radio checksum is wrong ...</para>
|
||||
/// </summary>
|
||||
public Boolean InvalidMod2
|
||||
public bool InvalidMod2
|
||||
{
|
||||
get => this.bits[3] == 1;
|
||||
set => this.bits[3] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[3] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -105,10 +107,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean LenOverflow
|
||||
public bool LenOverflow
|
||||
{
|
||||
get => this.bits[4] == 1;
|
||||
set => this.bits[4] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[4] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -123,10 +125,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean Attention
|
||||
public bool Attention
|
||||
{
|
||||
get => this.bits[5] == 1;
|
||||
set => this.bits[5] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[5] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,10 +149,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean ModeRF
|
||||
public bool ModeRF
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[6] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,16 +167,36 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean ModeSensus
|
||||
public bool ModeSensus
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[7] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(P11 param)
|
||||
=> param.bits.ToByte();
|
||||
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"));
|
||||
|
||||
public static implicit operator P11(Byte _byte)
|
||||
=> new P11(_byte.GetBits());
|
||||
return infoBuilder.ToString().Trim();
|
||||
}
|
||||
|
||||
public static implicit operator byte(P11 p11)
|
||||
=> p11.bits.GetByteLE();
|
||||
|
||||
public static implicit operator string(P11 p11)
|
||||
=> p11.ToString();
|
||||
|
||||
public static implicit operator P11(byte _byte)
|
||||
=> new P11(_byte.GetBitsLE());
|
||||
}
|
||||
}
|
||||
+41
-26
@@ -1,6 +1,6 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System;
|
||||
|
||||
@@ -13,11 +13,13 @@
|
||||
/// </summary>
|
||||
public class P12
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
private readonly byte[] bits;
|
||||
|
||||
public P12() => this.bits = new Byte[8];
|
||||
public P12() => this.bits = new byte[8];
|
||||
|
||||
private P12(Byte[] bits) => this.bits = bits;
|
||||
public P12(byte p12) => this.bits = p12.GetBitsLE();
|
||||
|
||||
public P12(byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
@@ -31,10 +33,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean BufFull
|
||||
public bool BufFull
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[0] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -49,10 +51,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean OsBusy
|
||||
public bool OsBusy
|
||||
{
|
||||
get => this.bits[1] == 1;
|
||||
set => this.bits[1] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[1] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -67,10 +69,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean WrongCRC
|
||||
public bool WrongCRC
|
||||
{
|
||||
get => this.bits[2] == 1;
|
||||
set => this.bits[2] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[2] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -85,17 +87,17 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean CmdNotExecuted
|
||||
public bool CmdNotExecuted
|
||||
{
|
||||
get => this.bits[3] == 1;
|
||||
set => this.bits[3] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[3] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>telegram or command Byte unknown</description>
|
||||
/// <description>telegram or command byte unknown</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
@@ -103,10 +105,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean CmdUnknown
|
||||
public bool CmdUnknown
|
||||
{
|
||||
get => this.bits[4] == 1;
|
||||
set => this.bits[4] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[4] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -121,10 +123,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean NoEntry
|
||||
public bool NoEntry
|
||||
{
|
||||
get => this.bits[5] == 1;
|
||||
set => this.bits[5] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[5] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -139,10 +141,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean ByteUnknown
|
||||
public bool ByteUnknown
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[6] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -157,16 +159,29 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean WildCardAddr
|
||||
public bool WildCardAddr
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[7] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(P12 param)
|
||||
=> param.bits.ToByte();
|
||||
public override string ToString()
|
||||
=> $"{nameof(P12)}: {string.Join(string.Empty, this.bits)}"
|
||||
+ (this.BufFull ? Environment.NewLine + nameof(this.BufFull) : default(string))
|
||||
+ (this.OsBusy ? Environment.NewLine + nameof(this.OsBusy) : default(string))
|
||||
+ (this.WrongCRC ? Environment.NewLine + nameof(this.WrongCRC) : default(string))
|
||||
+ (this.CmdNotExecuted ? Environment.NewLine + nameof(this.CmdNotExecuted) : default(string))
|
||||
+ (this.CmdUnknown ? Environment.NewLine + nameof(this.CmdUnknown) : default(string))
|
||||
+ (this.NoEntry ? Environment.NewLine + nameof(this.NoEntry) : default(string))
|
||||
+ (this.ByteUnknown ? Environment.NewLine + nameof(this.ByteUnknown) : default(string));
|
||||
|
||||
public static implicit operator P12(Byte _byte)
|
||||
=> new P12(_byte.GetBits());
|
||||
public static implicit operator byte(P12 p11)
|
||||
=> p11.bits.GetByteLE();
|
||||
|
||||
public static implicit operator string(P12 p11)
|
||||
=> p11.ToString();
|
||||
|
||||
public static implicit operator P12(byte _byte)
|
||||
=> new P12(_byte.GetBitsLE());
|
||||
}
|
||||
}
|
||||
+24
-26
@@ -1,13 +1,11 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
/// <summary>
|
||||
/// Parameter P81-1 is the first modifier of "Write to PAM Pool" command and is placed at third position,
|
||||
/// if telegram from PC -> SIRT begins with {0x55, 0x81}.
|
||||
/// This Byte describe in detailed what PAM message should do in detail.
|
||||
/// This byte describe in detailed what PAM message should do in detail.
|
||||
/// <para>There is an public priority within the bits which are described at next table:</para>
|
||||
/// <list type="table">
|
||||
/// <listheader>
|
||||
@@ -102,11 +100,11 @@
|
||||
/// </summary>
|
||||
public class P811
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
private readonly byte[] bits;
|
||||
|
||||
public P811() => this.bits = new Byte[8];
|
||||
public P811() => this.bits = new byte[8];
|
||||
|
||||
private P811(Byte[] bits) => this.bits = bits;
|
||||
private P811(byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
@@ -120,10 +118,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean WakeUpModul
|
||||
public bool WakeUpModul
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[0] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -138,10 +136,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean WakeUpCmd
|
||||
public bool WakeUpCmd
|
||||
{
|
||||
get => this.bits[2] == 1;
|
||||
set => this.bits[2] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[2] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -156,10 +154,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean IgnoreTimeout
|
||||
public bool IgnoreTimeout
|
||||
{
|
||||
get => this.bits[3] == 1;
|
||||
set => this.bits[3] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[3] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -174,10 +172,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean DelPamSemi
|
||||
public bool DelPamSemi
|
||||
{
|
||||
get => this.bits[4] == 1;
|
||||
set => this.bits[4] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[4] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -192,10 +190,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean DelPamTx
|
||||
public bool DelPamTx
|
||||
{
|
||||
get => this.bits[5] == 1;
|
||||
set => this.bits[5] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[5] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -210,10 +208,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean DelPamAdr
|
||||
public bool DelPamAdr
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[6] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -228,16 +226,16 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean DelPamAll
|
||||
public bool DelPamAll
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[7] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(P811 param)
|
||||
=> param.bits.ToByte();
|
||||
public static implicit operator byte(P811 param)
|
||||
=> param.bits.GetByteLE();
|
||||
|
||||
public static implicit operator P811(Byte _byte)
|
||||
=> new P811(_byte.GetBits());
|
||||
public static implicit operator P811(byte _byte)
|
||||
=> new P811(_byte.GetBitsLE());
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System.Text;
|
||||
|
||||
public class PAMStatus
|
||||
{
|
||||
private readonly byte[] bits;
|
||||
|
||||
public PAMStatus(byte _byte)
|
||||
=> this.bits = _byte.GetBitsLE();
|
||||
|
||||
public bool CMD_UNKNOWN => this.bits[0] == 1;
|
||||
|
||||
public bool WRONG_AUTH => this.bits[1] == 1;
|
||||
|
||||
public bool EXPIRED_AUTH => this.bits[2] == 1;
|
||||
|
||||
public bool MIXED_TYPES => this.bits[3] == 1;
|
||||
|
||||
public bool OUT_OF_RANGE => this.bits[4] == 1;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var statusBuilder = new StringBuilder();
|
||||
|
||||
if (this.CMD_UNKNOWN)
|
||||
{
|
||||
statusBuilder.AppendLine(nameof(this.CMD_UNKNOWN));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
public static byte EXPIREDAUTH = 4;
|
||||
|
||||
public static implicit operator byte(PAMStatus status)
|
||||
=> status?.bits?.GetByteLE() ?? 0xFF;
|
||||
|
||||
public static implicit operator string(PAMStatus status)
|
||||
=> status?.ToString();
|
||||
}
|
||||
}
|
||||
+5
-7
@@ -1,12 +1,10 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using System;
|
||||
|
||||
public class PamTimeout
|
||||
{
|
||||
public PamTimeout() => this.Minutes = 0;
|
||||
|
||||
private PamTimeout(Byte minutes) => this.Minutes = minutes;
|
||||
private PamTimeout(byte minutes) => this.Minutes = minutes;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
@@ -21,12 +19,12 @@
|
||||
/// </list>
|
||||
/// <para>Several bits at parameter P81-1 or P81-2 may delete entry at PAM-Pool before 5 minutes elapsed. </para>
|
||||
/// </summary>
|
||||
public Byte Minutes { get; set; }
|
||||
public byte Minutes { get; set; }
|
||||
|
||||
public static implicit operator Byte(PamTimeout param)
|
||||
public static implicit operator byte(PamTimeout param)
|
||||
=> param.Minutes;
|
||||
|
||||
public static implicit operator PamTimeout(Byte _byte)
|
||||
public static implicit operator PamTimeout(byte _byte)
|
||||
=> new PamTimeout(_byte);
|
||||
}
|
||||
}
|
||||
+16
-16
@@ -1,16 +1,16 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
|
||||
namespace Common.Hardware.SIRT.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System;
|
||||
|
||||
public class RFModuleOperating
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
private readonly byte[] bits;
|
||||
|
||||
public RFModuleOperating() => this.bits = new Byte[8];
|
||||
public RFModuleOperating() => this.bits = new byte[8];
|
||||
|
||||
private RFModuleOperating(Byte[] bits) => this.bits = bits;
|
||||
private RFModuleOperating(byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// 0 -> Transparent Mode at 115k2 Baud 8,n,1
|
||||
@@ -19,15 +19,15 @@
|
||||
{
|
||||
get
|
||||
{
|
||||
var bits = new Byte[8];
|
||||
var bits = new byte[8];
|
||||
|
||||
Array.Copy(this.bits, 0, bits, 0, 4);
|
||||
|
||||
return (OperatingModes)bits.ToByte();
|
||||
return (OperatingModes)bits.GetByteLE();
|
||||
}
|
||||
set
|
||||
{
|
||||
var bits = ((Byte)value).GetBits();
|
||||
var bits = ((byte)value).GetBitsLE();
|
||||
|
||||
Array.Copy(bits, 0, this.bits, 0, 4);
|
||||
}
|
||||
@@ -45,10 +45,10 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean Antenna
|
||||
public bool Antenna
|
||||
{
|
||||
get => this.bits[4] == 1;
|
||||
set => this.bits[4] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[4] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,16 +63,16 @@
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean RfOff
|
||||
public bool RfOff
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[7] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(RFModuleOperating param)
|
||||
=> param.bits.ToByte();
|
||||
public static implicit operator byte(RFModuleOperating param)
|
||||
=> param.bits.GetByteLE();
|
||||
|
||||
public static implicit operator RFModuleOperating(Byte _byte)
|
||||
=> new RFModuleOperating(_byte.GetBits());
|
||||
public static implicit operator RFModuleOperating(byte _byte)
|
||||
=> new RFModuleOperating(_byte.GetBitsLE());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
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; }
|
||||
|
||||
public override string ToString() => $"{this.Dbm}dBm ({this.Percent:0.0}%)";
|
||||
|
||||
public static implicit operator string(RSSI rssi) => rssi?.ToString();
|
||||
}
|
||||
}
|
||||
+22
-24
@@ -1,16 +1,14 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
public class SirtOperating
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
private readonly byte[] bits;
|
||||
|
||||
public SirtOperating() => this.bits = new Byte[8];
|
||||
public SirtOperating() => this.bits = new byte[8];
|
||||
|
||||
private SirtOperating(Byte[] bits) => this.bits = bits;
|
||||
private SirtOperating(byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
@@ -25,10 +23,10 @@
|
||||
/// </list>
|
||||
/// <para>non requested messages are received radio payloads if a radio module is switched on</para>
|
||||
/// </summary>
|
||||
public Boolean DataBtOut
|
||||
public bool DataBtOut
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[0] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,12 +40,12 @@
|
||||
/// <description>if both RF-Modules are set to SensusRF Mode, the channel with higher RSSI Level will be send out</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>for test purposes both receiver outputs can be shown - but remember Double traffic rate on Bluetoothor USB-output</para>
|
||||
/// <para>for test purposes both receiver outputs can be shown - but remember double traffic rate on Bluetoothor USB-output</para>
|
||||
/// </summary>
|
||||
public Boolean BothChsOut
|
||||
public bool BothChsOut
|
||||
{
|
||||
get => this.bits[1] == 1;
|
||||
set => this.bits[1] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[1] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,10 +61,10 @@
|
||||
/// </list>
|
||||
/// <para>may be only interesting for test purposes </para>
|
||||
/// </summary>
|
||||
public Boolean IgnoreCRC
|
||||
public bool IgnoreCRC
|
||||
{
|
||||
get => this.bits[2] == 1;
|
||||
set => this.bits[2] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[2] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -82,10 +80,10 @@
|
||||
/// </list>
|
||||
/// <para>New at Version 1.0.0.6</para>
|
||||
/// </summary>
|
||||
public Boolean IgnoreUSBrules
|
||||
public bool IgnoreUSBrules
|
||||
{
|
||||
get => this.bits[3] == 1;
|
||||
set => this.bits[3] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[3] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -101,10 +99,10 @@
|
||||
/// </list>
|
||||
/// <para>timeout starts at beginning, if any command or communication to and from SIRT is initiated</para>
|
||||
/// </summary>
|
||||
public Boolean SirtPwrSave
|
||||
public bool SirtPwrSave
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[6] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -123,16 +121,16 @@
|
||||
/// on per command only by pushing green button for a second
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public Boolean SirtOff
|
||||
public bool SirtOff
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
set => this.bits[7] = (byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(SirtOperating param)
|
||||
=> param.bits.ToByte();
|
||||
public static implicit operator byte(SirtOperating param)
|
||||
=> param.bits.GetByteLE();
|
||||
|
||||
public static implicit operator SirtOperating(Byte _byte)
|
||||
=> new SirtOperating(_byte.GetBits());
|
||||
public static implicit operator SirtOperating(byte _byte)
|
||||
=> new SirtOperating(_byte.GetBitsLE());
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Common.Hardware.Interfaces.Ports.SIRT")]
|
||||
[assembly: AssemblyTitle("Common.Hardware.SIRT")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Common.Hardware.Interfaces.Ports.SIRT")]
|
||||
[assembly: AssemblyProduct("Common.Hardware.SIRT")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("b23bfaf9-08ae-4311-8c08-fb2bb49ea2ad")]
|
||||
[assembly: Guid("8de8e742-ee0a-4004-aa49-3d08d748e5ac")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
@@ -0,0 +1,309 @@
|
||||
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
|
||||
= new ConcurrentDictionary<uint, ConcurrentQueue<SIRTTask>>();
|
||||
private readonly SerialPort serialPort;
|
||||
|
||||
private CancellationTokenSource cancellationTokenSource;
|
||||
private CancellationToken cancellationToken;
|
||||
private Task processingTask;
|
||||
|
||||
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 void ExceptionLogging(Task task)
|
||||
{
|
||||
if (task.Exception != null)
|
||||
{
|
||||
this.Logging?.Invoke(task.Exception.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
this.TaskRemoveEventHandlers(task);
|
||||
|
||||
if (task.State == SIRTTaskState.Completed)
|
||||
{
|
||||
if (this.tasks.TryGetValue(task.RequestAddress, out var tasks) && tasks.TryPeek(out var _task) && _task.State == SIRTTaskState.Completed)
|
||||
{
|
||||
tasks.TryDequeue(out _task);
|
||||
}
|
||||
|
||||
if (task.RequestAddress != task.ResponseAddress)
|
||||
{
|
||||
if (this.tasks.TryGetValue(task.ResponseAddress, out tasks) && tasks.TryPeek(out _task) && _task.State == SIRTTaskState.Completed)
|
||||
{
|
||||
tasks.TryDequeue(out _task);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (task.State == SIRTTaskState.Cancelled)
|
||||
{
|
||||
this.OnTaskTimeout(task);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTaskTimeout(SIRTTask task)
|
||||
{
|
||||
var deleteRequestAddress = SIRTTask.DeleteFromPamPool(task.RequestAddress);
|
||||
this.TryRun(deleteRequestAddress);
|
||||
|
||||
var deleteResponseAddress = SIRTTask.DeleteFromPamPool(task.ResponseAddress);
|
||||
this.TryRun(deleteResponseAddress);
|
||||
}
|
||||
|
||||
private void SerialPort_Connected()
|
||||
{
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
this.cancellationToken = this.cancellationTokenSource.Token;
|
||||
|
||||
Task.Factory
|
||||
.StartNew(this.StartReadingMessages, this.cancellationToken)
|
||||
.ContinueWith(this.ExceptionLogging);
|
||||
Task.Factory
|
||||
.StartNew(this.ActivateSIRT, this.cancellationToken)
|
||||
.ContinueWith(this.ExceptionLogging);
|
||||
|
||||
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()
|
||||
{
|
||||
this.processingTask = Task.Factory.StartNew(() =>
|
||||
{
|
||||
var manualResetEventSlim = new ManualResetEventSlim();
|
||||
var addresses = default(ICollection<uint>);
|
||||
|
||||
while (!this.cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
// addresses = this.GetAddressesInPamPool();
|
||||
|
||||
foreach (var tasksQueue in this.tasks.Values.ToArray())
|
||||
{
|
||||
if (tasksQueue.TryPeek(out var task) && task.State == SIRTTaskState.Pending)
|
||||
{
|
||||
// if (addresses.Count < 5 && !addresses.Any(x => x == task.RequestAddress) && !addresses.Any(x => x == task.ResponseAddress))
|
||||
{
|
||||
this.serialPort.Write(task.Start());
|
||||
this.Logging?.Invoke(task.ToString());
|
||||
|
||||
// addresses.Add(task.RequestAddress);
|
||||
}
|
||||
}
|
||||
|
||||
manualResetEventSlim.Wait(100);
|
||||
manualResetEventSlim.Reset();
|
||||
}
|
||||
|
||||
manualResetEventSlim.Wait(100);
|
||||
manualResetEventSlim.Reset();
|
||||
}
|
||||
|
||||
}, this.cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current)
|
||||
.ContinueWith(this.ExceptionLogging);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private void TaskRemoveEventHandlers(SIRTTask task)
|
||||
{
|
||||
task.Cancelled -= this.OnStateChanged;
|
||||
task.Completed -= this.OnStateChanged;
|
||||
task.Timeouted -= this.OnTaskTimeout;
|
||||
}
|
||||
|
||||
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());
|
||||
manualResetEventSlim.Wait(task.Timeout);
|
||||
manualResetEventSlim.Reset();
|
||||
|
||||
task.Cancelled += taskStateChanged;
|
||||
task.Completed += taskStateChanged;
|
||||
|
||||
this.MessageReceived -= messageReceived;
|
||||
|
||||
return result(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
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>>();
|
||||
}
|
||||
|
||||
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, (_, _requestTasks) => _requestTasks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveConnection()
|
||||
=> this.serialPort.RemoveConnection();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,428 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Parity = System.IO.Ports.Parity;
|
||||
using StopBits = System.IO.Ports.StopBits;
|
||||
|
||||
public class SIRTBroadcaster
|
||||
{
|
||||
private readonly ConcurrentDictionary<uint, ConcurrentQueue<SIRTTask>> tasks;
|
||||
private readonly SerialPort serialPort;
|
||||
|
||||
private CancellationTokenSource cancellationTokenSource;
|
||||
private CancellationToken cancellationToken;
|
||||
private Task readingTask;
|
||||
private Task processingTask;
|
||||
private Task activationTask;
|
||||
private AnswerTask sirtTask;
|
||||
|
||||
public SIRTBroadcaster(string comPort)
|
||||
{
|
||||
this.serialPort = new SerialPort(comPort, 115200, Parity.None, 8, StopBits.One);
|
||||
this.tasks = new ConcurrentDictionary<uint, ConcurrentQueue<SIRTTask>>();
|
||||
}
|
||||
|
||||
public event Action Activated;
|
||||
public event Action Connected;
|
||||
public event Action Disconnected;
|
||||
public event Action<string> Log;
|
||||
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.Log -= this.OnError;
|
||||
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.Log += this.OnError;
|
||||
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 _))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EnqueueTask(SIRTTask task)
|
||||
{
|
||||
if (this.Frequency == task.Frequency)
|
||||
{
|
||||
task.Cancelled += this.TryDequeueTask;
|
||||
task.Completed += this.TryDequeueTask;
|
||||
task.Timeouted += this.Task_Timeouted;
|
||||
task.Updated += this.Task_Updated;
|
||||
|
||||
var requestTasks = this.tasks.GetOrAdd(task.RequestAddress, new ConcurrentQueue<SIRTTask>());
|
||||
task.Index = requestTasks.Count;
|
||||
|
||||
requestTasks.Enqueue(task);
|
||||
|
||||
if (task.RequestAddress != task.ResponseAddress)
|
||||
{
|
||||
this.tasks.AddOrUpdate(task.ResponseAddress, requestTasks, (k, v) => requestTasks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove()
|
||||
{
|
||||
this.Close();
|
||||
this.serialPort.Remove();
|
||||
}
|
||||
|
||||
private void ActivateSIRT()
|
||||
{
|
||||
var awaiter = new ManualResetEventSlim();
|
||||
|
||||
bool ActivateSIRT()
|
||||
{
|
||||
this.sirtTask = SIRTTask.ActivateSIRT;
|
||||
this.sirtTask.Cancelled += _1 => awaiter.Set();
|
||||
this.sirtTask.Completed += _2 => awaiter.Set();
|
||||
|
||||
this.sirtTask.SetRunning();
|
||||
this.serialPort.Write(this.sirtTask);
|
||||
this.Log?.Invoke(this.sirtTask.ToString());
|
||||
awaiter.Wait(this.sirtTask.Timeout);
|
||||
awaiter.Reset();
|
||||
|
||||
return this.sirtTask.State == SIRTTaskState.Completed;
|
||||
}
|
||||
|
||||
bool IdentifySIRT(out byte[] data)
|
||||
{
|
||||
data = default(byte[]);
|
||||
|
||||
this.sirtTask = SIRTTask.IdentifySIRT;
|
||||
this.sirtTask.Cancelled += _1 => awaiter.Set();
|
||||
this.sirtTask.Completed += _2 => awaiter.Set();
|
||||
|
||||
this.sirtTask.SetRunning();
|
||||
this.serialPort.Write(this.sirtTask);
|
||||
this.Log?.Invoke(this.sirtTask.ToString());
|
||||
awaiter.Wait(this.sirtTask.Timeout);
|
||||
awaiter.Reset();
|
||||
|
||||
data = this.sirtTask.Last;
|
||||
|
||||
return this.sirtTask.State == SIRTTaskState.Completed && data?.Length == 8;
|
||||
}
|
||||
|
||||
void OnMessageReceived(SIRTMessage message)
|
||||
{
|
||||
if (message.Address == this.sirtTask?.RequestAddress)
|
||||
{
|
||||
this.sirtTask.BeginReceiveMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
this.MessageReceived += OnMessageReceived;
|
||||
|
||||
if (ActivateSIRT())
|
||||
{
|
||||
if (IdentifySIRT(out var data))
|
||||
{
|
||||
this.HexId = BitConverter.ToString(data);
|
||||
this.Frequency = this.HexId[10] == '0' ? 868 : 433;
|
||||
|
||||
this.Activated?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Log?.Invoke($"SIRT on {this.COMPort} not identified.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Log?.Invoke($"SIRT on {this.COMPort} not activated.");
|
||||
}
|
||||
|
||||
this.MessageReceived -= OnMessageReceived;
|
||||
}
|
||||
|
||||
private ICollection<uint> GetAddressesInPamPool()
|
||||
{
|
||||
var addresses = new List<uint>();
|
||||
var awaiter = new ManualResetEventSlim();
|
||||
var task = SIRTTask.ReadPamPool;
|
||||
|
||||
void messageReceived(SIRTMessage message)
|
||||
{
|
||||
if (message.Address == task.RequestAddress)
|
||||
{
|
||||
task.BeginReceiveMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
this.MessageReceived += messageReceived;
|
||||
task.Cancelled += _1 => awaiter.Set();
|
||||
task.Completed += _2 => awaiter.Set();
|
||||
|
||||
task.SetRunning();
|
||||
this.serialPort.Write(task);
|
||||
this.Log?.Invoke(task.ToString());
|
||||
awaiter.Wait(task.Timeout);
|
||||
awaiter.Reset();
|
||||
this.MessageReceived -= messageReceived;
|
||||
|
||||
var payload = task.Last;
|
||||
|
||||
if (task.State == SIRTTaskState.Completed && payload?.Length == 20)
|
||||
{
|
||||
var _address = 0U;
|
||||
|
||||
for (var i = 0; i < 20; i += 4)
|
||||
{
|
||||
_address = payload.ToUInt32BE(i);
|
||||
|
||||
if (_address != uint.MaxValue)
|
||||
{
|
||||
addresses.Add(_address);
|
||||
}
|
||||
}
|
||||
|
||||
this.Log?.Invoke(string.Join(", ", addresses));
|
||||
}
|
||||
|
||||
return addresses;
|
||||
}
|
||||
|
||||
private void OnError(string e)
|
||||
=> this.Log?.Invoke(e);
|
||||
|
||||
private void SerialPort_Connected()
|
||||
{
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
this.cancellationToken = this.cancellationTokenSource.Token;
|
||||
|
||||
this.readingTask = Task.Run((Action)this.StartReadingMessages, this.cancellationToken);
|
||||
this.activationTask = Task.Run((Action)this.ActivateSIRT, this.cancellationToken);
|
||||
|
||||
this.Connected?.Invoke();
|
||||
}
|
||||
|
||||
private void SerialPort_Disconnected()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.cancellationTokenSource?.Cancel();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.OnError(e.ToString());
|
||||
}
|
||||
|
||||
this.Disconnected?.Invoke();
|
||||
}
|
||||
|
||||
private void SIRTConnection_MessageReceived(SIRTMessage message)
|
||||
{
|
||||
if (this.tasks.TryGetValue(message.Address, out var tasksQueue))
|
||||
{
|
||||
if (tasksQueue.TryPeek(out var task))
|
||||
{
|
||||
task.BeginReceiveMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
this.Log?.Invoke(message.ToString());
|
||||
}
|
||||
|
||||
private void StartProcessingTasksAsync()
|
||||
{
|
||||
this.processingTask = Task.Factory.StartNew(async state =>
|
||||
{
|
||||
var connection = state as SIRTBroadcaster;
|
||||
|
||||
while (!connection.cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
var addressesInPamPool = this.GetAddressesInPamPool();
|
||||
|
||||
foreach (var tasksQueue in connection.tasks.Values.ToArray())
|
||||
{
|
||||
if (addressesInPamPool.Count >= 5)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (tasksQueue.TryPeek(out var task))
|
||||
{
|
||||
if (task.State == SIRTTaskState.Pending)
|
||||
{
|
||||
var requestAddress = task.RequestAddress;
|
||||
|
||||
if (!addressesInPamPool.Any(_address => _address == requestAddress))
|
||||
{
|
||||
task.SetRunning();
|
||||
connection.serialPort.Write(task);
|
||||
addressesInPamPool.Add(requestAddress);
|
||||
this.Log?.Invoke(task.ToString());
|
||||
this.Log?.Invoke(requestAddress.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
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 TryDequeueTask(SIRTTask task)
|
||||
{
|
||||
task.Cancelled -= this.TryDequeueTask;
|
||||
task.Completed -= this.TryDequeueTask;
|
||||
task.Timeouted -= this.Task_Timeouted;
|
||||
task.Updated -= this.Task_Updated;
|
||||
|
||||
if (this.tasks.TryGetValue(task.RequestAddress, out var requestTasks))
|
||||
{
|
||||
requestTasks.TryDequeue(out var _);
|
||||
}
|
||||
}
|
||||
|
||||
private void Task_Timeouted(SIRTTask task)
|
||||
{
|
||||
var awaiter = new ManualResetEventSlim();
|
||||
var _task = SIRTTask.DeleteFromPamPool(task.RequestAddress);
|
||||
|
||||
void messageReceived(SIRTMessage message)
|
||||
{
|
||||
if (message.Address == task.RequestAddress)
|
||||
{
|
||||
_task.BeginReceiveMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
this.MessageReceived += messageReceived;
|
||||
_task.Cancelled += _1 => awaiter.Set();
|
||||
_task.Completed += _2 => awaiter.Set();
|
||||
|
||||
_task.SetRunning();
|
||||
this.serialPort.Write(_task);
|
||||
this.Log?.Invoke(_task.ToString());
|
||||
awaiter.Wait(_task.Timeout);
|
||||
awaiter.Reset();
|
||||
this.MessageReceived -= messageReceived;
|
||||
}
|
||||
|
||||
private void Task_Updated(SIRTTask task)
|
||||
{
|
||||
if (this.tasks.TryGetValue(task.RequestAddress, out var tasksQueue))
|
||||
{
|
||||
foreach (var _task in tasksQueue.AsEnumerable())
|
||||
{
|
||||
if (_task.Index > task.Index)
|
||||
{
|
||||
_task.RequestAddress = task.RequestAddress;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
public class SIRTFactory
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, SIRTBroadcaster> connections
|
||||
= new ConcurrentDictionary<string, SIRTBroadcaster>();
|
||||
|
||||
public event Action<string> Logging;
|
||||
|
||||
public void CloseConnection(string portName)
|
||||
{
|
||||
if (this.connections.TryGetValue(portName, out var connection))
|
||||
{
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void CloseConnections()
|
||||
{
|
||||
foreach (var connection in this.GetConnections())
|
||||
{
|
||||
connection.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void DequeueTasks(uint address)
|
||||
{
|
||||
foreach (var connection in this.GetConnections())
|
||||
{
|
||||
connection.DequeueTasks(address);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenConnections()
|
||||
{
|
||||
foreach (var connection in this.GetConnections())
|
||||
{
|
||||
connection.Open();
|
||||
}
|
||||
}
|
||||
|
||||
public void ConnectSIRT(string portName, Action<SIRTBroadcaster> callback)
|
||||
{
|
||||
if (!this.connections.TryGetValue(portName, out var broadcaster))
|
||||
{
|
||||
broadcaster = new SIRTBroadcaster(portName);
|
||||
broadcaster.Logging += message => this.Logging?.Invoke(message);
|
||||
|
||||
if (!this.connections.TryAdd(portName, broadcaster))
|
||||
{
|
||||
broadcaster = null;
|
||||
}
|
||||
}
|
||||
|
||||
callback(broadcaster);
|
||||
broadcaster?.Close();
|
||||
broadcaster?.Open();
|
||||
}
|
||||
|
||||
public void EnqueueTask(SIRTTask task)
|
||||
{
|
||||
foreach (var connection in this.GetConnections())
|
||||
{
|
||||
connection.EnqueueTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetPortNames()
|
||||
=> this.connections.Keys.ToArray();
|
||||
|
||||
public void RemoveConnections()
|
||||
{
|
||||
foreach (var key in this.connections.Keys.ToArray())
|
||||
{
|
||||
if (this.connections.TryRemove(key, out var broadcaster))
|
||||
{
|
||||
broadcaster.RemoveConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<SIRTBroadcaster> GetConnections()
|
||||
=> this.connections.Values.ToArray();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
public class SIRTMessage
|
||||
{
|
||||
public const byte MIN_LEN = 12;
|
||||
public const byte PC2SIRT = 0x55;
|
||||
public const byte SIRT2PC = 0xFF;
|
||||
public const byte W_PAM = 0x81;
|
||||
public const byte R_PAM = 0x82;
|
||||
public const byte W_REG = 0x84;
|
||||
public const byte R_REG = 0x87;
|
||||
public const byte FROMAIR = 0x11;
|
||||
public const byte ACKNANSW = 0x12;
|
||||
public const byte STOP = 0x16;
|
||||
public const byte BUP = 0x00;
|
||||
public const byte LAT = 0x01;
|
||||
public const byte DEBUG = 0x0B;
|
||||
public const byte SEMI = 0x08;
|
||||
|
||||
private byte[] bytes;
|
||||
|
||||
public SIRTMessage()
|
||||
{
|
||||
this.bytes = new byte[MIN_LEN];
|
||||
this.bytes[0] = PC2SIRT;
|
||||
}
|
||||
|
||||
public SIRTMessage(byte[] bytes)
|
||||
{
|
||||
this.bytes = bytes;
|
||||
this.bytes[0] = SIRT2PC;
|
||||
}
|
||||
|
||||
public byte Cmd
|
||||
{
|
||||
get => this.bytes[1];
|
||||
set => this.bytes[1] = value;
|
||||
}
|
||||
|
||||
public byte P1
|
||||
{
|
||||
get => this.bytes[2];
|
||||
set => this.bytes[2] = value;
|
||||
}
|
||||
|
||||
public byte P2
|
||||
{
|
||||
get => this.bytes[3];
|
||||
set => this.bytes[3] = value;
|
||||
}
|
||||
|
||||
public uint Address
|
||||
{
|
||||
get => this.bytes.ToUInt32BE(4);
|
||||
set => value.GetBytesBE().CopyTo(this.bytes, 4);
|
||||
}
|
||||
|
||||
public byte Length => this.bytes[8];
|
||||
|
||||
[JsonIgnore]
|
||||
public byte[] Data
|
||||
{
|
||||
get
|
||||
{
|
||||
var data = new byte[this.Length];
|
||||
|
||||
Array.Copy(this.bytes, 9, data, 0, this.Length);
|
||||
|
||||
return data;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
value = new byte[0];
|
||||
}
|
||||
|
||||
this.bytes[8] = (byte)value.Length;
|
||||
|
||||
Array.Resize(ref this.bytes, MIN_LEN + this.Length);
|
||||
Array.Clear(this.bytes, 9, this.bytes.Length - 9);
|
||||
Array.Copy(value, 0, this.bytes, 9, this.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public ushort CRC => this.bytes.ToUInt16BE(this.bytes.Length - 3);
|
||||
|
||||
public string Content => this.ToString();
|
||||
|
||||
public byte[] ToByteArray()
|
||||
{
|
||||
var length = this.bytes.Length;
|
||||
var crc = this.bytes.CRCCCITT(1, length - 3);
|
||||
var crcBytes = crc.GetBytesBE();
|
||||
|
||||
this.bytes[length - 3] = crcBytes[0];
|
||||
this.bytes[length - 2] = crcBytes[1];
|
||||
this.bytes[length - 1] = STOP;
|
||||
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
=> BitConverter.ToString(this.ToByteArray());
|
||||
}
|
||||
}
|
||||
@@ -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, 1000)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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,126 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Timers;
|
||||
|
||||
public partial class SIRTTask
|
||||
{
|
||||
public readonly ConcurrentStack<SIRTMessage> responses;
|
||||
public 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 byte Cmd
|
||||
{
|
||||
get => this.request.Cmd;
|
||||
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)
|
||||
{
|
||||
if (this.State == SIRTTaskState.Cancelled)
|
||||
{
|
||||
this.NotifyCancelled();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.responses.Push(response);
|
||||
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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
using Common.Hardware.SIRT.Parameters;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Timers;
|
||||
|
||||
public class SIRTTask
|
||||
{
|
||||
protected readonly Timer timer;
|
||||
protected readonly SIRTMessage request;
|
||||
protected readonly ConcurrentStack<SIRTMessage> responses;
|
||||
|
||||
/// <param name="timeout">The tiemout in milliseconds, after the task will be cancelled.</param>
|
||||
public SIRTTask(int timeout = 5_000)
|
||||
{
|
||||
this.Timeout = timeout;
|
||||
this.State = SIRTTaskState.Pending;
|
||||
|
||||
this.timer = new Timer();
|
||||
this.request = new SIRTMessage();
|
||||
this.responses = new ConcurrentStack<SIRTMessage>();
|
||||
|
||||
// Cancel after 10 seconds
|
||||
this.timer.AutoReset = false;
|
||||
this.timer.Enabled = false;
|
||||
this.timer.Interval = this.Timeout;
|
||||
this.timer.Elapsed += this.Timer_Elapsed;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The tiemout in milliseconds, after the task will be cancelled.
|
||||
/// </summary>
|
||||
public int Timeout { get; }
|
||||
|
||||
public int Frequency { get; set; }
|
||||
|
||||
public int Index { get; internal set; }
|
||||
|
||||
public SIRTTaskState State { get; protected set; }
|
||||
|
||||
public virtual void BeginReceiveMessage(SIRTMessage response)
|
||||
{
|
||||
this.responses.Push(response);
|
||||
|
||||
if (this.State == SIRTTaskState.Running)
|
||||
{
|
||||
if (response.Cmd == SIRTMessage.FROMAIR && response?.Data?[0] == SIRTMessage.SEMI)
|
||||
{
|
||||
this.State = SIRTTaskState.Completed;
|
||||
}
|
||||
else if (response.Cmd == SIRTMessage.ACKNANSW)
|
||||
{
|
||||
this.State = SIRTTaskState.Completed;
|
||||
}
|
||||
}
|
||||
|
||||
this.EndReceiveMessage(response);
|
||||
}
|
||||
|
||||
public virtual void SetRunning()
|
||||
{
|
||||
this.State = SIRTTaskState.Running;
|
||||
|
||||
this.timer.Start();
|
||||
}
|
||||
|
||||
public virtual byte[] ToByteArray()
|
||||
=> this.request.ToByteArray();
|
||||
|
||||
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)
|
||||
{
|
||||
this.timer.Stop();
|
||||
this.Completed?.Invoke(this);
|
||||
}
|
||||
else if (this.State == SIRTTaskState.Cancelled)
|
||||
{
|
||||
this.timer.Stop();
|
||||
this.Cancelled?.Invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected void NotifyUpdated()
|
||||
=> this.Updated?.Invoke(this);
|
||||
|
||||
protected virtual void Timer_Elapsed(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
this.State = SIRTTaskState.Pending;
|
||||
|
||||
this.Timeouted?.Invoke(this);
|
||||
}
|
||||
|
||||
public static implicit operator byte[](SIRTTask task)
|
||||
=> task.ToByteArray();
|
||||
|
||||
public static implicit operator SIRTMessage(SIRTTask task)
|
||||
=> task.request;
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
public class AnswerTask : SIRTTask
|
||||
{
|
||||
public AnswerTask(int timeout = 3000) : base(timeout)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public byte[] Last { get; private set; }
|
||||
|
||||
public override void BeginReceiveMessage(SIRTMessage response)
|
||||
{
|
||||
base.BeginReceiveMessage(response);
|
||||
|
||||
this.Last = response.Data ?? new byte[] { };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Common.Hardware.SIRT
|
||||
{
|
||||
public enum SIRTTaskState
|
||||
{
|
||||
Pending = 0,
|
||||
Running = 1,
|
||||
Completed = 2,
|
||||
Cancelled = 4
|
||||
}
|
||||
}
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{B23BFAF9-08AE-4311-8C08-FB2BB49EA2AD}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Common.Hardware.Interfaces.Ports.Sirt</RootNamespace>
|
||||
<AssemblyName>Common.Hardware.Interfaces.Ports.Sirt</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn>IDE0003;IDE0017;IDE0049;</NoWarn>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Parameters\BluetoothOperating.cs" />
|
||||
<Compile Include="Parameters\OperatingModes.cs" />
|
||||
<Compile Include="Parameters\P11.cs" />
|
||||
<Compile Include="Parameters\P12.cs" />
|
||||
<Compile Include="Parameters\P811.cs" />
|
||||
<Compile Include="Parameters\PAMStatus.cs" />
|
||||
<Compile Include="Parameters\PamTimeout.cs" />
|
||||
<Compile Include="Parameters\RFModuleOperating.cs" />
|
||||
<Compile Include="Parameters\SirtOperating.cs" />
|
||||
<Compile Include="SirtBroadcaster.cs" />
|
||||
<Compile Include="SirtHub.cs" />
|
||||
<Compile Include="SirtMessage.cs" />
|
||||
<Compile Include="SirtConnection.cs" />
|
||||
<Compile Include="SirtTask.cs" />
|
||||
<Compile Include="SirtTaskState.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\Utils\Common.Utils.Extensions\Common.Utils.Extensions.csproj">
|
||||
<Project>{05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3}</Project>
|
||||
<Name>Common.Utils.Extensions</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\..\Utils\Crc16Ccitt\Crc16Ccitt.csproj">
|
||||
<Project>{91DEF0C0-AA4F-40AE-8F18-CB717FDE7E7F}</Project>
|
||||
<Name>Crc16Ccitt</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common.Hardware.Interfaces.Ports\Common.Hardware.Interfaces.Ports.csproj">
|
||||
<Project>{9ae071c0-db12-4e09-a3c7-43f6dcd518d6}</Project>
|
||||
<Name>Common.Hardware.Interfaces.Ports</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
-180
@@ -1,180 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Parameter P11 is given at third position of "Telegram from Air" telegram and give more detailed information about the
|
||||
/// received packets from radio section of SIRT.The bits of Parameter 11 are decoded as following, where Bit 0 is the least
|
||||
/// significant bit:
|
||||
/// </summary>
|
||||
public class P11
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
|
||||
public P11() => this.bits = new Byte[8];
|
||||
|
||||
private P11(Byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>RF-Module2 is source</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>RF-Module1 is source</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>only valid if both RF-Module programmed for Sensus RF</para>
|
||||
/// </summary>
|
||||
public Boolean SrcChannel
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>both RF module data are valid</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>only one RF module data is valid</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>only valid if both RF-Module programmed for Sensus RF</para>
|
||||
/// </summary>
|
||||
public Boolean BothValid
|
||||
{
|
||||
get => this.bits[1] == 1;
|
||||
set => this.bits[1] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>RF-Module1 data is invalid</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>RF-Module1 data is valid</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>i.e. radio checksum is wrong ...</para>
|
||||
/// </summary>
|
||||
public Boolean InvalidMod1
|
||||
{
|
||||
get => this.bits[2] == 1;
|
||||
set => this.bits[2] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>RF-Module2 data is invalid</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>RF-Module2 data is valid</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>i.e. radio checksum is wrong ...</para>
|
||||
/// </summary>
|
||||
public Boolean InvalidMod2
|
||||
{
|
||||
get => this.bits[3] == 1;
|
||||
set => this.bits[3] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>invalid -> module detects length > 128</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>all ok</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean LenOverflow
|
||||
{
|
||||
get => this.bits[4] == 1;
|
||||
set => this.bits[4] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>will look at PAM / RAC Pool</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>no attention for PAM / RAC</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean Attention
|
||||
{
|
||||
get => this.bits[5] == 1;
|
||||
set => this.bits[5] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>
|
||||
/// <para>If .modeSensus = 0 wireless M-busMode -> T1 - Mode</para>
|
||||
/// <para>If .modeSensus = 1 SensusRF -> receive at f2</para>
|
||||
/// </description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>
|
||||
/// <para>If .modeSensus = 0 wireless M-busMode -> S1 - Mode</para>
|
||||
/// <para>If .modeSensus = 1 SensusRF -> receive at f1</para>
|
||||
/// </description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean ModeRF
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>Sensus RF Mode</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>wireless M-Bus Mode</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean ModeSensus
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(P11 param)
|
||||
=> param.bits.ToByte();
|
||||
|
||||
public static implicit operator P11(Byte _byte)
|
||||
=> new P11(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
-172
@@ -1,172 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// P12 is the parameter of "Acknowledge or Answer" message and is placed at third position,
|
||||
/// if telegram from SIRT-> PC begins with {0xFF, 0x12}.
|
||||
/// This parameter gives more detailed information about the last command or request which
|
||||
/// was send to SIRT.
|
||||
/// Parameter 12 is given at third position of acknowledge- or answer telegram from SIRT.
|
||||
/// </summary>
|
||||
public class P12
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
|
||||
public P12() => this.bits = new Byte[8];
|
||||
|
||||
private P12(Byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>requested buffer is full or not available</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>Ok</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean BufFull
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>operating system is busy</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>Ok</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean OsBusy
|
||||
{
|
||||
get => this.bits[1] == 1;
|
||||
set => this.bits[1] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>wrong CRC recognized</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>Ok</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean WrongCRC
|
||||
{
|
||||
get => this.bits[2] == 1;
|
||||
set => this.bits[2] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>command cannot be executed</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>Ok</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean CmdNotExecuted
|
||||
{
|
||||
get => this.bits[3] == 1;
|
||||
set => this.bits[3] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>telegram or command Byte unknown</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>Ok</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean CmdUnknown
|
||||
{
|
||||
get => this.bits[4] == 1;
|
||||
set => this.bits[4] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>no such entry found</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>Ok</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean NoEntry
|
||||
{
|
||||
get => this.bits[5] == 1;
|
||||
set => this.bits[5] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>unknown fixed byte</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>Ok</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean ByteUnknown
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>address was 0xFFFFFFFF</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>normal address</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean WildCardAddr
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(P12 param)
|
||||
=> param.bits.ToByte();
|
||||
|
||||
public static implicit operator P12(Byte _byte)
|
||||
=> new P12(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class PAMStatus
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
|
||||
public PAMStatus(Byte _byte)
|
||||
=> this.bits = _byte.GetBits();
|
||||
|
||||
public Boolean CMD_UNKNOWN => this.bits[0] == 1;
|
||||
|
||||
public Boolean WRONG_AUTH => this.bits[1] == 1;
|
||||
|
||||
public Boolean EXPIRED_AUTH => this.bits[2] == 1;
|
||||
|
||||
public Boolean MIXED_TYPES => this.bits[3] == 1;
|
||||
|
||||
public Boolean OUT_OF_RANGE => this.bits[4] == 1;
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
var status = nameof(OK);
|
||||
var value = this.bits.ToByte();
|
||||
|
||||
if ((value & 1) == 1)
|
||||
{
|
||||
status = nameof(CMD_UNKNOWN);
|
||||
}
|
||||
|
||||
if ((value & 2) == 2)
|
||||
{
|
||||
status = nameof(WRONG_AUTH);
|
||||
}
|
||||
|
||||
if ((value & 4) == 4)
|
||||
{
|
||||
status = nameof(EXPIRED_AUTH);
|
||||
}
|
||||
|
||||
if ((value & 8) == 8)
|
||||
{
|
||||
status = nameof(MIXED_TYPES);
|
||||
}
|
||||
|
||||
if ((value & 16) == 16)
|
||||
{
|
||||
status = nameof(OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public static Byte OK = 0;
|
||||
|
||||
public static implicit operator Byte(PAMStatus status)
|
||||
=> status?.bits?.ToByte() ?? 0xFF;
|
||||
|
||||
public static implicit operator String(PAMStatus status)
|
||||
=> status?.ToString();
|
||||
}
|
||||
}
|
||||
-248
@@ -1,248 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class SirtBroadcaster
|
||||
{
|
||||
private readonly SirtConnection connection;
|
||||
private readonly ConcurrentDictionary<int, uint?> pampool;
|
||||
private readonly ConcurrentDictionary<uint, DateTime> endpoints;
|
||||
private readonly ConcurrentDictionary<uint, SirtTask> runningTasks;
|
||||
private readonly ConcurrentDictionary<uint, ConcurrentQueue<SirtTask>> pendingTasks;
|
||||
|
||||
private CancellationTokenSource cancellationTokenSource;
|
||||
private CancellationToken cancellationToken;
|
||||
|
||||
public SirtBroadcaster(String portName)
|
||||
{
|
||||
this.connection = new SirtConnection(portName);
|
||||
this.connection.Exception += this.Throw;
|
||||
this.connection.MessageReceived += this.Connection_MessageReceived;
|
||||
this.pampool = new ConcurrentDictionary<int, uint?>();
|
||||
this.endpoints = new ConcurrentDictionary<uint, DateTime>();
|
||||
this.runningTasks = new ConcurrentDictionary<uint, SirtTask>();
|
||||
this.pendingTasks = new ConcurrentDictionary<uint, ConcurrentQueue<SirtTask>>();
|
||||
}
|
||||
|
||||
public event Action<Exception> Exception;
|
||||
|
||||
public UInt64 Id { get; private set; }
|
||||
|
||||
public String SirtId { get; private set; }
|
||||
|
||||
public Int32 MHz { get; private set; }
|
||||
|
||||
public Boolean IsRunning { get; private set; }
|
||||
|
||||
public void Add(SirtTask task)
|
||||
{
|
||||
task.Cancelled += this.Task_Dismiss;
|
||||
task.Completed += this.Task_Dismiss;
|
||||
|
||||
this.pendingTasks
|
||||
.GetOrAdd(task.Address, new ConcurrentQueue<SirtTask>())
|
||||
.Enqueue(task);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
this.IsRunning = false;
|
||||
|
||||
if (this.connection.EnsureConnected())
|
||||
{
|
||||
this.pampool.Clear();
|
||||
this.endpoints.Clear();
|
||||
this.pendingTasks.Clear();
|
||||
this.runningTasks.Clear();
|
||||
|
||||
var awaiter = new ManualResetEventSlim();
|
||||
|
||||
var task = SirtTask.ActivateSIRT;
|
||||
task.Cancelled += _ => awaiter.Set();
|
||||
task.Completed += _ => awaiter.Set();
|
||||
task.Cancelled += this.Task_Dismiss;
|
||||
task.Completed += this.Task_Dismiss;
|
||||
|
||||
this.runningTasks.TryAdd(task.Address, task);
|
||||
this.connection.SendMessage(task);
|
||||
|
||||
awaiter.Wait();
|
||||
awaiter.Reset();
|
||||
|
||||
if (task.State == SirtTaskState.Completed)
|
||||
{
|
||||
task = SirtTask.IdentifySIRT;
|
||||
task.Cancelled += _ => awaiter.Set();
|
||||
task.Completed += _ => awaiter.Set();
|
||||
task.Cancelled += this.Task_Dismiss;
|
||||
task.Completed += this.Task_Dismiss;
|
||||
|
||||
this.runningTasks.TryAdd(task.Address, task);
|
||||
this.connection.SendMessage(task);
|
||||
|
||||
awaiter.Wait();
|
||||
awaiter.Reset();
|
||||
|
||||
if (task.State == SirtTaskState.Completed && task.Last?.Length == 8)
|
||||
{
|
||||
this.Id = BitConverter.ToUInt64(task.Last, 0);
|
||||
this.SirtId = BitConverter.ToString(task.Last);
|
||||
this.MHz = this.SirtId[10] == '0' ? 868 : 433;
|
||||
this.IsRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
this.cancellationToken = this.cancellationTokenSource.Token;
|
||||
|
||||
Task.Run(this.StartObservingPamPool, this.cancellationToken);
|
||||
Task.Run(this.StartObservingPendingTasks, this.cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
this.connection.MessageReceived -= this.Connection_MessageReceived;
|
||||
this.connection.Exception -= this.Throw;
|
||||
this.IsRunning = false;
|
||||
|
||||
try
|
||||
{
|
||||
this.cancellationTokenSource.Cancel(true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
this.connection.Close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
|
||||
this.pampool.Clear();
|
||||
this.endpoints.Clear();
|
||||
this.pendingTasks.Clear();
|
||||
this.runningTasks.Clear();
|
||||
}
|
||||
|
||||
public uint[] ViewEndpoints()
|
||||
=> this.endpoints.Keys.ToArray();
|
||||
|
||||
public uint?[] ViewPamPool()
|
||||
=> this.pampool.Values.ToArray();
|
||||
|
||||
private void Connection_MessageReceived(SirtMessage message)
|
||||
{
|
||||
if (this.runningTasks.TryGetValue(message.Address, out var task) && task != null)
|
||||
{
|
||||
task.ReceiveMessage(message, this.MHz);
|
||||
}
|
||||
|
||||
this.endpoints.AddOrUpdate(message.Address, DateTime.Now, (k, v) => DateTime.Now);
|
||||
}
|
||||
|
||||
private async Task StartObservingPamPool()
|
||||
{
|
||||
var awaiter = new ManualResetEventSlim();
|
||||
var task = SirtTask.ReadPamPool;
|
||||
task.Cancelled += this.Task_Dismiss;
|
||||
task.Completed += this.Task_Dismiss;
|
||||
task.Completed += _task =>
|
||||
{
|
||||
var payload = new byte[] { };
|
||||
|
||||
if (_task is AnswerTask answerTask)
|
||||
{
|
||||
payload = answerTask.Last;
|
||||
}
|
||||
|
||||
var length = payload?.Length ?? 0;
|
||||
|
||||
if (length == 20)
|
||||
{
|
||||
uint? address;
|
||||
var i = 0;
|
||||
|
||||
for (var x = 0; x < 5; x++)
|
||||
{
|
||||
address = 0;
|
||||
address ^= (uint)(payload[i++] << 24);
|
||||
address ^= (uint)(payload[i++] << 16);
|
||||
address ^= (uint)(payload[i++] << 8);
|
||||
address ^= payload[i++];
|
||||
|
||||
if (address == uint.MaxValue)
|
||||
{
|
||||
address = null;
|
||||
}
|
||||
|
||||
this.pampool.AddOrUpdate(x, address, (k, v) => address);
|
||||
}
|
||||
}
|
||||
|
||||
awaiter.Set();
|
||||
};
|
||||
|
||||
while (!this.cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
this.runningTasks.TryAdd(task.Address, task);
|
||||
this.connection.SendMessage(task);
|
||||
awaiter.Wait();
|
||||
awaiter.Reset();
|
||||
task.Reset();
|
||||
|
||||
await Task.Delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task StartObservingPendingTasks()
|
||||
{
|
||||
while (!this.cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
var pendingAddresses = this.pendingTasks.Keys.ToArray();
|
||||
|
||||
foreach (var address in pendingAddresses)
|
||||
{
|
||||
if (this.runningTasks.ContainsKey(address))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (this.pendingTasks.TryGetValue(address, out var pendingTasks))
|
||||
{
|
||||
if (pendingTasks.TryPeek(out var task))
|
||||
{
|
||||
if (task.Cmd == SirtMessage.W_PAM && this.pampool.Any(x => x.Value == address))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pendingTasks.TryDequeue(out task))
|
||||
{
|
||||
this.runningTasks.AddOrUpdate(address, task, (_1, _2) => task);
|
||||
this.connection.SendMessage(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await Task.Delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void Task_Dismiss(SirtTask task)
|
||||
=> this.runningTasks.TryRemove(task?.Address ?? 0, out var _);
|
||||
|
||||
private void Throw(Exception exception)
|
||||
=> this.Exception?.Invoke(exception);
|
||||
}
|
||||
}
|
||||
-155
@@ -1,155 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class SirtConnection
|
||||
{
|
||||
private readonly ISerialPort serialPort;
|
||||
private readonly List<Byte> buffer;
|
||||
|
||||
private CancellationTokenSource cancellationTokenSource;
|
||||
private CancellationToken cancellationToken;
|
||||
|
||||
public SirtConnection(String portName)
|
||||
{
|
||||
var settings = new SerialPortSettings
|
||||
{
|
||||
BaudRate = SerialPortBaudRate.X115200,
|
||||
DataBits = SerialPortDataBits.X8,
|
||||
Parity = SerialPortParity.None,
|
||||
PortName = portName,
|
||||
StopBits = SerialPortStopBits.One
|
||||
};
|
||||
this.serialPort = new SerialPort(settings);
|
||||
this.serialPort.Exception += this.Throw;
|
||||
this.buffer = new List<Byte>();
|
||||
}
|
||||
|
||||
public event Action<Exception> Exception;
|
||||
public event Action<SirtMessage> MessageReceived;
|
||||
|
||||
public void Close()
|
||||
{
|
||||
this.serialPort.Close();
|
||||
this.buffer.Clear();
|
||||
|
||||
try
|
||||
{
|
||||
this.cancellationTokenSource.Cancel(true);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnsureConnected()
|
||||
{
|
||||
this.serialPort.Close();
|
||||
this.serialPort.Open();
|
||||
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
this.cancellationToken = this.cancellationTokenSource.Token;
|
||||
Task.Run(this.StartReading, this.cancellationToken);
|
||||
Task.Run(this.StartParsing, this.cancellationToken);
|
||||
|
||||
return this.serialPort.IsOpen();
|
||||
}
|
||||
|
||||
public bool IsOpen() => this.serialPort.IsOpen();
|
||||
|
||||
public void SendMessage(SirtMessage message)
|
||||
=> this.serialPort.WriteBytes(message);
|
||||
|
||||
private async Task StartParsing()
|
||||
{
|
||||
var bufferLength = default(int);
|
||||
var startIX = default(int);
|
||||
var lengthIX = default(int);
|
||||
var dataLength = default(int);
|
||||
var stopIX = default(int);
|
||||
var messageLength = default(int);
|
||||
var message = default(byte[]);
|
||||
|
||||
while (!this.cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
{
|
||||
bufferLength = this.buffer.Count;
|
||||
|
||||
if (bufferLength >= 13)
|
||||
{
|
||||
startIX = this.buffer.IndexOf(SirtMessage.SIRT2PC);
|
||||
|
||||
if (startIX < 0)
|
||||
{
|
||||
this.buffer.Clear();
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
lengthIX = startIX + 8;
|
||||
|
||||
if (lengthIX >= bufferLength)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
dataLength = this.buffer[lengthIX];
|
||||
stopIX = lengthIX + dataLength + 3;
|
||||
|
||||
if (stopIX >= bufferLength)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (this.buffer[stopIX] != SirtMessage.STOP)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
messageLength = stopIX - startIX + 1;
|
||||
message = new Byte[messageLength];
|
||||
|
||||
this.buffer.CopyTo(startIX, message, 0, messageLength);
|
||||
this.MessageReceived?.Invoke(new SirtMessage(message));
|
||||
this.buffer.RemoveRange(0, startIX + messageLength);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
|
||||
await Task.Delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task StartReading()
|
||||
{
|
||||
var bytes = default(byte[]);
|
||||
var bytesLength = default(int);
|
||||
|
||||
while (!this.cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
bytes = this.serialPort.ReadBytes();
|
||||
bytesLength = bytes?.Length ?? 0;
|
||||
|
||||
if (bytesLength > 0)
|
||||
{
|
||||
this.buffer.AddRange(bytes);
|
||||
}
|
||||
|
||||
await Task.Delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
private void Throw(Exception exception)
|
||||
=> this.Exception?.Invoke(exception);
|
||||
|
||||
private void Throw(String _, Exception exception)
|
||||
=> this.Exception?.Invoke(exception);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt
|
||||
{
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
public class SirtHub
|
||||
{
|
||||
private readonly ConcurrentDictionary<int, ConcurrentDictionary<ulong, SirtBroadcaster>> sirts;
|
||||
|
||||
public SirtHub(string[] portNames)
|
||||
{
|
||||
this.sirts = new ConcurrentDictionary<int, ConcurrentDictionary<ulong, SirtBroadcaster>>();
|
||||
|
||||
foreach (var portName in portNames)
|
||||
{
|
||||
var broadcaster = new SirtBroadcaster(portName);
|
||||
|
||||
broadcaster.Start();
|
||||
|
||||
if (broadcaster.IsRunning)
|
||||
{
|
||||
this.sirts
|
||||
.GetOrAdd(broadcaster.MHz, new ConcurrentDictionary<ulong, SirtBroadcaster>())
|
||||
.AddOrUpdate(broadcaster.Id, broadcaster, (k, v) => broadcaster);
|
||||
}
|
||||
|
||||
broadcaster.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-166
@@ -1,166 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt
|
||||
{
|
||||
using System;
|
||||
|
||||
public class SirtMessage
|
||||
{
|
||||
public const Byte MIN_LEN = 12;
|
||||
public const Byte PC2SIRT = 0x55;
|
||||
public const Byte SIRT2PC = 0xFF;
|
||||
public const Byte W_PAM = 0x81;
|
||||
public const Byte R_PAM = 0x82;
|
||||
public const Byte W_REG = 0x84;
|
||||
public const Byte R_REG = 0x87;
|
||||
public const Byte FROMAIR = 0x11;
|
||||
public const Byte ACKNANSW = 0x12;
|
||||
public const Byte STOP = 0x16;
|
||||
public const Byte BUP = 0x00;
|
||||
public const Byte LAT = 0x01;
|
||||
public const Byte DEBUG = 0x0B;
|
||||
public const Byte SEMI = 0x08;
|
||||
|
||||
private readonly DateTime timestamp;
|
||||
|
||||
private Byte[] bytes;
|
||||
|
||||
public SirtMessage(DateTime? timestamp = null)
|
||||
{
|
||||
this.timestamp = timestamp ?? DateTime.Now;
|
||||
this.bytes = new Byte[MIN_LEN];
|
||||
this.bytes[0] = PC2SIRT;
|
||||
}
|
||||
|
||||
public SirtMessage(Byte[] bytes, DateTime? timestamp = null)
|
||||
{
|
||||
this.timestamp = timestamp ?? DateTime.Now;
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public Byte Cmd
|
||||
{
|
||||
get => this.bytes[1];
|
||||
set => this.bytes[1] = value;
|
||||
}
|
||||
|
||||
public Byte P1
|
||||
{
|
||||
get => this.bytes[2];
|
||||
set => this.bytes[2] = value;
|
||||
}
|
||||
|
||||
public Byte P2
|
||||
{
|
||||
get => this.bytes[3];
|
||||
set => this.bytes[3] = value;
|
||||
}
|
||||
|
||||
public UInt32 Address
|
||||
{
|
||||
get
|
||||
{
|
||||
var address = 0U;
|
||||
|
||||
address ^= (UInt32)this.bytes[4] << 24;
|
||||
address ^= (UInt32)this.bytes[5] << 16;
|
||||
address ^= (UInt32)this.bytes[6] << 8;
|
||||
address ^= (UInt32)this.bytes[7];
|
||||
|
||||
return address;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.bytes[4] = (Byte)(value >> 24);
|
||||
this.bytes[5] = (Byte)(value >> 16);
|
||||
this.bytes[6] = (Byte)(value >> 8);
|
||||
this.bytes[7] = (Byte)value;
|
||||
}
|
||||
}
|
||||
|
||||
public Byte Length => this.bytes[8];
|
||||
|
||||
public Byte[] Data
|
||||
{
|
||||
get
|
||||
{
|
||||
var data = new Byte[this.Length];
|
||||
|
||||
Array.Copy(this.bytes, 9, data, 0, this.Length);
|
||||
|
||||
return data;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
value = new Byte[0];
|
||||
}
|
||||
|
||||
this.bytes[8] = (Byte)value.Length;
|
||||
|
||||
Array.Resize(ref this.bytes, MIN_LEN + this.Length);
|
||||
Array.Clear(this.bytes, 9, this.bytes.Length - 9);
|
||||
Array.Copy(value, 0, this.bytes, 9, this.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public UInt16 CRC
|
||||
{
|
||||
get
|
||||
{
|
||||
var length = this.bytes.Length;
|
||||
var crc = default(UInt16);
|
||||
|
||||
crc ^= (UInt16)(this.bytes[length - 3] << 8);
|
||||
crc ^= (UInt16)(this.bytes[length - 2] << 0);
|
||||
|
||||
return crc;
|
||||
}
|
||||
}
|
||||
|
||||
public Byte[] ToByteArray()
|
||||
{
|
||||
var length = this.bytes.Length;
|
||||
var crc = this.CRCCCITT(1, length - 3);
|
||||
|
||||
this.bytes[length - 3] = (Byte)(crc >> 8);
|
||||
this.bytes[length - 2] = (Byte)(crc >> 0);
|
||||
this.bytes[length - 1] = STOP;
|
||||
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
=> BitConverter.ToString(this.ToByteArray());
|
||||
|
||||
public static implicit operator Byte[](SirtMessage message)
|
||||
=> message.ToByteArray() ?? new Byte[0];
|
||||
|
||||
private UInt16 CRCCCITT(Int32 start, Int32 length)
|
||||
{
|
||||
var crc = (UInt16)0xFFFF;
|
||||
|
||||
for (var b = start; b < length; b++)
|
||||
{
|
||||
var _byte = this.bytes[b];
|
||||
var token = (UInt16)((_byte << 8) & 0xFF00);
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
if (0x8000 == ((crc ^ token) & 0x8000))
|
||||
{
|
||||
crc <<= 1;
|
||||
crc ^= 0x1021;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc <<= 1;
|
||||
}
|
||||
|
||||
token <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.Sirt.Parameters;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Timers;
|
||||
|
||||
public class SirtTask
|
||||
{
|
||||
protected readonly Timer timer;
|
||||
private readonly SirtMessage request;
|
||||
private readonly ConcurrentStack<SirtMessage> responses;
|
||||
|
||||
public SirtTask()
|
||||
{
|
||||
this.State = SirtTaskState.Pending;
|
||||
|
||||
this.timer = new Timer();
|
||||
this.request = new SirtMessage();
|
||||
this.responses = new ConcurrentStack<SirtMessage>();
|
||||
|
||||
// Cancel after 10 seconds
|
||||
this.timer.AutoReset = false;
|
||||
this.timer.Interval = 10_000;
|
||||
this.timer.Elapsed += this.Timer_Elapsed;
|
||||
}
|
||||
|
||||
public event Action<SirtTask> Completed;
|
||||
public event Action<SirtTask> Cancelled;
|
||||
|
||||
public Byte Cmd
|
||||
{
|
||||
get => this.request.Cmd;
|
||||
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 UInt32 Address
|
||||
{
|
||||
get => this.request.Address;
|
||||
set => this.request.Address = value;
|
||||
}
|
||||
|
||||
public Byte[] Data
|
||||
{
|
||||
get => this.request.Data;
|
||||
set => this.request.Data = value;
|
||||
}
|
||||
|
||||
public SirtTaskState State { get; private set; }
|
||||
|
||||
public virtual void ReceiveMessage(SirtMessage response, Int32 mhz)
|
||||
{
|
||||
if (this.State != SirtTaskState.Completed && this.State != SirtTaskState.Cancelled)
|
||||
{
|
||||
this.responses.Push(response);
|
||||
|
||||
this.State = SirtTaskState.Running;
|
||||
|
||||
if (this.request.Cmd == SirtMessage.W_PAM)
|
||||
{
|
||||
if (response.Cmd == SirtMessage.FROMAIR && response.Data[0] == SirtMessage.SEMI)
|
||||
{
|
||||
this.State = SirtTaskState.Completed;
|
||||
}
|
||||
}
|
||||
else if (response.Cmd == SirtMessage.ACKNANSW)
|
||||
{
|
||||
this.State = SirtTaskState.Completed;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.State == SirtTaskState.Completed)
|
||||
{
|
||||
this.Completed?.Invoke(this);
|
||||
this.timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Reset()
|
||||
{
|
||||
this.State = SirtTaskState.Pending;
|
||||
|
||||
this.responses.Clear();
|
||||
this.timer.Stop();
|
||||
}
|
||||
|
||||
public virtual Byte[] ToByteArray()
|
||||
=> this.request.ToByteArray();
|
||||
|
||||
public override String ToString()
|
||||
=> BitConverter.ToString(this.ToByteArray());
|
||||
|
||||
private void Timer_Elapsed(Object sender, ElapsedEventArgs e)
|
||||
{
|
||||
this.State = SirtTaskState.Cancelled;
|
||||
|
||||
this.Cancelled?.Invoke(this);
|
||||
this.timer.Stop();
|
||||
}
|
||||
|
||||
public static implicit operator Byte[] (SirtTask task)
|
||||
=> task?.ToByteArray() ?? new Byte[] { };
|
||||
|
||||
public static implicit operator SirtMessage(SirtTask task)
|
||||
=> task?.request ?? new SirtMessage();
|
||||
|
||||
internal static readonly AnswerTask ActivateSIRT = new AnswerTask
|
||||
{
|
||||
Cmd = SirtMessage.W_REG,
|
||||
Address = 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,
|
||||
Address = 0x11001820,
|
||||
P2 = 0x08
|
||||
};
|
||||
|
||||
internal static readonly AnswerTask ReadPamPool = new AnswerTask
|
||||
{
|
||||
Cmd = SirtMessage.R_PAM,
|
||||
Address = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
internal static SirtTask DeleteFromPamPool(UInt32 address) => new SirtTask
|
||||
{
|
||||
Cmd = SirtMessage.W_PAM,
|
||||
P1 = new P811 { DelPamAdr = true },
|
||||
Address = address
|
||||
};
|
||||
}
|
||||
|
||||
public class AnswerTask : SirtTask
|
||||
{
|
||||
public AnswerTask() : base()
|
||||
=> this.timer.Interval = 1000;
|
||||
|
||||
public Byte[] Last { get; private set; }
|
||||
|
||||
public override void ReceiveMessage(SirtMessage response, Int32 mhz)
|
||||
{
|
||||
if (this.State == SirtTaskState.Completed)
|
||||
{
|
||||
this.Last = response.Data ?? new byte[] { };
|
||||
}
|
||||
|
||||
base.ReceiveMessage(response, mhz);
|
||||
}
|
||||
}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.Sirt
|
||||
{
|
||||
public enum SirtTaskState
|
||||
{
|
||||
Pending = 0,
|
||||
Running = 1,
|
||||
Completed = 2,
|
||||
Cancelled = 3
|
||||
}
|
||||
}
|
||||
-168
@@ -1,168 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.Sirt;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
|
||||
public class JustSirtBroadcaster
|
||||
{
|
||||
private static readonly ConcurrentDictionary<UInt32, JustSirtTask> runningTasks
|
||||
= new ConcurrentDictionary<UInt32, JustSirtTask>();
|
||||
private readonly JustSirtProxy proxy;
|
||||
|
||||
public JustSirtBroadcaster(String portName)
|
||||
{
|
||||
this.proxy = new JustSirtProxy(portName);
|
||||
this.proxy.MessageReceived += this.Proxy_MessageReceived;
|
||||
}
|
||||
|
||||
public event Action<String> Logging
|
||||
{
|
||||
add => this.proxy.Logging += value;
|
||||
remove => this.proxy.Logging -= value;
|
||||
}
|
||||
|
||||
public String SirtId { get; private set; }
|
||||
|
||||
public Int32 MHz { get; private set; }
|
||||
|
||||
public void Log(Object value) => this.proxy.Log(value);
|
||||
|
||||
public Boolean TryActivate()
|
||||
{
|
||||
var activated = this.proxy.TryOpen();
|
||||
|
||||
if (activated)
|
||||
{
|
||||
runningTasks.Clear();
|
||||
}
|
||||
|
||||
var awaiter = new ManualResetEventSlim();
|
||||
|
||||
var task = JustSirtTask.ActivateSIRT;
|
||||
task.Cancelled += _ => awaiter.Set();
|
||||
task.Completed += _task =>
|
||||
{
|
||||
activated = _task.TaskStatus == JustTaskStatus.Completed;
|
||||
|
||||
if (activated)
|
||||
{
|
||||
awaiter.Set();
|
||||
}
|
||||
};
|
||||
task = runningTasks.AddOrUpdate(task.Address, task, (a, t) => task);
|
||||
|
||||
task.PrepareForRun();
|
||||
this.proxy.WriteBytes(task);
|
||||
this.Log(task);
|
||||
awaiter.Wait();
|
||||
awaiter.Reset();
|
||||
|
||||
if (activated)
|
||||
{
|
||||
task = JustSirtTask.IdentifySIRT;
|
||||
task.Cancelled += _ => awaiter.Set();
|
||||
task.Completed += _task =>
|
||||
{
|
||||
activated = _task.TaskStatus == JustTaskStatus.Completed;
|
||||
|
||||
if (activated)
|
||||
{
|
||||
awaiter.Set();
|
||||
}
|
||||
};
|
||||
task = runningTasks.AddOrUpdate(task.Address, task, (a, t) => task);
|
||||
|
||||
task.PrepareForRun();
|
||||
this.proxy.WriteBytes(task);
|
||||
this.Log(task);
|
||||
awaiter.Wait();
|
||||
awaiter.Reset();
|
||||
|
||||
if (activated)
|
||||
{
|
||||
this.SirtId = BitConverter.ToString(task.LastPayload);
|
||||
this.MHz = this.SirtId[10] == '0' ? 868 : 433;
|
||||
}
|
||||
}
|
||||
|
||||
return activated;
|
||||
}
|
||||
|
||||
public Boolean TryDeactivate()
|
||||
{
|
||||
this.proxy.MessageReceived -= this.Proxy_MessageReceived;
|
||||
|
||||
return this.proxy.TryClose();
|
||||
}
|
||||
|
||||
public JustTaskStatus TryRun(JustSirtTask task)
|
||||
{
|
||||
if (!this.proxy.IsOpen)
|
||||
{
|
||||
return JustTaskStatus.ProxyNotOpen;
|
||||
}
|
||||
|
||||
var address = task.Address;
|
||||
|
||||
if (runningTasks.TryGetValue(address, out var runningTask) && runningTask != null)
|
||||
{
|
||||
return JustTaskStatus.InRunningTasks;
|
||||
}
|
||||
|
||||
var countInPamPool = 0;
|
||||
|
||||
foreach (var _task in runningTasks.Values)
|
||||
{
|
||||
if (_task != null && _task.Cmd == JustSirtMessage.W_PAM)
|
||||
{
|
||||
countInPamPool++;
|
||||
}
|
||||
}
|
||||
|
||||
if (countInPamPool >= 5)
|
||||
{
|
||||
return JustTaskStatus.PamPoolIsFull;
|
||||
}
|
||||
|
||||
task = runningTasks.AddOrUpdate(address, task, (a, t) => task);
|
||||
|
||||
if (task.TaskStatus == JustTaskStatus.Completed)
|
||||
{
|
||||
this.Task_DismissFromRunningTasks(task);
|
||||
|
||||
return JustTaskStatus.Completed;
|
||||
}
|
||||
|
||||
task.Cancelled += this.Task_DismissFromRunningTasks;
|
||||
task.Completed += this.Task_DismissFromRunningTasks;
|
||||
|
||||
task.PrepareForRun();
|
||||
this.proxy.WriteBytes(task);
|
||||
this.Log($"{task.Address}|{BitConverter.ToString(task)}");
|
||||
|
||||
return JustTaskStatus.Sent;
|
||||
}
|
||||
|
||||
private void Proxy_MessageReceived(JustSirtMessage message)
|
||||
{
|
||||
var address = message.Address;
|
||||
|
||||
if (runningTasks.TryGetValue(address, out var task) && task != null)
|
||||
{
|
||||
task.ReceiveMessage(message, this.MHz);
|
||||
this.Log($"{address}|{message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void Task_DismissFromRunningTasks(JustSirtTask task)
|
||||
{
|
||||
task.Cancelled -= this.Task_DismissFromRunningTasks;
|
||||
task.Completed -= this.Task_DismissFromRunningTasks;
|
||||
|
||||
runningTasks.TryRemove(task.Address, out var _);
|
||||
}
|
||||
}
|
||||
}
|
||||
-143
@@ -1,143 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.Sirt;
|
||||
using Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Timers;
|
||||
|
||||
public class JustSirtTask
|
||||
{
|
||||
private readonly Timer timer = new Timer();
|
||||
private readonly JustSirtMessage request = new JustSirtMessage();
|
||||
private readonly ConcurrentStack<JustSirtMessage> responses = new ConcurrentStack<JustSirtMessage>();
|
||||
|
||||
public event Action<JustSirtTask> Completed;
|
||||
public event Action<JustSirtTask> Cancelled;
|
||||
|
||||
public Byte Cmd
|
||||
{
|
||||
get => this.request.Cmd;
|
||||
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 UInt32 Address
|
||||
{
|
||||
get => this.request.Address;
|
||||
set => this.request.Address = value;
|
||||
}
|
||||
|
||||
public Byte[] Data
|
||||
{
|
||||
get => this.request.Data;
|
||||
set => this.request.Data = value;
|
||||
}
|
||||
|
||||
public JustTaskStatus TaskStatus { get; protected set; }
|
||||
|
||||
public Byte[] LastPayload
|
||||
=> this.responses.TryPeek(out var response)
|
||||
? response.Data
|
||||
: default(Byte[]);
|
||||
|
||||
public virtual void ReceiveMessage(JustSirtMessage response, Int32 mhz)
|
||||
{
|
||||
this.responses.Push(response);
|
||||
|
||||
if (this.TaskStatus != JustTaskStatus.Completed)
|
||||
{
|
||||
this.TaskStatus = JustTaskStatus.Running;
|
||||
|
||||
if (this.request.Cmd == JustSirtMessage.W_PAM)
|
||||
{
|
||||
if (response.Cmd == JustSirtMessage.FROMAIR && response.Data[0] == JustSirtMessage.SEMI)
|
||||
{
|
||||
this.TaskStatus = JustTaskStatus.Completed;
|
||||
}
|
||||
}
|
||||
else if (response.Cmd == JustSirtMessage.ACKNANSW)
|
||||
{
|
||||
this.TaskStatus = JustTaskStatus.Completed;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.TaskStatus == JustTaskStatus.Completed)
|
||||
{
|
||||
this.Completed?.Invoke(this);
|
||||
this.timer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void PrepareForRun()
|
||||
{
|
||||
this.responses.Clear();
|
||||
this.TaskStatus = JustTaskStatus.Pending;
|
||||
this.timer.AutoReset = false;
|
||||
this.timer.Interval = 10_000;
|
||||
this.timer.Elapsed += (sender, _1) =>
|
||||
{
|
||||
this.TaskStatus = JustTaskStatus.Cancelled;
|
||||
|
||||
this.Cancelled?.Invoke(this);
|
||||
};
|
||||
this.timer.Start();
|
||||
}
|
||||
|
||||
public virtual Byte[] ToByteArray()
|
||||
=> this.request.ToByteArray();
|
||||
|
||||
public override String ToString()
|
||||
=> BitConverter.ToString(this.ToByteArray());
|
||||
|
||||
public static implicit operator Byte[] (JustSirtTask task)
|
||||
=> task?.ToByteArray() ?? new Byte[] { };
|
||||
|
||||
public static readonly JustSirtTask ActivateSIRT = new JustSirtTask
|
||||
{
|
||||
Cmd = JustSirtMessage.W_REG,
|
||||
Address = 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 }
|
||||
}
|
||||
};
|
||||
|
||||
public static readonly JustSirtTask IdentifySIRT = new JustSirtTask
|
||||
{
|
||||
Cmd = JustSirtMessage.R_REG,
|
||||
Address = 0x11001820,
|
||||
P2 = 0x08
|
||||
};
|
||||
|
||||
public static readonly JustSirtTask ReadPamPool = new JustSirtTask
|
||||
{
|
||||
Cmd = JustSirtMessage.R_PAM,
|
||||
Address = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
public static JustSirtTask DeleteFromPamPool(UInt32 address) => new JustSirtTask
|
||||
{
|
||||
Cmd = JustSirtMessage.W_PAM,
|
||||
P1 = new P811 { DelPamAdr = true },
|
||||
Address = address
|
||||
};
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster
|
||||
{
|
||||
public enum JustTaskStatus
|
||||
{
|
||||
Pending = 0,
|
||||
Running = 1,
|
||||
Completed = 2,
|
||||
Cancelled = 3,
|
||||
InRunningTasks = 4,
|
||||
PamPoolIsFull = 5,
|
||||
InPamPool = 6,
|
||||
Sent = 7,
|
||||
ProxyNotOpen = 8,
|
||||
}
|
||||
}
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class BluetoothOperating
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
|
||||
public BluetoothOperating() => this.bits = new Byte[8];
|
||||
|
||||
private BluetoothOperating(Byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// 0 -> Transparent Mode at 115k2 Baud 8,n,1
|
||||
/// </summary>
|
||||
public Boolean BtOpMode
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>after "TIME_OFF" is elapsed without any command via Bluetooth, Bluetooth interface will be switched off</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>normal operation</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean BtPwrSave
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>BT module will be switched off</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>normal operation</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean BtOff
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(BluetoothOperating param)
|
||||
=> param.bits.ToByte();
|
||||
|
||||
public static implicit operator BluetoothOperating(Byte _byte)
|
||||
=> new BluetoothOperating(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
|
||||
{
|
||||
public enum OperatingModes
|
||||
{
|
||||
Off = 0,
|
||||
ReceiveF1TransmitSensusRFF3 = 1,
|
||||
ReceiveF2TransmitSensusRFF2 = 2,
|
||||
ReceiveWirelessMbusT1CMode = 3,
|
||||
ReceiveWirelessMbusS1Mode = 4,
|
||||
Receive = 5,
|
||||
TestMode = 8,
|
||||
Undefined = 15
|
||||
}
|
||||
}
|
||||
-243
@@ -1,243 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Parameter P81-1 is the first modifier of "Write to PAM Pool" command and is placed at third position,
|
||||
/// if telegram from PC -> SIRT begins with {0x55, 0x81}.
|
||||
/// This Byte describe in detailed what PAM message should do in detail.
|
||||
/// <para>There is an public priority within the bits which are described at next table:</para>
|
||||
/// <list type="table">
|
||||
/// <listheader>
|
||||
/// <term>7</term>
|
||||
/// <term>6</term>
|
||||
/// <term>5</term>
|
||||
/// <term>4</term>
|
||||
/// <term>3</term>
|
||||
/// <term>2</term>
|
||||
/// <term>1</term>
|
||||
/// <term>0</term>
|
||||
/// <description>Description</description>
|
||||
/// </listheader>
|
||||
/// <item>
|
||||
/// <term>1</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <description>delete all entries from pool, regardless of address</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <term>1</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <description>delete entry with this radio address from pool</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>1</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <description>write entry with this radio address to pool and delete after transmit</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>1</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <description>write entry with this radio address to pool and delete after SEMI received</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>1</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <description>write entry with this radio address to pool and leave entry at pool</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>1</term>
|
||||
/// <term>X</term>
|
||||
/// <term>0/1</term>
|
||||
/// <description>write entry with this radio address to pool, create Wake Up sequence and send out PAM after receive a BUP(LAT) from this address and delete after timeOutPam is elapsed</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>0</term>
|
||||
/// <term>X</term>
|
||||
/// <term>X</term>
|
||||
/// <description>write entry with this radio address to pool and delete after timeOutPam is elapsed</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public class P811
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
|
||||
public P811() => this.bits = new Byte[8];
|
||||
|
||||
private P811(Byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>module 2 is Wakeup Transmitter</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>module 1 is Wakeup Transmitter</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean WakeUpModul
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>first transmit Wakeup Sequence and afterwards normal PAM</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>normal PAM</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean WakeUpCmd
|
||||
{
|
||||
get => this.bits[2] == 1;
|
||||
set => this.bits[2] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>ignore timeout register for automatic delete of PAM</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>do nothing special</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean IgnoreTimeout
|
||||
{
|
||||
get => this.bits[3] == 1;
|
||||
set => this.bits[3] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>delete entry from PAM pool after SEMI receipt</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>do nothing after SEMI receipt</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean DelPamSemi
|
||||
{
|
||||
get => this.bits[4] == 1;
|
||||
set => this.bits[4] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>delete entry from PAM pool after PAM transmit</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>do nothing after PAM transmit</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean DelPamTx
|
||||
{
|
||||
get => this.bits[5] == 1;
|
||||
set => this.bits[5] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>delete from PAM pool</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>write to PAM pool</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean DelPamAdr
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>delete all entries from PAM pool</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>do nothing special</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean DelPamAll
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(P811 param)
|
||||
=> param.bits.ToByte();
|
||||
|
||||
public static implicit operator P811(Byte _byte)
|
||||
=> new P811(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class PAMStatus
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
|
||||
public PAMStatus(Byte _byte)
|
||||
=> this.bits = _byte.GetBits();
|
||||
|
||||
public Boolean CMD_UNKNOWN => this.bits[0] == 1;
|
||||
|
||||
public Boolean WRONG_AUTH => this.bits[1] == 1;
|
||||
|
||||
public Boolean EXPIRED_AUTH => this.bits[2] == 1;
|
||||
|
||||
public Boolean MIXED_TYPES => this.bits[3] == 1;
|
||||
|
||||
public Boolean OUT_OF_RANGE => this.bits[4] == 1;
|
||||
|
||||
public override String ToString()
|
||||
{
|
||||
var status = nameof(OK);
|
||||
var value = this.bits.ToByte();
|
||||
|
||||
if ((value & 1) == 1)
|
||||
{
|
||||
status = nameof(CMD_UNKNOWN);
|
||||
}
|
||||
|
||||
if ((value & 2) == 2)
|
||||
{
|
||||
status = nameof(WRONG_AUTH);
|
||||
}
|
||||
|
||||
if ((value & 4) == 4)
|
||||
{
|
||||
status = nameof(EXPIRED_AUTH);
|
||||
}
|
||||
|
||||
if ((value & 8) == 8)
|
||||
{
|
||||
status = nameof(MIXED_TYPES);
|
||||
}
|
||||
|
||||
if ((value & 16) == 16)
|
||||
{
|
||||
status = nameof(OUT_OF_RANGE);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public static Byte OK = 0;
|
||||
|
||||
public static implicit operator Byte(PAMStatus status)
|
||||
=> status?.bits?.ToByte() ?? 0xFF;
|
||||
|
||||
public static implicit operator String(PAMStatus status)
|
||||
=> status?.ToString();
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
|
||||
{
|
||||
using System;
|
||||
|
||||
public class PamTimeout
|
||||
{
|
||||
public PamTimeout() => this.Minutes = 0;
|
||||
|
||||
private PamTimeout(Byte minutes) => this.Minutes = minutes;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>value == 0</term>
|
||||
/// <description>PAM will never automatically deleted</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>value != 0</term>
|
||||
/// <description>duration after a PAM will be automatically deleted out of PAM-Pool, if no other rule deletes entry before</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>Several bits at parameter P81-1 or P81-2 may delete entry at PAM-Pool before 5 minutes elapsed. </para>
|
||||
/// </summary>
|
||||
public Byte Minutes { get; set; }
|
||||
|
||||
public static implicit operator Byte(PamTimeout param)
|
||||
=> param.Minutes;
|
||||
|
||||
public static implicit operator PamTimeout(Byte _byte)
|
||||
=> new PamTimeout(_byte);
|
||||
}
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class RFModuleOperating
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
|
||||
public RFModuleOperating() => this.bits = new Byte[8];
|
||||
|
||||
private RFModuleOperating(Byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// 0 -> Transparent Mode at 115k2 Baud 8,n,1
|
||||
/// </summary>
|
||||
public OperatingModes OpMode
|
||||
{
|
||||
get
|
||||
{
|
||||
var bits = new Byte[8];
|
||||
|
||||
Array.Copy(this.bits, 0, bits, 0, 4);
|
||||
|
||||
return (OperatingModes)bits.ToByte();
|
||||
}
|
||||
set
|
||||
{
|
||||
var bits = ((Byte)value).GetBits();
|
||||
|
||||
Array.Copy(bits, 0, this.bits, 0, 4);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>external antenna</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>internal antenna</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean Antenna
|
||||
{
|
||||
get => this.bits[4] == 1;
|
||||
set => this.bits[4] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>Module not powered</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>Module powered</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean RfOff
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(RFModuleOperating param)
|
||||
=> param.bits.ToByte();
|
||||
|
||||
public static implicit operator RFModuleOperating(Byte _byte)
|
||||
=> new RFModuleOperating(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
-138
@@ -1,138 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class SirtOperating
|
||||
{
|
||||
private readonly Byte[] bits;
|
||||
|
||||
public SirtOperating() => this.bits = new Byte[8];
|
||||
|
||||
private SirtOperating(Byte[] bits) => this.bits = bits;
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>Bluetooth is output for non-requested messages</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>USB port is output for non-requested messages</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>non requested messages are received radio payloads if a radio module is switched on</para>
|
||||
/// </summary>
|
||||
public Boolean DataBtOut
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>: if both RF-Modules are set to SensusRF Mode, both payloads of RF-Modules will be send out </description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>if both RF-Modules are set to SensusRF Mode, the channel with higher RSSI Level will be send out</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>for test purposes both receiver outputs can be shown - but remember Double traffic rate on Bluetoothor USB-output</para>
|
||||
/// </summary>
|
||||
public Boolean BothChsOut
|
||||
{
|
||||
get => this.bits[1] == 1;
|
||||
set => this.bits[1] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>also payloads with incorrect radio-CRC will send out!</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>normal operation</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>may be only interesting for test purposes </para>
|
||||
/// </summary>
|
||||
public Boolean IgnoreCRC
|
||||
{
|
||||
get => this.bits[2] == 1;
|
||||
set => this.bits[2] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>don't switch Power path off if going to USB Suspend and drawing more current as allowed</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>switch Power path off if going to USB Suspend</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>New at Version 1.0.0.6</para>
|
||||
/// </summary>
|
||||
public Boolean IgnoreUSBrules
|
||||
{
|
||||
get => this.bits[3] == 1;
|
||||
set => this.bits[3] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>after "TIME_OFF" is elapsed without any command to SIRT, SIRT will be switched off</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>normal operation</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>timeout starts at beginning, if any command or communication to and from SIRT is initiated</para>
|
||||
/// </summary>
|
||||
public Boolean SirtPwrSave
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>SIRT will be switched off {like push off button}</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>normal operation</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// <para>
|
||||
/// SIRT can be switched off per command, but no answer will send if this bit was set.SIRT can not be switched
|
||||
/// on per command only by pushing green button for a second
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public Boolean SirtOff
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public static implicit operator Byte(SirtOperating param)
|
||||
=> param.bits.ToByte();
|
||||
|
||||
public static implicit operator SirtOperating(Byte _byte)
|
||||
=> new SirtOperating(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Common.Hardware.Interfaces.Ports.SirtBroadcaster")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Common.Hardware.Interfaces.Ports.SirtBroadcaster")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f408de9e-01e6-4cff-ae79-b572b0674fa2")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -1,192 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq;
|
||||
|
||||
using SystemSerialPort = System.IO.Ports.SerialPort;
|
||||
|
||||
/// <summary>
|
||||
/// Class that implements the <see cref="Common.Hardware.Interfaces.Ports.ISerialPort"/> features over one of the opened <see cref="System.IO.Ports.SerialPort"/>.
|
||||
/// </summary>
|
||||
public class SerialPort : ISerialPort
|
||||
{
|
||||
/// <summary>
|
||||
/// Because it is possible that the serial port is used out of the current thread,
|
||||
/// all opened <see cref="System.IO.Ports.SerialPort"/>s are stored in a static
|
||||
/// <see cref="System.Collections.Concurrent.ConcurrentDictionary{TKey, TValue}"/> that is accessible from any thread and is stored on the current thread.
|
||||
/// Where the key is <see cref="System.String"/> and the value is <see cref="System.IO.Ports.SerialPort"/>
|
||||
/// </summary>
|
||||
private static readonly ConcurrentDictionary<string, SystemSerialPort> serialPorts
|
||||
= new ConcurrentDictionary<string, SystemSerialPort>();
|
||||
|
||||
/// <summary>
|
||||
/// Holds the current <see cref="System.IO.Ports.SerialPort"/> settings ready for use on <see cref="Common.Hardware.Interfaces.Ports.SerialPort.Open()"/>
|
||||
/// </summary>
|
||||
private readonly SerialPortSettings settings;
|
||||
|
||||
/// <summary>
|
||||
/// Returns current COM port name.
|
||||
/// </summary>
|
||||
private string portName => this.settings.PortName;
|
||||
|
||||
public SerialPort(SerialPortSettings serialPortSettings)
|
||||
{
|
||||
this.settings = serialPortSettings;
|
||||
|
||||
if (!SystemSerialPort.GetPortNames().Any(x => x.Equals(this.portName, StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(SystemSerialPort.PortName), "Dose not exists!");
|
||||
}
|
||||
}
|
||||
|
||||
public event Action<string, Exception> Exception;
|
||||
|
||||
public void Close()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (serialPorts.TryRemove(this.portName, out var serialPort))
|
||||
{
|
||||
serialPort.Close();
|
||||
|
||||
serialPort.ErrorReceived -= this.SerialPort_ErrorReceived;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsOpen()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (serialPorts.TryGetValue(this.portName, out var serialPort))
|
||||
{
|
||||
return serialPort.IsOpen;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
try
|
||||
{
|
||||
var serialPort = new SystemSerialPort
|
||||
{
|
||||
BaudRate = this.settings.BaudRate,
|
||||
DataBits = this.settings.DataBits,
|
||||
Parity = this.settings.Parity,
|
||||
PortName = this.settings.PortName,
|
||||
StopBits = this.settings.StopBits
|
||||
};
|
||||
|
||||
if (serialPorts.TryAdd(this.portName, serialPort))
|
||||
{
|
||||
serialPort.ErrorReceived += this.SerialPort_ErrorReceived;
|
||||
|
||||
serialPort.Open();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] ReadBytes()
|
||||
{
|
||||
var length = 0;
|
||||
var bytes = new byte[length];
|
||||
|
||||
try
|
||||
{
|
||||
if (serialPorts.TryGetValue(this.portName, out var serialPort) && serialPort.IsOpen)
|
||||
{
|
||||
bytes = new byte[serialPort.ReadBufferSize];
|
||||
length = serialPort.Read(bytes, 0, bytes.Length);
|
||||
|
||||
Array.Resize(ref bytes, length);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public string ReadLine()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (serialPorts.TryGetValue(this.portName, out var serialPort) && serialPort.IsOpen)
|
||||
{
|
||||
return serialPort.ReadLine();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
|
||||
return default(string);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
=> $"{this.settings.PortName}, "
|
||||
+ $"{this.settings.BaudRate}, "
|
||||
+ $"{this.settings.DataBits}, "
|
||||
+ $"{this.settings.Parity}, "
|
||||
+ $"{this.settings.StopBits}";
|
||||
|
||||
public void WriteBytes(params byte[] bytes)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (serialPorts.TryGetValue(this.portName, out var serialPort) && serialPort.IsOpen)
|
||||
{
|
||||
serialPort.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteLine(string line)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (serialPorts.TryGetValue(this.portName, out var serialPort) && serialPort.IsOpen)
|
||||
{
|
||||
serialPort.WriteLine(line);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
this.Throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void SerialPort_ErrorReceived(Object sender, System.IO.Ports.SerialErrorReceivedEventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
this.Open();
|
||||
this.Throw(new InvalidOperationException($"{nameof(System.IO.Ports.SerialError)}: {nameof(e.EventType)} = {e.EventType}"));
|
||||
}
|
||||
|
||||
private void Throw(Exception exception)
|
||||
=> this.Exception?.Invoke(this.portName, exception);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
namespace LaaPackages.Features.Cordonel.Models
|
||||
{
|
||||
using System;
|
||||
|
||||
public class CordonelRequirements
|
||||
{
|
||||
public Int32? SpecialId { get; set; } // ✓
|
||||
|
||||
public Int32? SpecialVersion { get; set; } // ✓
|
||||
|
||||
public Int32? StandardId { get; set; } // ✓
|
||||
|
||||
public Int32? StandardVersion { get; set; } // ✓
|
||||
|
||||
public String Region { get; set; } // ✓
|
||||
|
||||
public String MeterSize { get; set; } // ✓
|
||||
|
||||
public Int32? OuterProductionOrderNr { get; set; } // ✓
|
||||
|
||||
public Int32? ProductionOrderNr { get; set; } // ✓
|
||||
|
||||
public Int32? OuterPcbId { get; set; } // ✓
|
||||
|
||||
public Int32? PcbId { get; set; } // ✓
|
||||
|
||||
public Boolean? SkipCalibration { get; set; } // ✓
|
||||
|
||||
public Boolean? SkipRadioCheck { get; set; } // ✓
|
||||
|
||||
public String FwVersion { get; set; } // ✓
|
||||
|
||||
public String LutCrc { get; set; } // ✓
|
||||
|
||||
public Double? RequiredLifeTimeYearsAssembly { get; set; } // ✓
|
||||
|
||||
public Double? RequiredLifeTimeYearsShipping { get; set; } // ✓
|
||||
|
||||
public Double? MaxDrainedBatteryLoadPercentAssembly { get; set; } // ✓
|
||||
|
||||
public Double? MaxDrainedBatteryLoadPercentShipping { get; set; } // ✓
|
||||
|
||||
public Double? MaxStorageMonths { get; set; } // ✓
|
||||
|
||||
public Double? QuiescentCurrent_uA { get; set; } // ✓
|
||||
|
||||
public Double? EstimatedProductionBatteryLoadPercent { get; set; } // ✓
|
||||
|
||||
public DateTime? RequirementTimestamp { get; set; } // na
|
||||
|
||||
public String ApprovalName { get; set; } // na
|
||||
|
||||
public String ApprovalComment { get; set; } // na
|
||||
|
||||
public Boolean? IsSpecialActive { get; set; } // na
|
||||
|
||||
public Boolean? IsStandardActive { get; set; } // na
|
||||
|
||||
public Boolean? IsStandardApproved { get; set; }
|
||||
|
||||
public Boolean? IsSpecialApproved { get; set; }
|
||||
|
||||
public String RegionSizeKey { get; set; } // na
|
||||
}
|
||||
}
|
||||
@@ -51,9 +51,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\..\..\LaaProductionWeb\Data\LaaProduction.Data.Cordonel\Models\CordonelRequirements.cs">
|
||||
<Link>CordonelRequirements.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="CordonelRequirements.cs" />
|
||||
<Compile Include="GenesisStatusHandler.cs" />
|
||||
<Compile Include="GenesisStatus.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
||||
+2
-2
@@ -53,9 +53,9 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Interfaces\Ports\Common.Hardware.Interfaces.Ports\Common.Hardware.Interfaces.Ports.csproj">
|
||||
<ProjectReference Include="..\..\..\Common.Hardware.Ports\Common.Hardware.Ports.csproj">
|
||||
<Project>{9AE071C0-DB12-4E09-A3C7-43F6DCD518D6}</Project>
|
||||
<Name>Common.Hardware.Interfaces.Ports</Name>
|
||||
<Name>Common.Hardware.Ports</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common.Hardware.WaterMeter.OmniPlus.Features\Common.Hardware.WaterMeter.OmniPlus.Features.csproj">
|
||||
<Project>{9D89FA2A-1217-4CE9-B217-E7602B974EA9}</Project>
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Common.Hardware.WaterMeter.OmniPlus
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports;
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System;
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Common.Hardware.WaterMeter.OmniPlus
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports;
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System;
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
namespace Common.Hardware.WaterMeter.OmniPlus
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports;
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
using System;
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
c43c40a030005a8f189e6179faf40a6d42bfef5c
|
||||
89102b0142e574de38a9f47d370f3334e5e6c268
|
||||
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class AlarmsMask : Pam
|
||||
{
|
||||
protected readonly Byte[] bits;
|
||||
|
||||
protected AlarmsMask(Int32 length, Byte cmd) : base(length, cmd)
|
||||
=> this.bits = new Byte[8];
|
||||
|
||||
public AlarmsMask(Byte value, Byte cmd = DeactivateAlarms) : base(2, cmd)
|
||||
=> this.bits = value.GetBits();
|
||||
|
||||
public Boolean SpecificError
|
||||
{
|
||||
get => this.bits[0] == 1;
|
||||
set => this.bits[0] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean MediumAbsent
|
||||
{
|
||||
get => this.bits[1] == 1;
|
||||
set => this.bits[1] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean BrokenPipe
|
||||
{
|
||||
get => this.bits[2] == 1;
|
||||
set => this.bits[2] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean Backflow
|
||||
{
|
||||
get => this.bits[3] == 1;
|
||||
set => this.bits[3] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean MetrologyUnavailable
|
||||
{
|
||||
get => this.bits[4] == 1;
|
||||
set => this.bits[4] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean MagneticTamper
|
||||
{
|
||||
get => this.bits[5] == 1;
|
||||
set => this.bits[5] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean Leak
|
||||
{
|
||||
get => this.bits[6] == 1;
|
||||
set => this.bits[6] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean LowBattery
|
||||
{
|
||||
get => this.bits[7] == 1;
|
||||
set => this.bits[7] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public override Byte[] ToByteArray()
|
||||
{
|
||||
this.bytes[1] = this.bits.ToByte();
|
||||
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using System;
|
||||
|
||||
public enum AuthLevel : UInt64
|
||||
{
|
||||
O = 0x00_00_00_00_00_00_00_00,
|
||||
I = 0x01_00_00_0D_68_30_14_01,
|
||||
II = 0x02_00_00_40_80_0E_14_02,
|
||||
III = 0x03_00_00_22_73_93_63_03,
|
||||
}
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class ChangeDataLoggerSettings : Pam
|
||||
{
|
||||
public ChangeDataLoggerSettings() : base(5, ChangeDataLoggerSettings)
|
||||
{
|
||||
}
|
||||
|
||||
public UInt16 TimeInterval
|
||||
{
|
||||
get => this.bytes.ToUInt16BE(1);
|
||||
set => value.GetBytesBE().CopyTo(this.bytes, 1);
|
||||
}
|
||||
|
||||
public Byte TimeOfMinimumFlow
|
||||
{
|
||||
get => this.bytes[3];
|
||||
set => this.bytes[3] = value;
|
||||
}
|
||||
|
||||
public Byte MinimumFlow
|
||||
{
|
||||
get => this.bytes[4];
|
||||
set => this.bytes[4] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using System;
|
||||
|
||||
public class ChangeFixedDateReadingSettings : Pam
|
||||
{
|
||||
public ChangeFixedDateReadingSettings() : base(4, ChangeFixedDateReadingSettings)
|
||||
{
|
||||
}
|
||||
|
||||
public Byte DayOfMonth
|
||||
{
|
||||
get => this.bytes[1];
|
||||
set => this.bytes[1] = value;
|
||||
}
|
||||
|
||||
public Byte SettingI
|
||||
{
|
||||
get => this.bytes[2];
|
||||
set => this.bytes[2] = value;
|
||||
}
|
||||
|
||||
public Byte SettingII
|
||||
{
|
||||
get => this.bytes[3];
|
||||
set => this.bytes[3] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class ChangeRadioId : Pam
|
||||
{
|
||||
public ChangeRadioId() : base(5, ChangeRadioId)
|
||||
{
|
||||
}
|
||||
|
||||
public ChangeRadioId(UInt32 address) : this()
|
||||
=> this.Address = address;
|
||||
|
||||
public UInt32 Address
|
||||
{
|
||||
get => this.bytes.ToUInt32BigEndian(1);
|
||||
set => value.ToBigEndianBytes().CopyTo(this.bytes, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using System;
|
||||
|
||||
public class ChangeState : DebugCmd
|
||||
{
|
||||
public enum Modes : Byte
|
||||
{
|
||||
Production = 0,
|
||||
Shipment = 1,
|
||||
}
|
||||
|
||||
public ChangeState() : base(State)
|
||||
{
|
||||
}
|
||||
|
||||
public Modes Mode
|
||||
{
|
||||
get => (Modes)this.bytes[0];
|
||||
set => this.bytes[0] = (Byte)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{E19C1694-132E-477C-86CB-8E146D5F59B0}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Common.Hardware.WaterMeter.eRegister.Features</RootNamespace>
|
||||
<AssemblyName>Common.Hardware.WaterMeter.eRegister.Features</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<NoWarn>IDE0003;IDE0049;</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ActivateMetrologyTestMode.cs" />
|
||||
<Compile Include="AlarmsMask.cs" />
|
||||
<Compile Include="ChangeCustomerText.cs" />
|
||||
<Compile Include="ChangeDataLoggerSettings.cs" />
|
||||
<Compile Include="ChangePin.cs" />
|
||||
<Compile Include="ChangeSensusRFEncryptionKey.cs" />
|
||||
<Compile Include="ChangeFixedDateReadingSettings.cs" />
|
||||
<Compile Include="ChangeMeterId.cs" />
|
||||
<Compile Include="ChangeMeterReading.cs" />
|
||||
<Compile Include="ChangeRadioId.cs" />
|
||||
<Compile Include="ChangeTransmissionInterval.cs" />
|
||||
<Compile Include="DeactivateTransmitter.cs" />
|
||||
<Compile Include="DecimalPointLocations.cs" />
|
||||
<Compile Include="DisableOTAFirmwareUpdate.cs" />
|
||||
<Compile Include="EncapsulatedFlexNet.cs" />
|
||||
<Compile Include="EregisterFeatures.cs" />
|
||||
<Compile Include="EregisterFeaturesDebug.cs" />
|
||||
<Compile Include="FactoryComplete.cs" />
|
||||
<Compile Include="GetCustomerDebug.cs" />
|
||||
<Compile Include="MBusMode.cs" />
|
||||
<Compile Include="MeterTypes.cs" />
|
||||
<Compile Include="MeterUnits.cs" />
|
||||
<Compile Include="OTAMode.cs" />
|
||||
<Compile Include="PamAttribute.cs" />
|
||||
<Compile Include="ParameterizeBrokenPipeDetection.cs" />
|
||||
<Compile Include="ParameterizeLeakageDetection.cs" />
|
||||
<Compile Include="Ping.cs" />
|
||||
<Compile Include="PowerLevelModes.cs" />
|
||||
<Compile Include="ProvidePin.cs" />
|
||||
<Compile Include="AuthLevel.cs" />
|
||||
<Compile Include="DebugCmd.cs" />
|
||||
<Compile Include="DisableCredits.cs" />
|
||||
<Compile Include="EnableCredits.cs" />
|
||||
<Compile Include="SetMeterType.cs" />
|
||||
<Compile Include="OpticalTelegram.cs" />
|
||||
<Compile Include="Options.cs" />
|
||||
<Compile Include="ReceiveSequenceOfTestTelegrams.cs" />
|
||||
<Compile Include="RegisterMode.cs" />
|
||||
<Compile Include="RequestDebugTelegram.cs" />
|
||||
<Compile Include="RequestFixedDateReading.cs" />
|
||||
<Compile Include="RequestLoggingData.cs" />
|
||||
<Compile Include="RequestMemoryDump.cs" />
|
||||
<Compile Include="ResetAlarms.cs" />
|
||||
<Compile Include="ResetCredits.cs" />
|
||||
<Compile Include="ResetMode.cs" />
|
||||
<Compile Include="SendBubbleUpBurst.cs" />
|
||||
<Compile Include="SendSequenceOfTestTelegrams.cs" />
|
||||
<Compile Include="SendTestPattern.cs" />
|
||||
<Compile Include="SerialOutput.cs" />
|
||||
<Compile Include="SetActivationByThreshold.cs" />
|
||||
<Compile Include="SetActivityCreditLimits.cs" />
|
||||
<Compile Include="SetAlarms.cs" />
|
||||
<Compile Include="SetBatteryUsageTestOffset.cs" />
|
||||
<Compile Include="SetBytterySeconds.cs" />
|
||||
<Compile Include="ChangeNumberOfLatWindows.cs" />
|
||||
<Compile Include="ChangeNumberOfDeals.cs" />
|
||||
<Compile Include="CustomerDebug.cs" />
|
||||
<Compile Include="DeactivateAlarms.cs" />
|
||||
<Compile Include="Pam.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ChangeWakeUp.cs" />
|
||||
<Compile Include="SetDateAndTime.cs" />
|
||||
<Compile Include="SetRebootCount.cs" />
|
||||
<Compile Include="Reset.cs" />
|
||||
<Compile Include="AlarmPersistence.cs" />
|
||||
<Compile Include="SetFrequencyOffset.cs" />
|
||||
<Compile Include="SetHistoricalErrorLimit.cs" />
|
||||
<Compile Include="SetMetrologyParameters.cs" />
|
||||
<Compile Include="SetPcbId.cs" />
|
||||
<Compile Include="SetPowerLevel.cs" />
|
||||
<Compile Include="SetSpecificError.cs" />
|
||||
<Compile Include="SetTestFastActivityBupTiming.cs" />
|
||||
<Compile Include="SetTFXParameters.cs" />
|
||||
<Compile Include="SetVariablePcbId.cs" />
|
||||
<Compile Include="SingleBytePam.cs" />
|
||||
<Compile Include="ChangeState.cs" />
|
||||
<Compile Include="WakeUpMode.cs" />
|
||||
<Compile Include="WirelessMBusMode.cs" />
|
||||
<Compile Include="OpenMeteringTransmitionIntervalWMBus.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\Utils\Common.Utils.Extensions\Common.Utils.Extensions.csproj">
|
||||
<Project>{05f0ccaf-9f2b-45f9-a7f8-12f29ad182f3}</Project>
|
||||
<Name>Common.Utils.Extensions</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using System;
|
||||
|
||||
public class ParameterizeLeakageDetection : SingleBytePam
|
||||
{
|
||||
public ParameterizeLeakageDetection() : base(ParameterizeLeakageDetection)
|
||||
{
|
||||
}
|
||||
|
||||
public ParameterizeLeakageDetection(Byte value) : base(value, ParameterizeLeakageDetection)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
public class Ping : Pam
|
||||
{
|
||||
public Ping() : base(1 /* TODO: TBD */, Ping)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Common.Hardware.WaterMeter.eRegister.Features")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Common.Hardware.WaterMeter.eRegister.Features")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2024")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("e19c1694-132e-477c-86cb-8e146d5f59b0")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class SetPcbId : Pam
|
||||
{
|
||||
public SetPcbId() : base(5, SetPCB)
|
||||
{
|
||||
}
|
||||
|
||||
public UInt32 ID
|
||||
{
|
||||
get => this.bytes.ToUInt32BigEndian(1);
|
||||
set => value.ToBigEndianBytes().CopyTo(this.bytes, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using System;
|
||||
|
||||
public class SetPowerLevel : SingleBytePam
|
||||
{
|
||||
public SetPowerLevel() : base(SetPowerLevel)
|
||||
{
|
||||
}
|
||||
|
||||
public SetPowerLevel(Byte value) : base(value, SetPowerLevel)
|
||||
{
|
||||
}
|
||||
|
||||
public Byte PowerLevel { get; set; }
|
||||
|
||||
public PowerLevelModes Mode { get; set; }
|
||||
|
||||
public override Byte[] ToByteArray()
|
||||
{
|
||||
this.Value = (Byte)((Byte)this.Mode | 127 & this.PowerLevel);
|
||||
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
-188
@@ -1,188 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class SetTFXParameters : Pam
|
||||
{
|
||||
private readonly Byte[] bitsFromByte2;
|
||||
private readonly Byte[] bitsFromByte3;
|
||||
private readonly Byte[] bitsFromByte4;
|
||||
private readonly Byte[] bitsFromByte5;
|
||||
|
||||
public SetTFXParameters() : base(22, TFXParameters)
|
||||
{
|
||||
this.bitsFromByte2 = new Byte[8];
|
||||
this.bitsFromByte3 = new Byte[8];
|
||||
this.bitsFromByte4 = new Byte[8];
|
||||
this.bitsFromByte5 = new Byte[8];
|
||||
}
|
||||
|
||||
public Byte PamLength => (Byte)(this.bytes.Length - 1);
|
||||
|
||||
public Char SmartMeterType => (Char)this.bytes[2];
|
||||
|
||||
public Boolean MSRChanged
|
||||
{
|
||||
get => this.bitsFromByte2[0] == 1;
|
||||
set => this.bitsFromByte2[0] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean UnitsChanged
|
||||
{
|
||||
get => this.bitsFromByte2[1] == 1;
|
||||
set => this.bitsFromByte2[1] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean HistoryScaleChanged
|
||||
{
|
||||
get => this.bitsFromByte2[2] == 1;
|
||||
set => this.bitsFromByte2[2] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean ReadingResolutionChanged
|
||||
{
|
||||
get => this.bitsFromByte2[3] == 1;
|
||||
set => this.bitsFromByte2[3] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean NumberOfDigitsChanged
|
||||
{
|
||||
get => this.bitsFromByte2[4] == 1;
|
||||
set => this.bitsFromByte2[4] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean RegisterModeChanged
|
||||
{
|
||||
get => this.bitsFromByte2[5] == 1;
|
||||
set => this.bitsFromByte2[5] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean HistorySizeChanged
|
||||
{
|
||||
get => this.bitsFromByte2[6] == 1;
|
||||
set => this.bitsFromByte2[6] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Boolean TimeChanged
|
||||
{
|
||||
get => this.bitsFromByte2[7] == 1;
|
||||
set => this.bitsFromByte2[7] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
public Byte MeterSampleRate
|
||||
{
|
||||
get => this.bitsFromByte3.ToByte(0, 3);
|
||||
set => value.SetBits(this.bitsFromByte3, 0, 3);
|
||||
}
|
||||
|
||||
public Byte Units
|
||||
{
|
||||
get => this.bitsFromByte3.ToByte(3, 3);
|
||||
set => value.SetBits(this.bitsFromByte3, 3, 3);
|
||||
}
|
||||
|
||||
public Byte HistoryScale
|
||||
{
|
||||
get => this.bitsFromByte3.ToByte(6, 2);
|
||||
set => value.SetBits(this.bitsFromByte3, 6, 2);
|
||||
}
|
||||
|
||||
public Byte ReadingResolution
|
||||
{
|
||||
get => this.bitsFromByte4.ToByte(0, 4);
|
||||
set => value.SetBits(this.bitsFromByte4, 0, 4);
|
||||
}
|
||||
|
||||
public Byte NumberOfDigits
|
||||
{
|
||||
get => this.bitsFromByte4.ToByte(4, 3);
|
||||
set => value.SetBits(this.bitsFromByte4, 4, 3);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Boolean. SmartPoint will send this bit to request the Register use Zero Time
|
||||
/// Quantum on all incoming commands.Register is expected to return this bit if incoming
|
||||
/// time quantum is disabled.There is no change bit defined for this setting, the SmartPoint
|
||||
/// will send the expected setting in every PAM 145 command.
|
||||
/// SmartPoint is expecting this feature to be supported in x0.2.0B - Register FW -
|
||||
/// x1.1.00. The SmartPoint will handle the case of the register not returning the bit set to true
|
||||
/// when expected by continuing to send commands with time quantum according to the
|
||||
/// FlexNet AES CCM Matrix.
|
||||
/// </summary>
|
||||
public Boolean DisableIncomingTimeQuantum
|
||||
{
|
||||
get => this.bitsFromByte4[7] == 1;
|
||||
set => this.bitsFromByte4[7] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Value|Mode:
|
||||
/// 0|Idle
|
||||
/// 1|SensusRF
|
||||
/// 2|TFX
|
||||
/// 3|reserved
|
||||
/// </summary>
|
||||
public RegisterMode RegisterMode
|
||||
{
|
||||
get => (RegisterMode)this.bitsFromByte5.ToByte(0, 2);
|
||||
set => ((Byte)value).SetBits(this.bitsFromByte5, 0, 2);
|
||||
}
|
||||
|
||||
public Byte MeterTransmitRate
|
||||
{
|
||||
get => this.bitsFromByte5.ToByte(2, 3);
|
||||
set => value.SetBits(this.bitsFromByte5, 2, 3);
|
||||
}
|
||||
|
||||
public Boolean MTRChanged
|
||||
{
|
||||
get => this.bitsFromByte5[5] == 1;
|
||||
set => this.bitsFromByte5[5] = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Currently not used. This will allow future messages from SP->backend to be larger
|
||||
/// and take advantage of the larger payload for history.In the case of differing payload
|
||||
/// lengths(because of different modulation modes for example) the register should push the
|
||||
/// longest used and the SP can truncate.
|
||||
/// </summary>
|
||||
public Byte HistorySize
|
||||
{
|
||||
get => this.bytes[7];
|
||||
/// TBD: set => this.bytes[7] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Epoch time.
|
||||
/// </summary>
|
||||
public UInt32 Time
|
||||
{
|
||||
get => BitConverter.ToUInt32(this.bytes, 8);
|
||||
set => BitConverter.GetBytes(value).CopyTo(this.bytes, 8);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// SensusRF Meter ID.
|
||||
/// </summary>
|
||||
public UInt32 RegisterMeterID => BitConverter.ToUInt32(this.bytes, 12);
|
||||
|
||||
/// <summary>
|
||||
/// The pseudo random seed used to set up FlexNet BUP tracking.
|
||||
/// </summary>
|
||||
public UInt16 PSRValue => BitConverter.ToUInt16(this.bytes, 16);
|
||||
|
||||
public UInt32 CurrentReading => BitConverter.ToUInt32(this.bytes, 18);
|
||||
|
||||
public override Byte[] ToByteArray()
|
||||
{
|
||||
this.bytes[3] = this.bitsFromByte2.ToByte();
|
||||
this.bytes[4] = this.bitsFromByte3.ToByte();
|
||||
this.bytes[5] = this.bitsFromByte4.ToByte();
|
||||
this.bytes[6] = this.bitsFromByte5.ToByte();
|
||||
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using System;
|
||||
|
||||
public class SingleBytePam : Pam
|
||||
{
|
||||
const Int32 CmdLength = 2;
|
||||
|
||||
public SingleBytePam(Byte cmd) : base(CmdLength, cmd)
|
||||
{
|
||||
}
|
||||
|
||||
public SingleBytePam(Byte value, Byte cmd) : this(cmd)
|
||||
{
|
||||
this.Value = value;
|
||||
}
|
||||
|
||||
public Byte Value
|
||||
{
|
||||
get => this.bytes[1];
|
||||
set => this.bytes[1] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Attributes
|
||||
{
|
||||
using System;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
|
||||
public class ComparePropertyAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Attributes
|
||||
{
|
||||
using System;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
|
||||
public class EregisterFeatureAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
+103
-39
@@ -8,7 +8,7 @@
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Common.Hardware.WaterMeter.eRegister</RootNamespace>
|
||||
<AssemblyName>Common.Hardware.WaterMeter.eRegister</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<TargetFrameworkProfile />
|
||||
@@ -42,65 +42,129 @@
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\Newtonsoft.Json.13.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\..\packages\NLog.5.3.4\lib\net45\NLog.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" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Data\AppCode.cs" />
|
||||
<Compile Include="Data\BUP.cs" />
|
||||
<Compile Include="Data\DEBUG.cs" />
|
||||
<Compile Include="Attributes\EregisterFeatureAttribute.cs" />
|
||||
<Compile Include="Eregister.cs" />
|
||||
<Compile Include="EregisterBatch.cs" />
|
||||
<Compile Include="EregisterFactory.cs" />
|
||||
<Compile Include="EregisterCheckFinalizationTask.cs" />
|
||||
<Compile Include="EregisterCheckInitializationTask.cs" />
|
||||
<Compile Include="EregisterExtensions.cs" />
|
||||
<Compile Include="EregisterProgrammingTask.cs" />
|
||||
<Compile Include="Models\EregisterBatchSettings.cs" />
|
||||
<Compile Include="Models\EregisterPamModel.cs" />
|
||||
<Compile Include="EregisterTask.cs" />
|
||||
<Compile Include="Features\ActivateMetrologyTestMode.cs" />
|
||||
<Compile Include="Features\AlarmPersistence.cs" />
|
||||
<Compile Include="Features\AlarmsMask.cs" />
|
||||
<Compile Include="Features\AuthLevel.cs" />
|
||||
<Compile Include="Features\ChangeCustomerText.cs" />
|
||||
<Compile Include="Features\ChangeDataLoggerSettings.cs" />
|
||||
<Compile Include="Features\ChangeFixedDateReadingSettings.cs" />
|
||||
<Compile Include="Features\ChangeMeterId.cs" />
|
||||
<Compile Include="Features\ChangeMeterReading.cs" />
|
||||
<Compile Include="Features\ChangeNumberOfDeals.cs" />
|
||||
<Compile Include="Features\ChangeNumberOfLatWindows.cs" />
|
||||
<Compile Include="Features\ChangePin.cs" />
|
||||
<Compile Include="Features\ChangeRadioId.cs" />
|
||||
<Compile Include="Features\ChangeSensusRFEncryptionKey.cs" />
|
||||
<Compile Include="Features\ChangeState.cs" />
|
||||
<Compile Include="Features\ChangeTransmissionInterval.cs" />
|
||||
<Compile Include="Features\ChangeWakeUp.cs" />
|
||||
<Compile Include="Features\CustomerDebug.cs" />
|
||||
<Compile Include="Features\DeactivateAlarms.cs" />
|
||||
<Compile Include="Features\DeactivateTransmitter.cs" />
|
||||
<Compile Include="Features\DebugCmd.cs" />
|
||||
<Compile Include="Features\DecimalPointLocations.cs" />
|
||||
<Compile Include="Features\DisableCredits.cs" />
|
||||
<Compile Include="Features\DisableOTAFirmwareUpdate.cs" />
|
||||
<Compile Include="Features\EnableCredits.cs" />
|
||||
<Compile Include="Features\EncapsulatedFlexNet.cs" />
|
||||
<Compile Include="Features\FactoryComplete.cs" />
|
||||
<Compile Include="Features\GetCustomerDebug.cs" />
|
||||
<Compile Include="Features\MBusMode.cs" />
|
||||
<Compile Include="Features\MessurementUnits.cs" />
|
||||
<Compile Include="Features\MeterTypes.cs" />
|
||||
<Compile Include="Features\StateModes.cs" />
|
||||
<Compile Include="Features\OpenMeteringTransmitionIntervalWMBus.cs" />
|
||||
<Compile Include="Features\OpticalTelegram.cs" />
|
||||
<Compile Include="Features\Options.cs" />
|
||||
<Compile Include="Features\OTAMode.cs" />
|
||||
<Compile Include="Features\Pam.cs" />
|
||||
<Compile Include="Features\PamAttribute.cs" />
|
||||
<Compile Include="Features\ParameterizeBrokenPipeDetection.cs" />
|
||||
<Compile Include="Features\ParameterizeLeakageDetection.cs" />
|
||||
<Compile Include="Features\Ping.cs" />
|
||||
<Compile Include="Features\PowerLevelModes.cs" />
|
||||
<Compile Include="Features\ProvidePin.cs" />
|
||||
<Compile Include="Features\ReceiveSequenceOfTestTelegrams.cs" />
|
||||
<Compile Include="Features\RegisterMode.cs" />
|
||||
<Compile Include="Features\RequestDebugTelegram.cs" />
|
||||
<Compile Include="Features\RequestFixedDateReading.cs" />
|
||||
<Compile Include="Features\RequestLoggingData.cs" />
|
||||
<Compile Include="Features\RequestMemoryDump.cs" />
|
||||
<Compile Include="Features\Reset.cs" />
|
||||
<Compile Include="Features\ResetAlarms.cs" />
|
||||
<Compile Include="Features\ResetCredits.cs" />
|
||||
<Compile Include="Features\ResetMode.cs" />
|
||||
<Compile Include="Features\SendBubbleUpBurst.cs" />
|
||||
<Compile Include="Features\SendSequenceOfTestTelegrams.cs" />
|
||||
<Compile Include="Features\SendTestPattern.cs" />
|
||||
<Compile Include="Features\SerialOutput.cs" />
|
||||
<Compile Include="Features\SetActivationByThreshold.cs" />
|
||||
<Compile Include="Features\SetActivityCreditLimits.cs" />
|
||||
<Compile Include="Features\SetAlarms.cs" />
|
||||
<Compile Include="Features\SetBatteryUsageTestOffset.cs" />
|
||||
<Compile Include="Features\SetBytterySeconds.cs" />
|
||||
<Compile Include="Features\SetDateAndTime.cs" />
|
||||
<Compile Include="Features\SetFrequencyOffset.cs" />
|
||||
<Compile Include="Features\SetHistoricalErrorLimit.cs" />
|
||||
<Compile Include="Features\SetMeterType.cs" />
|
||||
<Compile Include="Features\SetMetrologyParameters.cs" />
|
||||
<Compile Include="Features\SetPcbId.cs" />
|
||||
<Compile Include="Features\SetPowerLevel.cs" />
|
||||
<Compile Include="Features\SetRebootCount.cs" />
|
||||
<Compile Include="Features\SetSpecificError.cs" />
|
||||
<Compile Include="Features\SetTestFastActivityBupTiming.cs" />
|
||||
<Compile Include="Features\SetTFXParameters.cs" />
|
||||
<Compile Include="Features\SetVariablePcbId.cs" />
|
||||
<Compile Include="Features\SingleBytePam.cs" />
|
||||
<Compile Include="Features\WakeUpMode.cs" />
|
||||
<Compile Include="Features\WirelessMBusMode.cs" />
|
||||
<Compile Include="Attributes\ComparePropertyAttribute.cs" />
|
||||
<Compile Include="Models\EregisterDebugFeatures.cs" />
|
||||
<Compile Include="Models\EregisterFeatures.cs" />
|
||||
<Compile Include="Models\EregisterAvailableParametersParser.cs" />
|
||||
<Compile Include="Models\EregisterProgrammingParameters.cs" />
|
||||
<Compile Include="Models\EregisterProgrammingParametersList.cs" />
|
||||
<Compile Include="ParameterSet.cs" />
|
||||
<Compile Include="ProgrammingBatch.cs" />
|
||||
<Compile Include="ProgrammingTask.cs" />
|
||||
<Compile Include="JustTask.cs" />
|
||||
<Compile Include="TaskState.cs" />
|
||||
<Compile Include="Data\Epoch20000101.cs" />
|
||||
<Compile Include="Data\LAT.cs" />
|
||||
<Compile Include="Data\MeterUnits.cs" />
|
||||
<Compile Include="Data\Payload.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Data\SEMI.cs" />
|
||||
<Compile Include="Telegrams\AppCode.cs" />
|
||||
<Compile Include="Telegrams\BUP.cs" />
|
||||
<Compile Include="Telegrams\DEBUG.cs" />
|
||||
<Compile Include="Telegrams\DisplayUnits.cs" />
|
||||
<Compile Include="Telegrams\Epoch20000101.cs" />
|
||||
<Compile Include="Telegrams\LAT.cs" />
|
||||
<Compile Include="Telegrams\Payload.cs" />
|
||||
<Compile Include="Telegrams\SEMI.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\..\Utils\Common.Utils.Extensions\Common.Utils.Extensions.csproj">
|
||||
<Project>{05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3}</Project>
|
||||
<Name>Common.Utils.Extensions</Name>
|
||||
<ProjectReference Include="..\..\..\Common.Hardware.Ports\Common.Hardware.Ports.csproj">
|
||||
<Project>{9ae071c0-db12-4e09-a3c7-43f6dcd518d6}</Project>
|
||||
<Name>Common.Hardware.Ports</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Interfaces\Ports\Common.Hardware.Interfaces.Ports.SIRT\Common.Hardware.Interfaces.Ports.SIRT.csproj">
|
||||
<Project>{B23BFAF9-08AE-4311-8C08-FB2BB49EA2AD}</Project>
|
||||
<Name>Common.Hardware.Interfaces.Ports.SIRT</Name>
|
||||
<ProjectReference Include="..\..\..\Common.Hardware.SIRT\Common.Hardware.SIRT.csproj">
|
||||
<Project>{8de8e742-ee0a-4004-aa49-3d08d748e5ac}</Project>
|
||||
<Name>Common.Hardware.SIRT</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\Interfaces\Ports\Common.Hardware.Interfaces.Ports\Common.Hardware.Interfaces.Ports.csproj">
|
||||
<Project>{9AE071C0-DB12-4E09-A3C7-43F6DCD518D6}</Project>
|
||||
<Name>Common.Hardware.Interfaces.Ports</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Common.Hardware.WaterMeter.eRegister.Features\Common.Hardware.WaterMeter.eRegister.Features.csproj">
|
||||
<Project>{E19C1694-132E-477C-86CB-8E146D5F59B0}</Project>
|
||||
<Name>Common.Hardware.WaterMeter.eRegister.Features</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Data
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.Sirt.Responses;
|
||||
|
||||
using System;
|
||||
|
||||
public class ACKN
|
||||
{
|
||||
public ACKN(AcknOrAnswerResponse response)
|
||||
{
|
||||
this.BufFull = response.BufFull;
|
||||
this.OsBusy = response.OsBusy;
|
||||
this.WrongCRC = response.WrongCRC;
|
||||
this.CmdNotExecuted = response.CmdNotExecuted;
|
||||
this.CmdUnknown = response.CmdUnknown;
|
||||
this.NoEntry = response.NoEntry;
|
||||
this.ByteUnknown = response.ByteUnknown;
|
||||
this.WildCardAddr = response.WildCardAddr;
|
||||
this.LastCmd = response.LastCmd;
|
||||
this.IsValid = response.IsCrcValid;
|
||||
}
|
||||
|
||||
public Boolean BufFull { get; }
|
||||
|
||||
public Boolean OsBusy { get; }
|
||||
|
||||
public Boolean WrongCRC { get; }
|
||||
|
||||
public Boolean CmdNotExecuted { get; }
|
||||
|
||||
public Boolean CmdUnknown { get; }
|
||||
|
||||
public Boolean NoEntry { get; }
|
||||
|
||||
public Boolean ByteUnknown { get; }
|
||||
|
||||
public Boolean WildCardAddr { get; }
|
||||
|
||||
public String LastCmd { get; }
|
||||
|
||||
public Boolean IsValid { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Data
|
||||
{
|
||||
using Common.Hardware.WaterMeter.eRegister.Features;
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class BUP : Payload
|
||||
{
|
||||
public BUP(Byte[] payload) : base(payload)
|
||||
{
|
||||
var index = 6;
|
||||
|
||||
this.Reading = payload.ToUInt32BigEndian((index += 4) - 4);
|
||||
this.Alarm = new AlarmsMask(payload[index++]);
|
||||
this.Crc = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
}
|
||||
|
||||
public UInt32 Reading { get; }
|
||||
|
||||
public AlarmsMask Alarm { get; }
|
||||
|
||||
public UInt16 Crc { get; protected set; }
|
||||
}
|
||||
}
|
||||
-149
@@ -1,149 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Data
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public class DEBUG : BUP
|
||||
{
|
||||
public DEBUG(Byte[] payload) : base(payload)
|
||||
{
|
||||
var index = 6;
|
||||
|
||||
this.DebugType = payload[index++];
|
||||
this.MeterType = payload[index++];
|
||||
this.RadioFirmwareVersion = this.VersionString(payload[index++], payload[index++]);
|
||||
this.MetrologyFirmwareVersion = this.VersionString(payload[index++], payload[index++]);
|
||||
this.HardwareVersion = payload[index++].ToString();
|
||||
this.FactoryState = payload[index++];
|
||||
this.PCBID = payload.ToUInt32BigEndian((index += 4) - 4);
|
||||
this.BoardTemperature = payload[index++];
|
||||
this.BatteryVoltage = 2 + payload.ToUInt16BigEndian((index += 2) - 2) / 64D;
|
||||
this.WakeupInterval = payload[index++];
|
||||
this.PowerLevelSensusRF = payload[index++];
|
||||
this.PowerLevelFlexNet = payload[index++];
|
||||
this.FrequencyOffset = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.RebootCount = payload[index++];
|
||||
this.WatchdogCount = payload[index++];
|
||||
this.BatterySeconds = payload.ToUInt32BigEndian((index += 4) - 4);
|
||||
this.MeterSampleRate = payload[index++];
|
||||
this.HistoryScale = payload[index++];
|
||||
this.RegisterMode = payload[index++];
|
||||
this.HistorySize = payload[index++];
|
||||
this.FactoryCalibration = payload[index++] / 10F;
|
||||
this.MeterSize = payload[index++];
|
||||
this.VolumePerLedPulse = payload.ToUInt32BigEndian((index += 4) - 4);
|
||||
this.VolumePerPulse = payload.ToUInt32BigEndian((index += 4) - 4);
|
||||
this.OffsetFactor = payload.ToUInt32BigEndian((index += 4) - 4);
|
||||
this.OffsetTime = payload[index++];
|
||||
|
||||
if (payload.Length > index + 2)
|
||||
{
|
||||
this.Crc = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Crc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public Byte DebugType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 0x0A for Residential and 0x0C for C & I
|
||||
/// </summary>
|
||||
public Byte MeterType { get; }
|
||||
|
||||
public String RadioFirmwareVersion { get; }
|
||||
|
||||
public String FirmwareVersion { get; }
|
||||
|
||||
public String HardwareVersion { get; }
|
||||
|
||||
public String MetrologyFirmwareVersion { get; }
|
||||
|
||||
public Byte FactoryState { get; }
|
||||
|
||||
public UInt32 PCBID { get; }
|
||||
|
||||
public Byte BoardTemperature { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Min: 3.565
|
||||
/// </summary>
|
||||
public Double BatteryVoltage { get; }
|
||||
|
||||
public Byte WakeupInterval { get; }
|
||||
|
||||
public Byte PowerLevelSensusRF { get; }
|
||||
|
||||
public Byte PowerLevelFlexNet { get; }
|
||||
|
||||
public UInt32 FrequencyOffset { get; }
|
||||
|
||||
public Byte RebootCount { get; }
|
||||
|
||||
public Byte WatchdogCount { get; }
|
||||
|
||||
public UInt32 BatterySeconds { get; }
|
||||
|
||||
public Byte MeterSampleRate { get; }
|
||||
|
||||
public Byte HistoryScale { get; }
|
||||
|
||||
public Byte RegisterMode { get; }
|
||||
|
||||
public Byte HistorySize { get; }
|
||||
|
||||
public Single FactoryCalibration { get; }
|
||||
|
||||
public Byte MeterSize { get; }
|
||||
|
||||
public UInt32 VolumePerLedPulse { get; }
|
||||
|
||||
public UInt32 VolumePerPulse { get; }
|
||||
|
||||
public UInt32 OffsetFactor { get; }
|
||||
|
||||
public Byte OffsetTime { 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.GetBits().Reverse();
|
||||
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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Data
|
||||
{
|
||||
using System;
|
||||
|
||||
public class LAT : BUP
|
||||
{
|
||||
public LAT(Byte[] payload) : base(payload)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Data
|
||||
{
|
||||
public enum MeterUnits
|
||||
{
|
||||
NA = 0,
|
||||
m3 = 19,
|
||||
CF = 35,
|
||||
GAL = 24,
|
||||
IGAL = 144
|
||||
}
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Data
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
|
||||
public abstract class Payload
|
||||
{
|
||||
protected readonly String bytes;
|
||||
|
||||
protected Payload(Byte[] payload)
|
||||
{
|
||||
var index = 0;
|
||||
|
||||
this.AppCode = (AppCode)payload[index++];
|
||||
this.Counter = payload[index++];
|
||||
this.Address = payload.ToUInt32BigEndian((index += 4) - 4);
|
||||
this.bytes = BitConverter.ToString(payload);
|
||||
}
|
||||
|
||||
public AppCode AppCode { get; }
|
||||
|
||||
public Byte Counter { get; }
|
||||
|
||||
public UInt32 Address { get; }
|
||||
|
||||
public override String ToString() => this.bytes;
|
||||
|
||||
public static implicit operator String(Payload payload) => payload?.ToString();
|
||||
}
|
||||
}
|
||||
-185
@@ -1,185 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Data
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.Sirt;
|
||||
using Common.Hardware.Interfaces.Ports.Sirt.Parameters;
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
public class SEMI : BUP
|
||||
{
|
||||
public SEMI(Byte[] payload, UInt16 mhz) : base(payload)
|
||||
{
|
||||
var index = 11;
|
||||
|
||||
this.PAMStatus = new PAMStatus(payload[index++]);
|
||||
this.RSSI = CalculateRSSI(payload[index++], mhz);
|
||||
this.MeterType = payload[index++];
|
||||
this.TransmissionInterval = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.LATInterval = payload[index++];
|
||||
this.CurrentFlow = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.BackwardVolume = payload.ToUInt32BigEndian((index += 4) - 4);
|
||||
this.NumberOfDials = payload[index++];
|
||||
this.Units = (MeterUnits)payload[index++];
|
||||
this.MeterID = payload.ToUInt32BigEndian((index += 4) - 4);
|
||||
this.MBusStatus = payload[index++];
|
||||
this.MBusTransmissionInterval = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.AlarmActiveInformation = payload[index++];
|
||||
this.LeakageDetectionParameters = payload[index++];
|
||||
this.BrokenPipeDetectionParameters = payload[index++];
|
||||
this.BatteryRemaining = payload.ToUInt16BigEndian((index += 2) - 2) / (4D * 365);
|
||||
this.BatteryEndDetected = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.MaximumFlow = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.TimeOfMaximumFlow = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.LowBatteryDetected = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.LeakStart = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.LeakEnd = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.MagneticTamperStart = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.MagneticTamperEnd = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.ModuleRemoveStart = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.ModuleRemoveEnd = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.BackflowStart = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.BackflowEnd = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.BrokenPipeStart = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.BrokenPipeEnd = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.LogContent = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.LoggingInterval = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.FixedDateReadingContent = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.DayOfMonth = payload[index++];
|
||||
this.ActualDateTime = new Epoch20000101(payload.ToUInt32BigEndian((index += 4) - 4), DateTimeKind.Local);
|
||||
this.HistoricalErrorLimit = payload[index++];
|
||||
this.CustomerSpecificText = Encoding.ASCII.GetString(payload, (index += 9) - 9, 9);
|
||||
this.TimeOfFDRReset = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.TimeOfLogReset = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
this.MeterSize = payload[index++];
|
||||
|
||||
if (payload.Length > index + 2)
|
||||
{
|
||||
this.Crc = payload.ToUInt16BigEndian((index += 2) - 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Crc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public UInt32 ModuleAddress { get; }
|
||||
|
||||
public UInt32 DisplayVolume { get; }
|
||||
|
||||
public Byte Alarms { get; }
|
||||
|
||||
public PAMStatus PAMStatus { get; }
|
||||
|
||||
public String RSSI { get; }
|
||||
|
||||
public Byte MeterType { get; }
|
||||
|
||||
public UInt16 TransmissionInterval { get; }
|
||||
|
||||
public Byte LATInterval { get; }
|
||||
|
||||
public UInt16 CurrentFlow { get; }
|
||||
|
||||
public UInt32 BackwardVolume { get; }
|
||||
|
||||
public Byte NumberOfDials { get; }
|
||||
|
||||
public MeterUnits Units { get; }
|
||||
|
||||
public UInt32 MeterID { get; }
|
||||
|
||||
public Byte MBusStatus { get; }
|
||||
|
||||
public UInt16 MBusTransmissionInterval { get; }
|
||||
|
||||
public Byte AlarmActiveInformation { get; }
|
||||
|
||||
public Byte LeakageDetectionParameters { get; }
|
||||
|
||||
public Byte BrokenPipeDetectionParameters { get; }
|
||||
|
||||
public Double BatteryRemaining { get; }
|
||||
|
||||
public UInt16 BatteryEndDetected { get; }
|
||||
|
||||
public UInt16 MaximumFlow { get; }
|
||||
|
||||
public UInt16 TimeOfMaximumFlow { get; }
|
||||
|
||||
public UInt16 LowBatteryDetected { get; }
|
||||
|
||||
public UInt16 LeakStart { get; }
|
||||
|
||||
public UInt16 LeakEnd { get; }
|
||||
|
||||
public UInt16 MagneticTamperStart { get; }
|
||||
|
||||
public UInt16 MagneticTamperEnd { get; }
|
||||
|
||||
public UInt16 ModuleRemoveStart { get; }
|
||||
|
||||
public UInt16 ModuleRemoveEnd { get; }
|
||||
|
||||
public UInt16 BackflowStart { get; }
|
||||
|
||||
public UInt16 BackflowEnd { get; }
|
||||
|
||||
public UInt16 BrokenPipeStart { get; }
|
||||
|
||||
public UInt16 BrokenPipeEnd { get; }
|
||||
|
||||
public UInt16 LogContent { get; }
|
||||
|
||||
public UInt16 LoggingInterval { get; }
|
||||
|
||||
public UInt16 FixedDateReadingContent { get; }
|
||||
|
||||
public Byte DayOfMonth { get; }
|
||||
|
||||
public DateTime ActualDateTime { get; }
|
||||
|
||||
public Byte HistoricalErrorLimit { get; }
|
||||
|
||||
public String CustomerSpecificText { get; }
|
||||
|
||||
public UInt16 TimeOfFDRReset { get; }
|
||||
|
||||
public UInt16 TimeOfLogReset { get; }
|
||||
|
||||
public Byte MeterSize { get; }
|
||||
|
||||
public static String CalculateRSSI(Byte value, UInt16 mhz)
|
||||
{
|
||||
var dbm = 0D;
|
||||
var per = 0D;
|
||||
|
||||
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}%)";
|
||||
}
|
||||
}
|
||||
}
|
||||
+145
-58
@@ -1,85 +1,172 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.Sirt;
|
||||
using Common.Hardware.Interfaces.Ports.Sirt.Parameters;
|
||||
using Common.Hardware.SIRT;
|
||||
using Common.Hardware.SIRT.Parameters;
|
||||
using Common.Hardware.WaterMeter.eRegister.Models;
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
public class Eregister
|
||||
{
|
||||
private readonly String portName;
|
||||
private readonly SirtBroadcaster sirt433;
|
||||
private readonly SirtBroadcaster sirt868;
|
||||
private readonly EregisterProgrammingParameters programmingParameters;
|
||||
private readonly ICollection<EregisterProgrammingTask> programmingTasks
|
||||
= new List<EregisterProgrammingTask>();
|
||||
private readonly ConcurrentQueue<EregisterTask> runningTasks;
|
||||
private readonly EregisterProgrammingParameters parameters;
|
||||
private readonly Action<SIRTTask> enqueueTask;
|
||||
|
||||
public Eregister(EregisterProgrammingParameters programmingParameters, SirtBroadcaster sirt433, SirtBroadcaster sirt868, String portName)
|
||||
public Eregister(EregisterProgrammingParameters parameters, Action<SIRTTask> enqueueTask)
|
||||
{
|
||||
this.portName = portName;
|
||||
this.sirt433 = sirt433;
|
||||
this.sirt868 = sirt868;
|
||||
this.programmingParameters = programmingParameters;
|
||||
this.parameters = parameters;
|
||||
this.enqueueTask = enqueueTask;
|
||||
this.runningTasks = new ConcurrentQueue<EregisterTask>();
|
||||
}
|
||||
|
||||
public ICollection<EregisterProgrammingTask> ProgrammingTasks { get; }
|
||||
public uint Address => this.parameters?.RequestAddress ?? 4291189262;
|
||||
|
||||
public void LoadInspectionInitializationTasks()
|
||||
public void Clear()
|
||||
{
|
||||
while (this.runningTasks.TryDequeue(out var _))
|
||||
{
|
||||
// Just dequeue all tasks
|
||||
}
|
||||
}
|
||||
|
||||
internal IEnumerable<EregisterTask> LoadInspectionFinalizationTasks()
|
||||
{
|
||||
var features = parameters.LoadInspectionFinalizationFeatures();
|
||||
|
||||
this.LoadProgrammingParameters(features);
|
||||
|
||||
this.runningTasks.Enqueue(new EregisterCheckFinalizationTask(this.parameters, features.Frequency)
|
||||
{
|
||||
SlotNr = features.SlotNr,
|
||||
PoNr = features.PoNr,
|
||||
SerialNr = features.SerialNr,
|
||||
P1 = new P811
|
||||
{
|
||||
DelPamSemi = true,
|
||||
},
|
||||
RequestAddress = features.RequestAddress,
|
||||
ResponseAddress = features.ResponseAddress,
|
||||
EncryptionKey = features.EncryptionKey
|
||||
});
|
||||
|
||||
return this.runningTasks.AsEnumerable();
|
||||
}
|
||||
|
||||
internal IEnumerable<EregisterTask> LoadInspectionInitializationTasks()
|
||||
{
|
||||
var features = parameters.LoadInspectionInitializationFeatures();
|
||||
|
||||
this.LoadProgrammingParameters(features);
|
||||
|
||||
return this.runningTasks.AsEnumerable();
|
||||
}
|
||||
|
||||
internal void StartProgramming()
|
||||
{
|
||||
var manualResetEventSlim = new ManualResetEventSlim();
|
||||
|
||||
void CompletedOrCancelled(SIRTTask task)
|
||||
{
|
||||
task.Completed -= CompletedOrCancelled;
|
||||
task.Cancelled -= CompletedOrCancelled;
|
||||
|
||||
if (task is EregisterTask _task)
|
||||
{
|
||||
foreach (var etask in this.runningTasks)
|
||||
{
|
||||
if (etask.State != SIRTTaskState.Cancelled && etask.State != SIRTTaskState.Completed)
|
||||
{
|
||||
etask.Mode = _task.Mode;
|
||||
etask.IsEncrypted = _task.IsEncrypted;
|
||||
etask.RequestAddress = _task.RequestAddress;
|
||||
etask.ResponseAddress = _task.ResponseAddress;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
manualResetEventSlim.Set();
|
||||
}
|
||||
|
||||
while (this.runningTasks.TryPeek(out var task))
|
||||
{
|
||||
task.Completed += CompletedOrCancelled;
|
||||
task.Cancelled += CompletedOrCancelled;
|
||||
|
||||
this.enqueueTask(task);
|
||||
|
||||
manualResetEventSlim.Wait();
|
||||
manualResetEventSlim.Reset();
|
||||
|
||||
if (task.State == SIRTTaskState.Completed)
|
||||
{
|
||||
this.runningTasks.TryDequeue(out task);
|
||||
}
|
||||
else if (task.State == SIRTTaskState.Cancelled)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadProgrammingParameters(EregisterFeatures features)
|
||||
{
|
||||
this.Clear();
|
||||
|
||||
var p1 = new P811
|
||||
var frequency = this.parameters.Frequency;
|
||||
|
||||
// Determinates the radio address of the end point and the encryption status
|
||||
this.runningTasks.Enqueue(new EregisterTask(frequency)
|
||||
{
|
||||
DelPamSemi = true
|
||||
};
|
||||
SlotNr = features.SlotNr,
|
||||
PoNr = features.PoNr,
|
||||
SerialNr = features.SerialNr,
|
||||
P1 = new P811
|
||||
{
|
||||
DelPamSemi = true,
|
||||
WakeUpCmd = true,
|
||||
},
|
||||
RequestAddress = features.RequestAddress,
|
||||
ResponseAddress = features.ResponseAddress,
|
||||
EncryptionKey = features.EncryptionKey,
|
||||
Name = "Dummy PAM"
|
||||
});
|
||||
|
||||
foreach (var pam in this.programmingParameters.BuildInspectionPreparationPams())
|
||||
// Determinates the state of the endpoint
|
||||
this.runningTasks.Enqueue(new EregisterCheckInitializationTask(this.parameters, features.Frequency)
|
||||
{
|
||||
var addressString = $"{this.programmingParameters.TempAdresse}";
|
||||
var addressLength = addressString.Length;
|
||||
|
||||
if (addressLength > 10)
|
||||
SlotNr = features.SlotNr,
|
||||
PoNr = features.PoNr,
|
||||
SerialNr = features.SerialNr,
|
||||
P1 = new P811
|
||||
{
|
||||
addressString = addressString.Substring(addressLength - 10);
|
||||
}
|
||||
DelPamSemi = true,
|
||||
},
|
||||
RequestAddress = features.RequestAddress,
|
||||
ResponseAddress = features.ResponseAddress,
|
||||
EncryptionKey = features.EncryptionKey
|
||||
});
|
||||
|
||||
if (uint.TryParse(addressString, out var address))
|
||||
foreach (var pam in features.BuildPams())
|
||||
{
|
||||
this.runningTasks.Enqueue(new EregisterTask(frequency)
|
||||
{
|
||||
var task = new EregisterProgrammingTask
|
||||
SlotNr = features.SlotNr,
|
||||
PoNr = features.PoNr,
|
||||
SerialNr = features.SerialNr,
|
||||
Name = pam.Key,
|
||||
P1 = new P811
|
||||
{
|
||||
Address = address,
|
||||
Cmd = SirtMessage.W_PAM,
|
||||
P1 = p1,
|
||||
Name = pam.Key,
|
||||
Data = pam.Value,
|
||||
EncryptionKey = this.programmingParameters.EncryptionKey.ToByteArray()
|
||||
};
|
||||
|
||||
this.programmingTasks.Add(task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void Clear() => this.programmingTasks.Clear();
|
||||
|
||||
internal void RunProgrammingTasks()
|
||||
{
|
||||
if (this.programmingParameters.Frequency == 433)
|
||||
{
|
||||
foreach (var programmingTask in this.programmingTasks)
|
||||
{
|
||||
this.sirt433.Add(programmingTask);
|
||||
}
|
||||
}
|
||||
else if (this.programmingParameters.Frequency == 868)
|
||||
{
|
||||
foreach (var programmingTask in this.programmingTasks)
|
||||
{
|
||||
this.sirt868.Add(programmingTask);
|
||||
}
|
||||
DelPamSemi = true,
|
||||
},
|
||||
RequestAddress = features.RequestAddress,
|
||||
ResponseAddress = features.ResponseAddress,
|
||||
Data = pam.Value,
|
||||
EncryptionKey = features.EncryptionKey
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-118
@@ -1,118 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.Sirt;
|
||||
using Common.Hardware.WaterMeter.eRegister.Models;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class EregisterBatch
|
||||
{
|
||||
private readonly EregisterBatchSettings settings;
|
||||
private readonly SirtBroadcaster sirt433;
|
||||
private readonly SirtBroadcaster sirt868;
|
||||
private readonly ConcurrentQueue<Eregister> eregisters;
|
||||
|
||||
public EregisterBatch(EregisterBatchSettings settings)
|
||||
{
|
||||
this.settings = settings;
|
||||
|
||||
foreach (var portName in settings.PortNamesSirt)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(portName))
|
||||
{
|
||||
this.sirt433 = new SirtBroadcaster(this.settings.PortNameSirt433);
|
||||
this.sirt433.Exception += this.SirtException;
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(this.settings.PortNameSirt433))
|
||||
{
|
||||
this.sirt433 = new SirtBroadcaster(this.settings.PortNameSirt433);
|
||||
this.sirt433.Exception += this.SirtException;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(this.settings.PortNameSirt868))
|
||||
{
|
||||
this.sirt868 = new SirtBroadcaster(this.settings.PortNameSirt868);
|
||||
this.sirt433.Exception += this.SirtException;
|
||||
}
|
||||
|
||||
this.eregisters = new ConcurrentQueue<Eregister>();
|
||||
}
|
||||
|
||||
public void Add(EregisterProgrammingParameters programmingParameters)
|
||||
{
|
||||
// this.settings.PortNamesEregister.TryGetValue(programmingParameters.Slotno, out var portName);
|
||||
// this.eregisters.Enqueue(new Eregister(programmingParameters, this.sirt433, this.sirt868, portName));
|
||||
}
|
||||
|
||||
public void CancelExecution()
|
||||
{
|
||||
// TODO: cancel running tasks.
|
||||
|
||||
this.Clear();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
while (this.eregisters.Count > 0)
|
||||
{
|
||||
if (this.eregisters.TryDequeue(out var eregister))
|
||||
{
|
||||
eregister.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadInspectionInitializationTasks(EregisterProgrammingParametersList eprogrammingParameters)
|
||||
{
|
||||
foreach (var programmingParameters in eprogrammingParameters)
|
||||
{
|
||||
this.Add(programmingParameters);
|
||||
}
|
||||
|
||||
foreach (var eregister in this.eregisters)
|
||||
{
|
||||
eregister.LoadInspectionInitializationTasks();
|
||||
}
|
||||
}
|
||||
|
||||
public EregisterProgrammingTask[][] GetInspectionInitializationTasks()
|
||||
=> this.eregisters
|
||||
.Select(x => x.ProgrammingTasks.ToArray())
|
||||
.ToArray();
|
||||
|
||||
public void StartSirts()
|
||||
{
|
||||
this.sirt433.Start();
|
||||
this.sirt868.Start();
|
||||
}
|
||||
|
||||
public void StopSirts()
|
||||
{
|
||||
this.sirt433.Stop();
|
||||
this.sirt868.Stop();
|
||||
}
|
||||
|
||||
public void RunProgrammingTasks()
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var eregister in this.eregisters)
|
||||
{
|
||||
tasks.Add(Task.Run((Action)eregister.RunProgrammingTasks));
|
||||
}
|
||||
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
}
|
||||
|
||||
private void SirtException(Exception exception)
|
||||
{
|
||||
Console.WriteLine(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
using Common.Hardware.SIRT;
|
||||
using Common.Hardware.WaterMeter.eRegister.Attributes;
|
||||
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()
|
||||
.Append(new ProvidePin
|
||||
{
|
||||
AuthLevel = AuthLevel.III
|
||||
});
|
||||
}
|
||||
|
||||
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)}"
|
||||
.ToString()
|
||||
.Trim('\0')
|
||||
.Trim();
|
||||
var responseValue = $"{property.GetValue(responseParameters)}"
|
||||
.ToString()
|
||||
.Trim('\0')
|
||||
.Trim();
|
||||
|
||||
if (requestValue != responseValue)
|
||||
{
|
||||
errors += $"- {property.Name}: request value {requestValue} != response value {responseValue}{Environment.NewLine}";
|
||||
}
|
||||
}
|
||||
|
||||
var volumeDifference = Math.Abs((int)this.requestParameters.DisplayVolume - (int)responseParameters.DisplayVolume);
|
||||
|
||||
if (volumeDifference > 10)
|
||||
{
|
||||
errors += $"- {nameof(this.requestParameters.DisplayVolume)}: request value {this.requestParameters.DisplayVolume} != response value {responseParameters.DisplayVolume}{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,
|
||||
OffsetTime = this.DEBUG.OffsetTime,
|
||||
FactoryCalibration = (byte)(this.DEBUG.FactoryCalibration * 10),
|
||||
UnitsOfMessureSEMI = (byte)this.SEMI.Units,
|
||||
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,
|
||||
TransmissionIntervalFinal = (byte)this.SEMI.TransmissionInterval,
|
||||
LATWindowsFinal = this.SEMI.LATInterval,
|
||||
MBusStatus = this.SEMI.MBusStatus,
|
||||
Adresse = this.SEMI.Address,
|
||||
};
|
||||
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
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 = "Initial Check";
|
||||
|
||||
this.Data = new OpticalTelegram
|
||||
{
|
||||
Minutes = 0
|
||||
}
|
||||
.Append(new ProvidePin
|
||||
{
|
||||
AuthLevel = AuthLevel.III
|
||||
});
|
||||
}
|
||||
|
||||
protected override void EndProcessResponse(SIRTMessage response)
|
||||
{
|
||||
this.timeoutTimer.Stop();
|
||||
|
||||
if (this.State == this.pendingState)
|
||||
{
|
||||
this.State = SIRTTaskState.Running;
|
||||
this.Name = "Initial Check - ✓";
|
||||
|
||||
var message = new StringBuilder();
|
||||
message.AppendLine();
|
||||
message.AppendLine();
|
||||
|
||||
if (this.DEBUG != null && this.SEMI != null)
|
||||
{
|
||||
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.Name = "Initial Check ✘";
|
||||
|
||||
this.NotifyTimeouted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.State = this.pendingState;
|
||||
|
||||
this.timeoutTimer.Start();
|
||||
base.EndProcessResponse(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
+200
-393
@@ -1,5 +1,6 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.Ports;
|
||||
using Common.Hardware.WaterMeter.eRegister.Features;
|
||||
using Common.Hardware.WaterMeter.eRegister.Models;
|
||||
|
||||
@@ -10,258 +11,226 @@
|
||||
|
||||
public static class EregisterExtensions
|
||||
{
|
||||
public static IDictionary<String, Byte[]> BuildInspectionPreparationPams(this EregisterProgrammingParameters parameters)
|
||||
public static IEnumerable<KeyValuePair<string, byte[]>> BuildPams(this EregisterFeatures eregister)
|
||||
{
|
||||
var eprogramming = new EregisterFeatures
|
||||
var pamList = new SortedDictionary<bool, SortedDictionary<AuthLevel, ICollection<byte[]>>>();
|
||||
var pamAttribute = default(PamAttribute);
|
||||
var cmd = default(byte);
|
||||
var bytes = default(byte[]);
|
||||
var value = default(object);
|
||||
var singleCmd = default(bool);
|
||||
var authLevel = default(AuthLevel);
|
||||
|
||||
foreach (var eregisterProperty in typeof(EregisterFeatures).GetProperties())
|
||||
{
|
||||
ChangeWakeUp = new ChangeWakeUp(WakeUpMode.StayAwake),
|
||||
ChangeTransmissionInterval = new ChangeTransmissionInterval(parameters.Transmission_Interval_Before),
|
||||
ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows(parameters.Lat_Windows_Before),
|
||||
ChangeMeterReading = new ChangeMeterReading(parameters.Display_Volume_Before),
|
||||
WirelessMBusMode = new WirelessMBusMode(parameters.MBusStatus),
|
||||
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 = (MeterUnits)parameters.UnitsOfMessure,
|
||||
Vpp = parameters.VolumePerPulse,
|
||||
VppLED = parameters.VolumePerLedPulse
|
||||
},
|
||||
Debug = new EregisterFeaturesDebug
|
||||
{
|
||||
OpticalTelegram = new OpticalTelegram(parameters.LED_On_Minutes)
|
||||
}
|
||||
};
|
||||
pamAttribute = eregisterProperty.GetCustomAttribute<PamAttribute>();
|
||||
|
||||
return eprogramming
|
||||
.BuildPams()
|
||||
.ToDictionary(x => x.PamNames, x => x.ToArray());
|
||||
}
|
||||
|
||||
public static IEnumerable<EregisterPamModel> BuildPams(this EregisterFeatures eregister)
|
||||
{
|
||||
var pams = eregister
|
||||
.GetPams()
|
||||
.OrderBy(x => x.CommandBytes[0]);
|
||||
var cmds = new List<EregisterPamModel>();
|
||||
var pamsLevel0 = new List<EregisterPamModel>();
|
||||
var pamsLevel1 = new List<EregisterPamModel>();
|
||||
var pamsLevel2 = new List<EregisterPamModel>();
|
||||
var pamsLevel3 = new List<EregisterPamModel>();
|
||||
|
||||
var pin1 = new ProvidePin { AuthLevel = AuthLevel.I }.ToByteArray();
|
||||
var pin2 = new ProvidePin { AuthLevel = AuthLevel.II }.ToByteArray();
|
||||
var pin3 = new ProvidePin { AuthLevel = AuthLevel.III }.ToByteArray();
|
||||
|
||||
foreach (var pam in pams)
|
||||
{
|
||||
if (pam.IsSingleCmd)
|
||||
{
|
||||
if (pam.AuthLevel == AuthLevel.I)
|
||||
{
|
||||
pam.CommandBytes.AddRange(pin1);
|
||||
}
|
||||
else if (pam.AuthLevel == AuthLevel.II)
|
||||
{
|
||||
pam.CommandBytes.AddRange(pin2);
|
||||
}
|
||||
else if (pam.AuthLevel == AuthLevel.III)
|
||||
{
|
||||
pam.CommandBytes.AddRange(pin3);
|
||||
}
|
||||
|
||||
cmds.Add(pam);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pam.AuthLevel == AuthLevel.O)
|
||||
{
|
||||
pamsLevel0.Add(pam);
|
||||
}
|
||||
else if (pam.AuthLevel == AuthLevel.I)
|
||||
{
|
||||
pamsLevel1.Add(pam);
|
||||
}
|
||||
else if (pam.AuthLevel == AuthLevel.II)
|
||||
{
|
||||
pamsLevel2.Add(pam);
|
||||
}
|
||||
else if (pam.AuthLevel == AuthLevel.III)
|
||||
{
|
||||
pamsLevel3.Add(pam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pamsLevel3.Count > 0)
|
||||
{
|
||||
var pamLevel3 = new EregisterPamModel();
|
||||
|
||||
foreach (var pam in pamsLevel3)
|
||||
{
|
||||
pamLevel3.PamNames += $"{pam.PamNames}{Environment.NewLine}";
|
||||
pamLevel3.CommandBytes.AddRange(pam.CommandBytes);
|
||||
}
|
||||
|
||||
pamLevel3.PamNames = pamLevel3.PamNames?.Trim();
|
||||
pamLevel3.CommandBytes.AddRange(pin3);
|
||||
cmds.Insert(0, pamLevel3);
|
||||
}
|
||||
|
||||
if (pamsLevel2.Count > 0)
|
||||
{
|
||||
var pamLevel2 = new EregisterPamModel();
|
||||
|
||||
foreach (var pam in pamsLevel2)
|
||||
{
|
||||
pamLevel2.PamNames += $"{pam.PamNames}{Environment.NewLine}";
|
||||
pamLevel2.CommandBytes.AddRange(pam.CommandBytes);
|
||||
}
|
||||
|
||||
pamLevel2.PamNames = pamLevel2.PamNames?.Trim();
|
||||
pamLevel2.CommandBytes.AddRange(pin2);
|
||||
cmds.Insert(0, pamLevel2);
|
||||
}
|
||||
|
||||
if (pamsLevel1.Count > 0)
|
||||
{
|
||||
var pamLevel1 = new EregisterPamModel();
|
||||
|
||||
foreach (var pam in pamsLevel1)
|
||||
{
|
||||
pamLevel1.PamNames += $"{pam.PamNames}{Environment.NewLine}";
|
||||
pamLevel1.CommandBytes.AddRange(pam.CommandBytes);
|
||||
}
|
||||
|
||||
pamLevel1.PamNames = pamLevel1.PamNames?.Trim();
|
||||
pamLevel1.CommandBytes.AddRange(pin1);
|
||||
cmds.Insert(0, pamLevel1);
|
||||
}
|
||||
|
||||
if (pamsLevel0.Count > 0)
|
||||
{
|
||||
var pamLevel0 = new EregisterPamModel();
|
||||
|
||||
foreach (var pam in pamsLevel0)
|
||||
{
|
||||
pamLevel0.PamNames += $"{pam.PamNames}{Environment.NewLine}";
|
||||
pamLevel0.CommandBytes.AddRange(pam.CommandBytes);
|
||||
}
|
||||
|
||||
pamLevel0.PamNames = pamLevel0.PamNames?.Trim();
|
||||
cmds.Insert(0, pamLevel0);
|
||||
}
|
||||
|
||||
return cmds;
|
||||
}
|
||||
|
||||
public static IEnumerable<ProgrammingTask> BuildTasks(this IEnumerable<EregisterPamModel> pams, Action<ProgrammingTask> taskOptions)
|
||||
{
|
||||
foreach (var pam in pams)
|
||||
{
|
||||
var task = new ProgrammingTask();
|
||||
|
||||
taskOptions(task);
|
||||
|
||||
task.PamNames = pam.PamNames;
|
||||
task.Data = pam.CommandBytes.ToArray();
|
||||
}
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
public static IEnumerable<EregisterPamModel> GetPams(this EregisterFeatures eregister)
|
||||
{
|
||||
foreach (var eregisterProperty in typeof(EregisterFeatures).GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
var pamType = eregisterProperty.GetCustomAttribute<PamAttribute>();
|
||||
|
||||
if (pamType is null)
|
||||
if (pamAttribute is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyValue = eregisterProperty.GetValue(eregister);
|
||||
value = eregisterProperty.GetValue(eregister);
|
||||
|
||||
if (propertyValue is null)
|
||||
if (value is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (propertyValue is EregisterFeaturesDebug debug)
|
||||
|
||||
singleCmd = pamAttribute.IsSingleCmd;
|
||||
|
||||
if (!pamList.ContainsKey(singleCmd))
|
||||
{
|
||||
foreach (var pam in debug.GetPams().OrderByDescending(x => x.CommandBytes[2]))
|
||||
pamList[singleCmd] = new SortedDictionary<AuthLevel, ICollection<byte[]>>();
|
||||
}
|
||||
|
||||
authLevel = pamAttribute.AuthLevel;
|
||||
|
||||
if (!pamList[singleCmd].ContainsKey(authLevel))
|
||||
{
|
||||
pamList[singleCmd][authLevel] = new List<byte[]>();
|
||||
}
|
||||
|
||||
if (eregisterProperty.Name == nameof(eregister.Debug))
|
||||
{
|
||||
var debugValue = default(object);
|
||||
var debugBytes = new List<byte[]>();
|
||||
|
||||
foreach (var debugProperty in typeof(EregisterDebugFeatures).GetProperties())
|
||||
{
|
||||
yield return pam;
|
||||
debugValue = debugProperty.GetValue(value);
|
||||
|
||||
if (debugValue is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (debugValue is Pam pam)
|
||||
{
|
||||
bytes = pam.ToByteArray();
|
||||
debugBytes.Add(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var _bytes in debugBytes.OrderByDescending(x => x[2]))
|
||||
{
|
||||
pamList[singleCmd][authLevel].Add(_bytes);
|
||||
}
|
||||
}
|
||||
else if (propertyValue is Pam pam)
|
||||
else if (value is Pam pam)
|
||||
{
|
||||
var commandBytes = pam.ToByteArray().ToList();
|
||||
var pamNames = $"PAM {commandBytes[0]}: {eregisterProperty.Name}";
|
||||
yield return new EregisterPamModel
|
||||
{
|
||||
PamNames = pamNames,
|
||||
AuthLevel = pamType.AuthLevel,
|
||||
IsSingleCmd = pamType.IsSingleCmd,
|
||||
CommandBytes = commandBytes
|
||||
};
|
||||
bytes = pam.ToByteArray();
|
||||
cmd = bytes[0];
|
||||
|
||||
pamList[singleCmd][authLevel].Add(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
return pamList
|
||||
.SelectMany(isSingle => isSingle.Key == false
|
||||
// Multi pams
|
||||
? isSingle.Value
|
||||
.Select(auth => new
|
||||
{
|
||||
Name = $"{string.Join(", ", auth.Value.OrderBy(x => x[0]).Select(x => $"{x[0]}"))}",
|
||||
Cmd = auth.Value.OrderByDescending(x => x[0]).SelectMany(x => x).ToList(),
|
||||
AuthLvl = auth.Key.AuthBytes()
|
||||
})
|
||||
// Single pams
|
||||
: isSingle.Value
|
||||
.SelectMany(auth => auth.Value
|
||||
.OrderByDescending(x => x[0])
|
||||
.Select(x => new
|
||||
{
|
||||
Name = $"{x[0]}{(x[0] == 31 ? $"-{x[2]}" : "")}",
|
||||
Cmd = x.ToList(),
|
||||
AuthLvl = auth.Key.AuthBytes()
|
||||
})))
|
||||
.Select(x =>
|
||||
{
|
||||
x.Cmd.AddRange(x.AuthLvl);
|
||||
|
||||
return new KeyValuePair<string, byte[]>(x.Name, x.Cmd.ToArray());
|
||||
});
|
||||
}
|
||||
|
||||
public static IEnumerable<EregisterPamModel> GetPams(this EregisterFeaturesDebug debug)
|
||||
public static IEnumerable<KeyValuePair<string, byte[]>> BuildPamsFull(this EregisterFeatures eregister)
|
||||
{
|
||||
foreach (var eregisterProperty in typeof(EregisterFeaturesDebug).GetProperties(BindingFlags.Public | BindingFlags.Instance))
|
||||
var pamList = new List<KeyValuePair<string, byte[]>>();
|
||||
var debugList = new List<KeyValuePair<string, byte[]>>();
|
||||
var pamNames = new Dictionary<byte, string>();
|
||||
var pamAttribute = default(PamAttribute);
|
||||
var cmd = default(byte);
|
||||
var bytes = default(byte[]);
|
||||
var value = default(object);
|
||||
|
||||
foreach (var field in typeof(Pam).GetFields(BindingFlags.Public | BindingFlags.Static))
|
||||
{
|
||||
var pamType = eregisterProperty.GetCustomAttribute<PamAttribute>();
|
||||
value = field.GetValue(null);
|
||||
|
||||
if (pamType is null)
|
||||
if (value is byte cmdByte)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var propertyValue = eregisterProperty.GetValue(debug);
|
||||
|
||||
if (propertyValue is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else if (propertyValue is Pam pam)
|
||||
{
|
||||
var commandBytes = pam.ToByteArray().ToList();
|
||||
var pamNames = $"PAM {commandBytes[0]}: {eregisterProperty.Name}";
|
||||
|
||||
yield return new EregisterPamModel
|
||||
{
|
||||
PamNames = pamNames,
|
||||
AuthLevel = pamType.AuthLevel,
|
||||
IsSingleCmd = pamType.IsSingleCmd,
|
||||
CommandBytes = commandBytes
|
||||
};
|
||||
pamNames[cmdByte] = field.Name;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var eregisterProperty in typeof(EregisterFeatures).GetProperties())
|
||||
{
|
||||
pamAttribute = eregisterProperty.GetCustomAttribute<PamAttribute>();
|
||||
|
||||
if (pamAttribute is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
value = eregisterProperty.GetValue(eregister);
|
||||
|
||||
if (value is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (eregisterProperty.Name == nameof(eregister.Debug))
|
||||
{
|
||||
var debugValue = default(object);
|
||||
|
||||
foreach (var debugProperty in typeof(EregisterDebugFeatures).GetProperties())
|
||||
{
|
||||
debugValue = debugProperty.GetValue(value);
|
||||
|
||||
if (debugValue is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (debugValue is Pam pam)
|
||||
{
|
||||
pam.Append(new ProvidePin { AuthLevel = pamAttribute.AuthLevel });
|
||||
bytes = pam.ToByteArray();
|
||||
cmd = bytes[0];
|
||||
|
||||
if (pamNames.TryGetValue(cmd, out var name))
|
||||
{
|
||||
debugList.Add(new KeyValuePair<string, byte[]>($"{cmd} - {debugProperty.Name}", bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (value is Pam pam)
|
||||
{
|
||||
pam.Append(new ProvidePin { AuthLevel = pamAttribute.AuthLevel });
|
||||
bytes = pam.ToByteArray();
|
||||
cmd = bytes[0];
|
||||
|
||||
if (pamNames.TryGetValue(cmd, out var name))
|
||||
{
|
||||
pamList.Add(new KeyValuePair<string, byte[]>($"{cmd} - {eregisterProperty.Name}", bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sortedPams = pamList
|
||||
.OrderByDescending(x => x.Value[0])
|
||||
.ToList();
|
||||
var sortedDebugs = debugList
|
||||
.OrderByDescending(x => x.Value[2])
|
||||
.ToList();
|
||||
|
||||
sortedPams.AddRange(sortedDebugs);
|
||||
|
||||
return sortedPams;
|
||||
}
|
||||
|
||||
public static Byte[] DecryptResponse(this Byte[] encryptedData, Byte[] encryptionKey)
|
||||
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)
|
||||
{
|
||||
return encryptedData;
|
||||
}
|
||||
|
||||
var length = encryptedData.Length;
|
||||
var length = encryptedData?.Length ?? 0;
|
||||
|
||||
if (length < 13)
|
||||
if (length == 0)
|
||||
{
|
||||
return encryptedData;
|
||||
}
|
||||
|
||||
var decryptedData = new Byte[length];
|
||||
var hex = BitConverter.ToString(decryptedData);
|
||||
var decryptedData = new byte[length];
|
||||
|
||||
Array.Copy(encryptedData, 0, decryptedData, 0, length);
|
||||
|
||||
@@ -269,27 +238,20 @@
|
||||
|
||||
for (var x = 6; x < length; x++)
|
||||
{
|
||||
token += (Byte)(decryptedData[x - (token & 0x3) - 1] >> ((token >> 6) & 0x1));
|
||||
token += (byte)(decryptedData[x - (token & 0x3) - 1] >> ((token >> 6) & 0x1));
|
||||
|
||||
decryptedData[x] ^= encryptionKey[(token >> 2) & 0x0F];
|
||||
|
||||
if (token >= 0x80)
|
||||
{
|
||||
decryptedData[x] = (Byte)~decryptedData[x];
|
||||
decryptedData[x] = (byte)~decryptedData[x];
|
||||
}
|
||||
}
|
||||
|
||||
var crc = decryptedData.CalculateCRC(5, length - 2);
|
||||
|
||||
if (crc == 0 || crc == UInt16.MaxValue)
|
||||
{
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
return encryptedData;
|
||||
return decryptedData;
|
||||
}
|
||||
|
||||
public static Byte[] EncryptRequest(this Byte[] plainData, Byte[] encryptionKey, UInt32 address)
|
||||
public static byte[] EncryptRequest(this byte[] plainData, byte[] encryptionKey, uint address)
|
||||
{
|
||||
if (encryptionKey?.Length != 16 || address <= 0)
|
||||
{
|
||||
@@ -298,198 +260,43 @@
|
||||
|
||||
var dataLength = plainData.Length;
|
||||
var telegramLength = dataLength + 2;
|
||||
var encryptedData = new Byte[telegramLength];
|
||||
var encryptedData = new byte[telegramLength];
|
||||
|
||||
Array.Copy(plainData, 0, encryptedData, 0, dataLength);
|
||||
|
||||
var telegramForCRCLength = telegramLength + 4;
|
||||
var telegramForCRC = new Byte[telegramForCRCLength];
|
||||
var telegramForCRC = new byte[telegramForCRCLength];
|
||||
|
||||
telegramForCRC[0] = (Byte)(address >> 24);
|
||||
telegramForCRC[1] = (Byte)(address >> 16);
|
||||
telegramForCRC[2] = (Byte)(address >> 8);
|
||||
telegramForCRC[3] = (Byte)(address >> 0);
|
||||
telegramForCRC[0] = (byte)(address >> 24);
|
||||
telegramForCRC[1] = (byte)(address >> 16);
|
||||
telegramForCRC[2] = (byte)(address >> 8);
|
||||
telegramForCRC[3] = (byte)(address >> 0);
|
||||
|
||||
Array.Copy(encryptedData, 0, telegramForCRC, 4, telegramLength);
|
||||
|
||||
var telegramCRC = telegramForCRC.CalculateCRC(1, telegramForCRCLength - 2);
|
||||
encryptedData[telegramLength - 2] = (Byte)(telegramCRC >> 8);
|
||||
encryptedData[telegramLength - 1] = (Byte)(telegramCRC >> 0);
|
||||
var telegramCRC = telegramForCRC.CRCCCITT(1, telegramForCRCLength - 2);
|
||||
encryptedData[telegramLength - 2] = (byte)(telegramCRC >> 8);
|
||||
encryptedData[telegramLength - 1] = (byte)(telegramCRC >> 0);
|
||||
|
||||
var reference = address;
|
||||
var token = (Byte)0xFF;
|
||||
var token = (byte)0xFF;
|
||||
|
||||
for (var i = 0; i < telegramLength; i++)
|
||||
{
|
||||
token += (Byte)(((reference >> ((token & 0x3) << 3)) & 0xFF) >> ((token >> 6) & 1));
|
||||
token += (byte)(((reference >> ((token & 0x3) << 3)) & 0xFF) >> ((token >> 6) & 1));
|
||||
|
||||
reference = reference << 8;
|
||||
reference <<= 8;
|
||||
reference += encryptedData[i];
|
||||
|
||||
encryptedData[i] ^= encryptionKey[(token >> 2) & 0x0F];
|
||||
|
||||
if (token >= 0x80)
|
||||
{
|
||||
encryptedData[i] = (Byte)~encryptedData[i];
|
||||
encryptedData[i] = (byte)~encryptedData[i];
|
||||
}
|
||||
}
|
||||
|
||||
return encryptedData;
|
||||
}
|
||||
|
||||
private static UInt16 CalculateCRC(this Byte[] data, Int32 start, Int32 length)
|
||||
{
|
||||
var crc = (UInt16)0xFFFF;
|
||||
var dataLength = data?.Length ?? 0;
|
||||
|
||||
if (start + length > dataLength)
|
||||
{
|
||||
return crc;
|
||||
}
|
||||
|
||||
for (var b = start; b < length; b++)
|
||||
{
|
||||
var _byte = data[b];
|
||||
var token = (UInt16)((_byte << 8) & 0xFF00);
|
||||
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
if (0x8000 == ((crc ^ token) & 0x8000))
|
||||
{
|
||||
crc <<= 1;
|
||||
crc ^= 0x1021;
|
||||
}
|
||||
else
|
||||
{
|
||||
crc <<= 1;
|
||||
}
|
||||
|
||||
token <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Working encryption from previous task
|
||||
//private void DecryptResponse(SirtMessage response)
|
||||
//{
|
||||
// var data = response.Data;
|
||||
// var length = data.Length;
|
||||
|
||||
// if (length < 13)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// var bytes = new Byte[length];
|
||||
// var hex = BitConverter.ToString(bytes);
|
||||
|
||||
// Array.Copy(data, 0, bytes, 0, length);
|
||||
|
||||
// var token = bytes[1];
|
||||
|
||||
// for (var x = 6; x < length; x++)
|
||||
// {
|
||||
// token += (Byte)(bytes[x - (token & 0x3) - 1] >> ((token >> 6) & 0x1));
|
||||
|
||||
// bytes[x] ^= this.EncryptionKey[(token >> 2) & 0x0F];
|
||||
|
||||
// if (token >= 0x80)
|
||||
// {
|
||||
// bytes[x] = (Byte)~bytes[x];
|
||||
// }
|
||||
// }
|
||||
|
||||
// var crc = this.CalculateCRC(bytes, 5, length - 2);
|
||||
|
||||
// if (crc == 0 || crc == UInt16.MaxValue)
|
||||
// {
|
||||
// response.Data = bytes;
|
||||
// }
|
||||
//}
|
||||
|
||||
//private void EncryptRequest()
|
||||
//{
|
||||
// var data = this.Data;
|
||||
// var dataLength = data.Length;
|
||||
// var telegramLength = dataLength + 2;
|
||||
// var telegram = new Byte[telegramLength];
|
||||
|
||||
// Array.Copy(data, 0, telegram, 0, dataLength);
|
||||
|
||||
// var telegramForCRCLength = telegramLength + 4;
|
||||
// var telegramForCRC = new Byte[telegramForCRCLength];
|
||||
// var address = this.Address;
|
||||
|
||||
// telegramForCRC[0] = (Byte)(address >> 24);
|
||||
// telegramForCRC[1] = (Byte)(address >> 16);
|
||||
// telegramForCRC[2] = (Byte)(address >> 8);
|
||||
// telegramForCRC[3] = (Byte)(address >> 0);
|
||||
|
||||
// Array.Copy(telegram, 0, telegramForCRC, 4, telegramLength);
|
||||
|
||||
// var telegramCRC = this.CalculateCRC(telegramForCRC, 1, telegramForCRCLength - 2);
|
||||
|
||||
// telegram[telegramLength - 2] = (Byte)(telegramCRC >> 8);
|
||||
// telegram[telegramLength - 1] = (Byte)(telegramCRC >> 0);
|
||||
|
||||
// var reference = address;
|
||||
// var token = (Byte)0xFF;
|
||||
|
||||
// for (var i = 0; i < telegramLength; i++)
|
||||
// {
|
||||
// token += (Byte)(((reference >> ((token & 0x3) << 3)) & 0xFF) >> ((token >> 6) & 1));
|
||||
|
||||
// reference = reference << 8;
|
||||
// reference += telegram[i];
|
||||
|
||||
// telegram[i] ^= this.EncryptionKey[(token >> 2) & 0x0F];
|
||||
|
||||
// if (token >= 0x80)
|
||||
// {
|
||||
// telegram[i] = (Byte)~telegram[i];
|
||||
// }
|
||||
// }
|
||||
|
||||
// this.Data = telegram;
|
||||
//}
|
||||
|
||||
//private UInt16 CalculateCRC(Byte[] data, Int32 start, Int32 length)
|
||||
//{
|
||||
// var crc = (UInt16)0xFFFF;
|
||||
// var dataLength = data?.Length ?? 0;
|
||||
|
||||
// if (start + length > dataLength)
|
||||
// {
|
||||
// return crc;
|
||||
// }
|
||||
|
||||
// for (var b = start; b < length; b++)
|
||||
// {
|
||||
// var _byte = data[b];
|
||||
// var token = (UInt16)((_byte << 8) & 0xFF00);
|
||||
|
||||
// for (var i = 0; i < 8; i++)
|
||||
// {
|
||||
// if (0x8000 == ((crc ^ token) & 0x8000))
|
||||
// {
|
||||
// crc <<= 1;
|
||||
// crc ^= 0x1021;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// crc <<= 1;
|
||||
// }
|
||||
|
||||
// token <<= 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return crc;
|
||||
//}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.WaterMeter.eRegister.Models;
|
||||
using Common.Hardware.SIRT;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class EregisterFactory
|
||||
{
|
||||
private readonly SIRTFactory sirtFactory;
|
||||
private readonly ICollection<Eregister> eregisters;
|
||||
|
||||
public EregisterFactory(SIRTFactory broadcaster)
|
||||
{
|
||||
this.sirtFactory = broadcaster;
|
||||
this.eregisters = new List<Eregister>();
|
||||
}
|
||||
|
||||
public IEnumerable<IEnumerable<EregisterTask>> LoadInspectionFinalizationTasks(EregisterProgrammingParametersList parametersList)
|
||||
{
|
||||
this.eregisters.Clear();
|
||||
|
||||
foreach (var parameters in parametersList)
|
||||
{
|
||||
var eregister = new Eregister(parameters, this.sirtFactory.EnqueueTask);
|
||||
|
||||
this.sirtFactory.DequeueTasks(parameters.RequestAddress);
|
||||
this.sirtFactory.DequeueTasks(parameters.ResponseAddress);
|
||||
this.eregisters.Add(eregister);
|
||||
|
||||
yield return eregister.LoadInspectionFinalizationTasks();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IEnumerable<EregisterTask>> LoadInspectionInitializationTasks(EregisterProgrammingParametersList parametersList)
|
||||
{
|
||||
this.eregisters.Clear();
|
||||
|
||||
foreach (var parameters in parametersList)
|
||||
{
|
||||
var eregister = new Eregister(parameters, this.sirtFactory.EnqueueTask);
|
||||
|
||||
this.sirtFactory.DequeueTasks(parameters.RequestAddress);
|
||||
this.sirtFactory.DequeueTasks(parameters.ResponseAddress);
|
||||
this.eregisters.Add(eregister);
|
||||
|
||||
yield return eregister.LoadInspectionInitializationTasks();
|
||||
}
|
||||
}
|
||||
|
||||
public Task StartProgrammingAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var eregister in this.eregisters)
|
||||
{
|
||||
tasks.Add(Task.Run((Action)eregister.StartProgramming, cancellationToken));
|
||||
}
|
||||
|
||||
return Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
public void StopProgramming()
|
||||
{
|
||||
foreach (var eregister in this.eregisters)
|
||||
{
|
||||
this.sirtFactory.DequeueTasks(eregister.Address);
|
||||
|
||||
eregister.Clear();
|
||||
}
|
||||
|
||||
this.eregisters.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.Sirt;
|
||||
using Common.Hardware.WaterMeter.eRegister.Data;
|
||||
|
||||
using System;
|
||||
|
||||
public class EregisterProgrammingTask : SirtTask
|
||||
{
|
||||
public String Name { get; internal set; }
|
||||
|
||||
public String Label { get; private set; }
|
||||
|
||||
public String RSSI { get; private set; }
|
||||
|
||||
public Byte[] EncryptionKey { get; internal set; }
|
||||
|
||||
public override void ReceiveMessage(SirtMessage response, Int32 mhz)
|
||||
{
|
||||
response.Data = response.Data.DecryptResponse(this.EncryptionKey);
|
||||
var dataLength = response.Data.Length;
|
||||
|
||||
if (dataLength > 0)
|
||||
{
|
||||
var type = response.Data[0];
|
||||
|
||||
if (type == SirtMessage.SEMI)
|
||||
{
|
||||
this.Label = new SEMI(response.Data, (UInt16)mhz)
|
||||
.PAMStatus
|
||||
.ToString();
|
||||
}
|
||||
else if (type == SirtMessage.BUP)
|
||||
{
|
||||
this.Label = nameof(SirtMessage.BUP);
|
||||
}
|
||||
else if (type == SirtMessage.LAT)
|
||||
{
|
||||
this.Label = nameof(SirtMessage.LAT);
|
||||
}
|
||||
else if (type == SirtMessage.DEBUG)
|
||||
{
|
||||
this.Label = nameof(SirtMessage.DEBUG);
|
||||
}
|
||||
|
||||
this.RSSI = SEMI.CalculateRSSI(response.P2, (UInt16)mhz);
|
||||
}
|
||||
|
||||
base.ReceiveMessage(response, mhz);
|
||||
}
|
||||
|
||||
public override Byte[] ToByteArray()
|
||||
{
|
||||
this.Data = this.Data.EncryptRequest(this.EncryptionKey, this.Address);
|
||||
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister
|
||||
{
|
||||
using Common.Hardware.SIRT;
|
||||
using Common.Hardware.SIRT.Parameters;
|
||||
using Common.Hardware.WaterMeter.eRegister.Features;
|
||||
using Common.Hardware.WaterMeter.eRegister.Models;
|
||||
using Common.Hardware.WaterMeter.eRegister.Telegrams;
|
||||
|
||||
using System;
|
||||
using System.Timers;
|
||||
|
||||
public class EregisterTask : SIRTTask
|
||||
{
|
||||
private int countFailures;
|
||||
|
||||
public EregisterTask(int frequency, int timeout = 5_000)
|
||||
: base(frequency, timeout)
|
||||
{
|
||||
this.Cmd = SIRTMessage.W_PAM;
|
||||
this.RSSI = new RSSI(0, frequency);
|
||||
this.Label = nameof(SIRTTaskState.Pending);
|
||||
}
|
||||
|
||||
public event Action<EregisterTask> Changed;
|
||||
public event Action<object> Telegram;
|
||||
|
||||
public int SlotNr { get; internal set; }
|
||||
|
||||
public int PoNr { get; internal set; }
|
||||
|
||||
public int SerialNr { get; internal set; }
|
||||
|
||||
public string Name { get; internal 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; }
|
||||
|
||||
public DEBUG DEBUG { get; private set; }
|
||||
|
||||
public SEMI SEMI { get; protected set; }
|
||||
|
||||
public bool IsEncrypted { get; set; }
|
||||
|
||||
public byte[] EncryptionKey { get; set; }
|
||||
|
||||
public FactoryState Mode { get; set; }
|
||||
|
||||
public override byte[] ToByteArray()
|
||||
{
|
||||
var data = this.request.Data;
|
||||
|
||||
if (this.Mode == FactoryState.Shipment)
|
||||
{
|
||||
data = new EregisterAvailableParametersParser(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.State = SIRTTaskState.Pending;
|
||||
|
||||
this.NotifyTimeouted();
|
||||
}
|
||||
|
||||
protected override void ProcessResponse(SIRTMessage response)
|
||||
{
|
||||
if (this.State == SIRTTaskState.Cancelled)
|
||||
{
|
||||
this.Label = nameof(SIRTTaskState.Cancelled);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.Address != this.RequestAddress)
|
||||
{
|
||||
var requestAddress = this.RequestAddress;
|
||||
this.RequestAddress = this.ResponseAddress;
|
||||
this.ResponseAddress = requestAddress;
|
||||
}
|
||||
|
||||
if (response.Cmd == SIRTMessage.FROMAIR)
|
||||
{
|
||||
this.P11 = new P11(response.P1);
|
||||
this.RSSI = new RSSI(response.P2, (ushort)this.Frequency);
|
||||
|
||||
var data = response.Data;
|
||||
var length = data.Length;
|
||||
|
||||
// TODO: get is encrypted from the data crc BUP, DEBUG, SEMI
|
||||
|
||||
if (this.IsEncrypted)
|
||||
{
|
||||
data = data.DecryptResponse(this.EncryptionKey);
|
||||
}
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
var type = data[0];
|
||||
|
||||
if (type == SIRTMessage.BUP)
|
||||
{
|
||||
this.Label = nameof(SIRTMessage.BUP);
|
||||
this.BUP = new BUP(data, this.P11);
|
||||
this.IsEncrypted = this.BUP.Crc != 0;
|
||||
this.NotifyTelegram(this.BUP);
|
||||
}
|
||||
else if (type == SIRTMessage.LAT)
|
||||
{
|
||||
this.Label = nameof(SIRTMessage.LAT);
|
||||
this.LAT = new LAT(data, this.P11);
|
||||
this.IsEncrypted = this.LAT.Crc != 0;
|
||||
this.NotifyTelegram(this.LAT);
|
||||
}
|
||||
else if (type == SIRTMessage.DEBUG)
|
||||
{
|
||||
this.Label = nameof(SIRTMessage.DEBUG);
|
||||
this.DEBUG = new DEBUG(data, this.P11);
|
||||
this.IsEncrypted = this.DEBUG.Crc != 0;
|
||||
this.Mode = (FactoryState)(this.DEBUG.FactoryState - 1);
|
||||
this.NotifyTelegram(this.DEBUG);
|
||||
}
|
||||
else if (type == SIRTMessage.SEMI)
|
||||
{
|
||||
this.SEMI = new SEMI(data, this.Frequency, this.P11);
|
||||
this.IsEncrypted = this.SEMI.Crc != 0;
|
||||
this.Label = this.SEMI.PAMStatus.ToString();
|
||||
|
||||
if (this.request.Data.Length > 0 && this.request.Data[0] == Pam.GetDebug && this.DEBUG == null)
|
||||
{
|
||||
this.Label = "!DEBUG";
|
||||
}
|
||||
else if (this.SEMI.PAMStatus == PAMStatus.OK)
|
||||
{
|
||||
this.State = SIRTTaskState.Completed;
|
||||
this.EndProcessResponse(response);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.SEMI.PAMStatus == PAMStatus.EXPIREDAUTH)
|
||||
{
|
||||
this.State = SIRTTaskState.Cancelled;
|
||||
this.timeoutTimer.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.countFailures++;
|
||||
|
||||
if (countFailures > 3)
|
||||
{
|
||||
this.State = SIRTTaskState.Cancelled;
|
||||
this.EndProcessResponse(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Label = "NA";
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (response.Cmd == SIRTMessage.ACKNANSW)
|
||||
{
|
||||
this.P12 = new P12(response.P1);
|
||||
this.Label = "ACKN";
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Label = "NA";
|
||||
}
|
||||
|
||||
this.NotifyChanged();
|
||||
}
|
||||
|
||||
protected virtual void EndProcessResponse(SIRTMessage response)
|
||||
=> base.ProcessResponse(response);
|
||||
|
||||
protected void NotifyChanged() => this.Changed?.Invoke(this);
|
||||
|
||||
protected void NotifyTelegram(object value) => this.Telegram?.Invoke(value);
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,8 +1,6 @@
|
||||
namespace Common.Hardware.WaterMeter.eRegister.Features
|
||||
{
|
||||
using Common.Utils.Extensions;
|
||||
|
||||
using System;
|
||||
using Common.Hardware.Ports;
|
||||
|
||||
public class ActivateMetrologyTestMode : Pam
|
||||
{
|
||||
@@ -10,7 +8,7 @@
|
||||
{
|
||||
}
|
||||
|
||||
public UInt16 Mode
|
||||
public ushort Mode
|
||||
{
|
||||
get => this.bytes.ToUInt16BE(1);
|
||||
set => value.GetBytesBE().CopyTo(this.bytes, 1);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user