BLE Gatt Characteristic value format

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

cross mob
Anonymous
Not applicable

Hello,

   

I don't seem to understand the how the data types work in PSoC creator. In the settings of the BLE component there is an option to choose what format does the Characteristic value has. It is pretty easy to use the value in the code when data type is uint8, but I can't get it to work with sint16. 

   

When server receives a write request it is easy to extract the value from  wrReq = (CYBLE_GATTS_WRITE_REQ_PARAM_T *)eventParam with the following line uint8 value = wrReq->handleValPair.value.val[0];

   

But this wouldn't work with the sint16. How can I take the two bytes from the characteristic value and make it into a number that can be used to comparison and math operations in the code of the server. 

   

Regards, Andris

0 Likes
1 Solution
Anonymous
Not applicable

You can get two uint8 values and merge them into a uint16 value as:

   

sint16 finalValue;

   

finalValue =  (wrReq->handleValPair.value.val[1]<<8) |  wrReq->handleValPair.value.val[0];

   

Regards,

   

- Madhu Sudhan

View solution in original post

0 Likes
5 Replies
Anonymous
Not applicable

You can get two uint8 values and merge them into a uint16 value as:

   

sint16 finalValue;

   

finalValue =  (wrReq->handleValPair.value.val[1]<<8) |  wrReq->handleValPair.value.val[0];

   

Regards,

   

- Madhu Sudhan

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@Madhu

   

Don't you need to typecast val[1] so that the bits do not get shifted out of the uint8 as:

   

finalValue =  ((uint16)(wrReq->handleValPair.value.val[1])<<8) |  wrReq->handleValPair.value.val[0];

   

 

   

Bob

0 Likes
Anonymous
Not applicable

@ Bob and @Madhu

   

What about

   

finalValue =  (sint16) *wrReq->handleValPair.value.val;

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

No parentheses needed????

   

 

   

Bob

0 Likes
Anonymous
Not applicable

My question was, is that ORing and shift operation required ? Can't we do it directly as I wrote in the post above ?

0 Likes