More cleanup, seemingly reading timestamp headers now
This commit is contained in:
+23
-7
@@ -33,6 +33,7 @@ Contains the header byte for a record row
|
|||||||
mutable struct RecordHeader
|
mutable struct RecordHeader
|
||||||
type::RecordType
|
type::RecordType
|
||||||
local_mesg_type::Int64
|
local_mesg_type::Int64
|
||||||
|
time_offset::Union{Nothing, Int64}
|
||||||
end
|
end
|
||||||
|
|
||||||
struct FieldDefinition
|
struct FieldDefinition
|
||||||
@@ -48,6 +49,16 @@ mutable struct DefinitionBody
|
|||||||
field_definitions::Vector{FieldDefinition}
|
field_definitions::Vector{FieldDefinition}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
"""
|
||||||
|
LocalMesgTypeMapping
|
||||||
|
|
||||||
|
For use in mapping local message type to a struct containing useful info.
|
||||||
|
"""
|
||||||
|
struct LocalMesgTypeMapping
|
||||||
|
row_sz::Int64
|
||||||
|
global_mesg_type::AbstractString
|
||||||
|
end
|
||||||
|
|
||||||
mutable struct DataBody
|
mutable struct DataBody
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -67,7 +78,7 @@ mutable struct FITFileReader
|
|||||||
bytes_read::Int64
|
bytes_read::Int64
|
||||||
header::Union{FITHeader, Nothing}
|
header::Union{FITHeader, Nothing}
|
||||||
body::Union{Vector{DataRecord}, Nothing}
|
body::Union{Vector{DataRecord}, Nothing}
|
||||||
mesg_map::Dict{Real, AbstractString}
|
mesg_map::Dict{Real, LocalMesgTypeMapping}
|
||||||
next_row_sz::Int64
|
next_row_sz::Int64
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -128,16 +139,22 @@ end
|
|||||||
Decode the header byte, determine if the record is a definition, data, or timestamp.
|
Decode the header byte, determine if the record is a definition, data, or timestamp.
|
||||||
"""
|
"""
|
||||||
function decode_header(v::Vector{UInt8})::RecordHeader
|
function decode_header(v::Vector{UInt8})::RecordHeader
|
||||||
type = if v[7] == 1
|
type = if v[8] == 1
|
||||||
timestamp
|
timestamp
|
||||||
elseif v[6] == 1
|
elseif v[7] == 1
|
||||||
definition
|
definition
|
||||||
else
|
else
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if type == timestamp
|
||||||
|
local_mesg_type = sum_bits(v[6:7])
|
||||||
|
time_offset = sum_bits(v[1:5])
|
||||||
|
RecordHeader(type, local_mesg_type, time_offset)
|
||||||
|
else
|
||||||
local_mesg_type = sum_bits(v[1:4])
|
local_mesg_type = sum_bits(v[1:4])
|
||||||
RecordHeader(type, local_mesg_type)
|
RecordHeader(type, local_mesg_type, nothing)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -165,7 +182,7 @@ Using f, read the appropriate message body given the hdr (which tells us if this
|
|||||||
"""
|
"""
|
||||||
function read_record_content!(f::FITFileReader, hdr::RecordHeader)::Union{DefinitionBody, DataBody}
|
function read_record_content!(f::FITFileReader, hdr::RecordHeader)::Union{DefinitionBody, DataBody}
|
||||||
# Read the definition record, return the body
|
# Read the definition record, return the body
|
||||||
if hdr.definition
|
if hdr.type == definition
|
||||||
# Read all bytes first
|
# Read all bytes first
|
||||||
header_bytes = read_bytes!(f, 5)
|
header_bytes = read_bytes!(f, 5)
|
||||||
header_field_definitions = read_bytes!(f, header_bytes[end] * 3) # sz * field size
|
header_field_definitions = read_bytes!(f, header_bytes[end] * 3) # sz * field size
|
||||||
@@ -185,8 +202,7 @@ function read_record_content!(f::FITFileReader, hdr::RecordHeader)::Union{Defini
|
|||||||
row_sz = sum(get_row_size.([field_definitions, developer_field_definitions]))
|
row_sz = sum(get_row_size.([field_definitions, developer_field_definitions]))
|
||||||
|
|
||||||
# Associate the global message type with this local message type.
|
# Associate the global message type with this local message type.
|
||||||
f.mesg_map[hdr.local_mesg_type] = global_mesg_type
|
f.mesg_map[hdr.local_mesg_type] = LocalMesgTypeMapping(row_sz, global_mesg_type)
|
||||||
f.next_row_sz = row_sz
|
|
||||||
|
|
||||||
DefinitionBody(
|
DefinitionBody(
|
||||||
header_bytes[2] == 0 ? "littleendian" : "bigendian",
|
header_bytes[2] == 0 ? "littleendian" : "bigendian",
|
||||||
|
|||||||
Reference in New Issue
Block a user