feat: Add FPL message parsing functionality

This commit adds functionality to parse FPL messages in the `aftn_parser.go` file. The `Parse` method now correctly parses the FPL message type and extracts the relevant data fields. The `FPL` struct is introduced in the `domain` package to represent FPL messages. The parsing logic is implemented to populate the `FPL` struct with the parsed data. This change enables the application to handle FPL messages and process them accordingly.
This commit is contained in:
windyboy
2024-07-20 00:46:31 +08:00
parent 969bb57902
commit afd4643696
3 changed files with 54 additions and 0 deletions
+16
View File
@@ -41,6 +41,22 @@ func (p AFTNParser) Parse(text string) (interface{}, error) {
DepartureTime: data["departure_time"],
Destination: data["arrival"],
}, nil
case "FPL":
return &domain.FPL{
Category: data["type"],
FlightNumber: data["number"],
FlightRulesAndType: data["indicator"],
AircraftID: data["aircraft"],
SSRModeAndCode: data["surve"],
DepartureAirport: data["departure"],
DepartureTime: data["departure_time"],
CruisingSpeedAndLevel: data["speed"] + data["level"],
Route: data["route"],
DestinationAndTotalTime: data["destination"] + data["estt"],
AlternateAirport: data["alter"],
OtherInfo: data["pbn"] + " " + data["nav"] + " " + "REG/" + data["reg"] + " " + "EET/" + data["eet"] + " " + "SEL/" + data["sel"] + " " + "PER/" + data["performance"] + " " + "RIF/" + data["rif"],
SupplementaryInfo: "RMK/" + data["remark"],
}, nil
default:
return nil, fmt.Errorf("invalid message type")
}
+28
View File
@@ -37,6 +37,34 @@ var _ = Describe("AFTN Parser", func() {
Expect(depMessage.Destination).To(Equal("KLAX"))
})
It("should parse FPL messages correctly", func() {
message := `(FPL-CCA1532-IS
-A332/H
-SDE3FGHIJ4J5M1RWY/LB101
-ZSSS2035
-K0859S1040 PIAKS G330 PIMOL A539 BTO W82 DOGAR
-ZBAA0153 ZBYN
-PBN/A1B2B3B4B5D1L1 NAV/ABAS REG/B6513 EET/ZBPE0112 SEL/KMAL PER/C RIF/FRT N640 ZBYN RMK/TCAS EQUIPPED)`
parser := AFTNParser{}
parsedMessage, err := parser.Parse(message)
Expect(err).NotTo(HaveOccurred())
Expect(parsedMessage).To(BeAssignableToTypeOf(&domain.FPL{}))
fplMessage := parsedMessage.(*domain.FPL)
Expect(fplMessage.FlightNumber).To(Equal("CCA1532"))
Expect(fplMessage.FlightRulesAndType).To(Equal("IS"))
Expect(fplMessage.AircraftID).To(Equal("A332/H"))
Expect(fplMessage.SSRModeAndCode).To(Equal("SDE3FGHIJ4J5M1RWY/LB101"))
Expect(fplMessage.DepartureAirport).To(Equal("ZSSS"))
Expect(fplMessage.DepartureTime).To(Equal("2035"))
Expect(fplMessage.CruisingSpeedAndLevel).To(Equal("K0859S1040"))
Expect(fplMessage.Route).To(Equal("PIAKS G330 PIMOL A539 BTO W82 DOGAR"))
Expect(fplMessage.DestinationAndTotalTime).To(Equal("ZBAA0153"))
Expect(fplMessage.AlternateAirport).To(Equal("ZBYN"))
Expect(fplMessage.OtherInfo).To(Equal("PBN/A1B2B3B4B5D1L1 NAV/ABAS REG/B6513 EET/ZBPE0112 SEL/KMAL PER/C RIF/FRT N640 ZBYN"))
Expect(fplMessage.SupplementaryInfo).To(Equal("RMK/TCAS EQUIPPED"))
})
It("should return an error for invalid message types", func() {
message := "(XYZ-AB123-SSR1234-KJFK-KLAX)"
parser := AFTNParser{}