Skip to main content
aj.sk
Associate III
Feb 26, 2019 4:07 PM UTC
Question

aci_gatt_update_char_value for 20 bytes structs

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?

    This topic has been closed for replies.

    4 replies

    aj.sk
    aj.skAuthor
    Associate III
    Mar 5, 2019 4:16 PM UTC

    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 III
    Mar 19, 2019 4:36 AM UTC

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

    kasi viswanadh
    Associate II
    May 11, 2019 7:38 AM UTC

    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
    May 13, 2019 2:44 AM UTC

    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;