cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

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

0 Likes
Reply
1 Solution
HeLi_263931
Honored Contributor II

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).

View solution in original post

0 Likes
Reply
2 Replies
HeLi_263931
Honored Contributor II

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).

View solution in original post

0 Likes
Reply
Anonymous
Not applicable

Thanks hli 🙂

0 Likes
Reply