Coder Social home page Coder Social logo

uparam's Introduction

程序参数管理

对需要保存到Flash的程序参数进行统一管理,提供读取、写入、还原默认值功能,含数据校验。 位置: /packages/misc/uparam 依赖: FAL

使用示例

原理简介 在应用里面初始化参数表,通过参数指针直接配置参数数据到flash,系统启动后自动读取数据并赋值到参数地址;会自动判断flash储存的值在内容是否存在,以及大小是否一致等等,防止溢出和错误。需要的RAM约每个参数占用5个字节。通过shell命令可以设置参数、复位参数、保存参数等等。

定义参数

#include "uparam.h"

/* 参数1*/
__attribute__((section(".PAR"))) static int pa1;
/* 参数2 */
__attribute__((section(".PAR"))) static float pa2;
/* 参数3 */
__attribute__((section(".PAR"))) static uint16_t pa3[3];

参数表

/* 参数表需要定义的数据结构 */
typedef struct
{
    /* 地址 */
    void *address;
    /* 长度 */
    uint8_t size;
    
    /* 参数名称 */
    const char *name;
    
    /* 参数解析的格式 'f'=float,'d'=int,'u'=uint, 
                     'vb'=byte vector,  'vw'=word vector, 
                     'vd'=dword vector, 'vf'=float vector
     */
    const char *type;
    /* 默认参数回调 */
    par_default default_fun;
} param_define_struct;

参数定义的结构体

param_list params[] = {
	{(void *)&pa1, sizeof(pa1), "pa1", "d",  params_default},
    {(void *)&pa2, sizeof(pa2), "pa2", "f",  params_default},
    {(void *)&pa3, sizeof(pa3), "pa3", "vd", params_default}, 
};

定义参数的默认值回调

static void params_default(void *address, uint8_t size)
{
    if ((uint32_t)address == (uint32_t)&pa1)
    {
        pa1 = 0.6f;
    }
	else if ((uint32_t)address == (uint32_t)&pa2)
    {
        pa2 = 0;
    }
    else if ((uint32_t)address == (uint32_t)&pa3[0])
    {
        pa3[0] = 450;
        pa3[1] = 600;
        pa3[2] = 0;
    }
}

初始化并导出此应用的参数

static int par_init()
{
    int cnt = sizeof(params) / sizeof(params[0]);
    if (uparam_add_list(params, cnt) != RT_EOK)
    {
        LOG_E("param init failed");
    }
    return RT_EOK;
}

//导出到参数管理
INIT_PREV_EXPORT(par_init);

###其他应用内的参数配置同理

shell指令

Usage:
par list  [*/index] [offset]     - list all param
par reset [index]                - reset 'index' param to default
par set   [index] [offset] data1 ... dataN  - set index data[offset] to param with the format
par erase [yes]                  - erase all param and reset to default
par flush                        - save all param to flash
par reload                       - read all param to ram 

par list只会显示出数组的最长5个数据,需要显示更长的使用 par list index offset

uparam's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.