1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-04-10 02:02:21 +02:00

Little updates

This commit is contained in:
James Cotton 2011-03-10 13:44:40 -06:00
parent abc07fd748
commit 29fd09b204
2 changed files with 51 additions and 21 deletions

View File

@ -202,7 +202,6 @@ public class UAVTalk extends Observable{
*/ */
public synchronized boolean sendObject(UAVObject obj, boolean acked, boolean allInstances) public synchronized boolean sendObject(UAVObject obj, boolean acked, boolean allInstances)
{ {
System.out.println("Sending obj: " + obj.toString());
if (acked) if (acked)
{ {
return objectTransaction(obj, TYPE_OBJ_ACK, allInstances); return objectTransaction(obj, TYPE_OBJ_ACK, allInstances);
@ -249,7 +248,6 @@ public class UAVTalk extends Observable{
} }
else if (type == TYPE_OBJ) else if (type == TYPE_OBJ)
{ {
System.out.println("Transmitting object: " + obj.toString());
return transmitObject(obj, TYPE_OBJ, allInstances); return transmitObject(obj, TYPE_OBJ, allInstances);
} }
else else
@ -263,7 +261,7 @@ public class UAVTalk extends Observable{
* \param[in] rxbyte Received byte * \param[in] rxbyte Received byte
* \return Success (true), Failure (false) * \return Success (true), Failure (false)
*/ */
public boolean processInputByte(int rxbyte) public synchronized boolean processInputByte(int rxbyte)
{ {
assert(objMngr != null); assert(objMngr != null);
@ -448,12 +446,10 @@ public class UAVTalk extends Observable{
break; break;
} }
//mutex->lock();
rxBuffer.position(0); rxBuffer.position(0);
receiveObject(rxType, rxObjId, rxInstId, rxBuffer); receiveObject(rxType, rxObjId, rxInstId, rxBuffer);
stats.rxObjectBytes += rxLength; stats.rxObjectBytes += rxLength;
stats.rxObjects++; stats.rxObjects++;
//mutex->unlock();
rxState = RxStateType.STATE_SYNC; rxState = RxStateType.STATE_SYNC;
break; break;
@ -484,13 +480,13 @@ public class UAVTalk extends Observable{
boolean error = false; boolean error = false;
boolean allInstances = (instId == ALL_INSTANCES? true : false); boolean allInstances = (instId == ALL_INSTANCES? true : false);
System.out.println("Received object: " + objId + " " + objMngr.getObject(objId).getName());
// Process message type // Process message type
switch (type) { switch (type) {
case TYPE_OBJ: case TYPE_OBJ:
// All instances, not allowed for OBJ messages // All instances, not allowed for OBJ messages
if (!allInstances) if (!allInstances)
{ {
System.out.println("Received object: " + objId + " " + objMngr.getObject(objId).getName());
// Get object and update its data // Get object and update its data
obj = updateObject(objId, instId, data); obj = updateObject(objId, instId, data);
// Check if an ack is pending // Check if an ack is pending
@ -512,6 +508,7 @@ public class UAVTalk extends Observable{
// All instances, not allowed for OBJ_ACK messages // All instances, not allowed for OBJ_ACK messages
if (!allInstances) if (!allInstances)
{ {
System.out.println("Received object ack: " + objId + " " + objMngr.getObject(objId).getName());
// Get object and update its data // Get object and update its data
obj = updateObject(objId, instId, data); obj = updateObject(objId, instId, data);
// Transmit ACK // Transmit ACK
@ -531,6 +528,7 @@ public class UAVTalk extends Observable{
break; break;
case TYPE_OBJ_REQ: case TYPE_OBJ_REQ:
// Get object, if all instances are requested get instance 0 of the object // Get object, if all instances are requested get instance 0 of the object
System.out.println("Received object request: " + objId + " " + objMngr.getObject(objId).getName());
if (allInstances) if (allInstances)
{ {
obj = objMngr.getObject(objId); obj = objMngr.getObject(objId);
@ -553,6 +551,7 @@ public class UAVTalk extends Observable{
// All instances, not allowed for ACK messages // All instances, not allowed for ACK messages
if (!allInstances) if (!allInstances)
{ {
System.out.println("Received ack: " + objId + " " + objMngr.getObject(objId).getName());
// Get object // Get object
obj = objMngr.getObject(objId, instId); obj = objMngr.getObject(objId, instId);
// Check if an ack is pending // Check if an ack is pending
@ -578,7 +577,7 @@ public class UAVTalk extends Observable{
* If the object instance could not be found in the list, then a * If the object instance could not be found in the list, then a
* new one is created. * new one is created.
*/ */
public UAVObject updateObject(int objId, int instId, ByteBuffer data) public synchronized UAVObject updateObject(int objId, int instId, ByteBuffer data)
{ {
assert(objMngr != null); assert(objMngr != null);
@ -613,13 +612,14 @@ public class UAVTalk extends Observable{
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("Unpacking new object");
instobj.unpack(data); instobj.unpack(data);
return instobj; return instobj;
} }
else else
{ {
// Unpack data into object instance // Unpack data into object instance
// System.out.println("Unpacking: " + data.position() + " / " + data.capacity() ); System.out.println("Unpacking existing object: " + data.position() + " / " + data.capacity() );
obj.unpack(data); obj.unpack(data);
return obj; return obj;
} }

View File

@ -1,10 +1,13 @@
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
@ -31,7 +34,7 @@ public class TalkTest {
UAVObjectsInitialize.register(objMngr); UAVObjectsInitialize.register(objMngr);
} }
@Test //@Test
public void testGetFlightStatus() { public void testGetFlightStatus() {
Socket connection = null; Socket connection = null;
UAVTalk talk = null; UAVTalk talk = null;
@ -78,22 +81,49 @@ public class TalkTest {
@Test @Test
public void testSendObjectRequest() { public void testSendObjectRequest() {
fail("Not yet implemented"); ByteArrayInputStream is = new ByteArrayInputStream(new byte[0], 0, 0);
ByteArrayOutputStream os = new ByteArrayOutputStream(100);
UAVTalk talk = new UAVTalk(is,os,objMngr);
UAVObject obj = objMngr.getObject("FlightTelemetryStats");
obj.getField("Status").setValue("Connected");
talk.sendObject(obj, false, false);
System.out.println("Size: " + os.size());
byte [] array = os.toByteArray();
for(int i = 0; i < array.length; i++) {
System.out.print("0x" + Integer.toHexString((int) array[i] & 0xff));
if(i != array.length-1)
System.out.print(", ");
}
System.out.print("\n");
} }
@Test
public void testSendObject() {
fail("Not yet implemented");
}
@Test @Test
public void testReceiveObject() { public void testReceiveObject() {
fail("Not yet implemented"); ByteArrayInputStream is = new ByteArrayInputStream(new byte[0], 0, 0);
ByteArrayOutputStream os = new ByteArrayOutputStream(100);
// Send object to create the test packet (should hard code in test string)
UAVTalk talk = new UAVTalk(is,os,objMngr);
UAVObject obj = objMngr.getObject("FlightTelemetryStats");
obj.getField("Status").setValue("Connected");
talk.sendObject(obj, false, false);
obj.getField("Status").setValue("Disconnected");
// Test receiving from that stream
is = new ByteArrayInputStream(os.toByteArray(), 0, os.size());
talk = new UAVTalk(is,os,objMngr);
Thread inputStream = talk.getInputProcessThread();
inputStream.start();
System.out.println("Should be FlightTelemetry Stats:");
System.out.println(objMngr.getObject("FlightTelemetryStats").toString());
fail("Not working yet");
} }
@Test
public void testUpdateObject() {
fail("Not yet implemented");
}
} }