FlashDB在哪里修改版本号实现自动更新?

发布于 2020-10-09 20:52:50

如题,easyflash可以通过设置版本号实现参数自动更新,flashDB在哪里设置?

查看更多

关注者
0
被浏览
333
刘小飞
刘小飞 2021-03-19

image.png
这里更改版本号进行更改判断

static void kv_auto_update(fdb_kvdb_t db)//这个代码是自动更新的源码
{
    size_t saved_ver_num, setting_ver_num = db->ver_num;

    if (get_kv(db, VER_NUM_KV_NAME, &saved_ver_num, sizeof(size_t), NULL) > 0) {
        /* check version number */
        if (saved_ver_num != setting_ver_num) {//判断是否更新
            struct fdb_kv kv;
            size_t i, value_len;
            struct kvdb_sec_info sector;
            FDB_DEBUG("Update the KV from version %u to %u.\n", saved_ver_num, setting_ver_num);
            for (i = 0; i < db->default_kvs.num; i++) {
                /* add a new KV when it's not found */
                if (!find_kv(db, db->default_kvs.kvs[i].key, &kv)) {
                    /* It seems to be a string when value length is 0.
                     * This mechanism is for compatibility with older versions (less then V4.0). */
                    if (db->default_kvs.kvs[i].value_len == 0) {
                        value_len = strlen(db->default_kvs.kvs[i].value);
                    } else {
                        value_len = db->default_kvs.kvs[i].value_len;
                    }
                    sector.empty_kv = FAILED_ADDR;
                    create_kv_blob(db, &sector, db->default_kvs.kvs[i].key, db->default_kvs.kvs[i].value, value_len);
                }
            }
        } else {
            /* version number not changed now return */
            return;
        }
    }

    set_kv(db, VER_NUM_KV_NAME, &setting_ver_num, sizeof(size_t));
}
4 个回答
HappyTime
HappyTime 2020-10-10

FDB_KV_AUTO_UPDATE
使能 KV 自动升级功能。该功能使能后, fdb_kvdb.ver_num 存储了当前数据库的版本,如果版本发生变化时,会自动触发升级动作,将更新新的默认 KV 集合至当前数据库中。

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览