/** * @file * * @author Max Lammers * @author Mamadou Babaei * * @section LICENSE * * Copyright (c) 2020 - 2026 SenseGlove * * @section DESCRIPTION * * Contains internal enumerators and classes for raw byte communications with * Sense Glove Devices. */ #pragma once #include #include #include #include namespace SGCore { namespace Util { /// Indices to access DeviceList data in Shared Memory. enum class EListFormat : uint8_t { Connected = 0, PacketsPerSecondGot, DeviceType, ConstantsString, Address, ConnectionType, PacketsPerSecondSent, IPCChannels, All, }; /// Indices to access Sensor Data in Shared Memory. enum class ESensorFormat : uint8_t { Sensors }; class SGCORE_API Communications; }// namespace Util }// namespace SGCore /// "Database" containing communications bytes and conversions. class SGCORE_API SGCore::Util::Communications { public: /// Byte indicating the start of a new command. [[nodiscard]] static char GetCommandOpen(); /// Byte indicating the end of a command. [[nodiscard]] static char GetCommandClose(); /// Byte indicating the start of a new sensor data package. [[nodiscard]] static char GetSenseOpen(); /// Byte indicating the end of a sensor data package. [[nodiscard]] static char GetSenseClose(); /// Denotes a block section of a DeviceList section. [[nodiscard]] static char GetListDelimiter(); /// ':' - Used to split a set of different constant values into individual groups. [[nodiscard]] static char GetSectionDelimiter(); /// ';' - Used to separate individual values [[nodiscard]] static char GetColumnDelimiter(); /// '|' - Used to group a set of values, for example per finger. [[nodiscard]] static char GetRowDelimiter(); /// Convert a value between 0..100 to a Sense Glove char/byte. [[nodiscard]] static char ToSGByte(int32_t level); /// Convert a value between 0..1 to a Sense Glove char/byte. [[nodiscard]] static char FloatToSGByte(float level01); /// Encode a series of floating-point values into a SenseGlove string /// An array of values that is to be encoded into multiple characters /// The length of the message. /// If values01 is not long enough to reach messageLength, pad valued with this /// [[nodiscard]] static std::string ToSGBytes(const std::vector& values01, int32_t messageLength, float fallbackValue = 0.0f); /// Encode a single value into a character into a range of bytes. Will alsways clamp! /// /// /// /// /// /// [[nodiscard]] static int32_t EncodeLinear(float value, float minValue, float maxValue, int32_t minByte = 1, int32_t maxByte = 101); /// Convert a decoded byte back into its original floating value. Useful for decoding. /// /// /// /// /// /// [[nodiscard]] static float DecodeLinear(int byteFromChar, float minValue, float maxValue, int32_t minByte = 1, int32_t maxByte = 101); public: Communications() = delete; virtual ~Communications() = delete; };