feat(infra): add TagMapper with address mapping, value parsing, and quality mapping
This commit is contained in:
43
infra/lmxfakeproxy/TagMapper.cs
Normal file
43
infra/lmxfakeproxy/TagMapper.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using LmxFakeProxy.Grpc;
|
||||
|
||||
namespace LmxFakeProxy;
|
||||
|
||||
public class TagMapper
|
||||
{
|
||||
private readonly string _prefix;
|
||||
|
||||
public TagMapper(string prefix)
|
||||
{
|
||||
_prefix = prefix;
|
||||
}
|
||||
|
||||
public string ToOpcNodeId(string lmxTag) => $"{_prefix}{lmxTag}";
|
||||
|
||||
public static object ParseWriteValue(string value)
|
||||
{
|
||||
if (double.TryParse(value, System.Globalization.NumberStyles.Float,
|
||||
System.Globalization.CultureInfo.InvariantCulture, out var d))
|
||||
return d;
|
||||
if (bool.TryParse(value, out var b))
|
||||
return b;
|
||||
return value;
|
||||
}
|
||||
|
||||
public static string MapQuality(uint statusCode)
|
||||
{
|
||||
if (statusCode == 0) return "Good";
|
||||
if ((statusCode & 0x80000000) != 0) return "Bad";
|
||||
return "Uncertain";
|
||||
}
|
||||
|
||||
public static VtqMessage ToVtqMessage(string tag, object? value, DateTime timestampUtc, uint statusCode)
|
||||
{
|
||||
return new VtqMessage
|
||||
{
|
||||
Tag = tag,
|
||||
Value = value?.ToString() ?? string.Empty,
|
||||
TimestampUtcTicks = timestampUtc.Ticks,
|
||||
Quality = MapQuality(statusCode)
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user