From 21bf580f9a5ed942f9e23785cd63b634f4c0e61c Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 11 Oct 2021 12:01:39 +0200 Subject: [PATCH] Merge switches / pots / sliders names into their config struct --- radio/src/datastructs.h | 8 +- .../storage/yaml/yaml_datastructs_funcs.cpp | 76 +++++++++++++++++++ .../storage/yaml/yaml_datastructs_nv14.cpp | 4 +- .../src/storage/yaml/yaml_datastructs_t12.cpp | 5 +- .../src/storage/yaml/yaml_datastructs_t8.cpp | 5 +- .../storage/yaml/yaml_datastructs_tlite.cpp | 5 +- .../storage/yaml/yaml_datastructs_tx12.cpp | 5 +- .../src/storage/yaml/yaml_datastructs_x10.cpp | 4 +- .../storage/yaml/yaml_datastructs_x12s.cpp | 4 +- .../src/storage/yaml/yaml_datastructs_x7.cpp | 5 +- .../src/storage/yaml/yaml_datastructs_x9d.cpp | 5 +- .../src/storage/yaml/yaml_datastructs_x9e.cpp | 5 +- .../storage/yaml/yaml_datastructs_x9lite.cpp | 5 +- .../storage/yaml/yaml_datastructs_x9lites.cpp | 5 +- .../storage/yaml/yaml_datastructs_xlite.cpp | 5 +- .../storage/yaml/yaml_datastructs_xlites.cpp | 5 +- radio/src/storage/yaml/yaml_node.h | 20 ++++- radio/src/storage/yaml/yaml_tree_walker.cpp | 23 ++++-- 18 files changed, 142 insertions(+), 52 deletions(-) diff --git a/radio/src/datastructs.h b/radio/src/datastructs.h index 21304de7e..d8be59c27 100644 --- a/radio/src/datastructs.h +++ b/radio/src/datastructs.h @@ -753,8 +753,8 @@ PACK(struct TrainerData { swconfig_t switchConfig ARRAY(2,struct_switchConfig,nullptr); \ uint16_t potsConfig ARRAY(2,struct_potConfig,nullptr); /* two bits per pot */ \ uint8_t slidersConfig ARRAY(1,struct_sliderConfig,nullptr); /* 1 bit per slider */ \ - NOBACKUP(char switchNames[STORAGE_NUM_SWITCHES][LEN_SWITCH_NAME]); \ - NOBACKUP(char anaNames[NUM_STICKS + STORAGE_NUM_POTS + STORAGE_NUM_SLIDERS][LEN_ANA_NAME]); \ + NOBACKUP(char switchNames[STORAGE_NUM_SWITCHES][LEN_SWITCH_NAME] SKIP); \ + NOBACKUP(char anaNames[NUM_STICKS + STORAGE_NUM_POTS + STORAGE_NUM_SLIDERS][LEN_ANA_NAME] SKIP); \ NOBACKUP(char currModelFilename[LEN_MODEL_FILENAME+1]); \ NOBACKUP(uint8_t spare5:1 SKIP); \ NOBACKUP(uint8_t blOffBright:7); \ @@ -774,8 +774,8 @@ PACK(struct TrainerData { uint8_t backlightColor; \ swarnstate_t switchUnlockStates; \ swconfig_t switchConfig ARRAY(2,struct_switchConfig,nullptr); \ - char switchNames[STORAGE_NUM_SWITCHES][LEN_SWITCH_NAME]; \ - char anaNames[NUM_STICKS+STORAGE_NUM_POTS+STORAGE_NUM_SLIDERS][LEN_ANA_NAME]; \ + char switchNames[STORAGE_NUM_SWITCHES][LEN_SWITCH_NAME] SKIP; \ + char anaNames[NUM_STICKS+STORAGE_NUM_POTS+STORAGE_NUM_SLIDERS][LEN_ANA_NAME] SKIP; \ BLUETOOTH_FIELDS #else #define EXTRA_GENERAL_FIELDS diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 0b81420e0..ee519d667 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -218,6 +218,29 @@ static bool sw_write(uint32_t idx, yaml_writer_func wf, void* opaque) return str ? wf(opaque, str, strlen(str)) : true; } +static void sw_name_read(const YamlNode* node, uint8_t* data, uint32_t bitoffs, + uint16_t idx, const char* val, uint8_t val_len) +{ + // data / bitoffs already incremented + data -= ((idx + 1) * 2) / 8; + data -= offsetof(RadioData, switchConfig); + + RadioData* rd = reinterpret_cast(data); + strncpy(rd->switchNames[idx], val, std::min(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) +{ + // data / bitoffs already incremented + data -= ((idx + 1) * 2) / 8; + data -= offsetof(RadioData, switchConfig); + + RadioData* rd = reinterpret_cast(data); + const char* str = rd->switchNames[idx]; + return wf(opaque, str, strnlen(str, LEN_SWITCH_NAME)); +} + static const struct YamlIdStr enum_SwitchConfig[] = { { SWITCH_NONE, "none" }, { SWITCH_TOGGLE, "toggle" }, @@ -229,6 +252,7 @@ static const struct YamlIdStr enum_SwitchConfig[] = { static const struct YamlNode struct_switchConfig[] = { 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 }; @@ -247,6 +271,31 @@ static bool pot_write(uint32_t idx, yaml_writer_func wf, void* opaque) 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) +{ + // data / bitoffs already incremented + data -= ((idx + 1) * 2) / 8; + data -= offsetof(RadioData, potsConfig); + + RadioData* rd = reinterpret_cast(data); + idx += NUM_STICKS; + strncpy(rd->anaNames[idx], val, std::min(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) +{ + // data / bitoffs already incremented + data -= ((idx + 1) * 2) / 8; + data -= offsetof(RadioData, potsConfig); + + RadioData* rd = reinterpret_cast(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[] = { { POT_NONE, "none" }, { POT_WITH_DETENT, "with_detent" }, @@ -258,6 +307,7 @@ static const struct YamlIdStr enum_PotConfig[] = { static const struct YamlNode struct_potConfig[] = { YAML_IDX_CUST( "pot", pot_read, pot_write ), YAML_ENUM( "type", 2, enum_PotConfig), + YAML_CUSTOM( "name", pot_name_read, pot_name_write), YAML_END }; @@ -276,6 +326,31 @@ static bool slider_write(uint32_t idx, yaml_writer_func wf, void* opaque) 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) +{ + // data / bitoffs already incremented + data -= (idx + 1) / 8; + data -= offsetof(RadioData, slidersConfig); + + RadioData* rd = reinterpret_cast(data); + idx += NUM_STICKS + STORAGE_NUM_POTS; + strncpy(rd->anaNames[idx], val, std::min(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) +{ + // data / bitoffs already incremented + data -= (idx + 1) / 8; + data -= offsetof(RadioData, slidersConfig); + + RadioData* rd = reinterpret_cast(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[] = { { SLIDER_NONE, "none" }, { SLIDER_WITH_DETENT, "with_detent" }, @@ -285,6 +360,7 @@ static const struct YamlIdStr enum_SliderConfig[] = { static const struct YamlNode struct_sliderConfig[] = { YAML_IDX_CUST( "sl", slider_read, slider_write ), YAML_ENUM( "type", 1, enum_SliderConfig), + YAML_CUSTOM( "name", sl_name_read, sl_name_write), YAML_END }; diff --git a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp index a391ad232..65f9ac6c2 100644 --- a/radio/src/storage/yaml/yaml_datastructs_nv14.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_nv14.cpp @@ -371,8 +371,8 @@ static const struct YamlNode struct_RadioData[] = { 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, 8, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 9, struct_string_24, NULL), + YAML_PADDING( 192 ), + YAML_PADDING( 216 ), YAML_STRING("currModelFilename", 17), YAML_PADDING( 1 ), YAML_UNSIGNED( "blOffBright", 7 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_t12.cpp b/radio/src/storage/yaml/yaml_datastructs_t12.cpp index bb99cd833..61595d01f 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t12.cpp @@ -346,13 +346,12 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 8, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 6, struct_string_24, NULL), + YAML_PADDING( 192 ), + YAML_PADDING( 144 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_t8.cpp b/radio/src/storage/yaml/yaml_datastructs_t8.cpp index bb99cd833..61595d01f 100644 --- a/radio/src/storage/yaml/yaml_datastructs_t8.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_t8.cpp @@ -346,13 +346,12 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 8, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 6, struct_string_24, NULL), + YAML_PADDING( 192 ), + YAML_PADDING( 144 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp index bb99cd833..61595d01f 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tlite.cpp @@ -346,13 +346,12 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 8, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 6, struct_string_24, NULL), + YAML_PADDING( 192 ), + YAML_PADDING( 144 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp index 29ed5ef37..ce6681667 100644 --- a/radio/src/storage/yaml/yaml_datastructs_tx12.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_tx12.cpp @@ -346,13 +346,12 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 8, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 6, struct_string_24, NULL), + YAML_PADDING( 192 ), + YAML_PADDING( 144 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x10.cpp b/radio/src/storage/yaml/yaml_datastructs_x10.cpp index a65a97de0..a000d62c4 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x10.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x10.cpp @@ -388,8 +388,8 @@ static const struct YamlNode struct_RadioData[] = { 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_PADDING( 240 ), + YAML_PADDING( 312 ), YAML_STRING("currModelFilename", 17), YAML_PADDING( 1 ), YAML_UNSIGNED( "blOffBright", 7 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp index 1e4703333..9c8838449 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x12s.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x12s.cpp @@ -388,8 +388,8 @@ static const struct YamlNode struct_RadioData[] = { 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_PADDING( 240 ), + YAML_PADDING( 312 ), YAML_STRING("currModelFilename", 17), YAML_PADDING( 1 ), YAML_UNSIGNED( "blOffBright", 7 ), diff --git a/radio/src/storage/yaml/yaml_datastructs_x7.cpp b/radio/src/storage/yaml/yaml_datastructs_x7.cpp index bb99cd833..61595d01f 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x7.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x7.cpp @@ -346,13 +346,12 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 8, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 6, struct_string_24, NULL), + YAML_PADDING( 192 ), + YAML_PADDING( 144 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp index 4534d0548..03ca4ed08 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9d.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9d.cpp @@ -353,13 +353,12 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 32 ), YAML_ARRAY("switchConfig", 2, 16, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 9, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 9, struct_string_24, NULL), + YAML_PADDING( 216 ), + YAML_PADDING( 216 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp index b219622d6..d136d89e7 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9e.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9e.cpp @@ -392,13 +392,12 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 64 ), YAML_ARRAY("switchConfig", 2, 32, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 18, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 12, struct_string_24, NULL), + YAML_PADDING( 432 ), + YAML_PADDING( 288 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp index 7acb1cc7c..b13641645 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lite.cpp @@ -333,11 +333,10 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 5, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 5, struct_string_24, NULL), + YAML_PADDING( 120 ), + YAML_PADDING( 120 ), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp index 95ca3f117..717db955e 100644 --- a/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_x9lites.cpp @@ -341,13 +341,12 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 7, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 5, struct_string_24, NULL), + YAML_PADDING( 168 ), + YAML_PADDING( 120 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp index eb75a1fee..28ea3132b 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlite.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlite.cpp @@ -338,13 +338,12 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 6, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 6, struct_string_24, NULL), + YAML_PADDING( 144 ), + YAML_PADDING( 144 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp index 4df9eb39c..707f14360 100644 --- a/radio/src/storage/yaml/yaml_datastructs_xlites.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_xlites.cpp @@ -340,15 +340,14 @@ static const struct YamlNode struct_RadioData[] = { YAML_UNSIGNED( "backlightColor", 8 ), YAML_UNSIGNED( "switchUnlockStates", 16 ), YAML_ARRAY("switchConfig", 2, 8, struct_switchConfig, nullptr), - YAML_ARRAY("switchNames", 24, 6, struct_string_24, NULL), - YAML_ARRAY("anaNames", 24, 6, struct_string_24, NULL), + YAML_PADDING( 144 ), + YAML_PADDING( 144 ), YAML_PADDING( 8 ), YAML_STRING("bluetoothName", 10), YAML_STRING("ownerRegistrationID", 8), YAML_SIGNED( "gyroMax", 8 ), YAML_SIGNED( "gyroOffset", 8 ), YAML_SIGNED( "uartSampleMode", 2 ), - YAML_STRING("currModelFilename", 17), YAML_END }; static const struct YamlNode struct_unsigned_8[] = { diff --git a/radio/src/storage/yaml/yaml_node.h b/radio/src/storage/yaml/yaml_node.h index b2dc1f790..9584a1a91 100644 --- a/radio/src/storage/yaml/yaml_node.h +++ b/radio/src/storage/yaml/yaml_node.h @@ -38,7 +38,8 @@ enum YamlDataType { YDT_ARRAY, YDT_ENUM, YDT_UNION, - YDT_PADDING + YDT_PADDING, + YDT_CUSTOM }; struct YamlIdStr @@ -62,7 +63,14 @@ struct YamlNode 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, + yaml_writer_func wf, void* opaque); + uint8_t type; uint32_t size; // bits uint8_t tag_len; @@ -92,6 +100,11 @@ struct YamlNode cust_idx_read_func read; cust_idx_write_func write; } _cust_idx; + + struct { + cust_read_func read; + cust_write_func write; + } _cust_attr; } u; }; @@ -135,6 +148,9 @@ struct YamlNode #define YAML_PADDING(bits) \ { .type=YDT_PADDING, .size=(bits) } +#define YAML_CUSTOM(tag, f_read, f_write) \ + { .type=YDT_CUSTOM, .size=0, YAML_TAG(tag), .u={._cust_attr={.read=(f_read), .write=(f_write) }} } + #define YAML_END \ { .type=YDT_NONE } diff --git a/radio/src/storage/yaml/yaml_tree_walker.cpp b/radio/src/storage/yaml/yaml_tree_walker.cpp index 9b4c3cf90..0edd4ea61 100644 --- a/radio/src/storage/yaml/yaml_tree_walker.cpp +++ b/radio/src/storage/yaml/yaml_tree_walker.cpp @@ -50,7 +50,7 @@ uint32_t yaml_parse_enum(const struct YamlIdStr* choices, const char* val, uint8 } static void yaml_set_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node, - const char* val, uint8_t val_len) + uint16_t idx, const char* val, uint8_t val_len) { uint32_t i = 0; @@ -78,6 +78,10 @@ static void yaml_set_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node, case YDT_ENUM: i = yaml_parse_enum(node->u._enum.choices, val, val_len); break; + case YDT_CUSTOM: + if (node->u._cust_attr.read) + node->u._cust_attr.read(node, ptr, bit_ofs, idx, val, val_len); + return; default: break; } @@ -127,7 +131,7 @@ static bool yaml_output_string(const char* str, uint32_t max_len, } static bool yaml_output_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* node, - yaml_writer_func wf, void* opaque) + uint16_t idx, yaml_writer_func wf, void* opaque) { if (node->type == YDT_NONE) return false; @@ -153,6 +157,11 @@ static bool yaml_output_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* nod if (!yaml_output_string((const char*)ptr, (node->size)>>3UL, wf, opaque)) return false; } + 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); @@ -435,7 +444,7 @@ void YamlTreeWalker::setAttrValue(char* buf, uint8_t len) idx_invalid = true; } else { - yaml_set_attr(data, getBitOffset(), attr, buf, len); + yaml_set_attr(data, getBitOffset(), attr, getElmts(), buf, len); //walker.dump_stack(); } } @@ -500,7 +509,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, node, wf, opaque)) + if (!yaml_output_attr(NULL, 0, node, getElmts(), wf, opaque)) return false; // TODO: error handling??? // grab attr idx... @@ -512,7 +521,7 @@ bool YamlTreeWalker::generate(yaml_writer_func wf, void* opaque) for(int i=1; i < getLevel(); i++) if (!wf(opaque, " ", 3)) return false; - if (!yaml_output_attr(data, getBitOffset(), attr, wf, opaque)) + if (!yaml_output_attr(data, getBitOffset(), attr, getElmts(), wf, opaque)) return false; // TODO: error handling??? if (attr->type != YDT_ARRAY @@ -545,7 +554,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(), wf, opaque)) + if (!yaml_output_attr(NULL, 0, getNode(), getElmts(), wf, opaque)) return false; // TODO: error handling??? continue; } @@ -596,7 +605,7 @@ bool YamlTreeWalker::generate(yaml_writer_func wf, void* opaque) if (!wf(opaque, "\r\n", 2)) return false; } - else if (!yaml_output_attr(data, getBitOffset(), attr, wf, opaque)) + else if (!yaml_output_attr(data, getBitOffset(), attr, getElmts(), wf, opaque)) return false; // TODO: error handling??? toNextAttr();