refactoring spit messages
This commit is contained in:
@@ -16,49 +16,46 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
static const string SPITID = "#spit#";
|
||||
// static char stringEmpty[] = "";
|
||||
static char nullChar[] = "\0";
|
||||
|
||||
class SPIT_Message {
|
||||
//----------- Header -----------
|
||||
public:
|
||||
class Header {
|
||||
public:
|
||||
static const int BYTESLENGTH = 99;
|
||||
static constexpr int BYTESLENGTH = 99;
|
||||
virtual ~Header();
|
||||
Header(const Header &orig);
|
||||
Header();
|
||||
// Members
|
||||
private:
|
||||
string m_SPITID;
|
||||
int m_SPITVersion;
|
||||
unsigned char m_MessageNumber;
|
||||
int m_BytesCount;
|
||||
string m_ServerID;
|
||||
string m_ClientID;
|
||||
int m_SPITVersion{SPITVERSION};
|
||||
unsigned char m_MessageNumber{};
|
||||
int m_BytesCount{BYTESLENGTH};
|
||||
string m_ServerID{};
|
||||
string m_ClientID{};
|
||||
int m_OPFlag;
|
||||
int m_ParseOffset = 0;
|
||||
|
||||
void initMembers();
|
||||
int m_ParseOffset{};
|
||||
|
||||
public:
|
||||
const string getSPITID() const { return m_SPITID; }
|
||||
string getSPITID() const { return m_SPITID; }
|
||||
int getSPITVersion() const { return m_SPITVersion; }
|
||||
unsigned char getMessageNumber() const { return m_MessageNumber; }
|
||||
int getBytesCount() const { return m_BytesCount; }
|
||||
const string getServerID() const { return m_ServerID; }
|
||||
const string getClientID() const { return m_ClientID; }
|
||||
string getServerID() const { return m_ServerID; }
|
||||
string getClientID() const { return m_ClientID; }
|
||||
int getOPFlag() const { return m_OPFlag; }
|
||||
|
||||
// Receive
|
||||
public:
|
||||
bool parse(char *p_Bytes, int p_ByteCount);
|
||||
|
||||
// Send
|
||||
public:
|
||||
Header(int p_SPITVersion, int p_OPFlag);
|
||||
void setMessageNumber(unsigned char p_MessageNumber);
|
||||
void setServerID(string p_ServerID);
|
||||
@@ -135,25 +132,22 @@ class SPIT_Message {
|
||||
static const char VALUEFLAG_INCREASE = 0x01; // increase the value
|
||||
static const char VALUEFLAG_DECREASE = 0x02; // decrease the value
|
||||
|
||||
SPIT_Message();
|
||||
SPIT_Message() = default;
|
||||
virtual ~SPIT_Message();
|
||||
// SPIT_Message(const SPIT_Message& orig);
|
||||
|
||||
// Members
|
||||
private:
|
||||
char *m_MessageBytes;
|
||||
int m_MessageByteCount;
|
||||
Header *m_Header;
|
||||
OPPart *m_OPPart;
|
||||
bool m_MessageBytesCreated;
|
||||
|
||||
void initMembers();
|
||||
char *m_MessageBytes{};
|
||||
int m_MessageByteCount{};
|
||||
Header *m_Header{};
|
||||
OPPart * m_OPPart{};
|
||||
bool m_MessageBytesCreated{};
|
||||
|
||||
// Receive
|
||||
public:
|
||||
SPIT_Message(char *p_MessageBytes, int p_MessageBytesLength);
|
||||
SPIT_Message(char *msgBytes, int msgSize);
|
||||
|
||||
// SPIT_Message(const SPIT_Message& orig);
|
||||
const Header *getHeader() const { return m_Header; }
|
||||
int getOPFlag() const {
|
||||
if (m_Header == NULL)
|
||||
@@ -213,7 +207,7 @@ class SPIT_Message {
|
||||
void setLoginPassword(string p_LoginPassword);
|
||||
void setServerIP(string p_ServerIP);
|
||||
void setServerPort(int p_ServerPort);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- ConnectAnswer -----------
|
||||
@@ -251,7 +245,7 @@ class SPIT_Message {
|
||||
void setServerName(string p_ContollerName);
|
||||
void setConnected(bool p_Connected);
|
||||
void setStepTime(int p_StepTime_ms);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- Disconnect -----------
|
||||
@@ -274,7 +268,7 @@ class SPIT_Message {
|
||||
// Send
|
||||
public:
|
||||
Disconnect();
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- Watchdog -----------
|
||||
@@ -297,7 +291,7 @@ class SPIT_Message {
|
||||
// Send
|
||||
public:
|
||||
Watchdog();
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- WatchdogAnswer -----------
|
||||
@@ -319,7 +313,7 @@ class SPIT_Message {
|
||||
// Send
|
||||
public:
|
||||
WatchdogAnswer();
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//------------------------------ SPITProject ----------------------------------
|
||||
@@ -358,7 +352,7 @@ class SPIT_Message {
|
||||
void setProjectID(string p_ClientID);
|
||||
void setProjectName(string p_ClientName);
|
||||
void setFramesPerSecond(const int p_FramesPerSecond);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- CloseSPITProject -----------
|
||||
@@ -387,7 +381,7 @@ class SPIT_Message {
|
||||
CloseSPITProject();
|
||||
|
||||
void setProjectID(string p_ClientID);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- StartProjectTransfer -----------
|
||||
@@ -408,7 +402,7 @@ class SPIT_Message {
|
||||
// Send
|
||||
public:
|
||||
RequestProjectTransfer();
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- StartProjectTransfer -----------
|
||||
@@ -430,7 +424,7 @@ class SPIT_Message {
|
||||
// Send
|
||||
public:
|
||||
StartProjectTransfer();
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- EndProjectTransfer -----------
|
||||
@@ -450,7 +444,7 @@ class SPIT_Message {
|
||||
bool parse(char *p_Bytes, int p_ByteCount);
|
||||
// Send
|
||||
EndProjectTransfer();
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//---------------------------- SPIT_Types ----------------------------------
|
||||
@@ -522,7 +516,7 @@ class SPIT_Message {
|
||||
void setDelay(long long p_Delay);
|
||||
void setDuration(long long p_Duration);
|
||||
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- RemoveSPITType -----------
|
||||
@@ -551,7 +545,7 @@ class SPIT_Message {
|
||||
RemoveSPITType();
|
||||
|
||||
void setID(string p_ID);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//---------------------------- SPITObjects ----------------------------------
|
||||
@@ -632,7 +626,7 @@ class SPIT_Message {
|
||||
void setDelay(long long p_Delay);
|
||||
void setDuration(long long p_Duration);
|
||||
void setActionAssigned(bool p_ActionAssigned);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- RemoveSPITObject -----------
|
||||
@@ -661,7 +655,7 @@ class SPIT_Message {
|
||||
public:
|
||||
RemoveSPITObject();
|
||||
void setID(string p_ID);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//---------------------------- SPITPlayer ----------------------------------
|
||||
@@ -704,7 +698,7 @@ class SPIT_Message {
|
||||
void setPlayerType(char p_PlayerType);
|
||||
void setPlayerIsRunning(bool p_IsPlaying);
|
||||
void setTime(long long p_Time);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- PlaySPITObject -----------
|
||||
@@ -746,7 +740,7 @@ class SPIT_Message {
|
||||
void setPlayPrePosition(bool p_PlayOldPosition);
|
||||
void setValue(int p_Value);
|
||||
void setValueFlag(char p_ValueFlag);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- PlaySPITEnd -----------
|
||||
@@ -772,7 +766,7 @@ class SPIT_Message {
|
||||
public:
|
||||
PlaySPITEnd();
|
||||
void setPlayerID(string p_PlayerID);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------- ReportPlayStatus -----------
|
||||
@@ -805,33 +799,29 @@ class SPIT_Message {
|
||||
void setID(string p_ID);
|
||||
void setFrameInsideObject(long long p_TimeInside);
|
||||
void setValue(int p_Value);
|
||||
bool fillBytes(char *p_MessageBytes, int p_ByteCount);
|
||||
bool fillBytes(char *msgBytes, int p_ByteCount);
|
||||
};
|
||||
|
||||
//----------------------- static helper functions ----------------------------
|
||||
public:
|
||||
static bool isSystemLittleEndian();
|
||||
static int getInt(char *p_Bytes, int p_ByteCount, int p_Offset);
|
||||
static int setInt(int p_Value, char *p_Bytes, int p_ByteCount, int p_Offset);
|
||||
static long long getLong(char *p_Bytes, int p_ByteCount, int p_Offset);
|
||||
static int setLong(long long p_Value, char *p_Bytes, int p_ByteCount, int p_Offset);
|
||||
static bool getBoolean(char *p_Bytes, int p_ByteCount, int p_Offset);
|
||||
static int setBoolean(bool p_Value, char *p_Bytes, int p_ByteCount, int p_Offset);
|
||||
static char getByte(char *p_Bytes, int p_ByteCount, int p_Offset);
|
||||
static int setByte(int p_Value, char *p_Bytes, int p_ByteCount, int p_Offset);
|
||||
static optional<int> getInt(char *bytes, int size, int& offset);
|
||||
static optional<long long> getLong(char *bytes, int size, int &offset);
|
||||
static optional<bool> getBoolean(char *bytes, int size, int& offset);
|
||||
static optional<char> getByte(char *bytes, int size, int& offset);
|
||||
static int setInt(int value, char *bytes, int size, int offset);
|
||||
static int setLong(long long value, char *bytes, int size, int offset);
|
||||
static int setBoolean(bool value, char *bytes, int size, int offset);
|
||||
static int setByte(int value, char *bytes, int size, int offset);
|
||||
|
||||
/**
|
||||
* Returns the string char* of the part of the byte sequence (0x00 null terminated).
|
||||
* @param p_Bytes the byte array
|
||||
* @param p_Offset the startposition of strings bytes
|
||||
* @param offset the startposition of strings bytes
|
||||
* @param p_Length the length of the string included the null terminate byte (0x00).<br>
|
||||
* The length of the string will be p_Length -1.
|
||||
* @return the String char*
|
||||
* @throws Exception if p_Bytes == null<br>
|
||||
* p_Offset less than 0<br>
|
||||
* p_Bytes.length less than p_Offset + p_Length<br>
|
||||
* No 0x00 null terminate byte is found
|
||||
*/
|
||||
static string getString(char *p_Bytes, int p_ByteCount, int p_Offset, int p_Length);
|
||||
static optional<string> getString(char *bytes, int size, int &offset, int maxLength);
|
||||
|
||||
/**
|
||||
* Fill the p_String in the byte array.<br>
|
||||
@@ -856,6 +846,6 @@ class SPIT_Message {
|
||||
*/
|
||||
// static bool stringEqual(const char* p_String1, const char* p_String2);
|
||||
// static char* stringCopy(const char* p_String);
|
||||
static char *createByteArray(const OPPart *p_OPPart, int *p_BytesCount);
|
||||
static char *createByteArray(const OPPart &p_OPPart, int *p_BytesCount);
|
||||
};
|
||||
#endif /* SPIT_MESSAGE_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -927,7 +927,7 @@ void onPlaySpitType(string p_PlayerID, string spitTypeId, bool p_PlayerIsRunning
|
||||
* @param p_Value the new value
|
||||
*/
|
||||
void onPlayRemoteObjectStatus(const SPITType &p_SPITType, const SPITObject &p_SPITObject, long long p_FrameInsideObject, int p_Value) {
|
||||
ESP_EARLY_LOGI(TAG, "eventPlayRemoteObjectStatus RemoteSPITType: %s RemoteSPITObject: %s Position: %lld Value: %d", p_SPITType.getName().data(), p_SPITObject.getName().data(), p_FrameInsideObject, p_Value);
|
||||
ESP_EARLY_LOGD(TAG, "eventPlayRemoteObjectStatus RemoteSPITType: %s RemoteSPITObject: %s Position: %lld Value: %d", p_SPITType.getName().data(), p_SPITObject.getName().data(), p_FrameInsideObject, p_Value);
|
||||
}
|
||||
|
||||
void SpitClientApp() {
|
||||
|
||||
Reference in New Issue
Block a user