/** * @file * * @author Max Lammers * @author Mamadou Babaei * * @section LICENSE * * Copyright (c) 2020 - 2023 SenseGlove * * @section DESCRIPTION * * Class that contains data of a Sense Glove device that has been detected on * the system. * Has an interchangeable communications component, which it uses to exchange * data based on its transmit mode. */ #pragma once #include #include #include #include "Platform.hpp" #include "PortInfo.hpp" /* Do not forward declare this, or else we'll encounter LINK2019 build error on MSVC */ #include "TransmissionMode.hpp" namespace SGConnect { class Connection; class IdResponse; class SGDevice; }// namespace SGConnect class SGConnect::SGDevice { public: /// Extract firmware main/sub versions from a constants string static void ExtractFirmware(const std::string& constantsString, int32_t& out_mainVersion, int32_t& out_subVersion); /// Determine the communications mode based on this device type and firmware version. static ETransmissionMode CommunicationMode(int32_t deviceType, int32_t mainFirmwareVersion, int32_t subFirmwareVersion); /// Convert a TransmissionMode into a string for debugging purposes. static std::string ToString(ETransmissionMode transmissionMode); private: struct Impl; std::unique_ptr Pimpl; public: /// The default constructor. SGDevice(); /// Create a new SGDevice based on a connection and its responses. SGDevice(std::shared_ptr startComm, const IdResponse& idInfo, const std::string& constantsResponse, int32_t deviceIndex); /// Destructor cleans up any remaining resources. virtual ~SGDevice(); public: #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ const IdResponse& GetDeviceInfo() const; /// Update this device's index in the DeviceScanner list, and generate a new IpcAddress. void SetDeviceIndex(int32_t deviceIndex); /// Check if this device's connection has the same address a port on the system. #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ bool SameAddress(const PortInfo& port) const; /// Check if this device's connection is still active. #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ bool IsConnected() const; /// End any existing connection and link this device to a new connection. void ReConnect(std::shared_ptr newComm); /// Update the Packets/Per/Second of this SGDevice. void UpdatePps(double deltaTime); /// Retrieve the IPC Address of this SG Device #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ const std::string& GetIpcAddress() const; /// Retrieve the IPC string for deviceInfo. #if !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) [[nodiscard]] #endif /* !defined ( SENSEGLOVE_UNREAL_ENGINE_PLUGIN ) */ std::string GetDeviceString() const; void StopUpdating(); };