common/Hardware/Common.Hardware.Ports/UI1236Control.cs
2026-04-23 17:50:07 +02:00

72 lines
1.9 KiB
C#

namespace Common.Hardware.Ports
{
using System;
public static partial class SerialPortExtensions
{
internal class UI1236Control
{
private readonly Byte[] bits;
private UI1236Control(Byte[] bits)
=> this.bits = bits;
public Boolean E0Encryption => this.bits[0] == 1;
public Boolean E1Encryption => this.bits[1] == 1;
public Boolean E2Encryption => this.bits[2] == 1;
public Boolean ReturnResponse
{
get => this.bits[3] == 1;
set => this.bits[3] = (Byte)(value ? 1 : 0);
}
public Boolean NFNetwork => this.bits[4] == 1;
public Boolean MultipleCommands
{
get => this.bits[5] == 1;
set => this.bits[5] = (Byte)(value ? 1 : 0);
}
public Boolean LongControl
{
get => this.bits[6] == 1;
set => this.bits[6] = (Byte)(value ? 1 : 0);
}
public Boolean MultipleFrames
{
get => this.bits[7] == 1;
set => this.bits[7] = (Byte)(value ? 1 : 0);
}
public static implicit operator UI1236Control(Byte controlByte)
{
var bits = new Byte[8];
for (var i = 0; i < 8; i++)
{
bits[i] = (Byte)((controlByte >> i) & 1);
}
return new UI1236Control(bits);
}
public static implicit operator Byte(UI1236Control control)
{
var @Byte = default(Byte);
for (var i = 0; i < 8; i++)
{
@Byte ^= (Byte)(control.bits[i] << i);
}
return @Byte;
}
}
}
}