restructuring for project (Backlog 3)

This commit is contained in:
cs-powell
2024-11-24 13:32:21 -05:00
parent d2156ae9bc
commit e574ca3215
38 changed files with 680 additions and 179 deletions

View File

@@ -0,0 +1,40 @@
package ProjectModels.CognitiveModel;
public abstract class Action {
Integer priority; //Priority of the Task
Integer delay; //Potential Delay before starting the task
String targetDREF;
Integer taskTime; //How long should the task take
boolean taskComplete; //Is the task completed?
ActionType actionType;
public Action(ActionType actionType, int delay){
this.actionType = actionType;
this.delay = delay;
this.targetDREF = null;
}
public Action(ActionType actionType, int delay, String target){
this.actionType = actionType;
this.delay = delay;
targetDREF = target;
}
public ActionType getType(){
return actionType;
}
public Integer getDelay(){
return delay;
}
public String getTarget(){
return targetDREF;
}
}

View File

@@ -0,0 +1,7 @@
package ProjectModels.CognitiveModel;
public enum ActionType{
VISION,
MOTOR,
DELAY
}

View File

@@ -0,0 +1,16 @@
package ProjectModels.CognitiveModel;
import java.util.Map;
import java.util.TreeMap;
public class Delay extends Action {
public Delay(){
super(ActionType.DELAY,1000);
}
public Delay(int delay){
super(ActionType.DELAY,delay);
}
}

View File

@@ -0,0 +1,58 @@
package ProjectModels.CognitiveModel;
import java.util.LinkedList;
public class MindQueue {
LinkedList<Action> q;
public MindQueue () {
q = new LinkedList<Action>();
}
public void push(Action e){
q.add(e);
}
public Action removeEvent(Action e){
Action temp = e;
q.remove(e);
return temp;
}
public Action pop() {
Vision v = new Vision();
if(q.isEmpty()) {
return v;
}
return q.remove();
}
public boolean isEmpty(){
return q.isEmpty();
}
public String printQueue(){
String queueTrace = "Next to Execute ==> ";
for (Action action : q) {
if(action.getType() == ActionType.VISION){
queueTrace += "[V]";
}
if(action.getType() == ActionType.MOTOR){
queueTrace += "[M]";
}
if(action.getType() == ActionType.DELAY){
queueTrace += "[D]";
}
}
return queueTrace;
}
public int queueLength(){
return q.size();
}
}

View File

