Ada gudang github yang bagus dari Kurt Schwehr yang bekerja di Pusat Pemetaan Pesisir dan Laut (misalnya untuk melacak aktivitas paus ). Di sana Anda akan menemukan decoder dan dokumen untuk memahami pesan nmea (sebagian besar tautan disebutkan oleh posting @ianmayo dan @GID Dev). Berikut adalah howto kecil yang berjalan di bawah LINUXdan python 2.7.
Untuk mendapatkan beberapa kode berjalan, Anda perlu gitsebuah C++compiler, yang python setup environment, cmake. Unduh data dari
$ cd YOUR_BUILD_PATH
$ git clone https://github.com/schwehr/libais.git
dan ikuti instruksi instalasi pada / di halaman github atau jalankan
$ 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
Bagaimanapun, Anda harus memiliki perpustakaan di pythonlingkungan Anda .
$ 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
Berikut ini beberapa kode cepat dan kotor dalam skrip yang dipanggil test-ais.pyuntuk mendapatkan unix seperti head& tailbehavoir. Saya menggunakan jsonsebagai "printer cukup teks yang jelas".
#!/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
Dengan asumsi bahwa nmea-samplesfile tersebut ada dalam datadirektori, Anda dapat memfilter baris yang ingin Anda tampilkan cat, headdan 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
}
Mulai dari kode json, seharusnya mudah untuk melanjutkan dengan memformat lebih lanjut dan menyimpan barang-barang.