67 lines
1.6 KiB
C#
67 lines
1.6 KiB
C#
namespace OmniPlus.Options
|
|
{
|
|
internal class OmniControlOptions
|
|
{
|
|
private readonly byte[] bits;
|
|
|
|
private OmniControlOptions(byte[] bits)
|
|
=> this.bits = bits;
|
|
|
|
public bool E0Encryption => this.bits[0] == 1;
|
|
|
|
public bool E1Encryption => this.bits[1] == 1;
|
|
|
|
public bool E2Encryption => this.bits[2] == 1;
|
|
|
|
public bool ReturnResponse
|
|
{
|
|
get => this.bits[3] == 1;
|
|
set => this.bits[3] = (byte)(value ? 1 : 0);
|
|
}
|
|
|
|
public bool NFNetwork => this.bits[4] == 1;
|
|
|
|
public bool MultipleCommands
|
|
{
|
|
get => this.bits[5] == 1;
|
|
set => this.bits[5] = (byte)(value ? 1 : 0);
|
|
}
|
|
|
|
public bool LongControl
|
|
{
|
|
get => this.bits[6] == 1;
|
|
set => this.bits[6] = (byte)(value ? 1 : 0);
|
|
}
|
|
|
|
public bool MultipleFrames
|
|
{
|
|
get => this.bits[7] == 1;
|
|
set => this.bits[7] = (byte)(value ? 1 : 0);
|
|
}
|
|
|
|
public static implicit operator OmniControlOptions(byte controlByte)
|
|
{
|
|
var bits = new byte[8];
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
bits[i] = (byte)((controlByte >> i) & 1);
|
|
}
|
|
|
|
return new OmniControlOptions(bits);
|
|
}
|
|
|
|
public static implicit operator byte (OmniControlOptions control)
|
|
{
|
|
var @byte = default(byte);
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
@byte ^= (byte)(control.bits[i] << i);
|
|
}
|
|
|
|
return @byte;
|
|
}
|
|
}
|
|
}
|