- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
A struct contaning all data required for my application stored in an uneven fashion which I crated just like how I arranged sensor data in HID input report using PRoC BLE device. By uneven I mean,
struct { uint8 data0; uint16 data1; uint32 data2; uint8 data3; uint16 data4; } InputReport;
The above type of declaration creates padding. Now since, CyBle_HidssSetCharacteristicValue() function requires character array as input for new data update, I did below coding for sending data.
InputReport report;
uint8 *dataForTransmission;
dataForTransmission = (uint8 *)malloc(sizeof(InputReport));
memcpy(dataForTransmission, &report, sizeof(InputReport));
CyBle_HidssSetCharacteristicValue(0, CYBLE_HIDS_REPORT_MAP, sizeof(InputReport), dataForTransmission);
Will the above code create any problem, since structure has padding and not sure if HID database for report map does not have any padding like thing?
Thanks
Ashutosh
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can do:
typedef struct { int whatever; } __attribute__ ((__packed__)) InputReport
to remove the padding.
Apart from that, as long as you use the actual size of the struct, and your receiving side knows about the padding, it doesn't matter (apart from transmitting more data than needed).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can do:
typedef struct { int whatever; } __attribute__ ((__packed__)) InputReport
to remove the padding.
Apart from that, as long as you use the actual size of the struct, and your receiving side knows about the padding, it doesn't matter (apart from transmitting more data than needed).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks hli 🙂