### Install Service Target, Header, and Docs (CMake) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/CMakeLists.txt This CMake snippet defines installation rules. It installs the 'droneforge-crsf-service' executable to the 'bin' directory, the 'telemetry_client.h' header to 'include/droneforge-crsf', and the 'README.md' file to the root installation directory. ```cmake install(TARGETS droneforge-crsf-service RUNTIME DESTINATION bin ) install(FILES src/client/telemetry_client.h DESTINATION include/droneforge-crsf ) install(FILES README.md DESTINATION . ) ``` -------------------------------- ### Singleton Pattern for CRSF Telemetry Access (C++) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Example C++ code demonstrating the use of the Singleton pattern for global access to the DroneForge CRSF Service telemetry data via TelemetryStore. ```cpp #include "client/telemetry_client.h" using namespace droneforge::telemetry; // Initialize once TelemetryStore::getInstance().connect(); // Use anywhere in your application auto attitude = TelemetryStore::getInstance().getAttitude(); if (attitude) { // Process attitude data } ``` -------------------------------- ### Basic Client Integration for CRSF Telemetry (C++) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Example C++ code demonstrating basic integration with the DroneForge CRSF Service client interface. Connects to the service and retrieves attitude, battery, and link data. ```cpp #include "client/telemetry_client.h" using namespace droneforge::telemetry; int main() { TelemetryClient client; if (!client.connect()) { std::cerr << "Failed to connect to CRSF service" return 1; } while (client.isConnected()) { // Get attitude data auto attitude = client.getAttitude(); if (attitude) { std::cout << "Pitch: " << attitude->pitch << "°, " << "Roll: " << attitude->roll << "°, " << "Yaw: " << attitude->yaw << "°" << std::endl; } // Get battery data auto battery = client.getBattery(); if (battery) { std::cout << "Voltage: " << battery->voltage << "V, " << "Current: " << battery->current << "A, " << "Remaining: " << (int)battery->remaining_percent << "%" << std::endl; } // Get link statistics auto link = client.getLink(); if (link) { std::cout << "RSSI: " << link->uplink_rssi << "dBm, " << "LQ: " << (int)link->link_quality << "%" << std::endl; } std::this_thread::sleep_for(std::chrono::milliseconds(100)); } return 0; } ``` -------------------------------- ### Run DroneForge CRSF Service (Windows) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Command to run the DroneForge CRSF Service on Windows, specifying the serial port (COM) and baud rate. Example uses COM3 and 420000 baud. ```cmd droneforge-crsf-service.exe COM3 420000 ``` -------------------------------- ### Run DroneForge CRSF Service (Linux) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Command to run the DroneForge CRSF Service on Linux, specifying the serial port and baud rate. Example uses /dev/ttyUSB0 and 420000 baud. ```bash ./droneforge-crsf-service /dev/ttyUSB0 420000 ``` -------------------------------- ### Project Setup and Compiler Flags (CMake) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/CMakeLists.txt This section of the CMake script defines the project name, version, and languages. It also enables the export of compile commands for better IDE integration. Platform-specific compiler definitions and options are set for Windows and macOS to ensure compatibility and adherence to standards. ```cmake project(droneforge-crsf-service VERSION 1.0.0 LANGUAGES CXX) # Enable compile commands export set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Global Windows-specific compiler definitions if(WIN32) add_compile_definitions( NOMINMAX # Prevent Windows.h from defining min/max macros WIN32_LEAN_AND_MEAN # Reduce Windows.h bloat _CRT_SECURE_NO_WARNINGS # Suppress MSVC security warnings ) # Global Windows-specific compile options add_compile_options( /permissive- # Strict C++ conformance /Zc:__cplusplus # Enable correct __cplusplus macro value ) elseif(APPLE) # macOS-specific compiler definitions and options add_compile_definitions( _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES # Enable removed C++17 features for compatibility ) # macOS-specific compile options add_compile_options( -Wno-deprecated-declarations # Suppress deprecation warnings -stdlib=libc++ # Use libc++ standard library -mmacosx-version-min=10.15 # Minimum macOS version ) # macOS-specific link options add_link_options( -stdlib=libc++ ) endif() ``` -------------------------------- ### Platform Detection and vcpkg Toolchain Setup (CMake) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/CMakeLists.txt This CMake script detects the operating system (Windows, Linux, macOS) and attempts to locate the vcpkg toolchain file. It prioritizes specific paths and environment variables for vcpkg, providing warnings or status messages based on availability. This ensures consistent build environments across different platforms. ```cmake cmake_minimum_required(VERSION 3.20 FATAL_ERROR) # Platform detection if(WIN32) set(PLATFORM_NAME "Windows") set(PLATFORM_SUFFIX "win") elseif(UNIX AND NOT APPLE) set(PLATFORM_NAME "Linux") set(PLATFORM_SUFFIX "linux") elseif(APPLE) set(PLATFORM_NAME "macOS") set(PLATFORM_SUFFIX "macos") endif() # Platform-specific vcpkg toolchain file detection if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) if(WIN32) # Windows - vcpkg is essential set(VCPKG_CANDIDATES "C:/dev/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake" "C:/vcpkg/scripts/buildsystems/vcpkg.cmake" "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" ) foreach(VCPKG_PATH ${VCPKG_CANDIDATES}) if(EXISTS "${VCPKG_PATH}") set(CMAKE_TOOLCHAIN_FILE "${VCPKG_PATH}" CACHE STRING "") message(STATUS "Found vcpkg toolchain: ${VCPKG_PATH}") break() endif() endforeach() if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) message(WARNING "vcpkg toolchain not found on Windows. Some dependencies may not be available.") endif() else() # Linux/Unix - vcpkg is optional, prefer system packages set(VCPKG_CANDIDATES "/usr/local/vcpkg/scripts/buildsystems/vcpkg.cmake" "$ENV{HOME}/vcpkg/scripts/buildsystems/vcpkg.cmake" "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" "/opt/vcpkg/scripts/buildsystems/vcpkg.cmake" ) foreach(VCPKG_PATH ${VCPKG_CANDIDATES}) if(EXISTS "${VCPKG_PATH}") set(CMAKE_TOOLCHAIN_FILE "${VCPKG_PATH}" CACHE STRING "") message(STATUS "Found vcpkg toolchain: ${VCPKG_PATH}") break() endif() endforeach() if(NOT DEFINED CMAKE_TOOLCHAIN_FILE) message(STATUS "vcpkg toolchain not found. Using system packages (recommended for Linux).") endif() endif() endif() ``` -------------------------------- ### Clone DroneForge CRSF Service Repository Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Instructions for cloning the DroneForge CRSF Service repository using Git. This is the initial step for building and using the service. ```bash git clone https://github.com/your-org/droneforge-crsf-service.git cd droneforge-crsf-service ``` -------------------------------- ### Platform-Specific Library Linking (CMake) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/CMakeLists.txt This CMake snippet handles platform-specific library linking for the 'droneforge-crsf-service'. On Windows (WIN32), it links 'setupapi'. On other platforms, it links 'pthread' and 'rt'. ```cmake if(WIN32) target_link_libraries(droneforge-crsf-service PRIVATE setupapi) else() target_link_libraries(droneforge-crsf-service PRIVATE pthread rt) endif() ``` -------------------------------- ### Build DroneForge CRSF Service on Windows Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Build instructions for the DroneForge CRSF Service on Windows using CMake and Visual Studio. Requires a C++17 compatible compiler and CMake 3.16+. ```cmd mkdir build && cd build cmake .. -G "Visual Studio 16 2019" cmake --build . --config Release ``` -------------------------------- ### Build DroneForge CRSF Service on Linux/macOS Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Build instructions for the DroneForge CRSF Service on Linux and macOS using CMake and Make. Requires a C++17 compatible compiler and CMake 3.16+. ```bash mkdir build && cd build cmake .. make -j$(nproc) ``` -------------------------------- ### TelemetryClient Methods Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md This section details the methods available in the TelemetryClient class for interacting with telemetry data. ```APIDOC ## TelemetryClient Class Methods ### `bool connect()` **Description**: Connects to the shared memory to establish a connection for telemetry data. **Method**: GET **Endpoint**: N/A (Client-side method) ### `void disconnect()` **Description**: Disconnects from the shared memory, releasing resources. **Method**: POST **Endpoint**: N/A (Client-side method) ### `bool isConnected()` **Description**: Checks the current connection status to the shared memory. **Method**: GET **Endpoint**: N/A (Client-side method) ### `std::optional getAttitude()` **Description**: Retrieves the latest attitude data. **Method**: GET **Endpoint**: N/A (Client-side method) ### `std::optional getBattery()` **Description**: Retrieves the latest battery data. **Method**: GET **Endpoint**: N/A (Client-side method) ### `std::optional getLink()` **Description**: Retrieves the latest link statistics. **Method**: GET **Endpoint**: N/A (Client-side method) ### `bool hasNewData()` **Description**: Checks if new telemetry data is available since the last call. **Method**: GET **Endpoint**: N/A (Client-side method) ``` -------------------------------- ### Dependency Management for fmt Library (CMake) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/CMakeLists.txt This CMake code handles the finding and integration of the 'fmt' library. It first attempts to find it using `find_package`. If not found, it tries using `pkgconfig` on Unix-like systems. If 'fmt' is still not located, a message is logged indicating that a direct target will be used, implying a fallback mechanism. ```cmake # Dependencies set(BUILD_TESTS OFF) set(BUILD_SHARED_LIBS OFF) # fmt configuration - simplified approach find_package(fmt QUIET) if(NOT fmt_FOUND) # Try pkgconfig on Linux if(UNIX AND NOT APPLE) find_package(PkgConfig QUIET) if(PkgConfig_FOUND) pkg_check_modules(FMT fmt) endif() endif() # If still not found, we'll create a simple target if(NOT FMT_FOUND) message(STATUS "fmt not found via package manager, will use target directly") endif() endif() ``` -------------------------------- ### Performance Metrics Callback Registration (C++) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md This C++ snippet shows how to register a callback function to receive performance metrics from the service. The callback receives the thread name and its processing time in milliseconds, which can be used for logging or monitoring. ```cpp callbacks.onPerformanceMetrics = [](const std::string& threadName, float processingTimeMs) { std::cout << threadName << " thread: " << processingTimeMs << "ms" << std::endl; }; ``` -------------------------------- ### Link fmt Library Conditionally (CMake) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/CMakeLists.txt This snippet demonstrates conditional linking of the 'fmt' library in CMake. It first checks for 'fmt::fmt' provided by a package manager like Conan or vcpkg. If not found, it falls back to using system-provided 'fmt' via pkgconfig. If neither is found, a warning is issued. ```cmake if(fmt_FOUND) target_link_libraries(droneforge-crsf-service PRIVATE fmt::fmt) message(STATUS "Using fmt::fmt") elseif(FMT_FOUND) target_include_directories(droneforge-crsf-service PRIVATE ${FMT_INCLUDE_DIRS}) target_link_libraries(droneforge-crsf-service PRIVATE ${FMT_LIBRARIES}) message(STATUS "Using system fmt via pkgconfig") else() # Fallback - assume fmt is available somehow message(WARNING "fmt not found, hoping it's available at link time") endif() ``` -------------------------------- ### Executable Target and Build Configuration (CMake) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/CMakeLists.txt This CMake script defines the source and header files for the 'droneforge-crsf-service' executable. It then adds the executable target using `add_executable`. Finally, it sets the C++ standard to C++17 and enforces that the standard is required for the build, ensuring modern C++ features are utilized. ```cmake # Include directories include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src) # Source files set(SOURCES src/main.cpp src/serial/serial.cpp src/crsf/crsf_manager.cpp src/crsf/crsf.cpp ) # Headers set(HEADERS src/common/types.h src/common/error.h src/common/static_vector.h src/common/thread_name.h src/common/scope.h src/common/compatibility.h src/serial/serial.h src/crsf/crsf_manager.hpp src/crsf/crsf.h src/crsf/frame.h src/crsf/parameter.h src/crsf/protocol.h src/crsf/crc.h src/client/telemetry_client.h ) # Create executable add_executable(droneforge-crsf-service ${SOURCES} ${HEADERS}) # Set C++ standard set_property(TARGET droneforge-crsf-service PROPERTY CXX_STANDARD 17) set_property(TARGET droneforge-crsf-service PROPERTY CXX_STANDARD_REQUIRED ON) ``` -------------------------------- ### Data Structures Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Defines the structure of the data objects used for telemetry. ```APIDOC ## Data Structures ### `AttitudeData` **Description**: Represents the attitude information of the vehicle. **Fields**: - **pitch** (float) - Pitch angle in degrees - **roll** (float) - Roll angle in degrees - **yaw** (float) - Yaw angle in degrees - **timestamp_us** (uint64_t) - Microseconds since epoch ### `BatteryData` **Description**: Represents the battery status. **Fields**: - **voltage** (float) - Voltage in volts - **current** (float) - Current in amps - **capacity** (float) - Capacity in mAh - **remaining_percent** (uint8_t) - Remaining battery percentage - **timestamp_us** (uint64_t) - Microseconds since epoch ### `LinkData` **Description**: Represents the wireless link statistics. **Fields**: - **uplink_rssi** (float) - Uplink signal strength in dBm - **downlink_rssi** (float) - Downlink signal strength in dBm - **link_quality** (uint8_t) - Link quality percentage - **snr** (int8_t) - Signal-to-noise ratio in dB - **timestamp_us** (uint64_t) - Microseconds since epoch ``` -------------------------------- ### Compiler Flags Configuration (CMake) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/CMakeLists.txt This CMake code configures compiler flags for the 'droneforge-crsf-service'. For MSVC, it sets warning level to 4 and suppresses specific deprecation warnings. For other compilers, it enables common warnings (-Wall, -Wextra, -Wpedantic) and suppresses deprecation warnings. ```cmake if(MSVC) target_compile_options(droneforge-crsf-service PRIVATE /W4 /wd4996 # Disable deprecation warnings for strncpy etc. ) else() target_compile_options(droneforge-crsf-service PRIVATE -Wall -Wextra -Wpedantic -Wno-deprecated-declarations # Suppress deprecation warnings ) endif() ``` -------------------------------- ### Validate Telemetry Data Freshness (C++) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md This snippet demonstrates how to check the freshness of telemetry data by comparing the data's timestamp with the current time. It assumes the data object has a 'timestamp_us' member and a 'getCurrentTimestamp()' function is available. The check is performed in milliseconds, with a threshold of 100ms for fresh data. ```cpp auto battery = client.getBattery(); if (battery) { auto age_ms = (getCurrentTimestamp() - battery->timestamp_us) / 1000; if (age_ms < 100) { // Data is fresh (< 100ms old) // Use battery data } } ``` -------------------------------- ### BatteryData Structure Definition (C++) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Defines the BatteryData structure, containing electrical properties like voltage, current, capacity, remaining percentage, and a timestamp. This structure is used to report battery status. ```cpp struct BatteryData { float voltage; // volts float current; // amps float capacity; // mAh uint8_t remaining_percent; // % uint64_t timestamp_us; // microseconds since epoch }; ``` -------------------------------- ### LinkData Structure Definition (C++) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Defines the LinkData structure, which encapsulates radio link quality metrics including uplink and downlink RSSI, link quality percentage, signal-to-noise ratio (SNR), and a timestamp. This is used for monitoring communication link status. ```cpp struct LinkData { float uplink_rssi; // dBm float downlink_rssi; // dBm uint8_t link_quality; // % int8_t snr; // dB uint64_t timestamp_us; // microseconds since epoch }; ``` -------------------------------- ### AttitudeData Structure Definition (C++) Source: https://github.com/droneforge/nimbus_sdk/blob/main/droneforge-crsf-service/README.md Defines the AttitudeData structure, which holds pitch, roll, and yaw in degrees, along with a timestamp in microseconds since the epoch. This structure is used to represent the orientation of a device. ```cpp struct AttitudeData { float pitch; // degrees float roll; // degrees float yaw; // degrees uint64_t timestamp_us; // microseconds since epoch }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.