mirror of
https://github.com/QIDITECH/klipper.git
synced 2026-02-01 08:28:41 +03:00
plus4的klipper版本
This commit is contained in:
@@ -21,7 +21,7 @@ MESSAGE_TRAILER_SYNC = 1
|
||||
MESSAGE_PAYLOAD_MAX = MESSAGE_MAX - MESSAGE_MIN
|
||||
MESSAGE_SEQ_MASK = 0x0f
|
||||
MESSAGE_DEST = 0x10
|
||||
MESSAGE_SYNC = '\x7E'
|
||||
MESSAGE_SYNC = 0x7e
|
||||
|
||||
class error(Exception):
|
||||
pass
|
||||
@@ -29,12 +29,10 @@ class error(Exception):
|
||||
def crc16_ccitt(buf):
|
||||
crc = 0xffff
|
||||
for data in buf:
|
||||
data = ord(data)
|
||||
data ^= crc & 0xff
|
||||
data ^= (data & 0x0f) << 4
|
||||
crc = ((data << 8) | (crc >> 8)) ^ (data >> 4) ^ (data << 3)
|
||||
crc = chr(crc >> 8) + chr(crc & 0xff)
|
||||
return crc
|
||||
return [crc >> 8, crc & 0xff]
|
||||
|
||||
class PT_uint32:
|
||||
is_int = True
|
||||
@@ -236,6 +234,7 @@ class MessageParser:
|
||||
self.messages = []
|
||||
self.messages_by_id = {}
|
||||
self.messages_by_name = {}
|
||||
self.msgtag_by_format = {}
|
||||
self.config = {}
|
||||
self.version = self.build_versions = ""
|
||||
self.raw_identify_data = ""
|
||||
@@ -245,10 +244,10 @@ class MessageParser:
|
||||
def check_packet(self, s):
|
||||
if len(s) < MESSAGE_MIN:
|
||||
return 0
|
||||
msglen = ord(s[MESSAGE_POS_LEN])
|
||||
msglen = s[MESSAGE_POS_LEN]
|
||||
if msglen < MESSAGE_MIN or msglen > MESSAGE_MAX:
|
||||
return -1
|
||||
msgseq = ord(s[MESSAGE_POS_SEQ])
|
||||
msgseq = s[MESSAGE_POS_SEQ]
|
||||
if (msgseq & ~MESSAGE_SEQ_MASK) != MESSAGE_DEST:
|
||||
return -1
|
||||
if len(s) < msglen:
|
||||
@@ -258,7 +257,7 @@ class MessageParser:
|
||||
return -1
|
||||
msgcrc = s[msglen-MESSAGE_TRAILER_CRC:msglen-MESSAGE_TRAILER_CRC+2]
|
||||
crc = crc16_ccitt(s[:msglen-MESSAGE_TRAILER_SIZE])
|
||||
if crc != msgcrc:
|
||||
if crc != list(msgcrc):
|
||||
#logging.debug("got crc %s vs %s", repr(crc), repr(msgcrc))
|
||||
return -1
|
||||
return msglen
|
||||
@@ -294,10 +293,10 @@ class MessageParser:
|
||||
def encode(self, seq, cmd):
|
||||
msglen = MESSAGE_MIN + len(cmd)
|
||||
seq = (seq & MESSAGE_SEQ_MASK) | MESSAGE_DEST
|
||||
out = [chr(msglen), chr(seq), cmd]
|
||||
out.append(crc16_ccitt(''.join(out)))
|
||||
out = [msglen, seq] + cmd
|
||||
out.append(crc16_ccitt(out))
|
||||
out.append(MESSAGE_SYNC)
|
||||
return ''.join(out)
|
||||
return out
|
||||
def _parse_buffer(self, value):
|
||||
if not value:
|
||||
return []
|
||||
@@ -318,6 +317,11 @@ class MessageParser:
|
||||
self._error("Command format mismatch: %s vs %s",
|
||||
msgformat, mp.msgformat)
|
||||
return mp
|
||||
def lookup_msgtag(self, msgformat):
|
||||
msgtag = self.msgtag_by_format.get(msgformat)
|
||||
if msgtag is None:
|
||||
self._error("Unknown command: %s", msgformat)
|
||||
return msgtag
|
||||
def create_command(self, msg):
|
||||
parts = msg.strip().split()
|
||||
if not parts:
|
||||
@@ -378,6 +382,7 @@ class MessageParser:
|
||||
self.messages.append((msgtag, msgtype, msgformat))
|
||||
if msgtag < -32 or msgtag > 95:
|
||||
self._error("Multi-byte msgtag not supported")
|
||||
self.msgtag_by_format[msgformat] = msgtag
|
||||
msgid = msgtag & 0x7f
|
||||
if msgtype == 'output':
|
||||
self.messages_by_id[msgid] = OutputFormat(msgid, msgformat)
|
||||
|
||||
Reference in New Issue
Block a user