Sirt connection and message translation
This commit is contained in:
+2
-2
@@ -40,8 +40,8 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="SIRTMessage.cs" />
|
||||
<Compile Include="SIRTPort.cs" />
|
||||
<Compile Include="SirtFixed.cs" />
|
||||
<Compile Include="SirtPort.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
-159
@@ -1,159 +0,0 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SIRT
|
||||
{
|
||||
using System;
|
||||
|
||||
public class SIRTMessage
|
||||
{
|
||||
public const Int32 LengthI = 8;
|
||||
public const Int32 MinLength = 12;
|
||||
public const Int32 PC2SIRT = 0x55;
|
||||
public const Int32 SIRT2PC = 0xFF;
|
||||
public const Int32 STOP = 0x16;
|
||||
|
||||
private const Int32 StartI = 0;
|
||||
private const Int32 DirectionI = 1;
|
||||
private const Int32 P1I = 2;
|
||||
private const Int32 P2I = 3;
|
||||
private const Int32 AddressI = 4;
|
||||
private const Int32 AddressL = 4;
|
||||
private const Int32 DataI = 9;
|
||||
private const Int32 CRCI = -3;
|
||||
private const Int32 CRCL = 2;
|
||||
private const Int32 StopI = -1;
|
||||
|
||||
private readonly Byte[] bytes;
|
||||
|
||||
public SIRTMessage(Byte[] bytes)
|
||||
=> this.bytes = bytes;
|
||||
|
||||
public SIRTMessage()
|
||||
{
|
||||
this.bytes = new Byte[MinLength];
|
||||
this.bytes[StartI] = PC2SIRT;
|
||||
this.bytes[this.Length + StopI] = STOP;
|
||||
}
|
||||
|
||||
public Int32 Length
|
||||
{
|
||||
get => this.bytes.Length;
|
||||
}
|
||||
|
||||
public Byte Start
|
||||
{
|
||||
get => this.bytes[StartI];
|
||||
}
|
||||
|
||||
public Byte Direction
|
||||
{
|
||||
get => this.bytes[DirectionI];
|
||||
set => this.bytes[DirectionI] = value;
|
||||
}
|
||||
|
||||
public Byte P1
|
||||
{
|
||||
get => this.bytes[P1I];
|
||||
set => this.bytes[P1I] = value;
|
||||
}
|
||||
|
||||
public Byte P2
|
||||
{
|
||||
get => this.bytes[P2I];
|
||||
set => this.bytes[P2I] = value;
|
||||
}
|
||||
|
||||
public Byte[] Address
|
||||
{
|
||||
get => this.bytes.SubArray(AddressI, AddressL);
|
||||
set => this.bytes.SubArray(AddressI, value);
|
||||
}
|
||||
|
||||
public Byte DataLength
|
||||
{
|
||||
get => this.bytes[LengthI];
|
||||
}
|
||||
|
||||
public Byte[] Data
|
||||
{
|
||||
get => this.bytes.SubArray(DataI, this.DataLength);
|
||||
set
|
||||
{
|
||||
this.bytes[LengthI] = (Byte)value.Length;
|
||||
this.bytes.Insert(DataI, value);
|
||||
this.CalculateCRCCCITT();
|
||||
}
|
||||
}
|
||||
|
||||
public Byte[] CRC
|
||||
{
|
||||
get => this.bytes.SubArray(this.Length + CRCI, CRCL);
|
||||
set => this.bytes.SubArray(this.Length + CRCI, value);
|
||||
}
|
||||
|
||||
public byte Stop
|
||||
{
|
||||
get => this.bytes[this.Length + StopI];
|
||||
}
|
||||
|
||||
public override String ToString()
|
||||
=> BitConverter.ToString(this.bytes);
|
||||
|
||||
private void CalculateCRCCCITT()
|
||||
{
|
||||
UInt32 ccitt(UInt16 start, UInt16 length)
|
||||
{
|
||||
Byte zeichen, test;
|
||||
UInt16 crc_result;
|
||||
UInt16 ui_index;
|
||||
Byte h;
|
||||
|
||||
if (this.Length < start + length)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
crc_result = 0xFFFF;
|
||||
ui_index = start;
|
||||
|
||||
while (ui_index < length + start)
|
||||
{
|
||||
zeichen = this.bytes[ui_index];
|
||||
ui_index++;
|
||||
|
||||
for (h = 0; h < 8; h++)
|
||||
{
|
||||
test = 0;
|
||||
|
||||
if ((crc_result & 0x8000) != 0)
|
||||
{
|
||||
test = 0x80;
|
||||
}
|
||||
|
||||
crc_result <<= 1;
|
||||
|
||||
if (((zeichen & 0x80) ^ test) != 0)
|
||||
{
|
||||
crc_result ^= 0x1021;
|
||||
}
|
||||
|
||||
zeichen <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return crc_result;
|
||||
}
|
||||
|
||||
var crci = this.Length + CRCI;
|
||||
var crc = ccitt(1, (UInt16)crci);
|
||||
var crcBytes = BitConverter.GetBytes(crc);
|
||||
|
||||
this.bytes[crci + 0] = crcBytes[1];
|
||||
this.bytes[crci + 1] = crcBytes[0];
|
||||
}
|
||||
|
||||
public static implicit operator Byte[] (SIRTMessage message)
|
||||
=> message.bytes;
|
||||
|
||||
public static implicit operator SIRTMessage(Byte[] bytes)
|
||||
=> new SIRTMessage(bytes);
|
||||
}
|
||||
}
|
||||
+54
-85
@@ -5,20 +5,22 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class SIRTPort : SerialPort
|
||||
public class SirtPort : SerialPort
|
||||
{
|
||||
private readonly List<Byte> buffer;
|
||||
|
||||
public SIRTPort(String serialPortName) : base(new SerialPortSettings
|
||||
public SirtPort(String serialPortName)
|
||||
: base(new SerialPortSettings
|
||||
{
|
||||
BaudRate = SerialPortBaudRate.X115200,
|
||||
DataBits = SerialPortDataBits.X8,
|
||||
Parity = SerialPortParity.None,
|
||||
PortName = serialPortName,
|
||||
StopBits = SerialPortStopBits.One
|
||||
}) => this.buffer = new List<Byte>();
|
||||
})
|
||||
=> this.buffer = new List<Byte>();
|
||||
|
||||
public event Action<SIRTMessage> MessageReceived;
|
||||
public event Action<Byte[]> MessageReceived;
|
||||
|
||||
public override void Open()
|
||||
{
|
||||
@@ -35,103 +37,70 @@
|
||||
|
||||
this.Close();
|
||||
});
|
||||
|
||||
this.Write(new SIRTMessage()
|
||||
{
|
||||
Direction = 0x84,
|
||||
P2 = 0x04,
|
||||
Address = new Byte[] { 0x20, 0x00, 0x00, 0x00 },
|
||||
Data = new Byte[] { 0x00, 0x80, 0x80, 0x01 },
|
||||
});
|
||||
}
|
||||
|
||||
public void Write(SIRTMessage message)
|
||||
=> base.Write(message, 0, message.Length);
|
||||
public void Write(Byte[] bytes)
|
||||
=> base.Write(bytes, 0, bytes.Length);
|
||||
|
||||
private void StartParsing(object state)
|
||||
private void StartParsing(Object state)
|
||||
{
|
||||
var SIRTPort = state as SIRTPort;
|
||||
var port = state as SirtPort;
|
||||
|
||||
if (SIRTPort is null)
|
||||
if (port is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var buffer = new List<Byte>();
|
||||
var reading = true;
|
||||
var readingTask = Task.Factory
|
||||
.StartNew(this.StartReading, state, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default)
|
||||
.ContinueWith(task =>
|
||||
{
|
||||
if (task.Exception != null)
|
||||
{
|
||||
this.NotifyInfoMessage(task.Exception.ToString());
|
||||
}
|
||||
|
||||
reading = false;
|
||||
});
|
||||
var messageReceived = SIRTPort.MessageReceived;
|
||||
|
||||
while (reading)
|
||||
{
|
||||
var bufferLength = buffer.Count;
|
||||
|
||||
if (bufferLength < SIRTMessage.MinLength)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var start = buffer.IndexOf(SIRTMessage.SIRT2PC);
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
buffer.RemoveRange(0, bufferLength);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
var lengthIndex = start + SIRTMessage.LengthI;
|
||||
|
||||
if (lengthIndex >= bufferLength)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var length = buffer[lengthIndex];
|
||||
var dataLength = length + SIRTMessage.MinLength;
|
||||
|
||||
if (start + dataLength > bufferLength)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var data = new Byte[dataLength];
|
||||
|
||||
buffer.CopyTo(start, data, 0, dataLength);
|
||||
buffer.RemoveRange(0, start + dataLength);
|
||||
messageReceived?.Invoke(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void StartReading(object state)
|
||||
{
|
||||
var SIRTPort = state as SIRTPort;
|
||||
|
||||
if (SIRTPort is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var buffer = SIRTPort.buffer;
|
||||
|
||||
var buffer = port.buffer;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var bytes = SIRTPort.Read();
|
||||
var bytes = port.Read();
|
||||
|
||||
if (bytes.Length > 0)
|
||||
{
|
||||
buffer.AddRange(bytes);
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
var bufferLength = buffer.Count;
|
||||
|
||||
if (bufferLength < SirtFixed.MinLength)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var start = buffer.IndexOf(SirtFixed.Sirt2Pc);
|
||||
|
||||
if (start < 0)
|
||||
{
|
||||
buffer.RemoveRange(0, bufferLength);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
var lengthIndex = start + SirtFixed.LengthIndex;
|
||||
|
||||
if (lengthIndex >= bufferLength)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var length = buffer[lengthIndex];
|
||||
var dataLength = length + SirtFixed.MinLength;
|
||||
|
||||
if (start + dataLength > bufferLength)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var data = new Byte[dataLength];
|
||||
|
||||
buffer.CopyTo(start, data, 0, dataLength);
|
||||
buffer.RemoveRange(0, start + dataLength);
|
||||
port.MessageReceived?.Invoke(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Common.Hardware.Interfaces.Ports.SIRT
|
||||
{
|
||||
using System;
|
||||
|
||||
public static class SirtFixed
|
||||
{
|
||||
public const Byte AckOrAnswer = 0x12;
|
||||
public const Byte FromAir = 0x11;
|
||||
public const Int32 LengthIndex = 0x08;
|
||||
public const Int32 MinLength = 12;
|
||||
public const Byte Pc2Sirt = 0x55;
|
||||
public const Byte ReadPam = 0x82;
|
||||
public const Byte ReadReg = 0x87;
|
||||
public const Byte Sirt2Pc = 0xFF;
|
||||
public const Byte StopByte = 0x16;
|
||||
public const Byte WritePam = 0x81;
|
||||
public const Byte WriteReg = 0x84;
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -18,13 +18,20 @@
|
||||
return array;
|
||||
}
|
||||
|
||||
public static T[] Reverse<T>(this T[] array)
|
||||
{
|
||||
Array.Reverse(array);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public static T[] SubArray<T>(this T[] array, Int32 index, Int32 count)
|
||||
{
|
||||
var subArray = new T[count];
|
||||
|
||||
Buffer.BlockCopy(array, index, subArray, 0, count);
|
||||
|
||||
return array;
|
||||
return subArray;
|
||||
}
|
||||
|
||||
public static T[] SubArray<T>(this T[] array, Int32 index, T[] items)
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
<?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>{DE225BDD-7DCD-4F4F-9E3F-348589DFE93C}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Common.Hardware.Interfaces.Protocols.SIRT</RootNamespace>
|
||||
<AssemblyName>Common.Hardware.Interfaces.Protocols.SIRT</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>
|
||||
</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="CompilerServices.cs" />
|
||||
<Compile Include="Messages\Parameters\BluetoothOperating.cs" />
|
||||
<Compile Include="Messages\Parameters\ByteExtensions.cs" />
|
||||
<Compile Include="Messages\Parameters\OperatingModes.cs" />
|
||||
<Compile Include="Messages\Parameters\P11.cs" />
|
||||
<Compile Include="Messages\Parameters\P12.cs" />
|
||||
<Compile Include="Messages\Parameters\P811.cs" />
|
||||
<Compile Include="Messages\Parameters\PamTimeout.cs" />
|
||||
<Compile Include="Messages\Parameters\RFModuleOperating.cs" />
|
||||
<Compile Include="Messages\Parameters\SirtOperating.cs" />
|
||||
<Compile Include="Messages\Requests\ReadPamRequest.cs" />
|
||||
<Compile Include="Messages\Requests\ReadRegRequest.cs" />
|
||||
<Compile Include="Messages\Requests\SirtRequest.cs" />
|
||||
<Compile Include="Messages\Requests\WritePamRequest.cs" />
|
||||
<Compile Include="Messages\Requests\WriteRegRequest.cs" />
|
||||
<Compile Include="Messages\Responses\AckOrAnswerResponse.cs" />
|
||||
<Compile Include="Messages\Responses\FromAirResponse.cs" />
|
||||
<Compile Include="Messages\Responses\SirtResponse.cs" />
|
||||
<Compile Include="Messages\SirtMessage.cs" />
|
||||
<Compile Include="Messages\SirtMessageStructure.cs" />
|
||||
<Compile Include="Payloads\Ack.cs" />
|
||||
<Compile Include="Payloads\Answer.cs" />
|
||||
<Compile Include="Payloads\Bup.cs" />
|
||||
<Compile Include="Payloads\Semi.cs" />
|
||||
<Compile Include="SirtAddresses.cs" />
|
||||
<Compile Include="SirtTask.cs" />
|
||||
<Compile Include="SirtBroadcaster.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\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>
|
||||
<ProjectReference Include="..\..\Ports\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>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
namespace System.Runtime.CompilerServices
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
|
||||
public class CallerMemberNameAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
|
||||
public class CallerFilePathAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
|
||||
public class CallerLineNumberAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters
|
||||
{
|
||||
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.GetByte();
|
||||
|
||||
public static implicit operator BluetoothOperating(Byte _byte)
|
||||
=> new BluetoothOperating(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters
|
||||
{
|
||||
using System;
|
||||
|
||||
public static class ByteExtensions
|
||||
{
|
||||
public static Byte[] GetBits(this Byte @byte)
|
||||
{
|
||||
var bits = new Byte[8];
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
bits[i] = (Byte)((@byte >> i) & 1);
|
||||
}
|
||||
|
||||
return bits;
|
||||
}
|
||||
|
||||
public static Byte GetByte(this Byte[] bits)
|
||||
{
|
||||
var @byte = default(int);
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
@byte |= bits[i] << i;
|
||||
}
|
||||
|
||||
return (Byte)@byte;
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters
|
||||
{
|
||||
public enum OperatingModes
|
||||
{
|
||||
Off = 0,
|
||||
ReceiveF1TransmitSensusRFF3 = 1,
|
||||
ReceiveF2TransmitSensusRFF2 = 2,
|
||||
ReceiveWirelessMbusT1CMode = 3,
|
||||
ReceiveWirelessMbusS1Mode = 4,
|
||||
Receive = 5,
|
||||
TestMode = 8,
|
||||
Undefined = 15
|
||||
}
|
||||
}
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters
|
||||
{
|
||||
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.GetByte();
|
||||
|
||||
public static implicit operator P11(Byte _byte)
|
||||
=> new P11(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters
|
||||
{
|
||||
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.GetByte();
|
||||
|
||||
public static implicit operator P12(Byte _byte)
|
||||
=> new P12(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters
|
||||
{
|
||||
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.GetByte();
|
||||
|
||||
public static implicit operator P811(Byte _byte)
|
||||
=> new P811(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.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);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters
|
||||
{
|
||||
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.GetByte();
|
||||
}
|
||||
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.GetByte();
|
||||
|
||||
public static implicit operator RFModuleOperating(Byte _byte)
|
||||
=> new RFModuleOperating(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters
|
||||
{
|
||||
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.GetByte();
|
||||
|
||||
public static implicit operator SirtOperating(Byte _byte)
|
||||
=> new SirtOperating(_byte.GetBits());
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Requests
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.SIRT;
|
||||
|
||||
using System;
|
||||
|
||||
public class ReadPamRequest : SirtRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// <list>
|
||||
/// <item>
|
||||
/// <term>true</term>
|
||||
/// <description>shows content of PAM structure of this address</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>false</term>
|
||||
/// <description>show stored PAM for this address</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public Boolean PamStruct
|
||||
{
|
||||
get => this.message.P1 == 1;
|
||||
set => this.message.P1 = (Byte)(value ? 1 : 0);
|
||||
}
|
||||
|
||||
protected override Byte[] ToByteArray()
|
||||
{
|
||||
this.message.Start = SirtFixed.Pc2Sirt;
|
||||
this.message.Cmd = SirtFixed.ReadPam;
|
||||
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Requests
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.SIRT;
|
||||
|
||||
using System;
|
||||
|
||||
public class ReadRegRequest : SirtRequest
|
||||
{
|
||||
public Byte ReadLength
|
||||
{
|
||||
get => this.message.P2;
|
||||
set => this.message.P2 = value;
|
||||
}
|
||||
|
||||
protected override Byte[] ToByteArray()
|
||||
{
|
||||
this.message.Start = SirtFixed.Pc2Sirt;
|
||||
this.message.Cmd = SirtFixed.ReadReg;
|
||||
this.message.P2 = this.ReadLength;
|
||||
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Requests
|
||||
{
|
||||
using System;
|
||||
|
||||
public abstract class SirtRequest : SirtMessage
|
||||
{
|
||||
public static implicit operator Byte[](SirtRequest request)
|
||||
=> request.ToByteArray();
|
||||
}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Requests
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.SIRT;
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters;
|
||||
|
||||
using System;
|
||||
|
||||
public class WritePamRequest : SirtRequest
|
||||
{
|
||||
private readonly P811 parameter811 = default(Byte);
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P811.WakeUpModul"/>
|
||||
/// </summary>
|
||||
public Boolean WakeUpModul
|
||||
{
|
||||
get => this.parameter811.WakeUpModul;
|
||||
set => this.parameter811.WakeUpModul = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P811.WakeUpCmd"/>
|
||||
/// </summary>
|
||||
public Boolean WakeUpCmd
|
||||
{
|
||||
get => this.parameter811.WakeUpCmd;
|
||||
set => this.parameter811.WakeUpCmd = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P811.IgnoreTimeout"/>
|
||||
/// </summary>
|
||||
public Boolean IgnoreTimeout
|
||||
{
|
||||
get => this.parameter811.IgnoreTimeout;
|
||||
set => this.parameter811.IgnoreTimeout = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P811.DelPamSemi"/>
|
||||
/// </summary>
|
||||
public Boolean DelPamSemi
|
||||
{
|
||||
get => this.parameter811.DelPamSemi;
|
||||
set => this.parameter811.DelPamSemi = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P811.DelPamTx"/>
|
||||
/// </summary>
|
||||
public Boolean DelPamTx
|
||||
{
|
||||
get => this.parameter811.DelPamTx;
|
||||
set => this.parameter811.DelPamTx = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P811.DelPamAdr"/>
|
||||
/// </summary>
|
||||
public Boolean DelPamAdr
|
||||
{
|
||||
get => this.parameter811.DelPamAdr;
|
||||
set => this.parameter811.DelPamAdr = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P811.DelPamAll"/>
|
||||
/// </summary>
|
||||
public Boolean DelPamAll
|
||||
{
|
||||
get => this.parameter811.DelPamAll;
|
||||
set => this.parameter811.DelPamAll = value;
|
||||
}
|
||||
|
||||
protected override Byte[] ToByteArray()
|
||||
{
|
||||
this.message.Start = SirtFixed.Pc2Sirt;
|
||||
this.message.Cmd = SirtFixed.WritePam;
|
||||
this.message.P1 = this.parameter811;
|
||||
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Requests
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.SIRT;
|
||||
|
||||
using System;
|
||||
|
||||
public class WriteRegRequest : SirtRequest
|
||||
{
|
||||
public Byte ReadLength
|
||||
{
|
||||
get => this.message.P2;
|
||||
set => this.message.P2 = value;
|
||||
}
|
||||
|
||||
protected override Byte[] ToByteArray()
|
||||
{
|
||||
this.message.Start = SirtFixed.Pc2Sirt;
|
||||
this.message.Cmd = SirtFixed.WriteReg;
|
||||
this.message.P2 = this.message.Length;
|
||||
|
||||
return base.ToByteArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Responses
|
||||
{
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters;
|
||||
|
||||
using System;
|
||||
|
||||
public class AckOrAnswerResponse : SirtResponse
|
||||
{
|
||||
private readonly P12 parameterP12;
|
||||
|
||||
public AckOrAnswerResponse(Byte[] bytes) : base(bytes)
|
||||
=> this.parameterP12 = this.message.P1;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P12.BufFull"/>
|
||||
/// </summary>
|
||||
public Boolean BufFull => this.parameterP12.BufFull;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P12.OsBusy"/>
|
||||
/// </summary>
|
||||
public Boolean OsBusy => this.parameterP12.OsBusy;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P12.WrongCRC"/>
|
||||
/// </summary>
|
||||
public Boolean WrongCRC => this.parameterP12.WrongCRC;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P12.CmdNotExecuted"/>
|
||||
/// </summary>
|
||||
public Boolean CmdNotExecuted => this.parameterP12.CmdNotExecuted;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P12.CmdUnknown"/>
|
||||
/// </summary>
|
||||
public Boolean CmdUnknown => this.parameterP12.CmdUnknown;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P12.NoEntry"/>
|
||||
/// </summary>
|
||||
public Boolean NoEntry => this.parameterP12.NoEntry;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P12.ByteUnknown"/>
|
||||
/// </summary>
|
||||
public Boolean ByteUnknown => this.parameterP12.ByteUnknown;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P12.WildCardAddr"/>
|
||||
/// </summary>
|
||||
public Boolean WildCardAddr => this.parameterP12.WildCardAddr;
|
||||
|
||||
public Byte LastCmd => this.message.P2;
|
||||
}
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Responses
|
||||
{
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters;
|
||||
|
||||
using System;
|
||||
|
||||
public class FromAirResponse : SirtMessage
|
||||
{
|
||||
private readonly P11 parameterP11;
|
||||
|
||||
public FromAirResponse(Byte[] bytes, Int32 moduleMHz) : base(bytes)
|
||||
{
|
||||
this.parameterP11 = this.message.P1;
|
||||
this.ReceivePowerDbm = this.CalculateReceivePowerDbm(moduleMHz, this.message.P2);
|
||||
this.ReceivePowerPer = this.CalculateReceivePowerPer(moduleMHz, this.message.P2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P11.SrcChannel"/>
|
||||
/// </summary>
|
||||
public Boolean SrcChannel => this.parameterP11.SrcChannel;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P11.BothValid"/>
|
||||
/// </summary>
|
||||
public Boolean BothValid => this.parameterP11.BothValid;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P11.InvalidMod1"/>
|
||||
/// </summary>
|
||||
public Boolean InvalidMod1 => this.parameterP11.InvalidMod1;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P11.InvalidMod2"/>
|
||||
/// </summary>
|
||||
public Boolean InvalidMod2 => this.parameterP11.InvalidMod2;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P11.LenOverflow"/>
|
||||
/// </summary>
|
||||
public Boolean LenOverflow => this.parameterP11.LenOverflow;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P11.Attention"/>
|
||||
/// </summary>
|
||||
public Boolean Attention => this.parameterP11.Attention;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P11.ModeRF"/>
|
||||
/// </summary>
|
||||
public Boolean ModeRF => this.parameterP11.ModeRF;
|
||||
|
||||
/// <summary>
|
||||
/// <inheritdoc cref="P11.ModeSensus"/>
|
||||
/// </summary>
|
||||
public Boolean ModeSensus => this.parameterP11.ModeSensus;
|
||||
|
||||
public Double ReceivePowerDbm { get; }
|
||||
|
||||
public Double ReceivePowerPer { get; }
|
||||
|
||||
private Double CalculateReceivePowerDbm(int moduleMHz, Byte rssi)
|
||||
{
|
||||
var value = default(Double);
|
||||
|
||||
if (moduleMHz == 433)
|
||||
{
|
||||
value = rssi * 0.5 - 140;
|
||||
}
|
||||
else if (moduleMHz == 868)
|
||||
{
|
||||
value = rssi * 0.5 - 131.3;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private Double CalculateReceivePowerPer(int moduleMHz, Byte rssi)
|
||||
{
|
||||
var value = default(Double);
|
||||
|
||||
if (moduleMHz == 433)
|
||||
{
|
||||
value = -57.6667 + 0.7333 * rssi;
|
||||
}
|
||||
else if (moduleMHz == 868)
|
||||
{
|
||||
value = -40.316 + 0.66 * rssi;
|
||||
}
|
||||
|
||||
if (value > 100)
|
||||
{
|
||||
value = 100;
|
||||
}
|
||||
else if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Responses
|
||||
{
|
||||
using System;
|
||||
|
||||
public abstract class SirtResponse : SirtMessage
|
||||
{
|
||||
protected SirtResponse(Byte[] bytes) : base(bytes)
|
||||
=> this.MatchCRC = this.CheckWhetherTelegramMatchCheckSum();
|
||||
|
||||
public Boolean MatchCRC { get; }
|
||||
|
||||
private Boolean CheckWhetherTelegramMatchCheckSum()
|
||||
{
|
||||
var existingCRC = this.message.CRC;
|
||||
var calculatedCRC = this.message.CalculateCRC();
|
||||
|
||||
return existingCRC[0] == calculatedCRC[1]
|
||||
&& existingCRC[1] == calculatedCRC[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages
|
||||
{
|
||||
using System;
|
||||
|
||||
public class SirtMessage
|
||||
{
|
||||
protected readonly SirtMessageStructure message = new SirtMessageStructure();
|
||||
|
||||
public SirtMessage()
|
||||
{
|
||||
}
|
||||
|
||||
public SirtMessage(Byte[] bytes) => this.message = bytes;
|
||||
|
||||
public Int32 Length => this.message.BytesCount;
|
||||
|
||||
public Byte Cmd => this.message.Cmd;
|
||||
|
||||
public UInt32 Address
|
||||
{
|
||||
get
|
||||
{
|
||||
var address = this.message.Address;
|
||||
|
||||
Array.Reverse(address);
|
||||
|
||||
return BitConverter.ToUInt32(address, 0);
|
||||
}
|
||||
set
|
||||
{
|
||||
var address = BitConverter.GetBytes(value);
|
||||
|
||||
Array.Reverse(address);
|
||||
|
||||
this.message.Address = address;
|
||||
}
|
||||
}
|
||||
|
||||
public Byte[] Payload
|
||||
{
|
||||
get => this.message.Payload;
|
||||
set => this.message.Payload = value;
|
||||
}
|
||||
|
||||
protected virtual Byte[] ToByteArray()
|
||||
=> this.message;
|
||||
|
||||
public static implicit operator Byte[] (SirtMessage message)
|
||||
=> message.ToByteArray();
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.SIRT;
|
||||
|
||||
using System;
|
||||
|
||||
public class SirtMessageStructure
|
||||
{
|
||||
private Byte[] bytes;
|
||||
|
||||
public SirtMessageStructure() => this.bytes = new Byte[SirtFixed.MinLength];
|
||||
|
||||
private SirtMessageStructure(Byte[] bytes) => this.bytes = bytes;
|
||||
|
||||
public Int32 BytesCount => this.bytes.Length;
|
||||
|
||||
public Byte Start
|
||||
{
|
||||
get => this.bytes[0];
|
||||
set => this.bytes[0] = value;
|
||||
}
|
||||
|
||||
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 Byte[] Address
|
||||
{
|
||||
get
|
||||
{
|
||||
var address = new Byte[4];
|
||||
|
||||
Array.Copy(this.bytes, 4, address, 0, 4);
|
||||
|
||||
return address;
|
||||
}
|
||||
set => Array.Copy(value, 0, this.bytes, 4, 4);
|
||||
}
|
||||
|
||||
public Byte Length
|
||||
{
|
||||
get => this.bytes[8];
|
||||
set => this.bytes[8] = value;
|
||||
}
|
||||
|
||||
public Byte[] Payload
|
||||
{
|
||||
get
|
||||
{
|
||||
var payload = new Byte[this.Length];
|
||||
|
||||
Array.Copy(this.bytes, 9, payload, 0, this.Length);
|
||||
|
||||
return payload;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is null)
|
||||
{
|
||||
value = new Byte[0];
|
||||
}
|
||||
|
||||
this.Length = (Byte)value.Length;
|
||||
var newLength = SirtFixed.MinLength + this.Length;
|
||||
|
||||
Array.Resize(ref this.bytes, newLength);
|
||||
Array.Copy(value, 0, this.bytes, 9, this.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public Byte[] CRC
|
||||
{
|
||||
get
|
||||
{
|
||||
var crc = new Byte[2];
|
||||
|
||||
Array.Copy(this.bytes, this.bytes.Length - 3, crc, 0, 2);
|
||||
|
||||
return crc;
|
||||
}
|
||||
set => Array.Copy(value, 0, this.bytes, this.bytes.Length - 3, 2);
|
||||
}
|
||||
|
||||
public Byte Stop => this.bytes[this.bytes.Length - 1];
|
||||
|
||||
public Byte[] CalculateCRC()
|
||||
{
|
||||
var crcSum = default(UInt16);
|
||||
var length = this.bytes.Length - 3;
|
||||
|
||||
crcSum = 0xFFFF;
|
||||
|
||||
for (int index = 1; index < length; index++)
|
||||
{
|
||||
var @byte = bytes[index];
|
||||
|
||||
for (int bit = 0; bit < 8; bit++)
|
||||
{
|
||||
var test = default(Byte);
|
||||
|
||||
if ((crcSum & 0x8000) != 0)
|
||||
{
|
||||
test = 0x80;
|
||||
}
|
||||
|
||||
crcSum <<= 1;
|
||||
|
||||
if (((@byte & 0x80) ^ test) != 0)
|
||||
{
|
||||
crcSum ^= 0x1021;
|
||||
}
|
||||
|
||||
@byte <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
return BitConverter.GetBytes(crcSum);
|
||||
}
|
||||
|
||||
private Byte[] ToByteArray()
|
||||
{
|
||||
var crc = this.CalculateCRC();
|
||||
var length = this.bytes.Length;
|
||||
|
||||
this.bytes[length - 3] = crc[1];
|
||||
this.bytes[length - 2] = crc[0];
|
||||
this.bytes[length - 1] = SirtFixed.StopByte;
|
||||
|
||||
return this.bytes;
|
||||
}
|
||||
|
||||
public static implicit operator SirtMessageStructure(Byte[] bytes)
|
||||
=> new SirtMessageStructure(bytes);
|
||||
|
||||
public static implicit operator Byte[](SirtMessageStructure message)
|
||||
=> message.ToByteArray();
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Payloads
|
||||
{
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Responses;
|
||||
|
||||
internal class Ack
|
||||
{
|
||||
private readonly AckOrAnswerResponse response;
|
||||
|
||||
public Ack(AckOrAnswerResponse response)
|
||||
=> this.response = response;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Payloads
|
||||
{
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Responses;
|
||||
|
||||
internal class Answer
|
||||
{
|
||||
private readonly AckOrAnswerResponse response;
|
||||
|
||||
public Answer(AckOrAnswerResponse response)
|
||||
=> this.response = response;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Payloads
|
||||
{
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Responses;
|
||||
|
||||
public class Bup
|
||||
{
|
||||
private readonly FromAirResponse response;
|
||||
|
||||
public Bup(FromAirResponse response)
|
||||
=> this.response = response;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT.Payloads
|
||||
{
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Responses;
|
||||
|
||||
public class Semi
|
||||
{
|
||||
private readonly FromAirResponse response;
|
||||
|
||||
public Semi(FromAirResponse response)
|
||||
=> this.response = response;
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
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.Protocols.SIRT")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Common.Hardware.Interfaces.Protocols.SIRT")]
|
||||
[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("de225bdd-7dcd-4f4f-9e3f-348589dfe93c")]
|
||||
|
||||
// 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")]
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT
|
||||
{
|
||||
using System;
|
||||
|
||||
public class SirtAddresses
|
||||
{
|
||||
public const UInt32 Wildcard = 0xFFFFFFFF;
|
||||
public const UInt32 IdNumberA = 0x11001820;
|
||||
public const UInt32 SirtOperating = 0x20000000;
|
||||
}
|
||||
}
|
||||
+160
@@ -0,0 +1,160 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT
|
||||
{
|
||||
using Common.Hardware.Interfaces.Ports.SIRT;
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages;
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters;
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Requests;
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages.Responses;
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Payloads;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
public class SirtBroadcaster
|
||||
{
|
||||
private readonly SirtPort sirtPort;
|
||||
private readonly ConcurrentDictionary<UInt32, Bup> availableAddresses;
|
||||
private readonly ConcurrentDictionary<UInt32, ConcurrentQueue<SirtTask>> sirtTasks;
|
||||
|
||||
public SirtBroadcaster(string comport)
|
||||
{
|
||||
this.sirtPort = new SirtPort(comport);
|
||||
this.sirtPort.Logging += Console.WriteLine;
|
||||
this.sirtPort.MessageReceived += this.MessageReceived;
|
||||
this.availableAddresses = new ConcurrentDictionary<UInt32, Bup>();
|
||||
this.sirtTasks = new ConcurrentDictionary<UInt32, ConcurrentQueue<SirtTask>>();
|
||||
}
|
||||
|
||||
public void Connect()
|
||||
{
|
||||
this.sirtPort.Open();
|
||||
this.sirtPort.Write(new WriteRegRequest
|
||||
{
|
||||
Address = SirtAddresses.SirtOperating,
|
||||
Payload = new Byte[]
|
||||
{
|
||||
new SirtOperating
|
||||
{
|
||||
// standard
|
||||
},
|
||||
new BluetoothOperating
|
||||
{
|
||||
BtOff = true,
|
||||
},
|
||||
new RFModuleOperating
|
||||
{
|
||||
RfOff = true
|
||||
},
|
||||
new RFModuleOperating
|
||||
{
|
||||
OpMode = OperatingModes.ReceiveF1TransmitSensusRFF3
|
||||
},
|
||||
new PamTimeout
|
||||
{
|
||||
Minutes = 1,
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
this.sirtPort.Close();
|
||||
}
|
||||
|
||||
public SirtTask ReadPam(Action<ReadPamRequest> requestBuilder)
|
||||
{
|
||||
var request = new ReadPamRequest();
|
||||
|
||||
requestBuilder(request);
|
||||
|
||||
return this.SirtTask(request);
|
||||
}
|
||||
|
||||
public SirtTask ReadReg(Action<ReadRegRequest> requestBuilder)
|
||||
{
|
||||
var request = new ReadRegRequest();
|
||||
|
||||
requestBuilder(request);
|
||||
|
||||
return this.SirtTask(request);
|
||||
}
|
||||
|
||||
public SirtTask WritePam(Action<WritePamRequest> requestBuilder)
|
||||
{
|
||||
var request = new WritePamRequest();
|
||||
|
||||
requestBuilder(request);
|
||||
|
||||
return this.SirtTask(request);
|
||||
}
|
||||
|
||||
public SirtTask WriteReg(Action<WriteRegRequest> requestBuilder)
|
||||
{
|
||||
var request = new WriteRegRequest();
|
||||
|
||||
requestBuilder(request);
|
||||
|
||||
return this.SirtTask(request);
|
||||
}
|
||||
|
||||
private SirtTask SirtTask(SirtRequest request)
|
||||
{
|
||||
var task = new SirtTask(request);
|
||||
|
||||
this.sirtTasks
|
||||
.GetOrAdd(task, new ConcurrentQueue<SirtTask>())
|
||||
.Enqueue(task);
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
private void MessageReceived(Byte[] bytes)
|
||||
{
|
||||
var message = new SirtMessage(bytes);
|
||||
var address = message.Address;
|
||||
var cmd = message.Cmd;
|
||||
var payloadLength = message.Payload.Length;
|
||||
var task = default(SirtTask);
|
||||
_ = this.sirtTasks.TryGetValue(address, out var queue)
|
||||
&& queue.TryPeek(out task);
|
||||
|
||||
if (cmd == SirtFixed.FromAir)
|
||||
{
|
||||
var response = new FromAirResponse(message, 433);
|
||||
|
||||
if (payloadLength == 13)
|
||||
{
|
||||
var bup = new Bup(response);
|
||||
|
||||
task?.Add(bup);
|
||||
|
||||
this.availableAddresses.AddOrUpdate(address, bup, (_1, _2) => bup);
|
||||
}
|
||||
else if (payloadLength == 87)
|
||||
{
|
||||
var semi = new Semi(response);
|
||||
|
||||
task?.Add(semi);
|
||||
}
|
||||
}
|
||||
else if (cmd == SirtFixed.AckOrAnswer)
|
||||
{
|
||||
var response = new AckOrAnswerResponse(message);
|
||||
|
||||
if (payloadLength == 0)
|
||||
{
|
||||
var ack = new Ack(response);
|
||||
|
||||
task?.Add(ack);
|
||||
}
|
||||
else
|
||||
{
|
||||
var answer = new Answer(response);
|
||||
|
||||
task?.Add(answer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
namespace Common.Hardware.Interfaces.Protocols.SIRT
|
||||
{
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Messages;
|
||||
using Common.Hardware.Interfaces.Protocols.SIRT.Payloads;
|
||||
|
||||
using System;
|
||||
|
||||
public class SirtTask
|
||||
{
|
||||
private static UInt64 taskNr;
|
||||
|
||||
private readonly SirtMessage request;
|
||||
|
||||
public SirtTask(SirtMessage request)
|
||||
{
|
||||
this.request = request;
|
||||
this.Nr = ++taskNr;
|
||||
}
|
||||
|
||||
public event Action<SirtTask> Done;
|
||||
|
||||
public UInt64 Nr { get; }
|
||||
|
||||
public UInt32 Address => this.request.Address;
|
||||
|
||||
public Boolean IsRunning { get; private set; }
|
||||
|
||||
public override Boolean Equals(object other)
|
||||
=> other is SirtTask task
|
||||
&& task.Address == this.Address;
|
||||
|
||||
public override Int32 GetHashCode()
|
||||
=> (int)this.Address;
|
||||
|
||||
public override string ToString()
|
||||
=> this.Address.ToString();
|
||||
|
||||
internal void Add(Bup bup)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal void Add(Semi semi)
|
||||
{
|
||||
this.IsRunning = false;
|
||||
|
||||
this.Done?.Invoke(this);
|
||||
}
|
||||
|
||||
internal void Add(Ack ack)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal void Add(Answer answer)
|
||||
{
|
||||
this.IsRunning = false;
|
||||
|
||||
this.Done?.Invoke(this);
|
||||
}
|
||||
|
||||
public static implicit operator SirtMessage(SirtTask task)
|
||||
{
|
||||
task.IsRunning = true;
|
||||
|
||||
return task.request;
|
||||
}
|
||||
|
||||
public static implicit operator uint(SirtTask task)
|
||||
=> task.Address;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user