From f33862509216ebd4383db53b0f3b42b9ac0fc851 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Sun, 6 Mar 2011 13:12:32 -0600 Subject: [PATCH] Removed various debugging outputs and exceptions for now (will add back in a more principled manner later). Also updated the auto generated code. --- androidgcs/.classpath | 1 + .../org/openpilot/uavtalk/UAVDataObject.java | 2 +- .../src/org/openpilot/uavtalk/UAVObject.java | 5 +- .../org/openpilot/uavtalk/UAVObjectField.java | 30 +++++++---- .../templates/uavobjectsinittemplate.java | 52 ++++--------------- .../templates/uavobjecttemplate.java | 6 +-- .../java/uavobjectgeneratorjava.cpp | 4 +- 7 files changed, 37 insertions(+), 63 deletions(-) diff --git a/androidgcs/.classpath b/androidgcs/.classpath index b24a2abf5..6f3f456df 100644 --- a/androidgcs/.classpath +++ b/androidgcs/.classpath @@ -1,6 +1,7 @@ + diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java b/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java index f0a2248f5..de04f81c5 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVDataObject.java @@ -9,7 +9,7 @@ public abstract class UAVDataObject extends UAVObject { * @param isSet * @param name */ - public UAVDataObject(int objID, Boolean isSingleInst, Boolean isSet, String name) throws Exception { + public UAVDataObject(int objID, Boolean isSingleInst, Boolean isSet, String name) { super(objID, isSingleInst, name); mobj = null; this.isSet = isSet; diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVObject.java b/androidgcs/src/org/openpilot/uavtalk/UAVObject.java index bf2c87d7e..cc6718ebd 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVObject.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVObject.java @@ -105,10 +105,9 @@ public abstract class UAVObject { * When unable to unpack a field */ public void initializeFields(List fields, ByteBuffer data, - int numBytes) throws Exception { + int numBytes) { // TODO: QMutexLocker locker(mutex); this.numBytes = numBytes; -// this.data = data; this.fields = fields; // Initialize fields for (int n = 0; n < fields.size(); ++n) { @@ -288,7 +287,7 @@ public abstract class UAVObject { * @throws Exception * @returns The number of bytes copied */ - public int unpack(ByteBuffer dataIn) throws Exception { + public int unpack(ByteBuffer dataIn) { if( dataIn == null ) return 0; diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java b/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java index 78ebd7b52..a5fc6b7da 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java @@ -90,8 +90,8 @@ public class UAVObjectField { * to the arm/uavtalk standard (little endian) * @param dataOut * @return the number of bytes added - * @throws Exception */ - public int pack(ByteBuffer dataOut) throws Exception { + **/ + public int pack(ByteBuffer dataOut) { //QMutexLocker locker(obj->getMutex()); // Pack each element in output buffer dataOut.order(ByteOrder.LITTLE_ENDIAN); @@ -147,7 +147,7 @@ public class UAVObjectField { break; case STRING: // TODO: Implement strings - throw new Exception("Strings not yet implemented"); + throw new Error("Strings not yet implemented"); } // Done return getNumBytes(); @@ -358,13 +358,13 @@ public class UAVObjectField { } } - public double getDouble() throws Exception { return getDouble(0); }; - public double getDouble(int index) throws Exception { + public double getDouble() { return getDouble(0); }; + public double getDouble(int index) { return Double.valueOf((Double) getValue(index)); } - public void setDouble(double value) throws Exception { setDouble(value, 0); }; - public void setDouble(double value, int index) throws Exception { + public void setDouble(double value) { setDouble(value, 0); }; + public void setDouble(double value, int index) { setValue(value, index); } @@ -436,9 +436,7 @@ public class UAVObjectField { String sout = new String(); sout += name + ": [ "; for (int n = 0; n < numElements; ++n) - { sout += String.valueOf(n) + "(" + getValue(n) + ") "; - } sout += "] " + units + "\n"; return sout; @@ -488,6 +486,18 @@ public class UAVObjectField { ((ArrayList) data).add((long) 0); } break; + case FLOAT32: + ((ArrayList) data).clear(); + for(int index = 0; index < numElements; ++index) { + ((ArrayList) data).add((float) 0); + } + break; + case ENUM: + ((ArrayList) data).clear(); + for(int index = 0; index < numElements; ++index) { + ((ArrayList) data).add((byte) 0); + } + break; } } @@ -546,8 +556,6 @@ public class UAVObjectField { numBytesPerElement = 0; } clear(); - - System.out.println(this); } /** diff --git a/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjectsinittemplate.java b/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjectsinittemplate.java index 5185ab237..7f9edb791 100644 --- a/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjectsinittemplate.java +++ b/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjectsinittemplate.java @@ -26,50 +26,18 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -package org.openpilot.uavtalk; +package org.openpilot.uavtalk.uavobjects; import org.openpilot.uavtalk.uavobjects.*; -import org.openpilot.uavtalk.UAVObject; -import java.util.HashMap; +import org.openpilot.uavtalk.UAVObjectManager; -public class UAVObjects { - - private static UAVObject[] uavobjects=null; - private static HashMap id2obj; - - public static void init() { - if (uavobjects==null) { - uavobjects=new UAVObject[] { -$(OBJINIT) - }; - id2obj=new HashMap(); - for (int i=0;i< uavobjects.length;i++) - id2obj.put(uavobjects[i].getObjID(),i); +public class UAVObjectsInitialize { + + public static void register(UAVObjectManager objMngr) { + try { +$(OBJINIT) + } catch (Exception e) { + e.printStackTrace(); + } } - } - - public static UAVObject[] getUAVObjectArray() { - return uavobjects; - } - - public static boolean hasObjectWithID(int id) { - return id2obj.containsKey(id); - } - - public static UAVObject getObjectByID(int id) { - if (!hasObjectWithID(id)) - return null; - return uavobjects[(Integer)id2obj.get(id)]; - } - - public static UAVObject getObjectByName(String name) { - return uavobjects[0]; - } - - public static void printAll() { - for (UAVObject obj : uavobjects) - System.out.println(obj.getObjName()); - } - -$(OBJGETTER) } \ No newline at end of file diff --git a/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjecttemplate.java b/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjecttemplate.java index af8f48fce..64e2461f5 100644 --- a/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjecttemplate.java +++ b/ground/openpilotgcs/src/libs/juavobjects/templates/uavobjecttemplate.java @@ -36,7 +36,6 @@ import java.util.ListIterator; import org.openpilot.uavtalk.UAVObjectManager; import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVDataObject; -import org.openpilot.uavtalk.UAVMetaObject; import org.openpilot.uavtalk.UAVObjectField; /** @@ -46,7 +45,7 @@ generated from $(XMLFILE) **/ public class $(NAME) extends UAVDataObject { - public $(NAME)() throws Exception { + public $(NAME)() { super(OBJID, ISSINGLEINST, ISSETTINGS, NAME); List fields = new ArrayList(); @@ -57,10 +56,9 @@ $(FIELDSINIT) int numBytes = 0; ListIterator li = fields.listIterator(); while(li.hasNext()) { - numBytes += li.next().getNumBytesElement(); + numBytes += li.next().getNumBytes(); } NUMBYTES = numBytes; - // Initialize object initializeFields(fields, ByteBuffer.allocate(NUMBYTES), NUMBYTES); diff --git a/ground/uavobjgenerator/generators/java/uavobjectgeneratorjava.cpp b/ground/uavobjgenerator/generators/java/uavobjectgeneratorjava.cpp index 7319b7767..b8d4b33d5 100644 --- a/ground/uavobjgenerator/generators/java/uavobjectgeneratorjava.cpp +++ b/ground/uavobjgenerator/generators/java/uavobjectgeneratorjava.cpp @@ -54,14 +54,14 @@ bool UAVObjectGeneratorJava::generate(UAVObjectParser* parser,QString templatepa ObjectInfo* info=parser->getObjectByIndex(objidx); process_object(info); - javaObjInit.append(" objMngr->registerObject( new " + info->name + "() );\n"); + javaObjInit.append("\t\t\tobjMngr.registerObject( new " + info->name + "() );\n"); objInc.append("#include \"" + info->namelc + ".h\"\n"); } // Write the gcs object inialization files javaInitTemplate.replace( QString("$(OBJINC)"), objInc); javaInitTemplate.replace( QString("$(OBJINIT)"), javaObjInit); - bool res = writeFileIfDiffrent( javaOutputPath.absolutePath() + "/uavobjectsinit.java", javaInitTemplate ); + bool res = writeFileIfDiffrent( javaOutputPath.absolutePath() + "/UAVObjectsInitialize.java", javaInitTemplate ); if (!res) { cout << "Error: Could not write output files" << endl; return false;