From f0e4c10cfae12a45b6d30657f01b43a36fd60a54 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Wed, 2 Mar 2011 20:23:27 -0600 Subject: [PATCH] Continuing to work on the java code to be more consistent with GCS code --- androidgcs/.classpath | 1 + .../org/openpilot/uavtalk/UAVDataObject.java | 34 +++++++++++--- .../org/openpilot/uavtalk/UAVMetaObject.java | 47 +++++++++++++++---- .../src/org/openpilot/uavtalk/UAVObject.java | 36 ++++++++++---- .../templates/uavobjecttemplate.java | 30 ++++++++---- 5 files changed, 117 insertions(+), 31 deletions(-) diff --git a/androidgcs/.classpath b/androidgcs/.classpath index 609aa00eb..b24a2abf5 100644 --- a/androidgcs/.classpath +++ b/androidgcs/.classpath @@ -3,5 +3,6 @@ + diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java b/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java index 12a4263c0..a2e6acf9e 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java @@ -2,17 +2,20 @@ package org.openpilot.uavtalk; public abstract class UAVDataObject extends UAVObject { + /** + * @brief Constructor for UAVDataObject + * @param objID the object id to be created + * @param isSingleInst + * @param isSet + * @param name + */ public UAVDataObject(int objID, Boolean isSingleInst, Boolean isSet, String name) { super(objID, isSingleInst, name); } - public void initialize(int instID, UAVMetaObject mobj) { - - } + public abstract void initialize(int instID, UAVMetaObject mobj); - public void initialize(UAVMetaObject mobj) { - - } + public abstract void initialize(UAVMetaObject mobj); Boolean isSettings() { return null; @@ -22,6 +25,23 @@ public abstract class UAVDataObject extends UAVObject { return null; } - public abstract UAVDataObject clone(int instID); + public UAVDataObject clone(int instID) { + try { + return (UAVDataObject) super.clone(); + } catch (CloneNotSupportedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + +public: + static int OBJID = $(OBJIDHEX); + static String NAME; + static String DESCRIPTION; + static boolean ISSINGLEINST = $(ISSINGLEINST); + static boolean ISSETTINGS = $(ISSETTINGS); + static int NUMBYTES = sizeof(DataFields); + } diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java b/androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java index e5197b02e..9c2e3b12d 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java @@ -2,23 +2,41 @@ package org.openpilot.uavtalk; public class UAVMetaObject extends UAVObject { - private UAVDataObject parent; - - public UAVMetaObject(int objID, String mname, UAVDataObject parent) { - super(objID, true, mname); + public UAVMetaObject(int objID, String name, UAVDataObject parent) { + super(objID, true, name); this.parent = parent; + + 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.gcsTelemetryUpdatePeriod = 0; + ownMetadata.loggingUpdateMode = UAVObject.UpdateMode.UPDATEMODE_ONCHANGE; + ownMetadata.loggingUpdatePeriod = 0; + + } + + UAVObject getParentObject() { + return parent; } @Override public void deserialize(byte[] arr, int offset) { // TODO Auto-generated method stub - + } @Override - public UAVMetaObject getDefaultMetadata() { - // TODO Auto-generated method stub - return null; + public Metadata getMetadata() { + return ownMetadata; + } + + @Override + public Metadata getDefaultMetadata() { + return ownMetadata; } @Override @@ -45,4 +63,17 @@ public class UAVMetaObject extends UAVObject { return null; } + + public UAVMetaObject(quint32 objID, const QString& name, UAVObject* parent); + UAVObject* getParentObject(); + void setMetadata(const Metadata& mdata); + void setData(const Metadata& mdata); + Metadata getData(); + + + private UAVObject parent; + private Metadata ownMetadata; + private Metadata parentMetadata; + + } diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVObject.java b/androidgcs/src/org/openpilot/uavtalk/UAVObject.java index c5ffc9d21..1decf3563 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVObject.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVObject.java @@ -20,11 +20,27 @@ public abstract class UAVObject { ACCESS_READWRITE, ACCESS_READONLY } ; - - - private Boolean isSingleInst; - private int instID; - private UAVMetaObject meta; + + /** + * Access mode + */ + public enum Acked{ + FALSE, + TRUE + } ; + + final class Metadata { + public AccessMode flightAccess; /** Defines the access level for the local flight transactions (readonly and readwrite) */ + 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 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 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 PERIODIC) */ + } ; public UAVObject(int objID, Boolean isSingleInst, String name) { assert(objID == getObjID()); // ID is in implementation code, make sure it matches object @@ -62,9 +78,13 @@ public abstract class UAVObject { return true; } - public void setMetadata(UAVMetaObject obj) { meta = obj; } - public UAVMetaObject getMetadata() { return meta; } - public abstract UAVMetaObject getDefaultMetadata(); + public abstract void setMetadata(Metadata obj); + public abstract Metadata getMetadata(); + public abstract Metadata getDefaultMetadata(); + + private Boolean isSingleInst; + private int instID; + private UAVMetaObject meta; /* // Unported code from QT diff --git a/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjecttemplate.java b/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjecttemplate.java index 13eeeb724..fa09f782f 100644 --- a/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjecttemplate.java +++ b/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjecttemplate.java @@ -31,29 +31,34 @@ package org.openpilot.uavtalk.uavobjects; import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVDataObject; import org.openpilot.uavtalk.UAVMetaObject; +import org.openpilot.uavtalk.UAVObjectField; /** $(DESCRIPTION) generated from $(XMLFILE) **/ -public class $(NAME) extends UAVDataObject{ +public class $(NAME) extends UAVDataObject { $(FIELDSINIT) + public $(NAME) (int objID, Boolean isSingleInst, Boolean isSet, String name) { + super(OBJID, ISSINGLEINST, ISSETTINGS, NAME); + } + public void setGeneratedMetaData() { - getMetaData().gcsAccess = UAVMetaObject.$(GCSACCESS); - getMetaData().gcsTelemetryAcked = UAVMetaObject.$(GCSTELEM_ACKEDTF); - getMetaData().gcsTelemetryUpdateMode = UAVMetaObject.$(GCSTELEM_UPDATEMODE); + getMetaData().gcsAccess = UAVObject.AccessMode.$(GCSACCESS); + getMetaData().gcsTelemetryAcked = UAVObject.Acked.$(GCSTELEM_ACKEDTF); + getMetaData().gcsTelemetryUpdateMode = UAVObject.UpdateMode.$(GCSTELEM_UPDATEMODE); getMetaData().gcsTelemetryUpdatePeriod = $(GCSTELEM_UPDATEPERIOD); - getMetaData().flightAccess = UAVMetaObject.$(FLIGHTACCESS); - getMetaData().flightTelemetryAcked = UAVMetaObject.$(FLIGHTTELEM_ACKEDTF); - getMetaData().flightTelemetryUpdateMode = UAVMetaObject.$(FLIGHTTELEM_UPDATEMODE); + getMetaData().flightAccess = UAVObject.AccessMode.$(FLIGHTACCESS); + getMetaData().flightTelemetryAcked = UAVObject.Acked.$(FLIGHTTELEM_ACKEDTF); + getMetaData().flightTelemetryUpdateMode = UAVObject.UpdateMode.$(FLIGHTTELEM_UPDATEMODE); getMetaData().flightTelemetryUpdatePeriod = $(FLIGHTTELEM_UPDATEPERIOD); - getMetaData().loggingUpdateMode = UAVMetaObject.$(LOGGING_UPDATEMODE); + getMetaData().loggingUpdateMode = UAVObject.UpdateMode.$(LOGGING_UPDATEMODE); getMetaData().loggingUpdatePeriod = $(LOGGING_UPDATEPERIOD); } @@ -69,6 +74,15 @@ $(FIELDSINIT) public String getDescription() { return "$(DESCRIPTION)"; } +protected: + // Constants + static final int OBJID = $(OBJIDHEX); + static final String NAME; + static final String DESCRIPTION; + static final boolean ISSINGLEINST = $(ISSINGLEINST); + static final boolean ISSETTINGS = $(ISSETTINGS); + static final int NUMBYTES = sizeof(DataFields); + $(GETTERSETTER) } \ No newline at end of file