SIRT setup to SirtConfig file

This commit is contained in:
Thomas Wiedebusch
2025-09-10 17:08:00 +02:00
parent 2670bbee92
commit b8bc03240b
18 changed files with 366 additions and 197 deletions
@@ -49,7 +49,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
/// <summary>
/// Send delay between records in milliseconds before
/// new record is going to be send or between retries,
/// new record is going to be sent or between retries,
/// this time is independent of the timeout, it is
/// used to delay the next send record after successful
/// response from meter.
@@ -100,10 +100,15 @@
</Compile>
<Compile Include="CommunicationConfig.cs" />
<Compile Include="Const\MeterConfig.cs" />
<Compile Include="SirtConfig.cs" />
<Compile Include="ProcessConfig.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\CommonCore\CommonCore.csproj">
<Project>{1B02C79E-0B19-43E2-8F6B-71EF0C786C97}</Project>
<Name>CommonCore</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Interfaces\Ports\PortCore\PortCore.csproj">
<Project>{2E139F63-B6FE-4EA9-A098-85364FE9B26C}</Project>
<Name>PortCore</Name>
@@ -2,6 +2,7 @@
using System.ComponentModel;
using System.IO;
using Newtonsoft.Json;
using Xylem.Common.CommonCore.Consts;
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
{
@@ -10,35 +11,26 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
/// </summary>
public class ProcessConfig
{
/// <summary>
/// ctor
/// </summary>
public ProcessConfig()
{
UseRegisterWatchService = false;
UseErrorLogger = false;
AutoUpdateFiles = false;
ProductionMode = true;
}
/// <summary>
/// Load configuration file from AppRoaming or working directory
/// </summary>
/// <param name="file"></param>
public ProcessConfig(String file)
public Boolean ReadProcessConfig()
{
// check for AppRoaming
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Genesis), file);
// Check for AppRoaming
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
nameof(Genesis), ProgramConfig.MeterConfigFileName);
if (!File.Exists(configFile))
{
// take actual working directory
configFile = Path.Combine(file);
// Take actual working directory
configFile = Path.Combine(ProgramConfig.MeterConfigFileName);
if (!File.Exists(configFile))
{
UseRegisterWatchService = false;
UseErrorLogger = false;
return;
AutoUpdateFiles = false;
ProductionMode = true;
return false;
}
}
@@ -54,21 +46,21 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
CalibrationLoggerServiceUrl = meterConfig.CalibrationLoggerServiceUrl;
AutoUpdateFiles = meterConfig.AutoUpdateFiles;
ProductionMode = meterConfig.ProductionMode;
}
return true;
}
/// <summary>
/// Write file to AppRoaming and backup it to actual working directory
/// </summary>
/// <param name="file"></param>
public void Update(String file)
public void Update()
{
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Genesis), file);
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
nameof(Genesis), ProgramConfig.MeterConfigFileName);
File.WriteAllText(configFile, JsonConvert.SerializeObject(this));
File.WriteAllText(file, JsonConvert.SerializeObject(this));
File.WriteAllText(ProgramConfig.MeterConfigFileName, JsonConvert.SerializeObject(this));
}
/// <summary>
@@ -114,6 +106,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
[DefaultValue(true)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
public Boolean ProductionMode { get; set; } = true;
public Boolean ProductionMode { get; set; }
}
}
@@ -0,0 +1,81 @@
using System;
using System.IO;
using Newtonsoft.Json;
using Xylem.Common.CommonCore.Consts;
namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig
{
/// <summary>
/// Configuration of SIRT
/// </summary>
public class SirtConfig
{
/// <summary>
/// Load SIRT configuration file from AppRoaming or working directory
/// </summary>
public Boolean ReadSirtConfig()
{
// Check for AppRoaming
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
nameof(Genesis), ProgramConfig.SirtConfigFileName);
if (!File.Exists(configFile))
{
// Take actual working directory
configFile = Path.Combine(ProgramConfig.SirtConfigFileName);
if (!File.Exists(configFile))
{
SirtComport433MHz = null;
SirtComport868MHz = null;
SirtBoxNo = null;
StationId = null;
return false;
}
}
using (var tr = new StreamReader(configFile))
{
var sirtConfig = JsonConvert.DeserializeObject<SirtConfig>(tr.ReadToEnd());
SirtComport433MHz = sirtConfig.SirtComport433MHz;
SirtComport868MHz = sirtConfig.SirtComport868MHz;
SirtBoxNo = sirtConfig.SirtBoxNo;
StationId = sirtConfig.StationId;
}
return true;
}
/// <summary>
/// Write file to AppRoaming and backup it to actual working directory
/// </summary>
public void Update()
{
var configFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
nameof(Genesis), ProgramConfig.SirtConfigFileName);
File.WriteAllText(configFile, JsonConvert.SerializeObject(this));
File.WriteAllText(ProgramConfig.SirtConfigFileName, JsonConvert.SerializeObject(this));
}
/// <summary>
/// Comport for SIRT interface with 433MHz radio frequency
/// </summary>
public String SirtComport433MHz { get; set; }
/// <summary>
/// Comport for SIRT interface with 868MHz radio frequency
/// </summary>
public String SirtComport868MHz { get; set; }
/// <summary>
/// Box number for calibration settings
/// </summary>
public Int32? SirtBoxNo { get; set; }
/// <summary>
/// Station ID where the SIRT is used
/// </summary>
public Int32? StationId { get; set; }
}
}
@@ -142,7 +142,7 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// <summary>
/// Process configuration
/// </summary>
public ProcessConfig Configuration { internal set; get; } = new ProcessConfig();
public ProcessConfig Configuration { internal set; get; } //= new ProcessConfig();
/// <summary>
/// Transmit protocol access for underlie objects to change response timeout
@@ -798,7 +798,8 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
ledTransmit.GetTransmitPortSettings());
StreamingProtocol = new StreamingProtocol(streamingIdent, ignoreCorruptedData);
}
Configuration = new ProcessConfig(ProgramConfig.MeterConfigFileName);
Configuration = new ProcessConfig();
Configuration.ReadProcessConfig();
Logger.Debug($"Slot:{Slot} - Setup done");
}
@@ -95,7 +95,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
private static readonly List<String> _excludedFromCompareParameters = new List<String>
{
"CUSTOMER_AlarmVisualMask", // Fully hard coded, cannot be overwritten
//"CUSTOMER_AlarmEnableMask", //Depending on FW version Will be overwritten by SENSUSRADIO if set System state to 0xFF
"CUSTOMER_AppArrangement", // Is read only, makes no sense to compare anything
"SENSUSRADIO_UpgFWVersion" // After a FW-Update the FW version has changed
};
@@ -111,7 +110,6 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore
/// </summary>
private static readonly List<String> _fieldUpdateBlacklist = new List<String>
{
//TODO THW "CUSTOMER_AlarmEnableMask", // Under discussion
"CUSTOMER_AlarmVisualMask",
"CUSTOMER_BackupCalendarSeconds",
"CUSTOMER_InstallationTime",
@@ -1 +1 @@
89102b0142e574de38a9f47d370f3334e5e6c268
8cb55c312de586b683d72cf58c13e2801d10e14b767777d98338d3e1473a1213