refactor: Update AFTN message parsing logic
This commit is contained in:
@@ -94,6 +94,7 @@ const (
|
||||
// - remark: Matches remarks, capturing any characters in this segment.
|
||||
//
|
||||
// The regular expression uses named capture groups for each segment, allowing for easy extraction of specific information from a matched flight plan string.
|
||||
// fplPatternString = `\((?P<category>[A-Z]{3})\-(?P<number>[A-Z]+\d+)\-(?P<indicator>[A-Z]{2})(.*\n)?(.*\n)?\-(?P<aircraft>[A-Z]+\d+\/?[A-Z]?)\s*\-(?P<surve>.*)(.*\n)?\-(?P<departure>[A-Z]{4})(?P<departure_time>\d{4})(.*\n)?\-(?P<speed>[A-Z]+\d+)(?P<level>[A-Z0-9]+)\s(?P<route>.*)(.*\n)?\-(?P<destination>[A-Z]{4})(?P<estt>\d{4})\s(?P<alter>[A-Z]{4})(.*\n)?\-(?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>.*)\)$`
|
||||
fplPatternString = `\((?P<category>[A-Z]{3})\-(?P<number>[A-Z]+\d+)\-(?P<indicator>[A-Z]{2})(.*\n)?(.*\n)?\-(?P<aircraft>[A-Z]+\d+\/?[A-Z]?)\s*\-(?P<surve>.*)(.*\n)?\-(?P<departure>[A-Z]{4})(?P<departure_time>\d{4})(.*\n)?\-(?P<speed>[A-Z]+\d+)(?P<level>[A-Z0-9]+)\s(?P<route>.*)(.*\n)?\-(?P<destination>[A-Z]{4})(?P<estt>\d{4})\s(?P<alter>[A-Z]{4})(.*\n)?\-(?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>.*)\)$`
|
||||
)
|
||||
|
||||
|
||||
+123
-22
@@ -2,35 +2,136 @@ package domain
|
||||
|
||||
import "time"
|
||||
|
||||
// An aviation message typically contains various fields that are crucial for air traffic management and communication.
|
||||
//These fields include identifiers, date and time, priority indicators, addresses,
|
||||
//and additional information such as call signs, flight plans, route details, altitude, speed, position,
|
||||
//emergency indicators, report types, supplementary information, filing times, originator indicators, service information,
|
||||
//and navigation aid details. The ParsedMessage struct is designed to encapsulate all these details in a structured format.
|
||||
|
||||
/*
|
||||
Example message 1:
|
||||
ZCZC TMQ1324 150631
|
||||
FF ZBTJZPZX
|
||||
150630 ZBACZQZX
|
||||
CALLSIGN/ABC123
|
||||
FPL/AB1234-AB
|
||||
ROUTE/NOR1.DCT
|
||||
ALTITUDE/35000FT
|
||||
SPEED/450KT
|
||||
POSITION/N55W011
|
||||
EMG/N
|
||||
RPT/POS
|
||||
SUP/Additional info
|
||||
FLIGHTPLANID/FP1234
|
||||
FILTIME/150600
|
||||
ORIIND/AB12
|
||||
SERINFO/Service info
|
||||
NAVINFO/NAV details
|
||||
|
||||
Field values:
|
||||
StartIndicator: "ZCZC".
|
||||
MessageID: "TMQ1324".
|
||||
DateTime: "150631".
|
||||
PriorityIndicator: "FF".
|
||||
PrimaryAddress: "ZBTJZPZX".
|
||||
SecondaryAddresses: ["150630", "ZBACZQZX"].
|
||||
Originator: "".
|
||||
OriginatorDateTime: "".
|
||||
Category: "".
|
||||
BodyAndFooter: "CALLSIGN/ABC123\nFPL/AB1234-AB\nROUTE/NOR1.DCT\nALTITUDE/35000FT\nSPEED/450KT\nPOSITION/N55W011\nEMG/N\nRPT/POS\nSUP/Additional info\nFLIGHTPLANID/FP1234\nFILTIME/150600\nORIIND/AB12\nSERINFO/Service info\nNAVINFO/NAV details".
|
||||
BodyData: nil.
|
||||
ReceivedAt: time.Time{}.
|
||||
ParsedAt: time.Time{}.
|
||||
DispatchedAt: time.Time{}.
|
||||
NeedDispatch: false.
|
||||
CallSign: "ABC123".
|
||||
FlightPlanID: "FP1234".
|
||||
Route: "NOR1.DCT".
|
||||
Altitude: "35000FT".
|
||||
Speed: "450KT".
|
||||
Position: "N55W011".
|
||||
EmergencyIndicator: "N".
|
||||
ReportType: "POS".
|
||||
SupplementaryInfo: "Additional info".
|
||||
FilingTime: "150600".
|
||||
OriginatorIndicator: "AB12".
|
||||
ServiceInformation: "Service info".
|
||||
NavigationAidInfo: "NAV details".
|
||||
*/
|
||||
|
||||
/*
|
||||
Start Indicator: ZCZC
|
||||
Message ID: TMQ1324
|
||||
Date-Time: 150631
|
||||
Priority Indicator: FF
|
||||
Primary Address: ZBTJZPZX
|
||||
Secondary Addresses: 150630 ZBACZQZX
|
||||
Originator and Originator Date-Time: Not present in this example but handled if present.
|
||||
Example message 2:
|
||||
ZCZC XMP4567 120915
|
||||
DD KLAXZPZX
|
||||
120914 KSFOZQZX
|
||||
CALLSIGN/DEF456
|
||||
FPL/CD5678-DC
|
||||
ROUTE/NOR2.DCT
|
||||
ALTITUDE/36000FT
|
||||
SPEED/500KT
|
||||
POSITION/N54W012
|
||||
EMG/Y
|
||||
RPT/WX
|
||||
SUP/Weather related info
|
||||
FLIGHTPLANID/FP5678
|
||||
FILTIME/120900
|
||||
ORIIND/CD34
|
||||
SERINFO/Service related info
|
||||
NAVINFO/Navigation details
|
||||
|
||||
Field values:
|
||||
StartIndicator: "ZCZC".
|
||||
MessageID: "XMP4567".
|
||||
DateTime: "120915".
|
||||
PriorityIndicator: "DD".
|
||||
PrimaryAddress: "KLAXZPZX".
|
||||
SecondaryAddresses: ["120914", "KSFOZQZX"].
|
||||
Originator: "".
|
||||
OriginatorDateTime: "".
|
||||
Category: "".
|
||||
BodyAndFooter: "CALLSIGN/DEF456\nFPL/CD5678-DC\nROUTE/NOR2.DCT\nALTITUDE/36000FT\nSPEED/500KT\nPOSITION/N54W012\nEMG/Y\nRPT/WX\nSUP/Weather related info\nFLIGHTPLANID/FP5678\nFILTIME/120900\nORIIND/CD34\nSERINFO/Service related info\nNAVINFO/Navigation details".
|
||||
BodyData: nil.
|
||||
ReceivedAt: time.Time{}.
|
||||
ParsedAt: time.Time{}.
|
||||
DispatchedAt: time.Time{}.
|
||||
NeedDispatch: false.
|
||||
CallSign: "DEF456".
|
||||
FlightPlanID: "FP5678".
|
||||
Route: "NOR2.DCT".
|
||||
Altitude: "36000FT".
|
||||
Speed: "500KT".
|
||||
Position: "N54W012".
|
||||
EmergencyIndicator: "Y".
|
||||
ReportType: "WX".
|
||||
SupplementaryInfo: "Weather related info".
|
||||
FilingTime: "120900".
|
||||
OriginatorIndicator: "CD34".
|
||||
ServiceInformation: "Service related info".
|
||||
NavigationAidInfo: "Navigation details".
|
||||
*/
|
||||
|
||||
// ParsedMessage holds the parsed data from an aviation message
|
||||
type ParsedMessage struct {
|
||||
StartIndicator string // Start of the message indicator
|
||||
MessageID string // Unique identifier for the message
|
||||
DateTime string // Date and time the message was created
|
||||
PriorityIndicator string // Priority level of the message
|
||||
PrimaryAddress string // Primary recipient address
|
||||
SecondaryAddresses []string // Additional recipient addresses
|
||||
Originator string // Sender of the message
|
||||
OriginatorDateTime string // Date and time when the originator sent the message
|
||||
Category string // Category of the message
|
||||
BodyAndFooter string
|
||||
BodyData interface{}
|
||||
ReceivedAt time.Time
|
||||
ParsedAt time.Time
|
||||
DispatchedAt time.Time
|
||||
NeedDispatch bool
|
||||
StartIndicator string `json:"startIndicator"` // "ZCZC".
|
||||
MessageID string `json:"messageId"` // "TMQ1324".
|
||||
DateTime string `json:"dateTime"` // "150631".
|
||||
PriorityIndicator string `json:"priorityIndicator"` // "FF".
|
||||
PrimaryAddress string `json:"primaryAddress"` // "ZBTJZPZX".
|
||||
SecondaryAddresses []string `json:"secondaryAddresses,omitempty"` // ["150630", "ZBACZQZX"].
|
||||
Originator string `json:"originator,omitempty"` // "".
|
||||
OriginatorDateTime string `json:"originatorDateTime,omitempty"` // "".
|
||||
Category string `json:"category,omitempty"` // "".
|
||||
BodyAndFooter string `json:"bodyAndFooter,omitempty"` // "CALLSIGN/ABC123\nFPL/AB1234-AB\nROUTE/NOR1.DCT\nALTITUDE/35000FT\nSPEED/450KT\nPOSITION/N55W011\nEMG/N\nRPT/POS\nSUP/Additional info\nFLIGHTPLANID/FP1234\nFILTIME/150600\nORIIND/AB12\nSERINFO/Service info\nNAVINFO/NAV details".
|
||||
BodyData interface{} `json:"bodyData,omitempty"` // nil.
|
||||
ReceivedAt time.Time `json:"receivedAt"` // time.Time{}.
|
||||
ParsedAt time.Time `json:"parsedAt,omitempty"` // time.Time{}.
|
||||
DispatchedAt time.Time `json:"dispatchedAt,omitempty"` // time.Time{}.
|
||||
NeedDispatch bool `json:"needDispatch"` // false.
|
||||
}
|
||||
|
||||
// NewParsedMessage initializes a ParsedMessage with default values
|
||||
func NewParsedMessage() *ParsedMessage {
|
||||
return &ParsedMessage{
|
||||
SecondaryAddresses: []string{},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user