APP_FLASHDB

Typedefs

typedef int32_t fdb_time_t
typedef bool (*tsdb_read_cb_t)(fdb_time_t time, void *user_data, void *data, uint16_t len)

tsdb data read callback function, which is realized by the user himself

Param time:

time in second

Param user_data:

User-defined data can be NULL

Param data:

point to read data, no need to free by user

Param len:

data length in byte

Retval bool:

true: interrupt read, false: continue read

Functions

rt_err_t app_flashdb_init(void *db, const char *part_name)

The flashdb initialize.

参数:
  • db -- For using fal_kvdb, kvdb db database object. otherwise flashdb name.

  • part_name -- Only used in fal_kvdb.FAL mode: partition name, File mode: database saved file name.

void app_flashdb_deinit(void *db)
参数:
  • db -- For using fal_kvdb, kvdb db database object. otherwise flashdb name.

  • db -- kvdb db database object.

size_t app_flashdb_reset(void *db)

The flashdb interface to reset flashdb.

参数:
  • db -- For using fal_kvdb, kvdb db database object. otherwise flashdb name.

返回值:

result -- RT_EOK: successful; RT_ERROR: faileed.

rt_err_t app_flashdb_del(void *db, const char *key_name)

The flashdb interface to delete from flash.

参数:
  • db -- For using fal_kvdb, kvdb db database object. otherwise flashdb name.

  • key_name -- For using fal_kvdb, it means key_id; otherwise, it means db file name.

返回值:

result -- RT_EOK: successful; RT_ERROR: faileed.

size_t app_flashdb_read(void *db, const char *key_name, const void *data, uint32_t len)

The flashdb interface to read from flash.

参数:
  • db -- For using fal_kvdb, kvdb db database object. otherwise flashdb name.

  • key_name -- For using fal_kvdb, it means key_id; otherwise, it means db file name.

  • data -- The data used to read flashdb.

  • len -- The data length will be readed.

返回值:

result -- Readed length.

rt_err_t app_flashdb_write(void *db, const char *key_name, const void *data, uint32_t len)

The flashdb interface to write to flash.

参数:
  • db -- For using fal_kvdb, kvdb db database object. otherwise flashdb name.

  • key_name -- For using fal_kvdb, it means key_id; otherwise, it means db file name.

  • data -- The data used to write flashdb.

  • len -- The data length will be writed.

返回值:

result -- RT_EOK: successful; RT_ERROR: faileed.

void app_flashdb_gc(void *db, const char *key_name, uint32_t collect_num)

Used for kvdb gc collection. only used in fal_kvdb.

参数:
  • db -- For using fal_kvdb, kvdb db database object. otherwise flashdb name.

  • key_name -- For using fal_kvdb, it means key_id; otherwise, it means db file name.

  • collect_num -- The number of gc collection.

void app_tsdb_init(void *db, const char *name, const char *part_name, size_t record_max_len, void *user_data)

Initial tsdb.

参数:
  • tsdb -- db database object

  • name -- The name of tsdb

  • part_name -- FAL mode: partition name, file mode: database saved file name.

  • record_max_len -- maximum length of each log

  • user_data -- user data

返回值:

result --

void app_tsdb_clean(void *db)

tsdb data all clear

参数:
  • db -- For using fal_tsdb, it means tsdb_handle; otherwise, it means tsdb name.

size_t app_tsdb_del(void *db, fdb_time_t start_time, fdb_time_t end_time, bool mode)

The tsdb interface to delete from flash.

参数:
  • db -- For using fal_tsdb, it means tsdb_handle; otherwise, it means tsdb name.

  • start_time -- from starting timestamp

  • end_time -- to end timestamp

  • mode -- true: Only the first data is deleted, false: Delete all data in sequence

返回值:

return -- delete data count

size_t app_tsdb_read(void *db, fdb_time_t start_time, fdb_time_t end_time, tsdb_read_cb_info_t *cb)

The tsdb interface to read from flash.

参数:
  • db -- For using fal_tsdb, it means tsdb_handle; otherwise, it means tsdb name.

  • start_time -- from starting timestamp. It will be a reverse iterator when ending timestamp less than starting timestamp

  • end_time -- to end timestamp

返回值:

result -- number of read messages

rt_err_t app_tsdb_write(void *db, fdb_time_t timestamp, void *data, uint32_t len)

The tsdb interface to write to flash.

参数:
  • db -- For using fal_tsdb, it means tsdb_handle; otherwise, it means tsdb name.

  • data -- The data used to write tsdb.

  • length -- The length of tsdb data.

返回值:

result -- RT_EOK: successful; RT_ERROR: faileed.

struct flashdb_blk_info_t

Public Members

size_t first_pos
fdb_time_t first_timestamp
fdb_time_t last_timestamp
struct flashdb_info_t

Public Members

char db_name[32]
uint32_t first_no
size_t first_pos
uint32_t last_no
size_t last_pos
uint16_t blk_num
uint16_t blk_size
uint32_t crc
flashdb_blk_info_t *blk_info
struct tsdb_read_cb_info_t

Public Members

tsdb_read_cb_t cb
void *user_data