2011-01-13 03:26:00 +01:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file main.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief UAVObjectGenerator main.
|
|
|
|
*
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "generators/java/uavobjectgeneratorjava.h"
|
|
|
|
#include "generators/flight/uavobjectgeneratorflight.h"
|
|
|
|
#include "generators/gcs/uavobjectgeneratorgcs.h"
|
|
|
|
#include "generators/matlab/uavobjectgeneratormatlab.h"
|
|
|
|
#include "generators/python/uavobjectgeneratorpython.h"
|
|
|
|
|
2011-01-16 02:45:42 +01:00
|
|
|
#define RETURN_ERR_USAGE 1
|
|
|
|
#define RETURN_ERR_XML 2
|
|
|
|
#define RETURN_OK 0
|
2011-01-13 03:26:00 +01:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* print usage info
|
|
|
|
*/
|
|
|
|
void usage() {
|
2011-01-16 02:45:42 +01:00
|
|
|
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;
|
2011-01-13 03:26:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* inform user of invalid usage
|
|
|
|
*/
|
|
|
|
int usage_err() {
|
|
|
|
cout << "Invalid usage!" << endl;
|
|
|
|
usage();
|
2011-01-16 02:45:42 +01:00
|
|
|
return RETURN_ERR_USAGE;
|
2011-01-13 03:26:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* entrance
|
|
|
|
*/
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
QCoreApplication a(argc, argv);
|
|
|
|
|
|
|
|
cout << "- OpenPilot UAVObject Generator -" << endl;
|
|
|
|
|
|
|
|
QString basepath;
|
2011-01-22 18:38:15 +01:00
|
|
|
QString outputpath;
|
2011-01-13 03:26:00 +01:00
|
|
|
QStringList arguments_stringlist;
|
|
|
|
|
|
|
|
// process arguments
|
|
|
|
for (int argi=1;argi<argc;argi++)
|
|
|
|
arguments_stringlist << argv[argi];
|
|
|
|
|
2011-01-16 02:45:42 +01:00
|
|
|
if ((arguments_stringlist.removeAll("-h")>0)||(arguments_stringlist.removeAll("-h")>0)) {
|
|
|
|
usage();
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool verbose=(arguments_stringlist.removeAll("-v")>0);
|
2011-01-13 03:26:00 +01:00
|
|
|
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);
|
2011-01-16 02:45:42 +01:00
|
|
|
bool do_none=(arguments_stringlist.removeAll("-none")>0); //
|
2011-01-13 03:26:00 +01:00
|
|
|
|
|
|
|
bool do_all=((do_gcs||do_flight||do_java||do_python||do_matlab)==false);
|
|
|
|
|
|
|
|
if (arguments_stringlist.length() == 0) // if we have no param left - make up a basepath
|
|
|
|
basepath =QString("../../../../../");
|
|
|
|
else if (arguments_stringlist.length() == 1) // if we have one param left it is the basepath
|
|
|
|
basepath = arguments_stringlist.at(0);
|
|
|
|
else // too many arguments
|
|
|
|
return usage_err();
|
|
|
|
|
|
|
|
if (!basepath.endsWith("/"))
|
|
|
|
basepath.append("/"); // append a slash if it is not there
|
|
|
|
|
2011-01-22 18:38:15 +01:00
|
|
|
outputpath = basepath + QString("build/uavobject-synthetics/");
|
|
|
|
|
2011-01-13 03:26:00 +01:00
|
|
|
QDir xmlPath = QDir( basepath + QString("ground/src/shared/uavobjectdefinition"));
|
|
|
|
UAVObjectParser* parser = new UAVObjectParser();
|
|
|
|
|
|
|
|
QStringList filters=QStringList("*.xml");
|
|
|
|
|
|
|
|
xmlPath.setNameFilters(filters);
|
|
|
|
QFileInfoList xmlList = xmlPath.entryInfoList();
|
|
|
|
|
|
|
|
// Read in each XML file and parse object(s) in them
|
2011-01-17 08:51:53 +01:00
|
|
|
|
2011-01-13 03:26:00 +01:00
|
|
|
for (int n = 0; n < xmlList.length(); ++n) {
|
|
|
|
QFileInfo fileinfo = xmlList[n];
|
2011-01-17 08:51:53 +01:00
|
|
|
if (verbose)
|
|
|
|
cout << "Parsing XML file: " << fileinfo.fileName().toStdString() << endl;
|
2011-01-13 03:26:00 +01:00
|
|
|
QString filename = fileinfo.fileName();
|
|
|
|
QString xmlstr = readFile(fileinfo.absoluteFilePath());
|
|
|
|
|
|
|
|
QString res = parser->parseXML(xmlstr, filename);
|
|
|
|
|
|
|
|
if (!res.isNull()) {
|
2011-01-16 02:45:42 +01:00
|
|
|
cout << "Error parsing " << res.toStdString() << endl;
|
|
|
|
return RETURN_ERR_XML;
|
2011-01-13 03:26:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for duplicate object ID's
|
|
|
|
QList<quint32> objIDList;
|
2011-01-17 08:51:53 +01:00
|
|
|
int numBytesTotal=0;
|
2011-01-13 03:26:00 +01:00
|
|
|
for (int objidx = 0; objidx < parser->getNumObjects(); ++objidx) {
|
|
|
|
quint32 id = parser->getObjectID(objidx);
|
2011-01-17 08:51:53 +01:00
|
|
|
numBytesTotal+=parser->getNumBytes(objidx);
|
|
|
|
if (verbose)
|
|
|
|
cout << "Checking object " << parser->getObjectName(objidx).toStdString() << " (" << parser->getNumBytes(objidx) << " bytes)" << endl;
|
|
|
|
if ( objIDList.contains(id) || id == 0 ) {
|
2011-01-13 03:26:00 +01:00
|
|
|
cout << "Error: Object ID collision found in object " << parser->getObjectName(objidx).toStdString() << ", modify object name" << endl;
|
2011-01-16 02:45:42 +01:00
|
|
|
return RETURN_ERR_XML;
|
2011-01-13 03:26:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
objIDList.append(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// done parsing and checking
|
|
|
|
cout << "Done: processed " << xmlList.length() << " XML files and generated "
|
2011-01-17 08:51:53 +01:00
|
|
|
<< objIDList.length() << " objects with no ID collisions. Total size of the data fields is " << numBytesTotal << " bytes." << endl;
|
|
|
|
|
2011-01-16 02:45:42 +01:00
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
cout << "used units: " << parser->all_units.join(",").toStdString() << endl;
|
|
|
|
|
|
|
|
if (do_none)
|
|
|
|
return RETURN_OK;
|
|
|
|
|
2011-01-13 03:26:00 +01:00
|
|
|
// generate flight code if wanted
|
|
|
|
if (do_flight|do_all) {
|
2011-01-16 02:45:42 +01:00
|
|
|
cout << "generating flight code" << endl ;
|
2011-01-13 03:26:00 +01:00
|
|
|
UAVObjectGeneratorFlight flightgen;
|
2011-01-22 18:38:15 +01:00
|
|
|
flightgen.generate(parser,basepath,outputpath);
|
2011-01-13 03:26:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// generate gcs code if wanted
|
|
|
|
if (do_gcs|do_all) {
|
2011-01-16 02:45:42 +01:00
|
|
|
cout << "generating gcs code" << endl ;
|
2011-01-13 03:26:00 +01:00
|
|
|
UAVObjectGeneratorGCS gcsgen;
|
|
|
|
gcsgen.generate(parser,basepath);
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate java code if wanted
|
|
|
|
if (do_java|do_all) {
|
2011-01-16 02:45:42 +01:00
|
|
|
cout << "generating java code" << endl ;
|
2011-01-13 03:26:00 +01:00
|
|
|
UAVObjectGeneratorJava javagen;
|
|
|
|
javagen.generate(parser,basepath);
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate python code if wanted
|
|
|
|
if (do_python|do_all) {
|
2011-01-16 02:45:42 +01:00
|
|
|
cout << "generating python code" << endl ;
|
2011-01-13 03:26:00 +01:00
|
|
|
UAVObjectGeneratorPython pygen;
|
|
|
|
pygen.generate(parser,basepath);
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate matlab code if wanted
|
|
|
|
if (do_matlab|do_all) {
|
2011-01-16 02:45:42 +01:00
|
|
|
cout << "generating matlab code" << endl ;
|
2011-01-13 03:26:00 +01:00
|
|
|
UAVObjectGeneratorMatlab matlabgen;
|
|
|
|
matlabgen.generate(parser,basepath);
|
|
|
|
}
|
|
|
|
|
2011-01-16 02:45:42 +01:00
|
|
|
return RETURN_OK;
|
2011-01-13 03:26:00 +01:00
|
|
|
}
|
|
|
|
|