Skip to content

Commit

Permalink
Don't use copy-pasted xcrc25
Browse files Browse the repository at this point in the history
  • Loading branch information
alehed committed Nov 6, 2022
1 parent 65702a1 commit d56a0b8
Showing 1 changed file with 3 additions and 21 deletions.
24 changes: 3 additions & 21 deletions mavutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import re
from pymavlink import mavexpression

# We want to re-export x25crc here
from pymavlink.generator.mavcrc import x25crc as x25crc

is_py3 = sys.version_info >= (3,0)
supports_type_annotations = sys.version_info >= (3,6)

Expand Down Expand Up @@ -2281,27 +2284,6 @@ def mode_string_acm(mode_number):
return mode_mapping_acm[mode_number]
return "Mode(%u)" % mode_number

class x25crc(object):
'''CRC-16/MCRF4XX - based on checksum.h from mavlink library'''
def __init__(self, buf=''):
self.crc = 0xffff
self.accumulate(buf)

def accumulate(self, buf):
'''add in some more bytes'''
byte_buf = array.array('B')
if isinstance(buf, array.array):
byte_buf.extend(buf)
else:
byte_buf.fromstring(buf)
accum = self.crc
for b in byte_buf:
tmp = b ^ (accum & 0xff)
tmp = (tmp ^ (tmp<<4)) & 0xFF
accum = (accum>>8) ^ (tmp<<8) ^ (tmp<<3) ^ (tmp>>4)
accum = accum & 0xFFFF
self.crc = accum

class MavlinkSerialPort(object):
'''an object that looks like a serial port, but
transmits using mavlink SERIAL_CONTROL packets'''
Expand Down

0 comments on commit d56a0b8

Please # to comment.