Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/AisParser/AisMessage.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
using MessagePack;

namespace AisParser
{
[MessagePackObject]
public abstract class AisMessage
{
[Key(0)]
public AisMessageType MessageType { get; }
[Key(1)]
public uint Repeat { get; set; }
[Key(2)]
public uint Mmsi { get; set; }

protected AisMessage(AisMessageType messageType)
Expand All @@ -17,5 +23,10 @@ protected AisMessage(AisMessageType messageType, Payload payload)
Repeat = payload.ReadUInt(6, 2);
Mmsi = payload.ReadUInt(8, 30);
}
public virtual void Encode(Payload payload)
{
payload.WriteUInt(Repeat, 2);
payload.WriteUInt(Mmsi, 30);
}
}
}
18 changes: 17 additions & 1 deletion src/AisParser/AisMessageFactory.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
using AisParser.Messages;
using System;

namespace AisParser
{
public class AisMessageFactory
{
public Payload Encode<T>(T message) where T : AisMessage
{
Payload payload = new Payload();
switch (message)
{
case PositionReportClassAMessage t1:
t1.Encode(payload);
break;
default:
return null;
}
return payload;
}

public AisMessage Create(Payload payload)
{
switch (payload.MessageType)
Expand Down Expand Up @@ -64,7 +79,8 @@ public AisMessage Create(Payload payload)
//TODO: 51
//TODO: 57
default:
throw new AisMessageException($"Unrecognised message type: {payload.MessageType}");
return null;
// throw new AisMessageException($"Unrecognised message type: {payload.MessageType}");
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/AisParser/AisParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

<LangVersion>7.3</LangVersion>
<AssemblyName>AisParser</AssemblyName>
<PackageId>AisParser</PackageId>
Expand All @@ -18,4 +18,9 @@
<Version>1.0.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MessagePack.ImmutableCollection" Version="1.8.74" />
<PackageReference Include="MessagePackAnalyzer" Version="1.8.74" />
</ItemGroup>

</Project>
10 changes: 9 additions & 1 deletion src/AisParser/Messages/AddressedSafetyRelatedMessage.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
namespace AisParser.Messages
using MessagePack;

namespace AisParser.Messages
{
[MessagePackObject]
public class AddressedSafetyRelatedMessage : AisMessage
{
[Key(3)]
public uint SequenceNumber { get; set; }
[Key(4)]
public uint DestinationMmsi { get; set; }
[Key(5)]
public bool RetransmitFlag { get; set; }
[Key(6)]
public uint Spare { get; set; }
[Key(7)]
public string Text { get; set; }

public AddressedSafetyRelatedMessage()
Expand Down
22 changes: 21 additions & 1 deletion src/AisParser/Messages/AidToNavigationReportMessage.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
namespace AisParser.Messages
using MessagePack;
namespace AisParser.Messages
{
[MessagePackObject]
public class AidToNavigationReportMessage : AisMessage
{
[Key(3)]
public NavigationalAidType NavigationalAidType { get; set; }
[Key(4)]
public string Name { get; set; }
[Key(5)]
public PositionAccuracy PositionAccuracy { get; set; }
[Key(6)]
public double Longitude { get; set; }
[Key(7)]
public double Latitude { get; set; }
[Key(8)]
public uint DimensionToBow { get; set; }
[Key(9)]
public uint DimensionToStern { get; set; }
[Key(10)]
public uint DimensionToPort { get; set; }
[Key(11)]
public uint DimensionToStarboard { get; set; }
[Key(12)]
public PositionFixType PositionFixType { get; set; }
[Key(13)]
public uint Timestamp { get; set; }
[Key(14)]
public bool OffPosition { get; set; }
[Key(15)]
public uint RegionalReserved { get; set; }
[Key(16)]
public Raim Raim { get; set; }
[Key(17)]
public bool VirtualAid { get; set; }
[Key(18)]
public bool Assigned { get; set; }
[Key(19)]
public uint Spare { get; set; }
[Key(20)]
public string NameExtension { get; set; }

public AidToNavigationReportMessage()
Expand Down
17 changes: 16 additions & 1 deletion src/AisParser/Messages/BaseStationReportMessage.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
namespace AisParser.Messages
using MessagePack;
namespace AisParser.Messages
{
[MessagePackObject]
public class BaseStationReportMessage : AisMessage
{
[Key(3)]
public uint Year { get; set; }
[Key(4)]
public uint Month { get; set; }
[Key(5)]
public uint Day { get; set; }
[Key(6)]
public uint Hour { get; set; }
[Key(7)]
public uint Minute { get; set; }
[Key(8)]
public uint Second { get; set; }
[Key(9)]
public PositionAccuracy PositionAccuracy { get; set; }
[Key(10)]
public double Longitude { get; set; }
[Key(11)]
public double Latitude { get; set; }
[Key(12)]
public PositionFixType PositionFixType { get; set; }
[Key(13)]
public uint Spare { get; set; }
[Key(14)]
public Raim Raim { get; set; }
[Key(15)]
public uint RadioStatus { get; set; }

public BaseStationReportMessage()
Expand Down
13 changes: 12 additions & 1 deletion src/AisParser/Messages/BinaryAcknowledgeMessage.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
namespace AisParser.Messages
using MessagePack;
namespace AisParser.Messages
{
[MessagePackObject]
public class BinaryAcknowledgeMessage : AisMessage
{
[Key(3)]
public uint Spare { get; set; }
[Key(4)]
public uint SequenceNumber1 { get; set; }
[Key(5)]
public uint Mmsi1 { get; set; }
[Key(6)]
public uint SequenceNumber2 { get; set; }
[Key(7)]
public uint? Mmsi2 { get; set; }
[Key(8)]
public uint SequenceNumber3 { get; set; }
[Key(9)]
public uint? Mmsi3 { get; set; }
[Key(10)]
public uint SequenceNumber4 { get; set; }
[Key(11)]
public uint? Mmsi4 { get; set; }

public BinaryAcknowledgeMessage()
Expand Down
11 changes: 10 additions & 1 deletion src/AisParser/Messages/BinaryAddressedMessage.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
namespace AisParser.Messages
using MessagePack;
namespace AisParser.Messages
{
[MessagePackObject]
public class BinaryAddressedMessage : AisMessage
{
[Key(3)]
public uint SequenceNumber { get; set; }
[Key(4)]
public uint DestinationMmsi { get; set; }
[Key(5)]
public bool RetransmitFlag { get; set; }
[Key(6)]
public uint Spare { get; set; }
[Key(7)]
public uint DesignatedAreaCode { get; set; }
[Key(8)]
public uint FunctionalId { get; set; }
[Key(9)]
public string Data { get; set; }

public BinaryAddressedMessage()
Expand Down
8 changes: 7 additions & 1 deletion src/AisParser/Messages/BinaryBroadcastMessage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
namespace AisParser.Messages
using MessagePack;
namespace AisParser.Messages
{
[MessagePackObject]
public class BinaryBroadcastMessage : AisMessage
{
[Key(3)]
public uint Spare { get; set; }
[Key(4)]
public uint DesignatedAreaCode { get; set; }
[Key(5)]
public uint FunctionalId { get; set; }
[Key(6)]
public string Data { get; set; }

public BinaryBroadcastMessage()
Expand Down
21 changes: 20 additions & 1 deletion src/AisParser/Messages/DataLinkManagementMessage.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,42 @@
namespace AisParser.Messages
using MessagePack;
namespace AisParser.Messages
{
[MessagePackObject]
public class DataLinkManagementMessage : AisMessage
{
[Key(3)]
public uint Spare { get; set; }
[Key(4)]
public uint Offset1 { get; set; }
[Key(5)]
public uint ReservedSlots1 { get; set; }
[Key(6)]
public uint Timeout1 { get; set; }
[Key(7)]
public uint Increment1 { get; set; }
[Key(8)]
public uint Offset2 { get; set; }
[Key(9)]
public uint ReservedSlots2 { get; set; }
[Key(10)]
public uint Timeout2 { get; set; }
[Key(11)]
public uint Increment2 { get; set; }
[Key(12)]
public uint Offset3 { get; set; }
[Key(13)]
public uint ReservedSlots3 { get; set; }
[Key(14)]
public uint Timeout3 { get; set; }
[Key(15)]
public uint Increment3 { get; set; }
[Key(16)]
public uint Offset4 { get; set; }
[Key(17)]
public uint ReservedSlots4 { get; set; }
[Key(18)]
public uint Timeout4 { get; set; }
[Key(19)]
public uint Increment4 { get; set; }

public DataLinkManagementMessage()
Expand Down
24 changes: 23 additions & 1 deletion src/AisParser/Messages/ExtendedClassBCsPositionReportMessage.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
namespace AisParser.Messages
using MessagePack;
namespace AisParser.Messages
{
[MessagePackObject]
public class ExtendedClassBCsPositionReportMessage : AisMessage
{
[Key(3)]
public uint Reserved { get; set; }
[Key(4)]
public double SpeedOverGround { get; set; }
[Key(5)]
public PositionAccuracy PositionAccuracy { get; set; }
[Key(6)]
public double Longitude { get; set; }
[Key(7)]
public double Latitude { get; set; }
[Key(8)]
public double CourseOverGround { get; set; }
[Key(9)]
public uint? TrueHeading { get; set; }
[Key(10)]
public uint Timestamp { get; set; }
[Key(11)]
public uint RegionalReserved { get; set; }
[Key(12)]
public string Name { get; set; }
[Key(13)]
public ShipType ShipType { get; set; }
[Key(14)]
public uint DimensionToBow { get; set; }
[Key(15)]
public uint DimensionToStern { get; set; }
[Key(16)]
public uint DimensionToPort { get; set; }
[Key(17)]
public uint DimensionToStarboard { get; set; }
[Key(18)]
public PositionFixType PositionFixType { get; set; }
[Key(19)]
public Raim Raim { get; set; }
[Key(20)]
public bool DataTerminalReady { get; set; }
[Key(21)]
public bool Assigned { get; set; }
[Key(22)]
public uint Spare { get; set; }

public ExtendedClassBCsPositionReportMessage()
Expand Down
12 changes: 11 additions & 1 deletion src/AisParser/Messages/InterrogationMessage.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
namespace AisParser.Messages
using MessagePack;
namespace AisParser.Messages
{
[MessagePackObject]
public class InterrogationMessage: AisMessage
{
[Key(3)]
public uint InterrogatedMmsi { get; set; }
[Key(4)]
public AisMessageType FirstMessageType { get; set; }
[Key(5)]
public uint FirstSlotOffset { get; set; }

[Key(6)]
public AisMessageType? SecondMessageType { get; set; }
[Key(7)]
public uint? SecondSlotOffset { get; set; }

[Key(8)]
public uint? SecondStationInterrogationMmsi { get; set; }
[Key(9)]
public AisMessageType? SecondStationFirstMessageType { get; set; }
[Key(10)]
public uint? SecondStationFirstSlotOffset { get; set; }


Expand Down
Loading