I have defined a Bus object in Matlab and I am passing it to a C S-function that will do some processing. I have initialized the input like this inside mdlInitializeSizes
:
#if defined(MATLAB_MEX_FILE)
if (ssGetSimMode(S) != SS_SIMMODE_SIZES_CALL_ONLY)
{
DTypeId dataTypeIdReg;
ssRegisterTypeFromNamedObject(S, BUS_OBJ_NAME, &dataTypeIdReg);
if(dataTypeIdReg == INVALID_DTYPE_ID) return;
ssSetInputPortDataType(S, 0, dataTypeIdReg);
}
#endif
ssSetInputPortWidth(S, 0, 1);
ssSetBusInputAsStruct(S, 0, 1);
ssSetInputPortDirectFeedThrough(S, 0, 1);
ssSetInputPortRequiredContiguous(S, 0, 1);
I have also auto-generated a C struct containing the same variables as the signals inside the Bus object.
Some of the signals in the Bus are also buses, so the C struct was generated recursively. For example:
struct myStruct
{
uint8_t var1[8];
uint32_t var2;
myOtherStruct1 var3;
myOtherStruct2 var4;
...
}
Now I want to read the Bus object into the struct. For that, I do:
const myStruct *busData = (const myStruct *) ssGetInputPortSignal(S, 0);
The problem is that busData does not have the correct data for var4
and following variables. If I print the raw data received from ssGetInputPortSignal I can find the data that I am expecting, but it is not at the correct position in the array; instead it has some padding.
Therefore I would like to ask:
- Is this the correct way of reading a Bus object into a struct in a C S-function?
- How can I disable the padding so that all the data is contiguous?
Thanks in advance!