diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..587b15b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "IvyQt"] + path = IvyQt + url = https://gitlab.com/ivybus/IvyQt.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e68d84a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.5) + +project(IvyQtExample LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + + +find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Xml REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS + Widgets + Network + Xml + REQUIRED) + +set(IvyQt_DIR "IvyQt/IvyQt/") +add_subdirectory(${IvyQt_DIR} ivyqt) + +set(PROJECT_SOURCES + main.cpp + pprzlinkqt.cpp + message_definition.cpp +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(IvyQtExample ${PROJECT_SOURCES}) +else() + add_executable(IvyQtExample ${PROJECT_SOURCES}) +endif() + + +target_include_directories(IvyQtExample PRIVATE ${IvyQt_DIR}) + +target_link_libraries(IvyQtExample PRIVATE + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Xml + IvyQt +) diff --git a/IvyQt b/IvyQt new file mode 160000 index 0000000..734a4d4 --- /dev/null +++ b/IvyQt @@ -0,0 +1 @@ +Subproject commit 734a4d438db43b4845781f277ec951d399853f56 diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b088544 --- /dev/null +++ b/main.cpp @@ -0,0 +1,12 @@ +#include +#include "pprzlinkqt.h" + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + PprzlinkQt pp("/home/fabien/paparazzi/var/messages.xml"); + + return a.exec(); +} + diff --git a/message_definition.cpp b/message_definition.cpp new file mode 100644 index 0000000..f28ae33 --- /dev/null +++ b/message_definition.cpp @@ -0,0 +1,29 @@ +#include "message_definition.h" + + +MessageDefinition::MessageDefinition(QDomElement msg_elt, QString class_name, uint8_t class_id): + class_name(class_name), class_id(class_id) +{ + name = msg_elt.attribute("name"); + id = msg_elt.attribute("id").toUInt(); + + for(auto elt = msg_elt.firstChildElement(); + !elt.isNull(); + elt = elt.nextSiblingElement()) { + + if(elt.tagName() == "description") { + description = elt.text(); + } else if(elt.tagName() == "field") { + QString field_description = elt.text(); + QString field_name = elt.attribute("name"); + QString field_type = elt.attribute("type"); + QString format = elt.attribute("format"); + QString unit = elt.attribute("unit"); + QString values = elt.attribute("values"); + QString alt_unit = elt.attribute("alt_unit"); + QString alt_unit_coef = elt.attribute("alt_unit_coef"); + qDebug() << field_name << field_type << format << unit << values << alt_unit << alt_unit_coef; + + } + } +} diff --git a/message_definition.h b/message_definition.h new file mode 100644 index 0000000..8871fff --- /dev/null +++ b/message_definition.h @@ -0,0 +1,29 @@ +#ifndef MESSAGEDEFINITION_H +#define MESSAGEDEFINITION_H + +#include +#include + +class MessageDefinition +{ +public: + MessageDefinition(QDomElement msg_elt, QString class_name, uint8_t class_id); + + QString getName() {return name;} + uint8_t getId() {return id;} + QString getClassName() {return class_name;} + uint8_t getClassId() {return class_id;} + QString getDescription() {return description;} + +private: + QString class_name; + uint8_t class_id; + QString name; + uint8_t id; + QString description; + + //fields + +}; + +#endif // MESSAGEDEFINITION_H diff --git a/pprzlinkqt.cpp b/pprzlinkqt.cpp new file mode 100644 index 0000000..d1e1d8c --- /dev/null +++ b/pprzlinkqt.cpp @@ -0,0 +1,43 @@ +#include "pprzlinkqt.h" +#include +#include "message_definition.h" + + +PprzlinkQt::PprzlinkQt(QString filename, QObject *parent) : QObject(parent) +{ + QDomDocument xmlMessages; + QFile f(filename); + if(!f.open(QIODevice::ReadOnly)) { + throw std::runtime_error("Error while loading layout file"); + } + xmlMessages.setContent(&f); + f.close(); + + QDomElement root = xmlMessages.documentElement(); + + QString rootTag = root.tagName(); + + if (rootTag != "protocol") { + throw std::runtime_error("Root tag expected to be \"protocol\". Is this a messages file ?"); + } + + for(auto class_elt = root.firstChildElement(); + !class_elt.isNull(); + class_elt = class_elt.nextSiblingElement()) { + + QString class_name = class_elt.attribute("name"); + uint8_t class_id = class_elt.attribute("id").toUInt(); + qDebug() << class_name << class_id; + + for(auto msg_elt = class_elt.firstChildElement(); + !msg_elt.isNull(); + msg_elt = msg_elt.nextSiblingElement()) { + + MessageDefinition def(msg_elt, class_name, class_id); + qDebug() << def.getName() << def.getId() << def.getDescription(); + + } + + } + +} diff --git a/pprzlinkqt.h b/pprzlinkqt.h new file mode 100644 index 0000000..003e8ae --- /dev/null +++ b/pprzlinkqt.h @@ -0,0 +1,16 @@ +#ifndef PPRZLINKQT_H +#define PPRZLINKQT_H + +#include + +class PprzlinkQt : public QObject +{ + Q_OBJECT +public: + explicit PprzlinkQt(QString filename, QObject *parent = nullptr); + +signals: + +}; + +#endif // PPRZLINKQT_H