mirror of https://github.com/Desuuuu/klipper.git
mcu: Add a get_status() callback with micro-controller info and stats
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
e74d5d57b2
commit
8a6619d18e
|
@ -288,6 +288,16 @@ The following are common printer attributes:
|
||||||
- `printer.hall_filament_width_sensor.Diameter`,
|
- `printer.hall_filament_width_sensor.Diameter`,
|
||||||
`printer.hall_filament_width_sensor.Raw`: The last read values from
|
`printer.hall_filament_width_sensor.Raw`: The last read values from
|
||||||
the sensor.
|
the sensor.
|
||||||
|
- `printer.mcu.mcu_version`: The Klipper code version reported by the
|
||||||
|
micro-controller.
|
||||||
|
- `printer.mcu.mcu_build_versions`: Information on the build tools
|
||||||
|
used to generate the micro-controller code (as reported by the
|
||||||
|
micro-controller).
|
||||||
|
- `printer.mcu.mcu_constants.<constant_name>`: Compile time constants
|
||||||
|
reported by the micro-controller. The available constants may differ
|
||||||
|
between micro-controller architectures and with each code revision.
|
||||||
|
- `printer.mcu.last_stats.<statistics_name>`: Statistics information
|
||||||
|
on the micro-controller connection.
|
||||||
|
|
||||||
The above list is subject to change - if using an attribute be sure to
|
The above list is subject to change - if using an attribute be sure to
|
||||||
review the [Config Changes document](Config_Changes.md) when upgrading
|
review the [Config Changes document](Config_Changes.md) when upgrading
|
||||||
|
|
|
@ -447,6 +447,7 @@ class MCU:
|
||||||
self._stepqueues = []
|
self._stepqueues = []
|
||||||
self._steppersync = None
|
self._steppersync = None
|
||||||
# Stats
|
# Stats
|
||||||
|
self._get_status_info = {}
|
||||||
self._stats_sumsq_base = 0.
|
self._stats_sumsq_base = 0.
|
||||||
self._mcu_tick_avg = 0.
|
self._mcu_tick_avg = 0.
|
||||||
self._mcu_tick_stddev = 0.
|
self._mcu_tick_stddev = 0.
|
||||||
|
@ -630,9 +631,13 @@ class MCU:
|
||||||
self._reset_cmd = self.try_lookup_command("reset")
|
self._reset_cmd = self.try_lookup_command("reset")
|
||||||
self._config_reset_cmd = self.try_lookup_command("config_reset")
|
self._config_reset_cmd = self.try_lookup_command("config_reset")
|
||||||
ext_only = self._reset_cmd is None and self._config_reset_cmd is None
|
ext_only = self._reset_cmd is None and self._config_reset_cmd is None
|
||||||
mbaud = self._serial.get_msgparser().get_constant('SERIAL_BAUD', None)
|
msgparser = self._serial.get_msgparser()
|
||||||
|
mbaud = msgparser.get_constant('SERIAL_BAUD', None)
|
||||||
if self._restart_method is None and mbaud is None and not ext_only:
|
if self._restart_method is None and mbaud is None and not ext_only:
|
||||||
self._restart_method = 'command'
|
self._restart_method = 'command'
|
||||||
|
self._get_status_info['mcu_version'] = msgparser.version
|
||||||
|
self._get_status_info['mcu_build_versions'] = msgparser.build_versions
|
||||||
|
self._get_status_info['mcu_constants'] = msgparser.get_constants()
|
||||||
self.register_response(self._handle_shutdown, 'shutdown')
|
self.register_response(self._handle_shutdown, 'shutdown')
|
||||||
self.register_response(self._handle_shutdown, 'is_shutdown')
|
self.register_response(self._handle_shutdown, 'is_shutdown')
|
||||||
self.register_response(self._handle_mcu_stats, 'stats')
|
self.register_response(self._handle_mcu_stats, 'stats')
|
||||||
|
@ -782,12 +787,17 @@ class MCU:
|
||||||
self._name, eventtime)
|
self._name, eventtime)
|
||||||
self._printer.invoke_shutdown("Lost communication with MCU '%s'" % (
|
self._printer.invoke_shutdown("Lost communication with MCU '%s'" % (
|
||||||
self._name,))
|
self._name,))
|
||||||
|
def get_status(self, eventtime):
|
||||||
|
return dict(self._get_status_info)
|
||||||
def stats(self, eventtime):
|
def stats(self, eventtime):
|
||||||
msg = "%s: mcu_awake=%.03f mcu_task_avg=%.06f mcu_task_stddev=%.06f" % (
|
load = "mcu_awake=%.03f mcu_task_avg=%.06f mcu_task_stddev=%.06f" % (
|
||||||
self._name, self._mcu_tick_awake, self._mcu_tick_avg,
|
self._mcu_tick_awake, self._mcu_tick_avg, self._mcu_tick_stddev)
|
||||||
self._mcu_tick_stddev)
|
stats = ' '.join([load, self._serial.stats(eventtime),
|
||||||
return False, ' '.join([msg, self._serial.stats(eventtime),
|
|
||||||
self._clocksync.stats(eventtime)])
|
self._clocksync.stats(eventtime)])
|
||||||
|
parts = [s.split('=', 1) for s in stats.split()]
|
||||||
|
last_stats = {k:(float(v) if '.' in v else int(v)) for k, v in parts}
|
||||||
|
self._get_status_info['last_stats'] = last_stats
|
||||||
|
return False, '%s: %s' % (self._name, stats)
|
||||||
|
|
||||||
Common_MCU_errors = {
|
Common_MCU_errors = {
|
||||||
("Timer too close", "No next step", "Missed scheduling of next "): """
|
("Timer too close", "No next step", "Missed scheduling of next "): """
|
||||||
|
|
Loading…
Reference in New Issue