Skip to content

Commit

Permalink
update nmea types
Browse files Browse the repository at this point in the history
  • Loading branch information
NickMcSweeney committed Mar 19, 2024
1 parent 34a8fdf commit f4ee37d
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 105 deletions.
6 changes: 1 addition & 5 deletions src/NMEAParser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ module NMEAParser
export NMEAData, parse_msg!, is_string_supported, update, nmea_parse
export NMEAString
export GGA, GSA, ZDA, GBS, GLL, GSV, RMC, VTG, DTM
export PASHR, PTWPOS, PTWHPR, PTWVCT, PTWPLS, PTWWHE, PTWHPR, PTACC, PTGYR

import Base.pop!
import Base.parse

export PASHR, WPOS, WHPR, WVCT, WPLS, WWHE, WHPR, ACC, GYR

include("utils.jl")
include("types.jl")
Expand Down
27 changes: 20 additions & 7 deletions src/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ const NMEA_TYPES = [
(r"GBS$", GBS),
(r"GLL$", GLL),
(r"GSV$", GSV),
(r"GST$", GST),
(r"RMC$", RMC),
(r"VTG$", VTG),
(r"ZDA$", ZDA),
(r"PASHR$", PASHR),
(r"PTWPOS$", PTWPOS),
(r"PTWVCT$", PTWVCT),
(r"PTWPLS$", PTWPLS),
(r"PTWWHE$", PTWWHE),
(r"PTWHPR$", PTWHPR),
(r"PTACC$", PTACC),
(r"PTGYR$", PTGYR),
(r"WPOS$", WPOS),
(r"WVCT$", WVCT),
(r"WPLS$", WPLS),
(r"WWHE$", WWHE),
(r"HPR$", WHPR),
(r"ACC$", ACC),
(r"GYR$", GYR),
]


Expand Down Expand Up @@ -58,6 +59,7 @@ function nmea_parse(nmea_string::AbstractString; validate_checksum = true)
throw(ArgumentError("NMEA string ($header) not supported"))
end

parse(nmea_string::AbstractString; validate_checksum = true) = nmea_parse(nmea_string, validate_checksum=validate_checksum)

Check warning on line 62 in src/parse.jl

View check run for this annotation

Codecov / codecov/patch

src/parse.jl#L62

Added line #L62 was not covered by tests

"""
NMEAData()
Expand All @@ -69,6 +71,7 @@ A mutable struct that stores the last parsed NMEA messages of different types.
- `last_RMC::Union{Nothing, RMC}`: the last RMC message parsed, or nothing if none
- `last_GSA::Union{Nothing, GSA}`: the last GSA message parsed, or nothing if none
- `last_GSV::Union{Nothing, GSV}`: the last GSV message parsed, or nothing if none
- `last_GST::Union{Nothing, GST}`: the last GST message parsed, or nothing if none
- `last_GBS::Union{Nothing, GBS}`: the last GBS message parsed, or nothing if none
- `last_VTG::Union{Nothing, VTG}`: the last VTG message parsed, or nothing if none
- `last_GLL::Union{Nothing, GLL}`: the last GLL message parsed, or nothing if none
Expand All @@ -80,6 +83,7 @@ mutable struct NMEAData
last_RMC::Union{Nothing,RMC}
last_GSA::Union{Nothing,GSA}
last_GSV::Union{Nothing,GSV}
last_GST::Union{Nothing,GST}
last_GBS::Union{Nothing,GBS}
last_VTG::Union{Nothing,VTG}
last_GLL::Union{Nothing,GLL}
Expand All @@ -105,6 +109,7 @@ update!(s::NMEAData, msg::GGA) = s.last_GGA = msg
update!(s::NMEAData, msg::RMC) = s.last_RMC = msg
update!(s::NMEAData, msg::GSA) = s.last_GSA = msg
update!(s::NMEAData, msg::GSV) = s.last_GSV = msg
update!(s::NMEAData, msg::GST) = s.last_GST = msg
update!(s::NMEAData, msg::GBS) = s.last_GBS = msg
update!(s::NMEAData, msg::VTG) = s.last_VTG = msg
update!(s::NMEAData, msg::GLL) = s.last_GLL = msg
Expand All @@ -121,6 +126,7 @@ update(msg::GGA, s::NMEAData) = (s.last_GGA = msg; s)
update(msg::RMC, s::NMEAData) = (s.last_RMC = msg; s)
update(msg::GSA, s::NMEAData) = (s.last_GSA = msg; s)
update(msg::GSV, s::NMEAData) = (s.last_GSV = msg; s)
update(msg::GST, s::NMEAData) = (s.last_GST = msg; s)
update(msg::GBS, s::NMEAData) = (s.last_GBS = msg; s)
update(msg::VTG, s::NMEAData) = (s.last_VTG = msg; s)
update(msg::GLL, s::NMEAData) = (s.last_GLL = msg; s)
Expand Down Expand Up @@ -162,6 +168,13 @@ function pop!(nmea_data::NMEAData, ::Type{GSV})
nmea_data.last_GSV = nothing
return last
end
function pop!(nmea_data::NMEAData, ::Type{GST})
last =

Check warning on line 172 in src/parse.jl

View check run for this annotation

Codecov / codecov/patch

src/parse.jl#L171-L172

Added lines #L171 - L172 were not covered by tests
isnothing(nmea_data.last_GST) ? throw(UndefVarError("last_GST not defined")) :
nmea_data.last_GST
nmea_data.last_GST = nothing
return last

Check warning on line 176 in src/parse.jl

View check run for this annotation

Codecov / codecov/patch

src/parse.jl#L175-L176

Added lines #L175 - L176 were not covered by tests
end
function pop!(nmea_data::NMEAData, ::Type{GBS})
last =
isnothing(nmea_data.last_GBS) ? throw(UndefVarError("last_GBS not defined")) :
Expand Down
Loading

0 comments on commit f4ee37d

Please sign in to comment.