Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for TagBlocks #59

Closed
wants to merge 10 commits into from
Closed

Added support for TagBlocks #59

wants to merge 10 commits into from

Conversation

klyve
Copy link
Contributor

@klyve klyve commented Aug 3, 2019

Satellites and some sources apply a tag block to the messages.
TagBlock is now parsed before any other messages and is a part of BaseSentence

Tagblocks:
https://www.nmea.org/Assets/may%2009%20rtcm%200183_v400.pdf
https://rietman.wordpress.com/2016/09/17/nemastudio-now-supports-the-nmea-0183-tag-block/

TagBlock is now parsed before any other messages and is a part of BaseSentence
@coveralls
Copy link

coveralls commented Aug 3, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 1270711 on klyve:master into d0c0080 on adrianmo:master.

Arxcis
Arxcis previously approved these changes Aug 3, 2019
tagblock.go Outdated Show resolved Hide resolved
sentence.go Outdated Show resolved Hide resolved
tagblock.go Outdated Show resolved Hide resolved
tagblock.go Outdated Show resolved Hide resolved
tagblock.go Outdated Show resolved Hide resolved
tagblock.go Outdated Show resolved Hide resolved
tagblock.go Outdated Show resolved Hide resolved
tagblock_test.go Outdated Show resolved Hide resolved
tagblock.go Outdated Show resolved Hide resolved
TypeSourceID = "s"
// TypeTextString valid character string, parameter -t
TypeTextString = "t"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need these constants in the public API. Since they're only used in the one spot, I think it would be better to just inline them into the switch.

Move the comments from these types to the TagBlock struct fields.

}

// Timestamp can come as milliseconds or seconds
func validUnixTimestamp(timestamp int64) (int64, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems hacky. I think we should leave it up to the user of the package to know what units their device is emitting. I'd prefer to just pass along the value we receive instead of trying to be clever with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

There was some debate about how to handle this on the gpsd mailing list. ESR's document (https://gpsd.gitlab.io/gpsd/AIVDM.html) says:

As of May 2014 no NMEA 4.10 relative time fields have been observed in the wild. It is unknown whether the unit is seconds or milliseconds.

I've worked with tagblock timestamps from AISHub.net, as well as a commercial satellite AIS provider, and so far have only seen seconds, never milliseconds. In light of this, beyond agreeing with @icholy about just passing the value along as an int64, I'd suggest documenting that the value should be seconds, not milliseconds (but warn the user that YMMV).


items := strings.Split(tags[:sumSepIndex], ",")
for _, item := range items {
if len(item) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be if len(item) < 2 { ?

Actually, I think a cleaner way would be to just use strings.Split on it.

parts := strings.SplitN(item, ":", 2)
if len(parts) != 2 {
	continue
}
key, value := parts[0], parts[1]

Text: "helloworld",
LineCount: 13,
},
//err: "nmea: tagblock checksum mismatch [25 != 49]",
Copy link
Collaborator

@icholy icholy Aug 8, 2019

Choose a reason for hiding this comment

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

don't commit commented-out code

case TypeUnixTime:
tagBlock.Time, err = parseInt64(item)
if err != nil {
return tagBlock, raw, err
Copy link
Collaborator

Choose a reason for hiding this comment

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

return "" instead of raw and TagBlock{} instead of the partially constructed tagBlock variable. This makes it explicit that these aren't being used by the caller. Do this at all the other error returns too.

@adrianmo
Copy link
Owner

@klyve thanks a lot for the contribution, you did a great job adding support for the TagBlock! The PR has been inactive for quite some time and I was wondering if you would be willing to address @icholy comments (and maybe a few more review rounds) and eventually get it merged. If you don't have cycles or are not interested anymore please let us know and I'll probably take over the work. Thanks you!

adrianmo and others added 3 commits February 13, 2020 11:02
Signed-off-by: Adrián Moreno <adrian@morenomartinez.com>
* 'master' of github.com:klyve/go-nmea:
  Fix checksum ref after branch update
  Correct copy paste typo
  Add VHW water speed and heading
  functions returning a direction sign have been added
  added latitude range checking
  added estimated fix which is returned by MTK3339
  add mtk test
  expose xorChecksum
  revert xorChecksum expose
  use the parser
  att support for parsing MTK commands and update go mod files
simeonmiteff added a commit to starboard-nz/go-nmea that referenced this pull request Aug 19, 2020
simeonmiteff added a commit to starboard-nz/go-nmea that referenced this pull request Aug 19, 2020
simeonmiteff added a commit to starboard-nz/go-nmea that referenced this pull request Aug 19, 2020
simeonmiteff added a commit to starboard-nz/go-nmea that referenced this pull request Aug 19, 2020
simeonmiteff added a commit to starboard-nz/go-nmea that referenced this pull request Aug 19, 2020
@simeonmiteff
Copy link
Contributor

@adrianmo @klyve in the interest of getting this very useful code merged, we have implemented the requested changes in a fork: https://github.com/xerra-eo/go-nmea

What would be the best way to proceed? A new PR?

@icholy
Copy link
Collaborator

icholy commented Aug 19, 2020

@simeonmiteff yes

@icholy icholy closed this Aug 19, 2020
adrianmo added a commit that referenced this pull request Aug 26, 2020
* Added support for TagBlocks
TagBlock is now parsed before any other messages and is a part of BaseSentence

* Added tests for linecount and relative time

* Early exit if no matches in tagblock

* Fixed PR comments

* Renamed parseUint to parseInt64

* Added validation for timestamp according to nmea spec

* changed go mod to fork

* Fix checksum ref after branch update

Signed-off-by: Adrián Moreno <adrian@morenomartinez.com>

* Remove tag string constants

Addresses #59 (comment)

* Pass through timestamp, don't try to normalise

Addresses #59 (comment)

* Clean up tag key/value parsing

Addresses #59 (comment)

* Remove commented code

Addresses #59 (comment)

* Explicitly blank values on error returns

Addresses #59 (comment)

* Revert module name to github.com/adrianmo/go-nmea

* Update readme: note tag blocks feature and code example

* Reference better resource for TAG Blocks info

Addresses #78 (comment)

* Make a malformatted field and error

Addresses #78 (comment)

* Remove blank lines

Adresses #78 (comment)

* Find tag block with strings.SplitN instead of regexp

Addresses #78 (comment)

* Strip tagblocks in parseSentence, remove prefix support

* Add tagblock parsing tests for parseSentence()

* Test parseTagblock directly (without the full sentence)

Co-authored-by: Bjarte Klyve Larsen <bjarteklarsen@gmail.com>
Co-authored-by: bjarte <bjarte@maritimeoptima.com>
Co-authored-by: Adrián Moreno <adrian@morenomartinez.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants