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:
@@ -49,6 +49,7 @@ type PatternConfig struct {
|
|||||||
const (
|
const (
|
||||||
arrPatternString = `^\((?P<type>[A-Z]{3})-(?P<number>[A-Z0-9]+)-(?P<ssr>[A-Z0-9]+)-(?P<departure>[A-Z]{4})-(?P<arrival>[A-Z]{4})\)$`
|
arrPatternString = `^\((?P<type>[A-Z]{3})-(?P<number>[A-Z0-9]+)-(?P<ssr>[A-Z0-9]+)-(?P<departure>[A-Z]{4})-(?P<arrival>[A-Z]{4})\)$`
|
||||||
depPatternString = `^\((?P<type>[A-Z]{3})-(?P<number>[A-Z0-9]+)-(?P<ssr>[A-Z0-9]+)-(?P<departure>[A-Z]{4})-(?P<departure_time>\d{4})-(?P<arrival>[A-Z]{4})\)$`
|
depPatternString = `^\((?P<type>[A-Z]{3})-(?P<number>[A-Z0-9]+)-(?P<ssr>[A-Z0-9]+)-(?P<departure>[A-Z]{4})-(?P<departure_time>\d{4})-(?P<arrival>[A-Z]{4})\)$`
|
||||||
|
fplPatternString = `^\((?P<type>[A-Z]{3})\-(?P<number>[A-Z]+\d+)\-(?P<indicator>[A-Z]{2})(?:.*\s*)?\-(?P<aircraft>[A-Z]+\d+\/?[A-Z]?)\s*\-(?P<surve>.*)\s*\-(?P<departure>[A-Z]{4})(?P<departure_time>\d{4})\s*\-(?P<speed>[A-Z]+\d+)(?P<level>[A-Z0-9]+)\s(?P<route>.*)\s*\-(?P<destination>[A-Z]{4})(?P<estt>\d{4})\s(?P<alter>[A-Z]{4})\s*\-(?P<pbn>PBN\/[A-Z0-9]+)\s(?P<nav>NAV\/\w+)\sREG\/(?P<reg>[A-Z0-9]+)\sEET\/(?P<eet>\w{4}\d{4})\sSEL\/(?P<sel>\w+)\sPER\/(?P<performance>\w)\sRIF\/(?P<rif>\w+\s[A-Z0-9]+\s[A-Z]+)\s*RMK\/(?P<remark>.*)\)$`
|
||||||
)
|
)
|
||||||
|
|
||||||
// Initialize the bodyPatterns map
|
// Initialize the bodyPatterns map
|
||||||
@@ -71,6 +72,15 @@ var bodyPatterns = map[string]BodyConfig{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"FPL": {
|
||||||
|
Patterns: []PatternConfig{
|
||||||
|
{
|
||||||
|
Pattern: fplPatternString,
|
||||||
|
Comments: "Pattern for FPL message",
|
||||||
|
Expression: regexp.MustCompile(fplPatternString),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBodyPatterns() map[string]BodyConfig {
|
func GetBodyPatterns() map[string]BodyConfig {
|
||||||
|
|||||||
@@ -41,6 +41,22 @@ func (p AFTNParser) Parse(text string) (interface{}, error) {
|
|||||||
DepartureTime: data["departure_time"],
|
DepartureTime: data["departure_time"],
|
||||||
Destination: data["arrival"],
|
Destination: data["arrival"],
|
||||||
}, nil
|
}, 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:
|
default:
|
||||||
return nil, fmt.Errorf("invalid message type")
|
return nil, fmt.Errorf("invalid message type")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,34 @@ var _ = Describe("AFTN Parser", func() {
|
|||||||
Expect(depMessage.Destination).To(Equal("KLAX"))
|
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() {
|
It("should return an error for invalid message types", func() {
|
||||||
message := "(XYZ-AB123-SSR1234-KJFK-KLAX)"
|
message := "(XYZ-AB123-SSR1234-KJFK-KLAX)"
|
||||||
parser := AFTNParser{}
|
parser := AFTNParser{}
|
||||||
|
|||||||
Reference in New Issue
Block a user