psoc 63 ble - clear memory for writeReqParameter->handleValPair.value.val

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

cross mob
user_3671066
Level 1
Level 1

Can i clear the memory when i am done writing to it ?

I am trying to transmit data over several characteristics using the cy smart app and writing ascii values as strings(chars )..

All of my characteristics have the same length (32 bytes).

Problem is, when I copy the data from the memory writeReqParameter->handleValPair.value.val to a char array, i dont know how to clear the memory and therefor I will copy both old and new data to my char array, if my new trasmitted data is of shorter length.

How can i avoid this?

I have tried using a simple memset, but this makes the program crash.

0 Likes
1 Solution

Hello,

If the number of bytes write in the GATT database is less than the previous written values then the GATT DB will contains the already stored values and the new values(based on total length). So, you have to write the unwanted bytes with zero value based on the total length of the GATT data. Update the values in GATT DB using Cy_BLE_GATTS_WriteAttributeValueLocal(&serviceHandle) api.

Please let me know if this helps. If possible, please share your project so that we can check at our end.

Thanks,
P Yugandhar.

View solution in original post

0 Likes
3 Replies
VenkataD_41
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hi,

I guess you are using custom characteristics and/or services. The implementation of custom characteristics in PSoC BLE is such that when you overwrite new characteristic values of small length on older characteristic values of larger length, the remaining values will not be erased. So you have to manually erase the data.

One simple method you can do is to create a buffer of 32 bytes and initialize the values to '0'.

uint8 clear_memory[32] = {0};

You can use the API CyBLE_GattSWriteAttributeLocal() and write the clear_memory[32] to the characteristic whenever you want to. This will clear the entire characteristic of 32 bytes.

Please try once and let us know if there is any problem for you with this method.

Thanks

Ganesh

It doesn't work. - and maybe it really doesn't have to, i don't know.

My problem is when i read from the psoc, the data i read is both old and new -  even though I thought that i could restrict it to the length of data chosen by me, the data i read is longer.

when writing from the app to the psoc my code is this:

                memset(arr1, 0, sizeof(arr1));

                memcpy(arr1,writeReqParameter->handleValPair.value.val,writeReqParameter->handleValPair.value.len);

             

                Cy_BLE_GATTS_WriteRsp(writeReqParameter->connHandle);

when reading on the app (receiving from psoc) my code is:

                 cy_stc_ble_gatt_handle_value_pair_t serviceHandle;

                cy_stc_ble_gatt_value_t serviceData;

               

                serviceData.val = (uint8*)arr1;

                serviceData.len = strlen(arr1);

                serviceData.actualLen = strlen(arr1);

                serviceHandle.attrHandle = CY_BLE_SERVICE_CHARAC_HANDLE;

                serviceHandle.value = serviceData;

                Cy_BLE_GATTS_WriteAttributeValueLocal(&serviceHandle);

the global array arr1 is of type: char[32]

if i'm typing "helloworld" the first time, and "test" the second time, what im receiving is "testoworld"

0 Likes

Hello,

If the number of bytes write in the GATT database is less than the previous written values then the GATT DB will contains the already stored values and the new values(based on total length). So, you have to write the unwanted bytes with zero value based on the total length of the GATT data. Update the values in GATT DB using Cy_BLE_GATTS_WriteAttributeValueLocal(&serviceHandle) api.

Please let me know if this helps. If possible, please share your project so that we can check at our end.

Thanks,
P Yugandhar.

0 Likes