Git Product home page Git Product logo

go-ais's Introduction

go-ais

Build Status Coverage Status Go Report Card License: MIT

Summary

This is a library written in Go to encode and decode Automatic Identification System packets. This is a VHF data system that is used for dependent tracking and identification of marine vessels. It is specified by the ITU-R M.1371-5 standard.

Rationale

There are a few other libraries offered on the internet, but all of them implement only a few messages (usually the position and static reports). In addition, very few libraries support encoding.

Many other libraries tightly integrate a NMEA (VDM/VDO) decoder with the AIS decoder. This is handy if you use a complete receiver that delivers NMEA sentences, but can be limiting. For example, you may have a low level RF receiver connected directly to an embedded system. I feel it is best to split NMEA and AIS coding as they are really two different functions. However, a convenience library is provided in this repository that combines this library with a golang NMEA decoder and a self-developed NMEA encoder.

How to use it

Start by getting an AIS packet from somewhere. It could for example come from AISHub or a local receiver. Extract the payload and convert it to a byte slice containing one bit per byte. Then call the DecodePacket function on it. It will return an object containing the decoded message. For example:

package main
     
import (
    "fmt"
    "encoding/json"
 
    ais "github.com/BertoldVdb/go-ais"
)
    
func main() {
    msg := []byte{0, 0, ... 1, 0, 0, 0, 0, 0, 0, 0}
    
    c := ais.CodecNew(false, false)
    c.DropSpace = true
       
    result := c.DecodePacket(msg)
    out, _ := json.MarshalIndent(result, "", "  ")
    fmt.Printf("%T: %s\n", result, out)
}   

The output of this program could be as follows:

ais.ShipStaticData: {
"MessageID": 5,
"RepeatIndicator": 0,
"UserID": 203999421,
"Valid": true,
"AisVersion": 0,
"ImoNumber": 0,
"CallSign": "OED3018",
"Name": "PRIMADONNA",
"Type": 69,
"Dimension": {
"A": 20,
"B": 93,
"C": 7,
"D": 10
},
"FixType": 1,
"Eta": {
"Month": 1,
"Day": 4,
"Hour": 18,
"Minute": 30
},
"MaximumStaticDraught": 1.7,
"Destination": "LINZ",
"Dte": false,
"Spare": false
}

To encode a packet, call the EncodePacket function. It works exactly in the opposite way of DecodePacket.

If you want to work with NMEA sentences you can use the following example to decode a packet:

package main

import (
    "fmt"
    "github.com/BertoldVdb/go-ais"
    "github.com/BertoldVdb/go-ais/aisnmea"
)

func main() {
    nm := aisnmea.NMEACodecNew(ais.CodecNew(false, false))
    
    decoded, _ := nm.ParseSentence("!AIVDM,1,1,,B,33aEP2hP00PBLRFMfCp;OOw<R>`<,0*49")
    if decoded != nil {
        fmt.Printf("%+v\n", decoded.Packet)
    }
}

go-ais's People

Contributors

bertoldvdb avatar simeonmiteff avatar quartercastle avatar

Watchers

James Cloos 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.