Properly reading the field definitions now.

This commit is contained in:
2023-04-26 07:47:55 -04:00
parent 475341ffb4
commit 27388ba049
+12 -4
View File
@@ -33,7 +33,7 @@ end
struct FieldDefinition struct FieldDefinition
number::UInt8 number::UInt8
sz_bytes::UInt8 sz_bytes::UInt8
base_type::AbstractString # Defined in mesg_num.jl base_type::UInt8 # TODO: This needs to be translated into an actual base type.
end end
mutable struct DefinitionBody mutable struct DefinitionBody
@@ -130,11 +130,16 @@ function decode_header(v::Vector{UInt8})::RecordHeader
record record
end end
"""
parse_field(bytes::Vector{UInt8})::FieldDefinition
Parse a field definition in the definition message into a struct
"""
function parse_field(bytes::Vector{UInt8})::FieldDefinition function parse_field(bytes::Vector{UInt8})::FieldDefinition
FieldDefinition( FieldDefinition(
bytes[1], bytes[1],
bytes[2], bytes[2],
get_field_definition_string(bytes[3]) bytes[3]
) )
end end
@@ -152,7 +157,7 @@ function read_record_content!(f::FITFileReader, hdr::RecordHeader)::Union{Defini
# Should always be a multiple of 3 # Should always be a multiple of 3
# TODO: There is a missing byte here that complicates parsing # TODO: There is a missing byte here that complicates parsing
field_definitions = [parse_field(def_header_bytes[i:i+2]) for i 1:3:length(def_header_fields)] field_definitions = [parse_field(def_header_fields[i:i+2]) for i 1:3:length(def_header_fields)]
# See if there is developer data # See if there is developer data
def_header_developer_flag = read_bytes!(f, 1) def_header_developer_flag = read_bytes!(f, 1)
@@ -227,7 +232,10 @@ function show(io::IO, ffr::FITFileReader)
end end
function show(io::IO, defbody::DefinitionBody) function show(io::IO, defbody::DefinitionBody)
println(io, "DefinitionBody(arch=$(defbody.architecture), global_type=$(defbody.global_mesg_type), num_fields=$(defbody.num_fields))") println(io, "DefinitionBody(arch=$(defbody.architecture),")
println(io, " global_type=$(defbody.global_mesg_type)")
println(io, " num_fields=$(defbody.num_fields)")
println(io, " field_defs=$(defbody.field_definitions))")
end end
end end