Introduced jobs, more work on protocols and transports
This commit is contained in:
1 parent
b7ad8faaee
commit
ff9b7de615
8 files changed
+958
-261
No files matched your search
@@ -8,13 +8,25 @@ __copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
class Protocol(object):
|
||||
|
||||
supported_jobs = []
|
||||
|
||||
def __init__(self):
|
||||
self._logger = logging.getLogger(__name__)
|
||||
self._state = ProtocolState.DISCONNECTED
|
||||
self._listeners = []
|
||||
|
||||
self._job = None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self._state
|
||||
|
||||
@state.setter
|
||||
def state(self, new_state):
|
||||
self._state = new_state
|
||||
|
||||
def register_listener(self, listener):
|
||||
self._listeners.append(listener)
|
||||
|
||||
@@ -27,8 +39,22 @@ class Protocol(object):
|
||||
def disconnect(self):
|
||||
pass
|
||||
|
||||
def process(self, job):
|
||||
pass
|
||||
def process(self, job, position=0):
|
||||
if not job.can_process(self):
|
||||
raise ValueError("Job {} cannot be processed with protocol {}".format(job, self))
|
||||
self._job = job
|
||||
self._job.register_listener(self)
|
||||
self._job.process(job, position=position)
|
||||
|
||||
def pause_processing(self):
|
||||
if self._job is None or self.state != ProtocolState.PRINTING:
|
||||
return
|
||||
self.state = ProtocolState.PAUSED
|
||||
|
||||
def resume_processing(self):
|
||||
if self._job is None or self.state != ProtocolState.PAUSED:
|
||||
return
|
||||
self.state = ProtocolState.PRINTING
|
||||
|
||||
def move(self, x=None, y=None, z=None, e=None, feedrate=None, relative=False):
|
||||
pass
|
||||
@@ -56,6 +82,38 @@ class Protocol(object):
|
||||
for key, value in kwargs.items()]))
|
||||
))
|
||||
|
||||
def on_job_started(self, job):
|
||||
if job != self._job:
|
||||
return
|
||||
self.state = ProtocolState.PRINTING
|
||||
|
||||
def on_job_done(self, job):
|
||||
if job != self._job:
|
||||
return
|
||||
self._job = None
|
||||
self.state = ProtocolState.CONNECTED
|
||||
|
||||
def on_job_cancelled(self, job):
|
||||
if job != self._job:
|
||||
return
|
||||
self._job = None
|
||||
self.state = ProtocolState.CONNECTED
|
||||
|
||||
def on_job_failed(self, job):
|
||||
if job != self._job:
|
||||
return
|
||||
self._job = None
|
||||
self.state = ProtocolState.CONNECTED
|
||||
|
||||
|
||||
class ProtocolState(object):
|
||||
CONNECTED = "connected"
|
||||
DISCONNECTED = "disconnected"
|
||||
PRINTING = "printing"
|
||||
PAUSED = "paused"
|
||||
ERROR = "error"
|
||||
DISCONNECTED_WITH_ERROR = "disconnected with error"
|
||||
|
||||
|
||||
class FanControlProtocolMixin(object):
|
||||
|
||||
@@ -95,7 +153,7 @@ class FileAwareProtocolMixin(object):
|
||||
def list_files(self):
|
||||
pass
|
||||
|
||||
def start_file_print(self, name):
|
||||
def start_file_print(self, name, position=0):
|
||||
pass
|
||||
|
||||
def pause_file_print(self):
|
||||
@@ -104,6 +162,9 @@ class FileAwareProtocolMixin(object):
|
||||
def resume_file_print(self):
|
||||
pass
|
||||
|
||||
def get_file_print_status(self):
|
||||
pass
|
||||
|
||||
|
||||
class FileManagementProtocolMixin(FileAwareProtocolMixin):
|
||||
|
||||
@@ -136,3 +197,9 @@ class FileAwareProtocolListener(object):
|
||||
|
||||
def on_protocol_sd_status(self, name, pos, total):
|
||||
pass
|
||||
|
||||
def on_protocol_file_print_started(self, name, size):
|
||||
pass
|
||||
|
||||
def on_protocol_file_print_done(self):
|
||||
pass
|
||||
Reference in new issue
Block a user