Fix case with invalid switch, pot & slider idx name in config
This commit is contained in:
@@ -205,13 +205,17 @@ static uint8_t select_sensor_cfg(uint8_t* data, uint32_t bitoffs)
|
|||||||
|
|
||||||
static uint32_t sw_read(const char* val, uint8_t val_len)
|
static uint32_t sw_read(const char* val, uint8_t val_len)
|
||||||
{
|
{
|
||||||
return yaml_parse_enum(enum_MixSources, val, val_len) - MIXSRC_FIRST_SWITCH;
|
uint32_t sw = yaml_parse_enum(enum_MixSources, val, val_len);
|
||||||
|
if (sw >= MIXSRC_FIRST_SWITCH)
|
||||||
|
return sw - MIXSRC_FIRST_SWITCH;
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sw_write(uint32_t idx, yaml_writer_func wf, void* opaque)
|
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);
|
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SWITCH, enum_MixSources);
|
||||||
return wf(opaque, str, strlen(str));
|
return str ? wf(opaque, str, strlen(str)) : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct YamlIdStr enum_SwitchConfig[] = {
|
static const struct YamlIdStr enum_SwitchConfig[] = {
|
||||||
@@ -230,13 +234,17 @@ static const struct YamlNode struct_switchConfig[] = {
|
|||||||
|
|
||||||
static uint32_t pot_read(const char* val, uint8_t val_len)
|
static uint32_t pot_read(const char* val, uint8_t val_len)
|
||||||
{
|
{
|
||||||
return yaml_parse_enum(enum_MixSources, val, val_len) - MIXSRC_FIRST_POT;
|
uint32_t pot = yaml_parse_enum(enum_MixSources, val, val_len);
|
||||||
|
if (pot >= MIXSRC_FIRST_POT)
|
||||||
|
return pot - MIXSRC_FIRST_POT;
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool pot_write(uint32_t idx, yaml_writer_func wf, void* opaque)
|
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);
|
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_POT, enum_MixSources);
|
||||||
return wf(opaque, str, strlen(str));
|
return str ? wf(opaque, str, strlen(str)) : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct YamlIdStr enum_PotConfig[] = {
|
static const struct YamlIdStr enum_PotConfig[] = {
|
||||||
@@ -255,13 +263,17 @@ static const struct YamlNode struct_potConfig[] = {
|
|||||||
|
|
||||||
static uint32_t slider_read(const char* val, uint8_t val_len)
|
static uint32_t slider_read(const char* val, uint8_t val_len)
|
||||||
{
|
{
|
||||||
return yaml_parse_enum(enum_MixSources, val, val_len) - MIXSRC_FIRST_SLIDER;
|
uint32_t sl = yaml_parse_enum(enum_MixSources, val, val_len);
|
||||||
|
if (sl >= MIXSRC_FIRST_SLIDER)
|
||||||
|
return sl - MIXSRC_FIRST_SLIDER;
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool slider_write(uint32_t idx, yaml_writer_func wf, void* opaque)
|
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);
|
const char* str = yaml_output_enum(idx + MIXSRC_FIRST_SLIDER, enum_MixSources);
|
||||||
return wf(opaque, str, strlen(str));
|
return str ? wf(opaque, str, strlen(str)) : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct YamlIdStr enum_SliderConfig[] = {
|
static const struct YamlIdStr enum_SliderConfig[] = {
|
||||||
|
|||||||
@@ -191,7 +191,8 @@ static bool yaml_output_attr(uint8_t* ptr, uint32_t bit_ofs, const YamlNode* nod
|
|||||||
YamlTreeWalker::YamlTreeWalker()
|
YamlTreeWalker::YamlTreeWalker()
|
||||||
: stack_level(NODE_STACK_DEPTH),
|
: stack_level(NODE_STACK_DEPTH),
|
||||||
virt_level(0),
|
virt_level(0),
|
||||||
anon_union(0)
|
anon_union(0),
|
||||||
|
idx_invalid(false)
|
||||||
{
|
{
|
||||||
memset(stack,0,sizeof(stack));
|
memset(stack,0,sizeof(stack));
|
||||||
}
|
}
|
||||||
@@ -201,6 +202,7 @@ void YamlTreeWalker::reset(const YamlNode* node, uint8_t* data)
|
|||||||
this->data = data;
|
this->data = data;
|
||||||
stack_level = NODE_STACK_DEPTH;
|
stack_level = NODE_STACK_DEPTH;
|
||||||
virt_level = 0;
|
virt_level = 0;
|
||||||
|
idx_invalid = false;
|
||||||
|
|
||||||
push();
|
push();
|
||||||
setNode(node);
|
setNode(node);
|
||||||
@@ -214,6 +216,7 @@ bool YamlTreeWalker::push()
|
|||||||
|
|
||||||
stack_level--;
|
stack_level--;
|
||||||
memset(&(stack[stack_level]), 0, sizeof(State));
|
memset(&(stack[stack_level]), 0, sizeof(State));
|
||||||
|
idx_invalid = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -225,6 +228,8 @@ bool YamlTreeWalker::pop()
|
|||||||
|
|
||||||
memset(&(stack[stack_level]), 0, sizeof(State));
|
memset(&(stack[stack_level]), 0, sizeof(State));
|
||||||
stack_level++;
|
stack_level++;
|
||||||
|
idx_invalid = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,6 +326,11 @@ bool YamlTreeWalker::toNextElmt()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (idx_invalid) {
|
||||||
|
idx_invalid = false;
|
||||||
|
stack[stack_level].elmts = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (getElmts() >= node->u._array.u._a.elmts - 1)
|
if (getElmts() >= node->u._array.u._a.elmts - 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -405,7 +415,7 @@ void YamlTreeWalker::toNextAttr()
|
|||||||
|
|
||||||
void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
|
void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
|
||||||
{
|
{
|
||||||
if (!buf || !len)
|
if (!buf || !len || idx_invalid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const YamlNode* attr = getAttr();
|
const YamlNode* attr = getAttr();
|
||||||
@@ -417,7 +427,12 @@ void YamlTreeWalker::setAttrValue(char* buf, uint8_t len)
|
|||||||
else
|
else
|
||||||
i = yaml_str2uint(buf, len);
|
i = yaml_str2uint(buf, len);
|
||||||
|
|
||||||
|
//TODO: detect -1 and set idx_invalid = true
|
||||||
|
|
||||||
while ((i > getElmts()) && toNextElmt());
|
while ((i > getElmts()) && toNextElmt());
|
||||||
|
|
||||||
|
if (i > getElmts())
|
||||||
|
idx_invalid = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
yaml_set_attr(data, getBitOffset(), attr, buf, len);
|
yaml_set_attr(data, getBitOffset(), attr, buf, len);
|
||||||
@@ -622,7 +637,7 @@ static bool find_node(void* ctx, char* buf, uint8_t len)
|
|||||||
|
|
||||||
static void set_attr(void* ctx, char* buf, uint8_t len)
|
static void set_attr(void* ctx, char* buf, uint8_t len)
|
||||||
{
|
{
|
||||||
return ((YamlTreeWalker*)ctx)->setAttrValue(buf,len);
|
((YamlTreeWalker*)ctx)->setAttrValue(buf,len);
|
||||||
}
|
}
|
||||||
|
|
||||||
const YamlParserCalls YamlTreeWalkerCalls = {
|
const YamlParserCalls YamlTreeWalkerCalls = {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class YamlTreeWalker
|
|||||||
uint8_t stack_level;
|
uint8_t stack_level;
|
||||||
uint8_t virt_level;
|
uint8_t virt_level;
|
||||||
uint8_t anon_union;
|
uint8_t anon_union;
|
||||||
|
bool idx_invalid;
|
||||||
|
|
||||||
uint8_t* data;
|
uint8_t* data;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user