wake up, test mode, com settings

This commit is contained in:
Stoyan Zlatev
2025-06-12 11:03:05 +02:00
parent 0f0bc7af43
commit 45a14354d5
8 changed files with 401 additions and 130 deletions
+1 -1
View File
@@ -126,7 +126,7 @@
<Version>8.3.0</Version> <Version>8.3.0</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.SharePointOnline.CSOM"> <PackageReference Include="Microsoft.SharePointOnline.CSOM">
<Version>16.1.26017.12000</Version> <Version>16.1.26121.12000</Version>
</PackageReference> </PackageReference>
<PackageReference Include="NUnit"> <PackageReference Include="NUnit">
<Version>4.3.2</Version> <Version>4.3.2</Version>
+22 -24
View File
@@ -1,43 +1,41 @@
namespace CommonConsole namespace CommonConsole
{ {
using System;
public static class Program public static class Program
{ {
public static void Main() public static void Main()
{ {
var x = (625L * 65536) | 0x80_00_00_00; ////var x = (625L * 65536) | 0x80_00_00_00;
Console.WriteLine((int)x); ////Console.WriteLine((int)x);
//var semiBytes25747925 = new byte[] { 0x08, 0x03, 0x12, 0x6B, 0x78, 0x41, 0x00, 0x00, 0x01, 0xF4, 0x00, 0x00, 0x83, 0x0C, 0x00, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x13, 0x01, 0x88, 0xE1, 0xD5, 0x07, 0x0E, 0x10, 0xEC, 0x56, 0x13, 0xDA, 0x4C, 0x00, 0x00, 0x7F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x1E, 0x00, 0x03, 0x01, 0x2F, 0xBE, 0xCA, 0x47, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0xEF, 0xA6 }; ////var semiBytes25747925 = new byte[] { 0x08, 0x03, 0x12, 0x6B, 0x78, 0x41, 0x00, 0x00, 0x01, 0xF4, 0x00, 0x00, 0x83, 0x0C, 0x00, 0x0F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x13, 0x01, 0x88, 0xE1, 0xD5, 0x07, 0x0E, 0x10, 0xEC, 0x56, 0x13, 0xDA, 0x4C, 0x00, 0x00, 0x7F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x03, 0x00, 0x1E, 0x00, 0x03, 0x01, 0x2F, 0xBE, 0xCA, 0x47, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0xEF, 0xA6 };
//var semi25747925 = new SEMI(semiBytes25747925, 868, 0); ////var semi25747925 = new SEMI(semiBytes25747925, 868, 0);
//var debugBytes25747925 = new byte[] { 0x0B, 0x10, 0x12, 0x6B, 0x78, 0x41, 0x00, 0x0C, 0x11, 0x0B, 0x11, 0x08, 0x04, 0x02, 0x7C, 0x4C, 0x12, 0x84, 0x15, 0x00, 0x66, 0x00, 0x35, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4A, 0x8F, 0xD2, 0x02, 0x01, 0x01, 0x16, 0x00, 0x1B, 0x02, 0x71, 0x00, 0x00, 0x82, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xA0, 0xA5 }; ////var debugBytes25747925 = new byte[] { 0x0B, 0x10, 0x12, 0x6B, 0x78, 0x41, 0x00, 0x0C, 0x11, 0x0B, 0x11, 0x08, 0x04, 0x02, 0x7C, 0x4C, 0x12, 0x84, 0x15, 0x00, 0x66, 0x00, 0x35, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4A, 0x8F, 0xD2, 0x02, 0x01, 0x01, 0x16, 0x00, 0x1B, 0x02, 0x71, 0x00, 0x00, 0x82, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0xA0, 0xA5 };
//var debug25747925 = new DEBUG(debugBytes25747925, 0); ////var debug25747925 = new DEBUG(debugBytes25747925, 0);
//var siteUrl = "https://1xylemeur.sharepoint.com/sites/geckoSrc/customer/Pub_CSD/Forms/AllItems.aspx"; ////var siteUrl = "https://1xylemeur.sharepoint.com/sites/geckoSrc/customer/Pub_CSD/Forms/AllItems.aspx";
//var userName = "stoyan.zlatev@xylem.com"; ////var userName = "stoyan.zlatev@xylem.com";
//var password = "****************"; ////var password = "****************";
//var securePassword = new SecureString(); ////var securePassword = new SecureString();
//foreach (var c in password) ////foreach (var c in password)
//{ ////{
// securePassword.AppendChar(c); //// securePassword.AppendChar(c);
//} ////}
//using (var context = new ClientContext(siteUrl)) ////using (var context = new ClientContext(siteUrl))
//{ ////{
// context.Credentials = new SharePointOnlineCredentials(userName, securePassword); //// context.Credentials = new SharePointOnlineCredentials(userName, securePassword);
// var web = context.Web; //// var web = context.Web;
// context.Load(web); //// context.Load(web);
// context.ExecuteQuery(); //// context.ExecuteQuery();
// Console.WriteLine("Site Title: " + web.Title); //// Console.WriteLine("Site Title: " + web.Title);
//} ////}
} }
@@ -1 +1 @@
8cb55c312de586b683d72cf58c13e2801d10e14b767777d98338d3e1473a1213 89102b0142e574de38a9f47d370f3334e5e6c268
@@ -1,17 +1,15 @@
namespace Common.Hardware.WaterMeter.eRegister.Features namespace Common.Hardware.WaterMeter.eRegister.Features
{ {
using Common.Hardware.SIRT;
public class ActivateMetrologyTestMode : Pam public class ActivateMetrologyTestMode : Pam
{ {
public ActivateMetrologyTestMode() : base(3, ActivateMetrologyTestMode) public ActivateMetrologyTestMode() : base(3, ActivateMetrologyTestMode)
{ {
} }
public ushort Mode public byte Hours
{ {
get => this.bytes.ToUInt16BE(1); get => this.bytes[2];
set => value.GetBytesBE().CopyTo(this.bytes, 1); set => this.bytes[2] = value;
} }
} }
} }
+38 -38
View File
@@ -1,41 +1,41 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" />
</startup> </startup>
<appSettings> <appSettings>
<add key="ConnectionString" value="Server=SLASQL01.emea.sensus.net; Database=Testreplikation; User ID=sa; Password=sqlserver;" /> <add key="ConnectionString" value="Server=SLASQL01.emea.sensus.net; Database=Testreplikation; User ID=sa; Password=sqlserver;" />
<!--<add key="ConnectionString" value="Server=SLASQL01.emea.sensus.net; Database=Auftrag; User ID=sa; Password=sqlserver;" />--> <!--<add key="ConnectionString" value="Server=SLASQL01.emea.sensus.net; Database=Auftrag; User ID=sa; Password=sqlserver;" />-->
<add key="EncryptionKeisUrl" value="http://sla12iis01.emea.sensus.net/LaaProductionWeb/api/eregister/radiokey/byserialno/{0}" /> <add key="EncryptionKeisUrl" value="http://sla12iis01.emea.sensus.net/LaaProductionWeb/api/eregister/radiokey/byserialno/{0}" />
<add key="SIRTComPorts" value="COM6,COM8" /> <add key="SIRTComPorts" value="COM6,COM8" />
<add key="PSNR" value="2001" /> <add key="PSNR" value="2001" />
</appSettings> </appSettings>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" /> <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.2.0" newVersion="6.0.2.0" /> <bindingRedirect oldVersion="0.0.0.0-6.0.2.0" newVersion="6.0.2.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="SQLitePCLRaw.core" publicKeyToken="1488e028ca7ab535" culture="neutral" /> <assemblyIdentity name="SQLitePCLRaw.core" publicKeyToken="1488e028ca7ab535" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.11.2622" newVersion="2.1.11.2622" /> <bindingRedirect oldVersion="0.0.0.0-2.1.11.2622" newVersion="2.1.11.2622" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="SQLitePCLRaw.batteries_v2" publicKeyToken="8226ea5df37bcae9" culture="neutral" /> <assemblyIdentity name="SQLitePCLRaw.batteries_v2" publicKeyToken="8226ea5df37bcae9" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.11.2622" newVersion="2.1.11.2622" /> <bindingRedirect oldVersion="0.0.0.0-2.1.11.2622" newVersion="2.1.11.2622" />
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
</configuration> </configuration>
@@ -14,11 +14,35 @@
try try
{ {
settingValue = ConfigurationManager var configuration = ConfigurationManager.OpenExeConfiguration(dll);
.OpenExeConfiguration(dll) var settings = configuration.AppSettings.Settings;
.AppSettings
.Settings[settingKey] settingValue = settings[settingKey]?.Value;
.Value; }
catch (Exception e)
{
AppHost.NLogger.Error(e);
}
return settingValue;
}
public static string SetSetting(string settingKey, string settingValue)
{
try
{
var configuration = ConfigurationManager.OpenExeConfiguration(dll);
var settings = configuration.AppSettings.Settings;
if (!settings.AllKeys.Any(x => x == settingKey))
{
settings.Add(settingKey, string.Empty);
}
settings[settingKey].Value = settingValue;
configuration.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
} }
catch (Exception e) catch (Exception e)
{ {
@@ -55,17 +55,31 @@
Grid.Column="1" Grid.Column="1"
Orientation="Vertical"> Orientation="Vertical">
<TextBlock FontWeight="Bold" <TextBlock FontWeight="Bold"
Text="COM Port" Text="Activate SIRT"
Padding="5 3 5 0" /> Padding="5 3 5 0"/>
<ComboBox ItemsSource="{Binding PortNames}" <Grid Margin="3 3 3 0">
Margin="3 3 3 0" <Grid.ColumnDefinitions>
Padding="5 7" <ColumnDefinition Width="*" />
SelectedValue="{Binding PortName}" /> <ColumnDefinition Width="3" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Button Command="{Binding ActivateSIRTCommand}"
CommandParameter="{Binding SIRT_433}"
Content="433MHz"
Cursor="Hand"
Grid.Column="0"
Padding="5" />
<Button Command="{Binding ActivateSIRTCommand}"
CommandParameter="{Binding SIRT_868}"
Content="868MHz"
Cursor="Hand"
Grid.Column="2"
Padding="5" />
</Grid>
<TextBlock Foreground="Gray" <TextBlock Foreground="Gray"
FontSize="11"
FontStyle="Italic" FontStyle="Italic"
Text="{Binding SIRTInfo}" Text="{Binding SIRTInfo}"
Padding="5 0" /> Padding="5 3 5 0" />
<TextBlock FontWeight="Bold" <TextBlock FontWeight="Bold"
Text="Address" Text="Address"
Padding="5 3 5 0" /> Padding="5 3 5 0" />
@@ -119,7 +133,7 @@
SelectedValue="{Binding DecimalPlaces}" /> SelectedValue="{Binding DecimalPlaces}" />
<CheckBox Content="Use C&amp;I rules" <CheckBox Content="Use C&amp;I rules"
IsChecked="{Binding UseCandIRules}" IsChecked="{Binding UseCandIRules}"
Margin="3 3 3 0" Margin="3 5 3 0"
Padding="5" Padding="5"
VerticalContentAlignment="Center"/> VerticalContentAlignment="Center"/>
<TextBlock FontWeight="Bold" <TextBlock FontWeight="Bold"
@@ -128,16 +142,126 @@
<TextBox Margin="3 3 3 0" <TextBox Margin="3 3 3 0"
Padding="5" Padding="5"
Text="{Binding VPPLED}" /> Text="{Binding VPPLED}" />
<CheckBox Content="Wake up &amp; stay awake"
IsChecked="{Binding StayAwake}"
Margin="3 5 3 0"
Padding="5"
VerticalContentAlignment="Center"/>
<TextBlock Foreground="Gray"
FontSize="11"
FontStyle="Italic"
Text="{Binding ModeInfo}"
Margin="0 5 0 0"
Padding="5 0" />
<Button Command="{Binding SetMetrologyParametersCommand}" <Button Command="{Binding SetMetrologyParametersCommand}"
Content="Set Metrolgy Parameters" Content="Set Metrolgy Parameters"
Cursor="Hand" Cursor="Hand"
Margin="3 5 3 0" Margin="3 1 3 0"
Padding="5" /> Padding="5" />
<Label BorderBrush="DarkBlue"
BorderThickness="0 0 0 1"
FontWeight="Bold"
FontStyle="Italic"
Foreground="DarkBlue"
Content="Open settings"
Cursor="Hand"
Padding="5 3 5 0"
Margin="3 3 3 0"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Left">
<Label.InputBindings>
<MouseBinding MouseAction="LeftClick" Command="{Binding SwitchSettingsVisibilityCommand}" />
</Label.InputBindings>
</Label>
<TextBlock FontSize="13" <TextBlock FontSize="13"
FontWeight="Bold" FontWeight="Bold"
Foreground="{Binding Status, Converter={StaticResource TaskStateToFG}}" Foreground="{Binding Status, Converter={StaticResource TaskStateToFG}}"
Text="{Binding Status}" Text="{Binding Status}"
Padding="5 3 5 0" /> Padding="5 3 5 0" />
</StackPanel> </StackPanel>
<Border Background="#20000000"
BorderThickness="0"
Grid.Column="0"
Grid.ColumnSpan="2"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Visibility="{Binding AreSettingsVisible, Converter={StaticResource BooleanToVisibility}, FallbackValue=Collapsed}">
<Border Background="White"
BorderBrush="LightGray"
BorderThickness="1"
CornerRadius="5"
Height="300"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Width="500">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Background="WhiteSmoke"
BorderBrush="LightGray"
BorderThickness="0 0 0 1"
CornerRadius="5"
Grid.Row="0">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock FontSize="13"
FontWeight="Bold"
Grid.Column="0"
HorizontalAlignment="Left"
Padding="10 0"
Text="Settings"
VerticalAlignment="Center"/>
<Button Background="Transparent"
BorderThickness="0"
Cursor="Hand"
Grid.Column="2"
Command="{Binding SwitchSettingsVisibilityCommand}">
<Path Data="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708"
Fill="Black"
Height="16"
Margin="10"
Stroke="Black"
Width="16" />
</Button>
</Grid>
</Border>
<StackPanel Grid.Row="1"
Margin="10"
Orientation="Vertical">
<TextBlock FontWeight="Bold"
Margin="0 10 0 0"
Text="COM port for SIRT 433"
Padding="5 3 5 0" />
<TextBox Margin="0 1 0 0"
Padding="5"
Text="{Binding SIRT_433}" />
<TextBlock FontWeight="Bold"
Margin="0 10 0 0"
Text="COM port for SIRT 868"
Padding="5 3 5 0" />
<TextBox Margin="0 1 0 0"
Padding="5"
Text="{Binding SIRT_868}" />
<TextBlock FontWeight="Bold"
Margin="0 10 0 0"
Text="Test mode time in hours: 0 - off, 1 - 72 on"
Padding="5 3 5 0" />
<TextBox Margin="0 1 0 0"
Padding="5"
Text="{Binding TestModeHours}" />
<Button Content="Save changes"
Cursor="Hand"
Margin="0 15 0 0"
Padding="5" />
</StackPanel>
</Grid>
</Border>
</Border>
</Grid> </Grid>
</Page> </Page>
@@ -12,10 +12,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Ports;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
@@ -25,14 +23,31 @@
private readonly Dictionary<string, PropertyVM> telegrams; private readonly Dictionary<string, PropertyVM> telegrams;
private readonly Dictionary<string, MeterSizeVM> meterSizes; private readonly Dictionary<string, MeterSizeVM> meterSizes;
private SIRTBroadcaster sirt;
private string portName;
private string sirtId;
private int frequency;
public SetMetrologyParametersVM() public SetMetrologyParametersVM()
{ {
AppHost.SIRTHub.Connected += this.SIRTHub_Connected; AppHost.SIRTHub.Connected += this.SIRTHub_Connected;
AppHost.SIRTHub.Disconnected += this.SIRTHub_Disconnected; AppHost.SIRTHub.Disconnected += this.SIRTHub_Disconnected;
this.SetMetrologyParametersCommand = new Command(this.SetMetrologyParametersCommandHandler); var hours = this.TestModeHours;
this.PortNames = SerialPort.GetPortNames(); if (hours == 0)
{
this.modeInfo = $"Test mode is off";
}
else
{
this.modeInfo = $"Test mode is on for {hours}h";
}
this.ActivateSIRTCommand = new Command<string>(this.ActivateSIRTCommandHandler);
this.SetMetrologyParametersCommand = new Command(this.SetMetrologyParametersCommandHandler);
this.SwitchSettingsVisibilityCommand = new Command(this.SwitchSettingsVisibilityCommandHandler);
this.meterSizes = SqlConnection this.meterSizes = SqlConnection
.CreateSqlConnection(Appsettings.GetSetting("ConnectionString")) .CreateSqlConnection(Appsettings.GetSetting("ConnectionString"))
.CreateCommand($@" .CreateCommand($@"
@@ -66,7 +81,6 @@
.ToDictionary(x => x.Title, x => x); .ToDictionary(x => x.Title, x => x);
this.MeterSizes = this.meterSizes.Keys.ToArray(); this.MeterSizes = this.meterSizes.Keys.ToArray();
this.DecimalPlacesSource = Enum.GetNames(typeof(DecimalPointLocations)); this.DecimalPlacesSource = Enum.GetNames(typeof(DecimalPointLocations));
this.telegrams = new Dictionary<string, PropertyVM>(); this.telegrams = new Dictionary<string, PropertyVM>();
foreach (var property in typeof(SEMI).GetProperties(BindingFlags.Public | BindingFlags.Instance)) foreach (var property in typeof(SEMI).GetProperties(BindingFlags.Public | BindingFlags.Instance))
@@ -129,12 +143,11 @@
set => this.SetValue(x => x.sirtInfo = value); set => this.SetValue(x => x.sirtInfo = value);
} }
private SIRTBroadcaster sirt; private string modeInfo;
private string portName; public string ModeInfo
public string PortName
{ {
get => this.portName; get => this.modeInfo;
set => this.SetPortName(value); set => this.SetValue(x => x.modeInfo = value);
} }
private uint address; private uint address;
@@ -226,9 +239,65 @@
set => this.SetValue(x => x.status = value); set => this.SetValue(x => x.status = value);
} }
private bool areSettingsVisible;
public bool AreSettingsVisible
{
get => this.areSettingsVisible;
set => this.SetValue(x => x.areSettingsVisible = value);
}
private bool stayAwake;
public bool StayAwake
{
get => this.stayAwake;
set => this.SetValue(x => x.stayAwake = value);
}
private byte testModeHours;
public byte TestModeHours
{
get
{
var testModeHoursString = Appsettings.GetSetting(nameof(this.TestModeHours));
_ = byte.TryParse($"{testModeHoursString}", out this.testModeHours);
return this.testModeHours;
}
set => this.SetValue(x =>
{
this.testModeHours = Math.Max(Math.Min(value, (byte)72), (byte)0);
if (this.testModeHours == 0)
{
this.modeInfo = $"Test mode is off";
}
else
{
this.modeInfo = $"Test mode is on for {this.testModeHours}h";
}
Appsettings.SetSetting(nameof(this.TestModeHours), $"{this.testModeHours}");
});
}
public string SIRT_433
{
get => Appsettings.GetSetting(nameof(this.SIRT_433));
set => Appsettings.SetSetting(nameof(this.SIRT_433), value);
}
public string SIRT_868
{
get => Appsettings.GetSetting(nameof(this.SIRT_868));
set => Appsettings.SetSetting(nameof(this.SIRT_868), value);
}
public ICommand ActivateSIRTCommand { get; }
public ICommand SetMetrologyParametersCommand { get; } public ICommand SetMetrologyParametersCommand { get; }
public string[] PortNames { get; } public ICommand SwitchSettingsVisibilityCommand { get; }
public string[] MeterSizes { get; } public string[] MeterSizes { get; }
@@ -238,32 +307,30 @@
public string[] MessurementUnitsSource { get; } public string[] MessurementUnitsSource { get; }
private void SetPortName(string value) private void ActivateSIRTCommandHandler(string portName)
=> this.SetValue(vm => {
Task.Run(() =>
{ {
vm.portName = value; this.InvokeAsync(() =>
Task.Run(() =>
{ {
this.InvokeAsync(() => this.SIRTInfo = $"Disconnecting {this.portName} ...";
{ AppHost.SIRTHub.Close(this.portName);
vm.SIRTInfo = $"Disconnecting {sirt.PortName} ..."; });
AppHost.SIRTHub.Close(vm.sirt?.PortName); })
}); .ContinueWith(_ =>
}) {
.ContinueWith(_ => this.InvokeAsync(() =>
{ {
this.InvokeAsync(() => this.SIRTInfo = $"Connecting {portName} ...";
{ AppHost.SIRTHub.TryOpen(portName, out this.sirtId, out this.frequency);
vm.SIRTInfo = $"Connecting {vm.portName} ...";
AppHost.SIRTHub.TryOpen(vm.PortName, out var _1, out var _2);
});
}); });
}); });
}
private void SIRTHub_Connected(SIRTBroadcaster sirt) private void SIRTHub_Connected(SIRTBroadcaster sirt)
{ {
this.sirt = sirt; this.sirt = sirt;
this.portName = this.sirt.PortName;
this.SIRTInfo = $"{this.sirt.Id}|{this.sirt.Frequency}Mhz"; this.SIRTInfo = $"{this.sirt.Id}|{this.sirt.Frequency}Mhz";
} }
@@ -337,6 +404,11 @@
{ {
this.Status = null; this.Status = null;
if (this.sirt is null)
{
this.Status = "No SIRT is activated";
}
foreach (var property in this.telegrams.Values) foreach (var property in this.telegrams.Values)
{ {
property.Value = null; property.Value = null;
@@ -350,23 +422,6 @@
DelPamSemi = true, DelPamSemi = true,
WakeUpCmd = true, WakeUpCmd = true,
RequestAddress = this.Address, RequestAddress = this.Address,
Data = new SetMetrologyParameters
{
DecimalPoint = this.VPP < 700 ? DecimalPointLocations.Three : DecimalPointLocations.Two,
MeterSize = this.meterSizes.TryGetValue(this.MeterSize, out var ms) ? ms.Size : (byte)23,
FactoryCalibration = this.FactoryCalibration,
OffsetFactor = this.OffsetFactor,
OffsetTime = this.OffsetTime,
Units = Enum.TryParse<MessurementUnits>($"{this.Units}", out var units)
? units : Hardware.WaterMeter.eRegister.Features.MessurementUnits.Cubic_Meters,
UseCandIRules = this.UseCandIRules,
VppLED = this.vppLED * 65536,
Vpp = __vpp,
}
.Append(new ProvidePin
{
AuthLevel = AuthLevel.III
})
}; };
Task.Run(() => Task.Run(() =>
@@ -379,6 +434,18 @@
task.MessageReceived += this.Ertask_MessageReceived; task.MessageReceived += this.Ertask_MessageReceived;
task.StateChanged += StateChanged; task.StateChanged += StateChanged;
task.WakeUpModul = true;
task.Data = new ChangeWakeUp
{
WakeUpMode = this.StayAwake ? WakeUpMode.StayAwake : WakeUpMode.SleepAutoOn
}
.Append(new ProvidePin
{
AuthLevel = AuthLevel.II
});
task.SetPending();
while (task.State != SIRTTaskState.Completed && task.State != SIRTTaskState.Cancelled) while (task.State != SIRTTaskState.Completed && task.State != SIRTTaskState.Cancelled)
{ {
AppHost.SIRTHub.Start(task); AppHost.SIRTHub.Start(task);
@@ -390,7 +457,64 @@
} }
} }
task.Data = new OpticalTelegram().Append(new ProvidePin task.WakeUpModul = false;
task.Data = new SetMetrologyParameters
{
DecimalPoint = this.VPP < 700 ? DecimalPointLocations.Three : DecimalPointLocations.Two,
MeterSize = this.meterSizes.TryGetValue(this.MeterSize, out var ms) ? ms.Size : (byte)23,
FactoryCalibration = this.FactoryCalibration,
OffsetFactor = this.OffsetFactor,
OffsetTime = this.OffsetTime,
Units = Enum.TryParse<MessurementUnits>($"{this.Units}", out var units) ? units : MessurementUnits.Cubic_Meters,
UseCandIRules = this.UseCandIRules,
VppLED = this.vppLED * 65536,
Vpp = __vpp,
}
.Append(new ProvidePin
{
AuthLevel = AuthLevel.III
});
task.SetPending();
while (task.State != SIRTTaskState.Completed && task.State != SIRTTaskState.Cancelled)
{
AppHost.SIRTHub.Start(task);
task.Wait();
if (task.State == SIRTTaskState.Completed && task.State == SIRTTaskState.Cancelled)
{
break;
}
}
task.Data = new ActivateMetrologyTestMode()
{
Hours = this.TestModeHours
}
.Append(new ProvidePin
{
AuthLevel = AuthLevel.I
});
task.SetPending();
while (task.State != SIRTTaskState.Completed && task.State != SIRTTaskState.Cancelled)
{
AppHost.SIRTHub.Start(task);
task.Wait();
if (task.State == SIRTTaskState.Completed && task.State == SIRTTaskState.Cancelled)
{
break;
}
}
task.Data = new RequestDebugTelegram
{
}
.Append(new ProvidePin
{ {
AuthLevel = AuthLevel.III AuthLevel = AuthLevel.III
}); });
@@ -412,5 +536,8 @@
task.MessageReceived -= this.Ertask_MessageReceived; task.MessageReceived -= this.Ertask_MessageReceived;
}); });
} }
private void SwitchSettingsVisibilityCommandHandler()
=> this.AreSettingsVisible = !this.AreSettingsVisible;
} }
} }