GithubHelp home page GithubHelp logo

yellowfeather / aisparser Goto Github PK

View Code? Open in Web Editor NEW
30.0 8.0 16.0 132 KB

C# decoder for Automatic Identification System (AIS) for tracking ships and decoding maritime information

License: MIT License

C# 100.00%
ais aivdm aivdo nmea encoder-decoder tracking-ships dotnet-standard

aisparser's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aisparser's Issues

Question about 'not available' values and nulls

Hi. I'm working through our shim between AisParser and our database and have noticed some inconsistency.
I'd got the impression (probably from looking at one particular parameter yesterday) that you weren't intercepting the "not available" values when parsing the bits. However I've just spotted that you do set null values in (for example) ReadRateOfTurn and ReadTrueHeading. Whereas you don't in (for example) ReadSpeedOverGround and ReadCourseOverGround.

It's debatable whether the 'not available' value (e.g. 511) should be passed back as-is, or intercepted-and-nulled - we had a long conversation ourselves this morning about which is best in later processing.
Our reasoning (in the context of our particular project): we have a wrapper around AisParser to convert a message into a 'dynamic data record' and/or a 'static/voyage data record'. The calling code doesn't know about the individual message types, it just gets the record(s) back.
So if the 'not available' values are nulled by AisParser, then that calling code can't differentiate between "the parameter has a 'not available' value in the message" compared with "the message [type] doesn't include that parameter". e.g. Rate Of Turn in a Position Report (1) vs. a StandardClassB (18).

It's not a killer for us at present, but if our customer needs us to process stuff differently in the future then it could be - so just thought I'd raise it with you for possible consideration/discussion! Cheers.

Incorrect/rogue parsing in StaticDataReportPartAMessage

Part A shouldn't be looking for 'Spare' - the Part A message ends with ShipName @ 160 bits.
[Apologies for not submitting a pull request, but I'm no expert on Git, so you might not thank me for trying lol. I think in this case it's just a one-line deletion]

MSB3644: The reference assemblies for framework ".NETFramework,Version=v5.0" were not found

Environment : Windows 10, laptop, Visual studio community 2017
dotnet version : 8.0.100-preview.1.23115.2(latest)

I downloaded this library and tried to compile as dll. because my plugin need this code.

but, it couldn't be compiled.

this is the error message :

MSB3644: The reference assemblies for framework ".NETFramework,Version=v5.0" were not found

