mirror of
https://github.com/armink/FlashDB.git
synced 2026-10-06 12:59:32 +08:00
[demo] read the last saved time for simulated timestamp
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user