-
Notifications
You must be signed in to change notification settings - Fork 12
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
Adding UnixTimestamp + Parse message type 27 #149
base: main
Are you sure you want to change the base?
Changes from all commits
0f850eb
05f38c8
c968667
f8c9973
d729321
5a1a1c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Ais.Net.Models.Abstractions | ||
{ | ||
public interface IAisMessageType27 | ||
{ | ||
float? CourseOverGroundDegrees { get; } | ||
|
||
bool NotGnssPosition { get; } | ||
|
||
NavigationStatus NavigationStatus { get; } | ||
|
||
Position? Position { get; } | ||
|
||
bool PositionAccuracy { get; } | ||
|
||
float? SpeedOverGround { get; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Ais.Net.Models.Abstractions; | ||
|
||
public interface ITimestamp | ||
{ | ||
public long? UnixTimestamp { get; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// <copyright file="AisMessageType18.cs" company="Endjin Limited"> | ||
// Copyright (c) Endjin Limited. All rights reserved. | ||
// </copyright> | ||
|
||
namespace Ais.Net.Models | ||
{ | ||
using Ais.Net.Models.Abstractions; | ||
|
||
public record AisMessageType27( | ||
float? CourseOverGroundDegrees, | ||
bool NotGnssPosition, | ||
uint Mmsi, | ||
NavigationStatus NavigationStatus, | ||
Position? Position, | ||
bool PositionAccuracy, | ||
bool RaimFlag, | ||
uint RepeatIndicator, | ||
float? SpeedOverGround, | ||
long? UnixTimestamp) : | ||
AisMessageBase(MessageType: 27, Mmsi, UnixTimestamp), | ||
IAisMessageType27, | ||
IRaimFlag, | ||
IRepeatIndicator; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,31 +30,37 @@ public void OnNext(in NmeaLineParser parsedLine, in ReadOnlySpan<byte> asciiPayl | |
{ | ||
case >= 1 and <= 3: | ||
{ | ||
this.ParseMessageTypes1Through3(asciiPayload, padding, messageType); | ||
this.ParseMessageTypes1Through3(parsedLine, asciiPayload, padding, messageType); | ||
return; | ||
} | ||
|
||
case 5: | ||
{ | ||
this.ParseMessageType5(asciiPayload, padding); | ||
this.ParseMessageType5(parsedLine, asciiPayload, padding); | ||
return; | ||
} | ||
|
||
case 18: | ||
{ | ||
this.ParseMessageType18(asciiPayload, padding); | ||
this.ParseMessageType18(parsedLine, asciiPayload, padding); | ||
return; | ||
} | ||
|
||
case 19: | ||
{ | ||
this.ParseMessageType19(asciiPayload, padding); | ||
this.ParseMessageType19(parsedLine, asciiPayload, padding); | ||
return; | ||
} | ||
|
||
case 24: | ||
{ | ||
this.ParseMessageType24(asciiPayload, padding); | ||
this.ParseMessageType24(parsedLine, asciiPayload, padding); | ||
return; | ||
} | ||
|
||
case 27: | ||
{ | ||
this.ParseMessageType27(parsedLine, asciiPayload, padding); | ||
return; | ||
} | ||
} | ||
|
@@ -87,7 +93,7 @@ public void Progress( | |
throw new NotImplementedException(); | ||
} | ||
|
||
private void ParseMessageTypes1Through3(ReadOnlySpan<byte> asciiPayload, uint padding, int messageType) | ||
private void ParseMessageTypes1Through3(NmeaLineParser nmeaLineParser, ReadOnlySpan<byte> asciiPayload, uint padding, int messageType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact that we're now passing in a line parser and the ASCII payload seemed like a code smell to me, and now has me wondering: is there a layering issue here? The timestamp isn't really part of the AIS message, it's actually from the surrounding NMEA layer, isn't it? Before this change, these various message types represent the information that was broadcast by the vessels' AIS systems. The timestamp is not part of that. The provenance of the timestamp is not necessarily clear. It might tell us when the ground station that picked up the radio transmission received it. But in cases where messages are relayed as part of a large-scale network that collects AIS data from numerous stations, it might just tell you when the particular equipment you're plugged into received the message. So for that reason I'm not sure if it is really correct to attach this to the types that represent AIS messages. If you need access to information from the NMEA layer, might it be better to design in something where we make that available, and make it clear which pieces of information came from where? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again my scope to refactor and improve general code quality is limited as I have many other commitments but would welcome PRs on my repository if you dont want to undertake this work in yours. |
||
{ | ||
var parser = new NmeaAisPositionReportClassAParser(asciiPayload, padding); | ||
|
||
|
@@ -108,12 +114,13 @@ private void ParseMessageTypes1Through3(ReadOnlySpan<byte> asciiPayload, uint pa | |
SpareBits145: parser.SpareBits145, | ||
SpeedOverGround: parser.SpeedOverGroundTenths.FromTenths(), | ||
TimeStampSecond: parser.TimeStampSecond, | ||
TrueHeadingDegrees: parser.TrueHeadingDegrees); | ||
TrueHeadingDegrees: parser.TrueHeadingDegrees, | ||
UnixTimestamp: nmeaLineParser.TagBlock.UnixTimestamp); | ||
|
||
this.messages.OnNext(message); | ||
} | ||
|
||
private void ParseMessageType5(ReadOnlySpan<byte> asciiPayload, uint padding) | ||
private void ParseMessageType5(NmeaLineParser nmeaLineParser, ReadOnlySpan<byte> asciiPayload, uint padding) | ||
{ | ||
var parser = new NmeaAisStaticAndVoyageRelatedDataParser(asciiPayload, padding); | ||
|
||
|
@@ -137,12 +144,13 @@ private void ParseMessageType5(ReadOnlySpan<byte> asciiPayload, uint padding) | |
DimensionToStern: parser.DimensionToStern, | ||
Draught10thMetres: parser.Draught10thMetres, | ||
Spare423: parser.Spare423, | ||
PositionFixType: parser.PositionFixType); | ||
PositionFixType: parser.PositionFixType, | ||
UnixTimestamp: nmeaLineParser.TagBlock.UnixTimestamp); | ||
|
||
this.messages.OnNext(message); | ||
} | ||
|
||
private void ParseMessageType18(ReadOnlySpan<byte> asciiPayload, uint padding) | ||
private void ParseMessageType18(NmeaLineParser nmeaLineParser, ReadOnlySpan<byte> asciiPayload, uint padding) | ||
{ | ||
var parser = new NmeaAisPositionReportClassBParser(asciiPayload, padding); | ||
|
||
|
@@ -164,12 +172,13 @@ private void ParseMessageType18(ReadOnlySpan<byte> asciiPayload, uint padding) | |
TrueHeadingDegrees: parser.TrueHeadingDegrees, | ||
IsAssigned: parser.IsAssigned, | ||
RaimFlag: parser.RaimFlag, | ||
RepeatIndicator: parser.RepeatIndicator); | ||
RepeatIndicator: parser.RepeatIndicator, | ||
UnixTimestamp: nmeaLineParser.TagBlock.UnixTimestamp); | ||
|
||
this.messages.OnNext(message); | ||
} | ||
|
||
private void ParseMessageType19(ReadOnlySpan<byte> asciiPayload, uint padding) | ||
private void ParseMessageType19(NmeaLineParser nmeaLineParser, ReadOnlySpan<byte> asciiPayload, uint padding) | ||
{ | ||
var parser = new NmeaAisPositionReportExtendedClassBParser(asciiPayload, padding); | ||
|
||
|
@@ -197,12 +206,13 @@ private void ParseMessageType19(ReadOnlySpan<byte> asciiPayload, uint padding) | |
SpeedOverGround: parser.SpeedOverGroundTenths.FromTenths(), | ||
TimeStampSecond: parser.TimeStampSecond, | ||
TrueHeadingDegrees: parser.TrueHeadingDegrees, | ||
Position: Position.From10000thMins(parser.Latitude10000thMins, parser.Longitude10000thMins)); | ||
Position: Position.From10000thMins(parser.Latitude10000thMins, parser.Longitude10000thMins), | ||
UnixTimestamp: nmeaLineParser.TagBlock.UnixTimestamp); | ||
|
||
this.messages.OnNext(message); | ||
} | ||
|
||
private void ParseMessageType24(ReadOnlySpan<byte> asciiPayload, uint padding) | ||
private void ParseMessageType24(NmeaLineParser nmeaLineParser, ReadOnlySpan<byte> asciiPayload, uint padding) | ||
{ | ||
uint part = NmeaAisStaticDataReportParser.GetPartNumber(asciiPayload, padding); | ||
|
||
|
@@ -219,7 +229,8 @@ private void ParseMessageType24(ReadOnlySpan<byte> asciiPayload, uint padding) | |
Mmsi: parser.Mmsi, | ||
PartNumber: parser.PartNumber, | ||
RepeatIndicator: parser.RepeatIndicator, | ||
Spare160: parser.Spare160); | ||
Spare160: parser.Spare160, | ||
UnixTimestamp: nmeaLineParser.TagBlock.UnixTimestamp); | ||
|
||
this.messages.OnNext(message); | ||
break; | ||
|
@@ -253,12 +264,32 @@ private void ParseMessageType24(ReadOnlySpan<byte> asciiPayload, uint padding) | |
Spare162: parser.Spare162, | ||
UnitModelCode: parser.UnitModelCode, | ||
VendorIdRev3: vendorIdRev3Ascii.GetString(), | ||
VendorIdRev4: vendorIdRev4Ascii.GetString()); | ||
VendorIdRev4: vendorIdRev4Ascii.GetString(), | ||
UnixTimestamp: nmeaLineParser.TagBlock.UnixTimestamp); | ||
|
||
this.messages.OnNext(message); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
private void ParseMessageType27(NmeaLineParser nmeaLineParser, ReadOnlySpan<byte> asciiPayload, uint padding) | ||
{ | ||
var parser = new NmeaAisLongRangeAisBroadcastParser(asciiPayload, padding); | ||
|
||
var message = new AisMessageType27( | ||
Mmsi: parser.Mmsi, | ||
Position: Position.From10thMins(parser.Latitude10thMins, parser.Longitude10thMins), | ||
CourseOverGroundDegrees: parser.CourseOverGroundDegrees, | ||
PositionAccuracy: parser.PositionAccuracy, | ||
SpeedOverGround: parser.SpeedOverGroundTenths.FromTenths(), | ||
RaimFlag: parser.RaimFlag, | ||
RepeatIndicator: parser.RepeatIndicator, | ||
NotGnssPosition: parser.NotGnssPosition, | ||
NavigationStatus: parser.NavigationStatus, | ||
UnixTimestamp: nmeaLineParser.TagBlock.UnixTimestamp); | ||
|
||
this.messages.OnNext(message); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unix timestamps come in two different units: seconds and milliseconds. I don't know which this is. Please could you rename it to make the units clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was simply using the field name that you had used to maintain continuity but can rename if desired?
https://github.com/ais-dotnet/Ais.Net/blob/3f0624713cd879f0234b167e9e77b899765e8843/Solutions/Ais.Net/Ais/Net/NmeaTagBlockParser.cs#L141