From a2e93f19716524d9237037f354472a32888827b2 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Sun, 6 Mar 2011 00:03:20 -0600 Subject: [PATCH] More work on the java UAVObject implementation --- .../org/openpilot/uavtalk/UAVDataObject.java | 93 ++- .../org/openpilot/uavtalk/UAVMetaObject.java | 140 +++-- .../src/org/openpilot/uavtalk/UAVObject.java | 581 +++++++++--------- .../org/openpilot/uavtalk/UAVObjectField.java | 35 +- .../openpilot/uavtalk/UAVObjectManager.java | 30 +- 5 files changed, 497 insertions(+), 382 deletions(-) diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java b/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java index a2e6acf9e..f0a2248f5 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java @@ -9,39 +9,78 @@ public abstract class UAVDataObject extends UAVObject { * @param isSet * @param name */ - public UAVDataObject(int objID, Boolean isSingleInst, Boolean isSet, String name) { + public UAVDataObject(int objID, Boolean isSingleInst, Boolean isSet, String name) throws Exception { super(objID, isSingleInst, name); + mobj = null; + this.isSet = isSet; } - - public abstract void initialize(int instID, UAVMetaObject mobj); - - public abstract void initialize(UAVMetaObject mobj); - - Boolean isSettings() { - return null; + /** + * Initialize instance ID and assign a metaobject + */ + public void initialize(int instID, UAVMetaObject mobj) + { + //QMutexLocker locker(mutex); + this.mobj = mobj; + super.initialize(instID); + } + + /** + * Assign a metaobject + */ + public void initialize(UAVMetaObject mobj) + { + //QMutexLocker locker(mutex); + this.mobj = mobj; + } + + /** + * Returns true if this is a data object holding module settings + */ + public boolean isSettings() + { + return isSet; + } + + /** + * Set the object's metadata + */ + public void setMetadata(Metadata mdata) + { + if ( mobj != null ) + { + mobj.setData(mdata); + } + } + + /** + * Get the object's metadata + */ + public Metadata getMetadata() + { + if ( mobj != null) + { + return mobj.getData(); + } + else + { + return getDefaultMetadata(); + } + } + + /** + * Get the metaobject + */ + public UAVMetaObject getMetaObject() + { + return mobj; } - - UAVMetaObject getMetaObject() { - return null; - } + // TODO: Make abstract public UAVDataObject clone(int instID) { - try { - return (UAVDataObject) super.clone(); - } catch (CloneNotSupportedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; + return (UAVDataObject) super.clone(); } -public: - static int OBJID = $(OBJIDHEX); - static String NAME; - static String DESCRIPTION; - static boolean ISSINGLEINST = $(ISSINGLEINST); - static boolean ISSETTINGS = $(ISSETTINGS); - static int NUMBYTES = sizeof(DataFields); - + private UAVMetaObject mobj; + private boolean isSet; } diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java b/androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java index 9c2e3b12d..70e661d46 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVMetaObject.java @@ -1,76 +1,116 @@ package org.openpilot.uavtalk; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; + public class UAVMetaObject extends UAVObject { - public UAVMetaObject(int objID, String name, UAVDataObject parent) { + public UAVMetaObject(int objID, String name, UAVDataObject parent) throws Exception { 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; - + + 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; + + // Setup fields + List boolEnum = new ArrayList(); + boolEnum.add("False"); + boolEnum.add("True"); + + List updateModeEnum = new ArrayList(); + updateModeEnum.add("Periodic"); + updateModeEnum.add("On Change"); + updateModeEnum.add("Manual"); + updateModeEnum.add("Never"); + + List accessModeEnum = new ArrayList(); + accessModeEnum.add("Read/Write"); + accessModeEnum.add("Read Only"); + + List fields = new ArrayList(); + 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 ) ); + + // Initialize parent + super.initialize(0); + super.initializeFields(fields, ByteBuffer.allocate(10), 10); + + // Setup metadata of parent + parentMetadata = parent.getDefaultMetadata(); } - UAVObject getParentObject() { + /** + * Get the parent object + */ + public UAVObject getParentObject() + { return parent; } - @Override - public void deserialize(byte[] arr, int offset) { - // TODO Auto-generated method stub - + /** + * Set the metadata of the metaobject, this function will + * do nothing since metaobjects have read-only metadata. + */ + public void setMetadata(Metadata mdata) + { + return; // can not update metaobject's metadata } - @Override - public Metadata getMetadata() { + /** + * Get the metadata of the metaobject + */ + public Metadata getMetadata() + { return ownMetadata; } - @Override - public Metadata getDefaultMetadata() { - return ownMetadata; + /** + * Get the default metadata + */ + public Metadata getDefaultMetadata() + { + return ownMetadata; } - @Override - public String getDescription() { - // TODO Auto-generated method stub - return null; + /** + * Set the metadata held by the metaobject + */ + public void setData(Metadata mdata) + { + //QMutexLocker locker(mutex); + parentMetadata = mdata; + // TODO: Callbacks + // emit objectUpdatedAuto(this); // trigger object updated event + // emit objectUpdated(this); } - @Override - public int getObjID() { - // TODO Auto-generated method stub - return 0; + /** + * Get the metadata held by the metaobject + */ + public Metadata getData() + { +// QMutexLocker locker(mutex); + return parentMetadata; } - @Override - public String getObjName() { - // TODO Auto-generated method stub - return null; - } - @Override - public byte[] serialize() { - // TODO Auto-generated method stub - 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 f987a03a9..926440805 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVObject.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVObject.java @@ -6,241 +6,274 @@ import java.util.ListIterator; public abstract class UAVObject { - /** * Object update mode */ public enum UpdateMode { - UPDATEMODE_PERIODIC, /** Automatically update object at periodic intervals */ + 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_MANUAL, /** + * Manually update object, by calling the updated() + * function + */ + UPDATEMODE_NEVER + /** Object is never updated */ + }; /** * Access mode */ - public enum AccessMode{ - ACCESS_READWRITE, - ACCESS_READONLY - } ; + public enum AccessMode { + ACCESS_READWRITE, ACCESS_READONLY + }; /** * Access mode */ - public enum Acked{ - FALSE, - TRUE - } ; + public enum Acked { + FALSE, TRUE + }; - protected 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 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) { this.objID = objID; this.instID = 0; this.isSingleInst = isSingleInst; this.name = name; - // this.mutex = new QMutex(QMutex::Recursive); + // this.mutex = new QMutex(QMutex::Recursive); }; public void initialize(int instID) { - //QMutexLocker locker(mutex); + // QMutexLocker locker(mutex); this.instID = instID; } /** * Initialize objects' data fields - * @param fields List of fields held by the object - * @param data Pointer to that actual object data, this is needed by the fields to access the data - * @param numBytes Number of bytes in the object (total, including all fields) - * @throws Exception When unable to unpack a field + * + * @param fields + * List of fields held by the object + * @param data + * Pointer to that actual object data, this is needed by the + * fields to access the data + * @param numBytes + * Number of bytes in the object (total, including all fields) + * @throws Exception + * When unable to unpack a field */ - public void initializeFields(List fields, ByteBuffer data, int numBytes) throws Exception - { - // TODO: QMutexLocker locker(mutex); + public void initializeFields(List fields, ByteBuffer data, + int numBytes) throws Exception { + // TODO: QMutexLocker locker(mutex); this.numBytes = numBytes; - this.data = data; +// this.data = data; this.fields = fields; // Initialize fields - for (int n = 0; n < fields.size(); ++n) - { + for (int n = 0; n < fields.size(); ++n) { fields.get(n).initialize(this); } - unpack(data); +// unpack(data); } /** * Get the object ID */ - public int getObjID() - { + public int getObjID() { return objID; } /** * Get the instance ID */ - public int getInstID() - { + public int getInstID() { return instID; } /** * Returns true if this is a single instance object */ - public boolean isSingleInstance() - { + public boolean isSingleInstance() { return isSingleInst; } /** * Get the name of the object */ - public String getName() - { + public String getName() { return name; } /** * Get the description of the object + * * @return The description of the object */ - public String getDescription() - { + public String getDescription() { return description; } /** * Set the description of the object - * @param The description of the object - * @return + * + * @param The + * description of the object + * @return */ - public void setDescription(String description) - { + public void setDescription(String description) { this.description = description; } - /** * Get the total number of bytes of the object's data */ - public int getNumBytes() - { + public int getNumBytes() { return numBytes; } - // /** - // * Request that this object is updated with the latest values from the autopilot - // */ - // /* void UAVObject::requestUpdate() - // { - // emit updateRequested(this); - // } */ + // /** + // * Request that this object is updated with the latest values from the + // autopilot + // */ + // /* void UAVObject::requestUpdate() + // { + // emit updateRequested(this); + // } */ // - // /** - // * Signal that the object has been updated - // */ - // /* void UAVObject::updated() - // { - // emit objectUpdatedManual(this); - // emit objectUpdated(this); - // } */ + // /** + // * Signal that the object has been updated + // */ + // /* void UAVObject::updated() + // { + // emit objectUpdatedManual(this); + // emit objectUpdated(this); + // } */ // - // /** - // * Lock mutex of this object - // */ - // /* void UAVObject::lock() - // { - // mutex->lock(); - // } */ + // /** + // * Lock mutex of this object + // */ + // /* void UAVObject::lock() + // { + // mutex->lock(); + // } */ // - // /** - // * Lock mutex of this object - // */ - // /* void UAVObject::lock(int timeoutMs) - // { - // mutex->tryLock(timeoutMs); - // } */ + // /** + // * Lock mutex of this object + // */ + // /* void UAVObject::lock(int timeoutMs) + // { + // mutex->tryLock(timeoutMs); + // } */ // - // /** - // * Unlock mutex of this object - // */ - // /* void UAVObject::unlock() - // { - // mutex->unlock(); - // } */ + // /** + // * Unlock mutex of this object + // */ + // /* void UAVObject::unlock() + // { + // mutex->unlock(); + // } */ // - // /** - // * Get object's mutex - // */ - // QMutex* UAVObject::getMutex() - // { - // return mutex; - // } + // /** + // * Get object's mutex + // */ + // QMutex* UAVObject::getMutex() + // { + // return mutex; + // } /** * Get the number of fields held by this object */ - public int getNumFields() - { - //QMutexLocker locker(mutex); + public int getNumFields() { + // QMutexLocker locker(mutex); return fields.size(); } /** * Get the object's fields */ - public List getFields() - { - //QMutexLocker locker(mutex); + public List getFields() { + // QMutexLocker locker(mutex); return fields; } /** * Get a specific field - * @throws Exception + * + * @throws Exception * @returns The field or NULL if not found */ - public UAVObjectField getField(String name) throws Exception - { - //QMutexLocker locker(mutex); + public UAVObjectField getField(String name) { + // QMutexLocker locker(mutex); // Look for field ListIterator li = fields.listIterator(); - while(li.hasNext()) { + while (li.hasNext()) { UAVObjectField field = li.next(); - if(field.getName().equals(name)) + if (field.getName().equals(name)) return field; } - throw new Exception("Field not found"); + //throw new Exception("Field not found"); + return null; } /** * Pack the object data into a byte array - * @param dataOut ByteBuffer to receive the data. - * @throws Exception + * + * @param dataOut + * ByteBuffer to receive the data. + * @throws Exception * @returns The number of bytes copied * @note The array must already have enough space allocated for the object */ - public int pack(ByteBuffer dataOut) throws Exception - { + public int pack(ByteBuffer dataOut) throws Exception { // QMutexLocker locker(mutex); - if(dataOut.remaining() < getNumBytes()) + if (dataOut.remaining() < getNumBytes()) throw new Exception("Not enough bytes in ByteBuffer to pack object"); int numBytes = 0; ListIterator li = fields.listIterator(); - while(li.hasNext()) { + while (li.hasNext()) { UAVObjectField field = li.next(); numBytes += field.pack(dataOut); } @@ -249,232 +282,232 @@ public abstract class UAVObject { /** * Unpack the object data from a byte array - * @param dataIn The ByteBuffer to pull data from - * @throws Exception + * + * @param dataIn + * The ByteBuffer to pull data from + * @throws Exception * @returns The number of bytes copied */ - public int unpack(ByteBuffer dataIn) throws Exception - { + public int unpack(ByteBuffer dataIn) throws Exception { + if( dataIn == null ) + return 0; + System.out.println( dataIn.toString() ); // QMutexLocker locker(mutex); int numBytes = 0; ListIterator li = fields.listIterator(); - while(li.hasNext()) { + while (li.hasNext()) { UAVObjectField field = li.next(); + System.out.println(field.toString()); numBytes += field.unpack(dataIn); } return numBytes; // TODO: Callbacks - //emit objectUnpacked(this); // trigger object updated event - //emit objectUpdated(this); + // emit objectUnpacked(this); // trigger object updated event + // emit objectUpdated(this); } - // /** - // * Save the object data to the file. - // * The file will be created in the current directory - // * and its name will be the same as the object with - // * the .uavobj extension. - // * @returns True on success, false on failure - // */ - // bool UAVObject::save() - // { - // QMutexLocker locker(mutex); + // /** + // * Save the object data to the file. + // * The file will be created in the current directory + // * and its name will be the same as the object with + // * the .uavobj extension. + // * @returns True on success, false on failure + // */ + // bool UAVObject::save() + // { + // QMutexLocker locker(mutex); // - // // Open file - // QFile file(name + ".uavobj"); - // if (!file.open(QFile::WriteOnly)) - // { - // return false; - // } + // // Open file + // QFile file(name + ".uavobj"); + // if (!file.open(QFile::WriteOnly)) + // { + // return false; + // } // - // // Write object - // if ( !save(file) ) - // { - // return false; - // } + // // Write object + // if ( !save(file) ) + // { + // return false; + // } // - // // Close file - // file.close(); - // return true; - // } + // // Close file + // file.close(); + // return true; + // } // - // /** - // * Save the object data to the file. - // * The file is expected to be already open for writting. - // * The data will be appended and the file will not be closed. - // * @returns True on success, false on failure - // */ - // bool UAVObject::save(QFile& file) - // { - // QMutexLocker locker(mutex); - // quint8 buffer[numBytes]; - // quint8 tmpId[4]; + // /** + // * Save the object data to the file. + // * The file is expected to be already open for writting. + // * The data will be appended and the file will not be closed. + // * @returns True on success, false on failure + // */ + // bool UAVObject::save(QFile& file) + // { + // QMutexLocker locker(mutex); + // quint8 buffer[numBytes]; + // quint8 tmpId[4]; // - // // Write the object ID - // qToLittleEndian(objID, tmpId); - // if ( file.write((const char*)tmpId, 4) == -1 ) - // { - // return false; - // } + // // Write the object ID + // qToLittleEndian(objID, tmpId); + // if ( file.write((const char*)tmpId, 4) == -1 ) + // { + // return false; + // } // - // // Write the instance ID - // if (!isSingleInst) - // { - // qToLittleEndian(instID, tmpId); - // if ( file.write((const char*)tmpId, 2) == -1 ) - // { - // return false; - // } - // } + // // Write the instance ID + // if (!isSingleInst) + // { + // qToLittleEndian(instID, tmpId); + // if ( file.write((const char*)tmpId, 2) == -1 ) + // { + // return false; + // } + // } // - // // Write the data - // pack(buffer); - // if ( file.write((const char*)buffer, numBytes) == -1 ) - // { - // return false; - // } + // // Write the data + // pack(buffer); + // if ( file.write((const char*)buffer, numBytes) == -1 ) + // { + // return false; + // } // - // // Done - // return true; - // } + // // Done + // return true; + // } // - // /** - // * Load the object data from a file. - // * The file will be openned in the current directory - // * and its name will be the same as the object with - // * the .uavobj extension. - // * @returns True on success, false on failure - // */ - // bool UAVObject::load() - // { - // QMutexLocker locker(mutex); + // /** + // * Load the object data from a file. + // * The file will be openned in the current directory + // * and its name will be the same as the object with + // * the .uavobj extension. + // * @returns True on success, false on failure + // */ + // bool UAVObject::load() + // { + // QMutexLocker locker(mutex); // - // // Open file - // QFile file(name + ".uavobj"); - // if (!file.open(QFile::ReadOnly)) - // { - // return false; - // } + // // Open file + // QFile file(name + ".uavobj"); + // if (!file.open(QFile::ReadOnly)) + // { + // return false; + // } // - // // Load object - // if ( !load(file) ) - // { - // return false; - // } + // // Load object + // if ( !load(file) ) + // { + // return false; + // } // - // // Close file - // file.close(); - // return true; - // } + // // Close file + // file.close(); + // return true; + // } // - // /** - // * Load the object data from file. - // * The file is expected to be already open for reading. - // * The data will be read and the file will not be closed. - // * @returns True on success, false on failure - // */ - // bool UAVObject::load(QFile& file) - // { - // QMutexLocker locker(mutex); - // quint8 buffer[numBytes]; - // quint8 tmpId[4]; + // /** + // * Load the object data from file. + // * The file is expected to be already open for reading. + // * The data will be read and the file will not be closed. + // * @returns True on success, false on failure + // */ + // bool UAVObject::load(QFile& file) + // { + // QMutexLocker locker(mutex); + // quint8 buffer[numBytes]; + // quint8 tmpId[4]; // - // // Read the object ID - // if ( file.read((char*)tmpId, 4) != 4 ) - // { - // return false; - // } + // // Read the object ID + // if ( file.read((char*)tmpId, 4) != 4 ) + // { + // return false; + // } // - // // Check that the IDs match - // if (qFromLittleEndian(tmpId) != objID) - // { - // return false; - // } + // // Check that the IDs match + // if (qFromLittleEndian(tmpId) != objID) + // { + // return false; + // } // - // // Read the instance ID - // if ( file.read((char*)tmpId, 2) != 2 ) - // { - // return false; - // } + // // Read the instance ID + // if ( file.read((char*)tmpId, 2) != 2 ) + // { + // return false; + // } // - // // Check that the IDs match - // if (qFromLittleEndian(tmpId) != instID) - // { - // return false; - // } + // // Check that the IDs match + // if (qFromLittleEndian(tmpId) != instID) + // { + // return false; + // } // - // // Read and unpack the data - // if ( file.read((char*)buffer, numBytes) != numBytes ) - // { - // return false; - // } - // unpack(buffer); + // // Read and unpack the data + // if ( file.read((char*)buffer, numBytes) != numBytes ) + // { + // return false; + // } + // unpack(buffer); // - // // Done - // return true; - // } + // // Done + // return true; + // } /** * Return a string with the object information */ @Override - public String toString() - { + public String toString() { return toStringBrief() + toStringData(); } /** * Return a string with the object information (only the header) */ - public String toStringBrief() - { - return String.format("%1 (ID: %2, InstID: %3, NumBytes: %4, SInst: %5)\n", - getName(), - getObjID(), - getInstID(), - getNumBytes(), - isSingleInstance()); + public String toStringBrief() { + return getName() + " ( " + getObjID() + " " + getInstID() + " " + getNumBytes() + ")\n"; + // getName(), getObjID(), getInstID(), getNumBytes(), + // isSingleInstance()); } /** * Return a string with the object information (only the data) */ - public String toStringData() - { + public String toStringData() { String s = new String(); ListIterator li = fields.listIterator(); - while(li.hasNext()) { + while (li.hasNext()) { UAVObjectField field = li.next(); s += field.toString(); } return s; } - // /** - // * Emit the transactionCompleted event (used by the UAVTalk plugin) - // */ - // void UAVObject::emitTransactionCompleted(bool success) - // { - // emit transactionCompleted(this, success); - // } + // /** + // * Emit the transactionCompleted event (used by the UAVTalk plugin) + // */ + // void UAVObject::emitTransactionCompleted(bool success) + // { + // emit transactionCompleted(this, success); + // } - /** + /** * Java specific functions */ public UAVObject clone() { return (UAVObject) clone(); } + /** * Abstract functions */ public abstract void setMetadata(Metadata mdata); + public abstract Metadata getMetadata(); + public abstract Metadata getDefaultMetadata(); - public abstract UAVDataObject clone(int instID); - protected abstract void setDefaultFieldValues(); /** * Private data for the object, common to all - */ + */ protected int objID; protected int instID; protected boolean isSingleInst; @@ -482,6 +515,6 @@ public abstract class UAVObject { protected String description; protected int numBytes; // TODO: QMutex* mutex; - protected ByteBuffer data; +// protected ByteBuffer data; protected List fields; } diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java b/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java index c7c774199..b37c992fb 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java @@ -248,34 +248,37 @@ public class UAVObjectField { return null; } - public void setValue(Object data) throws Exception { setValue(data,0); } - public void setValue(Object data, int index) throws Exception { + public void setValue(Object data) { setValue(data,0); } + public void setValue(Object data, int index) { // QMutexLocker locker(obj->getMutex()); // Check that index is not out of bounds if ( index >= numElements ) - throw new Exception("Index out of bounds"); + //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(); + UAVObject.Metadata mdata = obj.getMetadata(); // Update value if the access mode permits - if ( true ) //mdata.gcsAccess == UAVObject.AccessMode.ACCESS_READWRITE ) + if ( mdata.gcsAccess == UAVObject.AccessMode.ACCESS_READWRITE ) { - ByteBuffer bbuf = ByteBuffer.allocate(numBytesPerElement); switch (type) { case INT8: + data = new Integer((Byte) data); case INT16: + data = new Integer((Short) data); case INT32: { List l = (List) this.data; - l.set(index, (Integer) data); + l.set(index,(Integer) data); break; } case UINT8: + data = new Integer((Byte) data); case UINT16: + data = new Integer((Short) data); case UINT32: { List l = (List) this.data; @@ -291,14 +294,14 @@ public class UAVObjectField { case ENUM: { byte val = (byte) options.indexOf((String) data); - if(val < 0) throw new Exception("Enumerated value not found"); + //if(val < 0) throw new Exception("Enumerated value not found"); List l = (List) this.data; l.set(index, val); break; } case STRING: { - throw new Exception("Sorry I haven't implemented strings yet"); + //throw new Exception("Sorry I haven't implemented strings yet"); } } } @@ -309,24 +312,24 @@ public class UAVObjectField { return Double.valueOf((Double) getValue(index)); } - void setDouble(double value) throws Exception { setDouble(value, 0); }; - void setDouble(double value, int index) throws Exception { + public void setDouble(double value) throws Exception { setDouble(value, 0); }; + public void setDouble(double value, int index) throws Exception { setValue(value, index); } - int getDataOffset() { + public int getDataOffset() { return offset; } - int getNumBytes() { + public int getNumBytes() { return numBytesPerElement * numElements; } - int getNumBytesElement() { + public int getNumBytesElement() { return numBytesPerElement; } - boolean isNumeric() { + public boolean isNumeric() { switch (type) { case INT8: @@ -352,7 +355,7 @@ public class UAVObjectField { } } - boolean isText() { + public boolean isText() { switch (type) { case INT8: diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVObjectManager.java b/androidgcs/src/org/openpilot/uavtalk/UAVObjectManager.java index 3091595f0..d75b14b85 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVObjectManager.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVObjectManager.java @@ -21,8 +21,9 @@ public class UAVObjectManager { * A new instance can be created directly by instantiating a new object or by calling clone() of * an existing object. The object will be registered and will be properly initialized so that it can accept * updates. + * @throws Exception */ - Boolean registerObject(UAVDataObject obj) + public boolean registerObject(UAVDataObject obj) throws Exception { // QMutexLocker locker(mutex); @@ -126,7 +127,7 @@ public class UAVObjectManager { return true; } - void addObject(UAVObject obj) + public void addObject(UAVObject obj) { // Add to list List ls = new ArrayList(); @@ -139,7 +140,7 @@ public class UAVObjectManager { * Get all objects. A two dimentional QList is returned. Objects are grouped by * instances of the same object type. */ - List> getObjects() + public List> getObjects() { //QMutexLocker locker(mutex); return objects; @@ -148,7 +149,7 @@ public class UAVObjectManager { /** * Same as getObjects() but will only return DataObjects. */ - List< List > getDataObjects() + public List< List > getDataObjects() { return new ArrayList>(); @@ -186,7 +187,7 @@ public class UAVObjectManager { /** * Same as getObjects() but will only return MetaObjects. */ - List > getMetaObjects() + public List > getMetaObjects() { return new ArrayList< List >(); /* @@ -227,7 +228,7 @@ public class UAVObjectManager { * Get a specific object given its name and instance ID * @returns The object is found or NULL if not */ - UAVObject getObject(String name, int instId) + public UAVObject getObject(String name, int instId) { return getObject(name, 0, instId); } @@ -236,7 +237,7 @@ public class UAVObjectManager { * Get a specific object given its object and instance ID * @returns The object is found or NULL if not */ - UAVObject getObject(int objId, int instId) + public UAVObject getObject(int objId, int instId) { return getObject(null, objId, instId); } @@ -244,7 +245,7 @@ public class UAVObjectManager { /** * Helper function for the public getObject() functions. */ - UAVObject getObject(String name, int objId, int instId) + public UAVObject getObject(String name, int objId, int instId) { //QMutexLocker locker(mutex); // Check if this object type is already in the list @@ -271,7 +272,7 @@ public class UAVObjectManager { /** * Get all the instances of the object specified by name */ - List getObjectInstances(String name) + public List getObjectInstances(String name) { return getObjectInstances(name, 0); } @@ -279,7 +280,7 @@ public class UAVObjectManager { /** * Get all the instances of the object specified by its ID */ - List getObjectInstances(int objId) + public List getObjectInstances(int objId) { return getObjectInstances(null, objId); } @@ -287,7 +288,7 @@ public class UAVObjectManager { /** * Helper function for the public getObjectInstances() */ - List getObjectInstances(String name, int objId) + public List getObjectInstances(String name, int objId) { //QMutexLocker locker(mutex); // Check if this object type is already in the list @@ -307,7 +308,7 @@ public class UAVObjectManager { /** * Get the number of instances for an object given its name */ - int getNumInstances(String name) + public int getNumInstances(String name) { return getNumInstances(name, 0); } @@ -315,7 +316,7 @@ public class UAVObjectManager { /** * Get the number of instances for an object given its ID */ - int getNumInstances(int objId) + public int getNumInstances(int objId) { return getNumInstances(null, objId); } @@ -323,10 +324,9 @@ public class UAVObjectManager { /** * Helper function for public getNumInstances */ - int getNumInstances(String name, int objId) + public int getNumInstances(String name, int objId) { return getObjectInstances(name,objId).size(); } - }