diff --git a/.vscode/settings.json b/.vscode/settings.json index 2f4a520..cb22a9f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,5 +15,6 @@ "idf.toolsPathWin": "C:\\Tools\\ESP", "idf.flashType": "UART", "C_Cpp.autoAddFileAssociations": false, - "project.deviceIp": "172.16.17.56" + "project.deviceIp": "172.16.17.56", + "sonarlint.pathToCompileCommands": "${workspaceFolder}\\build\\compile_commands.json", } diff --git a/components/spit/Notes.md b/components/spit/Notes.md new file mode 100644 index 0000000..231a3ff --- /dev/null +++ b/components/spit/Notes.md @@ -0,0 +1,11 @@ +# SPIT + +Original implementation from Hag seem to be not suited for Embedded devices. + +- Supports IPv4 only +- Reduced Threads to a minimum +- Then reduced usage of Mutexes to a minimum +- Reduced Sockets to a minimum +- Introduced containers and removed plain new and delete +- Removed UUID-Generation because SPIT-Types never change on embedded devices +- Callbacks instead of interfaces where suitable \ No newline at end of file diff --git a/components/spit/SPIT_Protocol_en_20180211_1630.pdf b/components/spit/SPIT_Protocol_en_20180211_1630.pdf new file mode 100644 index 0000000..5702203 Binary files /dev/null and b/components/spit/SPIT_Protocol_en_20180211_1630.pdf differ diff --git a/components/spit/include/I_SAD_Client.hpp b/components/spit/include/I_SAD_Client.hpp deleted file mode 100644 index 1384906..0000000 --- a/components/spit/include/I_SAD_Client.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include -using namespace std; - -class SAD_DetectedServer; -class I_SAD_Client { - public: - /** - * If a new server was found by the ServerAutoDetect mechanism, this function is called.
- * To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect.
- * If a server can be reached via several IP addresses, the IP address is selected according to the following preference:
- * 1.) If a loopback address is available, it is used.
- * 2.) If an IP4 address is available, it is used.
- * 3.) In the other cases the IP6 address is used.
- * @param p_ID the id of the server (every started server should generate an id) - * @param p_Name the name of the SPIT server - * @param p_ComputerName the Hostname of the cpmputer on which the SPIT server is running - * @param p_IP the selected ip address of the SPIT server - * @param p_Port the port of the SPIT server - * @param p_Addition sometimes server may have additional informations - * @param p_IsIP4 the server ip is a ip4 address - */ - virtual void eventServerDetected(SAD_DetectedServer &server) = 0; - /** - * If a SPITServer is not more found, this function is called. - * To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect.
- * @param p_ID the id of the server (every started server should generate an id) - * @param p_Name the name of the SPIT server - * @param p_ComputerName the Hostname of the cpmputer on which the SPIT server is running - * @param p_IP the selected ip address of the SPIT server - * @param p_Port the port of the SPIT server - * @param p_Addition sometimes server may have additional informations - * @param p_IsIP4 the server ip is a ip4 address - */ - virtual void eventServerChanged(SAD_DetectedServer &server) = 0; - - virtual void eventServerLost(SAD_DetectedServer &server) = 0; -}; diff --git a/components/spit/include/SAD_DetectedServer.hpp b/components/spit/include/SAD_DetectedServer.hpp index e0cb50a..426e2f1 100644 --- a/components/spit/include/SAD_DetectedServer.hpp +++ b/components/spit/include/SAD_DetectedServer.hpp @@ -1,39 +1,47 @@ #pragma once -#include "I_SAD_Client.hpp" #include +#include #include #include using namespace std; -class SAD_DetectedServer { - +class SAD_DetectedServer; +class I_SAD_Client { public: - SAD_DetectedServer(); - SAD_DetectedServer(const SAD_DetectedServer &orig) { - m_ID = orig.getID(); - m_Name = orig.getName(); - m_ComputerName = orig.getComputerName(); - m_IP = orig.getIP(); - m_ClientIP = orig.getClientIP(); - m_Port = orig.getPort(); - m_Additions = orig.getAdditions(); + virtual void eventServerDetected(SAD_DetectedServer &server) = 0; + virtual void eventServerChanged(SAD_DetectedServer &server) = 0; + virtual void eventServerLost(SAD_DetectedServer &server) = 0; +}; + +class SAD_DetectedServer { + public: + SAD_DetectedServer(string p_Name, string p_ID, string p_ComputerName, + string p_IP, string p_Port, string p_ClientIP, + string p_Additions, string projName) + : m_Name(p_Name), + m_ID(p_ID), + m_ComputerName(p_ComputerName), + m_IP(p_IP), + m_Port(p_Port), + m_ClientIP(p_ClientIP), + m_Additions(p_Additions), + m_ServerProjectName(projName) { } - ~SAD_DetectedServer(); private: - string m_ID; - string m_Name; - string m_ComputerName; - string m_IP; - string m_ClientIP; - string m_Port; - string m_Additions; - string m_ServerProjectName; - bool m_New; - bool m_Changed; - bool m_FoundAgain; + string m_Name{}; + string m_ID{}; + string m_ComputerName{}; + string m_IP{}; + string m_Port{}; + string m_ClientIP{}; + string m_Additions{}; + string m_ServerProjectName{}; + bool m_New{true}; + bool m_Changed{}; + bool m_FoundAgain{}; public: string getID() const { return m_ID; } @@ -44,70 +52,91 @@ class SAD_DetectedServer { string getClientIP() const { return m_ClientIP; } string getAdditions() const { return m_Additions; } string getProjectName() const { return m_ServerProjectName; } - - private: - void setID(string p_ID) { m_ID = p_ID; } - void setName(string p_Name) { m_Name = p_Name; } - void setComputerName(string p_ComputerName) { m_ComputerName = p_ComputerName; } - void setIP(string p_IP) { m_IP = p_IP; } - void setClientIP(string p_IP) { m_ClientIP = p_IP; } - void setPort(string p_Port) { m_Port = p_Port; } - void setAdditions(string p_Additions) { m_Additions = p_Additions; } - void setProjectName(string p_ServerProjectName); - bool getNew() const { return m_New; } bool getChanged() const { return m_Changed; } bool getFoundAgain() const { return m_FoundAgain; } + void setChanged() { m_Changed = true; } - void setNew(bool p_New) { m_New = p_New; } + void setKnown() { m_New = false; } void setFoundAgain() { m_FoundAgain = true; } + void updateProjectName(string newProjectName) { + m_ServerProjectName = newProjectName; + if (m_ServerProjectName != newProjectName) { + m_Changed = true; + } + } // SAD_Client m_ThreadSend will send to Multicast addresses - void startCycleSAD() { + void resetFlags() { m_Changed = false; m_FoundAgain = false; m_New = false; } private: - static unordered_map s_DetectedServers; + static unordered_map> sKnownServers; public: - static const int PARAMINDEX_PRECODE = 0; - static const int PARAMINDEX_SPITTASKID = 1; - static const int PARAMINDEX_NAME = 2; - static const int PARAMINDEX_ID = 3; - static const int PARAMINDEX_COMPUTERNAME = 4; - static const int PARAMINDEX_PORT = 5; - static const int PARAMINDEX_CLIENTIP = 6; - static const int PARAMINDEX_ADDITIONS = 7; - static const int PARAMINDEX_SERVERPROJECTNAME = 8; - static const int PARAMINDEX_IP = 9; + static constexpr int PARAMINDEX_PRECODE = 0; + static constexpr int PARAMINDEX_SPITTASKID = 1; + static constexpr int PARAMINDEX_NAME = 2; + static constexpr int PARAMINDEX_ID = 3; + static constexpr int PARAMINDEX_COMPUTERNAME = 4; + static constexpr int PARAMINDEX_PORT = 5; + static constexpr int PARAMINDEX_CLIENTIP = 6; + static constexpr int PARAMINDEX_ADDITIONS = 7; + static constexpr int PARAMINDEX_SERVERPROJECTNAME = 8; + static constexpr int PARAMINDEX_IP = 9; + /** * Used by SAD_Client to add a found SPITServer - don't use this manually - * @param p_IsIP4 true = the server is reached via a IP4 address
false = the server is reahed via a IP6 address - * @param p_ServerID the id of the server, every instance of a SPITServer has an own id + * @param id the id of the server, every instance of a SPITServer has an own id * @param p_ServerParams the server's parameter */ - static void addDetectedServer(string p_ServerID, string p_ServerParams[]); - /** - * Used by SAD_Client to remove a SPITServer - don't use this manually - * @param p_DetectedServer - */ - static void removeDetectedServer(SAD_DetectedServer &server); - /** - * Used by SAD_Client to clear all found SPITServers - don't use this manually - */ - static void clearDetectedServers(); - /** - * Used by SAD_Client internally - don't use this manually - */ - static void cycleStart(); + static void addDetectedServer(unique_ptr detected) { + if (auto i = sKnownServers.find(detected->getID()); i != sKnownServers.end()) { + auto &known = *(i->second.get()); + known.setFoundAgain(); + if (detected->getProjectName() != known.getProjectName()) { + known.updateProjectName(detected->getProjectName()); + } + return; + } + sKnownServers[detected->getID()] = move(detected); + } + static void removeDetectedServer(SAD_DetectedServer &server) { + auto i = sKnownServers.find(server.getID()); + if (i != sKnownServers.end()) { + sKnownServers.erase(i); + } + } + static void clearDetectedServers() { + sKnownServers.clear(); + } + + static void resetServerFlags() { + for (auto &srv : sKnownServers) { + srv.second->resetFlags(); + } + } /** * Used by SAD_Client internally -don't use this manually * @param p_SADClientInterface */ - static void cycleEnd(I_SAD_Client &p_SADClientInterface); + static void evaluateDetectedServers(I_SAD_Client &sadClient) { + for (auto &srv : sKnownServers) { + SAD_DetectedServer &known = *srv.second; + if (known.getNew()) { + known.setKnown(); + sadClient.eventServerDetected(known); + } else if (known.getChanged()) { + sadClient.eventServerChanged(known); + } else if (known.getFoundAgain() == false) { + sadClient.eventServerLost(known); + removeDetectedServer(known); + } + } + } /** * Returns a reference of the DetectedServer with the id p_ServerID.
@@ -115,5 +144,7 @@ class SAD_DetectedServer { * @param p_ServerID the id of the SPITServer * @return the reference of the SAD_DetectedServer instance with getID() == p_ServerID */ - static const SAD_DetectedServer &getRefDetectedServer(string p_ServerID); + static const SAD_DetectedServer &getRefDetectedServer(const string &id) { + return *sKnownServers.at(id); + } }; diff --git a/components/spit/include/SPITObject.h b/components/spit/include/SPITObject.h index 8ae8232..ba2931c 100644 --- a/components/spit/include/SPITObject.h +++ b/components/spit/include/SPITObject.h @@ -16,76 +16,47 @@ #include "SPITType.h" #include "SPIT_Message.h" -#include -#include +#include "SpitRepo.hpp" using namespace std; class SPITObjectListener; class SPITObject { - private: - static unordered_map s_SPITObjects; - static unordered_map s_SPITObjectsRemote; - public: - static SPITObject *getSPITObject(string p_ID); - static const SPITObject &getSPITObjectRef(string p_ID); - static bool addSPITObject(SPITObject *p_ptrSpitObject); - static bool removeSPITObject(SPITObject *p_ptrSpitObject); - static bool removeSPITObject(string p_SpitObjectID); - static int getSPITObjectCount(); - static SPITObject *getSPITObject(int p_Index); - static const SPITObject &getSPITObjectRef(int p_Index); - static void clearSPITObjects(); - static void clearUnconfirmedSPITObjects(); - static void setConfirmedFalse(); + static void clearUnconfirmedSPITObjects(SpitRepo &repo); + static void setConfirmedFalse(SpitRepo &repo); + static void eventProjectClosed(SpitRepo &repo, SpitRepo &remoteRepo); - static SPITObject *getSPITObjectRemote(string p_ID); - static const SPITObject &getSPITObjectRemoteRef(string p_ID); - static bool addSPITObjectRemote(SPITObject *p_ptrSpitObject); - static bool removeSPITObjectRemote(SPITObject *p_ptrSpitObject); - static bool removeSPITObjectRemote(string p_SpitObjectID); - static int getSPITObjectRemoteCount(); - static SPITObject *getSPITObjectRemote(int p_Index); - static const SPITObject &getSPITObjectRemoteRef(int p_Index); - static void clearSPITObjectsRemote(); - - static void eventProjectClosed(); - - SPITObject(); - // SPITObject(const SPITObject& orig); - ~SPITObject(); + SPITObject(string p_ID); private: string m_ID; - string m_Name; - string m_SPITTypeID; - string m_ServerParams; - string m_Remark; - bool m_Confirmed; - bool m_Fixed; - bool m_CreatedByClient; - bool m_ServerRemote; - bool m_ActionAssigned; - bool m_ActionAssignedType; // Virtual construct - long long m_FrameStart; - long long m_FrameLength; - long long m_FrameFadeInLength; - long long m_FrameFadeOutLength; - char m_ValueUse; - int m_ValueFactor; - int m_Track; - long long m_Delay; - long long m_Duration; + string m_Name{}; + string m_SPITTypeID{}; + string m_ServerParams{}; + string m_Remark{}; + bool m_Confirmed{}; + bool m_Fixed{}; + bool m_CreatedByClient{}; + bool m_ServerRemote{}; + bool m_ActionAssigned{}; + bool m_ActionAssignedType{}; // Virtual construct + long long m_FrameStart{}; + long long m_FrameLength{}; + long long m_FrameFadeInLength{}; + long long m_FrameFadeOutLength{}; + char m_ValueUse{0x01}; + int m_ValueFactor{1000000}; // Values are given in ppm -> 1000000 = 1/1; + int m_Track{}; + long long m_Delay{}; + long long m_Duration{}; bool m_PlayPrePosition; long long m_PlayTimeInsideFrames; int m_PlayValue; char m_PlayValueFlag; - void initMembers(); - public: string getID() const { return m_ID; } string getName() const { return m_Name; } @@ -95,7 +66,7 @@ class SPITObject { /** * Returns if the SPITType triggers an action on the Server or on the client. - * @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType
+ * @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType * true = the action is triggered on the server. The server waits for the client to play objects of this SPITType. */ bool getServerRemote() const { return m_ServerRemote; } @@ -106,16 +77,16 @@ class SPITObject { */ bool getConfirmed() const { return m_Confirmed; } bool getFixed() const { return m_Fixed; } - bool getCreatedByClient() { return m_CreatedByClient; } + bool getCreatedByClient() const { return m_CreatedByClient; } /** - * This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.
- * This is used when an action is associated with a SPITType.
+ * This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol. + * This is used when an action is associated with a SPITType. * Then this action is done for every SPITObject with the SPITType. * @return true = an action is assigned for the SPITType. */ bool getActionAssignedType() const { return m_ActionAssignedType; } - /** Returns if this SPITObject has an associated action or not.
- * @return true = the user has asscociated an action with this SPITObject or
+ /** Returns if this SPITObject has an associated action or not. + * @return true = the user has asscociated an action with this SPITObject or * the user has asscociated an action with the SPITType of this SPITObject */ bool getActionAssigned() const { return m_ActionAssigned || m_ActionAssignedType; } @@ -132,24 +103,23 @@ class SPITObject { long long getDelay() const { return m_Delay; } long long getDuration() const { return m_Duration; } - bool getProjectIndepended() const { + bool getProjectIndepended(SpitRepo &repo, SpitRepo &remoteRepo) const { SPITType *ptrSPITType; if (m_ServerRemote == false) { - ptrSPITType = SPITType::getSPITType(m_SPITTypeID); - if (ptrSPITType == NULL) + ptrSPITType = repo.getEntry(m_SPITTypeID); + if (ptrSPITType == nullptr) return true; return ptrSPITType->getProjectIndepended(); } else { - ptrSPITType = SPITType::getSPITTypeRemote(m_SPITTypeID); - if (ptrSPITType == NULL) + ptrSPITType = remoteRepo.getEntry(m_SPITTypeID); + if (ptrSPITType == nullptr) return true; return ptrSPITType->getProjectIndepended(); } }; - void setID(string p_ID); bool setConfirmed(bool p_Confirmed); - void setCreatedByClient(bool p_CreatedByClient); + void setCreatedByClient(bool p_CreatedByClient) { m_CreatedByClient = p_CreatedByClient; } bool setName(string p_Name); bool setRemark(string p_Remark); bool setServerParams(string p_ServerParams); @@ -169,8 +139,8 @@ class SPITObject { bool setDuration(long long p_Duration); bool setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject); - void fillMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject); - void fillMessageOP(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject); + void fillMessageOP(SPIT_Message::ReportSPITObject &p_ReportSPITObject); + void fillMessageOP(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject); }; #endif /* SPITOBJECT_H */ diff --git a/components/spit/include/SPITPlayer.h b/components/spit/include/SPITPlayer.h index 1b74a00..34e41ac 100644 --- a/components/spit/include/SPITPlayer.h +++ b/components/spit/include/SPITPlayer.h @@ -23,13 +23,10 @@ class SPITPlayer { public: class PlaySPITType { public: - PlaySPITType(); PlaySPITType(SPITPlayer *p_SPITPlayer, string p_SPITObjectID); PlaySPITType(const PlaySPITType &orig); - string getSPITTypeID() const { - return m_SPITTypeID; - } + string getSPITTypeID() const { return m_SPITTypeID; } void startPlaySequence(); bool getIsNew() const { return m_IsNew; } @@ -57,9 +54,9 @@ class SPITPlayer { //----- SPITPlayer ------ public: // list the SPITPlayers - static unordered_map s_SPITPlayers; // all actual played objects - static SPITPlayer *getSPITPlayer(string p_PlayerID); // if a player does not exist creates a new one - static void clearPlayers(); + static unordered_map> s_SPITPlayers; // all actual played objects + static SPITPlayer &getSPITPlayer(string p_PlayerID); // if a player does not exist creates a new one + static void clearPlayers() { s_SPITPlayers.clear(); } SPITPlayer(string p_PlayerID); virtual ~SPITPlayer(); @@ -72,21 +69,22 @@ class SPITPlayer { return m_ID; } - unordered_map *getPlaySPITTypes(); + unordered_map> &getPlaySPITTypes() { return m_PlaySPITTypes; } void setIsRunning(bool p_IsRunning) { m_IsRunning = p_IsRunning; } void setName(string p_Name) { m_Name = p_Name; } void setType(char p_Type) { m_Type = p_Type; } void setTime(long long p_Frames) { m_TimeFrames = p_Frames; } - bool getIsRunning() { return m_IsRunning; } - string getName() { return m_Name; } - char getType() { return m_Type; } - long long getTime() { return m_TimeFrames; } + bool getIsRunning() const { return m_IsRunning; } + string getName() const { return m_Name; } + char getType() const { return m_Type; } + long long getTime() const { return m_TimeFrames; } private: string m_ID; string m_Name; char m_Type; - unordered_map m_PlaySPITTypes; + unordered_map> m_PlaySPITTypes; + bool m_IsRunning; long long m_TimeFrames; }; diff --git a/components/spit/include/SPITSocket.h b/components/spit/include/SPITSocket.h index 189ddda..7d0baff 100644 --- a/components/spit/include/SPITSocket.h +++ b/components/spit/include/SPITSocket.h @@ -79,14 +79,6 @@ class SPITSocket { //-------- class -------------- SPITSocket(IPAddress ip) : mOwnIp(ip) { m_UDPSocketIP4 = INVALID_SOCKET; - - m_ServerIP = ""; - m_ServerPort = ""; - m_ClientIP = ""; - m_ClientPort = ""; - m_BoundClientPort = ""; - m_BoundClientFamily = 0; - m_IsBound = false; createSocket_UDP(); } virtual ~SPITSocket() { @@ -102,65 +94,56 @@ class SPITSocket { } private: - string m_ServerIP; - string m_ServerPort; - string m_ClientIP; - string m_ClientPort; // port given by the user maybe "0" - string m_BoundClientPort; // port set after bind - int m_BoundClientFamily; - bool m_IsBound; + string m_ServerIP{}; + string m_ServerPort{}; + string m_ClientIP{}; + string m_ClientPort{}; // port given by the user maybe "0" + string m_BoundClientPort{}; // port set after bind + bool m_IsBound{}; public: - /** - * Sets the ip address and port for server and client. - * @param p_ServerIP - * @param p_ServerPort - * @param p_ClientIP - * @param p_ClientPort - */ - void setConnectionParams(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort) { - m_ServerIP = p_ServerIP; - m_ServerPort = p_ServerPort; - m_ClientIP = p_ClientIP; - m_ClientPort = p_ClientPort; + // Sets the ip address and port for server and client. + void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) { + m_ServerIP = serverIp; + m_ServerPort = serverPort; + m_ClientIP = clientIp; + m_ClientPort = clientPort; } /** * Send a message to the server as set by setConnectionParams - * @param p_MessageBytes byte buffer containing the message - * @param p_MessageLength length of the messaeg + * @param message byte buffer containing the message + * @param length length of the message * @return */ - int sendMessage(const char *p_MessageBytes, int p_MessageLength) { - if (m_ServerPort.length() <= 0) + int sendMessage(const char *message, int length) { + if (m_ServerPort.length() <= 0) { return -1; - int intResult; - { - if (m_IsBound == false) - return -1; - intResult = sendMessageTo(m_BoundClientFamily, m_ServerIP, m_ServerPort, p_MessageBytes, p_MessageLength); } + + if (m_IsBound == false) { + return -1; + } + int intResult = sendMessageTo(m_ServerIP, m_ServerPort, message, length); return intResult; } - int receiveMessage(int p_InetFamily, char *p_Buffer, int p_BufferLength, string *p_ServerIP); - int setBroadcast(bool p_Broadcast); - int bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort); + int receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const; + int setBroadcast(bool p_Broadcast) const; + int bindSocket(string clientIp, string clientPort); - // * Internal usage - don't use this manually - // * Use sendMessage instead - int sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Port, const char *p_MessageBytes, int p_MessageLength); + int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength); - string getServerIP() { return m_ServerIP; } - string getServerPort() { return m_ServerPort; } - string getClientIP() { return m_ClientIP; } - string getClientPort() { return m_ClientPort; } - string getBoundClientPort() { return m_BoundClientPort; } - void setBoundClientPort(string p_Port) { m_BoundClientPort = p_Port; } - void setBoundClientFamily(int p_Family) { m_BoundClientFamily = p_Family; } - int getBoundClientFamily() { return m_BoundClientFamily; } + string getServerIP() const { return m_ServerIP; } + string getServerPort() const { return m_ServerPort; } + string getClientIP() const { return m_ClientIP; } + string getClientPort() const { return m_ClientPort; } + string getBoundClientPort() const { return m_BoundClientPort; } + void setBoundClientPort(const string &p_Port) { m_BoundClientPort = p_Port; } void setIsBound(bool p_IsBound) { m_IsBound = p_IsBound; } - bool getIsBound() { return m_IsBound; } + bool getIsBound() const { return m_IsBound; } + + private: }; #endif /* SPITSOCKET_H */ diff --git a/components/spit/include/SPITType.h b/components/spit/include/SPITType.h index 6d27d91..7248402 100644 --- a/components/spit/include/SPITType.h +++ b/components/spit/include/SPITType.h @@ -16,55 +16,30 @@ #include "SPITSocket.h" #include "SPIT_Message.h" -#include -#include +#include "SpitRepo.hpp" using namespace std; class SPITTypeListener; class SPITType { - private: - static unordered_map s_SPITTypes; - static unordered_map s_SPITTypesRemote; - public: - static SPITType *getSPITType(string p_ID); - static const SPITType &getSPITTypeRef(string p_ID); - static bool addSPITType(SPITType *p_ptrSpitType); - static bool removeSPITType(SPITType *p_ptrSpitType); - static int getSPITTypeCount(); - static SPITType *getSPITType(int p_Index); - static const SPITType &getSPITTypeRef(int p_Index); - static void clearSPITTypes(); - static void setConfirmedFalse(); + static void setConfirmedFalse(SpitRepo &repo); + static void eventProjectClosed(SpitRepo &repo, SpitRepo &remoteRepo); - static SPITType *getSPITTypeRemote(string p_ID); - static const SPITType &getSPITTypeRemoteRef(string p_ID); - static bool addSPITTypeRemote(SPITType *p_ptrSpitType); - static bool removeSPITTypeRemote(SPITType *p_ptrSpitType); - static int getSPITTypeRemoteCount(); - static SPITType *getSPITTypeRemote(int p_Index); - static const SPITType &getSPITTypeRemoteRef(int p_Index); - static void clearSPITTypesRemote(); - - static void eventProjectClosed(); - - SPITType(); + SPITType(string p_ID); SPITType(string p_ID, string p_GroupName, string p_Name, bool p_Fixed, bool p_ProjectIndepended, long long p_DefaultDelay, long long p_DefaultDuration); - // SPITType(const SPITType& orig); - ~SPITType(); private: - bool m_Confirmed; + bool m_Confirmed{}; string m_ID; - bool m_Fixed; - bool m_ServerRemote; - bool m_ServerProjectIndepended; - string m_GroupName; - string m_Name; - long long m_DefaultDelay; - long long m_DefaultDuration; + bool m_Fixed{}; + bool m_ServerRemote{}; + bool m_ServerProjectIndepended{}; + string m_GroupName{}; + string m_Name{}; + long long m_DefaultDelay{}; + long long m_DefaultDuration{}; bool m_CreatedByClient; // flag true = the SPITTyype is created by the client // false = the SPITType is received from the server @@ -72,24 +47,17 @@ class SPITType { bool m_ActionAssigned; // This is a virtual flag if user associates an action with a SPITType. // Can be used to setActionAssigned for all SPITObjects with this SPITType - void initMembers(); - public: string getID() const { return m_ID; } string getGroupName() const { return m_GroupName; } string getName() const { return m_Name; } /** * Returns if the SPITType triggers an action on the Server or on the client. - * @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType
+ * @return false = the action is triggered on the client The client waits for the server to play objects of this SPITType * true = the action is triggered on the server. The server waits for the client to play objects of this SPITType. */ - bool getServerRemote() const { - return m_ServerRemote; - } - - bool getProjectIndepended() const { - return m_ServerProjectIndepended; - } + bool getServerRemote() const { return m_ServerRemote; } + bool getProjectIndepended() const { return m_ServerProjectIndepended; } /** * This is used by the server and client to tell if the other side has registered the changes. * @return true = other side has registered the changes. @@ -101,40 +69,36 @@ class SPITType { bool getCreatedByClient() const { return m_CreatedByClient; } /** - * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.
- * This can used to setActionAssigned to all SPITObjects with this SPITType.
- * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.
+ * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol. + * This can used to setActionAssigned to all SPITObjects with this SPITType. + * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated. * @return true = the user has associated an action with this SPITType. */ bool getActionAssigned() const { return m_ActionAssigned; } - public: - void setID(string p_ID); - bool setGroupName(string p_GroupName); - bool setName(string p_Name); + bool setGroupName(const string &p_GroupName); + bool setName(const string &p_Name); bool setServerRemote(bool p_BelongstoServer); bool setProjectIndepended(bool p_ProjectIndepeneded); bool setConfirmed(bool p_Confirmed); bool setFixed(bool p_Fixed); bool setDefaultDelay(long long p_Delay); bool setDefaultDuration(long long p_Duration); - void setCreatedByClient(bool p_CreatedByClient); /** - * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.
- * This can used to setActionAssigned to all SPITObjects with this SPITType.
- * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.
+ * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol. + * This can used to setActionAssigned to all SPITObjects with this SPITType. + * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated. * @return true = the m_ActionAssigned has changed. */ bool setActionAssigned(bool p_ActionAssigned); - bool setMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType); - void fillMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType); - void fillMessageOP(SPIT_Message::RemoveSPITType *p_RemoveSPITType); - // static char* stringCopy(const char* p_String); + bool setMessageOP(SPIT_Message::ReportSPITType &reportSpitType); + void fillMessageOP(SPIT_Message::ReportSPITType &smReportSpitType) const; + void fillMessageOP(SPIT_Message::RemoveSPITType &smRemoveSpitType) const; }; #endif /* SPITTYPE_H */ \ No newline at end of file diff --git a/components/spit/include/SPIT_Client.h b/components/spit/include/SPIT_Client.h index fd72916..33ec376 100644 --- a/components/spit/include/SPIT_Client.h +++ b/components/spit/include/SPIT_Client.h @@ -20,6 +20,7 @@ #include "SPITSocket.h" #include "SPITType.h" #include "SPIT_Message.h" +#include "SpitRepo.hpp" #include #include @@ -32,10 +33,10 @@ class SPIT_Client : I_SAD_Client { static const int MAXSPITMESSAGEBYTECOUNT = 512; enum class ProjUpdate { - ServerLoaded, - StartTransfer, - EndTransfer, - ServerClosed, + ServerLoaded, + StartTransfer, + EndTransfer, + ServerClosed, }; enum class ServerEvent { Detect, @@ -47,69 +48,60 @@ class SPIT_Client : I_SAD_Client { Changed, Deleted }; + enum class Connection { + None = 0, // No Connection established.
Either no connect tried or disconnected + NoneServer = 1, // Server has disconnected + Lost = 2, // The connection is lost
Either because of a network crash or because the server no longer responds. + Ok = 3, // Connection to the serv er is established. + TryConnection = 4, // A connection to the server is tried. + }; struct Callbacks { void (*onServerEvent)(ServerEvent event, const SAD_DetectedServer &p_DetectedServer){}; - void (*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus){}; + void (*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, Connection p_ConnectionStatus, Connection p_OldConnectionStatus){}; void (*onProjectUpdate)(ProjUpdate state, string projectId){}; - - void (*onSpitType)(ObjectEvent event, const SPITType &p_SPITType){}; - void (*onSpitTypeRemote)(ObjectEvent event, const SPITType &p_SPITType){}; - void (*onSpitObject)(ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject){}; - void (*onSpitObjectRemote)(ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject){}; + void (*onSpitType)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType){}; + void (*onSpitObject)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType, const SPITObject &p_SPITObject){}; void (*onPlay)(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames){}; void (*onPlaySpitType)(string p_PlayerID, string p_SPITTypeID, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value){}; void (*onPlayRemoteObjectStatus)(const SPITType &p_SPITType, const SPITObject &p_SPITObject, long long p_FrameInsideObject, int p_Value){}; - bool (*onCheckSpitTypeVeto)(SPIT_Message::ReportSPITType *p_ReportSPITType){}; - bool (*onCheckSpitObjectVeto)(SPIT_Message::ReportSPITObject *p_ReportSPITObject){}; + bool (*onCheckSpitTypeVeto)(bool knownType, bool createdByClient){}; + bool (*onCheckSpitObjectVeto)(bool knownType){}; }; - //----- Connection Status ----- - public: - /** No Connection established.
Either no connect tried or disconnected*/ - static const int CONNECTION_NONE = 0; - /** Server has disconnected*/ - static const int CONNECTION_NONESERVER = 1; - /** The connection is lost
Either because of a network crash or because the server no longer responds.*/ - static const int CONNECTION_LOST = 2; - /** Connection to the serv er is established.*/ - static const int CONNECTION_OK = 3; - /** A connection to the server is tried.*/ - static const int CONNECTION_TRYCONNECTION = 4; - //------ PlayerType ------ public: /** continous main player, time value can be used like a timecode.
The time value is the position in server's project.
A server should use only one main player.*/ - static const char PLAYERTYPE_MAIN = 0x02; + static constexpr char PLAYERTYPE_MAIN = 0x02; /** continous player. This player plays SPIT objects sometime during the project.*/ - static const char PLAYERTYPE_CONTINOUS = 0x01; + static constexpr char PLAYERTYPE_CONTINOUS = 0x01; /** diescrete player. This player is used to transmit single discrete values.*/ - static const char PLAYERTYPE_DISCRETE = 0x00; + static constexpr char PLAYERTYPE_DISCRETE = 0x00; //------ Value Flag ------ //------ used by sendRemoteObject public: /**Set the given value directly*/ - static const char VALUEFLAG_DIRECT = 0x00; + static constexpr char VALUEFLAG_DIRECT = 0x00; /**Increase the existing value by the given value.
This is usefull e.g. when instead of a fader a endless wheel is used*/ - static const char VALUEFLAG_INCREASE = 0x01; + static constexpr char VALUEFLAG_INCREASE = 0x01; /**Decrease the existing value by the given value.
This is usefull e.g. when instead of a fader a endless wheel is used*/ - static const char VALUEFLAG_DECREASE = 0x02; + static constexpr char VALUEFLAG_DECREASE = 0x02; + static constexpr int MAX_OVERTAKING_SPIT_MESSAGES = 10; //----- SPIT_Client ----- public: SPIT_Client(string name, string projName, Callbacks calls); virtual ~SPIT_Client(); - static int s_MAX_OVERTAKING_SPIT_MESSAGES; private: Callbacks mCallbacks; fos::TaskT *m_ThreadReceive{}; - bool m_StopReceiveSPITMessages; + bool m_StopReceiveSPITMessages{}; - int m_ConnectionStatus; + Connection m_ConnectionStatus{Connection::None}; bool m_DisconnectedByServer{}; // flag true = when server disconnects string m_ID; string m_Name; @@ -118,9 +110,9 @@ class SPIT_Client : I_SAD_Client { string m_ClientProjectName; - unsigned char m_MessageNumber_Send; - int m_MessageNumber_Received; - vector m_OvertakingSPIT_Messages; + uint8_t m_MessageNumber_Send{1}; + int m_MessageNumber_Received{-1}; // set to -1 because the first received message will set the number (1..255) + vector> m_OvertakingSPIT_Messages; // Server's info filled by parseConnectAnswer string m_ServerID{}; @@ -181,8 +173,7 @@ class SPIT_Client : I_SAD_Client { // Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by m_ServerID public: - void fillHeader(SPIT_Message::Header *p_Header); - int sendSPITMessage(SPIT_Message::OPPart &p_SPITMessageOPPart); + int sendSPITMessage(SPIT_Message::OPPart & spitMessageOPPart); //--------------- ServerAutoDetection SAD --------------- public: @@ -216,15 +207,15 @@ class SPIT_Client : I_SAD_Client { void disconnect(); private: - void disconnectInternal(int p_Cause); + void disconnectInternal(Connection p_Cause); void resetMessageNumberReceived(); void parseSPIT_Message(unique_ptr p_SPITMessage); void checkParseSPIT_Message(unique_ptr p_SPITMessage); - void addOvertakingSPIT_Message(SPIT_Message *p_SPIT_Message); - void parseConnectAnswer(SPIT_Message::ConnectAnswer *p_ConnectAnswer); - void parseDisconnect(SPIT_Message::Disconnect *p_Disconnect); - void parseWatchdog(SPIT_Message::Watchdog *p_Watchdog); - void parseWatchdogAnswer(SPIT_Message::WatchdogAnswer *p_WatchdogAnswer); + void addOvertakingSPIT_Message(unique_ptr p_SPIT_Message); + void parseConnectAnswer(SPIT_Message::ConnectAnswer &p_ConnectAnswer); + void parseDisconnect(SPIT_Message::Disconnect &p_Disconnect); + void parseWatchdog(SPIT_Message::Watchdog &p_Watchdog); + void parseWatchdogAnswer(SPIT_Message::WatchdogAnswer &p_WatchdogAnswer); public: /** Used internally*/ @@ -233,8 +224,8 @@ class SPIT_Client : I_SAD_Client { void eventWatchdogLost(); //--------------- SPIT Project --------------- private: - void parseReportSPITProject(SPIT_Message::ReportSPITProject *p_ReportSPITProject); - void parseCloseSPITProject(SPIT_Message::CloseSPITProject *p_CloseSPITProject); + void parseReportSPITProject(SPIT_Message::ReportSPITProject &p_ReportSPITProject); + void parseCloseSPITProject(SPIT_Message::CloseSPITProject &p_CloseSPITProject); public: /** Returns the SPITServer's project ID - may be the same as the project's name*/ @@ -245,9 +236,9 @@ class SPIT_Client : I_SAD_Client { int getServerFramesPerSecond(); private: - void parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer *p_RequestProjectTransfer); - void parseStartProjectTransfer(SPIT_Message::StartProjectTransfer *p_StartProjectTransfer); - void parseEndProjectTransfer(SPIT_Message::EndProjectTransfer *p_EndProjectTransfer); + void parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer &p_RequestProjectTransfer); + void parseStartProjectTransfer(SPIT_Message::StartProjectTransfer &p_StartProjectTransfer); + void parseEndProjectTransfer(SPIT_Message::EndProjectTransfer &p_EndProjectTransfer); public: static void sendProject(SPIT_Client *p_PtrSPIT_Client); @@ -283,9 +274,9 @@ class SPIT_Client : I_SAD_Client { private: // receive SPITTypes - void parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPITType); - void parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPITType); - int sendSPITTypeInternal(SPITType *p_SPITType); + void parseReportSPITType(SPIT_Message::ReportSPITType &p_ReportSPITType); + void parseRemoveSPITType(SPIT_Message::RemoveSPITType &p_RemoveSPITType); + int sendSPITTypeInternal(SPITType &p_SPITType); public: /** @@ -306,8 +297,8 @@ class SPIT_Client : I_SAD_Client { public: //--------------- SPIT Objects --------------- private: - void parseReportSPITObject(SPIT_Message::ReportSPITObject *p_ReportSPITObject); - void parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject); + void parseReportSPITObject(SPIT_Message::ReportSPITObject &p_ReportSPITObject); + void parseRemoveSPITObject(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject); int sendSPITObjectInternal(SPITObject *ptrSPITObject); public: @@ -329,10 +320,10 @@ class SPIT_Client : I_SAD_Client { public: //--------------- Play SPIT Objects --------------- private: - void parsePlaySPITStart(SPIT_Message::PlaySPITStart *p_PlaySPITStart); - void parsePlaySPITObject(SPIT_Message::PlaySPITObject *p_PlaySPITObject); - void parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd); - void parseReportPlayStatus(SPIT_Message::ReportPlayStatus *p_ReportPlayStatus); + void parsePlaySPITStart(SPIT_Message::PlaySPITStart &p_PlaySPITStart); + void parsePlaySPITObject(SPIT_Message::PlaySPITObject &p_PlaySPITObject); + void parsePlaySPITEnd(SPIT_Message::PlaySPITEnd &p_PlaySPITEnd); + void parseReportPlayStatus(SPIT_Message::ReportPlayStatus &p_ReportPlayStatus); public: //--------- Remote ---------- @@ -341,13 +332,18 @@ class SPIT_Client : I_SAD_Client { private: static void processSocketTask(SPIT_Client &instance); fos::TaskT *sThread{}; - bool abortSearch{}; + bool mAbortSearch{}; bool sAnswered{}; static fos::Semaphore sStartSad; SPITSocket *mSPITSocket; void answerWatchdog() { sAnswered = true; } + + SpitRepo mSpitObjects; + SpitRepo mRemoteSpitObjects; + SpitRepo mSpitTypes; + SpitRepo mRemoteSpitTypes; }; #endif /* SPIT_CLIENT_H */ diff --git a/components/spit/include/SPIT_Message.h b/components/spit/include/SPIT_Message.h index 9c3a0fb..360984d 100644 --- a/components/spit/include/SPIT_Message.h +++ b/components/spit/include/SPIT_Message.h @@ -15,56 +15,52 @@ #define SPIT_MESSAGE_H #include +#include +#include #include +#include 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; - virtual ~Header(); + static constexpr int BYTESLENGTH = 99; 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_OPFlag; - int m_ParseOffset = 0; - - void initMembers(); + int m_SPITVersion{SPITVERSION}; + unsigned char m_MessageNumber{}; + int m_BytesCount{BYTESLENGTH}; + string m_ServerID{}; + string m_ClientID{}; + int m_OPFlag{-1}; + 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); + bool parse(const std::vector &message); // Send - public: Header(int p_SPITVersion, int p_OPFlag); - void setMessageNumber(unsigned char p_MessageNumber); - void setServerID(string p_ServerID); - void setClientID(string p_ID); - void setOPFlag(int p_OPFlag); - bool fillBytes(char *p_Bytes, int p_ByteCount); + void setMessageNumber(unsigned char p_MessageNumber) { m_MessageNumber = p_MessageNumber; } + void setServerID(string p_ID) { m_ServerID = p_ID; } + void setClientID(string p_ID) { m_ClientID = p_ID; } + void setOPFlag(int p_OPFlag) { m_OPFlag = p_OPFlag; } + bool fillBytes(std::vector &message); }; //----------- OPPart ----------- @@ -73,103 +69,104 @@ class SPIT_Message { // Members protected: - Header *m_Header; - int m_ParseOffset; + unique_ptr
m_Header{}; + int m_ParseOffset{}; int m_BytesCount; - private: - void initMembers(); - public: - virtual ~OPPart(); - // OPPart(const OPPart& orig); - Header *getHeader() const { return m_Header; } - int getBytesCount() const { return m_BytesCount; } + virtual ~OPPart(); - const string getServerID() const { - if (m_Header == NULL) + Header *getHeader() const { return m_Header.get(); } + int getBytesCount() const { return m_BytesCount; } + void setServerInfoInHeader(string clientId, string serverId) { + if (!m_Header) + return; + m_Header->setClientID(clientId); + m_Header->setServerID(serverId); + } + void setMessageNumber(uint8_t no) { + if (!m_Header) + return; + m_Header->setMessageNumber(no); + } + + const string getServerID() const { + if (!m_Header) { return ""; + } return m_Header->getServerID(); } const string getClientID() const { - if (m_Header == NULL) + if (!m_Header) { return ""; + } return m_Header->getClientID(); } int getOPFlag() const { - if (m_Header == NULL) + if (!m_Header) { return -1; + } return m_Header->getOPFlag(); } // Receive - public: - OPPart(Header *p_Header, int p_OPFlag); - void setHeader(Header *p_Header); - virtual bool parse(char *p_Bytes, int p_ByteCounth) = 0; + OPPart(unique_ptr
p_Header, int p_OPFlag, int size); + void setHeader(int opFlag); + virtual bool parse(const std::vector &message) = 0; // Send - public: - OPPart(); - virtual bool fillBytes(char *p_Bytes, int p_ByteCount) = 0; + OPPart(int size); + virtual bool fillBytes(std::vector &message) = 0; }; //----------- SPIT_Message ----------- public: - static const int SPITVERSION = 1; + static constexpr int SPITVERSION = 1; // SPIT_Object value usage - static const char VALUEUSE_DISCARD = 0x00; // value of SPITObejct is not used - static const char VALUEUSE_INRANGE = 0x01; // value of SPITOBject in range 0 - 1000000ppm - static const char VALUEUSE_OVERRIDE = 0x02; // value can be overridden + 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 const char PLAYERTYPE_MAIN = 0x02; - static const char PLAYERTYPE_CONTINIOUS = 0x01; - static const char PLAYERTYPE_DISCRETE = 0x00; + static constexpr char PLAYERTYPE_MAIN = 0x02; + static constexpr char PLAYERTYPE_CONTINIOUS = 0x01; + static constexpr char PLAYERTYPE_DISCRETE = 0x00; // PlayObject value usage - static const char VALUEFLAG_DIRECT = 0x00; // use the vlue direct - static const char VALUEFLAG_INCREASE = 0x01; // increase the value - static const char VALUEFLAG_DECREASE = 0x02; // decrease the value + 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 - SPIT_Message(); - virtual ~SPIT_Message(); - // SPIT_Message(const SPIT_Message& orig); + SPIT_Message() = default; // Members private: - char *m_MessageBytes; - int m_MessageByteCount; - Header *m_Header; - OPPart *m_OPPart; - bool m_MessageBytesCreated; - - void initMembers(); + unique_ptr m_OPPart{}; // Receive public: - SPIT_Message(char *p_MessageBytes, int p_MessageBytesLength); + SPIT_Message(std::vector message); - // SPIT_Message(const SPIT_Message& orig); - const Header *getHeader() const { return m_Header; } + const Header *getHeader() const { return m_OPPart->getHeader(); } int getOPFlag() const { - if (m_Header == NULL) + if (!m_OPPart || !m_OPPart->getHeader()) { return -1; - return m_Header->getOPFlag(); + } + return m_OPPart->getHeader()->getOPFlag(); } - const OPPart *getOPPart() const { return m_OPPart; } - int getMesageByteCount() const { return m_MessageByteCount; } + const OPPart *getOPPart() const { return m_OPPart.get(); } + template + T &getOPPartAs() const { return *reinterpret_cast(m_OPPart.get()); } - OPPart *parse(); + private: + bool parse(std::vector message); // Send public: - SPIT_Message(OPPart *p_OPPart); - bool fillBytes(); - const char *getMessageBytes(); + static std::vector createMessage(OPPart & p_OPPart); //------------------------------ Connection ---------------------------------- @@ -177,67 +174,58 @@ class SPIT_Message { public: class Connect : public OPPart { public: - static const int OPFLAG = 1; - static const int BYTESLENGTH = 304; + static constexpr int OPFLAG = 1; + static constexpr int BYTESLENGTH = 304; private: - string m_ClientComputerName; - string m_ClientName; - string m_LoginName; - string m_LoginPassword; - string m_ServerIP; - int m_ServerPort; - void initMembers(); + string m_ClientComputerName{}; + string m_ClientName{}; + string m_LoginName{}; + string m_LoginPassword{}; + string m_ServerIP{}; + int m_ServerPort{}; public: - ~Connect(); - // Connect(const Connect& orig); // Receive - public: - Connect(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + Connect(unique_ptr
p_Header); + bool parse(const std::vector &message); - const string getClientComputerName() const { return m_ClientComputerName; } - const string getClientName() const { return m_ClientName; } - const string getLoginName() const { return m_LoginName; } - const string getLoginPassword() const { return m_LoginPassword; } - const string getServerIP() const { return m_ServerIP; } + string getClientComputerName() const { return m_ClientComputerName; } + string getClientName() const { return m_ClientName; } + string getLoginName() const { return m_LoginName; } + string getLoginPassword() const { return m_LoginPassword; } + string getServerIP() const { return m_ServerIP; } int getServerPort() const { return m_ServerPort; } // Send - public: - Connect(); - void setClientComputerName(string p_ComputerName); - void setClientName(string p_ClientName); - void setLoginName(string p_LoginName); - void setLoginPassword(string p_LoginPassword); - void setServerIP(string p_ServerIP); + Connect(string p_ComputerName, string p_ClientName); + + void setLoginName(string p_LoginName) { m_LoginName = p_LoginName; } + void setLoginPassword(string p_LoginPassword) { m_LoginPassword = p_LoginPassword; } + void setServerIP(string p_ServerIP) { m_ServerIP = p_ServerIP; } void setServerPort(int p_ServerPort); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + bool fillBytes(std::vector &message); }; //----------- ConnectAnswer ----------- class ConnectAnswer : public OPPart { public: - static const int OPFLAG = 2; - static const int BYTESLENGTH = 137; + static constexpr int OPFLAG = 2; + static constexpr int BYTESLENGTH = 137; private: - string m_ServerComputerName; - string m_ServerName; - bool m_Connected; - int m_StepTime; // ms step size the Server will send play sequences - - void initMembers(); + string m_ServerComputerName{}; + string m_ServerName{}; + bool m_Connected{}; + int m_StepTime{40}; // ms step size the Server will send play sequences public: - ~ConnectAnswer(); ConnectAnswer(const ConnectAnswer &orig); // Receive - ConnectAnswer(Header *p_Header); + ConnectAnswer(unique_ptr
p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + bool parse(const std::vector &message); const string getServerComputerName() const { return m_ServerComputerName; } const string getServerName() const { return m_ServerName; } @@ -245,81 +233,63 @@ class SPIT_Message { int getStepTime() const { return m_StepTime; } // Send - public: ConnectAnswer(); - void setServerComputerName(string p_ServerComputerName); - void setServerName(string p_ContollerName); - void setConnected(bool p_Connected); + void setServerComputerName(string p_ServerComputerName) { m_ServerComputerName = p_ServerComputerName; } + void setServerName(string p_ServerName) { m_ServerName = p_ServerName; } + void setConnected(bool p_Connected) { m_Connected = p_Connected; } void setStepTime(int p_StepTime_ms); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + bool fillBytes(std::vector &message); }; //----------- Disconnect ----------- class Disconnect : public OPPart { public: - static const int OPFLAG = 3; - static const int BYTESLENGTH = 4; + static constexpr int OPFLAG = 3; + static constexpr int BYTESLENGTH = 4; - private: - void initMembers(); - - public: - ~Disconnect(); Disconnect(const Disconnect &orig); // Receive - Disconnect(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + Disconnect(unique_ptr
p_Header); + bool parse(const std::vector &message); // Send - public: Disconnect(); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + bool fillBytes(std::vector &message); }; //----------- Watchdog ----------- class Watchdog : public OPPart { public: - static const int OPFLAG = 8; - static const int BYTESLENGTH = 4; + static constexpr int OPFLAG = 8; + static constexpr int BYTESLENGTH = 4; - private: - void initMembers(); - - public: - ~Watchdog(); Watchdog(const Watchdog &orig); // Receive - Watchdog(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + Watchdog(unique_ptr
p_Header); + bool parse(const std::vector &message); // Send - public: Watchdog(); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + bool fillBytes(std::vector &message); }; //----------- WatchdogAnswer ----------- class WatchdogAnswer : public OPPart { public: - static const int OPFLAG = 9; - static const int BYTESLENGTH = 4; + static constexpr int OPFLAG = 9; + static constexpr int BYTESLENGTH = 4; - private: - void initMembers(); // Receive - public: - ~WatchdogAnswer(); WatchdogAnswer(const WatchdogAnswer &orig); - WatchdogAnswer(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + WatchdogAnswer(unique_ptr
p_Header); + bool parse(const std::vector &message); // Send - public: WatchdogAnswer(); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + bool fillBytes(std::vector &message); }; //------------------------------ SPITProject ---------------------------------- @@ -328,129 +298,96 @@ class SPIT_Message { class ReportSPITProject : public OPPart { public: - static const int OPFLAG = 11; - static const int BYTESLENGTH = 113; + static constexpr int OPFLAG = 11; + static constexpr int BYTESLENGTH = 113; private: - string m_ProjectID; - string m_ProjectName; - int m_FramesPerSecond; // Frames per second + string m_ProjectID{}; + string m_ProjectName{}; + int m_FramesPerSecond{1000}; // Frames per second - void initMembers(); // Receive public: - ~ReportSPITProject(); ReportSPITProject(const ReportSPITProject &orig); - ReportSPITProject(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); - const string getProjectID() const { - return m_ProjectID; - } - const string getProjectName() const { - return m_ProjectName; - } - int getFramesPerSecond() const { - return m_FramesPerSecond; - } + ReportSPITProject(unique_ptr
p_Header); + bool parse(const std::vector &message); + const string getProjectID() const { return m_ProjectID; } + const string getProjectName() const { return m_ProjectName; } + int getFramesPerSecond() const { return m_FramesPerSecond; } // Send - ReportSPITProject(); + ReportSPITProject(string p_ProjectID, string p_ProjectName); - void setProjectID(string p_ClientID); - void setProjectName(string p_ClientName); - void setFramesPerSecond(const int p_FramesPerSecond); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + void setFramesPerSecond(const int p_FramesPerSecond) { m_FramesPerSecond = p_FramesPerSecond; } + bool fillBytes(std::vector &message); }; //----------- CloseSPITProject ----------- class CloseSPITProject : public OPPart { public: - static const int OPFLAG = 13; - static const int BYTESLENGTH = 45; + static constexpr int OPFLAG = 13; + static constexpr int BYTESLENGTH = 45; private: - string m_ProjectID; - - void initMembers(); + string m_ProjectID{}; public: - ~CloseSPITProject(); CloseSPITProject(const CloseSPITProject &orig); // Receive - CloseSPITProject(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + CloseSPITProject(unique_ptr
p_Header); + bool parse(const std::vector &message); const string getProjectID() const { return m_ProjectID; } // Send - public: - CloseSPITProject(); - - void setProjectID(string p_ClientID); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + CloseSPITProject(string projectID); + bool fillBytes(std::vector &message); }; //----------- StartProjectTransfer ----------- class RequestProjectTransfer : public OPPart { public: - static const int OPFLAG = 15; - static const int BYTESLENGTH = 4; + static constexpr int OPFLAG = 15; + static constexpr int BYTESLENGTH = 4; - private: - void initMembers(); - - public: - ~RequestProjectTransfer(); RequestProjectTransfer(const RequestProjectTransfer &orig); // Receive - RequestProjectTransfer(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + RequestProjectTransfer(unique_ptr
p_Header); + bool parse(const std::vector &message); // Send - public: RequestProjectTransfer(); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + bool fillBytes(std::vector &message); }; //----------- StartProjectTransfer ----------- class StartProjectTransfer : public OPPart { public: - static const int OPFLAG = 16; - static const int BYTESLENGTH = 4; + static constexpr int OPFLAG = 16; + static constexpr int BYTESLENGTH = 4; - private: - void initMembers(); - - public: - ~StartProjectTransfer(); StartProjectTransfer(const StartProjectTransfer &orig); // Receive - StartProjectTransfer(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + StartProjectTransfer(unique_ptr
p_Header); + bool parse(const std::vector &message); // Send - public: StartProjectTransfer(); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + bool fillBytes(std::vector &message); }; //----------- EndProjectTransfer ----------- class EndProjectTransfer : public OPPart { public: - static const int OPFLAG = 17; - static const int BYTESLENGTH = 4; + static constexpr int OPFLAG = 17; + static constexpr int BYTESLENGTH = 4; - private: - void initMembers(); - - public: - ~EndProjectTransfer(); EndProjectTransfer(const EndProjectTransfer &orig); // Receive - EndProjectTransfer(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + EndProjectTransfer(unique_ptr
p_Header); + bool parse(const std::vector &message); // Send EndProjectTransfer(); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + bool fillBytes(std::vector &message); }; //---------------------------- SPIT_Types ---------------------------------- @@ -458,100 +395,73 @@ class SPIT_Message { //----------- ReportSPITType ----------- class ReportSPITType : public OPPart { public: - static const int OPFLAG = 21; - static const int BYTESLENGTH = 168; + static constexpr int OPFLAG = 21; + static constexpr int BYTESLENGTH = 168; private: - bool m_Confirmed; - string m_SPITTypeID; - bool m_Fixed; - bool m_ServerRemote; - bool m_ServerProjectIndepended; - string m_SPITTypeGroupName; - string m_SPITTypeName; - long long m_Delay; - long long m_Duration; - - void initMembers(); + bool m_Confirmed{}; + string m_SPITTypeID{}; + bool m_Fixed{}; + bool m_ServerRemote{}; + bool m_ServerProjectIndepended{}; + string m_SPITTypeGroupName{}; + string m_SPITTypeName{}; + long long m_Delay{}; + long long m_Duration{}; public: - ~ReportSPITType(); ReportSPITType(const ReportSPITType &orig); // Receive - ReportSPITType(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + ReportSPITType(unique_ptr
p_Header); + bool parse(const std::vector &message); - bool getConfirmed() const { - return m_Confirmed; - } - const string getID() const { - return m_SPITTypeID; - } - bool getFixed() const { - return m_Fixed; - } - bool getServerRemote() const { - return m_ServerRemote; - } - bool getServerProjectIndepended() const { - return m_ServerProjectIndepended; - } - const string getGroupName() const { - return m_SPITTypeGroupName; - } - const string getName() const { - return m_SPITTypeName; - } - long long getDelay() const { - return m_Delay; - } - long long getDuration() const { - return m_Duration; - } + bool getConfirmed() const { return m_Confirmed; } + const string getID() const { return m_SPITTypeID; } + bool getFixed() const { return m_Fixed; } + bool getServerRemote() const { return m_ServerRemote; } + bool getServerProjectIndepended() const { return m_ServerProjectIndepended; } + const string getGroupName() const { return m_SPITTypeGroupName; } + const string getName() const { return m_SPITTypeName; } + long long getDelay() const { return m_Delay; } + long long getDuration() const { return m_Duration; } // Send - public: + ReportSPITType(); + void setConfirmed(bool p_Confirmed) { m_Confirmed = p_Confirmed; } + void setID(string p_ID) { m_SPITTypeID = p_ID; } + void setFixed(bool p_Fixed) { m_Fixed = p_Fixed; } + void setServerRemote(bool p_IsServerRemote) { m_ServerRemote = p_IsServerRemote; } + void setServerProjectIndepended(bool p_ProjectIndpended) { m_ServerProjectIndepended = p_ProjectIndpended; } + void setGroupName(string p_GroupName) { m_SPITTypeGroupName = p_GroupName; } + void setName(string p_Name) { m_SPITTypeName = p_Name; } + void setDelay(long long p_Delay) { m_Delay = p_Delay; } + void setDuration(long long p_Duration) { m_Duration = p_Duration; } - void setConfirmed(bool p_Confirmed); - void setID(string p_ID); - void setFixed(bool p_Fixed); - void setServerRemote(bool p_IsServerRemote); - void setServerProjectIndepended(bool p_ProjectIndpended); - void setGroupName(string p_GroupName); - void setName(string p_Name); - void setDelay(long long p_Delay); - void setDuration(long long p_Duration); - - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + bool fillBytes(std::vector &message); }; //----------- RemoveSPITType ----------- class RemoveSPITType : public OPPart { public: - static const int OPFLAG = 23; - static const int BYTESLENGTH = 45; + static constexpr int OPFLAG = 23; + static constexpr int BYTESLENGTH = 45; private: - string m_SPITTypeID; - - void initMembers(); + string m_SPITTypeID{}; public: - ~RemoveSPITType(); RemoveSPITType(const RemoveSPITType &orig); // Receive - RemoveSPITType(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + RemoveSPITType(unique_ptr
p_Header); + bool parse(const std::vector &message); + + const string getID() const { return m_SPITTypeID; } - const string getID() const { - return m_SPITTypeID; - } // Send RemoveSPITType(); - - void setID(string p_ID); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + void setID(string p_ID) { m_SPITTypeID = p_ID; } + bool fillBytes(std::vector &message); }; //---------------------------- SPITObjects ---------------------------------- @@ -560,37 +470,34 @@ class SPIT_Message { class ReportSPITObject : public OPPart { public: - static const int OPFLAG = 31; - static const int BYTESLENGTH = 339; + static constexpr int OPFLAG = 31; + static constexpr int BYTESLENGTH = 339; private: - bool m_Confirmed; - string m_SPITObjectID; - bool m_Fixed; - bool m_ServerRemote; - string m_SPITObjectName; - string m_SPITTypeID; - string m_ServerParams; - long long m_FrameStart; - long long m_FrameLength; - long long m_FrameFadeInLength; - long long m_FrameFadeOutLength; - int m_ValueFactor; - char m_ValueUse; - int m_Track; - string m_Remark; - long long m_Delay; - long long m_Duration; - bool m_ActionAssigned; - - void initMembers(); + bool m_Confirmed{}; + string m_SPITObjectID{}; + bool m_Fixed{}; + bool m_ServerRemote{}; + string m_SPITObjectName{}; + string m_SPITTypeID{}; + string m_ServerParams{}; + long long m_FrameStart{}; + long long m_FrameLength{}; + long long m_FrameFadeInLength{}; + long long m_FrameFadeOutLength{}; + int m_ValueFactor{}; + char m_ValueUse{VALUEUSE_DISCARD}; + int m_Track{}; + string m_Remark{}; + long long m_Delay{}; + long long m_Duration{}; + bool m_ActionAssigned{}; public: - ~ReportSPITObject(); ReportSPITObject(const ReportSPITObject &orig); // Receive - ReportSPITObject(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + ReportSPITObject(unique_ptr
p_Header); + bool parse(const std::vector &message); bool getConfirmed() const { return m_Confirmed; } const string getID() const { return m_SPITObjectID; } @@ -614,54 +521,49 @@ class SPIT_Message { public: ReportSPITObject(); - void setConfirmed(bool p_Confirmed); - void setID(string p_ID); - void setFixed(bool p_Fixed); - void setServerRemote(bool p_IsRemote); - void setName(string p_Name); - void setSPITTypeID(string p_ID); - void setServerParams(string p_Parameters); - void setFrameStart(long long p_StartTime); - void setFrameLength(long long p_Length); - void setFrameFadeInLength(long long p_FadeInTime); - void setFrameFadeOutLength(long long p_FadeOutTime); - void setValueFactor(int p_Volume); - void setValueUse(char p_ValueUse); - void setTrack(int p_Track); - void setRemark(string p_Description); + void setConfirmed(bool p_Confirmed) { m_Confirmed = p_Confirmed; }; + void setID(string p_ID) { m_SPITObjectID = p_ID; }; + void setFixed(bool p_Fixed) { m_Fixed = p_Fixed; }; + void setServerRemote(bool p_IsRemote) { m_ServerRemote = p_IsRemote; }; + void setName(string p_Name) { m_SPITObjectName = p_Name; }; + void setSPITTypeID(string p_ID) { m_SPITTypeID = p_ID; }; + void setServerParams(string p_Parameters) { m_ServerParams = p_Parameters; }; + void setFrameStart(long long p_StartTime) { m_FrameStart = p_StartTime; }; + void setFrameLength(long long p_Length) { m_FrameLength = p_Length; }; + void setFrameFadeInLength(long long p_FadeInTime) { m_FrameFadeInLength = p_FadeInTime; }; + void setFrameFadeOutLength(long long p_FadeOutTime) { m_FrameFadeOutLength = p_FadeOutTime; }; + void setValueFactor(int p_Volume) { m_ValueFactor = p_Volume; }; + void setValueUse(char p_ValueUse) { m_ValueUse = p_ValueUse; }; + void setTrack(int p_Track) { m_Track = p_Track; }; + void setRemark(string p_Description) { m_Remark = p_Description; }; 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); + void setActionAssigned(bool p_ActionAssigned) { m_ActionAssigned = p_ActionAssigned; } + bool fillBytes(std::vector &message); }; //----------- RemoveSPITObject ----------- class RemoveSPITObject : public OPPart { public: - static const int OPFLAG = 33; - static const int BYTESLENGTH = 45; + static constexpr int OPFLAG = 33; + static constexpr int BYTESLENGTH = 45; private: - string m_SPITObjectID; - - void initMembers(); + string m_SPITObjectID{}; public: - ~RemoveSPITObject(); RemoveSPITObject(const RemoveSPITObject &orig); // Receive - RemoveSPITObject(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + RemoveSPITObject(unique_ptr
p_Header); + bool parse(const std::vector &message); - const string getID() const { - return m_SPITObjectID; - } + const string getID() const { return m_SPITObjectID; } // Send public: RemoveSPITObject(); - void setID(string p_ID); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + void setID(string p_ID) { m_SPITObjectID = p_ID; } + bool fillBytes(std::vector &message); }; //---------------------------- SPITPlayer ---------------------------------- @@ -670,24 +572,21 @@ class SPIT_Message { class PlaySPITStart : public OPPart { public: - static const int OPFLAG = 37; - static const int BYTESLENGTH = 119; + static constexpr int OPFLAG = 37; + static constexpr int BYTESLENGTH = 119; private: - string m_PlayerID; - string m_PlayerName; - char m_PlayerType; - bool m_PlayerIsRunning; + string m_PlayerID{}; + string m_PlayerName{}; + char m_PlayerType{}; + bool m_PlayerIsRunning{}; long long m_Time; // Frames - void initMembers(); - public: - ~PlaySPITStart(); PlaySPITStart(const PlaySPITStart &orig); // Receive - PlaySPITStart(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + PlaySPITStart(unique_ptr
p_Header); + bool parse(const std::vector &message); const string getPlayerID() const { return m_PlayerID; } const string getPlayerName() const { return m_PlayerName; } @@ -696,40 +595,32 @@ class SPIT_Message { long long getTime() const { return m_Time; } // Send - public: - PlaySPITStart(); - - void setPlayerID(string p_PlayerID); - void setPlayerName(string p_PlayerName); - void setPlayerType(char p_PlayerType); - void setPlayerIsRunning(bool p_IsPlaying); - void setTime(long long p_Time); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + PlaySPITStart(string p_PlayerID, string p_PlayerName, char p_PlayerType); + void setPlayerIsRunning(bool p_IsPlaying) { m_PlayerIsRunning = p_IsPlaying; } + void setTime(long long p_Time) { m_Time = p_Time; } + bool fillBytes(std::vector &message); }; //----------- PlaySPITObject ----------- class PlaySPITObject : public OPPart { public: - static const int OPFLAG = 38; - static const int BYTESLENGTH = 100; + static constexpr int OPFLAG = 38; + static constexpr int BYTESLENGTH = 100; private: - string m_PlayerID; - string m_SPITObjectID; - long long m_FrameInsideObject; // Frames - bool m_PlayPrePosition; - int m_Value; - char m_ValueFlag; - - void initMembers(); + string m_PlayerID{}; + string m_SPITObjectID{}; + long long m_FrameInsideObject{}; // Frames + bool m_PlayPrePosition{}; + int m_Value{}; + char m_ValueFlag{VALUEFLAG_DIRECT}; public: - ~PlaySPITObject(); PlaySPITObject(const PlaySPITObject &orig); // Receive - PlaySPITObject(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + PlaySPITObject(unique_ptr
p_Header); + bool parse(const std::vector &message); const string getPlayerID() const { return m_PlayerID; } const string getSPITObjectID() const { return m_SPITObjectID; } @@ -740,61 +631,53 @@ class SPIT_Message { // Send PlaySPITObject(); - void setPlayerID(string p_PlayerID); - void setID(string p_ID); - void setFrameInsideObject(long long p_TimeInside); - void setPlayPrePosition(bool p_PlayOldPosition); - void setValue(int p_Value); - void setValueFlag(char p_ValueFlag); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + void setPlayerID(string p_PlayerID) { m_PlayerID = p_PlayerID; } + void setID(string p_ID) { m_SPITObjectID = p_ID; } + void setFrameInsideObject(long long p_TimeInside) { m_FrameInsideObject = p_TimeInside; } + void setPlayPrePosition(bool p_PlayOldPosition) { m_PlayPrePosition = p_PlayOldPosition; } + void setValue(int p_Value) { m_Value = p_Value; } + void setValueFlag(char p_ValueFlag) { m_ValueFlag = p_ValueFlag; } + bool fillBytes(std::vector &message); }; //----------- PlaySPITEnd ----------- class PlaySPITEnd : public OPPart { public: - static const int OPFLAG = 39; - static const int BYTESLENGTH = 45; + static constexpr int OPFLAG = 39; + static constexpr int BYTESLENGTH = 45; private: - string m_PlayerID; - - void initMembers(); + string m_PlayerID{}; public: - ~PlaySPITEnd(); PlaySPITEnd(const PlaySPITEnd &orig); // Receive - PlaySPITEnd(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); - + PlaySPITEnd(unique_ptr
p_Header); + bool parse(const std::vector &message); const string getPlayerID() const { return m_PlayerID; } + // Send - public: - PlaySPITEnd(); - void setPlayerID(string p_PlayerID); - bool fillBytes(char *p_MessageBytes, int p_ByteCount); + PlaySPITEnd(string p_PlayerID); + bool fillBytes(std::vector &message); }; //----------- ReportPlayStatus ----------- class ReportPlayStatus : public OPPart { public: - static const int OPFLAG = 40; - static const int BYTESLENGTH = 57; + static constexpr int OPFLAG = 40; + static constexpr int BYTESLENGTH = 57; private: - string m_SPITObjectID; - long long m_FrameInsideObject; // Frames - int m_Value; - - void initMembers(); + string m_SPITObjectID{}; + long long m_FrameInsideObject{}; // Frames + int m_Value{}; public: - ~ReportPlayStatus(); ReportPlayStatus(const ReportPlayStatus &orig); // Receive - ReportPlayStatus(Header *p_Header); - bool parse(char *p_Bytes, int p_ByteCount); + ReportPlayStatus(unique_ptr
p_Header); + bool parse(const std::vector &message); const string getID() const { return m_SPITObjectID; } long long getFrameInsideObject() const { return m_FrameInsideObject; } @@ -805,57 +688,41 @@ 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(std::vector &message); }; //----------------------- 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 getInt(const std::vector &message, int &offset); + static optional getLong(const std::vector &message, int &offset); + static optional getBoolean(const std::vector &message, int &offset); + static optional getByte(const std::vector &message, int &offset); + static int setInt(int value, std::vector &message, int offset); + static int setLong(long long value, std::vector &message, int offset); + static int setBoolean(bool value, std::vector &message, int offset); + static int setByte(int value, std::vector &message, 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 p_Length the length of the string included the null terminate byte (0x00).
+ * @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. - * @return the String char* - * @throws Exception if p_Bytes == null
- * p_Offset less than 0
- * p_Bytes.length less than p_Offset + p_Length
- * No 0x00 null terminate byte is found */ - static string getString(char *p_Bytes, int p_ByteCount, int p_Offset, int p_Length); + static optional getString(const std::vector &message, int &offset, int maxLength); /** - * Fill the p_String in the byte array.
+ * 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_Bytes the byte array where the string is filled - * @param p_Offset the offset inside the byte array - * @param p_Length the maximal length of the string included the null character.
- * @throws Exception if p_String == NULL, p_Bytes == NULL
- * p_Offset less than 0
+ * @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, char *p_Bytes, int p_ByteCount, int p_Offset, int p_Length); - /** - * Compares two strings for equality. - * @param p_String1 string terminated by null character - * @param p_String2 string terminated by null character - * @return true if both strings are equal
- * false if the strings are NULL or not equal or not terminated by "\0" - */ - // 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 int setString(string p_String, std::vector &message, int p_Offset, int p_Length); }; #endif /* SPIT_MESSAGE_H */ diff --git a/components/spit/include/SpitRepo.hpp b/components/spit/include/SpitRepo.hpp new file mode 100644 index 0000000..0b3432e --- /dev/null +++ b/components/spit/include/SpitRepo.hpp @@ -0,0 +1,68 @@ +#pragma once +#include +#include +#include + +template +class SpitRepo { + public: + bool hasEntry(const string &id) { + return mEntries.contains(id); + } + + T *getEntry(const string &id) { + auto i = mEntries.find(id); + if (i == mEntries.end()) { + return nullptr; + } + return i->second.get(); + } + + const T &getEntryRef(const string &id) { + return *mEntries.at(id); + } + + T *getEntry(int index) { + if (index >= 0 && index < mEntries.size()) { + return next(mEntries.begin(), index)->second.get(); + } + return nullptr; + } + const T &getEntryRef(int index) { + if (index >= 0 && index < mEntries.size()) { + auto i = next(mEntries.begin(), index); + return *i->second; + } else { + throw "SPITObject index out of range"; + } + } + + void addEntry(unique_ptr entry) { + mEntries[entry->getID()] = move(entry); + } + bool removeEntry(const T &entry) { + return removeEntry(entry.getID()); + } + bool removeEntry(const string &id) { + auto i = mEntries.find(id); + if (i == mEntries.end()) { + return false; + } + mEntries.erase(i); + return true; + } + int getEntryCount() { + return mEntries.size(); + } + + unordered_map> &getRepo() { + return mEntries; + } + + void clearEntries() { + mEntries.clear(); + } + + private: + unordered_map> mEntries; +}; diff --git a/components/spit/src/SAD_DetectedServer.cpp b/components/spit/src/SAD_DetectedServer.cpp deleted file mode 100644 index e50825f..0000000 --- a/components/spit/src/SAD_DetectedServer.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -/* - * SAD_DetectedServer holds information about SPIT Server detected by ServerAutoDetection (SAD). - * File: SAD_DetectedServer.cpp - * Author: Hagi - * - * Created on 4. Mai 2019, 13:51 - */ - -#include "SAD_DetectedServer.hpp" -#include "esp_log.h" - -static const char *TAG = "SpitSrv"; - -unordered_map SAD_DetectedServer::s_DetectedServers; - -SAD_DetectedServer::~SAD_DetectedServer() { -} -//----- Detected Server ----- -SAD_DetectedServer::SAD_DetectedServer() { - m_ID = ""; - m_Name = ""; - m_ComputerName = ""; - m_ClientIP = ""; - m_Port = ""; - m_Additions = ""; -} - -void SAD_DetectedServer::setProjectName(string p_ServerProjectName) { - if (m_ServerProjectName.compare(p_ServerProjectName) != 0) { - if (m_New == false) { - m_Changed = true; - } - } - m_ServerProjectName = p_ServerProjectName; -} - -void SAD_DetectedServer::cycleStart() { - for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) { - i->second->startCycleSAD(); - } -} -void SAD_DetectedServer::cycleEnd(I_SAD_Client &sadClient) { - for (auto &srv : s_DetectedServers) { - SAD_DetectedServer *ptrDetectedServer = srv.second; - if (ptrDetectedServer->getFoundAgain() == false) { - sadClient.eventServerLost(*ptrDetectedServer); - removeDetectedServer(*ptrDetectedServer); - } else if (ptrDetectedServer->getNew()) { - ptrDetectedServer->setNew(false); - sadClient.eventServerDetected(*ptrDetectedServer); - } else if (ptrDetectedServer->getChanged()) { - sadClient.eventServerChanged(*ptrDetectedServer); - } - } -} - -/** - * Used by SAD_Client to add a found SPITServer - don't use this manually - * @param p_IsIP4 true = the server is reached via a IP4 address
false = the server is reahed via a IP6 address - * @param p_ServerID the id of the server, every instance of a SPITServer has an own id - * @param p_ServerParams the server's parameter - */ -void SAD_DetectedServer::addDetectedServer(string p_ServerID, string p_ServerParams[]) { - SAD_DetectedServer *ptrDetectedServer; - { - auto i = s_DetectedServers.find(p_ServerID); - if (i != s_DetectedServers.end()) { - ptrDetectedServer = i->second; - } else { - ptrDetectedServer = new SAD_DetectedServer(); - ptrDetectedServer->setID(p_ServerParams[PARAMINDEX_ID]); - ptrDetectedServer->setNew(true); - } - ptrDetectedServer->setFoundAgain(); - - // second prefer IP4 - ptrDetectedServer->setIP(p_ServerParams[PARAMINDEX_IP]); - ptrDetectedServer->setClientIP(p_ServerParams[PARAMINDEX_CLIENTIP]); - ptrDetectedServer->setName(p_ServerParams[PARAMINDEX_NAME]); - ptrDetectedServer->setComputerName(p_ServerParams[PARAMINDEX_COMPUTERNAME]); - ptrDetectedServer->setPort(p_ServerParams[PARAMINDEX_PORT]); - ptrDetectedServer->setAdditions(p_ServerParams[PARAMINDEX_ADDITIONS]); - ptrDetectedServer->setProjectName(p_ServerParams[PARAMINDEX_SERVERPROJECTNAME]); - - s_DetectedServers[ptrDetectedServer->getID()] = ptrDetectedServer; - } -} -/** - * Used by SAD_Client to remove a SPITServer - don't use this manually - * @param p_DetectedServer - */ -void SAD_DetectedServer::removeDetectedServer(SAD_DetectedServer &server) { - auto i = s_DetectedServers.find(server.getID()); - if (i != s_DetectedServers.end()) { - SAD_DetectedServer *o_DetectedServer = i->second; - i = s_DetectedServers.erase(i); - delete o_DetectedServer; - } -} - -/** - * Used by SAD_Client to clear all found SPITServers - don't use this manually - */ -void SAD_DetectedServer::clearDetectedServers() { - for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) { - SAD_DetectedServer *ptrDetectedServer = i->second; - i = s_DetectedServers.erase(i); - delete ptrDetectedServer; - if (i == s_DetectedServers.end()) { - break; - } - } -} - -const SAD_DetectedServer &SAD_DetectedServer::getRefDetectedServer(string p_ServerID) { - SAD_DetectedServer *ptrDetectedServer = nullptr; - - auto i = s_DetectedServers.find(p_ServerID); - if (i != s_DetectedServers.end()) { - ptrDetectedServer = i->second; - } - if (ptrDetectedServer != NULL) { - return *ptrDetectedServer; - } - - throw new exception(); -} \ No newline at end of file diff --git a/components/spit/src/SPITObject.cpp b/components/spit/src/SPITObject.cpp index 377945b..f4c246e 100644 --- a/components/spit/src/SPITObject.cpp +++ b/components/spit/src/SPITObject.cpp @@ -14,280 +14,50 @@ #include "SPITObject.h" #include "SPITSocket.h" - -unordered_map SPITObject::s_SPITObjects; -unordered_map SPITObject::s_SPITObjectsRemote; - -SPITObject *SPITObject::getSPITObject(string p_ID) { - { - auto i = s_SPITObjects.find(p_ID); - if (i == s_SPITObjects.end()) { - return NULL; - } - return i->second; - } -} -/** - * Returns the reference of the SPITObject with ID == p_ID.
- * Throws an exception if no SPITObject is not found.
- * @param p_ID the ID - * @return reference of the SPITType with ID == p_ID - */ -const SPITObject &SPITObject::getSPITObjectRef(string p_ID) { - { - auto i = s_SPITObjects.find(p_ID); - if (i == s_SPITObjects.end()) { - throw "SPITObject no SPITObject with given id"; - } - return *(i->second); - } -} - -SPITObject *SPITObject::getSPITObjectRemote(string p_ID) { - { - auto i = s_SPITObjectsRemote.find(p_ID); - if (i == s_SPITObjectsRemote.end()) { - return NULL; - } - return i->second; - } -} -/** - * Returns the reference of the remote SPITObject with ID == p_ID.
- * Throws an exception if no SPITObject is not found.
- * @param p_ID the ID - * @return reference of the SPITType with ID == p_ID - */ -const SPITObject &SPITObject::getSPITObjectRemoteRef(string p_ID) { - { - auto i = s_SPITObjectsRemote.find(p_ID); - if (i == s_SPITObjectsRemote.end()) { - throw "Remote SPITObject no SPITObject with given id"; - } - return *(i->second); - } -} - -bool SPITObject::addSPITObject(SPITObject *p_ptrSPITObject) { - if (p_ptrSPITObject == NULL) - return false; - { - s_SPITObjects[p_ptrSPITObject->getID()] = p_ptrSPITObject; - return true; - } -} -bool SPITObject::addSPITObjectRemote(SPITObject *p_ptrSPITObject) { - if (p_ptrSPITObject == NULL) - return false; - { - s_SPITObjectsRemote[p_ptrSPITObject->getID()] = p_ptrSPITObject; - return true; - } -} -bool SPITObject::removeSPITObject(SPITObject *p_ptrSPITObject) { - if (p_ptrSPITObject == NULL) - return false; - return removeSPITObject(p_ptrSPITObject->getID()); -} -bool SPITObject::removeSPITObject(string p_SPITObjectID) { - { - auto i = s_SPITObjects.find(p_SPITObjectID); - if (i == s_SPITObjects.end()) { - return false; - } - i = s_SPITObjects.erase(i); - return true; - } -} -bool SPITObject::removeSPITObjectRemote(SPITObject *p_ptrSPITObject) { - if (p_ptrSPITObject == NULL) - return false; - return removeSPITObjectRemote(p_ptrSPITObject->getID()); -} -bool SPITObject::removeSPITObjectRemote(string p_ptrSPITObject) { - { - auto i = s_SPITObjectsRemote.find(p_ptrSPITObject); - if (i == s_SPITObjectsRemote.end()) { - return false; - } - i = s_SPITObjectsRemote.erase(i); - return true; - } -} - -int SPITObject::getSPITObjectCount() { - return s_SPITObjects.size(); -} -int SPITObject::getSPITObjectRemoteCount() { - return s_SPITObjectsRemote.size(); -} -SPITObject *SPITObject::getSPITObject(int p_Index) { - SPITObject *ptrSPITObject = NULL; - { - if (p_Index >= 0 && p_Index < s_SPITObjects.size()) { - unordered_map::iterator i = next(s_SPITObjects.begin(), p_Index); - ptrSPITObject = i->second; - return ptrSPITObject; - } else { - return NULL; - } - } -} -/** - * Returns a reference to the SPITObject at position p_Index.
- * Throws an exception if p_Index is out of range.
- * @param p_Index position - * @return the reference of the SPITObject at position. - */ -const SPITObject &SPITObject::getSPITObjectRef(int p_Index) { - SPITObject *ptrSPITObject = NULL; - { - if (p_Index >= 0 && p_Index < s_SPITObjects.size()) { - unordered_map::iterator i = next(s_SPITObjects.begin(), p_Index); - ptrSPITObject = i->second; - return *ptrSPITObject; - } else { - throw "SPITObject index out of range"; - } - } -} -SPITObject *SPITObject::getSPITObjectRemote(int p_Index) { - SPITObject *ptrSPITObject = NULL; - { - if (p_Index >= 0 && p_Index < s_SPITObjectsRemote.size()) { - unordered_map::iterator i = next(s_SPITObjectsRemote.begin(), p_Index); - ptrSPITObject = i->second; - return ptrSPITObject; - } else { - return NULL; - } - } -} -/** - * Returns a reference to the remote SPITObject at position p_Index.
- * Throws an exception if p_Index is out of range.
- * @param p_Index position - * @return the reference of the SPITObject at position. - */ -const SPITObject &SPITObject::getSPITObjectRemoteRef(int p_Index) { - SPITObject *ptrSPITObject = NULL; - { - if (p_Index >= 0 && p_Index < s_SPITObjectsRemote.size()) { - unordered_map::iterator i = next(s_SPITObjectsRemote.begin(), p_Index); - ptrSPITObject = i->second; - return *ptrSPITObject; - } else { - throw "Remote SPITObject index out of range"; - } - } -} - -void SPITObject::clearSPITObjects() { - SPITObject *ptrSPITObject; - { - for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) { - ptrSPITObject = i->second; - i = s_SPITObjects.erase(i); - delete ptrSPITObject; - if (i == s_SPITObjects.end()) { - break; - } - } - } -} -void SPITObject::clearSPITObjectsRemote() { - SPITObject *ptrSPITObject; - { - for (auto i = s_SPITObjectsRemote.begin(); i != s_SPITObjectsRemote.end(); i++) { - ptrSPITObject = i->second; - i = s_SPITObjectsRemote.erase(i); - delete ptrSPITObject; - if (i == s_SPITObjectsRemote.end()) { - break; - } - } - } -} +#include "esp_log.h" /** * clears all unconfirmed SPITObjects not created by this SPIT_Client. */ -void SPITObject::clearUnconfirmedSPITObjects() { - for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) { - SPITObject *ptrSPITObject = i->second; +void SPITObject::clearUnconfirmedSPITObjects(SpitRepo &repo) { + auto &entries = repo.getRepo(); + for (auto i = entries.begin(); i != entries.end();) { + SPITObject *ptrSPITObject = i->second.get(); if (ptrSPITObject->getCreatedByClient() == false && ptrSPITObject->getConfirmed() == false) { - i = s_SPITObjects.erase(i); - delete ptrSPITObject; - } - if (i == s_SPITObjects.end()) { - break; + i = entries.erase(i); + } else { + i++; } } } -void SPITObject::eventProjectClosed() { - for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) { - SPITObject *ptrSPITObject = i->second; +void SPITObject::eventProjectClosed(SpitRepo &repo, SpitRepo &remoteRepo) { + auto &entries = repo.getRepo(); + for (auto i = entries.begin(); i != entries.end(); ) { + SPITObject *ptrSPITObject = i->second.get(); if (ptrSPITObject->getCreatedByClient() == true) { + i++; continue; } - i = s_SPITObjects.erase(i); - delete ptrSPITObject; - if (i == s_SPITObjects.end()) { - break; - } + i = entries.erase(i); } // Remote - for (auto i = s_SPITObjectsRemote.begin(); i != s_SPITObjectsRemote.end(); i++) { - SPITObject *ptrSPITObject = i->second; - i = s_SPITObjectsRemote.erase(i); - delete ptrSPITObject; - if (i == s_SPITObjectsRemote.end()) { - break; - } - } + remoteRepo.clearEntries(); } /** - * sets confirmed = false for all SPITObjects.
- * This should be called when the client has loaded a project.
+ * sets confirmed = false for all SPITObjects. + * This should be called when the client has loaded a project. */ -void SPITObject::setConfirmedFalse() { - SPITObject *ptrSPITObject; - { - for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) { - ptrSPITObject = i->second; - ptrSPITObject->setConfirmed(false); - } +void SPITObject::setConfirmedFalse(SpitRepo &repo) { + auto &entries = repo.getRepo(); + for (auto i = entries.begin(); i != entries.end(); i++) { + i->second->setConfirmed(false); } } -SPITObject::SPITObject() { - initMembers(); +SPITObject::SPITObject(string p_ID) { + m_ID = p_ID; } -void SPITObject::initMembers() { - m_ActionAssigned = false; - m_ActionAssignedType = false; - m_Confirmed = false; - m_Delay = 0; - m_Duration = 0; - m_Fixed = false; - m_CreatedByClient = false; - m_FrameFadeInLength = 0; - m_FrameFadeOutLength = 0; - m_FrameLength = 0; - m_FrameStart = 0; - m_Remark = ""; - m_ID = createGUID(); - m_Name = ""; - m_SPITTypeID = ""; - m_ServerParams = ""; - m_ServerRemote = false; - m_Track = 0; - m_ValueFactor = 1000000; // Values are given in ppm -> 1000000 = 1/1; - m_ValueUse = 0x01; -} - -SPITObject::~SPITObject() {} bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject) { bool boolChangeAllowed; @@ -309,133 +79,142 @@ bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject } if (m_Delay != p_ReportSPITObject->getDelay()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_Delay = p_ReportSPITObject->getDelay(); boolChanged = true; } if (m_Duration != p_ReportSPITObject->getDuration()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_Duration = p_ReportSPITObject->getDuration(); boolChanged = true; } if (m_Fixed != p_ReportSPITObject->getFixed()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_Fixed = p_ReportSPITObject->getFixed(); boolChanged = true; } if (m_FrameFadeInLength != p_ReportSPITObject->getFrameFadeInLength()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_FrameFadeInLength = p_ReportSPITObject->getFrameFadeInLength(); boolChanged = true; } if (m_FrameFadeOutLength != p_ReportSPITObject->getFrameFadeOutLength()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_FrameFadeOutLength = p_ReportSPITObject->getFrameFadeOutLength(); boolChanged = true; } if (m_FrameLength != p_ReportSPITObject->getFrameLength()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_FrameLength = p_ReportSPITObject->getFrameLength(); boolChanged = true; } if (m_FrameStart != p_ReportSPITObject->getFrameStart()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_FrameStart = p_ReportSPITObject->getFrameStart(); boolChanged = true; } if (m_Remark != p_ReportSPITObject->getRemark()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_Remark = p_ReportSPITObject->getRemark(); boolChanged = true; } if (m_ID != p_ReportSPITObject->getID()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_ID = p_ReportSPITObject->getID(); boolChanged = true; } if (m_Name != p_ReportSPITObject->getName()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_Name = p_ReportSPITObject->getName(); boolChanged = true; } if (m_SPITTypeID != p_ReportSPITObject->getSPITTypeID()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_SPITTypeID = p_ReportSPITObject->getSPITTypeID(); boolChanged = true; } if (m_ServerParams != p_ReportSPITObject->getServerParams()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_ServerParams = p_ReportSPITObject->getServerParams(); boolChanged = true; } if (m_ServerRemote != p_ReportSPITObject->getServerRemote()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_ServerRemote = p_ReportSPITObject->getServerRemote(); boolChanged = true; } if (m_Track != p_ReportSPITObject->getTrack()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_Track = p_ReportSPITObject->getTrack(); boolChanged = true; } if (m_ValueFactor != p_ReportSPITObject->getValueFactor()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_ValueFactor = p_ReportSPITObject->getValueFactor(); boolChanged = true; } if (m_ValueUse != p_ReportSPITObject->getValueUse()) { - if (boolChangeAllowed == false) - throw new exception(); + if (boolChangeAllowed == false) { + return false; + } m_ValueUse = p_ReportSPITObject->getValueUse(); boolChanged = true; } return boolChanged; } -void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject) { - p_ReportSPITObject->setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object - p_ReportSPITObject->setConfirmed(m_Confirmed); - p_ReportSPITObject->setDelay(m_Delay); - p_ReportSPITObject->setDuration(m_Duration); - p_ReportSPITObject->setFixed(m_Fixed); - p_ReportSPITObject->setFrameFadeInLength(m_FrameFadeInLength); - p_ReportSPITObject->setFrameFadeOutLength(m_FrameFadeOutLength); - p_ReportSPITObject->setFrameLength(m_FrameLength); - p_ReportSPITObject->setFrameStart(m_FrameStart); - p_ReportSPITObject->setID(m_ID); - p_ReportSPITObject->setName(m_Name); - p_ReportSPITObject->setRemark(m_Remark); - p_ReportSPITObject->setSPITTypeID(m_SPITTypeID); - p_ReportSPITObject->setServerParams(m_ServerParams); - p_ReportSPITObject->setServerRemote(m_ServerRemote); - p_ReportSPITObject->setTrack(m_Track); - p_ReportSPITObject->setValueFactor(m_ValueFactor); - p_ReportSPITObject->setValueUse(m_ValueUse); +void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject &p_ReportSPITObject) { + p_ReportSPITObject.setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object + p_ReportSPITObject.setConfirmed(m_Confirmed); + p_ReportSPITObject.setDelay(m_Delay); + p_ReportSPITObject.setDuration(m_Duration); + p_ReportSPITObject.setFixed(m_Fixed); + p_ReportSPITObject.setFrameFadeInLength(m_FrameFadeInLength); + p_ReportSPITObject.setFrameFadeOutLength(m_FrameFadeOutLength); + p_ReportSPITObject.setFrameLength(m_FrameLength); + p_ReportSPITObject.setFrameStart(m_FrameStart); + p_ReportSPITObject.setID(m_ID); + p_ReportSPITObject.setName(m_Name); + p_ReportSPITObject.setRemark(m_Remark); + p_ReportSPITObject.setSPITTypeID(m_SPITTypeID); + p_ReportSPITObject.setServerParams(m_ServerParams); + p_ReportSPITObject.setServerRemote(m_ServerRemote); + p_ReportSPITObject.setTrack(m_Track); + p_ReportSPITObject.setValueFactor(m_ValueFactor); + p_ReportSPITObject.setValueUse(m_ValueUse); } -void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject) { - p_RemoveSPITObject->setID(m_ID); -} - -void SPITObject::setID(string p_ID) { - m_ID = p_ID; -} -void SPITObject::setCreatedByClient(bool p_CreatedByClient) { - m_CreatedByClient = p_CreatedByClient; +void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject) { + p_RemoveSPITObject.setID(m_ID); } /** @@ -486,8 +265,8 @@ bool SPITObject::setServerRemote(bool p_BelongstoServer) { return true; } /** - * This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol.
- * This is used when an action is associated with a SPITType.
+ * This is a virtual construct - ActionAssignedType is not implemented in the SPITProtocol. + * This is used when an action is associated with a SPITType. * Then this action is done for every SPITObject with the SPITType. * @return true = an action is assigned for the SPITType. */ diff --git a/components/spit/src/SPITPlayer.cpp b/components/spit/src/SPITPlayer.cpp index 4f7a513..97e6bda 100644 --- a/components/spit/src/SPITPlayer.cpp +++ b/components/spit/src/SPITPlayer.cpp @@ -13,57 +13,30 @@ */ #include "SPITPlayer.h" +#include "esp_log.h" +#include #include -unordered_map SPITPlayer::s_SPITPlayers; +using namespace std; -SPITPlayer *SPITPlayer::getSPITPlayer(string p_PlayerID) { - { - auto i = s_SPITPlayers.find(p_PlayerID); - if (i == s_SPITPlayers.end()) { - s_SPITPlayers[p_PlayerID] = new SPITPlayer(p_PlayerID); - } - i = s_SPITPlayers.find(p_PlayerID); - if (i == s_SPITPlayers.end()) - return NULL; - return i->second; - } -} +unordered_map> SPITPlayer::s_SPITPlayers; -void SPITPlayer::clearPlayers() { - ; - vector o_SPITPlayers; - for (auto i = s_SPITPlayers.begin(); i != s_SPITPlayers.end(); i++) { - SPITPlayer *ptrSPITPlayer = i->second; - o_SPITPlayers.push_back(ptrSPITPlayer); +SPITPlayer &SPITPlayer::getSPITPlayer(string p_PlayerID) { + auto i = s_SPITPlayers.find(p_PlayerID); + if (i == s_SPITPlayers.end()) { + s_SPITPlayers[p_PlayerID] = make_unique(p_PlayerID); } - for (auto i = o_SPITPlayers.begin(); i != o_SPITPlayers.end(); i++) { - SPITPlayer *ptrSPITPlayer = *i; - delete ptrSPITPlayer; - } - o_SPITPlayers.clear(); + return *s_SPITPlayers.at(p_PlayerID); } SPITPlayer::SPITPlayer(string p_PlayerID) { m_ID = p_PlayerID; - s_SPITPlayers[p_PlayerID] = this; } SPITPlayer::~SPITPlayer() { - PlaySPITType *ptrPlaySPITType; - for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) { - ptrPlaySPITType = i->second; - i = m_PlaySPITTypes.erase(i); - delete ptrPlaySPITType; - if (i == m_PlaySPITTypes.end()) { - break; - } - } + m_PlaySPITTypes.clear(); } -unordered_map *SPITPlayer::getPlaySPITTypes() { - return &m_PlaySPITTypes; -} /** * * @param p_SPITObjectID @@ -72,46 +45,38 @@ unordered_map *SPITPlayer::getPlaySPITTypes( */ SPITPlayer::PlaySPITType *SPITPlayer::addSPITType_Playing(string p_SPITTypeID) { PlaySPITType *ptrPlaySPITType; - auto i = m_PlaySPITTypes.find(p_SPITTypeID); if (i == m_PlaySPITTypes.end()) { - ptrPlaySPITType = new PlaySPITType(this, p_SPITTypeID); - ptrPlaySPITType->setIsPlayed(true); - ptrPlaySPITType->setIsNew(true); - m_PlaySPITTypes[p_SPITTypeID] = ptrPlaySPITType; + auto playSpitType = make_unique(this, p_SPITTypeID); + ptrPlaySPITType = playSpitType.get(); + m_PlaySPITTypes[p_SPITTypeID] = move(playSpitType); } else { - ptrPlaySPITType = i->second; - ptrPlaySPITType->setIsPlayed(true); + ptrPlaySPITType = i->second.get(); } + ptrPlaySPITType->setIsPlayed(true); return ptrPlaySPITType; } void SPITPlayer::startPlaySequence() { - PlaySPITType *ptrPlaySPITType; for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) { - ptrPlaySPITType = i->second; + PlaySPITType *ptrPlaySPITType = i->second.get(); ptrPlaySPITType->startPlaySequence(); } } void SPITPlayer::endPlaySequence() { - PlaySPITType *ptrPlaySPITType; - - for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) { - ptrPlaySPITType = i->second; - if (ptrPlaySPITType->getIsPlayed() == false) { + for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end();) { + if (i->second.get()->getIsPlayed() == false) { i = m_PlaySPITTypes.erase(i); - delete ptrPlaySPITType; - if (i == m_PlaySPITTypes.end()) { - break; - } + } else { + ++i; } } } -SPITPlayer::PlaySPITType::PlaySPITType() { -} SPITPlayer::PlaySPITType::PlaySPITType(SPITPlayer *p_SPITPlayer, string p_SPITTypeID) { + m_IsNew = true; + m_SPITTypeID = p_SPITTypeID; m_PlayerID = p_SPITPlayer->getID(); m_PlayerName = p_SPITPlayer->getName(); diff --git a/components/spit/src/SPITSocket.cpp b/components/spit/src/SPITSocket.cpp index b93b695..10cd6b2 100644 --- a/components/spit/src/SPITSocket.cpp +++ b/components/spit/src/SPITSocket.cpp @@ -27,27 +27,25 @@ using namespace std; * @return */ bool SPITSocket::createSocket_UDP() { - bool boolSuccess = true; - int intResult = -1; - int intOptionValue4 = 1; - - // ip4 if (m_UDPSocketIP4 != INVALID_SOCKET) { close(m_UDPSocketIP4); m_UDPSocketIP4 = INVALID_SOCKET; } m_UDPSocketIP4 = socket(AF_INET, SOCK_DGRAM, 0); + int intResult = -1; + bool success = true; if (m_UDPSocketIP4 == INVALID_SOCKET) { - boolSuccess = false; + success = false; } else { + int intOptionValue4 = 1; intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_REUSEADDR, (void *)&intOptionValue4, sizeof(intOptionValue4)); } if (intResult < 0) { - boolSuccess = false; + success = false; } - if (boolSuccess == true) { + if (success == true) { struct timeval tv; tv.tv_sec = 1; // seconds tv.tv_usec = 0; // microseconds (0.0 sec) @@ -64,138 +62,99 @@ bool SPITSocket::createSocket_UDP() { // intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVBUF, (void*)&intBufferSize, sizeof(intBufferSize)); // intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_SNDBUF, (void*)&intBufferSize, sizeof(intBufferSize)); } - return boolSuccess; + return success; } /** * Binds the socket to the client's ip address and port. The socket option SO_REUSEADDR is set to true. - * @param p_ClientIP ip address of the client - * @param p_ClientPort port of the client. + * @param clientIp ip address of the client + * @param clientPort port of the client. * if p_Port == "0" any free port will be used * @return -1 id bind fails, o if bind is ok * */ -int SPITSocket::bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort) { - addrinfo *clientAI; - struct sockaddr_in *ptrIP4SocketAddress; - struct sockaddr_in o_IP4SocketAddress; - int intSocklen; +int SPITSocket::bindSocket(string clientIp, string clientPort) { string stringClientPort; - if (p_ClientPort.length() <= 0) + if (clientPort.length() <= 0) stringClientPort = "0"; else - stringClientPort = p_ClientPort; - // int intResult = SOCKET_ERROR; - int intResult = 0; - if (getaddrinfo(p_ClientIP.data(), p_ClientPort.data(), NULL, &clientAI) != 0) { + stringClientPort = clientPort; + addrinfo *clientAI; + if (getaddrinfo(clientIp.data(), clientPort.data(), nullptr, &clientAI) != 0) { return -1; } - switch (clientAI->ai_family) { - case AF_INET: - if (m_UDPSocketIP4 == INVALID_SOCKET) { - break; - } - ptrIP4SocketAddress = reinterpret_cast(clientAI->ai_addr); - intSocklen = sizeof(*ptrIP4SocketAddress); - // copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo - memset(&o_IP4SocketAddress, 0, intSocklen); - o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr; - o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family; - // o_IP4SocketAddress.sin_zero = ptrIP4SocketAddress->sin_zero; - o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port; - intResult = bind(m_UDPSocketIP4, (const sockaddr *)(ptrIP4SocketAddress), (socklen_t)intSocklen); - if (intResult < 0) { - break; - } - setBoundClientFamily(AF_INET); - if (intResult == 0) { - if (getsockname(m_UDPSocketIP4, (sockaddr *)ptrIP4SocketAddress, (socklen_t *)&intSocklen) != -1) { - setBoundClientPort(to_string((int)ptrIP4SocketAddress->sin_port)); - } - } - break; - default: - setBoundClientFamily(0); - intResult = -1; - break; + if (m_UDPSocketIP4 == INVALID_SOCKET) { + return -1; + } + auto *socketAdr = (sockaddr_in *)(clientAI->ai_addr); + int intSocklen = sizeof(*socketAdr); + // copy the socketAdr, may be not filled correct by getaddrinfo + sockaddr_in o_IP4SocketAddress; + memset(&o_IP4SocketAddress, 0, intSocklen); + o_IP4SocketAddress.sin_addr = socketAdr->sin_addr; + o_IP4SocketAddress.sin_family = socketAdr->sin_family; + o_IP4SocketAddress.sin_port = socketAdr->sin_port; + int intResult = bind(m_UDPSocketIP4, (const sockaddr *)(socketAdr), (socklen_t)intSocklen); + if (intResult < 0) { + return intResult; + } + if ((intResult == 0) && + (getsockname(m_UDPSocketIP4, (sockaddr *)socketAdr, (socklen_t *)&intSocklen) != -1)) { + setBoundClientPort(to_string((int)socketAdr->sin_port)); } freeaddrinfo(clientAI); - if (intResult == -1) { - setIsBound(false); - } else { - setIsBound(true); - } + setIsBound(intResult != -1); return intResult; } /** - * Set whether the sockat are brodcast sockets or not. Set the sockopt SO_BROADCAST to 0 or 1 + * Set whether the socket are broadcast sockets or not. Set the sockopt SO_BROADCAST to 0 or 1 * @param p_Broadcast true SO_BROADCAST is set * false = SO_BROADCAST is not set * @return 0 = ok, -1 = error */ -int SPITSocket::setBroadcast(bool p_Broadcast) { - int intResult; - int intOptionValue = 1; - u_char charOptionValue = 0x01; - // IP4 - if (p_Broadcast) { - intOptionValue = 1; - } else { - intOptionValue = 0; - } - intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_BROADCAST, &intOptionValue, sizeof(int)); - // intResult = setsockopt(m_UDPSocketIP4, IPPROTO_IP, IP_MULTICAST_LOOP, (void*)&charOptionValue, sizeof(charOptionValue)); - +int SPITSocket::setBroadcast(bool broadcast) const { + int intOptionValue = broadcast ? 1 : 0; + int intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_BROADCAST, &intOptionValue, sizeof(int)); return intResult; } /** - * - * @param p_InetFamily AF_INET or AF_INET6 - * @param p_ServerIP the ip address of the server - * @param p_ServerPort the port of the server - * @param p_MessageBytes buffer containing the message - * @param p_MessageLength the length of the message + * @param ip the ip address of the server + * @param port the port of the server + * @param msg buffer containing the message + * @param msgLength the length of the message * @return -1 send fails * 0 send is done */ -int SPITSocket::sendMessageTo(int p_InetFamily, string p_ServerIP, string p_ServerPort, const char *p_MessageBytes, int p_MessageLength) { - if (m_UDPSocketIP4 == INVALID_SOCKET) +int SPITSocket::sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) { + if (m_UDPSocketIP4 == INVALID_SOCKET) { return -1; - struct addrinfo *ptrAddressInfo; - struct sockaddr_in *ptrIP4SocketAddress; - struct sockaddr_in o_IP4SocketAddress; - int intSocklen; - int intResult = -1; + } // prepare AddressInfo - if (getaddrinfo(p_ServerIP.data(), p_ServerPort.data(), NULL, &ptrAddressInfo) != 0) { - return -1; - } - switch (ptrAddressInfo->ai_family) { - case AF_INET: - ptrIP4SocketAddress = reinterpret_cast(ptrAddressInfo->ai_addr); - intSocklen = sizeof(*ptrIP4SocketAddress); - if (m_UDPSocketIP4 != INVALID_SOCKET) { - // copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo - memset(&o_IP4SocketAddress, 0, intSocklen); - o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr; - o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family; - o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port; - intResult = sendto(m_UDPSocketIP4, p_MessageBytes, p_MessageLength, 0, (const sockaddr *)&o_IP4SocketAddress, (socklen_t)intSocklen); - if (intResult < 0) { - printf("UnixSocket::sendMessageTo IP4 sendto %s FAILED %s\n", p_ServerIP.data(), strerror(errno)); - printf("UnixSocket::sendMessageTo ret=%d %s / %s / %d\n", intResult, - p_ServerPort.data(), p_MessageBytes, p_MessageLength); - } - freeaddrinfo(ptrAddressInfo); - } - break; - default: - intResult = -1; + int intResult = -1; + addrinfo *ptrAddressInfo; + if (getaddrinfo(ip.data(), port.data(), nullptr, &ptrAddressInfo) != 0) { + return intResult; } + auto *ptrIP4SocketAddress = (sockaddr_in *)(ptrAddressInfo->ai_addr); + int intSocklen = sizeof(*ptrIP4SocketAddress); + if (m_UDPSocketIP4 != INVALID_SOCKET) { + // copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo + sockaddr_in o_IP4SocketAddress; + memset(&o_IP4SocketAddress, 0, intSocklen); + o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr; + o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family; + o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port; + intResult = sendto(m_UDPSocketIP4, message, msgLength, 0, (const sockaddr *)&o_IP4SocketAddress, (socklen_t)intSocklen); + if (intResult < 0) { + ESP_LOGE("SPIT", "sendMessageTo IP4 sendto %s FAILED %s\n", ip.data(), strerror(errno)); + ESP_LOGE("SPIT", "sendMessageTo ret=%d %s / %s / %d\n", intResult, port.data(), message, msgLength); + } + freeaddrinfo(ptrAddressInfo); + } if (intResult < 0) { return -1; } @@ -204,52 +163,39 @@ int SPITSocket::sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Serv /** * Call this for receiving a message * This will block until a message is received or the underlying socket is closed - * @param p_InetFamily either AF_INET or AF_INET6
- * The SPITSocket creates two udp sockets, one for IP4 and one for IP6 - * This parameter decides from which socket should a message recieved * @param p_Buffer the buffer containing the received message later. * @param p_BufferLength the size of the buffer * @param p_ServerIP a pointer to a string, when a messages is received the string will contain the ip address of the sender/server * if p_ServerIP is NULL - no detection of the server will be done. * @return */ -int SPITSocket::receiveMessage(int p_InetFamily, char *p_Buffer, int p_BufferLength, string *p_ServerIP) { +int SPITSocket::receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const { int intResult = -1; - // ADDRINFO *AI; - struct sockaddr_in o_IP4SocketAddress; - int intSocklen; - - switch (p_InetFamily) { - case AF_INET: - if (m_UDPSocketIP4 == INVALID_SOCKET) { - break; - } - intSocklen = sizeof(o_IP4SocketAddress); - memset(&o_IP4SocketAddress, 0, intSocklen); - intResult = recvfrom(m_UDPSocketIP4, (void *)p_Buffer, p_BufferLength, 0, (sockaddr *)&o_IP4SocketAddress, (socklen_t *)&intSocklen); - if (intResult >= 0) { - if (p_ServerIP != NULL) { - char bufferIP4[INET_ADDRSTRLEN]; - inet_ntop(AF_INET, &(o_IP4SocketAddress.sin_addr), bufferIP4, intSocklen); - *p_ServerIP = bufferIP4; - } - } - break; + if (m_UDPSocketIP4 == INVALID_SOCKET) { + return intResult; + } + sockaddr_in o_IP4SocketAddress; + int intSocklen = sizeof(o_IP4SocketAddress); + memset(&o_IP4SocketAddress, 0, intSocklen); + intResult = recvfrom(m_UDPSocketIP4, (void *)p_Buffer, p_BufferLength, 0, (sockaddr *)&o_IP4SocketAddress, (socklen_t *)&intSocklen); + if (intResult >= 0 && serverIp != nullptr) { + char bufferIP4[INET_ADDRSTRLEN]; + inet_ntop(AF_INET, &(o_IP4SocketAddress.sin_addr), bufferIP4, intSocklen); + *serverIp = bufferIP4; } return intResult; } SPITSocket::IPAddress SPITSocket::getAdaptersInfo() { // iterate over active interfaces, and print out IPs - esp_netif_t *netif = NULL; - while ((netif = esp_netif_next_unsafe(netif)) != NULL) { + esp_netif_t *netif = nullptr; + if ((netif = esp_netif_next_unsafe(netif)) != nullptr) { ESP_LOGI("SPIT", "Connected to %s", esp_netif_get_desc(netif)); esp_netif_ip_info_t ip; ESP_ERROR_CHECK(esp_netif_get_ip_info(netif, &ip)); ESP_LOGI("SPIT", "- IPv4 address: " IPSTR ",", IP2STR(&ip.ip)); ESP_LOGI("SPIT", "- IPv4 netmask: " IPSTR ",", IP2STR(&ip.netmask)); char buffer[64]; - sprintf(buffer, IPSTR, IP2STR(&ip.ip)); string stringIP4 = buffer; sprintf(buffer, IPSTR, IP2STR(&ip.netmask)); @@ -260,29 +206,18 @@ SPITSocket::IPAddress SPITSocket::getAdaptersInfo() { } string createGUID() { - // uuid_t id; - // uuid_generate(id); - // char *guid_string = new char[100]; - // uuid_unparse(id, guid_string); - // string stringGUID = guid_string; - // return stringGUID; - uuid_t uu; - char uu_str[UUID_STR_LEN]; - uuid_generate(uu); + char uu_str[UUID_STR_LEN]; uuid_unparse(uu, uu_str); - string stringGUID = uu_str; - return stringGUID; + return {uu_str}; } -/** The name of the client's host computer*/ + string getClientHostName() { - string stringHostName = ""; const char *hostname; esp_netif_get_hostname(esp_netif_get_default_netif(), &hostname); if (hostname != nullptr) { - stringHostName = hostname; + return {hostname}; } - return stringHostName; - ; + return ""; } diff --git a/components/spit/src/SPITType.cpp b/components/spit/src/SPITType.cpp index 6883456..719c1cd 100644 --- a/components/spit/src/SPITType.cpp +++ b/components/spit/src/SPITType.cpp @@ -17,280 +17,51 @@ static const char *TAG = "SPIT"; -unordered_map SPITType::s_SPITTypes; -unordered_map SPITType::s_SPITTypesRemote; - -SPITType *SPITType::getSPITType(string p_ID) { - { - auto i = s_SPITTypes.find(p_ID); - if (i == s_SPITTypes.end()) { - return NULL; - } - return i->second; - } -} -/** - * Returns the reference of the SPITType with ID == p_ID.
- * Throws an exception if no SPITType is not found.
- * @param p_ID the ID - * @return reference of the SPITType with ID == p_ID - */ -const SPITType &SPITType::getSPITTypeRef(string p_ID) { - { - auto i = s_SPITTypes.find(p_ID); - if (i == s_SPITTypes.end()) { - throw "SPITType no SPITType with given ID"; - } - return *(i->second); - } -} - -SPITType *SPITType::getSPITTypeRemote(string p_ID) { - { - auto i = s_SPITTypesRemote.find(p_ID); - if (i == s_SPITTypesRemote.end()) { - return NULL; - } - return i->second; - } -} -/** - * Returns the reference of the remote SPITType with ID == p_ID.
- * Throws an exception if no SPITType is not found.
- * @param p_ID the ID - * @return reference of the SPITType with ID == p_ID - */ -const SPITType &SPITType::getSPITTypeRemoteRef(string p_ID) { - { - auto i = s_SPITTypesRemote.find(p_ID); - if (i == s_SPITTypesRemote.end()) { - throw "Remote SPITType no SPITType with given ID"; - } - return *(i->second); - } -} - -bool SPITType::addSPITType(SPITType *p_ptrSpitType) { - if (p_ptrSpitType == NULL) - return false; - { - s_SPITTypes[p_ptrSpitType->getID()] = p_ptrSpitType; - return true; - } -} -bool SPITType::addSPITTypeRemote(SPITType *p_ptrSpitType) { - if (p_ptrSpitType == NULL) - return false; - { - s_SPITTypesRemote[p_ptrSpitType->getID()] = p_ptrSpitType; - return true; - } -} -bool SPITType::removeSPITType(SPITType *p_ptrSpitType) { - if (p_ptrSpitType == NULL) - return false; - { - auto i = s_SPITTypes.find(p_ptrSpitType->getID()); - if (i == s_SPITTypes.end()) { - return false; - } - i = s_SPITTypes.erase(i); - return true; - } -} -bool SPITType::removeSPITTypeRemote(SPITType *p_ptrSpitType) { - if (p_ptrSpitType == NULL) - return false; - { - auto i = s_SPITTypesRemote.find(p_ptrSpitType->getID()); - if (i == s_SPITTypesRemote.end()) { - return false; - } - i = s_SPITTypesRemote.erase(i); - return true; - } -} - -int SPITType::getSPITTypeCount() { - return s_SPITTypes.size(); -} -int SPITType::getSPITTypeRemoteCount() { - return s_SPITTypesRemote.size(); -} -SPITType *SPITType::getSPITType(int p_Index) { - SPITType *ptrSPITType = NULL; - { - if (p_Index < s_SPITTypes.size()) { - unordered_map::iterator i = next(s_SPITTypes.begin(), p_Index); - ptrSPITType = i->second; - } - return ptrSPITType; - } -} -/** - * Returns a reference to the SPITType at position p_Index.
- * Throws an exception if p_Index is out of range.
- * @param p_Index position - * @return the reference of the SPITType at position. - */ -const SPITType &SPITType::getSPITTypeRef(int p_Index) { - SPITType *ptrSPITType = NULL; - { - if (p_Index >= 0 && p_Index < s_SPITTypes.size()) { - unordered_map::iterator i = next(s_SPITTypes.begin(), p_Index); - ptrSPITType = i->second; - return *ptrSPITType; - } else { - throw "SPITType index out of range"; - } - } -} -SPITType *SPITType::getSPITTypeRemote(int p_Index) { - SPITType *ptrSPITType = NULL; - { - if (p_Index < s_SPITTypesRemote.size()) { - unordered_map::iterator i = next(s_SPITTypesRemote.begin(), p_Index); - ptrSPITType = i->second; - } - return ptrSPITType; - } -} -/** - * Returns a reference to the remote SPITType at position p_Index.
- * Throws an exception if p_Index is out of range.
- * @param p_Index position - * @return the reference of the SPITType at position. - */ -const SPITType &SPITType::getSPITTypeRemoteRef(int p_Index) { - SPITType *ptrSPITType = NULL; - { - if (p_Index >= 0 && p_Index < s_SPITTypesRemote.size()) { - unordered_map::iterator i = next(s_SPITTypesRemote.begin(), p_Index); - ptrSPITType = i->second; - return *ptrSPITType; - } else { - throw "Remote SPITType index out of range"; - } - } -} - -void SPITType::clearSPITTypes() { - SPITType *ptrSPITType; - { - for (auto i = s_SPITTypes.begin(); i != s_SPITTypes.end(); i++) { - ptrSPITType = i->second; - i = s_SPITTypes.erase(i); - delete ptrSPITType; - if (i == s_SPITTypes.end()) { - break; - } - } - } -} -void SPITType::clearSPITTypesRemote() { - SPITType *ptrSPITType; - { - for (auto i = s_SPITTypesRemote.begin(); i != s_SPITTypesRemote.end(); i++) { - ptrSPITType = i->second; - i = s_SPITTypesRemote.erase(i); - delete ptrSPITType; - if (i == s_SPITTypesRemote.end()) { - break; - } - } - } -} - -void SPITType::eventProjectClosed() { - SPITType *ptrSPITType; - for (auto i = s_SPITTypes.begin(); i != s_SPITTypes.end(); i++) { - ptrSPITType = i->second; +void SPITType::eventProjectClosed(SpitRepo &repo, SpitRepo &remoteRepo) { + auto &entries = repo.getRepo(); + for (auto i = entries.begin(); i != entries.end();) { + SPITType *ptrSPITType = i->second.get(); if (ptrSPITType->getCreatedByClient() == true) { + i++; continue; } - i = s_SPITTypes.erase(i); - delete ptrSPITType; - if (i == s_SPITTypes.end()) { - break; - } + i = entries.erase(i); } // Remote - for (auto i = s_SPITTypesRemote.begin(); i != s_SPITTypesRemote.end(); i++) { - ptrSPITType = i->second; - i = s_SPITTypesRemote.erase(i); - delete ptrSPITType; - if (i == s_SPITTypesRemote.end()) { - break; - } - } + remoteRepo.clearEntries(); } /** - * Sets confirmed = false for all SPITTypes.
- * This should be called when the client has loaded a project.
+ * Sets confirmed = false for all SPITTypes. + * This should be called when the client has loaded a project. */ -void SPITType::setConfirmedFalse() { - SPITType *ptrSPITType; - { - for (auto i = s_SPITTypes.begin(); i != s_SPITTypes.end(); i++) { - ptrSPITType = i->second; - ptrSPITType->setConfirmed(false); - } +void SPITType::setConfirmedFalse(SpitRepo &repo) { + auto &entries = repo.getRepo(); + for (auto i = entries.begin(); i != entries.end(); i++) { + i->second->setConfirmed(false); } } -SPITType::SPITType() { - initMembers(); +SPITType::SPITType(string p_ID) { + m_ID = p_ID; } -/* -SPITType::SPITType(const SPITType& orig) { - m_Confirmed = orig.getConfirmed(); - m_DefaultDelay = orig.getDefaultDelay(); - m_DefaultDuration = orig.getDefaultDuration(); - m_Fixed = orig.getFixed(); - m_GroupName = orig.getGroupName(); - m_ID = orig.getID(); - m_Name = orig.getName(); - m_ServerProjectIndepended = orig.getProjectIndepended(); - m_ServerRemote = orig.getServerRemote(); -} -*/ -SPITType::SPITType(string p_ID, string p_GroupName, string p_Name, bool p_Fixed, bool p_ProjectIndepended, long long p_DefaultDelay, long long p_DefaultDuration) { - initMembers(); + +SPITType::SPITType(string id, string grpName, string name, bool fixed, bool projectIndependent, long long defaultDelay, long long defaultDuration) { m_ActionAssigned = false; m_Confirmed = false; - m_ID = p_ID; - m_GroupName = p_GroupName; - m_Name = p_Name; - m_Fixed = p_Fixed; - m_ServerProjectIndepended = p_ProjectIndepended; - m_DefaultDelay = p_DefaultDelay; - m_DefaultDuration = p_DefaultDuration; -} - -SPITType::~SPITType() { -} - -void SPITType::initMembers() { - m_Confirmed = false; - m_DefaultDelay = 0; - m_DefaultDuration = 0; - m_Fixed = false; - m_GroupName = ""; - m_ID = createGUID(); - m_Name = ""; - m_ServerProjectIndepended = false; - m_ServerRemote = false; + m_ID = id; + m_GroupName = grpName; + m_Name = name; + m_Fixed = fixed; + m_ServerProjectIndepended = projectIndependent; + m_DefaultDelay = defaultDelay; + m_DefaultDuration = defaultDuration; } void SPITType::setCreatedByClient(bool p_CreatedByClient) { m_CreatedByClient = p_CreatedByClient; } -void SPITType::setID(string p_ID) { - m_ID = p_ID; -} - /** * This is used by the server and client to tell if the other side has registered the changes. * @param p_Confirmed @@ -303,14 +74,14 @@ bool SPITType::setConfirmed(bool p_Confirmed) { return true; } -bool SPITType::setGroupName(string p_GroupName) { +bool SPITType::setGroupName(const string &p_GroupName) { if (m_GroupName == p_GroupName) return false; m_GroupName = p_GroupName; m_Confirmed = false; return true; } -bool SPITType::setName(string p_Name) { +bool SPITType::setName(const string &p_Name) { if (m_Name == p_Name) return false; m_Name = p_Name; @@ -354,9 +125,9 @@ bool SPITType::setDefaultDuration(long long p_Duration) { } /** - * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.
- * This can used to setActionAssigned to all SPITObjects with this SPITType.
- * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.
+ * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol. + * This can used to setActionAssigned to all SPITObjects with this SPITType. + * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated. * @return true = the m_ActionAssigned has changed. */ bool SPITType::setActionAssigned(bool p_ActionAssigned) { @@ -370,10 +141,10 @@ bool SPITType::setActionAssigned(bool p_ActionAssigned) { /** * Set the content of the SPITType as received from the server * @param p_ReportSPITType - * @return true = the SPITType is changed
+ * @return true = the SPITType is changed * false = the SPITType is NOT changed, because it is not allowed to change. */ -bool SPITType::setMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType) { +bool SPITType::setMessageOP(SPIT_Message::ReportSPITType &reportSpitType) { bool boolChangeAllowed; bool boolChanged = false; @@ -383,76 +154,84 @@ bool SPITType::setMessageOP(SPIT_Message::ReportSPITType *p_ReportSPITType) { boolChangeAllowed = true; } - // Confirmation should be changable + // Confirmation should be changeable if (m_CreatedByClient) { // Server reports a client created SPITType -> the type is confirmed m_Confirmed = true; } else { // type is NOT client created -> the client has to confirm the SPITtype - m_Confirmed = p_ReportSPITType->getConfirmed(); + m_Confirmed = reportSpitType.getConfirmed(); } - if (m_DefaultDelay != p_ReportSPITType->getDelay()) { - if (boolChangeAllowed == false) - throw new exception(); - m_DefaultDelay = p_ReportSPITType->getDelay(); + if (m_DefaultDelay != reportSpitType.getDelay()) { + if (boolChangeAllowed == false) { + return false; + } + m_DefaultDelay = reportSpitType.getDelay(); boolChanged = true; } - if (m_DefaultDuration != p_ReportSPITType->getDuration()) { - if (boolChangeAllowed == false) - throw new exception(); - m_DefaultDuration = p_ReportSPITType->getDuration(); + if (m_DefaultDuration != reportSpitType.getDuration()) { + if (boolChangeAllowed == false) { + return false; + } + m_DefaultDuration = reportSpitType.getDuration(); boolChanged = true; } - if (m_Fixed != p_ReportSPITType->getFixed()) { - if (boolChangeAllowed == false) - throw new exception(); - m_Fixed = p_ReportSPITType->getFixed(); + if (m_Fixed != reportSpitType.getFixed()) { + if (boolChangeAllowed == false) { + return false; + } + m_Fixed = reportSpitType.getFixed(); boolChanged = true; } - if (m_GroupName != p_ReportSPITType->getGroupName()) { - if (boolChangeAllowed == false) - throw new exception(); - m_GroupName = p_ReportSPITType->getGroupName(); + if (m_GroupName != reportSpitType.getGroupName()) { + if (boolChangeAllowed == false) { + return false; + } + m_GroupName = reportSpitType.getGroupName(); boolChanged = true; } - if (m_ID != p_ReportSPITType->getID()) { - if (boolChangeAllowed == false) - throw new exception(); - m_ID = p_ReportSPITType->getID(); + if (m_ID != reportSpitType.getID()) { + if (boolChangeAllowed == false) { + return false; + } + m_ID = reportSpitType.getID(); boolChanged = true; } - if (m_Name != p_ReportSPITType->getName()) { - if (boolChangeAllowed == false) - throw new exception(); - m_Name = p_ReportSPITType->getName(); + if (m_Name != reportSpitType.getName()) { + if (boolChangeAllowed == false) { + return false; + } + m_Name = reportSpitType.getName(); boolChanged = true; } - if (m_ServerProjectIndepended != p_ReportSPITType->getServerProjectIndepended()) { - if (boolChangeAllowed == false) - throw new exception(); - m_ServerProjectIndepended = p_ReportSPITType->getServerProjectIndepended(); + if (m_ServerProjectIndepended != reportSpitType.getServerProjectIndepended()) { + if (boolChangeAllowed == false) { + return false; + } + m_ServerProjectIndepended = reportSpitType.getServerProjectIndepended(); boolChanged = true; } - if (m_ServerRemote != p_ReportSPITType->getServerRemote()) { - if (boolChangeAllowed == false) - throw new exception(); - m_ServerRemote = p_ReportSPITType->getServerRemote(); + if (m_ServerRemote != reportSpitType.getServerRemote()) { + if (boolChangeAllowed == false) { + return false; + } + m_ServerRemote = reportSpitType.getServerRemote(); boolChanged = true; } return boolChanged; } -void SPITType::fillMessageOP(SPIT_Message::ReportSPITType *ptrSMReportSPITType) { - ptrSMReportSPITType->setConfirmed(m_Confirmed); - ptrSMReportSPITType->setDelay(m_DefaultDelay); - ptrSMReportSPITType->setDuration(m_DefaultDuration); - ptrSMReportSPITType->setFixed(m_Fixed); - ptrSMReportSPITType->setGroupName(m_GroupName); - ptrSMReportSPITType->setID(m_ID); - ptrSMReportSPITType->setName(m_Name); - ptrSMReportSPITType->setServerProjectIndepended(m_ServerProjectIndepended); - ptrSMReportSPITType->setServerRemote(m_ServerRemote); +void SPITType::fillMessageOP(SPIT_Message::ReportSPITType &smReportSpitType) const { + smReportSpitType.setConfirmed(m_Confirmed); + smReportSpitType.setDelay(m_DefaultDelay); + smReportSpitType.setDuration(m_DefaultDuration); + smReportSpitType.setFixed(m_Fixed); + smReportSpitType.setGroupName(m_GroupName); + smReportSpitType.setID(m_ID); + smReportSpitType.setName(m_Name); + smReportSpitType.setServerProjectIndepended(m_ServerProjectIndepended); + smReportSpitType.setServerRemote(m_ServerRemote); } -void SPITType::fillMessageOP(SPIT_Message::RemoveSPITType *ptrSMRemoveSPITType) { - ptrSMRemoveSPITType->setID(m_ID); +void SPITType::fillMessageOP(SPIT_Message::RemoveSPITType &smRemoveSpitType) const { + smRemoveSpitType.setID(m_ID); } diff --git a/components/spit/src/SPIT_Client.cpp b/components/spit/src/SPIT_Client.cpp index ad14445..329237e 100644 --- a/components/spit/src/SPIT_Client.cpp +++ b/components/spit/src/SPIT_Client.cpp @@ -20,32 +20,27 @@ static const char *TAG = "SPIT"; /** - * Create a new SPIT_client instance, should be done once by the user app.
+ * Create a new SPIT_client instance, should be done once by the user app. * @param p_SPITClientInterface the user app should implement the SPIT_ClientInterface. */ SPIT_Client::SPIT_Client(string name, string projName, Callbacks calls) : I_SAD_Client(), mCallbacks(calls), m_Name(name), m_ProjName(projName) { - m_ConnectionStatus = CONNECTION_NONE; - m_ID = createGUID(); m_ComputerName = getClientHostName(); auto ip = SPITSocket::getAdaptersInfo(); mSPITSocket = new SPITSocket(ip); - m_MessageNumber_Send = 1; - m_MessageNumber_Received = -1; // set to -1 because the first received message will set the number (1..255) } SPIT_Client::~SPIT_Client() { stopServerAutoDetect(); - disconnectInternal(CONNECTION_NONE); + disconnectInternal(Connection::None); } void SPIT_Client::clientProjectClose() { - if (m_ConnectionStatus == CONNECTION_OK) { + if (m_ConnectionStatus == Connection::Ok) { ESP_LOGI(TAG, " ... tidy up ressources"); - SPIT_Message::CloseSPITProject sMCloseSPITProject; - sMCloseSPITProject.setProjectID(m_ProjName); - if (sendSPITMessage(sMCloseSPITProject) < 0) { + SPIT_Message::CloseSPITProject closeSPITProject(m_ProjName); + if (sendSPITMessage(closeSPITProject) < 0) { ESP_LOGD(TAG, "SPIT_Client could not send Client's ReportSPITProject"); } } @@ -53,16 +48,14 @@ void SPIT_Client::clientProjectClose() { void SPIT_Client::clientProjectLoaded() { // set confirmed = false for all SPITTypes and SPITObjects - SPITType::setConfirmedFalse(); - SPITObject::setConfirmedFalse(); + SPITType::setConfirmedFalse(mSpitTypes); + SPITObject::setConfirmedFalse(mSpitObjects); - if (m_ConnectionStatus == CONNECTION_OK) { + if (m_ConnectionStatus == Connection::Ok) { // send ReportSPITProject to the server - SPIT_Message::ReportSPITProject sMReportSPITProject; - sMReportSPITProject.setProjectID(m_ProjName); - sMReportSPITProject.setProjectName(m_ProjName); - sMReportSPITProject.setFramesPerSecond(0); - if (sendSPITMessage(sMReportSPITProject) < 0) { + SPIT_Message::ReportSPITProject reportSPITProject(m_ProjName, m_ProjName); + reportSPITProject.setFramesPerSecond(0); + if (sendSPITMessage(reportSPITProject) < 0) { ESP_LOGD(TAG, "SPIT_CLient::clientProjectLoaded could not send Client's ReportSPITProject"); } @@ -75,92 +68,69 @@ void SPIT_Client::clientProjectLoaded() { } /** - * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol.
- * This can used to setActionAssigned to all SPITObjects with this SPITType.
- * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated.
- * This tells the server not what action is done, but it tells the server that there is an action.
- * @param p_SPITTypeID the id of the SPITType + * Virtual construct - means ActionAssigned for SPITTypes is is not implemented in SPITProtocol. + * This can used to setActionAssigned to all SPITObjects with this SPITType. + * This may be used in the case when the same action should be done for every SPITObject with this SPITType associated. + * This tells the server not what action is done, but it tells the server that there is an action. + * @param typeId the id of the SPITType * @param p_ActionAssigned */ -void SPIT_Client::setActionSPITType(string p_SPITTypeID, bool p_ActionAssigned) { - SPITType *ptrSPITType; - SPITObject *ptrSPITObject; - { - ptrSPITType = SPITType::getSPITType(p_SPITTypeID); - if (ptrSPITType == NULL) - return; - if (ptrSPITType->setActionAssigned(p_ActionAssigned) == true) { - sendSPITTypeInternal(ptrSPITType); +void SPIT_Client::setActionSPITType(string typeId, bool p_ActionAssigned) { + SPITType *spitType = mSpitTypes.getEntry(typeId); + if (spitType == nullptr) + return; + if (spitType->setActionAssigned(p_ActionAssigned)) { + sendSPITTypeInternal(*spitType); - for (int i = 0; i < SPITObject::getSPITObjectCount(); i++) { - ptrSPITObject = SPITObject::getSPITObject(i); - if (ptrSPITObject == NULL) - continue; - if (ptrSPITObject->getSPITTypeID() == ptrSPITType->getID()) { - if (ptrSPITObject->setActionAssignedType(p_ActionAssigned) == true) { - sendSPITObjectInternal(ptrSPITObject); - } + for (int i = 0; i < mSpitObjects.getEntryCount(); i++) { + SPITObject *ptrSPITObject = mSpitObjects.getEntry(i); + if (ptrSPITObject == nullptr) + continue; + if (ptrSPITObject->getSPITTypeID() == spitType->getID()) { + if (ptrSPITObject->setActionAssignedType(p_ActionAssigned) == true) { + sendSPITObjectInternal(ptrSPITObject); } } } } } -/** - * This should be called if the user wants to associate/remove an action with a SPITObject. - * @param p_SPITObjectID - * @param p_ActionAssigned - */ -void SPIT_Client::setActionSPITObject(string p_SPITObjectID, bool p_ActionAssigned) { - SPITObject *ptrSPITObject; - { - ptrSPITObject = SPITObject::getSPITObject(p_SPITObjectID); - if (ptrSPITObject == NULL) - return; - if (ptrSPITObject->setActionAssigned(p_ActionAssigned) == true) { - sendSPITObjectInternal(ptrSPITObject); - } +/** This should be called if the user wants to associate/remove an action with a SPITObject. */ +void SPIT_Client::setActionSPITObject(string spitObjId, bool actionAssigned) { + SPITObject *spitObject = mSpitObjects.getEntry(spitObjId); + if (spitObject == nullptr) + return; + if (spitObject->setActionAssigned(actionAssigned) == true) { + sendSPITObjectInternal(spitObject); } } //---------- ServerAutoDetection SAD ----------- -/** Starts the autodetection of SPITServers in the local network. If a connection is tried, the autodetection should be stopped before.
+/** Starts the autodetection of SPITServers in the local network. If a connection is tried, the autodetection should be stopped before. * If a SPITServer is detected in the locale network an eventServerDetected occurs. */ void SPIT_Client::startServerAutoDetect() { if (m_DisconnectedByServer == true) { // Server has previously disconnected -> do not start ServerAutodetect directly - // sleep a little to give the SPITServer time to clean up its stuff - - fos::Task::delayMs(1000); + fos::Task::delayMs(1000); // sleep a little to give the SPITServer time to clean up its stuff } SAD_DetectedServer::clearDetectedServers(); if (!sThread) { sThread = new fos::TaskT(SPIT_Client::processSocketTask, *this, "spitSock", fos::Task::DefaultStackSize * 2); } - abortSearch = false; + mAbortSearch = false; sStartSad.give(); } -/** - * Stops the auto detection of SPIT servers. - */ +/** Stops the auto detection of SPIT servers. */ void SPIT_Client::stopServerAutoDetect() { - abortSearch = true; + mAbortSearch = true; } /** - * If a new server was found by the ServerAutoDetect mechanism, this function is called.
- * To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect.
- * If a server can be reached via several IP addresses, the IP address is selected according to the following preference:
- * 1.) If a loopback address is available, it is used.
- * 2.) If an IP4 address is available, it is used.
- * 3.) In the other cases the IP6 address is used.
- * @param p_ID the id of the server (every started server should generate an id) - * @param p_Name the name of the SPIT server - * @param p_ComputerName the Hostname of the cpmputer on which the SPIT server is running - * @param p_IP the selected ip address of the SPIT server - * @param p_Port the port of the SPIT server - * @param p_Addition sometimes server may have additional informations + * If a new server was found by the ServerAutoDetect mechanism, this function is called. + * To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect. + * If a server can be reached via several IP addresses, the IP address is selected according to the following preference: */ void SPIT_Client::eventServerDetected(SAD_DetectedServer &server) { mCallbacks.onServerEvent(ServerEvent::Detect, server); @@ -168,8 +138,7 @@ void SPIT_Client::eventServerDetected(SAD_DetectedServer &server) { if (_doReconnect) { if (m_ServerID == server.getID()) { stopServerAutoDetect(); - ESP_LOGI(TAG, "reconnect to %s", server.getIP().data()); - // ClientPort = "0" meeans use any port + ESP_LOGI(TAG, "reconnect to %s / %s", server.getIP().data(), server.getPort().data()); if (connect(server.getIP(), server.getPort(), server.getClientIP(), "0")) { return; } @@ -178,22 +147,16 @@ void SPIT_Client::eventServerDetected(SAD_DetectedServer &server) { // Stop auto detection because a suitable server was found stopServerAutoDetect(); - ESP_LOGI(TAG, "connect to %s", server.getIP().data()); - // ClientPort = "0" meeans use any port - if (not connect(server.getIP(), server.getPort(), server.getClientIP(), "0")) { + ESP_LOGI(TAG, "connect to %s / %s", server.getIP().data(), server.getPort().data()); + if (!connect(server.getIP(), server.getPort(), server.getClientIP(), "0" /*= any port*/)) { // connection message could not be sent -> better to restart AutoDetection startServerAutoDetect(); } } + /** * If a SPITServer is not more found, this function is called. - * To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect.
- * @param p_ID the id of the server (every started server should generate an id) - * @param p_Name the name of the SPIT server - * @param p_ComputerName the Hostname of the cpmputer on which the SPIT server is running - * @param p_IP the selected ip address of the SPIT server - * @param p_Port the port of the SPIT server - * @param p_Addition sometimes server may have additional informations + * To do so the SAD_Client ServerAutoDetect has to be startet - see SAD_Client::startServerAutoDetect. */ void SPIT_Client::eventServerLost(SAD_DetectedServer &server) { mCallbacks.onServerEvent(ServerEvent::Lost, server); @@ -204,166 +167,122 @@ void SPIT_Client::eventServerChanged(SAD_DetectedServer &server) { // tryConnection(p_DetectedServer); } -// void MyApp::tryConnection(const SAD_DetectedServer& p_DetectedServer) { -// //fetch the infoemations from the p_DetectedServer -// bool boolPossibleConnect; -// bool boolSuccess; +// void MyApp::tryConnection(const SAD_DetectedServer &detected) { +// // fetch the infoemations from the detected +// bool boolSuccess = false; +// bool boolPossibleConnect = checkPossibleConnection(detected); -// boolPossibleConnect = checkPossibleConnection(p_DetectedServer); +// if (boolPossibleConnect == false) +// return; -// if (boolPossibleConnect == false) return; +// // -------------------------------------- +// // You have three Options to use the detected server +// // OPTION 1 Use the first server found +// // OPTION 2 Use the first server found that fulfills specific conditions +// // OPTION 3 take a copy of the detected and do connection later +// // SAD_DetectedServer o_DetectedServer = detected; //this will call the copy constructor +// // --------------------------------------- -// // -------------------------------------- -// // You have three Options to use the detected server -// // OPTION 1 Use the first server found -// // OPTION 2 Use the first server found that fulfills specific conditions -// // OPTION 3 take a copy of the p_DetectedServer and do connection later -// // SAD_DetectedServer o_DetectedServer = p_DetectedServer; //this will call the copy constructor -// // --------------------------------------- +// // Excample use the first detected LOOPBACK server, means the server runs on the same computer as this client +// // if (detected.getIpIsLoopback() == true) { //omit the if condition if you want to use the first server found -// //Excample use the first detected LOOPBACK server, means the server runs on the same computer as this client -// //if (p_DetectedServer.getIpIsLoopback() == true) { //omit the if condition if you want to use the first server found - -// boolSuccess = false; -// //Stop auto detection because a suitable server was found -// stopServerAutoDetect(); -// if (m_SPIT_Client != NULL) { -// m_ServerProjectName = p_DetectedServer.getProjectName(); -// m_ServerIP = p_DetectedServer.getIP(); +// boolSuccess = false; +// // Stop auto detection because a suitable server was found +// stopServerAutoDetect(); +// if (m_SPIT_Client != nullptr) { +// m_ServerProjectName = detected.getProjectName(); +// m_ServerIP = detected.getIP(); // #if defined(DEBUGOUTPUT) -// printf("MySPITApp: connect to %s ", p_DetectedServer.getIP().data()); +// printf("MySPITApp: connect to %s ", detected.getIP().data()); // #endif -// //Use the m_BoardNumber as login name -// string stringLoginName = ""; -// string stringLoginPassword = ""; -// boolSuccess = m_SPIT_Client->connect(p_DetectedServer.getIP(), p_DetectedServer.getPort(), p_DetectedServer.getClientIP(), stringLoginName, stringLoginPassword); //ClientPort = "0" meeans use any port -// } -// if (boolSuccess == false) { -// //connection message could not be sent -// //perhaps restart AutoDetection -// startServerAutoDetect(); -// } -// else { -// //WAITING FOR CONNECTION ANSWER -// //If the Server is closed in the meantime no answer will return -// //-> connect(..) has started the watchdog -// } +// // Use the m_BoardNumber as login name +// string stringLoginName = ""; +// string stringLoginPassword = ""; +// boolSuccess = m_SPIT_Client->connect(detected.getIP(), detected.getPort(), detected.getClientIP(), stringLoginName, stringLoginPassword); // ClientPort = "0" meeans use any port +// } +// if (boolSuccess == false) { +// // connection message could not be sent +// // perhaps restart AutoDetection +// startServerAutoDetect(); +// } else { +// // WAITING FOR CONNECTION ANSWER +// // If the Server is closed in the meantime no answer will return +// //-> connect(..) has started the watchdog +// } -// // } //Excample +// // } //Excample // } -void SPIT_Client::fillHeader(SPIT_Message::Header *p_Header) { - if (p_Header == NULL) - return; - p_Header->setClientID(m_ID); - p_Header->setServerID(m_ServerID); -} - -int SPIT_Client::sendSPITMessage(SPIT_Message::OPPart &spitMessageOPPart) { - if (m_StopReceiveSPITMessages == true) { - return -1; - } - - fillHeader(spitMessageOPPart.getHeader()); - +int SPIT_Client::sendSPITMessage(SPIT_Message::OPPart &opPart) { if (m_MessageNumber_Send == 255) m_MessageNumber_Send = 1; else m_MessageNumber_Send++; - spitMessageOPPart.getHeader()->setMessageNumber(m_MessageNumber_Send); + opPart.setMessageNumber(m_MessageNumber_Send); + opPart.setServerInfoInHeader(m_ID, m_ServerID); - SPIT_Message *ptrSPIT_Message; - ptrSPIT_Message = new SPIT_Message(&spitMessageOPPart); - const char *ptrMessageBytes = ptrSPIT_Message->getMessageBytes(); - int intByteCount = ptrSPIT_Message->getMesageByteCount(); - - if (ptrMessageBytes == NULL) { - return -1; - } + int opFlag = opPart.getHeader()->getOPFlag(); try { - int intResult = mSPITSocket->sendMessage(ptrMessageBytes, intByteCount); + auto spitMessage = SPIT_Message::createMessage(opPart); + if (spitMessage.empty()) { + return -1; + } + int intResult = mSPITSocket->sendMessage(spitMessage.data(), spitMessage.size()); if (intResult < 0) { - ESP_LOGD(TAG, "SPIT_Client::sendSPITMessage could not send message OPFlage: %d", ptrSPIT_Message->getOPFlag()); + ESP_LOGD(TAG, "client could not send message OPFlage: %d", opFlag); } return intResult; } catch (...) { - ESP_LOGD(TAG, "Exception SPIT_Client::sendSPITMessage OPFlag: %d", ptrSPIT_Message->getOPFlag()); - return -1; + ESP_LOGD(TAG, "Exception client OPFlag: %d", opFlag); } + return -1; } + bool SPIT_Client::startReceiveSPITMessages() { - { - if (mSPITSocket->getBoundClientFamily() <= 0) - return false; - m_StopReceiveSPITMessages = false; - m_ThreadReceive = new fos::TaskT(receiveSPITMessage, *this, "receiveTask", fos::Task::DefaultStackSize * 4); - } + if (!mSPITSocket->getIsBound()) + return false; + m_StopReceiveSPITMessages = false; + m_ThreadReceive = new fos::TaskT(receiveSPITMessage, *this, "receiveTask", fos::Task::DefaultStackSize * 4); + return true; } + void SPIT_Client::stopReceiveSPITMessages() { - { - if (m_StopReceiveSPITMessages == true) - return; - m_StopReceiveSPITMessages = true; - } + m_StopReceiveSPITMessages = true; } void SPIT_Client::receiveSPITMessage(SPIT_Client &rM) { - - char buffer[MAXSPITMESSAGEBYTECOUNT]; - int intResult; + char buffer[MAXSPITMESSAGEBYTECOUNT + 1]; + int rdLen; while (rM.m_StopReceiveSPITMessages == false) { - if (rM.m_StopReceiveSPITMessages == true) { - return; - } - intResult = rM.mSPITSocket->receiveMessage(rM.mSPITSocket->getBoundClientFamily(), buffer, MAXSPITMESSAGEBYTECOUNT, NULL); - if (intResult < 0) { + rdLen = rM.mSPITSocket->receiveMessage(buffer, MAXSPITMESSAGEBYTECOUNT, nullptr); + if (rdLen < 0) { if (rM.m_StopReceiveSPITMessages) { return; - ; } continue; } - auto ptrSPIT_Message = make_unique(buffer, intResult); - unsigned int intActualMessageNumber = (int)(ptrSPIT_Message->getHeader()->getMessageNumber() & 0xFF); - rM.parseSPIT_Message(move(ptrSPIT_Message)); - // rM.checkParseSPIT_Message(move(ptrSPIT_Message)); + auto vec = vector(buffer, buffer + rdLen); + auto spitMsg = make_unique(vec); + rM.parseSPIT_Message(move(spitMsg)); + // rM.checkParseSPIT_Message(move(spitMsg)); } } void SPIT_Client::resetMessageNumberReceived() { - SPIT_Message *ptrOvertakingSPIT_Message; - m_MessageNumber_Received = -1; - for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); it++) { - ptrOvertakingSPIT_Message = *it; - delete ptrOvertakingSPIT_Message; - // m_OvertakingSPIT_Messages.erase(it); - } m_OvertakingSPIT_Messages.clear(); } void SPIT_Client::checkParseSPIT_Message(unique_ptr p_SPITMessage) { answerWatchdog(); - if (p_SPITMessage == NULL) { - ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message Parameter == NULL\n"); - return; - } - if (p_SPITMessage->getHeader() == NULL) { - ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no Header\n"); - return; - } - if (p_SPITMessage->getOPPart() == NULL) { - ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no OPPart\n"); + if (!p_SPITMessage || !p_SPITMessage->getHeader() || p_SPITMessage->getOPPart()) { + ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message incomplete message"); return; } - int intActualMessageNumber; - int intNextMessageNumber; - SPIT_Message *ptrOvertakingSPIT_Message; - - intActualMessageNumber = (int)(p_SPITMessage->getHeader()->getMessageNumber() & 0xFF); + int intActualMessageNumber = (int)(p_SPITMessage->getHeader()->getMessageNumber() & 0xFF); if (intActualMessageNumber == 0) { parseSPIT_Message(std::move(p_SPITMessage)); @@ -375,7 +294,7 @@ void SPIT_Client::checkParseSPIT_Message(unique_ptr p_SPITMessage) return; } - intNextMessageNumber = m_MessageNumber_Received + 1; + int intNextMessageNumber = m_MessageNumber_Received + 1; if (intNextMessageNumber > 255 || intNextMessageNumber < 1) intNextMessageNumber = 1; @@ -391,12 +310,12 @@ void SPIT_Client::checkParseSPIT_Message(unique_ptr p_SPITMessage) if (intNextMessageNumber > 255 || intNextMessageNumber < 1) intNextMessageNumber = 1; - ptrOvertakingSPIT_Message = *it; + auto &ptrOvertakingSPIT_Message = *it; intActualMessageNumber = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF); if (intActualMessageNumber == intNextMessageNumber) { m_MessageNumber_Received = intActualMessageNumber; - // parseSPIT_Message(ptrOvertakingSPIT_Message); + parseSPIT_Message(move(ptrOvertakingSPIT_Message)); m_OvertakingSPIT_Messages.erase(it); it = m_OvertakingSPIT_Messages.begin(); @@ -407,120 +326,102 @@ void SPIT_Client::checkParseSPIT_Message(unique_ptr p_SPITMessage) } else { // p_SPITMessage has overtaken another message - addOvertakingSPIT_Message(p_SPITMessage.get()); + addOvertakingSPIT_Message(move(p_SPITMessage)); } } -int SPIT_Client::s_MAX_OVERTAKING_SPIT_MESSAGES = 10; - -void SPIT_Client::addOvertakingSPIT_Message(SPIT_Message *p_SPIT_Message) { - if (p_SPIT_Message == nullptr) +void SPIT_Client::addOvertakingSPIT_Message(unique_ptr p_SPIT_Message) { + if (!p_SPIT_Message) { return; - int intMessageNumber; - SPIT_Message *ptrOvertakingSPIT_Message; - int intOvertakingMessageNumber; - - if (m_OvertakingSPIT_Messages.size() > s_MAX_OVERTAKING_SPIT_MESSAGES) { + } + if (m_OvertakingSPIT_Messages.size() > MAX_OVERTAKING_SPIT_MESSAGES) { ESP_LOGD(TAG, "SPIT_Client receiveing: perhaps message lost !!!!!"); } - intMessageNumber = (int)(p_SPIT_Message->getHeader()->getMessageNumber() & 0xFF); - for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); it++) { - ptrOvertakingSPIT_Message = *it; - intOvertakingMessageNumber = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF); + int intMessageNumber = (int)(p_SPIT_Message->getHeader()->getMessageNumber() & 0xFF); + for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); ++it) { + const auto &overtaking = *it; + int intOvertakingMessageNumber = (int)(overtaking->getHeader()->getMessageNumber() & 0xFF); if (intMessageNumber < intOvertakingMessageNumber) { - m_OvertakingSPIT_Messages.insert(it, p_SPIT_Message); + m_OvertakingSPIT_Messages.insert(it, move(p_SPIT_Message)); return; } } - m_OvertakingSPIT_Messages.push_back(p_SPIT_Message); + m_OvertakingSPIT_Messages.push_back(move(p_SPIT_Message)); } void SPIT_Client::parseSPIT_Message(unique_ptr p_SPITMessage) { answerWatchdog(); - if (!p_SPITMessage) { - ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message Parameter == NULL"); - return; - } - if (p_SPITMessage->getHeader() == nullptr) { - ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no Header"); - return; - } - if (p_SPITMessage->getOPPart() == nullptr) { - ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no OPPart"); + if (!p_SPITMessage || !p_SPITMessage->getHeader() || !p_SPITMessage->getOPPart()) { + ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message incomplete message"); return; } + + switch (p_SPITMessage->getOPFlag()) { //----- Connection ----- - if (p_SPITMessage->getOPFlag() == SPIT_Message::ConnectAnswer::OPFLAG) { - SPIT_Message::ConnectAnswer *o_ConnectAnswer = (SPIT_Message::ConnectAnswer *)p_SPITMessage->getOPPart(); - parseConnectAnswer(o_ConnectAnswer); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::Disconnect::OPFLAG) { - SPIT_Message::Disconnect *o_Disconnect = (SPIT_Message::Disconnect *)p_SPITMessage->getOPPart(); - parseDisconnect(o_Disconnect); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::ReportSPITProject::OPFLAG) { - SPIT_Message::ReportSPITProject *o_ReportSPITProject = (SPIT_Message::ReportSPITProject *)p_SPITMessage->getOPPart(); - parseReportSPITProject(o_ReportSPITProject); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::Watchdog::OPFLAG) { - SPIT_Message::Watchdog *o_Watchdog = (SPIT_Message::Watchdog *)p_SPITMessage->getOPPart(); - parseWatchdog(o_Watchdog); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::WatchdogAnswer::OPFLAG) { - SPIT_Message::WatchdogAnswer *o_WatchdogAnswer = (SPIT_Message::WatchdogAnswer *)p_SPITMessage->getOPPart(); - parseWatchdogAnswer(o_WatchdogAnswer); - } + case SPIT_Message::ConnectAnswer::OPFLAG: + parseConnectAnswer(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::Disconnect::OPFLAG: + parseDisconnect(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::ReportSPITProject::OPFLAG: + parseReportSPITProject(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::Watchdog::OPFLAG: + parseWatchdog(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::WatchdogAnswer::OPFLAG: + parseWatchdogAnswer(p_SPITMessage->getOPPartAs()); + break; //----- SPIT Project ----- - else if (p_SPITMessage->getOPFlag() == SPIT_Message::StartProjectTransfer::OPFLAG) { - SPIT_Message::StartProjectTransfer *o_StartProjectTransfer = (SPIT_Message::StartProjectTransfer *)p_SPITMessage->getOPPart(); - parseStartProjectTransfer(o_StartProjectTransfer); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::CloseSPITProject::OPFLAG) { - SPIT_Message::CloseSPITProject *o_CloseSPITProjectr = (SPIT_Message::CloseSPITProject *)p_SPITMessage->getOPPart(); - parseCloseSPITProject(o_CloseSPITProjectr); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::RequestProjectTransfer::OPFLAG) { - SPIT_Message::RequestProjectTransfer *o_RequestProjectTransfer = (SPIT_Message::RequestProjectTransfer *)p_SPITMessage->getOPPart(); - parseRequestProjectTransfer(o_RequestProjectTransfer); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::StartProjectTransfer::OPFLAG) { - SPIT_Message::StartProjectTransfer *o_StartProjectTransfer = (SPIT_Message::StartProjectTransfer *)p_SPITMessage->getOPPart(); - parseStartProjectTransfer(o_StartProjectTransfer); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::EndProjectTransfer::OPFLAG) { - SPIT_Message::EndProjectTransfer *o_EndProjectTransfer = (SPIT_Message::EndProjectTransfer *)p_SPITMessage->getOPPart(); - parseEndProjectTransfer(o_EndProjectTransfer); - } + case SPIT_Message::StartProjectTransfer::OPFLAG: + parseStartProjectTransfer(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::CloseSPITProject::OPFLAG: + parseCloseSPITProject(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::RequestProjectTransfer::OPFLAG: + parseRequestProjectTransfer(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::EndProjectTransfer::OPFLAG: + parseEndProjectTransfer(p_SPITMessage->getOPPartAs()); + break; //----- SPIT Types ------ - else if (p_SPITMessage->getOPFlag() == SPIT_Message::ReportSPITType::OPFLAG) { - SPIT_Message::ReportSPITType *o_ReportSPITType = (SPIT_Message::ReportSPITType *)p_SPITMessage->getOPPart(); - parseReportSPITType(o_ReportSPITType); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::RemoveSPITType::OPFLAG) { - SPIT_Message::RemoveSPITType *o_RemoveSPITType = (SPIT_Message::RemoveSPITType *)p_SPITMessage->getOPPart(); - parseRemoveSPITType(o_RemoveSPITType); - } - //----- SPIT Objects ------ - else if (p_SPITMessage->getOPFlag() == SPIT_Message::ReportSPITObject::OPFLAG) { - SPIT_Message::ReportSPITObject *o_ReportSPITObject = (SPIT_Message::ReportSPITObject *)p_SPITMessage->getOPPart(); - parseReportSPITObject(o_ReportSPITObject); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::RemoveSPITObject::OPFLAG) { - SPIT_Message::RemoveSPITObject *o_RemoveSPITObject = (SPIT_Message::RemoveSPITObject *)p_SPITMessage->getOPPart(); - parseRemoveSPITObject(o_RemoveSPITObject); - } - //----- Play SPIT Objects ------ - else if (p_SPITMessage->getOPFlag() == SPIT_Message::PlaySPITStart::OPFLAG) { - SPIT_Message::PlaySPITStart *o_PlaySPITStart = (SPIT_Message::PlaySPITStart *)p_SPITMessage->getOPPart(); - parsePlaySPITStart(o_PlaySPITStart); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::PlaySPITObject::OPFLAG) { - SPIT_Message::PlaySPITObject *o_PlaySPITObject = (SPIT_Message::PlaySPITObject *)p_SPITMessage->getOPPart(); - parsePlaySPITObject(o_PlaySPITObject); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::PlaySPITEnd::OPFLAG) { - SPIT_Message::PlaySPITEnd *o_PlaySPITEnd = (SPIT_Message::PlaySPITEnd *)p_SPITMessage->getOPPart(); - parsePlaySPITEnd(o_PlaySPITEnd); - } else if (p_SPITMessage->getOPFlag() == SPIT_Message::ReportPlayStatus::OPFLAG) { - SPIT_Message::ReportPlayStatus *o_ReportPlayStatus = (SPIT_Message::ReportPlayStatus *)p_SPITMessage->getOPPart(); - parseReportPlayStatus(o_ReportPlayStatus); - } else { + case SPIT_Message::ReportSPITType::OPFLAG: + parseReportSPITType(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::RemoveSPITType::OPFLAG: + parseRemoveSPITType(p_SPITMessage->getOPPartAs()); + //----- SPIT Objects ------ + break; + case SPIT_Message::ReportSPITObject::OPFLAG: + parseReportSPITObject(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::RemoveSPITObject::OPFLAG: + parseRemoveSPITObject(p_SPITMessage->getOPPartAs()); + break; + //----- Play SPIT Objects ------ + case SPIT_Message::PlaySPITStart::OPFLAG: + parsePlaySPITStart(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::PlaySPITObject::OPFLAG: + parsePlaySPITObject(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::PlaySPITEnd::OPFLAG: + parsePlaySPITEnd(p_SPITMessage->getOPPartAs()); + break; + case SPIT_Message::ReportPlayStatus::OPFLAG: + parseReportPlayStatus(p_SPITMessage->getOPPartAs()); + break; + default: ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message: Unknown Message"); } } //----- Connection ------ /** - * Tries to connect to a SPITServer.
+ * Tries to connect to a SPITServer. * @param p_ServerIP the ip address of the SPIT server * @param p_ServerPort the port number of the SPIT server * @param p_ClientIP the local IP address of the client @@ -530,27 +431,20 @@ void SPIT_Client::parseSPIT_Message(unique_ptr p_SPITMessage) { * @return false = an error has occured, true = the connect was sent to the server */ bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort, string p_LoginName, string p_LoginPassword) { - int intResult; disconnect(); - { - mSPITSocket->setConnectionParams(p_ServerIP, p_ServerPort, p_ClientIP, p_ClientPort); - intResult = mSPITSocket->bindSocket(p_ServerIP, p_ClientIP, p_ClientPort); - if (intResult < 0) { - m_StopReceiveSPITMessages = true; - return false; - } + mSPITSocket->setConnectionParams(p_ServerIP, p_ServerPort, p_ClientIP, p_ClientPort); + if (mSPITSocket->bindSocket(p_ClientIP, p_ClientPort) < 0) { + m_StopReceiveSPITMessages = true; + return false; } - SPIT_Message::Connect sMConnect; - sMConnect.setClientComputerName(m_ComputerName); - sMConnect.setClientName(m_Name); + SPIT_Message::Connect sMConnect(m_ComputerName, m_Name); sMConnect.setLoginName(p_LoginName); sMConnect.setLoginPassword(p_LoginPassword); sMConnect.setServerIP(p_ServerIP); if (p_ServerPort.length() <= 0) { p_ServerPort = "0"; } - int intServerPort; - intServerPort = stoi(p_ServerPort); + int intServerPort = stoi(p_ServerPort); sMConnect.setServerPort(intServerPort); if (startReceiveSPITMessages() == false) { @@ -558,17 +452,16 @@ bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_Clien return false; } resetMessageNumberReceived(); - int intOldConnectionStatus = m_ConnectionStatus; + Connection intOldConnectionStatus = m_ConnectionStatus; - m_ConnectionStatus = CONNECTION_TRYCONNECTION; + m_ConnectionStatus = Connection::TryConnection; mCallbacks.onConnectionStatus(m_ServerID, m_ServerComputerName, m_ServerName, m_ServerStepTime, m_ConnectionStatus, intOldConnectionStatus); // sleep a little to make sure that the reception of the messages is started fos::Task::delayMs(500); - intResult = sendSPITMessage(sMConnect); - if (intResult < 0) { - m_ConnectionStatus = CONNECTION_NONE; + if (sendSPITMessage(sMConnect) < 0) { + m_ConnectionStatus = Connection::None; m_StopReceiveSPITMessages = true; return false; } @@ -579,36 +472,37 @@ bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_Clien * Terminates the connection to the SPITServer. */ void SPIT_Client::disconnect() { - disconnectInternal(CONNECTION_NONE); + disconnectInternal(Connection::None); } -void SPIT_Client::disconnectInternal(int p_Cause) { - int intOldConnectionStatus = m_ConnectionStatus; - int intResult; + +void SPIT_Client::disconnectInternal(Connection p_Cause) { + Connection intOldConnectionStatus = m_ConnectionStatus; m_ConnectionStatus = p_Cause; switch (m_ConnectionStatus) { - case CONNECTION_LOST: + case Connection::Lost: break; - case CONNECTION_NONE: { + case Connection::None: { SPIT_Message::Disconnect sMDisconnect; - intResult = sendSPITMessage(sMDisconnect); - if (intResult < 0) { - } + sendSPITMessage(sMDisconnect); } break; - case CONNECTION_NONESERVER: + case Connection::NoneServer: + break; + default: break; } + stopReceiveSPITMessages(); mCallbacks.onConnectionStatus(m_ServerID, m_ServerComputerName, m_ServerName, m_ServerStepTime, m_ConnectionStatus, intOldConnectionStatus); - if (intOldConnectionStatus != CONNECTION_NONE && intOldConnectionStatus != CONNECTION_NONESERVER) { - ESP_LOGI(TAG, "eventConnectionStatus %d ", m_ConnectionStatus); + if (intOldConnectionStatus != Connection::None && intOldConnectionStatus != Connection::NoneServer) { + ESP_LOGI(TAG, "eventConnectionStatus %d ", (int)m_ConnectionStatus); switch (m_ConnectionStatus) { - case SPIT_Client::CONNECTION_NONE: + case SPIT_Client::Connection::None: ESP_LOGD(TAG, "not connected"); break; - case SPIT_Client::CONNECTION_NONESERVER: + case SPIT_Client::Connection::NoneServer: ESP_LOGD(TAG, "connection terminated by server"); // call eventProjectClosed because this may not be sended by the server, // when the connection is closed @@ -618,34 +512,33 @@ void SPIT_Client::disconnectInternal(int p_Cause) { // _doReconnect = false; startServerAutoDetect(); break; - case SPIT_Client::CONNECTION_LOST: + case SPIT_Client::Connection::Lost: ESP_LOGD(TAG, "connection lost"); // Maybe you want to reconnect, see eventServerDetected(...) // We have lost the connection -> set the flag to true and start the autodetection to reconnect at eventServerDetected(...) // _doReconnect = true; startServerAutoDetect(); break; + default: + break; } } } -void SPIT_Client::parseConnectAnswer(SPIT_Message::ConnectAnswer *p_ConnectAnswer) { - int intOldConnectionStatus; - intOldConnectionStatus = m_ConnectionStatus; - - if (p_ConnectAnswer->getClientID() != m_ID) +void SPIT_Client::parseConnectAnswer(SPIT_Message::ConnectAnswer &p_ConnectAnswer) { + if (p_ConnectAnswer.getClientID() != m_ID) return; - m_ServerID = p_ConnectAnswer->getServerID(); - m_ServerComputerName = p_ConnectAnswer->getServerComputerName(); - m_ServerName = p_ConnectAnswer->getServerName(); - m_ServerStepTime = p_ConnectAnswer->getStepTime(); + m_ServerID = p_ConnectAnswer.getServerID(); + m_ServerComputerName = p_ConnectAnswer.getServerComputerName(); + m_ServerName = p_ConnectAnswer.getServerName(); + m_ServerStepTime = p_ConnectAnswer.getStepTime(); - if (p_ConnectAnswer->getConnected() == false) { - disconnectInternal(CONNECTION_NONESERVER); + if (p_ConnectAnswer.getConnected() == false) { + disconnectInternal(Connection::NoneServer); } else { - p_ConnectAnswer->getStepTime(); - m_ConnectionStatus = CONNECTION_OK; + p_ConnectAnswer.getStepTime(); + m_ConnectionStatus = Connection::Ok; m_DisconnectedByServer = false; ESP_LOGD(TAG, "connection established"); stopServerAutoDetect(); // normally you should stop the autodetection before you try a connection @@ -662,8 +555,8 @@ void SPIT_Client::parseConnectAnswer(SPIT_Message::ConnectAnswer *p_ConnectAnswe * The SPIT server was closed * @param p_Disconnect */ -void SPIT_Client::parseDisconnect(SPIT_Message::Disconnect *p_Disconnect) { - int intCauseDisconnect = CONNECTION_NONESERVER; +void SPIT_Client::parseDisconnect(SPIT_Message::Disconnect &p_Disconnect) { + Connection intCauseDisconnect = Connection::NoneServer; /* function o_Callable = bind(&SPIT_Client::disconnectInternal, this, intCauseDisconnect); SPIT_Handler::addCallable(o_Callable); @@ -674,28 +567,24 @@ void SPIT_Client::parseDisconnect(SPIT_Message::Disconnect *p_Disconnect) { //----- Watchdog ------ /** - * The SPIT server sends a watchdog message at regular intervals. The client responds immediately with WatchdogAnswer
- * Conversely, the client also sends a watchdog message at regular intervals and waits for a WatchdogAnswer message.
- * This is used to check if the other side is still present.
+ * The SPIT server sends a watchdog message at regular intervals. The client responds immediately with WatchdogAnswer + * Conversely, the client also sends a watchdog message at regular intervals and waits for a WatchdogAnswer message. + * This is used to check if the other side is still present. * @param p_Watchdog */ -void SPIT_Client::parseWatchdog(SPIT_Message::Watchdog *p_Watchdog) { +void SPIT_Client::parseWatchdog(SPIT_Message::Watchdog &p_Watchdog) { // printf("parse Watchdog \n"); SPIT_Message::WatchdogAnswer o_WatchdogAnswer; - ; - int intResult = sendSPITMessage(o_WatchdogAnswer); - if (intResult < 0) { - } + sendSPITMessage(o_WatchdogAnswer); } /** - * The SPIT server sends a watchdog message at regular intervals. The client responds immediately with WatchdogAnswer
- * Conversely, the client also sends a watchdog message at regular intervals and waits for a WatchdogAnswer message.
- * This is used to check if the other side is still present.
+ * The SPIT server sends a watchdog message at regular intervals. The client responds immediately with WatchdogAnswer + * Conversely, the client also sends a watchdog message at regular intervals and waits for a WatchdogAnswer message. + * This is used to check if the other side is still present. * @param p_Watchdog */ -void SPIT_Client::parseWatchdogAnswer(SPIT_Message::WatchdogAnswer *p_WatchdogAnswer) { - answerWatchdog(); - ; // is also done by parseSPIT_Message +void SPIT_Client::parseWatchdogAnswer(SPIT_Message::WatchdogAnswer &p_WatchdogAnswer) { + answerWatchdog(); // is also done by parseSPIT_Message } void SPIT_Client::sendWatchdog() { int intResult; @@ -706,26 +595,24 @@ void SPIT_Client::sendWatchdog() { } } void SPIT_Client::eventWatchdogLost() { - if (m_ConnectionStatus == CONNECTION_TRYCONNECTION) { - disconnectInternal(CONNECTION_NONESERVER); + if (m_ConnectionStatus == Connection::TryConnection) { + disconnectInternal(Connection::NoneServer); } else { - disconnectInternal(CONNECTION_LOST); + disconnectInternal(Connection::Lost); } } //----- SPIT Project ------ -void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject *p_ReportSPITProject) { +void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject &p_ReportSPITProject) { // printf("parse ReportSPITProject \n"); - if (p_ReportSPITProject == NULL) - return; - m_ServerProjectID = p_ReportSPITProject->getProjectID(); - m_ServerProjectName = p_ReportSPITProject->getProjectName(); - m_ServerFramesPerSecond = p_ReportSPITProject->getFramesPerSecond(); + m_ServerProjectID = p_ReportSPITProject.getProjectID(); + m_ServerProjectName = p_ReportSPITProject.getProjectName(); + m_ServerFramesPerSecond = p_ReportSPITProject.getFramesPerSecond(); mCallbacks.onProjectUpdate(ProjUpdate::ServerLoaded, m_ServerProjectID); // Set all SPITTypes and SPITObjects confirmed = false - SPITType::setConfirmedFalse(); - SPITObject::setConfirmedFalse(); + SPITType::setConfirmedFalse(mSpitTypes); + SPITObject::setConfirmedFalse(mSpitObjects); // Send RequestProjectTransfer SPIT_Message::RequestProjectTransfer sMRequestProjectTransfer; @@ -735,65 +622,53 @@ void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject *p_Repo // todo Don't send the ReportSPITProject here it should be sended after parseEndProjectTransfer // Send client's ReportSPITProject - SPIT_Message::ReportSPITProject sMReportSPITProject; - sMReportSPITProject.setProjectID(m_ProjName); - sMReportSPITProject.setProjectName(m_ProjName); - sMReportSPITProject.setFramesPerSecond(0); - if (sendSPITMessage(sMReportSPITProject) < 0) { + SPIT_Message::ReportSPITProject reportSPITProject(m_ProjName, m_ProjName); + reportSPITProject.setFramesPerSecond(0); + if (sendSPITMessage(reportSPITProject) < 0) { ESP_LOGD(TAG, "SPIT_Client::parseReportSPITProject could not send Client's ReportSPITProject"); } } -void SPIT_Client::parseCloseSPITProject(SPIT_Message::CloseSPITProject *p_CloseSPITProject) { +void SPIT_Client::parseCloseSPITProject(SPIT_Message::CloseSPITProject &p_CloseSPITProject) { // printf("parse CloseSPITProject \n"); - if (p_CloseSPITProject == NULL) - return; string stringProjectID; - mCallbacks.onProjectUpdate(ProjUpdate::ServerClosed, p_CloseSPITProject->getProjectID()); + mCallbacks.onProjectUpdate(ProjUpdate::ServerClosed, p_CloseSPITProject.getProjectID()); + SPITPlayer::clearPlayers(); } string SPIT_Client::getServerProjectID() { return m_ServerProjectID; } string SPIT_Client::getServerProjectName() { return m_ServerProjectName; } int SPIT_Client::getServerFramesPerSecond() { return m_ServerFramesPerSecond; } -void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer *p_RequestProjectTransfer) { +void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer &p_RequestProjectTransfer) { // printf("parse RequestProjectTransfer \n"); // StartProjectTransfer SPIT_Message::StartProjectTransfer sMStartProjectTransfer; - fillHeader(sMStartProjectTransfer.getHeader()); - int intResult = sendSPITMessage(sMStartProjectTransfer); - if (intResult < 0) { + if (sendSPITMessage(sMStartProjectTransfer) < 0) { return; } - { - // send all listes SPITTypes - int intCount = SPITType::getSPITTypeCount(); - for (int i = 0; i < intCount; i++) { - SPITType *ptrSPITType = SPITType::getSPITType(i); - if (ptrSPITType == NULL) - break; - sendSPITTypeInternal(ptrSPITType); - fos::Task::delayMs(10); - } + // send all listes SPITTypes + int cntT = mSpitTypes.getEntryCount(); + for (int i = 0; i < cntT; i++) { + SPITType *ptrSPITType = mSpitTypes.getEntry(i); + if (!ptrSPITType) + break; + sendSPITTypeInternal(*ptrSPITType); + fos::Task::delayMs(10); } - { - int intCount = SPITObject::getSPITObjectCount(); - for (int i = 0; i < intCount; i++) { - SPITObject *ptrSPITObject = SPITObject::getSPITObject(i); - if (ptrSPITObject == NULL) - break; - sendSPITObjectInternal(ptrSPITObject); - fos::Task::delayMs(10); - } + int cntO = mSpitObjects.getEntryCount(); + for (int i = 0; i < cntO; i++) { + SPITObject *ptrSPITObject = mSpitObjects.getEntry(i); + if (ptrSPITObject == nullptr) + break; + sendSPITObjectInternal(ptrSPITObject); + fos::Task::delayMs(10); } // EndProjectTransfer SPIT_Message::EndProjectTransfer sMEndProjectTransfer; - fillHeader(sMEndProjectTransfer.getHeader()); - intResult = sendSPITMessage(sMEndProjectTransfer); - if (intResult < 0) { - } + sendSPITMessage(sMEndProjectTransfer); } /* NEW IMPLEMENTATION @@ -825,8 +700,8 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf // unique_lock o_LockType(*SPITType::getMutex()); // intCount = SPITType::getSPITTypeCount(); // for (int i = 0; i < intCount; i++) { - // ptrSPITType = SPITType::getSPITType(i); - // if (ptrSPITType == NULL) continue; + // ptrSPITType = mSpitTypes.getEntry(i); + // if (ptrSPITType == nullptr) continue; // intResult = sendSPITTypeInternal(ptrSPITType); // if (intResult < 0) return; // m_Watchdog->answerWatchdog(); @@ -836,10 +711,10 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf // { // unique_lock o_LockObject(*SPITObject::getMutex()); - // intCount = SPITObject::getSPITObjectCount(); + // intCount = mSpitObjects.getEntryCount(); // for (int i = 0; i < intCount; i++) { - // ptrSPITObject = SPITObject::getSPITObject(i); - // if (ptrSPITObject == NULL) continue; + // ptrSPITObject = mSpitObjects.getEntry(i); + // if (ptrSPITObject == nullptr) continue; // intResult = sendSPITObjectInternal(ptrSPITObject); // if (intResult < 0) return; // m_Watchdog->answerWatchdog(); @@ -885,8 +760,8 @@ void SPIT_Client::sendProject(SPIT_Client *p_PtrSPIT_Client) { // // unique_lock o_LockType(*SPITType::getMutex()); // intCount = SPITType::getSPITTypeCount(); // for (int i = 0; i < intCount; i++) { - // ptrSPITType = SPITType::getSPITType(i); - // if (ptrSPITType == NULL) continue; + // ptrSPITType = mSpitTypes.getEntry(i); + // if (ptrSPITType == nullptr) continue; // if (ptrSPITType->getCreatedByClient() == false) continue; // intResult = p_PtrSPIT_Client->sendSPITTypeInternal(ptrSPITType); // if (intResult < 0) return; @@ -897,10 +772,10 @@ void SPIT_Client::sendProject(SPIT_Client *p_PtrSPIT_Client) { // // { // // unique_lock o_LockObject(*SPITObject::getMutex()); - // intCount = SPITObject::getSPITObjectCount(); + // intCount = mSpitObjects.getEntryCount(); // for (int i = 0; i < intCount; i++) { - // ptrSPITObject = SPITObject::getSPITObject(i); - // if (ptrSPITObject == NULL) continue; + // ptrSPITObject = mSpitObjects.getEntry(i); + // if (ptrSPITObject == nullptr) continue; // if (ptrSPITObject->getCreatedByClient() == false) continue; // intResult = p_PtrSPIT_Client->sendSPITObjectInternal(ptrSPITObject); // if (intResult < 0) return; @@ -922,161 +797,147 @@ void SPIT_Client::sendProject(SPIT_Client *p_PtrSPIT_Client) { // //Send act } -void SPIT_Client::parseStartProjectTransfer(SPIT_Message::StartProjectTransfer *p_StartProjectTransfer) { +void SPIT_Client::parseStartProjectTransfer(SPIT_Message::StartProjectTransfer &p_StartProjectTransfer) { mCallbacks.onProjectUpdate(ProjUpdate::StartTransfer, m_ServerProjectID); } -void SPIT_Client::parseEndProjectTransfer(SPIT_Message::EndProjectTransfer *p_EndProjectTransfer) { - SPITObject::clearUnconfirmedSPITObjects(); +void SPIT_Client::parseEndProjectTransfer(SPIT_Message::EndProjectTransfer &p_EndProjectTransfer) { + SPITObject::clearUnconfirmedSPITObjects(mSpitObjects); mCallbacks.onProjectUpdate(ProjUpdate::EndTransfer, m_ServerProjectID); // Send SPIT_Message::ReportSPITProject after the m_SPITClientInterface is notfied of EndProjectTransfer - SPIT_Message::ReportSPITProject ptrSMReportSPITProject; - ptrSMReportSPITProject.setProjectID(m_ProjName); - ptrSMReportSPITProject.setProjectName(m_ProjName); - ptrSMReportSPITProject.setFramesPerSecond(0); - if (sendSPITMessage(ptrSMReportSPITProject) < 0) { + SPIT_Message::ReportSPITProject reportSPITProject(m_ProjName, m_ProjName); + reportSPITProject.setFramesPerSecond(0); + if (sendSPITMessage(reportSPITProject) < 0) { ESP_LOGD(TAG, "SPIT_Client::parseReportSPITProject could not send Client's ReportSPITProject"); } } //----- SPIT Types ------ -void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPITType) { - // printf("parse ReportSPITType ID %s Name %s \n",p_ReportSPITType->getID(), p_ReportSPITType->getName()); - if (p_ReportSPITType == NULL) - return; +void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType &p_ReportSPITType) { + // printf("parse ReportSPITType ID %s Name %s \n",p_ReportSPITType.getID(), p_ReportSPITType.getName()); SPITType *ptrSPITType; bool boolNew = false; bool boolChanged = false; { - if (p_ReportSPITType->getServerRemote() == false) { - ptrSPITType = SPITType::getSPITType(p_ReportSPITType->getID()); - if (ptrSPITType == NULL) { + if (p_ReportSPITType.getServerRemote() == false) { + ptrSPITType = mSpitTypes.getEntry(p_ReportSPITType.getID()); + if (ptrSPITType == nullptr) { // The user's app my veto the SPITType - if (mCallbacks.onCheckSpitTypeVeto(p_ReportSPITType) == false) { + bool createdByClient = false; + if (ptrSPITType) { + createdByClient = ptrSPITType->getCreatedByClient(); + } + + if (mCallbacks.onCheckSpitTypeVeto(false, createdByClient) == false) { + ESP_LOGW(TAG, "TypeVeto %s / %s", p_ReportSPITType.getID().c_str(), p_ReportSPITType.getName().c_str()); return; } - ptrSPITType = new SPITType(); + auto spitType = make_unique(p_ReportSPITType.getID()); + ptrSPITType = spitType.get(); + mSpitTypes.addEntry(move(spitType)); boolNew = true; } } else { - ptrSPITType = SPITType::getSPITTypeRemote(p_ReportSPITType->getID()); - if (ptrSPITType == NULL) { - ptrSPITType = new SPITType(); + ptrSPITType = mRemoteSpitTypes.getEntry(p_ReportSPITType.getID()); + if (ptrSPITType == nullptr) { + auto spitType = make_unique(p_ReportSPITType.getID()); + ptrSPITType = spitType.get(); + mRemoteSpitTypes.addEntry(move(spitType)); boolNew = true; } } - try { - boolChanged = ptrSPITType->setMessageOP(p_ReportSPITType); - } catch (...) { + if (!ptrSPITType->setMessageOP(p_ReportSPITType)) { // SPITType is not changable -> send back to the server - sendSPITTypeInternal(ptrSPITType); + sendSPITTypeInternal(*ptrSPITType); return; } auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed; // add or change SPITType - if (ptrSPITType->getServerRemote() == false) { - SPITType::addSPITType(ptrSPITType); - mCallbacks.onSpitType(eventType, *ptrSPITType); - } else { - SPITType::addSPITTypeRemote(ptrSPITType); - mCallbacks.onSpitTypeRemote(eventType, *ptrSPITType); - } + mCallbacks.onSpitType(eventType, ptrSPITType->getServerRemote(), *ptrSPITType); - if (ptrSPITType != NULL) { + if (ptrSPITType != nullptr) { if (ptrSPITType->setConfirmed(true) == true || boolChanged == true) { - sendSPITTypeInternal(ptrSPITType); + sendSPITTypeInternal(*ptrSPITType); } } } } -void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPITType) { - // printf("parse RemoveSPITType %s\n", p_RemoveSPITType->getID()); - if (p_RemoveSPITType == NULL) - return; - string stringSPITTypeID; +void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType &p_RemoveSPITType) { + // printf("parse RemoveSPITType %s\n", p_RemoveSPITType.getID()); bool boolRemote = false; - SPITType *ptrSPITType; - stringSPITTypeID = p_RemoveSPITType->getID(); + string stringSPITTypeID = p_RemoveSPITType.getID(); - { - ptrSPITType = SPITType::getSPITTypeRemote(stringSPITTypeID); - if (ptrSPITType != NULL) { - boolRemote = true; + SPITType *ptrSPITType = mRemoteSpitTypes.getEntry(stringSPITTypeID); + if (!ptrSPITType) { + boolRemote = true; + } else { + ptrSPITType = mSpitTypes.getEntry(stringSPITTypeID); + if (!ptrSPITType) { + boolRemote = false; } else { - ptrSPITType = SPITType::getSPITType(stringSPITTypeID); - if (ptrSPITType != NULL) { - boolRemote = false; - } else { - // No SPITType with stringSPITTypeID is listet - return; - } - } - - if (ptrSPITType->getCreatedByClient() && ptrSPITType->getFixed()) { - // the SPITyte is created by client himself and it is fixed -> don't remove the SPITType!! - // Send the SPITTyp back to the server - sendSPITTypeInternal(ptrSPITType); + // No SPITType with stringSPITTypeID is listet return; } + } - if (boolRemote == false) { - mCallbacks.onSpitType(ObjectEvent::Deleted, *ptrSPITType); - SPITType::removeSPITType(ptrSPITType); - } else { - mCallbacks.onSpitTypeRemote(ObjectEvent::Deleted, *ptrSPITType); - SPITType::removeSPITTypeRemote(ptrSPITType); - } - delete ptrSPITType; + if (ptrSPITType->getCreatedByClient() && ptrSPITType->getFixed()) { + // the SPITyte is created by client himself and it is fixed -> don't remove the SPITType!! + // Send the SPITTyp back to the server + sendSPITTypeInternal(*ptrSPITType); + return; + } + + mCallbacks.onSpitType(ObjectEvent::Deleted, boolRemote, *ptrSPITType); + if (boolRemote == false) { + mSpitTypes.removeEntry(*ptrSPITType); + } else { + mRemoteSpitTypes.removeEntry(*ptrSPITType); } } /** - * If a client has changed a SPITType, it should send it to the server to transmit the changes.
- * If the SPITType is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the changes.
+ * If a client has changed a SPITType, it should send it to the server to transmit the changes. + * If the SPITType is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the changes. * @param p_SPITType the pointer to the changed SPITType * @return 0 = is sended, -1 = is not sended */ -int SPIT_Client::sendSPITTypeInternal(SPITType *p_SPITType) { - if (p_SPITType == NULL) - return -1; - SPIT_Message::ReportSPITType ptrSMReportSPITType; - p_SPITType->fillMessageOP(&ptrSMReportSPITType); - return sendSPITMessage(ptrSMReportSPITType); +int SPIT_Client::sendSPITTypeInternal(SPITType &p_SPITType) { + SPIT_Message::ReportSPITType sMReportSPITType; + p_SPITType.fillMessageOP(sMReportSPITType); + return sendSPITMessage(sMReportSPITType); } /** - * Change an existing SPIT_Type.
+ * Change an existing SPIT_Type. * @param p_SPITType the SPITType vont * @return true = changed, false = not changed maybe p_SPITType is NULL or the SPITType doesn't exists */ bool SPIT_Client::changeSPITType(SPITType *p_SPITType) { - if (p_SPITType == NULL) + if (p_SPITType == nullptr) + return false; + SPITType *ptrSPITType = mSpitTypes.getEntry(p_SPITType->getID()); + if (ptrSPITType == nullptr) return false; - SPITType *ptrSPITType; - { - ptrSPITType = SPITType::getSPITType(p_SPITType->getID()); - if (ptrSPITType == NULL) - return false; - ptrSPITType->setDefaultDelay(p_SPITType->getDefaultDelay()); - ptrSPITType->setDefaultDuration(p_SPITType->getDefaultDuration()); - ptrSPITType->setFixed(p_SPITType->getFixed()); - ptrSPITType->setGroupName(p_SPITType->getGroupName()); - ptrSPITType->setName(p_SPITType->getName()); - ptrSPITType->setProjectIndepended(p_SPITType->getProjectIndepended()); + ptrSPITType->setDefaultDelay(p_SPITType->getDefaultDelay()); + ptrSPITType->setDefaultDuration(p_SPITType->getDefaultDuration()); + ptrSPITType->setFixed(p_SPITType->getFixed()); + ptrSPITType->setGroupName(p_SPITType->getGroupName()); + ptrSPITType->setName(p_SPITType->getName()); + ptrSPITType->setProjectIndepended(p_SPITType->getProjectIndepended()); + + mCallbacks.onSpitType(ObjectEvent::Changed, false, *ptrSPITType); + sendSPITTypeInternal(*ptrSPITType); - mCallbacks.onSpitType(ObjectEvent::Changed, *ptrSPITType); - sendSPITTypeInternal(ptrSPITType); - } return true; } /** - * If a client has removed a SPITType where id == p_SPITTypeID, it should send it to the server.
- * The corresponding SPITType if listet in SPITType will be deleted.
- * An eventRemoveSPITType will occur.
- * If a connection to a SPITServer is established, the SPITServer may dicard the deletion an an eventSPITType will occur
- * -> the SPITType will be listet again.
+ * If a client has removed a SPITType where id == p_SPITTypeID, it should send it to the server. + * The corresponding SPITType if listet in SPITType will be deleted. + * An eventRemoveSPITType will occur. + * If a connection to a SPITServer is established, the SPITServer may dicard the deletion an an eventSPITType will occur + * -> the SPITType will be listet again. * @param p_SPITType the id of the SPITType ro remove * @return 0 = is sended, -1 = is not sended */ @@ -1085,14 +946,13 @@ int SPIT_Client::removeSPITType(string p_SPITTypeID) { return -1; SPITType *ptrSPITType; { - ptrSPITType = SPITType::getSPITType(p_SPITTypeID); - if (ptrSPITType == NULL) + ptrSPITType = mSpitTypes.getEntry(p_SPITTypeID); + if (ptrSPITType == nullptr) return -1; SPIT_Message::RemoveSPITType sMRemoveSPITType; - ptrSPITType->fillMessageOP(&sMRemoveSPITType); - mCallbacks.onSpitType(ObjectEvent::Deleted, *ptrSPITType); - SPITType::removeSPITType(ptrSPITType); - delete ptrSPITType; + ptrSPITType->fillMessageOP(sMRemoveSPITType); + mCallbacks.onSpitType(ObjectEvent::Deleted, false, *ptrSPITType); + mSpitTypes.removeEntry(*ptrSPITType); return sendSPITMessage(sMRemoveSPITType); } return -1; @@ -1103,95 +963,92 @@ SPITType *SPIT_Client::createSPITTypeFixed(string p_ID, string p_GroupName, stri } SPITType *SPIT_Client::createSPITType(string p_ID, string p_GroupName, string p_Name, long long p_DefaultDelay, long long p_DefaultDuration, bool p_FIxed, bool p_ProjectIndepended) { - SPITType *ptrSPITType; bool boolNew; - { - ptrSPITType = SPITType::getSPITType(p_ID); - if (ptrSPITType == NULL) { - ptrSPITType = new SPITType(p_ID, p_GroupName, p_Name, p_FIxed, p_ProjectIndepended, p_DefaultDelay, p_DefaultDuration); - ptrSPITType->setCreatedByClient(true); - boolNew = true; - } else { - ptrSPITType->setID(p_ID); - ptrSPITType->setGroupName(p_GroupName); - ptrSPITType->setName(p_Name); - ptrSPITType->setFixed(p_FIxed); - ptrSPITType->setProjectIndepended(p_ProjectIndepended); - ptrSPITType->setDefaultDelay(p_DefaultDelay); - ptrSPITType->setDefaultDuration(p_DefaultDuration); - boolNew = false; - } + SPITType *ptrSPITType = mSpitTypes.getEntry(p_ID); + if (ptrSPITType == nullptr) { + auto spitType = make_unique(p_ID, p_GroupName, p_Name, p_FIxed, p_ProjectIndepended, p_DefaultDelay, p_DefaultDuration); + ptrSPITType = spitType.get(); + mSpitTypes.addEntry(move(spitType)); + ptrSPITType->setCreatedByClient(true); + boolNew = true; + } else { + ptrSPITType->setGroupName(p_GroupName); + ptrSPITType->setName(p_Name); + ptrSPITType->setFixed(p_FIxed); + ptrSPITType->setProjectIndepended(p_ProjectIndepended); + ptrSPITType->setDefaultDelay(p_DefaultDelay); + ptrSPITType->setDefaultDuration(p_DefaultDuration); + boolNew = false; } auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed; - SPITType::addSPITType(ptrSPITType); - mCallbacks.onSpitType(eventType, *ptrSPITType); - sendSPITTypeInternal(ptrSPITType); + mCallbacks.onSpitType(eventType, false, *ptrSPITType); + sendSPITTypeInternal(*ptrSPITType); return ptrSPITType; } //----- SPIT Objects ------ -void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_ReportSPITObject) { - ESP_LOGD(TAG, "parse ReportSPITObject %s\n", p_ReportSPITObject->getID().c_str()); - if (p_ReportSPITObject == NULL) - return; +void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject &p_ReportSPITObject) { + ESP_LOGD(TAG, "parse ReportSPITObject %s\n", p_ReportSPITObject.getID().c_str()); SPITObject *ptrSPITObject; SPITType *ptrSPITType; bool boolNew = false; bool boolRemote = false; bool boolChanged = false; { - if (p_ReportSPITObject->getServerRemote() == false) { + ESP_LOGD(TAG, "parseReportSPITObject %s / %s", p_ReportSPITObject.getID().c_str(), p_ReportSPITObject.getName().c_str()); + if (p_ReportSPITObject.getServerRemote() == false) { boolRemote = false; - ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITObject->getID()); - ptrSPITType = SPITType::getSPITType(p_ReportSPITObject->getSPITTypeID()); + ptrSPITObject = mSpitObjects.getEntry(p_ReportSPITObject.getID()); + ptrSPITType = mSpitTypes.getEntry(p_ReportSPITObject.getSPITTypeID()); - if (ptrSPITType == NULL) { + if (ptrSPITType == nullptr) { // No associated SPITType found - if (ptrSPITObject != NULL) { + if (ptrSPITObject != nullptr) { // SpitObject exists but has no corresponding SPITType -> remove the SPITObject without sending a message // Maybe the SPITObject has changed the SPITTypeID to a SPITTypeID of another board - SPITObject::removeSPITObject(ptrSPITObject); - delete ptrSPITObject; + mSpitObjects.removeEntry(*ptrSPITObject); } return; } - if (ptrSPITObject == NULL) { + bool isKnownType = ptrSPITType != nullptr; + if (ptrSPITObject == nullptr) { // The user's app my veto the SPITType - if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) { - ESP_LOGD(TAG, "ObjectVeto %s / %s", p_ReportSPITObject->getID().c_str(), p_ReportSPITObject->getName().c_str()); + if (mCallbacks.onCheckSpitObjectVeto(isKnownType) == false) { + ESP_LOGW(TAG, "ObjectVeto %s / %s", p_ReportSPITObject.getID().c_str(), p_ReportSPITObject.getName().c_str()); return; } - - ptrSPITObject = new SPITObject(); + auto spitObj = make_unique(p_ReportSPITObject.getID()); + ptrSPITObject = spitObj.get(); + mSpitObjects.addEntry(move(spitObj)); boolNew = true; } else { // The user's app my veto the SPITType - if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) { + if (mCallbacks.onCheckSpitObjectVeto(isKnownType) == false) { // SpitObject exists and User APp denied the SPITObject -> remove the SPITObject without sending a message - SPITObject::removeSPITObject(ptrSPITObject); - ESP_LOGD(TAG, "TypeVeto %s / %s", p_ReportSPITObject->getID().c_str(), p_ReportSPITObject->getName().c_str()); - delete ptrSPITObject; + mSpitObjects.removeEntry(*ptrSPITObject); + ESP_LOGW(TAG, "TypeVeto %s / %s", p_ReportSPITObject.getID().c_str(), p_ReportSPITObject.getName().c_str()); return; } } } else { boolRemote = true; - ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportSPITObject->getID()); - ptrSPITType = SPITType::getSPITTypeRemote(p_ReportSPITObject->getSPITTypeID()); - if (ptrSPITType == NULL) { + ptrSPITObject = mRemoteSpitObjects.getEntry(p_ReportSPITObject.getID()); + ptrSPITType = mRemoteSpitTypes.getEntry(p_ReportSPITObject.getSPITTypeID()); + if (ptrSPITType == nullptr) { // No associated SPITType found return; } - if (ptrSPITObject == NULL) { - ptrSPITObject = new SPITObject(); + if (ptrSPITObject == nullptr) { + auto spitObj = make_unique(p_ReportSPITObject.getID()); + ptrSPITObject = spitObj.get(); + mRemoteSpitObjects.addEntry(move(spitObj)); boolNew = true; } } - try { - boolChanged = ptrSPITObject->setMessageOP(p_ReportSPITObject); - } catch (...) { + if (!ptrSPITObject->setMessageOP(&p_ReportSPITObject)) { + ESP_LOGE(TAG, "Change not allowed"); // setMessageOP error - the SPITObject can't be changed, it may be fixed and crated by this client sendSPITObjectInternal(ptrSPITObject); return; @@ -1200,17 +1057,10 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report if (boolRemote == false) { // set the virtual action assignment ptrSPITObject->setActionAssignedType(ptrSPITType->getActionAssigned()); - SPITObject::addSPITObject(ptrSPITObject); - } else { - SPITObject::addSPITObjectRemote(ptrSPITObject); } auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed; - if (boolRemote) { - mCallbacks.onSpitObjectRemote(eventType, *ptrSPITType, *ptrSPITObject); - } else { - mCallbacks.onSpitObject(eventType, *ptrSPITType, *ptrSPITObject); - } + mCallbacks.onSpitObject(eventType, boolRemote, *ptrSPITType, *ptrSPITObject); if (ptrSPITObject->setConfirmed(true) == true || boolChanged == true) { // Confirmation has changed @@ -1218,65 +1068,48 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject *p_Report } } } -void SPIT_Client::parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject) { - // printf("parse RemoveSPITObject %s\n", p_RemoveSPITObject->getID()); - if (p_RemoveSPITObject == NULL) - return; - bool boolRemote = false; - SPITObject *ptrSPITObject; - SPITType *ptrSPITType; - - { - ptrSPITObject = SPITObject::getSPITObjectRemote(p_RemoveSPITObject->getID()); - if (ptrSPITObject != NULL) { - boolRemote = true; - ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID()); - if (ptrSPITType != NULL) { - if (boolRemote) { - mCallbacks.onSpitObjectRemote(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject); - } else { - mCallbacks.onSpitObject(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject); - } - } else { - // No associated SPITType found - // delete the SPITObject without a notification - } - SPITObject::removeSPITObjectRemote(ptrSPITObject); - delete ptrSPITObject; - } else { - // call removeSPITObject, this will notify the server that the object is removed - removeSPITObject(p_RemoveSPITObject->getID()); +void SPIT_Client::parseRemoveSPITObject(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject) { + // printf("parse RemoveSPITObject %s\n", p_RemoveSPITObject.getID()); + SPITObject *ptrSPITObject = mRemoteSpitObjects.getEntry(p_RemoveSPITObject.getID()); + if (ptrSPITObject != nullptr) { + SPITType *ptrSPITType = mRemoteSpitTypes.getEntry(ptrSPITObject->getSPITTypeID()); + if (ptrSPITType != nullptr) { + mCallbacks.onSpitObject(ObjectEvent::Deleted, true, *ptrSPITType, *ptrSPITObject); } + mRemoteSpitObjects.removeEntry(*ptrSPITObject); + } else { + // call removeSPITObject, this will notify the server that the object is removed + removeSPITObject(p_RemoveSPITObject.getID()); } } int SPIT_Client::sendSPITObjectInternal(SPITObject *ptrSPITObject) { - if (ptrSPITObject == NULL) + if (ptrSPITObject == nullptr) return -1; - SPIT_Message::ReportSPITObject ptrSMReportSPITObject; - ptrSPITObject->fillMessageOP(&ptrSMReportSPITObject); + SPIT_Message::ReportSPITObject sMReportSPITObject; + ptrSPITObject->fillMessageOP(sMReportSPITObject); - return sendSPITMessage(ptrSMReportSPITObject); + return sendSPITMessage(sMReportSPITObject); } /** - * When the client changes an existing SPITObject (normally the client should not do this), then he should send the changes to the SPITServer.
- * An eventSPITObject occurs.
- * The SPITServer may discard the changes and a second eventSPITObject occurs to correct the changes.
- * @param p_SPITObject the pointer to the changed SPITObject.
+ * When the client changes an existing SPITObject (normally the client should not do this), then he should send the changes to the SPITServer. + * An eventSPITObject occurs. + * The SPITServer may discard the changes and a second eventSPITObject occurs to correct the changes. + * @param p_SPITObject the pointer to the changed SPITObject. * CAUTION: The SPITObject must already exist. * @return true = SPITObject is changed, false = not changed, maybe p_SPITObject is NULL or the SPITObject doesn't exists */ bool SPIT_Client::changeSPITObject(SPITObject *p_SPITObject) { - if (p_SPITObject == NULL) + if (p_SPITObject == nullptr) return false; SPITObject *ptrSPITObject; SPITType *ptrSPITType; { - ptrSPITObject = SPITObject::getSPITObject(p_SPITObject->getID()); - if (ptrSPITObject == NULL) + ptrSPITObject = mSpitObjects.getEntry(p_SPITObject->getID()); + if (ptrSPITObject == nullptr) return false; - ptrSPITType = SPITType::getSPITType(p_SPITObject->getID()); - if (ptrSPITObject == NULL) + ptrSPITType = mSpitTypes.getEntry(p_SPITObject->getID()); + if (ptrSPITObject == nullptr) return false; ptrSPITObject->setActionAssigned(p_SPITObject->getActionAssigned()); @@ -1296,18 +1129,18 @@ bool SPIT_Client::changeSPITObject(SPITObject *p_SPITObject) { ptrSPITObject->setValueFactor(p_SPITObject->getValueFactor()); ptrSPITObject->setValueUse(p_SPITObject->getValueUse()); - mCallbacks.onSpitObject(ObjectEvent::Changed, *ptrSPITType, *ptrSPITObject); + mCallbacks.onSpitObject(ObjectEvent::Changed, false, *ptrSPITType, *ptrSPITObject); sendSPITObjectInternal(ptrSPITObject); } return true; } /** - * When the client wants to remove a SPITObject with id == p_SPITObjectID (normally the client should not do this), then he should send it to the SPITServer.
- * The corresponding SPITObject if listet in SPITObject will be deleted.
+ * When the client wants to remove a SPITObject with id == p_SPITObjectID (normally the client should not do this), then he should send it to the SPITServer. + * The corresponding SPITObject if listet in SPITObject will be deleted. * An eventRemoveSPITType will occur. - * If an connection to a SPITServer is established, the SPITServer may discard the deletion and an eventSPITObject occurs
- * -> the SPITObject is listet again.
+ * If an connection to a SPITServer is established, the SPITServer may discard the deletion and an eventSPITObject occurs + * -> the SPITObject is listet again. * @param p_SPITObjectID the id of the SPITObject to remove. * @return 0 = sended to the SPITServer, -1 = not sended to the SPITServer or nos SPITObject with id == p_SPITObjectID exists. */ @@ -1319,16 +1152,15 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) { { SPIT_Message::RemoveSPITObject sMRemoveSPITObject; - ptrSPITObject = SPITObject::getSPITObject(p_SPITObjectID); - if (ptrSPITObject == NULL) + ptrSPITObject = mSpitObjects.getEntry(p_SPITObjectID); + if (ptrSPITObject == nullptr) return -1; - ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID()); - if (ptrSPITType == NULL) + ptrSPITType = mSpitTypes.getEntry(ptrSPITObject->getSPITTypeID()); + if (ptrSPITType == nullptr) return -1; - ptrSPITObject->fillMessageOP(&sMRemoveSPITObject); - mCallbacks.onSpitObject(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject); - SPITObject::removeSPITObject(ptrSPITObject); - delete ptrSPITObject; + ptrSPITObject->fillMessageOP(sMRemoveSPITObject); + mCallbacks.onSpitObject(ObjectEvent::Deleted, false, *ptrSPITType, *ptrSPITObject); + mSpitObjects.removeEntry(*ptrSPITObject); return sendSPITMessage(sMRemoveSPITObject); } return -1; @@ -1336,195 +1168,136 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) { //----- Play SPIT Objects ------ -void SPIT_Client::parsePlaySPITStart(SPIT_Message::PlaySPITStart *p_PlaySPITStart) { - ESP_LOGD(TAG, "parse PlaySPITStart ID: %s Name: %s Running: %d", p_PlaySPITStart->getPlayerID().c_str(), p_PlaySPITStart->getPlayerName().c_str(), (int)p_PlaySPITStart->getPlayerIsRunning()); - SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITStart->getPlayerID()); - if (ptrSPITPlayer == NULL) - return; - ptrSPITPlayer->setIsRunning(p_PlaySPITStart->getPlayerIsRunning()); - ptrSPITPlayer->setName(p_PlaySPITStart->getPlayerName()); - ptrSPITPlayer->setType(p_PlaySPITStart->getPlayerType()); - ptrSPITPlayer->setTime(p_PlaySPITStart->getTime()); - ptrSPITPlayer->startPlaySequence(); +void SPIT_Client::parsePlaySPITStart(SPIT_Message::PlaySPITStart &p_PlaySPITStart) { + ESP_LOGD(TAG, "parse PlaySPITStart ID: %s Name: %s Running: %d", p_PlaySPITStart.getPlayerID().c_str(), p_PlaySPITStart.getPlayerName().c_str(), (int)p_PlaySPITStart.getPlayerIsRunning()); + SPITPlayer &spitPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITStart.getPlayerID()); + spitPlayer.setIsRunning(p_PlaySPITStart.getPlayerIsRunning()); + spitPlayer.setName(p_PlaySPITStart.getPlayerName()); + spitPlayer.setType(p_PlaySPITStart.getPlayerType()); + spitPlayer.setTime(p_PlaySPITStart.getTime()); + spitPlayer.startPlaySequence(); - mCallbacks.onPlay(ptrSPITPlayer->getID(), ptrSPITPlayer->getName(), ptrSPITPlayer->getType(), ptrSPITPlayer->getIsRunning(), ptrSPITPlayer->getTime()); + mCallbacks.onPlay(spitPlayer.getID(), spitPlayer.getName(), spitPlayer.getType(), spitPlayer.getIsRunning(), spitPlayer.getTime()); } -void SPIT_Client::parsePlaySPITObject(SPIT_Message::PlaySPITObject *p_PlaySPITObject) { - SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITObject->getPlayerID()); - if (ptrSPITPlayer == NULL) - return; +void SPIT_Client::parsePlaySPITObject(SPIT_Message::PlaySPITObject &p_PlaySPITObject) { - SPITObject *ptrSPITObject = SPITObject::getSPITObject(p_PlaySPITObject->getSPITObjectID()); - if (ptrSPITObject == NULL) { + SPITPlayer &ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITObject.getPlayerID()); + SPITObject *ptrSPITObject = mSpitObjects.getEntry(p_PlaySPITObject.getSPITObjectID()); + + if (ptrSPITObject == nullptr) { return; } - SPITPlayer::PlaySPITType *ptrPlaySPITType = ptrSPITPlayer->addSPITType_Playing(ptrSPITObject->getSPITTypeID()); - if (ptrPlaySPITType == NULL) { + SPITPlayer::PlaySPITType *ptrPlaySPITType = ptrSPITPlayer.addSPITType_Playing(ptrSPITObject->getSPITTypeID()); + if (ptrPlaySPITType == nullptr) { return; } - ptrPlaySPITType->setPlayerIsRunning(ptrSPITPlayer->getIsRunning()); - ptrPlaySPITType->addValue(((double)p_PlaySPITObject->getValue() / 1000000), ((double)ptrSPITObject->getValueFactor() / 1000000)); + ptrPlaySPITType->setPlayerIsRunning(ptrSPITPlayer.getIsRunning()); + ptrPlaySPITType->addValue(((double)p_PlaySPITObject.getValue() / 1000000), ((double)ptrSPITObject->getValueFactor() / 1000000)); } -void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd *p_PlaySPITEnd) { - SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID()); - if (ptrSPITPlayer == NULL) - return; - // unordered_map* ptrPlayObjects; - // bool boolStarted; - // bool boolStopped; +void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd &p_PlaySPITEnd) { + SPITPlayer &ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd.getPlayerID()); - // SPITPlayer::PlaySPITType* ptrPlayObject = ptrSPITPlayer->getPlayObjects(); - // for (auto i = ptrPlayObjects->begin(); i != ptrPlayObjects->end(); i++) { - // ptrPlayObject = i->second; - // boolStarted = false; - // boolStopped = false; - // if (ptrPlayObject->getIsNew()) { - // boolStarted = true; - // } - // if (ptrPlayObject->getIsPlayed() == false) { - // boolStopped = true; - // } - // { - // ptrSPITObject = SPITObject::getSPITObject(ptrPlayObject->getSPITObjectID()); - // if (ptrSPITObject == NULL) { - // return; - // } - // SPITType *ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID()); - // if (ptrSPITType == NULL) { - // return; - // } - - // mCallbacks.onPlaySpitType(ptrPlayObject->getPlayerID(), boolStarted, boolStopped, *ptrSPITType, *ptrSPITObject, *ptrPlayObject); - // } - // } - // ptrSPITPlayer->endPlaySequence(); - - // SPITPlayer *ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID()); - // if (ptrSPITPlayer == NULL) - // return; - - unordered_map *ptrPlaySPITTypes = ptrSPITPlayer->getPlaySPITTypes(); - for (auto i = ptrPlaySPITTypes->begin(); i != ptrPlaySPITTypes->end(); i++) { - SPITPlayer::PlaySPITType *ptrPlaySPITType = i->second; - bool boolStarted = false; - bool boolStopped = false; - if (ptrPlaySPITType->getIsNew()) { - boolStarted = true; - } - if (ptrPlaySPITType->getIsPlayed() == false) { - boolStopped = true; - } - { - SPITType *ptrSPITType = SPITType::getSPITType(ptrPlaySPITType->getSPITTypeID()); - if (ptrSPITType == NULL) { - // set isplayed to false, the ptrPlayObject will be removed by ptrSPITPlayer->endPlaySequence() - ptrPlaySPITType->setIsPlayed(false); - continue; - } - mCallbacks.onPlaySpitType(ptrPlaySPITType->getPlayerID(), ptrPlaySPITType->getSPITTypeID(), ptrPlaySPITType->getPlayerIsRunning(), boolStarted, boolStopped, ptrPlaySPITType->getValue()); + auto &ptrPlaySPITTypes = ptrSPITPlayer.getPlaySPITTypes(); + for (auto i = ptrPlaySPITTypes.begin(); i != ptrPlaySPITTypes.end(); i++) { + SPITPlayer::PlaySPITType *ptrPlaySPITType = i->second.get(); + bool boolStarted = ptrPlaySPITType->getIsNew(); + bool boolStopped = (ptrPlaySPITType->getIsPlayed() == false); + SPITType *ptrSPITType = mSpitTypes.getEntry(ptrPlaySPITType->getSPITTypeID()); + if (ptrSPITType == nullptr) { + // set isplayed to false, the ptrPlayObject will be removed by ptrSPITPlayer.endPlaySequence() + ptrPlaySPITType->setIsPlayed(false); + continue; } + mCallbacks.onPlaySpitType(ptrPlaySPITType->getPlayerID(), ptrPlaySPITType->getSPITTypeID(), ptrPlaySPITType->getPlayerIsRunning(), boolStarted, boolStopped, ptrPlaySPITType->getValue()); } - ptrSPITPlayer->endPlaySequence(); + ptrSPITPlayer.endPlaySequence(); } -void SPIT_Client::parseReportPlayStatus(SPIT_Message::ReportPlayStatus *p_ReportPlayStatus) { - ESP_LOGD(TAG, "parseReportPlayStatus"); +void SPIT_Client::parseReportPlayStatus(SPIT_Message::ReportPlayStatus &p_ReportPlayStatus) { SPITType *ptrSPITType = NULL; - { - SPITObject *ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportPlayStatus->getID()); - if (ptrSPITObject == NULL) { - ptrSPITObject = SPITObject::getSPITObject(p_ReportPlayStatus->getID()); - if (ptrSPITObject == NULL) { - return; - } - } - if (ptrSPITObject->getServerRemote() == false) { - ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID()); - } else { - ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID()); - } - - if (ptrSPITType == NULL) { + SPITObject *ptrSPITObject = mRemoteSpitObjects.getEntry(p_ReportPlayStatus.getID()); + if (ptrSPITObject == nullptr) { + ptrSPITObject = mSpitObjects.getEntry(p_ReportPlayStatus.getID()); + if (ptrSPITObject == nullptr) { return; } - mCallbacks.onPlayRemoteObjectStatus(*ptrSPITType, *ptrSPITObject, p_ReportPlayStatus->getFrameInsideObject(), p_ReportPlayStatus->getValue()); } + if (ptrSPITObject->getServerRemote() == false) { + ptrSPITType = mSpitTypes.getEntry(ptrSPITObject->getSPITTypeID()); + } else { + ptrSPITType = mRemoteSpitTypes.getEntry(ptrSPITObject->getSPITTypeID()); + } + + if (ptrSPITType == nullptr) { + return; + } + mCallbacks.onPlayRemoteObjectStatus(*ptrSPITType, *ptrSPITObject, p_ReportPlayStatus.getFrameInsideObject(), p_ReportPlayStatus.getValue()); } //--------- Remote ---------- /** - * Send a remote control command to the SPITServer.
+ * Send a remote control command to the SPITServer. * There may be different command types: * a) Some don't use value e.g. go to next scene, olay a jingle * b) Some use values e.g. the main sound fader * @param p_SPITObjectID the id of the remote SPITObject (this represents the remote control command) - * @param p_Valueppm the value in ppm
- * in case a) the value is ignored
+ * @param p_Valueppm the value in ppm + * in case a) the value is ignored * in case b) the value is used - * @param p_ValueFlag indicates how the server should use p_Valueppm:
- * VALUEFLAG_DIRECT (0x00) The server overwrites its existing value with p_Value
+ * @param p_ValueFlag indicates how the server should use p_Valueppm: + * VALUEFLAG_DIRECT (0x00) The server overwrites its existing value with p_Value * VALUEFLAG_INCREASE (0x01) The server increases his existing value by p_Valueppm * VALUEFLAG_DECREASE (0x01) The server decreases his existing value by p_Valueppm */ void SPIT_Client::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p_ValueFlag) { - SPITObject *ptrRemoteSPITObject; - { - ptrRemoteSPITObject = SPITObject::getSPITObjectRemote(p_SPITObjectID); - if (ptrRemoteSPITObject == NULL) - return; + SPITObject *ptrRemoteSPITObject = mRemoteSpitObjects.getEntry(p_SPITObjectID); + if (ptrRemoteSPITObject == nullptr) + return; - SPIT_Message::PlaySPITStart playSPITStart; - playSPITStart.setPlayerID(m_ID); - playSPITStart.setPlayerName(m_ProjName); - playSPITStart.setPlayerIsRunning(false); - playSPITStart.setPlayerType(PLAYERTYPE_DISCRETE); - playSPITStart.setTime(0); - sendSPITMessage(playSPITStart); + SPIT_Message::PlaySPITStart playSPITStart(m_ID, m_ProjName, PLAYERTYPE_DISCRETE); + playSPITStart.setPlayerIsRunning(false); + playSPITStart.setTime(0); + sendSPITMessage(playSPITStart); - SPIT_Message::PlaySPITObject playSPITObject; - playSPITObject.setID(ptrRemoteSPITObject->getID()); - playSPITObject.setPlayPrePosition(false); - playSPITObject.setPlayerID(m_ID); - playSPITObject.setValue(p_Valueppm); - playSPITObject.setValueFlag(p_ValueFlag); - sendSPITMessage(playSPITObject); + SPIT_Message::PlaySPITObject playSPITObject; + playSPITObject.setID(ptrRemoteSPITObject->getID()); + playSPITObject.setPlayPrePosition(false); + playSPITObject.setPlayerID(m_ID); + playSPITObject.setValue(p_Valueppm); + playSPITObject.setValueFlag(p_ValueFlag); + sendSPITMessage(playSPITObject); - SPIT_Message::PlaySPITEnd playSPITEnd; - playSPITEnd.setPlayerID(m_ID); - sendSPITMessage(playSPITEnd); - } + SPIT_Message::PlaySPITEnd playSPITEnd(m_ID); + sendSPITMessage(playSPITEnd); } fos::Semaphore SPIT_Client::sStartSad; +unordered_map> SAD_DetectedServer::sKnownServers; void SPIT_Client::processSocketTask(SPIT_Client &instance) { ESP_LOGI(TAG, "Starting Socket managing"); - static const string SERVERAUTODETECT_PRECODE = "#SAD#"; static const string SERVERAUTODETECT_SEPERATOR = "#,#"; static const string SERVERAUTODETECT_TASKID = "#spit#"; // -> "#SAD##,##spit#" static const string SERVERAUTODETECT_PORT = "15110"; static constexpr int WATCHDOGTIME = 3000; - string stringDatagram = SERVERAUTODETECT_PRECODE + SERVERAUTODETECT_SEPERATOR + SERVERAUTODETECT_TASKID; - int intDatagramLength = stringDatagram.length(); - string stringPart; - string stringParts[10]; - while (true) { sStartSad.take(); bool searching = true; instance.mSPITSocket->setBroadcast(true); + string stringDatagram = SERVERAUTODETECT_PRECODE + SERVERAUTODETECT_SEPERATOR + SERVERAUTODETECT_TASKID; + int intDatagramLength = stringDatagram.length(); while (searching) { - if (instance.abortSearch) + if (instance.mAbortSearch) break; - SAD_DetectedServer::cycleStart(); + SAD_DetectedServer::resetServerFlags(); string stringBroadcastIP4 = instance.mSPITSocket->mOwnIp.getBroadcastIP4(); - instance.mSPITSocket->sendMessageTo(SPITSocket::FAMILY_IP4, stringBroadcastIP4, SERVERAUTODETECT_PORT, stringDatagram.data(), intDatagramLength); + instance.mSPITSocket->sendMessageTo(stringBroadcastIP4, SERVERAUTODETECT_PORT, stringDatagram.data(), intDatagramLength); { // wait for 3000 milliseconds or fos::Task::delayMs(3000); @@ -1532,29 +1305,27 @@ void SPIT_Client::processSocketTask(SPIT_Client &instance) { bool receiving = true; while (receiving) { - if (instance.abortSearch) + if (instance.mAbortSearch) { break; - - char buffer[512 + 1]; + } + constexpr int SIZE = 512; + char buffer[SIZE + 1]; string stringServerIP; - int intReceivedByteCount = instance.mSPITSocket->receiveMessage(SPITSocket::FAMILY_IP4, buffer, 512, &stringServerIP); + int intReceivedByteCount = instance.mSPITSocket->receiveMessage(buffer, SIZE, &stringServerIP); if (intReceivedByteCount <= 0) { break; } - - // add null chararcter - if (intReceivedByteCount < 512) { - buffer[intReceivedByteCount] = '\0'; - } else { - buffer[512] = '\0'; - } + buffer[intReceivedByteCount] = '\0'; string stringMessage = buffer; // Check if precode is ok if (stringMessage.find(SERVERAUTODETECT_PRECODE.data(), 0) != 0) { - return; + break; } int intIndex = 0; int intOldPos = 0; + string stringPart; + string strParts[10]; + while (intIndex < SAD_DetectedServer::PARAMINDEX_IP) { int intPos = stringMessage.find(SERVERAUTODETECT_SEPERATOR.data(), intOldPos); if (intPos == string::npos) { @@ -1563,17 +1334,27 @@ void SPIT_Client::processSocketTask(SPIT_Client &instance) { stringPart = stringMessage.substr(intOldPos, intPos - intOldPos); intOldPos = intPos + SERVERAUTODETECT_SEPERATOR.length(); } - stringParts[intIndex] = stringPart; + strParts[intIndex] = stringPart; intIndex++; } - stringParts[SAD_DetectedServer::PARAMINDEX_IP] = stringServerIP; - SAD_DetectedServer::addDetectedServer(stringParts[SAD_DetectedServer::PARAMINDEX_ID], stringParts); + + auto server = make_unique( + strParts[SAD_DetectedServer::PARAMINDEX_NAME], + strParts[SAD_DetectedServer::PARAMINDEX_ID], + strParts[SAD_DetectedServer::PARAMINDEX_COMPUTERNAME], + stringServerIP, + strParts[SAD_DetectedServer::PARAMINDEX_PORT], + strParts[SAD_DetectedServer::PARAMINDEX_CLIENTIP], + strParts[SAD_DetectedServer::PARAMINDEX_ADDITIONS], + strParts[SAD_DetectedServer::PARAMINDEX_SERVERPROJECTNAME]); + + SAD_DetectedServer::addDetectedServer(move(server)); } fos::Task::delayMs(100); - SAD_DetectedServer::cycleEnd(instance); + SAD_DetectedServer::evaluateDetectedServers(instance); - instance.abortSearch = false; - // if(instance.m_ConnectionStatus == CONNECTION_OK) break; + instance.mAbortSearch = false; + // if(instance.m_ConnectionStatus == Connection::Ok) break; fos::Task::delayMs(1000); } instance.mSPITSocket->setBroadcast(false); diff --git a/components/spit/src/SPIT_Message.cpp b/components/spit/src/SPIT_Message.cpp index b88d531..437927b 100644 --- a/components/spit/src/SPIT_Message.cpp +++ b/components/spit/src/SPIT_Message.cpp @@ -16,217 +16,151 @@ #include "SPIT_Message.h" -SPIT_Message::SPIT_Message() { - initMembers(); -} +#include "esp_log.h" +#include + +const char *TAG = "SpitMsg"; + //---------- Receive --------- -SPIT_Message::SPIT_Message(char *p_MessageBytes, int p_MessageByteCount) { - initMembers(); - m_MessageBytes = p_MessageBytes; - if (m_MessageBytes == NULL) { - m_MessageByteCount = 0; +SPIT_Message::SPIT_Message(std::vector message) { + if (message.empty()) { + ESP_LOGE(TAG, "message is emtpy, nothing to parse"); return; } - m_MessageByteCount = p_MessageByteCount; - if (parse() == NULL) { - } -} -SPIT_Message::~SPIT_Message() { - delete m_OPPart; - if (m_MessageBytesCreated && m_MessageBytes != NULL) { - free(m_MessageBytes); + if (!parse(message)) { + ESP_LOGE(TAG, "Failed ot parse message"); + return; } } -void SPIT_Message::initMembers() { - m_MessageBytes = NULL; - m_MessageByteCount = 0; - m_Header = NULL; - m_OPPart = NULL; - m_MessageBytesCreated = false; -} - // Receive -SPIT_Message::OPPart *SPIT_Message::parse() { - if (m_MessageBytes == NULL) - return NULL; - m_OPPart = NULL; - m_MessageBytesCreated = false; +bool SPIT_Message::parse(std::vector message) { // parse Header - m_Header = new Header(); - if (m_Header->parse(m_MessageBytes, m_MessageByteCount) == false) { - m_Header = NULL; - m_OPPart = NULL; - return NULL; + auto header = make_unique
(); + if (!header->parse(message)) { + return false; } // parse OP - switch (m_Header->getOPFlag()) { + switch (header->getOPFlag()) { // Connection case SPIT_Message::Connect::OPFLAG: { - m_OPPart = new Connect(m_Header); + m_OPPart = make_unique(move(header)); } break; case SPIT_Message::ConnectAnswer::OPFLAG: { - m_OPPart = new ConnectAnswer(m_Header); + m_OPPart = make_unique(move(header)); } break; case Disconnect::OPFLAG: { - m_OPPart = new Disconnect(m_Header); + m_OPPart = make_unique(move(header)); } break; case Watchdog::OPFLAG: { - m_OPPart = new Watchdog(m_Header); + m_OPPart = make_unique(move(header)); } break; case WatchdogAnswer::OPFLAG: { - m_OPPart = new WatchdogAnswer(m_Header); + m_OPPart = make_unique(move(header)); } break; - // SPITProject case ReportSPITProject::OPFLAG: { - m_OPPart = new ReportSPITProject(m_Header); + m_OPPart = make_unique(move(header)); } break; case CloseSPITProject::OPFLAG: { - m_OPPart = new CloseSPITProject(m_Header); + m_OPPart = make_unique(move(header)); } break; case RequestProjectTransfer::OPFLAG: { - m_OPPart = new RequestProjectTransfer(m_Header); + m_OPPart = make_unique(move(header)); } break; case StartProjectTransfer::OPFLAG: { - m_OPPart = new StartProjectTransfer(m_Header); + m_OPPart = make_unique(move(header)); } break; case EndProjectTransfer::OPFLAG: { - m_OPPart = new EndProjectTransfer(m_Header); + m_OPPart = make_unique(move(header)); } break; - // SPITType case ReportSPITType::OPFLAG: { - m_OPPart = new ReportSPITType(m_Header); + m_OPPart = make_unique(move(header)); } break; case RemoveSPITType::OPFLAG: { - m_OPPart = new RemoveSPITType(m_Header); + m_OPPart = make_unique(move(header)); } break; - // SPITObject case ReportSPITObject::OPFLAG: { - m_OPPart = new ReportSPITObject(m_Header); + m_OPPart = make_unique(move(header)); } break; case RemoveSPITObject::OPFLAG: { - m_OPPart = new RemoveSPITObject(m_Header); + m_OPPart = make_unique(move(header)); } break; // PlaySPITObjects case PlaySPITStart::OPFLAG: { - m_OPPart = new PlaySPITStart(m_Header); + m_OPPart = make_unique(move(header)); } break; case PlaySPITObject::OPFLAG: { - m_OPPart = new PlaySPITObject(m_Header); + m_OPPart = make_unique(move(header)); } break; case PlaySPITEnd::OPFLAG: { - m_OPPart = new PlaySPITEnd(m_Header); + m_OPPart = make_unique(move(header)); } break; case ReportPlayStatus::OPFLAG: { - m_OPPart = new ReportPlayStatus(m_Header); + m_OPPart = make_unique(move(header)); } break; default: - m_OPPart = NULL; - break; + return false; } - if (m_OPPart != NULL) { - if (m_OPPart->parse(m_MessageBytes, m_MessageByteCount) == false) { - delete m_OPPart; - m_Header = NULL; - m_OPPart = NULL; - return NULL; - } - } - return m_OPPart; + + return m_OPPart->parse(message); } //---------- Send ---------- -SPIT_Message::SPIT_Message(OPPart *p_OPPart) { - initMembers(); - if (p_OPPart == NULL) - return; - m_OPPart = p_OPPart; - m_Header = m_OPPart->getHeader(); - if (m_Header == NULL) { - m_OPPart = NULL; - return; +std::vector SPIT_Message::createMessage(OPPart &p_OPPart) { + if (!p_OPPart.getHeader()) { + return {}; } -} -bool SPIT_Message::fillBytes() { - if (m_OPPart == NULL) - return false; + try { - if (m_MessageBytes == NULL) - m_MessageBytes = createByteArray(m_OPPart, &m_MessageByteCount); - if (m_MessageBytes == NULL) - return false; - m_MessageBytesCreated = true; - return m_OPPart->fillBytes(m_MessageBytes, m_MessageByteCount); + int totalSize = Header::BYTESLENGTH + p_OPPart.getBytesCount(); + std::vector msgByts(totalSize); + p_OPPart.fillBytes(msgByts); + return msgByts; } catch (...) { - return false; + ESP_LOGE(TAG, "Failed to allocate memory"); } - return true; -} -const char *SPIT_Message::getMessageBytes() { - if (m_OPPart == NULL) - return NULL; - if (fillBytes() == false) - return NULL; - return m_MessageBytes; + return {}; } //----------- Header ----------- -SPIT_Message::Header::~Header() { -} SPIT_Message::Header::Header(const Header &orig) { - initMembers(); + m_SPITID = &SPITID[0]; m_MessageNumber = orig.getMessageNumber(); m_ServerID = orig.getServerID(); m_ClientID = orig.getClientID(); } -// Receive + SPIT_Message::Header::Header() { - initMembers(); -} - -void SPIT_Message::Header::initMembers() { m_SPITID = &SPITID[0]; - m_SPITVersion = SPITVERSION; - m_MessageNumber = 0; - m_BytesCount = BYTESLENGTH; - m_ServerID = ""; - m_ClientID = ""; } -bool SPIT_Message::Header::parse(char *p_MessageBytes, int p_MessageBytesLength) { - if (p_MessageBytes == NULL) - return false; - string stringSPIT_ID; +bool SPIT_Message::Header::parse(const std::vector &message) { try { m_ParseOffset = 0; - // SPIT ID - stringSPIT_ID = getString(p_MessageBytes, p_MessageBytesLength, m_ParseOffset, 7); - m_ParseOffset += 7; - if (SPITID != stringSPIT_ID) + auto strID = getString(message, m_ParseOffset, 7).value(); + if (strID != SPITID) { return false; - m_SPITVersion = getInt(p_MessageBytes, p_MessageBytesLength, m_ParseOffset); - if (m_SPITVersion < 0) + } + auto iVer = getInt(message, m_ParseOffset).value(); + if (iVer < 0) { return false; - m_ParseOffset += 4; - m_MessageNumber = getByte(p_MessageBytes, p_MessageBytesLength, m_ParseOffset); - m_ParseOffset += 1; - m_BytesCount = getInt(p_MessageBytes, p_MessageBytesLength, m_ParseOffset); - if (m_BytesCount < 0) + } + m_MessageNumber = getByte(message, m_ParseOffset).value(); + m_BytesCount = getInt(message, m_ParseOffset).value(); + if (m_BytesCount < 0) { return false; - m_ParseOffset += 4; - m_ServerID = getString(p_MessageBytes, p_MessageBytesLength, m_ParseOffset, 41); - m_ParseOffset += 41; - m_ClientID = getString(p_MessageBytes, p_MessageBytesLength, m_ParseOffset, 41); - m_ParseOffset += 41; - m_OPFlag = p_MessageBytes[m_ParseOffset] & 0xFF; - m_ParseOffset += 1; + } + m_ServerID = getString(message, m_ParseOffset, 41).value(); + m_ClientID = getString(message, m_ParseOffset, 41).value(); + m_OPFlag = message[m_ParseOffset++] & 0xFF; } catch (...) { + ESP_LOGE(TAG, "failed to parse Header"); return false; } return true; @@ -234,181 +168,111 @@ bool SPIT_Message::Header::parse(char *p_MessageBytes, int p_MessageBytesLength) // Send SPIT_Message::Header::Header(int p_SPITVersion, int p_OPFlag) { - initMembers(); + m_SPITID = &SPITID[0]; m_SPITVersion = p_SPITVersion; m_OPFlag = p_OPFlag; } -void SPIT_Message::Header::setMessageNumber(unsigned char p_MessageNumber) { - m_MessageNumber = p_MessageNumber; -} - -void SPIT_Message::Header::setServerID(string p_ID) { - m_ServerID = p_ID; -} -void SPIT_Message::Header::setClientID(string p_ID) { - m_ClientID = p_ID; -} -void SPIT_Message::Header::setOPFlag(int p_OPFlag) { - m_OPFlag = p_OPFlag; -} -bool SPIT_Message::Header::fillBytes(char *p_Bytes, int p_ByteCount) { - if (p_Bytes == NULL) - return false; +bool SPIT_Message::Header::fillBytes(std::vector &message) { try { m_ParseOffset = 0; - m_ParseOffset += setString(m_SPITID, p_Bytes, p_ByteCount, m_ParseOffset, 7); - m_ParseOffset += setInt(SPITVERSION, p_Bytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setByte(m_MessageNumber, p_Bytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setInt(m_BytesCount, p_Bytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_ServerID, p_Bytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setString(m_ClientID, p_Bytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setByte(m_OPFlag, p_Bytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setString(m_SPITID, message, m_ParseOffset, 7); + m_ParseOffset += setInt(SPITVERSION, message, m_ParseOffset); + m_ParseOffset += setByte(m_MessageNumber, message, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_ServerID, message, m_ParseOffset, 41); + m_ParseOffset += setString(m_ClientID, message, m_ParseOffset, 41); + m_ParseOffset += setByte(m_OPFlag, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create Header"); return false; } return true; } //----------- OPPart ----------- + SPIT_Message::OPPart::~OPPart() { - if (m_Header != NULL) { - delete m_Header; - } - m_Header = NULL; -} -void SPIT_Message::OPPart::initMembers() { - m_Header = NULL; - m_ParseOffset = 0; - m_BytesCount = 0; } // Receive -SPIT_Message::OPPart::OPPart(Header *p_Header, int p_OPFlag) { - initMembers(); - m_Header = p_Header; - if (m_Header != NULL) { +SPIT_Message::OPPart::OPPart(unique_ptr
p_Header, int p_OPFlag, int size) + : m_Header(move(p_Header)), + m_BytesCount(size) { + if (!m_Header) { m_ParseOffset = Header::BYTESLENGTH; m_Header->setOPFlag(p_OPFlag); } } -void SPIT_Message::OPPart::setHeader(Header *p_Header) { - m_Header = p_Header; - if (m_Header != NULL) { - m_ParseOffset = Header::BYTESLENGTH; - } +void SPIT_Message::OPPart::setHeader(int opFlag) { + m_Header = make_unique
(SPITVERSION, opFlag); + m_ParseOffset = Header::BYTESLENGTH; } // Send -SPIT_Message::OPPart::OPPart() { - initMembers(); -} +SPIT_Message::OPPart::OPPart(int size) + : m_BytesCount(size) {} //--------------------------- Connection -------------------------------- - //----------- Connect ----------- -SPIT_Message::Connect::~Connect() { -} -/* SPIT_Message::Connect::Connect(const Connect& orig) : OPPart(new Header(*orig.getHeader()), OPFLAG) { - initMembers(); - if (orig.getHeader() == NULL) return; - m_ClientComputerName = stringCopy(orig.getClientComputerName()); - m_ClientName = stringCopy(orig.getClientName()); - m_LoginName = stringCopy(orig.getLoginName()); - m_LoginPassword = stringCopy(orig.getLoginPassword()); - m_ServerIP = stringCopy(orig.getServerIP()); - m_ServerPort = orig.getServerPort(); - } -*/ // Receive -SPIT_Message::Connect::Connect(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::Connect::Connect(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -void SPIT_Message::Connect::initMembers() { - m_ClientComputerName = ""; - m_ClientName = ""; - m_LoginName = ""; - m_LoginPassword = ""; - m_ServerIP = ""; - m_ServerPort = 0; - m_BytesCount = BYTESLENGTH; -} - -bool SPIT_Message::Connect::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::Connect::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_ClientComputerName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_ClientName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_LoginName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_LoginPassword = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_ServerIP = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 40); - m_ParseOffset += 40; - m_ServerPort = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_ClientComputerName = getString(message, m_ParseOffset, 64).value(); + m_ClientName = getString(message, m_ParseOffset, 64).value(); + m_LoginName = getString(message, m_ParseOffset, 64).value(); + m_LoginPassword = getString(message, m_ParseOffset, 64).value(); + m_ServerIP = getString(message, m_ParseOffset, 40).value(); + m_ServerPort = getInt(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse Connect message"); return false; } return true; } // Send -SPIT_Message::Connect::Connect() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::Connect::Connect(string p_ComputerName, string p_ClientName) + : OPPart(BYTESLENGTH), + m_ClientComputerName(p_ComputerName), + m_ClientName(p_ClientName) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::Connect::setClientComputerName(string p_ComputerName) { - m_ClientComputerName = p_ComputerName; -} -void SPIT_Message::Connect::setClientName(string p_ClientName) { - m_ClientName = p_ClientName; -} -void SPIT_Message::Connect::setLoginName(string p_LoginName) { - m_LoginName = p_LoginName; -} -void SPIT_Message::Connect::setLoginPassword(string p_LoginPassword) { - m_LoginPassword = p_LoginPassword; -} -void SPIT_Message::Connect::setServerIP(string p_ServerIP) { - m_ServerIP = p_ServerIP; -} void SPIT_Message::Connect::setServerPort(int p_ServerPort) { if (p_ServerPort < 0 || p_ServerPort > 65535) p_ServerPort = 0; m_ServerPort = p_ServerPort; } -bool SPIT_Message::Connect::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::Connect::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_ClientComputerName, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setString(m_ClientName, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setString(m_LoginName, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setString(m_LoginPassword, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setString(m_ServerIP, p_MessageBytes, p_ByteCount, m_ParseOffset, 40); - m_ParseOffset += setInt(m_ServerPort, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_ClientComputerName, message, m_ParseOffset, 64); + m_ParseOffset += setString(m_ClientName, message, m_ParseOffset, 64); + m_ParseOffset += setString(m_LoginName, message, m_ParseOffset, 64); + m_ParseOffset += setString(m_LoginPassword, message, m_ParseOffset, 64); + m_ParseOffset += setString(m_ServerIP, message, m_ParseOffset, 40); + m_ParseOffset += setInt(m_ServerPort, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create Connect message"); return false; } return true; @@ -416,83 +280,56 @@ bool SPIT_Message::Connect::fillBytes(char *p_MessageBytes, int p_ByteCount) { //----------- ConnectAnswer ----------- -void SPIT_Message::ConnectAnswer::initMembers() { - m_ServerComputerName = ""; - m_ServerName = ""; - m_Connected = false; - m_BytesCount = BYTESLENGTH; - m_StepTime = 40; -} -SPIT_Message::ConnectAnswer::~ConnectAnswer() { -} -SPIT_Message::ConnectAnswer::ConnectAnswer(const ConnectAnswer &orig) { -} // Receive -SPIT_Message::ConnectAnswer::ConnectAnswer(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); -} -bool SPIT_Message::ConnectAnswer::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +SPIT_Message::ConnectAnswer::ConnectAnswer(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {} +bool SPIT_Message::ConnectAnswer::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_ServerComputerName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_ServerName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_StepTime = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_Connected = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_ServerComputerName = getString(message, m_ParseOffset, 64).value(); + m_ServerName = getString(message, m_ParseOffset, 64).value(); + m_StepTime = getInt(message, m_ParseOffset).value(); + m_Connected = getBoolean(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse ConnectAnswer message"); return false; } return true; } // Send -SPIT_Message::ConnectAnswer::ConnectAnswer() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::ConnectAnswer::ConnectAnswer() + : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::ConnectAnswer::setServerComputerName(string p_ServerComputerName) { - m_ServerComputerName = p_ServerComputerName; -} -void SPIT_Message::ConnectAnswer::setServerName(string p_ServerName) { - m_ServerName = p_ServerName; -} -void SPIT_Message::ConnectAnswer::setConnected(bool p_Connected) { - m_Connected = p_Connected; -} void SPIT_Message::ConnectAnswer::setStepTime(int p_StepTime_ms) { if (p_StepTime_ms < 0) p_StepTime_ms = 1; m_StepTime = p_StepTime_ms; } -bool SPIT_Message::ConnectAnswer::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::ConnectAnswer::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_ServerComputerName, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setString(m_ServerName, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setInt(m_StepTime, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setBoolean(m_Connected, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_ServerComputerName, message, m_ParseOffset, 64); + m_ParseOffset += setString(m_ServerName, message, m_ParseOffset, 64); + m_ParseOffset += setInt(m_StepTime, message, m_ParseOffset); + m_ParseOffset += setBoolean(m_Connected, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create ConnectAnswer message"); return false; } return true; @@ -500,105 +337,86 @@ bool SPIT_Message::ConnectAnswer::fillBytes(char *p_MessageBytes, int p_ByteCoun //----------- Disconnect ----------- -void SPIT_Message::Disconnect::initMembers() { - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::Disconnect::~Disconnect() { -} // Receive -SPIT_Message::Disconnect::Disconnect(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::Disconnect::Disconnect(unique_ptr
p_Header) : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::Disconnect::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::Disconnect::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_BytesCount = getInt(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse Disconnect message"); return false; } return true; } // Send -SPIT_Message::Disconnect::Disconnect() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::Disconnect::Disconnect() + : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); } -bool SPIT_Message::Disconnect::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::Disconnect::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create Disconnect message"); return false; } return true; } //----------- Watchdog ----------- -void SPIT_Message::Watchdog::initMembers() { - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::Watchdog::~Watchdog() { -} - // Receive -SPIT_Message::Watchdog::Watchdog(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::Watchdog::Watchdog(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::Watchdog::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::Watchdog::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_BytesCount = getInt(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse Watchdog message"); return false; } return true; } // Send -SPIT_Message::Watchdog::Watchdog() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::Watchdog::Watchdog() : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -bool SPIT_Message::Watchdog::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::Watchdog::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create Watchdog message"); return false; } return true; @@ -606,53 +424,42 @@ bool SPIT_Message::Watchdog::fillBytes(char *p_MessageBytes, int p_ByteCount) { //----------- WatchdogAnswer ----------- -void SPIT_Message::WatchdogAnswer::initMembers() { - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::WatchdogAnswer::~WatchdogAnswer() { -} - // Receive -SPIT_Message::WatchdogAnswer::WatchdogAnswer(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::WatchdogAnswer::WatchdogAnswer(unique_ptr
p_Header) : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::WatchdogAnswer::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::WatchdogAnswer::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_BytesCount = getInt(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse WatchdogAnswer message"); return false; } return true; } // Send -SPIT_Message::WatchdogAnswer::WatchdogAnswer() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::WatchdogAnswer::WatchdogAnswer() : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -bool SPIT_Message::WatchdogAnswer::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::WatchdogAnswer::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create WatchdogAnswer message"); return false; } return true; @@ -661,72 +468,52 @@ bool SPIT_Message::WatchdogAnswer::fillBytes(char *p_MessageBytes, int p_ByteCou //--------------------------- SPITProject -------------------------------- //----------- ReportSPITProject ----------- -void SPIT_Message::ReportSPITProject::initMembers() { - m_ProjectID = ""; - m_ProjectName = ""; - m_BytesCount = BYTESLENGTH; - m_FramesPerSecond = 1000; -} -SPIT_Message::ReportSPITProject::~ReportSPITProject() { -} // Receive -SPIT_Message::ReportSPITProject::ReportSPITProject(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::ReportSPITProject::ReportSPITProject(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::ReportSPITProject::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::ReportSPITProject::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_ProjectID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; - m_ProjectName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_FramesPerSecond = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_ProjectID = getString(message, m_ParseOffset, 41).value(); + m_ProjectName = getString(message, m_ParseOffset, 64).value(); + m_FramesPerSecond = getInt(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse ReportSPITProject message"); return false; } return true; } // Send -SPIT_Message::ReportSPITProject::ReportSPITProject() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::ReportSPITProject::ReportSPITProject(string p_ProjectID, string p_ProjectName) + : OPPart(BYTESLENGTH), + m_ProjectID(p_ProjectID), + m_ProjectName(p_ProjectName) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::ReportSPITProject::setProjectID(string p_ProjectID) { - m_ProjectID = p_ProjectID; -} -void SPIT_Message::ReportSPITProject::setProjectName(string p_ProjectName) { - m_ProjectName = p_ProjectName; -} -void SPIT_Message::ReportSPITProject::setFramesPerSecond(const int p_FramesPerSecond) { - m_FramesPerSecond = p_FramesPerSecond; -} -bool SPIT_Message::ReportSPITProject::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::ReportSPITProject::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_ProjectID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setString(m_ProjectName, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setInt(m_FramesPerSecond, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_ProjectID, message, m_ParseOffset, 41); + m_ParseOffset += setString(m_ProjectName, message, m_ParseOffset, 64); + m_ParseOffset += setInt(m_FramesPerSecond, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create ReportSPITProject message"); return false; } return true; @@ -734,58 +521,47 @@ bool SPIT_Message::ReportSPITProject::fillBytes(char *p_MessageBytes, int p_Byte //----------- StartProjectTransfer ----------- -void SPIT_Message::CloseSPITProject::initMembers() { - m_ProjectID = ""; - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::CloseSPITProject::~CloseSPITProject() { -} // Receive -SPIT_Message::CloseSPITProject::CloseSPITProject(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::CloseSPITProject::CloseSPITProject(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::CloseSPITProject::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::CloseSPITProject::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_ProjectID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_ProjectID = getString(message, m_ParseOffset, 41).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse CloseSPITProject message"); return false; } return true; } // Send -SPIT_Message::CloseSPITProject::CloseSPITProject() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::CloseSPITProject::CloseSPITProject(string projectID) + : OPPart(BYTESLENGTH), + m_ProjectID(projectID) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::CloseSPITProject::setProjectID(string p_ProjectID) { - m_ProjectID = p_ProjectID; -} -bool SPIT_Message::CloseSPITProject::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::CloseSPITProject::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_ProjectID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_ProjectID, message, m_ParseOffset, 41); } catch (...) { + ESP_LOGE(TAG, "failed to create CloseSPITProject message"); return false; } return true; @@ -793,50 +569,43 @@ bool SPIT_Message::CloseSPITProject::fillBytes(char *p_MessageBytes, int p_ByteC //----------- RequestProjectTransfer ----------- -void SPIT_Message::RequestProjectTransfer::initMembers() { - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::RequestProjectTransfer::~RequestProjectTransfer() { -} // Receive -SPIT_Message::RequestProjectTransfer::RequestProjectTransfer(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::RequestProjectTransfer::RequestProjectTransfer(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::RequestProjectTransfer::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::RequestProjectTransfer::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_BytesCount = getInt(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse RequestProjectTransfer message"); return false; } return true; } // Send -SPIT_Message::RequestProjectTransfer::RequestProjectTransfer() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::RequestProjectTransfer::RequestProjectTransfer() + : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -bool SPIT_Message::RequestProjectTransfer::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::RequestProjectTransfer::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create RequestProjectTransfer message"); return false; } return true; @@ -844,51 +613,44 @@ bool SPIT_Message::RequestProjectTransfer::fillBytes(char *p_MessageBytes, int p //----------- StartProjectTransfer ----------- -void SPIT_Message::StartProjectTransfer::initMembers() { - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::StartProjectTransfer::~StartProjectTransfer() { -} // Receive -SPIT_Message::StartProjectTransfer::StartProjectTransfer(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::StartProjectTransfer::StartProjectTransfer(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::StartProjectTransfer::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::StartProjectTransfer::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_BytesCount = getInt(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse StartProjectTransfer message"); return false; } return true; } // Send -SPIT_Message::StartProjectTransfer::StartProjectTransfer() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::StartProjectTransfer::StartProjectTransfer() + : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -bool SPIT_Message::StartProjectTransfer::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::StartProjectTransfer::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create StartProjectTransfer message"); return false; } return true; @@ -896,50 +658,43 @@ bool SPIT_Message::StartProjectTransfer::fillBytes(char *p_MessageBytes, int p_B //----------- ENdProjectTransfer ----------- -void SPIT_Message::EndProjectTransfer::initMembers() { - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::EndProjectTransfer::~EndProjectTransfer() { -} // Receive -SPIT_Message::EndProjectTransfer::EndProjectTransfer(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::EndProjectTransfer::EndProjectTransfer(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::EndProjectTransfer::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::EndProjectTransfer::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_BytesCount = getInt(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse EndProjectTransfer message"); return false; } return true; } // Send -SPIT_Message::EndProjectTransfer::EndProjectTransfer() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::EndProjectTransfer::EndProjectTransfer() + : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -bool SPIT_Message::EndProjectTransfer::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::EndProjectTransfer::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create EndProjectTransfer message"); return false; } return true; @@ -949,114 +704,62 @@ bool SPIT_Message::EndProjectTransfer::fillBytes(char *p_MessageBytes, int p_Byt //----------- ReportSPITType ----------- -void SPIT_Message::ReportSPITType::initMembers() { - m_Confirmed = false; - m_SPITTypeID = ""; - m_Fixed = false; - m_ServerRemote = false; - m_ServerProjectIndepended = false; - m_SPITTypeGroupName = ""; - m_SPITTypeName = ""; - m_Delay = 0; - m_Duration = 0; - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::ReportSPITType::~ReportSPITType() { -} // Receive -SPIT_Message::ReportSPITType::ReportSPITType(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::ReportSPITType::ReportSPITType(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::ReportSPITType::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::ReportSPITType::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_Confirmed = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_SPITTypeID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; - m_Fixed = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_ServerRemote = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_ServerProjectIndepended = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_SPITTypeGroupName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 39); - m_ParseOffset += 39; - m_SPITTypeName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_Delay = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; - m_Duration = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_Confirmed = getBoolean(message, m_ParseOffset).value(); + m_SPITTypeID = getString(message, m_ParseOffset, 41).value(); + m_Fixed = getBoolean(message, m_ParseOffset).value(); + m_ServerRemote = getBoolean(message, m_ParseOffset).value(); + m_ServerProjectIndepended = getBoolean(message, m_ParseOffset).value(); + m_SPITTypeGroupName = getString(message, m_ParseOffset, 39).value(); + m_SPITTypeName = getString(message, m_ParseOffset, 64).value(); + m_Delay = getLong(message, m_ParseOffset).value(); + m_Duration = getLong(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse ReportSPITType message"); return false; } return true; } // Send -SPIT_Message::ReportSPITType::ReportSPITType() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::ReportSPITType::ReportSPITType() + : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::ReportSPITType::setConfirmed(bool p_Confirmed) { - m_Confirmed = p_Confirmed; -} -void SPIT_Message::ReportSPITType::setID(string p_ID) { - m_SPITTypeID = p_ID; -} -void SPIT_Message::ReportSPITType::setFixed(bool p_Fixed) { - m_Fixed = p_Fixed; -} -void SPIT_Message::ReportSPITType::setServerRemote(bool p_IsServerRemote) { - m_ServerRemote = p_IsServerRemote; -} -void SPIT_Message::ReportSPITType::setServerProjectIndepended(bool p_ProjectIndpended) { - m_ServerProjectIndepended = p_ProjectIndpended; -} -void SPIT_Message::ReportSPITType::setGroupName(string p_GroupName) { - m_SPITTypeGroupName = p_GroupName; -} -void SPIT_Message::ReportSPITType::setName(string p_Name) { - m_SPITTypeName = p_Name; -} -void SPIT_Message::ReportSPITType::setDelay(long long p_Delay) { - m_Delay = p_Delay; -} -void SPIT_Message::ReportSPITType::setDuration(long long p_Duration) { - m_Duration = p_Duration; -} -bool SPIT_Message::ReportSPITType::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::ReportSPITType::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = m_Header->BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setBoolean(m_Confirmed, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_SPITTypeID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setBoolean(m_Fixed, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setBoolean(m_ServerRemote, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setBoolean(m_ServerProjectIndepended, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_SPITTypeGroupName, p_MessageBytes, p_ByteCount, m_ParseOffset, 39); - m_ParseOffset += setString(m_SPITTypeName, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setLong(m_Delay, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setLong(m_Duration, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setBoolean(m_Confirmed, message, m_ParseOffset); + m_ParseOffset += setString(m_SPITTypeID, message, m_ParseOffset, 41); + m_ParseOffset += setBoolean(m_Fixed, message, m_ParseOffset); + m_ParseOffset += setBoolean(m_ServerRemote, message, m_ParseOffset); + m_ParseOffset += setBoolean(m_ServerProjectIndepended, message, m_ParseOffset); + m_ParseOffset += setString(m_SPITTypeGroupName, message, m_ParseOffset, 39); + m_ParseOffset += setString(m_SPITTypeName, message, m_ParseOffset, 64); + m_ParseOffset += setLong(m_Delay, message, m_ParseOffset); + m_ParseOffset += setLong(m_Duration, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create ReportSPITType message"); return false; } return true; @@ -1064,58 +767,46 @@ bool SPIT_Message::ReportSPITType::fillBytes(char *p_MessageBytes, int p_ByteCou //----------- ReportSPITType ----------- -void SPIT_Message::RemoveSPITType::initMembers() { - m_SPITTypeID = ""; - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::RemoveSPITType::~RemoveSPITType() { -} // Receive -SPIT_Message::RemoveSPITType::RemoveSPITType(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::RemoveSPITType::RemoveSPITType(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::RemoveSPITType::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::RemoveSPITType::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_SPITTypeID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_SPITTypeID = getString(message, m_ParseOffset, 41).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse RemoveSPITType message"); return false; } return true; } // Send -SPIT_Message::RemoveSPITType::RemoveSPITType() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::RemoveSPITType::RemoveSPITType() + : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::RemoveSPITType::setID(string p_ID) { - m_SPITTypeID = p_ID; -} -bool SPIT_Message::RemoveSPITType::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::RemoveSPITType::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_SPITTypeID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_SPITTypeID, message, m_ParseOffset, 41); } catch (...) { + ESP_LOGE(TAG, "failed to create RemoveSPITType message"); return false; } return true; @@ -1124,139 +815,50 @@ bool SPIT_Message::RemoveSPITType::fillBytes(char *p_MessageBytes, int p_ByteCou //---------------------------- SPITObjects ---------------------------------- //----------- ReportSPITObject ----------- -void SPIT_Message::ReportSPITObject::initMembers() { - m_Confirmed = false; - m_SPITObjectID = ""; - m_Fixed = false; - m_ServerRemote = false; - m_SPITObjectName = ""; - m_SPITTypeID = ""; - m_ServerParams = ""; - m_FrameStart = 0; - m_FrameLength = 0; - m_FrameFadeInLength = 0; - m_FrameFadeOutLength = 0; - m_ValueFactor = 0; - m_ValueUse = VALUEUSE_DISCARD; - m_Track = 0; - m_Remark = ""; - m_Delay = 0; - m_Duration = 0; - m_ActionAssigned = false; - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::ReportSPITObject::~ReportSPITObject() { -} // Receive -SPIT_Message::ReportSPITObject::ReportSPITObject(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::ReportSPITObject::ReportSPITObject(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::ReportSPITObject::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::ReportSPITObject::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_Confirmed = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_SPITObjectID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; - m_Fixed = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_ServerRemote = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_SPITObjectName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_SPITTypeID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; - m_ServerParams = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_FrameStart = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; - m_FrameLength = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; - m_FrameFadeInLength = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; - m_FrameFadeOutLength = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; - m_ValueFactor = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_ValueUse = getByte(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_Track = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_Remark = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_Delay = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; - m_Duration = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; - m_ActionAssigned = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_Confirmed = getBoolean(message, m_ParseOffset).value(); + m_SPITObjectID = getString(message, m_ParseOffset, 41).value(); + m_Fixed = getBoolean(message, m_ParseOffset).value(); + m_ServerRemote = getBoolean(message, m_ParseOffset).value(); + m_SPITObjectName = getString(message, m_ParseOffset, 64).value(); + m_SPITTypeID = getString(message, m_ParseOffset, 41).value(); + m_ServerParams = getString(message, m_ParseOffset, 64).value(); + m_FrameStart = getLong(message, m_ParseOffset).value(); + m_FrameLength = getLong(message, m_ParseOffset).value(); + m_FrameFadeInLength = getLong(message, m_ParseOffset).value(); + m_FrameFadeOutLength = getLong(message, m_ParseOffset).value(); + m_ValueFactor = getInt(message, m_ParseOffset).value(); + m_ValueUse = getByte(message, m_ParseOffset).value(); + m_Track = getInt(message, m_ParseOffset).value(); + m_Remark = getString(message, m_ParseOffset, 64).value(); + m_Delay = getLong(message, m_ParseOffset).value(); + m_Duration = getLong(message, m_ParseOffset).value(); + m_ActionAssigned = getBoolean(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse ReportSPITObject message"); return false; } return true; } // Send -SPIT_Message::ReportSPITObject::ReportSPITObject() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::ReportSPITObject::ReportSPITObject() : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::ReportSPITObject::setConfirmed(bool p_Confirmed) { - m_Confirmed = p_Confirmed; -} -void SPIT_Message::ReportSPITObject::setID(string p_ID) { - m_SPITObjectID = p_ID; -} -void SPIT_Message::ReportSPITObject::setFixed(bool p_Fixed) { - m_Fixed = p_Fixed; -} -void SPIT_Message::ReportSPITObject::setServerRemote(bool p_IsRemote) { - m_ServerRemote = p_IsRemote; -} -void SPIT_Message::ReportSPITObject::setName(string p_Name) { - m_SPITObjectName = p_Name; -} -void SPIT_Message::ReportSPITObject::setSPITTypeID(string p_ID) { - m_SPITTypeID = p_ID; -} -void SPIT_Message::ReportSPITObject::setServerParams(string p_Parameters) { - m_ServerParams = p_Parameters; -} -void SPIT_Message::ReportSPITObject::setFrameStart(long long p_StartTime) { - m_FrameStart = p_StartTime; -} -void SPIT_Message::ReportSPITObject::setFrameLength(long long p_Length) { - m_FrameLength = p_Length; -} -void SPIT_Message::ReportSPITObject::setFrameFadeInLength(long long p_FadeInTime) { - m_FrameFadeInLength = p_FadeInTime; -} -void SPIT_Message::ReportSPITObject::setFrameFadeOutLength(long long p_FadeOutTime) { - m_FrameFadeOutLength = p_FadeOutTime; -} -void SPIT_Message::ReportSPITObject::setValueFactor(int p_Volume) { - m_ValueFactor = p_Volume; -} -void SPIT_Message::ReportSPITObject::setValueUse(char p_ValueUse) { - m_ValueUse = p_ValueUse; -} -void SPIT_Message::ReportSPITObject::setTrack(int p_Track) { - m_Track = p_Track; -} -void SPIT_Message::ReportSPITObject::setRemark(string p_Description) { - m_Remark = p_Description; -} void SPIT_Message::ReportSPITObject::setDelay(long long p_Delay) { if (p_Delay < 0) p_Delay = 0; @@ -1268,97 +870,81 @@ void SPIT_Message::ReportSPITObject::setDuration(long long p_Duration) { m_Duration = p_Duration; } -void SPIT_Message::ReportSPITObject::setActionAssigned(bool p_ActionAssigned) { - m_ActionAssigned = p_ActionAssigned; -} -bool SPIT_Message::ReportSPITObject::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::ReportSPITObject::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setBoolean(m_Confirmed, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_SPITObjectID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setBoolean(m_Fixed, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setBoolean(m_ServerRemote, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_SPITObjectName, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setString(m_SPITTypeID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setString(m_ServerParams, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setLong(m_FrameStart, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setLong(m_FrameLength, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setLong(m_FrameFadeInLength, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setLong(m_FrameFadeOutLength, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setInt(m_ValueFactor, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setByte(m_ValueUse, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setInt(m_Track, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_Remark, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setLong(m_Delay, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setLong(m_Duration, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setBoolean(m_ActionAssigned, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setBoolean(m_Confirmed, message, m_ParseOffset); + m_ParseOffset += setString(m_SPITObjectID, message, m_ParseOffset, 41); + m_ParseOffset += setBoolean(m_Fixed, message, m_ParseOffset); + m_ParseOffset += setBoolean(m_ServerRemote, message, m_ParseOffset); + m_ParseOffset += setString(m_SPITObjectName, message, m_ParseOffset, 64); + m_ParseOffset += setString(m_SPITTypeID, message, m_ParseOffset, 41); + m_ParseOffset += setString(m_ServerParams, message, m_ParseOffset, 64); + m_ParseOffset += setLong(m_FrameStart, message, m_ParseOffset); + m_ParseOffset += setLong(m_FrameLength, message, m_ParseOffset); + m_ParseOffset += setLong(m_FrameFadeInLength, message, m_ParseOffset); + m_ParseOffset += setLong(m_FrameFadeOutLength, message, m_ParseOffset); + m_ParseOffset += setInt(m_ValueFactor, message, m_ParseOffset); + m_ParseOffset += setByte(m_ValueUse, message, m_ParseOffset); + m_ParseOffset += setInt(m_Track, message, m_ParseOffset); + m_ParseOffset += setString(m_Remark, message, m_ParseOffset, 64); + m_ParseOffset += setLong(m_Delay, message, m_ParseOffset); + m_ParseOffset += setLong(m_Duration, message, m_ParseOffset); + m_ParseOffset += setBoolean(m_ActionAssigned, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create ReportSPITObject message"); return false; } return true; } //----------- RemoveSPITObject ----------- -void SPIT_Message::RemoveSPITObject::initMembers() { - m_SPITObjectID = ""; - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::RemoveSPITObject::~RemoveSPITObject() { -} // Receive -SPIT_Message::RemoveSPITObject::RemoveSPITObject(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::RemoveSPITObject::RemoveSPITObject(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::RemoveSPITObject::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::RemoveSPITObject::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_SPITObjectID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_SPITObjectID = getString(message, m_ParseOffset, 41).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse RemoveSPITObject message"); return false; } return true; } // Send -SPIT_Message::RemoveSPITObject::RemoveSPITObject() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::RemoveSPITObject::RemoveSPITObject() : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::RemoveSPITObject::setID(string p_ID) { - m_SPITObjectID = p_ID; -} -bool SPIT_Message::RemoveSPITObject::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::RemoveSPITObject::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_SPITObjectID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_SPITObjectID, message, m_ParseOffset, 41); } catch (...) { + ESP_LOGE(TAG, "failed to create RemoveSPITObject message"); return false; } return true; @@ -1367,87 +953,58 @@ bool SPIT_Message::RemoveSPITObject::fillBytes(char *p_MessageBytes, int p_ByteC //---------------------------- SPITPlayer ---------------------------------- //----------- PlaySPITStart ----------- -void SPIT_Message::PlaySPITStart::initMembers() { - m_PlayerID = ""; - m_PlayerName = ""; - m_PlayerType = 0x00; - m_Time = 0; - m_PlayerIsRunning = false; - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::PlaySPITStart::~PlaySPITStart() { -} // Receive -SPIT_Message::PlaySPITStart::PlaySPITStart(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::PlaySPITStart::PlaySPITStart(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::PlaySPITStart::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::PlaySPITStart::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_PlayerID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; - m_PlayerName = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += 64; - m_PlayerType = getByte(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_PlayerIsRunning = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_Time = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_PlayerID = getString(message, m_ParseOffset, 41).value(); + m_PlayerName = getString(message, m_ParseOffset, 64).value(); + m_PlayerType = getByte(message, m_ParseOffset).value(); + m_PlayerIsRunning = getBoolean(message, m_ParseOffset).value(); + m_Time = getLong(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse PlaySPITStart message"); return false; } return true; } // Send -SPIT_Message::PlaySPITStart::PlaySPITStart() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::PlaySPITStart::PlaySPITStart(string p_PlayerID, string p_PlayerName, char p_PlayerType) + : OPPart(BYTESLENGTH), + m_PlayerID(p_PlayerID), + m_PlayerName(p_PlayerName), + m_PlayerType(p_PlayerType) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::PlaySPITStart::setPlayerID(string p_PlayerID) { - m_PlayerID = p_PlayerID; -} -void SPIT_Message::PlaySPITStart::setPlayerName(string p_PlayerName) { - m_PlayerName = p_PlayerName; -} -void SPIT_Message::PlaySPITStart::setPlayerType(char p_PlayerType) { - m_PlayerType = p_PlayerType; -} -void SPIT_Message::PlaySPITStart::setPlayerIsRunning(bool p_IsPlaying) { - m_PlayerIsRunning = p_IsPlaying; -} -void SPIT_Message::PlaySPITStart::setTime(long long p_Time) { - m_Time = p_Time; -} -bool SPIT_Message::PlaySPITStart::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::PlaySPITStart::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_PlayerID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setString(m_PlayerName, p_MessageBytes, p_ByteCount, m_ParseOffset, 64); - m_ParseOffset += setByte(m_PlayerType, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setBoolean(m_PlayerIsRunning, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setLong(m_Time, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_PlayerID, message, m_ParseOffset, 41); + m_ParseOffset += setString(m_PlayerName, message, m_ParseOffset, 64); + m_ParseOffset += setByte(m_PlayerType, message, m_ParseOffset); + m_ParseOffset += setBoolean(m_PlayerIsRunning, message, m_ParseOffset); + m_ParseOffset += setLong(m_Time, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create PlaySPITStart message"); return false; } return true; @@ -1455,91 +1012,55 @@ bool SPIT_Message::PlaySPITStart::fillBytes(char *p_MessageBytes, int p_ByteCoun //----------- PlaySPITObject ----------- -void SPIT_Message::PlaySPITObject::initMembers() { - m_PlayerID = ""; - m_SPITObjectID = ""; - m_FrameInsideObject = 0; - m_Value = 0; - m_ValueFlag = VALUEFLAG_DIRECT; - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::PlaySPITObject::~PlaySPITObject() { -} // Receive -SPIT_Message::PlaySPITObject::PlaySPITObject(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::PlaySPITObject::PlaySPITObject(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::PlaySPITObject::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::PlaySPITObject::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_PlayerID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; - m_SPITObjectID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; - m_FrameInsideObject = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; - m_PlayPrePosition = getBoolean(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; - m_Value = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_ValueFlag = getByte(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 1; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_PlayerID = getString(message, m_ParseOffset, 41).value(); + m_SPITObjectID = getString(message, m_ParseOffset, 41).value(); + m_FrameInsideObject = getLong(message, m_ParseOffset).value(); + m_PlayPrePosition = getBoolean(message, m_ParseOffset).value(); + m_Value = getInt(message, m_ParseOffset).value(); + m_ValueFlag = getByte(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse PlaySPITObject message"); return false; } return true; } // Send -SPIT_Message::PlaySPITObject::PlaySPITObject() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::PlaySPITObject::PlaySPITObject() + : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::PlaySPITObject::setPlayerID(string p_PlayerID) { - m_PlayerID = p_PlayerID; -} -void SPIT_Message::PlaySPITObject::setID(string p_ID) { - m_SPITObjectID = p_ID; -} -void SPIT_Message::PlaySPITObject::setFrameInsideObject(long long p_TimeInside) { - m_FrameInsideObject = p_TimeInside; -} -void SPIT_Message::PlaySPITObject::setPlayPrePosition(bool p_PlayOldPosition) { - m_PlayPrePosition = p_PlayOldPosition; -} -void SPIT_Message::PlaySPITObject::setValue(int p_Value) { - m_Value = p_Value; -} -void SPIT_Message::PlaySPITObject::setValueFlag(char p_ValueFlag) { - m_ValueFlag = p_ValueFlag; -} -bool SPIT_Message::PlaySPITObject::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::PlaySPITObject::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_PlayerID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setString(m_SPITObjectID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setLong(m_FrameInsideObject, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setBoolean(m_PlayPrePosition, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setInt(m_Value, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setByte(m_ValueFlag, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_PlayerID, message, m_ParseOffset, 41); + m_ParseOffset += setString(m_SPITObjectID, message, m_ParseOffset, 41); + m_ParseOffset += setLong(m_FrameInsideObject, message, m_ParseOffset); + m_ParseOffset += setBoolean(m_PlayPrePosition, message, m_ParseOffset); + m_ParseOffset += setInt(m_Value, message, m_ParseOffset); + m_ParseOffset += setByte(m_ValueFlag, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create PlaySPITObject message"); return false; } return true; @@ -1547,58 +1068,47 @@ bool SPIT_Message::PlaySPITObject::fillBytes(char *p_MessageBytes, int p_ByteCou //----------- PlaySPITEnd ----------- -void SPIT_Message::PlaySPITEnd::initMembers() { - m_PlayerID = ""; - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::PlaySPITEnd::~PlaySPITEnd() { -} // Receive -SPIT_Message::PlaySPITEnd::PlaySPITEnd(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::PlaySPITEnd::PlaySPITEnd(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::PlaySPITEnd::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::PlaySPITEnd::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_PlayerID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_PlayerID = getString(message, m_ParseOffset, 41).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse PlaySPITEnd message"); return false; } return true; } // Send -SPIT_Message::PlaySPITEnd::PlaySPITEnd() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::PlaySPITEnd::PlaySPITEnd(string p_PlayerID) + : OPPart(BYTESLENGTH), + m_PlayerID(p_PlayerID) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } -void SPIT_Message::PlaySPITEnd::setPlayerID(string p_PlayerID) { - m_PlayerID = p_PlayerID; -} -bool SPIT_Message::PlaySPITEnd::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::PlaySPITEnd::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_PlayerID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_PlayerID, message, m_ParseOffset, 41); } catch (...) { + ESP_LOGE(TAG, "failed to create PlaySPITEnd message"); return false; } return true; @@ -1606,46 +1116,32 @@ bool SPIT_Message::PlaySPITEnd::fillBytes(char *p_MessageBytes, int p_ByteCount) //----------- ReportPlayStatus ----------- -void SPIT_Message::ReportPlayStatus::initMembers() { - m_SPITObjectID = ""; - m_FrameInsideObject = 0; - m_Value = 0; - m_BytesCount = BYTESLENGTH; -} -SPIT_Message::ReportPlayStatus::~ReportPlayStatus() { -} // Receive -SPIT_Message::ReportPlayStatus::ReportPlayStatus(Header *p_Header) : OPPart(p_Header, OPFLAG) { - initMembers(); +SPIT_Message::ReportPlayStatus::ReportPlayStatus(unique_ptr
p_Header) + : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) { } -bool SPIT_Message::ReportPlayStatus::parse(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) - return false; - if (m_Header == NULL) +bool SPIT_Message::ReportPlayStatus::parse(const std::vector &message) { + if (!m_Header) { return false; + } int intOPFlag = m_Header->getOPFlag(); if (intOPFlag != OPFLAG) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_BytesCount = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; - m_SPITObjectID = getString(p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += 41; - m_FrameInsideObject = getLong(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 8; - m_Value = getInt(p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += 4; + m_BytesCount = getInt(message, m_ParseOffset).value(); + m_SPITObjectID = getString(message, m_ParseOffset, 41).value(); + m_FrameInsideObject = getLong(message, m_ParseOffset).value(); + m_Value = getInt(message, m_ParseOffset).value(); } catch (...) { + ESP_LOGE(TAG, "failed to parse ReportPlayStatus message"); return false; } return true; } // Send -SPIT_Message::ReportPlayStatus::ReportPlayStatus() : OPPart() { - initMembers(); - m_Header = new Header(SPITVERSION, OPFLAG); - setHeader(m_Header); +SPIT_Message::ReportPlayStatus::ReportPlayStatus() : OPPart(BYTESLENGTH) { + setHeader(OPFLAG); m_ParseOffset = Header::BYTESLENGTH; } @@ -1658,20 +1154,20 @@ void SPIT_Message::ReportPlayStatus::setFrameInsideObject(long long p_TimeInside void SPIT_Message::ReportPlayStatus::setValue(int p_Value) { m_Value = p_Value; } -bool SPIT_Message::ReportPlayStatus::fillBytes(char *p_MessageBytes, int p_ByteCount) { - if (p_MessageBytes == NULL) +bool SPIT_Message::ReportPlayStatus::fillBytes(std::vector &message) { + if (!m_Header) { return false; - if (m_Header == NULL) - return false; - if (m_Header->fillBytes(p_MessageBytes, p_ByteCount) == false) + } + if (m_Header->fillBytes(message) == false) return false; try { m_ParseOffset = Header::BYTESLENGTH; - m_ParseOffset += setInt(m_BytesCount, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setString(m_SPITObjectID, p_MessageBytes, p_ByteCount, m_ParseOffset, 41); - m_ParseOffset += setLong(m_FrameInsideObject, p_MessageBytes, p_ByteCount, m_ParseOffset); - m_ParseOffset += setInt(m_Value, p_MessageBytes, p_ByteCount, m_ParseOffset); + m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset); + m_ParseOffset += setString(m_SPITObjectID, message, m_ParseOffset, 41); + m_ParseOffset += setLong(m_FrameInsideObject, message, m_ParseOffset); + m_ParseOffset += setInt(m_Value, message, m_ParseOffset); } catch (...) { + ESP_LOGE(TAG, "failed to create ReportPlayStatus message"); return false; } return true; @@ -1689,205 +1185,168 @@ bool SPIT_Message::isSystemLittleEndian() { return true; } -int SPIT_Message::getInt(char *p_Bytes, int p_ByteCount, int p_Offset) { - if (p_Offset < 0) - throw "ParseError_received"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + 4) - throw "ParseError_received"; +optional SPIT_Message::getInt(const std::vector &message, int &offset) { + if (offset < 0 || offset + 4 > message.size()) + return std::nullopt; // low byte first int intValue = 0; if (isSystemLittleEndian() == false) { - intValue += ((p_Bytes[p_Offset + 0] & 0x000000ff)); - intValue += ((p_Bytes[p_Offset + 1] & 0x000000ff) << 8); - intValue += ((p_Bytes[p_Offset + 2] & 0x000000ff) << 16); - intValue += ((p_Bytes[p_Offset + 3] & 0x000000ff) << 24); + intValue += ((message[offset + 0] & 0x000000ff)); + intValue += ((message[offset + 1] & 0x000000ff) << 8); + intValue += ((message[offset + 2] & 0x000000ff) << 16); + intValue += ((message[offset + 3] & 0x000000ff) << 24); } else { - intValue += ((p_Bytes[p_Offset + 3] & 0x000000ff)); - intValue += ((p_Bytes[p_Offset + 2] & 0x000000ff) << 8); - intValue += ((p_Bytes[p_Offset + 1] & 0x000000ff) << 16); - intValue += ((p_Bytes[p_Offset + 0] & 0x000000ff) << 24); + intValue += ((message[offset + 3] & 0x000000ff)); + intValue += ((message[offset + 2] & 0x000000ff) << 8); + intValue += ((message[offset + 1] & 0x000000ff) << 16); + intValue += ((message[offset + 0] & 0x000000ff) << 24); } + offset += 4; return intValue; } -int SPIT_Message::setInt(int p_Value, char *p_Bytes, int p_ByteCount, int p_Offset) { - if (p_Offset < 0) - throw "ParseError_send"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + 4) +int SPIT_Message::setInt(int p_Value, std::vector &message, int p_Offset) { + if ((p_Offset < 0) || (message.size() < p_Offset + 4)) throw "ParseError_send"; + // low byte first - int intTest; if (isSystemLittleEndian() == false) { - p_Bytes[p_Offset + 0] = (char)(p_Value & 0x000000ff); - p_Bytes[p_Offset + 1] = (char)((p_Value & 0x0000ff00) >> 8); - p_Bytes[p_Offset + 2] = (char)((p_Value & 0x00ff0000) >> 16); - p_Bytes[p_Offset + 3] = (char)((p_Value & 0xff000000) >> 24); - - intTest = getInt(p_Bytes, p_ByteCount, p_Offset); + message[p_Offset + 0] = (char)(p_Value & 0x000000ff); + message[p_Offset + 1] = (char)((p_Value & 0x0000ff00) >> 8); + message[p_Offset + 2] = (char)((p_Value & 0x00ff0000) >> 16); + message[p_Offset + 3] = (char)((p_Value & 0xff000000) >> 24); } else { - p_Bytes[p_Offset + 3] = (char)(p_Value & 0x000000ff); - p_Bytes[p_Offset + 2] = (char)((p_Value & 0x0000ff00) >> 8); - p_Bytes[p_Offset + 1] = (char)((p_Value & 0x00ff0000) >> 16); - p_Bytes[p_Offset + 0] = (char)((p_Value & 0xff000000) >> 24); - - intTest = getInt(p_Bytes, p_ByteCount, p_Offset); + message[p_Offset + 3] = (char)(p_Value & 0x000000ff); + message[p_Offset + 2] = (char)((p_Value & 0x0000ff00) >> 8); + message[p_Offset + 1] = (char)((p_Value & 0x00ff0000) >> 16); + message[p_Offset + 0] = (char)((p_Value & 0xff000000) >> 24); } return 4; } -long long SPIT_Message::getLong(char *p_Bytes, int p_ByteCount, int p_Offset) { - if (p_Offset < 0) - throw "ParseError_received"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + 8) - throw "ParseError_received"; + +optional SPIT_Message::getLong(const std::vector &message, int &offset) { + if (offset < 0 || offset + 8 > message.size()) + return std::nullopt; + // low byte first long long intValue = 0; if (isSystemLittleEndian() == false) { - intValue += ((long long)(p_Bytes[p_Offset] & 0x000000ff)); - intValue += ((long long)(p_Bytes[p_Offset + 1] & 0x000000ff) << 8); - intValue += ((long long)(p_Bytes[p_Offset + 2] & 0x000000ff) << 16); - intValue += ((long long)(p_Bytes[p_Offset + 3] & 0x000000ff) << 24); - intValue += ((long long)(p_Bytes[p_Offset + 4] & 0x000000ff) << 32); - intValue += ((long long)(p_Bytes[p_Offset + 5] & 0x000000ff) << 40); - intValue += ((long long)(p_Bytes[p_Offset + 6] & 0x000000ff) << 48); - intValue += ((long long)(p_Bytes[p_Offset + 7] & 0x000000ff) << 56); + intValue += ((long long)(message[offset] & 0x000000ff)); + intValue += ((long long)(message[offset + 1] & 0x000000ff) << 8); + intValue += ((long long)(message[offset + 2] & 0x000000ff) << 16); + intValue += ((long long)(message[offset + 3] & 0x000000ff) << 24); + intValue += ((long long)(message[offset + 4] & 0x000000ff) << 32); + intValue += ((long long)(message[offset + 5] & 0x000000ff) << 40); + intValue += ((long long)(message[offset + 6] & 0x000000ff) << 48); + intValue += ((long long)(message[offset + 7] & 0x000000ff) << 56); } else { - intValue += ((long long)(p_Bytes[p_Offset + 7] & 0x000000ff)); - intValue += ((long long)(p_Bytes[p_Offset + 6] & 0x000000ff) << 8); - intValue += ((long long)(p_Bytes[p_Offset + 5] & 0x000000ff) << 16); - intValue += ((long long)(p_Bytes[p_Offset + 4] & 0x000000ff) << 24); - intValue += ((long long)(p_Bytes[p_Offset + 3] & 0x000000ff) << 32); - intValue += ((long long)(p_Bytes[p_Offset + 2] & 0x000000ff) << 40); - intValue += ((long long)(p_Bytes[p_Offset + 1] & 0x000000ff) << 48); - intValue += ((long long)(p_Bytes[p_Offset + 0] & 0x000000ff) << 56); + intValue += ((long long)(message[offset + 7] & 0x000000ff)); + intValue += ((long long)(message[offset + 6] & 0x000000ff) << 8); + intValue += ((long long)(message[offset + 5] & 0x000000ff) << 16); + intValue += ((long long)(message[offset + 4] & 0x000000ff) << 24); + intValue += ((long long)(message[offset + 3] & 0x000000ff) << 32); + intValue += ((long long)(message[offset + 2] & 0x000000ff) << 40); + intValue += ((long long)(message[offset + 1] & 0x000000ff) << 48); + intValue += ((long long)(message[offset + 0] & 0x000000ff) << 56); } + offset += 8; return intValue; } -int SPIT_Message::setLong(long long p_Value, char *p_Bytes, int p_ByteCount, int p_Offset) { - if (p_Offset < 0) - throw "ParseError_send"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + 8) + +int SPIT_Message::setLong(long long p_Value, std::vector &message, int p_Offset) { + if ((p_Offset < 0) || (message.size() < p_Offset + 8)) throw "ParseError_send"; // low byte first if (isSystemLittleEndian() == false) { - p_Bytes[p_Offset + 0] = (char)((p_Value & 0x00000000000000ff)); - p_Bytes[p_Offset + 1] = (char)((p_Value & 0x000000000000ff00) >> 8); - p_Bytes[p_Offset + 2] = (char)((p_Value & 0x0000000000ff0000) >> 16); - p_Bytes[p_Offset + 3] = (char)((p_Value & 0x00000000ff000000) >> 24); - p_Bytes[p_Offset + 4] = (char)((p_Value & 0x000000ff00000000) >> 32); - p_Bytes[p_Offset + 5] = (char)((p_Value & 0x0000ff0000000000) >> 40); - p_Bytes[p_Offset + 6] = (char)((p_Value & 0x00ff000000000000) >> 48); - p_Bytes[p_Offset + 7] = (char)((p_Value & 0xff00000000000000) >> 56); + message[p_Offset + 0] = (char)((p_Value & 0x00000000000000ff)); + message[p_Offset + 1] = (char)((p_Value & 0x000000000000ff00) >> 8); + message[p_Offset + 2] = (char)((p_Value & 0x0000000000ff0000) >> 16); + message[p_Offset + 3] = (char)((p_Value & 0x00000000ff000000) >> 24); + message[p_Offset + 4] = (char)((p_Value & 0x000000ff00000000) >> 32); + message[p_Offset + 5] = (char)((p_Value & 0x0000ff0000000000) >> 40); + message[p_Offset + 6] = (char)((p_Value & 0x00ff000000000000) >> 48); + message[p_Offset + 7] = (char)((p_Value & 0xff00000000000000) >> 56); } else { - p_Bytes[p_Offset + 7] = (char)((p_Value & 0x00000000000000ff)); - p_Bytes[p_Offset + 6] = (char)((p_Value & 0x000000000000ff00) >> 8); - p_Bytes[p_Offset + 5] = (char)((p_Value & 0x0000000000ff0000) >> 16); - p_Bytes[p_Offset + 4] = (char)((p_Value & 0x00000000ff000000) >> 24); - p_Bytes[p_Offset + 3] = (char)((p_Value & 0x000000ff00000000) >> 32); - p_Bytes[p_Offset + 2] = (char)((p_Value & 0x0000ff0000000000) >> 40); - p_Bytes[p_Offset + 1] = (char)((p_Value & 0x00ff000000000000) >> 48); - p_Bytes[p_Offset + 0] = (char)((p_Value & 0xff00000000000000) >> 56); + message[p_Offset + 7] = (char)((p_Value & 0x00000000000000ff)); + message[p_Offset + 6] = (char)((p_Value & 0x000000000000ff00) >> 8); + message[p_Offset + 5] = (char)((p_Value & 0x0000000000ff0000) >> 16); + message[p_Offset + 4] = (char)((p_Value & 0x00000000ff000000) >> 24); + message[p_Offset + 3] = (char)((p_Value & 0x000000ff00000000) >> 32); + message[p_Offset + 2] = (char)((p_Value & 0x0000ff0000000000) >> 40); + message[p_Offset + 1] = (char)((p_Value & 0x00ff000000000000) >> 48); + message[p_Offset + 0] = (char)((p_Value & 0xff00000000000000) >> 56); } return 8; } -bool SPIT_Message::getBoolean(char *p_Bytes, int p_ByteCount, int p_Offset) { - if (p_Offset < 0) - throw "ParseError_received"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + 1) - throw "ParseError_received"; - // low byte first - if (p_Bytes[p_Offset] > 0x00) - return true; - else - return false; -} -int SPIT_Message::setBoolean(bool p_Value, char *p_Bytes, int p_ByteCount, int p_Offset) { - if (p_Offset < 0) - throw "ParseError_send"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + 1) - throw "ParseError_send"; - if (p_Value == false) { - p_Bytes[p_Offset] = 0x00; - } else { - p_Bytes[p_Offset] = 0x01; - } - return 1; -} -char SPIT_Message::getByte(char *p_Bytes, int p_ByteCount, int p_Offset) { - if (p_Offset < 0) - throw "ParseError_received"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + 1) - throw "ParseError_received"; - // low byte first - return p_Bytes[p_Offset]; -} -int SPIT_Message::setByte(int p_Value, char *p_Bytes, int p_ByteCount, int p_Offset) { - if (p_Offset < 0) - throw "ParseError_send"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + 1) - throw "ParseError_send"; - p_Bytes[p_Offset] = (char)(p_Value & 0xff); - return 1; -} -string SPIT_Message::getString(char *p_Bytes, int p_ByteCount, int p_Offset, int p_Length) { - if (p_Offset < 0) - throw "ParseError_received getString()"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + p_Length) - throw "ParseError_received getString()"; - int intPos; - // get Length of String - for (intPos = 0; intPos < p_Length; intPos++) { - if (p_Bytes[p_Offset + intPos] == 0x00) - break; - } - if (intPos >= p_Length) - throw "ParseError_received getString()"; - string stringResult; - stringResult = &p_Bytes[p_Offset]; - return stringResult; + +optional SPIT_Message::getBoolean(const std::vector &message, int &offset) { + if (offset < 0 || offset + 1 > message.size()) + return std::nullopt; + return {message[offset++] > 0x00}; } -int SPIT_Message::setString(string p_String, char *p_Bytes, int p_ByteCount, int p_Offset, int p_Length) { - if (p_Offset < 0) +int SPIT_Message::setBoolean(bool p_Value, std::vector &message, int p_Offset) { + if ((p_Offset < 0) || (message.size() < p_Offset + 1)) throw "ParseError_send"; - int intChar = 0; - bool boolNullChar = false; - if (p_Length < 1) + + if (p_Value == false) { + message[p_Offset] = 0x00; + } else { + message[p_Offset] = 0x01; + } + return 1; +} + +optional SPIT_Message::getByte(const std::vector &message, int &offset) { + if (offset < 0 || offset + 1 > message.size()) + return std::nullopt; + + return {message[offset++]}; +} + +int SPIT_Message::setByte(int p_Value, std::vector &message, int p_Offset) { + if ((p_Offset < 0) || (message.size() < p_Offset + 1)) throw "ParseError_send"; - if (p_Bytes == NULL || p_ByteCount < p_Offset + p_Length) + + message[p_Offset] = (char)(p_Value & 0xff); + return 1; +} + +optional SPIT_Message::getString(const std::vector &message, int &offset, int maxLength) { + if (offset < 0 || offset + maxLength > message.size()) + return std::nullopt; + + size_t len = strnlen(&message[offset], maxLength); + if (len >= maxLength) + return std::nullopt; + + string str(&message[offset], len); + offset += maxLength; + return str; +} + +int SPIT_Message::setString(string p_String, std::vector &message, int offset, int maxLength) { + if ((offset < 0) || (maxLength < 1) || (message.size() < offset + maxLength)) throw "ParseError_send"; int intLength; - if (p_String.length() + 1 > p_Length) { - intLength = p_Length; + if (p_String.length() + 1 > maxLength) { + intLength = maxLength; } else { intLength = p_String.length() + 1; } + int intChar = 0; + bool boolNullChar = false; while (intChar < intLength) { - p_Bytes[p_Offset + intChar] = p_String.data()[intChar]; - if (p_String[intChar] == nullChar[0]) { + message[offset + intChar] = p_String.data()[intChar]; + if (p_String[intChar] == '\0') { boolNullChar = true; break; } intChar++; } if (boolNullChar == false) { - p_Bytes[p_Offset + intLength - 1] = nullChar[0]; + message[offset + intLength - 1] = '\0'; } - return p_Length; -} - -char *SPIT_Message::createByteArray(const OPPart *p_OPPart, int *p_ByteCount) { - if (p_OPPart == NULL) - return NULL; - int intBytesCount = 0; - char *o_ByteArray; - try { - intBytesCount = Header::BYTESLENGTH; - intBytesCount += p_OPPart->getBytesCount(); - o_ByteArray = (char *)malloc(intBytesCount); - *p_ByteCount = intBytesCount; - } catch (...) { - return NULL; - } - return o_ByteArray; + return maxLength; } diff --git a/doc/InitRun.md b/doc/InitRun.md index c4538e5..87c6d2d 100644 --- a/doc/InitRun.md +++ b/doc/InitRun.md @@ -11,302 +11,178 @@ I (57) boot: 0 nvs WiFi data 01 02 00009000 00006000 I (64) boot: 1 phy_init RF data 01 01 0000f000 00001000 I (72) boot: 2 factory factory app 00 00 00010000 00100000 I (79) boot: End of partition table -I (83) esp_image: segment 0: paddr=00010020 vaddr=42070020 size=29b54h (170836) map -I (127) esp_image: segment 1: paddr=00039b7c vaddr=40800000 size=0649ch ( 25756) load -I (134) esp_image: segment 2: paddr=00040020 vaddr=42000020 size=6a434h (435252) map -I (225) esp_image: segment 3: paddr=000aa45c vaddr=4080649c size=07d28h ( 32040) load -I (233) esp_image: segment 4: paddr=000b218c vaddr=4080e1d0 size=01c00h ( 7168) load -I (239) boot: Loaded app from partition at offset 0x10000 -I (239) boot: Disabling RNG early entropy source... -I (253) cpu_start: Unicore app -I (262) cpu_start: Pro cpu start user code -I (262) cpu_start: cpu freq: 160000000 Hz -I (263) app_init: Application information: -I (265) app_init: Project name: X_WatchController_FW -I (271) app_init: App version: 3ec39a2-dirty -I (277) app_init: Compile time: Mar 29 2025 16:21:16 -I (283) app_init: ELF file SHA256: c5ad318a2... -I (288) app_init: ESP-IDF: v5.3 -I (292) efuse_init: Min chip rev: v0.0 -I (297) efuse_init: Max chip rev: v0.99 -I (302) efuse_init: Chip rev: v0.0 -I (307) heap_init: Initializing. RAM available for dynamic allocation: -I (314) heap_init: At 40812190 len 0006A480 (425 KiB): RAM -I (320) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM -I (326) heap_init: At 50000000 len 00003FE8 (15 KiB): RTCRAM -I (334) spi_flash: detected chip: generic -I (337) spi_flash: flash io: dio -I (343) sleep: Configure to isolate all GPIO pins in sleep state -I (348) sleep: Enable automatic switching of GPIO sleep configuration -I (355) coexist: coex firmware version: dab85ae96 -I (383) coexist: coexist rom version 5b8dcfa -I (383) main_task: Started on CPU0 -I (383) main_task: Calling app_main() -I (393) esp_eth.netif.netif_glue: 42:4c:ca:ff:fe:4e -I (393) esp_eth.netif.netif_glue: ethernet attached to netif -I (403) Watch: Ethernet Started -I (403) Watch: Start Lighting -I (403) gpio: GPIO[10]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 -I (413) gpio: GPIO[11]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 -I (423) Watch: Start Stepper -I (423) gpio: GPIO[18]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (433) gpio: GPIO[8]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (443) gpio: GPIO[15]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (453) TMR: Create timer handle -I (453) TMR: Setup timer -I (453) Stepper: Find Home -I (463) Stepper: Homing ... -I (463) Stepper: Fast find right side of home sensor -I (483) gpio: GPIO[1]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 -I (2133) Stepper: Find right side of home sensor -I (2313) Stepper: Find end of sensor -I (2403) Watch: Ethernet Link Up -I (2403) Watch: Ethernet Link Up -I (2403) Watch: Ethernet HW Addr 00:00:00:00:00:00 -I (3403) esp_netif_handlers: eth ip: 172.16.17.56, mask: 255.255.0.0, gw: 172.16.0.1 -I (3403) Watch: Ethernet Got IP Address -I (3403) Watch: ~~~~~~~~~~~ -I (3403) Watch: ETHIP:172.16.17.56 -I (3413) Watch: ETHMASK:255.255.0.0 -I (3413) Watch: ETHGW:172.16.0.1 -I (3413) Watch: ~~~~~~~~~~~ -I (3423) Watch: Start net services -I (3423) Watch: Starting Telnet task -I (3423) Watch: Starting ArtNet task -I (3423) Watch: Starting SPIT task -I (3433) SPIT: Connected to eth -I (3443) SPIT: - IPv4 address: 172.16.17.56, -I (3443) SPIT: - IPv4 netmask: 255.255.0.0, -I (3423) UDP: Starting syslog session to 172.16.16.10 -I (3433) TCP: Socket created -I (3433) UDP: Socket bound, port 6454 -I (3453) Watch: NEW SPIT-Type ID: ActionStartShuffle GroupName: CatasWatchMovement Name: ActionStartShuffle confirmed: 0 -I (3453) SysLog: Starting Syslog Task -I (3463) TCP: Socket bound, port 23 -I (3473) Watch: NEW SPIT-Type ID: ActionMoveTo1 GroupName: CatasWatchMovement Name: ActionMoveTo1 confirmed: 0 -I (3493) Watch: NEW SPIT-Type ID: ActionMoveTo2 GroupName: CatasWatchMovement Name: ActionMoveTo2 confirmed: 0 -I (3483) Telnet: Socket waiting for connect -I (3483) UDP: Socket bound, port 514 -I (3503) Watch: NEW SPIT-Type ID: ActionMoveTo3 GroupName: CatasWatchMovement Name: ActionMoveTo3 confirmed: 0 -I (3523) Watch: NEW SPIT-Type ID: ActionMoveTo4 GroupName: CatasWatchMovement Name: ActionMoveTo4 confirmed: 0 -I (3533) Watch: NEW SPIT-Type ID: ActionMoveTo5 GroupName: CatasWatchMovement Name: ActionMoveTo5 confirmed: 0 -I (3543) Watch: NEW SPIT-Type ID: ActionMoveTo6 GroupName: CatasWatchMovement Name: ActionMoveTo6 confirmed: 0 -I (3553) SPIT: Starting Socket managing -I (5713) Stepper: Find left side of home sensor -I (6183) Stepper: Move back to mid position 145 -I (7633) Stepper: Reset position -I (7633) Watch: Fist Position is 0.000000.2 -I (7663) Watch: SERVER DETECTED -I (7663) Watch: Name: liveShowSPIT -I (7663) Watch: ID: 698a3e4f-1ae9-4dd8-9015-29332d29629e -I (7663) Watch: Computer: GgP17 -I (7663) Watch: IP: 172.16.16.10 -I (7673) Watch: Port: 15120 -I (7673) Watch: Addition: -I (7673) Watch: ClientIP: 172.16.17.56 -I (7683) SPIT: connect to 172.16.16.10 -I (7683) Watch: MySPITApp: eventConnectionStatus 0 -I (7663) Watch: Changing picto-Illum to pos = 1 -I (7693) Watch: Current color set r128 g128 b128 -I (7693) Watch: MySPITApp: eventConnectionStatus 4 -I (8203) Watch: eventProjectReport ID: CatasWatchProject Name: CatasWatchProject FramesPerSecond: 44100 -I (8203) Watch: eventStartProjectTransfer -I (8283) Watch: SPIT-Type CHANGED ID: ActionMoveTo5 GroupName: CatasWatchMovement Name: ActionMoveTo5 confirmed: 1 -I (8283) Watch: SPIT-Type CHANGED ID: ActionMoveTo4 GroupName: CatasWatchMovement Name: ActionMoveTo4 confirmed: 1 -I (8293) Watch: SPIT-Type CHANGED ID: ActionMoveTo3 GroupName: CatasWatchMovement Name: ActionMoveTo3 confirmed: 1 -I (8303) Watch: SPIT-Type CHANGED ID: ActionMoveTo6 GroupName: CatasWatchMovement Name: ActionMoveTo6 confirmed: 1 -I (8313) Watch: NEW SPIT-REMOTE-Type ID: playControlStart GroupName: Playcontrol Name: start confirmed: 1 -I (8323) Watch: NEW SPIT-REMOTE-Type ID: playControlPause GroupName: Playcontrol Name: pause confirmed: 1 -I (8343) Watch: NEW SPIT-REMOTE-Type ID: nextSceneBridge GroupName: Playcontrol Name: next scene confirmed: 1 -I (8353) Watch: NEW SPIT-REMOTE-Type ID: nextMainSceneBridge GroupName: Playcontrol Name: next main scene confirmed: 1 -I (8373) Watch: NEW SPIT-REMOTE-Type ID: previuosSceneBridge GroupName: Playcontrol Name: previous scene confirmed: 1 -I (8383) Watch: NEW SPIT-REMOTE-Type ID: previousMainSceneBridge GroupName: Playcontrol Name: previous main scene confirmed: 1 -I (8403) Watch: NEW SPIT-REMOTE-Type ID: mainmixerSound_Volume00 GroupName: Main Mixer Name: Sound confirmed: 1 -I (8423) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_Dimmer00 GroupName: Main Mixer Name: confirmed: 1 -I (8433) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB00 GroupName: Main Mixer Name: confirmed: 1 -I (8453) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB10 GroupName: Main Mixer Name: confirmed: 1 -I (8463) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB20 GroupName: Main Mixer Name: confirmed: 1 -I (8483) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB30 GroupName: Main Mixer Name: confirmed: 1 -I (8503) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB40 GroupName: Main Mixer Name: confirmed: 1 -I (8513) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB50 GroupName: Main Mixer Name: confirmed: 1 -I (8533) Watch: NEW SPIT-REMOTE-Type ID: mainmixerMedia_SoundVolume00 GroupName: Main Mixer Name: Media confirmed: 1 -I (8543) Watch: NEW SPIT-REMOTE-Type ID: mainmixerMedia_Transparency00 GroupName: Main Mixer Name: Media confirmed: 1 -I (8563) Watch: NEW SPIT-REMOTE-Type ID: selectedJingles GroupName: Playcontrol Name: selected Jingles confirmed: 1 -I (8573) Watch: NEW SPIT-REMOTE-Type ID: selectedJingleGroups GroupName: Playcontrol Name: selected Jinglegroups confirmed: 1 -I (8593) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000lo0va8bom GroupName: MainScene Name: ChangingPositionScene confirmed: 1 -I (8603) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000m70va8bom GroupName: MainScene Name: InPosition1Scene confirmed: 1 -I (8623) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000mh0va8bom GroupName: MainScene Name: InPosition2Scene confirmed: 1 -I (8633) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000mr0va8bom GroupName: MainScene Name: InPosition3Scene confirmed: 1 -I (8653) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000nk0va8bom GroupName: MainScene Name: InPosition4Scene confirmed: 1 -I (8673) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000nu0va8bom GroupName: MainScene Name: InPosition5Scene confirmed: 1 -I (8683) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000o40va8bom GroupName: MainScene Name: InPosition6Scene confirmed: 1 -I (8703) Watch: NEW SPIT-REMOTE-Object ID: playControlStart Name: start -> SPITType: start -I (8703) Watch: eventPlayRemoteObjectStatus RemoteSPITType: start RemoteSPITObject: start Position: 0 Value: 0 -I (8713) Watch: NEW SPIT-REMOTE-Object ID: playControlPause Name: pause -> SPITType: pause -I (8723) Watch: eventPlayRemoteObjectStatus RemoteSPITType: pause RemoteSPITObject: pause Position: 0 Value: 0 -I (8733) Watch: NEW SPIT-REMOTE-Object ID: nextSceneBridge Name: next scene -> SPITType: next scene -I (8743) Watch: eventPlayRemoteObjectStatus RemoteSPITType: next scene RemoteSPITObject: next scene Position: 0 Value: 0 -I (8753) Watch: NEW SPIT-REMOTE-Object ID: nextMainSceneBridge Name: next main scene -> SPITType: next main scene -I (8763) Watch: eventPlayRemoteObjectStatus RemoteSPITType: next main scene RemoteSPITObject: next main scene Position: 0 Value: 0 -I (8773) Watch: NEW SPIT-REMOTE-Object ID: previuosSceneBridge Name: previous scene -> SPITType: previous scene -I (8783) Watch: eventPlayRemoteObjectStatus RemoteSPITType: previous scene RemoteSPITObject: previous scene Position: 0 Value: 0 -I (8793) Watch: NEW SPIT-REMOTE-Object ID: previousMainSceneBridge Name: previous main scene -> SPITType: previous main scene -I (8813) Watch: eventPlayRemoteObjectStatus RemoteSPITType: previous main scene RemoteSPITObject: previous main scene Position: 0 Value: 0 -I (8823) Watch: NEW SPIT-REMOTE-Object ID: mainmixerSound_Volume00 Name: Sound Volume -> SPITType: Sound -I (8833) Watch: eventPlayRemoteObjectStatus RemoteSPITType: Sound RemoteSPITObject: Sound Volume Position: 0 Value: 500000 -I (8843) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_Dimmer00 Name: Dimmer -> SPITType: -I (8853) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Dimmer Position: 0 Value: 1000000 -I (8863) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB00 Name: Red -> SPITType: -I (8873) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Red Position: 0 Value: 1000000 -I (8883) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB10 Name: Green -> SPITType: -I (8893) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Green Position: 0 Value: 1000000 -I (8903) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB20 Name: Blue -> SPITType: -I (8913) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Blue Position: 0 Value: 1000000 -I (8923) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB30 Name: Cyan -> SPITType: -I (8933) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB40 Name: Magenta -> SPITType: -I (8943) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Magenta Position: 0 Value: 0 -I (8953) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB50 Name: Yellow -> SPITType: -I (8963) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Yellow Position: 0 Value: 0 -I (8973) Watch: NEW SPIT-REMOTE-Object ID: mainmixerMedia_SoundVolume00 Name: Sound Volume -> SPITType: Media -I (8983) Watch: NEW SPIT-REMOTE-Object ID: mainmixerMedia_Transparency00 Name: Media Transparency -> SPITType: Media -I (8993) Watch: eventPlayRemoteObjectStatus RemoteSPITType: Media RemoteSPITObject: Media Transparency Position: 0 Value: 1000000 -I (9003) Watch: NEW SPIT-REMOTE-Object ID: selectedJinglesps Name: Play / Stop -> SPITType: selected Jingles -I (9013) Watch: eventPlayRemoteObjectStatus RemoteSPITType: selected Jingles RemoteSPITObject: Play / Stop Position: 0 Value: 0 -I (9023) Watch: NEW SPIT-REMOTE-Object ID: selectedJinglespf Name: Play / Fade Out -> SPITType: selected Jingles -I (9033) Watch: NEW SPIT-REMOTE-Object ID: selectedJingleGroupsps Name: Play / Stop -> SPITType: selected Jinglegroups -I (9053) Watch: eventPlayRemoteObjectStatus RemoteSPITType: selected Jinglegroups RemoteSPITObject: Play / Stop Position: 0 Value: 0 -I (9063) Watch: NEW SPIT-REMOTE-Object ID: selectedJingleGroupspf Name: Play / Fade Out -> SPITType: selected Jinglegroups -I (9073) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000lo0va8bom Name: play -> SPITType: ChangingPositionScene -I (9083) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000m70va8bom Name: play -> SPITType: InPosition1Scene -I (9093) Watch: eventPlayRemoteObjectStatus RemoteSPITType: InPosition1Scene RemoteSPITObject: play Position: 0 Value: 0 -I (9103) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000mh0va8bom Name: play -> SPITType: InPosition2Scene -I (9123) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000mr0va8bom Name: play -> SPITType: InPosition3Scene -I (9133) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000nk0va8bom Name: play -> SPITType: InPosition4Scene -I (9143) Watch: eventPlayRemoteObjectStatus RemoteSPITType: InPosition4Scene RemoteSPITObject: play Position: 0 Value: 0 -I (9153) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000nu0va8bom Name: play -> SPITType: InPosition5Scene -I (9163) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000o40va8bom Name: play -> SPITType: InPosition6Scene -I (9183) Watch: eventEndProjectTransfer -W (9203) SPIT: Finished searching -W (9203) SPIT: Start working -I (9253) Watch: SPIT-Type CHANGED ID: ActionMoveTo5 GroupName: CatasWatchMovement Name: ActionMoveTo5 confirmed: 1 -I (9253) Watch: SPIT-Type CHANGED ID: ActionMoveTo4 GroupName: CatasWatchMovement Name: ActionMoveTo4 confirmed: 1 -I (9263) Watch: SPIT-Type CHANGED ID: ActionMoveTo3 GroupName: CatasWatchMovement Name: ActionMoveTo3 confirmed: 1 -I (9273) Watch: SPIT-Type CHANGED ID: ActionMoveTo6 GroupName: CatasWatchMovement Name: ActionMoveTo6 confirmed: 1 -I (9283) Watch: SPIT-Type CHANGED ID: ActionMoveTo2 GroupName: CatasWatchMovement Name: ActionMoveTo2 confirmed: 1 -I (9293) Watch: SPIT-Type CHANGED ID: ActionMoveTo1 GroupName: CatasWatchMovement Name: ActionMoveTo1 confirmed: 1 -I (459853) Watch: SPIT-Type CHANGED ID: ActionMoveTo1 GroupName: CatasWatchMovement Name: ActionMoveTo1 confirmed: 1 -I (459853) Watch: SPIT-Type CHANGED ID: ActionMoveTo1 GroupName: CatasWatchMovement Name: ActionMoveTo1 confirmed: 1 -I (459863) Watch: SPIT-Type CHANGED ID: ActionMoveTo6 GroupName: CatasWatchMovement Name: ActionMoveTo6 confirmed: 1 -I (459883) Watch: SPIT-Type CHANGED ID: ActionMoveTo6 GroupName: CatasWatchMovement Name: ActionMoveTo6 confirmed: 1 -I (459893) Watch: SPIT-Type CHANGED ID: ActionMoveTo4 GroupName: CatasWatchMovement Name: ActionMoveTo4 confirmed: 1 -I (459903) Watch: SPIT-Type CHANGED ID: ActionMoveTo4 GroupName: CatasWatchMovement Name: ActionMoveTo4 confirmed: 1 -I (466093) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000000zq0va8bom Name: -> SPITType: ActionStartShuffle -I (466733) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt0000000000000000zq0va8bom Name: -> SPITType: ActionStartShuffle -I (468643) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt0000000000000000zq0va8bom Name: -> SPITType: ActionStartShuffle -I (471243) Watch: NEW SPIT-Object ID: 00000m8uedyyt00000000000000010u0va8bom Name: -> SPITType: ActionMoveTo1 -I (472153) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000010u0va8bom Name: -> SPITType: ActionMoveTo1 -I (473403) Watch: NEW SPIT-Object ID: 00000m8uedyyt00000000000000011a0va8bom Name: -> SPITType: ActionMoveTo2 -I (474763) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000011a0va8bom Name: -> SPITType: ActionMoveTo2 -I (483183) Watch: NEW SPIT-Object ID: 00000m8uedyyt00000000000000011s0va8bom Name: -> SPITType: ActionMoveTo3 -I (483283) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000011s0va8bom Name: -> SPITType: ActionMoveTo3 -I (483333) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000011s0va8bom Name: -> SPITType: ActionMoveTo3 -I (483703) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000011s0va8bom Name: -> SPITType: ActionMoveTo3 -I (484613) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000011s0va8bom Name: -> SPITType: ActionMoveTo3 -I (485993) Watch: NEW SPIT-Object ID: 00000m8uedyyt00000000000000012m0va8bom Name: -> SPITType: ActionMoveTo4 -I (486063) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000012m0va8bom Name: -> SPITType: ActionMoveTo4 -I (486593) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000012m0va8bom Name: -> SPITType: ActionMoveTo4 -I (488103) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000001330va8bom Name: -> SPITType: ActionMoveTo5 -I (489273) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt0000000000000001330va8bom Name: -> SPITType: ActionMoveTo5 -I (490913) Watch: NEW SPIT-Object ID: 00000m8uedyyt00000000000000013r0va8bom Name: -> SPITType: ActionMoveTo6 -I (491043) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000013r0va8bom Name: -> SPITType: ActionMoveTo6 -I (491083) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000013r0va8bom Name: -> SPITType: ActionMoveTo6 -I (493163) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000001470va8bom Name: -> SPITType: ActionMoveTo6 -I (493243) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt0000000000000001470va8bom Name: -> SPITType: ActionMoveTo6 -I (493353) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt0000000000000001470va8bom Name: -> SPITType: ActionMoveTo6 -I (493883) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt0000000000000001470va8bom Name: -> SPITType: ActionMoveTo6 -I (503223) Watch: eventProjectReport ID: CatasWatchProject Name: CatasWatchProject FramesPerSecond: 44100 -I (503373) Watch: eventStartProjectTransfer -I (503373) Watch: SPIT-Type CHANGED ID: ActionStartShuffle GroupName: CatasWatchMovement Name: ActionStartShuffle confirmed: 1 -I (503373) Watch: SPIT-Type CHANGED ID: ActionMoveTo5 GroupName: CatasWatchMovement Name: ActionMoveTo5 confirmed: 1 -I (503383) Watch: SPIT-Type CHANGED ID: ActionMoveTo4 GroupName: CatasWatchMovement Name: ActionMoveTo4 confirmed: 1 -I (503393) Watch: SPIT-Type CHANGED ID: ActionMoveTo1 GroupName: CatasWatchMovement Name: ActionMoveTo1 confirmed: 1 -I (503413) Watch: SPIT-Type CHANGED ID: ActionMoveTo3 GroupName: CatasWatchMovement Name: ActionMoveTo3 confirmed: 1 -I (503423) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000011s0va8bom Name: -> SPITType: ActionMoveTo3 -I (503433) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt00000000000000012m0va8bom Name: -> SPITType: ActionMoveTo4 -I (503443) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt0000000000000001330va8bom Name: -> SPITType: ActionMoveTo5 -I (503453) Watch: SPIT-Object CHANGED ID: 00000m8uedyyt0000000000000001470va8bom Name: -> SPITType: ActionMoveTo6 -I (503463) Watch: SPIT-REMOTE-Type CHANGED ID: playControlStart GroupName: Playcontrol Name: start confirmed: 1 -I (503473) Watch: SPIT-REMOTE-Type CHANGED ID: playControlPause GroupName: Playcontrol Name: pause confirmed: 1 -I (503483) Watch: SPIT-REMOTE-Type CHANGED ID: nextSceneBridge GroupName: Playcontrol Name: next scene confirmed: 1 -I (503493) Watch: SPIT-REMOTE-Type CHANGED ID: nextMainSceneBridge GroupName: Playcontrol Name: next main scene confirmed: 1 -I (503513) Watch: SPIT-REMOTE-Type CHANGED ID: previuosSceneBridge GroupName: Playcontrol Name: previous scene confirmed: 1 -I (503523) Watch: SPIT-REMOTE-Type CHANGED ID: previousMainSceneBridge GroupName: Playcontrol Name: previous main scene confirmed: 1 -I (503543) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerSound_Volume00 GroupName: Main Mixer Name: Sound confirmed: 1 -I (503553) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerDMX_Dimmer00 GroupName: Main Mixer Name: confirmed: 1 -I (503573) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerDMX_RGB00 GroupName: Main Mixer Name: confirmed: 1 -I (503583) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerDMX_RGB10 GroupName: Main Mixer Name: confirmed: 1 -I (503603) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerDMX_RGB20 GroupName: Main Mixer Name: confirmed: 1 -I (503613) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerDMX_RGB30 GroupName: Main Mixer Name: confirmed: 1 -I (503633) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerDMX_RGB40 GroupName: Main Mixer Name: confirmed: 1 -I (503653) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerDMX_RGB50 GroupName: Main Mixer Name: confirmed: 1 -I (503663) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerMedia_SoundVolume00 GroupName: Main Mixer Name: Media confirmed: 1 -I (503683) Watch: SPIT-REMOTE-Type CHANGED ID: mainmixerMedia_Transparency00 GroupName: Main Mixer Name: Media confirmed: 1 -I (503693) Watch: SPIT-REMOTE-Type CHANGED ID: selectedJingles GroupName: Playcontrol Name: selected Jingles confirmed: 1 -I (503713) Watch: SPIT-REMOTE-Type CHANGED ID: selectedJingleGroups GroupName: Playcontrol Name: selected Jinglegroups confirmed: 1 -I (503723) Watch: SPIT-REMOTE-Type CHANGED ID: 00000m8uedyyt0000000000000000lo0va8bom GroupName: MainScene Name: ChangingPositionScene confirmed: 1 -I (503743) Watch: SPIT-REMOTE-Type CHANGED ID: 00000m8uedyyt0000000000000000m70va8bom GroupName: MainScene Name: InPosition1Scene confirmed: 1 -I (503753) Watch: SPIT-REMOTE-Type CHANGED ID: 00000m8uedyyt0000000000000000mh0va8bom GroupName: MainScene Name: InPosition2Scene confirmed: 1 -I (503773) Watch: SPIT-REMOTE-Type CHANGED ID: 00000m8uedyyt0000000000000000mr0va8bom GroupName: MainScene Name: InPosition3Scene confirmed: 1 -I (503793) Watch: SPIT-REMOTE-Type CHANGED ID: 00000m8uedyyt0000000000000000nk0va8bom GroupName: MainScene Name: InPosition4Scene confirmed: 1 -I (503803) Watch: SPIT-REMOTE-Type CHANGED ID: 00000m8uedyyt0000000000000000nu0va8bom GroupName: MainScene Name: InPosition5Scene confirmed: 1 -I (503823) Watch: SPIT-REMOTE-Type CHANGED ID: 00000m8uedyyt0000000000000000o40va8bom GroupName: MainScene Name: InPosition6Scene confirmed: 1 -I (503833) Watch: SPIT-REMOTE-Object CHANGED ID: playControlStart Name: start -> SPITType: start -I (503833) Watch: eventPlayRemoteObjectStatus RemoteSPITType: start RemoteSPITObject: start Position: 0 Value: 0 -I (503853) Watch: SPIT-REMOTE-Object CHANGED ID: playControlPause Name: pause -> SPITType: pause -I (503853) Watch: eventPlayRemoteObjectStatus RemoteSPITType: pause RemoteSPITObject: pause Position: 0 Value: 0 -I (503863) Watch: SPIT-REMOTE-Object CHANGED ID: nextSceneBridge Name: next scene -> SPITType: next scene -I (503873) Watch: eventPlayRemoteObjectStatus RemoteSPITType: next scene RemoteSPITObject: next scene Position: 0 Value: 0 -I (503883) Watch: SPIT-REMOTE-Object CHANGED ID: nextMainSceneBridge Name: next main scene -> SPITType: next main scene -I (503903) Watch: eventPlayRemoteObjectStatus RemoteSPITType: next main scene RemoteSPITObject: next main scene Position: 0 Value: 0 -I (503913) Watch: SPIT-REMOTE-Object CHANGED ID: previuosSceneBridge Name: previous scene -> SPITType: previous scene -I (503923) Watch: eventPlayRemoteObjectStatus RemoteSPITType: previous scene RemoteSPITObject: previous scene Position: 0 Value: 0 -I (503933) Watch: SPIT-REMOTE-Object CHANGED ID: previousMainSceneBridge Name: previous main scene -> SPITType: previous main scene -I (503953) Watch: eventPlayRemoteObjectStatus RemoteSPITType: previous main scene RemoteSPITObject: previous main scene Position: 0 Value: 0 -I (503963) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerSound_Volume00 Name: Sound Volume -> SPITType: Sound -I (503973) Watch: eventPlayRemoteObjectStatus RemoteSPITType: Sound RemoteSPITObject: Sound Volume Position: 0 Value: 500000 -I (503983) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerDMX_Dimmer00 Name: Dimmer -> SPITType: -I (503993) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Dimmer Position: 0 Value: 1000000 -I (504003) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerDMX_RGB00 Name: Red -> SPITType: -I (504013) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Red Position: 0 Value: 1000000 -I (504023) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerDMX_RGB10 Name: Green -> SPITType: -I (504033) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Green Position: 0 Value: 1000000 -I (504043) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerDMX_RGB20 Name: Blue -> SPITType: -I (504053) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerDMX_RGB30 Name: Cyan -> SPITType: -I (504063) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Cyan Position: 0 Value: 0 -I (504073) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerDMX_RGB40 Name: Magenta -> SPITType: -I (504083) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerDMX_RGB50 Name: Yellow -> SPITType: -I (504093) Watch: eventPlayRemoteObjectStatus RemoteSPITType: RemoteSPITObject: Yellow Position: 0 Value: 0 -I (504103) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerMedia_SoundVolume00 Name: Sound Volume -> SPITType: Media -I (504113) Watch: eventPlayRemoteObjectStatus RemoteSPITType: Media RemoteSPITObject: Sound Volume Position: 0 Value: 500000 -I (504123) Watch: SPIT-REMOTE-Object CHANGED ID: mainmixerMedia_Transparency00 Name: Media Transparency -> SPITType: Media -I (504133) Watch: SPIT-REMOTE-Object CHANGED ID: selectedJinglesps Name: Play / Stop -> SPITType: selected Jingles -I (504143) Watch: eventPlayRemoteObjectStatus RemoteSPITType: selected Jingles RemoteSPITObject: Play / Stop Position: 0 Value: 0 -I (504163) Watch: SPIT-REMOTE-Object CHANGED ID: selectedJinglespf Name: Play / Fade Out -> SPITType: selected Jingles -I (504173) Watch: SPIT-REMOTE-Object CHANGED ID: selectedJingleGroupsps Name: Play / Stop -> SPITType: selected Jinglegroups -I (504183) Watch: eventPlayRemoteObjectStatus RemoteSPITType: selected Jinglegroups RemoteSPITObject: Play / Stop Position: 0 Value: 0 -I (504193) Watch: SPIT-REMOTE-Object CHANGED ID: selectedJingleGroupspf Name: Play / Fade Out -> SPITType: selected Jinglegroups -I (504213) Watch: SPIT-REMOTE-Object CHANGED ID: 00000m8uedyyt0000000000000000lo0va8bom Name: play -> SPITType: ChangingPositionScene -I (504223) Watch: eventPlayRemoteObjectStatus RemoteSPITType: ChangingPositionScene RemoteSPITObject: play Position: 0 Value: 0 -I (504233) Watch: SPIT-REMOTE-Object CHANGED ID: 00000m8uedyyt0000000000000000m70va8bom Name: play -> SPITType: InPosition1Scene -I (504243) Watch: SPIT-REMOTE-Object CHANGED ID: 00000m8uedyyt0000000000000000mh0va8bom Name: play -> SPITType: InPosition2Scene -I (504253) Watch: SPIT-REMOTE-Object CHANGED ID: 00000m8uedyyt0000000000000000mr0va8bom Name: play -> SPITType: InPosition3Scene -I (504273) Watch: SPIT-REMOTE-Object CHANGED ID: 00000m8uedyyt0000000000000000nk0va8bom Name: play -> SPITType: InPosition4Scene -I (504283) Watch: SPIT-REMOTE-Object CHANGED ID: 00000m8uedyyt0000000000000000nu0va8bom Name: play -> SPITType: InPosition5Scene -I (504293) Watch: SPIT-REMOTE-Object CHANGED ID: 00000m8uedyyt0000000000000000o40va8bom Name: play -> SPITType: InPosition6Scene -I (504303) Watch: eventEndProjectTransfer -I (504433) Watch: SPIT-Type CHANGED ID: ActionMoveTo5 GroupName: CatasWatchMovement Name: ActionMoveTo5 confirmed: 1 -I (504433) Watch: SPIT-Type CHANGED ID: ActionMoveTo4 GroupName: CatasWatchMovement Name: ActionMoveTo4 confirmed: 1 -I (504443) Watch: SPIT-Type CHANGED ID: ActionMoveTo3 GroupName: CatasWatchMovement Name: ActionMoveTo3 confirmed: 1 -I (504453) Watch: SPIT-Type CHANGED ID: ActionMoveTo6 GroupName: CatasWatchMovement Name: ActionMoveTo6 confirmed: 1 -I (504463) Watch: SPIT-Type CHANGED ID: ActionMoveTo2 GroupName: CatasWatchMovement Name: ActionMoveTo2 confirmed: 1 -I (504473) Watch: SPIT-Type CHANGED ID: ActionMoveTo1 GroupName: CatasWatchMovement Name: ActionMoveTo1 confirmed: 1 +I (83) esp_image: segment 0: paddr=00010020 vaddr=42070020 size=2b2e0h (176864) map +I (128) esp_image: segment 1: paddr=0003b308 vaddr=40800000 size=04d10h ( 19728) load +I (134) esp_image: segment 2: paddr=00040020 vaddr=42000020 size=6bfe0h (442336) map +I (226) esp_image: segment 3: paddr=000ac008 vaddr=40804d10 size=094b0h ( 38064) load +I (235) esp_image: segment 4: paddr=000b54c0 vaddr=4080e1c0 size=01bd0h ( 7120) load +I (241) boot: Loaded app from partition at offset 0x10000 +I (242) boot: Disabling RNG early entropy source... +I (256) cpu_start: Unicore app +I (265) cpu_start: Pro cpu start user code +I (265) cpu_start: cpu freq: 160000000 Hz +I (265) app_init: Application information: +I (268) app_init: Project name: X_WatchController_FW +I (274) app_init: App version: 858b7d8-dirty +I (279) app_init: Compile time: Apr 8 2025 22:42:59 +I (285) app_init: ELF file SHA256: ab11b461f... +I (290) app_init: ESP-IDF: v5.3 +I (295) efuse_init: Min chip rev: v0.0 +I (300) efuse_init: Max chip rev: v0.99 +I (305) efuse_init: Chip rev: v0.0 +I (309) heap_init: Initializing. RAM available for dynamic allocation: +I (317) heap_init: At 40812120 len 0006A4F0 (425 KiB): RAM +I (323) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM +I (329) heap_init: At 50000000 len 00003FE8 (15 KiB): RTCRAM +I (336) spi_flash: detected chip: generic +I (340) spi_flash: flash io: dio +I (345) sleep: Configure to isolate all GPIO pins in sleep state +I (351) sleep: Enable automatic switching of GPIO sleep configuration +I (358) coexist: coex firmware version: dab85ae96 +I (385) coexist: coexist rom version 5b8dcfa +I (386) main_task: Started on CPU0 +I (386) main_task: Calling app_main() +I (396) esp_eth.netif.netif_glue: 42:4c:ca:ff:fe:4e +I (396) esp_eth.netif.netif_glue: ethernet attached to netif +I (406) Watch: Ethernet Started +I (406) Watch: Start Lighting +I (406) gpio: GPIO[10]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 +I (416) gpio: GPIO[11]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 1| Pulldown: 0| Intr:0 +I (426) Watch: Start Stepper +I (426) gpio: GPIO[18]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 +I (436) gpio: GPIO[8]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 +I (446) gpio: GPIO[15]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 +I (456) TMR: Create timer handle +I (456) TMR: Setup timer +I (456) Stepper: Find Home +I (466) Stepper: Homing ... +I (466) Stepper: Fast find right side of home sensor +I (486) gpio: GPIO[1]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 +I (2206) Stepper: Find right side of home sensor +I (2376) Stepper: Find end of sensor +I (2406) Watch: Ethernet Link Up +I (2406) Watch: Ethernet Link Up +I (2406) Watch: Ethernet HW Addr 00:00:00:00:00:00 +I (3406) esp_netif_handlers: eth ip: 172.16.17.56, mask: 255.255.0.0, gw: 172.16.0.1 +I (3406) Watch: Ethernet Got IP Address +I (3406) Watch: ~~~~~~~~~~~ +I (3406) Watch: ETHIP:172.16.17.56 +I (3416) Watch: ETHMASK:255.255.0.0 +I (3416) Watch: ETHGW:172.16.0.1 +I (3416) Watch: ~~~~~~~~~~~ +I (5186) Stepper: Find left side of home sensor +I (5646) Stepper: Move back to mid position 116 +I (6806) Stepper: Reset position +I (7086) Stepper: Got to 1 +I (7086) Watch: Fist Position is 0.03 +I (7106) Watch: Changing picto-Illum to pos = 0 +I (7106) Watch: Current color set r128 g128 b128 +I (13426) Watch: Start net services +I (13426) Watch: Starting Telnet task +I (13426) TCP: Socket created +I (13426) Watch: Starting ArtNet task +I (13426) TCP: Socket bound, port 23 +I (13426) Watch: Starting SPIT task +I (13426) UDP: Starting syslog session to 172.16.16.10 +I (13426) UDP: Socket bound, port 6454 +I (13436) Telnet: Socket waiting for connect +I (13436) SPIT: Connected to eth +I (13456) SPIT: - IPv4 address: 172.16.17.56, +I (13456) SPIT: - IPv4 netmask: 255.255.0.0, +I (13446) SysLog: Starting Syslog Task +I (13466) Watch: NEW SPIT-Type ID: ActionStartShuffle GroupName: CatasWatchMovement Name: ActionStartShuffle confirmed: 0 +I (13466) UDP: Socket bound, port 514 +I (13486) Watch: NEW SPIT-Type ID: ActionMoveTo1 GroupName: CatasWatchMovement Name: ActionMoveTo1 confirmed: 0 +I (13496) Watch: NEW SPIT-Type ID: ActionMoveTo2 GroupName: CatasWatchMovement Name: ActionMoveTo2 confirmed: 0 +I (13506) Watch: NEW SPIT-Type ID: ActionMoveTo3 GroupName: CatasWatchMovement Name: ActionMoveTo3 confirmed: 0 +I (13516) Watch: NEW SPIT-Type ID: ActionMoveTo4 GroupName: CatasWatchMovement Name: ActionMoveTo4 confirmed: 0 +I (13526) Watch: NEW SPIT-Type ID: ActionMoveTo5 GroupName: CatasWatchMovement Name: ActionMoveTo5 confirmed: 0 +I (13536) Watch: NEW SPIT-Type ID: ActionMoveTo6 GroupName: CatasWatchMovement Name: ActionMoveTo6 confirmed: 0 +I (13546) SPIT: Starting Socket managing +I (17656) Watch: SERVER DETECTED +I (17656) Watch: Name: liveShowSPIT +I (17656) Watch: ID: 698a3e4f-1ae9-4dd8-9015-29332d29629e +I (17656) Watch: Computer: GgP17 +I (17656) Watch: IP: 172.16.16.10 +I (17666) Watch: Port: 15120 +I (17666) Watch: Addition: +I (17666) Watch: ClientIP: 172.16.17.56 +I (17676) SPIT: connect to 172.16.16.10 / 15120 +I (17676) Watch: MySPITApp: eventConnectionStatus 0->0 +I (17686) Watch: MySPITApp: eventConnectionStatus 0->4 +I (18196) Watch: eventProjectReport ID: CatasWatchProject +I (18196) Watch: eventStartProjectTransfer +W (18306) SPIT: TypeVeto e019646a-4e24-4608-954e-da4ca6761bb6 / ToIgnore 43 +I (18326) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000002sb0va8bom Name: -> SPITType: ActionStartShuffle +I (18336) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000002rd0va8bom Name: -> SPITType: ActionMoveTo1 +I (18356) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000002vl0va8bom Name: -> SPITType: ActionMoveTo2 +I (18366) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000002wh0va8bom Name: -> SPITType: ActionMoveTo3 +I (18386) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000002yl0va8bom Name: -> SPITType: ActionMoveTo4 +I (18396) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000002tc0va8bom Name: -> SPITType: ActionMoveTo5 +I (18416) Watch: NEW SPIT-Object ID: 00000m8uedyyt0000000000000002zi0va8bom Name: -> SPITType: ActionMoveTo6 +I (18446) Watch: Min heap size: 297568 / FreeHeap 299880 +I (18446) Watch: NEW SPIT-REMOTE-Type ID: playControlStart GroupName: Playcontrol Name: start confirmed: 1 +I (18466) Watch: NEW SPIT-REMOTE-Type ID: playControlPause GroupName: Playcontrol Name: pause confirmed: 1 +I (18476) Watch: NEW SPIT-REMOTE-Type ID: nextSceneBridge GroupName: Playcontrol Name: next scene confirmed: 1 +I (18496) Watch: NEW SPIT-REMOTE-Type ID: nextMainSceneBridge GroupName: Playcontrol Name: next main scene confirmed: 1 +I (18506) Watch: NEW SPIT-REMOTE-Type ID: previuosSceneBridge GroupName: Playcontrol Name: previous scene confirmed: 1 +I (18526) Watch: NEW SPIT-REMOTE-Type ID: previousMainSceneBridge GroupName: Playcontrol Name: previous main scene confirmed: 1 +I (18546) Watch: NEW SPIT-REMOTE-Type ID: mainmixerSound_Volume00 GroupName: Main Mixer Name: Sound confirmed: 1 +I (18556) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_Dimmer00 GroupName: Main Mixer Name: confirmed: 1 +I (18566) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB00 GroupName: Main Mixer Name: confirmed: 1 +I (18586) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB10 GroupName: Main Mixer Name: confirmed: 1 +I (18606) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB20 GroupName: Main Mixer Name: confirmed: 1 +I (18616) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB30 GroupName: Main Mixer Name: confirmed: 1 +I (18636) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB40 GroupName: Main Mixer Name: confirmed: 1 +I (18646) Watch: NEW SPIT-REMOTE-Type ID: mainmixerDMX_RGB50 GroupName: Main Mixer Name: confirmed: 1 +I (18666) Watch: NEW SPIT-REMOTE-Type ID: mainmixerMedia_SoundVolume00 GroupName: Main Mixer Name: Media confirmed: 1 +I (18686) Watch: NEW SPIT-REMOTE-Type ID: mainmixerMedia_Transparency00 GroupName: Main Mixer Name: Media confirmed: 1 +I (18696) Watch: NEW SPIT-REMOTE-Type ID: selectedJingles GroupName: Playcontrol Name: selected Jingles confirmed: 1 +I (18716) Watch: NEW SPIT-REMOTE-Type ID: selectedJingleGroups GroupName: Playcontrol Name: selected Jinglegroups confirmed: 1 +I (18726) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000lo0va8bom GroupName: MainScene Name: ChangingPositionScene confirmed: 1 +I (18746) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000m70va8bom GroupName: MainScene Name: InPosition1Scene confirmed: 1 +I (18756) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000mh0va8bom GroupName: MainScene Name: InPosition2Scene confirmed: 1 +I (18776) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000mr0va8bom GroupName: MainScene Name: InPosition3Scene confirmed: 1 +I (18786) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000nk0va8bom GroupName: MainScene Name: InPosition4Scene confirmed: 1 +I (18806) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000nu0va8bom GroupName: MainScene Name: InPosition5Scene confirmed: 1 +I (18826) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000000o40va8bom GroupName: MainScene Name: InPosition6Scene confirmed: 1 +I (18836) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000001au0va8bom GroupName: MainScene Name: StartShuffle confirmed: 1 +I (18856) Watch: NEW SPIT-REMOTE-Type ID: 00000m8uedyyt0000000000000001fj0va8bom GroupName: MainScene Name: Fence confirmed: 1 +I (18866) Watch: NEW SPIT-REMOTE-Object ID: playControlStart Name: start -> SPITType: start +I (18886) Watch: NEW SPIT-REMOTE-Object ID: playControlPause Name: pause -> SPITType: pause +I (18906) Watch: NEW SPIT-REMOTE-Object ID: nextSceneBridge Name: next scene -> SPITType: next scene +I (18916) Watch: NEW SPIT-REMOTE-Object ID: nextMainSceneBridge Name: next main scene -> SPITType: next main scene +I (18936) Watch: NEW SPIT-REMOTE-Object ID: previuosSceneBridge Name: previous scene -> SPITType: previous scene +I (18946) Watch: NEW SPIT-REMOTE-Object ID: previousMainSceneBridge Name: previous main scene -> SPITType: previous main scene +I (18966) Watch: NEW SPIT-REMOTE-Object ID: mainmixerSound_Volume00 Name: Sound Volume -> SPITType: Sound +I (18976) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_Dimmer00 Name: Dimmer -> SPITType: +I (18996) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB00 Name: Red -> SPITType: +I (19006) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB10 Name: Green -> SPITType: +I (19026) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB20 Name: Blue -> SPITType: +I (19036) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB30 Name: Cyan -> SPITType: +I (19056) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB40 Name: Magenta -> SPITType: +I (19076) Watch: NEW SPIT-REMOTE-Object ID: mainmixerDMX_RGB50 Name: Yellow -> SPITType: +I (19086) Watch: NEW SPIT-REMOTE-Object ID: mainmixerMedia_SoundVolume00 Name: Sound Volume -> SPITType: Media +I (19106) Watch: NEW SPIT-REMOTE-Object ID: mainmixerMedia_Transparency00 Name: Media Transparency -> SPITType: Media +I (19116) Watch: NEW SPIT-REMOTE-Object ID: selectedJinglesps Name: Play / Stop -> SPITType: selected Jingles +I (19136) Watch: NEW SPIT-REMOTE-Object ID: selectedJinglespf Name: Play / Fade Out -> SPITType: selected Jingles +I (19146) Watch: NEW SPIT-REMOTE-Object ID: selectedJingleGroupsps Name: Play / Stop -> SPITType: selected Jinglegroups +I (19166) Watch: NEW SPIT-REMOTE-Object ID: selectedJingleGroupspf Name: Play / Fade Out -> SPITType: selected Jinglegroups +I (19176) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000lo0va8bom Name: play -> SPITType: ChangingPositionScene +W (19196) SPIT: Finished searching +W (19196) SPIT: Start working +I (19196) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000m70va8bom Name: play -> SPITType: InPosition1Scene +I (19216) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000mh0va8bom Name: play -> SPITType: InPosition2Scene +I (19226) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000mr0va8bom Name: play -> SPITType: InPosition3Scene +I (19246) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000nk0va8bom Name: play -> SPITType: InPosition4Scene +I (19256) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000nu0va8bom Name: play -> SPITType: InPosition5Scene +I (19276) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000000o40va8bom Name: play -> SPITType: InPosition6Scene +I (19286) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000001au0va8bom Name: play -> SPITType: StartShuffle +I (19306) Watch: NEW SPIT-REMOTE-Object ID: 00000m8uedyyt0000000000000001fj0va8bom Name: play -> SPITType: Fence +I (19316) Watch: eventEndProjectTransfer +I (19316) Watch: eventProjectReport ID: CatasWatchProject Name: FramesPerSecond: 44100 +I (23446) Watch: Min heap size: 278024 / FreeHeap 282460 +I (28446) Watch: Min heap size: 278024 / FreeHeap 282460 +I (33446) Watch: Min heap size: 278024 / FreeHeap 282460 +I (38446) Watch: Min heap size: 278024 / FreeHeap 282460 +I (43446) Watch: Min heap size: 278024 / FreeHeap 282460 \ No newline at end of file diff --git a/doc/LiveShowProject/CatasWatchProject.ldv b/doc/LiveShowProject/CatasWatchProject.ldv index 7e827f5..1e63f22 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.ldv and b/doc/LiveShowProject/CatasWatchProject.ldv differ diff --git a/doc/LiveShowProject/CatasWatchProject.lmv b/doc/LiveShowProject/CatasWatchProject.lmv index 7d346ae..9bf5d80 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lmv and b/doc/LiveShowProject/CatasWatchProject.lmv differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsc b/doc/LiveShowProject/CatasWatchProject.lsc index b0c0567..d7a1d1b 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsc and b/doc/LiveShowProject/CatasWatchProject.lsc differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsd b/doc/LiveShowProject/CatasWatchProject.lsd index d3b6637..58223a0 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsd and b/doc/LiveShowProject/CatasWatchProject.lsd differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsf b/doc/LiveShowProject/CatasWatchProject.lsf index fbb39bc..aaa88e0 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsf and b/doc/LiveShowProject/CatasWatchProject.lsf differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsh b/doc/LiveShowProject/CatasWatchProject.lsh index c5f9c06..229de58 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsh and b/doc/LiveShowProject/CatasWatchProject.lsh differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsp b/doc/LiveShowProject/CatasWatchProject.lsp index 4cfe637..19cdd3b 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsp and b/doc/LiveShowProject/CatasWatchProject.lsp differ diff --git a/doc/LiveShowProject/CatasWatchProject.lss b/doc/LiveShowProject/CatasWatchProject.lss index 7f842f9..bfa76d2 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lss and b/doc/LiveShowProject/CatasWatchProject.lss differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsv b/doc/LiveShowProject/CatasWatchProject.lsv index 435b4dd..a56eb0e 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsv and b/doc/LiveShowProject/CatasWatchProject.lsv differ diff --git a/doc/LiveShowProject/CatasWatchProject.lsx b/doc/LiveShowProject/CatasWatchProject.lsx index de1b114..82a165c 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.lsx and b/doc/LiveShowProject/CatasWatchProject.lsx differ diff --git a/doc/LiveShowProject/CatasWatchProject.spi b/doc/LiveShowProject/CatasWatchProject.spi index a184f1b..08fa45d 100644 Binary files a/doc/LiveShowProject/CatasWatchProject.spi and b/doc/LiveShowProject/CatasWatchProject.spi differ diff --git a/main/watchMain.cpp b/main/watchMain.cpp index 5c1bb8c..6fd3d97 100644 --- a/main/watchMain.cpp +++ b/main/watchMain.cpp @@ -694,8 +694,9 @@ void onServerEvent(SPIT_Client::ServerEvent event, const SAD_DetectedServer &p_D } } -void onConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus) { - ESP_LOGI(TAG, "MySPITApp: eventConnectionStatus %d ", p_ConnectionStatus); +void onConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, + SPIT_Client::Connection p_ConnectionStatus, SPIT_Client::Connection p_OldConnectionStatus) { + ESP_LOGI(TAG, "MySPITApp: eventConnectionStatus %d->%d ", (int)p_OldConnectionStatus, (int)p_ConnectionStatus); } // The transfer of the server's SPITTypes and SPITObjects is finished. @@ -725,153 +726,107 @@ void onProjectUpdate(SPIT_Client::ProjUpdate state, string projectId) { } } -/** - * The SPITCLientInterface (implemented by this) will be asked to veto the SPITType while SPIT_Client.parseReportSPITType.
- * @param p_ReportSPITType - * @return false = the SPITType is denied, true = the SPITType is accepted - */ -bool onCheckSpitTypeVeto(SPIT_Message::ReportSPITType *p_ReportSPITType) { - return true; // Bypass veto - - if (p_ReportSPITType == NULL) - return true; - SPITType *ptrSPITType; - ptrSPITType = SPITType::getSPITType(p_ReportSPITType->getID()); - - // Don't allow foreign SPITTypes - if (ptrSPITType == NULL) { - // ESP_LOGW(TAG, "ObjectVeto NoSpitType"); - return false; - } - if (ptrSPITType->getCreatedByClient() == false) { - // ESP_LOGW(TAG, "getCreatedByClient"); - return false; - } - return true; -} - -bool onCheckSpitObjectVeto(SPIT_Message::ReportSPITObject *p_ReportSPITObject) { - return true; // Bypass veto - - if (p_ReportSPITObject == NULL) - return true; - SPITType *ptrSPITType = SPITType::getSPITType(p_ReportSPITObject->getSPITTypeID()); - if (ptrSPITType == NULL) { - // ESP_LOGW(TAG, "ObjectVeto NoSpitObj"); - return false; - } - - // Don't allow SPITObjects which refers to a SPITType which is not created by this client - other SPITTypes cannot be handled here - if (ptrSPITType->getCreatedByClient() == false) { - // ESP_LOGW(TAG, "getCreatedByClient"); - return false; - } - SPITObject *ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITObject->getID()); - // Don't allow foreign SPITTypes - if (ptrSPITObject == NULL) { - // ESP_LOGE(TAG, "Unknown ID"); +bool onCheckSpitTypeVeto(bool knownType, bool createdByClient) { + if (!knownType || !createdByClient) { // Don't allow foreign SPITTypes return false; } return true; } -// Called when the server has created, loaded, changed or deleted a SPITType. +bool onCheckSpitObjectVeto(bool knownType) { + return true; // Bypass veto + if (!knownType) { // Don't allow objects of unregistered SPITTypes + return false; + } + + return true; +} + +// Called when the server has created, loaded, changed or deleted a (Remote) SPITType. +// Remote SPITType are used in Remote SPITObjects. A Remote SPITObject is used to remote control the SPITServer. // May also occur when the server confirms a SPITType created or changed by the client. -void onSpitType(SPIT_Client::ObjectEvent event, const SPITType &p_SPITType) { - if (event == SPIT_Client::ObjectEvent::Created) { - // Whenever you provide an action for this SPITType take this over in your code. - // call _SpitClient.setActionSPITType(p_SPITType.getID(), true); - ESP_LOGI(TAG, "NEW SPIT-Type ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed()); - } else if (event == SPIT_Client::ObjectEvent::Changed) { - ESP_LOGI(TAG, "SPIT-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed()); - } else if (event == SPIT_Client::ObjectEvent::Deleted) { - ESP_LOGI(TAG, "SPIT-Type Removed ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data()); - } -} - -/** - * Called when the server has created or changed a Remote SPITType. - * Remote SPITType are used in Remote SPITObjects. A Remote SPITObject is used to remote control the SPITServer. - * @param p_New true = server created a new SPITType / false = server changed a existing SPITType - */ -void onSpitTypeRemote(SPIT_Client::ObjectEvent event, const SPITType &p_SPITType) { - if (event == SPIT_Client::ObjectEvent::Created) { - ESP_LOGI(TAG, "NEW SPIT-REMOTE-Type ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed()); - auto typeName = p_SPITType.getName(); - if (ExpectedObjects.contains(typeName)) { - ExpectedObjects[typeName] = p_SPITType.getID(); - } - } else if (event == SPIT_Client::ObjectEvent::Changed) { - // we had to inform all Remote SPITObjects using the p_SPITType - // perhaps the SPITObject uses information from the SPITType - SPITObject *ptrSPITObject; - int intSPITObjectCount; - intSPITObjectCount = SPITObject::getSPITObjectRemoteCount(); - for (int intObject = 0; intObject < intSPITObjectCount; intObject++) { - ptrSPITObject = SPITObject::getSPITObjectRemote(intObject); - if (ptrSPITObject == NULL) - continue; - if (ptrSPITObject->getSPITTypeID() == p_SPITType.getID()) { - // call ecentSPITObjectRemote - // onSpitObjectRemote(SPIT_Client::ObjectEvent::Changed, p_SPITType, *ptrSPITObject); +void onSpitType(SPIT_Client::ObjectEvent event, bool isRemote, const SPITType &p_SPITType) { + if (isRemote) { + if (event == SPIT_Client::ObjectEvent::Created) { + ESP_LOGI(TAG, "NEW SPIT-REMOTE-Type ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed()); + auto typeName = p_SPITType.getName(); + if (ExpectedObjects.contains(typeName)) { + ExpectedObjects[typeName] = p_SPITType.getID(); } + } else if (event == SPIT_Client::ObjectEvent::Changed) { + // we had to inform all Remote SPITObjects using the p_SPITType + // perhaps the SPITObject uses information from the SPITType + // SPITObject *ptrSPITObject; + // int intSPITObjectCount; + // intSPITObjectCount = SPITObject::getSPITObjectRemoteCount(); + // for (int intObject = 0; intObject < intSPITObjectCount; intObject++) { + // ptrSPITObject = SPITObject::getSPITObjectRemote(intObject); + // if (ptrSPITObject == nullptr) + // continue; + // if (ptrSPITObject->getSPITTypeID() == p_SPITType.getID()) { + // // call ecentSPITObjectRemote + // // onSpitObjectRemote(SPIT_Client::ObjectEvent::Changed, p_SPITType, *ptrSPITObject); + // } + // } + ESP_LOGI(TAG, "SPIT-REMOTE-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed()); + } else if (event == SPIT_Client::ObjectEvent::Deleted) { + ESP_LOGD(TAG, "SPIT-REMOTE-Type Removed ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data()); + } + } else { + if (event == SPIT_Client::ObjectEvent::Created) { + // Whenever you provide an action for this SPITType take this over in your code. + // call _SpitClient.setActionSPITType(p_SPITType.getID(), true); + ESP_LOGI(TAG, "NEW SPIT-Type ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed()); + } else if (event == SPIT_Client::ObjectEvent::Changed) { + ESP_LOGI(TAG, "SPIT-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed()); + } else if (event == SPIT_Client::ObjectEvent::Deleted) { + ESP_LOGI(TAG, "SPIT-Type Removed ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data()); } - ESP_LOGI(TAG, "SPIT-REMOTE-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data(), p_SPITType.getConfirmed()); - } else if (event == SPIT_Client::ObjectEvent::Deleted) { - ESP_LOGD(TAG, "SPIT-REMOTE-Type Removed ID: %s GroupName: %s Name: %s\n", p_SPITType.getID().data(), p_SPITType.getGroupName().data(), p_SPITType.getName().data()); } } -/** - * Called when the server has created, loaded or changed a SPITObject. - * May also occur when the server confirms a SPITObject created by the client, what the client should never do!!. - * false = server changed a existing SPITObject - * @param p_SPITType a reference to a copy of the associated SPITType instance. - * @param p_SPITObject a reference to a copy of the SPITObject instance. - */ -void onSpitObject(SPIT_Client::ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject) { - if (event == SPIT_Client::ObjectEvent::Created) { - ESP_LOGI(TAG, "NEW SPIT-Object ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data()); - // check your actions - // Whenever you provide an action for this SPITObject take this over in your code. - // call _SpitClient.setActionSPITObject(p_SPITObject.getID(), true); +// Called when the server has created, loaded or changed a SPITObject. +// A Remote SPITObject is used to remote control the SPITServer. +// May also occur when the server confirms a SPITObject created by the client, what the client should never do!!. +// false = server changed a existing SPITObject +// @param p_SPITType a reference to a copy of the associated SPITType instance. +// @param p_SPITObject a reference to a copy of the SPITObject instance. +void onSpitObject(SPIT_Client::ObjectEvent event, bool isRemote, const SPITType &p_SPITType, const SPITObject &p_SPITObject) { + if (isRemote) { + if (event == SPIT_Client::ObjectEvent::Created) { + ESP_LOGI(TAG, "NEW SPIT-REMOTE-Object ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data()); + // This is a remote SPITObject which can be used to remote control the server. + // If you want you can list this for later use + } else if (event == SPIT_Client::ObjectEvent::Changed) { + ESP_LOGI(TAG, "SPIT-REMOTE-Object CHANGED ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data()); + } else if (event == SPIT_Client::ObjectEvent::Deleted) { + ESP_LOGD(TAG, "SPIT-REMOTE-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data()); + // This is a remote SPITObject + // If you have listet this prior you should remove it from the list + } + } else { + if (event == SPIT_Client::ObjectEvent::Created) { + ESP_LOGI(TAG, "NEW SPIT-Object ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data()); + // check your actions + // Whenever you provide an action for this SPITObject take this over in your code. + // call _SpitClient.setActionSPITObject(p_SPITObject.getID(), true); - // for our little excample as described in loadClientProject: - // We have only actions for SPITTypes - means every SPITObject with the associated "Actionx"-SPITTypes will trigger the action when it is played - //-> no need to do something here, because setActionSPITType has been set prior and the SPITObject will automatically inherits this - // SPITObjects with other SPITTypes asscciated will trigger no actions + // for our little excample as described in loadClientProject: + // We have only actions for SPITTypes - means every SPITObject with the associated "Actionx"-SPITTypes will trigger the action when it is played + //-> no need to do something here, because setActionSPITType has been set prior and the SPITObject will automatically inherits this + // SPITObjects with other SPITTypes asscciated will trigger no actions - } else if (event == SPIT_Client::ObjectEvent::Changed) { - ESP_LOGI(TAG, "SPIT-Object CHANGED ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data()); - } else if (event == SPIT_Client::ObjectEvent::Deleted) { - ESP_LOGD(TAG, "SPIT-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data()); - // Check your actions - // take the removal of the SPITObject over in your code + } else if (event == SPIT_Client::ObjectEvent::Changed) { + ESP_LOGI(TAG, "SPIT-Object CHANGED ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data()); + } else if (event == SPIT_Client::ObjectEvent::Deleted) { + ESP_LOGD(TAG, "SPIT-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data()); + // Check your actions + // take the removal of the SPITObject over in your code - // CAUTION: Deleted SPITObjects can be added later again (perhaps per UNDO on the SPITServer) - //-> don't remove your assigned action immediately - keep it to reassign it later - } -} -/** - * Called when the server has created or changed a Remote SPITObject. - * A Remote SPITObject is used to remote control the SPITServer. - * @param p_New true = server created a new remote SPITObject - * false = server changed a existing remote SPITObject - * @param p_SPITType a reference to a copy of the associated SPITType instance. - * @param p_SPITObject a reference to a copy of the SPITObject instance. - */ -void onSpitObjectRemote(SPIT_Client::ObjectEvent event, const SPITType &p_SPITType, const SPITObject &p_SPITObject) { - if (event == SPIT_Client::ObjectEvent::Created) { - ESP_LOGI(TAG, "NEW SPIT-REMOTE-Object ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data()); - // This is a remote SPITObject which can be used to remote control the server. - // If you want you can list this for later use - } else if (event == SPIT_Client::ObjectEvent::Changed) { - ESP_LOGI(TAG, "SPIT-REMOTE-Object CHANGED ID: %s Name: %s -> SPITType: %s", p_SPITObject.getID().data(), p_SPITObject.getName().data(), p_SPITType.getName().data()); - } else if (event == SPIT_Client::ObjectEvent::Deleted) { - ESP_LOGD(TAG, "SPIT-REMOTE-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data()); - // This is a remote SPITObject - // If you have listet this prior you should remove it from the list + // CAUTION: Deleted SPITObjects can be added later again (perhaps per UNDO on the SPITServer) + //-> don't remove your assigned action immediately - keep it to reassign it later + } } } @@ -927,7 +882,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() { @@ -951,9 +906,7 @@ void SpitClientApp() { .onConnectionStatus = onConnectionStatus, .onProjectUpdate = onProjectUpdate, .onSpitType = onSpitType, - .onSpitTypeRemote = onSpitTypeRemote, .onSpitObject = onSpitObject, - .onSpitObjectRemote = onSpitObjectRemote, .onPlay = onPlay, .onPlaySpitType = onPlaySpitType, .onPlayRemoteObjectStatus = onPlayRemoteObjectStatus, @@ -1034,5 +987,9 @@ void app_main(void) { fos::Task::delayMs(5000); // ToDo send Syslog::logv(Syslog::Severity::Notice, "Health state"); + // ESP_LOGI(TAG, "Min heap size: %" PRIu32 " / FreeHeap %" PRIu32 "\n", + ESP_LOGI(TAG, "Min heap size: %u / FreeHeap %lu", + heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT), + esp_get_free_heap_size()); } }