您尚未登录。

楼主 # 2024-07-04 17:16:40

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,379
积分: 1344.5

rtt的flashdb库,如何将数据保存到文件系统里?

板子是匠芯创的d133,片外spi nor flash。目前有两个分区用来存储数据,/rodata分区格式化为fat32文件系统,/data分区格式化为littlefs文件系统,两个分区都可读写。

luban-lite sdk里虽然有flashdb配置选项,但是没有flashdb库文件。手动下载下来放到packages/third-party/目录下,将src,inc,sample三个文件夹加到工程里,demo目录下有多个单片机的demo,照抄stm32f405-spi-flash那个,写了个test_demo.c文件放到了demo目录下并添加到工程里。

初始化时,有这个语句:

// result = fdb_kvdb_init(&kvdb, "env", "fdb_kvdb1", &default_kv, NULL);
result = fdb_kvdb_init(&kvdb, "env", "/dev/data", &default_kv, NULL);

板子没有叫fdb_kvdb1的分区,我改成"data",报错:

dlk /> fal probe qspi01
Device qspi01 NOT found. Probe failed.
No flash device or partition was probed.
Usage: fal probe [dev_name|part_name]   - probe flash device or partition by given name.
[I/FAL] ==================== FAL partition table ====================
[I/FAL] | name     | flash_dev |   offset   |    length  |
[I/FAL] -------------------------------------------------------------
[I/FAL] | spl      | norflash0 | 0x00000000 | 0x00040000 |
[I/FAL] | env      | norflash0 | 0x00040000 | 0x00020000 |
[I/FAL] | env_r    | norflash0 | 0x00060000 | 0x00020000 |
[I/FAL] | os       | norflash0 | 0x00080000 | 0x00200000 |
[I/FAL] | os_r     | norflash0 | 0x00280000 | 0x00000000 |
[I/FAL] | rodata   | norflash0 | 0x00280000 | 0x00500000 |
[I/FAL] | rodata_r | norflash0 | 0x00780000 | 0x00100000 |
[I/FAL] | data     | norflash0 | 0x00880000 | 0x00700000 |
[I/FAL] =============================================================
dlk /> test_flashdb
dlk /> [FlashDB][kv][env][data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1784) The oldest addr is @0x00000000
[FlashDB][kv][env][data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1800) KVDB size is 7340032 bytes.
[FlashDB][kv][env][data] Sector header info is incorrect. Auto format this sector (0x00000000).

改成"/data"或"/dev/data",使能FDB_USING_FILE_LIBC_MODE或FDB_USING_FILE_POSIX_MODE,  报错找不到分区:

dlk /> test_flashdb
dlk /> [FlashDB] Error: Partition (/data) not found.
[FlashDB] Error: KVDB (env

最近编辑记录 Gentlepig (2024-07-04 17:20:14)

离线

楼主 #1 2024-07-04 17:43:25

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,379
积分: 1344.5

Re: rtt的flashdb库,如何将数据保存到文件系统里?

参考linux那个demo发现,要使用文件系统,除了使能那两个宏之一,还要增加个设置语句:

bool file_mode = true;
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_FILE_MODE, &file_mode);

运行后,提示堆栈溢出,原来分配了1K,改成10k,不再报那个错误了,但是有如下报错,也不知道写入是否成功,明天再看。

dlk /> test_flashdb
dlk /> [FlashDB] (db->sec_size != 0) has assert failed at _fdb_init_ex.

最近编辑记录 Gentlepig (2024-07-04 17:44:05)

离线

楼主 #2 2024-07-05 09:27:43

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,379
积分: 1344.5

Re: rtt的flashdb库,如何将数据保存到文件系统里?

dlk /> test_flashdb
dlk /> [FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ====================
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][sample][kvdb][basic] get the 'boot_count' value is 0
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][sample][kvdb][basic] set the 'boot_count' value to 1
[FlashDB][sample][kvdb][basic] ===========================================================
[FlashDB][sample][kvdb][string] ==================== kvdb_type_string_sample ====================
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][sample][kvdb][string] create the 'temp' string KV, value is: 36C
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][sample][kvdb][string] set 'temp' value to 38C
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][sample][kvdb][string] delete the 'temp' finish
[FlashDB][sample][kvdb][string] ===========================================================
[FlashDB][sample][kvdb][blob] ==================== kvdb_type_blob_sample ====================
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][sample][kvdb][blob] create the 'temp' blob KV, value is: 36
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][sample][kvdb][blob] get the 'temp' value is: 0
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][sample][kvdb][blob] set 'temp' value to 38
[FlashDB][kv][(null)][(null)] Error: KV ((null)) isn't initialize OK.
[FlashDB][sample][kvdb][blob] delete the 'temp' finish
[FlashDB][sample][kvdb][blob] ===========================================================
[FlashDB] Error: Partition (fdb_tsdb1) not found.
[FlashDB] Error: TSDB (log

今早发现FlashDB目录下不知道什么时候多了个文件,打开看貌似是些记录啥的。忘了名了,已经删了,再次编译也没再出现。
不过执行test_flashdb,出现以上信息。

--------------------------------------------

发现昨天保存时,不知道什么时候删除了个/,导致fdb_kvdb_init()这条语句被注释了。恢复后,还是昨天下午的那个报错。

lk /> test_flashdb
dlk /> [FlashDB] (db->sec_size != 0) has assert failed at _fdb_init_ex.

----------------------------------------------
照抄linux的demo,又增加了两个语句:

bool file_mode = true;
uint32_t sec_size = 4096, db_size = sec_size * 4;

/* set the sector and database max size */
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_SEC_SIZE, &sec_size);
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_MAX_SIZE, &db_size);
/* enable file mode */      
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_FILE_MODE, &file_mode);

编译后可以运行,但是/data目录下没有看到新增文件。

dlk /> test_flashdb
dlk /> [FlashDB][kv][env][/dev/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1784) The oldest addr is @0x00000000
[FlashDB][kv][env][/dev/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1800) KVDB size is 16384 bytes.
[FlashDB][kv][env][/dev/data] Sector header info is incorrect. Auto format this sector (0x00000000).
[FlashDB][file] Error: open (/dev/data/env.fdb.0) file failed.
[FlashDB][kv][env][/dev/data] Sector header info is incorrect. Auto format this sector (0x00001000).
[FlashDB][file] Error: open (/dev/data/env.fdb.1) file failed.
[FlashDB][kv][env][/dev/data] Sector header info is incorrect. Auto format this sector (0x00002000).
[FlashDB][file] Error: open (/dev/data/env.fdb.2) file failed.
[FlashDB][kv][env][/dev/data] Sector header info is incorrect. Auto format this sector (0x00003000).
[FlashDB][file] Error: open (/dev/data/env.fdb.3) file failed.
[FlashDB][kv][env][/dev/data] All sector header is incorrect. Set it to default.
[FlashDB][file] Error: open (/dev/data/env.fdb.0) file failed.
[FlashDB] FlashDB V2.1.0 is initialize success.
[FlashDB] You can get the latest version on https://github.com/armink/FlashDB .
[FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ====================
[FlashDB][sample][kvdb][basic] get the 'boot_count' failed
[FlashDB][sample][kvdb][basic] set the 'boot_count' value to 1
[FlashDB][sample][kvdb][basic] ===========================================================
[FlashDB][sample][kvdb][string] ==================== kvdb_type_string_sample ====================
[FlashDB][sample][kvdb][string] create the 'temp' string KV, value is: 36C
[FlashDB][sample][kvdb][string] set 'temp' value to 38C
[FlashDB][kv][env][/dev/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:954) Not found 'temp' in KV.
[FlashDB][sample][kvdb][string] delete the 'temp' finish
[FlashDB][sample][kvdb][string] ===========================================================
[FlashDB][sample][kvdb][blob] ==================== kvdb_type_blob_sample ====================
[FlashDB][sample][kvdb][blob] create the 'temp' blob KV, value is: 36
[FlashDB][sample][kvdb][blob] set 'temp' value to 38
[FlashDB][kv][env][/dev/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:954) Not found 'temp' in KV.
[FlashDB][sample][kvdb][blob] delete the 'temp' finish
[FlashDB][sample][kvdb][blob] ===========================================================
[FlashDB][tsl][log][/dev/data] Sector (0x00000000) header info is incorrect.
[FlashDB][file] Error: open (/dev/data/log.fdb.0) file failed.
[FlashDB][file] Error: open (/dev/data/log.fdb.1) file failed.
[FlashDB][file] Error: open (/dev/data/log.fdb.2) file failed.
[FlashDB][file] Error: open (/dev/data/log.fdb.3) file failed.
[FlashDB][tsl][log][/dev/data] All sector format finished.
[FlashDB][tsl][log][/dev/data] (packages/third-party/FlashDB/src/fdb_tsdb.c:978) TSDB (log) oldest sectors is 0x00000000, current using sec                                                                                                                                    .
[FlashDB][sample][tsdb] ==================== tsdb_sample ====================
[FlashDB][tsl][log][/dev/data] Error: write tsl failed (3)[FlashDB][sample][tsdb] append the new status.temp (36) and status.humi (85)
[FlashDB][tsl][log][/dev/data] Error: write tsl failed (3)[FlashDB][sample][tsdb] append the new status.temp (38) and status.humi (90)
[FlashDB][sample][tsdb] query count is: 0
[FlashDB][sample][tsdb] ===========================================================

---------------------------------------------

原来用的posix模式打开文件,修改为libc模式,貌似成功了。

35  /* Using file storage mode by LIBC file API, like fopen/fread/fwrte/fclose */
  1 #define FDB_USING_FILE_LIBC_MODE
  2                                                                                                      
  3 /* Using file storage mode by POSIX file API, like open/read/write/close */                          
  4 // #define FDB_USING_FILE_POSIX_MODE
dlk /> test_flashdb
dlk /> [FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1784) The oldest addr is @0x00000000
[FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1800) KVDB size is 16384 bytes.
[FlashDB][kv][env][/data] Sector header info is incorrect. Auto format this sector (0x00000000).
[FlashDB][kv][env][/data] Sector header info is incorrect. Auto format this sector (0x00001000).
[FlashDB][kv][env][/data] Sector header info is incorrect. Auto format this sector (0x00002000).
[FlashDB][kv][env][/data] Sector header info is incorrect. Auto format this sector (0x00003000).
[FlashDB][kv][env][/data] All sector header is incorrect. Set it to default.
[FlashDB] FlashDB V2.1.0 is initialize success.
[FlashDB] You can get the latest version on https://github.com/armink/FlashDB .
[FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ====================
[FlashDB][sample][kvdb][basic] get the 'boot_count' failed
[FlashDB][sample][kvdb][basic] set the 'boot_count' value to 1
[FlashDB][sample][kvdb][basic] ===========================================================
[FlashDB][sample][kvdb][string] ==================== kvdb_type_string_sample ====================
[FlashDB][kv][env][/data] Error: The KV @0x00000024 length has an error.
[FlashDB][sample][kvdb][string] create the 'temp' string KV, value is: 36C
[FlashDB][sample][kvdb][string] set 'temp' value to 38C
[FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:954) Not found 'temp' in KV.
[FlashDB][sample][kvdb][string] delete the 'temp' finish
[FlashDB][sample][kvdb][string] ===========================================================
[FlashDB][sample][kvdb][blob] ==================== kvdb_type_blob_sample ====================
[FlashDB][sample][kvdb][blob] create the 'temp' blob KV, value is: 36
[FlashDB][sample][kvdb][blob] set 'temp' value to 38
[FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:954) Not found 'temp' in KV.
[FlashDB][sample][kvdb][blob] delete the 'temp' finish
[FlashDB][sample][kvdb][blob] ===========================================================
[FlashDB][tsl][log][/data] Sector (0x00000000) header info is incorrect.
[FlashDB][tsl][log][/data] All sector format finished.
[FlashDB][tsl][log][/data] (packages/third-party/FlashDB/src/fdb_tsdb.c:978) TSDB (log) oldest sectors is 0x00000000, current using sector                                                                                                                                     .
[FlashDB][sample][tsdb] ==================== tsdb_sample ====================
[FlashDB][tsl][log][/data] Error: write tsl failed (2)[FlashDB][sample][tsdb] append the new status.temp (36) and status.humi (85)
[FlashDB][tsl][log][/data] Error: write tsl failed (2)[FlashDB][sample][tsdb] append the new status.temp (38) and status.humi (90)
[FlashDB][sample][tsdb] query count is: 0
[FlashDB][sample][tsdb] ===========================================================

dlk /> cd /data
dlk /data> ls
Directory /data:
env.fdb.0           4096                     
env.fdb.1           4096                     
env.fdb.2           4096                     
env.fdb.3           4096                     
log.fdb.0           4096                     
log.fdb.1           4096                     
log.fdb.2           4096                     
log.fdb.3           4096  

最近编辑记录 Gentlepig (2024-07-05 10:20:40)

离线

楼主 #3 2024-07-05 14:13:52

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,379
积分: 1344.5

Re: rtt的flashdb库,如何将数据保存到文件系统里?

追踪最后的这个报错:

[FlashDB][tsl][log][/data] Error: write tsl failed (2)

是在fdb_tsdc.c

    /* write the TSL node */
   1     result = write_tsl(db, blob, cur_time);
   2     if (result != FDB_NO_ERR) {
   3         FDB_INFO("Error: write tsl failed (%d)", result);
   4         return result;
   5     }

检测write_tsl()这个函数的返回,如果不是0,则报错。

static fdb_err_t write_tsl(fdb_tsdb_t db, fdb_blob_t blob, fdb_time_t time)
   1 {
   2     fdb_err_t result = FDB_NO_ERR;
   3     struct log_idx_data idx;
   4     uint32_t idx_addr = db->cur_sec.empty_idx;
   5 
   6     idx.log_len = blob->size;
   7     idx.time = time;
   8     idx.log_addr = db->cur_sec.empty_data - FDB_WG_ALIGN(idx.log_len);
   9     /* write the status will by write granularity */
  10     _FDB_WRITE_STATUS(db, idx_addr, idx.status_table, FDB_TSL_STATUS_NUM, FDB_TSL_PRE_WRITE, false);
  11     /* write other index info */
  12     FLASH_WRITE(db, idx_addr + LOG_IDX_TS_OFFSET, &idx.time,  sizeof(struct log_idx_data) - LOG_IDX_TS_OFFSET, false);
  13     /* write blob data */
  14     FLASH_WRITE(db, idx.log_addr, blob->buf, blob->size, false);
  15     /* write the status will by write granularity */
  16     _FDB_WRITE_STATUS(db, idx_addr, idx.status_table, FDB_TSL_STATUS_NUM, FDB_TSL_WRITE, true);
  17 
  18     return result;
  19 }

可write_tsl()这个函数,里面声明了result,赋值为0,然后就是最后的return result了,其他地方没用到result。
奇怪这个result是什么时候被赋值为2的。

-------------------------------

懂了,在该函数里调用的几个宏里,有return result返回,如:

68   #define _FDB_WRITE_STATUS(db, addr, status_table, status_num, status_index, sync)    \
   1     do {                                                                       \
   2         result = _fdb_write_status((fdb_db_t)db, addr, status_table, status_num, status_index, sync);\
   3         if (result != FDB_NO_ERR) return result;                               \
   4     } while(0);
   5 
   6 #define FLASH_WRITE(db, addr, buf, size, sync)                                 \
   7     do {                                                                       \
   8         result = _fdb_flash_write((fdb_db_t)db, addr, buf, size, sync);        \
   9         if (result != FDB_NO_ERR) return result;                               \
  10     } while(0);

---------------------------------------------

修改FDB_WRITE_GRAN这个值,由32改为1,结果报错crc错误。
我用的spi nor flash,四线qspi,应该选1吧?

26  /* Using FAL storage mode */
  1 // #define FDB_USING_FAL_MODE
  2 
  3 #ifdef FDB_USING_FAL_MODE
  4 /* the flash write granularity, unit: bit
  5  * only support 1(nor flash)/ 8(stm32f2/f4)/ 32(stm32f1)/ 64(stm32f7)/ 128(stm32h5) */
  6 #define FDB_WRITE_GRAN                1        /* @note you must define it for a value */
  7 #endif
dlk /> test_flashdb
dlk /> [FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1784) The oldest addr is @0x00000000
[FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1800) KVDB size is 16384 bytes.
[FlashDB][kv][env][/data] Sector header info is incorrect. Auto format this sector (0x00000000).
[FlashDB][kv][env][/data] Sector header info is incorrect. Auto format this sector (0x00001000).
[FlashDB][kv][env][/data] Sector header info is incorrect. Auto format this sector (0x00002000).
[FlashDB][kv][env][/data] Sector header info is incorrect. Auto format this sector (0x00003000).
[FlashDB][kv][env][/data] All sector header is incorrect. Set it to default.
[FlashDB] FlashDB V2.1.0 is initialize success.
[FlashDB] You can get the latest version on https://github.com/armink/FlashDB .
[FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ====================
[FlashDB][sample][kvdb][basic] get the 'boot_count' failed
[FlashDB][sample][kvdb][basic] set the 'boot_count' value to 1
[FlashDB][sample][kvdb][basic] ===========================================================
[FlashDB][sample][kvdb][string] ==================== kvdb_type_string_sample ====================
[FlashDB][kv][env][/data] Error: Read the KV (@0x00000010) CRC32 check failed!
[FlashDB][sample][kvdb][string] create the 'temp' string KV, value is: 36C
[FlashDB][kv][env][/data] Error: Read the KV (@0x00000010) CRC32 check failed!
[FlashDB][kv][env][/data] Error: Read the KV (@0x00000010) CRC32 check failed!
[FlashDB][sample][kvdb][string] set 'temp' value to 38C
[FlashDB][kv][env][/data] Error: Read the KV (@0x00000010) CRC32 check failed!
[FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:954) Not found 'temp' in KV.
[FlashDB][sample][kvdb][string] delete the 'temp' finish
[FlashDB][sample][kvdb][string] ===========================================================
[FlashDB][sample][kvdb][blob] ==================== kvdb_type_blob_sample ====================
[FlashDB][kv][env][/data] Error: Read the KV (@0x00000010) CRC32 check failed!
[FlashDB][sample][kvdb][blob] create the 'temp' blob KV, value is: 36
[FlashDB][kv][env][/data] Error: Read the KV (@0x00000010) CRC32 check failed!
[FlashDB][kv][env][/data] Error: Read the KV (@0x00000010) CRC32 check failed!
[FlashDB][sample][kvdb][blob] set 'temp' value to 38
[FlashDB][kv][env][/data] Error: Read the KV (@0x00000010) CRC32 check failed!
[FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:954) Not found 'temp' in KV.
[FlashDB][sample][kvdb][blob] delete the 'temp' finish
[FlashDB][sample][kvdb][blob] ===========================================================
[FlashDB][tsl][log][/data] Sector (0x00000000) header info is incorrect.
[FlashDB][tsl][log][/data] All sector format finished.
[FlashDB][tsl][log][/data] (packages/third-party/FlashDB/src/fdb_tsdb.c:978) TSDB (log) oldest sectors is 0x00000000, current using sector                                                                                                                                     .
[FlashDB][sample][tsdb] ==================== tsdb_sample ====================
[FlashDB][tsl][log][/data] Error: update the sector status failed (2)[FlashDB][sample][tsdb] append the new status.temp (36) and status.hum                                                                                                                                    )
[FlashDB][tsl][log][/data] Error: write tsl failed (2)[FlashDB][sample][tsdb] append the new status.temp (38) and status.humi (90)
[FlashDB][sample][tsdb] [query_cb] queried a TSL: time: 0, temp: 40, humi: 805688500
[FlashDB][sample][tsdb] [query_by_time_cb] queried a TSL: time: 0, temp: 40, humi: 805688604
[FlashDB][sample][tsdb] query count is: 0
[FlashDB][sample][tsdb] set the TSL (time 0) status from 1 to 3
[FlashDB][sample][tsdb] ===========================================================

--------------------------------

定位到这里,fwrite写入的size是12,可函数返回值却是1.

if ((fseek(fp, addr, SEEK_SET) != 0) || (fwrite(buf, size, 1, fp) != size))

最近编辑记录 Gentlepig (2024-07-06 08:51:48)

离线

楼主 #4 2024-07-06 09:09:43

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,379
积分: 1344.5

Re: rtt的flashdb库,如何将数据保存到文件系统里?

FashDB目录下有fdb_cfg.h文件,里边有FDB_USING_FAL_MODE  FDB_WRITE_GRAN    FDB_USING_FILE_LIBC_MODE  FDB_USING_FILE_POSIX_MODE等宏定义。而我用的luban-lite sdk里,menuconfig里也有对应选项,且生成到了rtconfig.h里。结果有些宏定义重复了,而以上MODE宏定义,只能三选一,由于有了两个地方都有定义,造成了同时使能了其中多个。
目前都改成使用FDB_USING_FILE_POSIX_MODE,貌似是成功了。

dlk /> test_flashdb
dlk /> [FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1784) The oldest addr is @0x00000000
[FlashDB][kv][env][/data] (packages/third-party/FlashDB/src/fdb_kvdb.c:1800) KVDB size is 16384 bytes.
[FlashDB] FlashDB V2.1.0 is initialize success.
[FlashDB] You can get the latest version on https://github.com/armink/FlashDB .
[FlashDB][sample][kvdb][basic] ==================== kvdb_basic_sample ====================
[FlashDB][sample][kvdb][basic] get the 'boot_count' value is 1
[FlashDB][sample][kvdb][basic] set the 'boot_count' value to 2
[FlashDB][sample][kvdb][basic] ===========================================================
[FlashDB][sample][kvdb][string] ==================== kvdb_type_string_sample ====================
[FlashDB][sample][kvdb][string] create the 'temp' string KV, value is: 36C
[FlashDB][sample][kvdb][string] get the 'temp' value is: 36C
[FlashDB][sample][kvdb][string] set 'temp' value to 38C
[FlashDB][sample][kvdb][string] delete the 'temp' finish
[FlashDB][sample][kvdb][string] ===========================================================
[FlashDB][sample][kvdb][blob] ==================== kvdb_type_blob_sample ====================
[FlashDB][sample][kvdb][blob] create the 'temp' blob KV, value is: 36
[FlashDB][sample][kvdb][blob] get the 'temp' value is: 36
[FlashDB][sample][kvdb][blob] set 'temp' value to 38
[FlashDB][sample][kvdb][blob] delete the 'temp' finish
[FlashDB][sample][kvdb][blob] ===========================================================
[FlashDB][tsl][log][/data] (packages/third-party/FlashDB/src/fdb_tsdb.c:978) TSDB (log) oldest sectors is 0x00000000, current using sector                                                                                                                                     .
[FlashDB][sample][tsdb] ==================== tsdb_sample ====================
[FlashDB][sample][tsdb] append the new status.temp (36) and status.humi (85)
[FlashDB][sample][tsdb] append the new status.temp (38) and status.humi (90)
[FlashDB][sample][tsdb] [query_cb] queried a TSL: time: 1, temp: 36, humi: 85
[FlashDB][sample][tsdb] [query_cb] queried a TSL: time: 2, temp: 38, humi: 90
[FlashDB][sample][tsdb] [query_cb] queried a TSL: time: 3, temp: 36, humi: 85
[FlashDB][sample][tsdb] [query_cb] queried a TSL: time: 4, temp: 38, humi: 90
[FlashDB][sample][tsdb] [query_by_time_cb] queried a TSL: time: 1, temp: 36, humi: 85
[FlashDB][sample][tsdb] [query_by_time_cb] queried a TSL: time: 2, temp: 38, humi: 90
[FlashDB][sample][tsdb] [query_by_time_cb] queried a TSL: time: 3, temp: 36, humi: 85
[FlashDB][sample][tsdb] [query_by_time_cb] queried a TSL: time: 4, temp: 38, humi: 90
[FlashDB][sample][tsdb] query count is: 2
[FlashDB][sample][tsdb] set the TSL (time 1) status from 3 to 3
[FlashDB][sample][tsdb] set the TSL (time 2) status from 3 to 3
[FlashDB][sample][tsdb] set the TSL (time 3) status from 2 to 3
[FlashDB][sample][tsdb] set the TSL (time 4) status from 2 to 3
[FlashDB][sample][tsdb] ===========================================================
hexdump env.fdb.0
0000000 3f3f ffff 4446 3042 ffff ffff ffff ffff
0000010 ff3f ffff 564b 3030 0026 0000 c32c b664
0000020 ff08 ffff 0006 0000 7375 7265 616e 656d
0000030 7261 696d 6b6e ff3f ffff 564b 3030 0026
0000040 0000 4c95 83fc ff08 ffff 0006 0000 6170
0000050 7373 6f77 6472 3231 3433 3635 ff0f ffff
0000060 564b 3030 0026 0000 f64e efde ff0a ffff
0000070 0004 0000 6f62 746f 635f 756f 746e 0000
0000080 0000 ff3f ffff 564b 3030 0071 0000 1dce
0000090 135c ff09 ffff 0050 0000 6f62 746f 745f
00000a0 6d69 0065 0000 0000 0000 0100 0000 0000
00000b0 0000 0200 0000 0000 0000 0300 0000 0000
00000c0 0000 0000 0000 0000 0000 0000 0000 0000
*
00000f0 0000 3f00 ffff 4bff 3056 2730 0000 a700
0000100 d62e 0b29 ffff 04ff 0000 5f00 765f 7265
0000110 6e5f 6d75 5f5f 0000 0000 ff3f ffff 564b
0000120 3030 0026 0000 912b 5762 ff0a ffff 0004
0000130 0000 6f62 746f 635f 756f 746e 0001 0000
0000140 ff0f ffff 564b 3030 001f 0000 b630 fa55
0000150 ff04 ffff 0003 0000 6574 706d 3633 0f43
0000160 ffff 4bff 3056 1f30 0000 be00 d69b 0464
0000170 ffff 03ff 0000 7400 6d65 3370 4338 ff0f
0000180 ffff 564b 3030 0020 0000 89da b6c5 ff04
0000190 ffff 0004 0000 6574 706d 0024 0000 ff0f
00001a0 ffff 564b 3030 0020 0000 4151 1ccc ff04
00001b0 ffff 0004 0000 6574 706d 0026 0000 ffff
00001c0 ffff ffff ffff ffff ffff ffff ffff ffff
*
0001000

使用FDB_USING_FILE_POSIX_MODE模式时,我以为文件路径会是/dev/data呢,结果/data就行。

而使用FDB_USING_FILE_LIBC_MODE模式时,就是上边楼层最后追踪到的fwrite()函数,写入size是12,返回却是1。原因未知。

在两个地方都配置为FDB_USING_FAL_MODE模式,FDB_WRITE_GRAN配置为1或32,都是卡到这里:

dlk /> test_flashdb
dlk /> [FlashDB][kv][(null)

最近编辑记录 Gentlepig (2024-07-06 09:20:28)

离线

楼主 #5 2024-07-06 11:42:05

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,379
积分: 1344.5

Re: rtt的flashdb库,如何将数据保存到文件系统里?

tsdb方式存储的数据,每一条目里,存储的是数据偏移位值及数据长度,实际数据是从该扇区底部开始往上存储的。

hexdump log.fdb.0
0000000 ff3f ffff 5354 304c 0001 0000 ffff ffff
0000010 ffff ffff ffff ffff ffff ffff ffff ffff
0000020 ffff ffff ffff ffff ff1f ffff 0001 0000
0000030 0008 0000 0ff8 0000 ff1f ffff 0002 0000
0000040 0008 0000 0ff0 0000 ff1f ffff 0003 0000
0000050 0008 0000 0fe8 0000 ff1f ffff 0004 0000
0000060 0008 0000 0fe0 0000 ff1f ffff 0005 0000
0000070 0008 0000 0fd8 0000 ff1f ffff 0006 0000
0000080 0008 0000 0fd0 0000 ff1f ffff 0007 0000
0000090 0008 0000 0fc8 0000 ff1f ffff 0008 0000
00000a0 0008 0000 0fc0 0000 ff1f ffff 0009 0000
00000b0 0008 0000 0fb8 0000 ff1f ffff 000a 0000
00000c0 0008 0000 0fb0 0000 ff1f ffff 000b 0000
00000d0 0008 0000 0fa8 0000 ff1f ffff 000c 0000
00000e0 0008 0000 0fa0 0000 ffff ffff ffff ffff
00000f0 ffff ffff ffff ffff ffff ffff ffff ffff
*
0000fa0 0026 0000 005a 0000 0024 0000 0055 0000
*
0001000

离线

#6 2024-07-25 12:39:52

asd7893361
会员
注册时间: 2018-05-01
已发帖子: 34
积分: 32

Re: rtt的flashdb库,如何将数据保存到文件系统里?

这个板子好像开源的资料还不多,看看大佬能不能分享

离线

楼主 #7 2024-07-25 15:58:47

Gentlepig
会员
注册时间: 2018-10-24
已发帖子: 1,379
积分: 1344.5

Re: rtt的flashdb库,如何将数据保存到文件系统里?

asd7893361 说:

这个板子好像开源的资料还不多,看看大佬能不能分享

官方提供了几个开发板的原理图和pcb,sdk里,本地软件包里有差不多常用到的已经移植好了的库,而且还在更新。
flashdb没在本地仓库里,不过按例程配置下可以运行。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn