Skip to content

Commit

Permalink
Merge pull request #12 from JuliaMessaging/feature/type-safe
Browse files Browse the repository at this point in the history
Feature/type safe
  • Loading branch information
NickMcSweeney authored Apr 11, 2024
2 parents 666e0fa + 0d06068 commit 35a03f4
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 138 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.2"
version = "2.1.0"

[weakdeps]
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Expand Down
28 changes: 14 additions & 14 deletions src/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function nmea_parse(nmea_string::T; validate_checksum = true) where { T <: Abstr

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

items = split(message, ',')
items = split(message, ',', keepempty=true)
header = items |> first
system = header |> get_system

Expand Down Expand Up @@ -136,75 +136,75 @@ update(msg::DTM, s::NMEAData) = (s.last_DTM = msg; s)
pop!(nmea_data::NMEAData, ::Type{T}) where T <: NMEAString
Pop the last received message of type T from the NMEAData object nmea_data and return it.
If no message of type T has been received, throw an UndefVarError.
If no message of type T has been received, throw an MissingException.
This function extends the Base.pop! function for NMEAData objects.
"""
function pop!(nmea_data::NMEAData, ::Type{GGA})
function pop!(nmea_data::NMEAData, ::Type{GGA})::GGA
last =
isnothing(nmea_data.last_GGA) ? throw(UndefVarError("last_GGA not defined")) :
nmea_data.last_GGA
(isnothing(nmea_data.last_GGA) ? throw(MissingException("last_GGA not defined")) :
nmea_data.last_GGA)::GGA
nmea_data.last_GGA = nothing
return last
end
function pop!(nmea_data::NMEAData, ::Type{RMC})
last =
isnothing(nmea_data.last_RMC) ? throw(UndefVarError("last_RMC not defined")) :
isnothing(nmea_data.last_RMC) ? throw(MissingException("last_RMC not defined")) :
nmea_data.last_RMC
nmea_data.last_RMC = nothing
return last
end
function pop!(nmea_data::NMEAData, ::Type{GSA})
last =
isnothing(nmea_data.last_GSA) ? throw(UndefVarError("last_GSA not defined")) :
isnothing(nmea_data.last_GSA) ? throw(MissingException("last_GSA not defined")) :
nmea_data.last_GSA
nmea_data.last_GSA = nothing
return last
end
function pop!(nmea_data::NMEAData, ::Type{GSV})
last =
isnothing(nmea_data.last_GSV) ? throw(UndefVarError("last_GSV not defined")) :
isnothing(nmea_data.last_GSV) ? throw(MissingException("last_GSV not defined")) :
nmea_data.last_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")) :
isnothing(nmea_data.last_GST) ? throw(MissingException("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")) :
isnothing(nmea_data.last_GBS) ? throw(MissingException("last_GBS not defined")) :
nmea_data.last_GBS
nmea_data.last_GBS = nothing
return last
end
function pop!(nmea_data::NMEAData, ::Type{VTG})
last =
isnothing(nmea_data.last_VTG) ? throw(UndefVarError("last_VTG not defined")) :
isnothing(nmea_data.last_VTG) ? throw(MissingException("last_VTG not defined")) :
nmea_data.last_VTG
nmea_data.last_VTG = nothing
return last
end
function pop!(nmea_data::NMEAData, ::Type{GLL})
last =
isnothing(nmea_data.last_GLL) ? throw(UndefVarError("last_GLL not defined")) :
isnothing(nmea_data.last_GLL) ? throw(MissingException("last_GLL not defined")) :
nmea_data.last_GLL
nmea_data.last_GLL = nothing
return last
end
function pop!(nmea_data::NMEAData, ::Type{ZDA})
last =
isnothing(nmea_data.last_ZDA) ? throw(UndefVarError("last_ZDA not defined")) :
isnothing(nmea_data.last_ZDA) ? throw(MissingException("last_ZDA not defined")) :
nmea_data.last_ZDA
nmea_data.last_ZDA = nothing
return last
end
function pop!(nmea_data::NMEAData, ::Type{DTM})
last =
isnothing(nmea_data.last_DTM) ? throw(UndefVarError("last_DTM not defined")) :
isnothing(nmea_data.last_DTM) ? throw(MissingException("last_DTM not defined")) :
nmea_data.last_DTM
nmea_data.last_DTM = nothing
return last
Expand Down
Loading

2 comments on commit 35a03f4

@NickMcSweeney
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

parser is type stable (tested with JET.jl)

Changes

  • created _to_int and _to_float helper functions to reduce code duplication
  • added default returns for _hms_to_secs and _dms_to_dd
  • changed array value lookups to use get function with a default return
  • fixed RMC type to align with nmea docs for GP and GN systems
  • fixed bad exception type in pop! function
  • improved GSA satellite list mapping
  • added more proprietary types

Notes & todos

  • the checksum/hash function is very expensive and has significant performance impact. still needs to get some optimization. if its not needed call nmea_parse(str, validate_checksum=false) to skip validation.
  • proprietary types are just being added to the base package. ideally they should be broken into sub-modules so they are not automatically included.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/104986

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.1.0 -m "<description of version>" 35a03f4023b6624c369dc7a4eff61f070ce16ef8
git push origin v2.1.0

Please sign in to comment.