OMNI latest:

This commit is contained in:
Stoyan Zlatev
2023-12-05 10:46:06 +01:00
parent e83163bb5d
commit 3f49a6d0a7
14 changed files with 334 additions and 48 deletions
+2 -1
View File
@@ -57,7 +57,7 @@
<Compile Include="Helpers\BooleanProgressBackgroundConverter.cs" />
<Compile Include="Helpers\BooleanVisibilityConverter.cs" />
<Compile Include="Models\Appsettings.cs" />
<Compile Include="ViewModels\Content\OMNIPlus.cs" />
<Compile Include="ViewModels\Features\OMNIPlus.cs" />
<Compile Include="ViewModels\Base\Command.cs" />
<Compile Include="ViewModels\Base\Command[T].cs" />
<Compile Include="ViewModels\Base\VM[T].cs" />
@@ -66,6 +66,7 @@
<Compile Include="ViewModels\Content\EOLContentVM.cs" />
<Compile Include="ViewModels\Content\ExchangeHubContentVM.cs" />
<Compile Include="ViewModels\Content\MainContentVM.cs" />
<Compile Include="ViewModels\Features\OMNISysParameters.cs" />
<Compile Include="ViewModels\NodeVM.cs" />
<Compile Include="ViewModels\Options\COMOptionVM.cs" />
<Compile Include="ViewModels\Options\EOLOptionVM.cs" />
@@ -8,5 +8,12 @@
protected void NotifyPropertyChanged(string property)
=> this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
protected void Set<T>(ref T property, T value, string propertyName)
{
property = value;
this.NotifyPropertyChanged(propertyName);
}
}
}
@@ -4,8 +4,8 @@
using System.Threading.Tasks;
using OmniPlus;
using OMNIPruefung.Models;
using OMNIPruefung.ViewModels.Base;
using OMNIPruefung.ViewModels.Features;
using OMNIPruefung.ViewModels.Options;
public class COMContentVM : ContentVM
@@ -33,15 +33,15 @@
}
}
private bool? completed;
public bool? Completed
private bool running;
public bool Running
{
get => this.completed;
get => this.running;
set
{
this.completed = value;
this.running = value;
this.NotifyPropertyChanged(nameof(this.Completed));
this.NotifyPropertyChanged(nameof(this.Running));
}
}
@@ -129,6 +129,7 @@
internal Task PrepareConnection()
{
this.cancellationTokenSource?.Cancel();
this.cancellationTokenSource = new CancellationTokenSource();
this.currentTask = Task.Factory
@@ -136,8 +137,8 @@
{
this.connection = new OmniPlusConnection(this.PortName);
this.Connected = this.connection.ConnectIrda();
this.State = $"Mit IRDA verbunden ...";
this.Running = this.Connected;
}, this.cancellationTokenSource.Token);
@@ -146,6 +147,7 @@
internal Task ReadSystemParameters()
{
this.cancellationTokenSource?.Cancel();
this.cancellationTokenSource = new CancellationTokenSource();
this.currentTask = Task.Factory
@@ -153,13 +155,14 @@
{
if (this.Connected)
{
this.Meter.SystemParameters = this.connection.ViewSystemParameters();
this.State = this.Meter.SystemParameters.BuildInfo.Value;
this.Header = this.Meter.SystemParameters.BuildInfo.Value;
this.Meter.SysParameters = this.connection.ViewSystemParameters();
this.Header = this.Meter.SysParameters.BuildInfo;
this.State = "Systemeigenschaften eingelesen";
this.Progress += 10;
}
else
{
this.State = $"Lesen der System eigenschaften ...";
this.State = $"Lesen der Systemeigenschaften fehlgeschlagen";
}
}, this.cancellationTokenSource.Token);
@@ -15,6 +15,7 @@
public class EOLContentVM : ContentVM
{
private readonly EOLSettings appsettings;
// private readonly OmniPlusDatabase
public EOLContentVM() : base()
{
@@ -1,20 +0,0 @@
namespace OMNIPruefung.Models
{
using OmniPlus.Features;
using OMNIPruefung.ViewModels.Base;
public class OMNIPlusVM : VM<OMNIPlusVM>
{
private SystemParameters systemParameters;
public SystemParameters SystemParameters
{
get => this.systemParameters;
set
{
this.systemParameters = value;
this.NotifyPropertyChanged(nameof(this.SystemParameters));
}
}
}
}
@@ -0,0 +1,33 @@
namespace OMNIPruefung.ViewModels.Features
{
using OMNIPruefung.ViewModels.Base;
using System.Collections.Generic;
public class OMNIPlusVM : VM<OMNIPlusVM>
{
private OMNISysParameters sysParameters;
public OMNISysParameters SysParameters
{
get => this.sysParameters;
set
{
this.sysParameters = value;
this.NotifyPropertyChanged(nameof(this.SysParameters));
}
}
public Dictionary<string, Dictionary<string, string>> Properties
{
get
{
var dictionary = new Dictionary<string, Dictionary<string, string>>();
dictionary["System parameters:"] = this.SysParameters.ToDictionary();
return dictionary;
}
}
}
}
@@ -0,0 +1,161 @@
namespace OMNIPruefung.ViewModels.Features
{
using OmniPlus.Features;
using OMNIPruefung.ViewModels.Base;
using System;
using System.Collections.Generic;
public class OMNISysParameters : VM<OMNIPlusVM>
{
private SystemParameters parameters;
public OMNISysParameters(SystemParameters parameters)
{
this.parameters = parameters;
if (this.parameters is null)
{
this.parameters = new SystemParameters();
}
this.BuildInfo = this.parameters.BuildInfo.Value;
this.Manifactured = this.parameters.ManifacturingTime.DateTime;
this.Timedrift = this.parameters.SystemTime.DateTime;
this.Reboots = this.parameters.RebootsCount;
this.Version = this.parameters.VersionAndType.Value;
var voltage = Math.Max(this.parameters.BatteryVoltage.Volts, (ushort)1);
this.Voltage = (double)voltage / 1000D;
this.ADCCounts = this.parameters.BatteryVoltage.ADCCount;
this.Sealed = this.parameters.FactorySealed;
this.IsValid = this.parameters.IsValid;
}
private string buildInfo;
public string BuildInfo
{
get => this.buildInfo;
set
{
this.buildInfo = value;
this.NotifyPropertyChanged(nameof(this.BuildInfo));
}
}
private DateTime manifactured;
public DateTime Manifactured
{
get => this.manifactured;
set
{
this.manifactured = value;
this.NotifyPropertyChanged(nameof(this.Manifactured));
}
}
private DateTime timedrift;
public DateTime Timedrift
{
get => this.timedrift;
set
{
this.timedrift = value;
this.NotifyPropertyChanged(nameof(this.Timedrift));
}
}
private byte reboots;
public byte Reboots
{
get => this.reboots;
set
{
this.reboots = value;
this.NotifyPropertyChanged(nameof(this.Reboots));
}
}
private string version;
public string Version
{
get => this.version;
set
{
this.version = value;
this.NotifyPropertyChanged(nameof(this.Version));
}
}
private double voltage;
public double Voltage
{
get => this.voltage;
set
{
this.voltage = value;
this.NotifyPropertyChanged(nameof(this.Voltage));
}
}
private uint adc;
public uint ADCCounts
{
get => this.adc;
set
{
this.adc = value;
this.NotifyPropertyChanged(nameof(this.ADCCounts));
}
}
private bool @sealed;
public bool Sealed
{
get => this.@sealed;
set
{
this.@sealed = value;
this.NotifyPropertyChanged(nameof(this.Sealed));
}
}
private bool isvalid;
public bool IsValid
{
get => this.isvalid;
set
{
this.isvalid = value;
this.NotifyPropertyChanged(nameof(this.IsValid));
}
}
public Dictionary<string, string> ToDictionary()
{
var dictionary = new Dictionary<string, string>();
dictionary["Version & Type: "] = this.Version;
dictionary["Build info: "] = this.BuildInfo;
dictionary["Manifactured: "] = $"{this.Manifactured:yyyy-MM-dd}";
dictionary["Last update: "] = $"{this.Timedrift:yyyy-MM-dd HH:mm:ss}";
dictionary["Battery voltage: "] = $"{this.Voltage:0.000}V";
dictionary["ADC counts: "] = $"{this.ADCCounts}";
dictionary["Reboots count: "] = $"{this.Reboots}";
dictionary["Factory sealed: "] = $"{this.Sealed}";
return dictionary;
}
public static implicit operator OMNISysParameters(SystemParameters parameters)
=> new OMNISysParameters(parameters);
}
}
@@ -25,10 +25,16 @@
set => this.NotifyPropertyChanged(nameof(this.Progress));
}
public bool? Completed
public bool Running
{
get => this.parent.Completed;
set => this.NotifyPropertyChanged(nameof(this.Completed));
get => this.parent.Running;
set => this.NotifyPropertyChanged(nameof(this.Running));
}
public bool Connected
{
get => this.parent.Connected;
set => this.NotifyPropertyChanged(nameof(this.Connected));
}
public bool Visible
@@ -46,7 +52,8 @@
{
base.Parent_PropertyChanged(sender, args);
this.NotifyPropertyChanged(nameof(this.Completed));
this.NotifyPropertyChanged(nameof(this.Connected));
this.NotifyPropertyChanged(nameof(this.Running));
this.NotifyPropertyChanged(nameof(this.Nr));
this.NotifyPropertyChanged(nameof(this.Progress));
this.NotifyPropertyChanged(nameof(this.State));
@@ -1,6 +1,28 @@
<Grid x:Class="OMNIPruefung.Views.Content.COMContent"
<ScrollViewer x:Class="OMNIPruefung.Views.Content.COMContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="White">
<Label Content="{Binding Header}" />
</Grid>
<ItemsControl ItemsSource="{Binding Meter.Properties}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Label Content="{Binding Path=Key}" Padding="21, 3" FontWeight="Bold"/>
<ItemsControl ItemsSource="{Binding Path=Value}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Content="{Binding Path=Key}" Padding="42, 3, 2, 3" Width="200" FontWeight="Bold"/>
<Label Content="{Binding Path=Value}" Padding="3"/>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
@@ -2,7 +2,7 @@
{
using System.Windows.Controls;
public partial class COMContent : Grid
public partial class COMContent : ScrollViewer
{
public COMContent()
{
@@ -61,11 +61,11 @@
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Foreground="{Binding Completed, Converter={StaticResource BooleanProgress}}"
Foreground="{Binding Running, Converter={StaticResource BooleanProgress}}"
Value="{Binding Progress}"
BorderBrush="Gray"
Background="WhiteSmoke"
BorderBrush="WhiteSmoke"
BorderThickness="1"
Opacity="0.1"
Margin="0, 5"
Padding="0"
Height="8"/>
@@ -34,7 +34,7 @@
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Visibility="{Binding Connected, Converter={StaticResource BooleanVisibility}}"
Foreground="{Binding Completed, Converter={StaticResource BooleanProgress}}"
Foreground="{Binding Running, Converter={StaticResource BooleanProgress}}"
Background="Transparent"
Value="{Binding Progress}"
BorderThickness="0"
@@ -41,6 +41,8 @@
this.BatteryVoltage.ADCCount = BitConverter.ToUInt32(this.bytes, 54);
this.FactorySealed = this.bytes[58] == 1;
this.ValidateParameters();
}
public BuildInfo BuildInfo { get; set; }
@@ -56,5 +58,73 @@
public BatteryVoltage BatteryVoltage { get; set; }
public bool FactorySealed { get; set; }
public bool IsValid { get; set; }
private void ValidateParameters()
{
this.IsValid = !this.FactorySealed;
if (!this.IsValid)
{
return;
}
var firmwareTokens = this.VersionAndType
?.Value
?.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries)
?? new string[2];
var versionString = string.Empty;
if (firmwareTokens?.Length > 0 && firmwareTokens[0]?.Length > 0)
{
versionString = firmwareTokens[0].Substring(1);
}
this.IsValid = double.TryParse(versionString, out var version) && version >= 1.23;
if (!this.IsValid)
{
return;
}
var typeString = string.Empty;
if (firmwareTokens?.Length > 1 && firmwareTokens[1]?.Length > 0)
{
typeString = firmwareTokens[1].ToUpper();
}
this.IsValid = typeString == "OMNI-01" || typeString == "OMNI-02";
if (!this.IsValid)
{
return;
}
this.IsValid = 3.19 <= this.BatteryVoltage.Volts && this.BatteryVoltage.Volts <= 3.75;
if (!this.IsValid)
{
return;
}
this.IsValid = this.RebootsCount != 0xFF;
if (!this.IsValid)
{
return;
}
this.IsValid = Math.Abs((DateTime.UtcNow - this.SystemTime.DateTime).Seconds) <= 700;
if (!this.IsValid)
{
return;
}
this.IsValid = Math.Abs((DateTime.UtcNow - this.ManifacturingTime.DateTime).Seconds) <= 365;
}
}
}
+2 -1
View File
@@ -1,4 +1,5 @@
using OmniPlus.Features;
using System;
using System.Data.SqlClient;
@@ -93,7 +94,7 @@ namespace OmniPlus
sqlCommand.ExecuteNonQuery();
sqlCommand.Parameters.Clear();
}
catch (System.Exception e)
catch (Exception e)
{
}