feat: add --debug tracing to hendi_ctrl_app.py, document v1.16 fix

HendiCtrl.cmd() previously raised a bare "Communication error" for any
non-OK response, discarding the firmware's actual reply. It now
includes the raw echo/answer bytes, and --debug prints every
request/response. Using this, the rejected R1 during lockout turned
out to be an explicit "ERR:Invalid state" reply, not a timeout.

Also flashed and retested v1.16: plain reconnect (no --reset) now
recovers from the lockout reliably (4/4 trials), fixing the
intermittent behavior seen on v1.15.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GpePKZiEZWbGo9HrfuML6U
This commit is contained in:
2026-07-02 18:44:00 +02:00
co-authored by Claude Sonnet 5
parent 7ebd2aaa63
commit 5bc278e875
3 changed files with 43 additions and 19 deletions
+12 -6
View File
@@ -10,7 +10,8 @@ class HendiException(Exception):
pass
class HendiCtrl:
def __init__(self, port, speed):
def __init__(self, port, speed, debug=False):
self.debug = debug
self.ser = serial.Serial(port, speed)
try:
self.ser.open()
@@ -102,6 +103,8 @@ class HendiCtrl:
def __write(self, s):
self.ser.flushInput()
data = s.encode()
if self.debug:
print(f"HendiCtrl: -> {data!r}")
self.ser.write(data + b'\r')
def __read(self):
@@ -109,21 +112,24 @@ class HendiCtrl:
echo = self.ser.readline()
# Read answer line
answer = self.ser.readline().decode('utf-8').replace('\r', '').replace('\n', '')
answer_raw = self.ser.readline()
if self.debug:
print(f"HendiCtrl: <- echo={echo!r} answer={answer_raw!r}")
answer = answer_raw.decode('utf-8').replace('\r', '').replace('\n', '')
if ':' in answer:
result = answer.split(':')
else:
result = answer
return result
return result, echo, answer_raw
def cmd(self, req):
self.__write(req)
rsp = self.__read()
rsp, echo, answer_raw = self.__read()
if len(rsp) == 0:
raise HendiException(f"Communication error")
raise HendiException(f"Communication error: req={req!r} echo={echo!r} answer={answer_raw!r}")
if "OK" not in rsp[0]:
raise HendiException(f"Communication error")
raise HendiException(f"Communication error: req={req!r} echo={echo!r} answer={answer_raw!r}")
return rsp[1]