What happens if you try to use pstorage_load from an empty handle? What value does it load? Is there a way to check if the pstorage handle is empty?
What happens if you try to use pstorage_load from an empty handle? What value does it load? Is there a way to check if the pstorage handle is empty?
Hi sbailes
The pstorage handle represents the physical memory address that is read or written to. If the handle->block_id = 0x0003F400 and you pass that handle to a load function, you will read the specified number of bytes from 0x0003F400 and onwards. How pstorage allocates physical memory is documented on this thread.
So I suspect if the handle is empty with handle->block_id = 0x00000000, then you will attempt to read physical memory address 0x00000000.
So if I wanted to set up a check to see that handle is empty how would I do that? Use pstorage_load and compare it to something? I want to only do the pstorage_load if that handle is not empty. How could I do this?
I dont find any pstorage function to check if the handle is empty or not. What you could do is to initialize the handle->block_id to 0. Then when you have called pstorage_register, check if the handle->block_id is non zero, then pstorage has written to it surely. But when looking at the implementation of the pstorage_register function, handle->block_id is always written if the pstorage_register call returns NRF_SUCCESS, so you could check that as well.
So are you saying if the handle is empty the pstorage_register call will not return NRF_SUCCESS? Could you check the return of the pstorage_load? If it loads from an empty handle will it still return NRF_SUCCESS?
Also, right now when it loads from the empty handle it seems to give me a string of diamond symbols for some reason. I am trying to set a custom device name that is stored in pstorage. When i clear pstorage it still loads the custom name but as that string of diamonds and sets that as the device name. Can you think of why this may be happening and/or how to avoid it?