1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

AndroidGCS: Add copyright headers to the UAVTalk/UAVObject/Telemetry implementations.

This commit is contained in:
James Cotton 2012-08-08 09:05:42 -05:00
parent 2008486922
commit dc6b3af707
8 changed files with 436 additions and 226 deletions

View File

@ -1,3 +1,27 @@
/**
******************************************************************************
* @file Telemetry.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Port of Telemetry.cpp from the GCS. Handles transactions on the
* UAVTalk channel.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
import java.io.IOException; import java.io.IOException;
@ -76,11 +100,13 @@ public class Telemetry {
// Listen to new object creations // Listen to new object creations
objMngr.addNewInstanceObserver(new Observer() { objMngr.addNewInstanceObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
newInstance((UAVObject) data); newInstance((UAVObject) data);
} }
}); });
objMngr.addNewObjectObserver(new Observer() { objMngr.addNewObjectObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
newObject((UAVObject) data); newObject((UAVObject) data);
} }
@ -88,6 +114,7 @@ public class Telemetry {
// Listen to transaction completions // Listen to transaction completions
utalk.addObserver(new Observer() { utalk.addObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
transactionCompleted((UAVObject) data); transactionCompleted((UAVObject) data);
@ -228,6 +255,7 @@ public class Telemetry {
if ( (eventMask&EV_UNPACKED) != 0) if ( (eventMask&EV_UNPACKED) != 0)
{ {
obj.addUnpackedObserver(new Observer() { obj.addUnpackedObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
objectUnpacked( (UAVObject) data); objectUnpacked( (UAVObject) data);
@ -241,6 +269,7 @@ public class Telemetry {
if ( (eventMask&EV_UPDATED) != 0) if ( (eventMask&EV_UPDATED) != 0)
{ {
obj.addUpdatedAutoObserver(new Observer() { obj.addUpdatedAutoObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
objectUpdatedAuto( (UAVObject) data); objectUpdatedAuto( (UAVObject) data);
@ -254,6 +283,7 @@ public class Telemetry {
if ( (eventMask&EV_UPDATED_MANUAL) != 0) if ( (eventMask&EV_UPDATED_MANUAL) != 0)
{ {
obj.addUpdatedManualObserver(new Observer() { obj.addUpdatedManualObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
objectUpdatedManual( (UAVObject) data); objectUpdatedManual( (UAVObject) data);
@ -267,6 +297,7 @@ public class Telemetry {
if ( (eventMask&EV_UPDATE_REQ) != 0) if ( (eventMask&EV_UPDATE_REQ) != 0)
{ {
obj.addUpdateRequestedObserver(new Observer() { obj.addUpdateRequestedObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
updateRequested( (UAVObject) data); updateRequested( (UAVObject) data);
@ -692,13 +723,13 @@ public class Telemetry {
/** /**
* Private variables * Private variables
*/ */
private UAVObjectManager objMngr; private final UAVObjectManager objMngr;
private UAVTalk utalk; private final UAVTalk utalk;
private UAVObject gcsStatsObj; private UAVObject gcsStatsObj;
private List<ObjectTimeInfo> objList = new ArrayList<ObjectTimeInfo>(); private final List<ObjectTimeInfo> objList = new ArrayList<ObjectTimeInfo>();
private Queue<ObjectQueueInfo> objQueue = new LinkedList<ObjectQueueInfo>(); private final Queue<ObjectQueueInfo> objQueue = new LinkedList<ObjectQueueInfo>();
private Queue<ObjectQueueInfo> objPriorityQueue = new LinkedList<ObjectQueueInfo>(); private final Queue<ObjectQueueInfo> objPriorityQueue = new LinkedList<ObjectQueueInfo>();
private ObjectTransactionInfo transInfo = new ObjectTransactionInfo(); private final ObjectTransactionInfo transInfo = new ObjectTransactionInfo();
private boolean transPending; private boolean transPending;
private Timer updateTimer; private Timer updateTimer;

