tbf/TBF/Rig/RegisterReaders/iPerlASICReader/communication/C4/led/TouchReadLedData.cs

77 lines
2.2 KiB
C#

using System;
using System.Globalization;
namespace TBF.Rig.RegisterReaders.iPerlASICReader.communication.C4.led
{
/// <summary>
/// Parsed data from a unidirectional TouchRead LED message.
/// The exact populated fields depend on the configured reading mode.
/// </summary>
public sealed class TouchReadLedData
{
/// <summary>
/// Raw LED message including delimiters.
/// Example: ";12345678,00012345.67,m3;"
/// </summary>
public string Raw { get; }
/// <summary>
/// Meter factory ID or serial number (if present).
/// </summary>
public string MeterId { get; set; }
/// <summary>
/// Customer programmable ID (if present).
/// </summary>
public string CustomerId { get; set; }
/// <summary>
/// Parsed meter reading value.
/// </summary>
public decimal? Reading { get; set; }
/// <summary>
/// Engineering units (e.g. "m3", "ft3", "gal").
/// </summary>
public string Units { get; set; }
/// <summary>
/// Optional alarm/status field (bitfield or text).
/// </summary>
public string AlarmStatus { get; set; }
/// <summary>
/// Timestamp when the LED data was received.
/// </summary>
public DateTime Timestamp { get; }
public TouchReadLedData(string raw)
{
if (string.IsNullOrWhiteSpace(raw))
throw new ArgumentException("Raw LED data must not be null or empty.", nameof(raw));
Raw = raw;
Timestamp = DateTime.UtcNow;
}
/// <summary>
/// Helper to safely parse a decimal value using invariant culture.
/// </summary>
public static decimal? ParseDecimal(string value)
{
if (string.IsNullOrWhiteSpace(value))
return null;
if (decimal.TryParse(
value,
NumberStyles.Number,
CultureInfo.InvariantCulture,
out var result))
{
return result;
}
return null;
}
}
}