IperlASIC - Improved and added tests, hardware integtration tests works
Improve `VersionTypeResult` parsing and handling: Add compact/legacy payload support. Extend `ReadingUnits`. Update `IperlHatIntegrationTests` and `RadioService` with new tests and functionality integration.
This commit is contained in:
+4
-1
@@ -4,6 +4,9 @@ namespace TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommon
|
||||
{
|
||||
CubicMeters = 0x00,
|
||||
CubicFeet = 0x01,
|
||||
UsGallons = 0x02
|
||||
UsGallons = 0x02,
|
||||
UsGallons1 = 0x04,
|
||||
UsGallons2 = 0x08,
|
||||
UsGallons3 = 0x10,
|
||||
}
|
||||
}
|
||||
+117
-41
@@ -2,58 +2,134 @@ using System.Text.RegularExpressions;
|
||||
|
||||
namespace TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons
|
||||
{
|
||||
public class VersionTypeResult
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace TBF.Rig.TestMethods.iPerlCommunication.communication.C4.IperlHatProtocol
|
||||
{
|
||||
public string TouchReadVersion { get; set; }
|
||||
public string MeterDeviceType { get; set; }
|
||||
public string MeterFirmwareVersion { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
public class VersionTypeResult
|
||||
{
|
||||
return $"TouchReadVersion={TouchReadVersion}, " +
|
||||
$"MeterDeviceType={MeterDeviceType}, " +
|
||||
$"MeterFirmwareVersion={MeterFirmwareVersion}";
|
||||
}
|
||||
|
||||
|
||||
public static VersionTypeResult ParseVersionTypePayload(string payload)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(payload))
|
||||
return null;
|
||||
public string TouchReadVersion { get; set; }
|
||||
|
||||
// Example:
|
||||
// vers: Harry T:B800, V:06.06.01, FW:190215,
|
||||
// 7ECE, B1.6.01, HW:4, Serial:0
|
||||
public string MeterDeviceType { get; set; }
|
||||
|
||||
string meterDeviceType = GetPayloadValue(payload, "T");
|
||||
string touchReadVersion = GetPayloadValue(payload, "V");
|
||||
string meterFirmwareVersion = GetPayloadValue(payload, "FW");
|
||||
public string MeterFirmwareVersion { get; set; }
|
||||
|
||||
if (string.IsNullOrWhiteSpace(meterDeviceType) &&
|
||||
string.IsNullOrWhiteSpace(touchReadVersion) &&
|
||||
string.IsNullOrWhiteSpace(meterFirmwareVersion))
|
||||
public static VersionTypeResult ParseVersionTypePayload(
|
||||
string payload)
|
||||
{
|
||||
return null;
|
||||
if (string.IsNullOrWhiteSpace(payload))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string normalizedPayload = payload
|
||||
.Trim('\0', '\r', '\n', ' ');
|
||||
|
||||
VersionTypeResult result =
|
||||
ParseCompactPayload(normalizedPayload);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
return ParseLegacyPayload(normalizedPayload);
|
||||
}
|
||||
|
||||
return new VersionTypeResult
|
||||
private static VersionTypeResult ParseCompactPayload(
|
||||
string payload)
|
||||
{
|
||||
MeterDeviceType = meterDeviceType,
|
||||
TouchReadVersion = touchReadVersion,
|
||||
MeterFirmwareVersion = meterFirmwareVersion
|
||||
};
|
||||
}
|
||||
// Expected format:
|
||||
// B1.23,SWM004,1.00
|
||||
|
||||
private static string GetPayloadValue(string payload, string key)
|
||||
{
|
||||
Match match = Regex.Match(
|
||||
payload,
|
||||
@"(?:^|[\s,])" + Regex.Escape(key) + @":\s*([^,\s]+)",
|
||||
RegexOptions.IgnoreCase);
|
||||
string[] parts = payload.Split(',');
|
||||
|
||||
return match.Success
|
||||
? match.Groups[1].Value.Trim()
|
||||
: null;
|
||||
if (parts.Length != 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string touchReadVersion = parts[0].Trim();
|
||||
string meterDeviceType = parts[1].Trim();
|
||||
string meterFirmwareVersion = parts[2].Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(touchReadVersion) ||
|
||||
string.IsNullOrWhiteSpace(meterDeviceType) ||
|
||||
string.IsNullOrWhiteSpace(meterFirmwareVersion))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new VersionTypeResult
|
||||
{
|
||||
TouchReadVersion = touchReadVersion,
|
||||
MeterDeviceType = meterDeviceType,
|
||||
MeterFirmwareVersion = meterFirmwareVersion
|
||||
};
|
||||
}
|
||||
|
||||
private static VersionTypeResult ParseLegacyPayload(
|
||||
string payload)
|
||||
{
|
||||
// Expected example:
|
||||
//
|
||||
// vers: Harry T:B800, V:06.06.01, FW:190215,
|
||||
// 7ECE, B1.6.01, HW:4, Serial:0
|
||||
|
||||
Match deviceTypeMatch = Regex.Match(
|
||||
payload,
|
||||
@"(?:^|[\s,])T\s*:\s*([^,\s]+)",
|
||||
RegexOptions.IgnoreCase);
|
||||
|
||||
Match versionMatch = Regex.Match(
|
||||
payload,
|
||||
@"(?:^|[\s,])V\s*:\s*([^,\s]+)",
|
||||
RegexOptions.IgnoreCase);
|
||||
|
||||
Match firmwareMatch = Regex.Match(
|
||||
payload,
|
||||
@"(?:^|[\s,])FW\s*:\s*([^,\s]+)",
|
||||
RegexOptions.IgnoreCase);
|
||||
|
||||
if (!deviceTypeMatch.Success ||
|
||||
!versionMatch.Success ||
|
||||
!firmwareMatch.Success)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string meterDeviceType =
|
||||
deviceTypeMatch.Groups[1].Value.Trim();
|
||||
|
||||
string touchReadVersion =
|
||||
versionMatch.Groups[1].Value.Trim();
|
||||
|
||||
string meterFirmwareVersion =
|
||||
firmwareMatch.Groups[1].Value.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(touchReadVersion) ||
|
||||
string.IsNullOrWhiteSpace(meterDeviceType) ||
|
||||
string.IsNullOrWhiteSpace(meterFirmwareVersion))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new VersionTypeResult
|
||||
{
|
||||
TouchReadVersion = touchReadVersion,
|
||||
MeterDeviceType = meterDeviceType,
|
||||
MeterFirmwareVersion = meterFirmwareVersion
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return
|
||||
$"TouchReadVersion={TouchReadVersion}, " +
|
||||
$"MeterDeviceType={MeterDeviceType}, " +
|
||||
$"MeterFirmwareVersion={MeterFirmwareVersion}";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using log4net;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.diagnosticLed;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.IperlHatProtocol;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.protocolCommons.TBF.Rig.TestMethods.iPerlCommunication.communication.C4.IperlHatProtocol;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.C4.wiredProtocol;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.communication.Utils;
|
||||
using TBF.Rig.TestMethods.iPerlCommunication.iPerlHead;
|
||||
|
||||
Reference in New Issue
Block a user