diff --git a/source/CPDLCServer.Tests/Clients/HoppieAcarsClientTests.cs b/source/CPDLCServer.Tests/Clients/HoppieAcarsClientTests.cs index 64ac5a3..88db370 100644 --- a/source/CPDLCServer.Tests/Clients/HoppieAcarsClientTests.cs +++ b/source/CPDLCServer.Tests/Clients/HoppieAcarsClientTests.cs @@ -388,6 +388,37 @@ public async Task Poll_WithoutMessageReferenceNumbers_MapsCorrectly() _clients.Remove(client); } + [Fact] + public async Task Poll_Data1PositionReport_ParsesCorrectly() + { + // Arrange + var httpHandler = new TestHttpMessageHandler(); + httpHandler.QueueResponse( + HttpStatusCode.OK, + "ok {UAL123 cpdlc {/DATA1/*/*/*/*/FL380/*/0.84/\n\nOVER MEPAB AT 0501Z, FL380,\nESTIMATING ISTEM AT 0533Z,\nNEXT MISLY.\n\nETA AT 0736Z,\n39.60 X 1000 KG FUEL REMAINING.}}"); + httpHandler.SetResponse(HttpStatusCode.OK, "ok"); + var client = CreateClient(httpHandler); + + // Act + await client.Connect(CancellationToken.None); + await Task.Delay(100); // Give polling task time to start + + using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); + var message = await client.MessageReader.ReadAsync(cts.Token); + + // Assert + Assert.Equal("UAL123", message.Sender); + Assert.Equal(-1, message.MessageId); + Assert.Null(message.MessageReference); + Assert.Equal(CpdlcDownlinkResponseType.NoResponse, message.ResponseType); + Assert.Equal( + "OVER MEPAB AT 0501Z, FL380, ESTIMATING ISTEM AT 0533Z, NEXT MISLY. ETA AT 0736Z, 39.60 X 1000 KG FUEL REMAINING.", + message.Content); + + await client.DisposeAsync(); + _clients.Remove(client); + } + [Fact] public async Task ListConnections_ReturnsCallsigns() { diff --git a/source/CPDLCServer/Clients/HoppieAcarsClient.cs b/source/CPDLCServer/Clients/HoppieAcarsClient.cs index 8c90da8..ae2c0d9 100644 --- a/source/CPDLCServer/Clients/HoppieAcarsClient.cs +++ b/source/CPDLCServer/Clients/HoppieAcarsClient.cs @@ -414,6 +414,9 @@ static List ExtractMessages(string responseText) ReceivedDownlink ParseCpdlcDownlink(string from, string packet) { + if (packet.StartsWith("/DATA1/", StringComparison.OrdinalIgnoreCase)) + return ParseData1Downlink(from, packet); + var parts = packet.Split('/', 6); if (parts.Length != 6) throw new MessageParseException($"Invalid CPDLC packet: Expected 6 components, got {parts.Length}: \"{packet}\""); @@ -439,6 +442,30 @@ ReceivedDownlink ParseCpdlcDownlink(string from, string packet) _clock.UtcNow()); } + // Some aircraft (for example, PMDG) send position reports in this format: + // /DATA1/*/*/*/*/FL380/*/0.84/ + // + // OVER MEPAB AT 0501Z, FL380, + // ESTIMATING ISTEM AT 0533Z, + // ... + // The first line is a header. The lines after the header contain the text of the report. + ReceivedDownlink ParseData1Downlink(string from, string packet) + { + var lines = packet.Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + var content = lines.Length > 1 + ? string.Join(" ", lines[1..]) + : packet; + + return new ReceivedDownlink( + -1, + null, + from, + CpdlcDownlinkResponseType.NoResponse, + AlertType.None, + content, + _clock.UtcNow()); + } + // Packet formats: // REPORT [] // REJECT