Use union of datatypes supported by dataman to reduce wasted space

This commit is contained in:
David Sidrane 2016-09-23 09:09:40 -10:00 committed by Lorenz Meier
parent b1e94b98b3
commit b2bf9e15eb
2 changed files with 18 additions and 6 deletions

View File

@ -47,6 +47,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <systemlib/systemlib.h>
#include <systemlib/err.h>
@ -388,7 +389,7 @@ static ssize_t _ram_write(dm_item_t item, unsigned char index, dm_persitence_t p
/* Make sure caller has not given us more data than we can handle */
if (count > DM_MAX_DATA_SIZE) {
return -1;
return -E2BIG;
}
uint8_t *buffer = &g_task_data[offset];
@ -429,7 +430,7 @@ _file_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, co
/* Make sure caller has not given us more data than we can handle */
if (count > DM_MAX_DATA_SIZE) {
return -1;
return -E2BIG;
}
/* Write out the data, prefixed with length and persistence level */
@ -474,7 +475,7 @@ static ssize_t _ram_read(dm_item_t item, unsigned char index, void *buf, size_t
/* Make sure the caller hasn't asked for more data than we can handle */
if (count > DM_MAX_DATA_SIZE) {
return -1;
return -E2BIG;
}
/* Read the prefix and data */
@ -517,7 +518,7 @@ _file_read(dm_item_t item, unsigned char index, void *buf, size_t count)
/* Make sure the caller hasn't asked for more data than we can handle */
if (count > DM_MAX_DATA_SIZE) {
return -1;
return -E2BIG;
}
/* Read the prefix and data */

View File

@ -42,6 +42,7 @@
#include <navigator/navigation.h>
#include <uORB/topics/mission.h>
#include <uORB/topics/fence.h>
#include <uORB/topics/fence_vertex.h>
#ifdef __cplusplus
extern "C" {
@ -102,8 +103,18 @@ typedef enum {
DM_INIT_REASON_VOLATILE /* Data does not survive reset */
} dm_reset_reason;
/** Maximum size in bytes of a single item instance */
#define DM_MAX_DATA_SIZE 126
/** Maximum size in bytes of a single item instance is
* defined by adding the structure type to the union below
*/
typedef union dataman_max_size_t {
struct mission_item_s mission_item;
struct mission_s mission;
struct fence_vertex_s vertex;
} dataman_max_size_t;
#define DM_MAX_DATA_SIZE sizeof(dataman_max_size_t)
/** Retrieve from the data manager store */
__EXPORT ssize_t