Record
public record ControlByte : System.ValueType, System.IEquatable<SharpMeter.Core.Protocol.ControlByte>

Namespace: SharpMeter.Core.Protocol

Represents the control byte in a PSEM L2 frame.

Inheritance

Inherits from: System.ValueType

Implements: System.IEquatable<SharpMeter.Core.Protocol.ControlByte>

Constructors

NameDescription
ControlByte(ControlFlags Flags, byte SequenceNumber) Represents the control byte in a PSEM L2 frame.

ControlByte(ControlFlags Flags, byte SequenceNumber)

ControlByte.ControlByte(ControlFlags Flags, byte SequenceNumber)

Represents the control byte in a PSEM L2 frame.

Parameters

NameTypeDescription
FlagsSharpMeter.Core.Protocol.ControlFlagsThe control flags.
SequenceNumberbyteThe frame sequence number (0-255).

Properties

NameDescription
Flags The control flags.
IsMultiPacket Gets whether this is a multi-packet frame.
IsSinglePacket Gets whether this is a single-packet frame.
IsToggled Gets the toggle state.
SequenceNumber The frame sequence number (0-255).

Flags

ControlFlags ControlByte.Flags { get; init; }

The control flags.

IsMultiPacket

bool ControlByte.IsMultiPacket { get; }

Gets whether this is a multi-packet frame.

IsSinglePacket

bool ControlByte.IsSinglePacket { get; }

Gets whether this is a single-packet frame.

IsToggled

bool ControlByte.IsToggled { get; }

Gets the toggle state.

SequenceNumber

byte ControlByte.SequenceNumber { get; init; }

The frame sequence number (0-255).

Methods

NameDescription
Decode(byte value) static Decodes a wire byte into a ControlByte.
Encode() Encodes this control byte for wire transmission.

Decode(byte value)

ControlByte ControlByte.Decode(byte value)

Decodes a wire byte into a ControlByte.

Encode()

byte ControlByte.Encode()

Encodes this control byte for wire transmission.

Type Relationships
classDiagram
                    style ControlByte fill:#f9f,stroke:#333,stroke-width:2px
                    ControlByte --|> ValueType : inherits
                    ControlByte ..|> ControlByte~ : implements
                
View Source
/// <summary>
///     Represents the control byte in a PSEM L2 frame.
/// </summary>
/// <param name = "Flags">The control flags.</param>
/// <param name = "SequenceNumber">The frame sequence number (0-255).</param>
public readonly record struct ControlByte(ControlFlags Flags, byte SequenceNumber)
{
#region Properties
    /// <summary>Gets whether this is a multi-packet frame.</summary>
    public bool IsMultiPacket => Flags.HasFlag(ControlFlags.MultiPacket);
    /// <summary>Gets whether this is a single-packet frame.</summary>
    public bool IsSinglePacket => Flags.HasFlag(ControlFlags.SinglePacket);
    /// <summary>Gets the toggle state.</summary>
    public bool IsToggled => Flags.HasFlag(ControlFlags.ToggleBit);

#endregion
#region Methods
    /// <summary>Encodes this control byte for wire transmission.</summary>
    public byte Encode() => (byte)((byte)Flags | (SequenceNumber & 0x1F));
    /// <summary>Decodes a wire byte into a <see cref = "ControlByte"/>.</summary>
    public static ControlByte Decode(byte value) => new((ControlFlags)(value & 0xE0), (byte)(value & 0x1F));
#endregion
}
Was this page helpful?