def calc_checksum(self, data, checksum=0):
'''
Calculate the checksum for a given block of data, can also be used to
update a checksum.
>>> csum = modem.calc_checksum('hello')
>>> csum = modem.calc_checksum('world', csum)
>>> hex(csum)
'0x3c'
'''
if platform.python_version_tuple() >= ('3', '0', '0'):
return (sum(data) + checksum) % 256
else:
return (sum(map(ord, data)) + checksum) % 256
评论列表
文章目录