Added support for VIEW command to Java client.
This commit is contained in:
60
Java/src/ViewType.java
Normal file
60
Java/src/ViewType.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
//NOTICES:
|
||||||
|
// Copyright <20> 2013-2015 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 gov.nasa.xpc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -720,6 +720,26 @@ public class XPlaneConnect implements AutoCloseable
|
|||||||
sendUDP(os.toByteArray());
|
sendUDP(os.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the camera view in X-Plane.
|
||||||
|
*
|
||||||
|
* @param view The view to use.
|
||||||
|
* @throws IOException If the command cannot be sent.
|
||||||
|
*/
|
||||||
|
public void sendVIEW(ViewType view) throws IOException
|
||||||
|
{
|
||||||
|
ByteBuffer bb = ByteBuffer.allocate(4);
|
||||||
|
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
|
bb.putInt(view.getValue());
|
||||||
|
|
||||||
|
//Build and send message
|
||||||
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
os.write("VIEW".getBytes(StandardCharsets.UTF_8));
|
||||||
|
os.write(0xFF); //Placeholder for message length
|
||||||
|
os.write(bb.array());
|
||||||
|
sendUDP(os.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds, removes, or clears a set of waypoints. If the command is clear, the points are ignored
|
* Adds, removes, or clears a set of waypoints. If the command is clear, the points are ignored
|
||||||
* and all points are removed.
|
* and all points are removed.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package gov.nasa.xpc.test;
|
package gov.nasa.xpc.test;
|
||||||
|
|
||||||
|
import gov.nasa.xpc.ViewType;
|
||||||
import gov.nasa.xpc.WaypointOp;
|
import gov.nasa.xpc.WaypointOp;
|
||||||
import gov.nasa.xpc.XPlaneConnect;
|
import gov.nasa.xpc.XPlaneConnect;
|
||||||
|
|
||||||
@@ -677,4 +678,24 @@ public class XPlaneConnectTest
|
|||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSendView() throws IOException
|
||||||
|
{
|
||||||
|
String dref = "sim/graphics/view/view_type";
|
||||||
|
float fwd = 1000;
|
||||||
|
float chase = 1017;
|
||||||
|
|
||||||
|
try(XPlaneConnect xpc = new XPlaneConnect())
|
||||||
|
{
|
||||||
|
xpc.sendVIEW(ViewType.Forwards);
|
||||||
|
float result = xpc.getDREF(dref)[0];
|
||||||
|
assertEquals(fwd, result, 1e-4);
|
||||||
|
|
||||||
|
xpc.sendVIEW(ViewType.Chase);
|
||||||
|
result = xpc.getDREF(dref)[0];
|
||||||
|
assertEquals(chase, result, 1e-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user