1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

Remove some debugging lines, also use Number interface instead of explicit

Byte, Integer, Short etc in setValue/getValue
This commit is contained in:
James Cotton 2011-03-06 00:56:56 -06:00
parent a9066494c7
commit f41980c276
2 changed files with 77 additions and 46 deletions

View File

@ -114,7 +114,7 @@ public abstract class UAVObject {
for (int n = 0; n < fields.size(); ++n) {
fields.get(n).initialize(this);
}
// unpack(data);
unpack(data);
}
/**
@ -291,13 +291,12 @@ public abstract class UAVObject {
public int unpack(ByteBuffer dataIn) throws Exception {
if( dataIn == null )
return 0;
System.out.println( dataIn.toString() );
// QMutexLocker locker(mutex);
int numBytes = 0;
ListIterator<UAVObjectField> li = fields.listIterator();
while (li.hasNext()) {
UAVObjectField field = li.next();
System.out.println(field.toString());
numBytes += field.unpack(dataIn);
}
return numBytes;

View File

@ -99,31 +99,43 @@ public class UAVObjectField {
switch (type)
{
case INT8:
for (int index = 0; index < numElements; ++index)
dataOut.put((Byte) getValue(index));
for (int index = 0; index < numElements; ++index) {
Integer val = (Integer) getValue(index);
dataOut.put(val.byteValue());
}
break;
case INT16:
for (int index = 0; index < numElements; ++index)
dataOut.putShort((Short) getValue(index));
for (int index = 0; index < numElements; ++index) {
Integer val = (Integer) getValue(index);
dataOut.putShort(val.shortValue());
}
break;
case INT32:
for (int index = 0; index < numElements; ++index)
dataOut.putInt((Integer) getValue(index));
for (int index = 0; index < numElements; ++index) {
Integer val = (Integer) getValue(index);
dataOut.putInt(val);
}
break;
case UINT8:
// TODO: Deal properly with unsigned
for (int index = 0; index < numElements; ++index)
dataOut.put((Byte) getValue(index));
for (int index = 0; index < numElements; ++index) {
Integer val = (Integer) getValue(index);
dataOut.put(val.byteValue());
}
break;
case UINT16:
// TODO: Deal properly with unsigned
for (int index = 0; index < numElements; ++index)
dataOut.putShort((Short) getValue(index));
for (int index = 0; index < numElements; ++index) {
Integer val = (Integer) getValue(index);
dataOut.putShort(val.shortValue());
}
break;
case UINT32:
// TODO: Deal properly with unsigned
for (int index = 0; index < numElements; ++index)
dataOut.putInt((Integer) getValue(index));
for (int index = 0; index < numElements; ++index) {
Integer val = (Integer) getValue(index);
dataOut.putInt(val);
}
break;
case FLOAT32:
for (int index = 0; index < numElements; ++index)
@ -142,64 +154,93 @@ public class UAVObjectField {
return getNumBytes();
}
public int unpack(ByteBuffer dataIn) throws Exception {
public int unpack(ByteBuffer dataIn) {
// Unpack each element from input buffer
dataIn.order(ByteOrder.LITTLE_ENDIAN);
switch (type)
{
case INT8:
{
List<Integer> l = (List<Integer>) this.data;
for (int index = 0 ; index < numElements; ++index) {
setValue((Byte) dataIn.get(), index);
Byte val = dataIn.get();
l.set(index, val.intValue());
}
break;
}
case INT16:
{
List<Integer> l = (List<Integer>) this.data;
for (int index = 0 ; index < numElements; ++index) {
setValue((Short) dataIn.getShort(), index);
Short val = dataIn.getShort();
l.set(index, val.intValue());
}
break;
}
case INT32:
{
List<Integer> l = (List<Integer>) this.data;
for (int index = 0 ; index < numElements; ++index) {
setValue((Integer) dataIn.getInt(), index);
Integer val = dataIn.getInt();
l.set(index, val.intValue());
}
break;
}
case UINT8:
// TODO: Deal with unsigned
// TOOD: Deal with unsigned
{
List<Integer> l = (List<Integer>) this.data;
for (int index = 0 ; index < numElements; ++index) {
setValue((Byte) dataIn.get(), index);
Byte val = dataIn.get();
l.set(index, val.intValue());
}
break;
}
case UINT16:
// TODO: Deal with unsigned
{
List<Integer> l = (List<Integer>) this.data;
for (int index = 0 ; index < numElements; ++index) {
setValue((Short) dataIn.getShort(), index);
Short val = dataIn.getShort();
l.set(index, val.intValue());
}
break;
}
case UINT32:
// TODO: Deal with unsigned
{
List<Integer> l = (List<Integer>) this.data;
for (int index = 0 ; index < numElements; ++index) {
setValue((Integer) dataIn.getInt(), index);
Integer val = dataIn.getInt();
l.set(index, val.intValue());
}
break;
}
case FLOAT32:
{
List<Float> l = (List<Float>) this.data;
for (int index = 0 ; index < numElements; ++index) {
setValue((Float) dataIn.getFloat(), index);
Float val = dataIn.getFloat();
l.set(index, val);
}
break;
}
case ENUM:
{
List<Byte> l = (List<Byte>) data;
for (int index = 0 ; index < numElements; ++index) {
l.set(index, dataIn.get(index));
}
break;
}
case STRING:
throw new Exception("Strings not handled");
// TODO: implement strings
//throw new Exception("Strings not handled");
}
// Done
return getNumBytes();
}
Object getValue() throws Exception { return getValue(0); };
Object getValue(int index) throws Exception {
Object getValue() { return getValue(0); };
Object getValue(int index) {
// QMutexLocker locker(obj->getMutex());
// Check that index is not out of bounds
if ( index >= numElements )
@ -234,14 +275,14 @@ public class UAVObjectField {
List<Byte> l = (List<Byte>) data;
Byte val = l.get(index);
if(val >= options.size() || val < 0)
throw new Exception("Invalid value for" + name);
//if(val >= options.size() || val < 0)
// throw new Exception("Invalid value for" + name);
return options.get(val);
}
case STRING:
{
throw new Exception("Shit I should do this");
//throw new Exception("Shit I should do this");
}
}
// If this point is reached then we got an invalid type
@ -252,12 +293,9 @@ public class UAVObjectField {
public void setValue(Object data, int index) {
// QMutexLocker locker(obj->getMutex());
// Check that index is not out of bounds
if ( index >= numElements )
if ( index >= numElements );
//throw new Exception("Index out of bounds");
System.out.println(data.toString());
System.out.println(this.data.toString());
// Get metadata
UAVObject.Metadata mdata = obj.getMetadata();
// Update value if the access mode permits
@ -266,23 +304,19 @@ public class UAVObjectField {
switch (type)
{
case INT8:
data = new Integer((Byte) data);
case INT16:
data = new Integer((Short) data);
case INT32:
{
List<Integer> l = (List<Integer>) this.data;
l.set(index,(Integer) data);
l.set(index,((Number) data).intValue());
break;
}
case UINT8:
data = new Integer((Byte) data);
case UINT16:
data = new Integer((Short) data);
case UINT32:
{
List<Integer> l = (List<Integer>) this.data;
l.set(index, (Integer) data);
l.set(index,((Number) data).intValue());
break;
}
case FLOAT32:
@ -386,7 +420,7 @@ public class UAVObjectField {
sout += name + ": [ ";
for (int n = 0; n < numElements; ++n)
{
sout += String.valueOf(n) + " ";
sout += String.valueOf(n) + "(" + getValue(n) + ") ";
}
sout += "] " + units + "\n";
@ -442,9 +476,8 @@ public class UAVObjectField {
this.data = null;
this.obj = null;
this.elementNames = elementNames;
// Set field size
System.out.println("Initializing: type " + type + this.numElements);
// Set field size
switch (type)
{
case INT8:
@ -487,7 +520,6 @@ public class UAVObjectField {
numBytesPerElement = 0;
}
clear();
System.out.println("Initialized: " + this.data.toString());
}