Added Java client support for multiplayer sendCTRL
This commit is contained in:
@@ -410,7 +410,7 @@ public class XPlaneConnect implements AutoCloseable
|
|||||||
* @param aircraft The aircraft to set. 0 for the player's aircraft.
|
* @param aircraft The aircraft to set. 0 for the player's aircraft.
|
||||||
* @throws IOException If the command cannot be sent.
|
* @throws IOException If the command cannot be sent.
|
||||||
*/
|
*/
|
||||||
private void sendCTRL(float[] ctrl, int aircraft) throws IOException
|
public void sendCTRL(float[] ctrl, int aircraft) throws IOException
|
||||||
{
|
{
|
||||||
//Preconditions
|
//Preconditions
|
||||||
if(ctrl == null)
|
if(ctrl == null)
|
||||||
@@ -421,13 +421,9 @@ public class XPlaneConnect implements AutoCloseable
|
|||||||
{
|
{
|
||||||
throw new IllegalArgumentException("ctrl must have 6 or fewer elements.");
|
throw new IllegalArgumentException("ctrl must have 6 or fewer elements.");
|
||||||
}
|
}
|
||||||
if(aircraft < 0)
|
if(aircraft < 0 || aircraft > 9)
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("aircraft must be non-negative.");
|
throw new IllegalArgumentException("aircraft must be non-negative and less than 9.");
|
||||||
}
|
|
||||||
if(aircraft != 0) //TODO: Implement support for non-player aircraft on plugin side.
|
|
||||||
{
|
|
||||||
throw new Error("Non-player aircraft not supported yet.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Pad command values and convert to bytes
|
//Pad command values and convert to bytes
|
||||||
@@ -461,6 +457,7 @@ public class XPlaneConnect implements AutoCloseable
|
|||||||
cur += 4;
|
cur += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bb.put(cur, (byte)aircraft);
|
||||||
|
|
||||||
//Build and send message
|
//Build and send message
|
||||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||||
|
|||||||
@@ -303,12 +303,12 @@ public class XPlaneConnectTest
|
|||||||
public void testSendCTRL() throws IOException
|
public void testSendCTRL() throws IOException
|
||||||
{
|
{
|
||||||
String[] drefs = {
|
String[] drefs = {
|
||||||
"sim/cockpit2/controls/yoke_pitch_ratio",
|
"sim/cockpit2/controls/yoke_pitch_ratio",
|
||||||
"sim/cockpit2/controls/yoke_roll_ratio",
|
"sim/cockpit2/controls/yoke_roll_ratio",
|
||||||
"sim/cockpit2/controls/yoke_heading_ratio",
|
"sim/cockpit2/controls/yoke_heading_ratio",
|
||||||
"sim/flightmodel/engine/ENGN_thro",
|
"sim/flightmodel/engine/ENGN_thro",
|
||||||
"sim/cockpit/switches/gear_handle_status",
|
"sim/cockpit/switches/gear_handle_status",
|
||||||
"sim/flightmodel/controls/flaprqst"
|
"sim/flightmodel/controls/flaprqst"
|
||||||
};
|
};
|
||||||
float[] ctrl = new float[] {0, 0, 1, 0.8F, 0, 1};
|
float[] ctrl = new float[] {0, 0, 1, 0.8F, 0, 1};
|
||||||
try(XPlaneConnect xpc = new XPlaneConnect())
|
try(XPlaneConnect xpc = new XPlaneConnect())
|
||||||
@@ -326,6 +326,40 @@ public class XPlaneConnectTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSendCTRL_NPC() throws IOException
|
||||||
|
{
|
||||||
|
String[] drefs1 = {
|
||||||
|
"sim/multiplayer/position/plane1_yolk_pitch",
|
||||||
|
"sim/multiplayer/position/plane1_yolk_roll",
|
||||||
|
"sim/multiplayer/position/plane1_yolk_yaw",
|
||||||
|
"sim/multiplayer/position/plane1_throttle"
|
||||||
|
};
|
||||||
|
String[] drefs2 = {
|
||||||
|
"sim/multiplayer/position/plane1_gear_deploy",
|
||||||
|
"sim/multiplayer/position/plane1_flap_ratio"
|
||||||
|
};
|
||||||
|
float[] ctrl = new float[] {0, 0, 1, 0.8F, 0, 0.5F};
|
||||||
|
try(XPlaneConnect xpc = new XPlaneConnect())
|
||||||
|
{
|
||||||
|
xpc.sendCTRL(ctrl, 1);
|
||||||
|
float[][] result1 = xpc.requestDREFs(drefs1);
|
||||||
|
float[][] result2 = xpc.requestDREFs(drefs2);
|
||||||
|
if(result1.length != 4 || result2.length != 2)
|
||||||
|
{
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
for(int i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
assertEquals(ctrl[i], result1[i][0], 1e-2);
|
||||||
|
}
|
||||||
|
for(int i = 0; i < 2; ++i)
|
||||||
|
{
|
||||||
|
assertEquals(ctrl[i + 4], result2[i][0], 1e-2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void testSendCTRL_NullCtrl() throws IOException
|
public void testSendCTRL_NullCtrl() throws IOException
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user