Characteristic - Multiple Fields

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Up until now all my custom characteristics have had a single data field, e.g. one uint8.  When using multiple data fields, how are they individually managed?  Here is my code that updates a characteristic:

void Updatecharacteristic(uint8* Data, uint16 len, uint16 attrHandle)

{

/* 'Handle' stores data parameters */

    CYBLE_GATT_HANDLE_VALUE_PAIR_T Handle;

    /* Update handle with new values */

    Handle.attrHandle = attrHandle;

    Handle.value.val = Data;

    Handle.value.len = len;

    /* Update the attribute value. This will allow

    * Client device to read the existing values over

    *  characteristic */

    CyBle_GattsWriteAttributeValue(&Handle,

    FALSE,

    &cyBle_connHandle,

    CYBLE_GATT_DB_PEER_INITIATED);

    /* Send the response to the write request received. */

    CyBle_GattsWriteRsp(cyBle_connHandle);

}

Thanks

Rich

0 Likes
1 Solution
Anonymous
Not applicable

Hi,

Whatever be the datatype used, it should be converted into uint8 types. For example if you have to send an uint16 array[ ] of 4 elements, you need to separate each word into two uint8 bytes (high end and lower end). Thus this array is converted into a uint8 array of length 8 and sent.

Regards,

- Madhu Sudhan

View solution in original post

0 Likes
4 Replies
Anonymous
Not applicable

I am guessing that all the data fields are concatenated into one data/number depending on the types.  That the fields are not individually accessible. 

Is this correct?

Rich

0 Likes
Anonymous
Not applicable

Hi,

Whatever be the datatype used, it should be converted into uint8 types. For example if you have to send an uint16 array[ ] of 4 elements, you need to separate each word into two uint8 bytes (high end and lower end). Thus this array is converted into a uint8 array of length 8 and sent.

Regards,

- Madhu Sudhan

0 Likes
Anonymous
Not applicable

Thanks Madhu.  So all characteristics are just a single string of bytes and the "fields" in the gui are just there for convenience?  Multiple fields of varying data types will presented as a string of bytes and it is up to the developer to parse the bytes.  Is that correct?

Rich

0 Likes
Anonymous
Not applicable

Yes. If you want the data to be easier to parse, you can clarify that by having the data split into multiple characteristics, as this allows using handles to differentiate data types/usage. The data bytes themselves will always be available/read/written as uint8 byte arrays to/from the database code.

0 Likes