Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/development/msp/format.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
**reply**: null or dict of data received\
**variable_len**: Optional boolean, if true, message does not have a predefined fixed length and needs appropriate handling\
**variants**: Optional special case, message has different cases of reply/request. Key/description is not a strict expression or code; just a readable condition\
**not_implemented**: Optional special case, message is not implemented\
**not_implemented**: Optional special case, message is not implemented (never or deprecated)\
**notes**: String with details of message

## Data dict fields:
Expand Down
5 changes: 4 additions & 1 deletion docs/development/msp/gen_enum_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def is_plain_int_literal(expr: str) -> Optional[int]:

# ---------- Parsing regexes ----------

RE_ENUM_START = re.compile(r'^\s*typedef\s+enum\s*\{')
RE_ENUM_START = re.compile(r'^\s*typedef\s+enum(?:\s+[A-Za-z_]\w*)?\s*\{')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Update the RE_ENUM_START regex to optionally match __attribute__((packed)) to correctly parse packed enums. [possible issue, importance: 6]

Suggested change
RE_ENUM_START = re.compile(r'^\s*typedef\s+enum(?:\s+[A-Za-z_]\w*)?\s*\{')
RE_ENUM_START = re.compile(r'^\s*typedef\s+enum(?:\s+[A-Za-z_]\w*)?(?:\s+__attribute__\(\([\w\s,\(\)]+\)\))?\s*\{')

RE_ENUM_END = re.compile(r'^\s*\}\s*([A-Za-z_]\w*)\s*;')
RE_LINE_COMMENT = re.compile(r'^\s*//\s*(.+?)\s*$')

Expand Down Expand Up @@ -273,6 +273,9 @@ def render_markdown(enums: List[EnumDef]) -> str:
cond = it.cond
out.append(f"| {name_md} | {val} | {cond} |")
jsonfile[e.name][name_md.strip('`')] = [val, cond] if len(cond)>0 else val
# normalize source to a stable inav/src/... path
if '_source' in jsonfile[e.name]:
jsonfile[e.name]['_source'] = jsonfile[e.name]['_source'].replace('../../../src', 'inav/src')
Comment on lines +277 to +278
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Replace the hardcoded path string replacement with a flexible regex using re.sub to normalize source paths with varying depths. [general, importance: 7]

Suggested change
if '_source' in jsonfile[e.name]:
jsonfile[e.name]['_source'] = jsonfile[e.name]['_source'].replace('../../../src', 'inav/src')
if '_source' in jsonfile[e.name]:
jsonfile[e.name]['_source'] = re.sub(r'^(?:\.\./)+src', 'inav/src', jsonfile[e.name]['_source'])

out.append("")
# While we're at it, chuck this all into a JSON file
Path("inav_enums.json").write_text(json.dumps(jsonfile,indent=4), encoding="utf-8")
Expand Down
Loading