Common: - RegisterConverter modified, - TimeT implemented, - LowLevelTools
This commit is contained in:
@@ -1,8 +1,49 @@
|
|||||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes
|
using System;
|
||||||
|
|
||||||
|
namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes
|
||||||
{
|
{
|
||||||
|
|
||||||
public struct TimeT
|
/// <summary>
|
||||||
|
/// Class for Genesis TimeT
|
||||||
|
/// </summary>
|
||||||
|
public class TimeT
|
||||||
{
|
{
|
||||||
//todo find out struct definition and implement it
|
/// <summary>
|
||||||
|
/// Seconds since 01. Jan 2000
|
||||||
|
/// </summary>
|
||||||
|
public Int32 SecondsSince2000
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
var secondsToTimeSpan = TimeSpan.FromSeconds(value);
|
||||||
|
DateTimeUtc = _fixedDateTime2000.Add(secondsToTimeSpan);
|
||||||
|
}
|
||||||
|
get
|
||||||
|
{
|
||||||
|
DateTimeUtc = DateTime.UtcNow;
|
||||||
|
var timeSince2000Utc = DateTimeUtc - _fixedDateTime2000;
|
||||||
|
var secondsSince2000 = Convert.ToInt32(timeSince2000Utc.TotalSeconds);
|
||||||
|
return secondsSince2000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The date and time of 01.Jan 2000 00:00:00
|
||||||
|
/// </summary>
|
||||||
|
private readonly DateTime _fixedDateTime2000 = new DateTime(2000, 1, 1, 0, 0, 0);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converted date and time to UTC using the FixedDateTime2000
|
||||||
|
/// and the SecondsSince2000
|
||||||
|
/// </summary>
|
||||||
|
public DateTime DateTimeUtc;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get string of UTC date and time universal language with 24 hours format
|
||||||
|
/// </summary>
|
||||||
|
public override String ToString()
|
||||||
|
{
|
||||||
|
return $@"{DateTimeUtc:yyyy-MM-dd HH:mm:ss}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes;
|
||||||
|
|
||||||
namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers
|
namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers
|
||||||
{
|
{
|
||||||
@@ -8,16 +11,84 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class RegisterConverter
|
public static class RegisterConverter
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Convert single register from Genesis and return a message of the result.
|
||||||
|
/// The raw value is swapped byte-wise to get a human readable
|
||||||
|
/// value with MSB at leftmost and LSB at rightmost.
|
||||||
|
/// The message contains the (swapped) raw value and the converted value.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>message with register name, (swapped raw value and converted value to use for
|
||||||
|
/// logging</returns>
|
||||||
|
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
|
||||||
|
/// - Initial.
|
||||||
|
/// </remarks>
|
||||||
|
public static String GetRegisterParameterInfo(MeterRegisters registersDefinitions, String registerName,
|
||||||
|
Byte[] registerValue)
|
||||||
|
{
|
||||||
|
String msg;
|
||||||
|
var strValueResult = "?";
|
||||||
|
var strRawResult = "?";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// build value for logging
|
||||||
|
var regDef = registersDefinitions.GetRegisterDefinitionByName(registerName);
|
||||||
|
var strValue = ConvertToText(registerValue, regDef.DataType);
|
||||||
|
// remove non printable char
|
||||||
|
strValueResult = Regex.Replace(strValue, @"\p{C}+", string.Empty);
|
||||||
|
|
||||||
|
// inverse the raw value to get a readable byte order MSB left and LSB last right position
|
||||||
|
var tmpList = registerValue.ToList();
|
||||||
|
tmpList.Reverse();
|
||||||
|
strRawResult = BitConverter.ToString(tmpList.ToArray());
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
// nothing to do
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
msg = $"{registerName} - {strRawResult} - {strValueResult}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert a value (T) into byte[]
|
/// Convert a value (T) into byte[]
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">Type to convert from</typeparam>
|
/// <typeparam name="T">Type to convert from</typeparam>
|
||||||
/// <param name="value">value to convert</param>
|
/// <param name="value">value to convert</param>
|
||||||
/// <returns>byte[] like it store in genesis meter</returns>
|
/// <returns>byte[] like it store in genesis meter</returns>
|
||||||
|
/// <remarks date="????" author="Roland Drabesch">
|
||||||
|
/// - Init.
|
||||||
|
/// </remarks>
|
||||||
|
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
|
||||||
|
/// - Used <see cref="TimeT"/> to calculate time in UTC based on 01. Jan 2000
|
||||||
|
/// and the given offset in seconds.
|
||||||
|
/// </remarks>
|
||||||
public static Byte[] ConvertFrom<T>(T value)
|
public static Byte[] ConvertFrom<T>(T value)
|
||||||
{
|
{
|
||||||
var converted = new Byte[] {0};
|
var converted = new Byte[] { 0 };
|
||||||
if (value == null) return converted;
|
if (value == null)
|
||||||
|
return converted;
|
||||||
|
|
||||||
|
if (value.GetType() == typeof(TimeT))
|
||||||
|
{
|
||||||
|
var teaTime = value as TimeT;
|
||||||
|
if (teaTime != null)
|
||||||
|
{
|
||||||
|
// the value contains always the seconds since 01.Jan 2000
|
||||||
|
var intValue = Convert.ToInt32(teaTime.SecondsSince2000);
|
||||||
|
return BitConverter.GetBytes(intValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value is Boolean)
|
||||||
|
{
|
||||||
|
var tmp = Convert.ToBoolean(value);
|
||||||
|
return BitConverter.GetBytes(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
if (value is UInt16)
|
if (value is UInt16)
|
||||||
{
|
{
|
||||||
var tmp = Convert.ToUInt16(value);
|
var tmp = Convert.ToUInt16(value);
|
||||||
@@ -59,27 +130,22 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers
|
|||||||
return Encoding.ASCII.GetBytes(value.ToString());
|
return Encoding.ASCII.GetBytes(value.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value is Byte)
|
if (value is Byte || value is Enum8)
|
||||||
{
|
{
|
||||||
converted[0] = Convert.ToByte(value);
|
converted[0] = Convert.ToByte(value);
|
||||||
}
|
}
|
||||||
else if (value is SByte)
|
else if (value is SByte)
|
||||||
{
|
{
|
||||||
return BitConverter.GetBytes(Convert.ToSByte(value));
|
return BitConverter.GetBytes(Convert.ToSByte(value));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
else if (value is Boolean)
|
|
||||||
{
|
|
||||||
if (Convert.ToBoolean(value))
|
|
||||||
converted[0] = 1;
|
|
||||||
}
|
|
||||||
else if (value is Byte[])
|
else if (value is Byte[])
|
||||||
{
|
{
|
||||||
return (Byte[])Convert.ChangeType(value, typeof(Byte[]));
|
return (Byte[])Convert.ChangeType(value, typeof(Byte[]));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new ApplicationException("unknown data type");
|
throw new ApplicationException($"Data type {typeof(T)} not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
return converted;
|
return converted;
|
||||||
@@ -91,50 +157,74 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers
|
|||||||
/// <param name="value">byte value for conversion</param>
|
/// <param name="value">byte value for conversion</param>
|
||||||
/// <param name="type">Type to cast from</param>
|
/// <param name="type">Type to cast from</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
/// <remarks date="????" author="Roland Drabesch">
|
||||||
|
/// - Init.
|
||||||
|
/// </remarks>
|
||||||
|
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
|
||||||
|
/// - Used <see cref="TimeT"/> to calculate time in UTC based on 01. Jan 2000
|
||||||
|
/// and the given offset in seconds.
|
||||||
|
/// </remarks>
|
||||||
public static String ConvertToText(Byte[] value, Type type)
|
public static String ConvertToText(Byte[] value, Type type)
|
||||||
{
|
{
|
||||||
if (type == typeof(UInt16))
|
try
|
||||||
{
|
{
|
||||||
return ConvertTo<UInt16>(value).ToString();
|
if (type == typeof(Boolean))
|
||||||
}
|
{
|
||||||
|
return ConvertTo<Boolean>(value).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
if (type == typeof(UInt32))
|
if (type == typeof(TimeT))
|
||||||
|
{
|
||||||
|
var teaTime = ConvertTo<TimeT>(value);
|
||||||
|
return teaTime.ToString();
|
||||||
|
}
|
||||||
|
if (type == typeof(UInt16))
|
||||||
|
{
|
||||||
|
return ConvertTo<UInt16>(value).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(UInt32))
|
||||||
|
{
|
||||||
|
return ConvertTo<UInt32>(value).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(UInt64))
|
||||||
|
{
|
||||||
|
return ConvertTo<UInt64>(value).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(Int16))
|
||||||
|
{
|
||||||
|
return ConvertTo<Int16>(value).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(Int32))
|
||||||
|
{
|
||||||
|
return ConvertTo<Int32>(value).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(Int64))
|
||||||
|
{
|
||||||
|
return ConvertTo<Int64>(value).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(Byte) || type == typeof(Enum8))
|
||||||
|
{
|
||||||
|
return ConvertTo<Byte>(value).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == typeof(SByte))
|
||||||
|
{
|
||||||
|
return ConvertTo<SByte>(value).ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConvertTo<String>(value);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
{
|
{
|
||||||
return ConvertTo<UInt32>(value).ToString();
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == typeof(UInt64))
|
|
||||||
{
|
|
||||||
return ConvertTo<UInt64>(value).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == typeof(Int16))
|
|
||||||
{
|
|
||||||
return ConvertTo<Int16>(value).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == typeof(Int32))
|
|
||||||
{
|
|
||||||
return ConvertTo<Int32>(value).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == typeof(Int64))
|
|
||||||
{
|
|
||||||
return ConvertTo<Int64>(value).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == typeof(Byte))
|
|
||||||
{
|
|
||||||
return ConvertTo<Byte>(value).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type == typeof(SByte))
|
|
||||||
{
|
|
||||||
return ConvertTo<SByte>(value).ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
return ConvertTo<String>(value);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -144,60 +234,105 @@ namespace Xylem.Common.Hardware.WaterMeter.Genesis.Registers
|
|||||||
/// <typeparam name="T">Type to cast in</typeparam>
|
/// <typeparam name="T">Type to cast in</typeparam>
|
||||||
/// <param name="value">byte value for conversion</param>
|
/// <param name="value">byte value for conversion</param>
|
||||||
/// <returns>converted value</returns>
|
/// <returns>converted value</returns>
|
||||||
|
/// <remarks date="????" author="Roland Drabesch">
|
||||||
|
/// - Init.
|
||||||
|
/// </remarks>
|
||||||
|
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
|
||||||
|
/// - Used <see cref="TimeT"/> to calculate time in UTC based on 01. Jan 2000
|
||||||
|
/// and the given offset in seconds.
|
||||||
|
/// - String removed from first zero in string until the end to avoid ghost signs!
|
||||||
|
/// </remarks>
|
||||||
public static T ConvertTo<T>(Byte[] value)
|
public static T ConvertTo<T>(Byte[] value)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object convertedObj;
|
Object convertedObj;
|
||||||
|
var type = typeof(T);
|
||||||
if (typeof(T) == typeof(UInt16))
|
|
||||||
|
if (type == typeof(Boolean))
|
||||||
{
|
{
|
||||||
convertedObj = (UInt16)((value[0] & 0xFF) | ((value[1] << 8) & 0xFF00));
|
convertedObj = BitConverter.ToBoolean(value, 0);
|
||||||
}
|
}
|
||||||
else if (typeof(T) == typeof(UInt32))
|
else if (type == typeof(UInt16))
|
||||||
|
{
|
||||||
|
convertedObj = BitConverter.ToUInt16(value, 0);
|
||||||
|
}
|
||||||
|
else if (type == typeof(UInt32))
|
||||||
{
|
{
|
||||||
convertedObj = BitConverter.ToUInt32(value, 0);
|
convertedObj = BitConverter.ToUInt32(value, 0);
|
||||||
}
|
}
|
||||||
else if (typeof(T) == typeof(UInt64))
|
else if (type == typeof(UInt64))
|
||||||
{
|
{
|
||||||
convertedObj = BitConverter.ToUInt64(value, 0);
|
convertedObj = BitConverter.ToUInt64(value, 0);
|
||||||
}
|
}
|
||||||
else if (typeof(T) == typeof(Int16))
|
else if (type == typeof(Int16))
|
||||||
{
|
{
|
||||||
|
|
||||||
convertedObj = BitConverter.ToInt16(value, 0);// (short)(value[0] << 8 | value[1]);
|
convertedObj = BitConverter.ToInt16(value, 0);
|
||||||
}
|
}
|
||||||
else if (typeof(T) == typeof(Int32))
|
else if (type == typeof(Int32))
|
||||||
{
|
{
|
||||||
convertedObj = BitConverter.ToInt32(value, 0);
|
convertedObj = BitConverter.ToInt32(value, 0);
|
||||||
}
|
}
|
||||||
else if (typeof(T) == typeof(Int64))
|
else if (type == typeof(Int64))
|
||||||
{
|
{
|
||||||
convertedObj = BitConverter.ToInt64(value, 0);
|
convertedObj = BitConverter.ToInt64(value, 0);
|
||||||
}
|
}
|
||||||
else if (typeof(T) == typeof(Byte))
|
else if (type == typeof(Byte) || type == typeof(Enum8))
|
||||||
{
|
{
|
||||||
convertedObj = value[0];
|
convertedObj = value[0];
|
||||||
}
|
}
|
||||||
else if (typeof(T) == typeof(SByte))
|
else if (type == typeof(SByte))
|
||||||
{
|
{
|
||||||
convertedObj = Convert.ToSByte(value[0]);
|
// set all others to 0 as only the LSB is of interest
|
||||||
|
for (var idx = 1; idx < value.Length; idx++)
|
||||||
|
value[idx] = 0;
|
||||||
|
convertedObj = Convert.ToSByte((SByte)value[0]);
|
||||||
}
|
}
|
||||||
else if (typeof(T) == typeof(Boolean))
|
else if (type == typeof(Boolean))
|
||||||
{
|
{
|
||||||
convertedObj = Convert.ToBoolean(value[0]);
|
convertedObj = Convert.ToBoolean(value[0]);
|
||||||
}
|
}
|
||||||
else // if (typeof(T) == typeof(string))
|
else if (type == typeof(String))
|
||||||
{
|
{
|
||||||
|
// the value may contain zeros at the beginning of the value-record, these have to be removed
|
||||||
var zeroPaddingCounter = 0;
|
var zeroPaddingCounter = 0;
|
||||||
|
|
||||||
while (value.Length > zeroPaddingCounter && value[zeroPaddingCounter] == 0)
|
while (value.Length > zeroPaddingCounter && value[zeroPaddingCounter] == 0)
|
||||||
zeroPaddingCounter = zeroPaddingCounter + 1;
|
zeroPaddingCounter += 1;
|
||||||
|
|
||||||
var trimmedValue = new Byte[value.Length - zeroPaddingCounter];
|
var trimmedValue = new Byte[value.Length - zeroPaddingCounter];
|
||||||
for (var i = 0; i < value.Length - zeroPaddingCounter; i++)
|
Int32 i;
|
||||||
|
for (i = 0; i < value.Length - zeroPaddingCounter; i++)
|
||||||
trimmedValue[i] = value[i + zeroPaddingCounter];
|
trimmedValue[i] = value[i + zeroPaddingCounter];
|
||||||
convertedObj = Encoding.ASCII.GetString(trimmedValue);
|
|
||||||
|
// as a string is terminated with a zero all following elements after including the initial
|
||||||
|
// zero have to be removed. This is caused due to the 4 byte chunks which will be sent.
|
||||||
|
var validCharCtr = 0;
|
||||||
|
// find the first zero in the trimmed value array
|
||||||
|
while (trimmedValue.Length > validCharCtr && trimmedValue[validCharCtr] != 0)
|
||||||
|
validCharCtr += 1;
|
||||||
|
// reserve space for valid chr plus the trailing 0 which will be added if
|
||||||
|
var rawResult = new Byte[validCharCtr + 1];
|
||||||
|
for (i = 0; i < validCharCtr; i++)
|
||||||
|
rawResult[i] = trimmedValue[i];
|
||||||
|
if (validCharCtr < trimmedValue.Length)
|
||||||
|
{
|
||||||
|
rawResult[i] = 0;
|
||||||
|
convertedObj = Encoding.ASCII.GetString(rawResult);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
convertedObj = Encoding.ASCII.GetString(trimmedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == typeof(TimeT))
|
||||||
|
{
|
||||||
|
// the value contains always the seconds since 01.Jan 2000
|
||||||
|
var teaTime = new TimeT { SecondsSince2000 = ConvertTo<Int32>(value) };
|
||||||
|
return (T)Convert.ChangeType(teaTime, typeof(TimeT));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new ApplicationException($"Data type {type} not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (T)Convert.ChangeType(convertedObj, Type.GetTypeCode(typeof(T)));
|
return (T)Convert.ChangeType(convertedObj, Type.GetTypeCode(typeof(T)));
|
||||||
|
|||||||
+13
-13
@@ -71,7 +71,7 @@
|
|||||||
this.saveConfigFile = new System.Windows.Forms.SaveFileDialog();
|
this.saveConfigFile = new System.Windows.Forms.SaveFileDialog();
|
||||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||||
this.ddlLocation = new System.Windows.Forms.ComboBox();
|
this.ddlLocation = new System.Windows.Forms.ComboBox();
|
||||||
this.button1 = new System.Windows.Forms.Button();
|
this.btnReadBatAndLog = new System.Windows.Forms.Button();
|
||||||
this.btnListFileDetails = new System.Windows.Forms.Button();
|
this.btnListFileDetails = new System.Windows.Forms.Button();
|
||||||
this.btnReadLogFiles = new System.Windows.Forms.Button();
|
this.btnReadLogFiles = new System.Windows.Forms.Button();
|
||||||
this.groupBox3 = new System.Windows.Forms.GroupBox();
|
this.groupBox3 = new System.Windows.Forms.GroupBox();
|
||||||
@@ -489,7 +489,7 @@
|
|||||||
// groupBox2
|
// groupBox2
|
||||||
//
|
//
|
||||||
this.groupBox2.Controls.Add(this.ddlLocation);
|
this.groupBox2.Controls.Add(this.ddlLocation);
|
||||||
this.groupBox2.Controls.Add(this.button1);
|
this.groupBox2.Controls.Add(this.btnReadBatAndLog);
|
||||||
this.groupBox2.Controls.Add(this.btnListFileDetails);
|
this.groupBox2.Controls.Add(this.btnListFileDetails);
|
||||||
this.groupBox2.Controls.Add(this.btnReadLogFiles);
|
this.groupBox2.Controls.Add(this.btnReadLogFiles);
|
||||||
this.groupBox2.Controls.Add(this.btnUploadConfig);
|
this.groupBox2.Controls.Add(this.btnUploadConfig);
|
||||||
@@ -511,20 +511,20 @@
|
|||||||
"EOL",
|
"EOL",
|
||||||
"R&D",
|
"R&D",
|
||||||
"Other"});
|
"Other"});
|
||||||
this.ddlLocation.Location = new System.Drawing.Point(5, 118);
|
this.ddlLocation.Location = new System.Drawing.Point(10, 116);
|
||||||
this.ddlLocation.Name = "ddlLocation";
|
this.ddlLocation.Name = "ddlLocation";
|
||||||
this.ddlLocation.Size = new System.Drawing.Size(57, 21);
|
this.ddlLocation.Size = new System.Drawing.Size(52, 21);
|
||||||
this.ddlLocation.TabIndex = 41;
|
this.ddlLocation.TabIndex = 41;
|
||||||
//
|
//
|
||||||
// button1
|
// btnReadBatAndLog
|
||||||
//
|
//
|
||||||
this.button1.Location = new System.Drawing.Point(68, 114);
|
this.btnReadBatAndLog.Location = new System.Drawing.Point(68, 114);
|
||||||
this.button1.Name = "button1";
|
this.btnReadBatAndLog.Name = "btnReadBatAndLog";
|
||||||
this.button1.Size = new System.Drawing.Size(58, 25);
|
this.btnReadBatAndLog.Size = new System.Drawing.Size(58, 25);
|
||||||
this.button1.TabIndex = 40;
|
this.btnReadBatAndLog.TabIndex = 40;
|
||||||
this.button1.Text = "Bat Info";
|
this.btnReadBatAndLog.Text = "All Info";
|
||||||
this.button1.UseVisualStyleBackColor = true;
|
this.btnReadBatAndLog.UseVisualStyleBackColor = true;
|
||||||
this.button1.Click += new System.EventHandler(this.btnReadLogFilesBattery_Click);
|
this.btnReadBatAndLog.Click += new System.EventHandler(this.btnReadLogFilesBattery_Click);
|
||||||
//
|
//
|
||||||
// btnListFileDetails
|
// btnListFileDetails
|
||||||
//
|
//
|
||||||
@@ -700,6 +700,6 @@
|
|||||||
private System.Windows.Forms.TextBox tbxFileToEraseName;
|
private System.Windows.Forms.TextBox tbxFileToEraseName;
|
||||||
private System.Windows.Forms.Button btnPulseModeOff;
|
private System.Windows.Forms.Button btnPulseModeOff;
|
||||||
private System.Windows.Forms.ComboBox ddlLocation;
|
private System.Windows.Forms.ComboBox ddlLocation;
|
||||||
private System.Windows.Forms.Button button1;
|
private System.Windows.Forms.Button btnReadBatAndLog;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
|||||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile;
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisFile;
|
||||||
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisStatus;
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisStatus;
|
||||||
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
||||||
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers.DataTypes;
|
||||||
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore;
|
||||||
using Xylem.Common.Utils.ProcessExec.EventArguments;
|
using Xylem.Common.Utils.ProcessExec.EventArguments;
|
||||||
using String = System.String;
|
using String = System.String;
|
||||||
@@ -117,7 +118,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
|
|
||||||
LogText($"GenesisToolBox: {_version.Major}.{_version.Minor}.{_version.Build}");
|
LogText($"GenesisToolBox: {_version.Major}.{_version.Minor}.{_version.Build}");
|
||||||
LogText(StrSeparator);
|
LogText(StrSeparator);
|
||||||
ddlLocation.SelectedIndex =0;
|
ddlLocation.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FrmLowLevelTools_FormClosing(Object sender, FormClosingEventArgs e)
|
private void FrmLowLevelTools_FormClosing(Object sender, FormClosingEventArgs e)
|
||||||
@@ -159,6 +160,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
btnStoreConfiguration.Enabled = false;
|
btnStoreConfiguration.Enabled = false;
|
||||||
btnUploadConfig.Enabled = false;
|
btnUploadConfig.Enabled = false;
|
||||||
btnReadLogFiles.Enabled = false;
|
btnReadLogFiles.Enabled = false;
|
||||||
|
btnReadBatAndLog.Enabled = false;
|
||||||
btnListFileDetails.Enabled = false;
|
btnListFileDetails.Enabled = false;
|
||||||
btnTidyFile.Enabled = false;
|
btnTidyFile.Enabled = false;
|
||||||
btnEraseFile.Enabled = false;
|
btnEraseFile.Enabled = false;
|
||||||
@@ -180,6 +182,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
btnStoreConfiguration.Enabled = true;
|
btnStoreConfiguration.Enabled = true;
|
||||||
btnUploadConfig.Enabled = true;
|
btnUploadConfig.Enabled = true;
|
||||||
btnReadLogFiles.Enabled = true;
|
btnReadLogFiles.Enabled = true;
|
||||||
|
btnReadBatAndLog.Enabled = true;
|
||||||
btnListFileDetails.Enabled = true;
|
btnListFileDetails.Enabled = true;
|
||||||
btnTidyFile.Enabled = true;
|
btnTidyFile.Enabled = true;
|
||||||
btnEraseFile.Enabled = true;
|
btnEraseFile.Enabled = true;
|
||||||
@@ -546,11 +549,12 @@ 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}";
|
||||||
LogText($@"PC date time [UTC]: {msg}");
|
LogText($@"PC date time [UTC]: {msg}");
|
||||||
|
|
||||||
CalculateMeterDateTime(RegisterConverter.ConvertTo<Int32>(
|
CalculateMeterDateTime(RegisterConverter.ConvertTo<Int32>(
|
||||||
_currentGenesis.ReadRegister("SYSTEM_CalendarSeconds")));
|
_currentGenesis.ReadRegister("SYSTEM_CalendarSeconds")));
|
||||||
|
|
||||||
//add a blank line to separate next operation
|
//add a blank line to separate next operation
|
||||||
LogText("");
|
LogText("");
|
||||||
_currentGenesis.Logout();
|
_currentGenesis.Logout();
|
||||||
@@ -562,11 +566,14 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
/// <remarks date="2023-Jan-06" author="Thomas Wiedebusch">
|
/// <remarks date="2023-Jan-06" author="Thomas Wiedebusch">
|
||||||
/// - Init.
|
/// - Init.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
/// <remarks date="2023-Jul-19" author="Thomas Wiedebusch">
|
||||||
|
/// - Used <see cref="TimeT"/> to calculate time in UTC based on 01. Jan 2000
|
||||||
|
/// and the given offset in seconds.
|
||||||
|
/// </remarks>
|
||||||
private void CalculateMeterDateTime(Int32 secSince2000)
|
private void CalculateMeterDateTime(Int32 secSince2000)
|
||||||
{
|
{
|
||||||
var ts = TimeSpan.FromSeconds(secSince2000);
|
var meterDateTime = new TimeT { SecondsSince2000 = secSince2000 };
|
||||||
var meterDateTime = new DateTime(2000, 1, 1, 0, 0, 0).Add(ts);
|
var msg = meterDateTime.ToString();
|
||||||
var msg = $@"{meterDateTime:yyyy-MM-dd hh:mm:ss}";
|
|
||||||
Invoke(new Action(() => { tbxDateTime.Text = msg; }));
|
Invoke(new Action(() => { tbxDateTime.Text = msg; }));
|
||||||
LogText($@"Meter date time [UTC]: {msg}");
|
LogText($@"Meter date time [UTC]: {msg}");
|
||||||
}
|
}
|
||||||
@@ -594,24 +601,19 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
/// <remarks date="2021-Apr-26" author="Thomas Wiedebusch">
|
/// <remarks date="2021-Apr-26" author="Thomas Wiedebusch">
|
||||||
/// - Color added.
|
/// - Color added.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private void LogText(String txtHistory)
|
/// <remarks date="2023-Aug-15" author="Thomas Wiedebusch">
|
||||||
|
/// - File output added.
|
||||||
|
/// </remarks>
|
||||||
|
private void LogText(String txtHistory, String filename = null)
|
||||||
{
|
{
|
||||||
InfoWindowColoredText(txtHistory, ColorDefault);
|
InfoWindowColoredText(txtHistory, ColorDefault);
|
||||||
|
if (!string.IsNullOrEmpty(filename))
|
||||||
|
{
|
||||||
|
File.AppendAllLines(filename, new[] { txtHistory });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Output exclusively to user update remarks text window.
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks date="2021-Apr-26" author="Thomas Wiedebusch">
|
|
||||||
/// - Color added.
|
|
||||||
/// </remarks>
|
|
||||||
private void LogTextAndFile(String txtHistory,string Filename)
|
|
||||||
{
|
|
||||||
LogText(txtHistory);
|
|
||||||
File.AppendAllLines(Filename, new[] { txtHistory });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the actual process and log the text.
|
/// Set the actual process and log the text.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -719,13 +721,123 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
|
|
||||||
return fileNames;
|
return fileNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// Read engineering log files from meter and analyzes the contents.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks date="2023-Aug-15" author="Roland Drabesch/Thomas Wiedebusch">
|
||||||
|
/// - Initial
|
||||||
|
/// </remarks>
|
||||||
|
private void ReadLogFiles(String logFileName = null)
|
||||||
|
{
|
||||||
|
if (_currentGenesis == null)
|
||||||
|
return;
|
||||||
|
if (_meterFile == null)
|
||||||
|
_meterFile = new MeterFile(_currentGenesis);
|
||||||
|
|
||||||
|
var statusMap = new Dictionary<Int32, String>();
|
||||||
|
if (File.Exists("Status.json"))
|
||||||
|
{
|
||||||
|
var dict = JsonConvert.DeserializeObject<Dictionary<String, JObject>>(File.ReadAllText("Status.json"));
|
||||||
|
if (dict != null)
|
||||||
|
foreach (var item in dict)
|
||||||
|
{
|
||||||
|
if (item.Value.First != null)
|
||||||
|
statusMap.Add(int.Parse(item.Value.First.Values().First().ToString()), item.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
_currentGenesis.ReLogin();
|
||||||
|
|
||||||
|
var fileNames = ListLogFiles(logFileName);
|
||||||
|
|
||||||
|
foreach (var fileName in fileNames)
|
||||||
|
{
|
||||||
|
SetActualProcessAndLog($@"Reading and analyzing {fileName}");
|
||||||
|
var success = _meterFile.ReadMeterFile(fileName, out var data);
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
{
|
||||||
|
_currentGenesis.Logout();
|
||||||
|
_currentGenesis.ReLogin();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.Count > 0)
|
||||||
|
{
|
||||||
|
LogText($"Data: {ByteArrayStyle.ByteStyler.ToString(data.ToArray())}", logFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.Count >= 5)
|
||||||
|
{
|
||||||
|
for (var ctr = 0; ctr < data.Count;)
|
||||||
|
{
|
||||||
|
var logType = data[ctr];
|
||||||
|
var status = (data[ctr + 2] << 8) + data[ctr + 1];
|
||||||
|
var count = data[ctr + 3] + 1;
|
||||||
|
var extraDataSize = data[ctr + 4];
|
||||||
|
|
||||||
|
String msg;
|
||||||
|
switch (logType)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
msg = $"({logType}) Informational";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
msg = $"({logType}) Warning";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
msg = $"({logType}) Critical";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
msg = $"({logType}) Unknown log type";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogText($"Log type: {msg}", logFileName);
|
||||||
|
LogText(statusMap.ContainsKey(status)
|
||||||
|
? $"Status: ({status}) {statusMap[status]}"
|
||||||
|
: $"Status: {status}", logFileName);
|
||||||
|
LogText($"Count: {count}", logFileName);
|
||||||
|
LogText($"Extra data size: {extraDataSize}", logFileName);
|
||||||
|
|
||||||
|
//avoid access beyond the buffer and check for data to display
|
||||||
|
if (ctr + 5 + extraDataSize < data.Count && extraDataSize > 0)
|
||||||
|
{
|
||||||
|
var extraData = data.GetRange(ctr + 5, extraDataSize);
|
||||||
|
LogText($"Extra data: {ByteArrayStyle.ByteStyler.ToString(extraData.ToArray())}", logFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
LogText("", logFileName);
|
||||||
|
|
||||||
|
ctr += (5 + extraDataSize);
|
||||||
|
//exit if index for next run is out of range
|
||||||
|
if (ctr + 5 >= data.Count)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogText("File is empty", logFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).ContinueWith(delegate
|
||||||
|
{
|
||||||
|
//add a blank line to separate next operation
|
||||||
|
LogText("");
|
||||||
|
_currentGenesis.Logout();
|
||||||
|
LowLevelActionControl(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
/// List all meter log files covered by the log index file
|
/// List all meter log files covered by the log index file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks date="2023-Jan-14" author="Thomas Wiedebusch">
|
/// <remarks date="2023-Jan-14" author="Thomas Wiedebusch">
|
||||||
/// - Initial
|
/// - Initial
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private List<String> ListLogFiles()
|
private List<String> ListLogFiles(String logFileName = null)
|
||||||
{
|
{
|
||||||
SetActualProcessAndLog(@"Flushing the logger");
|
SetActualProcessAndLog(@"Flushing the logger");
|
||||||
_currentGenesis.WriteRegister("LOGGER_TriggerLogFlush", 1);
|
_currentGenesis.WriteRegister("LOGGER_TriggerLogFlush", 1);
|
||||||
@@ -747,7 +859,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
}
|
}
|
||||||
|
|
||||||
var name = $"1\\{RegisterConverter.ConvertTo<Int32>(sample):X8}";
|
var name = $"1\\{RegisterConverter.ConvertTo<Int32>(sample):X8}";
|
||||||
LogText($"Log file catalogue: {name}");
|
LogText($"Log file catalogue: {name}", logFileName);
|
||||||
fileNames.Add(name);
|
fileNames.Add(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1174,104 +1286,13 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
//reset timer
|
//reset timer
|
||||||
_startTime = DateTimeOffset.UtcNow;
|
_startTime = DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
var statusMap = new Dictionary<Int32, String>();
|
|
||||||
if (File.Exists("Status.json"))
|
|
||||||
{
|
|
||||||
var dict = JsonConvert.DeserializeObject<Dictionary<String, JObject>>(File.ReadAllText("Status.json"));
|
|
||||||
foreach (var item in dict)
|
|
||||||
{
|
|
||||||
if (item.Value.First != null)
|
|
||||||
statusMap.Add(int.Parse(item.Value.First.Values().First().ToString()), item.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LowLevelActionControl(true);
|
LowLevelActionControl(true);
|
||||||
|
|
||||||
var msg = @"Upload engineering log file from meter";
|
var msg = @"Upload engineering log file from meter";
|
||||||
LogText(msg);
|
LogText(msg);
|
||||||
lblOverall.Text = msg;
|
lblOverall.Text = msg;
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
ReadLogFiles();
|
||||||
{
|
|
||||||
_currentGenesis.ReLogin();
|
|
||||||
|
|
||||||
var fileNames = ListLogFiles();
|
|
||||||
|
|
||||||
foreach (var fileName in fileNames)
|
|
||||||
{
|
|
||||||
SetActualProcessAndLog($@"Reading and analyzing {fileName}");
|
|
||||||
var success = _meterFile.ReadMeterFile(fileName, out var data);
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
_currentGenesis.Logout();
|
|
||||||
_currentGenesis.ReLogin();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.Count > 0)
|
|
||||||
{
|
|
||||||
LogText($"Data: {ByteArrayStyle.ByteStyler.ToString(data.ToArray())}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.Count >= 5)
|
|
||||||
{
|
|
||||||
for (var ctr = 0; ctr < data.Count;)
|
|
||||||
{
|
|
||||||
var logType = data[ctr];
|
|
||||||
var status = (data[ctr + 2] << 8) + data[ctr + 1];
|
|
||||||
var count = data[ctr + 3] + 1;
|
|
||||||
var extraDataSize = data[ctr + 4];
|
|
||||||
|
|
||||||
switch (logType)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
msg = $"({logType}) Informational";
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
msg = $"({logType}) Warning";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
msg = $"({logType}) Critical";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
msg = $"({logType}) Unknown log type";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogText($"Log type: {msg}");
|
|
||||||
LogText(statusMap.ContainsKey(status)
|
|
||||||
? $"Status: ({status}) {statusMap[status]}"
|
|
||||||
: $"Status: {status}");
|
|
||||||
LogText($"Count: {count}");
|
|
||||||
LogText($"Extra data size: {extraDataSize}");
|
|
||||||
|
|
||||||
//avoid access beyond the buffer and check for data to display
|
|
||||||
if (ctr + 5 + extraDataSize < data.Count && extraDataSize > 0)
|
|
||||||
{
|
|
||||||
var extraData = data.GetRange(ctr + 5, extraDataSize);
|
|
||||||
LogText($"Extra data: {ByteArrayStyle.ByteStyler.ToString(extraData.ToArray())}");
|
|
||||||
}
|
|
||||||
|
|
||||||
LogText(" ");
|
|
||||||
|
|
||||||
ctr += (5 + extraDataSize);
|
|
||||||
//exit if index for next run is out of range
|
|
||||||
if (ctr + 5 >= data.Count)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogText("File is empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).ContinueWith(delegate
|
|
||||||
{
|
|
||||||
//add a blank line to separate next operation
|
|
||||||
LogText("");
|
|
||||||
_currentGenesis.Logout();
|
|
||||||
LowLevelActionControl(false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1291,132 +1312,45 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
//reset timer
|
//reset timer
|
||||||
_startTime = DateTimeOffset.UtcNow;
|
_startTime = DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
var statusMap = new Dictionary<Int32, String>();
|
|
||||||
if (File.Exists("Status.json"))
|
|
||||||
{
|
|
||||||
var dict = JsonConvert.DeserializeObject<Dictionary<String, JObject>>(File.ReadAllText("Status.json"));
|
|
||||||
foreach (var item in dict)
|
|
||||||
{
|
|
||||||
if (item.Value.First != null)
|
|
||||||
statusMap.Add(int.Parse(item.Value.First.Values().First().ToString()), item.Key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
LowLevelActionControl(true);
|
LowLevelActionControl(true);
|
||||||
|
|
||||||
var msg = @"Upload engineering log file from meter";
|
var msg = @"Collect all information";
|
||||||
var Filename = $"LogAndCurrentBattery_{_currentGenesis.PcbId}_Station-{ddlLocation.Items[ddlLocation.SelectedIndex]}.log";
|
LogText(msg);
|
||||||
LogTextAndFile($"{DateTime.Now}", Filename);
|
|
||||||
File.AppendAllLines(Filename, _frmHistory.rtbHistory.Lines);
|
|
||||||
|
|
||||||
|
|
||||||
LogTextAndFile(msg, Filename);
|
|
||||||
lblOverall.Text = msg;
|
lblOverall.Text = msg;
|
||||||
|
|
||||||
Task.Factory.StartNew(() =>
|
var filename = $"LogAndCurrentBattery_{_currentGenesis.PcbId}_Station-{ddlLocation.Items[ddlLocation.SelectedIndex]}.log";
|
||||||
|
File.AppendAllLines(filename, _frmHistory.rtbHistory.Lines);
|
||||||
|
|
||||||
|
LogText($"Station: {ddlLocation.Items[ddlLocation.SelectedIndex]}", filename);
|
||||||
|
var dt = DateTime.UtcNow;
|
||||||
|
msg = $@"{dt:yyyy-MM-dd HH:mm:ss}";
|
||||||
|
|
||||||
|
LogText($@"PC date time [UTC]: {msg}", filename);
|
||||||
|
|
||||||
|
_currentGenesis.ReLogin();
|
||||||
|
|
||||||
|
var genesisStatus = new GenesisStatus();
|
||||||
|
if (GenesisStatusHandler.BuildLifeTimeInformation(_currentGenesis, genesisStatus))
|
||||||
{
|
{
|
||||||
_currentGenesis.ReLogin();
|
|
||||||
|
|
||||||
|
var sbMSG = new StringBuilder();
|
||||||
var genesisStatus = new GenesisStatus();
|
sbMSG.AppendLine($"Pcb = {_currentGenesis.PcbId}");
|
||||||
if (GenesisStatusHandler.BuildLifeTimeInformation(_currentGenesis, genesisStatus))
|
|
||||||
{
|
|
||||||
|
|
||||||
var sbMSG = new StringBuilder();
|
sbMSG.AppendLine($"POWERMON_TotalUsedSeconds = {genesisStatus.ExceededLifeTime_s}");
|
||||||
sbMSG.AppendLine($"Pcb = {_currentGenesis.PcbId}");
|
sbMSG.AppendLine($"POWERMON_TotalUsedCharge = {genesisStatus.DrainedBatteryLoad_uAs}");
|
||||||
|
sbMSG.AppendLine($"POWERMON_BatteryQuantity = {genesisStatus.BatteryQuantity}");
|
||||||
|
sbMSG.AppendLine($"POWERMON_BatteryMilliAHrRating = {genesisStatus.InitialBatteryLoad_mAh}");
|
||||||
|
sbMSG.AppendLine("");
|
||||||
|
sbMSG.AppendLine($"Remaining life time in years {genesisStatus.RemainingLifeTimeYears:F2}");
|
||||||
|
sbMSG.AppendLine($"Totally drained battery load in % {genesisStatus.DrainedBatteryLoadPercent:F2}");
|
||||||
|
|
||||||
sbMSG.AppendLine($"POWERMON_TotalUsedSeconds = {genesisStatus.ExceededLifeTime_s}");
|
MessageBox.Show(sbMSG.ToString(), $"Battery for {_currentGenesis.PcbId} has remaining life " +
|
||||||
sbMSG.AppendLine($"POWERMON_TotalUsedCharge = {genesisStatus.DrainedBatteryLoad_uAs}");
|
$"time of {genesisStatus.RemainingLifeTimeYears:F2} years");
|
||||||
sbMSG.AppendLine($"POWERMON_BatteryQuantity = {genesisStatus.BatteryQuantity}");
|
|
||||||
sbMSG.AppendLine($"POWERMON_BatteryMilliAHrRating = {genesisStatus.InitialBatteryLoad_mAh}");
|
|
||||||
sbMSG.AppendLine("");
|
|
||||||
sbMSG.AppendLine($"Remaining life time in years {genesisStatus.RemainingLifeTimeYears:F2}");
|
|
||||||
sbMSG.AppendLine($"Totally drained battery load in % {genesisStatus.DrainedBatteryLoadPercent:F2}");
|
|
||||||
|
|
||||||
MessageBox.Show(sbMSG.ToString(), $"Battery for {_currentGenesis.PcbId} has remaining life " +
|
LogText(sbMSG.ToString(), filename);
|
||||||
$"time of {genesisStatus.RemainingLifeTimeYears:F2} years");
|
}
|
||||||
|
|
||||||
LogTextAndFile(sbMSG.ToString(), Filename);
|
ReadLogFiles(filename);
|
||||||
}
|
|
||||||
_currentGenesis.ReLogin();
|
|
||||||
|
|
||||||
var fileNames = ListLogFiles();
|
|
||||||
|
|
||||||
foreach (var fileName in fileNames)
|
|
||||||
{
|
|
||||||
SetActualProcessAndLog($@"Reading and analyzing {fileName}");
|
|
||||||
var success = _meterFile.ReadMeterFile(fileName, out var data);
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
{
|
|
||||||
_currentGenesis.Logout();
|
|
||||||
_currentGenesis.ReLogin();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.Count > 0)
|
|
||||||
{
|
|
||||||
LogTextAndFile($"Data: {ByteArrayStyle.ByteStyler.ToString(data.ToArray())}", Filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.Count >= 5)
|
|
||||||
{
|
|
||||||
for (var ctr = 0; ctr < data.Count;)
|
|
||||||
{
|
|
||||||
var logType = data[ctr];
|
|
||||||
var status = (data[ctr + 2] << 8) + data[ctr + 1];
|
|
||||||
var count = data[ctr + 3] + 1;
|
|
||||||
var extraDataSize = data[ctr + 4];
|
|
||||||
|
|
||||||
switch (logType)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
msg = $"({logType}) Informational";
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
msg = $"({logType}) Warning";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
msg = $"({logType}) Critical";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
msg = $"({logType}) Unknown log type";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
LogTextAndFile($"Log type: {msg}", Filename);
|
|
||||||
LogTextAndFile(statusMap.ContainsKey(status)
|
|
||||||
? $"Status: ({status}) {statusMap[status]}"
|
|
||||||
: $"Status: {status}", Filename);
|
|
||||||
LogTextAndFile($"Count: {count}", Filename);
|
|
||||||
LogTextAndFile($"Extra data size: {extraDataSize}", Filename);
|
|
||||||
|
|
||||||
//avoid access beyond the buffer and check for data to display
|
|
||||||
if (ctr + 5 + extraDataSize < data.Count && extraDataSize > 0)
|
|
||||||
{
|
|
||||||
var extraData = data.GetRange(ctr + 5, extraDataSize);
|
|
||||||
LogTextAndFile($"Extra data: {ByteArrayStyle.ByteStyler.ToString(extraData.ToArray())}", Filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
LogTextAndFile(" ", Filename);
|
|
||||||
|
|
||||||
ctr += (5 + extraDataSize);
|
|
||||||
//exit if index for next run is out of range
|
|
||||||
if (ctr + 5 >= data.Count)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogTextAndFile("File is empty", Filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}).ContinueWith(delegate
|
|
||||||
{
|
|
||||||
//add a blank line to separate next operation
|
|
||||||
LogText("");
|
|
||||||
_currentGenesis.Logout();
|
|
||||||
LowLevelActionControl(false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1621,7 +1555,7 @@ namespace Xylem.Common.Ui.GenesisToolBox
|
|||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tbxFileToEraseName_KeyDown(Object sender, KeyEventArgs e)
|
private void tbxFileToEraseName_KeyDown(Object sender, KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.KeyCode == Keys.Enter)
|
if (e.KeyCode == Keys.Enter)
|
||||||
|
|||||||
Reference in New Issue
Block a user