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

new command line options for generator; print all used units on verbose ; new makefile target to test xml files

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2438 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ligi 2011-01-16 01:45:42 +00:00 committed by ligi
parent 23f0cab0c3
commit 3d3023e9ad
4 changed files with 48 additions and 16 deletions

View File

@ -54,6 +54,7 @@ areyousureyoushouldberunningthis:
@echo " [GCS and UAVObjects]"
@echo " gcs - Build the Ground Control System application"
@echo " uavobjects - Generate source files from the UAVObject definition XML files"
@echo " uavobjects_test - parse xml-files - check for valid, duplicate ObjId's, ... "
@echo " uavobjects_gcs - Generate groundstation source files from the UAVObject definition XML files"
@echo " uavobjects_flight - Generate flight source files from the UAVObject definition XML files"
@echo
@ -222,6 +223,9 @@ uavobjects_gcs: build_dir uavobjgenerator
uavobjects_flight: build_dir uavobjgenerator
$(UAVOBJGENERATOR) -flight "$(ROOT_DIR)/"
uavobjects_test: build_dir uavobjgenerator
$(UAVOBJGENERATOR) -v -none "$(ROOT_DIR)/"
##############################
#
# Flight related components

View File

@ -35,8 +35,9 @@
#include "generators/matlab/uavobjectgeneratormatlab.h"
#include "generators/python/uavobjectgeneratorpython.h"
#define ERR_USAGE 1
#define ERR_XML 2
#define RETURN_ERR_USAGE 1
#define RETURN_ERR_XML 2
#define RETURN_OK 0
using namespace std;
@ -44,9 +45,19 @@ using namespace std;
* print usage info
*/
void usage() {
cout << "Usage: uavobjectgenerator [-gcs] [-flight] [-java] [-python] [-mathlab] [base_path]" << endl;
cout << " If no language is specified - all are build." << endl;
cout << " base_path - base path to gcs and flight directories (as in svn)." << endl;
cout << "Usage: uavobjectgenerator [-gcs] [-flight] [-java] [-python] [-mathlab] [-none] [-v] [base_path]" << endl;
cout << "Languages: "<< endl;
cout << "\t-gcs build grounstation code" << endl;
cout << "\t-flight build flight code" << endl;
cout << "\t-java build java code" << endl;
cout << "\t-python build python code" << endl;
cout << "\t-matlab build matlab code" << endl;
cout << "\tIf no language is specified ( and not -none ) -> all are build." << endl;
cout << "Misc: "<< endl;
cout << "\t-none build no language - just parse xml's" << endl;
cout << "\t-h this help" << endl;
cout << "\t-v verbose" << endl;
cout << " \tbase_path base path to gcs and flight directories (as in svn)." << endl;
}
/**
@ -55,7 +66,7 @@ void usage() {
int usage_err() {
cout << "Invalid usage!" << endl;
usage();
return ERR_USAGE;
return RETURN_ERR_USAGE;
}
/**
@ -74,11 +85,18 @@ int main(int argc, char *argv[])
for (int argi=1;argi<argc;argi++)
arguments_stringlist << argv[argi];
if ((arguments_stringlist.removeAll("-h")>0)||(arguments_stringlist.removeAll("-h")>0)) {
usage();
return RETURN_OK;
}
bool verbose=(arguments_stringlist.removeAll("-v")>0);
bool do_gcs=(arguments_stringlist.removeAll("-gcs")>0);
bool do_flight=(arguments_stringlist.removeAll("-flight")>0);
bool do_java=(arguments_stringlist.removeAll("-java")>0);
bool do_python=(arguments_stringlist.removeAll("-python")>0);
bool do_matlab=(arguments_stringlist.removeAll("-mathlab")>0);
bool do_none=(arguments_stringlist.removeAll("-none")>0); //
bool do_all=((do_gcs||do_flight||do_java||do_python||do_matlab)==false);
@ -103,15 +121,15 @@ int main(int argc, char *argv[])
// Read in each XML file and parse object(s) in them
for (int n = 0; n < xmlList.length(); ++n) {
QFileInfo fileinfo = xmlList[n];
std::cout << "Parsing XML file: " << fileinfo.fileName().toStdString() << std::endl;
cout << "Parsing XML file: " << fileinfo.fileName().toStdString() << endl;
QString filename = fileinfo.fileName();
QString xmlstr = readFile(fileinfo.absoluteFilePath());
QString res = parser->parseXML(xmlstr, filename);
if (!res.isNull()) {
std::cout << "Error parsing " << res.toStdString() << endl;
return ERR_XML;
cout << "Error parsing " << res.toStdString() << endl;
return RETURN_ERR_XML;
}
}
@ -122,7 +140,7 @@ int main(int argc, char *argv[])
if ( objIDList.contains(id) || id == 0 ) {
cout << "Error: Object ID collision found in object " << parser->getObjectName(objidx).toStdString() << ", modify object name" << endl;
return ERR_XML;
return RETURN_ERR_XML;
}
objIDList.append(id);
@ -132,41 +150,48 @@ int main(int argc, char *argv[])
cout << "Done: processed " << xmlList.length() << " XML files and generated "
<< objIDList.length() << " objects with no ID collisions." << endl;
if (verbose)
cout << "used units: " << parser->all_units.join(",").toStdString() << endl;
if (do_none)
return RETURN_OK;
// generate flight code if wanted
if (do_flight|do_all) {
std::cout << "generating flight code" << endl ;
cout << "generating flight code" << endl ;
UAVObjectGeneratorFlight flightgen;
flightgen.generate(parser,basepath);
}
// generate gcs code if wanted
if (do_gcs|do_all) {
std::cout << "generating gcs code" << endl ;
cout << "generating gcs code" << endl ;
UAVObjectGeneratorGCS gcsgen;
gcsgen.generate(parser,basepath);
}
// generate java code if wanted
if (do_java|do_all) {
std::cout << "generating java code" << endl ;
cout << "generating java code" << endl ;
UAVObjectGeneratorJava javagen;
javagen.generate(parser,basepath);
}
// generate python code if wanted
if (do_python|do_all) {
std::cout << "generating python code" << endl ;
cout << "generating python code" << endl ;
UAVObjectGeneratorPython pygen;
pygen.generate(parser,basepath);
}
// generate matlab code if wanted
if (do_matlab|do_all) {
std::cout << "generating matlab code" << endl ;
cout << "generating matlab code" << endl ;
UAVObjectGeneratorMatlab matlabgen;
matlabgen.generate(parser,basepath);
}
return 0;
return RETURN_OK;
}

View File

@ -228,6 +228,7 @@ QString UAVObjectParser::parseXML(QString& xml, QString& filename)
node = node.nextSibling();
}
all_units.removeDuplicates();
// Done, return null string
return QString();
}
@ -375,6 +376,7 @@ QString UAVObjectParser::processObjectFields(QDomNode& childNode, ObjectInfo* in
return QString("Object:field:units attribute is missing");
field->units = elemAttr.nodeValue();
all_units << field->units;
// Get type attribute
elemAttr = elemAttributes.namedItem("type");

View File

@ -111,6 +111,7 @@ public:
ObjectInfo* getObjectByIndex(int objIndex);
int getNumBytes(int objIndex);
QStringList all_units;
private:
QList<ObjectInfo*> objInfo;