/octoprint_ackackack.py Secret
Last active
March 24, 2024 20:06
-
-
Save foosel/23b55541299b072e3f6dd399115f70ba to your computer and use it in GitHub Desktop.
OctoPrint-AckAckAck. Install by placing octoprint_ackackack.py in ~/.octoprint/plugins or (OctoPrint 1.4.1+) by pasting "https://gist.githubusercontent.com/foosel/23b55541299b072e3f6dd399115f70ba/raw/octoprint_ackackack.py" into Plugin Manager > Get More > from URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
from __future__ import absolute_import | |
import octoprint.plugin | |
import logging | |
from collections import deque | |
class AckAckAckPlugin(octoprint.plugin.StartupPlugin): | |
def __init__(self): | |
super(AckAckAckPlugin, self).__init__() | |
self._comm_tail = deque(maxlen=10) # Buffer 10 lines | |
def on_startup(self, host, port): | |
from octoprint.logging.handlers import CleaningTimedRotatingFileHandler | |
path = self._settings.get_plugin_logfile_path() | |
logging_handler = CleaningTimedRotatingFileHandler(path, | |
when="D", | |
backupCount=10) | |
formatter = logging.Formatter("%(asctime)s %(message)s") | |
logging_handler.setFormatter(formatter) | |
logging_handler.setLevel(logging.DEBUG) | |
self._logger.addHandler(logging_handler) | |
self._logger.setLevel(logging.DEBUG) | |
self._logger.propagate = False | |
def on_gcode_received(self, comm, line, *args, **kwargs): | |
self._comm_tail.append("Recv: {}".format(line)) | |
if "o\\x00k" in line or "o\x00k" in line: | |
self._logger.error("Garbled OK detected:") | |
self._logger.error("-" * 80) | |
for l in self._comm_tail: | |
self._logger.error(l) | |
self._logger.error("-" * 80) | |
return "ok" | |
elif "\x00" in line: | |
self._logger.error("Potential garble detected:") | |
self._logger.error("-" * 80) | |
for l in self._comm_tail: | |
self._logger.error(l) | |
self._logger.error("-" * 80) | |
return line | |
def on_gcode_sent(self, comm_instance, phase, cmd, cmd_type, gcode, | |
*args, **kwargs): | |
self._comm_tail.append("Send: {}".format(cmd)) | |
__plugin_name__ = "OctoPrint-AckAckAck" | |
__plugin_pythoncompat__ = ">=2.7,<4" | |
__plugin_implementation__ = AckAckAckPlugin() | |
__plugin_hooks__ = { | |
"octoprint.comm.protocol.gcode.received": __plugin_implementation__.on_gcode_received, | |
"octoprint.comm.protocol.gcode.sent": __plugin_implementation__.on_gcode_sent | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment