X9D+ conversion unit test + fixes
This commit is contained in:
@@ -465,11 +465,11 @@ bool fmd_is_active(void* user, uint8_t* data, uint32_t bitoffs)
|
||||
|
||||
// FM0 defaults to all 0
|
||||
if (idx == 0) {
|
||||
return !yaml_is_zero(data, bitoffs, sizeof(FlightModeData));
|
||||
return !yaml_is_zero(data, bitoffs, sizeof(FlightModeData) << 3UL);
|
||||
}
|
||||
|
||||
// assumes gvars array is last
|
||||
bool is_active = !yaml_is_zero(data, bitoffs, offsetof(FlightModeData, gvars));
|
||||
bool is_active = !yaml_is_zero(data, bitoffs, offsetof(FlightModeData, gvars) << 3UL);
|
||||
|
||||
data += bitoffs >> 3UL;
|
||||
FlightModeData* fmd = (FlightModeData*)(data);
|
||||
|
||||
@@ -88,9 +88,34 @@ uint32_t yaml_get_bits(uint8_t* src, uint32_t bit_ofs, uint32_t bits)
|
||||
return i;
|
||||
}
|
||||
|
||||
// if the start address is not aligned on a byte,
|
||||
// checking max 32 bits is supported.
|
||||
bool yaml_is_zero(uint8_t* data, uint32_t bitoffs, uint32_t bits)
|
||||
{
|
||||
return !yaml_get_bits(data + (bitoffs>>3UL), bitoffs & 0x7, bits);
|
||||
data += bitoffs >> 3;
|
||||
bitoffs &= 0x7;
|
||||
|
||||
if (bitoffs) {
|
||||
return !yaml_get_bits(data, bitoffs, bits);
|
||||
}
|
||||
|
||||
while (bits >= 32) {
|
||||
if (*(uint32_t*)data) return false;
|
||||
data += 4;
|
||||
bits -= 32;
|
||||
}
|
||||
|
||||
while (bits >= 8) {
|
||||
if (*data) return false;
|
||||
data++;
|
||||
bits -= 8;
|
||||
}
|
||||
|
||||
if (bits) {
|
||||
return !yaml_get_bits(data, 0, bits);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t yaml_str2int_ref(const char*& val, uint8_t& val_len)
|
||||
|
||||
@@ -29,10 +29,15 @@
|
||||
|
||||
#define MIN(a,b) (a < b ? a : b)
|
||||
|
||||
static void copy_string(char* dst, const char* src, uint8_t len)
|
||||
static void copy_string(char* dst, uint8_t dst_len, const char* src,
|
||||
uint8_t src_len)
|
||||
{
|
||||
memcpy(dst,src,len);
|
||||
dst[len] = '\0';
|
||||
if (src_len < dst_len) {
|
||||
memcpy(dst, src, src_len);
|
||||
dst[src_len] = '\0';
|
||||
} else {
|
||||
memcpy(dst, src, dst_len);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t yaml_parse_enum(const struct YamlIdStr* choices, const char* val, uint8_t val_len)
|
||||
@@ -63,7 +68,7 @@ static void yaml_set_attr(void* user, uint8_t* ptr, uint32_t bit_ofs,
|
||||
|
||||
if (node->type == YDT_STRING) {
|
||||
// assert(!bit_ofs);
|
||||
copy_string((char*)ptr, val, MIN(val_len, node->size - 1));
|
||||
copy_string((char*)ptr, node->size >> 3, val, val_len);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,7 +117,7 @@ static bool yaml_output_string(const char* str, uint32_t max_len,
|
||||
if (!wf(opaque, "\"", 1))
|
||||
return false;
|
||||
|
||||
while(*str && max_len > 0) {
|
||||
while(max_len > 0 && *str) {
|
||||
if (*str >= 0x20 && *str <= 0x7E) {
|
||||
if (!wf(opaque, str++, 1)) return false;
|
||||
max_len--;
|
||||
|
||||
@@ -89,7 +89,8 @@ class YamlTreeWalker
|
||||
}
|
||||
|
||||
inline bool isParentArrayElmt() {
|
||||
return !empty() && stack[stack_level + 1].flags & FLAG_STATE_ARRAY_ELMT;
|
||||
return (stack_level + 1 < NODE_STACK_DEPTH)
|
||||
&& stack[stack_level + 1].flags & FLAG_STATE_ARRAY_ELMT;
|
||||
}
|
||||
|
||||
inline void setArrayElmt(bool set) {
|
||||
|
||||
Reference in New Issue
Block a user