You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Loading from the settings is done via Zephyr settings API
static int battery_load_state(const char *p_key, size_t len,
settings_read_cb read_cb, void *p_cb_arg, void *p_param)
{
zsw_history_t* history = (zsw_history_t*) p_param;
ARG_UNUSED(p_key);
if (len != sizeof(zsw_history_t)) {
return -EINVAL;
}
int num_bytes_read = read_cb(p_cb_arg, &battery_context, len);
LOG_DBG("Read %d bytes", num_bytes_read);
LOG_DBG("Number samples: %d", battery_context.num_samples);
if (num_bytes_read == 0) {
LOG_ERR("Currupt battery settings data");
} else if (num_bytes_read != sizeof(zsw_history_t)) {
LOG_WRN("No battery settings data read");
return -ENODATA;
}
LOG_DBG("Loaded battery history data");
return 0;
}
...
if (settings_load_subtree_direct(Key, battery_load_state, &battery_context)) {
LOG_ERR("Error during settings_load_subtree!");
return -EFAULT;
}
But read_cb(p_cb_arg, &battery_context, len) requires a pointer to a data structure and a length. Because battery_context contains a pointer to data the data doesn´t get loaded correctly, because the samples pointer inside of battery_context doesn´t get dereferenced correctly. So the saved data contain the memory address of the samples array and not the data.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The idea is to write a generic history manager to provide an option to store sensor data as a history for a given time (like the current battery app).
Current idea
Use of a history object like this
and a sensor specific sample object like this
Then you can initialize it in the code as follows:
Current issue
Loading from the settings is done via Zephyr settings API
But
read_cb(p_cb_arg, &battery_context, len)
requires a pointer to a data structure and a length. Becausebattery_context
contains a pointer to data the data doesn´t get loaded correctly, because thesamples
pointer inside ofbattery_context
doesn´t get dereferenced correctly. So the saved data contain the memory address of thesamples
array and not the data.Ideas to solve it
Beta Was this translation helpful? Give feedback.
All reactions