diff --git a/.gitignore b/.gitignore index c7f3f6a..09f4f9f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ Thumbs.db *.rc /.qmake.cache /.qmake.stash +.vscode # qtcreator generated files *.pro.user* @@ -74,3 +75,4 @@ CMakeLists.txt.user* .idea/ cmake-build-debug/ +build/ \ No newline at end of file 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 86402b8..3479dc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,22 +1,70 @@ cmake_minimum_required(VERSION 3.16) - project(DAC-Qt VERSION 0.1 LANGUAGES CXX) -set(CMAKE_STANDARD_CXX 14) +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) +# 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}") +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") +# 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) -find_package(Qt6 6.4 REQUIRED COMPONENTS Quick Charts) -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() +qt_policy(SET QTP0001 NEW) +# Define library target if tests are enabled 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 @@ -29,56 +77,134 @@ if(PACKAGE_TESTS) ) endif() +# Define executable target qt_add_executable(appDAC-Qt + MANUAL_FINALIZATION main.cpp + # Add other source files as needed ) -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 - SOURCES sinks/LabJackSinkStrategy.h - SOURCES sinks/ColdFlowSinkStrategy.cpp sinks/ColdFlowSinkStrategy.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 -) - +# 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() - 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() +# 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::Quick Qt6::Charts LabJackM spdlog::spdlog InfluxData::InfluxDB + PRIVATE + Qt6::Core + Qt6::Widgets + Qt6::Charts + Qt6::Quick + spdlog::spdlog + 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 ) -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 . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} -) +) \ No newline at end of file diff --git a/Config.h b/Config.h.in similarity index 100% rename from Config.h rename to Config.h.in diff --git a/README.md b/README.md index 3a74782..a236f3b 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,174 @@ Dependencies: Running: 1. Build and run in Qt Creator + +## 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 .. +make +export DYLD_LIBRARY_PATH=/usr/local/lib +./appDAC-Qt.app/Contents/MacOS/appDAC-Qt + +*restart terminal* + +## 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/ + +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``` +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. +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. + +```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``` +```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 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``` + +```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``` + + +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 +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/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/install.sh b/install.sh new file mode 100755 index 0000000..009668f --- /dev/null +++ b/install.sh @@ -0,0 +1,137 @@ +#!/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 + 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!' + + if command -v conan &> /dev/null; 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 + 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 + + 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 + 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 diff --git a/main.cpp b/main.cpp index 67080fd..4af2e97 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" @@ -20,7 +22,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(); @@ -79,10 +82,10 @@ int main(int argc, char *argv[]) lj_sink.openS(config.labjack.device_type, config.labjack.identifier, config.labjack.connection_type); lj_sink.start_stream(1, 10, coldFlowStrategy); - QApplication app(argc, argv); - QQmlApplicationEngine engine; - const QUrl url(u"qrc:/DAC-Qt/Main.qml"_qs); + // 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); }, Qt::QueuedConnection); @@ -92,6 +95,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); + // QFile f(path); + QFile f("config.json"); if(f.open(QIODevice::ReadOnly)) { Config config; diff --git a/sinks/LabJackSink.cpp b/sinks/LabJackSink.cpp index 136367d..457466f 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/tempConfig.h b/tempConfig.h new file mode 100644 index 0000000..2cf7f33 --- /dev/null +++ b/tempConfig.h @@ -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; +// }; \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9848098..19a1f29 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,4 +24,4 @@ target_link_libraries(DAC-Qt_tests PRIVATE libDAC-Qt GTest::gtest_main ) -gtest_discover_tests(DAC-Qt_tests) +gtest_discover_tests(DAC-Qt_tests) \ No newline at end of file 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/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 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..bc55362 --- /dev/null +++ b/windows_install.ps1 @@ -0,0 +1,122 @@ +# 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==1.63.0 +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." + +# 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 = Join-Path -Path (Get-Location) -ChildPath "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."