Begin body reading code

main
Jacob Windle 2023-04-20 16:01:36 -04:00
parent 219ec38e22
commit 9dd04d2cb1
4 changed files with 75 additions and 8 deletions

View File

@ -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

48
src/body.jl Normal file
View File

@ -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

24
src/file.jl Normal file
View File

@ -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

View File

@ -1,3 +0,0 @@
function greet_package()
print("Hello package")
end