mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-06 21:54:15 +01:00
First step to fixing metat data representation for android
This commit is contained in:
parent
cd89d97bbb
commit
c736488c3b
@ -13,43 +13,25 @@ public class UAVMetaObject extends UAVObject {
|
|||||||
|
|
||||||
ownMetadata = new Metadata();
|
ownMetadata = new Metadata();
|
||||||
|
|
||||||
ownMetadata.flightAccess = UAVObject.AccessMode.ACCESS_READWRITE;
|
ownMetadata.flags = 0; // TODO: Fix flags
|
||||||
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.gcsTelemetryUpdatePeriod = 0;
|
ownMetadata.gcsTelemetryUpdatePeriod = 0;
|
||||||
ownMetadata.loggingUpdateMode = UAVObject.UpdateMode.UPDATEMODE_ONCHANGE;
|
|
||||||
ownMetadata.loggingUpdatePeriod = 0;
|
ownMetadata.loggingUpdatePeriod = 0;
|
||||||
|
|
||||||
// Setup fields
|
|
||||||
List<String> boolEnum = new ArrayList<String>();
|
|
||||||
boolEnum.add("False");
|
|
||||||
boolEnum.add("True");
|
|
||||||
|
|
||||||
List<String> updateModeEnum = new ArrayList<String>();
|
List<String> modesBitField = new ArrayList<String>();
|
||||||
updateModeEnum.add("Periodic");
|
modesBitField.add("FlightReadOnly");
|
||||||
updateModeEnum.add("On Change");
|
modesBitField.add("GCSReadOnly");
|
||||||
updateModeEnum.add("Manual");
|
modesBitField.add("FlightTelemetryAcked");
|
||||||
updateModeEnum.add("Never");
|
modesBitField.add("GCSTelemetryAcked");
|
||||||
|
modesBitField.add("FlightUpdatePeriodic");
|
||||||
|
modesBitField.add("FlightUpdateOnChange");
|
||||||
|
modesBitField.add("GCSUpdatePeriodic");
|
||||||
|
modesBitField.add("GCSUpdateOnChange");
|
||||||
|
|
||||||
List<String> accessModeEnum = new ArrayList<String>();
|
fields.add( new UAVObjectField("Modes", "", UAVObjectField.FieldType.BITFIELD, 1, modesBitField) );
|
||||||
accessModeEnum.add("Read/Write");
|
fields.add( new UAVObjectField("Flight Telemetry Update Period", "ms", UAVObjectField.FieldType.UINT16, 1, null) );
|
||||||
accessModeEnum.add("Read Only");
|
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) );
|
||||||
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 ) );
|
|
||||||
|
|
||||||
int numBytes = 0;
|
int numBytes = 0;
|
||||||
ListIterator<UAVObjectField> li = fields.listIterator();
|
ListIterator<UAVObjectField> li = fields.listIterator();
|
||||||
|
@ -120,17 +120,10 @@ public abstract class UAVObject {
|
|||||||
* Object update mode
|
* Object update mode
|
||||||
*/
|
*/
|
||||||
public enum UpdateMode {
|
public enum UpdateMode {
|
||||||
UPDATEMODE_PERIODIC, /**
|
UPDATEMODE_MANUAL, /** Manually update object, by calling the updated() function */
|
||||||
* Automatically update object at periodic
|
UPDATEMODE_PERIODIC, /** Automatically update object at periodic intervals */
|
||||||
* intervals
|
|
||||||
*/
|
|
||||||
UPDATEMODE_ONCHANGE, /** Only update object when its data changes */
|
UPDATEMODE_ONCHANGE, /** Only update object when its data changes */
|
||||||
UPDATEMODE_MANUAL, /**
|
UPDATEMODE_THROTTLED /** Object is updated on change, but not more often than the interval time */
|
||||||
* Manually update object, by calling the updated()
|
|
||||||
* function
|
|
||||||
*/
|
|
||||||
UPDATEMODE_NEVER
|
|
||||||
/** Object is never updated */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,47 +133,32 @@ public abstract class UAVObject {
|
|||||||
ACCESS_READWRITE, ACCESS_READONLY
|
ACCESS_READWRITE, ACCESS_READONLY
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Access mode
|
|
||||||
*/
|
|
||||||
public enum Acked {
|
|
||||||
FALSE, TRUE
|
|
||||||
};
|
|
||||||
|
|
||||||
public final class Metadata {
|
public final class Metadata {
|
||||||
public AccessMode flightAccess;
|
|
||||||
/**
|
/**
|
||||||
* Defines the access level for the local flight transactions (readonly
|
* Object metadata, each object has a meta object that holds its metadata. The metadata define
|
||||||
* and readwrite)
|
* 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;
|
public int flags; /** Defines flags for update and logging modes and whether an update should be ACK'd (bits defined above) */
|
||||||
/**
|
|
||||||
* Defines the access level for the local GCS transactions (readonly and
|
/** Update period used by the telemetry module (only if telemetry mode is PERIODIC) */
|
||||||
* 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 flightTelemetryUpdatePeriod;
|
public int flightTelemetryUpdatePeriod;
|
||||||
/**
|
|
||||||
* Update period used by the autopilot (only if telemetry mode is
|
/** Update period used by the GCS (only if telemetry mode is PERIODIC) */
|
||||||
* PERIODIC)
|
public int gcsTelemetryUpdatePeriod;
|
||||||
*/
|
|
||||||
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) */
|
/** 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;
|
public int loggingUpdatePeriod;
|
||||||
/**
|
/**
|
||||||
* Update period used by the logging module (only if logging mode is
|
* Update period used by the logging module (only if logging mode is
|
||||||
|
@ -7,7 +7,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class UAVObjectField {
|
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) {
|
public UAVObjectField(String name, String units, FieldType type, int numElements, List<String> options) {
|
||||||
List<String> elementNames = new ArrayList<String>();
|
List<String> elementNames = new ArrayList<String>();
|
||||||
@ -56,6 +56,8 @@ public class UAVObjectField {
|
|||||||
return "float32";
|
return "float32";
|
||||||
case ENUM:
|
case ENUM:
|
||||||
return "enum";
|
return "enum";
|
||||||
|
case BITFIELD:
|
||||||
|
return "bitfield";
|
||||||
case STRING:
|
case STRING:
|
||||||
return "string";
|
return "string";
|
||||||
default:
|
default:
|
||||||
@ -144,6 +146,11 @@ public class UAVObjectField {
|
|||||||
for (int index = 0; index < numElements; ++index)
|
for (int index = 0; index < numElements; ++index)
|
||||||
dataOut.put((Byte) l.get(index));
|
dataOut.put((Byte) l.get(index));
|
||||||
break;
|
break;
|
||||||
|
case BITFIELD:
|
||||||
|
for (int index = 0; index < numElements; ++index) {
|
||||||
|
Integer val = (Integer) getValue(index);
|
||||||
|
dataOut.put(val.byteValue());
|
||||||
|
}
|
||||||
case STRING:
|
case STRING:
|
||||||
// TODO: Implement strings
|
// TODO: Implement strings
|
||||||
throw new Error("Strings not yet implemented");
|
throw new Error("Strings not yet implemented");
|
||||||
@ -224,6 +231,16 @@ public class UAVObjectField {
|
|||||||
}
|
}
|
||||||
break;
|
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:
|
case ENUM:
|
||||||
{
|
{
|
||||||
List<Byte> l = (List<Byte>) this.data;
|
List<Byte> l = (List<Byte>) this.data;
|
||||||
@ -275,6 +292,9 @@ public class UAVObjectField {
|
|||||||
|
|
||||||
return options.get(val);
|
return options.get(val);
|
||||||
}
|
}
|
||||||
|
case BITFIELD:
|
||||||
|
return ((List<Short>) data).get(index).intValue();
|
||||||
|
|
||||||
case STRING:
|
case STRING:
|
||||||
{
|
{
|
||||||
//throw new Exception("Shit I should do this");
|
//throw new Exception("Shit I should do this");
|
||||||
@ -354,6 +374,12 @@ public class UAVObjectField {
|
|||||||
l.set(index, val);
|
l.set(index, val);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case BITFIELD:
|
||||||
|
{
|
||||||
|
List<Short> l = (List<Short>) this.data;
|
||||||
|
l.set(index, bound(data).shortValue());
|
||||||
|
break;
|
||||||
|
}
|
||||||
case STRING:
|
case STRING:
|
||||||
{
|
{
|
||||||
//throw new Exception("Sorry I haven't implemented strings yet");
|
//throw new Exception("Sorry I haven't implemented strings yet");
|
||||||
@ -404,6 +430,8 @@ public class UAVObjectField {
|
|||||||
return true;
|
return true;
|
||||||
case ENUM:
|
case ENUM:
|
||||||
return false;
|
return false;
|
||||||
|
case BITFIELD:
|
||||||
|
return true;
|
||||||
case STRING:
|
case STRING:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
@ -430,6 +458,8 @@ public class UAVObjectField {
|
|||||||
return false;
|
return false;
|
||||||
case ENUM:
|
case ENUM:
|
||||||
return true;
|
return true;
|
||||||
|
case BITFIELD:
|
||||||
|
return false;
|
||||||
case STRING:
|
case STRING:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
@ -493,6 +523,12 @@ public class UAVObjectField {
|
|||||||
((ArrayList<Float>) data).add((float) 0);
|
((ArrayList<Float>) data).add((float) 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case BITFIELD:
|
||||||
|
((ArrayList<Short>) data).clear();
|
||||||
|
for(int index = 0; index < numElements; ++index) {
|
||||||
|
((ArrayList<Short>) data).add((short) 0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case ENUM:
|
case ENUM:
|
||||||
((ArrayList<Byte>) data).clear();
|
((ArrayList<Byte>) data).clear();
|
||||||
for(int index = 0; index < numElements; ++index) {
|
for(int index = 0; index < numElements; ++index) {
|
||||||
@ -549,6 +585,10 @@ public class UAVObjectField {
|
|||||||
data = (Object) new ArrayList<Byte>(this.numElements);
|
data = (Object) new ArrayList<Byte>(this.numElements);
|
||||||
numBytesPerElement = 1;
|
numBytesPerElement = 1;
|
||||||
break;
|
break;
|
||||||
|
case BITFIELD:
|
||||||
|
data = (Object) new ArrayList<Short>(this.numElements);
|
||||||
|
numBytesPerElement = 1;
|
||||||
|
break;
|
||||||
case STRING:
|
case STRING:
|
||||||
data = (Object) new ArrayList<String>(this.numElements);
|
data = (Object) new ArrayList<String>(this.numElements);
|
||||||
numBytesPerElement = 1;
|
numBytesPerElement = 1;
|
||||||
@ -614,6 +654,12 @@ public class UAVObjectField {
|
|||||||
if(num > 4294967295L)
|
if(num > 4294967295L)
|
||||||
return 4294967295L;
|
return 4294967295L;
|
||||||
return num;
|
return num;
|
||||||
|
case BITFIELD:
|
||||||
|
if(num < 0)
|
||||||
|
return (long) 0;
|
||||||
|
if(num > 255)
|
||||||
|
return (long) 255;
|
||||||
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user