Strictly necessary cookies are on by default and cannot be turned off. Functional, Performance and Tracking/targeting/sharing cookies can be turned on below based on your preferences (this banner will remain available for you to accept cookies). You may change your cookie settings by deleting cookies from your browser. Then this banner will appear again. You can learn more details about cookies HERE.
Strictly necessary (always on)
Functional, Performance and Tracking/targeting/sharing (default off)
I need to send/receive data over BLE between my PSoC device and a mobile phone. There are multiple different parameters to transfer and the data length is bigger than 512 bytes.
So, instead of creating different characteristics for each parameter, I wanted to write a packet communication protocol on one characteristic. In this packet communication protocol, the sender will send the data and also say which parameter this data belongs.
I added multiple fields in my characteristic like below:
I also created a struct just like this characteristic fields, which is also below:
#pragma pack(push, 1)
Then when I need to write the attribute value, I will reference my struct by casting it to uint8 like below:
Do you think this is a good method? I saw this method (multiple field usage) in the Cypress's BLE Bootloader Module. But I couldn't find how they used these fields in the source codes. There is not any structure definition. Maybe they just defined these fields to help the developer to understand the packet easily? I don't know.
And the real question is:
Does Cypress Bootloader always send 500 bytes of data in each packet? Because if the data length changes, the position of the checksum and end bytes will shift. How to handle them? I mean, if I receive a packet in which the data length is not exactly 500, I can not mass copy the received packet to my structure?
If the data length is always 500, why do they added the 'Data Length' byte in the fields? And how do they handle the last packet that does not actually necessarily contain 500 bytes of data? Do you append zeros to it?
You can use this method by adding multiple fields in a characteristic. For more information on the Cypress Bootloader service please refer to this link. The maximum number of bytes that can be sent is Negotiated MTU Size-3 bytes only. If we don't update all the bytes in data then it will take zeros in that positions. The data length field is used for updating the length of the data with respect to MTU size.