diff --git a/Common/CommonConsole/CommonConsole.csproj b/Common/CommonConsole/CommonConsole.csproj
index 37154e77..35959d4d 100644
--- a/Common/CommonConsole/CommonConsole.csproj
+++ b/Common/CommonConsole/CommonConsole.csproj
@@ -40,6 +40,7 @@
+
diff --git a/Common/CommonConsole/Program.cs b/Common/CommonConsole/Program.cs
index 4c06270c..3e0c8d92 100644
--- a/Common/CommonConsole/Program.cs
+++ b/Common/CommonConsole/Program.cs
@@ -1,12 +1,28 @@
namespace CommonConsole
{
+ using Common.Hardware.SIRT;
+
using System;
public static partial class Program
{
static void Main()
{
+ SIRTLogger.Message += Console.WriteLine;
+ var sirtHub = new SIRTHub();
+ _ = sirtHub.TryOpen("COM6", out var _1, out var _2);
+ _ = sirtHub.TryOpen("COM7", out var _3, out var _4);
+ var addresses = new uint[]
+ {
+ 319017452,
+ 319017453,
+ 319017454,
+ 309031154,
+ };
+ Console.ReadKey();
+ sirtHub.CloseAll();
+ SIRTLogger.Message -= Console.WriteLine;
}
@@ -24,10 +40,6 @@
-
-
-
-
static void Main_ProgrammingParameters_Cordonel()
diff --git a/Common/Hardware/Common.Hardware.SIRT/SIRTHub.cs b/Common/Hardware/Common.Hardware.SIRT/SIRTHub.cs
index bd191b39..fa482fcb 100644
--- a/Common/Hardware/Common.Hardware.SIRT/SIRTHub.cs
+++ b/Common/Hardware/Common.Hardware.SIRT/SIRTHub.cs
@@ -4,14 +4,12 @@
using System;
using System.Collections.Concurrent;
- using System.Collections.Generic;
using System.Linq;
using System.Threading;
public class SIRTHub
{
private static readonly ConcurrentDictionary broadcasters = new ConcurrentDictionary();
- private static List> messageReceiveDelegates = new List>();
private readonly bool log_RX_TX;
@@ -20,6 +18,7 @@
public event Action Connected;
public event Action Disconnected;
+ public event Action MessageReceived;
public void CloseAll()
{
@@ -53,11 +52,6 @@
void SIRTBroadcaster_Disconnected(SIRTBroadcaster _broadcaster)
{
- foreach (var @delegate in messageReceiveDelegates)
- {
- broadcaster.MessageReceived -= @delegate;
- }
-
this.Disconnected?.Invoke(_broadcaster);
disconnectedEvent.Set();
@@ -99,27 +93,17 @@
void SIRTBroadcasterConnected(SIRTBroadcaster _broadcaster)
{
- broadcasters.GetOrAdd(portName, _broadcaster);
-
- foreach (var @delegate in messageReceiveDelegates)
- {
- _broadcaster.MessageReceived += @delegate;
- }
-
+ _broadcaster.MessageReceived += this.OnSIRTMessageReceived;
+ broadcasters.AddOrUpdate(portName, _broadcaster, (_, _1) => _broadcaster);
this.Connected?.Invoke(_broadcaster);
-
connectedEvent.Set();
}
void SIRTBroadcasterDisconnected(SIRTBroadcaster _broadcaster)
{
- foreach (var @delegate in messageReceiveDelegates)
- {
- _broadcaster.MessageReceived -= @delegate;
- }
-
+ _broadcaster.MessageReceived -= this.OnSIRTMessageReceived;
+ broadcasters.TryRemove(portName, out var _);
this.Disconnected?.Invoke(_broadcaster);
-
connectedEvent.Set();
}
@@ -127,7 +111,7 @@
broadcaster.Disconnected += SIRTBroadcasterDisconnected;
broadcaster.Open();
- connectedEvent.Wait(3000);
+ connectedEvent.Wait();
hexId = broadcaster.Id;
frequency = broadcaster.Frequency;
@@ -140,5 +124,8 @@
private void LogMessage(object message)
=> SIRTLogger.LogMessage($"{nameof(SIRTHub)}|{message}");
+
+ private void OnSIRTMessageReceived(SIRTMessage message)
+ => this.MessageReceived?.Invoke(message);
}
}
diff --git a/Common/Hardware/Common.Hardware.SIRT/SIRTPort.cs b/Common/Hardware/Common.Hardware.SIRT/SIRTPort.cs
index 5ca06bd6..4b6ded94 100644
--- a/Common/Hardware/Common.Hardware.SIRT/SIRTPort.cs
+++ b/Common/Hardware/Common.Hardware.SIRT/SIRTPort.cs
@@ -26,9 +26,11 @@
this.LogMessage($"Closing: {this}");
var waitEvent = new ManualResetEventSlim();
+ var disposed = false;
void SerialPortDisposed(object sender, EventArgs args)
{
+ disposed = true;
this.LogMessage($"Disposed: {this}");
waitEvent.Set();
}
@@ -47,7 +49,7 @@
this.serialPort.Disposed -= SerialPortDisposed;
- if (!this.IsOpen)
+ if (disposed)
{
this.LogMessage($"Closed: {this}");
}
@@ -76,6 +78,40 @@
}
}
+ public IEnumerable GetEnumerable()
+ {
+ var manualResetEventSlim = new ManualResetEventSlim();
+
+ void DataReceived(object sender, SerialDataReceivedEventArgs args)
+ {
+ if (args.EventType == SerialData.Chars)
+ {
+ manualResetEventSlim.Set();
+ }
+ }
+
+ this.serialPort.DataReceived += DataReceived;
+
+ var bufferSize = this.serialPort.ReadBufferSize;
+ var buffer = new byte[bufferSize];
+ var length = default(int);
+
+ while (this.serialPort.IsOpen)
+ {
+ buffer = new byte[bufferSize];
+ length = this.serialPort.Read(buffer, 0, bufferSize);
+
+ Array.Resize(ref buffer, length);
+
+ yield return buffer;
+
+ manualResetEventSlim.Reset();
+ manualResetEventSlim.Wait();
+ }
+
+ this.serialPort.DataReceived -= DataReceived;
+ }
+
public IEnumerable ReadBytes()
{
var bufferSize = this.serialPort.ReadBufferSize;
@@ -90,7 +126,7 @@
{
length = this.serialPort.Read(buffer, 0, bufferSize);
}
- catch (IOException _)
+ catch (IOException e)
{
break;
}
diff --git a/Common/Hardware/Common.Hardware.SIRT/SIRTStream.cs b/Common/Hardware/Common.Hardware.SIRT/SIRTStream.cs
index 0598dc32..58c124c6 100644
--- a/Common/Hardware/Common.Hardware.SIRT/SIRTStream.cs
+++ b/Common/Hardware/Common.Hardware.SIRT/SIRTStream.cs
@@ -2,15 +2,19 @@
{
using System;
using System.Collections.Generic;
+ using System.Threading;
+ using System.Threading.Tasks;
public sealed class SIRTStream
{
private readonly SIRTPort sirtPort;
private readonly bool log_RX_TX;
+ private readonly List stream;
public SIRTStream(string portName, bool log_RX_TX = true)
{
this.sirtPort = new SIRTPort(portName, false);
+ this.stream = new List();
this.log_RX_TX = log_RX_TX;
}
@@ -24,7 +28,17 @@
public IEnumerable ReadMessages()
{
- var buffer = new List();
+ void StartReading()
+ {
+ foreach (var bytes in this.sirtPort.ReadBytes())
+ {
+ this.stream.AddRange(bytes);
+ }
+ }
+
+ var cancellationTokenSource = new CancellationTokenSource();
+ var cancellationToken = cancellationTokenSource.Token;
+ var task = Task.Factory.StartNew(StartReading, cancellationToken);
var bytesCount = default(int);
var startIndex = default(int);
var lengthIndex = default(int);
@@ -33,20 +47,19 @@
var messageLength = default(int);
var message = default(byte[]);
- foreach (var bytes in this.sirtPort.ReadBytes())
+ while (this.sirtPort.IsOpen)
{
- buffer.AddRange(bytes);
- bytesCount = buffer.Count;
+ bytesCount = this.stream.Count;
// until can parse messages from the buffer
while (bytesCount > 0)
{
- startIndex = buffer.IndexOf(SIRTConstants.SIRT_PC, 0);
+ startIndex = this.stream.IndexOf(SIRTConstants.SIRT_PC, 0);
// when no start byte found clear and break
if (startIndex < 0)
{
- buffer.Clear();
+ this.stream.Clear();
break;
}
@@ -59,7 +72,7 @@
break;
}
- length = buffer[lengthIndex];
+ length = this.stream[lengthIndex];
endIndex = lengthIndex + length + 3;
// when not enough bytes to the end of the message just break
@@ -71,8 +84,8 @@
messageLength = endIndex - startIndex + 1;
message = new byte[messageLength];
- buffer.CopyTo(startIndex, message, 0, messageLength);
- buffer.RemoveRange(0, endIndex + 1);
+ this.stream.CopyTo(startIndex, message, 0, messageLength);
+ this.stream.RemoveRange(0, endIndex + 1);
// when message dose not ends with 0x16 clear bytes and break
if (message[messageLength - 1] != SIRTConstants.MSG_END)
@@ -88,11 +101,20 @@
}
// in case there are more messages in the buffer
- bytesCount = buffer.Count;
+ bytesCount = this.stream.Count;
yield return message;
}
}
+
+ try
+ {
+ cancellationTokenSource.Cancel();
+ }
+ catch (Exception e)
+ {
+ this.LogMessage($"{e.Message}");
+ }
}
public void Write(params byte[] bytes)
diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Eregister.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Eregister.cs
index 3e0e75d0..fb750052 100644
--- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Eregister.cs
+++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Eregister.cs
@@ -44,12 +44,6 @@
internal IEnumerable LoadInspectionInitializationTasks()
{
this.executionType = nameof(LoadInspectionInitializationTasks);
-
- //if (this.parameters.Completed)
- //{
- // return new EregisterTask[] { };
- //}
-
var features = this.parameters.LoadInspectionInitializationFeatures();
if (features.RequestAddress > 0 && features.ResponseAddress > 0)
@@ -82,12 +76,26 @@
if (features.RequestAddress > 0 && features.ResponseAddress > 0)
{
- this.LoadProgrammingParameters(features);
+ // this.LoadProgrammingParameters(features);
if (this.parameters.StatusFertigung == 30)
{
- this.runningTasks.Add(new EregisterCheckFinalizationTask(this.parameters, features.Frequency)
+ //this.runningTasks.Add(new EregisterCheckFinalizationTask(this.parameters, features.Frequency)
+ //{
+ // WakeUpModul = true,
+ // SlotNr = features.SlotNr,
+ // PoNr = features.PoNr,
+ // SerialNr = features.SerialNr,
+ // RequestAddress = features.RequestAddress,
+ // ResponseAddress = features.ResponseAddress,
+ // EncryptionKeyI = features.EncryptionKey,
+ // EncryptionKeyII = SENSUS_STANDARD.GetEncryptionKey(),
+ //});
+
+ this.runningTasks.Add(new EregisterTask(this.parameters.Frequency)
{
+ Name = "WUP",
+ WakeUpCmd = true,
WakeUpModul = true,
SlotNr = features.SlotNr,
PoNr = features.PoNr,
@@ -96,10 +104,18 @@
ResponseAddress = features.ResponseAddress,
EncryptionKeyI = features.EncryptionKey,
EncryptionKeyII = SENSUS_STANDARD.GetEncryptionKey(),
+ Data = new ChangeWakeUp(WakeUpMode.StayAwake)
+ .Append(new ChangeNumberOfLatWindows(this.parameters.LatWindowsInitialization))
+ .Append(new ChangeTransmissionInterval(this.parameters.TransmissionIntervalInitialization))
+ // .Append(new ChangeSensusRFEncryptionKey(features.EncryptionKey))
+ .Append(new ProvidePin(AuthLevel.II)),
+ Timeout = 10_000
});
+
this.runningTasks.Add(new EregisterTask(this.parameters.Frequency)
{
+ WakeUpModul = true,
Name = "0, 2, 16",
SlotNr = features.SlotNr,
PoNr = features.PoNr,
diff --git a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Models/EregisterProgrammingParameters.cs b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Models/EregisterProgrammingParameters.cs
index 000f56e3..5a259d42 100644
--- a/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Models/EregisterProgrammingParameters.cs
+++ b/Common/Hardware/WaterMeter/eRegister/Common.Hardware.WaterMeter.eRegister/Models/EregisterProgrammingParameters.cs
@@ -265,11 +265,6 @@
EncryptionKey = this.EncryptionKey.GetEncryptionKey(),
};
- //if (this.Completed)
- //{
- // return features;
- //}
-
features.Debug = new EregisterDebugFeatures();
features.ChangeMeterReading = this.DisplayVolume;
@@ -301,10 +296,7 @@
features.Debug.ChangeState = FactoryState.Shipment;
}
-
- // features.ChangeWakeUp = (WakeUpMode)this.Wake_Up_Interval;
- // features.ChangeNumberOfLatWindows = this.LAT_Interval;
- // features.ChangeTransmissionInterval = this.Transmission_Intervall;
+
features.OpenMeteringTransmitionIntervalWMBus = this.OMS_Interval;
features.ChangeRadioId = (uint)this.Adresse;
features.ChangeMeterId = this.MeterId;
diff --git a/Common/Ui/Common.UI/Infrastructure/AppHost.cs b/Common/Ui/Common.UI/Infrastructure/AppHost.cs
index fc65ba07..e53cbe9f 100644
--- a/Common/Ui/Common.UI/Infrastructure/AppHost.cs
+++ b/Common/Ui/Common.UI/Infrastructure/AppHost.cs
@@ -12,7 +12,7 @@
internal class AppHost
{
public static readonly ILogger NLogger = CreateSIRTLogger();
- public static readonly SIRTHub SIRTHub = CreateSIRTFactory();
+ public static readonly SIRTHub SIRTHub = CreateSIRTHub();
public static string GetSetting(string key)
=> Appsettings.GetSetting(key);
@@ -44,7 +44,7 @@
return LogManager.GetLogger(name);
}
- private static SIRTHub CreateSIRTFactory()
+ private static SIRTHub CreateSIRTHub()
{
var sirtHub = new SIRTHub();
diff --git a/Common/Ui/Common.UI/Infrastructure/Appsettings.cs b/Common/Ui/Common.UI/Infrastructure/Appsettings.cs
index c60455f3..83d1ba9c 100644
--- a/Common/Ui/Common.UI/Infrastructure/Appsettings.cs
+++ b/Common/Ui/Common.UI/Infrastructure/Appsettings.cs
@@ -51,11 +51,5 @@
return settingValue;
}
-
- public static string[] GetSIRTComPorts()
- => GetSetting("SIRTComPorts")
- ?.Split(new[] { ';', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
- ?.Select(x => x?.Trim())
- ?.ToArray() ?? new string[0];
}
}
diff --git a/Common/Ui/Common.UI/Infrastructure/VMLocator.cs b/Common/Ui/Common.UI/Infrastructure/VMLocator.cs
index d2fc09b1..2191d59d 100644
--- a/Common/Ui/Common.UI/Infrastructure/VMLocator.cs
+++ b/Common/Ui/Common.UI/Infrastructure/VMLocator.cs
@@ -6,14 +6,14 @@
{
public SIRTBroadcastersVM SIRTBroadcasterVM => new SIRTBroadcastersVM();
- public EregisterHistoryVM EregisterHistoryVM { get; } = new EregisterHistoryVM();
+ public EregisterHistoryVM EregisterHistoryVM => new EregisterHistoryVM();
- public EregisterInitializeVM EregisterInitializeVM { get; } = new EregisterInitializeVM();
+ public EregisterInitializeVM EregisterInitializeVM => new EregisterInitializeVM();
- public EregisterFinalizeVM EregisterFinalizeVM { get; } = new EregisterFinalizeVM();
+ public EregisterFinalizeVM EregisterFinalizeVM => new EregisterFinalizeVM();
- public ManualProgrammingVM ManualProgrammingVM { get; } = new ManualProgrammingVM();
+ public ManualProgrammingVM ManualProgrammingVM => new ManualProgrammingVM();
- public SetMetrologyParametersVM SetMetrologyParametersVM { get; } = new SetMetrologyParametersVM();
+ public SetMetrologyParametersVM SetMetrologyParametersVM => new SetMetrologyParametersVM();
}
}
diff --git a/Common/Ui/Common.UI/MainWindow.xaml b/Common/Ui/Common.UI/MainWindow.xaml
index 7001b641..6a063a20 100644
--- a/Common/Ui/Common.UI/MainWindow.xaml
+++ b/Common/Ui/Common.UI/MainWindow.xaml
@@ -3,5 +3,5 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ShowsNavigationUI="False"
Source="Pages/EregisterInitialize.xaml"
- Title="PAM 146: Set metrology parameters">
+ Title="Eregister Programierung">
diff --git a/Common/Ui/Common.UI/Models/AuftragDbContext.cs b/Common/Ui/Common.UI/Models/AuftragDbContext.cs
index bcbedbfb..f32e83e9 100644
--- a/Common/Ui/Common.UI/Models/AuftragDbContext.cs
+++ b/Common/Ui/Common.UI/Models/AuftragDbContext.cs
@@ -98,7 +98,7 @@
.CreateCommand($@"
SELECT CAST((SELECT DISTINCT *
FROM VieweRegisterProgrammingParameters
- WHERE SharedId = @{nameof(sharedId)}
+ WHERE SharedId = @{nameof(sharedId)} AND Completed = 0
FOR XML PATH('{nameof(EregisterProgrammingParameters)}')
, ROOT('{nameof(EregisterProgrammingParametersList)}')) AS XML)")
.SetParameter(nameof(sharedId), sharedId)
diff --git a/Common/Ui/Common.UI/Pages/ManualProgramming.xaml b/Common/Ui/Common.UI/Pages/ManualProgramming.xaml
index 3571b1d5..f0f59563 100644
--- a/Common/Ui/Common.UI/Pages/ManualProgramming.xaml
+++ b/Common/Ui/Common.UI/Pages/ManualProgramming.xaml
@@ -1,41 +1,20 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Common/Ui/Common.UI/ViewModels/EregisterInitializeVM.cs b/Common/Ui/Common.UI/ViewModels/EregisterInitializeVM.cs
index 1db2eb1e..43d4a64d 100644
--- a/Common/Ui/Common.UI/ViewModels/EregisterInitializeVM.cs
+++ b/Common/Ui/Common.UI/ViewModels/EregisterInitializeVM.cs
@@ -15,7 +15,6 @@
using System.Timers;
using System.Windows;
using System.Windows.Input;
- using System.Windows.Media;
using SystemTimer = System.Timers.Timer;
public class EregisterInitializeVM : VM
diff --git a/Common/Ui/Common.UI/ViewModels/ManualProgrammingVM.cs b/Common/Ui/Common.UI/ViewModels/ManualProgrammingVM.cs
index 0f8204b2..f5e7dfa9 100644
--- a/Common/Ui/Common.UI/ViewModels/ManualProgrammingVM.cs
+++ b/Common/Ui/Common.UI/ViewModels/ManualProgrammingVM.cs
@@ -1,212 +1,43 @@
namespace Common.UI.ViewModels
{
using Common.Hardware.SIRT;
- using Common.Hardware.SIRT.Tasks;
- using Common.Hardware.WaterMeter.eRegister;
- using Common.Hardware.WaterMeter.eRegister.Features;
- using Common.Hardware.WaterMeter.eRegister.Models;
using Common.UI.Infrastructure;
- using System;
using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Net.Http;
- using System.Reflection;
+ using System.Text.RegularExpressions;
using System.Threading.Tasks;
- using System.Windows.Input;
public class ManualProgrammingVM : VM
{
- public int? Frequency { get; set; } = 433;
-
- public uint? SerienNr { get; set; } = 22724224;
-
- public uint? Address { get; set; } = 319017454;
-
- private bool enabled = true;
- public bool IsEnabled
+ public ManualProgrammingVM()
{
- get => this.enabled;
- set => this.SetValue(x => x.enabled = value);
+ this.Messages = new SortedDictionary();
}
- public ICommand SetFactoryState => new Command(this.SetFactoryStateCommand);
+ public SortedDictionary Messages { get; }
- public ObservableCollection ItemsSource { get; set; } = new ObservableCollection();
-
- private void SetFactoryStateCommand()
+ internal override void ViewModel_Loaded(object _)
{
- this.InvokeAsync(() => this.IsEnabled = false);
+ AppHost.SIRTHub.MessageReceived += SirtHub_MessageReceived;
- Task.Factory.StartNew(async () =>
+ foreach (Match match in Regex.Matches(Appsettings.GetSetting("SIRTComPorts"), "[cC][oO][mM][0-9]+"))
{
- void WriteToLog(string message) => this.InvokeAsync(() => this.ItemsSource.Add(message));
-
- WriteToLog($"MHz| | {this.Frequency}");
- WriteToLog($"Adr| |esse: {this.Address}");
- WriteToLog($"Ser| |ienNr: {this.SerienNr}");
-
- var uriFormat = Appsettings.GetSetting("EncryptionKeisUrl");
- var httpClient = new HttpClient();
- var encryptionKey = default(byte[]);
-
- try
+ if (match.Success)
{
- using (var httpResponeMessage = await httpClient.GetAsync(string.Format(uriFormat, this.SerienNr)))
- {
- var content = await httpResponeMessage.Content.ReadAsStringAsync();
-
- if (httpResponeMessage?.IsSuccessStatusCode == true)
- {
- var _encryptionKey = content?.Trim('"');
- encryptionKey = _encryptionKey?.GetEncryptionKey();
- }
- else
- {
- WriteToLog("Feh| |ler beim Laden des Schlüssels!");
- }
- }
- }
- catch (Exception e)
- {
- WriteToLog(e.Message);
-
- return;
- }
-
- WriteToLog($"Enc| |ryption key: {BitConverter.ToString(encryptionKey)}");
-
- var task = new EregisterTask(this.Frequency.Value)
- {
- Timeout = 10_000,
- WakeUpCmd = true,
- DelPamSemi = true,
- WakeUpModul = true,
- RequestAddress = this.Address.Value,
- EncryptionKeyI = encryptionKey,
- Data = new ChangeFactoryState
- {
- FactoryState = FactoryState.Production
- }
- .Append(new ProvidePin
- {
- AuthLevel = AuthLevel.III
- })
- };
-
- void MessageReceived(byte[] bytes) => WriteToLog($"RX:| |{BitConverter.ToString(bytes)}");
-
- task.MessageReceived += MessageReceived;
-
- for (var i = 1; i <= 5 && task.State != SIRTTaskState.Completed && task.State != SIRTTaskState.Cancelled; i++)
- {
- if (AppHost.SIRTHub.Start(task))
- {
- WriteToLog($"---| |{i} -------------------------");
- WriteToLog($"TX:| |{task}");
-
- task.Wait();
- }
- }
-
- task.MessageReceived -= MessageReceived;
-
- WriteToLog($"---| |-----------------------------");
- WriteToLog($"ST:| |{task.State}");
-
- this.InvokeAsync(() => this.IsEnabled = true);
- });
- }
- }
-
- public class DynamicPropertyVM : VM
- {
- protected readonly Dictionary properties;
- protected readonly PropertyInfo propertyInfo;
- protected readonly object instance;
- protected readonly object value;
-
- public DynamicPropertyVM(object instance, PropertyInfo propertyInfo)
- {
- this.properties = new Dictionary();
- this.propertyInfo = propertyInfo;
- this.instance = instance;
-
- if (this.propertyInfo != null)
- {
- this.Name = this.propertyInfo.Name;
- this.value = Activator.CreateInstance(this.propertyInfo.PropertyType);
-
- if (this.value is Pam pam)
- {
- this.Name = $"{pam.CmdHex} - {this.Name}";
+ Task.Run(() => AppHost.SIRTHub.TryOpen(match.Value.ToUpper(), out var _1, out var _2));
}
}
}
- public event Action PropertyValueChanged;
-
- public string Name { get; }
-
- private bool selected;
- public bool Selected
+ protected override void ViewModel_Dispose()
{
- get => this.selected;
- set => this.SetValue(x =>
- {
- x.selected = value;
-
- var propertyValue = default(object);
-
- if (x.selected)
- {
- propertyValue = this.value;
- }
-
- this.propertyInfo.SetValue(this.instance, propertyValue);
- this.PropertyValueChanged?.Invoke();
- });
+ AppHost.SIRTHub.MessageReceived -= SirtHub_MessageReceived;
}
- public virtual IEnumerable GetAllProperties()
- => this.properties
- .Values
- .SelectMany(x => x.GetAllProperties())
- .Union(this.properties.Values)
- .OrderBy(x => x.Name);
- }
-
- public class DynamicTypeVM : DynamicPropertyVM
- {
- private readonly Type type;
-
- public DynamicTypeVM(object instance) : base(instance, null)
+ private void SirtHub_MessageReceived(SIRTMessage message)
{
- this.type = this.instance.GetType();
-
- foreach (var propertyInfo in this.type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
- {
- var pamAttribute = propertyInfo.GetCustomAttribute();
-
- if (pamAttribute is null)
- {
- continue;
- }
-
- var dynamicProperty = new DynamicPropertyVM(this.instance, propertyInfo);
-
- if (propertyInfo.PropertyType == typeof(EregisterDebugFeatures))
- {
- var propertyInstance = new EregisterDebugFeatures();
-
- propertyInfo.SetValue(this.instance, propertyInstance);
-
- dynamicProperty = new DynamicTypeVM(propertyInstance);
- }
-
- this.properties[propertyInfo.Name] = dynamicProperty;
- }
+ this.Messages[message.Address] = message;
+ this.NotifyPropertyChanged(nameof(this.Messages));
}
}
}