- Add JoeAppEngine folder to OPC UA nodes.json (BTCS, AlarmCntsBySeverity, Scheduler/ScanTime) - Fix DataConnectionActor: capture Self in PreStart for use from non-actor threads, preventing Self.Tell failure in Disconnected event handler - Implement InstanceActor.HandleConnectionQualityChanged to mark attributes Bad on disconnect - Fix LmxFakeProxy TagMapper to serialize arrays as JSON instead of "System.Int32[]" - Allow DataType and DataSourceReference updates in TemplateService.UpdateAttributeAsync - Update test_infra_opcua.md with JoeAppEngine documentation
54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Text.Json;
|
|
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 string FormatValue(object? value)
|
|
{
|
|
if (value is null) return string.Empty;
|
|
if (value is Array or IList)
|
|
return JsonSerializer.Serialize(value);
|
|
return value.ToString() ?? string.Empty;
|
|
}
|
|
|
|
public static VtqMessage ToVtqMessage(string tag, object? value, DateTime timestampUtc, uint statusCode)
|
|
{
|
|
return new VtqMessage
|
|
{
|
|
Tag = tag,
|
|
Value = FormatValue(value),
|
|
TimestampUtcTicks = timestampUtc.Ticks,
|
|
Quality = MapQuality(statusCode)
|
|
};
|
|
}
|
|
}
|