sendPOSI command change (double for lat/lon/h) (#111)
* Updated POSI to use doubles for lat/lon/alt, as step size for floats was unacceptably large at high longitudes.
This commit is contained in:
committed by
Jason Watkins
parent
48656f2b4c
commit
0e493920fa
@@ -25,11 +25,11 @@ public class Main
|
||||
xpc.getDREF("sim/test/test_float");
|
||||
|
||||
System.out.println("Setting player aircraft position");
|
||||
float[] posi = new float[] {37.524F, -122.06899F, 2500, 0, 0, 0, 1};
|
||||
double[] posi = new double[] {37.524, -122.06899, 2500, 0, 0, 0, 1};
|
||||
xpc.sendPOSI(posi);
|
||||
|
||||
System.out.println("Setting another aircraft position");
|
||||
posi[0] = 37.52465F;
|
||||
posi[0] = 37.52465;
|
||||
posi[4] = 20;
|
||||
xpc.sendPOSI(posi, 1);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class Main
|
||||
int aircraft = 0;
|
||||
while(true)
|
||||
{
|
||||
float[] posi = xpc.getPOSI(aircraft);
|
||||
float[] posi = xpc.getPOSI(aircraft); // FIXME: change this to 64-bit double
|
||||
float[] ctrl = xpc.getCTRL(aircraft);
|
||||
|
||||
System.out.format("Loc: (%4f, %4f, %4f) Aileron:%2f Elevator:%2f Rudder:%2f\n",
|
||||
|
||||
@@ -99,7 +99,7 @@ public class Main
|
||||
{
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
float[] posi = xpc.getPOSI(0);
|
||||
float[] posi = xpc.getPOSI(0); // FIXME: change this to 64-bit double
|
||||
writer.write(String.format("%1$f, %2$f, %3$f, %4$f, %5$f, %6$f, %7$f\n",
|
||||
posi[0], posi[1], posi[2], posi[3], posi[4], posi[5], posi[6]));
|
||||
try
|
||||
@@ -125,11 +125,11 @@ public class Main
|
||||
{
|
||||
while(reader.hasNextLine())
|
||||
{
|
||||
float[] posi = new float[7];
|
||||
double[] posi = new double[7];
|
||||
for (int i = 0; i < 7; ++i)
|
||||
{
|
||||
String s = reader.next();
|
||||
posi[i] = Float.parseFloat(s);
|
||||
posi[i] = Double.parseDouble(s);
|
||||
}
|
||||
reader.nextLine();
|
||||
xpc.sendPOSI(posi);
|
||||
|
||||
@@ -549,7 +549,7 @@ public class XPlaneConnect implements AutoCloseable
|
||||
* @return An array containing control surface data in the same format as {@code sendPOSI}.
|
||||
* @throws IOException If the command cannot be sent or a response cannot be read.
|
||||
*/
|
||||
public float[] getPOSI(int ac) throws IOException
|
||||
public double[] getPOSI(int ac) throws IOException
|
||||
{
|
||||
// Send request
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
@@ -570,7 +570,7 @@ public class XPlaneConnect implements AutoCloseable
|
||||
}
|
||||
|
||||
// Parse response
|
||||
float[] result = new float[7];
|
||||
double[] result = new double[7];
|
||||
ByteBuffer bb = ByteBuffer.wrap(data);
|
||||
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||
for(int i = 0; i < 7; ++i)
|
||||
@@ -600,13 +600,13 @@ public class XPlaneConnect implements AutoCloseable
|
||||
* </p>
|
||||
* @throws IOException If the command can not be sent.
|
||||
*/
|
||||
public void sendPOSI(float[] values) throws IOException
|
||||
public void sendPOSI(double[] values) throws IOException
|
||||
{
|
||||
sendPOSI(values, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position of the specified ac.
|
||||
* Sets the position of the specified ac with double precision coordinates.
|
||||
*
|
||||
* @param values <p>An array containing position elements as follows:</p>
|
||||
* <ol>
|
||||
@@ -626,7 +626,7 @@ public class XPlaneConnect implements AutoCloseable
|
||||
* @param ac The ac to set. 0 for the player ac.
|
||||
* @throws IOException If the command can not be sent.
|
||||
*/
|
||||
public void sendPOSI(float[] values, int ac) throws IOException
|
||||
public void sendPOSI(double[] values, int ac) throws IOException
|
||||
{
|
||||
//Preconditions
|
||||
if(values == null)
|
||||
@@ -644,15 +644,22 @@ public class XPlaneConnect implements AutoCloseable
|
||||
|
||||
//Pad command values and convert to bytes
|
||||
int i;
|
||||
ByteBuffer bb = ByteBuffer.allocate(28);
|
||||
ByteBuffer bb = ByteBuffer.allocate(40);
|
||||
bb.order(ByteOrder.LITTLE_ENDIAN);
|
||||
for(i = 0; i < values.length; ++i)
|
||||
{
|
||||
bb.putFloat(i * 4, values[i]);
|
||||
if(i<3) /* lat/lon/height as double */
|
||||
{
|
||||
bb.putDouble(values[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
bb.putFloat((float)values[i]);
|
||||
}
|
||||
}
|
||||
for(; i < 7; ++i)
|
||||
{
|
||||
bb.putFloat(i * 4, -998);
|
||||
bb.putFloat(-998);
|
||||
}
|
||||
|
||||
//Build and send message
|
||||
|
||||
Reference in New Issue
Block a user