@conf.commands.register
def fletcher16_checkbytes(binbuf, offset):
 if (len(binbuf) < offset):
  raise Exception(('Packet too short for checkbytes %d' % len(binbuf)))
 binbuf = ((binbuf[:offset] + '\x00\x00') + binbuf[(offset + 2):])
 (c0, c1) = _fletcher16(binbuf)
 x = (((((len(binbuf) - offset) - 1) * c0) - c1) % 255)
 if (x <= 0):
  x += 255
 y = ((510 - c0) - x)
 if (y > 255):
  y -= 255
 return (chr(x) + chr(y))

@ conf . commands . register def fletcher16_checkbytes ( binbuf , offset ) : if ( len ( binbuf ) < offset ) : raise Exception ( ( 'Packet too short for checkbytes %d' % len ( binbuf ) ) ) binbuf = ( ( binbuf [ : offset ] + '\x00\x00' ) + binbuf [ ( offset + 2 ) : ] ) ( c0 , c1 ) = _fletcher16 ( binbuf ) x = ( ( ( ( ( len ( binbuf ) - offset ) - 1 ) * c0 ) - c1 ) % 255 ) if ( x <= 0 ) : x += 255 y = ( ( 510 - c0 ) - x ) if ( y > 255 ) : y -= 255 return ( chr ( x ) + chr ( y ) )
calculates the fletcher-16 checkbytes returned as 2 byte binary-string .