mavcrc.py
Go to the documentation of this file.
1 '''MAVLink X25 CRC code'''
2 from builtins import object
3 
4 
5 class x25crc(object):
6  '''x25 CRC - based on checksum.h from mavlink library'''
7  def __init__(self, buf=None):
8  self.crc = 0xffff
9  if buf is not None:
10  if isinstance(buf, str):
11  self.accumulate_str(buf)
12  else:
13  self.accumulate(buf)
14 
15  def accumulate(self, buf):
16  '''add in some more bytes'''
17  accum = self.crc
18  for b in buf:
19  tmp = b ^ (accum & 0xff)
20  tmp = (tmp ^ (tmp<<4)) & 0xFF
21  accum = (accum>>8) ^ (tmp<<8) ^ (tmp<<3) ^ (tmp>>4)
22  self.crc = accum
23 
24  def accumulate_str(self, buf):
25  '''add in some more bytes'''
26  accum = self.crc
27  import array
28  bytes = array.array('B')
29  bytes.fromstring(buf)
30  self.accumulate(bytes)


mavlink
Author(s): Lorenz Meier
autogenerated on Sun Jul 7 2019 03:22:06