Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Encoding AIS and MessagePack definitions #23

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jefferypalmer
Copy link

This update allows re-encoding a decoded class into a binary AIS message with headers and checksum calculations. There may be some additional refactoring to look at to define options like channel A/B in the message. We are using this to generate an AIS stream to display MMSI and location. Overall there should be no breaking changes at all, as these are new functions that do not utilize the decoding framework.

@jefferypalmer
Copy link
Author

Quick example code:

`

//Use a sentence we know works
const string sentence = "!AIVDM,1,1,,B,19NWrrP02sbuuuuhM86hA0=n2<0:,0*12";

var aisParser = new Parser();

//Decode it to a class
var decodedClass = aisParser.Parse(sentence);

//Some general rules
//MMSI must be 9 digits, positive integer
//Timestamp is the seconds component of the timestamp (it's ok to use zero instead of extracting the seconds)
//CourseOverGround and TrueHeading can be the same
//Class type "PositionReportClassAMessage" is the only message that's setup for encoding at the moment

//Re-encode that class to a sentence
var encodedString = aisParser.Parse(decodedClass);
            
//See how close we are to the original!
Console.WriteLine(encodedString);

@@ -5,7 +5,7 @@
<Copyright>Copyright Chris Richards</Copyright>
<VersionPrefix>1.0.0</VersionPrefix>
<Authors>Chris Richards</Authors>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp2.0</TargetFramework>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be changed back to netstandard2.0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I'd probably favour netstandard too - if it doesn't need any particular Framework/Core dependencies then Standard [API] keeps it most flexible? (Albeit myself being no great expert on the wealth of MS SDK terminology n concepts...)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TargetFramework can be either netstandard or netcoreapp, it compiles as is with either target. The painful issue is that VS doesn't allow you to change it easily, you have to edit the file and restart VS.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Darren, As far as I understand these things (which isn't necessarily a lot), netstandard is just an API definition which - in many/most cases - framework or core sdk's should all support? If Chris doesn't insert anything not supported by one of those SDKs, then isn't NetStandard a decent/sensible 'target' for this library?
I'm unclear why you need to re-target it at NetCore. As it is, does it prevent usage in either a FrameWork or Core app? i.e. "VS doesn't allow you to change it easily" - not sure why you need to. (If I'm missing some pertinent point, then no offence intended)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could just be my quick referencing of a library in a new project, but VS complained about building a NetCore application with AisParser as a NetStandard library, IE, wouldn't compile...

You can set it to either framework, I'm good with either.

Cheers

@@ -15,9 +15,9 @@ public Payload(string rawValue)
MessageType = ReadEnum<AisMessageType>(0, 6);
}

public string RawValue { get; }
public string RawValue; // { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RawValue has to be get/set, so the get restriction was commented out. When we take a class structure and convert it back to binary, that gets pushed into RawValue.


public AisMessageType MessageType { get; }
public AisMessageType MessageType; // { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, MessageType gets set now too, so the get restriction was removed. (Bad modification on my part, I should have just removed it entirely instead of commenting it out)

@@ -139,11 +189,19 @@ public string ReadString(int startIndex, int length)

return value.Trim();
}
/*public void WriteString(string var, int length)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented out code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this as a placeholder as I wasn't exactly clear on taking a string value and writing it to AIS stream of bits. If you have a quick look at ReadString, it should perform the reverse of that function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note, this will be necessary for converting class's with "String" fields to binary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants