OSDP.Net 5.2.1
A .NET library for implementing the Open Supervised Device Protocol (OSDP)
Loading...
Searching...
No Matches
OSDP.Net.LineQuality.LineQualityProtocol Class Reference

Constants and helpers for the OSDP Line Quality Test Procedure. More...

Static Public Member Functions

static bool IsLineQualityVendorCode (ReadOnlySpan< byte > candidate)
 Determines whether the supplied bytes are the reserved line quality vendor code.
static byte[] GeneratePattern (TestPattern pattern, int length)
 Generates the test data for a pattern.
static bool ValidatePattern (TestPattern pattern, ReadOnlySpan< byte > data)
 Determines whether data matches what the pattern should have produced.
static bool IsSupportedPattern (TestPattern pattern)
 Determines whether a pattern identifier is one this implementation can generate.
static int ToBaudRate (LineQualityBaudRate baudRateId)
 Converts a Baud Rate ID into the baud rate it represents.
static bool TryGetBaudRateId (int baudRate, out LineQualityBaudRate baudRateId)
 Converts a baud rate into the Baud Rate ID that represents it.
static int IterationsPerCombination (TestProfile profile)
 Returns the number of iterations a profile runs for each pattern and size combination.
static double DetectionLimitPercent (int packetsSent)
 Calculates the smallest packet loss rate a run of the given size can rule out, as a percentage, using the rule of three: with no observed failures the 95% upper confidence bound on the loss rate is approximately 3/N.
static TimeSpan TransmissionTime (int byteCount, int baudRate)
 Calculates how long a frame occupies the line, used to let a transmission drain before changing the baud rate.

Static Public Attributes

const byte TestAddress = 0x7D
 The dedicated line quality test address, 125 (0x7D).
const byte EchoCommandId = 0x01
 Command and reply identifier for the echo exchange.
const byte BaudRateChangeCommandId = 0x02
 Command and reply identifier for the baud rate change exchange.
const int EchoHeaderLength = 7
 Number of bytes preceding the test data in an echo request or response: three vendor code bytes, command/reply identifier, sequence number, pattern or status, and length.
const int MaxPayloadLength = 113
 The largest test payload every conforming responder must accept, 113 bytes.

Properties

static IReadOnlyList< int > TestPayloadLengths = new[] { 0, 48, MaxPayloadLength } [get]
 The payload lengths exercised by the test matrix in section 3.10.
static IReadOnlyList< int > DefaultBaudRates [get]
 The six baud rates named by OSDP section 5.2, in ascending order.
static ReadOnlySpan< byte > VendorCode [get]
 The reserved line quality vendor code, 02-00-0A.

Detailed Description

Constants and helpers for the OSDP Line Quality Test Procedure.

The procedure measures RS-485 physical layer quality by bouncing known bit patterns off a responder at a dedicated address and counting what comes back. It rides on osdp_MFG (0x80) and osdp_MFGREP (0x90) with a reserved vendor code, so test traffic coexists with production devices on the same bus without either interfering with the other.

Test traffic is always sent in clear text with CRC-16. A secure channel would encrypt the payload and turn every pattern into statistically identical pseudo-random data.

Definition at line 21 of file LineQualityProtocol.cs.

Member Function Documentation

◆ DetectionLimitPercent()

double OSDP.Net.LineQuality.LineQualityProtocol.DetectionLimitPercent ( int packetsSent)
static

Calculates the smallest packet loss rate a run of the given size can rule out, as a percentage, using the rule of three: with no observed failures the 95% upper confidence bound on the loss rate is approximately 3/N.

Parameters
packetsSentNumber of packets sent at a single baud rate.
Returns
The detection limit as a percentage, or 100 when nothing was sent.

This is why a zero-failure result is not the same as a zero loss rate. Reporting the limit alongside a pass keeps the result from being read as a stronger claim than the sample size supports.

◆ GeneratePattern()

byte[] OSDP.Net.LineQuality.LineQualityProtocol.GeneratePattern ( TestPattern pattern,
int length )
inlinestatic

Generates the test data for a pattern.

Parameters
patternThe pattern to generate.
lengthNumber of bytes to generate, 0 to MaxPayloadLength.
Returns
The generated test data.
Exceptions
ArgumentOutOfRangeExceptionThe length is negative or exceeds MaxPayloadLength, or the pattern is not defined.

Definition at line 107 of file LineQualityProtocol.cs.

References IsSupportedPattern(), and MaxPayloadLength.

◆ IsLineQualityVendorCode()

bool OSDP.Net.LineQuality.LineQualityProtocol.IsLineQualityVendorCode ( ReadOnlySpan< byte > candidate)
inlinestatic

Determines whether the supplied bytes are the reserved line quality vendor code.

Parameters
candidateBytes to test, normally the first three bytes of an osdp_MFG payload.
Returns
true when the bytes match 02-00-0A.

Definition at line 87 of file LineQualityProtocol.cs.

Referenced by OSDP.Net.LineQuality.BaudRateChange.TryParse(), OSDP.Net.LineQuality.BaudRateChangeAck.TryParse(), OSDP.Net.LineQuality.EchoRequest.TryParse(), and OSDP.Net.LineQuality.EchoResponse.TryParse().

◆ IsSupportedPattern()

bool OSDP.Net.LineQuality.LineQualityProtocol.IsSupportedPattern ( TestPattern pattern)
static

Determines whether a pattern identifier is one this implementation can generate.

Parameters
patternThe pattern identifier to test.
Returns
true when the pattern is defined by the specification.

The underlying type is byte, so an identifier can never be below TestPattern.AllZeros; only the upper bound needs checking.

Referenced by GeneratePattern(), and ValidatePattern().

◆ IterationsPerCombination()

int OSDP.Net.LineQuality.LineQualityProtocol.IterationsPerCombination ( TestProfile profile)
inlinestatic

Returns the number of iterations a profile runs for each pattern and size combination.

Parameters
profileThe profile to look up.
Returns
Iterations per combination.
Exceptions
ArgumentOutOfRangeExceptionThe profile is not defined.

Definition at line 202 of file LineQualityProtocol.cs.

◆ ToBaudRate()

int OSDP.Net.LineQuality.LineQualityProtocol.ToBaudRate ( LineQualityBaudRate baudRateId)
inlinestatic

Converts a Baud Rate ID into the baud rate it represents.

Parameters
baudRateIdThe identifier to convert.
Returns
The baud rate in bits per second.
Exceptions
ArgumentOutOfRangeExceptionThe identifier is not defined.

Definition at line 164 of file LineQualityProtocol.cs.

Referenced by OSDP.Net.LineQuality.LineQualityTest.RunAsync().

◆ TransmissionTime()

TimeSpan OSDP.Net.LineQuality.LineQualityProtocol.TransmissionTime ( int byteCount,
int baudRate )
static

Calculates how long a frame occupies the line, used to let a transmission drain before changing the baud rate.

Parameters
byteCountNumber of bytes in the frame.
baudRateThe rate the frame was sent at.
Returns
The transmission time, assuming ten bits per byte.

◆ TryGetBaudRateId()

bool OSDP.Net.LineQuality.LineQualityProtocol.TryGetBaudRateId ( int baudRate,
out LineQualityBaudRate baudRateId )
inlinestatic

Converts a baud rate into the Baud Rate ID that represents it.

Parameters
baudRateThe baud rate in bits per second.
baudRateIdOn success, the matching identifier.
Returns
true when the rate has a defined identifier.

Definition at line 182 of file LineQualityProtocol.cs.

◆ ValidatePattern()

bool OSDP.Net.LineQuality.LineQualityProtocol.ValidatePattern ( TestPattern pattern,
ReadOnlySpan< byte > data )
inlinestatic

Determines whether data matches what the pattern should have produced.

Parameters
patternThe expected pattern.
dataThe data received back from the responder.
Returns
true when every byte matches the pattern.

Definition at line 135 of file LineQualityProtocol.cs.

References IsSupportedPattern().

Member Data Documentation

◆ BaudRateChangeCommandId

const byte OSDP.Net.LineQuality.LineQualityProtocol.BaudRateChangeCommandId = 0x02
static

◆ EchoCommandId

const byte OSDP.Net.LineQuality.LineQualityProtocol.EchoCommandId = 0x01
static

◆ EchoHeaderLength

const int OSDP.Net.LineQuality.LineQualityProtocol.EchoHeaderLength = 7
static

Number of bytes preceding the test data in an echo request or response: three vendor code bytes, command/reply identifier, sequence number, pattern or status, and length.

Definition at line 49 of file LineQualityProtocol.cs.

Referenced by OSDP.Net.LineQuality.EchoRequest.BuildData(), OSDP.Net.LineQuality.EchoResponse.BuildData(), OSDP.Net.LineQuality.EchoRequest.TryParse(), and OSDP.Net.LineQuality.EchoResponse.TryParse().

◆ MaxPayloadLength

const int OSDP.Net.LineQuality.LineQualityProtocol.MaxPayloadLength = 113
static

The largest test payload every conforming responder must accept, 113 bytes.

OSDP section 5.6 guarantees only a 128-byte receive buffer. A frame carries 6 header bytes and 2 CRC bytes, leaving 120 bytes of message data, of which EchoHeaderLength are consumed by the line quality header. At this length both the command and its echoed reply are exactly 128 bytes.

Definition at line 60 of file LineQualityProtocol.cs.

Referenced by GeneratePattern().

◆ TestAddress

const byte OSDP.Net.LineQuality.LineQualityProtocol.TestAddress = 0x7D
static

The dedicated line quality test address, 125 (0x7D).

Chosen to sit above the usual production range and below the 0x7F configuration address, while remaining a legal osdp_COMSET assignment target.

Definition at line 37 of file LineQualityProtocol.cs.

Property Documentation

◆ DefaultBaudRates

IReadOnlyList<int> OSDP.Net.LineQuality.LineQualityProtocol.DefaultBaudRates
staticget
Initial value:
=
new[] { 9600, 19200, 38400, 57600, 115200, 230400 }

The six baud rates named by OSDP section 5.2, in ascending order.

This is the default set a test sweeps; 460800 is deliberately excluded because it is not an OSDP rate.

Definition at line 74 of file LineQualityProtocol.cs.

Referenced by OSDP.Net.LineQuality.LineQualityTest.RunAsync().

◆ TestPayloadLengths

IReadOnlyList<int> OSDP.Net.LineQuality.LineQualityProtocol.TestPayloadLengths = new[] { 0, 48, MaxPayloadLength }
staticget

The payload lengths exercised by the test matrix in section 3.10.

Definition at line 65 of file LineQualityProtocol.cs.

◆ VendorCode

ReadOnlySpan<byte> OSDP.Net.LineQuality.LineQualityProtocol.VendorCode
staticget

The reserved line quality vendor code, 02-00-0A.

Definition at line 80 of file LineQualityProtocol.cs.


The documentation for this class was generated from the following file: