Compare commits

...

2 Commits

Author SHA1 Message Date
Jacob Windle 977b9bf507 Use bit_at utility function 2023-04-21 07:14:55 -04:00
Jacob Windle 83c34dbe23 More utility functions 2023-04-21 07:14:40 -04:00
3 changed files with 21 additions and 8 deletions

View File

@ -8,8 +8,8 @@ import Base.show
export RecordHeader, read_row
include("mesg_num.jl")
using .mesg_num
include("bytes.jl"); using.bytes
include("mesg_num.jl"); using .mesg_num
struct DefinitionMessage end
struct DataMessage end
@ -21,6 +21,7 @@ The byte that corresponds to the type of message that this record holds.
"""
struct RecordHeader
definition_message::Bool
timestamp_message::Bool
end
@ -32,13 +33,11 @@ TODO: Endianness matters here. Need to resolve endianness with the architecture
"""
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)
RecordHeader(
bit_at(header_byte, 2),
bit_at(header_byte, 1))
end
function show(io::IO, header::RecordHeader)

View File

@ -1,3 +1,6 @@
module bytes
export byte_vec_to_int, byte_vec_to_string, bit_at
"""
read_data_size(size::Vector{UInt8})::Real
@ -23,4 +26,14 @@ function byte_vec_to_string(byte_vec::Vector{UInt8})::AbstractString
String(Char.(byte_vec))
end
"""
bit_at(byte::UInt8, idx::Int64; t::Type=Int64)::Int64
Parse the bit at specific index in byte
"""
function bit_at(byte::UInt8, idx::Int64; t::Type=Int64)::Int64
parse(t, bitstring(byte)[idx])
end
end
# byte_vec_to_string(UInt8.(collect("ABC")))

View File

@ -7,7 +7,8 @@
module header
export FITHeader, read_header
include("bytes.jl")
include("bytes.jl"); using .bytes
const DATA_SIZE_LENGTH = 4