cancel
Showing results for 
Search instead for 
Did you mean: 

aci_gatt_update_char_value for 20 bytes structs

aj.sk
Associate III

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?

4 REPLIES 4
aj.sk
Associate III

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.

rdscliff
Associate II

Yeah, this looks like a compiler variable alignment problem. Nothing to do with the function itself.

kasi viswanadh
Associate II

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.

Winfred LU
ST Employee

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;