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:

typedef struct
{
    uint16_t total_runhours_flash;
    float total_energy_consumed_flash;
}energy_struct;

energy_struct energy_variables;

Is this correct by populating the record as such?:

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);

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)

energy_variables = (struct energy_struct *) config.p_data;

Parents Reply Children
  • So from the FDS example I kind of figured it out.

    The write function would be like:

    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) + 3 ) / sizeof(uint32_t);
    
    fds_record_desc_t desc = {0};
    
    rc = fds_record_update(&desc, &record);
    APP_ERROR_CHECK(rc);

    And for reading:

    rc = fds_record_open(&desc, &config);
    APP_ERROR_CHECK(rc);
    
    memcpy(&energy_variables, config.p_data, sizeof(energy_struct));

Related