Created
October 27, 2023 07:30
-
-
Save perillo/8bccfc210b0e848532173720868046e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_fit_header(path): | |
"""read_fit_header returns the FIT file header. | |
The FIT SDK has the `Decoder.read_file_header` method, but it cannot be | |
used because a local object can not be pickled and only the major version | |
is used, for both protocol_version and profile_version. | |
""" | |
stream = Stream.from_file(path) | |
header = {} | |
header["header_size"] = stream.read_byte() | |
protocol_version = stream.read_byte() | |
profile_version = stream.read_unint_16("little") | |
header["data_size"] = stream.read_unint_32("little") | |
data_type = stream.read_string(4)[0] | |
header["header_crc"] = 0 | |
header["file_total_size"] = header["header_size"] + header["data_size"] | |
header["protocol_version"] = (protocol_version >> 4, protocol_version & 0x0F) | |
header["profile_version"] = (profile_version // 100, profile_version % 100) | |
header["data_type"] = data_type.decode("utf") | |
if header["header_size"] == 14: | |
header["header_crc"] = stream.read_unint_16("little") | |
return header |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment