From 475341ffb4df574a7aa3d255fe00eeae18c21928 Mon Sep 17 00:00:00 2001 From: jaketothepast Date: Tue, 25 Apr 2023 09:09:32 -0400 Subject: [PATCH] Trying to parse field definitions --- src/file.jl | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/file.jl b/src/file.jl index f0dfc8f..0bd01ff 100644 --- a/src/file.jl +++ b/src/file.jl @@ -30,10 +30,17 @@ mutable struct RecordHeader local_mesg_type::Int64 end +struct FieldDefinition + number::UInt8 + sz_bytes::UInt8 + base_type::AbstractString # Defined in mesg_num.jl +end + mutable struct DefinitionBody architecture::AbstractString global_mesg_type::AbstractString # Read from mesg_num.jl using the bytes in this field. num_fields::UInt8 + field_definitions::Vector{FieldDefinition} end mutable struct DataBody @@ -123,6 +130,14 @@ function decode_header(v::Vector{UInt8})::RecordHeader record end +function parse_field(bytes::Vector{UInt8})::FieldDefinition + FieldDefinition( + bytes[1], + bytes[2], + get_field_definition_string(bytes[3]) + ) +end + """ read_record_content!(f::FITFileReader, hdr::RecordHeader)::Union{DefinitionBody, DataBody} @@ -134,7 +149,11 @@ function read_record_content!(f::FITFileReader, hdr::RecordHeader)::Union{Defini # Read the fixed 5 bytes first. def_header_bytes = read_bytes!(f, 5) def_header_fields = read_bytes!(f, def_header_bytes[end] * 3) - + + # Should always be a multiple of 3 + # 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)] + # See if there is developer data def_header_developer_flag = read_bytes!(f, 1) if def_header_developer_flag[1] > 0x00 @@ -148,7 +167,8 @@ function read_record_content!(f::FITFileReader, hdr::RecordHeader)::Union{Defini DefinitionBody( def_header_bytes[2] == 0 ? "littleendian" : "bigendian", global_mesg_type, - def_header_bytes[end] + def_header_bytes[end], + field_definitions ) end end