YAML: avoid forcing to add parser for non-existing old format v220 (#2068)

This commit is contained in:
Raphael Coeffic
2022-06-21 06:45:35 +02:00
committed by GitHub
parent 9f24e2d131
commit c2dc4e6c0b
4 changed files with 45 additions and 5 deletions
@@ -19,6 +19,8 @@
* GNU General Public License for more details.
*/
#if STORAGE_CONVERSIONS < 221
#include <cstdlib>
#include <cstring>
#include <string>
@@ -44,8 +46,6 @@ namespace yaml_conv_220 {
const YamlNode* get_partialmodel_nodes();
};
#if STORAGE_CONVERSIONS < 221
#if defined(STORAGE_MODELSLIST)
void patchFilenameToYaml(char* str);
@@ -33,6 +33,8 @@
#include "../../../timers.h"
#include "../../../pulses/multi.h"
#if STORAGE_CONVERSIONS < 221
namespace yaml_conv_220 {
#include "yaml_datastructs_funcs.cpp"
@@ -77,3 +79,11 @@ static_assert(MAX_STR > MAX_RADIODATA_MODELDATA_PARTIALMODEL_STR_LEN,
"MAX_STR > MAX_RADIODATA_MODELDATA_PARTIALMODEL_STR_LEN");
};
#else
namespace yaml_conv_220 {
#include "yaml_datastructs_funcs.cpp"
};
#endif // STORAGE_CONVERSIONS
@@ -66,6 +66,7 @@ bool output_source_1_param(const char* src_prefix, size_t src_len, uint32_t n,
return true;
}
#if STORAGE_CONVERSIONS < 221
bool w_mixSrcRaw(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
const char* str = nullptr;
@@ -149,6 +150,7 @@ bool w_mixSrcRaw(const YamlNode* node, uint32_t val, yaml_writer_func wf, void*
return true;
}
#endif
#define r_vbat_min nullptr
@@ -204,6 +206,7 @@ bool w_zov_color(void* user, uint8_t* data, uint32_t bitoffs,
}
#endif
#if STORAGE_CONVERSIONS < 221
static uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs)
{
data += bitoffs >> 3UL;
@@ -239,6 +242,7 @@ static uint8_t select_mod_type(void* user, uint8_t* data, uint32_t bitoffs)
}
return 0;
}
#endif
uint8_t select_script_input(void* user, uint8_t* data, uint32_t bitoffs)
{
@@ -293,6 +297,7 @@ uint8_t select_sensor_cfg(void* user, uint8_t* data, uint32_t bitoffs)
return 5;
}
#if STORAGE_CONVERSIONS < 221
#define r_calib nullptr
static bool w_calib(void* user, yaml_writer_func wf, void* opaque)
@@ -361,7 +366,8 @@ bool sw_name_write(void* user, uint8_t* data, uint32_t bitoffs,
return false;
return wf(opaque, "\"", 1);
}
#endif
extern const struct YamlIdStr enum_SwitchConfig[];
const struct YamlIdStr enum_SwitchConfig[] = {
{ SWITCH_NONE, "none" },
@@ -371,6 +377,7 @@ const struct YamlIdStr enum_SwitchConfig[] = {
{ 0, NULL }
};
#if STORAGE_CONVERSIONS < 221
static const struct YamlNode struct_switchConfig[] = {
YAML_IDX_CUST( "sw", nullptr, sw_write ),
YAML_ENUM( "type", 2, enum_SwitchConfig),
@@ -536,6 +543,7 @@ static bool w_swtchSrc(const YamlNode* node, uint32_t val, yaml_writer_func wf,
return false;
return true;
}
#endif
bool cfn_is_active(void* user, uint8_t* data, uint32_t bitoffs)
{
@@ -677,6 +685,7 @@ bool w_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
}
#endif
#if STORAGE_CONVERSIONS < 221
extern const struct YamlIdStr enum_BeeperMode[];
#define r_beeperMode nullptr
@@ -687,6 +696,7 @@ bool w_beeperMode(const YamlNode* node, uint32_t val, yaml_writer_func wf, void*
const char* str = yaml_output_enum(sval, enum_BeeperMode);
return wf(opaque, str, strlen(str));
}
#endif
#define r_5pos nullptr
@@ -744,6 +754,7 @@ const struct YamlIdStr enum_TrainerMode[] = {
#define r_trainerMode nullptr
#if STORAGE_CONVERSIONS < 221
static bool w_trainerMode(const YamlNode* node, uint32_t val,
yaml_writer_func wf, void* opaque)
{
@@ -756,6 +767,7 @@ static bool w_trainerMode(const YamlNode* node, uint32_t val,
return true;
}
#endif
#if !defined(COLORLCD)
#define r_tele_screen_type nullptr
@@ -856,6 +868,7 @@ const char* _adjust_gvar_mode_lookup[] = {
};
extern const uint8_t _adjust_gvar_mode_lookup_size = 4;
#if STORAGE_CONVERSIONS < 221
bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs,
yaml_writer_func wf, void* opaque)
{
@@ -1078,6 +1091,7 @@ bool w_thrSrc(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opa
auto src = throttleSource2Source(val);
return w_mixSrcRaw(nullptr, src, wf, opaque);
}
#endif
// Force external linkage
extern const struct YamlIdStr enum_XJT_Subtypes[];
@@ -52,7 +52,6 @@ namespace yaml_conv_220 {
bool fmd_is_active(void* user, uint8_t* data, uint32_t bitoffs);
bool swash_is_active(void* user, uint8_t* data, uint32_t bitoffs);
bool w_beeperMode(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque);
bool w_5pos(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque);
bool w_vol(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque);
bool w_spPitch(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque);
@@ -998,7 +997,9 @@ static uint32_t r_beeperMode(const YamlNode* node, const char* val, uint8_t val_
static bool w_beeperMode(const YamlNode* node, uint32_t val, yaml_writer_func wf, void* opaque)
{
return yaml_conv_220::w_beeperMode(node, val, wf, opaque);
int32_t sval = yaml_to_signed(val,node->size);
const char* str = yaml_output_enum(sval, enum_BeeperMode);
return wf(opaque, str, strlen(str));
}
static uint32_t r_5pos(const YamlNode* node, const char* val, uint8_t val_len)
@@ -1821,6 +1822,17 @@ static const struct YamlIdStr enum_SerialPort[] = {
{ 0, NULL }
};
#if STORAGE_CONVERSIONS >= 221
const struct YamlIdStr _old_enum_UartModes[] = {
{ UART_MODE_NONE, "MODE_NONE" },
{ UART_MODE_TELEMETRY_MIRROR, "MODE_TELEMETRY_MIRROR" },
{ UART_MODE_TELEMETRY, "MODE_TELEMETRY" },
{ UART_MODE_SBUS_TRAINER, "MODE_SBUS_TRAINER" },
{ UART_MODE_LUA, "MODE_LUA" },
{ 0, NULL }
};
#endif
static const struct YamlIdStr enum_UartModes[] = {
{ UART_MODE_NONE, "NONE" },
{ UART_MODE_TELEMETRY_MIRROR, "TELEMETRY_MIRROR" },
@@ -1875,7 +1887,11 @@ static void r_serialMode(void* user, uint8_t* data, uint32_t bitoffs,
else
return;
#if STORAGE_CONVERSIONS < 221
auto m = yaml_parse_enum(yaml_conv_220::enum_UartModes, val, val_len);
#else
auto m = yaml_parse_enum(_old_enum_UartModes, val, val_len);
#endif
if (!m) return;
auto serialPort = reinterpret_cast<uint32_t*>(data);