Added checksum checking to virtual printer

This commit is contained in:
Gina Häußge 2016-03-18 15:00:03 +01:00
parent 1a4c06d6f6
commit b54e1b44a4

View file

@ -141,7 +141,12 @@ class VirtualPrinter():
# strip checksum
if "*" in data:
checksum = int(data[data.rfind("*") + 1:])
data = data[:data.rfind("*")]
if not checksum == self._calculate_checksum(data):
self._triggerResend(expected=self.currentLine + 1)
continue
self.currentLine += 1
elif settings().getBoolean(["devel", "virtualPrinter", "forceChecksum"]):
self.outgoing.put("Error: Missing checksum")
@ -317,6 +322,12 @@ class VirtualPrinter():
if len(data.strip()) > 0 and not self._okBeforeCommandOutput:
self._sendOk()
def _calculate_checksum(self, line):
checksum = 0
for c in line:
checksum ^= ord(c)
return checksum
def _kill(self):
if not self._supportM112:
return