mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-12-01 09:24:10 +01:00
OP-301 Allow some special characters in uavobject enum options.
Now they can include special chars like '.' (dot), '-' (dash), '/' (slash), ' ' (space). All such chars will be removed from autogenerated identifiers ("S.Bus" -> SBUS), but kept intact in text strings (to be displayed by the GCS). This will not change any existing object IDs. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2592 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
c759253b77
commit
61d8c23a51
@ -121,7 +121,7 @@ bool UAVObjectGeneratorFlight::process_object(ObjectInfo* info)
|
||||
enums.append( s
|
||||
.arg( info->name.toUpper() )
|
||||
.arg( info->fields[n]->name.toUpper() )
|
||||
.arg( options[m].toUpper() )
|
||||
.arg( options[m].toUpper().replace(QRegExp(ENUM_SPECIAL_CHARS), "") )
|
||||
.arg(m) );
|
||||
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ bool UAVObjectGeneratorGCS::process_object(ObjectInfo* info)
|
||||
for (int m = 0; m < options.length(); ++m) {
|
||||
QString s = (m != (options.length()-1)) ? "%1_%2=%3, " : "%1_%2=%3";
|
||||
enums.append( s.arg( info->fields[n]->name.toUpper() )
|
||||
.arg( options[m].toUpper() )
|
||||
.arg( options[m].toUpper().replace(QRegExp(ENUM_SPECIAL_CHARS), "") )
|
||||
.arg(m) );
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,9 @@
|
||||
#include "../uavobjectparser.h"
|
||||
#include "generator_io.h"
|
||||
|
||||
// These special chars (regexp) will be removed from C/java identifiers
|
||||
#define ENUM_SPECIAL_CHARS "[\\.\\-\\s/]"
|
||||
|
||||
void replaceCommonTags(QString& out, ObjectInfo* info);
|
||||
void replaceCommonTags(QString& out);
|
||||
QString boolTo01String(bool value);
|
||||
|
@ -98,7 +98,7 @@ QString UAVObjectGeneratorJava::getFieldTypeStr(int type,bool as_obj) {
|
||||
QString UAVObjectGeneratorJava::formatJavaValue(FieldInfo* info,int idx) {
|
||||
switch(info->type) {
|
||||
case FIELDTYPE_ENUM:
|
||||
return (info->name.toUpper() + QString("_") + info->defaultValues[idx].toUpper());
|
||||
return (info->name.toUpper() + QString("_") + info->defaultValues[idx].toUpper().replace(QRegExp(ENUM_SPECIAL_CHARS), ""));
|
||||
case FIELDTYPE_FLOAT32:
|
||||
return QString("%1f").arg( info->defaultValues[idx].toFloat() );
|
||||
default:
|
||||
@ -208,7 +208,7 @@ bool UAVObjectGeneratorJava::process_object(ObjectInfo* info)
|
||||
type = getFieldTypeStr(act_field_info->type,false); // Determine type
|
||||
|
||||
for (int enum_n = 0; enum_n < act_field_info->options.length(); ++enum_n)
|
||||
fieldsinit.append(QString(" public final static byte %1 = %2;\n").arg(act_field_info->name.toUpper() + QString("_") + act_field_info->options[enum_n].toUpper()).arg(enum_n) );
|
||||
fieldsinit.append(QString(" public final static byte %1 = %2;\n").arg(act_field_info->name.toUpper() + QString("_") + act_field_info->options[enum_n].toUpper().replace(QRegExp(ENUM_SPECIAL_CHARS), "")).arg(enum_n) );
|
||||
|
||||
fieldsinit.append(QString(" private ") + type);
|
||||
|
||||
@ -233,7 +233,7 @@ bool UAVObjectGeneratorJava::process_object(ObjectInfo* info)
|
||||
fieldsinit.append(QString("= new ") + type + QString("[%1]").arg(info->fields[n]->numElements));
|
||||
}
|
||||
|
||||
fieldsinit.append(QString(";"));
|
||||
fieldsinit.append(QString(";\n"));
|
||||
|
||||
if (n!=0)
|
||||
serialize_code_inner.append(QString(","));
|
||||
|
Loading…
Reference in New Issue
Block a user