{"id":13367122,"url":"https://github.com/adrianmo/Go-nmea","last_synced_at":"2025-03-12T18:31:58.979Z","repository":{"id":35236521,"uuid":"39495964","full_name":"adrianmo/go-nmea","owner":"adrianmo","description":"A NMEA parser library in pure Go","archived":false,"fork":false,"pushed_at":"2024-08-12T16:23:21.000Z","size":444,"stargazers_count":219,"open_issues_count":1,"forks_count":77,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-08-12T19:01:59.230Z","etag":null,"topics":["go","golang","gps","nmea","nmea-library","nmea-parser"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adrianmo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-22T08:55:54.000Z","updated_at":"2024-08-12T16:23:25.000Z","dependencies_parsed_at":"2024-06-18T12:38:33.362Z","dependency_job_id":"7b811bfc-2470-4665-96c9-ef7c8e07ebf5","html_url":"https://github.com/adrianmo/go-nmea","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianmo%2Fgo-nmea","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianmo%2Fgo-nmea/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianmo%2Fgo-nmea/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrianmo%2Fgo-nmea/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adrianmo","download_url":"https://codeload.github.com/adrianmo/go-nmea/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221309923,"owners_count":16795832,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","gps","nmea","nmea-library","nmea-parser"],"created_at":"2024-07-30T00:01:39.106Z","updated_at":"2025-03-12T18:31:58.970Z","avatar_url":"https://github.com/adrianmo.png","language":"Go","funding_links":[],"categories":["文本处理","文本處理"],"sub_categories":["高级控制台界面","高級控制台界面"],"readme":"# go-nmea\n\n[![CI](https://github.com/adrianmo/go-nmea/actions/workflows/ci.yml/badge.svg)](https://github.com/adrianmo/go-nmea/actions/workflows/ci.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/adrianmo/go-nmea)](https://goreportcard.com/report/github.com/adrianmo/go-nmea) [![Coverage Status](https://coveralls.io/repos/adrianmo/go-nmea/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/adrianmo/go-nmea?branch=master) [![GoDoc](https://godoc.org/github.com/adrianmo/go-nmea?status.svg)](https://godoc.org/github.com/adrianmo/go-nmea)\n\nThis is a NMEA library for the Go programming language (Golang).\n\n## Features\n\n- Parse individual NMEA 0183 sentences\n- Support for sentences with NMEA 4.10 \"TAG Blocks\"\n- Register custom parser for unsupported sentence types\n- User-friendly MIT license\n\n## Installing\n\nTo install go-nmea use `go get`:\n\n```\ngo get github.com/adrianmo/go-nmea\n```\n\nThis will then make the `github.com/adrianmo/go-nmea` package available to you.\n\n### Staying up to date\n\nTo update go-nmea to the latest version, use `go get -u github.com/adrianmo/go-nmea`.\n\n## Supported sentences\n\nSentence with link is supported by this library. NMEA0183 sentences list is based\non [IEC 61162-1:2016 (Edition 5.0 2016-08)](https://webstore.iec.ch/publication/25754) table of contents.\n\n| Sentence           | Description                                                         | References                                                                                     |\n|--------------------|---------------------------------------------------------------------|------------------------------------------------------------------------------------------------|\n| [AAM](./aam.go)    | Waypoint arrival alarm                                              | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_aam_waypoint_arrival_alarm)                      |\n| ABK                | AIS addressed and binary broadcast acknowledgement                  |                                                                                                |\n| [ABM](./abm.go)    | AIS addressed binary and safety related message                     |                                                                                                |\n| ACA                | AIS channel assignment message                                      |                                                                                                |\n| [ACK](./ack.go)    | Acknowledge alarm                                                   |                                                                                                |\n| [ACN](./acn.go)    | Alert command                                                       |                                                                                                |\n| ACS                | AIS channel management information source                           |                                                                                                |\n| AIR                | AIS interrogation request                                           |                                                                                                |\n| AKD                | Acknowledge detail alarm condition                                  |                                                                                                |\n| [ALA](./ala.go)    | Report detailed alarm condition                                     |                                                                                                |\n| [ALC](./alc.go)    | Cyclic alert list                                                   |                                                                                                |\n| [ALF](./alf.go)    | Alert sentence                                                      |                                                                                                |\n| [ALR](./alr.go)    | Set alarm state                                                     |                                                                                                |\n| [APB](./apb.go)    | Heading/track controller (autopilot) sentence B                     | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_apb_autopilot_sentence_b)                        |\n| [ARC](./arc.go)    | Alert command refused                                               |                                                                                                |\n| [BBM](./bbm.go)    | AIS broadcast binary message                                        |                                                                                                |\n| [BEC](./bec.go)    | Bearing and distance to waypoint, Dead reckoning                    | [1](http://www.nmea.de/nmea0183datensaetze.html#bec)                                           |\n| [BOD](./bod.go)    | Bearing origin to destination                                       | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_bod_bearing_waypoint_to_waypoint)                |\n| [BWC](./bwc.go)    | Bearing and distance to waypoint, Great circle                      | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_bwc_bearing_distance_to_waypoint_great_circle)   |\n| [BWR](./bwr.go)    | Bearing and distance to waypoint, Rhumb line                        | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_bwr_bearing_and_distance_to_waypoint_rhumb_line) |\n| [BWW](./bww.go)    | Bearing waypoint to waypoint                                        | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_bww_bearing_waypoint_to_waypoint)                |\n| CUR                | Water current layer, Multi-layer water current data                 |                                                                                                |\n| [DBK](./dbk.go)    | Depth Below Keel (obsolete, use DPT instead)                        | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_dbk_depth_below_keel)                            |\n| [DBS](./dbs.go)    | Depth below transducer                                              | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_dbs_depth_below_surface)                         |\n| [DBT](./dbt.go)    | Depth below transducer                                              | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_dbt_depth_below_transducer)                      |\n| DDC                | Display dimming control                                             |                                                                                                |\n| [DOR](./dor.go)    | Door status detection                                               |                                                                                                |\n| [DPT](./dpt.go)    | Depth                                                               | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_dpt_depth_of_water)                              |\n| [DSC](./dsc.go)    | Digital selective calling information                               |                                                                                                |\n| [DSE](./dse.go)    | Expanded digital selective calling                                  |                                                                                                |\n| [DTM](./dtm.go)    | Datum reference                                                     | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_dtm_datum_reference)                             |\n| EPV                | Command or report equipment property value                          |                                                                                                |\n| ETL                | Engine telegraph operation status                                   |                                                                                                |\n| [EVE](./eve.go)    | General event message                                               |                                                                                                |\n| [FIR](./fir.go)    | Fire detection                                                      |                                                                                                |\n| FSI                | Frequency set information                                           |                                                                                                |\n| GBS                | GNSS satellite fault detection                                      |                                                                                                |\n| GEN                | Generic binary information                                          |                                                                                                |\n| GFA                | GNSS fix accuracy and integrity                                     |                                                                                                |\n| [GGA](./gga.go)    | Global positioning system (GPS) fix data                            | [1](http://aprs.gids.nl/nmea/#gga)                                                             |\n| [GLL](./gll.go)    | Geographic position, Latitude/longitude                             | [1](http://aprs.gids.nl/nmea/#gll)                                                             |\n| [GNS](./gns.go)    | GNSS fix data                                                       | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_gns_fix_data)                                    |\n| GRS                | GNSS range residuals                                                |                                                                                                |\n| [GSA](./gsa.go)    | GNSS DOP and active satellites                                      | [1](http://aprs.gids.nl/nmea/#gsa)                                                             |\n| GST                | GNSS pseudorange noise statistics                                   |                                                                                                |\n| [GSV](./gsv.go)    | GNSS satellites in view                                             | [1](http://aprs.gids.nl/nmea/#gsv)                                                             |\n| [HBT](./hbt.go)    | Heartbeat supervision sentence                                      |                                                                                                |\n| HCR                | Heading correction report                                           |                                                                                                |\n| [HDG](./hdg.go)    | Heading, deviation and variation                                    | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_hdg_heading_deviation_variation)                 |\n| HDM                | Heading - Magnetic                                                  | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_hdm_heading_magnetic)                            |\n| [HDT](./hdt.go)    | Heading true                                                        | [gpsd](http://aprs.gids.nl/nmea/#hdt)                                                          |\n| HMR                | Heading monitor receive                                             |                                                                                                |\n| HMS                | Heading monitor set                                                 |                                                                                                |\n| HRM                | heel angle, roll period and roll amplitude measurement device       |                                                                                                |\n| [HSC](./hsc.go)    | Heading steering command                                            | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_hsc_heading_steering_command)                    |\n| HSS                | Hull stress surveillance systems                                    |                                                                                                |\n| HTC                | Heading/track control command                                       |                                                                                                |\n| HTD                | Heading /track control data                                         |                                                                                                |\n| KLDS               | Kenwood LMR - FleetSync AVL                                         |                                                                                                |\n| KLID               | Kenwood LMR - FleetSync                                             |                                                                                                |\n| KLSH               | Kenwood LMR - FleetSync AVL                                         |                                                                                                |\n| KNDS               | Kenwood LMR - Digital AVL                                           |                                                                                                |\n| KNID               | Kenwood LMR - Digital                                               |                                                                                                |\n| KNSH               | Kenwood LMR - Digital AVL                                           |                                                                                                |\n| KWDWPL             | Kenwood Waypoint Location - Amateur Radio                           | [direwolf](https://github.com/wb2osz/direwolf/blob/master/src/waypoint.c)                      |\n| LR1                | AIS long-range reply sentence 1                                     |                                                                                                |\n| LR2                | AIS long-range reply sentence 2                                     |                                                                                                |\n| LR3                | AIS long-range reply sentence 3                                     |                                                                                                |\n| LRF                | AIS long-range function                                             |                                                                                                |\n| LRI                | AIS long-range interrogation                                        |                                                                                                |\n| [MDA](./mda.go)    | Meteorological Composite                                            | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_mda_meteorological_composite)                    |\n| [MTA](./mta.go)    | Air Temperature (obsolete, use XDR instead)                         |                                                                                                |\n| MOB                | Man over board notification                                         |                                                                                                |\n| MSK                | MSK receiver interface                                              |                                                                                                |\n| MSS                | MSK receiver signal status                                          |                                                                                                |\n| [MTW](./mtw.go)    | Water temperature                                                   | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_mtw_mean_temperature_of_water)                   |\n| [MWD](./mwd.go)    | Wind direction and speed                                            | [1](https://www.tronico.fi/OH6NT/docs/NMEA0183.pdf)                                            |\n| [MWV](./mwv.go)    | Wind speed and angle                                                | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_mwv_wind_speed_and_angle)                        |\n| NAK                | Negative acknowledgement                                            |                                                                                                |\n| NRM                | NAVTEX receiver mask                                                |                                                                                                |\n| NRX                | NAVTEX received message                                             |                                                                                                |\n| NSR                | Navigation status report                                            |                                                                                                |\n| [OSD](./osd.go)    | Own ship data                                                       | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_osd_own_ship_data)                               |\n| POS                | Device position and ship dimensions report or configuration command |                                                                                                |\n| PRC                | Propulsion remote control status                                    |                                                                                                |\n| RLM                | Return link message                                                 |                                                                                                |\n| RMA                | Recommended minimum specific LORAN-C data                           |                                                                                                |\n| [RMB](./rmb.go)    | Recommended minimum navigation information                          | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_rmb_recommended_minimum_navigation_information)  |\n| [RMC](./rmc.go)    | Recommended minimum specific GNSS data                              | [1](http://aprs.gids.nl/nmea/#rmc)                                                             |\n| ROR                | Rudder order status                                                 |                                                                                                |\n| [ROT](./rot.go)    | Rate of turn                                                        | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_rot_rate_of_turn)                                |\n| RRT                | Report route transfer                                               |                                                                                                |\n| [RPM](./rpm.go)    | Revolutions                                                         | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_rpm_revolutions)                                 |\n| [RSA](./rsa.go)    | Rudder sensor angle                                                 | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_rsa_rudder_sensor_angle)                         |\n| [RSD](./rsd.go)    | Radar system data                                                   | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_rsd_radar_system_data)                           |\n| [RTE](./rte.go)    | Routes                                                              | [1](http://aprs.gids.nl/nmea/#rte)                                                             |\n| SFI                | Scanning frequency information                                      |                                                                                                |\n| SMI                | SafetyNET Message, All Ships/NavArea                                |                                                                                                |\n| SM2                | SafetyNET Message, Coastal Warning Area                             |                                                                                                |\n| SM3                | SafetyNET Message, Circular Area address                            |                                                                                                |\n| SM4                | SafetyNET Message, Rectangular Area Address                         |                                                                                                |\n| SMB                | IMO SafetyNET Message Body                                          |                                                                                                |\n| SPW                | Security password sentence                                          |                                                                                                |\n| SSD                | AIS ship static data                                                |                                                                                                |\n| STN                | Multiple data ID                                                    |                                                                                                |\n| [THS](./ths.go)    | True heading and status                                             | [1](http://www.nuovamarea.net/pytheas_9.html)                                                  |\n| [TLB](./tlb.go)    | Target label                                                        |                                                                                                |\n| [TLL](./tll.go)    | Target latitude and longitude                                       | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_tll_target_latitude_and_longitude)               |\n| TRC                | Thruster control data                                               |                                                                                                |\n| TRL                | AIS transmitter-non-functioning log                                 |                                                                                                |\n| TRD                | Thruster response data                                              |                                                                                                |\n| [TTD](./ttd.go)    | Tracked target data                                                 |                                                                                                |\n| [TTM](./ttm.go)    | Tracked target message                                              | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_ttm_tracked_target_message)                      |\n| TUT                | Transmission of multi-language text                                 |                                                                                                |\n| [TXT](./txt.go)    | Text transmission                                                   | [NMEA](https://www.nmea.org/Assets/20160520%20txt%20amendment.pdf)                             |\n| UID                | User identification code transmission                               |                                                                                                |\n| [VBW](./vbw.go)    | Dual ground/water speed                                             | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_vbw_dual_groundwater_speed)                      |\n| [VDM](./vdmvdo.go) | AIS VHF data-link message                                           | [gpsd](https://gpsd.gitlab.io/gpsd/AIVDM.html)                                                 |\n| [VDO](./vdmvdo.go) | AIS VHF data-link own-vessel report                                 | [gpsd](https://gpsd.gitlab.io/gpsd/AIVDM.html)                                                 |\n| [VDR](./vdr.go)    | Set and drift                                                       | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_vdr_set_and_drift)                               |\n| VER                | Version                                                             |                                                                                                |\n| [VHW](./vhw.go)    | Water speed and heading                                             | [1](https://www.tronico.fi/OH6NT/docs/NMEA0183.pdf)                                            |\n| [VLW](./vlw.go)    | Dual ground/water distance                                          | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_vlw_distance_traveled_through_water)             |\n| [VPW](./vpw.go)    | Speed measured parallel to wind                                     | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_vpw_speed_measured_parallel_to_wind)             |\n| [VSD](./vsd.go)    | AIS voyage static data                                              |                                                                                                |\n| [VTG](./vtg.go)    | Course over ground and ground speed                                 | [1](http://aprs.gids.nl/nmea/#vtg)                                                             |\n| VWR                | Relative Wind Speed and Angle                                       | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_vwr_relative_wind_speed_and_angle)               |\n| VWT                | True Wind Speed and Angle                                           |                                                                                                |\n| WAT                | Water level detection                                               |                                                                                                |\n| WCV                | Waypoint closure velocity                                           |                                                                                                |\n| WNC                | Distance waypoint to waypoint                                       |                                                                                                |\n| [WPL](./wpl.go)    | Waypoint location                                                   | [1](http://aprs.gids.nl/nmea/#wpl)                                                             |\n| [XDR](./xdr.go)    | Transducer measurements                                             | [gpsd](https://gpsd.gitlab.io/gpsd/NMEA.html#_xdr_transducer_measurement)                      |\n| [XTE](./xte.go)    | Cross-track error, measured                                         |                                                                                                |\n| XTR                | Cross-track error, dead reckoning                                   |                                                                                                |\n| [ZDA](./zda.go)    | Time and date                                                       | [1](http://aprs.gids.nl/nmea/#zda)                                                             |\n| ZDL                | Time and distance to variable point                                 |                                                                                                |\n| ZFO                | UTC and time from origin waypoint                                   |                                                                                                |\n| ZTG                | UTC and time to destination waypoint                                |                                                                                                |\n\n| Proprietary sentence type | Description                                                                                     | References                                                                                         |\n|---------------------------|-------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------|\n| [PNG](./pgn.go)           | Transfer NMEA2000 frame as NMEA0183 sentence (ShipModul MiniPlex-3)                             | [1](https://opencpn.org/wiki/dokuwiki/lib/exe/fetch.php?media=opencpn:software:mxpgn_sentence.pdf) |\n| [PCDIN](./pcdin.go)       | Transfer NMEA2000 frame as NMEA0183 sentence (SeaSmart.Net Protocol)                            | [1](http://www.seasmart.net/pdf/SeaSmart_HTTP_Protocol_RevG_043012.pdf)                            |\n| [PGRME](./pgrme.go)       | Estimated Position Error (Garmin proprietary sentence)                                          | [1](http://aprs.gids.nl/nmea/#rme)                                                                 |\n| [PGRMT](./pgrmt.go)       | Sensor Status Information (Garmin proprietary sentence)                                         | [1#2.2.6](https://developer.garmin.com/downloads/legacy/uploads/2015/08/190-00684-00.pdf)          |\n| [PHTRO](./phtro.go)       | Vessel pitch and roll (Xsens IMU/VRU/AHRS)                                                      |                                                                                                    |\n| [PMTK001](./pmtk.go)      | Acknowledgement of previously sent command/packet                                               | [1](https://www.rhydolabz.com/documents/25/PMTK_A11.pdf)                                           |\n| [PRDID](./prdid.go)       | Vessel pitch, roll and heading (Xsens IMU/VRU/AHRS)                                             |                                                                                                    |\n| [PSKPDPT](./pskpdpt.go)   | Depth of Water for multiple transducer installation                                             |                                                                                                    |\n| [PSONCMS](./psoncms.go)   | Quaternion, acceleration, rate of turn, magnetic field, sensor temperature (Xsens IMU/VRU/AHRS) |                                                                                                    |\n\nIf you need to parse a message that contains an unsupported sentence type you can implement and register your own\nmessage parser and get yourself unblocked immediately. Check the example below to know how\nto [implement and register a custom message parser](#custom-message-parsing). However, if you think your custom message\nparser could be beneficial to other users we encourage you to contribute back to the library by submitting a PR and get\nit included in the list of supported sentences.\n\n## Examples\n\n### Built-in message parsing\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"github.com/adrianmo/go-nmea\"\n)\n\nfunc main() {\n\tsentence := \"$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70\"\n\ts, err := nmea.Parse(sentence)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tif s.DataType() == nmea.TypeRMC {\n\t\tm := s.(nmea.RMC)\n\t\tfmt.Printf(\"Raw sentence: %v\\n\", m)\n\t\tfmt.Printf(\"Time: %s\\n\", m.Time)\n\t\tfmt.Printf(\"Validity: %s\\n\", m.Validity)\n\t\tfmt.Printf(\"Latitude GPS: %s\\n\", nmea.FormatGPS(m.Latitude))\n\t\tfmt.Printf(\"Latitude DMS: %s\\n\", nmea.FormatDMS(m.Latitude))\n\t\tfmt.Printf(\"Longitude GPS: %s\\n\", nmea.FormatGPS(m.Longitude))\n\t\tfmt.Printf(\"Longitude DMS: %s\\n\", nmea.FormatDMS(m.Longitude))\n\t\tfmt.Printf(\"Speed: %f\\n\", m.Speed)\n\t\tfmt.Printf(\"Course: %f\\n\", m.Course)\n\t\tfmt.Printf(\"Date: %s\\n\", m.Date)\n\t\tfmt.Printf(\"Variation: %f\\n\", m.Variation)\n\t}\n}\n```\n\nOutput:\n\n```\n$ go run main/main.go\n\nRaw sentence: $GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70\nTime: 22:05:16.0000\nValidity: A\nLatitude GPS: 5133.8200\nLatitude DMS: 51° 33' 49.200000\"\nLongitude GPS: 042.2400\nLongitude DMS: 0° 42' 14.400000\"\nSpeed: 173.800000\nCourse: 231.800000\nDate: 13/06/94\nVariation: -4.200000\n```\n\n### Customize sentence parser\n\nParser logic can be customized by creating `nmea.SentenceParser` instance and by providing callback implementations.\n\n```go\np := nmea.SentenceParser{\n    CustomParsers: nil,\n    ParsePrefix:   nil,\n    CheckCRC:      nil,\n    OnTagBlock:    nil,\n}\ns, err := p.Parse(\"$GPRMC,220516,A,5133.82,N,00042.24,W,173.8,231.8,130694,004.2,W*70\")\n```\n\n### TAG Blocks\n\nNMEA 4.10 TAG Block values can be accessed via the message's `TagBlock` struct:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"time\"\n\t\"github.com/adrianmo/go-nmea\"\n)\n\nfunc main() {\n\tsentence := \"\\\\s:Satelite_1,c:1553390539*62\\\\!AIVDM,1,1,,A,13M@ah0025QdPDTCOl`K6`nV00Sv,0*52\"\n\ts, err := nmea.Parse(sentence)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tparsed := s.(nmea.VDMVDO)\n\tfmt.Printf(\"TAG Block timestamp: %v\\n\", time.Unix(parsed.TagBlock.Time, 0))\n\tfmt.Printf(\"TAG Block source:    %v\\n\", parsed.TagBlock.Source)\n}\n```\n\nOutput (locale/time zone dependent):\n\n```\n$  go run main/main.go\n\nTAG Block timestamp: 2019-03-24 14:22:19 +1300 NZDT\nTAG Block source:    Satelite_1\n```\n\n### Custom message parsing\n\nIf you need to parse a message not supported by the library you can implement your own message parsing. The following\nexample implements a parser for the hypothetical XYZ NMEA sentence type.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/adrianmo/go-nmea\"\n)\n\n// A type to hold the parsed record\ntype XYZType struct {\n\tnmea.BaseSentence\n\tTime    nmea.Time\n\tCounter int64\n\tLabel   string\n\tValue   float64\n}\n\nfunc main() {\n\t// Do this once it will error if you register the same type multiple times\n\terr := nmea.RegisterParser(\"XYZ\", func(s nmea.BaseSentence) (nmea.Sentence, error) {\n\t\t// This example uses the package builtin parsing helpers\n\t\t// you can implement your own parsing logic also\n\t\tp := nmea.NewParser(s)\n\t\treturn XYZType{\n\t\t\tBaseSentence: s,\n\t\t\tTime:         p.Time(0, \"time\"),\n\t\t\tLabel:        p.String(1, \"label\"),\n\t\t\tCounter:      p.Int64(2, \"counter\"),\n\t\t\tValue:        p.Float64(3, \"value\"),\n\t\t}, p.Err()\n\t})\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tsentence := \"$00XYZ,220516,A,23,5133.82,W*42\"\n\ts, err := nmea.Parse(sentence)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tswitch m := s.(type) {\n\tcase XYZType:\n\t\tfmt.Printf(\"Raw sentence: %v\\n\", m)\n\t\tfmt.Printf(\"Time: %s\\n\", m.Time)\n\t\tfmt.Printf(\"Label: %s\\n\", m.Label)\n\t\tfmt.Printf(\"Counter: %d\\n\", m.Counter)\n\t\tfmt.Printf(\"Value: %f\\n\", m.Value)\n\tdefault:\n\t\tpanic(\"Could not parse XYZ sentence\")\n\t}\n}\n```\n\nOutput:\n\n```\n$ go run main/main.go\n\nRaw sentence: $AAXYZ,220516,A,23,5133.82,W*42\nTime: 22:05:16.0000\nLabel: A\nCounter: 23\nValue: 5133.820000\n```\n\n### Message parsing with optional values\n\nSome messages have optional fields. By default, omitted numeric values are set to 0. In situations where you need finer\ncontrol to distinguish between an undefined value and an actual 0, you can register types overriding existing sentences,\nusing `nmea.Int64` and `nmea.Float64` instead of `int64` and `float64`. The matching parsing methods\nare `(*Parser).NullInt64` and `(*Parser).NullFloat64`. Both `nmea.Int64` and `nmea.Float64` contains a numeric\nfield `Value` which is defined only if the field `Valid` is `true`.\n\nSee below example for a modified VTG sentence parser:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/adrianmo/go-nmea\"\n)\n\n// VTG represents track \u0026 speed data.\n// http://aprs.gids.nl/nmea/#vtg\ntype VTG struct {\n\tnmea.BaseSentence\n\tTrueTrack        nmea.Float64\n\tMagneticTrack    nmea.Float64\n\tGroundSpeedKnots nmea.Float64\n\tGroundSpeedKPH   nmea.Float64\n}\n\nfunc main() {\n\tnmea.MustRegisterParser(\"VTG\", func(s nmea.BaseSentence) (nmea.Sentence, error) {\n\t\tp := nmea.NewParser(s)\n\t\treturn VTG{\n\t\t\tBaseSentence:     s,\n\t\t\tTrueTrack:        p.NullFloat64(0, \"true track\"),\n\t\t\tMagneticTrack:    p.NullFloat64(2, \"magnetic track\"),\n\t\t\tGroundSpeedKnots: p.NullFloat64(4, \"ground speed (knots)\"),\n\t\t\tGroundSpeedKPH:   p.NullFloat64(6, \"ground speed (km/h)\"),\n\t\t}, p.Err()\n\t})\n\n\tsentence := \"$GPVTG,140.88,T,,M,8.04,N,14.89,K,D*05\"\n\ts, err := nmea.Parse(sentence)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tm, ok := s.(VTG)\n\tif !ok {\n\t\tpanic(\"Could not parse VTG sentence\")\n\t}\n\tfmt.Printf(\"Raw sentence: %v\\n\", m)\n\tfmt.Printf(\"TrueTrack: %v\\n\", m.TrueTrack)\n\tfmt.Printf(\"MagneticTrack: %v\\n\", m.MagneticTrack)\n\tfmt.Printf(\"GroundSpeedKnots: %v\\n\", m.GroundSpeedKnots)\n\tfmt.Printf(\"GroundSpeedKPH: %v\\n\", m.GroundSpeedKPH)\n}\n```\n\nOutput:\n\n```\n$ go run main/main.go\n\nRaw sentence: $GPVTG,140.88,T,,M,8.04,N,14.89,K,D*05\nTrueTrack: {140.88 true}\nMagneticTrack: {0 false}\nGroundSpeedKnots: {8.04 true}\nGroundSpeedKPH: {14.89 true}\n```\n\n## Contributing\n\nPlease feel free to submit issues or fork the repository and send pull requests to update the library and fix bugs,\nimplement support for new sentence types, refactor code, etc.\n\n## License\n\nCheck [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianmo%2FGo-nmea","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrianmo%2FGo-nmea","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrianmo%2FGo-nmea/lists"}