Added algorithm to read header
This commit is contained in:
@@ -3,6 +3,9 @@ uuid = "5099a4e5-7ef4-45c0-baf4-116637be075d"
|
|||||||
authors = ["Jake Windle"]
|
authors = ["Jake Windle"]
|
||||||
version = "1.0.0-DEV"
|
version = "1.0.0-DEV"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
BitConverter = "3a3ce9e8-98e7-11e9-0fa0-055639f146d3"
|
||||||
|
|
||||||
[compat]
|
[compat]
|
||||||
julia = "1"
|
julia = "1"
|
||||||
|
|
||||||
|
|||||||
+40
-2
@@ -1,13 +1,51 @@
|
|||||||
struct FITHeader
|
struct FITHeader
|
||||||
sz::UInt8
|
sz::UInt8
|
||||||
|
using Base: sizeof_ios_t
|
||||||
|
protocol::UInt8
|
||||||
|
version::AbstractVector{<:Real}
|
||||||
|
size::Real
|
||||||
|
type::AbstractVector{<:Real}
|
||||||
|
crc::AbstractVector{<:Real}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
"""
|
||||||
|
length in bytes
|
||||||
|
"""
|
||||||
|
const DATA_SIZE_LENGTH = 4
|
||||||
|
|
||||||
"""
|
"""
|
||||||
read_header(fit_file::IOStream)
|
read_header(fit_file::IOStream)
|
||||||
|
|
||||||
Read the header of the given fit file, and return a FITHeader struct
|
Read the header of the given fit file, and return a FITHeader struct
|
||||||
"""
|
"""
|
||||||
function read_header(fit_file::IOStream)::FITHeader
|
function read_header(fit_file::IOStream)::FITHeader
|
||||||
sz = read(fit_file, 1; all=false)
|
sz = read(fit_file, 1; all=false)[1]
|
||||||
FITHeader(sz[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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user