def _read_and_assert_crc(self, allow_zero=False): # CRC Calculation is little endian from SDK crc_computed, crc_read = self._crc.value, self._read_struct(Crc.FMT) if not self.check_crc: return if crc_computed == crc_read or (allow_zero and crc_read == 0): return raise FitCRCError('CRC Mismatch [computed: %s, read: %s]' % (Crc.format(crc_computed), Crc.format(crc_read)))
def _read_and_assert_crc(self, allow_zero=False): # CRC Calculation is little endian from SDK crc_computed, crc_read = self._crc.value, self._read_struct(Crc.FMT) if not self.check_crc: return if crc_computed == crc_read or (allow_zero and crc_read == 0): return raise FitCRCError('CRC Mismatch [computed: %s, read: %s]' % ( Crc.format(crc_computed), Crc.format(crc_read)))
def _read_and_assert_crc(self, allow_zero=False): # CRC Calculation is little endian from SDK # TODO - How to handle the case of unterminated file? Error out and have user retry with check_crc=false? crc_computed, crc_read = self._crc.value, self._read_struct(Crc.FMT) if not self.check_crc: return if crc_computed == crc_read or (allow_zero and crc_read == 0): return raise FitCRCError('CRC Mismatch [computed: %s, read: %s]' % ( Crc.format(crc_computed), Crc.format(crc_read)))
def test_crc_format(self): self.assertEqual('0x0000', Crc.format(0)) self.assertEqual('0x12AB', Crc.format(0x12AB))