Created
January 26, 2021 10:03
-
-
Save mgravell/f8c6a3f9ebbecd9fc6ab30a0ef850e17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
Console.WriteLine(Unsafe.SizeOf<Flags>()); // 50, it worked! | |
[StructLayout(LayoutKind.Sequential, Pack = 1)] | |
public struct Flags | |
{ | |
public ushort frameCnt; //0-1 | |
public ushort progVersion;//2-3 | |
public byte algUM;//4 | |
public byte deviceNumber;//5 | |
public _alg_1U _alg_1U;//6-15 | |
public ushort OUTPUTS;//16-17 | |
public _statS _StatS1;//18-19 | |
// public _statS2 _StatS2; | |
public _statS _StatS2; //20-21 - changed type locally because I'm not doing 4xbit-mapping | |
//public ushort _StatS1; | |
//public ushort _StatS2; | |
public ushort nbLector; //22-23 | |
public ushort nbSignal; //24-25 | |
public byte comBlockadeT1; //26 | |
public byte comBlockadeT2; //27 | |
// public _permS permS; | |
public _statS permS; //28-29 - changed type locally because I'm not doing 4xbit-mapping | |
// public ushort permS; | |
public ushort permHistory; //30-31 | |
public ushort stopInfo; //32-33 | |
// public _controlFlagsS _controlFlagsS; | |
public _statS _controlFlagsS; //34-35 - changed type locally because I'm not doing 4xbit-mapping | |
//public ushort _controlFlagsS; | |
public ushort timerInfo; //36-37 | |
public ushort timerTrDiagCycle; //38-39 | |
public ushort sizeOfStruct; //40-41 | |
public ushort methanSensorValue1; //42-43 | |
public ushort methanSensorValue2; //44-45 | |
public ushort methanSensorValue3; //46-47 | |
public ushort methanSensorValue4; //48-49 | |
} | |
[StructLayout(LayoutKind.Sequential, Pack = 1)] | |
public struct _alg_1U | |
{ | |
public byte PZP1; | |
public byte PZP2; | |
public byte PZS; | |
public byte PZZ1; | |
public byte PZZ2; | |
public byte PZZ3; | |
public byte KB1; | |
public byte KB2; | |
public byte KRU; | |
public byte reserved; | |
} | |
[StructLayout(LayoutKind.Sequential, Pack = 1)] | |
public struct _statS | |
{ | |
private ushort _payload; | |
private bool Get(int bit) => (_payload & (1 << bit)) != 0; | |
private void Set(int bit, bool value) | |
{ | |
var mask = (ushort)(1 << bit); | |
if (value) | |
{ | |
_payload |= mask; | |
} | |
else | |
{ | |
_payload = (ushort)(_payload & ~mask); | |
} | |
} | |
public bool SYS_AW | |
{ | |
get => Get(0); | |
set => Set(0, value); | |
} | |
public bool SYS_BK | |
{ | |
get => Get(1); | |
set => Set(1, value); | |
} | |
public bool SYS_READY | |
{ | |
get => Get(2); | |
set => Set(2, value); | |
} | |
public bool SYS_WORK | |
{ | |
get => Get(3); | |
set => Set(3, value); | |
} | |
public bool PT_WORK | |
{ | |
get => Get(4); | |
set => Set(4, value); | |
} | |
public bool DISPATCHER_ON_LINE | |
{ | |
get => Get(5); | |
set => Set(5, value); | |
} | |
public bool SYS_STARTING | |
{ | |
get => Get(6); | |
set => Set(6, value); | |
} | |
public bool LEKTOR_ERROR | |
{ | |
get => Get(7); | |
set => Set(7, value); | |
} | |
public bool SYS_BK_KSR | |
{ | |
get => Get(8); | |
set => Set(8, value); | |
} | |
public bool SYS_READY_LEKTOR | |
{ | |
get => Get(9); | |
set => Set(9, value); | |
} | |
public bool SYS_INIT | |
{ | |
get => Get(10); | |
set => Set(10, value); | |
} | |
public bool KRU_WORK | |
{ | |
get => Get(11); | |
set => Set(11, value); | |
} | |
public bool SIG_RES_DIODA | |
{ | |
get => Get(12); | |
set => Set(12, value); | |
} | |
public bool SIG_RES_BK_KSR | |
{ | |
get => Get(13); | |
set => Set(13, value); | |
} | |
public bool SIG_RES_WORK | |
{ | |
get => Get(14); | |
set => Set(14, value); | |
} | |
public bool unUse16 | |
{ | |
get => Get(15); | |
set => Set(15, value); | |
} | |
} | |
// TODO: apply bit mapping as per _statS | |
[StructLayout(LayoutKind.Sequential, Pack = 1)] | |
public struct _statS2 | |
{ | |
public bool R1; | |
public bool R2; | |
public bool SAG_DISABLED; | |
public bool unUse4; | |
public bool unUse5; | |
public bool unUse6; | |
public bool unUse7; | |
public bool unUse8; | |
public bool unUse9; | |
public bool unUse10; | |
public bool unUse11; | |
public bool unUse12; | |
public bool unUse13; | |
public bool unUse14; | |
public bool unUse15; | |
public bool unUse16; | |
} | |
// TODO: apply bit mapping as per _statS | |
[StructLayout(LayoutKind.Sequential, Pack = 1)] | |
public struct _permS | |
{ | |
public bool PZP1; | |
public bool PZP2; | |
public bool PZS; | |
public bool PZZ1; | |
public bool PZZ2; | |
public bool PZZ3; | |
public bool KOMBAJN1; | |
public bool KOMBAJN2; | |
public bool KRU; | |
public bool PT; | |
public bool unUse11; | |
public bool unUse12; | |
public bool unUse13; | |
public bool unUse14; | |
public bool unUse15; | |
public bool unUse16; | |
} | |
// TODO: apply bit mapping as per _statS | |
[StructLayout(LayoutKind.Sequential, Pack = 1)] | |
public struct _controlFlagsS | |
{ | |
public bool confSaved; | |
public bool confFrameErr; | |
public bool confDataErr; | |
public bool passSaved; | |
public bool passFrameErr; | |
public bool unUse6; | |
public bool unUse7; | |
public bool unUse8; | |
public bool unUse9; | |
public bool unUse10; | |
public bool unUse11; | |
public bool unUse12; | |
public bool unUse13; | |
public bool unUse14; | |
public bool unUse15; | |
public bool unUse16; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment