aboutsummaryrefslogtreecommitdiff
path: root/src/modules/dataman
diff options
context:
space:
mode:
authorJean Cyr <jcyr@dillobits.com>2014-04-28 00:52:19 -0400
committerJean Cyr <jcyr@dillobits.com>2014-04-28 00:52:19 -0400
commitab257ebcced2af6ddb528a9d48355dc2cac7d10a (patch)
tree550b07e41052cccced28aafa439bcda264fa952b /src/modules/dataman
parentad77ba26427aa9a2d8b8241fc95271667a1c0863 (diff)
downloadpx4-firmware-ab257ebcced2af6ddb528a9d48355dc2cac7d10a.tar.gz
px4-firmware-ab257ebcced2af6ddb528a9d48355dc2cac7d10a.tar.bz2
px4-firmware-ab257ebcced2af6ddb528a9d48355dc2cac7d10a.zip
Proper data manager restart handling
Introduce SYS_RESTART_TYPE parameter having one of 3 values: boot restart, inflight restart, or unknown restart, and defaulting to unknown restart. px4io.cpp sets this parameter according to the type of restart detected. dataman.c retrieves this parameter and clears data entries according to their persistence level. Does nothing if unknown restart.
Diffstat (limited to 'src/modules/dataman')
-rw-r--r--src/modules/dataman/dataman.c33
-rw-r--r--src/modules/dataman/dataman.h5
2 files changed, 28 insertions, 10 deletions
diff --git a/src/modules/dataman/dataman.c b/src/modules/dataman/dataman.c
index c132b0040..7505ba358 100644
--- a/src/modules/dataman/dataman.c
+++ b/src/modules/dataman/dataman.c
@@ -416,26 +416,26 @@ static int
_restart(dm_reset_reason reason)
{
unsigned char buffer[2];
- int offset, result = 0;
+ int offset = 0, result = 0;
/* We need to scan the entire file and invalidate and data that should not persist after the last reset */
/* Loop through all of the data segments and delete those that are not persistent */
- offset = 0;
-
while (1) {
size_t len;
/* Get data segment at current offset */
if (lseek(g_task_fd, offset, SEEK_SET) != offset) {
- result = -1;
+ /* must be at eof */
break;
}
len = read(g_task_fd, buffer, sizeof(buffer));
- if (len == 0)
+ if (len != sizeof(buffer)) {
+ /* must be at eof */
break;
+ }
/* check if segment contains data */
if (buffer[0]) {
@@ -443,12 +443,12 @@ _restart(dm_reset_reason reason)
/* Whether data gets deleted depends on reset type and data segment's persistence setting */
if (reason == DM_INIT_REASON_POWER_ON) {
- if (buffer[1] != DM_PERSIST_POWER_ON_RESET) {
+ if (buffer[1] > DM_PERSIST_POWER_ON_RESET) {
clear_entry = 1;
}
} else {
- if ((buffer[1] != DM_PERSIST_POWER_ON_RESET) && (buffer[1] != DM_PERSIST_IN_FLIGHT_RESET)) {
+ if (buffer[1] > DM_PERSIST_IN_FLIGHT_RESET) {
clear_entry = 1;
}
}
@@ -628,6 +628,23 @@ task_main(int argc, char *argv[])
fsync(g_task_fd);
+ /* see if we need to erase any items based on restart type */
+ int sys_restart_val;
+ if (param_get(param_find("SYS_RESTART_TYPE"), &sys_restart_val) == OK) {
+ if (sys_restart_val == DM_INIT_REASON_POWER_ON) {
+ warnx("Power on restart");
+ _restart(DM_INIT_REASON_POWER_ON);
+ }
+ else if (sys_restart_val == DM_INIT_REASON_IN_FLIGHT) {
+ warnx("In flight restart");
+ _restart(DM_INIT_REASON_IN_FLIGHT);
+ }
+ else
+ warnx("Unknown restart");
+ }
+ else
+ warnx("Unknown restart");
+
/* We use two file descriptors, one for the caller context and one for the worker thread */
/* They are actually the same but we need to some way to reject caller request while the */
/* worker thread is shutting down but still processing requests */
@@ -724,7 +741,7 @@ start(void)
return -1;
}
- /* wait for the thread to actuall initialize */
+ /* wait for the thread to actually initialize */
sem_wait(&g_init_sema);
sem_destroy(&g_init_sema);
diff --git a/src/modules/dataman/dataman.h b/src/modules/dataman/dataman.h
index 33c9fcd15..4382baeb5 100644
--- a/src/modules/dataman/dataman.h
+++ b/src/modules/dataman/dataman.h
@@ -75,7 +75,8 @@ extern "C" {
/* The reason for the last reset */
typedef enum {
DM_INIT_REASON_POWER_ON = 0, /* Data survives resets */
- DM_INIT_REASON_IN_FLIGHT /* Data survives in-flight resets only */
+ DM_INIT_REASON_IN_FLIGHT, /* Data survives in-flight resets only */
+ DM_INIT_REASON_VOLATILE /* Data does not survive reset */
} dm_reset_reason;
/* Maximum size in bytes of a single item instance */
@@ -100,7 +101,7 @@ extern "C" {
size_t buflen /* Length in bytes of data to retrieve */
);
- /* Retrieve from the data manager store */
+ /* Erase all items of this type */
__EXPORT int
dm_clear(
dm_item_t item /* The item type to clear */