From 77262410123870a942746b81582b90477b981a34 Mon Sep 17 00:00:00 2001 From: jaketothepast Date: Wed, 26 Apr 2023 08:00:47 -0400 Subject: [PATCH] Read base types of field definitions --- src/base_types.jl | 29 +++++++++++++++++++++++++++++ src/file.jl | 8 ++++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/base_types.jl diff --git a/src/base_types.jl b/src/base_types.jl new file mode 100644 index 0000000..c8a60fd --- /dev/null +++ b/src/base_types.jl @@ -0,0 +1,29 @@ +module base_types + +export get_base_type + +BASE_TYPE_DICT = Dict( + 0x00 => Enum, + 0x01 => Int8, + 0x02 => UInt8, + 0x83 => Int16, + 0x84 => UInt16, + 0x85 => Int32, + 0x86 => UInt32, + 0x07 => AbstractString, + 0x88 => Float32, + 0x89 => Float64, + 0x0a => UInt8, #z? + 0x8b => UInt16, #z? + 0x8c => UInt32, #z? + 0x0d => UInt8, # Byte + 0x8e => Int64, + 0x8f => UInt64, + 0x90 => UInt64 #z? +) + +function get_base_type(num::UInt8)::Type + BASE_TYPE_DICT[num] +end + +end diff --git a/src/file.jl b/src/file.jl index da6a61b..7fe0ce0 100644 --- a/src/file.jl +++ b/src/file.jl @@ -6,7 +6,7 @@ export FITFile, read_file, DataRecord include("bytes.jl"); using .bytes include("mesg_num.jl"); using .mesg_num - +include("base_types.jl"); using .base_types HEADER_SZ = 14 @@ -33,7 +33,7 @@ end struct FieldDefinition number::UInt8 sz_bytes::UInt8 - base_type::UInt8 # TODO: This needs to be translated into an actual base type. + base_type::Type # TODO: This needs to be translated into an actual base type. end mutable struct DefinitionBody @@ -139,7 +139,7 @@ function parse_field(bytes::Vector{UInt8})::FieldDefinition FieldDefinition( bytes[1], bytes[2], - bytes[3] + get_base_type(bytes[3]) ) end @@ -235,7 +235,7 @@ function show(io::IO, defbody::DefinitionBody) 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))") + println(io, " field_defs=$(defbody.field_definitions)") end end \ No newline at end of file