/** * @file * * @author Max Lammers * @author Mamadou Babaei * * @section LICENSE * * Copyright (c) 2020 - 2025 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; class HapticResponse; }// 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, std::string& hapticsResponse, int32_t deviceIndex); /// Destructor cleans up any remaining resources. virtual ~SGDevice(); protected: explicit SGDevice(const IdResponse& idInfo, const std::string& constantsResponse, std::string& hapticsResponse, int32_t deviceIndex); public: SG_NODISCARD virtual const IdResponse& GetDeviceInfo() const; /// Update this device's index in the DeviceScanner list, and generate a new IpcAddress. virtual void SetDeviceIndex(int32_t deviceIndex); SG_NODISCARD virtual int32_t GetDeviceIndex() const; protected: void SetHapticResponse(HapticResponse& response); SG_NODISCARD HapticResponse& GetHapticResponse(); virtual void RegenerateAddresses(int32_t deviceIndex); SG_NODISCARD const std::string& GetConstantsString() const; void SetConstantsString(const std::string& constants) const; SG_NODISCARD const IdResponse& GetIDResponse() const; void SetIDResponse(const IdResponse& idResp) const; public: /// Check if this device's connection has the same address a port on the system. SG_NODISCARD virtual bool SameAddress(const PortInfo& port) const; /// Check if this device's connection is still active. SG_NODISCARD virtual bool IsConnected() const; /// End any existing connection and link this device to a new connection. virtual void ReConnect(std::shared_ptr newComm); /// Update the Packets/Per/Second of this SGDevice. virtual void UpdatePps(double deltaTime); /// Retrieve the IPC Address of this SG Device SG_NODISCARD virtual const std::string& GetIpcAddress() const; /// Retrieve the IPC string for deviceInfo. SG_NODISCARD virtual std::string GetDeviceString() const; virtual void StopUpdating(); virtual std::shared_ptr GetConnection(); virtual void SetDeviceDataUpdates(bool bEnabled); virtual void UpdateConstants(const std::string& newConstants); virtual int32_t GetPacketsPerSecondReceived(); };