[demo] read the last saved time for simulated timestamp

This commit is contained in:
armink
2020-07-06 22:52:03 +08:00
parent 8fb75abea0
commit f031d1574b
2 changed files with 10 additions and 4 deletions
+5 -2
View File
@@ -28,6 +28,8 @@ static struct fdb_default_kv_node default_kv_table[] = {
static struct fdb_kvdb kvdb = { 0 }; static struct fdb_kvdb kvdb = { 0 };
/* TSDB object */ /* TSDB object */
struct fdb_tsdb tsdb = { 0 }; struct fdb_tsdb tsdb = { 0 };
/* counts for simulated timestamp */
static int counts = 0;
extern void kvdb_basic_sample(fdb_kvdb_t kvdb); extern void kvdb_basic_sample(fdb_kvdb_t kvdb);
extern void kvdb_type_string_sample(fdb_kvdb_t kvdb); extern void kvdb_type_string_sample(fdb_kvdb_t kvdb);
@@ -46,11 +48,10 @@ static void unlock(fdb_db_t db)
static fdb_time_t get_time(void) static fdb_time_t get_time(void)
{ {
static int counts = 0;
/* Using the counts instead of timestamp. /* Using the counts instead of timestamp.
* Please change this function to return RTC time. * Please change this function to return RTC time.
*/ */
return counts++; return ++counts;
} }
int main(void) int main(void)
@@ -106,6 +107,8 @@ int main(void)
* NULL: The user data if you need, now is empty. * NULL: The user data if you need, now is empty.
*/ */
result = fdb_tsdb_init(&tsdb, "log", "fdb_tsdb1", get_time, 128, NULL); result = fdb_tsdb_init(&tsdb, "log", "fdb_tsdb1", get_time, 128, NULL);
/* read last saved time for simulated timestamp */
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_GET_LAST_TIME, &counts);
if (result != FDB_NO_ERR) { if (result != FDB_NO_ERR) {
return -1; return -1;
@@ -28,6 +28,8 @@ static struct fdb_default_kv_node default_kv_table[] = {
static struct fdb_kvdb kvdb = { 0 }; static struct fdb_kvdb kvdb = { 0 };
/* TSDB object */ /* TSDB object */
struct fdb_tsdb tsdb = { 0 }; struct fdb_tsdb tsdb = { 0 };
/* counts for simulated timestamp */
static int counts = 0;
extern void kvdb_basic_sample(fdb_kvdb_t kvdb); extern void kvdb_basic_sample(fdb_kvdb_t kvdb);
extern void kvdb_type_string_sample(fdb_kvdb_t kvdb); extern void kvdb_type_string_sample(fdb_kvdb_t kvdb);
@@ -46,11 +48,10 @@ static void unlock(fdb_db_t db)
static fdb_time_t get_time(void) static fdb_time_t get_time(void)
{ {
static int counts = 0;
/* Using the counts instead of timestamp. /* Using the counts instead of timestamp.
* Please change this function to return RTC time. * Please change this function to return RTC time.
*/ */
return counts++; return ++counts;
} }
int main(void) int main(void)
@@ -106,6 +107,8 @@ int main(void)
* NULL: The user data if you need, now is empty. * NULL: The user data if you need, now is empty.
*/ */
result = fdb_tsdb_init(&tsdb, "log", "fdb_tsdb1", get_time, 128, NULL); result = fdb_tsdb_init(&tsdb, "log", "fdb_tsdb1", get_time, 128, NULL);
/* read last saved time for simulated timestamp */
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_GET_LAST_TIME, &counts);
if (result != FDB_NO_ERR) { if (result != FDB_NO_ERR) {
return -1; return -1;