TimeT: - SecondsSince2000 default "01. Jan 2000 00:00:00 UTC" have to be preset by TimeT.UtcNowToSecondsSince2000 or TimeT.UtcAnyToSecondsSince2000 or by TimeT.SecondsSince2000
This commit is contained in:
@@ -9,8 +9,19 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes
|
|||||||
public class TimeT
|
public class TimeT
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Seconds since 01. Jan 2000
|
/// 1. Get seconds since 01. Jan 2000 00:00:00 UTC previously set by any call by
|
||||||
|
/// <see cref="UtcNowToSecondsSince2000"/> or <see cref="UtcAnyToSecondsSince2000"/>
|
||||||
|
/// or directly by this routine delivering the seconds e.g. read from meter,
|
||||||
|
/// 2. Set UTC seconds to analyze the corresponding time in UTC and use the ToString to
|
||||||
|
/// read the converted result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
|
||||||
|
/// - Used <see cref="TimeT"/> to calculate time in UTC based on 01. Jan 2000.
|
||||||
|
/// </remarks>
|
||||||
|
/// <remarks date="2024-May-02" author="Thomas Wiedebusch">
|
||||||
|
/// - Setting of seconds and conversion to corresponding UTC sine 2000 or return seconds
|
||||||
|
/// from set DataTimeUtc.
|
||||||
|
/// </remarks>
|
||||||
public Int32 SecondsSince2000
|
public Int32 SecondsSince2000
|
||||||
{
|
{
|
||||||
set
|
set
|
||||||
@@ -18,25 +29,74 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes
|
|||||||
var secondsToTimeSpan = TimeSpan.FromSeconds(value);
|
var secondsToTimeSpan = TimeSpan.FromSeconds(value);
|
||||||
DateTimeUtc = _fixedDateTime2000.Add(secondsToTimeSpan);
|
DateTimeUtc = _fixedDateTime2000.Add(secondsToTimeSpan);
|
||||||
}
|
}
|
||||||
|
// DateTimeUtc has to be set in advance with seconds or by the call
|
||||||
|
// of UtcNowToSecondsSince2000 or UtcAnyToSecondsSince2000
|
||||||
|
get => UtcToSecondsSince2000();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get actual seconds (UTC now) since 01. Jan 2000 00:00:00 UTC.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks date="2024-May-02" author="Thomas Wiedebusch">
|
||||||
|
/// - Initial.
|
||||||
|
/// </remarks>
|
||||||
|
public Int32 UtcNowToSecondsSince2000
|
||||||
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
DateTimeUtc = DateTime.UtcNow;
|
DateTimeUtc = DateTime.UtcNow;
|
||||||
var timeSince2000Utc = DateTimeUtc - _fixedDateTime2000;
|
return UtcToSecondsSince2000();
|
||||||
var secondsSince2000 = Convert.ToInt32(timeSince2000Utc.TotalSeconds);
|
|
||||||
return secondsSince2000;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The date and time of 01.Jan 2000 00:00:00
|
/// Common routine to convert given UTC timestamp to seconds since 01. Jan 2000 00:00:00 UTC.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly DateTime _fixedDateTime2000 = new DateTime(2000, 1, 1, 0, 0, 0);
|
/// <remarks date="2024-May-02" author="Thomas Wiedebusch">
|
||||||
|
/// - Initial.
|
||||||
|
/// </remarks>
|
||||||
|
private Int32 UtcToSecondsSince2000()
|
||||||
|
{
|
||||||
|
var timeSince2000Utc = DateTimeUtc - _fixedDateTime2000;
|
||||||
|
var secondsSince2000 = Convert.ToInt32(timeSince2000Utc.TotalSeconds);
|
||||||
|
return secondsSince2000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Builds the seconds for a given timestamp based on 01.Jan.2000 00:00:00 UTC
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dateTimeUtc">time stamp dateTime for conversion</param>
|
||||||
|
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
|
||||||
|
/// - Optional input of dateTime to convert this to the time in UTC based on 01. Jan 2000.
|
||||||
|
/// </remarks>
|
||||||
|
public Int32 UtcAnyToSecondsSince2000(DateTime dateTimeUtc)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// limit dateTime to 01. Jan 2000 00:00:00 UTC
|
||||||
|
DateTimeUtc = dateTimeUtc < _fixedDateTime2000 ? _fixedDateTime2000 : dateTimeUtc;
|
||||||
|
return UtcToSecondsSince2000();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The date and time of 01.Jan 2000 00:00:00 UTC
|
||||||
|
/// </summary>
|
||||||
|
private static readonly DateTime _fixedDateTime2000 = new DateTime(2000, 1, 1, 0, 0, 0);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converted date and time to UTC using the FixedDateTime2000
|
/// Converted date and time to UTC using the FixedDateTime2000
|
||||||
/// and the SecondsSince2000
|
/// and the SecondsSince2000
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTime DateTimeUtc;
|
public DateTime DateTimeUtc
|
||||||
|
{
|
||||||
|
private set;
|
||||||
|
get;
|
||||||
|
} = _fixedDateTime2000;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get string of UTC date and time universal language with 24 hours format
|
/// Get string of UTC date and time universal language with 24 hours format
|
||||||
|
|||||||
@@ -565,8 +565,8 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
_currentGenesis.ReLogin();
|
_currentGenesis.ReLogin();
|
||||||
|
|
||||||
var dt = DateTime.UtcNow;
|
var dt = DateTime.UtcNow;
|
||||||
var msg = $@"{dt:yyyy-MM-dd HH:mm:ss}";
|
var msg = $@"{dt:yyyy-MM-dd HH:mm:ss} UTC";
|
||||||
LogText($@"PC date time [UTC]: {msg}");
|
LogText($@"PC date time: {msg}");
|
||||||
|
|
||||||
CalculateMeterDateTime(RegisterConverter.ByteArrayToValue<Int32>(
|
CalculateMeterDateTime(RegisterConverter.ByteArrayToValue<Int32>(
|
||||||
_currentGenesis.ReadRegister("SYSTEM_CalendarSeconds")));
|
_currentGenesis.ReadRegister("SYSTEM_CalendarSeconds")));
|
||||||
@@ -591,7 +591,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
var meterDateTime = new TimeT { SecondsSince2000 = secSince2000 };
|
var meterDateTime = new TimeT { SecondsSince2000 = secSince2000 };
|
||||||
var msg = meterDateTime.ToString();
|
var msg = meterDateTime.ToString();
|
||||||
Invoke(new Action(() => { tbxDateTime.Text = msg; }));
|
Invoke(new Action(() => { tbxDateTime.Text = msg; }));
|
||||||
LogText($@"Meter date time [UTC]: {msg}");
|
LogText($@"Meter date time: {msg}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -861,10 +861,10 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
LogText("File is empty", logFileName);
|
LogText("File is empty", logFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var rawBat in rawDic)
|
//foreach (var rawBat in rawDic)
|
||||||
{
|
//{
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
}
|
}
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
@@ -1472,9 +1472,9 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
|
|
||||||
LogText($"Station: {ddlLocation.Items[ddlLocation.SelectedIndex]}", filename);
|
LogText($"Station: {ddlLocation.Items[ddlLocation.SelectedIndex]}", filename);
|
||||||
var dt = DateTime.UtcNow;
|
var dt = DateTime.UtcNow;
|
||||||
msg = $@"{dt:yyyy-MM-dd HH:mm:ss}";
|
msg = $@"{dt:yyyy-MM-dd HH:mm:ss} UTC";
|
||||||
|
|
||||||
LogText($@"PC date time [UTC]: {msg}", filename);
|
LogText($@"PC date time: {msg}", filename);
|
||||||
|
|
||||||
_currentGenesis.ReLogin();
|
_currentGenesis.ReLogin();
|
||||||
|
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
|
|||||||
/// - Compare registers reactivated based on new interface (configuration.json) with new
|
/// - Compare registers reactivated based on new interface (configuration.json) with new
|
||||||
/// "StaticType": “approximate”.
|
/// "StaticType": “approximate”.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <remarks date="2024-Apr-29" author="Thomas Wiedebusch">
|
/// <remarks date="2024-May-02" author="Thomas Wiedebusch">
|
||||||
/// - Power correction for FW update to new version starting with R1.3.x for EMEA and
|
/// - Power correction for FW update to new version starting with R1.3.x for EMEA and
|
||||||
/// R2.1.x for NA applied.
|
/// R2.1.x for NA applied.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
@@ -2005,10 +2005,10 @@ namespace Xylem.ServiceFwUpdate.Ui.ServiceFwUpdateSw
|
|||||||
Boolean retVal;
|
Boolean retVal;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// get the time in UTC to program the time for the Cordonel in seconds since 01. Jan 2000
|
// get the time in UTC to program the time for the Cordonel in seconds since 01. Jan 2000 00:00:00 UTC
|
||||||
var teaTime = new TimeT();
|
var teaTime = new TimeT();
|
||||||
// build byte array
|
// build byte array
|
||||||
var rawSeconds = RegisterConverter.ValueToByteArray(teaTime.SecondsSince2000);
|
var rawSeconds = RegisterConverter.ValueToByteArray(teaTime.UtcNowToSecondsSince2000);
|
||||||
retVal = _currentGenesis.WriteRegister("SYSTEM_CalendarSeconds", rawSeconds);
|
retVal = _currentGenesis.WriteRegister("SYSTEM_CalendarSeconds", rawSeconds);
|
||||||
LogSuccessText(Resources.StrDateTimeSetupSucceeded + " " + teaTime);
|
LogSuccessText(Resources.StrDateTimeSetupSucceeded + " " + teaTime);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user