feat(vesc): extend motor diagnostics, configuration and transport recovery
Add firmware and extension catalogues, configuration transactions, sample review and QML diagnostics. Preserve explicit authority, bounded retries and stop recovery in motor transport.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
"""Exact, read-only firmware configuration decoder. Never serializes a write."""
|
||||
import math
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import xml.etree.ElementTree as ET
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def crc32c(data):
|
||||
@@ -14,14 +15,25 @@ def crc32c(data):
|
||||
return value ^ 0xffffffff
|
||||
|
||||
|
||||
def decode(data, kind):
|
||||
@lru_cache(maxsize=2)
|
||||
def _schema(kind):
|
||||
"""Installed schemas are immutable for the lifetime of this process.
|
||||
|
||||
Parse/sign the definition once, not while accepting a 25 ms input RPC.
|
||||
Controller bytes and decoded results are never cached.
|
||||
"""
|
||||
code, name = {"motor": (14, "mcconf"), "application": (17, "appconf")}[kind]
|
||||
xml = ET.parse(Path(__file__).parent / "schemas/5.02" / ("parameters_" + name + ".xml")).getroot()
|
||||
params = {p.tag: p for p in xml.find("Params")}
|
||||
order = [p.text for p in xml.find("SerOrder")]
|
||||
signature = "".join(n + params[n].findtext("type", "0") + params[n].findtext("vTx", "0")
|
||||
+ "".join(x.text or "" for x in params[n].findall("enumNames")) for n in order)
|
||||
if len(data) < 5 or data[0] != code or int.from_bytes(data[1:5], "big") != crc32c(signature.encode()):
|
||||
return code, params, tuple(order), crc32c(signature.encode())
|
||||
|
||||
|
||||
def decode(data, kind):
|
||||
code, params, order, signature = _schema(kind)
|
||||
if len(data) < 5 or data[0] != code or int.from_bytes(data[1:5], "big") != signature:
|
||||
raise ValueError("Configuration signature differs from firmware 5.02 schema")
|
||||
offset, result = 5, {}
|
||||
for name in order:
|
||||
@@ -44,3 +56,9 @@ def decode(data, kind):
|
||||
result[name] = value
|
||||
if offset != len(data): raise ValueError("Unexpected configuration tail")
|
||||
return result
|
||||
|
||||
|
||||
# Load before the service starts its input/observation threads. Lazy warming
|
||||
# in the first arm would leave one avoidable XML/CRC pause in that session.
|
||||
for _kind in ("motor", "application"):
|
||||
_schema(_kind)
|
||||
|
||||
Reference in New Issue
Block a user