so, I tried to install .net SDK 5.0, but found it is not supported version and it is for visual studio 2019.(I'm using visual studio 2017.)

Can't parse certain AIS message.

Hello.

"!AIVDM,2,1,6,A,56T6Bb82;pLA<t;N20Lht84j0qD8U8622222216:@@<55QW0=Rl45Dp888,0*48"

<- I can decode this strings with online AIS decoder well, but when I put it in your library, it returns null.

using System; 
using System.Windows.Forms; 

using MissionPlanner;
using MissionPlanner.Utilities;
using System.Collections.Generic;
using System.Linq;
using MissionPlanner.Controls;

using AisParser;

using System.Text.RegularExpressions;

namespace AISParserSanityTestPlugins
{
    public class AISParserSanityTestPlugins : MissionPlanner.Plugin.Plugin
    {
        AisParser.Parser parser;

        public override string Name
        {
            get { return "AIS Parser Sanity Test Plugins"; }
        }

        public override string Version
        {
            get { return "0.30"; }
        }

        public override string Author
        {
            get { return "Open Source Community"; }
        }

        public override bool Init()
        {
            return true;
        }

        public override bool Loaded() //Loaded called after the plugin dll successfully loaded(different from loop())
        {
            parser = new AisParser.Parser();

            loopratehz = 12.0f;

            return true;
        }

        public override bool Loop()
        {
            string test_string = "!AIVDM,2,1,6,A,56T6Bb82;pL`A<t;N20Lht84j0qD8U8622222216:@@<55QW0=Rl`45Dp888,0*48";
            try
            {
                var aisMessage = parser.Parse(test_string);
                //Console.WriteLine("MMSI Number : " + aisMessage.Mmsi); //Error. Mmsi is null.
                //Console.WriteLine("MMSI Number : " + aisMessage.mmsi); //Error. there is no member mmsi.
                //Console.WriteLine("Ship Name : " + aisMessage.ShipName); //Error. no member. "ShipName" even though web AIS parser get ship name on this string.
                //Console.WriteLine(aisMessage); //Print blank Texts.
                //Console.WriteLine("ShipType : " + aisMessage.ShipType); //no member. "ShipType"
                Console.WriteLine("Latitude : " + aisMessage.Latitude); //no member. "Latitude"
            }
            catch (Exception e)
            {
                Console.WriteLine("Error with this string : " + test_string);
                Console.WriteLine("Error code : " + e);
                Console.WriteLine("Stack Trace : " + e.StackTrace); 
            }

            loopratehz = 20.0f;
            return true;
        }

        public override bool Exit()
        {
            return true;
        }

    }
}

this code is mission planner plugin.

you can test this by install mission planner and put this *.cs file to plugins folder.

I can decode almost all message, but sometimes static and voyage related data? message doesn't read well.

Encoding Updates

Great project! We have added the base support for encoding a class to a binary AIS message as well in our fork and wondering if you're interested in pulling in these updates?

https://github.com/darren1713/AisParser/tree/DotNetStandard

There is a few notes for universal use:
Expand the testing framework to include encoding
Add the encoding function for text (not exactly sure about the exact character transformation required)
Add encode function for remaining message types after text field encoding

Bug in Payload.ReadInt

I believe the Math.Pow should be:

    public int ReadInt(int startIndex, int length)
    {
        var bitValue = Substring(startIndex, length);
        var result = Convert.ToInt32(bitValue.Substring(1), 2);
        if (bitValue.StartsWith("1"))
            result = (int) (result - Math.Pow(2, bitValue.Length - 1 ));
        return result;
    }

Also, in conjunction, ReadRateOfTurn needs to return

    return rateOfTurn == -128 ? null : new int?(rateOfTurn);

Validation of Payload length

Hi, I've got <1 day experience with your library, but it's looking good so far!
I quickly catapulted a project together today for our system [we get raw AIS bytes, so I'm side-stepping the NMEA sentence parsing] and noticed that it seems possible to chuck invalid messages at it - e.g. a Message type 5 with only 2 bytes.
With many (all?) of the AIS message types being defined as a fixed numbers of bits, I was wondering if AisParser should throw if the Payload is too short (or too long) for the message type indicated by the first byte?
I've only been reading AIS spec for a couple of weeks, so apologies if I've over-simplified, but just looking to ensure catching rogue/corner cases in our code too.
'For discussion', not a criticism ;)

Unrecognised message type: GroupAssignmentCommand

GroupAssignmentCommand does not appear to be implemented.

This message:
"!AIVDM,1,1,,B,GM3NJTo9MWGe<6::LQCW3CiE9fl,2*4C"

threw the error:
AisParser.AisMessageException: 'Unrecognised message type: GroupAssignmentCommand'

I'll see if I can get some time to write some code to handle it, but it's not very important....would be more for sake of completeness. Per https://gpsd.gitlab.io/gpsd/AIVDM.html#_type_23_group_assignment_command:

"This message is intended to be broadcast by a competent authority (an AIS network-control base station) to set operational parameters for all mobile stations in an AIS coverage region. Length is 160 bits.

This message contains no navigational information, and is unlikely to be of interest unless you are implementing or studying an AIS base station network."

Code partially reused in dotnet/iot

Hi!

I have long been looking for an AIS parser I can integrate into our NMEA parser. This library helped me find around the basic stuff and so I started integrating it into https://github.com/dotnet/iot/, where I'm a maintainer. That project is officially supported by the .NET foundation and provides interfacing APIs for all kinds of iot devices and sensors.

You can find the PR I created at dotnet/iot#1939. You are welcome to provide any suggestions/improvements.

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.