chiark / gitweb /
Do not allow firmware to ask for a resend of more than 10 lines.
authorYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Fri, 7 Aug 2015 20:09:08 +0000 (16:09 -0400)
committerYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Fri, 7 Aug 2015 20:10:41 +0000 (16:10 -0400)
This is because if power gets interrupted or reset button is pressed,
then it will ask us to resend from line 0, and it will cause the print
to be restarted, which can be dangerous if there is a print half-finished
on the bed.
Fixes T37

Cura/util/machineCom.py

index 5fe86611c4aacdfe77b14981a1b54bd74c74f0da..9a516b61bc0d1f178bc79b06875edad30160462c 100644 (file)
@@ -487,11 +487,20 @@ class MachineCom(object):
                                        else:
                                                self._sendNext()
                                elif "resend" in line.lower() or "rs" in line:
+                                       newPos = self._gcodePos
                                        try:
-                                               self._gcodePos = int(line.replace("N:"," ").replace("N"," ").replace(":"," ").split()[-1])
+                                               newPos = int(line.replace("N:"," ").replace("N"," ").replace(":"," ").split()[-1])
                                        except:
                                                if "rs" in line:
-                                                       self._gcodePos = int(line.split()[1])
+                                                       newPos = int(line.split()[1])
+                                       # If we need to resend more than 10 lines, we can assume that the machine
+                                       # was shut down and turned back on or something else that's weird just happened.
+                                       # In that case, it can be dangerous to restart the print, so we'd better kill it
+                                       if self._gcodePos > newPos + 10:
+                                               self.cancelPrint()
+                                       else:
+                                               self._gcodePos = newPos
+
                self._log("Connection closed, closing down monitor")
 
        def _setBaudrate(self, baudrate):