Files
laatzen/Common/OmniPlus/OMNIPruefung/ViewModels/Features/OMNIPlusVM.cs
T

126 lines
4.7 KiB
C#

namespace OMNIPruefung.ViewModels.Features
{
using OmniPlus;
using OmniPlus.Features;
using OmniPlus.Inspection;
using OMNIPruefung.Models;
using OMNIPruefung.ViewModels.Base;
using System;
using System.Collections.ObjectModel;
using System.Windows;
public class OMNIPlusVM : VM<OMNIPlusVM>
{
// TODO: save all in database
private readonly OmniDatabase database;
public OMNIPlusVM()
{
this.database = new OmniDatabase(Appsettings.Current.OmniDB);
this.Results = new ObservableCollection<Result>();
}
public ushort IntPart { get; internal set; }
public ushort Fraction { get; internal set; }
public byte Size { get; internal set; }
public byte Range { get; internal set; }
public sbyte FactoryCorrection { get; internal set; }
public ObservableCollection<Result> Results { get; }
internal void AddResult(string key, string value)
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
this.Results.Add(new Result
{
Key = key,
Value = value
});
}));
}
internal void Add(OmniPlus.Features.SystemParameters response)
{
if (response.Succeeded)
{
this.AddResult(nameof(response.VersionAndType), response.VersionAndType.Value);
this.AddResult(nameof(response.BuildInfo), response.BuildInfo.Value);
this.AddResult(nameof(response.BatteryVoltage), $"{(response.BatteryVoltage.Volts + 0.0001) / 1000:0.0000 V}");
this.AddResult(nameof(response.ManifacturingTime), $"{response.ManifacturingTime.DateTime:dd.MM.yyyy}");
this.AddResult(nameof(response.SystemTime), $"{response.SystemTime.DateTime:dd.MM.yyyy}");
this.AddResult(nameof(response.RebootsCount), $"{response.RebootsCount}");
this.AddResult(nameof(response.FactorySealed), $"{response.FactorySealed}");
}
}
internal void Add(InputVolume response)
{
this.Size = response.Size;
this.Range = response.Range;
this.IntPart = response.IntPartFull;
this.Fraction = response.Fraction;
this.AddResult(nameof(response.Size), $"{response.Size}");
this.AddResult(nameof(response.Range), $"{response.Range}");
this.AddResult(nameof(response.Direction), $"{response.Direction}");
this.AddResult(nameof(response.IntPart), $"{response.IntPart}");
this.AddResult(nameof(response.Fraction), $"{response.Fraction}");
}
internal void Add(OmniPlusTestPoint pp)
{
this.AddResult("", $"");
this.AddResult("Test point:", $"{pp.Rotations}/{pp.Duration:0}");
this.AddResult("Volume", $"{pp.RequiredFlowM3H:0.00000000 m³/h}");
this.AddResult("Validation frame", $"{pp.MinDiff:0.00}% - {pp.MaxDiff:0.00}%");
}
internal void Add(OmniPlusTest test)
{
this.AddResult("Test result:", $"{test.Rotations:0}/{test.Duration:0.0000}");
this.AddResult("Meter volume", $"{test.MeterFlowM3S:0.00000000 m³}");
this.AddResult("Reference volume", $"{test.ReferenceFlowM3S:0.00000000 m³}");
this.AddResult("Deviation", $"{test.DifferencePercentage():0.00}%");
}
internal void Add(ConfigurationParameters response)
{
this.AddResult(nameof(response.ProgrammableID), response.ProgrammableID.Value);
this.AddResult(nameof(response.FactoryID), response.FactoryID.Value);
this.AddResult(nameof(response.ReadingDigits), $"{response.ReadingDigits.Count}");
this.AddResult(nameof(response.Readings), response.Readings.Value);
this.AddResult("Optional Uni-Dir-Fields", response.OptionalUniDirFields.Value);
this.AddResult("Alarm persistence", $"{response.AlarmPersistenceDays:0 days}");
this.AddResult("Data log interval", $"{response.DataLogIntervalMins:0 min.}");
this.AddResult(nameof(response.DeviceID), response.DeviceID.Value);
}
internal void AddFactoryCorrection(double value)
{
this.FactoryCorrection = (sbyte)(value * 10);
this.AddResult("Correction", $"{value:0.00} %");
}
}
public class Result
{
public string Key { get; set; }
public string Value { get; set; }
}
public class Property
{
public string Key { get; set; }
public string Value { get; set; }
}
}