2using System.Collections.Generic;
30 internal static readonly
byte[] VendorCodeBytes = { 0x02, 0x00, 0x0A };
67 private static readonly
int[] BaudRateValues =
68 { 9600, 19200, 38400, 57600, 115200, 230400, 460800 };
75 new[] { 9600, 19200, 38400, 57600, 115200, 230400 };
80 public static ReadOnlySpan<byte>
VendorCode => VendorCodeBytes;
89 if (candidate.Length < VendorCodeBytes.Length)
return false;
91 for (
int index = 0; index < VendorCodeBytes.Length; index++)
93 if (candidate[index] != VendorCodeBytes[index])
return false;
111 throw new ArgumentOutOfRangeException(nameof(length),
112 $
"Payload length must be between 0 and {MaxPayloadLength}.");
117 throw new ArgumentOutOfRangeException(nameof(pattern), $
"Unknown test pattern {pattern}.");
120 var data =
new byte[length];
121 for (
int index = 0; index < length; index++)
123 data[index] = ExpectedByte(pattern, index);
139 for (
int index = 0; index < data.Length; index++)
141 if (data[index] != ExpectedByte(pattern, index))
return false;
167 int index = (int)baudRateId;
168 if (index >= BaudRateValues.Length)
170 throw new ArgumentOutOfRangeException(nameof(baudRateId), $
"Unknown baud rate ID {baudRateId}.");
173 return BaudRateValues[index];
184 for (
int index = 0; index < BaudRateValues.Length; index++)
186 if (BaudRateValues[index] != baudRate)
continue;
192 baudRateId =
default;
210 throw new ArgumentOutOfRangeException(nameof(profile), $
"Unknown test profile {profile}.");
227 packetsSent <= 0 ? 100.0 : 300.0 / packetsSent;
239 : TimeSpan.FromSeconds(byteCount * 10.0 / baudRate);
241 internal static byte ExpectedByte(
TestPattern pattern,
int index)
249 case TestPattern.Sequential:
return (
byte)(index & 0xFF);
250 case TestPattern.WalkingOne:
return (
byte)(1 << (index % 8));
251 default:
return 0x00;
Constants and helpers for the OSDP Line Quality Test Procedure.
static IReadOnlyList< int > TestPayloadLengths
The payload lengths exercised by the test matrix in section 3.10.
static byte[] GeneratePattern(TestPattern pattern, int length)
Generates the test data for a pattern.
static int ToBaudRate(LineQualityBaudRate baudRateId)
Converts a Baud Rate ID into the baud rate it represents.
const byte BaudRateChangeCommandId
Command and reply identifier for the baud rate change exchange.
const int MaxPayloadLength
The largest test payload every conforming responder must accept, 113 bytes.
static IReadOnlyList< int > DefaultBaudRates
The six baud rates named by OSDP section 5.2, in ascending order.
static bool ValidatePattern(TestPattern pattern, ReadOnlySpan< byte > data)
Determines whether data matches what the pattern should have produced.
static double DetectionLimitPercent(int packetsSent)
Calculates the smallest packet loss rate a run of the given size can rule out, as a percentage,...
static int IterationsPerCombination(TestProfile profile)
Returns the number of iterations a profile runs for each pattern and size combination.
static bool IsSupportedPattern(TestPattern pattern)
Determines whether a pattern identifier is one this implementation can generate.
static ReadOnlySpan< byte > VendorCode
The reserved line quality vendor code, 02-00-0A.
static bool IsLineQualityVendorCode(ReadOnlySpan< byte > candidate)
Determines whether the supplied bytes are the reserved line quality vendor code.
static TimeSpan TransmissionTime(int byteCount, int baudRate)
Calculates how long a frame occupies the line, used to let a transmission drain before changing the b...
const int EchoHeaderLength
Number of bytes preceding the test data in an echo request or response: three vendor code bytes,...
static bool TryGetBaudRateId(int baudRate, out LineQualityBaudRate baudRateId)
Converts a baud rate into the Baud Rate ID that represents it.
const byte TestAddress
The dedicated line quality test address, 125 (0x7D).
const byte EchoCommandId
Command and reply identifier for the echo exchange.
TestPattern
Test pattern identifiers defined by the OSDP Line Quality Test Procedure, section 3....
LineQualityBaudRate
Baud Rate identifiers defined by the OSDP Line Quality Test Procedure, section 3.4.
TestProfile
Test profiles from section 3.10 of the Line Quality Test Procedure.