BLE Write Payload Best Practice | Cypress Semiconductor
BLE Write Payload Best Practice
What is the best way to get the entire payload of a BLE write request or BLE write command?
I was looking at the FindMe example and it shows that you can get the complete value of the payload by saving the data byte-by-byte into an array. Assuming that Cypress doesn't provide an API to just get the data in a variable directly, this seems logical. However, in the loop they use handleValPair.value.len instead of handleValPair.value.actualLen. My understanding is that .len will return the length that is defined for that Characteristic, and .actualLen will return the length of the data payload that got sent. For example, if you set the device_name Characteristic to 20 bytes, then .len will return 20 and .actualLen will return the actual length of the string that got sent over.
Can anyone verify that I'm understanding this correctly, and if there's a reason you would want to loop through the entire length, instead of just the number of bytes that came in from the BLE write? Perhaps it is because the changed_name variable is the full length of the attribute so you would want to read it all to make sure you fill up the array so you don't have any bytes that are 'left over' from a previous usage?
Here's the code from the FindMe example:
// lots of code skipped here when I pasted this example....
wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *) eventParam;
if(wrReqParam->handleValPair.attrHandle == 0x03) // this is the BLE standard device name Characteristic
changed_name[i] = wrReqParam->handleValPair.value.val[i];