From 9dd04d2cb113c5fa738179f90029fa27508f70e9 Mon Sep 17 00:00:00 2001 From: jaketothepast Date: Thu, 20 Apr 2023 16:01:36 -0400 Subject: [PATCH] Begin body reading code --- src/FIT.jl | 8 +++----- src/body.jl | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/file.jl | 24 ++++++++++++++++++++++++ src/functions.jl | 3 --- 4 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 src/body.jl create mode 100644 src/file.jl delete mode 100644 src/functions.jl diff --git a/src/FIT.jl b/src/FIT.jl index 198b399..cd100b2 100644 --- a/src/FIT.jl +++ b/src/FIT.jl @@ -1,11 +1,9 @@ module FIT -export greet_package -export read_header, FITHeader +export read_file -include("functions.jl") -include("header.jl") +include("file.jl") -using .header +using .file end diff --git a/src/body.jl b/src/body.jl new file mode 100644 index 0000000..684446e --- /dev/null +++ b/src/body.jl @@ -0,0 +1,48 @@ +""" +read the body of the FIT file. +""" +module body + +# TODO: Why do this? +import Base.show + +export RecordHeader, read_row + +include("mesg_num.jl") +using .mesg_num + +struct DefinitionMessage end +struct DataMessage end + +""" + RecordHeader + +The byte that corresponds to the type of message that this record holds. +""" +struct RecordHeader + definition_message::Bool +end + + +""" + read_row(f::io) + +Read a row of the file at a time. Parse the row into a data or def message. +TODO: Endianness matters here. Need to resolve endianness with the architecture bit. +""" +function read_row(f::IO) + header_byte = read(f, 1; all=false)[1] + println(bitstring(header_byte)) + + # The message byte is 7 + RecordHeader(Bool(parse(Int64, bitstring(header_byte)[2]))) +end + +function read_header_byte(f::Core.IO) +end + +function show(io::IO, header::RecordHeader) + println(io, header.definition_message ? "DefinitionMessage" : "DataMessage") +end + +end diff --git a/src/file.jl b/src/file.jl new file mode 100644 index 0000000..b7ee0e1 --- /dev/null +++ b/src/file.jl @@ -0,0 +1,24 @@ +module file + +export FITFile, read_file + +include("header.jl") +include("body.jl") + +using .header +using .body + +struct FITFile + header::FITHeader + body::RecordHeader +end + +function read_file(filepath::AbstractString)::FITFile + open(filepath, "r") do f + header = read_header(f) + body = read_row(f) + FITFile(header, body) + end +end + +end \ No newline at end of file diff --git a/src/functions.jl b/src/functions.jl deleted file mode 100644 index 2f44acf..0000000 --- a/src/functions.jl +++ /dev/null @@ -1,3 +0,0 @@ -function greet_package() - print("Hello package") -end