Hi Guys
My first post in this forum, how can i convert this phyton code to b4a?
I'm trying to do the checksum base on this...
Here is the perl code i found..
Thanks for your help
My first post in this forum, how can i convert this phyton code to b4a?
I'm trying to do the checksum base on this...
B4X:
class x25crc(object):
'''x25 CRC - 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'''
bytes = array.array('B')
if isinstance(buf, array.array):
bytes.extend(buf)
else:
bytes.fromstring(buf)
accum = self.crc
for b in bytes:
tmp = b ^ (accum & 0xff)
tmp = (tmp ^ (tmp<<4)) & 0xFF
accum = (accum>>8) ^ (tmp<<8) ^ (tmp<<3) ^ (tmp>>4)
accum = accum & 0xFFFF
self.crc = accum
Here is the perl code i found..
B4X:
#uses MAVLINK's x25 checksum
#https://github.com/mavlink/pymavlink/blob/master/mavutil.py
Sub do_crc{
my $bufstr= shift; my $len= shift;
my @buf= unpack( "C".$len, $bufstr );
#foreach my $b (@buf){ TextOut(UCharToHexstr($b)); } TextOut("!");
my $crc= 0xFFFF;
foreach my $b (@buf){
my $tmp= $b ^ ($crc & 0xFF );
$tmp= ($tmp ^ ($tmp<<4)) & 0xFF;
$crc= ($crc>>8) ^ ($tmp<<8) ^ ($tmp<<3) ^ ($tmp>>4);
$crc= $crc & 0xFFFF;
}
#TextOut( " CRC:0x".UIntToHexstr($crc)."!" );
Return $crc;
}
Thanks for your help