Skip to content

Commit

Permalink
Improved vatsim flight tracking
Browse files Browse the repository at this point in the history
Now supports VFR flights without flight plan
Improved handling of tracking start questions, code cleaned, 15 sec timeout added
  • Loading branch information
sushiat committed Dec 14, 2023
1 parent 783abdf commit 7e9fa5f
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 46 deletions.
32 changes: 29 additions & 3 deletions OpenSky.Agent.Simulator/OpenAPIs/swagger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8941,7 +8941,7 @@ public partial class Aircraft
/// </summary>
[Newtonsoft.Json.JsonProperty("registry", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required]
[System.ComponentModel.DataAnnotations.StringLength(12, MinimumLength = 7)]
[System.ComponentModel.DataAnnotations.StringLength(12, MinimumLength = 6)]
public string Registry { get; set; }

/// <summary>
Expand Down Expand Up @@ -11200,7 +11200,7 @@ public partial class FinancialRecord
/// Gets or sets the aircraft registry (optional, if record relates to an aircraft).
/// </summary>
[Newtonsoft.Json.JsonProperty("aircraftRegistry", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[System.ComponentModel.DataAnnotations.StringLength(10, MinimumLength = 5)]
[System.ComponentModel.DataAnnotations.StringLength(12, MinimumLength = 6)]
public string AircraftRegistry { get; set; }

[Newtonsoft.Json.JsonProperty("category", Required = Newtonsoft.Json.Required.Always)]
Expand Down Expand Up @@ -11322,6 +11322,9 @@ public partial class Flight
[Newtonsoft.Json.JsonProperty("flightPhase", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public FlightPhase FlightPhase { get; set; }

[Newtonsoft.Json.JsonProperty("flightRule", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public FlightRule FlightRule { get; set; }

/// <summary>
/// Gets or sets the fuel in gallons.
/// </summary>
Expand Down Expand Up @@ -11660,6 +11663,9 @@ public partial class FlightLog
[Newtonsoft.Json.JsonProperty("atcCallsign", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public string AtcCallsign { get; set; }

[Newtonsoft.Json.JsonProperty("category", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public AircraftTypeCategory Category { get; set; }

/// <summary>
/// Gets or sets the Date/Time of when the flight was completed.
/// </summary>
Expand Down Expand Up @@ -12026,6 +12032,9 @@ public enum FlightPhase
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v11.0.0.0))")]
public partial class FlightPlan
{
[Newtonsoft.Json.JsonProperty("flightRule", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public FlightRule FlightRule { get; set; }

[Newtonsoft.Json.JsonProperty("aircraft", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
public Aircraft Aircraft { get; set; }

Expand Down Expand Up @@ -12185,6 +12194,23 @@ public partial class FlightPlanIEnumerableApiResponse

}

/// <summary>
/// Flight rules. 0 = IFR, 1 = VFR, 2 = IFRtoVFR, 3 = VFRtoIFR
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v11.0.0.0))")]
public enum FlightRule
{

IFR = 0,

VFR = 1,

IFRtoVFR = 2,

VFRtoIFR = 3,

}

/// <summary>
/// Forgot password model.
/// </summary>
Expand Down Expand Up @@ -12710,7 +12736,7 @@ public partial class Payload
/// Gets or sets the aircraft registry the payload is currently loaded on, or NULL if stored at an airport.
/// </summary>
[Newtonsoft.Json.JsonProperty("aircraftRegistry", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
[System.ComponentModel.DataAnnotations.StringLength(10, MinimumLength = 5)]
[System.ComponentModel.DataAnnotations.StringLength(12, MinimumLength = 6)]
public string AircraftRegistry { get; set; }

/// <summary>
Expand Down
42 changes: 37 additions & 5 deletions OpenSky.Agent.Simulator/OpenAPIs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4333,7 +4333,7 @@
},
"registry": {
"maxLength": 12,
"minLength": 7,
"minLength": 6,
"type": "string",
"description": "Gets or sets the aircraft registration."
},
Expand Down Expand Up @@ -6729,8 +6729,8 @@
"type": "object",
"properties": {
"aircraftRegistry": {
"maxLength": 10,
"minLength": 5,
"maxLength": 12,
"minLength": 6,
"type": "string",
"description": "Gets or sets the aircraft registry (optional, if record relates to an aircraft).",
"nullable": true
Expand Down Expand Up @@ -6851,6 +6851,9 @@
"flightPhase": {
"$ref": "#/components/schemas/FlightPhase"
},
"flightRule": {
"$ref": "#/components/schemas/FlightRule"
},
"fuelGallons": {
"type": "number",
"description": "Gets or sets the fuel in gallons.",
Expand Down Expand Up @@ -7161,6 +7164,9 @@
"description": "Gets or sets the atc callsign.",
"nullable": true
},
"category": {
"$ref": "#/components/schemas/AircraftTypeCategory"
},
"completed": {
"type": "string",
"description": "Gets or sets the Date/Time of when the flight was completed.",
Expand Down Expand Up @@ -7501,6 +7507,9 @@
],
"type": "object",
"properties": {
"flightRule": {
"$ref": "#/components/schemas/FlightRule"
},
"aircraft": {
"$ref": "#/components/schemas/Aircraft"
},
Expand Down Expand Up @@ -7649,6 +7658,29 @@
"additionalProperties": false,
"description": "API standard response model."
},
"FlightRule": {
"enum": [
0,
1,
2,
3
],
"type": "integer",
"description": "Flight rules. 0 = IFR, 1 = VFR, 2 = IFRtoVFR, 3 = VFRtoIFR",
"format": "int32",
"x-enumNames": [
"IFR",
"VFR",
"IFRtoVFR",
"VFRtoIFR"
],
"x-enum-varnames": [
"IFR",
"VFR",
"IFRtoVFR",
"VFRtoIFR"
]
},
"ForgotPassword": {
"required": [
"email"
Expand Down Expand Up @@ -8150,8 +8182,8 @@
"type": "object",
"properties": {
"aircraftRegistry": {
"maxLength": 10,
"minLength": 5,
"maxLength": 12,
"minLength": 6,
"type": "string",
"description": "Gets or sets the aircraft registry the payload is currently loaded on, or NULL if stored at an airport.",
"nullable": true
Expand Down
11 changes: 10 additions & 1 deletion OpenSky.Agent.Simulator/Simulator.Flight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,16 @@ public Flight Flight
{
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].Enabled = true;
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].Current = "Unknown";
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].Expected = $"True, Callsign: {value.AtcCallsign}, Flight plan: {value.Origin.Icao}-{value.Destination.Icao}, Location: <50 km";

// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
if (value.FlightRule != FlightRule.VFR)
{
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].Expected = $"True, Callsign: {value.AtcCallsign}, Flight plan: {value.Origin.Icao}-{value.Destination.Icao}, Location: <50 km";
}
else
{
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].Expected = $"True, Callsign: {value.AtcCallsign}, Location: <50 km";
}
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion OpenSky.Agent.Simulator/Simulator.Process.Systems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private void MonitorSecondarySystems(ProcessSecondaryTracking pst)
pst.New,
FlightTrackingEventType.TaxiLandingLightsEngine,
OpenSkyColors.OpenSkyRed,
$"OpenSky Warning: Taxi and/or Landing light on when engine was turned {(pst.New.EngineRunning ? "on" : "off")}");
$"Taxi and/or Landing light on when engine was turned {(pst.New.EngineRunning ? "on" : "off")}");
}

// Was the engine turned off on the ground, not moving, while tracking? -> Report that we can now finish up tracking
Expand Down
44 changes: 34 additions & 10 deletions OpenSky.Agent.Simulator/Simulator.Vatsim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ private void MonitorVatsimFlight()
this.VatsimClientConnection.Departure = string.Empty;
this.VatsimClientConnection.Arrival = string.Empty;
}


this.OnlineNetworkConnectionStarted ??= DateTime.UtcNow;
}
}
}
Expand Down Expand Up @@ -154,13 +151,40 @@ private void MonitorVatsimFlight()

// Update tracking condition
var locationDiffKm = this.PrimaryTracking.GeoCoordinate.GetDistanceTo(new GeoCoordinate(this.VatsimClientConnection?.Latitude ?? 0, this.VatsimClientConnection?.Longitude ?? 0, 0.3048 * this.VatsimClientConnection?.Altitude ?? 0)) / 1000;
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].Current = $"{this.VatsimClientConnection != null}, Callsign: {this.VatsimClientConnection?.Callsign ?? "none"}, Flight plan: {this.VatsimClientConnection?.Departure ?? "??"}-{this.VatsimClientConnection?.Arrival ?? "??"}, Location: {locationDiffKm:N1} km";
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].ConditionMet =
this.VatsimClientConnection != null &&
locationDiffKm < 50 &&
this.VatsimClientConnection.Callsign.Equals(this.Flight.AtcCallsign, StringComparison.InvariantCultureIgnoreCase) &&
this.VatsimClientConnection.Departure.Equals(this.Flight.Origin.Icao, StringComparison.InvariantCultureIgnoreCase) &&
this.VatsimClientConnection.Arrival.Equals(this.Flight.Destination.Icao, StringComparison.InvariantCultureIgnoreCase);

if (this.Flight.FlightRule != FlightRule.VFR)
{
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].Current = $"{this.VatsimClientConnection != null}, Callsign: {this.VatsimClientConnection?.Callsign ?? "none"}, Flight plan: {this.VatsimClientConnection?.Departure ?? "??"}-{this.VatsimClientConnection?.Arrival ?? "??"}, Location: {locationDiffKm:N1} km";
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].ConditionMet =
this.VatsimClientConnection != null &&
locationDiffKm < 50 &&
this.VatsimClientConnection.Callsign.Equals(this.Flight.AtcCallsign, StringComparison.InvariantCultureIgnoreCase) &&
this.VatsimClientConnection.Departure.Equals(this.Flight.Origin.Icao, StringComparison.InvariantCultureIgnoreCase) &&
this.VatsimClientConnection.Arrival.Equals(this.Flight.Destination.Icao, StringComparison.InvariantCultureIgnoreCase);
}
else
{
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].Current = $"{this.VatsimClientConnection != null}, Callsign: {this.VatsimClientConnection?.Callsign ?? "none"}, Location: {locationDiffKm:N1} km";
this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].ConditionMet =
this.VatsimClientConnection != null &&
locationDiffKm < 50 &&
this.VatsimClientConnection.Callsign.Equals(this.Flight.AtcCallsign, StringComparison.InvariantCultureIgnoreCase);
}


if (this.TrackingConditions[(int)Models.TrackingConditions.Vatsim].ConditionMet)
{
this.OnlineNetworkConnectionStarted ??= DateTime.UtcNow;
}
else
{
if (this.OnlineNetworkConnectionStarted.HasValue)
{
this.OnlineNetworkConnectionDuration += (DateTime.UtcNow - this.OnlineNetworkConnectionStarted.Value);
this.OnlineNetworkConnectionStarted = null;
}
}


SleepScheduler.SleepFor(TimeSpan.FromSeconds(this.VatsimClientConnection == null ? 15 : 60));
}
Expand Down
2 changes: 1 addition & 1 deletion OpenSky.Agent.Simulator/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected Simulator(OpenSkyService openSkyServiceInstance)

this.TrackingConditions = new Dictionary<int, TrackingCondition>
{
{ (int)Models.TrackingConditions.DateTime, new TrackingCondition { AutoSet = true } },
{ (int)Models.TrackingConditions.DateTime, new TrackingCondition() },
{ (int)Models.TrackingConditions.Fuel, new TrackingCondition { AutoSet = true } },
{ (int)Models.TrackingConditions.Payload, new TrackingCondition { AutoSet = true } },
{ (int)Models.TrackingConditions.PlaneModel, new TrackingCondition() },
Expand Down
Loading

0 comments on commit 7e9fa5f

Please sign in to comment.