Skip to content

Commit 61e88d5

Browse files
committed
Different problems with real-time decoding addressed
1 parent 85d9a04 commit 61e88d5

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

src/devices/Nmea0183/AisManager.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ public SentenceId GeneratedSentencesId
225225
}
226226
}
227227

228+
/// <summary>
229+
/// Provides access to the positioning provider for the AIS manager
230+
/// </summary>
231+
public PositionProvider PositionProvider => _positionProvider;
232+
228233
/// <summary>
229234
/// Gets the data of the own ship (including position and movement vectors) as a ship structure.
230235
/// </summary>

src/devices/Nmea0183/MagneticDeviationCorrection.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ void MessageFilter(NmeaSinkAndSource nmeaSinkAndSource, NmeaSentence nmeaSentenc
214214
}
215215

216216
NmeaLogDataReader reader = new NmeaLogDataReader("Reader", fileSet);
217+
reader.DecodeInRealtime = false;
217218
reader.OnNewSequence += MessageFilter;
218219
reader.StartDecode();
219220
reader.StopDecode();

src/devices/Nmea0183/NmeaLogDataReader.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public override void StartDecode()
124124
}
125125
else
126126
{
127+
_internalParser.LastPacketTime = DateTime.UnixEpoch; // Long ago
127128
_internalParser.OnNewSequence += ForwardDecoded;
128129
}
129130

@@ -149,18 +150,22 @@ private void ForwardDecoded(NmeaSinkAndSource source, NmeaSentence sentence)
149150

150151
private bool DoForwardSequence(NmeaSentence sentence)
151152
{
152-
if (sentence is RawSentence &&
153-
(sentence.SentenceId == TimeDate.Id ||
154-
sentence.SentenceId == RecommendedMinimumNavigationInformation.Id ||
155-
sentence.SentenceId == BearingAndDistanceToWayPoint.Id ||
156-
sentence.SentenceId == GlobalPositioningSystemFixData.Id ||
157-
sentence.SentenceId == PositionFastUpdate.Id))
153+
// If this is false, parse all messages with their original time stamps
154+
if (DecodeInRealtime)
158155
{
159-
// Do not forward these raw sentences, as these can only be used with a patched time.
160-
return false;
161-
}
156+
if (sentence is RawSentence &&
157+
(sentence.SentenceId == TimeDate.Id ||
158+
sentence.SentenceId == RecommendedMinimumNavigationInformation.Id ||
159+
sentence.SentenceId == BearingAndDistanceToWayPoint.Id ||
160+
sentence.SentenceId == GlobalPositioningSystemFixData.Id ||
161+
sentence.SentenceId == PositionFastUpdate.Id))
162+
{
163+
// Do not forward these raw sentences, as these can only be used with a patched time.
164+
return false;
165+
}
162166

163-
sentence.DateTime = DateTime.UtcNow;
167+
sentence.DateTime = DateTime.UtcNow;
168+
}
164169

165170
return true;
166171
}

src/devices/Nmea0183/PositionProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ public PositionProvider(SentenceCache cache)
4848
_cache = cache ?? throw new ArgumentNullException(nameof(cache));
4949
}
5050

51+
/// <summary>
52+
/// Provides access to the underlying sentence cache
53+
/// </summary>
54+
public SentenceCache Cache => _cache;
55+
5156
/// <summary>
5257
/// Get the current position from the latest message containing any of the relevant data parts. This does not extrapolate the position
5358
/// if the last received message is old

src/devices/Nmea0183/tests/Ais/AisManagerTest.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public class AisManagerTest : IDisposable
2626
public AisManagerTest()
2727
{
2828
_manager = new AisManager("Test", true, 269110660u, "Cirrus");
29+
30+
// Our test data isn't _that_ old.
31+
// We need to disable this test when replaying data with their original time stamps
32+
_manager.PositionProvider.Cache.MaxDataAge = TimeSpan.FromDays(10000);
2933
}
3034

3135
public void Dispose()
@@ -158,9 +162,9 @@ public void CheckSafety1()
158162
}
159163

160164
[Theory]
161-
[InlineData(600, 1852, 20)] // Default settings
165+
[InlineData(600, 1852, 18)] // Default settings
162166
[InlineData(600, 0, 0)] // Warning distance zero -> No warnings
163-
[InlineData(10, 1852, 39)] // Very short warning timeout -> Many warnings
167+
[InlineData(10, 1852, 34)] // Very short warning timeout -> Many warnings
164168
public void CheckSafetyPermanently(int warningRepeatSeconds, int warningDistance, int expectedWarningCount)
165169
{
166170
// This does a safety check all the time. Very expensive...
@@ -185,7 +189,8 @@ public void CheckSafetyPermanently(int warningRepeatSeconds, int warningDistance
185189
reader.OnNewSequence += (source, msg) =>
186190
{
187191
_manager.SendSentence(source, msg);
188-
if (msg.SentenceId == new SentenceId("VDM"))
192+
// Do the test when we find VDM sequences, but ignore anything until we have a valid time sync for the data
193+
if (msg.SentenceId == new SentenceId("VDM") && msg.DateTime.Year > 1970)
189194
{
190195
// This is a big number that misses some dangerous encounters, but causes the test to end in reasonable time (10s instead of 22s)
191196
if ((msgCount++ % 60) == 0)
@@ -212,7 +217,7 @@ public void CheckSafetyPermanently(int warningRepeatSeconds, int warningDistance
212217
Assert.False(ship!.IsEstimate);
213218
Assert.NotNull(ship.RelativePosition);
214219
Assert.True(ship.RelativePosition!.From.Name == "Cirrus");
215-
Assert.Equal(8260.2, ship.RelativePosition.Distance.Meters, 1);
220+
Assert.Equal(8258.7, ship.RelativePosition.Distance.Meters, 1);
216221
}
217222

218223
[Fact]

0 commit comments

Comments
 (0)