1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

First step to fixing metat data representation for android

This commit is contained in:
James Cotton 2012-08-02 11:04:35 -05:00
parent 574c2000b6
commit 1a63c21be9
3 changed files with 85 additions and 79 deletions

View File

@ -13,43 +13,25 @@ public class UAVMetaObject extends UAVObject {
ownMetadata = new Metadata();
ownMetadata.flightAccess = UAVObject.AccessMode.ACCESS_READWRITE;
ownMetadata.gcsAccess = UAVObject.AccessMode.ACCESS_READWRITE;
ownMetadata.flightTelemetryAcked = UAVObject.Acked.TRUE;
ownMetadata.flightTelemetryUpdateMode = UAVObject.UpdateMode.UPDATEMODE_ONCHANGE;
ownMetadata.flightTelemetryUpdatePeriod = 0;
ownMetadata.gcsTelemetryAcked = UAVObject.Acked.TRUE;
ownMetadata.gcsTelemetryUpdateMode = UAVObject.UpdateMode.UPDATEMODE_ONCHANGE;
ownMetadata.flags = 0; // TODO: Fix flags
ownMetadata.gcsTelemetryUpdatePeriod = 0;
ownMetadata.loggingUpdateMode = UAVObject.UpdateMode.UPDATEMODE_ONCHANGE;
ownMetadata.loggingUpdatePeriod = 0;
// Setup fields
List<String> boolEnum = new ArrayList<String>();
boolEnum.add("False");
boolEnum.add("True");
List<String> updateModeEnum = new ArrayList<String>();
updateModeEnum.add("Periodic");
updateModeEnum.add("On Change");
updateModeEnum.add("Manual");
updateModeEnum.add("Never");
List<String> modesBitField = new ArrayList<String>();
modesBitField.add("FlightReadOnly");
modesBitField.add("GCSReadOnly");
modesBitField.add("FlightTelemetryAcked");
modesBitField.add("GCSTelemetryAcked");
modesBitField.add("FlightUpdatePeriodic");
modesBitField.add("FlightUpdateOnChange");
modesBitField.add("GCSUpdatePeriodic");
modesBitField.add("GCSUpdateOnChange");
List<String> accessModeEnum = new ArrayList<String>();
accessModeEnum.add("Read/Write");
accessModeEnum.add("Read Only");
List<UAVObjectField> fields = new ArrayList<UAVObjectField>();
fields.add( new UAVObjectField("Flight Access Mode", "", UAVObjectField.FieldType.ENUM, 1, accessModeEnum) );
fields.add( new UAVObjectField("GCS Access Mode", "", UAVObjectField.FieldType.ENUM, 1, accessModeEnum) );
fields.add( new UAVObjectField("Flight Telemetry Acked", "", UAVObjectField.FieldType.ENUM, 1, boolEnum) );
fields.add( new UAVObjectField("Flight Telemetry Update Mode", "", UAVObjectField.FieldType.ENUM, 1, updateModeEnum) );
fields.add( new UAVObjectField("Flight Telemetry Update Period", "", UAVObjectField.FieldType.UINT32, 1, null) );
fields.add( new UAVObjectField("GCS Telemetry Acked", "", UAVObjectField.FieldType.ENUM, 1, boolEnum) );
fields.add( new UAVObjectField("GCS Telemetry Update Mode", "", UAVObjectField.FieldType.ENUM, 1, updateModeEnum) );
fields.add( new UAVObjectField("GCS Telemetry Update Period", "", UAVObjectField.FieldType.UINT32, 1, null ) );
fields.add( new UAVObjectField("Logging Update Mode", "", UAVObjectField.FieldType.ENUM, 1, updateModeEnum) );
fields.add( new UAVObjectField("Logging Update Period", "", UAVObjectField.FieldType.UINT32, 1, null ) );
fields.add( new UAVObjectField("Modes", "", UAVObjectField.FieldType.BITFIELD, 1, modesBitField) );
fields.add( new UAVObjectField("Flight Telemetry Update Period", "ms", UAVObjectField.FieldType.UINT16, 1, null) );
fields.add( new UAVObjectField("GCS Telemetry Update Period", "ms", UAVObjectField.FieldType.UINT16, 1, null) );
fields.add( new UAVObjectField("Logging Update Period", "ms", UAVObjectField.FieldType.UINT16, 1, null) );
int numBytes = 0;
ListIterator<UAVObjectField> li = fields.listIterator();

View File

@ -120,17 +120,10 @@ public abstract class UAVObject {
* Object update mode
*/
public enum UpdateMode {
UPDATEMODE_PERIODIC, /**
* Automatically update object at periodic
* intervals
*/
UPDATEMODE_MANUAL, /** Manually update object, by calling the updated() function */
UPDATEMODE_PERIODIC, /** Automatically update object at periodic intervals */
UPDATEMODE_ONCHANGE, /** Only update object when its data changes */
UPDATEMODE_MANUAL, /**
* Manually update object, by calling the updated()
* function
*/
UPDATEMODE_NEVER
/** Object is never updated */
UPDATEMODE_THROTTLED /** Object is updated on change, but not more often than the interval time */
};
/**
@ -140,47 +133,32 @@ public abstract class UAVObject {
ACCESS_READWRITE, ACCESS_READONLY
};
/**
* Access mode
*/
public enum Acked {
FALSE, TRUE
};
public final class Metadata {
public AccessMode flightAccess;
/**
* Defines the access level for the local flight transactions (readonly
* and readwrite)
* Object metadata, each object has a meta object that holds its metadata. The metadata define
* properties for each object and can be used by multiple modules (e.g. telemetry and logger)
*
* The object metadata flags are packed into a single 16 bit integer.
* The bits in the flag field are defined as:
*
* Bit(s) Name Meaning
* ------ ---- -------
* 0 access Defines the access level for the local transactions (readonly=0 and readwrite=1)
* 1 gcsAccess Defines the access level for the local GCS transactions (readonly=0 and readwrite=1), not used in the flight s/w
* 2 telemetryAcked Defines if an ack is required for the transactions of this object (1:acked, 0:not acked)
* 3 gcsTelemetryAcked Defines if an ack is required for the transactions of this object (1:acked, 0:not acked)
* 4-5 telemetryUpdateMode Update mode used by the telemetry module (UAVObjUpdateMode)
* 6-7 gcsTelemetryUpdateMode Update mode used by the GCS (UAVObjUpdateMode)
*/
public AccessMode gcsAccess;
/**
* Defines the access level for the local GCS transactions (readonly and
* readwrite)
*/
public Acked flightTelemetryAcked;
/**
* Defines if an ack is required for the transactions of this object
* (1:acked, 0:not acked)
*/
public UpdateMode flightTelemetryUpdateMode;
/** Update mode used by the autopilot (UpdateMode) */
public int flags; /** Defines flags for update and logging modes and whether an update should be ACK'd (bits defined above) */
/** Update period used by the telemetry module (only if telemetry mode is PERIODIC) */
public int flightTelemetryUpdatePeriod;
/**
* Update period used by the autopilot (only if telemetry mode is
* PERIODIC)
*/
public Acked gcsTelemetryAcked;
/**
* Defines if an ack is required for the transactions of this object
* (1:acked, 0:not acked)
*/
public UpdateMode gcsTelemetryUpdateMode;
/** Update mode used by the GCS (UpdateMode) */
public int gcsTelemetryUpdatePeriod;
/** Update period used by the GCS (only if telemetry mode is PERIODIC) */
public int gcsTelemetryUpdatePeriod;
/** Update period used by the GCS (only if telemetry mode is PERIODIC) */
public UpdateMode loggingUpdateMode;
/** Update mode used by the logging module (UpdateMode) */
public int loggingUpdatePeriod;
/**
* Update period used by the logging module (only if logging mode is

View File

@ -7,7 +7,7 @@ import java.util.List;
public class UAVObjectField {
public enum FieldType { INT8, INT16, INT32, UINT8, UINT16, UINT32, FLOAT32, ENUM, STRING };
public enum FieldType { INT8, INT16, INT32, UINT8, UINT16, UINT32, FLOAT32, ENUM, BITFIELD, STRING };
public UAVObjectField(String name, String units, FieldType type, int numElements, List<String> options) {
List<String> elementNames = new ArrayList<String>();
@ -56,6 +56,8 @@ public class UAVObjectField {
return "float32";
case ENUM:
return "enum";
case BITFIELD:
return "bitfield";
case STRING:
return "string";
default:
@ -144,6 +146,11 @@ public class UAVObjectField {
for (int index = 0; index < numElements; ++index)
dataOut.put((Byte) l.get(index));
break;
case BITFIELD:
for (int index = 0; index < numElements; ++index) {
Integer val = (Integer) getValue(index);
dataOut.put(val.byteValue());
}
case STRING:
// TODO: Implement strings
throw new Error("Strings not yet implemented");
@ -224,6 +231,16 @@ public class UAVObjectField {
}
break;
}
case BITFIELD:
{
List<Short> l = (List<Short>) this.data;
for (int index = 0 ; index < numElements; ++index) {
int signedval = (int) dataIn.get(); // this sign extends it
int unsignedval = signedval & 0xff; // drop sign extension
l.set(index, (short) unsignedval);
}
break;
}
case ENUM:
{
List<Byte> l = (List<Byte>) this.data;
@ -275,6 +292,9 @@ public class UAVObjectField {
return options.get(val);
}
case BITFIELD:
return ((List<Short>) data).get(index).intValue();
case STRING:
{
//throw new Exception("Shit I should do this");
@ -354,6 +374,12 @@ public class UAVObjectField {
l.set(index, val);
break;
}
case BITFIELD:
{
List<Short> l = (List<Short>) this.data;
l.set(index, bound(data).shortValue());
break;
}
case STRING:
{
//throw new Exception("Sorry I haven't implemented strings yet");
@ -404,6 +430,8 @@ public class UAVObjectField {
return true;
case ENUM:
return false;
case BITFIELD:
return true;
case STRING:
return false;
default:
@ -430,6 +458,8 @@ public class UAVObjectField {
return false;
case ENUM:
return true;
case BITFIELD:
return false;
case STRING:
return true;
default:
@ -493,6 +523,12 @@ public class UAVObjectField {
((ArrayList<Float>) data).add((float) 0);
}
break;
case BITFIELD:
((ArrayList<Short>) data).clear();
for(int index = 0; index < numElements; ++index) {
((ArrayList<Short>) data).add((short) 0);
}
break;
case ENUM:
((ArrayList<Byte>) data).clear();
for(int index = 0; index < numElements; ++index) {
@ -549,6 +585,10 @@ public class UAVObjectField {
data = (Object) new ArrayList<Byte>(this.numElements);
numBytesPerElement = 1;
break;
case BITFIELD:
data = (Object) new ArrayList<Short>(this.numElements);
numBytesPerElement = 1;
break;
case STRING:
data = (Object) new ArrayList<String>(this.numElements);
numBytesPerElement = 1;
@ -614,6 +654,12 @@ public class UAVObjectField {
if(num > 4294967295L)
return 4294967295L;
return num;
case BITFIELD:
if(num < 0)
return (long) 0;
if(num > 255)
return (long) 255;
return num;
}
return num;