-
Notifications
You must be signed in to change notification settings - Fork 23
Storage flash backend #501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
02da245 to
930471b
Compare
app/src/modules/cloud/cloud.h
Outdated
| * -EALREADY if the provided time was already in unix time (>= 2026-01-01), | ||
| * -ENODATA if date time is not valid, | ||
| */ | ||
| static inline int64_t attempt_timestamp_to_unix_ms(int64_t *uptime_ms) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the ifs be spaced?
| target_sources_ifdef(CONFIG_APP_STORAGE_BACKEND_LITTLEFS app PRIVATE | ||
| backends/littlefs_backend.c | ||
| ) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space
| /* Drop oldest when full to overwrite */ | ||
| header.read_offset++; | ||
| LOG_WRN("Storage file %s full, overwriting oldest data", file_path); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space
| LOG_WRN("Setting timestamp to current time"); | ||
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| LOG_WRN("Setting timestamp to current time"); | |
| return 0; | |
| LOG_WRN("Setting timestamp to current time"); | |
| return 0; |
| *timestamp_ms = NRF_CLOUD_NO_TIMESTAMP; | ||
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| *timestamp_ms = NRF_CLOUD_NO_TIMESTAMP; | |
| return 0; | |
| *timestamp_ms = NRF_CLOUD_NO_TIMESTAMP; | |
| return 0; |
| timestamp_ms = msg->timestamp; | ||
| err = handle_data_timestamp(×tamp_ms); | ||
| if (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| timestamp_ms = msg->timestamp; | |
| err = handle_data_timestamp(×tamp_ms); | |
| if (err) { | |
| timestamp_ms = msg->timestamp; | |
| err = handle_data_timestamp(×tamp_ms); | |
| if (err) { |
| LOG_WRN("Keeping original timestamp value"); | ||
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| LOG_WRN("Keeping original timestamp value"); | |
| return 0; | |
| LOG_WRN("Keeping original timestamp value"); | |
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicks incoming, will not comment on them all
| *timestamp_ms = k_uptime_get(); | ||
| err = attempt_timestamp_to_unix_ms(timestamp_ms); | ||
| if (err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| *timestamp_ms = k_uptime_get(); | |
| err = attempt_timestamp_to_unix_ms(timestamp_ms); | |
| if (err) { | |
| *timestamp_ms = k_uptime_get(); | |
| err = attempt_timestamp_to_unix_ms(timestamp_ms); | |
| if (err) { |
| static void create_storage_file_path(const struct storage_data *type, char *out_path, | ||
| size_t max_len) | ||
| { | ||
| snprintf(out_path, max_len, "%s/%s.bin", mountpoint.mnt_point, type->name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| snprintf(out_path, max_len, "%s/%s.bin", mountpoint.mnt_point, type->name); | |
| err = snprintk(out_path, max_len, "%s/%s.bin", mountpoint.mnt_point, type->name); |
Return value should be checked, so this function should probably return an int
| max_records_per_type = total_storage_size / total_data_size; | ||
|
|
||
| if (max_records_per_type < RECORDS_PER_TYPE) { | ||
| LOG_WRN("Configured max records per type (%d) exceeds calculated capacity (%d). " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log message takes up a decent amount of flash, could it be compressed?
| ssize_t rc; | ||
|
|
||
| /* If data is NULL, use temporary buffer to verify data exists */ | ||
| uint8_t temp_buffer[type->data_size]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to make this static to avoid blowing up the stack
| return -EINVAL; | ||
| } | ||
|
|
||
| /* Open storage file */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function needs some air in form of blank lines
| ssize_t rc; | ||
|
|
||
| if (!type) { | ||
| return -EINVAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could even assert here, it's a programming error that should not happen when a static function is called with invalid arguments
SyverHaraldsen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really good, and super cool.
Just nit-pick; there are a few places with inconsistent spacing. Pointed out just a couple.
c6ab86c to
cee43d6
Compare
Changes module msg timestamps to unix time at sample creation if possible. If conversion fails, original uptime value is kept. Reattempts conversion if needed before sending to cloud, if still not possible handle error based on Kconfig setting. Signed-off-by: Trond F. Christiansen <[email protected]>
Remove the unused memory slabs from the storage_data struct, and its alocation. Signed-off-by: Trond F. Christiansen <[email protected]>
Add littleFS based flash storage backend for the storage module. Uses a file per storage data type to store a circular buffer of records. Signed-off-by: Trond F. Christiansen <[email protected]>
cee43d6 to
bfce8fb
Compare
|


Adds littlefs based flash backend for the storage module