Added algorithm to read header

main
Jacob Windle 2023-04-06 15:30:48 -04:00
parent a3ec238b38
commit ce7126b60e
2 changed files with 43 additions and 2 deletions

View File

@ -3,6 +3,9 @@ uuid = "5099a4e5-7ef4-45c0-baf4-116637be075d"
authors = ["Jake Windle"]
version = "1.0.0-DEV"
[deps]
BitConverter = "3a3ce9e8-98e7-11e9-0fa0-055639f146d3"
[compat]
julia = "1"

View File

@ -1,13 +1,51 @@
struct FITHeader
sz::UInt8
using Base: sizeof_ios_t
protocol::UInt8
version::AbstractVector{<:Real}
size::Real
type::AbstractVector{<:Real}
crc::AbstractVector{<:Real}
end
"""
length in bytes
"""
const DATA_SIZE_LENGTH = 4
"""
read_header(fit_file::IOStream)
Read the header of the given fit file, and return a FITHeader struct
"""
function read_header(fit_file::IOStream)::FITHeader
sz = read(fit_file, 1; all=false)
FITHeader(sz[1])
sz = read(fit_file, 1; all=false)[1]
protocol = read(fit_file, 1; all=false)[1]
version = read(fit_file, 2; all=false)
size = read_data_size!(read(fit_file, 4; all=false))
type = read(fit_file, 4; all=false)
crc = read(fit_file, 2; all=false)
FITHeader(sz, protocol, version, size, type, crc)
end
"""
read_data_size(size::Vector{UInt8})::Real
FIT headers have a data size field, with 4 bytes.
"""
function read_data_size!(size::Vector{UInt8})::Real
data_size::Int64 = 0
size = Int64.(size)
for i 0:length(size) - 1
data_size += size[1 + i] << (8 * i)
end
data_size
end
function test_read_header()
open("test.FIT", "r") do f
read_header(f)
end
end