Skip to content

Commit

Permalink
Merge pull request #11 from JuliaMessaging/feature/add-gst
Browse files Browse the repository at this point in the history
update nmea types
  • Loading branch information
NickMcSweeney authored Mar 20, 2024
2 parents 34a8fdf + ef8091b commit 666e0fa
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "NMEAParser"
uuid = "e33883a1-8aa8-4e6e-a42d-0daf9e203b40"
authors = ["Nicholas Shindler <[email protected]>"]
version = "2.0.1"
version = "2.0.2"

[weakdeps]
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Expand Down
8 changes: 2 additions & 6 deletions src/NMEAParser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ 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 GGA, GSA, ZDA, GBS, GLL, GSV, GST, RMC, VTG, DTM
export PASHR, WPOS, WHPR, WVCT, WPLS, WWHE, WHPR, ACC, GYR

include("utils.jl")
include("types.jl")
Expand Down
32 changes: 22 additions & 10 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 All @@ -40,14 +41,13 @@ result = nmea_parse("\$GGA,123456,123.456,N,987.654,W,1,8,0.9,123.4,M,54.3,M,1,"
```
"""
function nmea_parse(nmea_string::AbstractString; validate_checksum = true)
function nmea_parse(nmea_string::T; validate_checksum = true) where { T <: AbstractString }
isempty(nmea_string) && throw(BoundsError("Input string is empty"))

message, checksum =
contains(nmea_string, "*") ? split(nmea_string, '*') : (nmea_string, 00)

valid =
validate_checksum ? Base.parse(UInt8, "0x$checksum") === hash_msg(message) : true
valid = validate_checksum ? Base.parse(UInt8, "0x$checksum") === hash_msg(message) : true

items = split(message, ',')
header = items |> first
Expand All @@ -58,6 +58,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)

"""
NMEAData()
Expand All @@ -69,6 +70,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 +82,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 +108,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 +125,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 +167,13 @@ function pop!(nmea_data::NMEAData, ::Type{GSV})
nmea_data.last_GSV = nothing
return last
end
function pop!(nmea_data::NMEAData, ::Type{GST})
last =
isnothing(nmea_data.last_GST) ? throw(UndefVarError("last_GST not defined")) :
nmea_data.last_GST
nmea_data.last_GST = nothing
return last
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 666e0fa

Please sign in to comment.