[tsdb] add get last save time control command.
This commit is contained in:
parent
165d37d531
commit
65a4b8968a
|
@ -72,6 +72,7 @@ if (!(EXPR)) \
|
||||||
#define FDB_TSDB_CTRL_SET_UNLOCK 0x3 /**< set unlock function control command */
|
#define FDB_TSDB_CTRL_SET_UNLOCK 0x3 /**< set unlock function control command */
|
||||||
#define FDB_TSDB_CTRL_SET_ROLLOVER 0x4 /**< set rollover control command */
|
#define FDB_TSDB_CTRL_SET_ROLLOVER 0x4 /**< set rollover control command */
|
||||||
#define FDB_TSDB_CTRL_GET_ROLLOVER 0x5 /**< get rollover control command */
|
#define FDB_TSDB_CTRL_GET_ROLLOVER 0x5 /**< get rollover control command */
|
||||||
|
#define FDB_TSDB_CTRL_GET_LAST_TIME 0x6 /**< get last save time control command */
|
||||||
|
|
||||||
typedef time_t fdb_time_t;
|
typedef time_t fdb_time_t;
|
||||||
#ifdef FDB_USING_TIMESTAMP_64BIT
|
#ifdef FDB_USING_TIMESTAMP_64BIT
|
||||||
|
|
|
@ -635,6 +635,7 @@ static void tsl_format_all(fdb_tsdb_t db)
|
||||||
sector_iterator(db, §or, FDB_SECTOR_STORE_UNUSED, db, NULL, format_all_cb, false);
|
sector_iterator(db, §or, FDB_SECTOR_STORE_UNUSED, db, NULL, format_all_cb, false);
|
||||||
db->oldest_addr = 0;
|
db->oldest_addr = 0;
|
||||||
db->cur_sec.addr = 0;
|
db->cur_sec.addr = 0;
|
||||||
|
db->last_time = 0;
|
||||||
/* read the current using sector info */
|
/* read the current using sector info */
|
||||||
read_sector_info(db, db->cur_sec.addr, &db->cur_sec, false);
|
read_sector_info(db, db->cur_sec.addr, &db->cur_sec, false);
|
||||||
|
|
||||||
|
@ -667,12 +668,6 @@ void fdb_tsdb_control(fdb_tsdb_t db, int cmd, void *arg)
|
||||||
FDB_ASSERT(db);
|
FDB_ASSERT(db);
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case FDB_TSDB_CTRL_SET_ROLLOVER:
|
|
||||||
db->rollover = *(bool *)arg;
|
|
||||||
break;
|
|
||||||
case FDB_TSDB_CTRL_GET_ROLLOVER:
|
|
||||||
*(bool *)arg = db->rollover;
|
|
||||||
break;
|
|
||||||
case FDB_TSDB_CTRL_SET_SEC_SIZE:
|
case FDB_TSDB_CTRL_SET_SEC_SIZE:
|
||||||
/* the sector size change MUST before database initialization */
|
/* the sector size change MUST before database initialization */
|
||||||
FDB_ASSERT(db->parent.init_ok == false);
|
FDB_ASSERT(db->parent.init_ok == false);
|
||||||
|
@ -687,6 +682,15 @@ void fdb_tsdb_control(fdb_tsdb_t db, int cmd, void *arg)
|
||||||
case FDB_TSDB_CTRL_SET_UNLOCK:
|
case FDB_TSDB_CTRL_SET_UNLOCK:
|
||||||
db->parent.unlock = (void (*)(fdb_db_t db))arg;
|
db->parent.unlock = (void (*)(fdb_db_t db))arg;
|
||||||
break;
|
break;
|
||||||
|
case FDB_TSDB_CTRL_SET_ROLLOVER:
|
||||||
|
db->rollover = *(bool *)arg;
|
||||||
|
break;
|
||||||
|
case FDB_TSDB_CTRL_GET_ROLLOVER:
|
||||||
|
*(bool *)arg = db->rollover;
|
||||||
|
break;
|
||||||
|
case FDB_TSDB_CTRL_GET_LAST_TIME:
|
||||||
|
*(fdb_time_t *)arg = db->last_time;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -753,6 +757,21 @@ fdb_err_t fdb_tsdb_init(fdb_tsdb_t db, const char *name, const char *part_name,
|
||||||
db->cur_sec.addr);
|
db->cur_sec.addr);
|
||||||
/* read the current using sector info */
|
/* read the current using sector info */
|
||||||
read_sector_info(db, db->cur_sec.addr, &db->cur_sec, true);
|
read_sector_info(db, db->cur_sec.addr, &db->cur_sec, true);
|
||||||
|
/* get last save time */
|
||||||
|
if (db->cur_sec.status == FDB_SECTOR_STORE_USING) {
|
||||||
|
db->last_time = db->cur_sec.end_time;
|
||||||
|
} else if (db->cur_sec.status == FDB_SECTOR_STORE_EMPTY && db->oldest_addr != db->cur_sec.addr) {
|
||||||
|
struct tsdb_sec_info sec;
|
||||||
|
uint32_t addr = db->cur_sec.addr;
|
||||||
|
|
||||||
|
if (addr == 0) {
|
||||||
|
addr = db_part_size(db) - db_sec_size(db);
|
||||||
|
} else {
|
||||||
|
addr -= db_sec_size(db);
|
||||||
|
}
|
||||||
|
read_sector_info(db, addr, &sec, false);
|
||||||
|
db->last_time = sec.end_time;
|
||||||
|
}
|
||||||
|
|
||||||
__exit:
|
__exit:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue