- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@ Bob and @Madhu
What about
finalValue = (sint16) *wrReq->handleValPair.value.val;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No parentheses needed????
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My question was, is that ORing and shift operation required ? Can't we do it directly as I wrote in the post above ?