mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-25 09:33:34 +08:00
dataman: add DatamanClient with sync functions
Rework of dataman
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2013, 2014 PX4 Development Team. All rights reserved.
|
||||
* Copyright (c) 2013-2023 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@@ -42,21 +42,29 @@
|
||||
#include <navigator/navigation.h>
|
||||
#include <uORB/topics/mission.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Types of items that the data manager can store */
|
||||
typedef enum {
|
||||
DM_KEY_SAFE_POINTS = 0, /* Safe points coordinates, safe point 0 is home point */
|
||||
DM_KEY_FENCE_POINTS, /* Fence vertex coordinates */
|
||||
DM_KEY_WAYPOINTS_OFFBOARD_0, /* Mission way point coordinates sent over mavlink */
|
||||
DM_KEY_WAYPOINTS_OFFBOARD_1, /* (alternate between 0 and 1) */
|
||||
DM_KEY_MISSION_STATE, /* Persistent mission state */
|
||||
DM_KEY_SAFE_POINTS = 0, ///< Safe points coordinates, safe point 0 is home point
|
||||
DM_KEY_FENCE_POINTS, ///< Fence vertex coordinates
|
||||
DM_KEY_WAYPOINTS_OFFBOARD_0, ///< Mission way point coordinates sent over mavlink
|
||||
DM_KEY_WAYPOINTS_OFFBOARD_1, ///< (alternate between 0 and 1)
|
||||
DM_KEY_MISSION_STATE, ///< Persistent mission state
|
||||
DM_KEY_COMPAT,
|
||||
DM_KEY_NUM_KEYS /* Total number of item types defined */
|
||||
DM_KEY_NUM_KEYS ///< Total number of item types defined
|
||||
} dm_item_t;
|
||||
|
||||
/** Types of function calls supported by the worker task */
|
||||
typedef enum {
|
||||
DM_GET_ID = 0, ///< Get dataman client ID
|
||||
DM_WRITE, ///< Write index for given item
|
||||
DM_READ, ///< Read index for given item
|
||||
DM_CLEAR, ///< Clear all index for given item
|
||||
DM_LOCK, ///< Lock all items for given item types
|
||||
DM_UNLOCK, ///< Unlock all items for given item types
|
||||
DM_NUMBER_OF_FUNCS
|
||||
} dm_function_t;
|
||||
|
||||
/** The maximum number of instances for each item type */
|
||||
#if defined(MEMORY_CONSTRAINED_SYSTEM)
|
||||
enum {
|
||||
DM_KEY_SAFE_POINTS_MAX = 8,
|
||||
@@ -67,7 +75,6 @@ enum {
|
||||
DM_KEY_COMPAT_MAX = 1
|
||||
};
|
||||
#else
|
||||
/** The maximum number of instances for each item type */
|
||||
enum {
|
||||
DM_KEY_SAFE_POINTS_MAX = 8,
|
||||
DM_KEY_FENCE_POINTS_MAX = 64,
|
||||
@@ -78,6 +85,32 @@ enum {
|
||||
};
|
||||
#endif
|
||||
|
||||
/* table of maximum number of instances for each item type */
|
||||
static const unsigned g_per_item_max_index[DM_KEY_NUM_KEYS] = {
|
||||
DM_KEY_SAFE_POINTS_MAX,
|
||||
DM_KEY_FENCE_POINTS_MAX,
|
||||
DM_KEY_WAYPOINTS_OFFBOARD_0_MAX,
|
||||
DM_KEY_WAYPOINTS_OFFBOARD_1_MAX,
|
||||
DM_KEY_MISSION_STATE_MAX,
|
||||
DM_KEY_COMPAT_MAX
|
||||
};
|
||||
|
||||
constexpr uint32_t MISSION_SAFE_POINT_SIZE = sizeof(struct mission_safe_point_s);
|
||||
constexpr uint32_t MISSION_FENCE_POINT_SIZE = sizeof(struct mission_fence_point_s);
|
||||
constexpr uint32_t MISSION_ITEM_SIZE = sizeof(struct mission_item_s);
|
||||
constexpr uint32_t MISSION_SIZE = sizeof(struct mission_s);
|
||||
constexpr uint32_t DATAMAN_COMPAT_SIZE = sizeof(struct mission_s);
|
||||
|
||||
/** The table of the size of each item type */
|
||||
static constexpr size_t g_per_item_size[DM_KEY_NUM_KEYS] = {
|
||||
MISSION_SAFE_POINT_SIZE,
|
||||
MISSION_FENCE_POINT_SIZE,
|
||||
MISSION_ITEM_SIZE,
|
||||
MISSION_ITEM_SIZE,
|
||||
MISSION_SIZE,
|
||||
DATAMAN_COMPAT_SIZE
|
||||
};
|
||||
|
||||
struct dataman_compat_s {
|
||||
uint64_t key;
|
||||
};
|
||||
@@ -89,57 +122,3 @@ struct dataman_compat_s {
|
||||
(sizeof(struct mission_s) << 16) + (sizeof(struct mission_stats_entry_s) << 12) + \
|
||||
(sizeof(struct mission_fence_point_s) << 8) + (sizeof(struct mission_safe_point_s) << 4) + \
|
||||
sizeof(struct dataman_compat_s))
|
||||
|
||||
/** Retrieve from the data manager store */
|
||||
__EXPORT ssize_t
|
||||
dm_read(
|
||||
dm_item_t item, /* The item type to retrieve */
|
||||
unsigned index, /* The index of the item */
|
||||
void *buffer, /* Pointer to caller data buffer */
|
||||
size_t buflen /* Length in bytes of data to retrieve */
|
||||
);
|
||||
|
||||
/** write to the data manager store */
|
||||
__EXPORT ssize_t
|
||||
dm_write(
|
||||
dm_item_t item, /* The item type to store */
|
||||
unsigned index, /* The index of the item */
|
||||
const void *buffer, /* Pointer to caller data buffer */
|
||||
size_t buflen /* Length in bytes of data to retrieve */
|
||||
);
|
||||
|
||||
/**
|
||||
* Lock all items of a type. Can be used for atomic updates of multiple items (single items are always updated
|
||||
* atomically).
|
||||
* Note that this lock is independent from dm_read & dm_write calls.
|
||||
* @return 0 on success and lock taken, -1 on error (lock not taken, errno set)
|
||||
*/
|
||||
__EXPORT int
|
||||
dm_lock(
|
||||
dm_item_t item /* The item type to lock */
|
||||
);
|
||||
|
||||
/**
|
||||
* Try to lock all items of a type (@see sem_trywait()).
|
||||
* @return 0 if lock is taken, -1 otherwise (on error or if already locked. errno is set accordingly)
|
||||
*/
|
||||
__EXPORT int
|
||||
dm_trylock(
|
||||
dm_item_t item /* The item type to lock */
|
||||
);
|
||||
|
||||
/** Unlock all items of a type */
|
||||
__EXPORT void
|
||||
dm_unlock(
|
||||
dm_item_t item /* The item type to unlock */
|
||||
);
|
||||
|
||||
/** Erase all items of this type */
|
||||
__EXPORT int
|
||||
dm_clear(
|
||||
dm_item_t item /* The item type to clear */
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user