N2KLib - A Java NMEA 2000 library
Phil May and Andrea Twigg
Wed 28 Nov 2018 17:29
It all started when my second Volvo Penta 4” engine display was destroyed by UV. Rather than throw another $1000 down the drain replacing like for like, I decided to go with a more standard solution, involving a Volvo->NMEA 2000 gateway plus a Maretron NMEA 2000 display (DSM410). Half the price and a much more versatile colour display. The majority of the replacement is up and running, but the Maretron has the ability to highlight display engine alarms, which is something I have not managed to get working so far. I decided to get an Actisense NMEA2000 to serial gateway (NGT) so I could connect my laptop to the NMEA 2000 network and see what is going on.
Having purchased the NGT gateway I wanted to try it out, but it was three months before I could connect to the real network on Anastasia, so I decided to see what NMEA2000 my Raymarine E120 chart plotter (the one I brought home to fix the display backlight) would produce on its own. I plugged it into the NGT, fired up the Actisense packet sniffer and immediately saw some packets coming in from the plotter (it sends out datum and cross track error messages all the time). Obviously I then wanted to send some data to the plotter to see what I could get it to do. Google came up with various apps that might do what I want, but they all cost money. However, I did find and excellent project on github (Canboat) that has an XML file defining most of the NMEA 2000 packets, so how hard could it be to write something to send packets to my plotter?
One thing led to another. First I wrote the NMEA2000 library with a simple command line interface. Then I added log file input, to replay a log file I found in the Canboat project). It was logical to add a GUI to be able to see packets on the fly, and control the logging. Finally I added a simple autohelm to generate more meaningful data for the simulation. So now I can construct a route on my chartplotter, fire up the app, and see the chartplotter navigate the route, with simulated wind and tide to give it something to think about. The UI can also capture log files so you can recreate a session at a later time.
I am going to release the code as open source to github, but here is what it looks like in action.
Wind, heading, cog, current vectors all present and correct on the chartplotter.
The data screens are all populated
The UI main window lists the latest of each packet type received and sent. You can see that the E120 sends quite a few unknown packet types, but interpreting these is not necessary for operation. The sent messages are being generated by the application based on the initial configuration plus navigation information from the chart plotter.
You can zoom in on the details of a packet to see more information (all from the pgns.xml file).
The UI menus should be self-explanatory.
Configuration of the yacht.
The set of N2K messages for simulation that I have written so far. I would have liked to simulate some random AIS targets but unfortunately the E120 does not support AIS input over the NMEA 2000 port.