YAML storage (#7071)

YAML storage
This commit is contained in:
Raphael Coeffic
2019-11-12 14:50:05 +01:00
committed by Bertrand Songis
parent bb2ca31dad
commit 8b4d2b698d
69 changed files with 5577 additions and 425 deletions
+46
View File
@@ -0,0 +1,46 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(SRC ${SRC} storage/yaml/yaml_tree_walker.cpp
storage/yaml/yaml_parser.cpp
storage/yaml/yaml_bits.cpp
storage/yaml/yaml_modelslist.cpp
storage/yaml/yaml_datastructs.cpp)
if(PCB STREQUAL X12S)
set(YAML_GEN_OUTPUT storage/yaml/yaml_datastructs_x12s.cpp)
elseif(PCB STREQUAL X10)
set(YAML_GEN_OUTPUT storage/yaml/yaml_datastructs_x10.cpp)
else()
message(FATAL_ERROR "PCB '${PCB}' is not supported by YAML storage")
endif()
set(YAML_GEN ${RADIO_DIRECTORY}/util/generate_yaml.py)
set(YAML_GEN_TEMPLATE ${RADIO_DIRECTORY}/util/yaml_parser.tmpl)
SET(YAML_NODES "\"RadioData,ModelData\"")
set(YAML_GEN_ARGS myeeprom.h ${YAML_GEN_TEMPLATE} ${YAML_NODES} -DYAML_GENERATOR)
get_property(flags DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_DEFINITIONS)
foreach(flag ${flags})
#message(STATUS "dir='${dir}'")
set(YAML_GEN_ARGS ${YAML_GEN_ARGS} -D${flag})
endforeach()
get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
foreach(dir ${dirs})
#message(STATUS "dir='${dir}'")
set(YAML_GEN_ARGS ${YAML_GEN_ARGS} -I${dir})
endforeach()
set(YAML_GEN_ARGS ${YAML_GEN_ARGS} -DRTOS_COOS -Wno-inconsistent-missing-override)
#message(STATUS "YAML_GEN_ARGS=${YAML_GEN_ARGS}")
add_custom_target(yaml_data
WORKING_DIRECTORY ${RADIO_DIRECTORY}/src
COMMAND ${PYTHON_EXECUTABLE} ${YAML_GEN} ${YAML_GEN_ARGS} > ${YAML_GEN_OUTPUT}
DEPENDS ${RADIO_DIRECTORY}/src/datastructs.h
${RADIO_DIRECTORY}/src/dataconstants.h
${RADIO_DIRECTORY}/src/myeeprom.h
${RADIO_DIRECTORY}/util/generate_yaml.py
)
+137
View File
@@ -0,0 +1,137 @@
#include <stdio.h>
#include "yaml_bits.h"
#include "yaml_parser.h"
#define MASK_LOWER(bits) ((1 << (bits)) - 1)
#define MASK_UPPER(bits) (0xFF << bits)
void yaml_put_bits(uint8_t* dst, uint32_t i, uint32_t bit_ofs, uint32_t bits)
{
i &= ((1UL << bits) - 1);
if (bit_ofs) {
*dst &= MASK_LOWER(bit_ofs);
*(dst++) |= (i << bit_ofs) & 0xFF;
if (bits <= 8 - bit_ofs)
return;
bits -= 8 - bit_ofs;
i = i >> (8 - bit_ofs);
}
while(bits >= 8) {
*(dst++) = i & 0xFF;
bits -= 8;
i = i >> 8;
}
if (bits) {
uint8_t mask = MASK_UPPER(bits);
*dst &= mask;
*dst |= i & ~mask;
}
}
uint32_t yaml_get_bits(uint8_t* src, uint32_t bit_ofs, uint32_t bits)
{
uint32_t i = 0;
uint32_t bit_shift = 0;
if (bit_ofs) {
i = (*(src++) & MASK_UPPER(bit_ofs)) >> bit_ofs;
if (bits <= 8 - bit_ofs) {
i &= MASK_LOWER(bits);
return i;
}
bit_shift = 8 - bit_ofs;
bits -= bit_shift;
}
while(bits >= 8) {
i |= (uint32_t)*(src++) << bit_shift;
bits -= 8;
bit_shift += 8;
}
if (bits) {
i |= ((uint32_t)*src & MASK_LOWER(bits)) << bit_shift;
}
return i;
}
bool yaml_is_zero(uint8_t* data, uint32_t bitoffs, uint32_t bits)
{
return !yaml_get_bits(data + (bitoffs>>3UL), bitoffs & 0x7, bits);
}
int32_t yaml_str2int(const char* val, uint8_t val_len)
{
bool neg = false;
int i_val = 0;
for(uint8_t i=0; i < val_len; i++) {
if (val[i] == '-')
neg = true;
else if (val[i] >= '0' && val[i] <= '9') {
i_val = i_val * 10 + (val[i] - '0');
}
}
return neg ? -i_val : i_val;
}
uint32_t yaml_str2uint(const char* val, uint8_t val_len)
{
uint32_t i_val = 0;
for(uint8_t i=0; i < val_len; i++) {
if (val[i] >= '0' && val[i] <= '9') {
i_val = i_val * 10 + (val[i] - '0');
}
}
return i_val;
}
static char int2str_buffer[MAX_STR] = {0};
static const char _int2str_lookup[] = { '0', '1', '2', '3', '4', '5', '6' , '7', '8', '9' };
char* yaml_unsigned2str(uint32_t i)
{
char* c = &(int2str_buffer[MAX_STR-2]);
do {
*(c--) = _int2str_lookup[i % 10];
i = i / 10;
} while((c > int2str_buffer) && i);
return (c + 1);
}
char* yaml_signed2str(int32_t i)
{
if (i < 0) {
char* c = yaml_unsigned2str(-i);
*(--c) = '-';
return c;
}
return yaml_unsigned2str((uint32_t)i);
}
int32_t yaml_to_signed(uint32_t i, uint32_t bits)
{
if (i & (1 << (bits-1))) {
i |= 0xFFFFFFFF << bits;
}
return i;
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef _yaml_bits_h_
#define _yaml_bits_h_
#include <stdint.h>
void yaml_put_bits(uint8_t* dst, uint32_t i, uint32_t bit_ofs, uint32_t bits);
uint32_t yaml_get_bits(uint8_t* src, uint32_t bit_ofs, uint32_t bits);
// assumes bits is a multiple of 8
bool yaml_is_zero(uint8_t* data, uint32_t bitoffs, uint32_t bits);
int32_t yaml_str2int(const char* val, uint8_t val_len);
uint32_t yaml_str2uint(const char* val, uint8_t val_len);
char* yaml_unsigned2str(uint32_t i);
char* yaml_signed2str(int32_t i);
int32_t yaml_to_signed(uint32_t i, uint32_t bits);
#endif
@@ -0,0 +1,13 @@
#include "opentx.h"
#include "yaml_node.h"
#include "yaml_datastructs_funcs.cpp"
#if defined(PCBX10)
#include "yaml_datastructs_x10.cpp"
#elif defined(PCBX12S)
#include "yaml_datastructs_x12s.cpp"
#else
#error "Board not supported by YAML storage"
#endif
@@ -0,0 +1,9 @@
#ifndef _YAML_DATASTRUCTS_H_
#define _YAML_DATASTRUCTS_H_
struct YamlNode;
const YamlNode* get_radiodata_nodes();
const YamlNode* get_modeldata_nodes();
#endif
@@ -0,0 +1,361 @@
#include "opentx.h"
#include "yaml_bits.h"
#include "yaml_tree_walker.h"
#define GVAR_SMALL 128
static uint32_t in_read_weight(const YamlNode* node, const char* val, uint8_t val_len)
{
if ((val_len == 4)
&& (val[0] == '-')
&& (val[1] == 'G')
&& (val[2] == 'V')
&& (val[3] >= '1')
&& (val[3] <= '9')) {
TRACE("%.*s -> %i\n", val_len, val, GVAR_SMALL - (val[3] - '0'));
return GVAR_SMALL - (val[3] - '0'); // -GVx => 128 - x
}
if ((val_len == 3)
&& (val[0] == 'G')
&& (val[1] == 'V')
&& (val[2] >= '1')
&& (val[2] <= '9')) {
TRACE("%.*s -> %i\n", val_len, val, -GVAR_SMALL + (val[2] - '1'));
return -GVAR_SMALL + (val[2] - '1'); // GVx => -128 + (x-1)
}
return (uint32_t)yaml_str2int(val, val_len);
}
static bool in_write_weight(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
int32_t sval = yaml_to_signed(val,node->size);
if (sval > GVAR_SMALL-11 && sval < GVAR_SMALL-1) {
char n = GVAR_SMALL - sval + '0';
return wf(opaque, "-GV", 3) && wf(opaque, &n, 1);
}
else if (sval < -GVAR_SMALL+11 && sval > -GVAR_SMALL+1) {
char n = val - GVAR_SMALL + '1';
return wf(opaque, "GV", 2) && wf(opaque, &n, 1);
}
char* s = yaml_signed2str(sval);
return wf(opaque, s, strlen(s));
}
extern const struct YamlIdStr enum_MixSources[];
static uint32_t r_mixSrcRaw(const YamlNode* node, const char* val, uint8_t val_len)
{
if (val_len > 0 && val[0] == 'I') {
return yaml_str2uint(val+1, val_len-1) + MIXSRC_FIRST_INPUT;
}
return yaml_parse_enum(enum_MixSources, val, val_len);
}
static bool w_mixSrcRaw(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
const char* str = nullptr;
if (val >= MIXSRC_FIRST_INPUT
&& val <= MIXSRC_LAST_INPUT) {
if (!wf(opaque, "I", 1))
return false;
str = yaml_unsigned2str(val - MIXSRC_FIRST_INPUT);
}
else {
str = yaml_output_enum(val, enum_MixSources);
}
if (str) {
return wf(opaque, str, strlen(str));
}
return true;
}
static uint32_t r_vbat_min(const YamlNode* node, const char* val, uint8_t val_len)
{
int32_t v = yaml_str2int(val, val_len);
return (uint32_t)(v - 90);
}
static bool w_vbat_min(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
char* s = yaml_signed2str(yaml_to_signed(val,node->size) + 90);
return wf(opaque, s, strlen(s));
}
static uint32_t r_vbat_max(const YamlNode* node, const char* val, uint8_t val_len)
{
int32_t v = yaml_str2int(val, val_len);
return (uint32_t)(v - 120);
}
static bool w_vbat_max(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
char* s = yaml_signed2str(yaml_to_signed(val,node->size) + 120);
return wf(opaque, s, strlen(s));
}
static uint8_t select_zov(uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= sizeof(ZoneOptionValueEnum);
ZoneOptionValueEnum* p_zovt = (ZoneOptionValueEnum*)data;
return *p_zovt;
}
static uint8_t select_mod_type(uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= offsetof(ModuleData, ppm);
switch(((ModuleData*)data)->type) {
case MODULE_TYPE_NONE:
case MODULE_TYPE_PPM:
case MODULE_TYPE_DSM2:
case MODULE_TYPE_CROSSFIRE:
return 1;
case MODULE_TYPE_MULTIMODULE:
return 2;
case MODULE_TYPE_XJT_PXX1:
case MODULE_TYPE_R9M_PXX1:
case MODULE_TYPE_R9M_LITE_PXX1:
case MODULE_TYPE_R9M_LITE_PRO_PXX1:
return 3;
case MODULE_TYPE_SBUS:
return 4;
case MODULE_TYPE_ISRM_PXX2:
case MODULE_TYPE_R9M_PXX2:
case MODULE_TYPE_R9M_LITE_PXX2:
case MODULE_TYPE_R9M_LITE_PRO_PXX2:
case MODULE_TYPE_XJT_LITE_PXX2:
return 5;
}
return 0;
}
static uint8_t select_custom_fn(uint8_t* data, uint32_t bitoffs)
{
// always use 'all'
return 1;
}
static uint8_t select_script_input(uint8_t* data, uint32_t bitoffs)
{
// always use 'value'
return 0;
}
static uint8_t select_id1(uint8_t* data, uint32_t bitoffs)
{
// always use 'id'
return 0;
}
static uint8_t select_id2(uint8_t* data, uint32_t bitoffs)
{
// always use 'instance'
return 0;
}
static uint8_t select_sensor_cfg(uint8_t* data, uint32_t bitoffs)
{
// always use 'param'
return 5;
}
static uint32_t sw_read(const char* val, uint8_t val_len)
{
return yaml_parse_enum(enum_MixSources, val, val_len) - MIXSRC_FIRST_SWITCH;
}
static bool sw_write(uint32_t idx, yaml_writer_func wf, void* opaque)
{
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SWITCH, enum_MixSources);
return wf(opaque, str, strlen(str));
}
static const struct YamlIdStr enum_SwitchConfig[] = {
{ SWITCH_NONE, "none" },
{ SWITCH_TOGGLE, "toggle" },
{ SWITCH_2POS, "2pos" },
{ SWITCH_3POS, "3pos" },
{ 0, NULL }
};
static const struct YamlNode struct_switchConfig[] = {
YAML_IDX_CUST( "sw", sw_read, sw_write ),
YAML_ENUM( "type", 2, enum_SwitchConfig),
YAML_END
};
static uint32_t pot_read(const char* val, uint8_t val_len)
{
return yaml_parse_enum(enum_MixSources, val, val_len) - MIXSRC_FIRST_POT;
}
static bool pot_write(uint32_t idx, yaml_writer_func wf, void* opaque)
{
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_POT, enum_MixSources);
return wf(opaque, str, strlen(str));
}
static const struct YamlIdStr enum_PotConfig[] = {
{ POT_NONE, "none" },
{ POT_WITH_DETENT, "with_detent" },
{ POT_MULTIPOS_SWITCH, "multipos_switch" },
{ POT_WITHOUT_DETENT, "without_detent" },
{ 0, NULL }
};
static const struct YamlNode struct_potConfig[] = {
YAML_IDX_CUST( "pot", pot_read, pot_write ),
YAML_ENUM( "type", 2, enum_PotConfig),
YAML_END
};
static uint32_t slider_read(const char* val, uint8_t val_len)
{
return yaml_parse_enum(enum_MixSources, val, val_len) - MIXSRC_FIRST_SLIDER;
}
static bool slider_write(uint32_t idx, yaml_writer_func wf, void* opaque)
{
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SLIDER, enum_MixSources);
return wf(opaque, str, strlen(str));
}
static const struct YamlIdStr enum_SliderConfig[] = {
{ SLIDER_NONE, "none" },
{ SLIDER_WITH_DETENT, "with_detent" },
{ 0, NULL }
};
static const struct YamlNode struct_sliderConfig[] = {
YAML_IDX_CUST( "sl", slider_read, slider_write ),
YAML_ENUM( "type", 1, enum_SliderConfig),
YAML_END
};
extern const struct YamlIdStr enum_SwitchSources[];
static uint32_t r_swtchSrc(const YamlNode* node, const char* val, uint8_t val_len)
{
int32_t ival=0;
bool neg = false;
if (val_len > 0 && val[0] == '!') {
neg = true;
val++;
val_len--;
}
if (val_len > 3
&& val[0] == '6'
&& val[1] == 'P'
&& (val[2] >= '0' && val[2] <= '9')
&& (val[3] >= '0' && val[3] < (XPOTS_MULTIPOS_COUNT + '0'))) {
ival = (val[2] - '0') * XPOTS_MULTIPOS_COUNT + (val[3] - '0')
+ SWSRC_FIRST_MULTIPOS_SWITCH;
}
else if (val_len >= 2
&& val[0] == 'L'
&& (val[1] >= '0' && val[1] <= '9')) {
ival = SWSRC_FIRST_LOGICAL_SWITCH + yaml_str2int(val+1, val_len-1) - 1;
}
//TODO: Flight modes ('FM[0-9]')
//TODO: Sensors ('Sensor[0-9]')
else {
ival = yaml_parse_enum(enum_SwitchSources, val, val_len);
}
return neg ? -ival : ival;
}
static bool w_swtchSrc(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
int32_t sval = yaml_to_signed(val, node->size);
if (sval < 0) {
wf(opaque, "!", 1);
sval = abs(sval);
}
const char* str = NULL;
if (sval >= SWSRC_FIRST_MULTIPOS_SWITCH
&& sval <= SWSRC_LAST_MULTIPOS_SWITCH) {
wf(opaque, "6P", 2);
// pot #: start with 6P1
sval -= SWSRC_FIRST_MULTIPOS_SWITCH;
str = yaml_unsigned2str(sval / XPOTS_MULTIPOS_COUNT);
wf(opaque,str, strlen(str));
// position
str = yaml_unsigned2str(sval % XPOTS_MULTIPOS_COUNT);
return wf(opaque,str, strlen(str));
}
else if (sval >= SWSRC_FIRST_LOGICAL_SWITCH
&& sval <= SWSRC_LAST_LOGICAL_SWITCH) {
wf(opaque, "L", 1);
str = yaml_unsigned2str(sval - SWSRC_FIRST_LOGICAL_SWITCH + 1);
return wf(opaque,str, strlen(str));
}
else if (sval >= SWSRC_FIRST_FLIGHT_MODE
&& sval <= SWSRC_LAST_FLIGHT_MODE) {
//TODO
return true;
}
else if (sval >= SWSRC_FIRST_SENSOR
&& sval <= SWSRC_LAST_SENSOR) {
//TODO
return true;
}
str = yaml_output_enum(sval, enum_SwitchSources);
return wf(opaque, str, strlen(str));
}
static bool cfn_is_active(uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
return ((CustomFunctionData*)data)->swtch;
}
static bool gvar_is_active(uint8_t* data, uint32_t bitoffs)
{
gvar_t* gvar = (gvar_t*)(data + (bitoffs>>3UL));
return *gvar != GVAR_MAX+1;
}
static bool fmd_is_active(uint8_t* data, uint32_t bitoffs)
{
uint32_t data_ofs = bitoffs >> 3UL;
if (data_ofs == offsetof(ModelData, flightModeData)) {
return !yaml_is_zero(data, bitoffs, sizeof(FlightModeData)*8);
}
bool is_active = !yaml_is_zero(data, bitoffs,
(sizeof(FlightModeData)
- sizeof(FlightModeData::gvars))*8);
FlightModeData* fmd = (FlightModeData*)(data + data_ofs);
for (uint8_t i=0; i<MAX_GVARS; i++) {
is_active |= fmd->gvars[i] != GVAR_MAX+1;
}
return is_active;
}
@@ -0,0 +1,770 @@
// generated by generate_yaml.py
//
// Enums first
//
const struct YamlIdStr enum_Functions[] = {
{ FUNC_OVERRIDE_CHANNEL, "OVERRIDE_CHANNEL" },
{ FUNC_TRAINER, "TRAINER" },
{ FUNC_INSTANT_TRIM, "INSTANT_TRIM" },
{ FUNC_RESET, "RESET" },
{ FUNC_SET_TIMER, "SET_TIMER" },
{ FUNC_ADJUST_GVAR, "ADJUST_GVAR" },
{ FUNC_VOLUME, "VOLUME" },
{ FUNC_SET_FAILSAFE, "SET_FAILSAFE" },
{ FUNC_RANGECHECK, "RANGECHECK" },
{ FUNC_BIND, "BIND" },
{ FUNC_FIRST_WITHOUT_ENABLE, "FIRST_WITHOUT_ENABLE" },
{ FUNC_PLAY_SOUND, "PLAY_SOUND" },
{ FUNC_PLAY_TRACK, "PLAY_TRACK" },
{ FUNC_PLAY_VALUE, "PLAY_VALUE" },
{ FUNC_RESERVE4, "RESERVE4" },
{ FUNC_PLAY_SCRIPT, "PLAY_SCRIPT" },
{ FUNC_RESERVE5, "RESERVE5" },
{ FUNC_BACKGND_MUSIC, "BACKGND_MUSIC" },
{ FUNC_BACKGND_MUSIC_PAUSE, "BACKGND_MUSIC_PAUSE" },
{ FUNC_VARIO, "VARIO" },
{ FUNC_HAPTIC, "HAPTIC" },
{ FUNC_LOGS, "LOGS" },
{ FUNC_BACKLIGHT, "BACKLIGHT" },
{ FUNC_SCREENSHOT, "SCREENSHOT" },
{ FUNC_MAX, "MAX" },
{ 0, NULL }
};
const struct YamlIdStr enum_ZoneOptionValueEnum[] = {
{ ZOV_Unsigned, "Unsigned" },
{ ZOV_Signed, "Signed" },
{ ZOV_Bool, "Bool" },
{ ZOV_String, "String" },
{ 0, NULL }
};
const struct YamlIdStr enum_MixSources[] = {
{ MIXSRC_NONE, "NONE" },
{ MIXSRC_Rud, "Rud" },
{ MIXSRC_Ele, "Ele" },
{ MIXSRC_Thr, "Thr" },
{ MIXSRC_Ail, "Ail" },
{ MIXSRC_S1, "S1" },
{ MIXSRC_6POS, "6POS" },
{ MIXSRC_S2, "S2" },
{ MIXSRC_EXT1, "EXT1" },
{ MIXSRC_EXT2, "EXT2" },
{ MIXSRC_LS, "LS" },
{ MIXSRC_RS, "RS" },
{ MIXSRC_MOUSE1, "MOUSE1" },
{ MIXSRC_MOUSE2, "MOUSE2" },
{ MIXSRC_MAX, "MAX" },
{ MIXSRC_CYC1, "CYC1" },
{ MIXSRC_CYC2, "CYC2" },
{ MIXSRC_CYC3, "CYC3" },
{ MIXSRC_TrimRud, "TrimRud" },
{ MIXSRC_TrimEle, "TrimEle" },
{ MIXSRC_TrimThr, "TrimThr" },
{ MIXSRC_TrimAil, "TrimAil" },
{ MIXSRC_TrimT5, "TrimT5" },
{ MIXSRC_TrimT6, "TrimT6" },
{ MIXSRC_SA, "SA" },
{ MIXSRC_SB, "SB" },
{ MIXSRC_SC, "SC" },
{ MIXSRC_SD, "SD" },
{ MIXSRC_SE, "SE" },
{ MIXSRC_SF, "SF" },
{ MIXSRC_SG, "SG" },
{ MIXSRC_SH, "SH" },
{ MIXSRC_SI, "SI" },
{ MIXSRC_SJ, "SJ" },
{ MIXSRC_SW1, "SW1" },
{ MIXSRC_CH1, "CH1" },
{ MIXSRC_CH2, "CH2" },
{ MIXSRC_CH3, "CH3" },
{ MIXSRC_CH4, "CH4" },
{ MIXSRC_CH5, "CH5" },
{ MIXSRC_CH6, "CH6" },
{ MIXSRC_CH7, "CH7" },
{ MIXSRC_CH8, "CH8" },
{ MIXSRC_CH9, "CH9" },
{ MIXSRC_CH10, "CH10" },
{ MIXSRC_CH11, "CH11" },
{ MIXSRC_CH12, "CH12" },
{ MIXSRC_CH13, "CH13" },
{ MIXSRC_CH14, "CH14" },
{ MIXSRC_CH15, "CH15" },
{ MIXSRC_CH16, "CH16" },
{ MIXSRC_GVAR1, "GVAR1" },
{ MIXSRC_TX_VOLTAGE, "TX_VOLTAGE" },
{ MIXSRC_TX_TIME, "TX_TIME" },
{ MIXSRC_TIMER1, "TIMER1" },
{ MIXSRC_TIMER2, "TIMER2" },
{ MIXSRC_TIMER3, "TIMER3" },
{ 0, NULL }
};
const struct YamlIdStr enum_LogicalSwitchesFunctions[] = {
{ LS_FUNC_NONE, "FUNC_NONE" },
{ LS_FUNC_VEQUAL, "FUNC_VEQUAL" },
{ LS_FUNC_VALMOSTEQUAL, "FUNC_VALMOSTEQUAL" },
{ LS_FUNC_VPOS, "FUNC_VPOS" },
{ LS_FUNC_VNEG, "FUNC_VNEG" },
{ LS_FUNC_RANGE, "FUNC_RANGE" },
{ LS_FUNC_APOS, "FUNC_APOS" },
{ LS_FUNC_ANEG, "FUNC_ANEG" },
{ LS_FUNC_AND, "FUNC_AND" },
{ LS_FUNC_OR, "FUNC_OR" },
{ LS_FUNC_XOR, "FUNC_XOR" },
{ LS_FUNC_EDGE, "FUNC_EDGE" },
{ LS_FUNC_EQUAL, "FUNC_EQUAL" },
{ LS_FUNC_GREATER, "FUNC_GREATER" },
{ LS_FUNC_LESS, "FUNC_LESS" },
{ LS_FUNC_DIFFEGREATER, "FUNC_DIFFEGREATER" },
{ LS_FUNC_ADIFFEGREATER, "FUNC_ADIFFEGREATER" },
{ LS_FUNC_TIMER, "FUNC_TIMER" },
{ LS_FUNC_STICKY, "FUNC_STICKY" },
{ LS_FUNC_COUNT, "FUNC_COUNT" },
{ LS_FUNC_MAX, "FUNC_MAX" },
{ 0, NULL }
};
const struct YamlIdStr enum_SwitchSources[] = {
{ SWSRC_NONE, "NONE" },
{ SWSRC_SA0, "SA0" },
{ SWSRC_SA1, "SA1" },
{ SWSRC_SA2, "SA2" },
{ SWSRC_SB0, "SB0" },
{ SWSRC_SB1, "SB1" },
{ SWSRC_SB2, "SB2" },
{ SWSRC_SC0, "SC0" },
{ SWSRC_SC1, "SC1" },
{ SWSRC_SC2, "SC2" },
{ SWSRC_SD0, "SD0" },
{ SWSRC_SD1, "SD1" },
{ SWSRC_SD2, "SD2" },
{ SWSRC_SE0, "SE0" },
{ SWSRC_SE1, "SE1" },
{ SWSRC_SE2, "SE2" },
{ SWSRC_SF0, "SF0" },
{ SWSRC_SF1, "SF1" },
{ SWSRC_SF2, "SF2" },
{ SWSRC_SG0, "SG0" },
{ SWSRC_SG1, "SG1" },
{ SWSRC_SG2, "SG2" },
{ SWSRC_SH0, "SH0" },
{ SWSRC_SH1, "SH1" },
{ SWSRC_SH2, "SH2" },
{ SWSRC_SI0, "SI0" },
{ SWSRC_SI1, "SI1" },
{ SWSRC_SI2, "SI2" },
{ SWSRC_SJ0, "SJ0" },
{ SWSRC_SJ1, "SJ1" },
{ SWSRC_SJ2, "SJ2" },
{ SWSRC_TrimRudLeft, "TrimRudLeft" },
{ SWSRC_TrimRudRight, "TrimRudRight" },
{ SWSRC_TrimEleDown, "TrimEleDown" },
{ SWSRC_TrimEleUp, "TrimEleUp" },
{ SWSRC_TrimThrDown, "TrimThrDown" },
{ SWSRC_TrimThrUp, "TrimThrUp" },
{ SWSRC_TrimAilLeft, "TrimAilLeft" },
{ SWSRC_TrimAilRight, "TrimAilRight" },
{ SWSRC_TrimT5Down, "TrimT5Down" },
{ SWSRC_TrimT5Up, "TrimT5Up" },
{ SWSRC_TrimT6Down, "TrimT6Down" },
{ SWSRC_TrimT6Up, "TrimT6Up" },
{ SWSRC_SW1, "SW1" },
{ SWSRC_SW2, "SW2" },
{ SWSRC_ON, "ON" },
{ SWSRC_ONE, "ONE" },
{ SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" },
{ SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" },
{ SWSRC_OFF, "OFF" },
{ 0, NULL }
};
const struct YamlIdStr enum_ModuleType[] = {
{ MODULE_TYPE_NONE, "TYPE_NONE" },
{ MODULE_TYPE_PPM, "TYPE_PPM" },
{ MODULE_TYPE_XJT_PXX1, "TYPE_XJT_PXX1" },
{ MODULE_TYPE_ISRM_PXX2, "TYPE_ISRM_PXX2" },
{ MODULE_TYPE_DSM2, "TYPE_DSM2" },
{ MODULE_TYPE_CROSSFIRE, "TYPE_CROSSFIRE" },
{ MODULE_TYPE_MULTIMODULE, "TYPE_MULTIMODULE" },
{ MODULE_TYPE_R9M_PXX1, "TYPE_R9M_PXX1" },
{ MODULE_TYPE_R9M_PXX2, "TYPE_R9M_PXX2" },
{ MODULE_TYPE_R9M_LITE_PXX1, "TYPE_R9M_LITE_PXX1" },
{ MODULE_TYPE_R9M_LITE_PXX2, "TYPE_R9M_LITE_PXX2" },
{ MODULE_TYPE_R9M_LITE_PRO_PXX1, "TYPE_R9M_LITE_PRO_PXX1" },
{ MODULE_TYPE_R9M_LITE_PRO_PXX2, "TYPE_R9M_LITE_PRO_PXX2" },
{ MODULE_TYPE_SBUS, "TYPE_SBUS" },
{ MODULE_TYPE_XJT_LITE_PXX2, "TYPE_XJT_LITE_PXX2" },
{ MODULE_TYPE_FLYSKY, "TYPE_FLYSKY" },
{ MODULE_TYPE_COUNT, "TYPE_COUNT" },
{ MODULE_TYPE_MAX, "TYPE_MAX" },
{ 0, NULL }
};
//
// Structs last
//
static const struct YamlNode struct_CalibData[] = {
YAML_IDX,
YAML_SIGNED( "mid", 16 ),
YAML_SIGNED( "spanNeg", 16 ),
YAML_SIGNED( "spanPos", 16 ),
YAML_END
};
static const struct YamlNode struct_signed_16[] = {
YAML_IDX,
YAML_SIGNED( "val", 16 ),
YAML_END
};
static const struct YamlNode struct_TrainerMix[] = {
YAML_IDX,
YAML_UNSIGNED( "srcChn", 6 ),
YAML_UNSIGNED( "mode", 2 ),
YAML_SIGNED( "studWeight", 8 ),
YAML_END
};
static const struct YamlNode struct_TrainerData[] = {
YAML_ARRAY("calib", 16, 4, struct_signed_16, NULL),
YAML_ARRAY("mix", 16, 4, struct_TrainerMix, NULL),
YAML_END
};
static const struct YamlNode struct_anonymous_1[] = {
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
YAML_STRUCT("play", 48, struct_anonymous_1, NULL),
YAML_STRUCT("all", 48, struct_anonymous_2, NULL),
YAML_STRUCT("clear", 48, struct_anonymous_3, NULL),
YAML_END
};
static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
YAML_IDX,
YAML_STRING("val", 3),
YAML_END
};
static const struct YamlNode union_ZoneOptionValue_elmts[] = {
YAML_UNSIGNED( "unsignedValue", 32 ),
YAML_SIGNED( "signedValue", 32 ),
YAML_UNSIGNED( "boolValue", 32 ),
YAML_STRING("stringValue", 8),
YAML_END
};
static const struct YamlNode struct_ZoneOptionValueTyped[] = {
YAML_IDX,
YAML_ENUM("type", 32, enum_ZoneOptionValueEnum),
YAML_UNION("value", 64, union_ZoneOptionValue_elmts, select_zov),
YAML_END
};
static const struct YamlNode struct_ThemeBase__PersistentData[] = {
YAML_ARRAY("options", 96, 5, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "version", 8 ),
YAML_UNSIGNED( "variant", 16 ),
YAML_ARRAY("calib", 48, 15, struct_CalibData, NULL),
YAML_UNSIGNED( "chkSum", 16 ),
YAML_UNSIGNED( "vBatWarn", 8 ),
YAML_SIGNED( "txVoltageCalibration", 8 ),
YAML_UNSIGNED( "backlightMode", 3 ),
YAML_SIGNED( "antennaMode", 2 ),
YAML_UNSIGNED( "disableRtcWarning", 1 ),
YAML_PADDING( 2 ),
YAML_STRUCT("trainer", 128, struct_TrainerData, NULL),
YAML_UNSIGNED( "view", 8 ),
YAML_PADDING( 2 ),
YAML_UNSIGNED( "fai", 1 ),
YAML_SIGNED( "beepMode", 2 ),
YAML_UNSIGNED( "alarmsFlash", 1 ),
YAML_UNSIGNED( "disableMemoryWarning", 1 ),
YAML_UNSIGNED( "disableAlarmWarning", 1 ),
YAML_UNSIGNED( "stickMode", 2 ),
YAML_SIGNED( "timezone", 5 ),
YAML_UNSIGNED( "adjustRTC", 1 ),
YAML_UNSIGNED( "inactivityTimer", 8 ),
YAML_UNSIGNED( "telemetryBaudrate", 3 ),
YAML_UNSIGNED( "splashSpares", 3 ),
YAML_SIGNED( "hapticMode", 2 ),
YAML_SIGNED( "switchesDelay", 8 ),
YAML_UNSIGNED( "lightAutoOff", 8 ),
YAML_UNSIGNED( "templateSetup", 8 ),
YAML_SIGNED( "PPM_Multiplier", 8 ),
YAML_SIGNED( "hapticLength", 8 ),
YAML_SIGNED( "beepLength", 3 ),
YAML_SIGNED( "hapticStrength", 3 ),
YAML_UNSIGNED( "gpsFormat", 1 ),
YAML_UNSIGNED( "unexpectedShutdown", 1 ),
YAML_UNSIGNED( "speakerPitch", 8 ),
YAML_SIGNED( "speakerVolume", 8 ),
YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ),
YAML_SIGNED_CUST( "vBatMax", 8, r_vbat_max, w_vbat_max ),
YAML_UNSIGNED( "backlightBright", 8 ),
YAML_UNSIGNED( "globalTimer", 32 ),
YAML_UNSIGNED( "bluetoothBaudrate", 4 ),
YAML_UNSIGNED( "bluetoothMode", 4 ),
YAML_UNSIGNED( "countryCode", 2 ),
YAML_SIGNED( "pwrOnSpeed", 3 ),
YAML_SIGNED( "pwrOffSpeed", 3 ),
YAML_UNSIGNED( "imperial", 1 ),
YAML_UNSIGNED( "jitterFilter", 1 ),
YAML_UNSIGNED( "disableRssiPoweroffAlarm", 1 ),
YAML_UNSIGNED( "USBMode", 2 ),
YAML_UNSIGNED( "jackMode", 2 ),
YAML_PADDING( 1 ),
YAML_STRING("ttsLanguage", 2),
YAML_SIGNED( "beepVolume", 4 ),
YAML_SIGNED( "wavVolume", 4 ),
YAML_SIGNED( "varioVolume", 4 ),
YAML_SIGNED( "backgroundVolume", 4 ),
YAML_SIGNED( "varioPitch", 8 ),
YAML_SIGNED( "varioRange", 8 ),
YAML_SIGNED( "varioRepeat", 8 ),
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
YAML_UNSIGNED( "auxSerialMode", 8 ),
YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr),
YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr),
YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr),
YAML_ARRAY("switchNames", 24, 10, struct_string_24, NULL),
YAML_ARRAY("anaNames", 24, 13, struct_string_24, NULL),
YAML_STRING("currModelFilename", 17),
YAML_PADDING( 1 ),
YAML_UNSIGNED( "blOffBright", 7 ),
YAML_STRING("bluetoothName", 10),
YAML_STRING("themeName", 8),
YAML_STRUCT("themeData", 480, struct_ThemeBase__PersistentData, NULL),
YAML_STRING("ownerRegistrationID", 8),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
YAML_IDX,
YAML_UNSIGNED( "val", 8 ),
YAML_END
};
static const struct YamlNode struct_ModelHeader[] = {
YAML_STRING("name", 15),
YAML_ARRAY("modelId", 8, 2, struct_unsigned_8, NULL),
YAML_STRING("bitmap", 14),
YAML_END
};
static const struct YamlNode struct_TimerData[] = {
YAML_IDX,
YAML_UNSIGNED( "start", 22 ),
YAML_SIGNED( "swtch", 10 ),
YAML_SIGNED( "value", 22 ),
YAML_UNSIGNED( "mode", 3 ),
YAML_UNSIGNED( "countdownBeep", 2 ),
YAML_UNSIGNED( "minuteBeep", 1 ),
YAML_UNSIGNED( "persistent", 2 ),
YAML_SIGNED( "countdownStart", 2 ),
YAML_STRING("name", 8),
YAML_END
};
static const struct YamlNode struct_CurveRef[] = {
YAML_UNSIGNED( "type", 8 ),
YAML_SIGNED( "value", 8 ),
YAML_END
};
static const struct YamlNode struct_MixData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_UNSIGNED( "mltpx", 2 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "offset", 14 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED( "flightModes", 9 ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_UNSIGNED( "delayUp", 8 ),
YAML_UNSIGNED( "delayDown", 8 ),
YAML_UNSIGNED( "speedUp", 8 ),
YAML_UNSIGNED( "speedDown", 8 ),
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_LimitData[] = {
YAML_IDX,
YAML_SIGNED( "min", 11 ),
YAML_SIGNED( "max", 11 ),
YAML_SIGNED( "ppmCenter", 10 ),
YAML_SIGNED( "offset", 11 ),
YAML_UNSIGNED( "symetrical", 1 ),
YAML_UNSIGNED( "revert", 1 ),
YAML_PADDING( 3 ),
YAML_SIGNED( "curve", 8 ),
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_ExpoData[] = {
YAML_IDX,
YAML_UNSIGNED( "mode", 2 ),
YAML_UNSIGNED( "scale", 14 ),
YAML_ENUM("srcRaw", 10, enum_MixSources),
YAML_SIGNED( "carryTrim", 6 ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED( "flightModes", 9 ),
YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ),
YAML_PADDING( 1 ),
YAML_STRING("name", 6),
YAML_SIGNED( "offset", 8 ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_END
};
static const struct YamlNode struct_CurveHeader[] = {
YAML_IDX,
YAML_UNSIGNED( "type", 1 ),
YAML_UNSIGNED( "smooth", 1 ),
YAML_SIGNED( "points", 6 ),
YAML_STRING("name", 3),
YAML_END
};
static const struct YamlNode struct_signed_8[] = {
YAML_IDX,
YAML_SIGNED( "val", 8 ),
YAML_END
};
static const struct YamlNode struct_LogicalSwitchData[] = {
YAML_IDX,
YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions),
YAML_SIGNED( "v1", 10 ),
YAML_SIGNED( "v3", 10 ),
YAML_SIGNED( "andsw", 9 ),
YAML_UNSIGNED( "andswtype", 1 ),
YAML_PADDING( 2 ),
YAML_SIGNED( "v2", 16 ),
YAML_UNSIGNED( "delay", 8 ),
YAML_UNSIGNED( "duration", 8 ),
YAML_END
};
static const struct YamlNode struct_SwashRingData[] = {
YAML_UNSIGNED( "type", 8 ),
YAML_UNSIGNED( "value", 8 ),
YAML_UNSIGNED( "collectiveSource", 8 ),
YAML_UNSIGNED( "aileronSource", 8 ),
YAML_UNSIGNED( "elevatorSource", 8 ),
YAML_SIGNED( "collectiveWeight", 8 ),
YAML_SIGNED( "aileronWeight", 8 ),
YAML_SIGNED( "elevatorWeight", 8 ),
YAML_END
};
static const struct YamlNode struct_trim_t[] = {
YAML_IDX,
YAML_SIGNED( "value", 11 ),
YAML_UNSIGNED( "mode", 5 ),
YAML_END
};
static const struct YamlNode struct_FlightModeData[] = {
YAML_IDX,
YAML_ARRAY("trim", 16, 6, struct_trim_t, NULL),
YAML_STRING("name", 10),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 7 ),
YAML_UNSIGNED( "fadeIn", 8 ),
YAML_UNSIGNED( "fadeOut", 8 ),
YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active),
YAML_END
};
static const struct YamlNode struct_GVarData[] = {
YAML_IDX,
YAML_STRING("name", 3),
YAML_UNSIGNED( "min", 12 ),
YAML_UNSIGNED( "max", 12 ),
YAML_UNSIGNED( "popup", 1 ),
YAML_UNSIGNED( "prec", 1 ),
YAML_UNSIGNED( "unit", 2 ),
YAML_PADDING( 4 ),
YAML_END
};
static const struct YamlNode struct_VarioData[] = {
YAML_UNSIGNED( "source", 7 ),
YAML_UNSIGNED( "centerSilent", 1 ),
YAML_SIGNED( "centerMax", 8 ),
YAML_SIGNED( "centerMin", 8 ),
YAML_SIGNED( "min", 8 ),
YAML_SIGNED( "max", 8 ),
YAML_END
};
static const struct YamlNode struct_RssiAlarmData[] = {
YAML_SIGNED( "disabled", 1 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "warning", 6 ),
YAML_PADDING( 2 ),
YAML_SIGNED( "critical", 6 ),
YAML_END
};
static const struct YamlNode struct_anonymous_5[] = {
YAML_SIGNED( "delay", 6 ),
YAML_UNSIGNED( "pulsePol", 1 ),
YAML_UNSIGNED( "outputType", 1 ),
YAML_SIGNED( "frameLength", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_6[] = {
YAML_UNSIGNED( "rfProtocolExtra", 2 ),
YAML_PADDING( 3 ),
YAML_UNSIGNED( "customProto", 1 ),
YAML_UNSIGNED( "autoBindMode", 1 ),
YAML_UNSIGNED( "lowPowerMode", 1 ),
YAML_SIGNED( "optionValue", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_7[] = {
YAML_UNSIGNED( "power", 2 ),
YAML_PADDING( 2 ),
YAML_UNSIGNED( "receiverTelemetryOff", 1 ),
YAML_UNSIGNED( "receiverHigherChannels", 1 ),
YAML_SIGNED( "antennaMode", 2 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_8[] = {
YAML_PADDING( 6 ),
YAML_UNSIGNED( "noninverted", 1 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "refreshRate", 8 ),
YAML_END
};
static const struct YamlNode struct_string_64[] = {
YAML_IDX,
YAML_STRING("val", 8),
YAML_END
};
static const struct YamlNode struct_anonymous_9[] = {
YAML_UNSIGNED( "receivers", 8 ),
YAML_ARRAY("receiverName", 64, 3, struct_string_64, NULL),
YAML_END
};
static const struct YamlNode union_anonymous_4_elmts[] = {
YAML_ARRAY("raw", 8, 25, struct_unsigned_8, NULL),
YAML_STRUCT("ppm", 16, struct_anonymous_5, NULL),
YAML_STRUCT("multi", 16, struct_anonymous_6, NULL),
YAML_STRUCT("pxx", 16, struct_anonymous_7, NULL),
YAML_STRUCT("sbus", 16, struct_anonymous_8, NULL),
YAML_STRUCT("pxx2", 200, struct_anonymous_9, NULL),
YAML_END
};
static const struct YamlNode struct_ModuleData[] = {
YAML_IDX,
YAML_ENUM("type", 4, enum_ModuleType),
YAML_SIGNED( "rfProtocol", 4 ),
YAML_UNSIGNED( "channelsStart", 8 ),
YAML_SIGNED( "channelsCount", 8 ),
YAML_UNSIGNED( "failsafeMode", 4 ),
YAML_UNSIGNED( "subType", 3 ),
YAML_UNSIGNED( "invertedSerial", 1 ),
YAML_UNION("mod", 200, union_anonymous_4_elmts, select_mod_type),
YAML_END
};
static const struct YamlNode struct_TrainerModuleData[] = {
YAML_UNSIGNED( "mode", 3 ),
YAML_PADDING( 5 ),
YAML_UNSIGNED( "channelsStart", 8 ),
YAML_SIGNED( "channelsCount", 8 ),
YAML_SIGNED( "frameLength", 8 ),
YAML_SIGNED( "delay", 6 ),
YAML_UNSIGNED( "pulsePol", 1 ),
YAML_PADDING( 1 ),
YAML_END
};
static const struct YamlNode union_ScriptDataInput_elmts[] = {
YAML_SIGNED( "value", 16 ),
YAML_UNSIGNED( "source", 16 ),
YAML_END
};
static const struct YamlNode union_ScriptDataInput[] = {
YAML_IDX,
YAML_UNION("u", 16, union_ScriptDataInput_elmts, select_script_input),
YAML_END
};
static const struct YamlNode struct_ScriptData[] = {
YAML_IDX,
YAML_STRING("file", 6),
YAML_STRING("name", 6),
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_10_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_12[] = {
YAML_UNSIGNED( "physID", 5 ),
YAML_UNSIGNED( "rxIndex", 3 ),
YAML_END
};
static const struct YamlNode union_anonymous_11_elmts[] = {
YAML_STRUCT("frskyInstance", 8, struct_anonymous_12, NULL),
YAML_UNSIGNED( "instance", 8 ),
YAML_UNSIGNED( "formula", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_14[] = {
YAML_UNSIGNED( "ratio", 16 ),
YAML_SIGNED( "offset", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_15[] = {
YAML_UNSIGNED( "source", 8 ),
YAML_UNSIGNED( "index", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_16[] = {
YAML_ARRAY("sources", 8, 4, struct_signed_8, NULL),
YAML_END
};
static const struct YamlNode struct_anonymous_17[] = {
YAML_UNSIGNED( "source", 8 ),
YAML_PADDING( 24 ),
YAML_END
};
static const struct YamlNode struct_anonymous_18[] = {
YAML_UNSIGNED( "gps", 8 ),
YAML_UNSIGNED( "alt", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_13_elmts[] = {
YAML_STRUCT("custom", 32, struct_anonymous_14, NULL),
YAML_STRUCT("cell", 32, struct_anonymous_15, NULL),
YAML_STRUCT("calc", 32, struct_anonymous_16, NULL),
YAML_STRUCT("consumption", 32, struct_anonymous_17, NULL),
YAML_STRUCT("dist", 32, struct_anonymous_18, NULL),
YAML_UNSIGNED( "param", 32 ),
YAML_END
};
static const struct YamlNode struct_TelemetrySensor[] = {
YAML_IDX,
YAML_UNION("id1", 16, union_anonymous_10_elmts, select_id1),
YAML_UNION("id2", 8, union_anonymous_11_elmts, select_id2),
YAML_STRING("label", 4),
YAML_UNSIGNED( "subId", 8 ),
YAML_UNSIGNED( "type", 1 ),
YAML_PADDING( 1 ),
YAML_UNSIGNED( "unit", 6 ),
YAML_UNSIGNED( "prec", 2 ),
YAML_UNSIGNED( "autoOffset", 1 ),
YAML_UNSIGNED( "filter", 1 ),
YAML_UNSIGNED( "logs", 1 ),
YAML_UNSIGNED( "persistent", 1 ),
YAML_UNSIGNED( "onlyPositive", 1 ),
YAML_PADDING( 1 ),
YAML_UNION("cfg", 32, union_anonymous_13_elmts, select_sensor_cfg),
YAML_END
};
static const struct YamlNode struct_Widget__PersistentData[] = {
YAML_ARRAY("options", 96, 5, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_ZonePersistentData[] = {
YAML_IDX,
YAML_STRING("widgetName", 10),
YAML_STRUCT("widgetData", 480, struct_Widget__PersistentData, NULL),
YAML_END
};
static const struct YamlNode struct_Layout__PersistentData[] = {
YAML_ARRAY("zones", 576, 10, struct_ZonePersistentData, NULL),
YAML_ARRAY("options", 96, 10, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_CustomScreenData[] = {
YAML_IDX,
YAML_STRING("layoutName", 10),
YAML_STRUCT("layoutData", 6720, struct_Layout__PersistentData, NULL),
YAML_END
};
static const struct YamlNode struct_Topbar__PersistentData[] = {
YAML_ARRAY("zones", 576, 4, struct_ZonePersistentData, NULL),
YAML_ARRAY("options", 96, 1, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("header", 248, struct_ModelHeader, NULL),
YAML_ARRAY("timers", 128, 3, struct_TimerData, NULL),
YAML_UNSIGNED( "telemetryProtocol", 3 ),
YAML_UNSIGNED( "thrTrim", 1 ),
YAML_UNSIGNED( "noGlobalFunctions", 1 ),
YAML_UNSIGNED( "displayTrims", 2 ),
YAML_UNSIGNED( "ignoreSensorIds", 1 ),
YAML_SIGNED( "trimInc", 3 ),
YAML_UNSIGNED( "disableThrottleWarning", 1 ),
YAML_UNSIGNED( "displayChecklist", 1 ),
YAML_UNSIGNED( "extendedLimits", 1 ),
YAML_UNSIGNED( "extendedTrims", 1 ),
YAML_UNSIGNED( "throttleReversed", 1 ),
YAML_UNSIGNED( "beepANACenter", 16 ),
YAML_ARRAY("mixData", 160, 64, struct_MixData, NULL),
YAML_ARRAY("limitData", 104, 32, struct_LimitData, NULL),
YAML_ARRAY("expoData", 136, 64, struct_ExpoData, NULL),
YAML_ARRAY("curves", 32, 32, struct_CurveHeader, NULL),
YAML_ARRAY("points", 8, 512, struct_signed_8, NULL),
YAML_ARRAY("logicalSw", 72, 64, struct_LogicalSwitchData, NULL),
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
YAML_STRUCT("swashR", 64, struct_SwashRingData, NULL),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED( "thrTraceSrc", 8 ),
YAML_UNSIGNED( "switchWarningState", 32 ),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED( "rssiSource", 8 ),
YAML_STRUCT("rssiAlarms", 16, struct_RssiAlarmData, NULL),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "potsWarnMode", 2 ),
YAML_ARRAY("moduleData", 232, 2, struct_ModuleData, NULL),
YAML_ARRAY("failsafeChannels", 16, 32, struct_signed_16, NULL),
YAML_STRUCT("trainerData", 40, struct_TrainerModuleData, NULL),
YAML_ARRAY("scriptsData", 192, 9, struct_ScriptData, NULL),
YAML_ARRAY("inputNames", 32, 32, struct_string_32, NULL),
YAML_UNSIGNED( "potsWarnEnabled", 8 ),
YAML_ARRAY("potsWarnPosition", 8, 9, struct_signed_8, NULL),
YAML_ARRAY("telemetrySensors", 112, 60, struct_TelemetrySensor, NULL),
YAML_ARRAY("screenData", 6800, 5, struct_CustomScreenData, NULL),
YAML_STRUCT("topbarData", 2400, struct_Topbar__PersistentData, NULL),
YAML_UNSIGNED( "view", 8 ),
YAML_STRING("modelRegistrationID", 8),
YAML_END
};
#define MAX_RADIODATA_MODELDATA_STR_LEN 24
static const struct YamlNode __RadioData_root_node = YAML_ROOT( struct_RadioData );
const YamlNode* get_radiodata_nodes()
{
return &__RadioData_root_node;
}
static const struct YamlNode __ModelData_root_node = YAML_ROOT( struct_ModelData );
const YamlNode* get_modeldata_nodes()
{
return &__ModelData_root_node;
}
@@ -0,0 +1,771 @@
// generated by generate_yaml.py
//
// Enums first
//
const struct YamlIdStr enum_Functions[] = {
{ FUNC_OVERRIDE_CHANNEL, "OVERRIDE_CHANNEL" },
{ FUNC_TRAINER, "TRAINER" },
{ FUNC_INSTANT_TRIM, "INSTANT_TRIM" },
{ FUNC_RESET, "RESET" },
{ FUNC_SET_TIMER, "SET_TIMER" },
{ FUNC_ADJUST_GVAR, "ADJUST_GVAR" },
{ FUNC_VOLUME, "VOLUME" },
{ FUNC_SET_FAILSAFE, "SET_FAILSAFE" },
{ FUNC_RANGECHECK, "RANGECHECK" },
{ FUNC_BIND, "BIND" },
{ FUNC_FIRST_WITHOUT_ENABLE, "FIRST_WITHOUT_ENABLE" },
{ FUNC_PLAY_SOUND, "PLAY_SOUND" },
{ FUNC_PLAY_TRACK, "PLAY_TRACK" },
{ FUNC_PLAY_VALUE, "PLAY_VALUE" },
{ FUNC_RESERVE4, "RESERVE4" },
{ FUNC_PLAY_SCRIPT, "PLAY_SCRIPT" },
{ FUNC_RESERVE5, "RESERVE5" },
{ FUNC_BACKGND_MUSIC, "BACKGND_MUSIC" },
{ FUNC_BACKGND_MUSIC_PAUSE, "BACKGND_MUSIC_PAUSE" },
{ FUNC_VARIO, "VARIO" },
{ FUNC_HAPTIC, "HAPTIC" },
{ FUNC_LOGS, "LOGS" },
{ FUNC_BACKLIGHT, "BACKLIGHT" },
{ FUNC_SCREENSHOT, "SCREENSHOT" },
{ FUNC_MAX, "MAX" },
{ 0, NULL }
};
const struct YamlIdStr enum_ZoneOptionValueEnum[] = {
{ ZOV_Unsigned, "Unsigned" },
{ ZOV_Signed, "Signed" },
{ ZOV_Bool, "Bool" },
{ ZOV_String, "String" },
{ 0, NULL }
};
const struct YamlIdStr enum_MixSources[] = {
{ MIXSRC_NONE, "NONE" },
{ MIXSRC_Rud, "Rud" },
{ MIXSRC_Ele, "Ele" },
{ MIXSRC_Thr, "Thr" },
{ MIXSRC_Ail, "Ail" },
{ MIXSRC_S1, "S1" },
{ MIXSRC_6POS, "6POS" },
{ MIXSRC_S2, "S2" },
{ MIXSRC_S3, "S3" },
{ MIXSRC_S4, "S4" },
{ MIXSRC_LS, "LS" },
{ MIXSRC_RS, "RS" },
{ MIXSRC_MOUSE1, "MOUSE1" },
{ MIXSRC_MOUSE2, "MOUSE2" },
{ MIXSRC_MAX, "MAX" },
{ MIXSRC_CYC1, "CYC1" },
{ MIXSRC_CYC2, "CYC2" },
{ MIXSRC_CYC3, "CYC3" },
{ MIXSRC_TrimRud, "TrimRud" },
{ MIXSRC_TrimEle, "TrimEle" },
{ MIXSRC_TrimThr, "TrimThr" },
{ MIXSRC_TrimAil, "TrimAil" },
{ MIXSRC_TrimT5, "TrimT5" },
{ MIXSRC_TrimT6, "TrimT6" },
{ MIXSRC_SA, "SA" },
{ MIXSRC_SB, "SB" },
{ MIXSRC_SC, "SC" },
{ MIXSRC_SD, "SD" },
{ MIXSRC_SE, "SE" },
{ MIXSRC_SF, "SF" },
{ MIXSRC_SG, "SG" },
{ MIXSRC_SH, "SH" },
{ MIXSRC_SI, "SI" },
{ MIXSRC_SJ, "SJ" },
{ MIXSRC_SW1, "SW1" },
{ MIXSRC_CH1, "CH1" },
{ MIXSRC_CH2, "CH2" },
{ MIXSRC_CH3, "CH3" },
{ MIXSRC_CH4, "CH4" },
{ MIXSRC_CH5, "CH5" },
{ MIXSRC_CH6, "CH6" },
{ MIXSRC_CH7, "CH7" },
{ MIXSRC_CH8, "CH8" },
{ MIXSRC_CH9, "CH9" },
{ MIXSRC_CH10, "CH10" },
{ MIXSRC_CH11, "CH11" },
{ MIXSRC_CH12, "CH12" },
{ MIXSRC_CH13, "CH13" },
{ MIXSRC_CH14, "CH14" },
{ MIXSRC_CH15, "CH15" },
{ MIXSRC_CH16, "CH16" },
{ MIXSRC_GVAR1, "GVAR1" },
{ MIXSRC_TX_VOLTAGE, "TX_VOLTAGE" },
{ MIXSRC_TX_TIME, "TX_TIME" },
{ MIXSRC_TX_GPS, "TX_GPS" },
{ MIXSRC_TIMER1, "TIMER1" },
{ MIXSRC_TIMER2, "TIMER2" },
{ MIXSRC_TIMER3, "TIMER3" },
{ 0, NULL }
};
const struct YamlIdStr enum_LogicalSwitchesFunctions[] = {
{ LS_FUNC_NONE, "FUNC_NONE" },
{ LS_FUNC_VEQUAL, "FUNC_VEQUAL" },
{ LS_FUNC_VALMOSTEQUAL, "FUNC_VALMOSTEQUAL" },
{ LS_FUNC_VPOS, "FUNC_VPOS" },
{ LS_FUNC_VNEG, "FUNC_VNEG" },
{ LS_FUNC_RANGE, "FUNC_RANGE" },
{ LS_FUNC_APOS, "FUNC_APOS" },
{ LS_FUNC_ANEG, "FUNC_ANEG" },
{ LS_FUNC_AND, "FUNC_AND" },
{ LS_FUNC_OR, "FUNC_OR" },
{ LS_FUNC_XOR, "FUNC_XOR" },
{ LS_FUNC_EDGE, "FUNC_EDGE" },
{ LS_FUNC_EQUAL, "FUNC_EQUAL" },
{ LS_FUNC_GREATER, "FUNC_GREATER" },
{ LS_FUNC_LESS, "FUNC_LESS" },
{ LS_FUNC_DIFFEGREATER, "FUNC_DIFFEGREATER" },
{ LS_FUNC_ADIFFEGREATER, "FUNC_ADIFFEGREATER" },
{ LS_FUNC_TIMER, "FUNC_TIMER" },
{ LS_FUNC_STICKY, "FUNC_STICKY" },
{ LS_FUNC_COUNT, "FUNC_COUNT" },
{ LS_FUNC_MAX, "FUNC_MAX" },
{ 0, NULL }
};
const struct YamlIdStr enum_SwitchSources[] = {
{ SWSRC_NONE, "NONE" },
{ SWSRC_SA0, "SA0" },
{ SWSRC_SA1, "SA1" },
{ SWSRC_SA2, "SA2" },
{ SWSRC_SB0, "SB0" },
{ SWSRC_SB1, "SB1" },
{ SWSRC_SB2, "SB2" },
{ SWSRC_SC0, "SC0" },
{ SWSRC_SC1, "SC1" },
{ SWSRC_SC2, "SC2" },
{ SWSRC_SD0, "SD0" },
{ SWSRC_SD1, "SD1" },
{ SWSRC_SD2, "SD2" },
{ SWSRC_SE0, "SE0" },
{ SWSRC_SE1, "SE1" },
{ SWSRC_SE2, "SE2" },
{ SWSRC_SF0, "SF0" },
{ SWSRC_SF1, "SF1" },
{ SWSRC_SF2, "SF2" },
{ SWSRC_SG0, "SG0" },
{ SWSRC_SG1, "SG1" },
{ SWSRC_SG2, "SG2" },
{ SWSRC_SH0, "SH0" },
{ SWSRC_SH1, "SH1" },
{ SWSRC_SH2, "SH2" },
{ SWSRC_SI0, "SI0" },
{ SWSRC_SI1, "SI1" },
{ SWSRC_SI2, "SI2" },
{ SWSRC_SJ0, "SJ0" },
{ SWSRC_SJ1, "SJ1" },
{ SWSRC_SJ2, "SJ2" },
{ SWSRC_TrimRudLeft, "TrimRudLeft" },
{ SWSRC_TrimRudRight, "TrimRudRight" },
{ SWSRC_TrimEleDown, "TrimEleDown" },
{ SWSRC_TrimEleUp, "TrimEleUp" },
{ SWSRC_TrimThrDown, "TrimThrDown" },
{ SWSRC_TrimThrUp, "TrimThrUp" },
{ SWSRC_TrimAilLeft, "TrimAilLeft" },
{ SWSRC_TrimAilRight, "TrimAilRight" },
{ SWSRC_TrimT5Down, "TrimT5Down" },
{ SWSRC_TrimT5Up, "TrimT5Up" },
{ SWSRC_TrimT6Down, "TrimT6Down" },
{ SWSRC_TrimT6Up, "TrimT6Up" },
{ SWSRC_SW1, "SW1" },
{ SWSRC_SW2, "SW2" },
{ SWSRC_ON, "ON" },
{ SWSRC_ONE, "ONE" },
{ SWSRC_TELEMETRY_STREAMING, "TELEMETRY_STREAMING" },
{ SWSRC_RADIO_ACTIVITY, "RADIO_ACTIVITY" },
{ SWSRC_OFF, "OFF" },
{ 0, NULL }
};
const struct YamlIdStr enum_ModuleType[] = {
{ MODULE_TYPE_NONE, "TYPE_NONE" },
{ MODULE_TYPE_PPM, "TYPE_PPM" },
{ MODULE_TYPE_XJT_PXX1, "TYPE_XJT_PXX1" },
{ MODULE_TYPE_ISRM_PXX2, "TYPE_ISRM_PXX2" },
{ MODULE_TYPE_DSM2, "TYPE_DSM2" },
{ MODULE_TYPE_CROSSFIRE, "TYPE_CROSSFIRE" },
{ MODULE_TYPE_MULTIMODULE, "TYPE_MULTIMODULE" },
{ MODULE_TYPE_R9M_PXX1, "TYPE_R9M_PXX1" },
{ MODULE_TYPE_R9M_PXX2, "TYPE_R9M_PXX2" },
{ MODULE_TYPE_R9M_LITE_PXX1, "TYPE_R9M_LITE_PXX1" },
{ MODULE_TYPE_R9M_LITE_PXX2, "TYPE_R9M_LITE_PXX2" },
{ MODULE_TYPE_R9M_LITE_PRO_PXX1, "TYPE_R9M_LITE_PRO_PXX1" },
{ MODULE_TYPE_R9M_LITE_PRO_PXX2, "TYPE_R9M_LITE_PRO_PXX2" },
{ MODULE_TYPE_SBUS, "TYPE_SBUS" },
{ MODULE_TYPE_XJT_LITE_PXX2, "TYPE_XJT_LITE_PXX2" },
{ MODULE_TYPE_FLYSKY, "TYPE_FLYSKY" },
{ MODULE_TYPE_COUNT, "TYPE_COUNT" },
{ MODULE_TYPE_MAX, "TYPE_MAX" },
{ 0, NULL }
};
//
// Structs last
//
static const struct YamlNode struct_CalibData[] = {
YAML_IDX,
YAML_SIGNED( "mid", 16 ),
YAML_SIGNED( "spanNeg", 16 ),
YAML_SIGNED( "spanPos", 16 ),
YAML_END
};
static const struct YamlNode struct_signed_16[] = {
YAML_IDX,
YAML_SIGNED( "val", 16 ),
YAML_END
};
static const struct YamlNode struct_TrainerMix[] = {
YAML_IDX,
YAML_UNSIGNED( "srcChn", 6 ),
YAML_UNSIGNED( "mode", 2 ),
YAML_SIGNED( "studWeight", 8 ),
YAML_END
};
static const struct YamlNode struct_TrainerData[] = {
YAML_ARRAY("calib", 16, 4, struct_signed_16, NULL),
YAML_ARRAY("mix", 16, 4, struct_TrainerMix, NULL),
YAML_END
};
static const struct YamlNode struct_anonymous_1[] = {
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_anonymous_2[] = {
YAML_SIGNED( "val", 16 ),
YAML_UNSIGNED( "mode", 8 ),
YAML_UNSIGNED( "param", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_3[] = {
YAML_SIGNED( "val1", 32 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_0_elmts[] = {
YAML_STRUCT("play", 48, struct_anonymous_1, NULL),
YAML_STRUCT("all", 48, struct_anonymous_2, NULL),
YAML_STRUCT("clear", 48, struct_anonymous_3, NULL),
YAML_END
};
static const struct YamlNode struct_CustomFunctionData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_ENUM("func", 7, enum_Functions),
YAML_UNION("fp", 48, union_anonymous_0_elmts, select_custom_fn),
YAML_UNSIGNED( "active", 8 ),
YAML_END
};
static const struct YamlNode struct_string_24[] = {
YAML_IDX,
YAML_STRING("val", 3),
YAML_END
};
static const struct YamlNode union_ZoneOptionValue_elmts[] = {
YAML_UNSIGNED( "unsignedValue", 32 ),
YAML_SIGNED( "signedValue", 32 ),
YAML_UNSIGNED( "boolValue", 32 ),
YAML_STRING("stringValue", 8),
YAML_END
};
static const struct YamlNode struct_ZoneOptionValueTyped[] = {
YAML_IDX,
YAML_ENUM("type", 32, enum_ZoneOptionValueEnum),
YAML_UNION("value", 64, union_ZoneOptionValue_elmts, select_zov),
YAML_END
};
static const struct YamlNode struct_ThemeBase__PersistentData[] = {
YAML_ARRAY("options", 96, 5, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "version", 8 ),
YAML_UNSIGNED( "variant", 16 ),
YAML_ARRAY("calib", 48, 15, struct_CalibData, NULL),
YAML_UNSIGNED( "chkSum", 16 ),
YAML_UNSIGNED( "vBatWarn", 8 ),
YAML_SIGNED( "txVoltageCalibration", 8 ),
YAML_UNSIGNED( "backlightMode", 3 ),
YAML_SIGNED( "antennaMode", 2 ),
YAML_UNSIGNED( "disableRtcWarning", 1 ),
YAML_PADDING( 2 ),
YAML_STRUCT("trainer", 128, struct_TrainerData, NULL),
YAML_UNSIGNED( "view", 8 ),
YAML_PADDING( 2 ),
YAML_UNSIGNED( "fai", 1 ),
YAML_SIGNED( "beepMode", 2 ),
YAML_UNSIGNED( "alarmsFlash", 1 ),
YAML_UNSIGNED( "disableMemoryWarning", 1 ),
YAML_UNSIGNED( "disableAlarmWarning", 1 ),
YAML_UNSIGNED( "stickMode", 2 ),
YAML_SIGNED( "timezone", 5 ),
YAML_UNSIGNED( "adjustRTC", 1 ),
YAML_UNSIGNED( "inactivityTimer", 8 ),
YAML_UNSIGNED( "telemetryBaudrate", 3 ),
YAML_UNSIGNED( "splashSpares", 3 ),
YAML_SIGNED( "hapticMode", 2 ),
YAML_SIGNED( "switchesDelay", 8 ),
YAML_UNSIGNED( "lightAutoOff", 8 ),
YAML_UNSIGNED( "templateSetup", 8 ),
YAML_SIGNED( "PPM_Multiplier", 8 ),
YAML_SIGNED( "hapticLength", 8 ),
YAML_SIGNED( "beepLength", 3 ),
YAML_SIGNED( "hapticStrength", 3 ),
YAML_UNSIGNED( "gpsFormat", 1 ),
YAML_UNSIGNED( "unexpectedShutdown", 1 ),
YAML_UNSIGNED( "speakerPitch", 8 ),
YAML_SIGNED( "speakerVolume", 8 ),
YAML_SIGNED_CUST( "vBatMin", 8, r_vbat_min, w_vbat_min ),
YAML_SIGNED_CUST( "vBatMax", 8, r_vbat_max, w_vbat_max ),
YAML_UNSIGNED( "backlightBright", 8 ),
YAML_UNSIGNED( "globalTimer", 32 ),
YAML_UNSIGNED( "bluetoothBaudrate", 4 ),
YAML_UNSIGNED( "bluetoothMode", 4 ),
YAML_UNSIGNED( "countryCode", 2 ),
YAML_SIGNED( "pwrOnSpeed", 3 ),
YAML_SIGNED( "pwrOffSpeed", 3 ),
YAML_UNSIGNED( "imperial", 1 ),
YAML_UNSIGNED( "jitterFilter", 1 ),
YAML_UNSIGNED( "disableRssiPoweroffAlarm", 1 ),
YAML_UNSIGNED( "USBMode", 2 ),
YAML_UNSIGNED( "jackMode", 2 ),
YAML_PADDING( 1 ),
YAML_STRING("ttsLanguage", 2),
YAML_SIGNED( "beepVolume", 4 ),
YAML_SIGNED( "wavVolume", 4 ),
YAML_SIGNED( "varioVolume", 4 ),
YAML_SIGNED( "backgroundVolume", 4 ),
YAML_SIGNED( "varioPitch", 8 ),
YAML_SIGNED( "varioRange", 8 ),
YAML_SIGNED( "varioRepeat", 8 ),
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
YAML_UNSIGNED( "auxSerialMode", 8 ),
YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr),
YAML_ARRAY("potsConfig", 2, 8, struct_potConfig, nullptr),
YAML_ARRAY("slidersConfig", 1, 8, struct_sliderConfig, nullptr),
YAML_ARRAY("switchNames", 24, 10, struct_string_24, NULL),
YAML_ARRAY("anaNames", 24, 13, struct_string_24, NULL),
YAML_STRING("currModelFilename", 17),
YAML_PADDING( 1 ),
YAML_UNSIGNED( "blOffBright", 7 ),
YAML_STRING("bluetoothName", 10),
YAML_STRING("themeName", 8),
YAML_STRUCT("themeData", 480, struct_ThemeBase__PersistentData, NULL),
YAML_STRING("ownerRegistrationID", 8),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
YAML_IDX,
YAML_UNSIGNED( "val", 8 ),
YAML_END
};
static const struct YamlNode struct_ModelHeader[] = {
YAML_STRING("name", 15),
YAML_ARRAY("modelId", 8, 2, struct_unsigned_8, NULL),
YAML_STRING("bitmap", 14),
YAML_END
};
static const struct YamlNode struct_TimerData[] = {
YAML_IDX,
YAML_UNSIGNED( "start", 22 ),
YAML_SIGNED( "swtch", 10 ),
YAML_SIGNED( "value", 22 ),
YAML_UNSIGNED( "mode", 3 ),
YAML_UNSIGNED( "countdownBeep", 2 ),
YAML_UNSIGNED( "minuteBeep", 1 ),
YAML_UNSIGNED( "persistent", 2 ),
YAML_SIGNED( "countdownStart", 2 ),
YAML_STRING("name", 8),
YAML_END
};
static const struct YamlNode struct_CurveRef[] = {
YAML_UNSIGNED( "type", 8 ),
YAML_SIGNED( "value", 8 ),
YAML_END
};
static const struct YamlNode struct_MixData[] = {
YAML_IDX,
YAML_SIGNED_CUST( "weight", 11, in_read_weight, in_write_weight ),
YAML_UNSIGNED( "destCh", 5 ),
YAML_UNSIGNED_CUST( "srcRaw", 10, r_mixSrcRaw, w_mixSrcRaw ),
YAML_UNSIGNED( "carryTrim", 1 ),
YAML_UNSIGNED( "mixWarn", 2 ),
YAML_UNSIGNED( "mltpx", 2 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "offset", 14 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED( "flightModes", 9 ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_UNSIGNED( "delayUp", 8 ),
YAML_UNSIGNED( "delayDown", 8 ),
YAML_UNSIGNED( "speedUp", 8 ),
YAML_UNSIGNED( "speedDown", 8 ),
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_LimitData[] = {
YAML_IDX,
YAML_SIGNED( "min", 11 ),
YAML_SIGNED( "max", 11 ),
YAML_SIGNED( "ppmCenter", 10 ),
YAML_SIGNED( "offset", 11 ),
YAML_UNSIGNED( "symetrical", 1 ),
YAML_UNSIGNED( "revert", 1 ),
YAML_PADDING( 3 ),
YAML_SIGNED( "curve", 8 ),
YAML_STRING("name", 6),
YAML_END
};
static const struct YamlNode struct_ExpoData[] = {
YAML_IDX,
YAML_UNSIGNED( "mode", 2 ),
YAML_UNSIGNED( "scale", 14 ),
YAML_ENUM("srcRaw", 10, enum_MixSources),
YAML_SIGNED( "carryTrim", 6 ),
YAML_UNSIGNED( "chn", 5 ),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_UNSIGNED( "flightModes", 9 ),
YAML_SIGNED_CUST( "weight", 8, in_read_weight, in_write_weight ),
YAML_PADDING( 1 ),
YAML_STRING("name", 6),
YAML_SIGNED( "offset", 8 ),
YAML_STRUCT("curve", 16, struct_CurveRef, NULL),
YAML_END
};
static const struct YamlNode struct_CurveHeader[] = {
YAML_IDX,
YAML_UNSIGNED( "type", 1 ),
YAML_UNSIGNED( "smooth", 1 ),
YAML_SIGNED( "points", 6 ),
YAML_STRING("name", 3),
YAML_END
};
static const struct YamlNode struct_signed_8[] = {
YAML_IDX,
YAML_SIGNED( "val", 8 ),
YAML_END
};
static const struct YamlNode struct_LogicalSwitchData[] = {
YAML_IDX,
YAML_ENUM("func", 8, enum_LogicalSwitchesFunctions),
YAML_SIGNED( "v1", 10 ),
YAML_SIGNED( "v3", 10 ),
YAML_SIGNED( "andsw", 9 ),
YAML_UNSIGNED( "andswtype", 1 ),
YAML_PADDING( 2 ),
YAML_SIGNED( "v2", 16 ),
YAML_UNSIGNED( "delay", 8 ),
YAML_UNSIGNED( "duration", 8 ),
YAML_END
};
static const struct YamlNode struct_SwashRingData[] = {
YAML_UNSIGNED( "type", 8 ),
YAML_UNSIGNED( "value", 8 ),
YAML_UNSIGNED( "collectiveSource", 8 ),
YAML_UNSIGNED( "aileronSource", 8 ),
YAML_UNSIGNED( "elevatorSource", 8 ),
YAML_SIGNED( "collectiveWeight", 8 ),
YAML_SIGNED( "aileronWeight", 8 ),
YAML_SIGNED( "elevatorWeight", 8 ),
YAML_END
};
static const struct YamlNode struct_trim_t[] = {
YAML_IDX,
YAML_SIGNED( "value", 11 ),
YAML_UNSIGNED( "mode", 5 ),
YAML_END
};
static const struct YamlNode struct_FlightModeData[] = {
YAML_IDX,
YAML_ARRAY("trim", 16, 6, struct_trim_t, NULL),
YAML_STRING("name", 10),
YAML_SIGNED_CUST( "swtch", 9, r_swtchSrc, w_swtchSrc ),
YAML_PADDING( 7 ),
YAML_UNSIGNED( "fadeIn", 8 ),
YAML_UNSIGNED( "fadeOut", 8 ),
YAML_ARRAY("gvars", 16, 9, struct_signed_16, gvar_is_active),
YAML_END
};
static const struct YamlNode struct_GVarData[] = {
YAML_IDX,
YAML_STRING("name", 3),
YAML_UNSIGNED( "min", 12 ),
YAML_UNSIGNED( "max", 12 ),
YAML_UNSIGNED( "popup", 1 ),
YAML_UNSIGNED( "prec", 1 ),
YAML_UNSIGNED( "unit", 2 ),
YAML_PADDING( 4 ),
YAML_END
};
static const struct YamlNode struct_VarioData[] = {
YAML_UNSIGNED( "source", 7 ),
YAML_UNSIGNED( "centerSilent", 1 ),
YAML_SIGNED( "centerMax", 8 ),
YAML_SIGNED( "centerMin", 8 ),
YAML_SIGNED( "min", 8 ),
YAML_SIGNED( "max", 8 ),
YAML_END
};
static const struct YamlNode struct_RssiAlarmData[] = {
YAML_SIGNED( "disabled", 1 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "warning", 6 ),
YAML_PADDING( 2 ),
YAML_SIGNED( "critical", 6 ),
YAML_END
};
static const struct YamlNode struct_anonymous_5[] = {
YAML_SIGNED( "delay", 6 ),
YAML_UNSIGNED( "pulsePol", 1 ),
YAML_UNSIGNED( "outputType", 1 ),
YAML_SIGNED( "frameLength", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_6[] = {
YAML_UNSIGNED( "rfProtocolExtra", 2 ),
YAML_PADDING( 3 ),
YAML_UNSIGNED( "customProto", 1 ),
YAML_UNSIGNED( "autoBindMode", 1 ),
YAML_UNSIGNED( "lowPowerMode", 1 ),
YAML_SIGNED( "optionValue", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_7[] = {
YAML_UNSIGNED( "power", 2 ),
YAML_PADDING( 2 ),
YAML_UNSIGNED( "receiverTelemetryOff", 1 ),
YAML_UNSIGNED( "receiverHigherChannels", 1 ),
YAML_SIGNED( "antennaMode", 2 ),
YAML_PADDING( 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_8[] = {
YAML_PADDING( 6 ),
YAML_UNSIGNED( "noninverted", 1 ),
YAML_PADDING( 1 ),
YAML_SIGNED( "refreshRate", 8 ),
YAML_END
};
static const struct YamlNode struct_string_64[] = {
YAML_IDX,
YAML_STRING("val", 8),
YAML_END
};
static const struct YamlNode struct_anonymous_9[] = {
YAML_UNSIGNED( "receivers", 8 ),
YAML_ARRAY("receiverName", 64, 3, struct_string_64, NULL),
YAML_END
};
static const struct YamlNode union_anonymous_4_elmts[] = {
YAML_ARRAY("raw", 8, 25, struct_unsigned_8, NULL),
YAML_STRUCT("ppm", 16, struct_anonymous_5, NULL),
YAML_STRUCT("multi", 16, struct_anonymous_6, NULL),
YAML_STRUCT("pxx", 16, struct_anonymous_7, NULL),
YAML_STRUCT("sbus", 16, struct_anonymous_8, NULL),
YAML_STRUCT("pxx2", 200, struct_anonymous_9, NULL),
YAML_END
};
static const struct YamlNode struct_ModuleData[] = {
YAML_IDX,
YAML_ENUM("type", 4, enum_ModuleType),
YAML_SIGNED( "rfProtocol", 4 ),
YAML_UNSIGNED( "channelsStart", 8 ),
YAML_SIGNED( "channelsCount", 8 ),
YAML_UNSIGNED( "failsafeMode", 4 ),
YAML_UNSIGNED( "subType", 3 ),
YAML_UNSIGNED( "invertedSerial", 1 ),
YAML_UNION("mod", 200, union_anonymous_4_elmts, select_mod_type),
YAML_END
};
static const struct YamlNode struct_TrainerModuleData[] = {
YAML_UNSIGNED( "mode", 3 ),
YAML_PADDING( 5 ),
YAML_UNSIGNED( "channelsStart", 8 ),
YAML_SIGNED( "channelsCount", 8 ),
YAML_SIGNED( "frameLength", 8 ),
YAML_SIGNED( "delay", 6 ),
YAML_UNSIGNED( "pulsePol", 1 ),
YAML_PADDING( 1 ),
YAML_END
};
static const struct YamlNode union_ScriptDataInput_elmts[] = {
YAML_SIGNED( "value", 16 ),
YAML_UNSIGNED( "source", 16 ),
YAML_END
};
static const struct YamlNode union_ScriptDataInput[] = {
YAML_IDX,
YAML_UNION("u", 16, union_ScriptDataInput_elmts, select_script_input),
YAML_END
};
static const struct YamlNode struct_ScriptData[] = {
YAML_IDX,
YAML_STRING("file", 6),
YAML_STRING("name", 6),
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_10_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_12[] = {
YAML_UNSIGNED( "physID", 5 ),
YAML_UNSIGNED( "rxIndex", 3 ),
YAML_END
};
static const struct YamlNode union_anonymous_11_elmts[] = {
YAML_STRUCT("frskyInstance", 8, struct_anonymous_12, NULL),
YAML_UNSIGNED( "instance", 8 ),
YAML_UNSIGNED( "formula", 8 ),
YAML_END
};
static const struct YamlNode struct_anonymous_14[] = {
YAML_UNSIGNED( "ratio", 16 ),
YAML_SIGNED( "offset", 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_15[] = {
YAML_UNSIGNED( "source", 8 ),
YAML_UNSIGNED( "index", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode struct_anonymous_16[] = {
YAML_ARRAY("sources", 8, 4, struct_signed_8, NULL),
YAML_END
};
static const struct YamlNode struct_anonymous_17[] = {
YAML_UNSIGNED( "source", 8 ),
YAML_PADDING( 24 ),
YAML_END
};
static const struct YamlNode struct_anonymous_18[] = {
YAML_UNSIGNED( "gps", 8 ),
YAML_UNSIGNED( "alt", 8 ),
YAML_PADDING( 16 ),
YAML_END
};
static const struct YamlNode union_anonymous_13_elmts[] = {
YAML_STRUCT("custom", 32, struct_anonymous_14, NULL),
YAML_STRUCT("cell", 32, struct_anonymous_15, NULL),
YAML_STRUCT("calc", 32, struct_anonymous_16, NULL),
YAML_STRUCT("consumption", 32, struct_anonymous_17, NULL),
YAML_STRUCT("dist", 32, struct_anonymous_18, NULL),
YAML_UNSIGNED( "param", 32 ),
YAML_END
};
static const struct YamlNode struct_TelemetrySensor[] = {
YAML_IDX,
YAML_UNION("id1", 16, union_anonymous_10_elmts, select_id1),
YAML_UNION("id2", 8, union_anonymous_11_elmts, select_id2),
YAML_STRING("label", 4),
YAML_UNSIGNED( "subId", 8 ),
YAML_UNSIGNED( "type", 1 ),
YAML_PADDING( 1 ),
YAML_UNSIGNED( "unit", 6 ),
YAML_UNSIGNED( "prec", 2 ),
YAML_UNSIGNED( "autoOffset", 1 ),
YAML_UNSIGNED( "filter", 1 ),
YAML_UNSIGNED( "logs", 1 ),
YAML_UNSIGNED( "persistent", 1 ),
YAML_UNSIGNED( "onlyPositive", 1 ),
YAML_PADDING( 1 ),
YAML_UNION("cfg", 32, union_anonymous_13_elmts, select_sensor_cfg),
YAML_END
};
static const struct YamlNode struct_Widget__PersistentData[] = {
YAML_ARRAY("options", 96, 5, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_ZonePersistentData[] = {
YAML_IDX,
YAML_STRING("widgetName", 10),
YAML_STRUCT("widgetData", 480, struct_Widget__PersistentData, NULL),
YAML_END
};
static const struct YamlNode struct_Layout__PersistentData[] = {
YAML_ARRAY("zones", 576, 10, struct_ZonePersistentData, NULL),
YAML_ARRAY("options", 96, 10, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_CustomScreenData[] = {
YAML_IDX,
YAML_STRING("layoutName", 10),
YAML_STRUCT("layoutData", 6720, struct_Layout__PersistentData, NULL),
YAML_END
};
static const struct YamlNode struct_Topbar__PersistentData[] = {
YAML_ARRAY("zones", 576, 4, struct_ZonePersistentData, NULL),
YAML_ARRAY("options", 96, 1, struct_ZoneOptionValueTyped, NULL),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
YAML_STRUCT("header", 248, struct_ModelHeader, NULL),
YAML_ARRAY("timers", 128, 3, struct_TimerData, NULL),
YAML_UNSIGNED( "telemetryProtocol", 3 ),
YAML_UNSIGNED( "thrTrim", 1 ),
YAML_UNSIGNED( "noGlobalFunctions", 1 ),
YAML_UNSIGNED( "displayTrims", 2 ),
YAML_UNSIGNED( "ignoreSensorIds", 1 ),
YAML_SIGNED( "trimInc", 3 ),
YAML_UNSIGNED( "disableThrottleWarning", 1 ),
YAML_UNSIGNED( "displayChecklist", 1 ),
YAML_UNSIGNED( "extendedLimits", 1 ),
YAML_UNSIGNED( "extendedTrims", 1 ),
YAML_UNSIGNED( "throttleReversed", 1 ),
YAML_UNSIGNED( "beepANACenter", 16 ),
YAML_ARRAY("mixData", 160, 64, struct_MixData, NULL),
YAML_ARRAY("limitData", 104, 32, struct_LimitData, NULL),
YAML_ARRAY("expoData", 136, 64, struct_ExpoData, NULL),
YAML_ARRAY("curves", 32, 32, struct_CurveHeader, NULL),
YAML_ARRAY("points", 8, 512, struct_signed_8, NULL),
YAML_ARRAY("logicalSw", 72, 64, struct_LogicalSwitchData, NULL),
YAML_ARRAY("customFn", 72, 64, struct_CustomFunctionData, cfn_is_active),
YAML_STRUCT("swashR", 64, struct_SwashRingData, NULL),
YAML_ARRAY("flightModeData", 352, 9, struct_FlightModeData, fmd_is_active),
YAML_UNSIGNED( "thrTraceSrc", 8 ),
YAML_UNSIGNED( "switchWarningState", 32 ),
YAML_ARRAY("gvars", 56, 9, struct_GVarData, NULL),
YAML_STRUCT("varioData", 40, struct_VarioData, NULL),
YAML_UNSIGNED( "rssiSource", 8 ),
YAML_STRUCT("rssiAlarms", 16, struct_RssiAlarmData, NULL),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "potsWarnMode", 2 ),
YAML_ARRAY("moduleData", 232, 2, struct_ModuleData, NULL),
YAML_ARRAY("failsafeChannels", 16, 32, struct_signed_16, NULL),
YAML_STRUCT("trainerData", 40, struct_TrainerModuleData, NULL),
YAML_ARRAY("scriptsData", 192, 9, struct_ScriptData, NULL),
YAML_ARRAY("inputNames", 32, 32, struct_string_32, NULL),
YAML_UNSIGNED( "potsWarnEnabled", 8 ),
YAML_ARRAY("potsWarnPosition", 8, 9, struct_signed_8, NULL),
YAML_ARRAY("telemetrySensors", 112, 60, struct_TelemetrySensor, NULL),
YAML_ARRAY("screenData", 6800, 5, struct_CustomScreenData, NULL),
YAML_STRUCT("topbarData", 2400, struct_Topbar__PersistentData, NULL),
YAML_UNSIGNED( "view", 8 ),
YAML_STRING("modelRegistrationID", 8),
YAML_END
};
#define MAX_RADIODATA_MODELDATA_STR_LEN 24
static const struct YamlNode __RadioData_root_node = YAML_ROOT( struct_RadioData );
const YamlNode* get_radiodata_nodes()
{
return &__RadioData_root_node;
}
static const struct YamlNode __ModelData_root_node = YAML_ROOT( struct_ModelData );
const YamlNode* get_modeldata_nodes()
{
return &__ModelData_root_node;
}
+37
View File
@@ -0,0 +1,37 @@
#ifndef _YAML_DEFS_H_
#define _YAML_DEFS_H_
#if defined(YAML_GENERATOR)
/* private definitions */
#define _yaml_note(label) #label
#define _yaml_attribute(attr) __attribute__((annotate(attr)))
/* public definitions */
#define ENUM(label) _yaml_attribute("enum:" _yaml_note(label))
#define SKIP _yaml_attribute("skip:true")
#define USE_IDX _yaml_attribute("idx:true")
#define FUNC(name) _yaml_attribute("func:" _yaml_note(name))
#define NAME(label) _yaml_attribute("name:" _yaml_note(label))
#define CUST(read,write) \
_yaml_attribute("read:" _yaml_note(read)) \
_yaml_attribute("write:" _yaml_note(write))
#define ARRAY(elmt_size,elmt_type,fcn) \
_yaml_attribute("array:" _yaml_note(elmt_size) "|" \
_yaml_note(elmt_type) "|" _yaml_note(fcn))
#else
#define ENUM(label)
#define SKIP
#define USE_IDX
#define FUNC(name)
#define NAME(label)
#define CUST(read,write)
#define ARRAY(elmt_size,elmt_type,fcn)
#endif
#endif
+136
View File
@@ -0,0 +1,136 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "yaml_modelslist.h"
#include "yaml_parser.h"
#include "storage/modelslist.h"
using std::list;
struct modelslist_iter
{
enum Level {
Root=0,
Category=1,
Model=2
};
ModelsList* root;
uint8_t level;
char current_attr[16]; // set after find_node()
};
static modelslist_iter __modelslist_iter_inst;
void* get_modelslist_iter()
{
__modelslist_iter_inst.root = &modelslist;
__modelslist_iter_inst.level = 0;
return &__modelslist_iter_inst;
}
static bool to_parent(void* ctx)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
if (mi->level == modelslist_iter::Root) {
return false;
}
mi->level--;
return true;
}
static bool to_child(void* ctx)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
if (mi->level == modelslist_iter::Model) {
return false;
}
mi->level++;
return true;
}
static bool to_next_elmt(void* ctx)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
if (mi->level == modelslist_iter::Root) {
return false;
}
return true;
}
static bool find_node(void* ctx, char* buf, uint8_t len)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
if (len > sizeof(modelslist_iter::current_attr)-1)
len = sizeof(modelslist_iter::current_attr)-1;
memcpy(mi->current_attr, buf, len);
mi->current_attr[len] = '\0';
return true;
}
static void set_attr(void* ctx, char* buf, uint8_t len)
{
modelslist_iter* mi = (modelslist_iter*)ctx;
list<ModelsCategory *>& cats = mi->root->getCategories();
switch(mi->level) {
case modelslist_iter::Category: {
ModelsCategory* cat = new ModelsCategory(buf,len);
cats.push_back(cat);
} break;
case modelslist_iter::Model:
if (!strcmp(mi->current_attr,"filename")) {
if (!cats.empty()) {
ModelCell* model = new ModelCell(buf, len);
cats.back()->push_back(model);
mi->root->incModelsCount();
}
}
else if (!strcmp(mi->current_attr,"name")) {
if (!cats.empty()) {
ModelsCategory* cat = cats.back();
if (!cat->empty()) {
ModelCell* model = cat->back();
model->setModelName(buf,len);
}
}
}
break;
}
}
static const YamlParserCalls modelslistCalls = {
to_parent,
to_child,
to_next_elmt,
find_node,
set_attr
};
const YamlParserCalls* get_modelslist_parser_calls()
{
return &modelslistCalls;
}
+29
View File
@@ -0,0 +1,29 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _YAML_MODELSLIST_H_
#define _YAML_MODELSLIST_H_
struct YamlParserCalls;
void* get_modelslist_iter();
const YamlParserCalls* get_modelslist_parser_calls();
#endif
+174
View File
@@ -0,0 +1,174 @@
#ifndef _node_h_
#define _node_h_
#include <stdint.h>
#include <stddef.h>
#include "yaml_parser.h"
#define NODE_STACK_DEPTH 12
enum YamlDataType {
YDT_NONE=0,
YDT_IDX,
YDT_SIGNED,
YDT_UNSIGNED,
YDT_STRING,
YDT_ARRAY,
YDT_ENUM,
YDT_UNION,
YDT_PADDING
};
struct YamlIdStr
{
int id;
const char* str;
};
// return false if error
typedef bool (*yaml_writer_func)(void* opaque, const char* str, size_t len);
struct YamlNode
{
typedef bool (*is_active_func)(uint8_t* data, uint32_t bitoffs);
typedef uint32_t (*cust_to_uint_func)(const YamlNode* node, const char* val, uint8_t val_len);
typedef bool (*uint_to_cust_func)(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque);
typedef uint8_t (*select_member_func)(uint8_t* data, uint32_t bitoffs);
typedef uint32_t (*cust_idx_read_func)(const char* val, uint8_t val_len);
typedef bool (*cust_idx_write_func)(uint32_t idx, yaml_writer_func wf, void* opaque);
uint8_t type;
uint32_t size; // bits
uint8_t tag_len;
const char* tag;
union {
struct {
const YamlNode* child;
union {
struct {
is_active_func is_active;
uint16_t elmts; // maximum number of elements
} _a;
select_member_func select_member;
} u;
} _array;
struct {
const YamlIdStr* choices;
} _enum;
struct {
cust_to_uint_func cust_to_uint;
uint_to_cust_func uint_to_cust;
} _cust;
struct {
cust_idx_read_func read;
cust_idx_write_func write;
} _cust_idx;
} u;
};
#if !defined(_MSC_VER)
#define YAML_TAG(str) \
.tag_len=(sizeof(str)-1), .tag=(str)
#define YAML_IDX \
{ .type=YDT_IDX, .size=0, YAML_TAG("idx") }
#define YAML_IDX_CUST(tag, f_read, f_write) \
{ .type=YDT_IDX, .size=0, YAML_TAG(tag), .u={._cust_idx={.read=(f_read), .write=(f_write) }} }
#define YAML_SIGNED(tag, bits) \
{ .type=YDT_SIGNED, .size=(bits), YAML_TAG(tag) }
#define YAML_UNSIGNED(tag, bits) \
{ .type=YDT_UNSIGNED, .size=(bits), YAML_TAG(tag) }
#define YAML_SIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
{ .type=YDT_SIGNED, .size=(bits), YAML_TAG(tag), .u={._cust={ .cust_to_uint=f_cust_to_uint, .uint_to_cust=f_uint_to_cust }} }
#define YAML_UNSIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
{ .type=YDT_UNSIGNED, .size=(bits), YAML_TAG(tag), .u={._cust={ .cust_to_uint=f_cust_to_uint, .uint_to_cust=f_uint_to_cust }} }
#define YAML_STRING(tag, max_len) \
{ .type=YDT_STRING, .size=((max_len)<<3), YAML_TAG(tag) }
#define YAML_STRUCT(tag, bits, nodes, f_is_active) \
{ .type=YDT_ARRAY, .size=(bits), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={ ._a={.is_active=(f_is_active), .elmts=1 }}}} }
#define YAML_ARRAY(tag, bits, max_elmts, nodes, f_is_active) \
{ .type=YDT_ARRAY, .size=(bits), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={ ._a={.is_active=(f_is_active), .elmts=(max_elmts) }}}} }
#define YAML_ENUM(tag, bits, id_strs) \
{ .type=YDT_ENUM, .size=(bits), YAML_TAG(tag), .u={._enum={ .choices=(id_strs) }} }
#define YAML_UNION(tag, bits, nodes, f_sel_m) \
{ .type=YDT_UNION, .size=(bits), YAML_TAG(tag), .u={._array={ .child=(nodes), .u={.select_member=(f_sel_m) }}} }
#define YAML_PADDING(bits) \
{ .type=YDT_PADDING, .size=(bits) }
#define YAML_END \
{ .type=YDT_NONE }
#define YAML_ROOT(nodes) \
{ .type=YDT_ARRAY, .size=0, .tag_len=0, .tag=NULL, \
.u={ \
._array={ .child=(nodes), \
.u={._a={.is_active=NULL, .elmts=1 }} \
}} \
}
#else // MSVC++ compat
#define YAML_TAG(str) \
(sizeof(str)-1), (str)
#define YAML_IDX \
{ YDT_IDX , 0, YAML_TAG("idx") }
#define YAML_SIGNED(tag, bits) \
{ YDT_SIGNED, (bits), YAML_TAG(tag) }
#define YAML_UNSIGNED(tag, bits) \
{ YDT_UNSIGNED, (bits), YAML_TAG(tag) }
#define YAML_SIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
{ YDT_SIGNED, (bits), YAML_TAG(tag), {{ (const YamlNode*)f_cust_to_uint, {{ (YamlNode::is_active_func)f_uint_to_cust, 0 }}}} }
#define YAML_UNSIGNED_CUST(tag, bits, f_cust_to_uint, f_uint_to_cust) \
{ YDT_UNSIGNED, (bits), YAML_TAG(tag), {{ (const YamlNode*)f_cust_to_uint, {{ (YamlNode::is_active_func)f_uint_to_cust, 0}}}} }
#define YAML_STRING(tag, max_len) \
{ YDT_STRING, ((max_len)<<3), YAML_TAG(tag) }
#define YAML_STRUCT(tag, bits, nodes, f_is_active) \
{ YDT_ARRAY, (bits), YAML_TAG(tag), {{ (nodes), {{ (f_is_active), 1 }}}} }
#define YAML_ARRAY(tag, bits, max_elmts, nodes, f_is_active) \
{ YDT_ARRAY, (bits), YAML_TAG(tag), {{ (nodes), {{ (f_is_active), (max_elmts) }}}} }
#define YAML_ENUM(tag, bits, id_strs) \
{ YDT_ENUM, (bits), YAML_TAG(tag), {{ (const YamlNode*)(id_strs) }} }
#define YAML_UNION(tag, bits, nodes, f_sel_m) \
{ YDT_UNION, (bits), YAML_TAG(tag), {{ (nodes), {{ (YamlNode::is_active_func)(f_sel_m), 0 }}}} }
#define YAML_PADDING(bits) \
{ YDT_PADDING, (bits) }
#define YAML_END \
{ YDT_NONE }
#define YAML_ROOT(nodes) \
{ YDT_ARRAY, 0, 0, NULL, {{ (nodes), {{ NULL, 1 }}}} }
#endif
#endif
+256
View File
@@ -0,0 +1,256 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include "yaml_parser.h"
#include "debug.h"
YamlParser::YamlParser()
{
}
void YamlParser::init(const YamlParserCalls* parser_calls, void* parser_ctx)
{
indent = 0;
level = 0;
memset(indents, 0, sizeof(indents));
calls = parser_calls;
ctx = parser_ctx;
reset();
}
void YamlParser::reset()
{
state = ps_Indent;
indents[level] = indent;
indent = scratch_len = 0;
node_found = false;
}
bool YamlParser::toChild()
{
bool ret = calls->to_child(ctx);
if (ret) level++;
return ret;
}
bool YamlParser::toParent()
{
if (!level)
return false;
bool ret = calls->to_parent(ctx);
if (ret) level--;
return ret;
}
uint8_t YamlParser::getLastIndent()
{
return indents[level];
}
YamlParser::YamlResult
YamlParser::parse(const char* buffer, unsigned int size)
{
#define CONCAT_STR(s,s_len,c) \
{ \
if(s_len < MAX_STR) \
s[s_len++] = c; \
else { \
TRACE("STRING_OVERFLOW"); \
return STRING_OVERFLOW; \
} \
}
const char* c = buffer;
const char* end = c + size;
while(c < end) {
switch(state) {
case ps_Indent:
if (*c == '-') {
state = ps_Dash;
++indent;
break;
}
// trap
case ps_Dash:
if (*c == ' ') { // skip space(s), should be only one??
++indent;
break;
}
if (indent < getLastIndent()) {
// go up as many levels as necessary
do {
if (!toParent()) {
TRACE("STOP (no parent)!\n");
return DONE_PARSING;
}
} while (indent < getLastIndent());
if (state == ps_Dash) {
if (!calls->to_next_elmt(ctx)) {
return DONE_PARSING;
}
}
}
// go down one level
else if (indent > getLastIndent()) {
if (!toChild()) {
TRACE("STOP (stack full)!\n");
return DONE_PARSING; // ERROR
}
}
// same level, next element
else if (state == ps_Dash) {
if (!calls->to_next_elmt(ctx)) {
return DONE_PARSING;
}
}
state = ps_Attr;
CONCAT_STR(scratch_buf, scratch_len, *c);
break;
case ps_Attr:
if (*c == ' ') {// assumes nothing else comes after spaces start
node_found = calls->find_node(ctx, scratch_buf, scratch_len);
if (!node_found) {
TRACE("YAML_PARSER: Could not find node '%.*s' (1)\n",
scratch_len, scratch_buf);
}
state = ps_AttrSP;
break;
}
if (*c != ':')
CONCAT_STR(scratch_buf, scratch_len, *c);
// trap
case ps_AttrSP:
if (*c == '\r' || *c == '\n') {
if (state == ps_Attr) {
node_found = calls->find_node(ctx, scratch_buf, scratch_len);
if (!node_found) {
TRACE("YAML_PARSER: Could not find node '%.*s' (2)\n",
scratch_len, scratch_buf);
}
}
state = ps_CRLF;
continue;
}
if (*c == ':') {
if (state == ps_Attr) {
node_found = calls->find_node(ctx, scratch_buf, scratch_len);
if (!node_found) {
TRACE("YAML_PARSER: Could not find node '%.*s' (3)\n",
scratch_len, scratch_buf);
}
}
state = ps_Sep;
break;
}
break;
case ps_Sep:
if (*c == ' ')
break;
if (*c == '\r' || *c == '\n'){
state = ps_CRLF;
continue;
}
state = ps_Val;
scratch_len = 0;
if (*c == '\"') {
state = ps_ValQuo;
break;
}
CONCAT_STR(scratch_buf, scratch_len, *c);
break;
case ps_ValQuo:
if (*c == '\"') {
state = ps_Val;
break;
}
if (*c == '\\') {
state = ps_ValEsc1;
break;
}
CONCAT_STR(scratch_buf, scratch_len, *c);
break;
case ps_ValEsc1:
if (*c == 'x') {
state = ps_ValEsc2;
break;
}
//TODO: more escapes needed???
TRACE("unknown escape char '%c'",*c);
return DONE_PARSING;
case ps_ValEsc2:
if(scratch_len >= MAX_STR) {
TRACE("STRING_OVERFLOW");
return STRING_OVERFLOW;
}
else if (*c >= '0' && *c <= '9') {
scratch_buf[scratch_len] = (*c - '0') << 4;
state = ps_ValEsc3;
break;
}
else if (*c >= 'A' && *c <= 'F') {
scratch_buf[scratch_len] = (*c - 'A' + 10) << 4;
state = ps_ValEsc3;
break;
}
TRACE("wrong hex digit '%c'",*c);
return DONE_PARSING;
case ps_ValEsc3:
if (*c >= '0' && *c <= '9') {
scratch_buf[scratch_len++] |= (*c - '0');
state = ps_ValQuo;
break;
}
else if (*c >= 'A' && *c <= 'F') {
scratch_buf[scratch_len++] |= (*c - 'A' + 10);
state = ps_ValQuo;
break;
}
TRACE("wrong hex digit '%c'",*c);
return DONE_PARSING;
case ps_Val:
if (*c == ' ' || *c == '\r' || *c == '\n') {
// set attribute
if (node_found) {
calls->set_attr(ctx, scratch_buf, scratch_len);
}
state = ps_CRLF;
continue;
}
if (*c == '\"') {
state = ps_ValQuo;
break;
}
CONCAT_STR(scratch_buf, scratch_len, *c);
break;
case ps_CRLF:
if (*c == '\n') {
// reset state at EOL
reset();
}
break;
}
c++;
} // for each char
return CONTINUE_PARSING;
}
+79
View File
@@ -0,0 +1,79 @@
#ifndef _yaml_parser_h_
#define _yaml_parser_h_
#include <stdint.h>
#define MAX_STR 40
#define MAX_DEPTH 16 // 12 real + 4 virtual
struct YamlParserCalls
{
bool (*to_parent) (void* ctx);
bool (*to_child) (void* ctx);
bool (*to_next_elmt) (void* ctx);
bool (*find_node) (void* ctx, char* buf, uint8_t len);
void (*set_attr) (void* ctx, char* buf, uint8_t len);
};
class YamlParser
{
enum ParserState {
ps_Indent=0,
ps_Dash,
ps_Attr,
ps_AttrSP,
ps_Sep,
ps_Val,
ps_ValQuo,
ps_ValEsc1,
ps_ValEsc2,
ps_ValEsc3,
ps_CRLF
};
// last indents for each level
uint8_t indents[MAX_DEPTH];
// current indent
uint8_t indent;
// current level
uint8_t level;
// parser state
uint8_t state;
// scratch buffer w/ 16 bytes
// used for attribute and values
char scratch_buf[MAX_STR];
uint8_t scratch_len;
bool node_found;
// tree iterator state
const YamlParserCalls* calls;
void* ctx;
// Reset parser state for next line
void reset();
bool toChild();
bool toParent();
uint8_t getLastIndent();
public:
enum YamlResult {
DONE_PARSING,
CONTINUE_PARSING,
STRING_OVERFLOW
};
YamlParser();
void init(const YamlParserCalls* parser_calls, void* parser_ctx);
YamlResult parse(const char* buffer, unsigned int size);
};
#endif
+620
View File
@@ -0,0 +1,620 @@
#include "debug.h"
#include "yaml_node.h"
#include "yaml_bits.h"
#include "yaml_tree_walker.h"
#include "yaml_parser.h"
#include <string.h>
#define MIN(a,b) (a < b ? a : b)
static void copy_string(char* dst, const char* src, uint8_t len)
{
memcpy(dst,src,len);
dst[len] = '\0';
}
uint32_t yaml_parse_enum(const struct YamlIdStr* choices, const char* val, uint8_t val_len)
{
while (choices->str) {
// we have a match!
if (!strncmp(val, choices->str, val_len))
break;
choices++;
}
return choices->id;
}
static void yaml_set_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node,
const char* val, uint8_t val_len)
{
uint32_t i = 0;
//TRACE("set(%s, %.*s, bit-ofs=%u, bits=%u)\n",
// node->tag, val_len, val, bit_ofs, node->size);
ptr += bit_ofs >> 3UL;
bit_ofs &= 0x07;
if (node->type == YDT_STRING) {
//assert(!bit_ofs);
copy_string((char*)ptr, val, MIN(val_len, node->size - 1));
return;
}
switch(node->type) {
case YDT_SIGNED:
i = node->u._cust.cust_to_uint ? node->u._cust.cust_to_uint(node, val, val_len)
: (uint32_t)yaml_str2int(val, val_len);
break;
case YDT_UNSIGNED:
i = node->u._cust.cust_to_uint ? node->u._cust.cust_to_uint(node, val, val_len)
: yaml_str2uint(val, val_len);
break;
case YDT_ENUM:
i = yaml_parse_enum(node->u._enum.choices, val, val_len);
break;
default:
break;
}
yaml_put_bits(ptr, i, bit_ofs, node->size);
}
const char* yaml_output_enum(int32_t i, const struct YamlIdStr* choices)
{
//TRACE("<choice = %d>", i);
while(choices->str) {
if (i == choices->id)
break;
choices++;
}
return choices->str;
}
static const char hex_digits[] {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
static bool yaml_output_string(const char* str, uint32_t max_len,
yaml_writer_func wf, void* opaque)
{
if (!wf(opaque, "\"", 1))
return false;
while(*str && max_len > 0) {
if (*str >= 0x20 && *str <= 0x7E) {
if (!wf(opaque, str++, 1)) return false;
max_len--;
}
else {
if (!wf(opaque, "\\x", 2)) return false;
if (!wf(opaque, &(hex_digits[((uint8_t)*str) >> 4]), 1)) return false;
if (!wf(opaque, &(hex_digits[((uint8_t)*str) & 0x0F]), 1)) return false;
str++; max_len--;
}
}
if (!wf(opaque, "\"", 1))
return false;
return true;
}
static bool yaml_output_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node,
yaml_writer_func wf, void* opaque)
{
if (node->type == YDT_NONE)
return false;
if (node->type == YDT_PADDING)
return true;
// output tag
if (!wf(opaque, node->tag, node->tag_len))
return false;
if (!wf(opaque, ": ", 2))
return false;
if (ptr) {
ptr += bit_ofs >> 3UL;
bit_ofs &= 0x07;
const char* p_out = NULL;
if (node->type == YDT_STRING) {
//assert(!bit_ofs);
if (!yaml_output_string((const char*)ptr, (node->size)>>3UL, wf, opaque))
return false;
}
else {
unsigned int i = yaml_get_bits(ptr, bit_ofs, node->size);
if ((node->type == YDT_SIGNED || node->type == YDT_UNSIGNED)
&& node->u._cust.uint_to_cust) {
return node->u._cust.uint_to_cust(node, i, wf, opaque)
&& wf(opaque, "\r\n", 2);
}
else {
switch(node->type) {
case YDT_SIGNED:
p_out = yaml_signed2str((int)yaml_to_signed(i, node->size));
break;
case YDT_UNSIGNED:
p_out = yaml_unsigned2str(i);
break;
case YDT_ENUM:
p_out = yaml_output_enum(i, node->u._enum.choices);
break;
case YDT_ARRAY:
case YDT_UNION:
default:
break;
}
}
}
if (p_out && !wf(opaque, p_out, strlen(p_out)))
return false;
}
return wf(opaque, "\r\n", 2);
}
YamlTreeWalker::YamlTreeWalker()
: stack_level(NODE_STACK_DEPTH),
virt_level(0),
anon_union(0)
{
memset(stack,0,sizeof(stack));
}
void YamlTreeWalker::reset(const YamlNode* node, uint8_t* data)
{
this->data = data;
stack_level = NODE_STACK_DEPTH;
virt_level = 0;
push();
setNode(node);
rewind();
}
bool YamlTreeWalker::push()
{
if (full())
return false;
stack_level--;
memset(&(stack[stack_level]), 0, sizeof(State));
return true;
}
bool YamlTreeWalker::pop()
{
if (empty())
return false;
memset(&(stack[stack_level]), 0, sizeof(State));
stack_level++;
return true;
}
// Rewind to the current node's first attribute
// (and reset the bit offset)
void YamlTreeWalker::rewind()
{
if (getNode()->type == YDT_ARRAY
|| getNode()->type == YDT_UNION) {
setAttrIdx(0);
setAttrOfs(getLevelOfs());
}
}
// Increment the cursor until a match is found or the end of
// the current collection (node of type YDT_NONE) is reached.
//
// return true if a match has been found.
bool YamlTreeWalker::findNode(const char* tag, uint8_t tag_len)
{
if (virt_level)
return false;
rewind();
const struct YamlNode* attr = getAttr();
while(attr && attr->type != YDT_NONE) {
if ((tag_len == attr->tag_len)
&& !strncmp(tag, attr->tag, tag_len)) {
return true; // attribute found!
}
toNextAttr();
attr = getAttr();
}
return false;
}
// Get the current bit offset
unsigned int YamlTreeWalker::getBitOffset()
{
return stack[stack_level].getOfs();
}
bool YamlTreeWalker::toParent()
{
if(virt_level) {
virt_level--;
return true;
}
if (!pop())
return false;
return !empty();
}
bool YamlTreeWalker::toChild()
{
const struct YamlNode* attr = getAttr();
if (!attr
|| (attr->type != YDT_ARRAY
&& attr->type != YDT_UNION)) {
virt_level++;
return true;
}
if (!push()) {
virt_level++;
return false;
}
setNode(attr);
setAttrOfs(getLevelOfs());
attr = getAttr();
if ((attr->type == YDT_UNION) && (attr->tag_len == 0)) {
toChild();
anon_union++;
}
return true;
}
bool YamlTreeWalker::toNextElmt()
{
const struct YamlNode* node = getNode();
if (!virt_level && (node->type == YDT_ARRAY
|| node->type == YDT_UNION)) {
if (node->type == YDT_UNION) {
return false;
}
if (getElmts() >= node->u._array.u._a.elmts - 1)
return false;
incElmts();
rewind();
}
return true;
}
bool YamlTreeWalker::isElmtEmpty(uint8_t* data)
{
if (virt_level)
return true;
if (!data)
return false;
const struct YamlNode* node = getNode();
uint32_t bit_ofs = 0;
if (node->type == YDT_ARRAY) {
bit_ofs = ((uint32_t)getElmts())
* getNode()->size
+ getLevelOfs();
// assume structs aligned on 8bit boundaries
if (node->u._array.u._a.is_active)
return !node->u._array.u._a.is_active(data, bit_ofs);
return yaml_is_zero(data, bit_ofs, node->size);
}
else if ((node->type == YDT_UNION) && hasParent()) {
bit_ofs = getLevelOfs();
TRACE("<not empty>");
return false;//node->u._array.u.select_member; //TODO!
// // assume structs aligned on 8bit boundaries
// && !node->_array.is_active(data + (bit_ofs >> 3));
}
return false;
}
void YamlTreeWalker::toNextAttr()
{
const struct YamlNode* node = getNode();
const struct YamlNode* attr = NULL;
if (node->type != YDT_UNION) {
attr = getAttr();
uint32_t attr_bit_ofs = getAttrOfs();
if (attr->type == YDT_ARRAY)
attr_bit_ofs += ((uint32_t)attr->u._array.u._a.elmts * attr->size);
else
attr_bit_ofs += attr->size;
setAttrOfs(attr_bit_ofs);
}
incAttr();
// anonymous union handling
attr = getAttr();
if ((attr->type == YDT_UNION) && (attr->tag_len == 0)) {
toChild();
anon_union++;
}
else if ((attr->type == YDT_NONE)
&& (getNode()->type == YDT_UNION)
&& anon_union) {
anon_union--;
toParent();
toNextAttr();
}
}
void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
{
if (!buf || !len)
return;
const YamlNode* attr = getAttr();
if (attr->type == YDT_IDX) {
uint32_t i = 0;
if (attr->u._cust_idx.read)
i = attr->u._cust_idx.read(buf, len);
else
i = yaml_str2uint(buf, len);
while ((i > getElmts()) && toNextElmt());
}
else {
yaml_set_attr(data, getBitOffset(), attr, buf, len);
//walker.dump_stack();
}
}
bool YamlTreeWalker::generate(yaml_writer_func wf, void* opaque)
{
bool new_elmt = false;
while (true) {
const struct YamlNode* attr = getAttr();
if (attr->type == YDT_PADDING) {
toNextAttr();
continue;
}
// end of this level, go up or die
if (attr->type == YDT_NONE) {
const struct YamlNode* node = getNode();
if (node->type != YDT_ARRAY && node->type != YDT_UNION)
return false; // Error in the structure (probably)
// if parent is a union, no need to output the other elements...
const YamlNode* parent = getParent();
if (parent && (parent->type == YDT_UNION)) {
if (!toParent())
return false;
}
else {
// walk to next non-empty element
while (toNextElmt()) {
if (!isElmtEmpty(data)) {
new_elmt = true;
break;
}
}
if (new_elmt)
continue;
}
// no next element, go up
if (!toParent())
return true;
toNextAttr();
continue;
}
else if (attr->type == YDT_ARRAY || attr->type == YDT_UNION) {
if (!toChild())
return false; // TODO: error handling???
const struct YamlNode* node = getNode();
if (node->type == YDT_UNION && node->u._array.u.select_member) {
// output union tag, select member and go up one level
// output union tag
for(int i=2; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!yaml_output_attr(NULL, 0, node, wf, opaque))
return false; // TODO: error handling???
// grab attr idx...
uint8_t idx = node->u._array.u.select_member(data, getBitOffset());
//TRACE("<idx = %d>", idx);
setAttrIdx(idx);
attr = getAttr();
for(int i=1; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!yaml_output_attr(data, getBitOffset(), attr, wf, opaque))
return false; // TODO: error handling???
if (attr->type != YDT_ARRAY
&& attr->type != YDT_UNION) {
if (!toParent())
return false;
toNextAttr();
}
else {
if (!toChild() && !toParent())
return false;
}
continue;
}
// walk to next non-empty element
do {
if (!isElmtEmpty(data)) {
new_elmt = true;
break;
}
new_elmt = false;
} while (toNextElmt());
if (new_elmt) {
// non-empty element present in a new structure/array
// let's output the attribute
for(int i=2; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!yaml_output_attr(NULL, 0, getNode(), wf, opaque))
return false; // TODO: error handling???
continue;
}
// no next element, go up
if (!toParent())
return true;
toNextAttr();
continue;
}
if (new_elmt) {
for(int i=2; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!wf(opaque, " - ", 3))
return false;
new_elmt = false;
}
else {
for(int i=1; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
}
if (attr->type == YDT_IDX) {
if (!wf(opaque, attr->tag, attr->tag_len))
return false;
if (!wf(opaque, ": ", 2))
return false;
if (attr->u._cust_idx.write) {
if (!attr->u._cust_idx.write(getElmts(),wf,opaque))
return false;
}
else {
char* idx = yaml_unsigned2str(getElmts());
if (!wf(opaque, idx, strlen(idx)))
return false;
}
if (!wf(opaque, "\r\n", 2))
return false;
}
else if (!yaml_output_attr(data, getBitOffset(), attr, wf, opaque))
return false; // TODO: error handling???
toNextAttr();
}
return true;
}
void YamlTreeWalker::dump_stack()
{
for (int i=0; i<NODE_STACK_DEPTH; i++) {
TRACE(" [%p|%u|%i|%i]",
stack[i].node,stack[i].bit_ofs,
stack[i].attr_idx,stack[i].elmts);
}
TRACE("\n");
}
static bool to_parent(void* ctx)
{
return ((YamlTreeWalker*)ctx)->toParent();
}
static bool to_child(void* ctx)
{
return ((YamlTreeWalker*)ctx)->toChild();
}
static bool to_next_elmt(void* ctx)
{
return ((YamlTreeWalker*)ctx)->toNextElmt();
}
static bool find_node(void* ctx, char* buf, uint8_t len)
{
return ((YamlTreeWalker*)ctx)->findNode(buf,len);
}
static void set_attr(void* ctx, char* buf, uint8_t len)
{
return ((YamlTreeWalker*)ctx)->setAttrValue(buf,len);
}
const YamlParserCalls YamlTreeWalkerCalls = {
to_parent,
to_child,
to_next_elmt,
find_node,
set_attr
};
const YamlParserCalls* YamlTreeWalker::get_parser_calls()
{
return &YamlTreeWalkerCalls;
}
+122
View File
@@ -0,0 +1,122 @@
#ifndef _YAML_TREE_WALKER_H_
#define _YAML_TREE_WALKER_H_
#include <stdint.h>
#include "yaml_node.h"
struct YamlParserCalls;
class YamlTreeWalker
{
struct State {
const YamlNode* node;
uint32_t bit_ofs;
int8_t attr_idx;
uint16_t elmts;
inline uint32_t getOfs() {
return bit_ofs + node->size * elmts;
}
};
State stack[NODE_STACK_DEPTH];
uint8_t stack_level;
uint8_t virt_level;
uint8_t anon_union;
uint8_t* data;
uint32_t getAttrOfs() { return stack[stack_level].bit_ofs; }
uint32_t getLevelOfs() {
if (hasParent()) {
return stack[stack_level + 1].getOfs();
}
return 0;
}
const YamlNode* getParent() {
if (hasParent())
return stack[stack_level + 1].node;
return nullptr;
}
void setNode(const YamlNode* node) { stack[stack_level].node = node; }
void setAttrIdx(uint8_t idx) { stack[stack_level].attr_idx = idx; }
void setAttrOfs(unsigned int ofs) { stack[stack_level].bit_ofs = ofs; }
void incAttr() { stack[stack_level].attr_idx++; }
void incElmts() { stack[stack_level].elmts++; }
bool empty() { return stack_level == NODE_STACK_DEPTH; }
bool full() { return stack_level == 0; }
bool hasParent() { return stack_level < NODE_STACK_DEPTH -1; }
// return true on success
bool push();
bool pop();
// Rewind to the current node's first attribute
// (and reset the bit offset)
void rewind();
public:
YamlTreeWalker();
void reset(const YamlNode* node, uint8_t* data);
int getLevel() {
return NODE_STACK_DEPTH - stack_level
+ virt_level - anon_union;
}
const YamlNode* getNode() {
return stack[stack_level].node;
}
const YamlNode* getAttr() {
int8_t idx = stack[stack_level].attr_idx;
if (idx >= 0)
return &(stack[stack_level].node->u._array.child[idx]);
return NULL;
}
uint16_t getElmts() {
return stack[stack_level].elmts;
}
// Increment the cursor until a match is found or the end of
// the current collection (node of type YDT_NONE) is reached.
//
// return true if a match has been found.
bool findNode(const char* tag, uint8_t tag_len);
// Get the current bit offset
unsigned int getBitOffset();
bool toParent();
bool toChild();
bool toNextElmt();
void toNextAttr();
bool isElmtEmpty(uint8_t* data);
void setAttrValue(char* buf, uint8_t len);
bool generate(yaml_writer_func wf, void* opaque);
void dump_stack();
static const YamlParserCalls* get_parser_calls();
};
// utils
uint32_t yaml_parse_enum(const struct YamlIdStr* choices, const char* val, uint8_t val_len);
const char* yaml_output_enum(int32_t i, const struct YamlIdStr* choices);
#endif