@@ -0,0 +1,139 @@
package ProjectModels.CognitiveModel;
import java.io.IOException;
public class Model {
private MindQueue q; //Queue for actions
boolean modelActive; // On/Off Switch for the model execution
XPlaneConnect xpc; //Allows connection to the simulator
//Constructors
public Model() {
q = new MindQueue();
modelActive = false;
}
public Model(XPlaneConnect xpc) {
q = new MindQueue();
modelActive = false;
this.xpc = xpc;
}
/*Getters*/
public MindQueue getQueue() {
return q;
}
/*Setters*/
/*
* Setup Methods
* Printing, Empty check, Activation/Deactivation of Model, etc.
*/
public void activateModel() {
modelActive = true;
}
public void establishConnection(XPlaneConnect newXPC){
this.xpc = newXPC;
}
public void deactivateModel(){
modelActive = false;
}
public boolean isEmpty(){
return q.isEmpty();
}
public void push(Action a){
q.push(a);
}
public boolean isActive(){
return modelActive;
}
public void printModelQueue(){
System.out.println(q.printQueue());
}
public int getModelQueueLength(){
return q.queueLength();
}
public void createAction(int actionType,int delay,String target) {
Action newAction = null;
switch(actionType){
case 1:
newAction = new Vision(delay,target);
this.push(newAction);
case 2:
newAction = new Motor(delay,target);
this.push(newAction);
case 3:
newAction = new Delay(delay);
this.push(newAction);
}
}
/*
* Processing Methods
*
*/
/*
* Process the next event in the model queue
*/
public float[] next() {
float[] returnArray = null;
Action temp = q.pop();
// System.out.println("Type of Action: " + temp.getType());
if(temp.getType() == ActionType.VISION){ // Vision Action (Get Data)
handelVisionAction(temp, returnArray);
} else if (temp.getType() == ActionType.MOTOR){ //Motor Action (Act Upon Data)
handleMotorAction(temp);
} else if (temp.getType() == ActionType.DELAY){//Pure Delays (Do nothing)
handleDelayAction(temp);
}
// q.push(temp);
return returnArray;
}
/* Next Helpers */
private void handelVisionAction(Action temp, float[] returnArray) {
Vision tempV = (Vision) temp;
initiateDelay(tempV.getDelay());
String dref = tempV.getTarget();
try {
returnArray = xpc.getDREF(dref);
} catch (IOException e) {
}
}
private void handleMotorAction(Action temp){
Motor tempM = (Motor) temp;
tempM.getDelay();
}
private void handleDelayAction(Action temp){
Delay tempD = (Delay) temp;
initiateDelay(tempD.getDelay());
}
public static void initiateDelay(int delay){
try {
Thread.sleep(delay); // Using the action's Built in Delay
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,39 @@
package ProjectModels.CognitiveModel;
import java.io.IOException;
public class Motor extends Action {
float[] control;
public Motor() {
super(ActionType.MOTOR,1000);
}
public Motor(int delay) {
super(ActionType.MOTOR,delay);
}
public Motor(int delay, String target) {
super(ActionType.MOTOR,delay,target);
}
public void createMotorControl(){ // TODO: Maybe takes in a formatted set of vision inputs?
control = null;
}
public void sendMotorControl(XPlaneConnect xpc) {
if(control != null) {
try {
xpc.sendCTRL(control);
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Control failed to send");
}
}
}
}

View File

@@ -1,3 +1,4 @@
package ProjectModels.CognitiveModel;
public class Process { public class Process {

View File

@@ -1,3 +1,4 @@
package ProjectModels.CognitiveModel;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;

View File

@@ -0,0 +1,22 @@
package ProjectModels.CognitiveModel;
public class Vision extends Action {
public Vision(){
super(ActionType.VISION,1000);
}
public Vision(int delay){
super(ActionType.VISION,delay);
}
public Vision(String dref){
super(ActionType.VISION,1000,dref);
}
public Vision(int delay, String dref){
super(ActionType.VISION,delay, dref);
}
}

View File

@@ -0,0 +1,45 @@
package ProjectModels.CognitiveModel.XPCdependencies;
import java.net.InetAddress;
public class Beacon {
private InetAddress xplaneAddress;
private int pluginPort;
private String pluginVersion;
private int xPlaneVersion;
public Beacon(InetAddress xplaneAddress, int pluginPort, String pluginVersion, int xPlaneVersion) {
this.xplaneAddress = xplaneAddress;
this.pluginPort = pluginPort;
this.pluginVersion = pluginVersion;
this.xPlaneVersion = xPlaneVersion;
}
public String getHost() {
return xplaneAddress.getHostAddress();
}
public String getPluginVersion() {
return pluginVersion;
}
public String getXplaneVersion() {
return String.format("%.2f", xPlaneVersion / 100.0);
}
public int getPluginPort() {
return pluginPort;
}
public InetAddress getXplaneAddress() {
return xplaneAddress;
}
@Override
public String toString() {
return "host: " + getHost() + ":" + getPluginPort() +" version: " + getPluginVersion() + " X-Plane Version: " + getXplaneVersion();
}
}

View File

@@ -0,0 +1,54 @@
package ProjectModels.CognitiveModel.XPCdependencies;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* Parser class that parses the UDP discovery BECN packet. The format of the packet is
* - 4 bytes: BECN
* - 1 byte: 0
* - 2 bytes: XPlaneConnect server port e.g. '49009'
* - 4 bytes: X-Plane version e.g. '11260'
* - null terminated string: XPlaneConnect plugin version e.g. '1.3-rc.1'
*/
public class BeaconParser {
private static String BECN = "BECN";
private static int XPC_PORT_OFFSET = BECN.length() + 1;
private static int XPC_PORT_LEN = 2;
private static int XPC_VERSION_OFFSET = XPC_PORT_OFFSET + XPC_PORT_LEN;
private static int XPC_VERSION_LEN = 4;
private static int XPC_PLUGIN_VERSION_OFFSET = XPC_VERSION_OFFSET + XPC_VERSION_LEN;
public Beacon readBCN(DatagramPacket packet) throws IOException {
if (packet.getLength() < BECN.length()) {
throw new IOException("BECN response too short");
}
byte[] data = packet.getData();
String command = new String(data, 0, BECN.length());
if (!command.equals(BECN)) {
throw new IOException("Expected " + BECN + " got '" + command + "'");
}
InetAddress address = packet.getAddress();
ByteBuffer bb = ByteBuffer.wrap(data);
bb.order(ByteOrder.LITTLE_ENDIAN);
// 2 bytes: port as short + converted to an int
int port = bb.getShort(XPC_PORT_OFFSET) & 0xffff;
// 4 bytes: x plane version as int
int version = bb.getInt(XPC_VERSION_OFFSET);
// plugin version
String pluginVersion = new String(data, XPC_PLUGIN_VERSION_OFFSET, packet.getLength() - XPC_PLUGIN_VERSION_OFFSET);
return new Beacon(address, port, pluginVersion.trim(), version);
}
}

View File

@@ -0,0 +1,10 @@
package ProjectModels.CognitiveModel.XPCdependencies;
public interface BeaconReceivedListener {
/**
* Called every time a BECN packet is received
* @param beacon The parsed beacon
*/
void onBeaconReceived(Beacon beacon);
}

View File

@@ -0,0 +1,14 @@
package ProjectModels.CognitiveModel.XPCdependencies;
import ProjectModels.CognitiveModel.*;
public interface DiscoveryConnectionCallback {
/**
* Helper callback called when a 1st XPlanePlugin is discovered. When the 1st packet is received, an XPlaneConnect
* instance is created and the discovery is stopped.
*
* @param xpc The XPlaneConnect instance configured with the discovered
*/
void onConnectionEstablished(XPlaneConnect xpc);
}

View File

@@ -0,0 +1,60 @@
//NOTICES:
// Copyright (c) 2013-2018 United States Government as represented by the Administrator of the
// National Aeronautics and Space Administration. All Rights Reserved.
//
// DISCLAIMERS
// 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.
package ProjectModels.CognitiveModel.XPCdependencies;
/**
* Represents a camera view in X-Plane
*
* @author Jason Watkins
* @version 1.1
* @since 2015-05-08
*/
public enum ViewType
{
Forwards(73),
Down(74),
Left(75),
Right(76),
Back(77),
Tower(78),
Runway(79),
Chase(80),
Follow(81),
FollowWithPanel(82),
Spot(83),
FullscreenWithHud(84),
FullscreenNoHud(85);
private final int value;
private ViewType(int value)
{
this.value = value;
}
public int getValue()
{
return value;
}
}

View File

@@ -0,0 +1,50 @@
//NOTICES:
// Copyright (c) 2013-2018 United States Government as represented by the Administrator of the
// National Aeronautics and Space Administration. All Rights Reserved.
//
// DISCLAIMERS
// 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.
package ProjectModels.CognitiveModel.XPCdependencies;
/**
* Represents operations that can be performed by the WYPT command.
*
* @author Jason Watkins
* @version 1.0
* @since 2015-04-09
*/
public enum WaypointOp
{
Add(1),
Del(2),
Clr(3);
private final int value;
private WaypointOp(int value)
{
this.value = value;
}
public int getValue()
{
return value;
}
}

View File

@@ -0,0 +1,94 @@
package ProjectModels.CognitiveModel.XPCdependencies;
import ProjectModels.CognitiveModel.*;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.SocketException;
/**
* The XPlaneConnectDiscovery joins a UDP multi cast group and listens for BECN packets published by
* XPlaneConnect server plugin. It allows to clients to discover XPlane instances and be sure that the XPlanePlugin is
* installed.
*/
public class XPlaneConnectDiscovery implements AutoCloseable {
private static int DEFAULT_PORT = 49710;
private static String DEFAULT_ADDRESS = "239.255.1.1";
private BeaconReceivedListener mListener;
private MulticastSocket socket = null;
private byte[] buf = new byte[256];
private int mPort;
private String mAddress;
private BeaconParser parser = new BeaconParser();
private XPlaneConnectDiscovery(int port, String address) {
mPort = port;
mAddress = address;
}
public XPlaneConnectDiscovery() {
this(DEFAULT_PORT, DEFAULT_ADDRESS);
}
public void start(DiscoveryConnectionCallback callback) throws IOException {
onBeaconReceived(beacon -> {
this.close();
try {
XPlaneConnect xpc = new XPlaneConnect(beacon);
callback.onConnectionEstablished(xpc);
} catch (SocketException e) {
System.err.println("Could not connect to a discovered XplaneConnect " +beacon+ ": " + e.getMessage());
}
});
start();
}
public void start() throws IOException {
System.out.println("Starting XPlane Connect discovery");
socket = new MulticastSocket(mPort);
InetAddress group = InetAddress.getByName(mAddress);
socket.joinGroup(group);
while (socket != null) {
DatagramPacket packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
if (mListener == null) {
continue;
}
try {
Beacon beacon = parser.readBCN(packet);
mListener.onBeaconReceived(beacon);
} catch (IOException ex) {
System.err.println("Received packet on discovery group but could not parse it: " + ex);
}
}
close();
System.out.println("XPlane Connect discovery ended");
}
public void onBeaconReceived(BeaconReceivedListener mListener) {
this.mListener = mListener;
}
@Override
public void close() {
if (socket != null) {
socket.close();
socket = null;
}
}
public void stop() {
close();
}
}

View File

@@ -23,9 +23,11 @@
// PRIOR RECIPIENT, TO THE EXTENT PERMITTED BY LAW. RECIPIENT'S SOLE REMEDY FOR ANY SUCH MATTER // 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. // SHALL BE THE IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT.
// package gov.nasa.xpc; package ProjectModels.CognitiveModel;
// import gov.nasa.xpc.discovery.Beacon; import ProjectModels.CognitiveModel.XPCdependencies.*;
import src.discovery.ViewType;
import src.discovery.WaypointOp;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@@ -45,7 +47,7 @@ import java.util.Arrays;
*/ */
public class XPlaneConnect implements AutoCloseable public class XPlaneConnect implements AutoCloseable
{ {
private static int clientNum; //private static int clientNum;
private DatagramSocket socket; private DatagramSocket socket;
private InetAddress xplaneAddr; private InetAddress xplaneAddr;
private int xplanePort; private int xplanePort;

View File

Before

Width:  |  Height:  |  Size: 115 KiB

After

Width:  |  Height:  |  Size: 115 KiB

View File

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -1,3 +1,4 @@
package ProjectModels.src;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@@ -12,10 +13,11 @@ import javax.swing.OverlayLayout;
import javax.swing.SwingConstants; import javax.swing.SwingConstants;
import javax.swing.border.Border; import javax.swing.border.Border;
import ProjectModels.CognitiveModel.*;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
//Encapsulation (or lack thereof) Test //Encapsulation (or lack thereof) Test
Model m = new Model(); Model m = new Model();
MindQueue q = m.getQueue(); MindQueue q = m.getQueue();
@@ -25,25 +27,35 @@ public class Main {
MindQueue q2 = m.getQueue(); MindQueue q2 = m.getQueue();
System.out.println(q2.pop()); System.out.println(q2.pop());
//Using actions
try(XPlaneConnect xpc = new XPlaneConnect()) try(XPlaneConnect xpc = new XPlaneConnect())
{ {
Action b = new Vision(); m.createAction(0, 0, null);
Action b = new Vision(10,"sim/cockpit2/gauges/indicators/airspeed_kts_pilot");
Action d = new Delay(20);
// Ensure connection established. // Ensure connection established.
m = new Model(xpc); m = new Model(xpc);
m.activate(); m.activateModel();
m.push(b); m.push(b);
m.push(d);
m.printModelQueue();
// m.deactivateModel();
while(m.isActive() && !m.isEmpty()) { while(m.isActive() && !m.isEmpty()) {
float[] array = m.next(); float[] array = m.next();
if(array != null){ if(array != null){
System.out.println(array[0]); // System.out.println(array[0]);
if(array[0] > 80.0f){
m.push(d);
}
} else { } else {
System.out.println("no dice"); // System.out.println("no dice");
// System.out.println(xpc.getDREF(null)"); // System.out.println(xpc.getDREF(null)");
} }
if(m.getModelQueueLength() < 5){
m.push(b);
}
m.printModelQueue();
} }
} }
catch (SocketException ex) catch (SocketException ex)
{ {
@@ -52,7 +64,6 @@ public class Main {
catch (IOException ex) catch (IOException ex)
{ {
System.out.println("Something went wrong with one of the commands. (Error message was '" + ex.getMessage() + "'.)"); System.out.println("Something went wrong with one of the commands. (Error message was '" + ex.getMessage() + "'.)");
} }
System.out.println("Exiting"); System.out.println("Exiting");
} }

View File

@@ -1,26 +0,0 @@
public abstract class Action {
Integer priority; //Priority of the Task
Integer delay; //Potential Delay before starting the task
Integer taskTime; //How long should the task take
boolean taskComplete; //Is the task completed?
int actionType;
public Action(int actionType, int delay){
this.actionType = actionType;
this.delay = delay;
}
public int getType(){
return actionType;
}
public Integer getDelay(){
return delay;
}
}

View File

@@ -1,40 +0,0 @@
import java.util.LinkedList;
public class MindQueue {
LinkedList<Action> q;
public MindQueue () {
q = new LinkedList<Action>();
}
public void push(Action e){
q.add(e);
}
public Action removeEvent(Action e){
Action temp = e;
q.remove(e);
return temp;
}
public Action pop() {
Vision v = new Vision();
if(q.isEmpty()) {
return v;
}
return q.remove();
}
public boolean isEmpty(){
return q.isEmpty();
}
}

View File

@@ -1,83 +0,0 @@
import java.io.IOException;
// import gov.nasa.xpc.XPlaneConnect;
public class Model {
private MindQueue q;
boolean modelActive;
XPlaneConnect xpc;
public Model() {
q = new MindQueue();
modelActive = false;
}
public Model(XPlaneConnect xpc) {
q = new MindQueue();
modelActive = false;
this.xpc = xpc;
}
public MindQueue getQueue() {
return q;
}
public float[] next(){
Action temp = q.pop();
System.out.println("Type of Action: " + temp.getType());
float[] returnArray = null;
if(temp.getType() == 1){
System.out.println("in next if statement");
Vision tempV = (Vision) temp;
//execute delay
try {
Thread.sleep(tempV.getDelay()); // Using the action's Built in Delay
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String dref = "sim/cockpit2/gauges/indicators/airspeed_kts_pilot";
try {
returnArray = xpc.getDREF(dref);
} catch (IOException e) {
// TODO: handle exception
}
}
q.push(temp);
return returnArray;
}
public boolean isEmpty(){
return q.isEmpty();
}
public void push(Action a){
q.push(a);
}
public void activate() {
modelActive = true;
}
public void establishConnection(XPlaneConnect newXPC){
this.xpc = newXPC;
}
public void deactivate(){
modelActive = false;
}
public boolean isActive(){
return modelActive;
}
}

View File

@@ -1,15 +0,0 @@
import java.util.Map;
import java.util.TreeMap;
public class Vision extends Action {
public Vision(){
super(1,1000);
}
public Vision(int delay){
super(1,delay);
}
}

View File

@@ -26,6 +26,8 @@
package gov.nasa.xpc; package gov.nasa.xpc;
import gov.nasa.xpc.discovery.Beacon; import gov.nasa.xpc.discovery.Beacon;
import src.discovery.ViewType;
import src.discovery.WaypointOp;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;

View File

@@ -22,7 +22,7 @@
// HARMLESS THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY // 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 // 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. // SHALL BE THE IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT.
package gov.nasa.xpc; package src.discovery;
/** /**
* Represents a camera view in X-Plane * Represents a camera view in X-Plane

View File

@@ -22,7 +22,7 @@
// HARMLESS THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL AS ANY // 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 // 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. // SHALL BE THE IMMEDIATE, UNILATERAL TERMINATION OF THIS AGREEMENT.
package gov.nasa.xpc; package src.discovery;
/** /**
* Represents operations that can be performed by the WYPT command. * Represents operations that can be performed by the WYPT command.