mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 07:53:34 +08:00
Use union of datatypes supported by dataman to reduce wasted space
This commit is contained in:
committed by
Lorenz Meier
parent
b1e94b98b3
commit
b2bf9e15eb
@@ -47,6 +47,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <systemlib/systemlib.h>
|
#include <systemlib/systemlib.h>
|
||||||
#include <systemlib/err.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 */
|
/* Make sure caller has not given us more data than we can handle */
|
||||||
if (count > DM_MAX_DATA_SIZE) {
|
if (count > DM_MAX_DATA_SIZE) {
|
||||||
return -1;
|
return -E2BIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *buffer = &g_task_data[offset];
|
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 */
|
/* Make sure caller has not given us more data than we can handle */
|
||||||
if (count > DM_MAX_DATA_SIZE) {
|
if (count > DM_MAX_DATA_SIZE) {
|
||||||
return -1;
|
return -E2BIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write out the data, prefixed with length and persistence level */
|
/* 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 */
|
/* Make sure the caller hasn't asked for more data than we can handle */
|
||||||
if (count > DM_MAX_DATA_SIZE) {
|
if (count > DM_MAX_DATA_SIZE) {
|
||||||
return -1;
|
return -E2BIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the prefix and data */
|
/* 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 */
|
/* Make sure the caller hasn't asked for more data than we can handle */
|
||||||
if (count > DM_MAX_DATA_SIZE) {
|
if (count > DM_MAX_DATA_SIZE) {
|
||||||
return -1;
|
return -E2BIG;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the prefix and data */
|
/* Read the prefix and data */
|
||||||
|
|||||||
@@ -42,6 +42,7 @@
|
|||||||
#include <navigator/navigation.h>
|
#include <navigator/navigation.h>
|
||||||
#include <uORB/topics/mission.h>
|
#include <uORB/topics/mission.h>
|
||||||
#include <uORB/topics/fence.h>
|
#include <uORB/topics/fence.h>
|
||||||
|
#include <uORB/topics/fence_vertex.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -102,8 +103,18 @@ typedef enum {
|
|||||||
DM_INIT_REASON_VOLATILE /* Data does not survive reset */
|
DM_INIT_REASON_VOLATILE /* Data does not survive reset */
|
||||||
} dm_reset_reason;
|
} dm_reset_reason;
|
||||||
|
|
||||||
/** Maximum size in bytes of a single item instance */
|
/** Maximum size in bytes of a single item instance is
|
||||||
#define DM_MAX_DATA_SIZE 126
|
* 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 */
|
/** Retrieve from the data manager store */
|
||||||
__EXPORT ssize_t
|
__EXPORT ssize_t
|
||||||
|
|||||||
Reference in New Issue
Block a user