-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -337,6 +337,84 @@ static void send_request_failed(void) | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * @brief Attempt to set the provided uptime (in milliseconds) to unix time. | ||||||||||||
| * | ||||||||||||
| * Tries to convert the provided timestamp from uptime to unix time in milliseconds, if needed. | ||||||||||||
| * If it can't convert it will stay unchanged. | ||||||||||||
| * | ||||||||||||
| * @param uptime_ms Uptime to convert to unix time. | ||||||||||||
| * @return int 0 if conversion was successful, | ||||||||||||
| * -EINVAL if the provided pointer is NULL, | ||||||||||||
| * -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) | ||||||||||||
| { | ||||||||||||
| int err; | ||||||||||||
|
|
||||||||||||
| if (uptime_ms == NULL) { | ||||||||||||
| return -EINVAL; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (*uptime_ms >= UNIX_TIME_MS_2026_01_01) { | ||||||||||||
| /* Already unix time */ | ||||||||||||
| return -EALREADY; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (*uptime_ms > k_uptime_get()) { | ||||||||||||
| /* Uptime cannot be in the future */ | ||||||||||||
| return -EINVAL; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (!date_time_is_valid()) { | ||||||||||||
| /* Cannot convert without valid time */ | ||||||||||||
| return -ENODATA; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| err = date_time_uptime_to_unix_time_ms(uptime_ms); | ||||||||||||
| if (err) { | ||||||||||||
| return err; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return 0; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| static int handle_data_timestamp(int64_t *timestamp_ms) | ||||||||||||
| { | ||||||||||||
| int err; | ||||||||||||
|
|
||||||||||||
| /* Soft attempt to convert uptime to unix time, keep original value on failure */ | ||||||||||||
| err = attempt_timestamp_to_unix_ms(timestamp_ms); | ||||||||||||
| if (err == 0 || err == -EALREADY) { | ||||||||||||
| return 0; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (IS_ENABLED(CONFIG_APP_CLOUD_HANDLE_WRONG_SAMPLE_TIMESTAMPS_KEEP)) { | ||||||||||||
| LOG_WRN("Keeping original timestamp value"); | ||||||||||||
| return 0; | ||||||||||||
| } else if (IS_ENABLED(CONFIG_APP_CLOUD_HANDLE_WRONG_SAMPLE_TIMESTAMPS_NOW)) { | ||||||||||||
| *timestamp_ms = k_uptime_get(); | ||||||||||||
|
|
||||||||||||
| err = attempt_timestamp_to_unix_ms(timestamp_ms); | ||||||||||||
| if (err) { | ||||||||||||
| LOG_ERR("Failed to set timestamp to current time, error: %d", err); | ||||||||||||
| return err; | ||||||||||||
|
Comment on lines
+401
to
+402
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| LOG_WRN("Setting timestamp to current time"); | ||||||||||||
| return 0; | ||||||||||||
|
Comment on lines
+405
to
+406
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| } else if (IS_ENABLED(CONFIG_APP_CLOUD_HANDLE_WRONG_SAMPLE_TIMESTAMPS_NO_TIMESTAMP)) { | ||||||||||||
| *timestamp_ms = NRF_CLOUD_NO_TIMESTAMP; | ||||||||||||
| return 0; | ||||||||||||
|
Comment on lines
+408
to
+409
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
| } else if (IS_ENABLED(CONFIG_APP_CLOUD_HANDLE_WRONG_SAMPLE_TIMESTAMPS_DROP)) { | ||||||||||||
| LOG_WRN("Dropping data with invalid timestamp"); | ||||||||||||
| return 0; | ||||||||||||
| } else { /* Default behavior: APP_CLOUD_HANDLE_WRONG_SAMPLE_TIMESTAMPS_DROP */ | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could add an if for |
||||||||||||
| return err; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| static void handle_network_data_message(const struct network_msg *msg) | ||||||||||||
| { | ||||||||||||
| int err; | ||||||||||||
|
|
@@ -347,11 +425,12 @@ static void handle_network_data_message(const struct network_msg *msg) | |||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /* Convert uptime to unix time */ | ||||||||||||
| timestamp_ms = msg->uptime; | ||||||||||||
| err = date_time_uptime_to_unix_time_ms(×tamp_ms); | ||||||||||||
| /* Convert timestamp to unix time */ | ||||||||||||
| timestamp_ms = msg->timestamp; | ||||||||||||
|
|
||||||||||||
| err = handle_data_timestamp(×tamp_ms); | ||||||||||||
| if (err) { | ||||||||||||
| LOG_ERR("date_time_uptime_to_unix_time_ms, error: %d", err); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| err = nrf_cloud_coap_sensor_send(CUSTOM_JSON_APPID_VAL_CONEVAL, | ||||||||||||
|
|
@@ -387,11 +466,12 @@ static int send_storage_data_to_cloud(const struct storage_data_item *item) | |||||||||||
| if (item->type == STORAGE_TYPE_BATTERY) { | ||||||||||||
| const struct power_msg *power = &item->data.BATTERY; | ||||||||||||
|
|
||||||||||||
| /* Convert uptime to unix time */ | ||||||||||||
| timestamp_ms = power->uptime; | ||||||||||||
| err = date_time_uptime_to_unix_time_ms(×tamp_ms); | ||||||||||||
| /* Convert timestamp to unix time */ | ||||||||||||
| timestamp_ms = power->timestamp; | ||||||||||||
|
|
||||||||||||
| err = handle_data_timestamp(×tamp_ms); | ||||||||||||
| if (err) { | ||||||||||||
| LOG_ERR("date_time_uptime_to_unix_time_ms, error: %d", err); | ||||||||||||
| return err; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| err = nrf_cloud_coap_sensor_send(CUSTOM_JSON_APPID_VAL_BATTERY, | ||||||||||||
|
|
@@ -416,11 +496,12 @@ static int send_storage_data_to_cloud(const struct storage_data_item *item) | |||||||||||
| if (item->type == STORAGE_TYPE_ENVIRONMENTAL) { | ||||||||||||
| const struct environmental_msg *env = &item->data.ENVIRONMENTAL; | ||||||||||||
|
|
||||||||||||
| /* Convert uptime to unix time */ | ||||||||||||
| timestamp_ms = env->uptime; | ||||||||||||
| err = date_time_uptime_to_unix_time_ms(×tamp_ms); | ||||||||||||
| /* Convert timestamp to unix time */ | ||||||||||||
| timestamp_ms = env->timestamp; | ||||||||||||
|
|
||||||||||||
| err = handle_data_timestamp(×tamp_ms); | ||||||||||||
| if (err) { | ||||||||||||
| LOG_ERR("date_time_uptime_to_unix_time_ms, error: %d", err); | ||||||||||||
| return err; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return cloud_environmental_send(env, timestamp_ms, confirmable); | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,10 @@ target_sources_ifdef(CONFIG_APP_STORAGE_BACKEND_RAM app PRIVATE | |
| backends/ram_ring_buffer_backend.c | ||
| ) | ||
|
|
||
| target_sources_ifdef(CONFIG_APP_STORAGE_BACKEND_LITTLEFS app PRIVATE | ||
| backends/littlefs_backend.c | ||
| ) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space |
||
| target_sources_ifdef(CONFIG_APP_STORAGE_SHELL app PRIVATE | ||
| storage_shell.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.
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