-
Notifications
You must be signed in to change notification settings - Fork 2
Settings Tree Definition
djpnewton edited this page Apr 18, 2012
·
2 revisions
The settings tree is likely to be parsed by a micro-controller and stored in a code page so it needs to be simple to parse and is probably ok to be a few kilobytes or more in size.
The tree will be an array of node structures which together describe the topography of the tree. The node structure will have the following fields:
- uint16 type (the type of this node)
- uint16 name (the name of this node)
- uint16 count (if count is greater then 1 then this node is repeated $count times like an array)
- uint16 tag (an app specific parameter)
- branch-start (the branch node names build up the hierarchy of the settings tree)
- branch-end (the end node terminates the settings tree node array that describes the tree)
- int8
- uint8
- int16
- uint16
- int32
- uint32
- float
A node name is any 16 bit number, a table of semantic symbols should be enumerated so a descriptive settings naming hierarchy can be created for your application.
kowhai library definitions::
#include <stdint.h>
// base tree node entry
struct kowhai_node_t
{
uint16_t type;
uint16_t name;
uint16_t count;
uint16_t tag;
};
// tree node types
#define KOW_BRANCH_START 0
#define KOW_BRANCH_END 1
// leaf settings types
#define KOW_INT8 0
#define KOW_UINT8 1
#define KOW_INT16 2
#define KOW_UINT16 3
#define KOW_INT32 4
#define KOW_UINT32 5
#define KOW_FLOAT 6
app implementation::
//
// treenode symbols
//
#define SYM_SETTINGS 0
#define SYM_START 1
#define SYM_STOP 2
#define SYM_RUNNING 3
#define SYM_FLUXCAPACITOR 4
#define SYM_FREQUENCY 5
#define SYM_COEFFICIENT 6
#define SYM_GAIN 7
#define SYM_OVEN 8
#define SYM_TEMP 9
#define SYM_TIMEOUT 10
//
// settings tree descriptor
//
#define FLUX_CAP_COUNT 2
#define COEFF_COUNT 6
struct kowhai_node_t settings_descriptor[] =
{
{ KOW_BRANCH_START, SYM_SETTINGS, 1, 0 },
{ KOW_UINT8, SYM_RUNNING, 1, 0 },
{ KOW_BRANCH_START, SYM_FLUXCAPACITOR, FLUX_CAP_COUNT, 0 },
{ KOW_UINT32, SYM_FREQUENCY, 1, 0 },
{ KOW_UINT32, SYM_GAIN, 1, 0 },
{ KOW_FLOAT, SYM_COEFFICIENT, COEFF_COUNT, 0 },
{ KOW_BRANCH_END, SYM_FLUXCAPACITOR, 0, 0 },
{ KOW_BRANCH_START, SYM_OVEN, 1, 0 },
{ KOW_INT16, SYM_TEMP, 1, 0 },
{ KOW_UINT16, SYM_TIMEOUT, 1, 0 },
{ KOW_BRANCH_END, SYM_OVEN, 0, 0 },
{ KOW_BRANCH_END, SYM_SETTINGS, 1, 0 },
};
//
// settings tree structs
//
#pragma pack(1)
struct flux_capacitor_t
{
uint32_t frequency;
uint32_t gain;
float coefficient[COEFF_COUNT];
};
struct oven_t
{
int16_t temp;
uint16_t timeout;
};
struct settings_tree_t
{
uint8_t running;
struct flux_capacitor_t flux_capacitor[FLUX_CAP_COUNT];
struct oven_t oven;
};
#pragma pack()