Pad the configuration struct to 250 bytes, so the SDK.DLL ABI doesn't change when fields are added.

master
Glenn Maynard 6 years ago
parent 6e09b2ea53
commit 7a4bbc6eab
  1. 8
      sdk/SMX.h
  2. 13
      smx-config/SMX.cs

@ -215,8 +215,14 @@ struct SMXConfig
uint8_t panelThreshold5Low, panelThreshold5High;
uint8_t panelThreshold6Low, panelThreshold6High;
uint8_t panelThreshold8Low, panelThreshold8High;
// Pad the struct to 250 bytes. This keeps this struct size from changing
// as we add fields, so the ABI doesn't change. Applications should leave
// any data in here unchanged when calling SMX_SetConfig.
uint8_t padding[166];
};
static_assert(sizeof(SMXConfig) == 84, "Expected 84 bytes");
static_assert(offsetof(SMXConfig, padding) == 84, "Expected 84 bytes"); // includes one padding byte
static_assert(sizeof(SMXConfig) == 250, "Expected 250 bytes");
// The values (except for Off) correspond with the protocol and must not be changed.
enum SensorTestMode {

@ -60,6 +60,10 @@ namespace SMX
public Byte panelThreshold6Low, panelThreshold6High;
public Byte panelThreshold8Low, panelThreshold8High;
// Pad this struct to exactly 250 bytes.
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 166)]
public Byte[] padding;
// enabledSensors is a mask of which panels are enabled. Return this as an array
// for convenience.
public bool[] GetEnabledPanels()
@ -291,6 +295,15 @@ namespace SMX
{
if(!DLLAvailable()) return;
// Sanity check SMXConfig, which should be 250 bytes. If this is incorrect,
// check the padding array.
{
SMXConfig config = new SMXConfig();
int bytes = Marshal.SizeOf(config);
if(bytes != 250)
throw new Exception("SMXConfig is " + bytes + " bytes, but should be 250 bytes");
}
// Make a wrapper to convert from the native enum to SMXUpdateCallbackReason.
InternalUpdateCallback NewCallback = delegate(int PadNumber, int reason, IntPtr user) {
SMXUpdateCallbackReason ReasonEnum = (SMXUpdateCallbackReason) Enum.ToObject(typeof(SMXUpdateCallbackReason), reason);

Loading…
Cancel
Save