This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Saving & Reading a structure using FDS (Flash Data Storage) SDK15.3

I am trying to save and read a structure using FDS, how do I go about it?

I have the structure:

Fullscreen
1
2
3
4
5
6
7
typedef struct
{
uint16_t total_runhours_flash;
float total_energy_consumed_flash;
}energy_struct;
energy_struct energy_variables;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Is this correct by populating the record as such?:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
fds_record_t record;
fds_record_desc_t record_desc;
record.file_id = FILE_ID;
record.key = ENERGY_KEY;
record.data.p_data = &energy_variables;
record.data.length_words = sizeof(energy_variables);
fds_record_desc_t desc = {0};
rc = fds_record_update(&desc, &record);
APP_ERROR_CHECK(rc);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

And to read is the main problem, I can't seem to match the types in which it would load data from the structure: (This is giving error)

Fullscreen
1
energy_variables = (struct energy_struct *) config.p_data;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Parents
  • Hi,

    The first two code snippets (defining a struct and writing it with FDS looks sensible). I am not sure what you want to convey in the last. What are you trying to do? What fails? If you need a simple example you can refer to this post. You can also refer to the FDS example, but it is a bit over-complicated.

  • I am facing another problem with another structure saving. The structure I have is: 

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    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;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    My custom function for saving is:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    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)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I call the function using below:

    Fullscreen
    1
    fds_write_struct(FILE_ID,BEACON_STATE_KEY);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    But I get error 0x03 at:

    Fullscreen
    1
    2
    ret_code_t ret = fds_record_write(&record_desc, &record);
    APP_ERROR_CHECK(ret);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Suggestion would be greatly appreciated Slight smile

Reply Children
No Data