I am trying to save and read a structure using FDS, how do I go about it?
I have the structure:
typedef struct { uint8_t led_blink; //was bool uint8_t initial_adv_disable; //was bool uint8_t enable_ibeacon_Packet; //was bool uint8_t enable_cbeacon1_Health_Packet; //was bool uint8_t enable_cbeacon2_Proximity_Packet; //was bool uint8_t enable_ibeacon_SOS_Packet; //was bool uint8_t enable_Mems; //was bool }beacon_packet_struct;
My custom function for saving is:
int fds_write_struct(uint16_t file_id, uint16_t flash_key)
{
ret_code_t ret;
fds_record_t record;
fds_record_desc_t record_desc;
fds_record_desc_t desc = {0};
fds_find_token_t tok = {0};
if (flash_key == BEACON_STATE_KEY)
{
record.file_id = FILE_ID;
record.key = BEACON_STATE_KEY;
record.data.p_data = &beacon_flags; //&beacon_flags;
record.data.length_words = ( sizeof(beacon_packet_struct) + 3 ) / sizeof(uint32_t);
ret_code_t rc = fds_record_find(FILE_ID, BEACON_STATE_KEY , &desc, &tok); //Search for record. Update if found else write a new one
if (rc == FDS_SUCCESS)
{
NRF_LOG_INFO("Similar BEACON STATE Variables Record was found thus it is being updated");
rc = fds_record_update(&desc, &record);
APP_ERROR_CHECK(rc);
}
else
{
ret_code_t ret = fds_record_write(&record_desc, &record);
APP_ERROR_CHECK(ret);
NRF_LOG_INFO("First time writing BEACON STATE record");
}
return 1;
}
}
I call the function using below:
fds_write_struct(FILE_ID,BEACON_STATE_KEY);
But I get error 0x03 at:
ret_code_t ret = fds_record_write(&record_desc, &record);
APP_ERROR_CHECK(ret);
Suggestions would be greatly appreciated