Skip to content

Commit

Permalink
Merge pull request #4 from LazoYoung/feature/xplane-support
Browse files Browse the repository at this point in the history
Feature: x-plane support
  • Loading branch information
LazoYoung authored Jul 7, 2023
2 parents ce3c8d6 + 10ef795 commit 13035fa
Show file tree
Hide file tree
Showing 17 changed files with 742 additions and 154 deletions.
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ plugins {
}

group = 'com.naver.idealproduction'
version = '1.0.2'
version = '1.0.3'
sourceCompatibility = '17'
targetCompatibility = '17'
var fsuipc = 'lib/FSUIPC-1.0.2.jar'
var xpc = 'lib/XPlaneConnect.jar'

repositories {
mavenCentral()
Expand All @@ -28,8 +29,9 @@ dependencies {
// Burningwave Core (Let us export module packages required for JCEF)
implementation 'org.burningwave:core:12.62.5'

// FSUIPC
// Simulator bridges
implementation files(fsuipc)
implementation files(xpc)

// Mockito
testImplementation "org.mockito:mockito-core:3.+"
Expand Down
50 changes: 50 additions & 0 deletions lib/XPlaneConnect-license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
------------------------------------------
Official License of XPlaneConnect
https://github.com/nasa/XPlaneConnect
------------------------------------------

Copyright ©2013-2018 United States Government as represented by
the Administrator of the National Aeronautics and Space Administration.
All Rights Reserved.

No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY KIND,
EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY
THAT THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED,
WILL CONFORM TO THE SUBJECT SOFTWARE. THIS AGREEMENT DOES NOT, IN ANY MANNER,
CONSTITUTE AN ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT OF ANY RESULTS,
RESULTING DESIGNS, HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS RESULTING FROM
USE OF THE SUBJECT SOFTWARE. FURTHER, GOVERNMENT AGENCY DISCLAIMS ALL WARRANTIES
AND LIABILITIES REGARDING THIRD-PARTY SOFTWARE, IF PRESENT IN THE ORIGINAL SOFTWARE,
AND DISTRIBUTES IT "AS IS."

Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST
THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY PRIOR RECIPIENT.
IF RECIPIENT'S USE OF THE SUBJECT SOFTWARE RESULTS IN ANY LIABILITIES, DEMANDS, DAMAGES,
EXPENSES OR LOSSES ARISING FROM SUCH USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON,
OR RESULTING FROM, RECIPIENT'S USE OF THE SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY
AND HOLD HARMLESS THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS,
AS WELL AS ANY PRIOR RECIPIENT, TO THE EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY
FOR ANY SUCH MATTER SHALL BE THE IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT.

X-Plane API
Copyright (c) 2008, Sandy Barbour and Ben Supnik All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer. Neither the names of the authors nor that of X-Plane or Laminar Research
may be used to endorse or promote products derived from this software without specific prior written permission
from the authors or Laminar Research, respectively.
X-Plane API SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Binary file added lib/XPlaneConnect.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public static void main(String[] args) {
window.showDialog(WARNING_MESSAGE, String.format("Failed to bind existing port %d.\nNew port: %d", defaultPort, finalPort));
}
});
simTracker.start();
Runtime.getRuntime().addShutdownHook(new Thread(simTracker::terminate));
simTracker.hookBridges();
Runtime.getRuntime().addShutdownHook(new Thread(() -> simTracker.getBridge().release()));
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
exit(1);
Expand Down Expand Up @@ -245,7 +245,7 @@ private static boolean isPortAvailable(int port) {
public static void exit(int code) {
if (context != null) {
var simTracker = context.getBean(SimTracker.class);
simTracker.terminate();
simTracker.getBridge().release();

int exitCode = SpringApplication.exit(context, () -> 1);
System.exit(exitCode + code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@XmlType(name = "simvar")
public class Simvar {
public enum Type {
FRAME_PER_SEC,
LOCAL_TIME,
ZULU_TIME,
BLOCK_RAMP_OUT_LOCAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ public enum Length {
this.ratio = ratio;
}

@SuppressWarnings("DuplicatedCode")
public Double convertTo(Length unit, double value) {
if (this == unit) {
return value;
}
return getConversion(unit, value).doubleValue();
}

var ctx = MathContext.DECIMAL64;
var dividend = BigDecimal.valueOf(unit.ratio);
var divisor = BigDecimal.valueOf(this.ratio);
var bigValue = BigDecimal.valueOf(value);
return dividend.divide(divisor, ctx).multiply(bigValue, ctx).doubleValue();
public Float convertTo(Length unit, float value) {
return getConversion(unit, value).floatValue();
}

public double getDistance(double lat1, double lon1, double lat2, double lon2) {
Expand All @@ -40,4 +35,14 @@ public double getDistance(double lat1, double lon1, double lat2, double lon2) {
return Length.KILOMETER.convertTo(this, km);
}

private BigDecimal getConversion(Length unit, double value) {
if (this == unit) return BigDecimal.valueOf(value);

var ctx = MathContext.DECIMAL64;
var dividend = BigDecimal.valueOf(this.ratio);
var divisor = BigDecimal.valueOf(unit.ratio);
var bigValue = BigDecimal.valueOf(value);
return dividend.divide(divisor, ctx).multiply(bigValue, ctx);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ public enum Speed {
this.ratio = ratio;
}

@SuppressWarnings("DuplicatedCode")
public Double convertTo(Speed unit, double value) {
return getConversion(unit, value).doubleValue();
}

public Float convertTo(Speed unit, float value) {
return getConversion(unit, value).floatValue();
}

private BigDecimal getConversion(Speed unit, double value) {
if (this == unit) {
return value;
return BigDecimal.valueOf(value);
}

var ctx = MathContext.DECIMAL64;
var dividend = BigDecimal.valueOf(unit.ratio);
var divisor = BigDecimal.valueOf(this.ratio);
var dividend = BigDecimal.valueOf(this.ratio);
var divisor = BigDecimal.valueOf(unit.ratio);
var bigValue = BigDecimal.valueOf(value);
return dividend.divide(divisor, ctx).multiply(bigValue, ctx).doubleValue();
return dividend.divide(divisor, ctx).multiply(bigValue, ctx);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public JTabbedPane getContentTab() {
@Override
public void dispose() {
super.dispose();
simTracker.terminate();
simTracker.getBridge().release();
}

private Font registerFonts(String fileName, float size) throws IOException, FontFormatException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import com.naver.idealproduction.song.domain.Properties;
import com.naver.idealproduction.song.gui.Dashboard;
import com.naver.idealproduction.song.gui.component.TextInput;
import com.naver.idealproduction.song.servlet.bridge.SimBridge;
import com.naver.idealproduction.song.servlet.repository.AircraftRepository;
import com.naver.idealproduction.song.servlet.service.SimBridge;
import com.naver.idealproduction.song.servlet.service.SimDataService;
import com.naver.idealproduction.song.servlet.service.SimTracker;
import org.apache.commons.lang3.exception.ExceptionUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.naver.idealproduction.song.gui.subpanel;

import com.naver.idealproduction.song.gui.Dashboard;
import com.naver.idealproduction.song.servlet.service.SimBridge;
import com.naver.idealproduction.song.servlet.bridge.SimBridge;
import com.naver.idealproduction.song.servlet.service.SimTracker;

import javax.swing.*;
import java.awt.*;

public class SimMonitor extends SimplePanel {
private final SimTracker simTracker;
private final JLabel fsuipcLabel;
private final JLabel bridgeLabel;
private final JLabel simLabel;
private final JLabel simValue;
private final JLabel fpsLabel;
Expand All @@ -25,23 +25,24 @@ public class SimMonitor extends SimplePanel {

public SimMonitor(Dashboard dashboard) {
simTracker = dashboard.getSpringContext().getBean(SimTracker.class);
simTracker.addProcessListener(this::onUpdate);
String bridge = simTracker.getBridge().getBridgeName();
simTracker.addUpdateListener(this::onUpdate);

var labelFont = new Font("Ubuntu Medium", Font.PLAIN, 18);
var valueFont = new Font("Ubuntu Regular", Font.PLAIN, 16);
var stateFont = new Font("Ubuntu Medium", Font.PLAIN, 30);
fsuipcLabel = bakeLabel("FSUIPC", stateFont, Color.white);
var stateFont = new Font("Ubuntu Medium", Font.PLAIN, 24);
bridgeLabel = bakeLabel(bridge, stateFont, Color.white);
simLabel = bakeLabel("Simulator", labelFont, Color.gray);
simValue = bakeLabel(NOT_AVAIL, valueFont, Color.black);
fpsLabel = bakeLabel("FPS", labelFont, Color.gray);
fpsValue = bakeLabel(NOT_AVAIL, valueFont, Color.black);
refreshLabel = bakeLabel("Refresh rate", labelFont, Color.gray);
refreshValue = bakeLabel(NOT_AVAIL, valueFont, Color.black);
offlineLabel = bakeLabel("Offline", labelFont, Color.red);
offlineLabel = bakeLabel("No simulator detected.", labelFont, Color.black);

fsuipcLabel.setBackground(Color.red);
fsuipcLabel.setOpaque(true);
fsuipcLabel.setBorder(getMargin(fsuipcLabel, 10, 10, 10, 10));
bridgeLabel.setBackground(Color.red);
bridgeLabel.setOpaque(true);
bridgeLabel.setBorder(getMargin(bridgeLabel, 10, 10, 10, 10));
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.setBackground(Color.white);
this.setPreferredSize(new Dimension(250, 0));
Expand All @@ -53,7 +54,7 @@ private void onUpdate(SimBridge data) {
isConnected = data.isConnected();

if (isConnected) {
var fps = data.getFramerate();
var fps = data.getFPS();
simText = data.getSimulator();
fpsText = (fps < 0 || fps > 500) ? NOT_AVAIL : String.valueOf(fps);
refreshText = simTracker.getRefreshRate() + "ms";
Expand All @@ -66,18 +67,20 @@ private void onUpdate(SimBridge data) {

private void updateContentPane(boolean draw) {
if (isConnected) {
String bridgeName = simTracker.getBridge().getBridgeName();
simValue.setText(simText);
fpsValue.setText(fpsText);
refreshValue.setText(refreshText);
fsuipcLabel.setBackground(Color.green);
bridgeLabel.setText(bridgeName);
bridgeLabel.setBackground(Color.green);
} else {
fsuipcLabel.setBackground(Color.red);
bridgeLabel.setBackground(Color.red);
}

if (draw) {
removeAll();
add(Box.createRigidArea(new Dimension(0, 20)));
add(fsuipcLabel);
add(bridgeLabel);

if (isConnected) {
add(Box.createVerticalGlue());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.naver.idealproduction.song.servlet.bridge;

public interface BridgeListener {
void onConnected(SimBridge newBridge);
void onDisconnected();
void onProcess();
void onFail(String message);
}
Loading

0 comments on commit 13035fa

Please sign in to comment.