mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-02 05:30:36 +08:00
dataman file read fixed size buffer
This commit is contained in:
@@ -227,7 +227,7 @@ static const unsigned g_per_item_max_index[DM_KEY_NUM_KEYS] = {
|
||||
#define DM_SECTOR_HDR_SIZE 4 /* data manager per item header overhead */
|
||||
|
||||
/* Table of the len of each item type */
|
||||
static const unsigned g_per_item_size[DM_KEY_NUM_KEYS] = {
|
||||
static constexpr size_t g_per_item_size[DM_KEY_NUM_KEYS] = {
|
||||
sizeof(struct mission_save_point_s) + DM_SECTOR_HDR_SIZE,
|
||||
sizeof(struct mission_fence_point_s) + DM_SECTOR_HDR_SIZE,
|
||||
sizeof(struct mission_item_s) + DM_SECTOR_HDR_SIZE,
|
||||
@@ -612,11 +612,14 @@ static ssize_t _ram_read(dm_item_t item, unsigned index, void *buf, size_t count
|
||||
static ssize_t
|
||||
_file_read(dm_item_t item, unsigned index, void *buf, size_t count)
|
||||
{
|
||||
if (item >= DM_KEY_NUM_KEYS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char buffer[g_per_item_size[item]];
|
||||
int len, offset;
|
||||
|
||||
/* Get the offset for this item */
|
||||
offset = calculate_offset(item, index);
|
||||
int offset = calculate_offset(item, index);
|
||||
|
||||
/* If item type or index out of range, return error */
|
||||
if (offset < 0) {
|
||||
@@ -629,7 +632,7 @@ _file_read(dm_item_t item, unsigned index, void *buf, size_t count)
|
||||
}
|
||||
|
||||
/* Read the prefix and data */
|
||||
len = -1;
|
||||
int len = -1;
|
||||
|
||||
if (lseek(dm_operations_data.file.fd, offset, SEEK_SET) == offset) {
|
||||
len = read(dm_operations_data.file.fd, buffer, count + DM_SECTOR_HDR_SIZE);
|
||||
|
||||
Reference in New Issue
Block a user