717 lines
24 KiB
C++
717 lines
24 KiB
C++
#pragma once
|
|
|
|
#include <cstdlib>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
using namespace std;
|
|
|
|
static const string SPITID = "#spit#";
|
|
|
|
namespace spit {
|
|
|
|
class Message {
|
|
//----------- Header -----------
|
|
public:
|
|
class Header {
|
|
public:
|
|
static constexpr int BYTESLENGTH = 99;
|
|
Header(const Header &orig);
|
|
Header();
|
|
|
|
private:
|
|
string mID;
|
|
int mVersion{SPITVERSION};
|
|
unsigned char mMessageNumber{};
|
|
int mBytesCount{BYTESLENGTH};
|
|
string mServerId{};
|
|
string mClientId{};
|
|
int mOpFlag{-1};
|
|
int mParseOffset{};
|
|
|
|
public:
|
|
string getSPITID() const { return mID; }
|
|
int getSPITVersion() const { return mVersion; }
|
|
unsigned char getMessageNumber() const { return mMessageNumber; }
|
|
int getBytesCount() const { return mBytesCount; }
|
|
string getServerID() const { return mServerId; }
|
|
string getClientID() const { return mClientId; }
|
|
int getType() const { return mOpFlag; }
|
|
|
|
// Receive
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
// Send
|
|
Header(int p_SPITVersion, int pOpFlag);
|
|
void setMessageNumber(unsigned char messageNumber) { mMessageNumber = messageNumber; }
|
|
void setServerID(string iD) { mServerId = iD; }
|
|
void setClientID(string iD) { mClientId = iD; }
|
|
void setOPFlag(int pOpFlag) { mOpFlag = pOpFlag; }
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- OPPart -----------
|
|
public:
|
|
class OPPart {
|
|
// Members
|
|
protected:
|
|
unique_ptr<Header> mHeader{};
|
|
int mParseOffset{};
|
|
int mBytesCount;
|
|
|
|
public:
|
|
virtual ~OPPart();
|
|
|
|
Header *getHeader() const { return mHeader.get(); }
|
|
int getBytesCount() const { return mBytesCount; }
|
|
void setServerInfoInHeader(string clientId, string serverId) {
|
|
if (!mHeader) {
|
|
return;
|
|
}
|
|
mHeader->setClientID(clientId);
|
|
mHeader->setServerID(serverId);
|
|
}
|
|
void setMessageNumber(uint8_t no) {
|
|
if (!mHeader) {
|
|
return;
|
|
}
|
|
mHeader->setMessageNumber(no);
|
|
}
|
|
|
|
const string getServerID() const {
|
|
if (!mHeader) {
|
|
return "";
|
|
}
|
|
return mHeader->getServerID();
|
|
}
|
|
const string getClientID() const {
|
|
if (!mHeader) {
|
|
return "";
|
|
}
|
|
return mHeader->getClientID();
|
|
}
|
|
|
|
int getType() const {
|
|
if (!mHeader) {
|
|
return -1;
|
|
}
|
|
return mHeader->getType();
|
|
}
|
|
|
|
// Receive
|
|
OPPart(unique_ptr<Header> header, int pOpFlag, int size);
|
|
void setHeader(int opFlag);
|
|
virtual bool parse(const std::vector<char> &message) = 0;
|
|
|
|
// Send
|
|
OPPart(int size);
|
|
virtual bool fillBytes(std::vector<char> &message) = 0;
|
|
};
|
|
|
|
//----------- Message -----------
|
|
|
|
public:
|
|
static constexpr int SPITVERSION = 1;
|
|
|
|
// SPIT_Object value usage
|
|
static constexpr char VALUEUSE_DISCARD = 0x00; // value of SPITObejct is not used
|
|
static constexpr char VALUEUSE_INRANGE = 0x01; // value of SPITOBject in range 0 - 1000000ppm
|
|
static constexpr char VALUEUSE_OVERRIDE = 0x02; // value can be overridden
|
|
|
|
// SPIT Player type
|
|
static constexpr char PLAYERTYPE_MAIN = 0x02;
|
|
static constexpr char PLAYERTYPE_CONTINIOUS = 0x01;
|
|
static constexpr char PLAYERTYPE_DISCRETE = 0x00;
|
|
|
|
// PlayObject value usage
|
|
static constexpr char VALUEFLAG_DIRECT = 0x00; // use the vlue direct
|
|
static constexpr char VALUEFLAG_INCREASE = 0x01; // increase the value
|
|
static constexpr char VALUEFLAG_DECREASE = 0x02; // decrease the value
|
|
|
|
Message() = default;
|
|
|
|
// Members
|
|
private:
|
|
unique_ptr<OPPart> oPPart{};
|
|
|
|
// Receive
|
|
public:
|
|
Message(std::vector<char> message);
|
|
|
|
const Header *getHeader() const { return oPPart->getHeader(); }
|
|
int getType() const {
|
|
if (!oPPart || !oPPart->getHeader()) {
|
|
return -1;
|
|
}
|
|
return oPPart->getHeader()->getType();
|
|
}
|
|
const OPPart *getOPPart() const { return oPPart.get(); }
|
|
template<typename T>
|
|
T &getAs() const { return *reinterpret_cast<T *>(oPPart.get()); }
|
|
|
|
private:
|
|
bool parse(std::vector<char> message);
|
|
|
|
// Send
|
|
public:
|
|
static std::vector<char> createMessage(OPPart & p_OPPart);
|
|
|
|
//------------------------------ Connection ----------------------------------
|
|
|
|
//----------- Connect -----------
|
|
public:
|
|
class Connect : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 1;
|
|
static constexpr int BYTESLENGTH = 304;
|
|
|
|
private:
|
|
string mClientComputerName{};
|
|
string mClientName{};
|
|
string mLoginName{};
|
|
string mLoginPassword{};
|
|
string mServerIp{};
|
|
int mServerPort{};
|
|
|
|
public:
|
|
// Receive
|
|
Connect(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
string getClientComputerName() const { return mClientComputerName; }
|
|
string getClientName() const { return mClientName; }
|
|
string getLoginName() const { return mLoginName; }
|
|
string getLoginPassword() const { return mLoginPassword; }
|
|
string getServerIP() const { return mServerIp; }
|
|
int getServerPort() const { return mServerPort; }
|
|
|
|
// Send
|
|
Connect(string p_ComputerName, string p_ClientName);
|
|
|
|
void setLoginName(string p_LoginName) { mLoginName = p_LoginName; }
|
|
void setLoginPassword(string p_LoginPassword) { mLoginPassword = p_LoginPassword; }
|
|
void setServerIP(string p_ServerIP) { mServerIp = p_ServerIP; }
|
|
void setServerPort(int p_ServerPort);
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- ConnectAnswer -----------
|
|
|
|
class ConnectAnswer : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 2;
|
|
static constexpr int BYTESLENGTH = 137;
|
|
|
|
private:
|
|
string mServerComputerName{};
|
|
string mServerName{};
|
|
bool mConnected{};
|
|
int mStepTime{40}; // ms step size the Server will send play sequences
|
|
|
|
public:
|
|
ConnectAnswer(const ConnectAnswer &orig);
|
|
// Receive
|
|
ConnectAnswer(unique_ptr<Header> header);
|
|
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
const string getServerComputerName() const { return mServerComputerName; }
|
|
const string getServerName() const { return mServerName; }
|
|
bool getConnected() const { return mConnected; }
|
|
int getStepTime() const { return mStepTime; }
|
|
|
|
// Send
|
|
ConnectAnswer();
|
|
void setServerComputerName(string p_ServerComputerName) { mServerComputerName = p_ServerComputerName; }
|
|
void setServerName(string p_ServerName) { mServerName = p_ServerName; }
|
|
void setConnected(bool p_Connected) { mConnected = p_Connected; }
|
|
void setStepTime(int p_StepTime_ms);
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- Disconnect -----------
|
|
|
|
class Disconnect : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 3;
|
|
static constexpr int BYTESLENGTH = 4;
|
|
|
|
Disconnect(const Disconnect &orig);
|
|
// Receive
|
|
Disconnect(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
// Send
|
|
Disconnect();
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- Watchdog -----------
|
|
|
|
class Watchdog : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 8;
|
|
static constexpr int BYTESLENGTH = 4;
|
|
|
|
Watchdog(const Watchdog &orig);
|
|
// Receive
|
|
Watchdog(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
// Send
|
|
Watchdog();
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- WatchdogAnswer -----------
|
|
|
|
class WatchdogAnswer : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 9;
|
|
static constexpr int BYTESLENGTH = 4;
|
|
|
|
// Receive
|
|
WatchdogAnswer(const WatchdogAnswer &orig);
|
|
WatchdogAnswer(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
// Send
|
|
WatchdogAnswer();
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//------------------------------ SPITProject ----------------------------------
|
|
|
|
//----------- ReportProject -----------
|
|
|
|
class ReportProject : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 11;
|
|
static constexpr int BYTESLENGTH = 113;
|
|
|
|
private:
|
|
string mProjectID{};
|
|
string mProjectName{};
|
|
int mFramesPerSecond{1000}; // Frames per second
|
|
|
|
// Receive
|
|
public:
|
|
ReportProject(const ReportProject &orig);
|
|
ReportProject(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
const string getProjectID() const { return mProjectID; }
|
|
const string getProjectName() const { return mProjectName; }
|
|
int getFramesPerSecond() const { return mFramesPerSecond; }
|
|
// Send
|
|
ReportProject(string p_ProjectID, string p_ProjectName);
|
|
|
|
void setFramesPerSecond(const int p_FramesPerSecond) { mFramesPerSecond = p_FramesPerSecond; }
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- CloseProject -----------
|
|
|
|
class CloseProject : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 13;
|
|
static constexpr int BYTESLENGTH = 45;
|
|
|
|
private:
|
|
string mProjectID{};
|
|
|
|
public:
|
|
CloseProject(const CloseProject &orig);
|
|
// Receive
|
|
CloseProject(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
const string getProjectID() const {
|
|
return mProjectID;
|
|
}
|
|
// Send
|
|
CloseProject(string projectID);
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- StartProjectTransfer -----------
|
|
class RequestProjectTransfer : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 15;
|
|
static constexpr int BYTESLENGTH = 4;
|
|
|
|
RequestProjectTransfer(const RequestProjectTransfer &orig);
|
|
// Receive
|
|
RequestProjectTransfer(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
// Send
|
|
RequestProjectTransfer();
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- StartProjectTransfer -----------
|
|
|
|
class StartProjectTransfer : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 16;
|
|
static constexpr int BYTESLENGTH = 4;
|
|
|
|
StartProjectTransfer(const StartProjectTransfer &orig);
|
|
// Receive
|
|
StartProjectTransfer(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
// Send
|
|
StartProjectTransfer();
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- EndProjectTransfer -----------
|
|
class EndProjectTransfer : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 17;
|
|
static constexpr int BYTESLENGTH = 4;
|
|
|
|
EndProjectTransfer(const EndProjectTransfer &orig);
|
|
// Receive
|
|
EndProjectTransfer(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
// Send
|
|
EndProjectTransfer();
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//---------------------------- SPIT_Types ----------------------------------
|
|
|
|
//----------- ReportType -----------
|
|
class ReportType : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 21;
|
|
static constexpr int BYTESLENGTH = 168;
|
|
|
|
private:
|
|
bool mConfirmed{};
|
|
string mSPITTypeID{};
|
|
bool mFixed{};
|
|
bool mServerRemote{};
|
|
bool mServerProjectIndepended{};
|
|
string mTypeGroupName{};
|
|
string mSPITTypeName{};
|
|
uint64_t mDelay{};
|
|
uint64_t mDuration{};
|
|
|
|
public:
|
|
ReportType(const ReportType &orig);
|
|
// Receive
|
|
ReportType(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
bool getConfirmed() const { return mConfirmed; }
|
|
const string getID() const { return mSPITTypeID; }
|
|
bool getFixed() const { return mFixed; }
|
|
bool getServerRemote() const { return mServerRemote; }
|
|
bool getServerProjectIndepended() const { return mServerProjectIndepended; }
|
|
const string getGroupName() const { return mTypeGroupName; }
|
|
const string getName() const { return mSPITTypeName; }
|
|
uint64_t getDelay() const { return mDelay; }
|
|
uint64_t getDuration() const { return mDuration; }
|
|
// Send
|
|
|
|
ReportType();
|
|
void setConfirmed(bool p_Confirmed) { mConfirmed = p_Confirmed; }
|
|
void setID(string iD) { mSPITTypeID = iD; }
|
|
void setFixed(bool p_Fixed) { mFixed = p_Fixed; }
|
|
void setServerRemote(bool p_IsServerRemote) { mServerRemote = p_IsServerRemote; }
|
|
void setServerProjectIndepended(bool p_ProjectIndpended) { mServerProjectIndepended = p_ProjectIndpended; }
|
|
void setGroupName(string p_GroupName) { mTypeGroupName = p_GroupName; }
|
|
void setName(string p_Name) { mSPITTypeName = p_Name; }
|
|
void setDelay(uint64_t p_Delay) { mDelay = p_Delay; }
|
|
void setDuration(uint64_t p_Duration) { mDuration = p_Duration; }
|
|
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- RemoveType -----------
|
|
|
|
class RemoveType : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 23;
|
|
static constexpr int BYTESLENGTH = 45;
|
|
|
|
private:
|
|
string mSPITTypeID{};
|
|
|
|
public:
|
|
RemoveType(const RemoveType &orig);
|
|
// Receive
|
|
RemoveType(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
const string getID() const { return mSPITTypeID; }
|
|
|
|
// Send
|
|
RemoveType();
|
|
void setID(string iD) { mSPITTypeID = iD; }
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//---------------------------- SPITObjects ----------------------------------
|
|
|
|
//----------- ReportObject -----------
|
|
|
|
class ReportObject : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 31;
|
|
static constexpr int BYTESLENGTH = 339;
|
|
|
|
private:
|
|
bool mConfirmed{};
|
|
string mSPITObjectID{};
|
|
bool mFixed{};
|
|
bool mServerRemote{};
|
|
string mSPITObjectName{};
|
|
string mSPITTypeID{};
|
|
string mServerParams{};
|
|
uint64_t mFrameStart{};
|
|
uint64_t mFrameLength{};
|
|
uint64_t mFrameFadeInLength{};
|
|
uint64_t mFrameFadeOutLength{};
|
|
int mValueFactor{};
|
|
char mValueUse{VALUEUSE_DISCARD};
|
|
int mTrack{};
|
|
string mRemark{};
|
|
uint64_t mDelay{};
|
|
uint64_t mDuration{};
|
|
bool mActionAssigned{};
|
|
|
|
public:
|
|
ReportObject(const ReportObject &orig);
|
|
// Receive
|
|
ReportObject(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
bool getConfirmed() const { return mConfirmed; }
|
|
const string getID() const { return mSPITObjectID; }
|
|
bool getFixed() const { return mFixed; }
|
|
bool getServerRemote() const { return mServerRemote; }
|
|
const string getName() const { return mSPITObjectName; }
|
|
const string getSPITTypeID() const { return mSPITTypeID; }
|
|
const string getServerParams() const { return mServerParams; }
|
|
uint64_t getFrameStart() const { return mFrameStart; }
|
|
uint64_t getFrameLength() const { return mFrameLength; }
|
|
uint64_t getFrameFadeInLength() const { return mFrameFadeInLength; }
|
|
uint64_t getFrameFadeOutLength() const { return mFrameFadeOutLength; }
|
|
int getValueFactor() const { return mValueFactor; }
|
|
char getValueUse() const { return mValueUse; }
|
|
int getTrack() const { return mTrack; }
|
|
const string getRemark() const { return mRemark; }
|
|
uint64_t getDelay() const { return mDelay; }
|
|
uint64_t getDuration() const { return mDuration; }
|
|
bool getActionAssigned() const { return mActionAssigned; }
|
|
// Send
|
|
public:
|
|
ReportObject();
|
|
|
|
void setConfirmed(bool p_Confirmed) { mConfirmed = p_Confirmed; };
|
|
void setID(string iD) { mSPITObjectID = iD; };
|
|
void setFixed(bool p_Fixed) { mFixed = p_Fixed; };
|
|
void setServerRemote(bool p_IsRemote) { mServerRemote = p_IsRemote; };
|
|
void setName(string p_Name) { mSPITObjectName = p_Name; };
|
|
void setSPITTypeID(string iD) { mSPITTypeID = iD; };
|
|
void setServerParams(string p_Parameters) { mServerParams = p_Parameters; };
|
|
void setFrameStart(uint64_t p_StartTime) { mFrameStart = p_StartTime; };
|
|
void setFrameLength(uint64_t p_Length) { mFrameLength = p_Length; };
|
|
void setFrameFadeInLength(uint64_t p_FadeInTime) { mFrameFadeInLength = p_FadeInTime; };
|
|
void setFrameFadeOutLength(uint64_t p_FadeOutTime) { mFrameFadeOutLength = p_FadeOutTime; };
|
|
void setValueFactor(int p_Volume) { mValueFactor = p_Volume; };
|
|
void setValueUse(char p_ValueUse) { mValueUse = p_ValueUse; };
|
|
void setTrack(int p_Track) { mTrack = p_Track; };
|
|
void setRemark(string p_Description) { mRemark = p_Description; };
|
|
void setDelay(uint64_t p_Delay);
|
|
void setDuration(uint64_t p_Duration);
|
|
void setActionAssigned(bool p_ActionAssigned) { mActionAssigned = p_ActionAssigned; }
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- RemoveObject -----------
|
|
|
|
class RemoveObject : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 33;
|
|
static constexpr int BYTESLENGTH = 45;
|
|
|
|
private:
|
|
string mSPITObjectID{};
|
|
|
|
public:
|
|
RemoveObject(const RemoveObject &orig);
|
|
// Receive
|
|
RemoveObject(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
const string getID() const { return mSPITObjectID; }
|
|
// Send
|
|
public:
|
|
RemoveObject();
|
|
void setID(string iD) { mSPITObjectID = iD; }
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//---------------------------- SPITPlayer ----------------------------------
|
|
|
|
//----------- PlayStart -----------
|
|
|
|
class PlayStart : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 37;
|
|
static constexpr int BYTESLENGTH = 119;
|
|
|
|
private:
|
|
string mPlayerID{};
|
|
string mPlayerName{};
|
|
char mPlayerType{};
|
|
bool mPlayerIsRunning{};
|
|
uint64_t mTime; // Frames
|
|
|
|
public:
|
|
PlayStart(const PlayStart &orig);
|
|
// Receive
|
|
PlayStart(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
const string getPlayerID() const { return mPlayerID; }
|
|
const string getPlayerName() const { return mPlayerName; }
|
|
char getPlayerType() const { return mPlayerType; }
|
|
bool getPlayerIsRunning() const { return mPlayerIsRunning; }
|
|
uint64_t getTime() const { return mTime; }
|
|
|
|
// Send
|
|
PlayStart(string p_PlayerID, string p_PlayerName, char p_PlayerType);
|
|
void setPlayerIsRunning(bool p_IsPlaying) { mPlayerIsRunning = p_IsPlaying; }
|
|
void setTime(uint64_t p_Time) { mTime = p_Time; }
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- PlayObject -----------
|
|
|
|
class PlayObject : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 38;
|
|
static constexpr int BYTESLENGTH = 100;
|
|
|
|
private:
|
|
string mPlayerID{};
|
|
string mSPITObjectID{};
|
|
uint64_t mFrameInsideObject{}; // Frames
|
|
bool mPlayPrePosition{};
|
|
int mValue{};
|
|
char mValueFlag{VALUEFLAG_DIRECT};
|
|
|
|
public:
|
|
PlayObject(const PlayObject &orig);
|
|
// Receive
|
|
PlayObject(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
const string getPlayerID() const { return mPlayerID; }
|
|
const string getSPITObjectID() const { return mSPITObjectID; }
|
|
uint64_t getFrameInsideObject() const { return mFrameInsideObject; }
|
|
bool getPlayPrePosition() const { return mPlayPrePosition; }
|
|
int getValue() const { return mValue; }
|
|
char getValueFlag() const { return mValueFlag; }
|
|
// Send
|
|
PlayObject();
|
|
|
|
void setPlayerID(string p_PlayerID) { mPlayerID = p_PlayerID; }
|
|
void setID(string iD) { mSPITObjectID = iD; }
|
|
void setFrameInsideObject(uint64_t p_TimeInside) { mFrameInsideObject = p_TimeInside; }
|
|
void setPlayPrePosition(bool p_PlayOldPosition) { mPlayPrePosition = p_PlayOldPosition; }
|
|
void setValue(int p_Value) { mValue = p_Value; }
|
|
void setValueFlag(char p_ValueFlag) { mValueFlag = p_ValueFlag; }
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- PlayEnd -----------
|
|
class PlayEnd : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 39;
|
|
static constexpr int BYTESLENGTH = 45;
|
|
|
|
private:
|
|
string mPlayerID{};
|
|
|
|
public:
|
|
PlayEnd(const PlayEnd &orig);
|
|
// Receive
|
|
PlayEnd(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
const string getPlayerID() const { return mPlayerID; }
|
|
|
|
// Send
|
|
PlayEnd(string p_PlayerID);
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------- ReportPlayStatus -----------
|
|
class ReportPlayStatus : public OPPart {
|
|
public:
|
|
static constexpr int OPFLAG = 40;
|
|
static constexpr int BYTESLENGTH = 57;
|
|
|
|
private:
|
|
string mSPITObjectID{};
|
|
uint64_t mFrameInsideObject{};
|
|
int mValue{};
|
|
|
|
public:
|
|
ReportPlayStatus(const ReportPlayStatus &orig);
|
|
// Receive
|
|
ReportPlayStatus(unique_ptr<Header> header);
|
|
bool parse(const std::vector<char> &message);
|
|
|
|
const string getID() const { return mSPITObjectID; }
|
|
uint64_t getFrameInsideObject() const { return mFrameInsideObject; }
|
|
int getValue() const { return mValue; }
|
|
// Send
|
|
ReportPlayStatus();
|
|
|
|
void setID(string iD);
|
|
void setFrameInsideObject(uint64_t p_TimeInside);
|
|
void setValue(int p_Value);
|
|
bool fillBytes(std::vector<char> &message);
|
|
};
|
|
|
|
//----------------------- static helper functions ----------------------------
|
|
public:
|
|
static bool isSystemLittleEndian();
|
|
static optional<int> getInt(const std::vector<char> &message, int &offset);
|
|
static optional<uint64_t> getLong(const std::vector<char> &message, int &offset);
|
|
static optional<bool> getBoolean(const std::vector<char> &message, int &offset);
|
|
static optional<char> getByte(const std::vector<char> &message, int &offset);
|
|
static int setInt(int value, std::vector<char> &message, int offset);
|
|
static int setLong(uint64_t value, std::vector<char> &message, int offset);
|
|
static int setBoolean(bool value, std::vector<char> &message, int offset);
|
|
static int setByte(int value, std::vector<char> &message, int offset);
|
|
|
|
/**
|
|
* Returns the string char* of the part of the byte sequence (0x00 null terminated).
|
|
* @param p_Bytes the byte array
|
|
* @param offset the startposition of strings bytes
|
|
* @param p_Length the length of the string included the null terminate byte (0x00).
|
|
* The length of the string will be p_Length -1.
|
|
*/
|
|
static optional<string> getString(const std::vector<char> &message, int &offset, int maxLength);
|
|
|
|
/**
|
|
* Fill the p_String in the byte array.
|
|
* If p_String length is greater than p_Length -1, the p_String will be truncated.
|
|
* CAUTION the return value should be freed after use.
|
|
* @param p_String the string
|
|
* @param p_Length the maximal length of the string included the null character.
|
|
* @throws Exception if p_String == nullptr, p_Bytes == nullptr
|
|
* p_Offset less than 0
|
|
* p_ByteCount less than p_Offset + p_Length
|
|
* @return p_Length
|
|
*/
|
|
static int setString(string p_String, std::vector<char> &message, int p_Offset, int p_Length);
|
|
};
|
|
|
|
} |