Skip to content

Commit 498797e

Browse files
PCrnjakclaude
andcommitted
sync tool: a case is cut at its own break, and the gripper's answer function is recognised
The gripper command's handler has a break inside a loop, which cut the extracted case short: its empty (0-byte) form and its answer, Respond_Gripper_data_pack, were missing from the generated reference. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 8cbd68a commit 498797e

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎docs/includes/generated/firmware_facts.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@
6363
"IN_GRIPPER_DATA_PACK": {
6464
"empty": false,
6565
"lengths": [
66+
0,
6667
5
6768
],
68-
"responds": []
69+
"responds": [
70+
"Gripper_pack_data"
71+
]
6972
},
7073
"IN_IDLE": {
7174
"empty": false,

‎tools/sync_firmware.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def uart_handlers(communication_cpp: str) -> list[dict]:
122122
DEFINE = re.compile(r"^#define[ \t]+((?:IN_|OUT_|OUT_IN_)[A-Z0-9_]+|HEARTBEAT_SETUP)[ \t]+(\d+)[ \t]*(?://[ \t]*(.*))?$", re.M)
123123
CASE = re.compile(r"case\s+([A-Z0-9_]+)\s*:")
124124
LEN = re.compile(r"CAN_RX_msg\.len\s*==\s*(\d+)")
125-
RESPONSE_FN = re.compile(r"\b([A-Z][A-Za-z_0-9]*(?:_CAN|_response|_pack))\(\)\s*;")
125+
RESPONSE_FN = re.compile(r"\b([A-Z][A-Za-z_0-9]*(?:_CAN|_response|_pack|_pack_data))\(\)\s*;")
126126
TX_FN = re.compile(r"^void\s+(\w+)\s*\(\s*\)\s*\{", re.M)
127127
TX_LEN = re.compile(r"CAN_TX_msg\.len\s*=\s*(\d+)")
128128
TX_ID = re.compile(r"Combine_2_CAN_ID\([^,]+,\s*([A-Z0-9_]+)")
@@ -140,7 +140,12 @@ def can_handlers(communication_can_cpp: str) -> dict[str, dict]:
140140
for i, m in enumerate(matches):
141141
end = matches[i + 1].start() if i + 1 < len(matches) else len(text)
142142
block = text[m.start():end]
143-
body = block.split("break;")[0]
143+
# up to the case's own `break;`: the first one that is not inside a loop or an if of the handler
144+
body = block
145+
for bm in re.finditer(r"break;", block):
146+
if block[:bm.start()].count("{") - block[:bm.start()].count("}") <= 1:
147+
body = block[:bm.start()]
148+
break
144149
out[m.group(1)] = {"lengths": sorted({int(x) for x in LEN.findall(body)}),
145150
"responds": list(dict.fromkeys(RESPONSE_FN.findall(body))),
146151
"empty": body.strip().count("\n") <= 1}

0 commit comments

Comments
 (0)