Browse Source

dataman: don't wrap around at 256

The dataman started overwriting contents after 256 items because the
item index were only uint8_t. This fix allows for more than 256
waypoints.
sbg
Julian Oes 8 years ago committed by Daniel Agar
parent
commit
8c1e85a65f
  1. 34
      src/modules/dataman/dataman.c
  2. 4
      src/modules/dataman/dataman.h

34
src/modules/dataman/dataman.c

@ -67,8 +67,8 @@
*/ */
__EXPORT int dataman_main(int argc, char *argv[]); __EXPORT int dataman_main(int argc, char *argv[]);
__EXPORT ssize_t dm_read(dm_item_t item, unsigned char index, void *buffer, size_t buflen); __EXPORT ssize_t dm_read(dm_item_t item, unsigned index, void *buffer, size_t buflen);
__EXPORT ssize_t dm_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, const void *buffer, __EXPORT ssize_t dm_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buffer,
size_t buflen); size_t buflen);
__EXPORT int dm_clear(dm_item_t item); __EXPORT int dm_clear(dm_item_t item);
__EXPORT void dm_lock(dm_item_t item); __EXPORT void dm_lock(dm_item_t item);
@ -76,22 +76,22 @@ __EXPORT void dm_unlock(dm_item_t item);
__EXPORT int dm_restart(dm_reset_reason restart_type); __EXPORT int dm_restart(dm_reset_reason restart_type);
/* Private File based Operations */ /* Private File based Operations */
static ssize_t _file_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, const void *buf, static ssize_t _file_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf,
size_t count); size_t count);
static ssize_t _file_read(dm_item_t item, unsigned char index, void *buf, size_t count); static ssize_t _file_read(dm_item_t item, unsigned index, void *buf, size_t count);
static int _file_clear(dm_item_t item); static int _file_clear(dm_item_t item);
static int _file_restart(dm_reset_reason reason); static int _file_restart(dm_reset_reason reason);
/* Private Ram based Operations */ /* Private Ram based Operations */
static ssize_t _ram_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, const void *buf, static ssize_t _ram_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf,
size_t count); size_t count);
static ssize_t _ram_read(dm_item_t item, unsigned char index, void *buf, size_t count); static ssize_t _ram_read(dm_item_t item, unsigned index, void *buf, size_t count);
static int _ram_clear(dm_item_t item); static int _ram_clear(dm_item_t item);
static int _ram_restart(dm_reset_reason reason); static int _ram_restart(dm_reset_reason reason);
typedef struct dm_operations_t { typedef struct dm_operations_t {
ssize_t (*write)(dm_item_t item, unsigned char index, dm_persitence_t persistence, const void *buf, size_t count); ssize_t (*write)(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf, size_t count);
ssize_t (*read)(dm_item_t item, unsigned char index, void *buf, size_t count); ssize_t (*read)(dm_item_t item, unsigned index, void *buf, size_t count);
int (*clear)(dm_item_t item); int (*clear)(dm_item_t item);
int (*restart)(dm_reset_reason reason); int (*restart)(dm_reset_reason reason);
} dm_operations_t; } dm_operations_t;
@ -131,14 +131,14 @@ typedef struct {
union { union {
struct { struct {
dm_item_t item; dm_item_t item;
unsigned char index; unsigned index;
dm_persitence_t persistence; dm_persitence_t persistence;
const void *buf; const void *buf;
size_t count; size_t count;
} write_params; } write_params;
struct { struct {
dm_item_t item; dm_item_t item;
unsigned char index; unsigned index;
void *buf; void *buf;
size_t count; size_t count;
} read_params; } read_params;
@ -351,7 +351,7 @@ static bool is_running(void)
} }
/* Calculate the offset in file of specific item */ /* Calculate the offset in file of specific item */
static int static int
calculate_offset(dm_item_t item, unsigned char index) calculate_offset(dm_item_t item, unsigned index)
{ {
/* Make sure the item type is valid */ /* Make sure the item type is valid */
@ -380,7 +380,7 @@ calculate_offset(dm_item_t item, unsigned char index)
*/ */
/* write to the data manager RAM buffer */ /* write to the data manager RAM buffer */
static ssize_t _ram_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, const void *buf, static ssize_t _ram_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf,
size_t count) size_t count)
{ {
@ -419,7 +419,7 @@ static ssize_t _ram_write(dm_item_t item, unsigned char index, dm_persitence_t p
/* write to the data manager file */ /* write to the data manager file */
static ssize_t static ssize_t
_file_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, const void *buf, size_t count) _file_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf, size_t count)
{ {
unsigned char buffer[k_sector_size]; unsigned char buffer[k_sector_size];
size_t len; size_t len;
@ -469,7 +469,7 @@ _file_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, co
} }
/* Retrieve from the data manager RAM buffer*/ /* Retrieve from the data manager RAM buffer*/
static ssize_t _ram_read(dm_item_t item, unsigned char index, void *buf, size_t count) static ssize_t _ram_read(dm_item_t item, unsigned index, void *buf, size_t count)
{ {
/* Get the offset for this item */ /* Get the offset for this item */
int offset = calculate_offset(item, index); int offset = calculate_offset(item, index);
@ -509,7 +509,7 @@ static ssize_t _ram_read(dm_item_t item, unsigned char index, void *buf, size_t
/* Retrieve from the data manager file */ /* Retrieve from the data manager file */
static ssize_t static ssize_t
_file_read(dm_item_t item, unsigned char index, void *buf, size_t count) _file_read(dm_item_t item, unsigned index, void *buf, size_t count)
{ {
unsigned char buffer[k_sector_size]; unsigned char buffer[k_sector_size];
int len, offset; int len, offset;
@ -756,7 +756,7 @@ _file_restart(dm_reset_reason reason)
/** Write to the data manager file */ /** Write to the data manager file */
__EXPORT ssize_t __EXPORT ssize_t
dm_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, const void *buf, size_t count) dm_write(dm_item_t item, unsigned index, dm_persitence_t persistence, const void *buf, size_t count)
{ {
work_q_item_t *work; work_q_item_t *work;
@ -783,7 +783,7 @@ dm_write(dm_item_t item, unsigned char index, dm_persitence_t persistence, const
/** Retrieve from the data manager file */ /** Retrieve from the data manager file */
__EXPORT ssize_t __EXPORT ssize_t
dm_read(dm_item_t item, unsigned char index, void *buf, size_t count) dm_read(dm_item_t item, unsigned index, void *buf, size_t count)
{ {
work_q_item_t *work; work_q_item_t *work;

4
src/modules/dataman/dataman.h

@ -134,7 +134,7 @@ typedef union dataman_max_size_t {
__EXPORT ssize_t __EXPORT ssize_t
dm_read( dm_read(
dm_item_t item, /* The item type to retrieve */ dm_item_t item, /* The item type to retrieve */
unsigned char index, /* The index of the item */ unsigned index, /* The index of the item */
void *buffer, /* Pointer to caller data buffer */ void *buffer, /* Pointer to caller data buffer */
size_t buflen /* Length in bytes of data to retrieve */ size_t buflen /* Length in bytes of data to retrieve */
); );
@ -143,7 +143,7 @@ dm_read(
__EXPORT ssize_t __EXPORT ssize_t
dm_write( dm_write(
dm_item_t item, /* The item type to store */ dm_item_t item, /* The item type to store */
unsigned char index, /* The index of the item */ unsigned index, /* The index of the item */
dm_persitence_t persistence, /* The persistence level of this item */ dm_persitence_t persistence, /* The persistence level of this item */
const void *buffer, /* Pointer to caller data buffer */ const void *buffer, /* Pointer to caller data buffer */
size_t buflen /* Length in bytes of data to retrieve */ size_t buflen /* Length in bytes of data to retrieve */

Loading…
Cancel
Save