#pragma once #include #include #include #include // Forward declarations struct HidDeviceInfo; struct HidReport; struct HidReportDescriptorItem; /** * @brief Class for analyzing HID devices and their reports * * This class provides functionality to: * 1. Enumerate and detect HID devices * 2. Connect to specific HID devices * 3. Read and parse HID report descriptors * 4. Read raw HID reports and analyze their contents */ class HidDeviceAnalyzer { public: HidDeviceAnalyzer(); ~HidDeviceAnalyzer(); /** * @brief Initialize the HID device analyzer * * @return true if initialization was successful * @return false if initialization failed */ bool Initialize(); /** * @brief Shutdown the HID device analyzer */ void Shutdown(); /** * @brief Enumerate all HID devices and return their information * * @param filterVendorId Optional vendor ID to filter devices (0 = no filter) * @return std::vector List of HID devices */ std::vector EnumerateHidDevices(uint16_t filterVendorId = 0); /** * @brief Open a specific HID device * * @param devicePath Path to the HID device * @return true if the device was opened successfully * @return false if the device could not be opened */ bool OpenDevice(const std::string& devicePath); /** * @brief Close the currently open HID device */ void CloseDevice(); /** * @brief Check if a device is currently open * * @return true if a device is open * @return false if no device is open */ bool IsDeviceOpen() const; /** * @brief Get the report descriptor for the currently open device * * @return std::vector The parsed report descriptor items */ std::vector GetReportDescriptor(); /** * @brief Read a report from the device * * @param reportId The report ID to read (0 = default report) * @return HidReport The read report */ HidReport ReadReport(uint8_t reportId = 0); /** * @brief Read multiple reports from the device * * @param count Number of reports to read * @param reportId The report ID to read (0 = default report) * @return std::vector The read reports */ std::vector ReadReports(int count, uint8_t reportId = 0); /** * @brief Print a human-readable description of the report descriptor */ void PrintReportDescriptor(); /** * @brief Print a human-readable description of a report * * @param report The report to print */ void PrintReport(const HidReport& report); /** * @brief Analyze a series of reports to identify patterns and potential IMU data * * @param reports The reports to analyze */ void AnalyzeReports(const std::vector& reports); private: // Platform-specific device handle void* m_deviceHandle; // Device information std::string m_devicePath; std::string m_deviceName; uint16_t m_vendorId; uint16_t m_productId; // Report descriptor std::vector m_rawReportDescriptor; // Internal methods for parsing report descriptors void ParseReportDescriptor(); // Flag to track initialization state bool m_initialized; }; /** * @brief Structure to hold HID device information */ struct HidDeviceInfo { std::string path; // Device path for opening the device std::string name; // Device name/description uint16_t vendorId; // Vendor ID uint16_t productId; // Product ID std::string serialNumber; // Serial number (if available) std::string manufacturer; // Manufacturer name (if available) std::string product; // Product name (if available) }; /** * @brief Structure to hold a HID report */ struct HidReport { uint8_t reportId; // Report ID std::vector data; // Raw report data size_t dataLength; // Length of the data }; /** * @brief Structure to hold a HID report descriptor item */ struct HidReportDescriptorItem { uint8_t tag; // Item tag uint8_t type; // Item type uint8_t size; // Item size std::vector data; // Item data // Parsed information std::string description; // Human-readable description };