comm: Synchronized write access to line number
New method wraps line sending and incrementing
This commit is contained in:
parent
22a660404b
commit
f8e72c9233
1 changed files with 14 additions and 8 deletions
|
|
@ -243,6 +243,7 @@ class MachineCom(object):
|
||||||
self._sendChecksumWithUnknownCommands = settings().getBoolean(["feature", "sendChecksumWithUnknownCommands"])
|
self._sendChecksumWithUnknownCommands = settings().getBoolean(["feature", "sendChecksumWithUnknownCommands"])
|
||||||
self._unknownCommandsNeedAck = settings().getBoolean(["feature", "unknownCommandsNeedAck"])
|
self._unknownCommandsNeedAck = settings().getBoolean(["feature", "unknownCommandsNeedAck"])
|
||||||
self._currentLine = 1
|
self._currentLine = 1
|
||||||
|
self._line_mutex = threading.RLock()
|
||||||
self._resendDelta = None
|
self._resendDelta = None
|
||||||
self._lastLines = deque([], 50)
|
self._lastLines = deque([], 50)
|
||||||
self._lastCommError = None
|
self._lastCommError = None
|
||||||
|
|
@ -1620,10 +1621,7 @@ class MachineCom(object):
|
||||||
checksum_enabled = self.isPrinting() or self._alwaysSendChecksum
|
checksum_enabled = self.isPrinting() or self._alwaysSendChecksum
|
||||||
|
|
||||||
if command_requiring_checksum or (command_allowing_checksum and checksum_enabled):
|
if command_requiring_checksum or (command_allowing_checksum and checksum_enabled):
|
||||||
linenumber = self._currentLine
|
self._doIncrementAndSendWithChecksum(command)
|
||||||
self._addToLastLines(command)
|
|
||||||
self._currentLine += 1
|
|
||||||
self._doSendWithChecksum(command, linenumber)
|
|
||||||
else:
|
else:
|
||||||
self._doSendWithoutChecksum(command)
|
self._doSendWithoutChecksum(command)
|
||||||
|
|
||||||
|
|
@ -1716,6 +1714,13 @@ class MachineCom(object):
|
||||||
|
|
||||||
##~~ actual sending via serial
|
##~~ actual sending via serial
|
||||||
|
|
||||||
|
def _doIncrementAndSendWithChecksum(self, cmd):
|
||||||
|
with self._line_mutex:
|
||||||
|
linenumber = self._currentLine
|
||||||
|
self._addToLastLines(cmd)
|
||||||
|
self._currentLine += 1
|
||||||
|
self._doSendWithChecksum(cmd, linenumber)
|
||||||
|
|
||||||
def _doSendWithChecksum(self, cmd, lineNumber):
|
def _doSendWithChecksum(self, cmd, lineNumber):
|
||||||
commandToSend = "N%d %s" % (lineNumber, cmd)
|
commandToSend = "N%d %s" % (lineNumber, cmd)
|
||||||
checksum = reduce(lambda x,y:x^y, map(ord, commandToSend))
|
checksum = reduce(lambda x,y:x^y, map(ord, commandToSend))
|
||||||
|
|
@ -1824,11 +1829,12 @@ class MachineCom(object):
|
||||||
else:
|
else:
|
||||||
newLineNumber = 0
|
newLineNumber = 0
|
||||||
|
|
||||||
# send M110 command with new line number
|
with self._line_mutex:
|
||||||
self._currentLine = newLineNumber
|
# send M110 command with new line number
|
||||||
|
self._currentLine = newLineNumber
|
||||||
|
|
||||||
# after a reset of the line number we have no way to determine what line exactly the printer now wants
|
# after a reset of the line number we have no way to determine what line exactly the printer now wants
|
||||||
self._lastLines.clear()
|
self._lastLines.clear()
|
||||||
self._resendDelta = None
|
self._resendDelta = None
|
||||||
|
|
||||||
def _gcode_M112_queuing(self, cmd, cmd_type=None):
|
def _gcode_M112_queuing(self, cmd, cmd_type=None):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue