def __check_crc(self, cmd, result): """ Calculate the CRC of the data for a certain master command. :param cmd: instance of MasterCommandSpec. :param result: A dict containing the result of the master command. :returns: boolean """ crc = 0 for field in cmd.output_fields: if Field.is_crc(field): break else: for byte in field.encode(result[field.name]): crc += ord(byte) return result['crc'] == [67, (crc / 256), (crc % 256)]
def __check_crc(cmd, result, extended_crc=False): """ Calculate the CRC of the data for a certain master command. :param cmd: instance of MasterCommandSpec. :param result: A dict containing the result of the master command. :param extended_crc: Indicates whether the action should be included in the crc :returns: boolean """ crc = 0 if extended_crc: crc += ord(cmd.action[0]) crc += ord(cmd.action[1]) for field in cmd.output_fields: if Field.is_crc(field): break else: for byte in field.encode(result[field.name]): crc += ord(byte) return result['crc'] == [67, (crc / 256), (crc % 256)]