diff --git a/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java b/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java index a5fc6b7da..bb525a5e0 100644 --- a/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java +++ b/androidgcs/src/org/openpilot/uavtalk/UAVObjectField.java @@ -343,8 +343,14 @@ public class UAVObjectField { break; } case ENUM: - { - byte val = (byte) options.indexOf((String) data); + { + byte val; + try { + // Test if numeric constant passed in + val = ((Number) data).byteValue(); + } catch (Exception e) { + val = (byte) options.indexOf((String) data); + } //if(val < 0) throw new Exception("Enumerated value not found"); List l = (List) this.data; l.set(index, val); diff --git a/ground/uavobjgenerator/generators/java/uavobjectgeneratorjava.cpp b/ground/uavobjgenerator/generators/java/uavobjectgeneratorjava.cpp index b8d4b33d5..e942b238f 100644 --- a/ground/uavobjgenerator/generators/java/uavobjectgeneratorjava.cpp +++ b/ground/uavobjgenerator/generators/java/uavobjectgeneratorjava.cpp @@ -210,9 +210,9 @@ bool UAVObjectGeneratorJava::process_object(ObjectInfo* info) { if ( info->fields[n]->type == FIELDTYPE_ENUM ) { - initfields.append( QString("\t\tgetField(\"%1\").setValue(%2);\n") + initfields.append( QString("\t\tgetField(\"%1\").setValue(\"%2\");\n") .arg( info->fields[n]->name ) - .arg( info->fields[n]->options.indexOf( info->fields[n]->defaultValues[0] ) ) ); + .arg( info->fields[n]->defaultValues[0] ) ); } else if ( info->fields[n]->type == FIELDTYPE_FLOAT32 ) { @@ -233,10 +233,10 @@ bool UAVObjectGeneratorJava::process_object(ObjectInfo* info) for (int idx = 0; idx < info->fields[n]->numElements; ++idx) { if ( info->fields[n]->type == FIELDTYPE_ENUM ) { - initfields.append( QString("\t\tgetField(\"%1\").setValue(%3,%2);\n") + initfields.append( QString("\t\tgetField(\"%1\").setValue(\"%3\",%2);\n") .arg( info->fields[n]->name ) .arg( idx ) - .arg( info->fields[n]->options.indexOf( info->fields[n]->defaultValues[idx] ) ) ); + .arg( info->fields[n]->defaultValues[idx] ) ); } else if ( info->fields[n]->type == FIELDTYPE_FLOAT32 ) { initfields.append( QString("\t\tgetField(\"%1\").setValue(%3,%2);\n")