def generate_fitfile(data=None, endian='<'): fit_data = ( generate_messages( # local mesg 0, global mesg 0 (file_id) mesg_num=0, local_mesg_num=0, endian=endian, field_defs=[ # serial number, time_created, manufacturer (3, 'uint32z'), (4, 'uint32'), (1, 'uint16'), # product/garmin_product, number, type (2, 'uint16'), (5, 'uint16'), (0, 'enum'), ], # random serial number, random time, garmin, edge500, null, activity data=[[558069241, 723842606, 1, 1036, (2**16) - 1, 4]], )) if data: fit_data += data # Prototcol version 1.0, profile version 1.52 header = pack('<2BHI4s', 14, 16, 152, len(fit_data), b'.FIT') file_data = header + pack('<H', calc_crc(header)) + fit_data return file_data + pack('<H', calc_crc(file_data))
def _read(self, size): if size <= 0: return None data = self._file.read(size) self._crc = calc_crc(data, self._crc) self._bytes_left -= len(data) return data
def _read(self, size): if size <= 0: return '' data = self._file.read(size) self._crc = calc_crc(data, self._crc) self._bytes_left -= len(data) return data
def generate_fitfile(data=None, endian='<'): fit_data = ( generate_messages( # local mesg 0, global mesg 0 (file_id) mesg_num=0, local_mesg_num=0, endian=endian, field_defs=[ # serial number, time_created, manufacturer (3, 'uint32z'), (4, 'uint32'), (1, 'uint16'), # product/garmin_product, number, type (2, 'uint16'), (5, 'uint16'), (0, 'enum'), ], # random serial number, random time, garmin, edge500, null, activity data=[[558069241, 723842606, 1, 1036, (2 ** 16) - 1, 4]], ) ) if data: fit_data += data # Prototcol version 1.0, profile version 1.52 header = pack('<2BHI4s', 14, 16, 152, len(fit_data), b'.FIT') file_data = header + pack('<H', calc_crc(header)) + fit_data return file_data + pack('<H', calc_crc(file_data))
def fit_crc ( data ): return struct.pack('<H', calc_crc(data, 0))
def fit_crc(data): return struct.pack('<H', calc_crc(data, 0))