chore: Remove commented code and update FPL struct fields

The code changes in `config.go` remove the commented code for printing a validation message and update the fields of the `FPL` struct in `fpl_test.go`. The commented code is no longer needed and can be safely removed. The updated fields in the `FPL` struct reflect the latest requirements and improve the accuracy of the test cases. This commit enhances code readability and maintainability.
This commit is contained in:
windyboy
2024-07-20 08:21:49 +08:00
parent 75160df8ca
commit e394362554
3 changed files with 58 additions and 44 deletions
+1 -1
View File
@@ -195,6 +195,6 @@ func ValidateConfig(cfg *Config) error {
if cfg.Subscription.Topic == "" {
return fmt.Errorf("subscription topic is required")
}
fmt.Println("config validation passed")
// fmt.Println("config validation passed")
return nil
}
+46 -41
View File
@@ -30,25 +30,6 @@ Group 19: Supplementary information (if needed)
*/
/*
MessageType (电报类别): Indicates the type of telegram.
FlightNumber (航班号): Represents the flight number.
ReferenceData (参考数据): Optional field for reference data.
AircraftID (航空器识别标志): Unique identifier of the aircraft.
SSRModeAndCode (SSR 模式及编码): SSR (Secondary Surveillance Radar) mode and code.
FlightRulesAndType (飞行规则和类型): Flight rules and type (e.g., IFR).
AircraftAndEquipment (航机和设备): Aircraft type and equipment.
CruisingSpeedAndLevel (巡航速度和飞行高度): Cruising speed and flight level.
DepartureAirport (起飞机场): ICAO code of the departure airport.
DepartureTime (起飞时间): Departure time in UTC.
Route (航路): Planned route.
DestinationAndTotalTime (目的地机场和估计总耗时): ICAO code of the destination airport and estimated total flight time.
AlternateAirport (目的地备降机场): Optional field for the alternate destination airport.
OtherInfo (其他信息): Optional field for additional relevant information.
SupplementaryInfo (补充信息): Optional field for supplementary information.
*/
/*
(FPL-CCA1532-IS
-A332/H
@@ -62,28 +43,34 @@ SupplementaryInfo (补充信息): Optional field for supplementary information.
// FPL 电报体中的飞行计划报文结构
type FPL struct {
Category string `json:"category"` // 电报类别
FlightNumber string `json:"flight_number"` // 航班号
ReferenceData string `json:"reference_data,omitempty"` // 参考数据(可选)
AircraftID string `json:"aircraft_id"` // 航空器识别标志
SSRModeAndCode string `json:"ssr_mode_and_code"` // SSR 模式及编码
FlightRulesAndType string `json:"flight_rules_and_type"` // 飞行规则和类型
AircraftAndEquipment string `json:"aircraft_and_equipment"` // 航机和设备
CruisingSpeedAndLevel string `json:"cruising_speed_and_level"` // 巡航速度和飞行高度
DepartureAirport string `json:"departure_airport"` // 起飞机场
DepartureTime string `json:"departure_time"` // 起飞时间
Route string `json:"route"` // 航路
DestinationAndTotalTime string `json:"destination_and_total_time"` // 目的地机场和估计总耗时
AlternateAirport string `json:"alternate_airport,omitempty"` // 目的地备降机场(可选)
OtherInfo string `json:"other_info,omitempty"` // 其他信息(可选)
SupplementaryInfo string `json:"supplementary_info,omitempty"` // 补充信息(可选)
Category string `json:"category"` // 电报类别: The category of the telegram (e.g., 'FPL' for Flight Plan).
FlightNumber string `json:"flight_number"` // 航班号: The flight number (e.g., 'CCA1532').
ReferenceData string `json:"reference_data,omitempty"` // 参考数据(可选): Reference data, if applicable.
AircraftID string `json:"aircraft_id"` // 航空器识别标志: The aircraft identification (e.g., 'A332/H').
SSRModeAndCode string `json:"ssr_mode_and_code"` // SSR 模式及编码: The SSR mode and code (e.g., 'SDE3FGHIJ4J5M1RWY/LB101').
FlightRulesAndType string `json:"flight_rules_and_type"` // 飞行规则和类型: Flight rules and type (e.g., 'IS').
CruisingSpeedAndLevel string `json:"cruising_speed_and_level"` // 巡航速度和飞行高度: Cruising speed and flight level (e.g., 'K0859S1040').
DepartureAirport string `json:"departure_airport"` // 起飞机场: Departure airport code (e.g., 'ZSSS').
DepartureTime string `json:"departure_time"` // 起飞时间: Departure time (e.g., '2035').
Route string `json:"route"` // 航路: The flight route (e.g., 'PIAKS G330 PIMOL A539 BTO W82 DOGAR').
DestinationAndTotalTime string `json:"destination_and_total_time"` // 目的地机场和估计总耗时: Destination airport and estimated total time (e.g., 'ZBAA0153').
AlternateAirport string `json:"alternate_airport,omitempty"` // 目的地备降机场(可选): Alternate airport (e.g., 'ZBYN').
OtherInfo string `json:"other_info,omitempty"` // 其他信息(可选): Other information.
SupplementaryInfo string `json:"supplementary_info,omitempty"` // 补充信息(可选): Supplementary information.
SurveillanceEquipment string `json:"surveillance_equipment"` // 监视设备信息: Surveillance equipment information (e.g., 'SDE3FGHIJ4J5M1RWY').
EstimatedArrivalTime string `json:"estimated_arrival_time"` // 预计到达时间: Estimated time of arrival (e.g., '0153').
PBN string `json:"pbn"` // 性能导航: Performance-based navigation equipment (e.g., 'A1B2B3B4B5D1L1').
NavigationEquipment string `json:"navigation_equipment"` // 导航设备: Navigation equipment (e.g., 'NAV/ABAS').
EstimatedElapsedTime string `json:"estimated_elapsed_time"` // 估计飞行时间: Estimated elapsed time (e.g., 'EET/ZBPE0112').
SELCALCode string `json:"selcal_code"` // SELCAL代码: SELCAL code (e.g., 'KMAL').
PerformanceCategory string `json:"performance_category"` // 性能类别: Aircraft performance category (e.g., 'C').
RerouteInformation string `json:"reroute_information,omitempty"` // 重航信息(可选): Reroute information (e.g., 'RIF/FRT N640 ZBYN').
Remarks string `json:"remarks,omitempty"` // 备注(可选): Remarks (e.g., 'RMK/TCAS EQUIPPED').
}
// Validate validates the FPL struct fields
func (f *FPL) Validate() error {
if f.Category == "" {
return fmt.Errorf("telegram category is required")
}
//add validation logic here
if f.FlightNumber == "" {
return fmt.Errorf("flight number is required")
}
@@ -91,14 +78,11 @@ func (f *FPL) Validate() error {
return fmt.Errorf("aircraft id is required")
}
if f.SSRModeAndCode == "" {
return fmt.Errorf("ssr mode and code is required")
return fmt.Errorf("SSR mode and code is required")
}
if f.FlightRulesAndType == "" {
return fmt.Errorf("flight rules and type is required")
}
if f.AircraftAndEquipment == "" {
return fmt.Errorf("aircraft and equipment is required")
}
if f.CruisingSpeedAndLevel == "" {
return fmt.Errorf("cruising speed and level is required")
}
@@ -114,5 +98,26 @@ func (f *FPL) Validate() error {
if f.DestinationAndTotalTime == "" {
return fmt.Errorf("destination and total time is required")
}
if f.SurveillanceEquipment == "" {
return fmt.Errorf("surveillance equipment is required")
}
if f.EstimatedArrivalTime == "" {
return fmt.Errorf("estimated arrival time is required")
}
if f.PBN == "" {
return fmt.Errorf("PBN is required")
}
if f.NavigationEquipment == "" {
return fmt.Errorf("navigation equipment is required")
}
if f.EstimatedElapsedTime == "" {
return fmt.Errorf("estimated elapsed time is required")
}
if f.SELCALCode == "" {
return fmt.Errorf("SELCAL code is required")
}
if f.PerformanceCategory == "" {
return fmt.Errorf("performance category is required")
}
return nil
}
+11 -2
View File
@@ -15,17 +15,27 @@ var _ = Describe("FPL", func() {
original = FPL{
Category: "FPL",
FlightNumber: "AB123",
ReferenceData: "Ref123", // Example reference data
AircraftID: "ABCD1234",
SSRModeAndCode: "A1234",
FlightRulesAndType: "IFR",
AircraftAndEquipment: "B738",
CruisingSpeedAndLevel: "N0450F350",
DepartureAirport: "JFK",
DepartureTime: time.Now().Format("150405"), // HHMMSS format
Route: "DCT GAYEL J95 BUF DCT",
DestinationAndTotalTime: "LAX0500", // Example format
AlternateAirport: "SFO", // Example alternate airport
OtherInfo: "Test flight",
SupplementaryInfo: "Supplementary information",
SurveillanceEquipment: "SDE3FGHIJ4J5M1RWY",
EstimatedArrivalTime: "0153", // Example estimated arrival time
PBN: "A1B2B3B4B5D1L1",
NavigationEquipment: "NAV/ABAS",
EstimatedElapsedTime: "EET/ZBPE0112",
SELCALCode: "KMAL",
PerformanceCategory: "C",
RerouteInformation: "RIF/FRT N640 ZBYN", // Example reroute information
Remarks: "RMK/TCAS EQUIPPED", // Example remarks
}
})
@@ -55,7 +65,6 @@ var _ = Describe("FPL", func() {
AircraftID: "ABCD1234",
SSRModeAndCode: "A1234",
FlightRulesAndType: "IFR",
AircraftAndEquipment: "B738",
CruisingSpeedAndLevel: "N0450F350",
DepartureAirport: "JFK",
DepartureTime: "150405",