diff --git a/mavlinkgen.pro b/mavlinkgen.pro deleted file mode 100644 index f12b2c871c901a5bb4517601e97eeac916f1448c..0000000000000000000000000000000000000000 --- a/mavlinkgen.pro +++ /dev/null @@ -1,48 +0,0 @@ - -# } -# Include general settings for MAVGround -# necessary as last include to override any non-acceptable settings -# done by the plugins above -QT += svg xml - -TEMPLATE = app -TARGET = mavlinkgen - -BASEDIR = . -BUILDDIR = build/mavlinkgen -LANGUAGE = C++ - -CONFIG += release -CONFIG -= debug - -OBJECTS_DIR = $$BUILDDIR/obj -MOC_DIR = $$BUILDDIR/moc -UI_HEADERS_DIR = src/ui/generated - -macx:DESTDIR = $$BASEDIR/bin/mac - -INCLUDEPATH += . \ - src \ - src/ui \ - src/comm \ - include/ui \ - src/ui/mavlink \ - src/standalone/mavlinkgen - -# Input -FORMS += src/ui/XMLCommProtocolWidget.ui - -HEADERS += src/standalone/mavlinkgen/MAVLinkGen.h \ - src/ui/XMLCommProtocolWidget.h \ - src/comm/MAVLinkXMLParser.h \ - src/ui/mavlink/DomItem.h \ - src/ui/mavlink/DomModel.h \ - src/ui/mavlink/QGCMAVLinkTextEdit.h -SOURCES += src/standalone/mavlinkgen/main.cc \ - src/standalone/mavlinkgen/MAVLinkGen.cc \ - src/ui/XMLCommProtocolWidget.cc \ - src/ui/mavlink/DomItem.cc \ - src/ui/mavlink/DomModel.cc \ - src/comm/MAVLinkXMLParser.cc \ - src/ui/mavlink/QGCMAVLinkTextEdit.cc -RESOURCES = mavground.qrc diff --git a/qgroundcontrol.pro b/qgroundcontrol.pro index 13f9f202e3ed778f5950290d9b120b7093cc6455..30c6143e656c609ec2e3ab69bc5a03744bc1443d 100644 --- a/qgroundcontrol.pro +++ b/qgroundcontrol.pro @@ -32,8 +32,13 @@ include(lib/nmea/nmea.pri) # of open-source software! # (We're not reusing any part of the OP GCS, just the map library) + +# Include MAVLink generator +include(src/apps/mavlinkgen.pri) + + # Try to get it from OP mainline, if this fails fall back to internal copies -exists(../openpilot/ground/openpilotgcs/src/libs) { +exists(../openpilot-xxxxxxx/ground/openpilotgcs/src/libs) { include(../openpilot/ground/openpilotgcs/src/libs/utils/utils_external.pri) include(../openpilot/ground/openpilotgcs/src/libs/opmapcontrol/opmapcontrol_external.pri) DEPENDPATH += \ diff --git a/src/comm/MAVLinkSyntaxHighlighter.cc b/src/comm/MAVLinkSyntaxHighlighter.cc deleted file mode 100644 index fa388557e15b8b0a4782bdfd5823cdf992cab44e..0000000000000000000000000000000000000000 --- a/src/comm/MAVLinkSyntaxHighlighter.cc +++ /dev/null @@ -1,46 +0,0 @@ -/*===================================================================== - -QGroundControl Open Source Ground Control Station - -(c) 2009, 2010 QGROUNDCONTROL PROJECT - -This file is part of the QGROUNDCONTROL project - - QGROUNDCONTROL 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. - - QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . - -======================================================================*/ - -#include "MAVLinkSyntaxHighlighter.h" - -MAVLinkSyntaxHighlighter::MAVLinkSyntaxHighlighter(QObject *parent) : - QSyntaxHighlighter(parent) -{ -} - - -void MAVLinkSyntaxHighlighter::highlightBlock(const QString &text) -{ - QTextCharFormat myClassFormat; - myClassFormat.setFontWeight(QFont::Bold); - myClassFormat.setForeground(Qt::darkMagenta); - QString pattern = "\"[A-Za-z0-9]+\""; - - QRegExp expression(pattern); - int index = text.indexOf(expression); - while (index >= 0) { - int length = expression.matchedLength(); - setFormat(index, length, myClassFormat); - index = text.indexOf(expression, index + length); - } -} diff --git a/src/comm/MAVLinkSyntaxHighlighter.h b/src/comm/MAVLinkSyntaxHighlighter.h deleted file mode 100644 index 2a0e8432e3edc562d158c6c2e6bb2eeae0fa053e..0000000000000000000000000000000000000000 --- a/src/comm/MAVLinkSyntaxHighlighter.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef MAVLINKSYNTAXHIGHLIGHTER_H -#define MAVLINKSYNTAXHIGHLIGHTER_H - -#include - -class MAVLinkSyntaxHighlighter : public QSyntaxHighlighter -{ - Q_OBJECT -public: - explicit MAVLinkSyntaxHighlighter(QObject *parent = 0); - -signals: - -public slots: - void highlightBlock(const QString &text); - -}; - -#endif // MAVLINKSYNTAXHIGHLIGHTER_H diff --git a/src/comm/MAVLinkXMLParser.cc b/src/comm/MAVLinkXMLParser.cc deleted file mode 100644 index e494e52830d70d3164d5a71892a22f65887d8ddb..0000000000000000000000000000000000000000 --- a/src/comm/MAVLinkXMLParser.cc +++ /dev/null @@ -1,651 +0,0 @@ -/*===================================================================== -======================================================================*/ - -/** - * @file - * @brief Implementation of class MAVLinkXMLParser - * @author Lorenz Meier - */ - -#include -#include -#include -#include -#include -#include -#include -#include "MAVLinkXMLParser.h" - -#include - -MAVLinkXMLParser::MAVLinkXMLParser(QDomDocument* document, QString outputDirectory, QObject* parent) : QObject(parent), - doc(document), - outputDirName(outputDirectory), - fileName("") -{ -} - -MAVLinkXMLParser::MAVLinkXMLParser(QString document, QString outputDirectory, QObject* parent) : QObject(parent) -{ - doc = new QDomDocument(); - QFile file(document); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - const QString instanceText(QString::fromUtf8(file.readAll())); - doc->setContent(instanceText); - } - fileName = document; - outputDirName = outputDirectory; -} - -MAVLinkXMLParser::~MAVLinkXMLParser() -{ -} - -/** - * Generate C-code (C-89 compliant) out of the XML protocol specs. - */ -bool MAVLinkXMLParser::generate() -{ - // Process result - bool success = true; - - // Only generate if output dir is correctly set - if (outputDirName == "") { - emit parseState(tr("ERROR: No output directory given.\nAbort.")); - return false; - } - - QString topLevelOutputDirName = outputDirName; - - // print out the element names of all elements that are direct children - // of the outermost element. - QDomElement docElem = doc->documentElement(); - QDomNode n = docElem;//.firstChild(); - QDomNode p = docElem; - - // Sanity check variables - QList* usedMessageIDs = new QList(); - QMap* usedMessageNames = new QMap(); - QMap* usedEnumNames = new QMap(); - - QList< QPair > cFiles; - QString lcmStructDefs = ""; - - QString pureFileName; - QString pureIncludeFileName; - - QFileInfo fInfo(this->fileName); - pureFileName = fInfo.baseName().split(".", QString::SkipEmptyParts).first(); - - // XML parsed and converted to C code. Now generating the files - outputDirName += QDir::separator() + pureFileName; - QDateTime now = QDateTime::currentDateTime().toUTC(); - QLocale loc(QLocale::English); - QString dateFormat = "dddd, MMMM d yyyy, hh:mm UTC"; - QString date = loc.toString(now, dateFormat); - QString includeLine = "#include \"%1\"\n"; - QString mainHeaderName = pureFileName + ".h"; - QString messagesDirName = ".";//"generated"; - QDir dir(outputDirName + "/" + messagesDirName); - - int mavlinkVersion = 0; - - // we need to gather the message lengths across multiple includes, - // which we can do via detecting recursion - static unsigned message_lengths[256]; - static int highest_message_id; - static int recursion_level; - - if (recursion_level == 0) { - highest_message_id = 0; - memset(message_lengths, 0, sizeof(message_lengths)); - } - - - // Start main header - QString mainHeader = QString("/** @file\n *\t@brief MAVLink comm protocol.\n *\t@see http://pixhawk.ethz.ch/software/mavlink\n *\t Generated on %1\n */\n#ifndef " + pureFileName.toUpper() + "_H\n#define " + pureFileName.toUpper() + "_H\n\n").arg(date); // The main header includes all messages - // Mark all code as C code - mainHeader += "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n"; - mainHeader += "\n#include \"../protocol.h\"\n"; - mainHeader += "\n#define MAVLINK_ENABLED_" + pureFileName.toUpper() + "\n\n"; - - QString enums; - - - // Run through root children - while(!n.isNull()) { - // Each child is a message - QDomElement e = n.toElement(); // try to convert the node to an element. - if(!e.isNull()) { - if (e.tagName() == "mavlink") { - p = n; - n = n.firstChild(); - while (!n.isNull()) { - e = n.toElement(); - if (!e.isNull()) { - // Handle all include tags - if (e.tagName() == "include") { - QString incFileName = e.text(); - // Load file - //QDomDocument includeDoc = QDomDocument(); - - // Prepend file path if it is a relative path and - // make it relative to opened file - QFileInfo fInfo(incFileName); - - QString incFilePath; - if (fInfo.isRelative()) { - QFileInfo rInfo(this->fileName); - incFilePath = rInfo.absoluteDir().canonicalPath() + "/" + incFileName; - pureIncludeFileName = fInfo.baseName().split(".", QString::SkipEmptyParts).first(); - } - - QFile file(incFilePath); - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - emit parseState(QString("Included messages from file: %1").arg(incFileName)); - // NEW MODE: CREATE INDIVIDUAL FOLDERS - // Create new output directory, parse included XML and generate C-code - MAVLinkXMLParser includeParser(incFilePath, topLevelOutputDirName, this); - connect(&includeParser, SIGNAL(parseState(QString)), this, SIGNAL(parseState(QString))); - // Generate and write - recursion_level++; - // Abort if inclusion fails - if (!includeParser.generate()) return false; - recursion_level--; - mainHeader += "\n#include \"../" + pureIncludeFileName + "/" + pureIncludeFileName + ".h\"\n"; - - - // OLD MODE: MERGE BOTH FILES - // const QString instanceText(QString::fromUtf8(file.readAll())); - // includeDoc.setContent(instanceText); - // // Get all messages - // QDomNode in = includeDoc.documentElement().firstChild(); - // QDomElement ie = in.toElement(); - // if (!ie.isNull()) - // { - // if (ie.tagName() == "messages" || ie.tagName() == "include") - // { - // QDomNode ref = n.parentNode().insertAfter(in, n); - // if (ref.isNull()) - // { - // emit parseState(QString("ERROR: Inclusion failed: XML syntax error in file %1. Wrong/misspelled XML?\nAbort.").arg(fileName)); - // return false; - // } - // } - // } - - emit parseState(QString("End of inclusion from file: %1").arg(incFileName)); - } else { - // Include file could not be opened - emit parseState(QString("ERROR: Failed including file: %1, file is not readable. Wrong/misspelled filename?\nAbort.").arg(fileName)); - return false; - } - - } - // Handle all enum tags - else if (e.tagName() == "version") { - //QString fieldType = e.attribute("type", ""); - //QString fieldName = e.attribute("name", ""); - QString fieldText = e.text(); - - // Check if version has been previously set - if (mavlinkVersion != 0) { - emit parseState(QString("ERROR: Protocol version tag set twice, please use it only once. First version was %1, second version is %2.\nAbort.").arg(mavlinkVersion).arg(fieldText)); - return false; - } - - bool ok; - int version = fieldText.toInt(&ok); - if (ok && (version > 0) && (version < 256)) { - // Set MAVLink version - mavlinkVersion = version; - } else { - emit parseState(QString("ERROR: Reading version string failed: %1, string is not an integer number between 1 and 255.\nAbort.").arg(fieldText)); - return false; - } - } - // Handle all enum tags - else if (e.tagName() == "enums") { - // One down into the enums list - p = n; - n = n.firstChild(); - while (!n.isNull()) { - e = n.toElement(); - - QString currEnum; - QString currEnumEnd; - // Comment - QString comment; - - if(!e.isNull() && e.tagName() == "enum") { - // Get enum name - QString enumName = e.attribute("name", "").toLower(); - if (enumName.size() == 0) { - emit parseState(tr("ERROR: Missing required name=\"\" attribute for tag %2 near line %1\nAbort.").arg(QString::number(e.lineNumber()), e.tagName())); - return false; - } else { - // Sanity check: Accept only enum names not used previously - if (usedEnumNames->contains(enumName)) { - emit parseState(tr("ERROR: Enum name %1 used twice, second occurence near line %2 of file %3\nAbort.").arg(enumName, QString::number(e.lineNumber()), fileName)); - return false; - } else { - usedEnumNames->insert(enumName, QString::number(e.lineNumber())); - } - - // Everything sane, starting with enum content - currEnum = "enum " + enumName.toUpper() + "\n{\n"; - currEnumEnd = QString("\t%1_ENUM_END\n};\n\n").arg(enumName.toUpper()); - - int nextEnumValue = 0; - - // Get the enum fields - QDomNode f = e.firstChild(); - while (!f.isNull()) { - QDomElement e2 = f.toElement(); - if (!e2.isNull() && e2.tagName() == "entry") { - QString fieldValue = e2.attribute("value", ""); - - // If value was given, use it, if not, use the enum iterator - // value. The iterator value gets reset by manual values - - QString fieldName = e2.attribute("name", ""); - if (fieldValue.length() == 0) { - fieldValue = QString::number(nextEnumValue); - nextEnumValue++; - } else { - bool ok; - nextEnumValue = fieldValue.toInt(&ok) + 1; - if (!ok) { - emit parseState(tr("ERROR: Enum entry %1 has not a valid number (%2) in the value field.\nAbort.").arg(fieldName, fieldValue)); - return false; - } - } - - // Add comment of field if there is one - QString fieldComment; - if (e2.text().length() > 0) - { - QString sep(" | "); - QDomNode pp = e2.firstChild(); - while (!pp.isNull()) { - QDomElement pp2 = pp.toElement(); - if (pp2.isText() || pp2.isCDATASection()) - { - fieldComment += pp2.nodeValue() + sep; - } - else if (pp2.isElement()) - { - fieldComment += pp2.text() + sep; - pp = pp.nextSibling(); - } - } - fieldComment = fieldComment.replace("\n", " "); - fieldComment = " /* " + fieldComment.simplified() + " */"; - } - currEnum += "\t" + fieldName.toUpper() + "=" + fieldValue + "," + fieldComment + "\n"; - } - else if(!e2.isNull() && e2.tagName() == "description") - { - comment = " " + e2.text().replace("\n", " ") + comment; - } - f = f.nextSibling(); - } - } - // Add the last parsed enum - // Remove the last comma, as the last value has none - // ENUM END MARKER IS LAST ENTRY, COMMA REMOVAL NOT NEEDED - //int commaPosition = currEnum.lastIndexOf(","); - //currEnum.remove(commaPosition, 1); - - enums += "/** @brief " + comment + " */\n" + currEnum + currEnumEnd; - } // Element is non-zero and element name is - n = n.nextSibling(); - } // While through - // One up, back into the structure - n = p; - } - - // Handle all message tags - else if (e.tagName() == "messages") { - p = n; - n = n.firstChild(); - while (!n.isNull()) { - e = n.toElement(); - if(!e.isNull()) { - //if (e.isNull()) continue; - // Get message name - QString messageName = e.attribute("name", "").toLower(); - if (messageName.size() == 0) { - emit parseState(tr("ERROR: Missing required name=\"\" attribute for tag %2 near line %1\nAbort.").arg(QString::number(e.lineNumber()), e.tagName())); - return false; - } else { - // Get message id - bool ok; - int messageId = e.attribute("id", "-1").toInt(&ok, 10); - emit parseState(tr("Compiling message %1 \t(#%3) \tnear line %2").arg(messageName, QString::number(n.lineNumber()), QString::number(messageId))); - - // Sanity check: Accept only message IDs not used previously - if (usedMessageIDs->contains(messageId)) { - emit parseState(tr("ERROR: Message ID %1 used twice, second occurence near line %2 of file %3\nAbort.").arg(QString::number(messageId), QString::number(e.lineNumber()), fileName)); - return false; - } else { - usedMessageIDs->append(messageId); - } - - // Sanity check: Accept only message names not used previously - if (usedMessageNames->contains(messageName)) { - emit parseState(tr("ERROR: Message name %1 used twice, second occurence near line %2 of file %3\nAbort.").arg(messageName, QString::number(e.lineNumber()), fileName)); - return false; - } else { - usedMessageNames->insert(messageName, QString::number(e.lineNumber())); - } - - QString channelType("mavlink_channel_t"); - QString messageType("mavlink_message_t"); - - // Build up function call - QString commentContainer("/**\n * @brief Pack a %1 message\n * @param system_id ID of this system\n * @param component_id ID of this component (e.g. 200 for IMU)\n * @param msg The MAVLink message to compress the data into\n *\n%2 * @return length of the message in bytes (excluding serial stream start sign)\n */\n"); - QString commentPackChanContainer("/**\n * @brief Pack a %1 message\n * @param system_id ID of this system\n * @param component_id ID of this component (e.g. 200 for IMU)\n * @param chan The MAVLink channel this message was sent over\n * @param msg The MAVLink message to compress the data into\n%2 * @return length of the message in bytes (excluding serial stream start sign)\n */\n"); - QString commentSendContainer("/**\n * @brief Send a %1 message\n * @param chan MAVLink channel to send the message\n *\n%2 */\n"); - QString commentEncodeContainer("/**\n * @brief Encode a %1 struct into a message\n *\n * @param system_id ID of this system\n * @param component_id ID of this component (e.g. 200 for IMU)\n * @param msg The MAVLink message to compress the data into\n * @param %1 C-struct to read the message contents from\n */\n"); - QString commentDecodeContainer("/**\n * @brief Decode a %1 message into a struct\n *\n * @param msg The message to decode\n * @param %1 C-struct to decode the message contents into\n */\n"); - QString commentEntry(" * @param %1 %2\n"); - QString idDefine = QString("#define MAVLINK_MSG_ID_%1 %2").arg(messageName.toUpper(), QString::number(messageId)); - QString arrayDefines; - QString cStructName = QString("mavlink_%1_t").arg(messageName); - QString cStruct("typedef struct __%1 \n{\n%2\n} %1;"); - QString cStructLines; - QString encode("static inline uint16_t mavlink_msg_%1_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const %2* %1)\n{\n\treturn mavlink_msg_%1_pack(%3);\n}\n"); - - QString decode("static inline void mavlink_msg_%1_decode(const mavlink_message_t* msg, %2* %1)\n{\n%3}\n"); - QString pack("static inline uint16_t mavlink_msg_%1_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg%2)\n{\n\tuint16_t i = 0;\n\tmsg->msgid = MAVLINK_MSG_ID_%3;\n\n%4\n\treturn mavlink_finalize_message(msg, system_id, component_id, i);\n}\n\n"); - QString packChan("static inline uint16_t mavlink_msg_%1_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg%2)\n{\n\tuint16_t i = 0;\n\tmsg->msgid = MAVLINK_MSG_ID_%3;\n\n%4\n\treturn mavlink_finalize_message_chan(msg, system_id, component_id, chan, i);\n}\n\n"); - QString compactSend("#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS\n\nstatic inline void mavlink_msg_%3_send(%1 chan%5)\n{\n\t%2 msg;\n\tmavlink_msg_%3_pack_chan(mavlink_system.sysid, mavlink_system.compid, chan, &msg%4);\n\tmavlink_send_uart(chan, &msg);\n}\n\n#endif"); - //QString compactStructSend = "#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS\n\nstatic inline void mavlink_msg_%3_struct_send(%1 chan%5)\n{\n\t%2 msg;\n\tmavlink_msg_%3_encode(mavlink_system.sysid, mavlink_system.compid, &msg%4);\n\tmavlink_send_uart(chan, &msg);\n}\n\n#endif"; - QString unpacking; - QString prepends; - QString packParameters; - QString packArguments("system_id, component_id, msg"); - QString packLines; - QString decodeLines; - QString sendArguments; - QString commentLines; - unsigned message_length = 0; - - - // Get the message fields - QDomNode f = e.firstChild(); - while (!f.isNull()) { - QDomElement e2 = f.toElement(); - if (!e2.isNull() && e2.tagName() == "field") { - QString fieldType = e2.attribute("type", ""); - QString fieldName = e2.attribute("name", ""); - QString fieldText = e2.text(); - - QString unpackingCode; - QString unpackingComment = QString("/**\n * @brief Get field %1 from %2 message\n *\n * @return %3\n */\n").arg(fieldName, messageName, fieldText); - - // Send arguments do not work for the version field - if (!fieldType.contains("uint8_t_mavlink_version")) { - // Send arguments are the same for integral types and arrays - sendArguments += ", " + fieldName; - commentLines += commentEntry.arg(fieldName, fieldText.replace("\n", " ")); - } - - // MAVLink version field - // this is a special field always containing the version define - if (fieldType.contains("uint8_t_mavlink_version")) { - // Add field to C structure - cStructLines += QString("\t%1 %2; ///< %3\n").arg("uint8_t", fieldName, fieldText); - // Add pack line to message_xx_pack function - packLines += QString("\ti += put_uint8_t_by_index(%1, i, msg->payload); // %2\n").arg(mavlinkVersion).arg(fieldText); - // Add decode function for this type - decodeLines += QString("\t%1->%2 = mavlink_msg_%1_get_%2(msg);\n").arg(messageName, fieldName); - } - - // Array handling is different from simple types - else if (fieldType.startsWith("array")) { - int arrayLength = QString(fieldType.split("[").at(1).split("]").first()).toInt(); - QString arrayType = fieldType.split("[").first(); - packParameters += QString(", const ") + QString("int8_t*") + " " + fieldName; - packArguments += ", " + messageName + "->" + fieldName; - - // Add field to C structure - cStructLines += QString("\t%1 %2[%3]; ///< %4\n").arg("int8_t", fieldName, QString::number(arrayLength), fieldText); - // Add pack line to message_xx_pack function - packLines += QString("\ti += put_%1_by_index(%2, %3, i, msg->payload); // %4\n").arg(arrayType, fieldName, QString::number(arrayLength), fieldText); - // Add decode function for this type - decodeLines += QString("\tmavlink_msg_%1_get_%2(msg, %1->%2);\n").arg(messageName, fieldName); - arrayDefines += QString("#define MAVLINK_MSG_%1_FIELD_%2_LEN %3\n").arg(messageName.toUpper(), fieldName.toUpper(), QString::number(arrayLength)); - } else if (fieldType.startsWith("string")) { - int arrayLength = QString(fieldType.split("[").at(1).split("]").first()).toInt(); - QString arrayType = fieldType.split("[").first(); - packParameters += QString(", const ") + QString("char*") + " " + fieldName; - packArguments += ", " + messageName + "->" + fieldName; - - // Add field to C structure - cStructLines += QString("\t%1 %2[%3]; ///< %4\n").arg("char", fieldName, QString::number(arrayLength), fieldText); - // Add pack line to message_xx_pack function - packLines += QString("\ti += put_%1_by_index(%2, %3, i, msg->payload); // %4\n").arg(arrayType, fieldName, QString::number(arrayLength), e2.text()); - // Add decode function for this type - decodeLines += QString("\tmavlink_msg_%1_get_%2(msg, %1->%2);\n").arg(messageName, fieldName); - arrayDefines += QString("#define MAVLINK_MSG_%1_FIELD_%2_LEN %3\n").arg(messageName.toUpper(), fieldName.toUpper(), QString::number(arrayLength)); - } - // Expand array handling to all valid mavlink data types - else if(fieldType.contains('[') && fieldType.contains(']')) { - int arrayLength = QString(fieldType.split("[").at(1).split("]").first()).toInt(); - QString arrayType = fieldType.split("[").first(); - packParameters += QString(", const ") + arrayType + "* " + fieldName; - packArguments += ", " + messageName + "->" + fieldName; - - // Add field to C structure - cStructLines += QString("\t%1 %2[%3]; ///< %4\n").arg(arrayType, fieldName, QString::number(arrayLength), fieldText); - // Add pack line to message_xx_pack function - packLines += QString("\ti += put_array_by_index((const int8_t*)%1, sizeof(%2)*%3, i, msg->payload); // %4\n").arg(fieldName, arrayType, QString::number(arrayLength), fieldText); - // Add decode function for this type - decodeLines += QString("\tmavlink_msg_%1_get_%2(msg, %1->%2);\n").arg(messageName, fieldName); - arrayDefines += QString("#define MAVLINK_MSG_%1_FIELD_%2_LEN %3\n").arg(messageName.toUpper(), fieldName.toUpper(), QString::number(arrayLength)); - - unpackingCode = QString("\n\tmemcpy(r_data, msg->payload%1, sizeof(%2)*%3);\n\treturn sizeof(%2)*%3;").arg(prepends, arrayType, QString::number(arrayLength)); - - unpacking += unpackingComment + QString("static inline uint16_t mavlink_msg_%1_get_%2(const mavlink_message_t* msg, %3* r_data)\n{\n%4\n}\n\n").arg(messageName, fieldName, arrayType, unpackingCode); - // decodeLines += ""; - prepends += QString("+sizeof(%1)*%2").arg(arrayType, QString::number(arrayLength)); - - } else - // Handle simple types like integers and floats - { - packParameters += ", " + fieldType + " " + fieldName; - packArguments += ", " + messageName + "->" + fieldName; - - // Add field to C structure - cStructLines += QString("\t%1 %2; ///< %3\n").arg(fieldType, fieldName, fieldText); - // Add pack line to message_xx_pack function - packLines += QString("\ti += put_%1_by_index(%2, i, msg->payload); // %3\n").arg(fieldType, fieldName, e2.text()); - // Add decode function for this type - decodeLines += QString("\t%1->%2 = mavlink_msg_%1_get_%2(msg);\n").arg(messageName, fieldName); - } - - - // message length calculation - unsigned element_multiplier = 1; - unsigned element_length = 0; - const struct { - const char *prefix; - unsigned length; - } length_map[] = { - { "array", 1 }, - { "char", 1 }, - { "uint8", 1 }, - { "int8", 1 }, - { "uint16", 2 }, - { "int16", 2 }, - { "uint32", 4 }, - { "int32", 4 }, - { "uint64", 8 }, - { "int64", 8 }, - { "float", 4 }, - { "double", 8 }, - }; - if (fieldType.contains("[")) { - element_multiplier = fieldType.split("[").at(1).split("]").first().toInt(); - } - for (unsigned i=0; iERROR: Unable to calculate length for %2 near line %1\nAbort.").arg(QString::number(e.lineNumber()), fieldType)); - } - message_length += element_length; - - // - // QString unpackingCode; - - if (fieldType == "uint8_t_mavlink_version") { - unpackingCode = QString("\treturn (%1)(msg->payload%2)[0];").arg("uint8_t", prepends); - } else if (fieldType == "uint8_t" || fieldType == "int8_t") { - unpackingCode = QString("\treturn (%1)(msg->payload%2)[0];").arg(fieldType, prepends); - } else if (fieldType == "uint16_t" || fieldType == "int16_t") { - unpackingCode = QString("\tgeneric_16bit r;\n\tr.b[1] = (msg->payload%1)[0];\n\tr.b[0] = (msg->payload%1)[1];\n\treturn (%2)r.s;").arg(prepends).arg(fieldType); - } else if (fieldType == "uint32_t" || fieldType == "int32_t") { - unpackingCode = QString("\tgeneric_32bit r;\n\tr.b[3] = (msg->payload%1)[0];\n\tr.b[2] = (msg->payload%1)[1];\n\tr.b[1] = (msg->payload%1)[2];\n\tr.b[0] = (msg->payload%1)[3];\n\treturn (%2)r.i;").arg(prepends).arg(fieldType); - } else if (fieldType == "float") { - unpackingCode = QString("\tgeneric_32bit r;\n\tr.b[3] = (msg->payload%1)[0];\n\tr.b[2] = (msg->payload%1)[1];\n\tr.b[1] = (msg->payload%1)[2];\n\tr.b[0] = (msg->payload%1)[3];\n\treturn (%2)r.f;").arg(prepends).arg(fieldType); - } else if (fieldType == "uint64_t" || fieldType == "int64_t") { - unpackingCode = QString("\tgeneric_64bit r;\n\tr.b[7] = (msg->payload%1)[0];\n\tr.b[6] = (msg->payload%1)[1];\n\tr.b[5] = (msg->payload%1)[2];\n\tr.b[4] = (msg->payload%1)[3];\n\tr.b[3] = (msg->payload%1)[4];\n\tr.b[2] = (msg->payload%1)[5];\n\tr.b[1] = (msg->payload%1)[6];\n\tr.b[0] = (msg->payload%1)[7];\n\treturn (%2)r.ll;").arg(prepends).arg(fieldType); - } else if (fieldType.startsWith("array")) { - // fieldtype formatis string[n] where n is the number of bytes, extract n from field type string - unpackingCode = QString("\n\tmemcpy(r_data, msg->payload%1, %2);\n\treturn %2;").arg(prepends, fieldType.split("[").at(1).split("]").first()); - } else if (fieldType.startsWith("string")) { - // fieldtype formatis string[n] where n is the number of bytes, extract n from field type string - unpackingCode = QString("\n\tstrcpy(r_data, msg->payload%1, %2);\n\treturn %2;").arg(prepends, fieldType.split("[").at(1).split("]").first()); - } - - - // Generate the message decoding function - if (fieldType.contains("uint8_t_mavlink_version")) { - unpacking += unpackingComment + QString("static inline %1 mavlink_msg_%2_get_%3(const mavlink_message_t* msg)\n{\n%4\n}\n\n").arg("uint8_t", messageName, fieldName, unpackingCode); - decodeLines += ""; - prepends += "+sizeof(uint8_t)"; - } - // Array handling is different from simple types - else if (fieldType.startsWith("array")) { - unpacking += unpackingComment + QString("static inline uint16_t mavlink_msg_%1_get_%2(const mavlink_message_t* msg, int8_t* r_data)\n{\n%4\n}\n\n").arg(messageName, fieldName, unpackingCode); - decodeLines += ""; - QString arrayLength = QString(fieldType.split("[").at(1).split("]").first()); - prepends += "+" + arrayLength; - } else if (fieldType.startsWith("string")) { - unpacking += unpackingComment + QString("static inline uint16_t mavlink_msg_%1_get_%2(const mavlink_message_t* msg, char* r_data)\n{\n%4\n}\n\n").arg(messageName, fieldName, unpackingCode); - decodeLines += ""; - QString arrayLength = QString(fieldType.split("[").at(1).split("]").first()); - prepends += "+" + arrayLength; - } else if(fieldType.contains('[') && fieldType.contains(']')) { - // prevent this case from being caught in the following else - } else { - unpacking += unpackingComment + QString("static inline %1 mavlink_msg_%2_get_%3(const mavlink_message_t* msg)\n{\n%4\n}\n\n").arg(fieldType, messageName, fieldName, unpackingCode); - decodeLines += ""; - prepends += "+sizeof(" + e2.attribute("type", "void") + ")"; - } - } - f = f.nextSibling(); - } - - if (messageId > highest_message_id) { - highest_message_id = messageId; - } - message_lengths[messageId] = message_length; - - cStruct = cStruct.arg(cStructName, cStructLines); - lcmStructDefs.append("\n").append(cStruct).append("\n"); - pack = pack.arg(messageName, packParameters, messageName.toUpper(), packLines); - packChan = packChan.arg(messageName, packParameters, messageName.toUpper(), packLines); - encode = encode.arg(messageName).arg(cStructName).arg(packArguments); - decode = decode.arg(messageName).arg(cStructName).arg(decodeLines); - compactSend = compactSend.arg(channelType, messageType, messageName, sendArguments, packParameters); - QString cFile = "// MESSAGE " + messageName.toUpper() + " PACKING\n\n" + idDefine + "\n\n" + cStruct + "\n\n" + arrayDefines + "\n\n" + commentContainer.arg(messageName.toLower(), commentLines) + pack + commentPackChanContainer.arg(messageName.toLower(), commentLines) + packChan + commentEncodeContainer.arg(messageName.toLower()) + encode + "\n" + commentSendContainer.arg(messageName.toLower(), commentLines) + compactSend + "\n" + "// MESSAGE " + messageName.toUpper() + " UNPACKING\n\n" + unpacking + commentDecodeContainer.arg(messageName.toLower()) + decode; - cFiles.append(qMakePair(QString("mavlink_msg_%1.h").arg(messageName), cFile)); - } // Check if tag = message - } // Check if e = NULL - n = n.nextSibling(); - } // While through - n = p; - - } // Check if tag = messages - } // Check if e = NULL - n = n.nextSibling(); - } // While through include and messages - // One up - current node = parent - n = p; - - } // Check if tag = mavlink - } // Check if e = NULL - n = n.nextSibling(); - } // While through root children - - // Add version to main header - - mainHeader += "// MAVLINK VERSION\n\n"; - mainHeader += QString("#ifndef MAVLINK_VERSION\n#define MAVLINK_VERSION %1\n#endif\n\n").arg(mavlinkVersion); - mainHeader += QString("#if (MAVLINK_VERSION == 0)\n#undef MAVLINK_VERSION\n#define MAVLINK_VERSION %1\n#endif\n\n").arg(mavlinkVersion); - - // Add enums to main header - - mainHeader += "// ENUM DEFINITIONS\n\n"; - mainHeader += enums; - mainHeader += "\n"; - - mainHeader += "// MESSAGE DEFINITIONS\n\n"; - // Create directory if it doesn't exist, report result in success - if (!dir.exists()) success = success && dir.mkpath(outputDirName + "/" + messagesDirName); - for (int i = 0; i < cFiles.size(); i++) { - QFile rawFile(dir.filePath(cFiles.at(i).first)); - bool ok = rawFile.open(QIODevice::WriteOnly | QIODevice::Text); - success = success && ok; - rawFile.write(cFiles.at(i).second.toLatin1()); - rawFile.close(); - mainHeader += includeLine.arg(messagesDirName + "/" + cFiles.at(i).first); - } - - mainHeader += "\n\n// MESSAGE LENGTHS\n\n"; - mainHeader += "#undef MAVLINK_MESSAGE_LENGTHS\n"; - mainHeader += "#define MAVLINK_MESSAGE_LENGTHS { "; - for (int i=0; i - -This file is part of the QGROUNDCONTROL project - - QGROUNDCONTROL 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. - - QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . - -======================================================================*/ - -/** - * @file - * @brief Definition of class MAVLinkXMLParser - * @author Lorenz Meier - */ - -#ifndef MAVLINKXMLPARSER_H -#define MAVLINKXMLPARSER_H - -#include -#include -#include - -/** - * @brief MAVLink micro air vehicle protocol generator - * - * MAVLink is a generic communication protocol for micro air vehicles. - * for more information, please see the official website. - * @ref http://pixhawk.ethz.ch/software/mavlink/ - **/ -class MAVLinkXMLParser : public QObject -{ - Q_OBJECT -public: - MAVLinkXMLParser(QDomDocument* document, QString outputDirectory, QObject* parent=0); - MAVLinkXMLParser(QString document, QString outputDirectory, QObject* parent=0); - ~MAVLinkXMLParser(); - -public slots: - /** @brief Parse XML and generate C files */ - bool generate(); - -signals: - /** @brief Status message on the parsing */ - void parseState(QString message); - -protected: - QDomDocument* doc; - QString outputDirName; - QString fileName; -}; - -#endif // MAVLINKXMLPARSER_H diff --git a/src/standalone/mavlinkgen/MAVLinkGen.cc b/src/standalone/mavlinkgen/MAVLinkGen.cc deleted file mode 100644 index 5e17404df760a451ad365796563b76bea9a6ea5c..0000000000000000000000000000000000000000 --- a/src/standalone/mavlinkgen/MAVLinkGen.cc +++ /dev/null @@ -1,94 +0,0 @@ -/*===================================================================== - -PIXHAWK Micro Air Vehicle Flying Robotics Toolkit - -(c) 2009, 2010 PIXHAWK PROJECT - -This file is part of the PIXHAWK project - - PIXHAWK 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. - - PIXHAWK 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 PIXHAWK. If not, see . - -======================================================================*/ - -/** - * @file - * @brief Implementation of class MAVLinkGen - * - * @author Lorenz Meier - * - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "MAVLinkGen.h" -#include "XMLCommProtocolWidget.h" - - -/** - * @brief Constructor for the main application. - * - * This constructor initializes and starts the whole application. It takes standard - * command-line parameters - * - * @param argc The number of command-line parameters - * @param argv The string array of parameters - **/ - -MAVLinkGen::MAVLinkGen(int &argc, char* argv[]) : QApplication(argc, argv) -{ - this->setApplicationName("MAVLink Generator"); - this->setApplicationVersion("v. 1.0.0 (Beta)"); - this->setOrganizationName(QLatin1String("QGroundControl")); - this->setOrganizationDomain("http://qgroundcontrol.org"); - - QSettings::setDefaultFormat(QSettings::IniFormat); - // Exit main application when last window is closed - connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit())); - - // Set application font - QFontDatabase fontDatabase = QFontDatabase(); - const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app - const QString fontFamilyName = "Bitstream Vera Sans"; - if(!QFile::exists(fontFileName)) printf("ERROR! font file: %s DOES NOT EXIST!\n", fontFileName.toStdString().c_str()); - fontDatabase.addApplicationFont(fontFileName); - setFont(fontDatabase.font(fontFamilyName, "Roman", 12)); - - // Create main window - QMainWindow* window = new QMainWindow(); - window->setCentralWidget(new XMLCommProtocolWidget(window)); - window->setWindowTitle(applicationName() + " " + applicationVersion()); -// window->setBaseSize(qMin(1024, static_cast(QApplication::desktop()->width()*0.8f)), qMin(900, static_cast(QApplication::desktop()->height()*0.8f))); - window->show(); -} - -/** - * @brief Destructor for the groundstation. It destroys all loaded instances. - * - **/ -MAVLinkGen::~MAVLinkGen() -{ -} - diff --git a/src/standalone/mavlinkgen/MAVLinkGen.h b/src/standalone/mavlinkgen/MAVLinkGen.h deleted file mode 100644 index 14ac63bde04aefb57303dd046ecedc8280f15c12..0000000000000000000000000000000000000000 --- a/src/standalone/mavlinkgen/MAVLinkGen.h +++ /dev/null @@ -1,58 +0,0 @@ -/*===================================================================== - -PIXHAWK Micro Air Vehicle Flying Robotics Toolkit - -(c) 2009, 2010 PIXHAWK PROJECT - -This file is part of the PIXHAWK project - - PIXHAWK 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. - - PIXHAWK 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 PIXHAWK. If not, see . - -======================================================================*/ - -/** - * @file - * @brief Definition of class MAVLinkGen - * - * @author Lorenz Meier - * - */ - - -#ifndef MAVLINKGEN_H -#define MAVLINKGEN_H - -#include - -/** - * @brief The main application and management class. - * - * This class is started by the main method and provides - * the central management unit of the groundstation application. - * - **/ -class MAVLinkGen : public QApplication -{ - Q_OBJECT - -public: - MAVLinkGen(int &argc, char* argv[]); - ~MAVLinkGen(); - -protected: - -private: -}; - -#endif /* MAVLINKGEN_H */ diff --git a/src/standalone/mavlinkgen/main.cc b/src/standalone/mavlinkgen/main.cc deleted file mode 100644 index 4a57b36902f237b23f4801f2a2e7ec75ab93e164..0000000000000000000000000000000000000000 --- a/src/standalone/mavlinkgen/main.cc +++ /dev/null @@ -1,46 +0,0 @@ -/*===================================================================== - -PIXHAWK Micro Air Vehicle Flying Robotics Toolkit - -(c) 2009, 2010 PIXHAWK PROJECT - -This file is part of the PIXHAWK project - - PIXHAWK 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. - - PIXHAWK 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 PIXHAWK. If not, see . - -======================================================================*/ - -/** - * @file - * @brief Main executable - * @author Lorenz Meier - * - */ - -#include -#include "MAVLinkGen.h" - -/** - * @brief Starts the application - * - * @param argc Number of commandline arguments - * @param argv Commandline arguments - * @return exit code, 0 for normal exit and !=0 for error cases - */ -int main(int argc, char *argv[]) -{ - - MAVLinkGen gen(argc, argv); - return gen.exec(); -} diff --git a/src/ui/JoystickWidget.cc b/src/ui/JoystickWidget.cc index b73de204b321fe25c5c4cec914f5317bdefab9e1..fcbf7489c9d762d5a492d047da499be9fc3e41ac 100644 --- a/src/ui/JoystickWidget.cc +++ b/src/ui/JoystickWidget.cc @@ -69,7 +69,6 @@ void JoystickWidget::setZ(float z) void JoystickWidget::setHat(float x, float y) { - qDebug() << __FILE__ << __LINE__ << "HAT X:" << x << "HAT Y:" << y; updateStatus(tr("Hat position: x: %1, y: %2").arg(x, y)); } @@ -129,7 +128,6 @@ void JoystickWidget::pressKey(int key) break; } QTimer::singleShot(20, this, SLOT(clearKeys())); - qDebug() << __FILE__ << __LINE__ << "KEY" << key << " pressed on joystick"; updateStatus(tr("Key %1 pressed").arg(key)); } diff --git a/src/ui/JoystickWidget.ui b/src/ui/JoystickWidget.ui index 390736324ab66f2bf28d66ec1d1081a45b430505..bf13daea0e59b04d6fc3327530c3898a9bcc4863 100644 --- a/src/ui/JoystickWidget.ui +++ b/src/ui/JoystickWidget.ui @@ -37,6 +37,9 @@ + + -100 + 100 @@ -68,7 +71,14 @@ - + + + -100 + + + 100 + + @@ -114,6 +124,9 @@ + + -100 + 100 diff --git a/src/ui/XMLCommProtocolWidget.cc b/src/ui/XMLCommProtocolWidget.cc deleted file mode 100644 index 294a4862c3e093cd98039d7deb3490d7bde2f53b..0000000000000000000000000000000000000000 --- a/src/ui/XMLCommProtocolWidget.cc +++ /dev/null @@ -1,170 +0,0 @@ -#include -#include -#include -#include - -#include "XMLCommProtocolWidget.h" -#include "ui_XMLCommProtocolWidget.h" -#include "MAVLinkXMLParser.h" -#include "MAVLinkSyntaxHighlighter.h" -#include "QGC.h" - -#include -#include - -XMLCommProtocolWidget::XMLCommProtocolWidget(QWidget *parent) : - QWidget(parent), - m_ui(new Ui::XMLCommProtocolWidget) -{ - m_ui->setupUi(this); - - // Now set syntax highlighter - //highlighter = new MAVLinkSyntaxHighlighter(m_ui->xmlTextView->document()); - - connect(m_ui->selectFileButton, SIGNAL(clicked()), this, SLOT(selectXMLFile())); - connect(m_ui->selectOutputButton, SIGNAL(clicked()), this, SLOT(selectOutputDirectory())); - connect(m_ui->generateButton, SIGNAL(clicked()), this, SLOT(generate())); - connect(m_ui->saveButton, SIGNAL(clicked()), this, SLOT(save())); -} - -void XMLCommProtocolWidget::selectXMLFile() -{ - //QString fileName = QFileDialog::getOpenFileName(this, tr("Load Protocol Definition File"), ".", "*.xml"); - QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); - const QString mavlinkXML = "MAVLINK_XML_FILE"; - QString dirPath = settings.value(mavlinkXML, QCoreApplication::applicationDirPath() + "../").toString(); - QFileInfo dir(dirPath); - QFileDialog dialog; - dialog.setDirectory(dir.absoluteDir()); - dialog.setFileMode(QFileDialog::AnyFile); - dialog.setFilter(tr("MAVLink XML (*.xml)")); - dialog.setViewMode(QFileDialog::Detail); - QStringList fileNames; - if (dialog.exec()) { - fileNames = dialog.selectedFiles(); - } - - if (fileNames.size() > 0) { - m_ui->fileNameLabel->setText(fileNames.first()); - QFile file(fileNames.first()); - - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - const QString instanceText(QString::fromUtf8(file.readAll())); - setXML(instanceText); - // Store filename for next time - settings.setValue(mavlinkXML, QFileInfo(file).absoluteFilePath()); - settings.sync(); - } else { - QMessageBox msgBox; - msgBox.setText("Could not read XML file. Permission denied"); - msgBox.exec(); - } - } -} - -void XMLCommProtocolWidget::setXML(const QString& xml) -{ - m_ui->xmlTextView->setText(xml); - QDomDocument doc; - - if (doc.setContent(xml)) { - m_ui->validXMLLabel->setText(tr("Valid XML file")); - } else { - m_ui->validXMLLabel->setText(tr("File is NOT valid XML, please fix in editor")); - } - - if (model != NULL) { - m_ui->xmlTreeView->reset(); - //delete model; - } - model = new DomModel(doc, this); - m_ui->xmlTreeView->setModel(model); - // Expand the tree so that message names are visible - m_ui->xmlTreeView->expandToDepth(1); - m_ui->xmlTreeView->hideColumn(2); - m_ui->xmlTreeView->repaint(); -} - -void XMLCommProtocolWidget::selectOutputDirectory() -{ - QSettings settings(QGC::COMPANYNAME, QGC::APPNAME); - const QString mavlinkOutputDir = "MAVLINK_OUTPUT_DIR"; - QString dirPath = settings.value(mavlinkOutputDir, QCoreApplication::applicationDirPath() + "../").toString(); - QFileDialog dialog; - dialog.setDirectory(dirPath); - dialog.setFileMode(QFileDialog::Directory); - dialog.setViewMode(QFileDialog::Detail); - QStringList fileNames; - if (dialog.exec()) { - fileNames = dialog.selectedFiles(); - } - - if (fileNames.size() > 0) { - m_ui->outputDirNameLabel->setText(fileNames.first()); - // Store directory for next time - settings.setValue(mavlinkOutputDir, QFileInfo(fileNames.first()).absoluteFilePath()); - settings.sync(); - //QFile file(fileName); - } -} - -void XMLCommProtocolWidget::generate() -{ - // Check if input file is present - if (!QFileInfo(m_ui->fileNameLabel->text().trimmed()).isFile()) { - QMessageBox::critical(this, tr("Please select an XML input file first"), tr("You have to select an input XML file before generating C files."), QMessageBox::Ok); - return; - } - - // Check if output dir is selected - if (!QFileInfo(m_ui->outputDirNameLabel->text().trimmed()).isDir()) { - QMessageBox::critical(this, tr("Please select output directory first"), tr("You have to select an output directory before generating C files."), QMessageBox::Ok); - return; - } - - // First save file - save(); - // Clean log - m_ui->compileLog->clear(); - - // Check XML validity - if (!m_ui->xmlTextView->syntaxcheck()) return; - - MAVLinkXMLParser* parser = new MAVLinkXMLParser(m_ui->fileNameLabel->text().trimmed(), m_ui->outputDirNameLabel->text().trimmed()); - connect(parser, SIGNAL(parseState(QString)), m_ui->compileLog, SLOT(appendHtml(QString))); - bool result = parser->generate(); - if (result) { - QMessageBox msgBox; - msgBox.setText(QString("The C code / headers have been generated in folder\n%1").arg(m_ui->outputDirNameLabel->text().trimmed())); - msgBox.exec(); - } else { - QMessageBox::critical(this, tr("C code generation failed, please see the compile log for further information"), QString("The C code / headers could not be written to folder\n%1").arg(m_ui->outputDirNameLabel->text().trimmed()), QMessageBox::Ok); - } - delete parser; -} - -void XMLCommProtocolWidget::save() -{ - QFile file(m_ui->fileNameLabel->text().trimmed()); - setXML(m_ui->xmlTextView->document()->toPlainText().toUtf8()); - file.open(QIODevice::WriteOnly | QIODevice::Text); - file.write(m_ui->xmlTextView->document()->toPlainText().toUtf8()); -} - -XMLCommProtocolWidget::~XMLCommProtocolWidget() -{ - delete model; - delete m_ui; -} - -void XMLCommProtocolWidget::changeEvent(QEvent *e) -{ - QWidget::changeEvent(e); - switch (e->type()) { - case QEvent::LanguageChange: - m_ui->retranslateUi(this); - break; - default: - break; - } -} diff --git a/src/ui/XMLCommProtocolWidget.h b/src/ui/XMLCommProtocolWidget.h deleted file mode 100644 index 015f76d3fff4a2514722f6f48f77c6001d559991..0000000000000000000000000000000000000000 --- a/src/ui/XMLCommProtocolWidget.h +++ /dev/null @@ -1,75 +0,0 @@ -/*===================================================================== - -QGroundControl Open Source Ground Control Station - -(c) 2009, 2010 QGROUNDCONTROL PROJECT - -This file is part of the QGROUNDCONTROL project - - QGROUNDCONTROL 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. - - QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see . - -======================================================================*/ - -/** - * @file - * @brief Definition of class XMLCommProtocolWidget - * @author Lorenz Meier - * - */ - -#ifndef XMLCOMMPROTOCOLWIDGET_H -#define XMLCOMMPROTOCOLWIDGET_H - -#include -#include "DomModel.h" -#include "MAVLinkSyntaxHighlighter.h" - -namespace Ui -{ -class XMLCommProtocolWidget; -} - -/** - * @brief Tool to generate MAVLink code out of XML protocol definitions - * @see http://doc.trolltech.com/4.6/itemviews-simpledommodel.html for a XML view tutorial - */ -class XMLCommProtocolWidget : public QWidget -{ - Q_OBJECT -public: - XMLCommProtocolWidget(QWidget *parent = 0); - ~XMLCommProtocolWidget(); - -protected slots: - /** @brief Select input XML protocol definition */ - void selectXMLFile(); - /** @brief Select output directory for generated .h files */ - void selectOutputDirectory(); - /** @brief Set the XML this widget currently operates on */ - void setXML(const QString& xml); - /** @brief Parse XML file and generate .h files */ - void generate(); - /** @brief Save the edited file */ - void save(); - -protected: - MAVLinkSyntaxHighlighter* highlighter; - DomModel* model; - void changeEvent(QEvent *e); - -private: - Ui::XMLCommProtocolWidget *m_ui; -}; - -#endif // XMLCOMMPROTOCOLWIDGET_H diff --git a/src/ui/XMLCommProtocolWidget.ui b/src/ui/XMLCommProtocolWidget.ui deleted file mode 100644 index 8b1fb3d58f8952320350b901f89e5c87c34c7ac2..0000000000000000000000000000000000000000 --- a/src/ui/XMLCommProtocolWidget.ui +++ /dev/null @@ -1,144 +0,0 @@ - - - XMLCommProtocolWidget - - - - 0 - 0 - 846 - 480 - - - - Form - - - - 6 - - - 6 - - - 6 - - - 12 - - - - - - 300 - 16777215 - - - - Select input file - - - true - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - Select input file - - - - :/images/status/folder-open.svg:/images/status/folder-open.svg - - - - - - - false - - - - - - - - 400 - 16777215 - - - - Select output directory - - - true - - - - - - - Select directory - - - - :/images/status/folder-open.svg:/images/status/folder-open.svg - - - - - - - - - - Compile Output - - - - - - - - - - No file loaded - - - - - - - Save file - - - - - - - Save and generate - - - - :/images/categories/applications-system.svg:/images/categories/applications-system.svg - - - - - - - - QGCMAVLinkTextEdit - QTextEdit -
QGCMAVLinkTextEdit.h
-
-
- - - - -
diff --git a/src/ui/mavlink/DomItem.cc b/src/ui/mavlink/DomItem.cc deleted file mode 100644 index df2c52bc8b46753ea0068c9248ddb2a1e7fb563b..0000000000000000000000000000000000000000 --- a/src/ui/mavlink/DomItem.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include - -#include "DomItem.h" - -DomItem::DomItem(QDomNode &node, int row, DomItem *parent) -{ - domNode = node; - // Record the item's location within its parent. - rowNumber = row; - parentItem = parent; -} - -DomItem::~DomItem() -{ - QHash::iterator it; - for (it = childItems.begin(); it != childItems.end(); ++it) - delete it.value(); -} - -QDomNode DomItem::node() const -{ - return domNode; -} - -DomItem *DomItem::parent() -{ - return parentItem; -} - -DomItem *DomItem::child(int i) -{ - if (childItems.contains(i)) - return childItems[i]; - - if (i >= 0 && i < domNode.childNodes().count()) { - QDomNode childNode = domNode.childNodes().item(i); - DomItem *childItem = new DomItem(childNode, i, this); - childItems[i] = childItem; - return childItem; - } - return 0; -} - -int DomItem::row() -{ - return rowNumber; -} diff --git a/src/ui/mavlink/DomItem.h b/src/ui/mavlink/DomItem.h deleted file mode 100644 index 30432795f220b18e2464a0ebbb497b9bf977d4c1..0000000000000000000000000000000000000000 --- a/src/ui/mavlink/DomItem.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef DOMITEM_H -#define DOMITEM_H - -#include -#include - -class DomItem -{ -public: - DomItem(QDomNode &node, int row, DomItem *parent = 0); - ~DomItem(); - DomItem *child(int i); - DomItem *parent(); - QDomNode node() const; - int row(); - -private: - QDomNode domNode; - QHash childItems; - DomItem *parentItem; - int rowNumber; -}; - -#endif diff --git a/src/ui/mavlink/DomModel.cc b/src/ui/mavlink/DomModel.cc deleted file mode 100644 index 36138c9c5e3bbebba41cf09e6615b243f54b8abd..0000000000000000000000000000000000000000 --- a/src/ui/mavlink/DomModel.cc +++ /dev/null @@ -1,197 +0,0 @@ -#include -#include - -#include "DomItem.h" -#include "DomModel.h" - -DomModel::DomModel(QDomDocument document, QObject *parent) - : QAbstractItemModel(parent), domDocument(document) -{ - rootItem = new DomItem(domDocument, 0); -} - -DomModel::~DomModel() -{ - delete rootItem; -} - -int DomModel::columnCount(const QModelIndex &/*parent*/) const -{ - return 3; -} - -QVariant DomModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) - return QVariant(); - - if (role != Qt::DisplayRole) - return QVariant(); - - DomItem *item = static_cast(index.internalPointer()); - - QDomNode node = item->node(); - QStringList attributes; - QDomNamedNodeMap attributeMap = node.attributes(); - - switch (index.column()) { - case 0: - { - if (node.nodeName() == "message") - { - for (int i = 0; i < attributeMap.count(); ++i) { - QDomNode attribute = attributeMap.item(i); - if (attribute.nodeName() == "name") return attribute.nodeValue(); - } - } - else if (node.nodeName() == "field") - { - for (int i = 0; i < attributeMap.count(); ++i) { - QDomNode attribute = attributeMap.item(i); - if (attribute.nodeName() == "name") return attribute.nodeValue(); - } - } - else if (node.nodeName() == "enum") - { - for (int i = 0; i < attributeMap.count(); ++i) { - QDomNode attribute = attributeMap.item(i); - if (attribute.nodeName() == "name") return attribute.nodeValue(); - } - } - else if (node.nodeName() == "entry") - { - for (int i = 0; i < attributeMap.count(); ++i) { - QDomNode attribute = attributeMap.item(i); - if (attribute.nodeName() == "name") return attribute.nodeValue(); - } - } - else if (node.nodeName() == "#text") - { - return node.nodeValue().split("\n").join(" "); - } - else - { - return node.nodeName(); - } - } - break; - case 1: - if (node.nodeName() == "description") - { - return node.nodeValue().split("\n").join(" "); - } - else - { - for (int i = 0; i < attributeMap.count(); ++i) { - QDomNode attribute = attributeMap.item(i); - - if (attribute.nodeName() == "id" || attribute.nodeName() == "index" || attribute.nodeName() == "value") - { - return QString("(# %1)").arg(attribute.nodeValue()); - } - else if (attribute.nodeName() == "type") - { - return attribute.nodeValue(); - } - } - } - break; -// case 2: -// { -//// if (node.nodeName() != "description") -//// { -//// for (int i = 0; i < attributeMap.count(); ++i) { -//// QDomNode attribute = attributeMap.item(i); -//// attributes << attribute.nodeName() + "=\"" -//// +attribute.nodeValue() + "\""; -//// } -//// return attributes.join(" "); -//// } -//// else -//// { -//// return node.nodeValue().split("\n").join(" "); -//// } -// } -// break; - default: - { - return QVariant(); - } - } -} - -Qt::ItemFlags DomModel::flags(const QModelIndex &index) const -{ - if (!index.isValid()) - return 0; - - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; -} - -QVariant DomModel::headerData(int section, Qt::Orientation orientation, - int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) { - switch (section) { - case 0: - return tr("Name "); - case 1: - return tr("Value"); -// case 2: -// return tr("Description"); - default: - return QVariant(); - } - } - - return QVariant(); -} - -QModelIndex DomModel::index(int row, int column, const QModelIndex &parent) - const -{ - if (!hasIndex(row, column, parent)) - return QModelIndex(); - - DomItem *parentItem; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast(parent.internalPointer()); - - DomItem *childItem = parentItem->child(row); - if (childItem) - return createIndex(row, column, childItem); - else - return QModelIndex(); -} - -QModelIndex DomModel::parent(const QModelIndex &child) const -{ - if (!child.isValid()) - return QModelIndex(); - - DomItem *childItem = static_cast(child.internalPointer()); - DomItem *parentItem = childItem->parent(); - - if (!parentItem || parentItem == rootItem) - return QModelIndex(); - - return createIndex(parentItem->row(), 0, parentItem); -} - -int DomModel::rowCount(const QModelIndex &parent) const -{ - if (parent.column() > 0) - return 0; - - DomItem *parentItem; - - if (!parent.isValid()) - parentItem = rootItem; - else - parentItem = static_cast(parent.internalPointer()); - - return parentItem->node().childNodes().count(); -} diff --git a/src/ui/mavlink/DomModel.h b/src/ui/mavlink/DomModel.h deleted file mode 100644 index ae6bf6a749bc5f51390f8fe33c3aea85ec54e66a..0000000000000000000000000000000000000000 --- a/src/ui/mavlink/DomModel.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef DOMMODEL_H -#define DOMMODEL_H - -#include -#include -#include -#include - -class DomItem; - -class DomModel : public QAbstractItemModel -{ - Q_OBJECT - -public: - DomModel(QDomDocument document, QObject *parent = 0); - ~DomModel(); - - QVariant data(const QModelIndex &index, int role) const; - Qt::ItemFlags flags(const QModelIndex &index) const; - QVariant headerData(int section, Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - QModelIndex index(int row, int column, - const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &child) const; - int rowCount(const QModelIndex &parent = QModelIndex()) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - -private: - QDomDocument domDocument; - DomItem *rootItem; -}; - -#endif diff --git a/standalone/qgroundcontrol-server/qgroundcontrol-server.pro b/standalone/qgroundcontrol-server/qgroundcontrol-server.pro deleted file mode 100644 index 8ab537f1f8261ec96c292cf1781967e55fe82523..0000000000000000000000000000000000000000 --- a/standalone/qgroundcontrol-server/qgroundcontrol-server.pro +++ /dev/null @@ -1,28 +0,0 @@ -QT += net - -TEMPLATE = app -TARGET = qgroundcontrol-server - -BASEDIR = ../.. -BUILDDIR = $$BASEDIR/build/qgroundcontrol-server -LANGUAGE = C++ - -CONFIG += release -CONFIG -= debug - -OBJECTS_DIR = $$BUILDDIR/qgroundcontrol-server/obj -MOC_DIR = $$BUILDDIR/qgroundcontrol-server/moc - -macx:DESTDIR = $$BASEDIR/bin/mac - -INCLUDEPATH += $$BASEDIR/. \ - $$BASEDIR/src \ - $$BASEDIR/src/comm \ - $$BASEDIR/standalone/qgroundcontrol-server/src - -HEADERS += src/QGroundControlServer.h \ - $$BASEDIR/src/comm/MAVLinkProtocol.h -SOURCES += src/main.cc \ - src/QGroundControlServer.cc \ - $$BASEDIR/src/comm/MAVLinkProtocol.cc -RESOURCES = $$BASEDIR/mavground.qrc diff --git a/standalone/qgroundcontrol-server/src/QGroundControlServer.cc b/standalone/qgroundcontrol-server/src/QGroundControlServer.cc deleted file mode 100644 index 86c06d47f3cf932da916989a665b4c3a76d14003..0000000000000000000000000000000000000000 --- a/standalone/qgroundcontrol-server/src/QGroundControlServer.cc +++ /dev/null @@ -1,93 +0,0 @@ -/*===================================================================== - -PIXHAWK Micro Air Vehicle Flying Robotics Toolkit - -(c) 2009, 2010 PIXHAWK PROJECT - -This file is part of the PIXHAWK project - - PIXHAWK 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. - - PIXHAWK 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 PIXHAWK. If not, see . - -======================================================================*/ - -/** - * @file - * @brief Implementation of class MAVLinkGen - * - * @author Lorenz Meier - * - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "MAVLinkGen.h" -#include "XMLCommProtocolWidget.h" - - -/** - * @brief Constructor for the main application. - * - * This constructor initializes and starts the whole application. It takes standard - * command-line parameters - * - * @param argc The number of command-line parameters - * @param argv The string array of parameters - **/ - -MAVLinkGen::MAVLinkGen(int &argc, char* argv[]) : QApplication(argc, argv) -{ - this->setApplicationName("MAVLink Generator"); - this->setApplicationVersion("v. 0.1.0 (Beta)"); - this->setOrganizationName(QLatin1String("OpenMAV Association")); - this->setOrganizationDomain("http://qgroundcontrol.org"); - - QSettings::setDefaultFormat(QSettings::IniFormat); - // Exit main application when last window is closed - connect(this, SIGNAL(lastWindowClosed()), this, SLOT(quit())); - - // Set application font - QFontDatabase fontDatabase = QFontDatabase(); - const QString fontFileName = ":/general/vera.ttf"; ///< Font file is part of the QRC file and compiled into the app - const QString fontFamilyName = "Bitstream Vera Sans"; - if(!QFile::exists(fontFileName)) printf("ERROR! font file: %s DOES NOT EXIST!\n", fontFileName.toStdString().c_str()); - fontDatabase.addApplicationFont(fontFileName); - setFont(fontDatabase.font(fontFamilyName, "Roman", 12)); - - // Create main window - QMainWindow* window = new QMainWindow(); - window->setCentralWidget(new XMLCommProtocolWidget(window)); - window->setWindowTitle(applicationName() + " " + applicationVersion()); - window->show(); -} - -/** - * @brief Destructor for the groundstation. It destroys all loaded instances. - * - **/ -MAVLinkGen::~MAVLinkGen() -{ -} - diff --git a/standalone/qgroundcontrol-server/src/QGroundControlServer.h b/standalone/qgroundcontrol-server/src/QGroundControlServer.h deleted file mode 100644 index 518fed03d6e587b80de55db958e8db7f9714b9c7..0000000000000000000000000000000000000000 --- a/standalone/qgroundcontrol-server/src/QGroundControlServer.h +++ /dev/null @@ -1,58 +0,0 @@ -/*===================================================================== - -PIXHAWK Micro Air Vehicle Flying Robotics Toolkit - -(c) 2009, 2010 PIXHAWK PROJECT - -This file is part of the PIXHAWK project - - PIXHAWK 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. - - PIXHAWK 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 PIXHAWK. If not, see . - -======================================================================*/ - -/** - * @file - * @brief Definition of class MAVLinkGen - * - * @author Lorenz Meier - * - */ - - -#ifndef MAVLINKGEN_H -#define MAVLINKGEN_H - -#include - -/** - * @brief The main application and management class. - * - * This class is started by the main method and provides - * the central management unit of the groundstation application. - * - **/ -class MAVLinkGen : public QApplication -{ - Q_OBJECT - -public: - MAVLinkGen(int &argc, char* argv[]); - ~MAVLinkGen(); - -protected: - -private: -}; - -#endif /* MAVLINKGEN_H */ diff --git a/standalone/qgroundcontrol-server/src/main.cc b/standalone/qgroundcontrol-server/src/main.cc deleted file mode 100644 index 4a57b36902f237b23f4801f2a2e7ec75ab93e164..0000000000000000000000000000000000000000 --- a/standalone/qgroundcontrol-server/src/main.cc +++ /dev/null @@ -1,46 +0,0 @@ -/*===================================================================== - -PIXHAWK Micro Air Vehicle Flying Robotics Toolkit - -(c) 2009, 2010 PIXHAWK PROJECT - -This file is part of the PIXHAWK project - - PIXHAWK 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. - - PIXHAWK 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 PIXHAWK. If not, see . - -======================================================================*/ - -/** - * @file - * @brief Main executable - * @author Lorenz Meier - * - */ - -#include -#include "MAVLinkGen.h" - -/** - * @brief Starts the application - * - * @param argc Number of commandline arguments - * @param argv Commandline arguments - * @return exit code, 0 for normal exit and !=0 for error cases - */ -int main(int argc, char *argv[]) -{ - - MAVLinkGen gen(argc, argv); - return gen.exec(); -}