4 Copyright (c) 2017 Mario Konrad (mario.konrad@gmx.net)
11 This is a C++ library for **MAR**itime **NAV**igation purposes.
13 It supports (partially):
16 - SeaTalk (Raymarine device communication)
17 - Reading data from serial ports (NMEA, SeaTalk)
18 - Basic geodesic functions, suitable for martime navigation.
20 See chapter _Features_ for a complete and detailed list.
27 There are already implementaions for reading and writing NMEA-0183 or AIS.
28 The goal of this library is
29 - to have an implementation in modern C++
30 - easy to use API (std lib like, integrating well)
31 - unit tested (high test coverage)
32 - trivial integration into projects (liberal license, as few dependencies as
34 - (more or less) well documented
35 - (more or less) complete, as far as information is freely available
45 Supported sentences for NMEA-0183 (read and write):
46 - AAM: Waypoint Arrival Alarm
47 - ALM: GPS Almanac Data
48 - APA: Autopilot Sentence "A"
49 - APB: Autopilot Sentence "B"
50 - BOD: Bearing - Waypoint to Waypoint
51 - BWC: Bearing & Distance to Waypoint - Geat Circle
52 - BWR: Bearing and Distance to Waypoint - Rhumb Line
53 - BWW: Bearing - Waypoint to Waypoint
54 - DBT: Depth Below Transducer
56 - DSC: Digital Selective Calling Information (**experimental**)
57 - DSE: Extended DSC (**experimental**)
58 - DTM: Datum Reference
59 - FSI: Frequency Set Information
60 - GBS: GPS Satellite Fault Detection
61 - GGA: Global Positioning System Fix Data
62 - GLC: Geographic Position, Loran-C
63 - GLL: Geographic Position - Latitude/Longitude
65 - GRS: GPS Range Residuals
66 - GSA: Geographic Position - Latitude/Longitude
67 - GST: GPS Pseudorange Noise Statistics
68 - GSV: Satellites in view
69 - GTD: Geographic Location in Time Differences
70 - HDG: Heading - Deviation & Variation
72 - HFB: Trawl Headrope to Footrope and Bottom
73 - HSC: Heading Steering Command
74 - ITS: Trawl Door Spread 2 Distance
75 - LCD: Loran-C Signal Data
76 - MSK: Control for a Beacon Receiver
77 - MSS: Beacon Receiver Status
78 - MTW: Mean Temperature of Water
79 - MWD: Wind Direction and Speed
80 - MWV: Wind Speed and Angle
82 - RMA: Recommended Minimum Navigation Information
83 - RMB: Recommended Minimum Navigation Information
84 - RMC: Recommended Minimum Navigation Information
87 - RSA: Rudder Sensor Angle
88 - RSD: RADAR System Data (**experimental**)
90 - SFI: Scanning Frequency Information
91 - STN: Multiple Data ID
92 - TDS: Trawl Door Spread Distance
93 - TFI: Trawl Filling Indicator
94 - TLL: Target Latitude and Longitude
95 - TPC: Trawl Position Cartesian Coordinates
96 - TPR: Trawl Position Relative Vessel
97 - TPT: Trawl Position True
98 - TTM: Tracked Target Message
99 - VBW: Dual Ground/Water Speed
100 - VDM: AIS VHF Data-Link Message
101 - VDO: AIS VHF Data-Link Own-Vessel Report
103 - VHW: Water speed and heading
104 - VLW: Distance Traveled through Water
105 - VTG: Track made good and Ground speed
106 - VWR: Relative Wind Speed and Angle.
107 - VPW: Speed - Measured Parallel to Wind
108 - WCV: Waypoint Closure Velocity
109 - WNC: Distance - Waypoint to Waypoint
110 - WPL: Waypoint Location
111 - XDR: Transducer Measurement
112 - XTE: Cross-Track Error, Measured
113 - XTR: Cross Track Error - Dead Reckoning
114 - ZDA: Time & Date - UTC, day, month, year and local time zone
115 - ZDL: Time and Distance to Variable Point
116 - ZFO: UTC & Time from origin Waypoint
117 - ZTG: UTC & Time to Destination Waypoint
119 Obsolete (according to the standard) but implemented:
120 - DBK: Depth Below Keel
121 - HDM: Heading - Magnetic (obsolete as of 2009)
122 - R00: Waypoints in active route
125 - PGRME: Garmin Estimated Error
126 - PGRMM: Garmin Map Datum
127 - PGRMZ: Garmin Altitude Information
130 - Tag Block Support (generic for all sentences)
135 Supported messages for AIS (decode and encode):
136 - Type 01: Position Report Class A
137 - Type 02: Position Report Class A (Assigned Schedule)
138 - Type 03: Position Report Class A (Response to Interrogation)
139 - Type 04: Base Station Report
140 - Type 05: Static and Voyage Related Data
141 - Type 06: Binary Addressed Message
142 - Type 07: Binary Acknowledge
143 - Type 08: Binary Broadcast Message
144 - Type 09: Standard SAR Aircraft Position Report
145 - Type 10: UTC/Date Inquiry
146 - Type 11: UTC/Date Response
147 - Type 12: Addressed Safety-Related Message
148 - Type 13: Safety-Related Acknowledgement
149 - Type 14: Safety-Related Broadcast Message
150 - Type 17: DGNSS Broadcast Binary Message
151 - Type 18: Standard Class B CS Position Report
152 - Type 19: Extended Class B CS Position Report
153 - Type 20: Data Link Management
154 - Type 21: Aid-to-Navigation Report
155 - Type 22: Channel Management
156 - Type 23: Group Assignment Command
157 - Type 24: Static Data Report (part A and B, norma and auxiliary vessel)
159 Supported payload of binary message 08:
160 - 001/11: Meteorological and Hydrological Data (IMO236)
161 - 200/10: Inland ship static and voyage related data (Inland AIS)
165 Suported messages for SeaTalk (decode and encode):
166 - Type 00: depth below transducer
167 - Type 01: equipment id
168 - Type 05: Engine RPM and PITCH
169 - Type 10: apparent wind angle
170 - Type 11: apparent wind speed
171 - Type 20: speed through water
172 - Type 21: trip mileage
173 - Type 22: total mileage
174 - Type 23: water temperature 1
175 - Type 24: Display unit for Mileage and Speed
176 - Type 25: total and trip log
177 - Type 26: Speed through Water
178 - Type 27: water temperature 2
179 - Type 30: Set Lamp Intensity
180 - Type 36: Cancel MOB condition
181 - Type 38: Codelock data (**experimental**)
182 - Type 50: LAT Postion
183 - Type 51: LON Postion
184 - Type 52: Speed over Ground
185 - Type 53: Magnetic Course in Degrees
189 - Type 59: Set Count Down Timer (sent by ST60)
190 - Type 65: Select Fathom display unit for depth display (see message 00)
191 - Type 66: Wind Alarm
192 - Type 6C: Second equipment-ID
194 - Type 87: Response Level
195 - Type 89: Compass heading (sent by ST40 compass instrument)
200 - Reading data from serial ports (NMEA, SeaTalk)
203 ### Geodesic Functions
205 Basic geodesic functions, suitable for martime navigation.
207 - Calculation of CPA (closest point of approach)
208 and TCPA (time to closest point of approach)
209 - Distance of two points on a sphere
210 - Distance of two points on an ellipsoid using formula of Vincenty
211 - Distance of two points on an ellipsoid using formula of Lambert
219 More examples [here](doc/examples.md).
221 ### Parse NMEA Sentence
224 using namespace marnav;
226 auto sentence = nmea::make_sentence(
227 "$GPRMC,201034,A,4702.4040,N,00818.3281,E,0.0,328.4,260807,0.6,E,A*17");
228 std::cout << sentence->tag() << "\n";
229 auto rmc = nmea::sentence_cast<nmea::rmc>(sentence);
230 std::cout << "latitude : " << nmea::to_string(rmc->get_latitude()) << "\n";
231 std::cout << "longitude: " << nmea::to_string(rmc->get_longitude()) << "\n";
234 Create a specific sentence directly:
237 using namespace marnav;
239 auto rmc = nmea::create_sentence<nmea::rmc>(
240 "$GPRMC,201034,A,4702.4040,N,00818.3281,E,0.0,328.4,260807,0.6,E,A*17");
241 std::cout << "latitude : " << nmea::to_string(rmc.get_latitude()) << "\n";
242 std::cout << "longitude: " << nmea::to_string(rmc.get_longitude()) << "\n";
245 ### Write NMEA Sentence
249 mtw.set_temperature(22.5);
250 std::string data = nmea::to_string(mtw);
253 ### Parse AIS Message from NMEA data
256 using namespace marnav;
258 // received sentences
259 const std::vector<std::string> received_strings
260 = {"!AIVDM,2,1,3,B,55P5TL01VIaAL@7WKO@mBplU@<PDhh000000001S;AJ::4A80?4i@E53,0*3E",
261 "!AIVDM,2,2,3,B,1@0000000000000,2*55"};
263 // parse NMEA sentences
264 std::vector<std::unique_ptr<nmea::sentence>> sentences;
265 for (auto const & txt : received_strings) {
266 auto sentence = nmea::make_sentence(txt);
267 if (sentence->id() == nmea::sentence_id::VDM) {
268 sentences.push_back(std::move(sentence));
272 // parse and and process AIS messags
273 auto payload = nmea::collect_payload(sentences.begin(), sentences.end());
274 auto message = ais::make_message(payload);
275 if (message->type() == ais::message_id::static_and_voyage_related_data) {
276 auto report = ais::message_cast<ais::message_05>(message);
277 std::cout << "shipname: " << report->get_shipname() << "\n";
278 std::cout << "callsign: " << report->get_callsign() << "\n";
282 ### Create NMEA sentences from AIS data
285 using namespace marnav;
288 ais::message_01 pos_report;
289 pos_report.set_sog(82);
290 // ... most data not shown here
293 auto payload = ais::encode_message(pos_report);
295 // create NMEA sentences
296 for (uint32_t fragment = 0; fragment < payload.size(); ++fragment) {
298 vdm.set_n_fragments(payload.size());
299 vdm.set_fragment(fragment + 1);
300 vdm.set_radio_channel(nmea::ais_channel::B);
301 vdm.set_payload(payload[fragment]);
303 // collect, send or do something with the sentence...
304 std::string s = nmea::to_string(vdm);
305 std::cout << s << "\n";
309 or simply use `nmea::make_vdms`:
312 using namespace marnav;
315 ais::message_01 pos_report;
316 pos_report.set_sog(82);
317 // ... most data not shown here
320 auto payload = ais::encode_message(pos_report);
322 // create NMEA sentences
323 auto sentences = nmea::make_vdms(payload);
325 // process sentences, somehow...
326 for (auto const & sentence : sentences) {
327 std::cout << nmea::to_string(*sentence) << "\n";
336 This chapter describes the requirements in order to build the library.
337 Tools and their versions are listed below, newer/older/other tools
338 (i.e. compilers, etc.) may work, but not tested.
354 Tools needed to build the library:
355 - cmake 3.11 or newer
357 Tools needed to develop the library:
361 Tools needed to build the documentation:
364 - LaTeX (there are formulas!)
366 Optional used for development:
367 - lcov / genhtml, c++filt
373 Optional (no core dependency):
374 - Boost.ASIO (used only for some examples)
375 - Qt 5 (used only for some examples)
380 There are no other dependencies despite the standard library (C++11)
381 to build this library.
388 The following build types `-DCMAKE_BUILD_TYPE=x` are possible:
394 - `ENABLE_STATIC` : enables static build, if `OFF`, a shared library is being built.
396 - `ENABLE_WARNING_HELL` : enables _much_ more warnings, used for development purposes.
397 Currently implemented only for GCC. Default is `OFF`
398 - `ENABLE_PROFILING` : enables profiling for `gprof`
399 - `ENABLE_BENCHMARK` : enables benchmarking (disables some optimization)
400 - `ENABLE_SANITIZER` : enables address and undefined sanitizers
403 - `ENABLE_AIS ` : enables AIS support. Default: `ON`
404 - `ENABLE_SEATALK` : enables SeaTalk support. Default: `ON`
405 - `ENABLE_IO` : enables IO support. Default: `ON`
408 - `ENABLE_EXAMPLES`: enables examples. Default: `ON`
409 - `ENABLE_TESTS`: enables unit tests, integration tests and benchmarks. Default: `ON`
410 - `ENABLE_TOOLS`: enables tools. Default: `ON`
417 cmake -DCMAKE_BUILD_TYPE=Release ..
433 or individual package types:
439 ### Developpers Choice
443 cmake -DCMAKE_BUILD_TYPE=Coverage -DENABLE_WARNING_HELL=YES ..
445 make coverage doc cppcheck
448 ### Static Analysis with Clang
450 There is a script ```bin/static-analysis-clang``` for doing this, or do it manually:
454 cmake -DCMAKE_CXX_COMPILER=/usr/share/clang/scan-build-3.9/libexec/c++-analyzer ..
455 scan-build-3.9 -o doc/analysis --use-analyzer=/usr/bin/clang++-3.9 make
457 After the build, ```scan-build``` will tell you what to do in order to inspect
461 ### Perform Benchmarks
463 Build in `Release` mode, perform individual benchmarks:
467 cmake -DCMAKE_BUILD_TYPE=Release ..
469 test/benchmark_nmea_split
471 Using `perf` to do performance analysis:
475 cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_BENCHMARK=ON ..
477 perf record -g test/benchmark_nmea_split
478 perf report -g 'graph,0.5,caller'
483 There is a helper script ```bin/check-format``` which uses ```clang-format``` to
484 check the formatting of all files in the directories containing code (```src```,
485 ```test``` and ```examples```). This script can be used manually:
489 or used as git pre-commit hook:
492 ln -s ../../bin/check-format pre-commit
494 which prevents a commit if there are files not complying with the formatting
495 rules. Be aware of using the script as pre-commit hook, the checking can take
504 Mario Konrad (mario.konrad@gmx.net) with help from others.
506 Search the repository for a complete list:
508 git log --format=%an | sort -u
515 A (non-complete) collection of resources from where information was gathered.
517 - [NMEA Revealed](http://www.catb.org/gpsd/NMEA.html) (by Eric S. Raymond)
518 - [NMEA FAQ](http://www.kh-gps.de/nmea.faq)
519 - [it-digin's blog](http://www.it-digin.com/blog/?cat=4)
520 - [AIVDM/AIVDO Protocol decoding](http://www.catb.org/gpsd/AIVDM.html) (by Eric S. Raymond)
521 - [DSC Position Request](http://www.thehulltruth.com/marine-electronics-forum/43945-dsc-position-request.html)
522 - [NMEA-0183 Sentences DSC,DSE](http://www.cruisersforum.com/forums/f13/nmea-0183-sentences-dsc-dse-124887.html)
523 - [SerialMon - NMEA 0183 Protocol](http://www.serialmon.com/protocols/nmea0183.html)
524 - [SeaTalk Reference](http://thomasknauf.de/seatalk.htm) (by Thomas Knauf)
525 - [Navigation Center - AIS Standard Class B Equipment Position Report](http://www.navcen.uscg.gov/?pageName=AISMessagesB)
526 - [GPS Forums](http://www.gps-forums.net)
527 - [NMEA Datensaetze](http://www.nmea.de/nmea0183datensaetze.html)
528 - [AIS VDM & VDO Message Decoder](http://www.maritec.co.za/tools/aisvdmvdodecoding/)
536 > The official NMEA 0183 Standard document is not available for free. It was not
537 > consulted at any point during the development of this library. All information
538 > was found from free sources on the internet. This library (especially the NMEA
539 > part) is not derivative work of this standard.
542 See also [LICENSE](LICENSE)
547 Copyright (c) 2016, Mario Konrad
550 Redistribution and use in source and binary forms, with or without
551 modification, are permitted provided that the following conditions are met:
552 1. Redistributions of source code must retain the above copyright
553 notice, this list of conditions and the following disclaimer.
554 2. Redistributions in binary form must reproduce the above copyright
555 notice, this list of conditions and the following disclaimer in the
556 documentation and/or other materials provided with the distribution.
557 3. All advertising materials mentioning features or use of this software
558 must display the following acknowledgement:
559 This product includes software developed by Mario Konrad.
560 4. Neither the name of the software nor the names of its contributors
561 may be used to endorse or promote products derived from this software
562 without specific prior written permission.
564 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
565 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
566 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
567 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
568 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
569 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
570 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
571 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
572 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
573 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.