Giter VIP home page Giter VIP logo

pyaism's Introduction

pyAISm

A small and incomplete python decoder for AIS messaging.

A bunch of naive pythons functions to decode somes ais_data/AIVDM messages:

Based on the doc here: (http://catb.org/gpsd/AIVDM.html).

How to use it

In python 2 console:

> msg = '!AIVDO,1,1,,,B00000000868rA6<H7KNswPUoP06,0*6A'  # standard AIVDO sentence as a string
> ais_data = decod_ais(msg)         # Return a dictionnary
> ais_format = format_ais(ais_data) # A more human readable dictionnary
> print ais_data, ais_data['lon'], ais_format['lon'] # Accessing the value of the key

Decode a file:

def decode_file_example():
    """
    Example for decoding a file
    :return:
    """
    with open("ais.exploratorium.edu", "r") as file:
        for aline in file:
            try:
                msg = aline.rstrip("\n")
                ais_data = pyAISm.decod_ais(msg)  # Return a dictionnary
                ais_format = pyAISm.format_ais(ais_data)  # A more human readable dictionnary
                print(ais_format)  # Accessing the value of the key
            except pyAISm.UnrecognizedNMEAMessageError as e:
                print e
            except pyAISm.BadChecksumError as e:
                print e
            except Exception as e:
                print e
        print('End of file')

Decode a stream:

def decode_stream_example():
    """
    Example for decoding an online data stream
    :return:
    """
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect(("ais.exploratorium.edu", 80))
    s.sendall("GET / HTTP/1.1\r\nHost: www.cnn.com\r\n\r\n".encode())
    while (True):
        msg = (s.recv(4096).decode('utf-8')).splitlines()
        for m in msg:
            try:
                msg = m.rstrip("\n")
                ais_data = pyAISm.decod_ais(msg)  # Return a dictionnary
                ais_format = pyAISm.format_ais(ais_data)  # A more human readable dictionnary
                print(ais_format)  # Accessing the value of the key
            except pyAISm.UnrecognizedNMEAMessageError as e:
                print e
            except pyAISm.BadChecksumError as e:
                print e
            except Exception as e:
                print e

pyaism's People

Contributors

aayaffe avatar pirpyn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.