PupAIS: An NMEA string parser and vessel plotter


The acronym AIS stands for Automated Identification System. This is an international marine navigation transponder system, which is compulsory for larger ships. (See this wikipedia article for details.) There is already a number of sophisticated AIS receivers and plotters in the market, many of which are suitable for leisure yachts. But as I already had most of the hardware needed aboard my 27' sailing yacht Cypris -- including VHF, GPS and a 9" Asus Eee PC with modest power requirements running directly on 12 volts -- I wrote this Python application primarily so that I could monitor (and possibly hail) approaching ships while sailing in fog, darkness, or poor visibility in general.

This is an overview of my system:

 
                   

Software description

All AIS-transmitting ships are required to automatically broadcast their dynamic and static navigation data on VHF maritime channels 87B (161.975 MHz) and 88B (162.025 MHz). These GMSK-modulated binary messages are transmitted in very short bursts that could be just barely heard as sudden "pops", easy enough to misinterpret as random static noise.

The first step in decoding these minute packets of binary signal-trains is to translate them into ASCII-formatted raw NMEA messsage strings. They then become human-readable in principle, but are actually still cryptic and rather incomprehensible at this stage. Common NMEA sentence tags are AIVDM and AIVDO, and a typical string would look something like this: 

!AIVDM,1,1,,A,1?4Gw0QPjb1AaC8R4<UcmaN6050l,0*3E

AISMon.exe is a freeware demodulator/decoder that executes this first step effortlessly, directing the NMEA formatted output to a serial port and/or a log file. Unfortunately, the code is not open-source, and furthermore Windows only. The latter restriction to Linux users, though, is easily overcome by running it under Wine.

The second step in the transformation is to "decapsulate" each NMEA message string in order to discover its meaningful data content, which can then be parsed and presented by a dedicated application.

This last step is what PupAIS is about! It generates a dynamic list of all the message emitting ships (and some other types of targets) within VHF range. This list is written to a repeatedly updated CSV file, which is then parsed by the two companion python programs: 
PopuLister (AISflukt.py), shows the available information for the entire "population" of targets in radio range, one "screen" per target, while PloyPlotter (Ployplot.py) presents positional data in the form of a pseudo radar screen, graphically indicating Range, Bearing and Course for each target. (And, yes -- snazzy app names are important!)

  



The example screenshots below were made while sitting at home, about 10 NM from the closest shipping lanes and with generally poor VHF reception, hence the limited number of targets (click to enlarge).  

   


The Help-screen explains how to interpret PloyPlot: 





Hardware requirements

In order to to feed PupAIS live information we need access to some sort of AIS input stream, obviously. The basic options are to use either a dedicated AIS receiver/transponder (expensive), or to modify a regular VHF receiver/scanner (potentially cheaper). In the latter case one needs to tap the unfiltered signal at the "discriminator" level. If you already have a VHF radio, it is very possible that it can be modified with a little surgery. The standard site for information in this field of hardware hacking is here:  http://www.discriminator.nl/

If you, like I do, happen to posses the venerable Shipmate RS 8000, and want to locate the relevant pin, you may find these overviews useful:

                


The VHF radio also needs a suitable antenna. For my receiver I built a simple "Slim Jim" type dedicated antenna, which at 1306 mm is optimised for 162 MHz.

Okay -- once we have a working Rx that can output the required signal, this signal should be passed to the computer's sound card (line in). The built-in sound card in my little EeePC 900 is rather lacking, but I have found the IMic external USB sound card by Griffin works well for this purpose. The raw audio signal from the sound card is what the AISMon demodulator/decoder (described above) needs as input.

Another necessary piece of kit is a GPS receiver -- unless you intend to always use PupAIS with a stationary computer (in which case you can simply define your position statically with the variable "myPosGPS" in circa line 1283 in the source). I use the popular and fairly cheap BU-353 USB dongle from USGlobalsat.

       
  


Setting it all up

In AISMon's configuration window, tick the "Logfile Output" box. Then set the path to AISMon.log as the input file in the PupAIS source (the variable "ipf" in circa line 1280). 

That should be it. When launching PupAIS the two windows for PopuLister and PloyPlot also pop up, and after a while any available targets start appearing. When exiting the program it is always best to close the PupAIS window first to ensure that the sub-processes are killed with it.

It is very possible that you want to simultaneously run a program like SeaClear2, or similar charting software, that needs to access the same AIS information. AISMon.exe can be configured to send serial data to another program via a pair of virtual COM ports, i.e. using serial port emulation in software. This works well under Windows proper, but not at all under Wine, as far as I understand. 

I eventually resigned trying to hack around this problem and went for a pure hardware solution instead. A pair of FT232RL USB-to-serial UART chips from FTDI  were wired up in null-modem fashion with full handshaking (probably overkill) and connected to a cheap USB port splitter dongle. It all fits in a cutesy little plastic box and works as expected (although for some reason it is very sensitive to even the slightest accidental USB connector movements). Finally, to make SeaClear2 see the ttyUSB(n) ports as the corresponding COM(n+1) ports when running under Wine you have to create links like so:
 
    ln -s /dev/ttyUSB0 ~/.wine/dosdevices/com1  
    ln -s /dev/ttyUSB1 ~/.wine/dosdevices/com2  
    ln -s /dev/ttyUSB2 ~/.wine/dosdevices/com3   
        etc...

   
   
 
The last picture just shows the no-nonsense 12V power cable for the netbook with it's 3A fuse. No regulator -- no smoothing caps -- no nothing!



The source code

Source code files can be found in the Github repository: https://github.com/moof-moof/pup-ais




Comments

There is no regular comments feature with Google Sites (yet), but you may mail me here instead: xneb.contact@gmail.com