Merge branch 'devel' into dev/commRefactoringNG

# Conflicts:
#	setup.py
#	src/octoprint/filemanager/__init__.py
#	src/octoprint/filemanager/storage.py
#	src/octoprint/printer/__init__.py
#	src/octoprint/printer/standard.py
#	src/octoprint/server/__init__.py
This commit is contained in:
Gina Häußge committed 2017-04-20 12:25:08 +02:00
commit 2dea5e0ffc
198 files changed
+10415 -4826

No files matched your search

@@ -25,6 +25,8 @@ class VirtualPrinter(object):
sleep_after_regex = re.compile("sleep_after ([GMTF]\d+) (\d+)")
sleep_after_next_regex = re.compile("sleep_after_next ([GMTF]\d+) (\d+)")
custom_action_regex = re.compile("action_custom ([a-zA-Z0-9_]+)(\s+.*)?")
prepare_ok_regex = re.compile("prepare_ok (.*)")
send_regex = re.compile("send (.*)")
def __init__(self, seriallog_handler=None, read_timeout=5.0, write_timeout=10.0):
import logging
@@ -50,12 +52,23 @@ class VirtualPrinter(object):
self.outgoing = queue.Queue()
self.buffered = queue.Queue(maxsize=settings().getInt(["devel", "virtualPrinter", "commandBuffer"]))
for item in ['start\n', 'Marlin: Virtual Marlin!\n', '\x80\n', 'SD card ok\n']:
self._send(item)
if settings().getBoolean(["devel", "virtualPrinter", "simulateReset"]):
for item in ['start\n', 'Marlin: Virtual Marlin!\n', '\x80\n', 'SD card ok\n']:
self._send(item)
self._prepared_oks = []
prepared = settings().get(["devel", "virtualPrinter", "preparedOks"])
if prepared and isinstance(prepared, list):
for prep in prepared:
self._prepared_oks.append(prep)
self.currentExtruder = 0
self.temp = [0.0] * settings().getInt(["devel", "virtualPrinter", "numExtruders"])
self.targetTemp = [0.0] * settings().getInt(["devel", "virtualPrinter", "numExtruders"])
self.extruderCount = settings().getInt(["devel", "virtualPrinter", "numExtruders"])
self.sharedNozzle = settings().getBoolean(["devel", "virtualPrinter", "sharedNozzle"])
self.temperatureCount = (1 if self.sharedNozzle else self.extruderCount)
self.temp = [0.0] * self.temperatureCount
self.targetTemp = [0.0] * self.temperatureCount
self.lastTempAt = time.time()
self.bedTemp = 1.0
self.bedTargetTemp = 1.0
@@ -88,14 +101,18 @@ class VirtualPrinter(object):
self._supportF = settings().getBoolean(["devel", "virtualPrinter", "supportF"])
self._sendWait = settings().getBoolean(["devel", "virtualPrinter", "sendWait"])
self._sendBusy = settings().getBoolean(["devel", "virtualPrinter", "sendBusy"])
self._waitInterval = settings().getFloat(["devel", "virtualPrinter", "waitInterval"])
self._echoOnM117 = settings().getBoolean(["devel", "virtualPrinter", "echoOnM117"])
self._brokenM29 = settings().getBoolean(["devel", "virtualPrinter", "brokenM29"])
self._m115FormatString = settings().get(["devel", "virtualPrinter", "m115FormatString"])
self._firmwareName = settings().get(["devel", "virtualPrinter", "firmwareName"])
self._okFormatString = settings().get(["devel", "virtualPrinter", "okFormatString"])
self.currentLine = 0
self.lastN = 0
@@ -301,8 +318,10 @@ class VirtualPrinter(object):
##~~ command implementations
def _gcode_T(self, code, data):
self.currentExtruder = int(code)
self._send("Active Extruder: %d" % self.currentExtruder)
t = int(code)
if 0 <= t <= self.extruderCount:
self.currentExtruder = t
self._send("Active Extruder: %d" % self.currentExtruder)
def _gcode_F(self, code, data):
if self._supportF:
@@ -378,12 +397,12 @@ class VirtualPrinter(object):
def _gcode_M114(self, data):
output = "X:{} Y:{} Z:{} E:{} Count: A:{} B:{} C:{}".format(self._lastX, self._lastY, self._lastZ, self._lastE, int(self._lastX*100), int(self._lastY*100), int(self._lastZ*100))
if not self._okBeforeCommandOutput:
output = "ok " + output
output = "{} {}".format(self._ok(), output)
self._send(output)
return True
def _gcode_M115(self, data):
output = "FIRMWARE_NAME:{} PROTOCOL_VERSION:1.0".format(self._firmwareName)
output = self._m115FormatString.format(firmware_name=self._firmwareName)
self._send(output)
def _gcode_M117(self, data):
@@ -445,6 +464,24 @@ class VirtualPrinter(object):
_gcode_G2 = _gcode_G0
_gcode_G3 = _gcode_G0
def _gcode_G4(self, data):
matchS = re.search('S([0-9]+)', data)
matchP = re.search('P([0-9]+)', data)
_timeout = 0
if matchP:
_timeout = float(matchP.group(1)) / 1000.0
elif matchS:
_timeout = float(matchS.group(1))
if self._sendBusy:
until = time.time() + _timeout
while time.time() < until:
time.sleep(1.0)
self._send("busy:processing")
else:
time.sleep(_timeout)
##~~ further helpers
def _calculate_checksum(self, line):
@@ -473,7 +510,7 @@ class VirtualPrinter(object):
def request_resend():
self._send("Resend:%d" % expected)
self._send("ok")
self._send(self._ok())
if settings().getBoolean(["devel", "virtualPrinter", "repetierStyleResends"]):
request_resend()
@@ -513,6 +550,9 @@ class VirtualPrinter(object):
| Triggers a resend error with a checksum mismatch
drop_connection
| Drops the serial connection
prepare_ok <broken ok>
| Will cause <broken ok> to be enqueued for use,
| will be used instead of actual "ok"
# Reply Timing / Sleeping
@@ -521,7 +561,12 @@ class VirtualPrinter(object):
sleep_after <str:command> <int:seconds>
| Sleeps <seconds> s after each execution of <command>
sleep_after_next <str:command> <int:seconds>
| Sleeps <seconds> s after execution of <command>
| Sleeps <seconds> s after execution of next <command>
# Misc
send <str:message>
| Sends back <message>
"""
for line in usage.split("\n"):
self._send("echo: {}".format(line.strip()))
@@ -550,6 +595,8 @@ class VirtualPrinter(object):
sleep_after_match = VirtualPrinter.sleep_after_regex.match(data)
sleep_after_next_match = VirtualPrinter.sleep_after_next_regex.match(data)
custom_action_match = VirtualPrinter.custom_action_regex.match(data)
prepare_ok_match = VirtualPrinter.prepare_ok_regex.match(data)
send_match = VirtualPrinter.send_regex.match(data)
if sleep_match is not None:
interval = int(sleep_match.group(1))
@@ -570,6 +617,11 @@ class VirtualPrinter(object):
params = custom_action_match.group(2)
params = params.strip() if params is not None else ""
self._send("// action:{action} {params}".format(**locals()).strip())
elif prepare_ok_match is not None:
ok = prepare_ok_match.group(1)
self._prepared_oks.append(ok)
elif send_match is not None:
self._send(send_match.group(1))
except:
pass
@@ -628,7 +680,7 @@ class VirtualPrinter(object):
includeOk = not self._okBeforeCommandOutput
# send simulated temperature data
if settings().getInt(["devel", "virtualPrinter", "numExtruders"]) > 1:
if self.temperatureCount > 1:
allTemps = []
for i in range(len(self.temp)):
allTemps.append((i, self.temp[i], self.targetTemp[i]))
@@ -659,7 +711,7 @@ class VirtualPrinter(object):
output += " @:64\n"
if includeOk:
output = "ok " + output
output = "{} {}".format(self._ok(), output)
self._send(output)
def _parseHotendCommand(self, line, wait=False, support_r=False):
@@ -672,7 +724,7 @@ class VirtualPrinter(object):
except:
pass
if tool >= settings().getInt(["devel", "virtualPrinter", "numExtruders"]):
if tool >= self.temperatureCount:
return
try:
@@ -1032,11 +1084,7 @@ class VirtualPrinter(object):
def _sendOk(self):
if self.outgoing is None:
return
if settings().getBoolean(["devel", "virtualPrinter", "okWithLinenumber"]):
self._send("ok %d" % self.lastN)
else:
self._send("ok")
self._send(self._ok())
def _sendWaitAfterTimeout(self, timeout=5):
time.sleep(timeout)
@@ -1047,6 +1095,13 @@ class VirtualPrinter(object):
if self.outgoing is not None:
self.outgoing.put(line)
def _ok(self):
ok = self._okFormatString
if self._prepared_oks:
ok = self._prepared_oks.pop(0)
return ok.format(ok, lastN=self.lastN, buffer=self.buffered.maxsize - self.buffered.qsize())
class CharCountingQueue(queue.Queue):
def __init__(self, maxsize, name=None):