Updated Java client to support "switch" argument in SIMU command.
This commit is contained in:
@@ -214,6 +214,26 @@ public class XPlaneConnect implements AutoCloseable
|
||||
sendUDP(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses, unpauses, or switches the pause state of X-Plane.
|
||||
*
|
||||
* @param pause {@code 1} to pause the simulator, {@code 0} to unpause, or {@code 2} to switch.
|
||||
* @throws IllegalArgumentException If the values of {@code pause} is not a valid command.
|
||||
* @throws IOException If the command cannot be sent.
|
||||
*/
|
||||
public void pauseSim(int pause) throws IOException
|
||||
{
|
||||
if(pause < 0 || pause > 2)
|
||||
{
|
||||
throw new IllegalArgumentException("pause must be a value in the range [0, 2].");
|
||||
}
|
||||
|
||||
// S I M U LEN VAL
|
||||
byte[] msg = {0x53, 0x49, 0x4D, 0x55, 0x00, 0x00};
|
||||
msg[5] = (byte)pause;
|
||||
sendUDP(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a single dref value from X-Plane.
|
||||
*
|
||||
|
||||
@@ -208,12 +208,30 @@ public class XPlaneConnectTest
|
||||
{
|
||||
xpc.pauseSim(true);
|
||||
float[] result = xpc.getDREF(dref);
|
||||
//assertEquals(1, result.length); //TODO: Why is this result 20 elements long in Java? (It's only one in MATLAB)
|
||||
assertEquals(20, result.length);
|
||||
assertEquals(1, result[0], 1e-4);
|
||||
|
||||
xpc.pauseSim(false);
|
||||
result = xpc.getDREF(dref);
|
||||
//assertEquals(1, result.length);
|
||||
assertEquals(20, result.length);
|
||||
assertEquals(0, result[0], 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPauseSim_Switch() throws IOException
|
||||
{
|
||||
String dref = "sim/operation/override/override_planepath";
|
||||
try(XPlaneConnect xpc = new XPlaneConnect())
|
||||
{
|
||||
xpc.pauseSim(true);
|
||||
float[] result = xpc.getDREF(dref);
|
||||
assertEquals(20, result.length);
|
||||
assertEquals(1, result[0], 1e-4);
|
||||
|
||||
xpc.pauseSim(2);
|
||||
result = xpc.getDREF(dref);
|
||||
assertEquals(20, result.length);
|
||||
assertEquals(0, result[0], 1e-4);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user