From 307990cc0beceb3489ce30e077bb9a029495b0ee Mon Sep 17 00:00:00 2001 From: Tacosaurus100 Date: Wed, 6 Mar 2024 12:58:00 -0800 Subject: [PATCH 01/12] Temp mac fix --- .gitignore | 1 + CMakeLists.txt | 123 ++++++++++++++---- README.md | 17 +++ main.cpp | 4 +- .../CMakeDirectoryInformation.cmake | 16 +++ tests/CMakeFiles/progress.marks | 1 + tests/CMakeLists.txt | 62 ++++++--- tests/CTestTestfile.cmake | 6 + tests/broadcaster-tests.cpp | 2 +- tests/cmake_install.cmake | 39 ++++++ tests/labjacksink-tests.cpp | 2 +- 11 files changed, 222 insertions(+), 51 deletions(-) create mode 100644 tests/CMakeFiles/CMakeDirectoryInformation.cmake create mode 100644 tests/CMakeFiles/progress.marks create mode 100644 tests/CTestTestfile.cmake create mode 100644 tests/cmake_install.cmake diff --git a/.gitignore b/.gitignore index c7f3f6a..6b94391 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,4 @@ CMakeLists.txt.user* .idea/ cmake-build-debug/ +build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index c2d0d5e..4411dd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,16 +2,22 @@ cmake_minimum_required(VERSION 3.16) project(DAC-Qt VERSION 0.1 LANGUAGES CXX) -set(CMAKE_STANDARD_CXX 14) +set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# Find packages +find_package(Qt6 6.4 REQUIRED COMPONENTS Widgets Charts Quick) find_package(spdlog REQUIRED) +find_package(nlohmann_json REQUIRED) -find_package(Qt6 6.4 REQUIRED COMPONENTS Quick Charts) +# Add external libraries or subdirectories add_subdirectory("extern/influxdb-cxx") +# Setup Qt project qt_standard_project_setup() +qt_policy(SET QTP0001 NEW) +# Define library target if tests are enabled option(PACKAGE_TESTS "Build with Tests" ON) if(PACKAGE_TESTS) enable_testing() @@ -29,51 +35,112 @@ if(PACKAGE_TESTS) ) endif() +# Define executable target qt_add_executable(appDAC-Qt + MANUAL_FINALIZATION main.cpp + # Add other source files as needed ) +# Define QML module qt_add_qml_module(appDAC-Qt URI DAC-Qt VERSION 1.0 - QML_FILES Main.qml - QML_FILES Visualization.qml - QML_FILES Settings.qml - QML_FILES Navigation.qml - QML_FILES Setup.qml - QML_FILES components/visualization/MockChart.qml - QML_FILES components/navigation/NavButton.qml - SOURCES Config.h - SOURCES models/ForceData.h models/PressureData.h models/TelemetryData.h models/TemperatureData.h - SOURCES sinks/LabJackSink.h sinks/LabJackSink.cpp sinks/LabJackSinkStrategy.h - SOURCES broadcast/Sink.h broadcast/Broadcaster.h - SOURCES launchinhibitor.h launchinhibitor.cpp -) - -# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. -# If you are developing for iOS or macOS you should consider setting an -# explicit, fixed bundle identifier manually though. -set_target_properties(appDAC-Qt PROPERTIES -# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appDAC-Qt - MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} - MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} - MACOSX_BUNDLE TRUE - WIN32_EXECUTABLE TRUE + QML_FILES + Main.qml + Visualization.qml + Settings.qml + Navigation.qml + Setup.qml + components/visualization/MockChart.qml + components/navigation/NavButton.qml + SOURCES + Config.h + models/ForceData.h + models/PressureData.h + models/TelemetryData.h + models/TemperatureData.h + sinks/LabJackSink.h + sinks/LabJackSink.cpp + sinks/LabJackSinkStrategy.h + broadcast/Sink.h + broadcast/Broadcaster.h + launchinhibitor.h + launchinhibitor.cpp ) +# Platform-specific configurations if(WIN32) target_include_directories(appDAC-Qt PRIVATE "C:/Program Files (x86)/LabJack/Drivers") target_link_libraries(appDAC-Qt PRIVATE "C:/Program Files (x86)/LabJack/Drivers/64bit/LabJackM.lib") else() - target_link_libraries(appDAC-Qt PRIVATE LabJackM) + set(CMAKE_MACOSX_RPATH 1) + set(CMAKE_INSTALL_RPATH "/usr/local/lib") + + list(APPEND CMAKE_PREFIX_PATH /opt/homebrew /usr/local) + + find_path(LabJackM_INCLUDE_DIR NAMES LabJackM.h) + find_library(LabJackM_LIBRARY NAMES LabJackM-1.23.1 PATHS "/usr/local/lib") + find_library(LibUSB_LIBRARY NAMES usb-1.0.0 PATHS "/usr/local/lib") + + message(STATUS "LabJackM_LIBRARY: ${LabJackM_LIBRARY}") + message(STATUS "LabJackM_INCLUDE_DIR: ${LabJackM_INCLUDE_DIR}") + message(STATUS "LibUSB_LIBRARY: ${LibUSB_LIBRARY}") + + # Assuming you have a target named 'your_target' + # Replace 'your_target' with the actual target name + if(LabJackM_LIBRARY AND LabJackM_INCLUDE_DIR AND LibUSB_LIBRARY) + target_include_directories(appDAC-Qt PRIVATE ${LabJackM_INCLUDE_DIR}) + target_link_libraries(appDAC-Qt PRIVATE ${LabJackM_LIBRARY}) + target_link_libraries(appDAC-Qt PRIVATE ${LibUSB_LIBRARY}) + target_include_directories(libDAC-Qt PRIVATE ${LabJackM_INCLUDE_DIR}) + target_link_libraries(libDAC-Qt PRIVATE ${LabJackM_LIBRARY}) + target_link_libraries(libDAC-Qt PRIVATE ${LibUSB_LIBRARY}) + else() + message(FATAL_ERROR "LabJackM library not found") + endif() + + # For CURL, using find_package is more portable if available + find_package(CURL REQUIRED) + if(CURL_FOUND) + target_include_directories(appDAC-Qt PRIVATE ${CURL_INCLUDE_DIRS}) + target_link_libraries(appDAC-Qt PRIVATE ${CURL_LIBRARIES}) + target_include_directories(libDAC-Qt PRIVATE ${CURL_INCLUDE_DIRS}) + target_link_libraries(libDAC-Qt PRIVATE ${CURL_LIBRARIES}) + else() + message(FATAL_ERROR "CURL not found") + endif() endif() +# Common link libraries target_link_libraries(appDAC-Qt - PRIVATE Qt6::Quick Qt6::Charts LabJackM spdlog::spdlog InfluxData::InfluxDB + PRIVATE + Qt6::Widgets + Qt6::Charts + Qt6::Quick + spdlog::spdlog + InfluxData::InfluxDB + nlohmann_json::nlohmann_json ) -configure_file("config.json" "config.json" COPYONLY) +# Conditionally link LabJackM library for non-Windows platforms +# if(NOT WIN32) +# target_link_libraries(appDAC-Qt PRIVATE ${LabJackM_LIBRARY}) +# if(PACKAGE_TESTS) +# target_link_libraries(libDAC-Qt PRIVATE ${LabJackM_LIBRARY}) +# endif() +# endif() + +# Setup target properties for macOS and Windows +set_target_properties(appDAC-Qt PROPERTIES + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} +) +# Configure file copying and installation paths +configure_file("config.json" "${CMAKE_CURRENT_BINARY_DIR}/config.json" COPYONLY) include(GNUInstallDirs) install(TARGETS appDAC-Qt BUNDLE DESTINATION . diff --git a/README.md b/README.md index 3a74782..4983a26 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,20 @@ Dependencies: Running: 1. Build and run in Qt Creator + +Setup (Mac) +xcode-select --install +git submodule update --init --recursive +brew reinstall spdlog cpr curl libusb +mkdir build +cd build +cmake .. +make +export DYLD_LIBRARY_PATH=/usr/local/lib +./appDAC-Qt.app/Contents/MacOS/appDAC-Qt + +*restart terminal* + +## Troubleshooting +With an error like: dyld[94071]: Library not loaded: /usr/local/lib/libusb-1.0.0.dylib + \ No newline at end of file diff --git a/main.cpp b/main.cpp index 3bbf16c..abfcbec 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,9 @@ #include #include #include +#include +#include "sinks/LabJackSink.h" #include "broadcast/Broadcaster.h" #include "models/ForceData.h" #include "models/TemperatureData.h" @@ -49,7 +51,7 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QQmlApplicationEngine engine; - const QUrl url(u"qrc:/DAC-Qt/Main.qml"_qs); + const QUrl url = QUrl::fromLocalFile(QDir::current().absoluteFilePath("DAC-Qt/Main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); diff --git a/tests/CMakeFiles/CMakeDirectoryInformation.cmake b/tests/CMakeFiles/CMakeDirectoryInformation.cmake new file mode 100644 index 0000000..6fecab3 --- /dev/null +++ b/tests/CMakeFiles/CMakeDirectoryInformation.cmake @@ -0,0 +1,16 @@ +# CMAKE generated file: DO NOT EDIT! +# Generated by "Unix Makefiles" Generator, CMake Version 3.28 + +# Relative path conversion top directories. +set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt") +set(CMAKE_RELATIVE_PATH_TOP_BINARY "/Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt") + +# Force unix paths in dependencies. +set(CMAKE_FORCE_UNIX_PATHS 1) + + +# The C and CXX include file regular expressions for this directory. +set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") +set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") +set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) +set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) diff --git a/tests/CMakeFiles/progress.marks b/tests/CMakeFiles/progress.marks new file mode 100644 index 0000000..573541a --- /dev/null +++ b/tests/CMakeFiles/progress.marks @@ -0,0 +1 @@ +0 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9848098..c63f6a0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,27 +1,49 @@ -cmake_minimum_required(VERSION 3.16) +# cmake_minimum_required(VERSION 3.16) -project(DAC-Qt_tests) +# project(DAC-Qt_tests) -SET(CMAKE_CXX_STANDARD 11) -SET(CMAKE_CXX_STANDARD_REQUIRED ON) +# set(CMAKE_CXX_STANDARD 11) +# set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_subdirectory("${CMAKE_SOURCE_DIR}/extern/googletest" "extern/googletest") +# # Add GoogleTest directly to our build. This defines the gtest and gtest_main targets. +# add_subdirectory("${CMAKE_SOURCE_DIR}/extern/googletest" "extern/googletest") -add_executable( - DAC-Qt_tests - broadcaster-tests.cpp - labjacksink-tests.cpp -) +# add_executable( +# DAC-Qt_tests +# broadcaster-tests.cpp +# labjacksink-tests.cpp +# ) -if(WIN32) - target_include_directories(DAC-Qt_tests PRIVATE "C:/Program Files (x86)/LabJack/Drivers") - target_link_libraries(DAC-Qt_tests PRIVATE "C:/Program Files (x86)/LabJack/Drivers/64bit/LabJackM.lib") -else() - target_link_libraries(DAC-Qt_tests PRIVATE LabJackM) -endif() +# # Include the GoogleTest headers +# target_include_directories(DAC-Qt_tests PRIVATE "${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include") -target_link_libraries(DAC-Qt_tests - PRIVATE libDAC-Qt GTest::gtest_main -) +# if(WIN32) +# target_include_directories(DAC-Qt_tests PRIVATE "C:/Program Files (x86)/LabJack/Drivers") +# target_link_libraries(DAC-Qt_tests PRIVATE "C:/Program Files (x86)/LabJack/Drivers/64bit/LabJackM.lib") +# else() +# list(APPEND CMAKE_PREFIX_PATH /opt/homebrew /usr/local) -gtest_discover_tests(DAC-Qt_tests) +# find_path(LabJackM_INCLUDE_DIR NAMES LabJackM.h) +# find_library(LabJackM_LIBRARY NAMES LabJackM LabJackM-1.23.0 PATHS "/usr/local/lib") + +# # Assuming you have a target named 'your_target' +# # Replace 'your_target' with the actual target name +# if(LabJackM_LIBRARY AND LabJackM_INCLUDE_DIR) +# message(STATUS "Testing LabJackM_LIBRARY: ${LabJackM_LIBRARY}") +# message(STATUS "Testing LabJackM_INCLUDE_DIR: ${LabJackM_INCLUDE_DIR}") + +# target_include_directories(DAC-Qt_tests PRIVATE ${LabJackM_INCLUDE_DIR}) +# target_link_libraries(DAC-Qt_tests PRIVATE ${LabJackM_LIBRARY}) +# else() +# message(FATAL_ERROR "LabJackM library not found") +# endif() +# endif() + +# # Linking against libDAC-Qt (your project library) and GoogleTest +# target_link_libraries(DAC-Qt_tests +# PRIVATE libDAC-Qt GTest::gtest_main +# ) + +# # Discover and run tests +# include(GoogleTest) +# gtest_discover_tests(DAC-Qt_tests) diff --git a/tests/CTestTestfile.cmake b/tests/CTestTestfile.cmake new file mode 100644 index 0000000..d1176b3 --- /dev/null +++ b/tests/CTestTestfile.cmake @@ -0,0 +1,6 @@ +# CMake generated Testfile for +# Source directory: /Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt/tests +# Build directory: /Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt/tests +# +# This file includes the relevant testing commands required for +# testing this directory and lists subdirectories to be tested as well. diff --git a/tests/broadcaster-tests.cpp b/tests/broadcaster-tests.cpp index 15c9823..5fa49e5 100644 --- a/tests/broadcaster-tests.cpp +++ b/tests/broadcaster-tests.cpp @@ -43,4 +43,4 @@ TEST_F(BroadcasterTest, SinkShouldNullptr) { Sink sink({str_broadcaster}); sink.sendData({&data}); -} +} \ No newline at end of file diff --git a/tests/cmake_install.cmake b/tests/cmake_install.cmake new file mode 100644 index 0000000..b196f46 --- /dev/null +++ b/tests/cmake_install.cmake @@ -0,0 +1,39 @@ +# Install script for directory: /Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt/tests + +# Set the install prefix +if(NOT DEFINED CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "/usr/local") +endif() +string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") + +# Set the install configuration name. +if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) + if(BUILD_TYPE) + string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" + CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") + else() + set(CMAKE_INSTALL_CONFIG_NAME "RelWithDebInfo") + endif() + message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") +endif() + +# Set the component getting installed. +if(NOT CMAKE_INSTALL_COMPONENT) + if(COMPONENT) + message(STATUS "Install component: \"${COMPONENT}\"") + set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") + else() + set(CMAKE_INSTALL_COMPONENT) + endif() +endif() + +# Is this installation the result of a crosscompile? +if(NOT DEFINED CMAKE_CROSSCOMPILING) + set(CMAKE_CROSSCOMPILING "FALSE") +endif() + +# Set default install directory permissions. +if(NOT DEFINED CMAKE_OBJDUMP) + set(CMAKE_OBJDUMP "/Library/Developer/CommandLineTools/usr/bin/objdump") +endif() + diff --git a/tests/labjacksink-tests.cpp b/tests/labjacksink-tests.cpp index b65427a..b50c813 100644 --- a/tests/labjacksink-tests.cpp +++ b/tests/labjacksink-tests.cpp @@ -6,4 +6,4 @@ TEST(LabJackSinkTest, OpensDevice) { LabJackSink sink; sink.open(0, "-2", 0); ASSERT_EQ(sink.serial_number(), -2); -} +} \ No newline at end of file From 26ad1749ceaa522889c2820e71857108f446d3e4 Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 13 Mar 2024 22:52:34 -0700 Subject: [PATCH 02/12] Works on QTCreator --- CMakeLists.txt | 113 ++++++++++----- CMakeUserPresets.json | 9 ++ README.md | 133 +++++++++++++++++- Visualization.qml | 2 +- conanfile.txt | 1 + extern/influxdb-cxx | 1 - sinks/LabJackSink.cpp | 7 +- .../CMakeDirectoryInformation.cmake | 16 --- tests/CMakeFiles/progress.marks | 1 - tests/CMakeLists.txt | 49 ------- tests/CTestTestfile.cmake | 6 - tests/broadcaster-tests.cpp | 46 ------ tests/cmake_install.cmake | 39 ----- tests/labjacksink-tests.cpp | 9 -- 14 files changed, 223 insertions(+), 209 deletions(-) create mode 100644 CMakeUserPresets.json delete mode 160000 extern/influxdb-cxx delete mode 100644 tests/CMakeFiles/CMakeDirectoryInformation.cmake delete mode 100644 tests/CMakeFiles/progress.marks delete mode 100644 tests/CMakeLists.txt delete mode 100644 tests/CTestTestfile.cmake delete mode 100644 tests/broadcaster-tests.cpp delete mode 100644 tests/cmake_install.cmake delete mode 100644 tests/labjacksink-tests.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 4411dd9..fac4b48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,39 @@ cmake_minimum_required(VERSION 3.16) - project(DAC-Qt VERSION 0.1 LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# set(CMAKE_CXX_EXTENSIONS OFF) + +add_definitions(-DSPDLOG_FMT_EXTERNAL=1) + +include(${CMAKE_BINARY_DIR}/conan-dependencies/conan_toolchain.cmake) +message(STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}") + +message(STATUS "CMAKE_PROGRAM_PATH: ${CMAKE_PROGRAM_PATH}") +message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") +message(STATUS "CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}") +message(STATUS "CMAKE_LIBRARY_PATH: ${CMAKE_LIBRARY_PATH}") +include_directories(${CMAKE_INCLUDE_PATH}) + +list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}") +# list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/generators") -# Find packages -find_package(Qt6 6.4 REQUIRED COMPONENTS Widgets Charts Quick) +# Include the conan toolchain file +find_package(Qt6 6.6.2 COMPONENTS Core Widgets Charts Quick REQUIRED) find_package(spdlog REQUIRED) find_package(nlohmann_json REQUIRED) +find_package(Boost REQUIRED COMPONENTS system filesystem) +find_package(InfluxDB REQUIRED) -# Add external libraries or subdirectories -add_subdirectory("extern/influxdb-cxx") +# Setup Qt project +qt_standard_project_setup() +qt_policy(SET QTP0001 NEW) + +if(NOT TARGET Boost::Boost AND TARGET Boost::boost) + add_library(Boost::Boost INTERFACE IMPORTED) + set_property(TARGET Boost::Boost PROPERTY INTERFACE_LINK_LIBRARIES Boost::boost) +endif() # Setup Qt project qt_standard_project_setup() @@ -22,7 +44,7 @@ option(PACKAGE_TESTS "Build with Tests" ON) if(PACKAGE_TESTS) enable_testing() include(GoogleTest) - add_subdirectory(tests) + # add_subdirectory(test) add_library(libDAC-Qt models/ForceData.h models/PressureData.h @@ -42,37 +64,17 @@ qt_add_executable(appDAC-Qt # Add other source files as needed ) -# Define QML module -qt_add_qml_module(appDAC-Qt - URI DAC-Qt - VERSION 1.0 - QML_FILES - Main.qml - Visualization.qml - Settings.qml - Navigation.qml - Setup.qml - components/visualization/MockChart.qml - components/navigation/NavButton.qml - SOURCES - Config.h - models/ForceData.h - models/PressureData.h - models/TelemetryData.h - models/TemperatureData.h - sinks/LabJackSink.h - sinks/LabJackSink.cpp - sinks/LabJackSinkStrategy.h - broadcast/Sink.h - broadcast/Broadcaster.h - launchinhibitor.h - launchinhibitor.cpp -) - # Platform-specific configurations if(WIN32) target_include_directories(appDAC-Qt PRIVATE "C:/Program Files (x86)/LabJack/Drivers") + target_include_directories(libDAC-Qt PRIVATE "C:/Program Files (x86)/LabJack/Drivers") target_link_libraries(appDAC-Qt PRIVATE "C:/Program Files (x86)/LabJack/Drivers/64bit/LabJackM.lib") + target_link_libraries(libDAC-Qt PRIVATE "C:/Program Files (x86)/LabJack/Drivers/64bit/LabJackM.lib") + message (STATUS "Including: LabJack/Drivers and LabJackM.lib on Windows") + if(MSVC) + target_compile_options(appDAC-Qt PRIVATE "/Zc:__cplusplus" "/permissive-") + target_compile_options(libDAC-Qt PRIVATE "/Zc:__cplusplus" "/permissive-") + endif() else() set(CMAKE_MACOSX_RPATH 1) set(CMAKE_INSTALL_RPATH "/usr/local/lib") @@ -112,14 +114,53 @@ else() endif() endif() +# Define QML module +qt_add_qml_module(appDAC-Qt + URI DAC-Qt + VERSION 1.0 + QML_FILES + Main.qml + Visualization.qml + Settings.qml + Navigation.qml + Setup.qml + components/visualization/MockChart.qml + components/navigation/NavButton.qml + SOURCES + Config.h + models/ForceData.h + models/PressureData.h + models/TelemetryData.h + models/TemperatureData.h + sinks/LabJackSink.h + sinks/LabJackSink.cpp + sinks/LabJackSinkStrategy.h + broadcast/Sink.h + broadcast/Broadcaster.h + launchinhibitor.h + launchinhibitor.cpp +) + # Common link libraries target_link_libraries(appDAC-Qt PRIVATE + Qt6::Core Qt6::Widgets Qt6::Charts Qt6::Quick spdlog::spdlog - InfluxData::InfluxDB + InfluxData::InfluxDB + nlohmann_json::nlohmann_json +) + +target_link_libraries(libDAC-Qt + PRIVATE + Qt6::Core + Qt6::Widgets + Qt6::Charts + Qt6::Quick + spdlog::spdlog + InfluxData::InfluxDB nlohmann_json::nlohmann_json ) @@ -146,4 +187,4 @@ install(TARGETS appDAC-Qt BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} -) +) \ No newline at end of file diff --git a/CMakeUserPresets.json b/CMakeUserPresets.json new file mode 100644 index 0000000..d3f26cf --- /dev/null +++ b/CMakeUserPresets.json @@ -0,0 +1,9 @@ +{ + "version": 4, + "vendor": { + "conan": {} + }, + "include": [ + "C:\\Users\\bmarc\\Desktop\\UCR\\SPACE\\DAC-Qt\\build\\CMakePresets.json" + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 4983a26..4b6bb74 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Dependencies: Running: 1. Build and run in Qt Creator -Setup (Mac) +## Setup (Mac) xcode-select --install git submodule update --init --recursive brew reinstall spdlog cpr curl libusb @@ -22,6 +22,137 @@ export DYLD_LIBRARY_PATH=/usr/local/lib *restart terminal* +## Setup (Windows) + +#### Install and Setup winget +This is based off of the link below +https://learn.microsoft.com/en-us/windows/package-manager/winget/ + +Start by installing or updating App Installer +https://apps.microsoft.com/detail/9nblggh4nns1?rtc=1&hl=en-us&gl=US#activetab=pivot:overviewtab + +To add the source if it isn't already added, run this command +```winget source add --name winget --arg https://cdn.winget.microsoft.com/cache``` + +To test if it worked, it should be at 1.6 or above +```winget --version``` + +#### Install choco +Open Powershell as Administrator, and run the following: +```Get-ExecutionPolicy``` +If it return 'Restricted', run: + Set-ExecutionPolicy RemoteSigned -Scope CurrentUser +Else: + continue + +Run: +```Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))``` + +Verify it by running +```choco --version``` + +#### Install vscode +Go to the following link and click the installer. +Select any options you like while installing. +I checked all options yes, including the desktop shortcut, to allow windows to open with code, and the defaults they had. +https://code.visualstudio.com/download + +#### Install git (and git bash) +Within an admin powershell, run: + ```winget install Git.Git``` + +Open powershell as admin and type git to verify installation + +#### (Recommended) Make vscode always run as Admin +To use the git bash terminal in VSCode as admin, VSCode must be run as admin. +As this is almost always necessary, the following steps will make the shortcut default to that. + +Go to the shortcut (either on desktop or in windows search) and right click +Select Properties +Go to the Compatibility tab +Select Run this program as an administrator + +#### (Recommended) Set git bash as default vscode terminal +Open VSCode, and open the Command Palette with Ctrl + Shift + P. +Type Terminal: Select Default Profile and select it. +Choose the Git Bash terminal from the list. + +To open new a terminal, type Ctrl + Shift + P and then select Terminal: Create New Terminal +This should be a git bash terminal. + +#### Install cmake, conan, g++, Qt 6 +In a git bash terminal being Run with Administrator, +1. make an account and install Qt 6. Go to the following link and create an account with your school email. Select QT Edu for Developers +https://www.qt.io/qt-educational-license#application + +2. Verify your email and you will be redirected to the download page. Select your OS. +https://www.qt.io/download-qt-installer-oss + +3. Log into your QT account in the installer. Continue through each page, until you see an option for custom installation (in the Installation Folder). Ensure it is checked and then continue. + +4. Click the Qt drop down and ensure that the latest stable version is checked, and then ensure that Qt Charts is also checked (under Additional Libraries). Continue through the rest of the install. + +```winget install -e --id Kitware.CMake``` +```winget install -e --id JFrog.Conan``` +```choco install visualstudio2022buildtools -y --execution-timeout=10800 --package-parameters "--allWorkloads --includeRecommended --includeOptional --passive --locale en-US"``` (This will also take a while, for my computer with a slow network it was about 2 hours) +```echo 'export PATH=$PATH:/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2022/BuildTools/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64' >> ~/.bashrc``` +```source ~/.bashrc``` +```echo 'export CMAKE_PREFIX_PATH=/c/Qt/6.6.2/mingw_64' >> ~/.bashrc``` + +To see if the installation worked properly, try the following. All of these should return values and not error: +```cmake --version``` +```conan --version``` +```g++ --version``` +```nmake --version``` +```ninja --version``` + +```mkdir build``` +```conan profile detect``` +This step is very important. Ensure that the profile it creates has cpp 17 or higher, or cpr wont install properly. If you need to change it, run the following commands: +```nano ~/.conan2/profiles/default``` +```conan install ./extern/influxdb-cxx/ --profile=default --build=missing -of=./extern/influxdb-cxx/build``` +```conan install conanfile.txt -of=build -g CMakeDeps -g CMakeToolchain``` + + + +```conan install . -if=build --build-require --build``` +```conan install . -if=build --build=missing -g=cmake_paths -g=cmake_find_package -g=json -g=cmake``` + +```conan install . -if=build --build-require --build``` +```cmake . -G "Visual Studio 17 2022" -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DINFLUXCXX_TESTING=OFF -DINFLUXCXX_WITH_BOOST=ON -Bbuild -DCMAKE_CXX_STANDARD=17 --toolchain ./build/conan_toolchain.cmake``` + + +```echo 'export CMAKE_PREFIX_PATH=/c/Users/bmarc/Desktop/UCR/SPACE/DAC-Qt/build' >> ~/.bashrc``` + + +in extern/inf/build +cmake .. -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE=/c/Users/bmarc/Desktop/UCR/SPACE/DAC-Qt/extern/influxdb-cxx/build/conan_toolchain.cmake -DINFLUXCXX_TESTING=OFF -DINFLUXCXX_WITH_BOOST=ON -DCMAKE_POLICY_DEFAULT_CMP0091=NEW + +#### Install LabJack libraries: +Go to the following link and install the executable. +Select any options you like while installing. I didn't change anything off of default. +https://labjack.com/pages/support?doc=/software-driver/installer-downloads/ljm-software-installers-t4-t7-digit/ +If this link is broken, look up `labjack windows 11 t7 install downloads` + +#### Install dependencies +git submodule update --init --recursive + +## Compile and run +cmake . -Bbuild -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake +cmake --build build + + + ## Troubleshooting + +### Mac With an error like: dyld[94071]: Library not loaded: /usr/local/lib/libusb-1.0.0.dylib + +### Windows +First ensure packages are up to date +```choco upgrade all``` + + + +### Linux \ No newline at end of file diff --git a/Visualization.qml b/Visualization.qml index bd892a3..22c4c83 100644 --- a/Visualization.qml +++ b/Visualization.qml @@ -76,4 +76,4 @@ Item { } } } -} +} \ No newline at end of file diff --git a/conanfile.txt b/conanfile.txt index bf9c0ec..49e15ed 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,6 +1,7 @@ [requires] nlohmann_json/[>=3.11.2] spdlog/[>=1.13.0] +influxdb-cxx/[>=0.7.2] [generators] CMakeDeps diff --git a/extern/influxdb-cxx b/extern/influxdb-cxx deleted file mode 160000 index 909bd1c..0000000 --- a/extern/influxdb-cxx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 909bd1c1ad274a9a14d68acb8167c13f9de7e523 diff --git a/sinks/LabJackSink.cpp b/sinks/LabJackSink.cpp index 11ecec6..d84149f 100644 --- a/sinks/LabJackSink.cpp +++ b/sinks/LabJackSink.cpp @@ -12,20 +12,19 @@ const char* LabJackException::what() const noexcept { } LabJackSink::LabJackSink() { - stream_callback_ = [](void* args){ auto stream_args = reinterpret_cast(args); const size_t size = stream_args->scans_per_read * stream_args->strategy->address_list().size(); - double arr[size]; + std::vector arr(size); // Use std::vector for dynamic allocation int error, device_scan_backlog, ljm_scan_backlog; error = LJM_eStreamRead(stream_args->handle, - arr, + arr.data(), // Pass pointer to the underlying array &device_scan_backlog, &ljm_scan_backlog); if (error) { throw LabJackException(error); } - stream_args->strategy->process(arr, stream_args); + stream_args->strategy->process(arr.data(), stream_args); }; } diff --git a/tests/CMakeFiles/CMakeDirectoryInformation.cmake b/tests/CMakeFiles/CMakeDirectoryInformation.cmake deleted file mode 100644 index 6fecab3..0000000 --- a/tests/CMakeFiles/CMakeDirectoryInformation.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.28 - -# Relative path conversion top directories. -set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt") -set(CMAKE_RELATIVE_PATH_TOP_BINARY "/Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt") - -# Force unix paths in dependencies. -set(CMAKE_FORCE_UNIX_PATHS 1) - - -# The C and CXX include file regular expressions for this directory. -set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") -set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") -set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) -set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) diff --git a/tests/CMakeFiles/progress.marks b/tests/CMakeFiles/progress.marks deleted file mode 100644 index 573541a..0000000 --- a/tests/CMakeFiles/progress.marks +++ /dev/null @@ -1 +0,0 @@ -0 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index c63f6a0..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,49 +0,0 @@ -# cmake_minimum_required(VERSION 3.16) - -# project(DAC-Qt_tests) - -# set(CMAKE_CXX_STANDARD 11) -# set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# # Add GoogleTest directly to our build. This defines the gtest and gtest_main targets. -# add_subdirectory("${CMAKE_SOURCE_DIR}/extern/googletest" "extern/googletest") - -# add_executable( -# DAC-Qt_tests -# broadcaster-tests.cpp -# labjacksink-tests.cpp -# ) - -# # Include the GoogleTest headers -# target_include_directories(DAC-Qt_tests PRIVATE "${gtest_SOURCE_DIR}/include" "${gmock_SOURCE_DIR}/include") - -# if(WIN32) -# target_include_directories(DAC-Qt_tests PRIVATE "C:/Program Files (x86)/LabJack/Drivers") -# target_link_libraries(DAC-Qt_tests PRIVATE "C:/Program Files (x86)/LabJack/Drivers/64bit/LabJackM.lib") -# else() -# list(APPEND CMAKE_PREFIX_PATH /opt/homebrew /usr/local) - -# find_path(LabJackM_INCLUDE_DIR NAMES LabJackM.h) -# find_library(LabJackM_LIBRARY NAMES LabJackM LabJackM-1.23.0 PATHS "/usr/local/lib") - -# # Assuming you have a target named 'your_target' -# # Replace 'your_target' with the actual target name -# if(LabJackM_LIBRARY AND LabJackM_INCLUDE_DIR) -# message(STATUS "Testing LabJackM_LIBRARY: ${LabJackM_LIBRARY}") -# message(STATUS "Testing LabJackM_INCLUDE_DIR: ${LabJackM_INCLUDE_DIR}") - -# target_include_directories(DAC-Qt_tests PRIVATE ${LabJackM_INCLUDE_DIR}) -# target_link_libraries(DAC-Qt_tests PRIVATE ${LabJackM_LIBRARY}) -# else() -# message(FATAL_ERROR "LabJackM library not found") -# endif() -# endif() - -# # Linking against libDAC-Qt (your project library) and GoogleTest -# target_link_libraries(DAC-Qt_tests -# PRIVATE libDAC-Qt GTest::gtest_main -# ) - -# # Discover and run tests -# include(GoogleTest) -# gtest_discover_tests(DAC-Qt_tests) diff --git a/tests/CTestTestfile.cmake b/tests/CTestTestfile.cmake deleted file mode 100644 index d1176b3..0000000 --- a/tests/CTestTestfile.cmake +++ /dev/null @@ -1,6 +0,0 @@ -# CMake generated Testfile for -# Source directory: /Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt/tests -# Build directory: /Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt/tests -# -# This file includes the relevant testing commands required for -# testing this directory and lists subdirectories to be tested as well. diff --git a/tests/broadcaster-tests.cpp b/tests/broadcaster-tests.cpp deleted file mode 100644 index 5fa49e5..0000000 --- a/tests/broadcaster-tests.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include - -#include "../broadcast/Broadcaster.h" -#include "../broadcast/Sink.h" -#include "../models/ForceData.h" - -class BroadcasterTest : public testing::Test{ -protected: - std::shared_ptr> broadcaster = Broadcaster::getInstance(); - std::shared_ptr> forceBroadcaster = Broadcaster::getInstance(); -}; - -TEST_F(BroadcasterTest, ShouldBroadcast) { - TelemetryData data; - data.label = "Test"; - broadcaster->subscribe([](const TelemetryData *data){ - EXPECT_NE(data, nullptr); - ASSERT_EQ(data->label, "Test"); - }); - - broadcaster->broadcastBase(&data); -} - -TEST_F(BroadcasterTest, SinkShouldSend) { - TelemetryData data; - data.label = "Test"; - broadcaster->subscribe([](const TelemetryData *data){ - EXPECT_NE(data, nullptr); - ASSERT_EQ(data->label, "Test"); - }); - Sink sink({broadcaster}); - - sink.sendData({&data}); -} - -TEST_F(BroadcasterTest, SinkShouldNullptr) { - TelemetryData data; - data.label = "Type test"; - auto str_broadcaster = Broadcaster::getInstance(); - str_broadcaster->subscribe([](const std::string *data){ - ASSERT_EQ(data, nullptr); - }); - - Sink sink({str_broadcaster}); - sink.sendData({&data}); -} \ No newline at end of file diff --git a/tests/cmake_install.cmake b/tests/cmake_install.cmake deleted file mode 100644 index b196f46..0000000 --- a/tests/cmake_install.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# Install script for directory: /Users/brandonmarcus/Desktop/UCR/SPACE/DAC-Qt/tests - -# Set the install prefix -if(NOT DEFINED CMAKE_INSTALL_PREFIX) - set(CMAKE_INSTALL_PREFIX "/usr/local") -endif() -string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") - -# Set the install configuration name. -if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) - if(BUILD_TYPE) - string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" - CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") - else() - set(CMAKE_INSTALL_CONFIG_NAME "RelWithDebInfo") - endif() - message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") -endif() - -# Set the component getting installed. -if(NOT CMAKE_INSTALL_COMPONENT) - if(COMPONENT) - message(STATUS "Install component: \"${COMPONENT}\"") - set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") - else() - set(CMAKE_INSTALL_COMPONENT) - endif() -endif() - -# Is this installation the result of a crosscompile? -if(NOT DEFINED CMAKE_CROSSCOMPILING) - set(CMAKE_CROSSCOMPILING "FALSE") -endif() - -# Set default install directory permissions. -if(NOT DEFINED CMAKE_OBJDUMP) - set(CMAKE_OBJDUMP "/Library/Developer/CommandLineTools/usr/bin/objdump") -endif() - diff --git a/tests/labjacksink-tests.cpp b/tests/labjacksink-tests.cpp deleted file mode 100644 index b50c813..0000000 --- a/tests/labjacksink-tests.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -#include "../sinks/LabJackSink.h" - -TEST(LabJackSinkTest, OpensDevice) { - LabJackSink sink; - sink.open(0, "-2", 0); - ASSERT_EQ(sink.serial_number(), -2); -} \ No newline at end of file From 766709fbf6c5fe75a6446aa9abf716bc04807a87 Mon Sep 17 00:00:00 2001 From: Brandon Date: Wed, 13 Mar 2024 23:16:39 -0700 Subject: [PATCH 03/12] README --- README.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/README.md b/README.md index 4b6bb74..0fc7611 100644 --- a/README.md +++ b/README.md @@ -110,18 +110,10 @@ To see if the installation worked properly, try the following. All of these shou ```conan profile detect``` This step is very important. Ensure that the profile it creates has cpp 17 or higher, or cpr wont install properly. If you need to change it, run the following commands: ```nano ~/.conan2/profiles/default``` -```conan install ./extern/influxdb-cxx/ --profile=default --build=missing -of=./extern/influxdb-cxx/build``` -```conan install conanfile.txt -of=build -g CMakeDeps -g CMakeToolchain``` - - -```conan install . -if=build --build-require --build``` -```conan install . -if=build --build=missing -g=cmake_paths -g=cmake_find_package -g=json -g=cmake``` - -```conan install . -if=build --build-require --build``` +```conan install . -if=build --build-require --build=missing``` ```cmake . -G "Visual Studio 17 2022" -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DINFLUXCXX_TESTING=OFF -DINFLUXCXX_WITH_BOOST=ON -Bbuild -DCMAKE_CXX_STANDARD=17 --toolchain ./build/conan_toolchain.cmake``` - ```echo 'export CMAKE_PREFIX_PATH=/c/Users/bmarc/Desktop/UCR/SPACE/DAC-Qt/build' >> ~/.bashrc``` From 8de915372fb16a8a556a0d6f3316be5a764671e8 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 1 Apr 2024 15:23:26 -0700 Subject: [PATCH 04/12] temp push --- README.md | 13 ++++++-- windows_install.bat | 1 + windows_install.ps1 | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 windows_install.bat create mode 100644 windows_install.ps1 diff --git a/README.md b/README.md index 0fc7611..d98c34f 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,8 @@ Run: Verify it by running ```choco --version``` - +It should be at 2.2.2 or higher + #### Install vscode Go to the following link and click the installer. Select any options you like while installing. @@ -92,22 +93,28 @@ https://www.qt.io/download-qt-installer-oss 4. Click the Qt drop down and ensure that the latest stable version is checked, and then ensure that Qt Charts is also checked (under Additional Libraries). Continue through the rest of the install. +```pip install conan=1``` ```winget install -e --id Kitware.CMake``` ```winget install -e --id JFrog.Conan``` ```choco install visualstudio2022buildtools -y --execution-timeout=10800 --package-parameters "--allWorkloads --includeRecommended --includeOptional --passive --locale en-US"``` (This will also take a while, for my computer with a slow network it was about 2 hours) ```echo 'export PATH=$PATH:/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2022/BuildTools/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64' >> ~/.bashrc``` -```source ~/.bashrc``` ```echo 'export CMAKE_PREFIX_PATH=/c/Qt/6.6.2/mingw_64' >> ~/.bashrc``` +```source ~/.bashrc``` To see if the installation worked properly, try the following. All of these should return values and not error: ```cmake --version``` +This should be cmake > 3. ```conan --version``` +This should be 1.63.0 ```g++ --version``` +This shouldn't error ```nmake --version``` +This should show something ```ninja --version``` +This shouldn't error ```mkdir build``` -```conan profile detect``` +```conan profile list``` This step is very important. Ensure that the profile it creates has cpp 17 or higher, or cpr wont install properly. If you need to change it, run the following commands: ```nano ~/.conan2/profiles/default``` diff --git a/windows_install.bat b/windows_install.bat new file mode 100644 index 0000000..2984d4b --- /dev/null +++ b/windows_install.bat @@ -0,0 +1 @@ +PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File \"" + $PWD.Path.Replace('\', '\\') + "\\setupDAC-Qt.ps1\"' -Verb RunAs}" \ No newline at end of file diff --git a/windows_install.ps1 b/windows_install.ps1 new file mode 100644 index 0000000..40a5df3 --- /dev/null +++ b/windows_install.ps1 @@ -0,0 +1,74 @@ +# Ensure the script is running with Administrator privileges +Write-Host "Checking for Administrator privileges..." +If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { + Write-Warning "Please run this script as an Administrator!" + Exit +} else { + Write-Host "Running with Administrator privileges." +} + +# Check for winget availability +try { + winget --version +} catch { + Write-Host "winget is not installed. Please install App Installer from https://apps.microsoft.com/detail/9nblggh4nns1?rtc=1&hl=en-us&gl=US#activetab=pivot:overviewtab" + Exit +} + +# Check for pip availability +try { + pip --version +} catch { + Write-Host "pip is not installed. Please install the latest version of Python from https://www.python.org/downloads/windows/ and ensure pip is selected during installation." + Exit +} + +# Install winget and choco, if necessary +# Note: Instructions for setting up winget and Chocolatey have been omitted for brevity. + +# Install dependencies +Write-Host "Installing CMake with winget..." +winget install -e --id Kitware.CMake +Write-Host "CMake installation complete." + +Write-Host "Installing Conan with winget..." +pip install conan +Write-Host "Conan installation complete." + +Write-Host "Installing Visual Studio Build Tools with Chocolatey. This may take some time..." +choco install visualstudio2022buildtools -y --execution-timeout=10800 --package-parameters "--allWorkloads --includeRecommended --includeOptional --passive --locale en-US" +Write-Host "Visual Studio Build Tools installation complete." + +Write-Host "Updating PATH and CMAKE_PREFIX_PATH environment variables..." +echo 'export PATH=$PATH:/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio/2022/BuildTools/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64' >> $env:UserProfile/.bashrc +. $env:UserProfile/.bashrc +echo 'export CMAKE_PREFIX_PATH=/c/Qt/6.6.2/mingw_64' >> $env:UserProfile/.bashrc +Write-Host "Environment variables updated." + +# Initialize submodules +Write-Host "Initializing git submodules..." +git submodule update --init --recursive +Write-Host "Git submodules initialized." + +# Clean up and prepare the build directory +Write-Host "Preparing the build directory..." +$buildDir = "C:\Users\bmarc\Desktop\UCR\SPACE\DAC-Qt\build" +if (Test-Path $buildDir) { + Remove-Item -Path $buildDir -Recurse -Force + Write-Host "Existing build directory removed." +} +New-Item -Path $buildDir -ItemType Directory +Write-Host "New build directory created." + +cd $buildDir +Write-Host "Creating build directory and running Conan profile detect..." +conan profile list +Write-Host "Conan profile detection complete." + +# Compile the application +# Write-Host "Compiling the application with CMake..." +# cmake .. -G "Visual Studio 17 2022" -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DINFLUXCXX_TESTING=OFF -DINFLUXCXX_WITH_BOOST=ON -Bbuild -DCMAKE_CXX_STANDARD=17 --toolchain ./build/conan_toolchain.cmake +# Write-Host "Compilation complete." + +# Note: Users must manually follow steps for Qt 6 installation and setting VSCode as admin +Write-Host "Setup complete. Please follow the manual steps for Qt 6 installation, open QT Creator, select the CMakeLists file as your project, select the Projects tab on the left side of the QT Creator, select any of the MinGW options. Click build, then run." \ No newline at end of file From daef5dea090a3f01cef930d1012ec3128a53cb19 Mon Sep 17 00:00:00 2001 From: sudoNeo <113386291+sudoNeo@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:06:49 -0700 Subject: [PATCH 05/12] Makes sure it's conan 1.63.0 --- windows_install.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/windows_install.ps1 b/windows_install.ps1 index 40a5df3..99810d4 100644 --- a/windows_install.ps1 +++ b/windows_install.ps1 @@ -32,7 +32,7 @@ winget install -e --id Kitware.CMake Write-Host "CMake installation complete." Write-Host "Installing Conan with winget..." -pip install conan +pip install conan==1.63.0 Write-Host "Conan installation complete." Write-Host "Installing Visual Studio Build Tools with Chocolatey. This may take some time..." @@ -71,4 +71,4 @@ Write-Host "Conan profile detection complete." # Write-Host "Compilation complete." # Note: Users must manually follow steps for Qt 6 installation and setting VSCode as admin -Write-Host "Setup complete. Please follow the manual steps for Qt 6 installation, open QT Creator, select the CMakeLists file as your project, select the Projects tab on the left side of the QT Creator, select any of the MinGW options. Click build, then run." \ No newline at end of file +Write-Host "Setup complete. Please follow the manual steps for Qt 6 installation, open QT Creator, select the CMakeLists file as your project, select the Projects tab on the left side of the QT Creator, select any of the MinGW options. Click build, then run." From bc879fbbf06054ba401b83a9788aced00ca3ead6 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sun, 7 Apr 2024 18:34:16 -0700 Subject: [PATCH 06/12] temp fix --- README.md | 3 +++ windows_install.ps1 | 50 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d98c34f..e8d3e4c 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ export DYLD_LIBRARY_PATH=/usr/local/lib ## Setup (Windows) +```powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$(pwd -W)/windows_install.ps1"``` + #### Install and Setup winget This is based off of the link below https://learn.microsoft.com/en-us/windows/package-manager/winget/ @@ -127,6 +129,7 @@ This step is very important. Ensure that the profile it creates has cpp 17 or hi in extern/inf/build cmake .. -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE=/c/Users/bmarc/Desktop/UCR/SPACE/DAC-Qt/extern/influxdb-cxx/build/conan_toolchain.cmake -DINFLUXCXX_TESTING=OFF -DINFLUXCXX_WITH_BOOST=ON -DCMAKE_POLICY_DEFAULT_CMP0091=NEW + #### Install LabJack libraries: Go to the following link and install the executable. Select any options you like while installing. I didn't change anything off of default. diff --git a/windows_install.ps1 b/windows_install.ps1 index 40a5df3..bc3fb4b 100644 --- a/windows_install.ps1 +++ b/windows_install.ps1 @@ -50,9 +50,57 @@ Write-Host "Initializing git submodules..." git submodule update --init --recursive Write-Host "Git submodules initialized." +# Check for cmake version > 3 +try { + $cmakeVersion = cmake --version | Select-String -Pattern "version (\d+\.\d+)" -AllMatches | ForEach-Object { $_.Matches.Groups[1].Value } + If ([version]$cmakeVersion -lt [version]"3.0") { + Write-Host "cmake version is less than 3. Please update cmake." + Exit + } +} catch { + Write-Host "cmake is not installed or not found in PATH." + Exit +} + +# Check for conan version 1.63.0 +try { + $conanVersion = conan --version | Select-String -Pattern "version (\d+\.\d+\.\d+)" -AllMatches | ForEach-Object { $_.Matches.Groups[1].Value } + If ($conanVersion -ne "1.63.0") { + Write-Host "conan version is not 1.63.0. Found version $conanVersion. Please install the correct version." + Exit + } +} catch { + Write-Host "conan is not installed or not found in PATH." + Exit +} + +# Check for g++ availability +try { + g++ --version +} catch { + Write-Host "g++ is not installed or not found in PATH." + Exit +} + +# Check for nmake availability +try { + nmake --version +} catch { + Write-Host "nmake is not installed or not found in PATH." + Exit +} + +# Check for ninja availability +try { + ninja --version +} catch { + Write-Host "ninja is not installed or not found in PATH." + Exit +} + # Clean up and prepare the build directory Write-Host "Preparing the build directory..." -$buildDir = "C:\Users\bmarc\Desktop\UCR\SPACE\DAC-Qt\build" +$buildDir = Join-Path -Path (Get-Location) -ChildPath "build" if (Test-Path $buildDir) { Remove-Item -Path $buildDir -Recurse -Force Write-Host "Existing build directory removed." From 8e58a9b122687c06c2b3e2ec3dc6f20b75b6b774 Mon Sep 17 00:00:00 2001 From: Brandon Marcus Date: Sun, 7 Apr 2024 12:11:13 -0700 Subject: [PATCH 07/12] Temp --- README.md | 10 ++++- install.sh | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100755 install.sh diff --git a/README.md b/README.md index e8d3e4c..3ef9d1a 100644 --- a/README.md +++ b/README.md @@ -157,4 +157,12 @@ First ensure packages are up to date ### Linux - \ No newline at end of file +https://www.qt.io/download +After the file is downloaded, you will need to make it runnable with +```chmod +x /path/to/downloaded/file``` +The specific command I used was chmod +x ~/Downloads/qt-unified-linux-x64-4.7.0-online.run + +Then run the file by just typing the name of it or running it in finder. +```~/Downloads/qt-unified-linux-x64-4.7.0-online.run``` + +Follow the steps \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..1d69bba --- /dev/null +++ b/install.sh @@ -0,0 +1,120 @@ +#!/bin/bash + +# Exit script if any command fails +set -e + +# Function to install pip for Linux +install_pip_linux() { + echo "Installing pip for Linux..." + sudo apt-get update + sudo apt-get install -y python3-pip +} + +# Function to install pip for macOS using Homebrew +install_pip_macos() { + echo "Installing Python (and pip) for macOS using Homebrew..." + # Ensure Homebrew is installed + if ! command -v brew &> /dev/null; then + echo "Homebrew not found, installing Homebrew..." + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + fi + # Install Python. Pip comes with Python. + brew install python +} + +# Function to check if pip, conan, and cmake are correctly installed +check_installations() { + if ! command -v pip &> /dev/null; then + echo "pip could not be found. Exiting..." + exit 1 + fi + + if ! command -v cmake &> /dev/null; then + echo "cmake could not be found. Exiting..." + exit 1 + fi + + # Check for Conan installation and version + if command -v conan &> /dev/null; then + conan_version=$(conan --version | grep -oP 'Conan version \K[^\s]+') + if [ "$conan_version" != "1.63.0" ]; then + echo "Conan version 1.63.0 is required. Found version $conan_version. Exiting..." + exit 1 + fi + else + echo "Conan could not be found. Exiting..." + exit 1 + fi +} + +# Function to install cmake for both macOS and Linux +install_cmake() { + echo "Installing cmake..." + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + sudo apt-get install -y cmake + elif [[ "$OSTYPE" == "darwin"* ]]; then + brew install cmake + fi +} + +# Main installation routine for Linux and macOS +install_main() { + git submodule update --init --recursive + + # Attempt to install pip and cmake if missing + if ! command -v pip &> /dev/null; then + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + install_pip_linux + elif [[ "$OSTYPE" == "darwin"* ]]; then + install_pip_macos + fi + fi + + if ! command -v cmake &> /dev/null; then + install_cmake + fi + + # Install Conan, checking for version after installation + pip install conan==1.63.0 + + check_installations + + # Continue with build and setup + mkdir -p build && cd build + cmake .. + make + if [[ "$OSTYPE" == "darwin"* ]]; then + export DYLD_LIBRARY_PATH=/usr/local/lib + echo 'export DYLD_LIBRARY_PATH=/usr/local/lib' >> ~/.bashrc + else + export LD_LIBRARY_PATH=/usr/local/lib + echo 'export LD_LIBRARY_PATH=/usr/local/lib' >> ~/.bashrc + fi + source ~/.bashrc + if [[ "$OSTYPE" == "darwin"* ]]; then + ./appDAC-Qt.app/Contents/MacOS/appDAC-Qt + else + ./appDAC-Qt + fi +} + +# Check for operating system and run appropriate commands +case "$OSTYPE" in + linux-gnu*) + echo "Detected Linux OS..." + install_main + ;; + darwin*) + echo "Detected macOS..." + xcode-select --install || true # Proceed even if xcode-select fails + install_main + ;; + cygwin | msys) + echo "Detected Windows..." + powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$(pwd -W)/windows_install.ps1" + ;; + *) + echo "Unsupported OS." + exit 1 + ;; +esac From 2c66360a2deb14b0cf69f6d56174649c6aae9d9f Mon Sep 17 00:00:00 2001 From: Tacosaurus100 Date: Wed, 24 Apr 2024 13:00:48 -0700 Subject: [PATCH 08/12] Temp Push mostly working --- CMakeLists.txt | 43 +++++++++++++++++++++++++++++++++++++++++++ CMakeUserPresets.json | 9 --------- README.md | 13 +++++++++++++ install.sh | 25 +++++++++++++++++++++---- 4 files changed, 77 insertions(+), 13 deletions(-) delete mode 100644 CMakeUserPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index fac4b48..4059893 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,58 @@ cmake_minimum_required(VERSION 3.16) project(DAC-Qt VERSION 0.1 LANGUAGES CXX) +# if(APPLE) +# if(NOT DEFINED CMAKE_OSX_SYSROOT) +# message(FATAL_ERROR "Cannot check SDK version if CMAKE_OSX_SYSROOT" +# " is not defined." +# ) +# endif() + +# set(DYLD_LIBRARY_PATH "${DYLD_LIBRARY_PATH}:/usr/local/lib") + +# execute_process( +# COMMAND xcrun --sdk "${CMAKE_OSX_SYSROOT}" --show-sdk-version +# OUTPUT_VARIABLE sdk_version +# OUTPUT_STRIP_TRAILING_WHITESPACE +# ) + +# if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +# if(sdk_version VERSION_LESS 14.2) +# message(FATAL_ERROR "This project requires at least iPhoneOS SDK" +# " 14.2, but got ${sdk_version} instead." +# ) +# endif() +# else() +# if(sdk_version VERSION_LESS 11.0) +# message(FATAL_ERROR "This project requires at least macOS SDK" +# " 11.0, but got ${sdk_version} instead." +# ) +# endif() +# endif() +# endif() + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # set(CMAKE_CXX_EXTENSIONS OFF) +list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}") + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") + + + +message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") + +# if(NOT EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") +# execute_process(COMMAND conan install ${CMAKE_BINARY_DIR} --build=missing -s build_type=Release +# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +# endif() add_definitions(-DSPDLOG_FMT_EXTERNAL=1) include(${CMAKE_BINARY_DIR}/conan-dependencies/conan_toolchain.cmake) message(STATUS "CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}") +message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") message(STATUS "CMAKE_PROGRAM_PATH: ${CMAKE_PROGRAM_PATH}") message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") message(STATUS "CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}") diff --git a/CMakeUserPresets.json b/CMakeUserPresets.json deleted file mode 100644 index d3f26cf..0000000 --- a/CMakeUserPresets.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": 4, - "vendor": { - "conan": {} - }, - "include": [ - "C:\\Users\\bmarc\\Desktop\\UCR\\SPACE\\DAC-Qt\\build\\CMakePresets.json" - ] -} \ No newline at end of file diff --git a/README.md b/README.md index 3ef9d1a..a236f3b 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,21 @@ Running: ## Setup (Mac) xcode-select --install +sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer + +click run in terminal in the run section of qt creator +added /usr/local/lib to my DYLD_LIBRARY_PATH +use xcode, not ninja for cmake gen +cmake doesnt seem to matter + git submodule update --init --recursive brew reinstall spdlog cpr curl libusb +brew install ninja +in qt creator, add PATH+=/opt/homebrew/bin to environment var in preferences > kits > your kit > environment. Just click change and add that line. + +Troubleshooting: +if it says something like c++ or C compile failed, check your $CC and $CXX variables. if these arent set, then update or reinstall xcode tools. + mkdir build cd build cmake .. diff --git a/install.sh b/install.sh index 1d69bba..009668f 100755 --- a/install.sh +++ b/install.sh @@ -20,24 +20,32 @@ install_pip_macos() { fi # Install Python. Pip comes with Python. brew install python + brew install ninja } # Function to check if pip, conan, and cmake are correctly installed check_installations() { + if ! command -v pip &> /dev/null; then echo "pip could not be found. Exiting..." exit 1 fi + echo 'Pip found!' if ! command -v cmake &> /dev/null; then echo "cmake could not be found. Exiting..." exit 1 fi + echo 'Cmake found!' - # Check for Conan installation and version if command -v conan &> /dev/null; then - conan_version=$(conan --version | grep -oP 'Conan version \K[^\s]+') - if [ "$conan_version" != "1.63.0" ]; then + conan_version_output=$(conan --version) + echo "Conan version output: $conan_version_output" # For debugging + conan_version=$(echo "$conan_version_output" | grep -oE 'Conan version [0-9]+\.[0-9]+\.[0-9]+' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+') + if [ -z "$conan_version" ]; then + echo "Failed to parse Conan version. Exiting..." + exit 1 + elif [ "$conan_version" != "1.63.0" ]; then echo "Conan version 1.63.0 is required. Found version $conan_version. Exiting..." exit 1 fi @@ -45,6 +53,7 @@ check_installations() { echo "Conan could not be found. Exiting..." exit 1 fi + } # Function to install cmake for both macOS and Linux @@ -80,9 +89,17 @@ install_main() { check_installations # Continue with build and setup - mkdir -p build && cd build + mkdir -p build + + echo 'Changing directory to build' + cd build + + echo 'Running CMake...' cmake .. + echo 'Cmake Complete!' + echo 'Running Make...' make + echo 'Make Complete!' if [[ "$OSTYPE" == "darwin"* ]]; then export DYLD_LIBRARY_PATH=/usr/local/lib echo 'export DYLD_LIBRARY_PATH=/usr/local/lib' >> ~/.bashrc From c3e2a20546ce4a1557e9df40db82b7a1238b91fe Mon Sep 17 00:00:00 2001 From: Tacosaurus100 Date: Wed, 24 Apr 2024 13:18:03 -0700 Subject: [PATCH 09/12] Test --- CMakeLists.txt | 2 +- main.cpp | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4059893..7c8485a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # set(CMAKE_CXX_EXTENSIONS OFF) list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") +# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") diff --git a/main.cpp b/main.cpp index abfcbec..6f318ab 100644 --- a/main.cpp +++ b/main.cpp @@ -20,7 +20,8 @@ Config read_config(); int main(int argc, char *argv[]) { spdlog::info("Starting DAC-Qt"); - + QApplication app(argc, argv); + Config config = read_config(); auto forceBroadcaster = Broadcaster::getInstance(); @@ -48,8 +49,6 @@ int main(int argc, char *argv[]) } // lj_sink.start_stream(100, 100, std::make_shared(pressureBroadcaster)); - QApplication app(argc, argv); - QQmlApplicationEngine engine; const QUrl url = QUrl::fromLocalFile(QDir::current().absoluteFilePath("DAC-Qt/Main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, @@ -61,7 +60,11 @@ int main(int argc, char *argv[]) } Config read_config() { - QFile f("config.json"); + QString path = QCoreApplication::applicationDirPath() + "/config.json"; + spdlog::info("Trying to open config file at: {}", path.toStdString()); + QFile f(path); + + // QFile f("config.json"); if(f.open(QIODevice::ReadOnly)) { Config config; QJsonDocument json = QJsonDocument::fromJson(f.readAll()); From a807757c2916f28a4743b19f42cf2e794a0503eb Mon Sep 17 00:00:00 2001 From: Tacosaurus100 Date: Sat, 27 Apr 2024 13:13:44 -0700 Subject: [PATCH 10/12] Tests --- .vscode/settings.json | 50 +++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 35 +++++--------------------- Config.h.in | 20 +++++++++++++++ main.cpp | 9 ++++--- Config.h => tempConfig.h | 0 tests/CMakeLists.txt | 27 ++++++++++++++++++++ tests/broadcaster-tests.cpp | 46 ++++++++++++++++++++++++++++++++++ tests/labjacksink-tests.cpp | 9 +++++++ 8 files changed, 164 insertions(+), 32 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 Config.h.in rename Config.h => tempConfig.h (100%) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/broadcaster-tests.cpp create mode 100644 tests/labjacksink-tests.cpp diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..aa3a0c4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,50 @@ +{ + "files.associations": { + "__bit_reference": "cpp", + "__config": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "execution": "cpp", + "initializer_list": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "locale": "cpp", + "mutex": "cpp", + "new": "cpp", + "optional": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "variant": "cpp", + "vector": "cpp" + } +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c8485a..3479dc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,35 +1,11 @@ cmake_minimum_required(VERSION 3.16) project(DAC-Qt VERSION 0.1 LANGUAGES CXX) -# if(APPLE) -# if(NOT DEFINED CMAKE_OSX_SYSROOT) -# message(FATAL_ERROR "Cannot check SDK version if CMAKE_OSX_SYSROOT" -# " is not defined." -# ) -# endif() - -# set(DYLD_LIBRARY_PATH "${DYLD_LIBRARY_PATH}:/usr/local/lib") - -# execute_process( -# COMMAND xcrun --sdk "${CMAKE_OSX_SYSROOT}" --show-sdk-version -# OUTPUT_VARIABLE sdk_version -# OUTPUT_STRIP_TRAILING_WHITESPACE -# ) - -# if(CMAKE_SYSTEM_NAME STREQUAL "iOS") -# if(sdk_version VERSION_LESS 14.2) -# message(FATAL_ERROR "This project requires at least iPhoneOS SDK" -# " 14.2, but got ${sdk_version} instead." -# ) -# endif() -# else() -# if(sdk_version VERSION_LESS 11.0) -# message(FATAL_ERROR "This project requires at least macOS SDK" -# " 11.0, but got ${sdk_version} instead." -# ) -# endif() -# endif() -# endif() +set(BUILD_DIR ${CMAKE_BINARY_DIR}) + +# Configure a header file to pass some of the CMake settings to the source code +configure_file(Config.h.in ${CMAKE_BINARY_DIR}/Config.h) +include_directories(${CMAKE_BINARY_DIR}) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -58,6 +34,7 @@ message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") message(STATUS "CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}") message(STATUS "CMAKE_LIBRARY_PATH: ${CMAKE_LIBRARY_PATH}") include_directories(${CMAKE_INCLUDE_PATH}) +include_directories(${CMAKE_BINARY_DIR}) list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}") # list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/generators") diff --git a/Config.h.in b/Config.h.in new file mode 100644 index 0000000..2864b69 --- /dev/null +++ b/Config.h.in @@ -0,0 +1,20 @@ +#pragma once + +#define BUILD_DIR "@BUILD_DIR@" + +class Config { + public: + struct LabJackConfig { + std::string identifier; + std::string device_type; + std::string connection_type; + }; + + struct InfluxConfig { + std::string address; + std::string token; + }; + + LabJackConfig labjack; + InfluxConfig influx; +}; diff --git a/main.cpp b/main.cpp index 6f318ab..1626a3a 100644 --- a/main.cpp +++ b/main.cpp @@ -50,7 +50,8 @@ int main(int argc, char *argv[]) // lj_sink.start_stream(100, 100, std::make_shared(pressureBroadcaster)); QQmlApplicationEngine engine; - const QUrl url = QUrl::fromLocalFile(QDir::current().absoluteFilePath("DAC-Qt/Main.qml")); + QString path = QString::fromStdString(std::string(BUILD_DIR) + "/../DAC-Qt/Main.qml"); + const QUrl url = QUrl::fromLocalFile(QDir::current().absoluteFilePath(path)); QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); @@ -60,9 +61,11 @@ int main(int argc, char *argv[]) } Config read_config() { - QString path = QCoreApplication::applicationDirPath() + "/config.json"; - spdlog::info("Trying to open config file at: {}", path.toStdString()); +// CMAKE_CURRENT_BINARY_DIR + std::cout << "Build directory: " << BUILD_DIR << std::endl; + QString path = QString::fromStdString(std::string(BUILD_DIR) + "/config.json"); QFile f(path); + // QFile f(path); // QFile f("config.json"); if(f.open(QIODevice::ReadOnly)) { diff --git a/Config.h b/tempConfig.h similarity index 100% rename from Config.h rename to tempConfig.h diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..19a1f29 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.16) + +project(DAC-Qt_tests) + +SET(CMAKE_CXX_STANDARD 11) +SET(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_subdirectory("${CMAKE_SOURCE_DIR}/extern/googletest" "extern/googletest") + +add_executable( + DAC-Qt_tests + broadcaster-tests.cpp + labjacksink-tests.cpp +) + +if(WIN32) + target_include_directories(DAC-Qt_tests PRIVATE "C:/Program Files (x86)/LabJack/Drivers") + target_link_libraries(DAC-Qt_tests PRIVATE "C:/Program Files (x86)/LabJack/Drivers/64bit/LabJackM.lib") +else() + target_link_libraries(DAC-Qt_tests PRIVATE LabJackM) +endif() + +target_link_libraries(DAC-Qt_tests + PRIVATE libDAC-Qt GTest::gtest_main +) + +gtest_discover_tests(DAC-Qt_tests) \ No newline at end of file diff --git a/tests/broadcaster-tests.cpp b/tests/broadcaster-tests.cpp new file mode 100644 index 0000000..5fa49e5 --- /dev/null +++ b/tests/broadcaster-tests.cpp @@ -0,0 +1,46 @@ +#include + +#include "../broadcast/Broadcaster.h" +#include "../broadcast/Sink.h" +#include "../models/ForceData.h" + +class BroadcasterTest : public testing::Test{ +protected: + std::shared_ptr> broadcaster = Broadcaster::getInstance(); + std::shared_ptr> forceBroadcaster = Broadcaster::getInstance(); +}; + +TEST_F(BroadcasterTest, ShouldBroadcast) { + TelemetryData data; + data.label = "Test"; + broadcaster->subscribe([](const TelemetryData *data){ + EXPECT_NE(data, nullptr); + ASSERT_EQ(data->label, "Test"); + }); + + broadcaster->broadcastBase(&data); +} + +TEST_F(BroadcasterTest, SinkShouldSend) { + TelemetryData data; + data.label = "Test"; + broadcaster->subscribe([](const TelemetryData *data){ + EXPECT_NE(data, nullptr); + ASSERT_EQ(data->label, "Test"); + }); + Sink sink({broadcaster}); + + sink.sendData({&data}); +} + +TEST_F(BroadcasterTest, SinkShouldNullptr) { + TelemetryData data; + data.label = "Type test"; + auto str_broadcaster = Broadcaster::getInstance(); + str_broadcaster->subscribe([](const std::string *data){ + ASSERT_EQ(data, nullptr); + }); + + Sink sink({str_broadcaster}); + sink.sendData({&data}); +} \ No newline at end of file diff --git a/tests/labjacksink-tests.cpp b/tests/labjacksink-tests.cpp new file mode 100644 index 0000000..b50c813 --- /dev/null +++ b/tests/labjacksink-tests.cpp @@ -0,0 +1,9 @@ +#include + +#include "../sinks/LabJackSink.h" + +TEST(LabJackSinkTest, OpensDevice) { + LabJackSink sink; + sink.open(0, "-2", 0); + ASSERT_EQ(sink.serial_number(), -2); +} \ No newline at end of file From 75d4320dcf03d25460ea249a4cf838cf8daba3c8 Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 27 Apr 2024 20:19:22 -0700 Subject: [PATCH 11/12] Small Fix --- .gitignore | 1 + Config.h.in | 32 ++++++++++++++++++-------------- main.cpp | 11 ++++++----- tempConfig.h | 36 ++++++++++++++++-------------------- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index 6b94391..09f4f9f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ Thumbs.db *.rc /.qmake.cache /.qmake.stash +.vscode # qtcreator generated files *.pro.user* diff --git a/Config.h.in b/Config.h.in index 2864b69..a907446 100644 --- a/Config.h.in +++ b/Config.h.in @@ -1,20 +1,24 @@ -#pragma once +#ifndef DAC_QT_CONFIG_H +#define DAC_QT_CONFIG_H -#define BUILD_DIR "@BUILD_DIR@" +#include class Config { +public: + class LabJackConfig { public: - struct LabJackConfig { - std::string identifier; - std::string device_type; - std::string connection_type; - }; - - struct InfluxConfig { - std::string address; - std::string token; - }; + std::string identifier; + std::string device_type; + std::string connection_type; + }; + class InfluxConfig { + public: + std::string address; + std::string token; + }; - LabJackConfig labjack; - InfluxConfig influx; + LabJackConfig labjack; + InfluxConfig influx; }; + +#endif //DAC_QT_CONFIG_H diff --git a/main.cpp b/main.cpp index 1626a3a..43bb803 100644 --- a/main.cpp +++ b/main.cpp @@ -50,7 +50,8 @@ int main(int argc, char *argv[]) // lj_sink.start_stream(100, 100, std::make_shared(pressureBroadcaster)); QQmlApplicationEngine engine; - QString path = QString::fromStdString(std::string(BUILD_DIR) + "/../DAC-Qt/Main.qml"); + // QString path = QString::fromStdString(std::string(BUILD_DIR) + "/../DAC-Qt/Main.qml"); + QString path = QString::fromStdString("./DAC-Qt/Main.qml"); const QUrl url = QUrl::fromLocalFile(QDir::current().absoluteFilePath(path)); QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, @@ -62,12 +63,12 @@ int main(int argc, char *argv[]) Config read_config() { // CMAKE_CURRENT_BINARY_DIR - std::cout << "Build directory: " << BUILD_DIR << std::endl; - QString path = QString::fromStdString(std::string(BUILD_DIR) + "/config.json"); - QFile f(path); + // std::cout << "Build directory: " << BUILD_DIR << std::endl; + // QString path = QString::fromStdString(std::string(BUILD_DIR) + "/config.json"); + // QFile f(path); // QFile f(path); - // QFile f("config.json"); + QFile f("config.json"); if(f.open(QIODevice::ReadOnly)) { Config config; QJsonDocument json = QJsonDocument::fromJson(f.readAll()); diff --git a/tempConfig.h b/tempConfig.h index a907446..2cf7f33 100644 --- a/tempConfig.h +++ b/tempConfig.h @@ -1,24 +1,20 @@ -#ifndef DAC_QT_CONFIG_H -#define DAC_QT_CONFIG_H +// #pragma once -#include +// #define BUILD_DIR "@BUILD_DIR@" -class Config { -public: - class LabJackConfig { - public: - std::string identifier; - std::string device_type; - std::string connection_type; - }; - class InfluxConfig { - public: - std::string address; - std::string token; - }; +// class Config { +// public: +// struct LabJackConfig { +// std::string identifier; +// std::string device_type; +// std::string connection_type; +// }; - LabJackConfig labjack; - InfluxConfig influx; -}; +// struct InfluxConfig { +// std::string address; +// std::string token; +// }; -#endif //DAC_QT_CONFIG_H +// LabJackConfig labjack; +// InfluxConfig influx; +// }; \ No newline at end of file From 9daa5daeba4e8bfc0d173c5f49be8f3d1d26e6ef Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 27 Apr 2024 20:19:34 -0700 Subject: [PATCH 12/12] Small Fix --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 43bb803..59cf24c 100644 --- a/main.cpp +++ b/main.cpp @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; // QString path = QString::fromStdString(std::string(BUILD_DIR) + "/../DAC-Qt/Main.qml"); - QString path = QString::fromStdString("./DAC-Qt/Main.qml"); + QString path = QString::fromStdString("../DAC-Qt/Main.qml"); const QUrl url = QUrl::fromLocalFile(QDir::current().absoluteFilePath(path)); QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); },