refactoring - builds ok

This commit is contained in:
Stoyan Zlatev
2024-10-14 15:02:21 +02:00
parent 4c230b97cf
commit 4cc1be9326
114 changed files with 1730 additions and 1708 deletions
-67
View File
@@ -239,8 +239,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "api_doc", "api_doc", "{E608
Hardware\WaterMeter\MagFlux\MagFluxApi\api_doc\SensorInfo.cs = Hardware\WaterMeter\MagFlux\MagFluxApi\api_doc\SensorInfo.cs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common.Hardware.Interfaces.Ports.SirtBroadcaster", "Hardware\Interfaces\Ports\Common.Hardware.Interfaces.Ports.SirtBroadcaster\Common.Hardware.Interfaces.Ports.SirtBroadcaster.csproj", "{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
Utils\DateTimeServerShared\DateTimeServerShared.projitems*{4806d89a-fbfb-41bc-aaa7-2242444bf55a}*SharedItemsImports = 4
@@ -5459,70 +5457,6 @@ Global
{F7316525-FF8E-4651-BA67-3C9B948D1E91}.XP32bit|x64.Build.0 = Release|Any CPU
{F7316525-FF8E-4651-BA67-3C9B948D1E91}.XP32bit|x86.ActiveCfg = Release|Any CPU
{F7316525-FF8E-4651-BA67-3C9B948D1E91}.XP32bit|x86.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}._MANUAL_CONTROL|Any CPU.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}._MANUAL_CONTROL|Any CPU.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}._MANUAL_CONTROL|Mixed Platforms.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}._MANUAL_CONTROL|Mixed Platforms.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}._MANUAL_CONTROL|x64.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}._MANUAL_CONTROL|x64.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}._MANUAL_CONTROL|x86.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}._MANUAL_CONTROL|x86.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.COM|Any CPU.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.COM|Any CPU.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.COM|Mixed Platforms.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.COM|Mixed Platforms.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.COM|x64.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.COM|x64.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.COM|x86.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.COM|x86.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Debug|x64.ActiveCfg = Debug|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Debug|x64.Build.0 = Debug|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Debug|x86.ActiveCfg = Debug|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Debug|x86.Build.0 = Debug|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.GenesisDisplayTool_V01|Any CPU.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.GenesisDisplayTool_V01|Any CPU.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.GenesisDisplayTool_V01|Mixed Platforms.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.GenesisDisplayTool_V01|Mixed Platforms.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.GenesisDisplayTool_V01|x64.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.GenesisDisplayTool_V01|x64.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.GenesisDisplayTool_V01|x86.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.GenesisDisplayTool_V01|x86.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.PerformTest|Any CPU.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.PerformTest|Any CPU.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.PerformTest|Mixed Platforms.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.PerformTest|Mixed Platforms.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.PerformTest|x64.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.PerformTest|x64.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.PerformTest|x86.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.PerformTest|x86.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Release|Any CPU.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Release|x64.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Release|x64.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Release|x86.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.Release|x86.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.ReleaseTest|Any CPU.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.ReleaseTest|Any CPU.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.ReleaseTest|Mixed Platforms.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.ReleaseTest|Mixed Platforms.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.ReleaseTest|x64.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.ReleaseTest|x64.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.ReleaseTest|x86.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.ReleaseTest|x86.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.XP32bit|Any CPU.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.XP32bit|Any CPU.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.XP32bit|Mixed Platforms.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.XP32bit|Mixed Platforms.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.XP32bit|x64.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.XP32bit|x64.Build.0 = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.XP32bit|x86.ActiveCfg = Release|Any CPU
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}.XP32bit|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -5626,7 +5560,6 @@ Global
{F7316525-FF8E-4651-BA67-3C9B948D1E91} = {03D4F23E-7E4A-4091-BC96-036C996D351A}
{56768A27-D0E4-430E-8E75-AFC7319F189A} = {C9393A97-C0BB-4D59-A879-B572BE04CE15}
{E6081C0A-8452-44B4-8EB4-E0CAE9119830} = {56768A27-D0E4-430E-8E75-AFC7319F189A}
{F408DE9E-01E6-4CFF-AE79-B572B0674FA2} = {B9444AB7-1EB1-484A-8DE6-4EEE03498CD7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4BCB7B69-696C-436A-86F7-C91EA5588164}
+1 -4
View File
@@ -24,6 +24,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
<NoWarn>IDE003;IDE0049;</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -55,10 +56,6 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hardware\Interfaces\Ports\Common.Hardware.Interfaces.Ports.SirtBroadcaster\Common.Hardware.Interfaces.Ports.SirtBroadcaster.csproj">
<Project>{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}</Project>
<Name>Common.Hardware.Interfaces.Ports.SirtBroadcaster</Name>
</ProjectReference>
<ProjectReference Include="..\Hardware\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>
+88 -25
View File
@@ -1,38 +1,101 @@
namespace CommonConsole
{
using Common.Hardware.WaterMeter.eRegister;
using Common.Hardware.WaterMeter.eRegister.Features;
using System;
public class Program
{
public static void Main()
{
var bytes = new Byte[] { 0x00, 0x00, 0x00, 0x05 };
var eregister = EregisterModel();
var index = 0;
var valueMSB = 0;
var pams = eregister.BuildPams();
valueMSB ^= bytes[index++] << 24;
valueMSB ^= bytes[index++] << 16;
valueMSB ^= bytes[index++] << 08;
valueMSB ^= bytes[index++] << 00;
index = 3;
var valueLSB = 0;
valueLSB ^= bytes[index--] << 24;
valueLSB ^= bytes[index--] << 16;
valueLSB ^= bytes[index--] << 08;
valueLSB ^= bytes[index--] << 00;
Console.WriteLine($"{nameof(valueMSB)} == {nameof(valueLSB)} => {valueMSB} == {valueLSB} = {valueMSB == valueLSB}");
var _lsb = BitConverter.ToInt32(bytes, 0);
Array.Reverse(bytes);
var _msb = BitConverter.ToInt32(bytes, 0);
Console.WriteLine($"{nameof(_msb)} == {nameof(_lsb)} => {_msb} == {_lsb} = {_msb == _lsb}");
foreach (var pam in pams)
{
Console.WriteLine($"{pam.Name}: {BitConverter.ToString(pam.CommandBytes.ToArray()).Replace("-", String.Empty)}");
}
}
private static Eregister EregisterModel() => new Eregister
{
ChangeWakeUp = new ChangeWakeUp
{
Mode = WakeUpMode.StayAwake
},
ChangeMeterReading = new ChangeMeterReading
{
DisplayVolume = 500
},
ChangeCustomerText = new ChangeCustomerText
{
Text = "242300147"
},
DeactivateAlarms = new DeactivateAlarms
{
Backflow = true,
MagneticTamper = true,
SpecificError = true,
},
ResetAlarms = new ResetAlarms
{
Value = byte.MaxValue
},
ParameterizeLeakageDetection = new ParameterizeLeakageDetection
{
Value = 10,
},
ParameterizeBrokenPipeDetection = new ParameterizeBrokenPipeDetection
{
Value = 50
},
SetHistoricalErrorLimit = new SetHistoricalErrorLimit
{
Value = 50
},
ChangeDataLoggerSettings = new ChangeDataLoggerSettings
{
MinimumFlow = 10,
TimeInterval = 1440,
TimeOfMinimumFlow = 1
},
WirelessMBusMode = new WirelessMBusMode
{
WMBusEnabled = true,
InstallationModeEnabled = true,
EncryptionEnabled = true,
},
SetPowerLevelSensusRF = new SetPowerLevel
{
Mode = PowerLevelModes.SensusRF,
PowerLevel = 10
},
SetPowerLevelFlexNet = new SetPowerLevel
{
Mode = PowerLevelModes.FlexNet,
PowerLevel = 10
},
Debug = new EregisterDebug
{
DisableOTAFirmwareUpdate = new DisableOTAFirmwareUpdate
{
Mode = OTAMode.DisableFWUpdate
},
SetActivationByThreshold = new SetActivationByThreshold
{
Rotations = 1
}
},
OpenMeteringTransmitionIntervalWMBus = new OpenMeteringTransmitionIntervalWMBus
{
Seconds = 15
},
ChangeNumberOfLatWindows = new ChangeNumberOfLatWindows
{
N = 3
}
};
}
}
@@ -41,39 +41,27 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="JustSirtBroadcaster.cs" />
<Compile Include="JustSirtMessage.cs" />
<Compile Include="JustSirtProxy.cs" />
<Compile Include="Parameters\AuthLevel.cs" />
<Compile Include="JustSirtTask.cs" />
<Compile Include="JustTaskStatus.cs" />
<Compile Include="Parameters\BluetoothOperating.cs" />
<Compile Include="Parameters\ByteExtensions.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="Requests\ReadPamRequest.cs" />
<Compile Include="Requests\ReadRegRequest.cs" />
<Compile Include="SIRTRequest.cs" />
<Compile Include="Requests\WritePamRequest.cs" />
<Compile Include="Requests\WriteRegRequest.cs" />
<Compile Include="Responses\AcknOrAnswerResponse.cs" />
<Compile Include="Responses\FromAirResponse.cs" />
<Compile Include="SIRTResponse.cs" />
<Compile Include="SIRTMessage.cs" />
<Compile Include="SIRTBroadcaster.cs" />
<Compile Include="SIRTConstants.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SIRTTask.cs" />
<Compile Include="SIRTTask[TRequest].cs" />
<Compile Include="Tasks\ActivateSIRTTask.cs" />
<Compile Include="Tasks\DeleteFromPamPoolTask.cs" />
<Compile Include="Tasks\IdentifySIRTTask.cs" />
<Compile Include="Tasks\ReadPamPoolTask.cs" />
<Compile Include="Tasks\WritePamTask.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>
@@ -0,0 +1,166 @@
namespace 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 _);
}
}
}
@@ -1,4 +1,4 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
namespace Common.Hardware.Interfaces.Ports.SIRT
{
using System;
@@ -1,4 +1,4 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
namespace Common.Hardware.Interfaces.Ports.SIRT
{
using System;
using System.Collections.Generic;
@@ -0,0 +1,142 @@
namespace Common.Hardware.Interfaces.Ports.SIRT
{
using Common.Hardware.Interfaces.Ports.SIRT.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
};
}
}
@@ -0,0 +1,15 @@
namespace Common.Hardware.Interfaces.Ports.SIRT
{
public enum JustTaskStatus
{
Pending = 0,
Running = 1,
Completed = 2,
Cancelled = 3,
InRunningTasks = 4,
PamPoolIsFull = 5,
InPamPool = 6,
Sent = 7,
ProxyNotOpen = 8,
}
}
@@ -1,45 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
{
using System;
public class AuthLevel
{
public enum Level : UInt64
{
I = 0x004301143068D0,
II = 0x004302140E8040,
III = 0x00430363937322,
}
private readonly Level pin;
private readonly Byte[] bytes;
private AuthLevel(Level pin)
{
this.pin = pin;
this.bytes = new Byte[6];
var bytes = BitConverter.GetBytes((UInt64)this.pin);
Array.Copy(bytes, 0, this.bytes, 0, this.bytes.Length);
}
public static readonly AuthLevel I = Level.I;
public static readonly AuthLevel II = Level.II;
public static readonly AuthLevel III = Level.III;
public override String ToString()
=> BitConverter.ToString(this.bytes);
public static implicit operator AuthLevel(Level level)
=> new AuthLevel(level);
public static implicit operator UInt64(AuthLevel level)
=> (UInt64)level.pin;
public static implicit operator Byte[](AuthLevel level)
=> level.bytes;
public static implicit operator String (AuthLevel level)
=> level.ToString();
}
}
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters
{
using Common.Utils.Extensions;
using System;
public class BluetoothOperating
@@ -55,7 +57,7 @@
}
public static implicit operator Byte(BluetoothOperating param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator BluetoothOperating(Byte _byte)
=> new BluetoothOperating(_byte.GetBits());
@@ -1,31 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.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;
}
}
}
@@ -1,4 +1,4 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters
{
public enum OperatingModes
{
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters
{
using Common.Utils.Extensions;
using System;
/// <summary>
@@ -170,7 +172,7 @@
}
public static implicit operator Byte(P11 param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator P11(Byte _byte)
=> new P11(_byte.GetBits());
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters
{
using Common.Utils.Extensions;
using System;
/// <summary>
@@ -162,7 +164,7 @@
}
public static implicit operator Byte(P12 param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator P12(Byte _byte)
=> new P12(_byte.GetBits());
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters
{
using Common.Utils.Extensions;
using System;
/// <summary>
@@ -232,19 +234,8 @@
set => this.bits[7] = (Byte)(value ? 1 : 0);
}
public static P811 DelPamAfterSemi => new P811
{
DelPamSemi = true
};
public static P811 WupDelPamAfterSemi => new P811
{
WakeUpCmd = true,
DelPamSemi = true
};
public static implicit operator Byte(P811 param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator P811(Byte _byte)
=> new P811(_byte.GetBits());
@@ -0,0 +1,65 @@
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();
}
}
@@ -1,4 +1,4 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters
{
using System;
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
namespace Common.Hardware.Interfaces.Ports.SIRT.Parameters
{
using Common.Utils.Extensions;
using System;
public class RFModuleOperating
@@ -21,7 +23,7 @@
Array.Copy(this.bits, 0, bits, 0, 4);
return (OperatingModes)bits.GetByte();
return (OperatingModes)bits.ToByte();
}
set
{
@@ -68,7 +70,7 @@
}
public static implicit operator Byte(RFModuleOperating param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator RFModuleOperating(Byte _byte)
=> new RFModuleOperating(_byte.GetBits());
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Parameters
namespace Common.Hardware.Interfaces.Ports.SIRT
{
using Common.Utils.Extensions;
using System;
public class SirtOperating
@@ -128,7 +130,7 @@
}
public static implicit operator Byte(SirtOperating param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator SirtOperating(Byte _byte)
=> new SirtOperating(_byte.GetBits());
@@ -1,35 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.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 = SIRTConstants.Pc2Sirt;
this.message.Cmd = SIRTConstants.ReadPam;
return this.message.ToByteArray();
}
}
}
@@ -1,23 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.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 = SIRTConstants.Pc2Sirt;
this.message.Cmd = SIRTConstants.ReadReg;
return this.message.ToByteArray();
}
}
}
@@ -1,87 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Requests
{
using Common.Hardware.Interfaces.Ports.Sirt;
using Common.Hardware.Interfaces.Ports.Sirt.Parameters;
using System;
public class WritePamRequest : SIRTRequest
{
private readonly P811 parameter811 = default(Byte);
public WritePamRequest()
=> this.parameter811 = this.message.P1;
/// <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 = SIRTConstants.Pc2Sirt;
this.message.Cmd = SIRTConstants.WritePam;
this.message.P1 = this.parameter811;
return this.message.ToByteArray();
}
}
}
@@ -1,24 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Requests
{
using Common.Hardware.Interfaces.Ports.Sirt;
using System;
public class WriteRegRequest : SIRTRequest
{
public Byte WriteLength
{
get => this.message.P2;
set => this.message.P2 = value;
}
protected override Byte[] ToByteArray()
{
this.message.Start = SIRTConstants.Pc2Sirt;
this.message.Cmd = SIRTConstants.WriteReg;
this.message.P2 = this.message.Length;
return this.message.ToByteArray();
}
}
}
@@ -1,58 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Responses
{
using Common.Hardware.Interfaces.Ports.Sirt.Parameters;
using System;
public class AcknOrAnswerResponse : SIRTResponse
{
private readonly P12 parameterP12;
public AcknOrAnswerResponse(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 String LastCmd => this.message.P2.ToString("X2");
public override Boolean IsCrcValid => base.IsCrcValid && (this.parameterP12 == 0 || this.parameterP12 == 128);
}
}
@@ -1,112 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Responses
{
using Common.Hardware.Interfaces.Ports.Sirt.Parameters;
using System;
public class FromAirResponse : SIRTResponse
{
private readonly P11 parameterP11;
private UInt16 mhz;
public FromAirResponse(Byte[] bytes) : base(bytes)
=> this.parameterP11 = this.message.P1;
/// <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 UInt16 MHz
{
get => this.mhz;
set
{
this.mhz = value;
this.ReceivePowerDbm = this.CalculateReceivePowerDbm(this.mhz, this.message.P2);
this.ReceivePowerPer = this.CalculateReceivePowerPer(this.mhz, this.message.P2);
}
}
public Double ReceivePowerDbm { get; private set; }
public Double ReceivePowerPer { get; private set; }
private Double CalculateReceivePowerDbm(Int32 MHz, Byte rssi)
{
var value = default(Double);
if (MHz == 433)
{
value = rssi * 0.5 - 140;
}
else if (MHz == 868)
{
value = rssi * 0.5 - 131.3;
}
return value;
}
private Double CalculateReceivePowerPer(Int32 MHz, Byte rssi)
{
var value = default(Double);
if (MHz == 433)
{
value = -57.6667 + 0.7333 * rssi;
}
else if (MHz == 868)
{
value = -40.316 + 0.66 * rssi;
}
if (value > 100)
{
value = 100;
}
else if (value < 0)
{
value = 0;
}
return value;
}
}
}
@@ -1,29 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
{
using System;
public abstract class SIRTRequest
{
internal readonly SIRTMessage message = new SIRTMessage();
public UInt32 Address
{
get => this.message.Address;
set => this.message.Address = value;
}
public Byte[] Payload
{
get => this.message.Payload;
set => this.message.Payload = value;
}
public override String ToString()
=> BitConverter.ToString(this);
protected abstract Byte[] ToByteArray();
public static implicit operator Byte[] (SIRTRequest request)
=> request.ToByteArray();
}
}
@@ -1,33 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
{
using System;
using Xylem.Common.Utils.Crc16Ccitt;
public class SIRTResponse
{
internal readonly SIRTMessage message;
public SIRTResponse(Byte[] bytes)
{
this.message = new SIRTMessage(bytes);
var existingCRC = this.message.CRC;
var calculatedCRC = Crc16Ccitt.CalculateCRC1021LSBFirst(bytes, 1, bytes.Length - 3);
this.IsCrcValid = existingCRC[0] == calculatedCRC[1]
&& existingCRC[1] == calculatedCRC[0];
}
public Byte ResponseType => this.message.Cmd;
public UInt32 Address => this.message.Address;
public Byte[] Payload => this.message.Payload;
public virtual Boolean IsCrcValid { get; }
public static implicit operator Byte[] (SIRTResponse response)
=> response?.message.Bytes ?? new Byte[0];
}
}
@@ -1,47 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
{
using Common.Hardware.Interfaces.Ports.Sirt.Responses;
using System;
public abstract class SIRTTask<TRequest> : SIRTTask where TRequest : SIRTRequest, new()
{
protected readonly TRequest request;
protected SIRTTask(UInt32 timeout) : base(timeout)
{
this.request = new TRequest();
this.Cmd = this.request.message.Cmd;
}
public override UInt32 Address
{
get => this.request.Address;
set => this.request.Address = value;
}
internal override void BeginAddResponse(AcknOrAnswerResponse response)
{
this.BeginAddResponse();
var done = this.AcknOrAnswerReceived(response);
this.EndAddResponse(done);
}
internal override void BeginAddResponse(FromAirResponse response)
{
this.BeginAddResponse();
var done = this.FromAirReceived(response);
this.EndAddResponse(done);
}
protected virtual Boolean AcknOrAnswerReceived(AcknOrAnswerResponse response) => false;
protected virtual Boolean FromAirReceived(FromAirResponse response) => false;
protected override Byte[] GetRequestBytes() => this.request;
}
}
@@ -1,220 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
{
using Common.Hardware.Interfaces.Ports.Sirt.Responses;
using Common.Hardware.Interfaces.Ports.Sirt.Tasks;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
public class SIRTBroadcaster : SirtSerialPort
{
private readonly ConcurrentDictionary<UInt32, Queue<SIRTTask>> tasks;
private CancellationTokenSource cancellationTokenSource;
private CancellationToken cancellationToken;
public SIRTBroadcaster(SerialPortSettings settings) : base(settings)
{
this.tasks = new ConcurrentDictionary<UInt32, Queue<SIRTTask>>();
this.DataReceived += this.SirtBroadcaster_DataReceived;
}
public event Action<String, Int32> Activated;
public event Action<UInt32> EndpointAvailable;
public String SIRTID { get; private set; }
public UInt16 MHz { get; private set; }
public void Add(SIRTTask task)
{
task.AddressChanged += this.MoveToNewAddress;
task.Cancelled += _task => _task.Retry(60);
task.Done += this.RemoveSucceededAndExecuteNext;
this.tasks
.GetOrAdd(task.Address, new Queue<SIRTTask>())
.Enqueue(task);
}
public override void Close()
{
try
{
this.cancellationTokenSource.Cancel();
}
catch (Exception e)
{
this.LogMessage(e.ToString());
}
base.Close();
}
public override void Open()
{
this.cancellationTokenSource = new CancellationTokenSource();
this.cancellationToken = this.cancellationTokenSource.Token;
base.Open();
this.ActivateSIRT();
this.StartTasksExecutionAsync();
// this.StartPamPoolTrackingAsync();
}
private void ActivateSIRT()
{
var manuelResetEventSlim = new ManualResetEventSlim();
var activationTask = new ActivateSIRTTask();
activationTask.Cancelled += _ => manuelResetEventSlim.Set();
activationTask.Done += _ => manuelResetEventSlim.Set();
this.Add(activationTask);
this.Write(activationTask);
manuelResetEventSlim.Wait();
manuelResetEventSlim.Reset();
tasks.TryRemove(activationTask.Address, out var _);
var identificationTask = new IdentifySIRTTask();
identificationTask.Cancelled += task => manuelResetEventSlim.Set();
identificationTask.Done += task => manuelResetEventSlim.Set();
identificationTask.Identified += sirtID =>
{
this.SIRTID = sirtID;
if (!String.IsNullOrWhiteSpace(this.SIRTID))
{
this.MHz = (UInt16)(this.SIRTID[10] == '1' ? 433 : 868);
}
};
this.Add(identificationTask);
this.Write(identificationTask);
manuelResetEventSlim.Wait();
manuelResetEventSlim.Reset();
tasks.TryRemove(identificationTask.Address, out var _);
var deleteFromPamPool = new DeleteFromPamPoolTask(0xFFFFFFFF);
deleteFromPamPool.Cancelled += x => this.RemoveCancelled(x);
deleteFromPamPool.Done += x => manuelResetEventSlim.Set();
this.Write(deleteFromPamPool);
this.Activated?.Invoke(this.SIRTID, this.MHz);
}
private void SirtBroadcaster_DataReceived(Byte[] data)
{
var address = default(UInt32);
var dataType = data[1];
if (dataType == SIRTConstants.FromAir)
{
var response = new FromAirResponse(data);
response.MHz = this.MHz;
address = response.Address;
if (this.tasks.TryGetValue(address, out var queue) && queue.Count > 0)
{
queue.Peek()?.BeginAddResponse(response);
}
}
else if (dataType == SIRTConstants.AcknOrAnswer)
{
var response = new AcknOrAnswerResponse(data);
address = response.Address;
if (this.tasks.TryGetValue(address, out var queue) && queue.Count > 0)
{
queue.Peek()?.BeginAddResponse(response);
}
}
else
{
var response = new SIRTResponse(data);
address = response.Address;
}
this.EndpointAvailable?.Invoke(address);
}
private void StartTasksExecutionAsync()
{
Task.Factory.StartNew(state =>
{
if (state is SIRTBroadcaster broadcaster)
{
var tasks = broadcaster.tasks;
while (true)
{
foreach (var address in tasks.Keys)
{
if (tasks.TryGetValue(address, out var queue))
{
if (queue.Count > 0)
{
var peek = queue.Peek();
if (peek != null && !peek.IsRunning)
{
this.Write(peek);
peek.IsRunning = true;
}
}
}
}
}
}
}, this, this.cancellationToken);
}
private void MoveToNewAddress(UInt32 oldAddress, UInt32 newAddress)
{
if (this.tasks.TryRemove(oldAddress, out var queue))
{
this.tasks.GetOrAdd(newAddress, queue);
}
}
private void RemoveSucceededAndExecuteNext(SIRTTask task)
{
if (this.tasks.TryGetValue(task.Address, out var queue))
{
if (queue.Count > 0)
{
var peek = queue.Peek();
if (peek.IsDone)
{
queue.Dequeue();
}
}
}
}
private void RemoveCancelled(SIRTTask task)
{
if (this.tasks.TryGetValue(task.Address, out var queue))
{
if (queue.Count > 0)
{
var peek = queue.Peek();
var manuelResetEventSlim = new ManualResetEventSlim();
var deleteFromPamPool = new DeleteFromPamPoolTask(task.Address);
this.Write(deleteFromPamPool);
if (!peek.IsCancelled)
{
task.Retry(60);
}
}
}
}
}
}
@@ -1,30 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
{
using System;
public static class SIRTConstants
{
public const Int32 CmdIndex = 1;
public const Int32 LengthIndex = 8;
public const Int32 MinLength = 12;
public const Byte AcknOrAnswer = 0x12;
public const Byte FromAir = 0x11;
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;
public const Byte Bup = 0x00;
public const Byte Lat = 0x01;
public const Byte Semi = 0x08;
public const Byte Logger = 0x09;
public const Byte Test = 0x0A;
public const Byte Debug = 0x0B;
public const Byte EncFlexNet = 0x10;
public const Byte Pam = 0x20;
}
}
@@ -1,139 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
{
using System;
using Xylem.Common.Utils.Crc16Ccitt;
internal class SIRTMessage
{
private Byte[] bytes;
private Int32 bytesLength;
public SIRTMessage()
{
this.bytes = new Byte[SIRTConstants.MinLength];
this.bytesLength = this.bytes.Length;
}
public SIRTMessage(Byte[] bytes)
{
this.bytes = bytes;
this.bytesLength = 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 UInt32 Address
{
get
{
var address = new Byte[4];
Array.Copy(this.bytes, 4, address, 0, 4);
Array.Reverse(address);
return BitConverter.ToUInt32(address, 0);
}
set
{
var address = BitConverter.GetBytes(value);
Array.Reverse(address);
Array.Copy(address, 0, this.bytes, 4, 4);
}
}
public Byte Length
{
get => this.bytes[8];
set
{
this.bytes[8] = value;
var newLength = SIRTConstants.MinLength + value;
Array.Resize(ref this.bytes, newLength);
this.bytesLength = this.bytes.Length;
}
}
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 = SIRTConstants.MinLength + this.Length;
Array.Resize(ref this.bytes, newLength);
Array.Copy(value, 0, this.bytes, 9, this.Length);
this.bytesLength = this.bytes.Length;
}
}
internal Byte[] CRC => new Byte[]
{
this.bytes[this.bytesLength - 3],
this.bytes[this.bytesLength - 2]
};
internal Byte[] Bytes => this.bytes;
public override String ToString()
=> BitConverter.ToString(this.ToByteArray());
internal Byte[] ToByteArray()
{
var crc = Crc16Ccitt.CalculateCRC1021LSBFirst(this.bytes, 1, this.bytes.Length - 3);
this.bytes[this.bytesLength - 3] = crc[1];
this.bytes[this.bytesLength - 2] = crc[0];
this.bytes[this.bytesLength - 1] = SIRTConstants.StopByte;
return this.bytes;
}
public static implicit operator SIRTMessage(Byte[] bytes)
=> new SIRTMessage(bytes);
public static implicit operator Byte[](SIRTMessage message)
=> message.ToByteArray();
public static implicit operator String (SIRTMessage message)
=> message.ToString();
}
}
@@ -1,97 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
{
using Common.Hardware.Interfaces.Ports.Sirt.Requests;
using Common.Hardware.Interfaces.Ports.Sirt.Responses;
using System;
public abstract class SIRTTask
{
protected const UInt32 TIMEOUT_SECONDS = 15;
protected readonly UInt32 timeout;
protected readonly DateTime created;
protected readonly ReadRegRequest readRegRequest;
protected readonly ReadPamRequest readPamRequest;
protected readonly WriteRegRequest writeRegRequest;
protected SIRTTask(UInt32 timeout)
{
this.timeout = timeout;
this.created = DateTime.Now;
this.Timestamp = DateTime.MinValue;
}
public event Action<SIRTTask> Done;
public event Action<SIRTTask> Cancelled;
public event Action<UInt32, UInt32> AddressChanged;
public event Action<Byte[]> TRXLogging;
public virtual UInt32 Address { get; set; }
public Boolean IsRunning { get; internal set; }
public Byte Cmd { get; protected set; }
public DateTime Timestamp { get; protected set; }
public Boolean IsDone { get; protected set; }
public Boolean IsCancelled { get; protected set; }
internal abstract void BeginAddResponse(AcknOrAnswerResponse response);
internal abstract void BeginAddResponse(FromAirResponse response);
internal void Retry(Double seconds)
{
if (this.IsDone || (DateTime.Now - this.created).TotalSeconds > seconds)
{
this.IsCancelled = true;
}
else
{
this.IsCancelled = false;
this.IsRunning = false;
}
}
protected void BeginAddResponse()
{
if (this.Timestamp == DateTime.MinValue)
{
this.Timestamp = DateTime.Now;
}
}
protected void EndAddResponse(Boolean done)
{
if (done)
{
this.NotifyDone();
}
else if ((DateTime.Now - this.Timestamp).TotalSeconds > this.timeout)
{
this.NotifyCancelled();
}
}
protected abstract Byte[] GetRequestBytes();
protected void NotifyAddressChanged(UInt32 oldAddress, UInt32 newAddress)
=> this.AddressChanged?.Invoke(oldAddress, newAddress);
protected void NotifyCancelled() => this.Cancelled?.Invoke(this);
protected void NotifyDone()
{
this.IsDone = true;
this.Done?.Invoke(this);
}
protected void NotifyTRX(Byte[] bytes) => this.TRXLogging?.Invoke(bytes);
public static implicit operator Byte[] (SIRTTask task) => task.GetRequestBytes();
}
}
@@ -1,35 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Tasks
{
using Common.Hardware.Interfaces.Ports.Sirt.Parameters;
using Common.Hardware.Interfaces.Ports.Sirt.Requests;
using Common.Hardware.Interfaces.Ports.Sirt.Responses;
using System;
internal class ActivateSIRTTask : SIRTTask<WriteRegRequest>
{
private UInt32 address;
public ActivateSIRTTask() : base(TIMEOUT_SECONDS)
{
this.request.Address = 0x20000000;
this.address = this.request.Address;
this.request.Payload = new Byte[]
{
new SirtOperating { /* standard */ },
new BluetoothOperating { BtOff = true },
new RFModuleOperating { RfOff = true },
new RFModuleOperating { OpMode = OperatingModes.ReceiveF1TransmitSensusRFF3 },
new PamTimeout { Minutes = 1 }
};
}
public override UInt32 Address
{
get => this.address;
set => this.address = value;
}
protected override Boolean AcknOrAnswerReceived(AcknOrAnswerResponse response) => response.IsCrcValid;
}
}
@@ -1,17 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Tasks
{
using System;
using Common.Hardware.Interfaces.Ports.Sirt.Responses;
public class DeleteFromPamPoolTask : WritePamTask
{
public DeleteFromPamPoolTask(UInt32 address)
{
this.Address = address;
this.request.DelPamAdr = true;
}
protected override Boolean AcknOrAnswerReceived(AcknOrAnswerResponse response) => true;
}
}
@@ -1,49 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Tasks
{
using Common.Hardware.Interfaces.Ports.Sirt.Requests;
using Common.Hardware.Interfaces.Ports.Sirt.Responses;
using System;
internal class IdentifySIRTTask : SIRTTask<ReadRegRequest>
{
private UInt32 address;
public IdentifySIRTTask() : base(TIMEOUT_SECONDS)
{
this.request.Address = 0x11001820;
this.address = this.request.Address;
this.request.ReadLength = 8;
}
public event Action<String> Identified;
public override UInt32 Address
{
get => this.address;
set => this.address = value;
}
protected override Boolean AcknOrAnswerReceived(AcknOrAnswerResponse response)
{
if (!response.IsCrcValid)
{
this.NotifyCancelled();
return false;
}
var payload = response.Payload;
var identified = payload.Length > 0;
if (identified && this.Identified != null)
{
var sirtID = BitConverter.ToString(payload);
this.Identified.Invoke(sirtID);
}
return identified;
}
}
}
@@ -1,68 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt.Tasks
{
using Common.Hardware.Interfaces.Ports.Sirt.Requests;
using Common.Hardware.Interfaces.Ports.Sirt.Responses;
using System;
internal class ReadPamPoolTask : SIRTTask<ReadPamRequest>
{
private UInt32 address;
public ReadPamPoolTask() : base(TIMEOUT_SECONDS)
{
this.request.Address = 0xFFFFFFFF;
this.address = this.request.Address;
}
public event Action<UInt32[]> AddressesParsed;
public override UInt32 Address
{
get => this.address;
set => this.address = value;
}
protected override Boolean AcknOrAnswerReceived(AcknOrAnswerResponse response)
{
if (!response.IsCrcValid)
{
this.NotifyCancelled();
return false;
}
var payload = response.Payload;
var length = payload.Length;
var parsed = false;
if (length == 20)
{
var bytes = new Byte[4];
var addresses = new UInt32[5];
for (var i = 0; i < length; i += 4)
{
Array.Clear(bytes, 0, 4);
Array.Copy(payload, i, bytes, 0, 4);
Array.Reverse(bytes);
var address = BitConverter.ToUInt32(bytes, 0);
if (address == UInt32.MaxValue)
{
address = 0;
}
addresses[i / 4] = address;
}
this.AddressesParsed?.Invoke(addresses);
parsed = true;
}
return parsed;
}
}
}
@@ -1,74 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.Sirt
{
using Common.Hardware.Interfaces.Ports.Sirt.Requests;
using System;
public class WritePamTask : SIRTTask<WritePamRequest>
{
public WritePamTask() : base(TIMEOUT_SECONDS)
{
}
public WritePamTask(UInt32 timeout) : base(timeout)
{
}
public override UInt32 Address
{
get => this.request.Address;
set => this.request.Address = value;
}
public Boolean WakeUpModul
{
get => this.request.WakeUpModul;
set => this.request.WakeUpModul = value;
}
public Boolean WakeUpCmd
{
get => this.request.WakeUpCmd;
set => this.request.WakeUpCmd = value;
}
public Boolean IgnoreTimeout
{
get => this.request.IgnoreTimeout;
set => this.request.IgnoreTimeout = value;
}
public Boolean DelPamSemi
{
get => this.request.DelPamSemi;
set => this.request.DelPamSemi = value;
}
public Boolean DelPamTx
{
get => this.request.DelPamTx;
set => this.request.DelPamTx = value;
}
public Boolean DelPamAdr
{
get => this.request.DelPamAdr;
set => this.request.DelPamAdr = value;
}
public Boolean DelPamAll
{
get => this.request.DelPamAll;
set => this.request.DelPamAll = value;
}
public Byte[] Payload
{
get => this.request.Payload;
set => this.request.Payload = value;
}
}
}
@@ -51,7 +51,6 @@
<Compile Include="JustSirtTask.cs" />
<Compile Include="JustTaskStatus.cs" />
<Compile Include="Parameters\BluetoothOperating.cs" />
<Compile Include="Parameters\ByteExtensions.cs" />
<Compile Include="Parameters\OperatingModes.cs" />
<Compile Include="Parameters\P11.cs" />
<Compile Include="Parameters\P12.cs" />
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
{
using Common.Utils.Extensions;
using System;
public class BluetoothOperating
@@ -55,7 +57,7 @@
}
public static implicit operator Byte(BluetoothOperating param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator BluetoothOperating(Byte _byte)
=> new BluetoothOperating(_byte.GetBits());
@@ -1,31 +0,0 @@
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.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;
}
}
}
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
{
using Common.Utils.Extensions;
using System;
/// <summary>
@@ -170,7 +172,7 @@
}
public static implicit operator Byte(P11 param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator P11(Byte _byte)
=> new P11(_byte.GetBits());
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
{
using Common.Utils.Extensions;
using System;
/// <summary>
@@ -162,7 +164,7 @@
}
public static implicit operator Byte(P12 param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator P12(Byte _byte)
=> new P12(_byte.GetBits());
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
{
using Common.Utils.Extensions;
using System;
/// <summary>
@@ -233,7 +235,7 @@
}
public static implicit operator Byte(P811 param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator P811(Byte _byte)
=> new P811(_byte.GetBits());
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
{
using Common.Utils.Extensions;
using System;
public class RFModuleOperating
@@ -21,7 +23,7 @@
Array.Copy(this.bits, 0, bits, 0, 4);
return (OperatingModes)bits.GetByte();
return (OperatingModes)bits.ToByte();
}
set
{
@@ -68,7 +70,7 @@
}
public static implicit operator Byte(RFModuleOperating param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator RFModuleOperating(Byte _byte)
=> new RFModuleOperating(_byte.GetBits());
@@ -1,5 +1,7 @@
namespace Common.Hardware.Interfaces.Ports.SirtBroadcaster.Parameters
{
using Common.Utils.Extensions;
using System;
public class SirtOperating
@@ -128,7 +130,7 @@
}
public static implicit operator Byte(SirtOperating param)
=> param.bits.GetByte();
=> param.bits.ToByte();
public static implicit operator SirtOperating(Byte _byte)
=> new SirtOperating(_byte.GetBits());
@@ -0,0 +1,19 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using Common.Utils.Extensions;
using System;
public class ActivateMetrologyTestMode : Pam
{
public ActivateMetrologyTestMode() : base(3, ActivateMetrologyTestMode)
{
}
public UInt16 Mode
{
get => this.bytes.ToUInt16BE(1);
set => value.GetBytesBE().CopyTo(this.bytes, 1);
}
}
}
@@ -1,17 +0,0 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class ActivationByFlow : DebugCmd
{
public ActivationByFlow() : base(ActivationByFlow)
{
}
public Byte RotationsX10
{
get => this.bytes[0];
set => this.bytes[0] = value;
}
}
}
@@ -6,7 +6,7 @@
public class AlarmsMask : Pam
{
private readonly Byte[] bits;
protected readonly Byte[] bits;
protected AlarmsMask(Int32 length, Byte cmd) : base(length, cmd)
=> this.bits = new Byte[8];
@@ -32,7 +32,7 @@
set => this.bits[2] = (Byte)(value ? 1 : 0);
}
public Boolean Byckflow
public Boolean Backflow
{
get => this.bits[3] == 1;
set => this.bits[3] = (Byte)(value ? 1 : 0);
@@ -62,7 +62,7 @@
set => this.bits[7] = (Byte)(value ? 1 : 0);
}
protected override Byte[] ToByteArray()
public override Byte[] ToByteArray()
{
this.bytes[1] = this.bits.ToByte();
@@ -5,8 +5,8 @@
public enum AuthLevel : UInt64
{
O = 0x00_00_00_00_00_00_00_00,
I = 0x00_00_00_0D_68_30_14_01,
II = 0x00_00_00_40_80_0E_14_02,
III = 0x00_00_00_22_73_93_63_03,
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,
}
}
@@ -2,9 +2,9 @@
{
using System;
public class ChangeFixedDateReading : Pam
public class ChangeFixedDateReadingSettings : Pam
{
public ChangeFixedDateReading() : base(4, ChangeFixedDateReading)
public ChangeFixedDateReadingSettings() : base(4, ChangeFixedDateReadingSettings)
{
}
@@ -11,9 +11,9 @@
}
public ChangeMeterReading(UInt32 value) : this()
=> this.Value = value;
=> this.DisplayVolume = value;
public UInt32 Value
public UInt32 DisplayVolume
{
get => this.bytes.ToUInt32BigEndian(1);
set => value.ToBigEndianBytes().CopyTo(this.bytes, 1);
@@ -4,7 +4,6 @@
public partial class ChangeNumberOfDeals : Pam
{
public ChangeNumberOfDeals() : base(2, ChangeNimberOfDeals)
{
}
@@ -0,0 +1,29 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class ChangePin : Pam
{
public ChangePin() : base(6, ChangePin)
{
}
public AuthLevel AuthLevel
{
get
{
var bytes = new Byte[8];
Array.Copy(this.bytes, 1, bytes, 0, 5);
return (AuthLevel)BitConverter.ToUInt64(bytes, 0);
}
set
{
var bytes = BitConverter.GetBytes((UInt64)value);
Array.Copy(bytes, 0, this.bytes, 1, 5);
}
}
}
}
@@ -1,10 +1,41 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using Common.Utils.Extensions;
using System;
public class ChangeSensusRFEncryptionKey : Pam
{
public ChangeSensusRFEncryptionKey(Byte[] encryptionKey) : base(17, ChangeSensusRFEncryptionKey)
public ChangeSensusRFEncryptionKey() : base(17, ChangeSensusRFEncryptionKey)
{
}
public ChangeSensusRFEncryptionKey(Byte[] encryptionKey) : this()
=> encryptionKey.CopyTo(this.bytes, 1);
public Byte[] Key
{
get
{
var key = new Byte[16];
Array.Copy(this.bytes, 1, key, 0, 16);
return key;
}
set
{
if (value?.Length == 16)
{
value.CopyTo(this.bytes, 1);
}
}
}
public String HexKey
{
get => BitConverter.ToString(this.Key).Replace("-", String.Empty);
set => this.Key = value.ToBytes();
}
}
}
@@ -2,7 +2,7 @@
{
using System;
public class State : DebugCmd
public class ChangeState : DebugCmd
{
public enum Modes : Byte
{
@@ -10,7 +10,7 @@
Shipment = 1,
}
public State() : base(State)
public ChangeState() : base(State)
{
}
@@ -1,70 +0,0 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class ChangeTransmission : Pam
{
private Byte oldn;
private Byte newn;
private Byte oldt;
private Byte newt;
protected ChangeTransmission(Int32 length, Byte cmd) : base(length, cmd)
{
}
public ChangeTransmission() : base(3, ChangeTransmitionInterval)
{
}
public Byte LatWindowIntervalCount
{
get => this.bytes[1];
set
{
this.oldn = this.newn;
this.newn = value;
if (this.IsValid)
{
this.bytes[2] = this.newn;
}
else
{
this.newn = this.oldn;
this.oldn = this.bytes[2];
}
}
}
public Byte LatTXIntervalSeconds
{
get => this.bytes[2];
set
{
this.oldt = this.newt;
this.newt = value;
if (this.IsValid)
{
this.bytes[2] = this.newt;
}
else
{
this.newt = this.oldt;
this.oldt = this.bytes[2];
}
}
}
protected Boolean IsValid
{
get
{
var x = this.newt * (this.newn + 1);
return 0 < x && x <= 3600;
}
}
}
}
@@ -41,63 +41,82 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActivationByFlow.cs" />
<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="ChangeFixedDateReading.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="DisableOTA.cs" />
<Compile Include="DisableOTAFirmwareUpdate.cs" />
<Compile Include="EncapsulatedFlexNet.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="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="MeterType.cs" />
<Compile Include="SetMeterType.cs" />
<Compile Include="OpticalTelegram.cs" />
<Compile Include="Options.cs" />
<Compile Include="OTAFWUpdate.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="ChangeTransmission.cs" />
<Compile Include="CustomerDebug.cs" />
<Compile Include="DeactivateAlarms.cs" />
<Compile Include="GetDebug.cs" />
<Compile Include="Pam.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ChangeWakeUp.cs" />
<Compile Include="RebootsCounter.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="SetPCB.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="State.cs" />
<Compile Include="ChangeState.cs" />
<Compile Include="WakeUpMode.cs" />
<Compile Include="WMBusMode.cs" />
<Compile Include="SetOpenMeteringTransmitionIntervalWMBus.cs" />
<Compile Include="WirelessMBusMode.cs" />
<Compile Include="OpenMeteringTransmitionIntervalWMBus.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\Utils\Common.Utils.Extensions\Common.Utils.Extensions.csproj">
@@ -2,7 +2,7 @@
{
public class CustomerDebug : Pam
{
public CustomerDebug() : base(3, RequestCustomerDebug)
public CustomerDebug() : base(3, GetCustomerDebug)
{
}
}
@@ -0,0 +1,15 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class DeactivateTransmitter : SingleBytePam
{
public DeactivateTransmitter() : base(DeactivateTransmitter)
{
}
public DeactivateTransmitter(Byte value) : base(value, DeactivateTransmitter)
{
}
}
}
@@ -9,6 +9,11 @@
public static implicit operator Byte[] (DebugCmd cmd) => cmd.bytes;
/// <summary>
/// No action accept sending Debug Telegram
/// </summary>
protected const Byte RequestDebugTelegram = 0;
/// <summary>
/// Change from Production Mode to Shipment Mode. 1 = Shipment
/// </summary>
@@ -25,22 +30,53 @@
/// </summary>
protected const Byte DisableCredits = 4;
/// <summary>
/// Toggles routing received packets out the serial port
/// </summary>
protected const Byte SerialOutput = 5;
/// <summary>
/// Bit field following the Alarm Byte definition. 1 indicates setting the alarm.
/// Only currently enabled Alarms can be set.
/// </summary>
internal const Byte SetAlarms = 6;
/// <summary>
/// Turns on the indicated Specific Error Flag
/// </summary>
protected const Byte SetSpecificError = 7;
/// <summary>
/// Number of minutes to send LED data 0 will shut down the optical data.
/// </summary>
internal const Byte OpticalTelegram = 8;
/// <summary>
/// Restores most NV to default except radio ID, PCB ID, calibrations and metrology data Beta FW only
/// </summary>
protected const Byte FactoryComplete = 9;
/// <summary>
/// Restores counter settings controlled changed by the Deactivate Counter command.
/// </summary>
internal const Byte EnableCredits = 10;
/// <summary>
/// Used to offset the present battery consumption level to allow simulation of Low Battery,
/// Very Low Battery and End of Life testing.Not intended to be used except in a test environment.
/// </summary>
protected const Byte SetBatteryUsageTestOffset = 11;
/// <summary>
/// Used for testing OTA software updates. Not intended to be used except in a test environment.
/// </summary>
protected const Byte SetTestFastActivityBupTiming = 12;
/// <summary>
/// Used to change the number of activity credits allowed in a 24 hour period for each mode of operation.
/// </summary>
protected const Byte SetActivityCreditLimits = 13;
/// <summary>
/// 0 – Set to Default Rotations value of 8 (8*10) Rotations
/// 1 - 255 Increments of 10 * setting which translates to(10 to 2550) Rotations.
@@ -1,10 +0,0 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class DisableOTA : DebugCmd
{
public DisableOTA(Byte parameter) : base(DisableOTA)
=> this.bytes[1] = parameter;
}
}
@@ -0,0 +1,20 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class DisableOTAFirmwareUpdate : DebugCmd
{
public DisableOTAFirmwareUpdate() : base(DisableOTA)
{
}
public DisableOTAFirmwareUpdate(Byte parameter) : this()
=> this.bytes[1] = parameter;
public OTAMode Mode
{
get => (OTAMode)this.bytes[1];
set => this.bytes[1] = (Byte)value;
}
}
}
@@ -0,0 +1,9 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
public class FactoryComplete : DebugCmd
{
public FactoryComplete() : base(FactoryComplete)
{
}
}
}
@@ -0,0 +1,9 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
public class GetCustomerDebug : Pam
{
public GetCustomerDebug() : base(3, GetCustomerDebug)
{
}
}
}
@@ -1,20 +0,0 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class GetDebug : Pam
{
public GetDebug() : base(3, GetDebug)
{
}
public DebugCmd Cmd { get; set; }
protected override Byte[] ToByteArray()
{
Array.Copy(this.Cmd, 0, this.bytes, 1, 2);
return base.ToByteArray();
}
}
}
@@ -1,17 +0,0 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class OTAFWUpdate : DebugCmd
{
protected OTAFWUpdate() : base(OTAFWUpdate)
{
}
public Boolean Enabled
{
get => this.bytes[0] == 2;
set => this.bytes[0] = (Byte)(value ? 2 : 1);
}
}
}
@@ -0,0 +1,10 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public enum OTAMode : Byte
{
DisableFWUpdate = 1,
EnableFWUpdate = 2,
}
}
@@ -4,13 +4,13 @@
using System;
public class SetOpenMeteringTransmitionIntervalWMBus : Pam
public class OpenMeteringTransmitionIntervalWMBus : Pam
{
public SetOpenMeteringTransmitionIntervalWMBus() : base(3, WMBusTransmisionInterval)
public OpenMeteringTransmitionIntervalWMBus() : base(3, WMBusTransmisionInterval)
{
}
public SetOpenMeteringTransmitionIntervalWMBus(UInt16 seconds) : this()
public OpenMeteringTransmitionIntervalWMBus(UInt16 seconds) : this()
=> this.Seconds = seconds;
public UInt16 Seconds
@@ -25,7 +25,7 @@
return this;
}
protected virtual Byte[] ToByteArray()
public virtual Byte[] ToByteArray()
=> this.bytes;
public static implicit operator Byte[] (Pam pam)
@@ -104,7 +104,7 @@
/// <summary>
/// 19 Send Bubble Up Burst 2 yes 3
/// </summary>
public const Byte SendBUPBurst = 19;
public const Byte SendBubbleUpBurst = 19;
/// <summary>
/// 20 Set frequency offset 2 yes 3
@@ -114,12 +114,12 @@
/// <summary>
/// 21 Activate Metrology Test Mode 2 no 1
/// </summary>
public const Byte ActivateTestMode = 21;
public const Byte ActivateMetrologyTestMode = 21;
/// <summary>
/// 22 Set Reboot Count 2 no? (Production Mode) 3
/// </summary>
public const Byte RebootsCounter = 22;
public const Byte SetRebootCount = 22;
/// <summary>
/// 31 Get debug 2 yes 3
@@ -129,12 +129,12 @@
/// <summary>
/// 32 Change Fixed Date Reading Settings 3 no 0
/// </summary>
public const Byte ChangeFixedDateReading = 32;
public const Byte ChangeFixedDateReadingSettings = 32;
/// <summary>
/// 33 Get Customer Debug 2 yes 2
/// </summary>
public const Byte RequestCustomerDebug = 33;
public const Byte GetCustomerDebug = 33;
/// <summary>
/// 48 Change Meter Reading 4 no(Production Mode) 3
@@ -149,7 +149,7 @@
/// <summary>
/// 50 Set date and time 4 no 1
/// </summary>
public const Byte SetDatetime = 50;
public const Byte SetDateAndTime = 50;
/// <summary>
/// 51 Change settings for data logger 4 no 0
@@ -204,12 +204,12 @@
/// <summary>
/// 72 Send Sequence of Test-Telegrams 7 yes 3
/// </summary>
public const Byte SendTestTelegrams = 72;
public const Byte SendSequenceOfTestTelegrams = 72;
/// <summary>
/// 73 Receive Sequence of Test-Telegrams 7 yes 3
/// </summary>
public const Byte ReceiveTestTelegrams = 73;
public const Byte ReceiveSequenceOfTestTelegrams = 73;
/// <summary>
/// 80 Change Customer Text 9 no 2
@@ -244,6 +244,6 @@
/// <summary>
/// 148 Set Variable PCB ID variable no 3
/// </summary>
public const Byte VariablePCB = 148;
public const Byte SetVariablePcbId = 148;
}
}
@@ -0,0 +1,14 @@
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)
{
}
}
}
@@ -0,0 +1,54 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
// TODO: parameters - TBD
public class ReceiveSequenceOfTestTelegrams : Pam
{
public ReceiveSequenceOfTestTelegrams() : base(8, ReceiveSequenceOfTestTelegrams)
{
}
public Byte Parameter1
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
public Byte Parameter2
{
get => this.bytes[2];
set => this.bytes[2] = value;
}
public Byte Parameter3
{
get => this.bytes[3];
set => this.bytes[3] = value;
}
public Byte Parameter4
{
get => this.bytes[4];
set => this.bytes[4] = value;
}
public Byte Parameter5
{
get => this.bytes[5];
set => this.bytes[5] = value;
}
public Byte Parameter6
{
get => this.bytes[6];
set => this.bytes[6] = value;
}
public Byte Parameter7
{
get => this.bytes[7];
set => this.bytes[7] = value;
}
}
}
@@ -0,0 +1,9 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
public class RequestDebugTelegram : DebugCmd
{
public RequestDebugTelegram() : base(RequestDebugTelegram)
{
}
}
}
@@ -0,0 +1,42 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
// TODO: parameters - TBD
public class RequestFixedDateReading : Pam
{
public RequestFixedDateReading() : base(6, RequestFixedDateReading)
{
}
public Byte Parameter1
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
public Byte Parameter2
{
get => this.bytes[2];
set => this.bytes[2] = value;
}
public Byte Parameter3
{
get => this.bytes[3];
set => this.bytes[3] = value;
}
public Byte Parameter4
{
get => this.bytes[4];
set => this.bytes[4] = value;
}
public Byte Parameter5
{
get => this.bytes[5];
set => this.bytes[5] = value;
}
}
}
@@ -0,0 +1,42 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
// TODO: parameters - TBD
public class RequestLoggingData : Pam
{
public RequestLoggingData() : base(6, RequestLoggingData)
{
}
public Byte Parameter1
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
public Byte Parameter2
{
get => this.bytes[2];
set => this.bytes[2] = value;
}
public Byte Parameter3
{
get => this.bytes[3];
set => this.bytes[3] = value;
}
public Byte Parameter4
{
get => this.bytes[4];
set => this.bytes[4] = value;
}
public Byte Parameter5
{
get => this.bytes[5];
set => this.bytes[5] = value;
}
}
}
@@ -0,0 +1,47 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class RequestMemoryDump : Pam
{
public RequestMemoryDump() : base(7, MemoryDump)
{
}
public Byte Parameter1
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
public Byte Parameter2
{
get => this.bytes[2];
set => this.bytes[2] = value;
}
public Byte Parameter3
{
get => this.bytes[3];
set => this.bytes[3] = value;
}
public Byte Parameter4
{
get => this.bytes[4];
set => this.bytes[4] = value;
}
public Byte Parameter5
{
get => this.bytes[5];
set => this.bytes[5] = value;
}
public Byte Parameter6
{
get => this.bytes[6];
set => this.bytes[6] = value;
}
}
}
@@ -0,0 +1,19 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using Common.Utils.Extensions;
using System;
public class SendBubbleUpBurst : Pam
{
public SendBubbleUpBurst() : base(3, SendBubbleUpBurst)
{
}
public UInt16 Value
{
get => this.bytes.ToUInt16BE(1);
set => value.GetBytesBE().CopyTo(this.bytes, 1);
}
}
}
@@ -0,0 +1,54 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
// TODO: parameters - TBD
public class SendSequenceOfTestTelegrams : Pam
{
public SendSequenceOfTestTelegrams() : base(8, SendSequenceOfTestTelegrams)
{
}
public Byte Parameter1
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
public Byte Parameter2
{
get => this.bytes[2];
set => this.bytes[2] = value;
}
public Byte Parameter3
{
get => this.bytes[3];
set => this.bytes[3] = value;
}
public Byte Parameter4
{
get => this.bytes[4];
set => this.bytes[4] = value;
}
public Byte Parameter5
{
get => this.bytes[5];
set => this.bytes[5] = value;
}
public Byte Parameter6
{
get => this.bytes[6];
set => this.bytes[6] = value;
}
public Byte Parameter7
{
get => this.bytes[7];
set => this.bytes[7] = value;
}
}
}
@@ -0,0 +1,48 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
// TODO: parameters - TBD
public class SendTestPattern : Pam
{
public SendTestPattern() : base(6, SendTestPattern)
{
}
public Byte Parameter1
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
public Byte Parameter2
{
get => this.bytes[2];
set => this.bytes[2] = value;
}
public Byte Parameter3
{
get => this.bytes[3];
set => this.bytes[3] = value;
}
public Byte Parameter4
{
get => this.bytes[4];
set => this.bytes[4] = value;
}
public Byte Parameter5
{
get => this.bytes[5];
set => this.bytes[5] = value;
}
public Byte Parameter6
{
get => this.bytes[6];
set => this.bytes[6] = value;
}
}
}
@@ -0,0 +1,9 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
public class SerialOutput : DebugCmd
{
public SerialOutput() : base(SerialOutput)
{
}
}
}
@@ -4,7 +4,17 @@
public class SetActivationByThreshold : DebugCmd
{
public SetActivationByThreshold(Byte parameter) : base(SetActivationByThreshold)
public SetActivationByThreshold() : base(SetActivationByThreshold)
{
}
public SetActivationByThreshold(Byte parameter) : this()
=> this.bytes[1] = parameter;
public Byte Rotations
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
}
}
@@ -0,0 +1,22 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class SetActivityCreditLimits : DebugCmd
{
public SetActivityCreditLimits() : base(SetActivityCreditLimits)
{
}
/// <summary>
/// Bit Field
/// Bits 6 - 7 -> Mode, 00 TFX, 01 Idle, 10 Sensus RF
/// Bits 0 - 5 – Number of Activity Credits (X+1)*100. Value of 63 sets limit to 10000
/// </summary>
public Byte Mask
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
}
}
@@ -1,9 +1,17 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using Common.Utils.Extensions;
public class SetAlarms : AlarmsMask
{
public SetAlarms() : base(2, DebugCmd.SetAlarms)
public SetAlarms() : base(3, GetDebug)
=> this.bytes[2] = DebugCmd.SetAlarms;
public override System.Byte[] ToByteArray()
{
this.bytes[1] = this.bits.ToByte();
return base.ToByteArray();
}
}
}
@@ -0,0 +1,23 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class SetBatteryUsageTestOffset : DebugCmd
{
public SetBatteryUsageTestOffset() : base(SetBatteryUsageTestOffset)
{
}
/// <summary>
/// 0 Remove Battery Usage offset
/// 1 &lt;= X &lt;= 99 Set Test EOL to 1 to 99 percent
/// 100 &lt; X &lt;= 199 Set Test EOL offset to 99.01 to 99.99 percent
/// 100 -&gt; End of Life
/// </summary>
public Byte BatteryUsedInPercent // TODO: implement as double value
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
}
}
@@ -12,8 +12,8 @@
public UInt32 Seconds
{
get => this.bytes.ToUInt32BigEndian(1);
set => value.ToBigEndianBytes().CopyTo(this.bytes, 1);
get => this.bytes.ToUInt32BE(1);
set => value.GetBytesBE().CopyTo(this.bytes, 1);
}
}
}
@@ -0,0 +1,19 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using Common.Utils.Extensions;
using System;
public class SetDateAndTime : Pam
{
public SetDateAndTime() : base(5, SetDateAndTime)
{
}
public UInt32 SecondsSince20000101
{
get => this.bytes.ToUInt32BE(1);
set => value.GetBytesBE().CopyTo(this.bytes, 1);
}
}
}
@@ -0,0 +1,19 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using Common.Utils.Extensions;
using System;
public class SetFrequencyOffset : Pam
{
public SetFrequencyOffset() : base(3, SetFrequencyOffset)
{
}
public UInt16 Offset
{
get => this.bytes.ToUInt16BE(1);
set => value.GetBytesBE().CopyTo(this.bytes, 1);
}
}
}
@@ -2,9 +2,9 @@
{
using System;
public class MeterType : DebugCmd
public class SetMeterType : DebugCmd
{
public MeterType() : base(MeterType)
public SetMeterType() : base(MeterType)
{
}
@@ -106,7 +106,7 @@
set => value.ToBigEndianBytes().CopyTo(this.bytes, 14);
}
protected override Byte[] ToByteArray()
public override Byte[] ToByteArray()
{
this.bytes[12] = this.bitsFromByte11.ToByte();
this.bytes[1] = 0x10;
@@ -4,9 +4,9 @@
using System;
public class SetPCB : Pam
public class SetPcbId : Pam
{
public SetPCB() : base(5, SetPCB)
public SetPcbId() : base(5, SetPCB)
{
}
@@ -12,16 +12,15 @@
{
}
public Byte PowerLevel
{
get => (Byte)(this.bytes[1] - this.Mode);
set => this.bytes[1] = (Byte)(Math.Min(value, (Byte)127) + this.Mode);
}
public Byte PowerLevel { get; set; }
public PowerLevelModes Mode
public PowerLevelModes Mode { get; set; }
public override Byte[] ToByteArray()
{
get => (PowerLevelModes)(this.bytes[1] - this.PowerLevel);
set => this.bytes[1] = (Byte)(value + this.PowerLevel);
this.Value = (Byte)((Byte)this.Mode | 127 & this.PowerLevel);
return base.ToByteArray();
}
}
}
@@ -2,9 +2,9 @@
{
using System;
public class RebootsCounter : Pam
public class SetRebootCount : Pam
{
public RebootsCounter() : base(3, RebootsCounter)
public SetRebootCount() : base(3, SetRebootCount)
{
}
@@ -0,0 +1,9 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
public class SetSpecificError : DebugCmd
{
public SetSpecificError() : base(SetSpecificError)
{
}
}
}
@@ -175,7 +175,7 @@
public UInt32 CurrentReading => BitConverter.ToUInt32(this.bytes, 18);
protected override Byte[] ToByteArray()
public override Byte[] ToByteArray()
{
this.bytes[3] = this.bitsFromByte2.ToByte();
this.bytes[4] = this.bitsFromByte3.ToByte();
@@ -0,0 +1,21 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
using System;
public class SetTestFastActivityBupTiming : DebugCmd
{
public SetTestFastActivityBupTiming() : base(SetTestFastActivityBupTiming)
{
}
/// <summary>
/// 0 – Default setting of 3 seconds.
/// 1 - 255 Number of 250ms offset between Activity BUP’s after a Block Load Command.
/// </summary>
public Byte Miliseconds
{
get => this.bytes[1];
set => this.bytes[1] = value;
}
}
}
@@ -0,0 +1,9 @@
namespace Common.Hardware.WaterMeter.eRegister.Features
{
public class SetVariablePcbId : Pam
{
public SetVariablePcbId() : base(1 /* TODO: TBD */, SetVariablePcbId)
{
}
}
}
@@ -4,15 +4,14 @@
using System;
public class WMBusMode : Pam
public class WirelessMBusMode : Pam
{
private readonly Byte[] bits;
private Byte mBusStatus;
public WMBusMode() : base(2, ChangeWirelessMBusMode)
public WirelessMBusMode() : base(2, ChangeWirelessMBusMode)
=> this.bits = new Byte[8];
public WMBusMode(Byte mBusStatus) : base(2, ChangeWirelessMBusMode)
public WirelessMBusMode(Byte mBusStatus) : this()
{
this.bytes[1] = mBusStatus;
this.bits = mBusStatus.GetBits();
@@ -81,7 +80,7 @@
set => this.bits[0] = (Byte)(value ? 1 : 0);
}
protected override Byte[] ToByteArray()
public override Byte[] ToByteArray()
{
this.bytes[1] = this.bits.ToByte();
@@ -58,10 +58,13 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Data\ACKN.cs" />
<Compile Include="Data\AppCode.cs" />
<Compile Include="Data\BUP.cs" />
<Compile Include="Data\DEBUG.cs" />
<Compile Include="Eregister.cs" />
<Compile Include="EregisterDebug.cs" />
<Compile Include="EregisterPam.cs" />
<Compile Include="PamTypeAttribute.cs" />
<Compile Include="ParameterSet.cs" />
<Compile Include="ProgrammingBatch.cs" />
<Compile Include="ProgrammingTask.cs" />
@@ -79,10 +82,6 @@
<Project>{05F0CCAF-9F2B-45F9-A7F8-12F29AD182F3}</Project>
<Name>Common.Utils.Extensions</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Interfaces\Ports\Common.Hardware.Interfaces.Ports.SirtBroadcaster\Common.Hardware.Interfaces.Ports.SirtBroadcaster.csproj">
<Project>{F408DE9E-01E6-4CFF-AE79-B572B0674FA2}</Project>
<Name>Common.Hardware.Interfaces.Ports.SirtBroadcaster</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>
@@ -1,6 +1,7 @@
namespace Common.Hardware.WaterMeter.eRegister.Data
{
using Common.Hardware.Interfaces.Ports.SirtBroadcaster;
using Common.Hardware.Interfaces.Ports.SIRT;
using Common.Hardware.Interfaces.Ports.SIRT.Parameters;
using Common.Utils.Extensions;
using System;
@@ -0,0 +1,274 @@
namespace Common.Hardware.WaterMeter.eRegister
{
using Common.Hardware.WaterMeter.eRegister.Features;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
public class Eregister
{
[PamType(AuthLevel.II)]
public ChangeWakeUp ChangeWakeUp { get; set; }
[PamType(AuthLevel.O)]
public SetPowerLevel SetPowerLevelSensusRF { get; set; }
[PamType(AuthLevel.III)]
public SetPowerLevel SetPowerLevelFlexNet { get; set; }
[PamType(AuthLevel.II)]
public ChangeNumberOfLatWindows ChangeNumberOfLatWindows { get; set; }
[PamType(AuthLevel.I)]
public ResetAlarms ResetAlarms { get; set; }
[PamType(AuthLevel.II, true)]
public DeactivateTransmitter DeactivateTransmiter { get; set; }
[PamType(AuthLevel.II)]
public WirelessMBusMode WirelessMBusMode { get; set; }
[PamType(AuthLevel.O)]
public DeactivateAlarms DeactivateAlarms { get; set; }
[PamType(AuthLevel.O)]
public ChangeNumberOfDeals ChangeNumberOfDeals { get; set; }
[PamType(AuthLevel.O)]
public ParameterizeLeakageDetection ParameterizeLeakageDetection { get; set; }
[PamType(AuthLevel.O)]
public ParameterizeBrokenPipeDetection ParameterizeBrokenPipeDetection { get; set; }
[PamType(AuthLevel.I)]
public SetHistoricalErrorLimit SetHistoricalErrorLimit { get; set; }
[PamType(AuthLevel.III, true)]
public Reset Reset { get; set; }
[PamType(AuthLevel.II)]
public ChangeTransmissionInterval ChangeTransmissionInterval { get; set; }
[PamType(AuthLevel.II)]
public OpenMeteringTransmitionIntervalWMBus OpenMeteringTransmitionIntervalWMBus { get; set; }
[PamType(AuthLevel.III, true)]
public SendBubbleUpBurst SendBubbleUpBurst { get; set; }
[PamType(AuthLevel.III, true)]
public SetFrequencyOffset SetFrequencyOffset { get; set; }
[PamType(AuthLevel.I)]
public ActivateMetrologyTestMode ActivateMetrologyTestMode { get; set; }
[PamType(AuthLevel.III)]
public SetRebootCount SetRebootCount { get; set; }
[PamType(AuthLevel.III, true)]
public EregisterDebug Debug { get; set; }
[PamType(AuthLevel.O)]
public ChangeFixedDateReadingSettings ChangeFixedDateReadingSettings { get; set; }
[PamType(AuthLevel.II, true)]
public GetCustomerDebug GetCustomerDebug { get; set; }
[PamType(AuthLevel.III)]
public ChangeMeterReading ChangeMeterReading { get; set; }
[PamType(AuthLevel.III)]
public ChangeMeterId ChangeMeterId { get; set; }
[PamType(AuthLevel.I)]
public SetDateAndTime SetDateAndTime { get; set; }
[PamType(AuthLevel.O)]
public ChangeDataLoggerSettings ChangeDataLoggerSettings { get; set; }
[PamType(AuthLevel.III)]
public SetBytterySeconds SetBytterySeconds { get; set; }
[PamType(AuthLevel.III)]
public SetPcbId SetPcbId { get; set; }
[PamType(AuthLevel.O, true)]
public RequestFixedDateReading RequestFixedDateReading { get; set; }
[PamType(AuthLevel.O, true)]
public RequestLoggingData RequestLoggingData { get; set; }
[PamType(AuthLevel.III, true)]
public SendTestPattern SendTestPattern { get; set; }
[PamType(AuthLevel.III, true)]
public RequestMemoryDump RequestMemoryDump { get; set; }
[PamType(AuthLevel.III, true)]
public SendSequenceOfTestTelegrams SendSequenceOfTestTelegrams { get; set; }
[PamType(AuthLevel.III, true)]
public ReceiveSequenceOfTestTelegrams ReceiveSequenceOfTestTelegrams { get; set; }
[PamType(AuthLevel.II)]
public ChangeCustomerText ChangeCustomerText { get; set; }
[PamType(AuthLevel.O, true)]
public EncapsulatedFlexNet EncapsulatedFlexNet { get; set; }
[PamType(AuthLevel.O)]
public SetTFXParameters SetTFXParameters { get; set; }
[PamType(AuthLevel.III, true)]
public SetMetrologyParameters SetMetrologyParameters { get; set; }
[PamType(AuthLevel.O, true)]
public Ping Ping { get; set; }
[PamType(AuthLevel.III)]
public SetVariablePcbId SetVariablePcbId { get; set; }
public IEnumerable<EregisterPam> BuildPams()
{
var pams = this.GetPams()
.OrderBy(x => x.CommandBytes[0]);
var cmds = new List<EregisterPam>();
var pamsLevel0 = new List<EregisterPam>();
var pamsLevel1 = new List<EregisterPam>();
var pamsLevel2 = new List<EregisterPam>();
var pamsLevel3 = new List<EregisterPam>();
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);
}
}
}
var pamLevel0 = new EregisterPam();
foreach (var pam in pamsLevel0)
{
pamLevel0.Name += $"{pam.Name}{Environment.NewLine}";
pamLevel0.CommandBytes.AddRange(pam.CommandBytes);
}
pamLevel0.Name = pamLevel0.Name.Trim();
var pamLevel1 = new EregisterPam();
foreach (var pam in pamsLevel1)
{
pamLevel1.Name += $"{pam.Name}{Environment.NewLine}";
pamLevel1.CommandBytes.AddRange(pam.CommandBytes);
}
pamLevel1.Name = pamLevel1.Name.Trim();
pamLevel1.CommandBytes.AddRange(pin1);
var pamLevel2 = new EregisterPam();
foreach (var pam in pamsLevel2)
{
pamLevel2.Name += $"{pam.Name}{Environment.NewLine}";
pamLevel2.CommandBytes.AddRange(pam.CommandBytes);
}
pamLevel2.Name = pamLevel2.Name.Trim();
pamLevel2.CommandBytes.AddRange(pin2);
var pamLevel3 = new EregisterPam();
foreach (var pam in pamsLevel3)
{
pamLevel3.Name += $"{pam.Name}{Environment.NewLine}";
pamLevel3.CommandBytes.AddRange(pam.CommandBytes);
}
pamLevel3.Name = pamLevel3.Name.Trim();
pamLevel3.CommandBytes.AddRange(pin3);
cmds.Insert(0, pamLevel3);
cmds.Insert(0, pamLevel2);
cmds.Insert(0, pamLevel1);
cmds.Insert(0, pamLevel0);
return cmds;
}
private IEnumerable<EregisterPam> GetPams()
{
foreach (var eregisterProperty in typeof(Eregister).GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
var pamType = eregisterProperty.GetCustomAttribute<PamTypeAttribute>();
if (pamType is null)
{
continue;
}
var propertyValue = eregisterProperty.GetValue(this);
if (propertyValue is null)
{
continue;
}
else if (propertyValue is EregisterDebug debug)
{
foreach (var pam in debug.GetPams().OrderBy(x => x.CommandBytes[2]))
{
yield return pam;
}
}
else if (propertyValue is Pam pam)
{
yield return new EregisterPam
{
Name = eregisterProperty.Name,
AuthLevel = pamType.AuthLevel,
IsSingleCmd = pamType.IsSingleCmd,
CommandBytes = pam.ToByteArray().ToList()
};
}
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More