WiP pass YamlTreeParser where needed

This commit is contained in:
Raphael Coeffic
2021-11-10 11:07:02 +01:00
parent d1c7ae4141
commit b7640a830f
28 changed files with 424 additions and 411 deletions
+1 -1
View File
@@ -310,7 +310,7 @@ union TelemetryScreenData {
#if defined(PCBTARANIS)
TelemetryScriptData script;
#endif
};
} FUNC(select_tele_screen_data);
#endif
PACK(struct VarioData {
@@ -89,7 +89,7 @@ static bool w_vbat_max(const YamlNode* node, uint32_t val, yaml_writer_func wf,
}
#if defined(COLORLCD)
static uint8_t select_zov(uint8_t* data, uint32_t bitoffs)
static uint8_t select_zov(void* user, uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= sizeof(ZoneOptionValueEnum);
@@ -100,7 +100,7 @@ static uint8_t select_zov(uint8_t* data, uint32_t bitoffs)
}
#endif
static uint8_t select_mod_type(uint8_t* data, uint32_t bitoffs)
static uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= offsetof(ModuleData, ppm);
@@ -136,7 +136,7 @@ static uint8_t select_mod_type(uint8_t* data, uint32_t bitoffs)
return 0;
}
static uint8_t select_custom_fn(uint8_t* data, uint32_t bitoffs)
static uint8_t select_custom_fn(void* user, uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= offsetof(CustomFunctionData, all);
@@ -154,71 +154,58 @@ static uint8_t select_custom_fn(uint8_t* data, uint32_t bitoffs)
return 1;
}
static uint8_t select_script_input(uint8_t* data, uint32_t bitoffs)
static uint8_t select_script_input(void* user, uint8_t* data, uint32_t bitoffs)
{
// always use 'value'
return 0;
}
static uint8_t select_id1(uint8_t* data, uint32_t bitoffs)
static uint8_t select_id1(void* user, uint8_t* data, uint32_t bitoffs)
{
// always use 'id'
return 0;
}
static uint8_t select_id2(uint8_t* data, uint32_t bitoffs)
static uint8_t select_id2(void* user, uint8_t* data, uint32_t bitoffs)
{
// always use 'instance'
return 0;
}
static uint8_t select_sensor_cfg(uint8_t* data, uint32_t bitoffs)
static uint8_t select_sensor_cfg(void* user, uint8_t* data, uint32_t bitoffs)
{
// always use 'param'
return 5;
}
#if 0
static uint32_t sw_read(const char* val, uint8_t val_len)
static bool sw_write(void* user, yaml_writer_func wf, void* opaque)
{
uint32_t sw = yaml_parse_enum(enum_MixSources, val, val_len);
if (sw >= MIXSRC_FIRST_SWITCH)
return sw - MIXSRC_FIRST_SWITCH;
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts();
return -1;
}
#endif
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 str ? wf(opaque, str, strlen(str)) : true;
const char* str =
yaml_output_enum(idx + MIXSRC_FIRST_SWITCH, enum_MixSources);
return str ? wf(opaque, str, strlen(str)) : true;
}
#if 0
static void r_stick_name(const YamlNode* node, uint8_t* data,
uint32_t bitoffs, uint16_t idx,
const char* val, uint8_t val_len)
{
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
}
#endif
static bool w_stick_name(const YamlNode* node, uint8_t* data,
uint32_t bitoffs, uint16_t idx,
static bool w_stick_name(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
return wf(opaque, rd->anaNames[idx], strnlen(rd->anaNames[idx], LEN_ANA_NAME));
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
return wf(opaque, rd->anaNames[idx],
strnlen(rd->anaNames[idx], LEN_ANA_NAME));
}
static bool stick_name_valid(uint8_t* data, uint32_t bitoffs, uint16_t idx)
static bool stick_name_valid(void* user, uint8_t* data, uint32_t bitoffs)
{
RadioData* rd = reinterpret_cast<RadioData*>(data);
return rd->anaNames[idx][0] != '\0';
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts();
RadioData* rd = reinterpret_cast<RadioData*>(data);
return rd->anaNames[idx][0] != '\0';
}
static const struct YamlNode struct_sticksConfig[] = {
@@ -227,29 +214,19 @@ static const struct YamlNode struct_sticksConfig[] = {
YAML_END
};
#if 0
static void sw_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, const char* val, uint8_t val_len)
static bool sw_name_write(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, switchConfig);
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
RadioData* rd = reinterpret_cast<RadioData*>(data);
strncpy(rd->switchNames[idx], val, std::min<uint8_t>(val_len, LEN_SWITCH_NAME));
}
#endif
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, switchConfig);
static bool sw_name_write(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, yaml_writer_func wf, void* opaque)
{
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
const char* str = rd->switchNames[idx];
return wf(opaque, str, strnlen(str, LEN_SWITCH_NAME));
RadioData* rd = reinterpret_cast<RadioData*>(data);
const char* str = rd->switchNames[idx];
return wf(opaque, str, strnlen(str, LEN_SWITCH_NAME));
}
static const struct YamlIdStr enum_SwitchConfig[] = {
@@ -267,48 +244,29 @@ static const struct YamlNode struct_switchConfig[] = {
YAML_END
};
#if 0
static uint32_t pot_read(const char* val, uint8_t val_len)
static bool pot_write(void* user, yaml_writer_func wf, void* opaque)
{
uint32_t pot = yaml_parse_enum(enum_MixSources, val, val_len);
if (pot >= MIXSRC_FIRST_POT)
return pot - MIXSRC_FIRST_POT;
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts();
return -1;
}
#endif
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 str ? wf(opaque, str, strlen(str)) : true;
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_POT, enum_MixSources);
return str ? wf(opaque, str, strlen(str)) : true;
}
#if 0
static void pot_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, const char* val, uint8_t val_len)
static bool pot_name_write(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, potsConfig);
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS;
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
}
#endif
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, potsConfig);
static bool pot_name_write(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, yaml_writer_func wf, void* opaque)
{
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, potsConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS;
const char* str = rd->anaNames[idx];
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS;
const char* str = rd->anaNames[idx];
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
}
static const struct YamlIdStr enum_PotConfig[] = {
@@ -326,66 +284,39 @@ static const struct YamlNode struct_potConfig[] = {
YAML_END
};
#if 0
static uint32_t slider_read(const char* val, uint8_t val_len)
static bool slider_write(void* user, yaml_writer_func wf, void* opaque)
{
uint32_t sl = yaml_parse_enum(enum_MixSources, val, val_len);
if (sl >= MIXSRC_FIRST_SLIDER)
return sl - MIXSRC_FIRST_SLIDER;
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts();
return -1;
}
#endif
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 str ? wf(opaque, str, strlen(str)) : true;
const char* str =
yaml_output_enum(idx + MIXSRC_FIRST_SLIDER, enum_MixSources);
return str ? wf(opaque, str, strlen(str)) : true;
}
#if 0
static void sl_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, const char* val, uint8_t val_len)
static bool sl_name_write(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
// data / bitoffs already incremented
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
// data / bitoffs already incremented
#if defined(PCBTARANIS)
// Please note:
// slidersConfig is defined as a bit-field member,
// so let's take the next field and subtract 1
//
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
data -= offsetof(RadioData, potsConfig) - 1;
// Please note:
// slidersConfig is defined as a bit-field member,
// so let's take the next field and subtract 1
//
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
data -= offsetof(RadioData, potsConfig) - 1;
#else
data -= (idx + 1) / 8;
data -= offsetof(RadioData, slidersConfig);
data -= (idx + 1) / 8;
data -= offsetof(RadioData, slidersConfig);
#endif
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS + STORAGE_NUM_POTS;
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
}
#endif
static bool sl_name_write(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, yaml_writer_func wf, void* opaque)
{
// data / bitoffs already incremented
#if defined(PCBTARANIS)
// Please note:
// slidersConfig is defined as a bit-field member,
// so let's take the next field and subtract 1
//
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
data -= offsetof(RadioData, potsConfig) - 1;
#else
data -= (idx + 1) / 8;
data -= offsetof(RadioData, slidersConfig);
#endif
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS + STORAGE_NUM_POTS;
const char* str = rd->anaNames[idx];
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS + STORAGE_NUM_POTS;
const char* str = rd->anaNames[idx];
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
}
static const struct YamlIdStr enum_SliderConfig[] = {
@@ -456,19 +387,19 @@ static bool w_swtchSrc(const YamlNode* node, uint32_t val, yaml_writer_func wf,
return wf(opaque, str, strlen(str));
}
static bool cfn_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx)
static bool cfn_is_active(void* user, uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
return ((CustomFunctionData*)data)->swtch;
}
static bool gvar_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx)
static bool gvar_is_active(void* user, 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, uint16_t idx)
static bool fmd_is_active(void* user, uint8_t* data, uint32_t bitoffs)
{
uint32_t data_ofs = bitoffs >> 3UL;
if (data_ofs == offsetof(ModelData, flightModeData)) {
@@ -612,3 +543,27 @@ static bool w_trainerMode(const YamlNode* node, uint32_t val,
return true;
}
#if !defined(COLORLCD)
static uint8_t select_tele_screen_data(void* user, uint8_t* data, uint32_t bitoffs)
{
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(2);
auto md = reinterpret_cast<ModelData*>(data);
uint8_t st = (md->screensType >> (2 * idx)) & 0x03;
switch(st){
case TELEMETRY_SCREEN_TYPE_NONE:
break;
case TELEMETRY_SCREEN_TYPE_VALUES:
return 1; // lines
case TELEMETRY_SCREEN_TYPE_BARS:
return 0; // bars
case TELEMETRY_SCREEN_TYPE_SCRIPT:
return 2;
}
TRACE("select_tele_screen_data(idx=%d)", idx);
return 0;
}
#endif
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -764,7 +764,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -803,7 +803,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -736,7 +736,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -746,7 +746,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -743,7 +743,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -747,7 +747,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
+171 -109
View File
@@ -127,7 +127,7 @@ static bool w_vbat_max(const YamlNode* node, uint32_t val, yaml_writer_func wf,
}
#if defined(COLORLCD)
static uint8_t select_zov(uint8_t* data, uint32_t bitoffs)
static uint8_t select_zov(void* user, uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= sizeof(ZoneOptionValueEnum);
@@ -138,7 +138,7 @@ static uint8_t select_zov(uint8_t* data, uint32_t bitoffs)
}
#endif
static uint8_t select_mod_type(uint8_t* data, uint32_t bitoffs)
static uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
data -= offsetof(ModuleData, ppm);
@@ -174,74 +174,86 @@ static uint8_t select_mod_type(uint8_t* data, uint32_t bitoffs)
return 0;
}
static uint8_t select_custom_fn(uint8_t* data, uint32_t bitoffs)
static uint8_t select_custom_fn(void* user, uint8_t* data, uint32_t bitoffs)
{
// always use 'all'
//TODO
return 1;
}
static uint8_t select_script_input(uint8_t* data, uint32_t bitoffs)
static uint8_t select_script_input(void* user, uint8_t* data, uint32_t bitoffs)
{
// always use 'value'
return 0;
}
static uint8_t select_id1(uint8_t* data, uint32_t bitoffs)
static uint8_t select_id1(void* user, uint8_t* data, uint32_t bitoffs)
{
// always use 'id'
return 0;
}
static uint8_t select_id2(uint8_t* data, uint32_t bitoffs)
static uint8_t select_id2(void* user, uint8_t* data, uint32_t bitoffs)
{
// always use 'instance'
return 0;
}
static uint8_t select_sensor_cfg(uint8_t* data, uint32_t bitoffs)
static uint8_t select_sensor_cfg(void* user, uint8_t* data, uint32_t bitoffs)
{
// always use 'param'
return 5;
}
static uint32_t sw_read(const char* val, uint8_t val_len)
static uint32_t sw_read(void* user, const char* val, uint8_t val_len)
{
uint32_t sw = yaml_parse_enum(enum_MixSources, val, val_len);
if (sw >= MIXSRC_FIRST_SWITCH)
return sw - MIXSRC_FIRST_SWITCH;
(void)user;
uint32_t sw = yaml_parse_enum(enum_MixSources, val, val_len);
if (sw >= MIXSRC_FIRST_SWITCH) return sw - MIXSRC_FIRST_SWITCH;
return -1;
return -1;
}
static bool sw_write(uint32_t idx, yaml_writer_func wf, void* opaque)
static bool sw_write(void* user, yaml_writer_func wf, void* opaque)
{
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SWITCH, enum_MixSources);
return str ? wf(opaque, str, strlen(str)) : true;
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts();
const char* str =
yaml_output_enum(idx + MIXSRC_FIRST_SWITCH, enum_MixSources);
return str ? wf(opaque, str, strlen(str)) : true;
}
static void r_stick_name(const YamlNode* node, uint8_t* data,
uint32_t bitoffs, uint16_t idx,
static void r_stick_name(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
if (idx >= NUM_STICKS) return;
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
}
static bool w_stick_name(const YamlNode* node, uint8_t* data,
uint32_t bitoffs, uint16_t idx,
static bool w_stick_name(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
return wf(opaque, rd->anaNames[idx], strnlen(rd->anaNames[idx], LEN_ANA_NAME));
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
return wf(opaque, rd->anaNames[idx],
strnlen(rd->anaNames[idx], LEN_ANA_NAME));
}
static bool stick_name_valid(uint8_t* data, uint32_t bitoffs, uint16_t idx)
static bool stick_name_valid(void* user, uint8_t* data, uint32_t bitoffs)
{
RadioData* rd = reinterpret_cast<RadioData*>(data);
return rd->anaNames[idx][0] != '\0';
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts();
RadioData* rd = reinterpret_cast<RadioData*>(data);
return rd->anaNames[idx][0] != '\0';
}
static const struct YamlNode struct_sticksConfig[] = {
@@ -250,27 +262,34 @@ static const struct YamlNode struct_sticksConfig[] = {
YAML_END
};
static void sw_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, const char* val, uint8_t val_len)
static void sw_name_read(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, switchConfig);
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
RadioData* rd = reinterpret_cast<RadioData*>(data);
strncpy(rd->switchNames[idx], val, std::min<uint8_t>(val_len, LEN_SWITCH_NAME));
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
strncpy(rd->switchNames[idx], val,
std::min<uint8_t>(val_len, LEN_SWITCH_NAME));
}
static bool sw_name_write(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, yaml_writer_func wf, void* opaque)
static bool sw_name_write(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, switchConfig);
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
RadioData* rd = reinterpret_cast<RadioData*>(data);
const char* str = rd->switchNames[idx];
return wf(opaque, str, strnlen(str, LEN_SWITCH_NAME));
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, switchConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
const char* str = rd->switchNames[idx];
return wf(opaque, str, strnlen(str, LEN_SWITCH_NAME));
}
static const struct YamlIdStr enum_SwitchConfig[] = {
@@ -282,50 +301,59 @@ static const struct YamlIdStr enum_SwitchConfig[] = {
};
static const struct YamlNode struct_switchConfig[] = {
YAML_IDX_CUST( "sw", sw_read, sw_write ),
YAML_IDX_CUST( "sw", sw_read, sw_write),
YAML_ENUM( "type", 2, enum_SwitchConfig),
YAML_CUSTOM( "name", sw_name_read, sw_name_write),
YAML_END
};
static uint32_t pot_read(const char* val, uint8_t val_len)
static uint32_t pot_read(void* user, const char* val, uint8_t val_len)
{
uint32_t pot = yaml_parse_enum(enum_MixSources, val, val_len);
if (pot >= MIXSRC_FIRST_POT)
return pot - MIXSRC_FIRST_POT;
(void)user;
uint32_t pot = yaml_parse_enum(enum_MixSources, val, val_len);
if (pot >= MIXSRC_FIRST_POT) return pot - MIXSRC_FIRST_POT;
return -1;
return -1;
}
static bool pot_write(uint32_t idx, yaml_writer_func wf, void* opaque)
static bool pot_write(void* user, yaml_writer_func wf, void* opaque)
{
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_POT, enum_MixSources);
return str ? wf(opaque, str, strlen(str)) : true;
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts();
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_POT, enum_MixSources);
return str ? wf(opaque, str, strlen(str)) : true;
}
static void pot_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, const char* val, uint8_t val_len)
static void pot_name_read(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, potsConfig);
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS;
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, potsConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS;
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
}
static bool pot_name_write(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, yaml_writer_func wf, void* opaque)
static bool pot_name_write(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, potsConfig);
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS;
const char* str = rd->anaNames[idx];
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
// data / bitoffs already incremented
data -= ((idx + 1) * 2) / 8;
data -= offsetof(RadioData, potsConfig);
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS;
const char* str = rd->anaNames[idx];
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
}
static const struct YamlIdStr enum_PotConfig[] = {
@@ -343,62 +371,72 @@ static const struct YamlNode struct_potConfig[] = {
YAML_END
};
static uint32_t slider_read(const char* val, uint8_t val_len)
static uint32_t slider_read(void* user, const char* val, uint8_t val_len)
{
uint32_t sl = yaml_parse_enum(enum_MixSources, val, val_len);
if (sl >= MIXSRC_FIRST_SLIDER)
return sl - MIXSRC_FIRST_SLIDER;
(void)user;
uint32_t sl = yaml_parse_enum(enum_MixSources, val, val_len);
if (sl >= MIXSRC_FIRST_SLIDER) return sl - MIXSRC_FIRST_SLIDER;
return -1;
return -1;
}
static bool slider_write(uint32_t idx, yaml_writer_func wf, void* opaque)
static bool slider_write(void* user, yaml_writer_func wf, void* opaque)
{
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SLIDER, enum_MixSources);
return str ? wf(opaque, str, strlen(str)) : true;
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts();
const char* str =
yaml_output_enum(idx + MIXSRC_FIRST_SLIDER, enum_MixSources);
return str ? wf(opaque, str, strlen(str)) : true;
}
static void sl_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, const char* val, uint8_t val_len)
static void sl_name_read(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len)
{
// data / bitoffs already incremented
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
// data / bitoffs already incremented
#if defined(PCBTARANIS)
// Please note:
// slidersConfig is defined as a bit-field member,
// so let's take the next field and subtract 1
//
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
data -= offsetof(RadioData, potsConfig) - 1;
// Please note:
// slidersConfig is defined as a bit-field member,
// so let's take the next field and subtract 1
//
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
data -= offsetof(RadioData, potsConfig) - 1;
#else
data -= (idx + 1) / 8;
data -= offsetof(RadioData, slidersConfig);
data -= (idx + 1) / 8;
data -= offsetof(RadioData, slidersConfig);
#endif
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS + STORAGE_NUM_POTS;
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS + STORAGE_NUM_POTS;
strncpy(rd->anaNames[idx], val, std::min<uint8_t>(val_len, LEN_ANA_NAME));
}
static bool sl_name_write(const YamlNode* node, uint8_t* data, uint32_t bitoffs,
uint16_t idx, yaml_writer_func wf, void* opaque)
static bool sl_name_write(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
// data / bitoffs already incremented
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(1);
// data / bitoffs already incremented
#if defined(PCBTARANIS)
// Please note:
// slidersConfig is defined as a bit-field member,
// so let's take the next field and subtract 1
//
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
data -= offsetof(RadioData, potsConfig) - 1;
// Please note:
// slidersConfig is defined as a bit-field member,
// so let's take the next field and subtract 1
//
data -= (idx + 4 /* bitsize previous field (auxSerialMode) */ + 1) / 8;
data -= offsetof(RadioData, potsConfig) - 1;
#else
data -= (idx + 1) / 8;
data -= offsetof(RadioData, slidersConfig);
data -= (idx + 1) / 8;
data -= offsetof(RadioData, slidersConfig);
#endif
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS + STORAGE_NUM_POTS;
const char* str = rd->anaNames[idx];
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
RadioData* rd = reinterpret_cast<RadioData*>(data);
idx += NUM_STICKS + STORAGE_NUM_POTS;
const char* str = rd->anaNames[idx];
return wf(opaque, str, strnlen(str, LEN_ANA_NAME));
}
static const struct YamlIdStr enum_SliderConfig[] = {
@@ -514,19 +552,19 @@ static bool w_swtchSrc(const YamlNode* node, uint32_t val, yaml_writer_func wf,
return wf(opaque, str, strlen(str));
}
static bool cfn_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx)
static bool cfn_is_active(void* user, uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
return ((CustomFunctionData*)data)->swtch;
}
static bool gvar_is_active(uint8_t* data, uint32_t bitoffs, uint16_t idx)
static bool gvar_is_active(void* user, 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, uint16_t idx)
static bool fmd_is_active(void* user, uint8_t* data, uint32_t bitoffs)
{
uint32_t data_ofs = bitoffs >> 3UL;
if (data_ofs == offsetof(ModelData, flightModeData)) {
@@ -727,3 +765,27 @@ static bool w_trainerMode(const YamlNode* node, uint32_t val,
return true;
}
#if !defined(COLORLCD)
static uint8_t select_tele_screen_data(void* user, uint8_t* data, uint32_t bitoffs)
{
auto tw = reinterpret_cast<YamlTreeWalker*>(user);
uint16_t idx = tw->getElmts(2);
auto md = reinterpret_cast<ModelData*>(data);
uint8_t st = (md->screensType >> (2 * idx)) & 0x03;
switch(st){
case TELEMETRY_SCREEN_TYPE_NONE:
break;
case TELEMETRY_SCREEN_TYPE_VALUES:
return 1; // lines
case TELEMETRY_SCREEN_TYPE_BARS:
return 0; // bars
case TELEMETRY_SCREEN_TYPE_SCRIPT:
return 2;
}
TRACE("select_tele_screen_data(idx=%d)", idx);
return 0;
}
#endif
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -751,7 +751,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -764,7 +764,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -803,7 +803,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -736,7 +736,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -746,7 +746,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -743,7 +743,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
@@ -747,7 +747,7 @@ static const struct YamlNode union_TelemetryScreenData_elmts[] = {
};
static const struct YamlNode union_TelemetryScreenData[] = {
YAML_IDX,
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, NULL),
YAML_UNION("u", 192, union_TelemetryScreenData_elmts, select_tele_screen_data),
YAML_END
};
static const struct YamlNode struct_ModelData[] = {
+47 -44
View File
@@ -53,59 +53,62 @@ 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, uint16_t idx);
typedef bool (*is_active_func)(void* user, uint8_t* data, uint32_t bitoffs);
typedef uint32_t (*cust_to_uint_func)(const YamlNode* node, const char* val, uint8_t val_len);
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);
typedef void (*cust_read_func)(const YamlNode* node, uint8_t* data,
uint32_t bitoffs, uint16_t idx,
const char* val, uint8_t val_len);
typedef bool (*cust_write_func)(const YamlNode* node, uint8_t* data,
uint32_t bitoffs, uint16_t idx,
typedef bool (*uint_to_cust_func)(const YamlNode* node, uint32_t val,
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;
typedef uint8_t (*select_member_func)(void* user, uint8_t* data,
uint32_t bitoffs);
struct {
const YamlIdStr* choices;
} _enum;
typedef uint32_t (*cust_idx_read_func)(void* user, const char* val,
uint8_t val_len);
typedef bool (*cust_idx_write_func)(void* user, yaml_writer_func wf,
void* opaque);
struct {
cust_to_uint_func cust_to_uint;
uint_to_cust_func uint_to_cust;
} _cust;
typedef void (*cust_read_func)(void* user, uint8_t* data, uint32_t bitoffs,
const char* val, uint8_t val_len);
typedef bool (*cust_write_func)(void* user, uint8_t* data, uint32_t bitoffs,
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 {
cust_idx_read_func read;
cust_idx_write_func write;
} _cust_idx;
is_active_func is_active;
uint16_t elmts; // maximum number of elements
} _a;
select_member_func select_member;
} u;
} _array;
struct {
cust_read_func read;
cust_write_func write;
} _cust_attr;
} u;
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;
struct {
cust_read_func read;
cust_write_func write;
} _cust_attr;
} u;
};
#if !defined(_MSC_VER)
+76 -81
View File
@@ -49,24 +49,25 @@ uint32_t yaml_parse_enum(const struct YamlIdStr* choices, const char* val, uint8
return choices->id;
}
static void yaml_set_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node,
uint16_t idx, const char* val, uint8_t val_len)
static void yaml_set_attr(void* user, uint8_t* ptr, uint32_t bit_ofs,
const YamlNode* node, const char* val,
uint8_t val_len)
{
uint32_t i = 0;
uint32_t i = 0;
//TRACE("set(%s, %.*s, bit-ofs=%u, bits=%u)\n",
// node->tag, val_len, val, bit_ofs, node->size);
// 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;
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;
}
if (node->type == YDT_STRING) {
// assert(!bit_ofs);
copy_string((char*)ptr, val, MIN(val_len, node->size - 1));
return;
}
switch(node->type) {
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);
@@ -80,7 +81,7 @@ static void yaml_set_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node,
break;
case YDT_CUSTOM:
if (node->u._cust_attr.read)
node->u._cust_attr.read(node, ptr, bit_ofs, idx, val, val_len);
node->u._cust_attr.read(user, ptr, bit_ofs, val, val_len);
return;
default:
break;
@@ -130,71 +131,64 @@ static bool yaml_output_string(const char* str, uint32_t max_len,
return true;
}
static bool yaml_output_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node,
uint16_t idx, yaml_writer_func wf, void* opaque)
static bool yaml_output_attr(void* user, uint8_t* ptr, uint32_t bit_ofs,
const YamlNode* node, yaml_writer_func wf,
void* opaque)
{
if (node->type == YDT_NONE)
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;
if (node->type == YDT_PADDING)
return true;
// output tag
if (!wf(opaque, node->tag, node->tag_len))
} else if (node->type == YDT_CUSTOM) {
if (node->u._cust_attr.write &&
!node->u._cust_attr.write(user, ptr, bit_ofs, wf, opaque))
return false;
} else {
unsigned int i = yaml_get_bits(ptr, bit_ofs, node->size);
if (!wf(opaque, ": ", 2))
return false;
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;
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;
case YDT_ARRAY:
case YDT_UNION:
default:
break;
}
else if (node->type == YDT_CUSTOM) {
if (node->u._cust_attr.write
&& !node->u._cust_attr.write(node, ptr, bit_ofs, idx, 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);
if (p_out && !wf(opaque, p_out, strlen(p_out))) return false;
}
return wf(opaque, "\r\n", 2);
}
YamlTreeWalker::YamlTreeWalker()
@@ -389,7 +383,7 @@ bool YamlTreeWalker::isElmtEmpty(uint8_t* data)
// 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, getElmts());
return !node->u._array.u._a.is_active(this, data, bit_ofs);
return yaml_is_zero(data, bit_ofs, node->size);
}
@@ -452,7 +446,7 @@ void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
uint32_t i = 0;
if (attr->u._cust_idx.read)
i = attr->u._cust_idx.read(buf, len);
i = attr->u._cust_idx.read(this, buf, len);
else
i = yaml_str2uint(buf, len);
@@ -465,7 +459,7 @@ void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
}
}
else {
yaml_set_attr(data, getBitOffset(), attr, getParentElmts(), buf, len);
yaml_set_attr(this, data, getBitOffset(), attr, buf, len);
}
}
@@ -533,19 +527,20 @@ bool YamlTreeWalker::generate(yaml_writer_func wf, void* opaque)
for(int i=2; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!yaml_output_attr(NULL, 0, node, 0, wf, opaque))
if (!yaml_output_attr(this, 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);
uint8_t idx =
node->u._array.u.select_member(this, 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, 0, wf, opaque))
if (!yaml_output_attr(this, data, getBitOffset(), attr, wf, opaque))
return false; // TODO: error handling???
if (attr->type != YDT_ARRAY
@@ -578,7 +573,7 @@ bool YamlTreeWalker::generate(yaml_writer_func wf, void* opaque)
for(int i=2; i < getLevel(); i++)
if (!wf(opaque, " ", 3))
return false;
if (!yaml_output_attr(NULL, 0, getNode(),0, wf, opaque))
if (!yaml_output_attr(this, NULL, 0, getNode(), wf, opaque))
return false; // TODO: error handling???
continue;
}
@@ -600,7 +595,7 @@ bool YamlTreeWalker::generate(yaml_writer_func wf, void* opaque)
return false;
if (attr->u._cust_idx.write) {
if (!attr->u._cust_idx.write(getElmts(),wf,opaque))
if (!attr->u._cust_idx.write(this,wf,opaque))
return false;
}
else {
@@ -633,7 +628,7 @@ bool YamlTreeWalker::generate(yaml_writer_func wf, void* opaque)
if (!wf(opaque, " ", 3))
return false;
if (!yaml_output_attr(data, getBitOffset(), attr, getParentElmts(), wf, opaque))
if (!yaml_output_attr(this, data, getBitOffset(), attr, wf, opaque))
return false; // TODO: error handling???
}
+4 -6
View File
@@ -132,14 +132,12 @@ public:
return NULL;
}
uint16_t getElmts() {
return stack[stack_level].elmts;
uint16_t getElmts(uint8_t lvl = 0) {
if (stack_level + lvl >= NODE_STACK_DEPTH)
return 0;
return stack[stack_level + lvl].elmts;
}
uint16_t getParentElmts() {
return empty() ? 0 : stack[stack_level + 1].elmts;
}
// Increment the cursor until a match is found or the end of
// the current collection (node of type YDT_NONE) is reached.
//