Skip to content

Commit

Permalink
Suppress some variables if simulator is offline
Browse files Browse the repository at this point in the history
  • Loading branch information
LazoYoung committed Feb 18, 2023
1 parent c28503e commit 8089292
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,15 @@ private void importSimbrief() {

private void submitFlightPlan() {
if (plan == null) {
plan = new FlightPlan(null, null, null, null, null);
plan = new FlightPlan();
}

var cs = csInput.getText();
var acf = acfInput.getText();
var aircraft = (acf != null) ? aircraftRepo.get(acf) : null;
var dep = depInput.getText();
var arr = arrInput.getText();
var route = plan.getRoute();
FlightPlan.submit(new FlightPlan(cs, aircraft, dep, arr, route));
plan.setCallsign(csInput.getText());
plan.setAircraft((acf != null) ? aircraftRepo.get(acf) : null);
plan.setDepartureCode(depInput.getText());
plan.setArrivalCode(arrInput.getText());
FlightPlan.submit(plan);
simDataService.requestUpdate();
actionLabel.setText("Plan sent!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.List;

import static com.naver.idealproduction.song.domain.FlightPlan.*;
import static com.naver.idealproduction.song.domain.overlay.Simvar.Type.*;

@Service
Expand All @@ -24,7 +25,6 @@ public class SimDataService {
private final AirportRepository airportService;
private final AirlineRepository airlineRepo;
private final SimTracker simTracker;
private final String notAvail = "N/A";
private int phaseSkipCounter = 0;
private String lastPhase = null;

Expand Down Expand Up @@ -58,7 +58,16 @@ private void update(SimBridge simBridge) {
var arr = (plan != null) ? airportService.get(plan.getArrivalCode()) : null;
var airline = (plan != null) ? airlineRepo.get(plan.getAirline()) : null;
var acf = (plan != null) ? plan.getAircraft() : null;
var dist = (arr != null) ? Length.KILOMETER.getDistance(simBridge.getLatitude(), simBridge.getLongitude(), arr.getLatitude(), arr.getLongitude()) : null;
var lat = simBridge.getLatitude();
var lon = simBridge.getLongitude();
boolean isOnline = (Math.abs(lat) > 0.05 || Math.abs(lon) > 0.05);
double distKM = -1;
double distNM = -1;

if (isOnline && arr != null) {
distKM = Length.KILOMETER.getDistance(lat, lon, arr.getLatitude(), arr.getLongitude());
distNM = Length.NAUTICAL_MILE.getDistance(lat, lon, arr.getLatitude(), arr.getLongitude());
}

data.put(LOCAL_TIME, simBridge.getLocalTime().format(timeFormat));
data.put(ZULU_TIME, ZonedDateTime.now(ZoneOffset.UTC).format(timeFormat));
Expand Down Expand Up @@ -104,8 +113,8 @@ private void update(SimBridge simBridge) {
data.put(ENGINE2_FUEL_FLOW, simBridge.getEngineFuelFlow(2));
data.put(ENGINE3_FUEL_FLOW, simBridge.getEngineFuelFlow(3));
data.put(ENGINE4_FUEL_FLOW, simBridge.getEngineFuelFlow(4));
data.put(CALLSIGN, (plan != null) ? plan.getCallsign() : notAvail);
data.put(PHASE, getFlightPhase());
data.put(CALLSIGN, (plan != null) ? plan.getCallsign() : null);
data.put(PHASE, isOnline ? getFlightPhase() : null);

notifyListeners();
}
Expand All @@ -122,7 +131,7 @@ private String getFlightPhase() {
phase = simTracker.getBridge().getFlightPhase();
lastPhase = phase;
}
return (phase != null) ? phase : notAvail;
return phase;
}

private void notifyListeners() {
Expand Down

0 comments on commit 8089292

Please sign in to comment.