mirror of https://github.com/Desuuuu/klipper.git
util: Try to dump mcu build information on a connection error
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
eeee2a9a35
commit
f3667fd453
|
@ -144,10 +144,12 @@ class Printer:
|
|||
except msgproto.error as e:
|
||||
logging.exception("Protocol error")
|
||||
self._set_state("%s%s" % (str(e), message_protocol_error))
|
||||
util.dump_mcu_build()
|
||||
return
|
||||
except mcu.error as e:
|
||||
logging.exception("MCU error during connect")
|
||||
self._set_state("%s%s" % (str(e), message_mcu_connect_error))
|
||||
util.dump_mcu_build()
|
||||
return
|
||||
except Exception as e:
|
||||
logging.exception("Unhandled exception during connect")
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
# Low level unix utility functions
|
||||
#
|
||||
# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
|
||||
# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
import sys, os, pty, fcntl, termios, signal, logging
|
||||
import sys, os, pty, fcntl, termios, signal, logging, json, time
|
||||
import subprocess, traceback, shlex
|
||||
|
||||
|
||||
######################################################################
|
||||
# Low-level Unix commands
|
||||
######################################################################
|
||||
|
||||
# Return the SIGINT interrupt handler back to the OS default
|
||||
def fix_sigint():
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
@ -41,6 +46,54 @@ def create_pty(ptyname):
|
|||
termios.tcsetattr(mfd, termios.TCSADRAIN, old)
|
||||
return mfd
|
||||
|
||||
|
||||
######################################################################
|
||||
# Helper code for extracting mcu build info
|
||||
######################################################################
|
||||
|
||||
def dump_file_stats(build_dir, filename):
|
||||
fname = os.path.join(build_dir, filename)
|
||||
try:
|
||||
mtime = os.path.getmtime(fname)
|
||||
fsize = os.path.getsize(fname)
|
||||
timestr = time.asctime(time.localtime(mtime))
|
||||
logging.info("Build file %s(%d): %s", fname, fsize, timestr)
|
||||
except:
|
||||
logging.info("No build file %s", fname)
|
||||
|
||||
# Try to log information on the last mcu build
|
||||
def dump_mcu_build():
|
||||
build_dir = os.path.join(os.path.dirname(__file__), '..')
|
||||
# Try to log last mcu config
|
||||
dump_file_stats(build_dir, '.config')
|
||||
try:
|
||||
f = open(os.path.join(build_dir, '.config'), 'rb')
|
||||
data = f.read(32*1024)
|
||||
f.close()
|
||||
logging.info("========= Last MCU build config =========\n%s"
|
||||
"=======================", data)
|
||||
except:
|
||||
pass
|
||||
# Try to log last mcu build version
|
||||
dump_file_stats(build_dir, 'out/klipper.dict')
|
||||
try:
|
||||
f = open(os.path.join(build_dir, 'out/klipper.dict'), 'rb')
|
||||
data = f.read(32*1024)
|
||||
f.close()
|
||||
data = json.loads(data)
|
||||
logging.info("Last MCU build version: %s", data.get('version', ''))
|
||||
logging.info("Last MCU build tools: %s", data.get('build_versions', ''))
|
||||
cparts = ["%s=%s" % (k, v) for k, v in data.get('config', {}).items()]
|
||||
logging.info("Last MCU build config: %s", " ".join(cparts))
|
||||
except:
|
||||
pass
|
||||
dump_file_stats(build_dir, 'out/klipper.elf')
|
||||
|
||||
|
||||
######################################################################
|
||||
# General system and software information
|
||||
######################################################################
|
||||
|
||||
def get_cpu_info():
|
||||
try:
|
||||
f = open('/proc/cpuinfo', 'rb')
|
||||
|
|
Loading…
Reference in New Issue