View File

@ -1,3 +1,28 @@
/**
******************************************************************************
* @file TelemetryMonitor.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief High level monitoring of telemetry to handle connection and
* disconnection and then signal the rest of the application.
* This also makes sure to fetch all objects on initial connection.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
import java.io.IOException; import java.io.IOException;
@ -22,15 +47,15 @@ public class TelemetryMonitor extends Observable{
static final int STATS_CONNECT_PERIOD_MS = 1000; static final int STATS_CONNECT_PERIOD_MS = 1000;
static final int CONNECTION_TIMEOUT_MS = 8000; static final int CONNECTION_TIMEOUT_MS = 8000;
private UAVObjectManager objMngr; private final UAVObjectManager objMngr;
private Telemetry tel; private final Telemetry tel;
// private UAVObject objPending; // private UAVObject objPending;
private UAVObject gcsStatsObj; private UAVObject gcsStatsObj;
private UAVObject flightStatsObj; private UAVObject flightStatsObj;
private Timer periodicTask; private Timer periodicTask;
private int currentPeriod; private int currentPeriod;
private long lastUpdateTime; private long lastUpdateTime;
private List<UAVObject> queue; private final List<UAVObject> queue;
private boolean connected = false; private boolean connected = false;
private boolean objects_updated = false; private boolean objects_updated = false;
@ -50,6 +75,7 @@ public class TelemetryMonitor extends Observable{
flightStatsObj = objMngr.getObject("FlightTelemetryStats"); flightStatsObj = objMngr.getObject("FlightTelemetryStats");
flightStatsObj.addUpdatedObserver(new Observer() { flightStatsObj.addUpdatedObserver(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
try { try {
flightStatsUpdated((UAVObject) data); flightStatsUpdated((UAVObject) data);
@ -146,6 +172,7 @@ public class TelemetryMonitor extends Observable{
// TODO: Does this need to stay here permanently? This appears to be used for setup mainly // TODO: Does this need to stay here permanently? This appears to be used for setup mainly
obj.addTransactionCompleted(new Observer() { obj.addTransactionCompleted(new Observer() {
@Override
public void update(Observable observable, Object data) { public void update(Observable observable, Object data) {
UAVObject.TransactionResult result = (UAVObject.TransactionResult) data; UAVObject.TransactionResult result = (UAVObject.TransactionResult) data;
if (DEBUG) Log.d(TAG,"Got transaction completed event from " + result.obj.getName() + " status: " + result.success); if (DEBUG) Log.d(TAG,"Got transaction completed event from " + result.obj.getName() + " status: " + result.success);
@ -224,12 +251,12 @@ public class TelemetryMonitor extends Observable{
if (DEBUG) Log.d(TAG, "processStatsUpdates() - stats reset"); if (DEBUG) Log.d(TAG, "processStatsUpdates() - stats reset");
// Need to compute time because this update is not regular enough // Need to compute time because this update is not regular enough
float dT = (float) (System.currentTimeMillis() - lastStatsTime) / 1000.0f; float dT = (System.currentTimeMillis() - lastStatsTime) / 1000.0f;
lastStatsTime = System.currentTimeMillis(); lastStatsTime = System.currentTimeMillis();
// Update stats object // Update stats object
gcsStatsObj.getField("RxDataRate").setDouble( (float)telStats.rxBytes / dT ); gcsStatsObj.getField("RxDataRate").setDouble( telStats.rxBytes / dT );
gcsStatsObj.getField("TxDataRate").setDouble( (float)telStats.txBytes / dT ); gcsStatsObj.getField("TxDataRate").setDouble( telStats.txBytes / dT );
UAVObjectField field = gcsStatsObj.getField("RxFailures"); UAVObjectField field = gcsStatsObj.getField("RxFailures");
field.setDouble(field.getDouble() + telStats.rxErrors); field.setDouble(field.getDouble() + telStats.rxErrors);
field = gcsStatsObj.getField("TxFailures"); field = gcsStatsObj.getField("TxFailures");

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file UAVDataObject.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief The base object for all UAVO data.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
public abstract class UAVDataObject extends UAVObject { public abstract class UAVDataObject extends UAVObject {
@ -24,6 +47,7 @@ public abstract class UAVDataObject extends UAVObject {
super.initialize(instID); super.initialize(instID);
} }
@Override
public boolean isMetadata() { return false; }; public boolean isMetadata() { return false; };
/** /**
* Assign a metaobject * Assign a metaobject
@ -45,6 +69,7 @@ public abstract class UAVDataObject extends UAVObject {
/** /**
* Set the object's metadata * Set the object's metadata
*/ */
@Override
public void setMetadata(Metadata mdata) public void setMetadata(Metadata mdata)
{ {
if ( mobj != null ) if ( mobj != null )
@ -56,6 +81,7 @@ public abstract class UAVDataObject extends UAVObject {
/** /**
* Get the object's metadata * Get the object's metadata
*/ */
@Override
public Metadata getMetadata() public Metadata getMetadata()
{ {
if ( mobj != null) if ( mobj != null)
@ -82,6 +108,6 @@ public abstract class UAVDataObject extends UAVObject {
} }
private UAVMetaObject mobj; private UAVMetaObject mobj;
private boolean isSet; private final boolean isSet;
} }

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file UAVMetaObject.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Base object for all UAVO meta data
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -67,6 +90,7 @@ public class UAVMetaObject extends UAVObject {
* Set the metadata of the metaobject, this function will * Set the metadata of the metaobject, this function will
* do nothing since metaobjects have read-only metadata. * do nothing since metaobjects have read-only metadata.
*/ */
@Override
public void setMetadata(Metadata mdata) public void setMetadata(Metadata mdata)
{ {
return; // can not update metaobject's metadata return; // can not update metaobject's metadata
@ -75,6 +99,7 @@ public class UAVMetaObject extends UAVObject {
/** /**
* Get the metadata of the metaobject * Get the metadata of the metaobject
*/ */
@Override
public Metadata getMetadata() public Metadata getMetadata()
{ {
return ownMetadata; return ownMetadata;
@ -83,6 +108,7 @@ public class UAVMetaObject extends UAVObject {
/** /**
* Get the default metadata * Get the default metadata
*/ */
@Override
public Metadata getDefaultMetadata() public Metadata getDefaultMetadata()
{ {
return ownMetadata; return ownMetadata;
@ -110,8 +136,8 @@ public class UAVMetaObject extends UAVObject {
} }
private UAVObject parent; private final UAVObject parent;
private Metadata ownMetadata; private final Metadata ownMetadata;
private Metadata parentMetadata; private Metadata parentMetadata;

View File

@ -1,16 +1,39 @@
/**
******************************************************************************
* @file UAVObject.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Base object for UAVDataObject and UAVMetaObject.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Observer;
import java.util.Observable; import java.util.Observable;
import java.util.Observer;
public abstract class UAVObject { public abstract class UAVObject {
public class CallbackListener extends Observable { public class CallbackListener extends Observable {
private UAVObject parent; private final UAVObject parent;
public CallbackListener(UAVObject parent) { public CallbackListener(UAVObject parent) {
this.parent = parent; this.parent = parent;
@ -39,7 +62,7 @@ public abstract class UAVObject {
} }
} }
private CallbackListener transactionCompletedListeners = new CallbackListener(this); private final CallbackListener transactionCompletedListeners = new CallbackListener(this);
public void addTransactionCompleted(Observer o) { public void addTransactionCompleted(Observer o) {
synchronized(transactionCompletedListeners) { synchronized(transactionCompletedListeners) {
transactionCompletedListeners.addObserver(o); transactionCompletedListeners.addObserver(o);
@ -56,7 +79,7 @@ public abstract class UAVObject {
} }
} }
private CallbackListener updatedListeners = new CallbackListener(this); private final CallbackListener updatedListeners = new CallbackListener(this);
public void removeUpdatedObserver(Observer o) { public void removeUpdatedObserver(Observer o) {
synchronized(updatedListeners) { synchronized(updatedListeners) {
updatedListeners.deleteObserver(o); updatedListeners.deleteObserver(o);
@ -76,7 +99,7 @@ public abstract class UAVObject {
} }
public void updated() { updated(true); }; public void updated() { updated(true); };
private CallbackListener unpackedListeners = new CallbackListener(this); private final CallbackListener unpackedListeners = new CallbackListener(this);
public void addUnpackedObserver(Observer o) { public void addUnpackedObserver(Observer o) {
synchronized(unpackedListeners) { synchronized(unpackedListeners) {
unpackedListeners.addObserver(o); unpackedListeners.addObserver(o);
@ -88,7 +111,7 @@ public abstract class UAVObject {
} }
} }
private CallbackListener updatedAutoListeners = new CallbackListener(this); private final CallbackListener updatedAutoListeners = new CallbackListener(this);
public void addUpdatedAutoObserver(Observer o) { public void addUpdatedAutoObserver(Observer o) {
synchronized(updatedAutoListeners) { synchronized(updatedAutoListeners) {
updatedAutoListeners.addObserver(o); updatedAutoListeners.addObserver(o);
@ -100,7 +123,7 @@ public abstract class UAVObject {
} }
} }
private CallbackListener updatedManualListeners = new CallbackListener(this); private final CallbackListener updatedManualListeners = new CallbackListener(this);
public void addUpdatedManualObserver(Observer o) { public void addUpdatedManualObserver(Observer o) {
synchronized(updatedManualListeners) { synchronized(updatedManualListeners) {
updatedManualListeners.addObserver(o); updatedManualListeners.addObserver(o);
@ -112,7 +135,7 @@ public abstract class UAVObject {
} }
} }
private CallbackListener updateRequestedListeners = new CallbackListener(this); private final CallbackListener updateRequestedListeners = new CallbackListener(this);
public void addUpdateRequestedObserver(Observer o) { public void addUpdateRequestedObserver(Observer o) {
synchronized(updateRequestedListeners) { synchronized(updateRequestedListeners) {
updateRequestedListeners.addObserver(o); updateRequestedListeners.addObserver(o);
@ -774,6 +797,7 @@ public abstract class UAVObject {
/** /**
* Java specific functions * Java specific functions
*/ */
@Override
public synchronized UAVObject clone() { public synchronized UAVObject clone() {
UAVObject newObj = clone(); UAVObject newObj = clone();
List<UAVObjectField> newFields = new ArrayList<UAVObjectField>(); List<UAVObjectField> newFields = new ArrayList<UAVObjectField>();

View File

@ -1,3 +1,26 @@
/**
******************************************************************************
* @file Telemetry.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Implementation of all the UAVObjectFields.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -144,7 +167,7 @@ public class UAVObjectField {
case ENUM: case ENUM:
List<Byte> l = (List<Byte>) data; List<Byte> l = (List<Byte>) data;
for (int index = 0; index < numElements; ++index) for (int index = 0; index < numElements; ++index)
dataOut.put((Byte) l.get(index)); dataOut.put(l.get(index));
break; break;
case BITFIELD: case BITFIELD:
for (int index = 0; index < numElements; ++index) { for (int index = 0; index < numElements; ++index) {
@ -196,7 +219,7 @@ public class UAVObjectField {
{ {
List<Short> l = (List<Short>) this.data; List<Short> l = (List<Short>) this.data;
for (int index = 0 ; index < numElements; ++index) { for (int index = 0 ; index < numElements; ++index) {
int signedval = (int) dataIn.get(); // this sign extends it int signedval = dataIn.get(); // this sign extends it
int unsignedval = signedval & 0xff; // drop sign extension int unsignedval = signedval & 0xff; // drop sign extension
l.set(index, (short) unsignedval); l.set(index, (short) unsignedval);
} }
@ -206,7 +229,7 @@ public class UAVObjectField {
{ {
List<Integer> l = (List<Integer>) this.data; List<Integer> l = (List<Integer>) this.data;
for (int index = 0 ; index < numElements; ++index) { for (int index = 0 ; index < numElements; ++index) {
int signedval = (int) dataIn.getShort(); // this sign extends it int signedval = dataIn.getShort(); // this sign extends it
int unsignedval = signedval & 0xffff; // drop sign extension int unsignedval = signedval & 0xffff; // drop sign extension
l.set(index, unsignedval); l.set(index, unsignedval);
} }
@ -216,7 +239,7 @@ public class UAVObjectField {
{ {
List<Long> l = (List<Long>) this.data; List<Long> l = (List<Long>) this.data;
for (int index = 0 ; index < numElements; ++index) { for (int index = 0 ; index < numElements; ++index) {
long signedval = (long) dataIn.getInt(); // this sign extends it long signedval = dataIn.getInt(); // this sign extends it
long unsignedval = signedval & 0xffffffffL; // drop sign extension long unsignedval = signedval & 0xffffffffL; // drop sign extension
l.set(index, unsignedval); l.set(index, unsignedval);
} }
@ -235,7 +258,7 @@ public class UAVObjectField {
{ {
List<Short> l = (List<Short>) this.data; List<Short> l = (List<Short>) this.data;
for (int index = 0 ; index < numElements; ++index) { for (int index = 0 ; index < numElements; ++index) {
int signedval = (int) dataIn.get(); // this sign extends it int signedval = dataIn.get(); // this sign extends it
int unsignedval = signedval & 0xff; // drop sign extension int unsignedval = signedval & 0xff; // drop sign extension
l.set(index, (short) unsignedval); l.set(index, (short) unsignedval);
} }
@ -367,7 +390,7 @@ public class UAVObjectField {
// Test if numeric constant passed in // Test if numeric constant passed in
val = ((Number) data).byteValue(); val = ((Number) data).byteValue();
} catch (Exception e) { } catch (Exception e) {
val = (byte) options.indexOf((String) data); val = (byte) options.indexOf(data);
} }
//if(val < 0) throw new Exception("Enumerated value not found"); //if(val < 0) throw new Exception("Enumerated value not found");
List<Byte> l = (List<Byte>) this.data; List<Byte> l = (List<Byte>) this.data;
@ -474,6 +497,7 @@ public class UAVObjectField {
} }
} }
@Override
public String toString() { public String toString() {
String sout = new String(); String sout = new String();
sout += name + ": "; sout += name + ": ";
@ -572,43 +596,43 @@ public class UAVObjectField {
switch (type) switch (type)
{ {
case INT8: case INT8:
data = (Object) new ArrayList<Byte>(this.numElements); data = new ArrayList<Byte>(this.numElements);
numBytesPerElement = 1; numBytesPerElement = 1;
break; break;
case INT16: case INT16:
data = (Object) new ArrayList<Short>(this.numElements); data = new ArrayList<Short>(this.numElements);
numBytesPerElement = 2; numBytesPerElement = 2;
break; break;
case INT32: case INT32:
data = (Object) new ArrayList<Integer>(this.numElements); data = new ArrayList<Integer>(this.numElements);
numBytesPerElement = 4; numBytesPerElement = 4;
break; break;
case UINT8: case UINT8:
data = (Object) new ArrayList<Short>(this.numElements); data = new ArrayList<Short>(this.numElements);
numBytesPerElement = 1; numBytesPerElement = 1;
break; break;
case UINT16: case UINT16:
data = (Object) new ArrayList<Integer>(this.numElements); data = new ArrayList<Integer>(this.numElements);
numBytesPerElement = 2; numBytesPerElement = 2;
break; break;
case UINT32: case UINT32:
data = (Object) new ArrayList<Long>(this.numElements); data = new ArrayList<Long>(this.numElements);
numBytesPerElement = 4; numBytesPerElement = 4;
break; break;
case FLOAT32: case FLOAT32:
data = (Object) new ArrayList<Float>(this.numElements); data = new ArrayList<Float>(this.numElements);
numBytesPerElement = 4; numBytesPerElement = 4;
break; break;
case ENUM: case ENUM:
data = (Object) new ArrayList<Byte>(this.numElements); data = new ArrayList<Byte>(this.numElements);
numBytesPerElement = 1; numBytesPerElement = 1;
break; break;
case BITFIELD: case BITFIELD:
data = (Object) new ArrayList<Short>(this.numElements); data = new ArrayList<Short>(this.numElements);
numBytesPerElement = 1; numBytesPerElement = 1;
break; break;
case STRING: case STRING:
data = (Object) new ArrayList<String>(this.numElements); data = new ArrayList<String>(this.numElements);
numBytesPerElement = 1; numBytesPerElement = 1;
break; break;
default: default:

View File

@ -1,3 +1,28 @@
/**
******************************************************************************
* @file UAVObjectManager.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief Critical class. This is the data store for all UAVOs. Allows
* other objects to access and change this data. Takes care of
* propagating changes to the UAV.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,13 +39,13 @@ public class UAVObjectManager {
notifyObservers(obj); notifyObservers(obj);
} }
} }
private CallbackListener newInstance = new CallbackListener(); private final CallbackListener newInstance = new CallbackListener();
public void addNewInstanceObserver(Observer o) { public void addNewInstanceObserver(Observer o) {
synchronized(newInstance) { synchronized(newInstance) {
newInstance.addObserver(o); newInstance.addObserver(o);
} }
} }
private CallbackListener newObject = new CallbackListener(); private final CallbackListener newObject = new CallbackListener();
public void addNewObjectObserver(Observer o) { public void addNewObjectObserver(Observer o) {
synchronized(newObject) { synchronized(newObject) {
newObject.addObserver(o); newObject.addObserver(o);
@ -29,7 +54,7 @@ public class UAVObjectManager {
private final int MAX_INSTANCES = 10; private final int MAX_INSTANCES = 10;
// Use array list to store objects since rarely added or deleted // Use array list to store objects since rarely added or deleted
private List<List<UAVObject>> objects = new ArrayList<List<UAVObject>>(); private final List<List<UAVObject>> objects = new ArrayList<List<UAVObject>>();
public UAVObjectManager() public UAVObjectManager()
{ {

View File

@ -1,3 +1,29 @@
/**
******************************************************************************
* @file UAVTalk.java
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
* @brief The protocol layer implementation of UAVTalk. Serializes objects
* for transmission (which is done in the object itself which is aware
* of byte packing) wraps that in the UAVTalk packet. Parses UAVTalk
* packets and updates the UAVObjectManager.
* @see The GNU Public License (GPL) Version 3
*
*****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.openpilot.uavtalk; package org.openpilot.uavtalk;
import java.io.IOException; import java.io.IOException;
@ -26,6 +52,7 @@ public class UAVTalk extends Observable {
if (inputProcessingThread == null) if (inputProcessingThread == null)
inputProcessingThread = new Thread() { inputProcessingThread = new Thread() {
@Override
public void run() { public void run() {
while(true) { while(true) {
try { try {
@ -753,7 +780,7 @@ public class UAVTalk extends Observable {
int updateCRC(int crc, byte[] data, int length) { int updateCRC(int crc, byte[] data, int length) {
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
crc = updateCRC(crc, (int) data[i]); crc = updateCRC(crc, data[i]);
return crc; return crc;
} }