There is a good github repository of Kurt Schwehr who works at the Center for Coastal and Ocean Mapping (to track whale activities for example). There you will find a decoder and documents to understand the nmea messages (mostly links menioned by the posts of @ianmayo and @GID Dev). Here is a small howto running under LINUX
and python 2.7
.
To get some code running, you need git
a C++
compiler, the python setup environment
, cmake
. Download the data from
$ cd YOUR_BUILD_PATH
$ git clone https://github.com/schwehr/libais.git
and follow the installation instruction on/at the github page or run
$ cd YOUR_BUILD_PATH/libais
$ cmake . # to bulid the Makefile
$ make # to build the libais C++
$ python setup.py build # to build the python stuff
$ sudo python setup.py install # to deploy it
After all you should have the libraries in your python
environment.
$ ls /usr/local/lib/python2.7/dist-packages/
easy-install.pth libais-0.16-py2.7-linux-x86_64.egg
$ ls /usr/local/lib/python2.7/dist-packages/libais-0.16-py2.7-linux-x86_64.egg
ais _ais.py _ais.pyc _ais.so EGG-INFO test
Here is some quick and dirty code in a script called test-ais.py
to get the unix like head
& tail
behavoir. I use json
as a "clear text pretty printer".
#!/usr/bin/python
# To supress the warning ...could be done better
# FutureWarning: The stream module is deprecated and will be removed in 1.0
# https://github.com/schwehr/libais/blob/master/ais/stream/__init__.py
# coded in in __init__.py line 10-14
import warnings
warnings.filterwarnings("ignore")
# import json module for pretty print
import json
# import ais.stream module to decode
# a ais binary nmea message to json
import ais.stream
# import sys module to read stuff from
# standard input STDIN
import sys
# decode a file or somthing form the STDIN
f = open(sys.argv[1]) if len(sys.argv) > 1 else sys.stdin
# Iterate over the messages
for msg in ais.stream.decode(f):
# make a json pretty print for each message
print json.dumps(msg, indent=4, sort_keys=True)
# EOF
Assuming that the nmea-samples
file is in a data
directory, you can filter out the line you want to show cat
, head
and tail
...
$ tail -1 data/nmea-sample | ./test-ais.py
{
"day": 14,
"fix_type": 1,
"hour": 11,
"id": 4,
"minute": 33,
"mmsi": 2320717,
"month": 3,
"position_accuracy": 0,
"raim": false,
"repeat_indicator": 3,
"second": 30,
"slot_offset": 2250,
"slot_timeout": 0,
"spare": 0,
"sync_state": 0,
"transmission_ctl": 0,
"x": -5.782454967498779,
"y": 57.842193603515625,
"year": 2012
}
Starting from the json code, it should be easy to go on with further formatting and storing stuff.