Add linux platform demo.
This commit is contained in:
parent
474fc522e5
commit
60cee13a1d
|
@ -1,6 +1,8 @@
|
||||||
| folder name | flash type |
|
| folder name | storage type |
|
||||||
| :-------------------- | :------------ |
|
| :-------------------- | :------------------ |
|
||||||
| stm32f103ve | stm32 on-chip |
|
| stm32f103ve | stm32 on-chip flash |
|
||||||
| stm32f405rg | stm32 on-chip |
|
| stm32f405rg | stm32 on-chip flash |
|
||||||
| stm32f405rg_spi_flash | spi flash |
|
| stm32f405rg_spi_flash | spi flash |
|
||||||
|
| esp8266_spi_flash | spi flash |
|
||||||
|
| linux | posix file |
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
CC = cc
|
||||||
|
|
||||||
|
ROOTPATH=../..
|
||||||
|
INCLUDE = -I./applications -I$(ROOTPATH)/inc
|
||||||
|
LIB=-lpthread
|
||||||
|
|
||||||
|
OBJ += $(patsubst %.c, %.o, $(wildcard applications/*.c))
|
||||||
|
OBJ += $(patsubst %.c, %.o, $(wildcard $(ROOTPATH)/src/*.c))
|
||||||
|
OBJ += $(patsubst %.c, %.o, $(wildcard $(ROOTPATH)/samples/*.c))
|
||||||
|
|
||||||
|
CFLAGS = -O0 -g3 -Wall
|
||||||
|
target = FlashDBLinuxDemo
|
||||||
|
|
||||||
|
all:$(OBJ)
|
||||||
|
$(CC) out/*.o -o $(target) $(LIB)
|
||||||
|
mv $(target) out
|
||||||
|
%.o:%.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDE)
|
||||||
|
mv $@ out
|
||||||
|
clean:
|
||||||
|
rm -rf out/*
|
|
@ -0,0 +1,19 @@
|
||||||
|
# linux demo
|
||||||
|
|
||||||
|
## What
|
||||||
|
|
||||||
|
KVDB and TSDB demo on linux platform
|
||||||
|
|
||||||
|
## How
|
||||||
|
|
||||||
|
### Step1: build
|
||||||
|
|
||||||
|
Run `make` command on terminal. The generated executable program is located in the `out` folder.
|
||||||
|
|
||||||
|
### Step2: run demo
|
||||||
|
|
||||||
|
Switch to the `out` folder. Then run the `./FlashDBLinuxDemo` file multiple times.
|
||||||
|
|
||||||
|
### Step3: check the log
|
||||||
|
|
||||||
|
This demo's log will output to terminal.
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020, Armink, <armink.ztl@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief configuration file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FDB_CFG_H_
|
||||||
|
#define _FDB_CFG_H_
|
||||||
|
|
||||||
|
/* using KVDB feature */
|
||||||
|
#define FDB_USING_KVDB
|
||||||
|
|
||||||
|
#ifdef FDB_USING_KVDB
|
||||||
|
/* Auto update KV to latest default when current KVDB version number is changed. @see fdb_kvdb.ver_num */
|
||||||
|
/* #define FDB_KV_AUTO_UPDATE */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* using TSDB (Time series database) feature */
|
||||||
|
#define FDB_USING_TSDB
|
||||||
|
|
||||||
|
/* Using file storage mode by POSIX file API, like open/read/write/close */
|
||||||
|
#define FDB_USING_FILE_POSIX_MODE
|
||||||
|
|
||||||
|
/* log print macro. default EF_PRINT macro is printf() */
|
||||||
|
/* #define FDB_PRINT(...) my_printf(__VA_ARGS__) */
|
||||||
|
|
||||||
|
/* print debug information */
|
||||||
|
#define FDB_DEBUG_ENABLE
|
||||||
|
|
||||||
|
#endif /* _FDB_CFG_H_ */
|
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Armink, <armink.ztl@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <board.h>
|
||||||
|
#include <flashdb.h>
|
||||||
|
#include <stm32f1xx_hal.h>
|
||||||
|
|
||||||
|
#define FDB_LOG_TAG "[main]"
|
||||||
|
|
||||||
|
static uint32_t boot_count = 0;
|
||||||
|
static time_t boot_time[10] = {0, 1, 2, 3};
|
||||||
|
/* default KV nodes */
|
||||||
|
static struct fdb_default_kv_node default_kv_table[] = {
|
||||||
|
{"username", "armink", 0}, /* string KV */
|
||||||
|
{"password", "123456", 0}, /* string KV */
|
||||||
|
{"boot_count", &boot_count, sizeof(boot_count)}, /* int type KV */
|
||||||
|
{"boot_time", &boot_time, sizeof(boot_time)}, /* int array type KV */
|
||||||
|
};
|
||||||
|
/* KVDB object */
|
||||||
|
static struct fdb_kvdb kvdb = { 0 };
|
||||||
|
/* TSDB object */
|
||||||
|
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_type_string_sample(fdb_kvdb_t kvdb);
|
||||||
|
extern void kvdb_type_blob_sample(fdb_kvdb_t kvdb);
|
||||||
|
extern void tsdb_sample(fdb_tsdb_t tsdb);
|
||||||
|
|
||||||
|
static void lock(fdb_db_t db)
|
||||||
|
{
|
||||||
|
__disable_irq();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unlock(fdb_db_t db)
|
||||||
|
{
|
||||||
|
__enable_irq();
|
||||||
|
}
|
||||||
|
|
||||||
|
static fdb_time_t get_time(void)
|
||||||
|
{
|
||||||
|
/* Using the counts instead of timestamp.
|
||||||
|
* Please change this function to return RTC time.
|
||||||
|
*/
|
||||||
|
return ++counts;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
fdb_err_t result;
|
||||||
|
|
||||||
|
#ifdef FDB_USING_KVDB
|
||||||
|
{ /* KVDB Sample */
|
||||||
|
struct fdb_default_kv default_kv;
|
||||||
|
|
||||||
|
default_kv.kvs = default_kv_table;
|
||||||
|
default_kv.num = sizeof(default_kv_table) / sizeof(default_kv_table[0]);
|
||||||
|
/* set the lock and unlock function if you want */
|
||||||
|
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_LOCK, (void *)lock);
|
||||||
|
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_UNLOCK, (void *)unlock);
|
||||||
|
/* Key-Value database initialization
|
||||||
|
*
|
||||||
|
* &kvdb: database object
|
||||||
|
* "env": database name
|
||||||
|
* "fdb_kvdb1": The flash partition name base on FAL. Please make sure it's in FAL partition table.
|
||||||
|
* Please change to YOUR partition name.
|
||||||
|
* &default_kv: The default KV nodes. It will auto add to KVDB when first initialize successfully.
|
||||||
|
* NULL: The user data if you need, now is empty.
|
||||||
|
*/
|
||||||
|
result = fdb_kvdb_init(&kvdb, "env", "fdb_kvdb1", &default_kv, NULL);
|
||||||
|
|
||||||
|
if (result != FDB_NO_ERR) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* run basic KV samples */
|
||||||
|
kvdb_basic_sample(&kvdb);
|
||||||
|
/* run string KV samples */
|
||||||
|
kvdb_type_string_sample(&kvdb);
|
||||||
|
/* run blob KV samples */
|
||||||
|
kvdb_type_blob_sample(&kvdb);
|
||||||
|
}
|
||||||
|
#endif /* FDB_USING_KVDB */
|
||||||
|
|
||||||
|
#ifdef FDB_USING_TSDB
|
||||||
|
{ /* TSDB Sample */
|
||||||
|
/* set the lock and unlock function if you want */
|
||||||
|
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_LOCK, (void *)lock);
|
||||||
|
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_UNLOCK, (void *)unlock);
|
||||||
|
/* Time series database initialization
|
||||||
|
*
|
||||||
|
* &tsdb: database object
|
||||||
|
* "log": database name
|
||||||
|
* "fdb_tsdb1": The flash partition name base on FAL. Please make sure it's in FAL partition table.
|
||||||
|
* Please change to YOUR partition name.
|
||||||
|
* get_time: The get current timestamp function.
|
||||||
|
* 128: maximum length of each log
|
||||||
|
* NULL: The user data if you need, now is empty.
|
||||||
|
*/
|
||||||
|
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) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* run TSDB sample */
|
||||||
|
tsdb_sample(&tsdb);
|
||||||
|
}
|
||||||
|
#endif /* FDB_USING_TSDB */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
*.o
|
||||||
|
*.exe
|
||||||
|
EasyLoggerLinuxDemo
|
Loading…
Reference in New Issue