Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. struct BURInSyncStruct
  2. {
  3. uint16_t Sync1 : 12;
  4. uint16_t Sync2 : 12;
  5. uint16_t Sync3 : 12;
  6. uint16_t Sync4 : 12;
  7. } __attribute__((packed));
  8.  
  9. [StructLayout(LayoutKind.Explicit)]
  10. struct BURInSyncStruct
  11. {
  12. [FieldOffset(0)]
  13. public ushort Sync1;
  14. [FieldOffset(1)]
  15. public ushort Sync2;
  16. [FieldOffset(2)]
  17. public ushort Sync3;
  18. [FieldOffset(3)]
  19. public ushort Sync4;
  20. }
  21.  
  22. [StructLayout(LayoutKind.Sequential)]
  23. public struct BURInSyncStruct
  24. {
  25. public static BURInSyncStruct Create()
  26. {
  27. BURInSyncStruct s = new BURInSyncStruct();
  28. s.data = new byte[6];
  29. return s;
  30. }
  31.  
  32. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
  33. public byte[] data;
  34.  
  35. public ushort Sync1
  36. {
  37. get
  38. {
  39. byte[] bytes64 = new byte[8];
  40. Array.Copy(data, bytes64, data.Length);
  41. ulong x = BitConverter.ToUInt64(bytes64, 0);
  42.  
  43. ulong y = x & 0x0FFF;
  44. return (ushort)y;
  45. }
  46.  
  47. set
  48. {
  49. byte[] bytes64 = new byte[8];
  50. Array.Copy(data, bytes64, data.Length);
  51. ulong x = BitConverter.ToUInt64(bytes64, 0);
  52. x = x & ~((ulong)0x0FFF);
  53.  
  54. ulong y = (ulong)value & 0x0FFF;
  55. ulong res = x | y;
  56. bytes64 = BitConverter.GetBytes(res);
  57. Array.Copy(bytes64, data, data.Length);
  58. }
  59. }
  60.  
  61. public ushort Sync2
  62. {
  63. get
  64. {
  65. byte[] bytes64 = new byte[8];
  66. Array.Copy(data, bytes64, data.Length);
  67. ulong x = BitConverter.ToUInt64(bytes64, 0);
  68. ulong y = x & 0xFFF000;
  69. y = y >> 12;
  70. return (ushort)y;
  71. }
  72.  
  73. set
  74. {
  75. byte[] bytes64 = new byte[8];
  76. Array.Copy(data, bytes64, data.Length);
  77. ulong x = BitConverter.ToUInt64(bytes64, 0);
  78. x = x & ~((ulong)0xFFF000);
  79.  
  80. ulong y = (ulong)(value << 12) & 0xFFF000;
  81. ulong res = x | y;
  82. bytes64 = BitConverter.GetBytes(res);
  83. Array.Copy(bytes64, data, data.Length);
  84. }
  85. }
  86.  
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement