Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
flashDB
使用FlashDB迭代器,无法遍历所有KV,使用for循环加读取函数,可以读取到这个kv
发布于 2024-04-29 14:22:55 浏览:363
订阅该版
我按照官方给的例程,在使用迭代器遍历所有KV时,发现并不能获取到我已经存储的KV,但是通过读取函数,可以直接读取; 下面是遍历所有 键值对的代码及其日志 ```c void check_wireless_device(uint8_t dbid, uint8_t type, uint8_t max_size) { struct fdb_kv_iterator iterator; fdb_kv_t cur_kv; struct fdb_blob blob; size_t data_size; uint8_t *data_buf; int32_t i = 0; uint32_t y = 0; uint32_t wireless_base_data = dbid*1000; uint32_t addr = 0; int count = 0; fdb_kv_iterator_init(&iterator); while (fdb_kv_iterate(ptr_pt_global_kvdb, &iterator)) { cur_kv = &(iterator.curr_kv); data_size = (size_t) cur_kv->value_len; data_buf = (uint8_t *) malloc(data_size); if (data_buf == NULL) { break; } fdb_blob_read((fdb_db_t) ptr_pt_global_kvdb, fdb_kv_to_blob(cur_kv, fdb_blob_make(&blob, data_buf, data_size))); y = atoi(cur_kv->name); i = y-(wireless_base_data); addr = *((uint32_t *)data_buf); PT_LOGD("[index:%d]kv_name:%s ,addr: 0x%x", count++, cur_kv->name, addr); if(i > 0 && i
= 128+32 -1) { return; } } free(data_buf); } } ``` 日志 ``` [pt_check_wireless_device][887](D)> [index:0]kv_name:29000 ,addr: 0xffffff01 [pt_check_wireless_device][887](D)> [index:1]kv_name:29010 ,addr: 0xffffff0a [pt_check_wireless_device][887](D)> [index:2]kv_name:29002 ,addr: 0xffffff0a [pt_check_wireless_device][887](D)> [index:3]kv_name:29005 ,addr: 0xffffff0a [pt_check_wireless_device][887](D)> [index:4]kv_name:29006 ,addr: 0xffffff0a [pt_check_wireless_device][887](D)> [index:5]kv_name:29007 ,addr: 0xffffff0a [pt_check_wireless_device][887](D)> [index:6]kv_name:29004 ,addr: 0xffffff0a [pt_check_wireless_device][887](D)> [index:7]kv_name:29008 ,addr: 0xffffff0a [pt_check_wireless_device][887](D)> [index:8]kv_name:29003 ,addr: 0xffffff0a [pt_check_wireless_device][887](D)> [index:9]kv_name:22003 ,addr: 0xffff0001 [pt_check_wireless_device][887](D)> [index:10]kv_name:22004 ,addr: 0xffff0001 [pt_check_wireless_device][887](D)> [index:11]kv_name:22006 ,addr: 0xffff0001 [pt_check_wireless_device][887](D)> [index:12]kv_name:22007 ,addr: 0xffff0001 [pt_check_wireless_device][887](D)> [index:13]kv_name:22008 ,addr: 0xffff0001 [pt_check_wireless_device][887](D)> [index:14]kv_name:22002 ,addr: 0xffff0001 [pt_check_wireless_device][887](D)> [index:15]kv_name:23001 ,addr: 0x3 [pt_check_wireless_device][887](D)> [index:16]kv_name:25001 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:17]kv_name:44001 ,addr: 0x81 [pt_check_wireless_device][887](D)> [index:18]kv_name:29067 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:19]kv_name:29068 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:20]kv_name:29069 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:21]kv_name:29070 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:22]kv_name:29072 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:23]kv_name:29073 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:24]kv_name:22000 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:25]kv_name:29071 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:26]kv_name:29014 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:27]kv_name:29001 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:28]kv_name:29066 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:29]kv_name:23066 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:30]kv_name:23067 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:31]kv_name:23068 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:32]kv_name:23069 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:33]kv_name:23070 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:34]kv_name:23014 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:35]kv_name:23071 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:36]kv_name:23072 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:37]kv_name:23073 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:38]kv_name:29100 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:39]kv_name:23100 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:40]kv_name:29101 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:41]kv_name:23101 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:42]kv_name:23002 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:43]kv_name:23004 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:44]kv_name:23010 ,addr: 0x1 [pt_check_wireless_device][887](D)> [index:45]kv_name:29011 ,addr: 0xa [pt_check_wireless_device][887](D)> [index:46]kv_name:23011 ,addr: 0x1 ``` 下边是直接调用for循环读取的相关代码: ```C pt_db_data_t read_data = { .type = PT_DATA_UINT32}; int err = pt_fdb_read(9, 1, &read_data); PT_LOGD("err:%d addr:0x%x", err, read_data.val.val_u32); rt_thread_mdelay(2000); pt_db_data_t write_data = { .type = PT_DATA_UINT32, .val.val_u32 = 0x10, .len = sizeof(uint32_t)}; err = pt_fdb_write(70, 1, &write_data); PT_LOGD("err:%d addr:0x%x", err, write_data.val.val_u32); rt_thread_mdelay(2000); err = pt_fdb_read(70, 1, &read_data); PT_LOGD("err:%d addr:0x%x", err, read_data.val.val_u32); rt_thread_mdelay(2000); int count = 0; for (uint8_t i = 0; i < 100; i++) { for (uint8_t j = 0; j < 20; j++) { err = pt_fdb_read(i, j, &read_data); if (err == PT_DB_ERR_CODE_EOK) { count++; PT_LOGD("dbid:%d, group_id:%d, count:%d", i, j, count); } } } PT_LOGD("end"); ``` 日志: ``` [main][94](D)> err:0 addr:0x10 [main][98](D)> err:0 addr:0x10 [main][111](D)> dbid:9, group_id:0, count:1 [main][111](D)> dbid:9, group_id:1, count:2 [main][111](D)> dbid:9, group_id:2, count:3 [main][111](D)> dbid:9, group_id:8, count:4 [main][111](D)> dbid:10, group_id:1, count:5 [main][111](D)> dbid:10, group_id:2, count:6 [main][111](D)> dbid:10, group_id:3, count:7 [main][111](D)> dbid:10, group_id:4, count:8 [main][111](D)> dbid:10, group_id:5, count:9 [main][111](D)> dbid:10, group_id:8, count:10 [main][111](D)> dbid:10, group_id:9, count:11 [main][111](D)> dbid:15, group_id:0, count:12 [main][111](D)> dbid:16, group_id:0, count:13 [main][111](D)> dbid:17, group_id:0, count:14 [main][111](D)> dbid:20, group_id:0, count:15 [main][111](D)> dbid:21, group_id:0, count:16 [main][111](D)> dbid:22, group_id:0, count:17 [main][111](D)> dbid:22, group_id:1, count:18 [main][111](D)> dbid:22, group_id:2, count:19 [main][111](D)> dbid:22, group_id:3, count:20 [main][111](D)> dbid:22, group_id:4, count:21 [main][111](D)> dbid:22, group_id:5, count:22 [main][111](D)> dbid:22, group_id:6, count:23 [main][111](D)> dbid:22, group_id:7, count:24 [main][111](D)> dbid:22, group_id:8, count:25 [main][111](D)> dbid:22, group_id:11, count:26 [main][111](D)> dbid:23, group_id:1, count:27 [main][111](D)> dbid:23, group_id:2, count:28 [main][111](D)> dbid:23, group_id:3, count:29 [main][111](D)> dbid:23, group_id:4, count:30 [main][111](D)> dbid:23, group_id:5, count:31 [main][111](D)> dbid:23, group_id:6, count:32 [main][111](D)> dbid:23, group_id:7, count:33 [main][111](D)> dbid:23, group_id:8, count:34 [main][111](D)> dbid:23, group_id:10, count:35 [main][111](D)> dbid:23, group_id:11, count:36 [main][111](D)> dbid:23, group_id:14, count:37 [main][111](D)> dbid:23, group_id:19, count:38 [main][111](D)> dbid:24, group_id:1, count:39 [main][111](D)> dbid:25, group_id:1, count:40 [main][111](D)> dbid:25, group_id:3, count:41 [main][111](D)> dbid:26, group_id:0, count:42 [main][111](D)> dbid:27, group_id:0, count:43 [main][111](D)> dbid:29, group_id:0, count:44 [main][111](D)> dbid:29, group_id:1, count:45 [main][111](D)> dbid:29, group_id:2, count:46 [main][111](D)> dbid:29, group_id:3, count:47 [main][111](D)> dbid:29, group_id:4, count:48 [main][111](D)> dbid:29, group_id:5, count:49 [main][111](D)> dbid:29, group_id:6, count:50 [main][111](D)> dbid:29, group_id:7, count:51 [main][111](D)> dbid:29, group_id:8, count:52 [main][111](D)> dbid:29, group_id:10, count:53 [main][111](D)> dbid:29, group_id:11, count:54 [main][111](D)> dbid:29, group_id:12, count:55 [main][111](D)> dbid:29, group_id:13, count:56 [main][111](D)> dbid:29, group_id:14, count:57 [main][111](D)> dbid:29, group_id:15, count:58 [main][111](D)> dbid:43, group_id:0, count:59 [main][111](D)> dbid:43, group_id:1, count:60 [main][111](D)> dbid:44, group_id:1, count:61 [main][111](D)> dbid:44, group_id:2, count:62 [main][111](D)> dbid:44, group_id:5, count:63 [main][111](D)> dbid:44, group_id:6, count:64 [main][111](D)> dbid:44, group_id:7, count:65 [main][111](D)> dbid:61, group_id:0, count:66 [main][111](D)> dbid:70, group_id:1, count:67 [main][115](D)> end ```
查看更多
0
个回答
默认排序
按发布时间排序
暂无答案,快来添加答案吧
撰写答案
登录
注册新账号
关注者
0
被浏览
363
关于作者
雪落长安
这家伙很懒,什么也没写!
提问
1
回答
0
被采纳
0
关注TA
发私信
相关问题
1
flashDB有两个变量未定义?
2
FlashDB 初始化时出现 check failed
3
FlashDB初始化isn't initialize OK
4
FlashDB在哪里修改版本号实现自动更新?
5
flashDB重复更新同一个参数的问题
6
flashDB kv ts 最大存储字节在哪里设置
7
操作flashDB时thread 提示error -2 超时
8
flashdb 断言错误问题求解
9
FlashDB没法选择版本
10
flashdb出现moved kv日志后,再去查询发现数据有丢失
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
【RT-Thread】【ci】【scons】将ci.attachconfig.yml和scons结合使用
2
Rt-thread中OTA下载后,bootloader不搬程序
3
ulog 日志 LOG_HEX 输出时间改为本地日期时间
4
在RT-Thread Studio中构建前执行python命令
5
研究一了一段时间RTT,直接标准版上手太难,想用nano,但又舍不得组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
WIZnet_W5500
ota在线升级
cubemx
PWM
flash
freemodbus
BSP
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
flashDB
GD32
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
SFUD
msh
keil_MDK
ulog
C++_cpp
MicroPython
本月问答贡献
xusiwei1236
8
个答案
2
次被采纳
踩姑娘的小蘑菇
1
个答案
2
次被采纳
用户名由3_15位
9
个答案
1
次被采纳
bernard
4
个答案
1
次被采纳
RTT_逍遥
3
个答案
1
次被采纳
本月文章贡献
聚散无由
2
篇文章
15
次点赞
catcatbing
2
篇文章
5
次点赞
Wade
2
篇文章
4
次点赞
Ghost_Girls
1
篇文章
7
次点赞
xiaorui
1
篇文章
2
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部