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

Removed various debugging outputs and exceptions for now (will add back in a

more principled manner later).  Also updated the auto generated code.
This commit is contained in:
James Cotton 2011-03-06 13:12:32 -06:00
parent b98bdb9be0
commit 72de0c622a
7 changed files with 37 additions and 63 deletions

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>

View File

@ -9,7 +9,7 @@ public abstract class UAVDataObject extends UAVObject {
* @param isSet * @param isSet
* @param name * @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); super(objID, isSingleInst, name);
mobj = null; mobj = null;
this.isSet = isSet; this.isSet = isSet;

View File

@ -105,10 +105,9 @@ public abstract class UAVObject {
* When unable to unpack a field * When unable to unpack a field
*/ */
public void initializeFields(List<UAVObjectField> fields, ByteBuffer data, public void initializeFields(List<UAVObjectField> fields, ByteBuffer data,
int numBytes) throws Exception { int numBytes) {
// TODO: QMutexLocker locker(mutex); // TODO: QMutexLocker locker(mutex);
this.numBytes = numBytes; this.numBytes = numBytes;
// this.data = data;
this.fields = fields; this.fields = fields;
// Initialize fields // Initialize fields
for (int n = 0; n < fields.size(); ++n) { for (int n = 0; n < fields.size(); ++n) {
@ -288,7 +287,7 @@ public abstract class UAVObject {
* @throws Exception * @throws Exception
* @returns The number of bytes copied * @returns The number of bytes copied
*/ */
public int unpack(ByteBuffer dataIn) throws Exception { public int unpack(ByteBuffer dataIn) {
if( dataIn == null ) if( dataIn == null )
return 0; return 0;

View File

@ -90,8 +90,8 @@ public class UAVObjectField {
* to the arm/uavtalk standard (little endian) * to the arm/uavtalk standard (little endian)
* @param dataOut * @param dataOut
* @return the number of bytes added * @return the number of bytes added
* @throws Exception */ **/
public int pack(ByteBuffer dataOut) throws Exception { public int pack(ByteBuffer dataOut) {
//QMutexLocker locker(obj->getMutex()); //QMutexLocker locker(obj->getMutex());
// Pack each element in output buffer // Pack each element in output buffer
dataOut.order(ByteOrder.LITTLE_ENDIAN); dataOut.order(ByteOrder.LITTLE_ENDIAN);
@ -147,7 +147,7 @@ public class UAVObjectField {
break; break;
case STRING: case STRING:
// TODO: Implement strings // TODO: Implement strings
throw new Exception("Strings not yet implemented"); throw new Error("Strings not yet implemented");
} }
// Done // Done
return getNumBytes(); return getNumBytes();
@ -358,13 +358,13 @@ public class UAVObjectField {
} }
} }
public double getDouble() throws Exception { return getDouble(0); }; public double getDouble() { return getDouble(0); };
public double getDouble(int index) throws Exception { public double getDouble(int index) {
return Double.valueOf((Double) getValue(index)); return Double.valueOf((Double) getValue(index));
} }
public void setDouble(double value) throws Exception { setDouble(value, 0); }; public void setDouble(double value) { setDouble(value, 0); };
public void setDouble(double value, int index) throws Exception { public void setDouble(double value, int index) {
setValue(value, index); setValue(value, index);
} }
@ -436,9 +436,7 @@ public class UAVObjectField {
String sout = new String(); String sout = new String();
sout += name + ": [ "; sout += name + ": [ ";
for (int n = 0; n < numElements; ++n) for (int n = 0; n < numElements; ++n)
{
sout += String.valueOf(n) + "(" + getValue(n) + ") "; sout += String.valueOf(n) + "(" + getValue(n) + ") ";
}
sout += "] " + units + "\n"; sout += "] " + units + "\n";
return sout; return sout;
@ -488,6 +486,18 @@ public class UAVObjectField {
((ArrayList<Long>) data).add((long) 0); ((ArrayList<Long>) data).add((long) 0);
} }
break; break;
case FLOAT32:
((ArrayList<Float>) data).clear();
for(int index = 0; index < numElements; ++index) {
((ArrayList<Float>) data).add((float) 0);
}
break;
case ENUM:
((ArrayList<Byte>) data).clear();
for(int index = 0; index < numElements; ++index) {
((ArrayList<Byte>) data).add((byte) 0);
}
break;
} }
} }
@ -546,8 +556,6 @@ public class UAVObjectField {
numBytesPerElement = 0; numBytesPerElement = 0;
} }
clear(); clear();
System.out.println(this);
} }
/** /**

View File

@ -26,50 +26,18 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 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.uavobjects.*;
import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVObjectManager;
import java.util.HashMap;
public class UAVObjects { public class UAVObjectsInitialize {
private static UAVObject[] uavobjects=null; public static void register(UAVObjectManager objMngr) {
private static HashMap id2obj; try {
public static void init() {
if (uavobjects==null) {
uavobjects=new UAVObject[] {
$(OBJINIT) $(OBJINIT)
}; } catch (Exception e) {
id2obj=new HashMap(); e.printStackTrace();
for (int i=0;i< uavobjects.length;i++) }
id2obj.put(uavobjects[i].getObjID(),i);
} }
}
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)
} }

View File

@ -36,7 +36,6 @@ import java.util.ListIterator;
import org.openpilot.uavtalk.UAVObjectManager; import org.openpilot.uavtalk.UAVObjectManager;
import org.openpilot.uavtalk.UAVObject; import org.openpilot.uavtalk.UAVObject;
import org.openpilot.uavtalk.UAVDataObject; import org.openpilot.uavtalk.UAVDataObject;
import org.openpilot.uavtalk.UAVMetaObject;
import org.openpilot.uavtalk.UAVObjectField; import org.openpilot.uavtalk.UAVObjectField;
/** /**
@ -46,7 +45,7 @@ generated from $(XMLFILE)
**/ **/
public class $(NAME) extends UAVDataObject { public class $(NAME) extends UAVDataObject {
public $(NAME)() throws Exception { public $(NAME)() {
super(OBJID, ISSINGLEINST, ISSETTINGS, NAME); super(OBJID, ISSINGLEINST, ISSETTINGS, NAME);
List<UAVObjectField> fields = new ArrayList<UAVObjectField>(); List<UAVObjectField> fields = new ArrayList<UAVObjectField>();
@ -57,11 +56,10 @@ $(FIELDSINIT)
int numBytes = 0; int numBytes = 0;
ListIterator<UAVObjectField> li = fields.listIterator(); ListIterator<UAVObjectField> li = fields.listIterator();
while(li.hasNext()) { while(li.hasNext()) {
numBytes += li.next().getNumBytesElement(); numBytes += li.next().getNumBytes();
} }
NUMBYTES = numBytes; NUMBYTES = numBytes;
// Initialize object // Initialize object
initializeFields(fields, ByteBuffer.allocate(NUMBYTES), NUMBYTES); initializeFields(fields, ByteBuffer.allocate(NUMBYTES), NUMBYTES);
// Set the default field values // Set the default field values

View File

@ -54,14 +54,14 @@ bool UAVObjectGeneratorJava::generate(UAVObjectParser* parser,QString templatepa
ObjectInfo* info=parser->getObjectByIndex(objidx); ObjectInfo* info=parser->getObjectByIndex(objidx);
process_object(info); 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"); objInc.append("#include \"" + info->namelc + ".h\"\n");
} }
// Write the gcs object inialization files // Write the gcs object inialization files
javaInitTemplate.replace( QString("$(OBJINC)"), objInc); javaInitTemplate.replace( QString("$(OBJINC)"), objInc);
javaInitTemplate.replace( QString("$(OBJINIT)"), javaObjInit); javaInitTemplate.replace( QString("$(OBJINIT)"), javaObjInit);
bool res = writeFileIfDiffrent( javaOutputPath.absolutePath() + "/uavobjectsinit.java", javaInitTemplate ); bool res = writeFileIfDiffrent( javaOutputPath.absolutePath() + "/UAVObjectsInitialize.java", javaInitTemplate );
if (!res) { if (!res) {
cout << "Error: Could not write output files" << endl; cout << "Error: Could not write output files" << endl;
return false; return false;