2019-02-26 08:07 AM
I have an issue with an aci_gatt_update_char_value call to update a 20 byte characteristics.
So I defined a data struct that holds all my values.
typedef struct data {
uint16_t var1;
uint16_t var2;
uint16_t var3;
uint32_t var4;
uint16_t var5;
uint16_t var6;
uint16_t var7;
uint16_t var8;
uint16_t var9;
} dataset;
and then call the update function (*data is a pointer to the initialized struct)
ret = aci_gatt_update_char_value(service_handle_runtime, char_handle_du, 0, 20, (uint8_t*)&data);
If I define the struct only containing uint8_t or uint16_t everything arrives as expected. But with the uint32_t value I get somehow an offset or whatever.
Are there any restrictions when I have a characteristic with 20 bytes?
2019-03-05 08:16 AM
In case someone ever runs into this, just copy the struct into a uint8_t array buffer and hand the buffer to the aci_gatt_update_char_value() function.
2019-03-18 09:36 PM
Yeah, this looks like a compiler variable alignment problem. Nothing to do with the function itself.
2019-05-11 12:38 AM
Basically u need to define 32 bit variables first and then 16 bits and 8bits in the struct to save space. Some compilers optimise it.
2019-05-12 07:44 PM
Please declare the structure with the "packed" attribute to prevent compiler adding padding in the structure.
With GCC, declare your structure with "__attribute__((packed))":
typdef struct __attribute__((packed)) data {
uint16_t var1;
uint16_t var2;
uint16_t var3;
uint32_t var4;
uint16_t var5;
uint16_t var6;
uint16_t var7;
uint16_t var8;
uint16_t var9;
} dataset;
In case of ArmCC, it is equivalent to:
typedef __packed struct data {
uint16_t var1;
uint16_t var2;
uint16_t var3;
uint32_t var4;
uint16_t var5;
uint16_t var6;
uint16_t var7;
uint16_t var8;
uint16_t var9;
} dataset;