From 8f4438fbd68b7fc815ae9f94cbff3e82767bdb1e Mon Sep 17 00:00:00 2001 From: Nicolas Appriou Date: Sun, 10 Jul 2022 11:40:46 +0200 Subject: [PATCH 1/3] setup Cmake buildsystem --- .gitignore | 2 ++ CMakeLists.txt | 26 ++++++++++++++++++++++++++ README.md | 12 ++++++++++++ src/KeyReceiver.cpp | 4 ++-- src/KeyReceiver.h | 2 +- src/QtSimPanel.cpp | 6 +++--- src/QtSimPanel.h | 2 +- src/main.cpp | 2 +- 8 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index f147edf..c74505c 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,5 @@ compile_commands.json # QtCreator local machine specific files for imported projects *creator.user* + +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..46c1453 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +# This file is a copy/paste from Qt manual +# see: https://doc.qt.io/qt-5/cmake-manual.html + +cmake_minimum_required(VERSION 3.16) + +project(SimPanel LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +find_package(Qt5 REQUIRED Qml Widgets) + +add_executable(SimPanel + src/datastore.cpp + src/KeyReceiver.cpp + src/main.cpp + src/qml.qrc + src/QtSimPanel.cpp + src/xplaneudpclient.cpp +) + +target_link_libraries(SimPanel Qt5::Qml Qt5::Widgets) diff --git a/README.md b/README.md index 1cc9a42..6f45008 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,15 @@ Todo list : - [ ] Provide compiled files for Rapberry, Mac and windows (linux 64 only at the moment0 QtSimPanel is writen in C++ / QML using Qt5. + + +## Build + +With Cmake: + +``` +$ mkdir build +$ cd build/ +$ cmake ../ +$ make +``` diff --git a/src/KeyReceiver.cpp b/src/KeyReceiver.cpp index e895d9f..d273775 100644 --- a/src/KeyReceiver.cpp +++ b/src/KeyReceiver.cpp @@ -1,7 +1,7 @@ -#include "KeyReceiver.h" -#include #include #include +#include "KeyReceiver.h" +#include "QtSimPanel.h" KeyReceiver::KeyReceiver(QtSimPanel* qtSimPanel) { diff --git a/src/KeyReceiver.h b/src/KeyReceiver.h index 362f40e..c58f1a4 100644 --- a/src/KeyReceiver.h +++ b/src/KeyReceiver.h @@ -2,7 +2,7 @@ #define KEYRECEIVER_H #include -#include +#include "QtSimPanel.h" class KeyReceiver : public QObject { diff --git a/src/QtSimPanel.cpp b/src/QtSimPanel.cpp index 2c63a9d..4968f53 100644 --- a/src/QtSimPanel.cpp +++ b/src/QtSimPanel.cpp @@ -1,10 +1,10 @@ -#include "QtSimPanel.h" -#include "xplaneudpclient.h" -#include #include #include #include #include +#include "QtSimPanel.h" +#include "xplaneudpclient.h" +#include "KeyReceiver.h" QtSimPanel::QtSimPanel(int argc, char** argv): QGuiApplication(argc, argv), m_settings(QDir::currentPath()+"/settings.ini", QSettings::IniFormat) diff --git a/src/QtSimPanel.h b/src/QtSimPanel.h index d26ba0c..4563744 100644 --- a/src/QtSimPanel.h +++ b/src/QtSimPanel.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include "datastore.h" class QtSimPanel : public QGuiApplication { diff --git a/src/main.cpp b/src/main.cpp index 0b7bb8c..e243ef5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include "QtSimPanel.h" int main(int argc, char *argv[]) { From e0d48446e5bfcc98283273714da33244a575285b Mon Sep 17 00:00:00 2001 From: Nicolas Appriou Date: Sun, 10 Jul 2022 11:49:24 +0200 Subject: [PATCH 2/3] add export compile commands --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46c1453..1c23fad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.16) project(SimPanel LANGUAGES CXX) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) From 81e0faea8ca9ded40cff11f5cc749c7396977be5 Mon Sep 17 00:00:00 2001 From: Nicolas Appriou Date: Sun, 10 Jul 2022 11:51:57 +0200 Subject: [PATCH 3/3] use cstring for char array prefix comparison --- src/xplaneudpclient.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/xplaneudpclient.cpp b/src/xplaneudpclient.cpp index c68ed91..ca4c1d3 100644 --- a/src/xplaneudpclient.cpp +++ b/src/xplaneudpclient.cpp @@ -1,3 +1,5 @@ +#include + #include "xplaneudpclient.h" XplaneUdpClient::XplaneUdpClient(DataStore *dataStore, QObject *parent) : QObject(parent) @@ -107,7 +109,7 @@ void XplaneUdpClient::readStream() union { int intValue; float floatValue; } ieee754Union; - if (buffer[0] == 'D' && buffer[1] == 'A' && buffer[2] == 'T' && buffer[3] == 'A') // Handle XPlane DATA + if (strncmp(buffer, "DATA", 4) == 0) { // Segments of data unsigned nbSegs = (datagramSize-5)/36; @@ -152,7 +154,7 @@ void XplaneUdpClient::readStream() } } } - else if (buffer[0] == 'D' && buffer[1] == 'R' && buffer[2] == 'E' && buffer[3] == 'F') // Handle XPlane DREF + else if (strncmp(buffer, "DREF", 4) == 0) { char dataSegment[500]; memcpy( dataSegment, &buffer[9], 500 ); @@ -184,7 +186,7 @@ void XplaneUdpClient::readStream() } } } - else if (buffer[0] == 'R' && buffer[1] == 'R' && buffer[2] == 'E' && buffer[3] == 'F') // Handle XPlane DREF + else if (strncmp(buffer, "RREF", 4) == 0) { // Segments of data