refactor: Heavy refactoring of SPIT
This commit is contained in:
@@ -1,150 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <list>
|
|
||||||
#include <memory>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class SAD_DetectedServer;
|
|
||||||
class I_SAD_Client {
|
|
||||||
public:
|
|
||||||
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) {
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
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; }
|
|
||||||
string getName() const { return m_Name; }
|
|
||||||
string getComputerName() const { return m_ComputerName; }
|
|
||||||
string getIP() const { return m_IP; }
|
|
||||||
string getPort() const { return m_Port; }
|
|
||||||
string getClientIP() const { return m_ClientIP; }
|
|
||||||
string getAdditions() const { return m_Additions; }
|
|
||||||
string getProjectName() const { return m_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 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 resetFlags() {
|
|
||||||
m_Changed = false;
|
|
||||||
m_FoundAgain = false;
|
|
||||||
m_New = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
static unordered_map<string, unique_ptr<SAD_DetectedServer>> sKnownServers;
|
|
||||||
|
|
||||||
public:
|
|
||||||
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 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(unique_ptr<SAD_DetectedServer> 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 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.<br>
|
|
||||||
* If no DetectedServer is found an eyception is thrown.
|
|
||||||
* @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(const string &id) {
|
|
||||||
return *sKnownServers.at(id);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,147 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* File: SPITObject.h
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 9. April 2019, 12:11
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SPITOBJECT_H
|
|
||||||
#define SPITOBJECT_H
|
|
||||||
|
|
||||||
#include "SPITType.h"
|
|
||||||
#include "spit_message.hpp"
|
|
||||||
#include "spit_repo.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace spit;
|
|
||||||
|
|
||||||
class SPITObjectListener;
|
|
||||||
|
|
||||||
class SPITObject {
|
|
||||||
public:
|
|
||||||
static void clearUnconfirmedSPITObjects(SpitRepo<SPITObject> &repo);
|
|
||||||
static void setConfirmedFalse(SpitRepo<SPITObject> &repo);
|
|
||||||
static void eventProjectClosed(SpitRepo<SPITObject> &repo, SpitRepo<SPITObject> &remoteRepo);
|
|
||||||
|
|
||||||
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{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;
|
|
||||||
|
|
||||||
public:
|
|
||||||
string getID() const { return m_ID; }
|
|
||||||
string getName() const { return m_Name; }
|
|
||||||
string getRemark() const { return m_Remark; }
|
|
||||||
string getSPITTypeID() const { return m_SPITTypeID; }
|
|
||||||
string getServerParams() const { return m_ServerParams; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
* 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; }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
bool getConfirmed() const { return m_Confirmed; }
|
|
||||||
bool getFixed() const { return m_Fixed; }
|
|
||||||
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.
|
|
||||||
* 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
|
|
||||||
* the user has asscociated an action with the SPITType of this SPITObject
|
|
||||||
*/
|
|
||||||
bool getActionAssigned() const { return m_ActionAssigned || m_ActionAssignedType; }
|
|
||||||
|
|
||||||
long long getFrameStart() const { return m_FrameStart; }
|
|
||||||
// contains the length of the SPITObject
|
|
||||||
long long getFrameLength() const { return m_FrameLength; }
|
|
||||||
long long getFrameFadeInLength() const { return m_FrameFadeInLength; }
|
|
||||||
long long getFrameFadeOutLength() const { return m_FrameFadeOutLength; }
|
|
||||||
char getValueUse() const { return m_ValueUse; }
|
|
||||||
int getValueFactor() const { return m_ValueFactor; }
|
|
||||||
int getTrack() const { return m_Track; }
|
|
||||||
|
|
||||||
long long getDelay() const { return m_Delay; }
|
|
||||||
long long getDuration() const { return m_Duration; }
|
|
||||||
|
|
||||||
bool getProjectIndepended(SpitRepo<SPITType> &repo, SpitRepo<SPITType> &remoteRepo) const {
|
|
||||||
SPITType *ptrSPITType;
|
|
||||||
if (m_ServerRemote == false) {
|
|
||||||
ptrSPITType = repo.getEntry(m_SPITTypeID);
|
|
||||||
if (ptrSPITType == nullptr)
|
|
||||||
return true;
|
|
||||||
return ptrSPITType->getProjectIndepended();
|
|
||||||
} else {
|
|
||||||
ptrSPITType = remoteRepo.getEntry(m_SPITTypeID);
|
|
||||||
if (ptrSPITType == nullptr)
|
|
||||||
return true;
|
|
||||||
return ptrSPITType->getProjectIndepended();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
bool setConfirmed(bool p_Confirmed);
|
|
||||||
void setCreatedByClient(bool p_CreatedByClient) { m_CreatedByClient = p_CreatedByClient; }
|
|
||||||
bool setName(string p_Name);
|
|
||||||
bool setRemark(string p_Remark);
|
|
||||||
bool setServerParams(string p_ServerParams);
|
|
||||||
bool setSPITTypeID(string p_GroupName);
|
|
||||||
bool setServerRemote(bool p_BelongstoServer);
|
|
||||||
bool setActionAssignedType(bool p_ActionAssigned);
|
|
||||||
bool setActionAssigned(bool p_ActionAssigned);
|
|
||||||
bool setFixed(bool p_Fixed);
|
|
||||||
bool setFrameStart(long long p_FrameStart);
|
|
||||||
bool setFrameLength(long long p_FrameLength);
|
|
||||||
bool setFrameFadeInLength(long long p_FrameFadeInLength);
|
|
||||||
bool setFrameFadeOutLength(long long p_FrameFadeOutLength);
|
|
||||||
bool setValueUse(char p_ValueUse);
|
|
||||||
bool setValueFactor(int p_ValueFactor);
|
|
||||||
bool setTrack(int p_Track);
|
|
||||||
bool setDelay(long long p_Delay);
|
|
||||||
bool setDuration(long long p_Duration);
|
|
||||||
|
|
||||||
bool setMessageOP(Message::ReportObject *p_ReportSPITObject);
|
|
||||||
void fillMessageOP(Message::ReportObject &p_ReportSPITObject);
|
|
||||||
void fillMessageOP(Message::RemoveObject &p_RemoveSPITObject);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* SPITOBJECT_H */
|
|
||||||
@@ -1,92 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* File: SPITPLayer.h
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 30. April 2019, 11:44
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SPITPLAYER_H
|
|
||||||
#define SPITPLAYER_H
|
|
||||||
|
|
||||||
#include "SPITObject.h"
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
class SPITPlayer {
|
|
||||||
|
|
||||||
//----- PlayObject used in PlaySequences: PlaySPITStart, PlaySPITObject,..., PlaySPITEnd ------
|
|
||||||
public:
|
|
||||||
class PlaySPITType {
|
|
||||||
public:
|
|
||||||
PlaySPITType(SPITPlayer *p_SPITPlayer, string p_SPITObjectID);
|
|
||||||
PlaySPITType(const PlaySPITType &orig);
|
|
||||||
|
|
||||||
string getSPITTypeID() const { return m_SPITTypeID; }
|
|
||||||
|
|
||||||
void startPlaySequence();
|
|
||||||
bool getIsNew() const { return m_IsNew; }
|
|
||||||
void setIsNew(bool p_IsNew) { m_IsNew = p_IsNew; }
|
|
||||||
bool getIsPlayed() const { return m_IsPlayed; }
|
|
||||||
void setIsPlayed(bool p_IsFound) { m_IsPlayed = p_IsFound; }
|
|
||||||
string getPlayerID() const { return m_PlayerID; }
|
|
||||||
string getPlayerName() const { return m_PlayerName; }
|
|
||||||
bool getPlayerIsRunning() const { return m_PlayerRuns; }
|
|
||||||
void setPlayerIsRunning(bool p_PlayerRuns) { m_PlayerRuns = p_PlayerRuns; }
|
|
||||||
void setValue(double p_Value) { m_Value = p_Value; }
|
|
||||||
void addValue(double p_Value, double p_ValueFactor) { m_Value += (p_Value * p_ValueFactor); }
|
|
||||||
double getValue() const { return m_Value; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
string m_PlayerID;
|
|
||||||
string m_PlayerName;
|
|
||||||
bool m_PlayerRuns;
|
|
||||||
string m_SPITTypeID;
|
|
||||||
bool m_IsPlayed;
|
|
||||||
bool m_IsNew;
|
|
||||||
double m_Value;
|
|
||||||
};
|
|
||||||
|
|
||||||
//----- SPITPlayer ------
|
|
||||||
public:
|
|
||||||
// list the SPITPlayers
|
|
||||||
static unordered_map<string, unique_ptr<SPITPlayer>> 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();
|
|
||||||
|
|
||||||
void startPlaySequence(); // called by SPIT_Client::parsePlaySPITStart
|
|
||||||
PlaySPITType *addSPITType_Playing(string p_SPITTypeID); // called by SPIT_Client::parsePlaySPITStart
|
|
||||||
void endPlaySequence(); // called by SPIT_Client::parsePlaySPITEnd
|
|
||||||
|
|
||||||
string getID() {
|
|
||||||
return m_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
unordered_map<string, unique_ptr<PlaySPITType>> &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() 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<string, unique_ptr<PlaySPITType>> m_PlaySPITTypes;
|
|
||||||
|
|
||||||
bool m_IsRunning;
|
|
||||||
long long m_TimeFrames;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* SPITPLAYER_H */
|
|
||||||
@@ -1,149 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* SPITSocket is the base class for WindowsSocket, UnixSocket,.
|
|
||||||
* Used by SPIT_Client and SAD_Client.
|
|
||||||
* File: SPITSocket.h
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 12. April 2019, 15:40
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SPITSOCKET_H
|
|
||||||
#define SPITSOCKET_H
|
|
||||||
|
|
||||||
#include "Task.hpp"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include "esp_netif.h"
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <string>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
/** Returns an guid */
|
|
||||||
string createGUID();
|
|
||||||
/** Returns the name of the client's host computer*/
|
|
||||||
string getClientHostName();
|
|
||||||
|
|
||||||
class SPITSocket {
|
|
||||||
public:
|
|
||||||
static const int FAMILY_IP4 = AF_INET;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* IPAddress class is used to fetch all available IP addresses of the computer
|
|
||||||
* This is for internal usage
|
|
||||||
*/
|
|
||||||
struct IPAddress {
|
|
||||||
public:
|
|
||||||
IPAddress(const string &p_IPAddress, const string &p_SubnetMask)
|
|
||||||
: m_IPAddress(p_IPAddress), m_SubnetMask(p_SubnetMask) {}
|
|
||||||
const string m_IPAddress;
|
|
||||||
const string m_SubnetMask;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculates the broadcast address from a ip4 address
|
|
||||||
* @param p_IPAddress the ip4 address
|
|
||||||
* @return returns the broadcast address
|
|
||||||
*/
|
|
||||||
string getBroadcastIP4() const {
|
|
||||||
struct in_addr broadcast;
|
|
||||||
unsigned long ulIPAddress;
|
|
||||||
unsigned long ulSubnetMask;
|
|
||||||
|
|
||||||
ulIPAddress = inet_addr(m_IPAddress.data());
|
|
||||||
ulSubnetMask = inet_addr(m_SubnetMask.data());
|
|
||||||
broadcast.s_addr = ulIPAddress | ~ulSubnetMask;
|
|
||||||
|
|
||||||
return inet_ntoa(broadcast);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const IPAddress mOwnIp;
|
|
||||||
static IPAddress getAdaptersInfo();
|
|
||||||
bool createSocket_UDP();
|
|
||||||
static const int INVALID_SOCKET = -1;
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_UDPSocketIP4;
|
|
||||||
|
|
||||||
public:
|
|
||||||
//-------- class --------------
|
|
||||||
SPITSocket(IPAddress ip) : mOwnIp(ip) {
|
|
||||||
m_UDPSocketIP4 = INVALID_SOCKET;
|
|
||||||
createSocket_UDP();
|
|
||||||
}
|
|
||||||
virtual ~SPITSocket() {
|
|
||||||
ESP_LOGD("UDP", "Shutting down ...");
|
|
||||||
|
|
||||||
if (m_UDPSocketIP4 != INVALID_SOCKET) {
|
|
||||||
shutdown(m_UDPSocketIP4, 2);
|
|
||||||
close(m_UDPSocketIP4);
|
|
||||||
m_UDPSocketIP4 = INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
fos::Task::delayMs(100);
|
|
||||||
m_IsBound = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
bool m_IsBound{};
|
|
||||||
|
|
||||||
public:
|
|
||||||
// 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 message byte buffer containing the message
|
|
||||||
* @param length length of the message
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int sendMessage(const char *message, int length) {
|
|
||||||
if (m_ServerPort.length() <= 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_IsBound == false) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
int intResult = sendMessageTo(m_ServerIP, m_ServerPort, message, length);
|
|
||||||
return intResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
int receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const;
|
|
||||||
int setBroadcast(bool p_Broadcast) const;
|
|
||||||
int bindSocket(string clientIp, string clientPort);
|
|
||||||
|
|
||||||
int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength);
|
|
||||||
|
|
||||||
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() const { return m_IsBound; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* SPITSOCKET_H */
|
|
||||||
@@ -1,105 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* File: SPITType.h
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 8. April 2019, 08:40
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SPITTYPE_H
|
|
||||||
#define SPITTYPE_H
|
|
||||||
|
|
||||||
#include "SPITSocket.h"
|
|
||||||
#include "spit_message.hpp"
|
|
||||||
#include "spit_repo.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace spit;
|
|
||||||
|
|
||||||
class SPITTypeListener;
|
|
||||||
|
|
||||||
class SPITType {
|
|
||||||
public:
|
|
||||||
static void setConfirmedFalse(SpitRepo<SPITType> &repo);
|
|
||||||
static void eventProjectClosed(SpitRepo<SPITType> &repo, SpitRepo<SPITType> &remoteRepo);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
private:
|
|
||||||
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_CreatedByClient; // flag true = the SPITTyype is created by the client
|
|
||||||
// false = the SPITType is received from the server
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
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
|
|
||||||
* 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; }
|
|
||||||
/**
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
bool getConfirmed() const { return m_Confirmed; }
|
|
||||||
bool getFixed() const { return m_Fixed; }
|
|
||||||
long long getDefaultDelay() const { return m_DefaultDelay; }
|
|
||||||
long long getDefaultDuration() const { return m_DefaultDuration; }
|
|
||||||
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.
|
|
||||||
* @return true = the user has associated an action with this SPITType.
|
|
||||||
*/
|
|
||||||
bool getActionAssigned() const {
|
|
||||||
return m_ActionAssigned;
|
|
||||||
}
|
|
||||||
|
|
||||||
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.
|
|
||||||
* @return true = the m_ActionAssigned has changed.
|
|
||||||
*/
|
|
||||||
bool setActionAssigned(bool p_ActionAssigned);
|
|
||||||
|
|
||||||
bool setMessageOP(Message::ReportType &reportSpitType);
|
|
||||||
void fillMessageOP(Message::ReportType &smReportSpitType) const;
|
|
||||||
void fillMessageOP(Message::RemoveType &smRemoveSpitType) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* SPITTYPE_H */
|
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace spit {
|
||||||
|
|
||||||
|
class SadDetectedServer;
|
||||||
|
class ISadClient {
|
||||||
|
public:
|
||||||
|
virtual void eventServerDetected(SadDetectedServer &server) = 0;
|
||||||
|
virtual void eventServerChanged(SadDetectedServer &server) = 0;
|
||||||
|
virtual void eventServerLost(SadDetectedServer &server) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SadDetectedServer {
|
||||||
|
public:
|
||||||
|
SadDetectedServer(string name, string iD, string computerName,
|
||||||
|
string iP, string port, string clientIP,
|
||||||
|
string additions, string projName)
|
||||||
|
: mName(name),
|
||||||
|
mID(iD),
|
||||||
|
mComputerName(computerName),
|
||||||
|
mIP(iP),
|
||||||
|
mPort(port),
|
||||||
|
mClientIP(clientIP),
|
||||||
|
mAdditions(additions),
|
||||||
|
mServerProjectName(projName) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
string mName{};
|
||||||
|
string mID{};
|
||||||
|
string mComputerName{};
|
||||||
|
string mIP{};
|
||||||
|
string mPort{};
|
||||||
|
string mClientIP{};
|
||||||
|
string mAdditions{};
|
||||||
|
string mServerProjectName{};
|
||||||
|
bool mNew{true};
|
||||||
|
bool mChanged{};
|
||||||
|
bool mFoundAgain{};
|
||||||
|
|
||||||
|
public:
|
||||||
|
string getID() const { return mID; }
|
||||||
|
string getName() const { return mName; }
|
||||||
|
string getComputerName() const { return mComputerName; }
|
||||||
|
string getIP() const { return mIP; }
|
||||||
|
string getPort() const { return mPort; }
|
||||||
|
string getClientIP() const { return mClientIP; }
|
||||||
|
string getAdditions() const { return mAdditions; }
|
||||||
|
string getProjectName() const { return mServerProjectName; }
|
||||||
|
bool getNew() const { return mNew; }
|
||||||
|
bool getChanged() const { return mChanged; }
|
||||||
|
bool getFoundAgain() const { return mFoundAgain; }
|
||||||
|
|
||||||
|
void setChanged() { mChanged = true; }
|
||||||
|
void setKnown() { mNew = false; }
|
||||||
|
void setFoundAgain() { mFoundAgain = true; }
|
||||||
|
void updateProjectName(string newProjectName) {
|
||||||
|
mServerProjectName = newProjectName;
|
||||||
|
if (mServerProjectName != newProjectName) {
|
||||||
|
mChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SAD_Client mThreadSend will send to Multicast addresses
|
||||||
|
void resetFlags() {
|
||||||
|
mChanged = false;
|
||||||
|
mFoundAgain = false;
|
||||||
|
mNew = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static unordered_map<string, unique_ptr<SadDetectedServer>> sKnownServers;
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum ParamIndex {
|
||||||
|
PARAM_PRECODE = 0,
|
||||||
|
PARAM_SPITTASKID = 1,
|
||||||
|
PARAM_NAME = 2,
|
||||||
|
PARAM_ID = 3,
|
||||||
|
PARAM_COMPUTERNAME = 4,
|
||||||
|
PARAM_PORT = 5,
|
||||||
|
PARAM_CLIENTIP = 6,
|
||||||
|
PARAM_ADDITIONS = 7,
|
||||||
|
PARAM_SERVERPROJECTNAME = 8,
|
||||||
|
PARAM_IP = 9,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used by SAD_Client to add a found SPITServer - don't use this manually
|
||||||
|
* @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(unique_ptr<SadDetectedServer> 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(SadDetectedServer &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
|
||||||
|
*/
|
||||||
|
static void evaluateDetectedServers(ISadClient &sadClient) {
|
||||||
|
for (auto &srv : sKnownServers) {
|
||||||
|
SadDetectedServer &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.<br>
|
||||||
|
* If no DetectedServer is found an eyception is thrown.
|
||||||
|
* @param id the id of the SPITServer
|
||||||
|
* @return the reference of the SadDetectedServer instance with getID() == p_ServerID
|
||||||
|
*/
|
||||||
|
static const SadDetectedServer &getRefDetectedServer(const string &id) {
|
||||||
|
return *sKnownServers.at(id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,34 +1,21 @@
|
|||||||
/*
|
#pragma once
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
#include "sad_DetectedServer.hpp"
|
||||||
* File: SPIT_Client.h
|
#include "spit_object.hpp"
|
||||||
* Author: Hagi
|
#include "spit_player.hpp"
|
||||||
*
|
#include "spit_socket.hpp"
|
||||||
* Created on 7. April 2019, 08:50
|
#include "spit_type.hpp"
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef SPIT_CLIENT_H
|
|
||||||
#define SPIT_CLIENT_H
|
|
||||||
|
|
||||||
#include "SAD_DetectedServer.hpp"
|
|
||||||
#include "SPITObject.h"
|
|
||||||
#include "SPITPlayer.h"
|
|
||||||
#include "SPITSocket.h"
|
|
||||||
#include "SPITType.h"
|
|
||||||
#include "spit_message.hpp"
|
#include "spit_message.hpp"
|
||||||
#include "spit_repo.hpp"
|
#include "spit_repo.hpp"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace spit;
|
|
||||||
|
|
||||||
class SPIT_Client : I_SAD_Client {
|
namespace spit {
|
||||||
|
|
||||||
|
class SClient : ISadClient {
|
||||||
public:
|
public:
|
||||||
/** Maximal length of a SPITMessage*/
|
/** Maximal length of a SPITMessage*/
|
||||||
static const int MAXSPITMESSAGEBYTECOUNT = 512;
|
static const int MAXSPITMESSAGEBYTECOUNT = 512;
|
||||||
@@ -58,17 +45,16 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Callbacks {
|
struct Callbacks {
|
||||||
void (*onServerEvent)(ServerEvent event, const SAD_DetectedServer &p_DetectedServer){};
|
function<void(ServerEvent event, const SadDetectedServer &detectedServer)> onServerEvent;
|
||||||
void (*onConnectionStatus)(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, Connection p_ConnectionStatus, Connection p_OldConnectionStatus){};
|
function<void(string serverID, string serverComputerName, string serverName, int serverStepTime, Connection connectionStatus, Connection oldConnectionStatus)> onConnectionStatus;
|
||||||
void (*onProjectUpdate)(ProjUpdate state, string projectId){};
|
function<void(ProjUpdate state, string projectId)> onProjectUpdate;
|
||||||
void (*onSpitType)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType){};
|
function<void(ObjectEvent event, bool isRemote, const SType &spitType)> onSpitType;
|
||||||
void (*onSpitObject)(ObjectEvent event, bool isRemote, const SPITType &p_SPITType, const SPITObject &p_SPITObject){};
|
function<void(ObjectEvent event, bool isRemote, const SType &spitType, const SObject &spitObject)> onSpitObject;
|
||||||
|
function<void(string playerID, string playerName, char playerType, bool playerIsRunning, uint64_t timeFrames)> onPlay;
|
||||||
void (*onPlay)(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames){};
|
function<void(string playerID, string spitTypeID, bool playerIsRunning, bool started, bool ended, double value)> onPlaySpitType;
|
||||||
void (*onPlaySpitType)(string p_PlayerID, string p_SPITTypeID, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value){};
|
function<void(const SType &spitType, const SObject &spitObject, uint64_t p_FrameInsideObject, int value)> onPlayRemoteObjectStatus;
|
||||||
void (*onPlayRemoteObjectStatus)(const SPITType &p_SPITType, const SPITObject &p_SPITObject, long long p_FrameInsideObject, int p_Value){};
|
function<bool(bool knownType, bool createdByClient)> onCheckSpitTypeVeto;
|
||||||
bool (*onCheckSpitTypeVeto)(bool knownType, bool createdByClient){};
|
function<bool(bool knownType)> onCheckSpitObjectVeto;
|
||||||
bool (*onCheckSpitObjectVeto)(bool knownType){};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//------ PlayerType ------
|
//------ PlayerType ------
|
||||||
@@ -91,65 +77,65 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
static constexpr char VALUEFLAG_DECREASE = 0x02;
|
static constexpr char VALUEFLAG_DECREASE = 0x02;
|
||||||
static constexpr int MAX_OVERTAKING_SPIT_MESSAGES = 10;
|
static constexpr int MAX_OVERTAKING_SPIT_MESSAGES = 10;
|
||||||
|
|
||||||
//----- SPIT_Client -----
|
//----- SClient -----
|
||||||
public:
|
public:
|
||||||
SPIT_Client(string name, string projName, Callbacks calls);
|
SClient(string name, string projName, ISocket &socket, Callbacks calls);
|
||||||
virtual ~SPIT_Client();
|
virtual ~SClient();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Callbacks mCallbacks;
|
Callbacks mCallbacks;
|
||||||
|
|
||||||
fos::TaskT<SPIT_Client &> *m_ThreadReceive{};
|
fos::TaskT<SClient &> *mThreadReceive{};
|
||||||
bool m_StopReceiveSPITMessages{};
|
bool mStopReceiveMessages{};
|
||||||
|
|
||||||
Connection m_ConnectionStatus{Connection::None};
|
Connection mConnectionStatus{Connection::None};
|
||||||
bool m_DisconnectedByServer{}; // flag true = when server disconnects
|
bool mDisconnectedByServer{}; // flag true = when server disconnects
|
||||||
string m_ID;
|
string mID;
|
||||||
string m_Name;
|
string mName;
|
||||||
string m_ProjName;
|
string mProjName;
|
||||||
string m_ComputerName;
|
string mComputerName;
|
||||||
|
|
||||||
string m_ClientProjectName;
|
string mClientProjectName;
|
||||||
|
|
||||||
uint8_t m_MessageNumber_Send{1};
|
uint8_t mMessageNumberSend{1};
|
||||||
int m_MessageNumber_Received{-1}; // set to -1 because the first received message will set the number (1..255)
|
int mMessageNumberReceived{-1}; // set to -1 because the first received message will set the number (1..255)
|
||||||
vector<unique_ptr<Message>> m_OvertakingSPIT_Messages;
|
vector<unique_ptr<Message>> mOvertakingMessages;
|
||||||
|
|
||||||
// Server's info filled by parseConnectAnswer
|
// Server's info filled by parseConnectAnswer
|
||||||
string m_ServerID{};
|
string mServerID{};
|
||||||
string m_ServerName{};
|
string mServerName{};
|
||||||
string m_ServerComputerName{};
|
string mServerComputerName{};
|
||||||
int m_ServerStepTime{-1};
|
int mServerStepTime{-1};
|
||||||
|
|
||||||
//--- Server Project ---
|
//--- Server Project ---
|
||||||
string m_ServerProjectID;
|
string mServerProjectID;
|
||||||
string m_ServerProjectName;
|
string mServerProjectName;
|
||||||
int m_ServerFramesPerSecond;
|
int mServerFramesPerSecond;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** The ID of the client.<br>Every client instance should set an unique id*/
|
/** The ID of the client.<br>Every client instance should set an unique id*/
|
||||||
string getID() { return m_ID; }
|
string getID() { return mID; }
|
||||||
/** The name of the client, should be set by the user app*/
|
/** The name of the client, should be set by the user app*/
|
||||||
string getName() { return m_Name; }
|
string getName() { return mName; }
|
||||||
//----- Computer Params -----
|
//----- Computer Params -----
|
||||||
/** The name of the client's host computer*/
|
/** The name of the client's host computer*/
|
||||||
string getComputerName() { return m_ComputerName; }
|
string getComputerName() { return mComputerName; }
|
||||||
void setClientProjectName(string p_ClientProjectName) { m_ClientProjectName = p_ClientProjectName; }
|
void setClientProjectName(string clientProjectName) { mClientProjectName = clientProjectName; }
|
||||||
string getClientProjectName() { return m_ClientProjectName; }
|
string getClientProjectName() { return mClientProjectName; }
|
||||||
|
|
||||||
// connected Server Infos
|
// connected Server Infos
|
||||||
/** The ID of the connected SPITServer*/
|
/** The ID of the connected SPITServer*/
|
||||||
string getServerID() { return m_ServerID; }
|
string getServerID() { return mServerID; }
|
||||||
/** The host computername of the connected SPITServer*/
|
/** The host computername of the connected SPITServer*/
|
||||||
string getServerComputerName() { return m_ServerComputerName; }
|
string getServerComputerName() { return mServerComputerName; }
|
||||||
/** The name of the connected SPITServer*/
|
/** The name of the connected SPITServer*/
|
||||||
string getServerName() { return m_ServerName; }
|
string getServerName() { return mServerName; }
|
||||||
|
|
||||||
/** Expected Refreah Rate of the connectd SPITServer.<br>
|
/** Expected Refreah Rate of the connectd SPITServer.<br>
|
||||||
* When the server plays objects, it will do so at discrete time steps.<br>
|
* When the server plays objects, it will do so at discrete time steps.<br>
|
||||||
* Play events will take place in these time steps..
|
* Play events will take place in these time steps..
|
||||||
*/
|
*/
|
||||||
int getServerStepTime() { return m_ServerStepTime; }
|
int getServerStepTime() { return mServerStepTime; }
|
||||||
|
|
||||||
/** Should be called when the client wants to close his project*/
|
/** Should be called when the client wants to close his project*/
|
||||||
void clientProjectClose();
|
void clientProjectClose();
|
||||||
@@ -158,21 +144,16 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
*/
|
*/
|
||||||
void clientProjectLoaded();
|
void clientProjectLoaded();
|
||||||
|
|
||||||
/**
|
void setActionSPITType(string spitypeID, bool actionAssigned);
|
||||||
*
|
void setActionSPITObject(string objectID, bool actionAssigned);
|
||||||
* @param p_SPITTypeID
|
|
||||||
* @param p_ActionAssigned
|
|
||||||
*/
|
|
||||||
void setActionSPITType(string p_SPITTypeID, bool p_ActionAssigned);
|
|
||||||
void setActionSPITObject(string p_SPITObjectID, bool p_ActionAssigned);
|
|
||||||
|
|
||||||
//--------------- SPITMessage ---------------
|
//--------------- SPITMessage ---------------
|
||||||
private:
|
private:
|
||||||
bool startReceiveSPITMessages();
|
bool startReceiveSPITMessages();
|
||||||
void stopReceiveSPITMessages();
|
void stopReceiveSPITMessages();
|
||||||
static void receiveSPITMessage(SPIT_Client &rM);
|
static void receiveSPITMessage(SClient &rM);
|
||||||
// Reconnect to the server when connection is lost see eventConnectionStatus and eventServerDetected
|
// 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
|
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by mServerID
|
||||||
public:
|
public:
|
||||||
int sendSPITMessage(Message::OPPart & spitMessageOPPart);
|
int sendSPITMessage(Message::OPPart & spitMessageOPPart);
|
||||||
|
|
||||||
@@ -183,10 +164,10 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
/** Stops the autodetection of SPITServers in the local network*/
|
/** Stops the autodetection of SPITServers in the local network*/
|
||||||
void stopServerAutoDetect();
|
void stopServerAutoDetect();
|
||||||
/** Called every time a new SPITServer is detetced in the local network */
|
/** Called every time a new SPITServer is detetced in the local network */
|
||||||
void eventServerDetected(SAD_DetectedServer &server);
|
void eventServerDetected(SadDetectedServer &server);
|
||||||
/** Called every time a prior detected SPITServer is is no longer found.*/
|
/** Called every time a prior detected SPITServer is is no longer found.*/
|
||||||
void eventServerLost(SAD_DetectedServer &server);
|
void eventServerLost(SadDetectedServer &server);
|
||||||
void eventServerChanged(SAD_DetectedServer &server);
|
void eventServerChanged(SadDetectedServer &server);
|
||||||
|
|
||||||
//--------------- Connection ---------------
|
//--------------- Connection ---------------
|
||||||
public:
|
public:
|
||||||
@@ -201,22 +182,22 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
* @return true = the connection try is ok, SPITServer will answer with COnnectAnswer and an eventConnectionStatus will occur.<br>
|
* @return true = the connection try is ok, SPITServer will answer with COnnectAnswer and an eventConnectionStatus will occur.<br>
|
||||||
* false = something is going wrong. (client could not bind)
|
* false = something is going wrong. (client could not bind)
|
||||||
*/
|
*/
|
||||||
bool connect(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort, string p_LoginName = "", string p_LoginPassword = "");
|
bool connect(string serverIP, string serverPort, string clientIP, string clientPort, string loginName = "", string loginPassword = "");
|
||||||
/**
|
/**
|
||||||
* Terminates the connection to the SPITServer.
|
* Terminates the connection to the SPITServer.
|
||||||
*/
|
*/
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void disconnectInternal(Connection p_Cause);
|
void disconnectInternal(Connection cause);
|
||||||
void resetMessageNumberReceived();
|
void resetMessageNumberReceived();
|
||||||
void parseSPIT_Message(unique_ptr<Message> p_SPITMessage);
|
void parseMessage(unique_ptr<Message> message);
|
||||||
void checkParseSPIT_Message(unique_ptr<Message> p_SPITMessage);
|
void checkParseMessage(unique_ptr<Message> message);
|
||||||
void addOvertakingSPIT_Message(unique_ptr<Message> p_SPIT_Message);
|
void addOvertakingMessage(unique_ptr<Message> message);
|
||||||
void parseConnectAnswer(Message::ConnectAnswer &p_ConnectAnswer);
|
void parseConnectAnswer(Message::ConnectAnswer &message);
|
||||||
void parseDisconnect(Message::Disconnect &p_Disconnect);
|
void parseDisconnect(Message::Disconnect &message);
|
||||||
void parseWatchdog(Message::Watchdog &p_Watchdog);
|
void parseWatchdog(Message::Watchdog &message);
|
||||||
void parseWatchdogAnswer(Message::WatchdogAnswer &p_WatchdogAnswer);
|
void parseWatchdogAnswer(Message::WatchdogAnswer &message);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Used internally*/
|
/** Used internally*/
|
||||||
@@ -225,8 +206,8 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
void eventWatchdogLost();
|
void eventWatchdogLost();
|
||||||
//--------------- SPIT Project ---------------
|
//--------------- SPIT Project ---------------
|
||||||
private:
|
private:
|
||||||
void parseReportSPITProject(Message::ReportProject &p_ReportSPITProject);
|
void parseReportProject(Message::ReportProject &message);
|
||||||
void parseCloseSPITProject(Message::CloseProject &p_CloseSPITProject);
|
void parseCloseProject(Message::CloseProject &message);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Returns the SPITServer's project ID - may be the same as the project's name*/
|
/** Returns the SPITServer's project ID - may be the same as the project's name*/
|
||||||
@@ -237,12 +218,12 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
int getServerFramesPerSecond();
|
int getServerFramesPerSecond();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseRequestProjectTransfer(Message::RequestProjectTransfer &p_RequestProjectTransfer);
|
void parseRequestProjectTransfer(Message::RequestProjectTransfer &message);
|
||||||
void parseStartProjectTransfer(Message::StartProjectTransfer &p_StartProjectTransfer);
|
void parseStartProjectTransfer(Message::StartProjectTransfer &message);
|
||||||
void parseEndProjectTransfer(Message::EndProjectTransfer &p_EndProjectTransfer);
|
void parseEndProjectTransfer(Message::EndProjectTransfer &message);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void sendProject(SPIT_Client *p_PtrSPIT_Client);
|
static void sendProject(SClient *p_PtrSClient);
|
||||||
|
|
||||||
// --------------- SPIT Types ---------------
|
// --------------- SPIT Types ---------------
|
||||||
public:
|
public:
|
||||||
@@ -257,7 +238,7 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
* @param p_DefaultDuration maybe the action has a default duration, this is only used for graphical representations, 0 is allowd
|
* @param p_DefaultDuration maybe the action has a default duration, this is only used for graphical representations, 0 is allowd
|
||||||
* @return the pointer to the new SPITType.
|
* @return the pointer to the new SPITType.
|
||||||
*/
|
*/
|
||||||
SPITType *createSPITTypeFixed(string p_ID, string p_GroupName, string p_Name, long long p_DefaultDelay, long long p_DefaultDuration);
|
SType *createSPITTypeFixed(string iD, string groupName, string name, uint64_t defaultDelay, uint64_t defaultDuration);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a SPITType for application actions.<br>
|
* Creates a SPITType for application actions.<br>
|
||||||
@@ -271,80 +252,80 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
* @param p_ProjectIndepended true = the SPITType belongs to a specific project, false = the SpitType always exists for every project
|
* @param p_ProjectIndepended true = the SPITType belongs to a specific project, false = the SpitType always exists for every project
|
||||||
* @return the pointer to the new SPITType.
|
* @return the pointer to the new SPITType.
|
||||||
*/
|
*/
|
||||||
SPITType *createSPITType(string p_ID, string p_GroupName, string p_Name, long long p_DefaultDelay, long long p_DefaultDuration, bool p_Fixed, bool p_ProjectIndepended);
|
SType *createSPITType(string iD, string groupName, string name, uint64_t defaultDelay, uint64_t defaultDuration, bool fixed, bool projectIndepended);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// receive SPITTypes
|
// receive SPITTypes
|
||||||
void parseReportSPITType(Message::ReportType &p_ReportSPITType);
|
void parseReportSPITType(Message::ReportType &message);
|
||||||
void parseRemoveSPITType(Message::RemoveType &p_RemoveSPITType);
|
void parseRemoveSPITType(Message::RemoveType &message);
|
||||||
int sendSPITTypeInternal(SPITType &p_SPITType);
|
int sendSPITTypeInternal(SType &spitType);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* If a client wants to change a SPITType, he should send it to the server.<br>
|
* If a client wants to change a SPITType, he should send it to the server.<br>
|
||||||
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the change.<br>
|
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the change.<br>
|
||||||
* @param p_SPITTypeID the id of the SPITType to remove.
|
* @param spitypeID the id of the SPITType to remove.
|
||||||
* @return 0 = is sended, -1 = is not sended
|
* @return 0 = is sended, -1 = is not sended
|
||||||
*/
|
*/
|
||||||
bool changeSPITType(SPITType *p_SPITType);
|
bool changeSPITType(SType *spitType);
|
||||||
/**
|
/**
|
||||||
* If a client wants to remove a SPITType, he should send it to the server.<br>
|
* If a client wants to remove a SPITType, he should send it to the server.<br>
|
||||||
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the deletion.<br>
|
* If the SPITTye is a fixed one and not created by the client himself, then an eventSPITType can be sent from the server, which cancels the deletion.<br>
|
||||||
* @param p_SPITTypeID the id of the SPITType to remove.
|
* @param spitypeID the id of the SPITType to remove.
|
||||||
* @return 0 = is sended, -1 = is not sended
|
* @return 0 = is sended, -1 = is not sended
|
||||||
*/
|
*/
|
||||||
int removeSPITType(string p_SPITTypeID);
|
int removeSPITType(string spitypeID);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//--------------- SPIT Objects ---------------
|
//--------------- SPIT Objects ---------------
|
||||||
private:
|
private:
|
||||||
void parseReportSPITObject(Message::ReportObject &p_ReportSPITObject);
|
void parseReportSPITObject(Message::ReportObject &message);
|
||||||
void parseRemoveSPITObject(Message::RemoveObject &p_RemoveSPITObject);
|
void parseRemoveSPITObject(Message::RemoveObject &message);
|
||||||
int sendSPITObjectInternal(SPITObject *ptrSPITObject);
|
int sendSPITObjectInternal(SObject *ptrObject);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* When the client changes a SPITObject (normally the client should not do this), then it should send the changes to the SPITServer.<br>
|
* When the client changes a SPITObject (normally the client should not do this), then it should send the changes to the SPITServer.<br>
|
||||||
* The SPITServer may discard the changes and an eventSPITObject occurs.<br>
|
* The SPITServer may discard the changes and an eventSPITObject occurs.<br>
|
||||||
* @param p_SPITObject the pointer to the changed SPITObject.
|
* @param spitObject the pointer to the changed SPITObject.
|
||||||
* @return 0 = sended, -1 = not sended
|
* @return 0 = sended, -1 = not sended
|
||||||
*/
|
*/
|
||||||
bool changeSPITObject(SPITObject *p_SPITObject);
|
bool changeSPITObject(SObject *spitObject);
|
||||||
/**
|
/**
|
||||||
* When the client removes a SPITObject (normally the client should not do this), then he should send it to the SPITServer.<br>
|
* When the client removes a SPITObject (normally the client should not do this), then he should send it to the SPITServer.<br>
|
||||||
* The SPITServer may discard the deletion and an eventSPITObject occurs.<br>
|
* The SPITServer may discard the deletion and an eventSPITObject occurs.<br>
|
||||||
* @param p_SPITObjectID the id of the SPITObject to remove.
|
* @param objectID the id of the SPITObject to remove.
|
||||||
* @return 0 = sended, -1 = not sended
|
* @return 0 = sended, -1 = not sended
|
||||||
*/
|
*/
|
||||||
int removeSPITObject(string p_SPITObjectID);
|
int removeSPITObject(string objectID);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//--------------- Play SPIT Objects ---------------
|
//--------------- Play SPIT Objects ---------------
|
||||||
private:
|
private:
|
||||||
void parsePlaySPITStart(Message::PlayStart &p_PlaySPITStart);
|
void parsePlaySPITStart(Message::PlayStart &message);
|
||||||
void parsePlaySPITObject(Message::PlayObject &p_PlaySPITObject);
|
void parsePlaySPITObject(Message::PlayObject &message);
|
||||||
void parsePlaySPITEnd(Message::PlayEnd &p_PlaySPITEnd);
|
void parsePlaySPITEnd(Message::PlayEnd &message);
|
||||||
void parseReportPlayStatus(Message::ReportPlayStatus &p_ReportPlayStatus);
|
void parseReportPlayStatus(Message::ReportPlayStatus &message);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//--------- Remote ----------
|
//--------- Remote ----------
|
||||||
void sendRemoteObject(string p_SPITObjectID, int p_Valueppm = 0, char p_ValueFlag = 0x00);
|
void sendRemoteObject(string objectID, int valuePpm = 0, char valueFlag = 0x00);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void processSocketTask(SPIT_Client &instance);
|
static void processSocketTask(SClient &instance);
|
||||||
fos::TaskT<SPIT_Client &> *sThread{};
|
fos::TaskT<SClient &> *sThread{};
|
||||||
bool mAbortSearch{};
|
bool mAbortSearch{};
|
||||||
bool sAnswered{};
|
bool sAnswered{};
|
||||||
static fos::Semaphore sStartSad;
|
static fos::Semaphore sStartSad;
|
||||||
SPITSocket *mSPITSocket;
|
ISocket &mSocket;
|
||||||
void answerWatchdog() {
|
void answerWatchdog() {
|
||||||
sAnswered = true;
|
sAnswered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SpitRepo<SPITObject> mSpitObjects;
|
SpitRepo<SObject> mSpitObjects;
|
||||||
SpitRepo<SPITObject> mRemoteSpitObjects;
|
SpitRepo<SObject> mRemoteSpitObjects;
|
||||||
SpitRepo<SPITType> mSpitTypes;
|
SpitRepo<SType> mSpitTypes;
|
||||||
SpitRepo<SPITType> mRemoteSpitTypes;
|
SpitRepo<SType> mRemoteSpitTypes;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SPIT_CLIENT_H */
|
}
|
||||||
@@ -1,15 +1,3 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* File: Message.h
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 3. April 2019, 08:51
|
|
||||||
*/
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -37,8 +25,8 @@ class Message {
|
|||||||
int mVersion{SPITVERSION};
|
int mVersion{SPITVERSION};
|
||||||
unsigned char mMessageNumber{};
|
unsigned char mMessageNumber{};
|
||||||
int mBytesCount{BYTESLENGTH};
|
int mBytesCount{BYTESLENGTH};
|
||||||
string mServerID{};
|
string mServerId{};
|
||||||
string mClientID{};
|
string mClientId{};
|
||||||
int mOpFlag{-1};
|
int mOpFlag{-1};
|
||||||
int mParseOffset{};
|
int mParseOffset{};
|
||||||
|
|
||||||
@@ -47,8 +35,8 @@ class Message {
|
|||||||
int getSPITVersion() const { return mVersion; }
|
int getSPITVersion() const { return mVersion; }
|
||||||
unsigned char getMessageNumber() const { return mMessageNumber; }
|
unsigned char getMessageNumber() const { return mMessageNumber; }
|
||||||
int getBytesCount() const { return mBytesCount; }
|
int getBytesCount() const { return mBytesCount; }
|
||||||
string getServerID() const { return mServerID; }
|
string getServerID() const { return mServerId; }
|
||||||
string getClientID() const { return mClientID; }
|
string getClientID() const { return mClientId; }
|
||||||
int getType() const { return mOpFlag; }
|
int getType() const { return mOpFlag; }
|
||||||
|
|
||||||
// Receive
|
// Receive
|
||||||
@@ -56,9 +44,9 @@ class Message {
|
|||||||
|
|
||||||
// Send
|
// Send
|
||||||
Header(int p_SPITVersion, int pOpFlag);
|
Header(int p_SPITVersion, int pOpFlag);
|
||||||
void setMessageNumber(unsigned char p_MessageNumber) { mMessageNumber = p_MessageNumber; }
|
void setMessageNumber(unsigned char messageNumber) { mMessageNumber = messageNumber; }
|
||||||
void setServerID(string p_ID) { mServerID = p_ID; }
|
void setServerID(string iD) { mServerId = iD; }
|
||||||
void setClientID(string p_ID) { mClientID = p_ID; }
|
void setClientID(string iD) { mClientId = iD; }
|
||||||
void setOPFlag(int pOpFlag) { mOpFlag = pOpFlag; }
|
void setOPFlag(int pOpFlag) { mOpFlag = pOpFlag; }
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
@@ -112,7 +100,7 @@ class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Receive
|
// Receive
|
||||||
OPPart(unique_ptr<Header> p_Header, int pOpFlag, int size);
|
OPPart(unique_ptr<Header> header, int pOpFlag, int size);
|
||||||
void setHeader(int opFlag);
|
void setHeader(int opFlag);
|
||||||
virtual bool parse(const std::vector<char> &message) = 0;
|
virtual bool parse(const std::vector<char> &message) = 0;
|
||||||
|
|
||||||
@@ -145,22 +133,22 @@ class Message {
|
|||||||
|
|
||||||
// Members
|
// Members
|
||||||
private:
|
private:
|
||||||
unique_ptr<OPPart> m_OPPart{};
|
unique_ptr<OPPart> oPPart{};
|
||||||
|
|
||||||
// Receive
|
// Receive
|
||||||
public:
|
public:
|
||||||
Message(std::vector<char> message);
|
Message(std::vector<char> message);
|
||||||
|
|
||||||
const Header *getHeader() const { return m_OPPart->getHeader(); }
|
const Header *getHeader() const { return oPPart->getHeader(); }
|
||||||
int getType() const {
|
int getType() const {
|
||||||
if (!m_OPPart || !m_OPPart->getHeader()) {
|
if (!oPPart || !oPPart->getHeader()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return m_OPPart->getHeader()->getType();
|
return oPPart->getHeader()->getType();
|
||||||
}
|
}
|
||||||
const OPPart *getOPPart() const { return m_OPPart.get(); }
|
const OPPart *getOPPart() const { return oPPart.get(); }
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T &getAs() const { return *reinterpret_cast<T *>(m_OPPart.get()); }
|
T &getAs() const { return *reinterpret_cast<T *>(oPPart.get()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool parse(std::vector<char> message);
|
bool parse(std::vector<char> message);
|
||||||
@@ -179,31 +167,31 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 304;
|
static constexpr int BYTESLENGTH = 304;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_ClientComputerName{};
|
string mClientComputerName{};
|
||||||
string m_ClientName{};
|
string mClientName{};
|
||||||
string m_LoginName{};
|
string mLoginName{};
|
||||||
string m_LoginPassword{};
|
string mLoginPassword{};
|
||||||
string m_ServerIP{};
|
string mServerIp{};
|
||||||
int m_ServerPort{};
|
int mServerPort{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Receive
|
// Receive
|
||||||
Connect(unique_ptr<Header> p_Header);
|
Connect(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
string getClientComputerName() const { return m_ClientComputerName; }
|
string getClientComputerName() const { return mClientComputerName; }
|
||||||
string getClientName() const { return m_ClientName; }
|
string getClientName() const { return mClientName; }
|
||||||
string getLoginName() const { return m_LoginName; }
|
string getLoginName() const { return mLoginName; }
|
||||||
string getLoginPassword() const { return m_LoginPassword; }
|
string getLoginPassword() const { return mLoginPassword; }
|
||||||
string getServerIP() const { return m_ServerIP; }
|
string getServerIP() const { return mServerIp; }
|
||||||
int getServerPort() const { return m_ServerPort; }
|
int getServerPort() const { return mServerPort; }
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
Connect(string p_ComputerName, string p_ClientName);
|
Connect(string p_ComputerName, string p_ClientName);
|
||||||
|
|
||||||
void setLoginName(string p_LoginName) { m_LoginName = p_LoginName; }
|
void setLoginName(string p_LoginName) { mLoginName = p_LoginName; }
|
||||||
void setLoginPassword(string p_LoginPassword) { m_LoginPassword = p_LoginPassword; }
|
void setLoginPassword(string p_LoginPassword) { mLoginPassword = p_LoginPassword; }
|
||||||
void setServerIP(string p_ServerIP) { m_ServerIP = p_ServerIP; }
|
void setServerIP(string p_ServerIP) { mServerIp = p_ServerIP; }
|
||||||
void setServerPort(int p_ServerPort);
|
void setServerPort(int p_ServerPort);
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
@@ -216,28 +204,28 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 137;
|
static constexpr int BYTESLENGTH = 137;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_ServerComputerName{};
|
string mServerComputerName{};
|
||||||
string m_ServerName{};
|
string mServerName{};
|
||||||
bool m_Connected{};
|
bool mConnected{};
|
||||||
int m_StepTime{40}; // ms step size the Server will send play sequences
|
int mStepTime{40}; // ms step size the Server will send play sequences
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ConnectAnswer(const ConnectAnswer &orig);
|
ConnectAnswer(const ConnectAnswer &orig);
|
||||||
// Receive
|
// Receive
|
||||||
ConnectAnswer(unique_ptr<Header> p_Header);
|
ConnectAnswer(unique_ptr<Header> header);
|
||||||
|
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
const string getServerComputerName() const { return m_ServerComputerName; }
|
const string getServerComputerName() const { return mServerComputerName; }
|
||||||
const string getServerName() const { return m_ServerName; }
|
const string getServerName() const { return mServerName; }
|
||||||
bool getConnected() const { return m_Connected; }
|
bool getConnected() const { return mConnected; }
|
||||||
int getStepTime() const { return m_StepTime; }
|
int getStepTime() const { return mStepTime; }
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
ConnectAnswer();
|
ConnectAnswer();
|
||||||
void setServerComputerName(string p_ServerComputerName) { m_ServerComputerName = p_ServerComputerName; }
|
void setServerComputerName(string p_ServerComputerName) { mServerComputerName = p_ServerComputerName; }
|
||||||
void setServerName(string p_ServerName) { m_ServerName = p_ServerName; }
|
void setServerName(string p_ServerName) { mServerName = p_ServerName; }
|
||||||
void setConnected(bool p_Connected) { m_Connected = p_Connected; }
|
void setConnected(bool p_Connected) { mConnected = p_Connected; }
|
||||||
void setStepTime(int p_StepTime_ms);
|
void setStepTime(int p_StepTime_ms);
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
@@ -251,7 +239,7 @@ class Message {
|
|||||||
|
|
||||||
Disconnect(const Disconnect &orig);
|
Disconnect(const Disconnect &orig);
|
||||||
// Receive
|
// Receive
|
||||||
Disconnect(unique_ptr<Header> p_Header);
|
Disconnect(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
@@ -268,7 +256,7 @@ class Message {
|
|||||||
|
|
||||||
Watchdog(const Watchdog &orig);
|
Watchdog(const Watchdog &orig);
|
||||||
// Receive
|
// Receive
|
||||||
Watchdog(unique_ptr<Header> p_Header);
|
Watchdog(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
@@ -285,7 +273,7 @@ class Message {
|
|||||||
|
|
||||||
// Receive
|
// Receive
|
||||||
WatchdogAnswer(const WatchdogAnswer &orig);
|
WatchdogAnswer(const WatchdogAnswer &orig);
|
||||||
WatchdogAnswer(unique_ptr<Header> p_Header);
|
WatchdogAnswer(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
@@ -303,22 +291,22 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 113;
|
static constexpr int BYTESLENGTH = 113;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_ProjectID{};
|
string mProjectID{};
|
||||||
string m_ProjectName{};
|
string mProjectName{};
|
||||||
int m_FramesPerSecond{1000}; // Frames per second
|
int mFramesPerSecond{1000}; // Frames per second
|
||||||
|
|
||||||
// Receive
|
// Receive
|
||||||
public:
|
public:
|
||||||
ReportProject(const ReportProject &orig);
|
ReportProject(const ReportProject &orig);
|
||||||
ReportProject(unique_ptr<Header> p_Header);
|
ReportProject(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
const string getProjectID() const { return m_ProjectID; }
|
const string getProjectID() const { return mProjectID; }
|
||||||
const string getProjectName() const { return m_ProjectName; }
|
const string getProjectName() const { return mProjectName; }
|
||||||
int getFramesPerSecond() const { return m_FramesPerSecond; }
|
int getFramesPerSecond() const { return mFramesPerSecond; }
|
||||||
// Send
|
// Send
|
||||||
ReportProject(string p_ProjectID, string p_ProjectName);
|
ReportProject(string p_ProjectID, string p_ProjectName);
|
||||||
|
|
||||||
void setFramesPerSecond(const int p_FramesPerSecond) { m_FramesPerSecond = p_FramesPerSecond; }
|
void setFramesPerSecond(const int p_FramesPerSecond) { mFramesPerSecond = p_FramesPerSecond; }
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -330,15 +318,15 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 45;
|
static constexpr int BYTESLENGTH = 45;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_ProjectID{};
|
string mProjectID{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CloseProject(const CloseProject &orig);
|
CloseProject(const CloseProject &orig);
|
||||||
// Receive
|
// Receive
|
||||||
CloseProject(unique_ptr<Header> p_Header);
|
CloseProject(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
const string getProjectID() const {
|
const string getProjectID() const {
|
||||||
return m_ProjectID;
|
return mProjectID;
|
||||||
}
|
}
|
||||||
// Send
|
// Send
|
||||||
CloseProject(string projectID);
|
CloseProject(string projectID);
|
||||||
@@ -353,7 +341,7 @@ class Message {
|
|||||||
|
|
||||||
RequestProjectTransfer(const RequestProjectTransfer &orig);
|
RequestProjectTransfer(const RequestProjectTransfer &orig);
|
||||||
// Receive
|
// Receive
|
||||||
RequestProjectTransfer(unique_ptr<Header> p_Header);
|
RequestProjectTransfer(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
// Send
|
// Send
|
||||||
RequestProjectTransfer();
|
RequestProjectTransfer();
|
||||||
@@ -369,7 +357,7 @@ class Message {
|
|||||||
|
|
||||||
StartProjectTransfer(const StartProjectTransfer &orig);
|
StartProjectTransfer(const StartProjectTransfer &orig);
|
||||||
// Receive
|
// Receive
|
||||||
StartProjectTransfer(unique_ptr<Header> p_Header);
|
StartProjectTransfer(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
// Send
|
// Send
|
||||||
StartProjectTransfer();
|
StartProjectTransfer();
|
||||||
@@ -384,7 +372,7 @@ class Message {
|
|||||||
|
|
||||||
EndProjectTransfer(const EndProjectTransfer &orig);
|
EndProjectTransfer(const EndProjectTransfer &orig);
|
||||||
// Receive
|
// Receive
|
||||||
EndProjectTransfer(unique_ptr<Header> p_Header);
|
EndProjectTransfer(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
// Send
|
// Send
|
||||||
EndProjectTransfer();
|
EndProjectTransfer();
|
||||||
@@ -400,43 +388,43 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 168;
|
static constexpr int BYTESLENGTH = 168;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_Confirmed{};
|
bool mConfirmed{};
|
||||||
string m_SPITTypeID{};
|
string mSPITTypeID{};
|
||||||
bool m_Fixed{};
|
bool mFixed{};
|
||||||
bool m_ServerRemote{};
|
bool mServerRemote{};
|
||||||
bool m_ServerProjectIndepended{};
|
bool mServerProjectIndepended{};
|
||||||
string m_SPITTypeGroupName{};
|
string mTypeGroupName{};
|
||||||
string m_SPITTypeName{};
|
string mSPITTypeName{};
|
||||||
uint64_t m_Delay{};
|
uint64_t mDelay{};
|
||||||
uint64_t m_Duration{};
|
uint64_t mDuration{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ReportType(const ReportType &orig);
|
ReportType(const ReportType &orig);
|
||||||
// Receive
|
// Receive
|
||||||
ReportType(unique_ptr<Header> p_Header);
|
ReportType(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
bool getConfirmed() const { return m_Confirmed; }
|
bool getConfirmed() const { return mConfirmed; }
|
||||||
const string getID() const { return m_SPITTypeID; }
|
const string getID() const { return mSPITTypeID; }
|
||||||
bool getFixed() const { return m_Fixed; }
|
bool getFixed() const { return mFixed; }
|
||||||
bool getServerRemote() const { return m_ServerRemote; }
|
bool getServerRemote() const { return mServerRemote; }
|
||||||
bool getServerProjectIndepended() const { return m_ServerProjectIndepended; }
|
bool getServerProjectIndepended() const { return mServerProjectIndepended; }
|
||||||
const string getGroupName() const { return m_SPITTypeGroupName; }
|
const string getGroupName() const { return mTypeGroupName; }
|
||||||
const string getName() const { return m_SPITTypeName; }
|
const string getName() const { return mSPITTypeName; }
|
||||||
uint64_t getDelay() const { return m_Delay; }
|
uint64_t getDelay() const { return mDelay; }
|
||||||
uint64_t getDuration() const { return m_Duration; }
|
uint64_t getDuration() const { return mDuration; }
|
||||||
// Send
|
// Send
|
||||||
|
|
||||||
ReportType();
|
ReportType();
|
||||||
void setConfirmed(bool p_Confirmed) { m_Confirmed = p_Confirmed; }
|
void setConfirmed(bool p_Confirmed) { mConfirmed = p_Confirmed; }
|
||||||
void setID(string p_ID) { m_SPITTypeID = p_ID; }
|
void setID(string iD) { mSPITTypeID = iD; }
|
||||||
void setFixed(bool p_Fixed) { m_Fixed = p_Fixed; }
|
void setFixed(bool p_Fixed) { mFixed = p_Fixed; }
|
||||||
void setServerRemote(bool p_IsServerRemote) { m_ServerRemote = p_IsServerRemote; }
|
void setServerRemote(bool p_IsServerRemote) { mServerRemote = p_IsServerRemote; }
|
||||||
void setServerProjectIndepended(bool p_ProjectIndpended) { m_ServerProjectIndepended = p_ProjectIndpended; }
|
void setServerProjectIndepended(bool p_ProjectIndpended) { mServerProjectIndepended = p_ProjectIndpended; }
|
||||||
void setGroupName(string p_GroupName) { m_SPITTypeGroupName = p_GroupName; }
|
void setGroupName(string p_GroupName) { mTypeGroupName = p_GroupName; }
|
||||||
void setName(string p_Name) { m_SPITTypeName = p_Name; }
|
void setName(string p_Name) { mSPITTypeName = p_Name; }
|
||||||
void setDelay(uint64_t p_Delay) { m_Delay = p_Delay; }
|
void setDelay(uint64_t p_Delay) { mDelay = p_Delay; }
|
||||||
void setDuration(uint64_t p_Duration) { m_Duration = p_Duration; }
|
void setDuration(uint64_t p_Duration) { mDuration = p_Duration; }
|
||||||
|
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
@@ -449,19 +437,19 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 45;
|
static constexpr int BYTESLENGTH = 45;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_SPITTypeID{};
|
string mSPITTypeID{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RemoveType(const RemoveType &orig);
|
RemoveType(const RemoveType &orig);
|
||||||
// Receive
|
// Receive
|
||||||
RemoveType(unique_ptr<Header> p_Header);
|
RemoveType(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
const string getID() const { return m_SPITTypeID; }
|
const string getID() const { return mSPITTypeID; }
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
RemoveType();
|
RemoveType();
|
||||||
void setID(string p_ID) { m_SPITTypeID = p_ID; }
|
void setID(string iD) { mSPITTypeID = iD; }
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -475,71 +463,71 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 339;
|
static constexpr int BYTESLENGTH = 339;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_Confirmed{};
|
bool mConfirmed{};
|
||||||
string m_SPITObjectID{};
|
string mSPITObjectID{};
|
||||||
bool m_Fixed{};
|
bool mFixed{};
|
||||||
bool m_ServerRemote{};
|
bool mServerRemote{};
|
||||||
string m_SPITObjectName{};
|
string mSPITObjectName{};
|
||||||
string m_SPITTypeID{};
|
string mSPITTypeID{};
|
||||||
string m_ServerParams{};
|
string mServerParams{};
|
||||||
uint64_t m_FrameStart{};
|
uint64_t mFrameStart{};
|
||||||
uint64_t m_FrameLength{};
|
uint64_t mFrameLength{};
|
||||||
uint64_t m_FrameFadeInLength{};
|
uint64_t mFrameFadeInLength{};
|
||||||
uint64_t m_FrameFadeOutLength{};
|
uint64_t mFrameFadeOutLength{};
|
||||||
int m_ValueFactor{};
|
int mValueFactor{};
|
||||||
char m_ValueUse{VALUEUSE_DISCARD};
|
char mValueUse{VALUEUSE_DISCARD};
|
||||||
int m_Track{};
|
int mTrack{};
|
||||||
string m_Remark{};
|
string mRemark{};
|
||||||
uint64_t m_Delay{};
|
uint64_t mDelay{};
|
||||||
uint64_t m_Duration{};
|
uint64_t mDuration{};
|
||||||
bool m_ActionAssigned{};
|
bool mActionAssigned{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ReportObject(const ReportObject &orig);
|
ReportObject(const ReportObject &orig);
|
||||||
// Receive
|
// Receive
|
||||||
ReportObject(unique_ptr<Header> p_Header);
|
ReportObject(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
bool getConfirmed() const { return m_Confirmed; }
|
bool getConfirmed() const { return mConfirmed; }
|
||||||
const string getID() const { return m_SPITObjectID; }
|
const string getID() const { return mSPITObjectID; }
|
||||||
bool getFixed() const { return m_Fixed; }
|
bool getFixed() const { return mFixed; }
|
||||||
bool getServerRemote() const { return m_ServerRemote; }
|
bool getServerRemote() const { return mServerRemote; }
|
||||||
const string getName() const { return m_SPITObjectName; }
|
const string getName() const { return mSPITObjectName; }
|
||||||
const string getSPITTypeID() const { return m_SPITTypeID; }
|
const string getSPITTypeID() const { return mSPITTypeID; }
|
||||||
const string getServerParams() const { return m_ServerParams; }
|
const string getServerParams() const { return mServerParams; }
|
||||||
uint64_t getFrameStart() const { return m_FrameStart; }
|
uint64_t getFrameStart() const { return mFrameStart; }
|
||||||
uint64_t getFrameLength() const { return m_FrameLength; }
|
uint64_t getFrameLength() const { return mFrameLength; }
|
||||||
uint64_t getFrameFadeInLength() const { return m_FrameFadeInLength; }
|
uint64_t getFrameFadeInLength() const { return mFrameFadeInLength; }
|
||||||
uint64_t getFrameFadeOutLength() const { return m_FrameFadeOutLength; }
|
uint64_t getFrameFadeOutLength() const { return mFrameFadeOutLength; }
|
||||||
int getValueFactor() const { return m_ValueFactor; }
|
int getValueFactor() const { return mValueFactor; }
|
||||||
char getValueUse() const { return m_ValueUse; }
|
char getValueUse() const { return mValueUse; }
|
||||||
int getTrack() const { return m_Track; }
|
int getTrack() const { return mTrack; }
|
||||||
const string getRemark() const { return m_Remark; }
|
const string getRemark() const { return mRemark; }
|
||||||
uint64_t getDelay() const { return m_Delay; }
|
uint64_t getDelay() const { return mDelay; }
|
||||||
uint64_t getDuration() const { return m_Duration; }
|
uint64_t getDuration() const { return mDuration; }
|
||||||
bool getActionAssigned() const { return m_ActionAssigned; }
|
bool getActionAssigned() const { return mActionAssigned; }
|
||||||
// Send
|
// Send
|
||||||
public:
|
public:
|
||||||
ReportObject();
|
ReportObject();
|
||||||
|
|
||||||
void setConfirmed(bool p_Confirmed) { m_Confirmed = p_Confirmed; };
|
void setConfirmed(bool p_Confirmed) { mConfirmed = p_Confirmed; };
|
||||||
void setID(string p_ID) { m_SPITObjectID = p_ID; };
|
void setID(string iD) { mSPITObjectID = iD; };
|
||||||
void setFixed(bool p_Fixed) { m_Fixed = p_Fixed; };
|
void setFixed(bool p_Fixed) { mFixed = p_Fixed; };
|
||||||
void setServerRemote(bool p_IsRemote) { m_ServerRemote = p_IsRemote; };
|
void setServerRemote(bool p_IsRemote) { mServerRemote = p_IsRemote; };
|
||||||
void setName(string p_Name) { m_SPITObjectName = p_Name; };
|
void setName(string p_Name) { mSPITObjectName = p_Name; };
|
||||||
void setSPITTypeID(string p_ID) { m_SPITTypeID = p_ID; };
|
void setSPITTypeID(string iD) { mSPITTypeID = iD; };
|
||||||
void setServerParams(string p_Parameters) { m_ServerParams = p_Parameters; };
|
void setServerParams(string p_Parameters) { mServerParams = p_Parameters; };
|
||||||
void setFrameStart(uint64_t p_StartTime) { m_FrameStart = p_StartTime; };
|
void setFrameStart(uint64_t p_StartTime) { mFrameStart = p_StartTime; };
|
||||||
void setFrameLength(uint64_t p_Length) { m_FrameLength = p_Length; };
|
void setFrameLength(uint64_t p_Length) { mFrameLength = p_Length; };
|
||||||
void setFrameFadeInLength(uint64_t p_FadeInTime) { m_FrameFadeInLength = p_FadeInTime; };
|
void setFrameFadeInLength(uint64_t p_FadeInTime) { mFrameFadeInLength = p_FadeInTime; };
|
||||||
void setFrameFadeOutLength(uint64_t p_FadeOutTime) { m_FrameFadeOutLength = p_FadeOutTime; };
|
void setFrameFadeOutLength(uint64_t p_FadeOutTime) { mFrameFadeOutLength = p_FadeOutTime; };
|
||||||
void setValueFactor(int p_Volume) { m_ValueFactor = p_Volume; };
|
void setValueFactor(int p_Volume) { mValueFactor = p_Volume; };
|
||||||
void setValueUse(char p_ValueUse) { m_ValueUse = p_ValueUse; };
|
void setValueUse(char p_ValueUse) { mValueUse = p_ValueUse; };
|
||||||
void setTrack(int p_Track) { m_Track = p_Track; };
|
void setTrack(int p_Track) { mTrack = p_Track; };
|
||||||
void setRemark(string p_Description) { m_Remark = p_Description; };
|
void setRemark(string p_Description) { mRemark = p_Description; };
|
||||||
void setDelay(uint64_t p_Delay);
|
void setDelay(uint64_t p_Delay);
|
||||||
void setDuration(uint64_t p_Duration);
|
void setDuration(uint64_t p_Duration);
|
||||||
void setActionAssigned(bool p_ActionAssigned) { m_ActionAssigned = p_ActionAssigned; }
|
void setActionAssigned(bool p_ActionAssigned) { mActionAssigned = p_ActionAssigned; }
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -551,19 +539,19 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 45;
|
static constexpr int BYTESLENGTH = 45;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_SPITObjectID{};
|
string mSPITObjectID{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RemoveObject(const RemoveObject &orig);
|
RemoveObject(const RemoveObject &orig);
|
||||||
// Receive
|
// Receive
|
||||||
RemoveObject(unique_ptr<Header> p_Header);
|
RemoveObject(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
const string getID() const { return m_SPITObjectID; }
|
const string getID() const { return mSPITObjectID; }
|
||||||
// Send
|
// Send
|
||||||
public:
|
public:
|
||||||
RemoveObject();
|
RemoveObject();
|
||||||
void setID(string p_ID) { m_SPITObjectID = p_ID; }
|
void setID(string iD) { mSPITObjectID = iD; }
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -577,28 +565,28 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 119;
|
static constexpr int BYTESLENGTH = 119;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_PlayerID{};
|
string mPlayerID{};
|
||||||
string m_PlayerName{};
|
string mPlayerName{};
|
||||||
char m_PlayerType{};
|
char mPlayerType{};
|
||||||
bool m_PlayerIsRunning{};
|
bool mPlayerIsRunning{};
|
||||||
uint64_t m_Time; // Frames
|
uint64_t mTime; // Frames
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlayStart(const PlayStart &orig);
|
PlayStart(const PlayStart &orig);
|
||||||
// Receive
|
// Receive
|
||||||
PlayStart(unique_ptr<Header> p_Header);
|
PlayStart(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
const string getPlayerID() const { return m_PlayerID; }
|
const string getPlayerID() const { return mPlayerID; }
|
||||||
const string getPlayerName() const { return m_PlayerName; }
|
const string getPlayerName() const { return mPlayerName; }
|
||||||
char getPlayerType() const { return m_PlayerType; }
|
char getPlayerType() const { return mPlayerType; }
|
||||||
bool getPlayerIsRunning() const { return m_PlayerIsRunning; }
|
bool getPlayerIsRunning() const { return mPlayerIsRunning; }
|
||||||
uint64_t getTime() const { return m_Time; }
|
uint64_t getTime() const { return mTime; }
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
PlayStart(string p_PlayerID, string p_PlayerName, char p_PlayerType);
|
PlayStart(string p_PlayerID, string p_PlayerName, char p_PlayerType);
|
||||||
void setPlayerIsRunning(bool p_IsPlaying) { m_PlayerIsRunning = p_IsPlaying; }
|
void setPlayerIsRunning(bool p_IsPlaying) { mPlayerIsRunning = p_IsPlaying; }
|
||||||
void setTime(uint64_t p_Time) { m_Time = p_Time; }
|
void setTime(uint64_t p_Time) { mTime = p_Time; }
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -610,34 +598,34 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 100;
|
static constexpr int BYTESLENGTH = 100;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_PlayerID{};
|
string mPlayerID{};
|
||||||
string m_SPITObjectID{};
|
string mSPITObjectID{};
|
||||||
uint64_t m_FrameInsideObject{}; // Frames
|
uint64_t mFrameInsideObject{}; // Frames
|
||||||
bool m_PlayPrePosition{};
|
bool mPlayPrePosition{};
|
||||||
int m_Value{};
|
int mValue{};
|
||||||
char m_ValueFlag{VALUEFLAG_DIRECT};
|
char mValueFlag{VALUEFLAG_DIRECT};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlayObject(const PlayObject &orig);
|
PlayObject(const PlayObject &orig);
|
||||||
// Receive
|
// Receive
|
||||||
PlayObject(unique_ptr<Header> p_Header);
|
PlayObject(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
const string getPlayerID() const { return m_PlayerID; }
|
const string getPlayerID() const { return mPlayerID; }
|
||||||
const string getSPITObjectID() const { return m_SPITObjectID; }
|
const string getSPITObjectID() const { return mSPITObjectID; }
|
||||||
uint64_t getFrameInsideObject() const { return m_FrameInsideObject; }
|
uint64_t getFrameInsideObject() const { return mFrameInsideObject; }
|
||||||
bool getPlayPrePosition() const { return m_PlayPrePosition; }
|
bool getPlayPrePosition() const { return mPlayPrePosition; }
|
||||||
int getValue() const { return m_Value; }
|
int getValue() const { return mValue; }
|
||||||
char getValueFlag() const { return m_ValueFlag; }
|
char getValueFlag() const { return mValueFlag; }
|
||||||
// Send
|
// Send
|
||||||
PlayObject();
|
PlayObject();
|
||||||
|
|
||||||
void setPlayerID(string p_PlayerID) { m_PlayerID = p_PlayerID; }
|
void setPlayerID(string p_PlayerID) { mPlayerID = p_PlayerID; }
|
||||||
void setID(string p_ID) { m_SPITObjectID = p_ID; }
|
void setID(string iD) { mSPITObjectID = iD; }
|
||||||
void setFrameInsideObject(uint64_t p_TimeInside) { m_FrameInsideObject = p_TimeInside; }
|
void setFrameInsideObject(uint64_t p_TimeInside) { mFrameInsideObject = p_TimeInside; }
|
||||||
void setPlayPrePosition(bool p_PlayOldPosition) { m_PlayPrePosition = p_PlayOldPosition; }
|
void setPlayPrePosition(bool p_PlayOldPosition) { mPlayPrePosition = p_PlayOldPosition; }
|
||||||
void setValue(int p_Value) { m_Value = p_Value; }
|
void setValue(int p_Value) { mValue = p_Value; }
|
||||||
void setValueFlag(char p_ValueFlag) { m_ValueFlag = p_ValueFlag; }
|
void setValueFlag(char p_ValueFlag) { mValueFlag = p_ValueFlag; }
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -648,14 +636,14 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 45;
|
static constexpr int BYTESLENGTH = 45;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_PlayerID{};
|
string mPlayerID{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlayEnd(const PlayEnd &orig);
|
PlayEnd(const PlayEnd &orig);
|
||||||
// Receive
|
// Receive
|
||||||
PlayEnd(unique_ptr<Header> p_Header);
|
PlayEnd(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
const string getPlayerID() const { return m_PlayerID; }
|
const string getPlayerID() const { return mPlayerID; }
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
PlayEnd(string p_PlayerID);
|
PlayEnd(string p_PlayerID);
|
||||||
@@ -669,23 +657,23 @@ class Message {
|
|||||||
static constexpr int BYTESLENGTH = 57;
|
static constexpr int BYTESLENGTH = 57;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string m_SPITObjectID{};
|
string mSPITObjectID{};
|
||||||
uint64_t m_FrameInsideObject{};
|
uint64_t mFrameInsideObject{};
|
||||||
int m_Value{};
|
int mValue{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ReportPlayStatus(const ReportPlayStatus &orig);
|
ReportPlayStatus(const ReportPlayStatus &orig);
|
||||||
// Receive
|
// Receive
|
||||||
ReportPlayStatus(unique_ptr<Header> p_Header);
|
ReportPlayStatus(unique_ptr<Header> header);
|
||||||
bool parse(const std::vector<char> &message);
|
bool parse(const std::vector<char> &message);
|
||||||
|
|
||||||
const string getID() const { return m_SPITObjectID; }
|
const string getID() const { return mSPITObjectID; }
|
||||||
uint64_t getFrameInsideObject() const { return m_FrameInsideObject; }
|
uint64_t getFrameInsideObject() const { return mFrameInsideObject; }
|
||||||
int getValue() const { return m_Value; }
|
int getValue() const { return mValue; }
|
||||||
// Send
|
// Send
|
||||||
ReportPlayStatus();
|
ReportPlayStatus();
|
||||||
|
|
||||||
void setID(string p_ID);
|
void setID(string iD);
|
||||||
void setFrameInsideObject(uint64_t p_TimeInside);
|
void setFrameInsideObject(uint64_t p_TimeInside);
|
||||||
void setValue(int p_Value);
|
void setValue(int p_Value);
|
||||||
bool fillBytes(std::vector<char> &message);
|
bool fillBytes(std::vector<char> &message);
|
||||||
|
|||||||
@@ -0,0 +1,122 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "spit_type.hpp"
|
||||||
|
#include "spit_message.hpp"
|
||||||
|
#include "spit_repo.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
namespace spit {
|
||||||
|
|
||||||
|
class SObjectListener;
|
||||||
|
|
||||||
|
class SObject {
|
||||||
|
public:
|
||||||
|
template <typename T>
|
||||||
|
struct Property {
|
||||||
|
friend SObject;
|
||||||
|
Property(bool &confirmed)
|
||||||
|
: rConfirmed(confirmed) {
|
||||||
|
}
|
||||||
|
bool set(const T& val) {
|
||||||
|
if (mValue == val)
|
||||||
|
return false;
|
||||||
|
mValue = val;
|
||||||
|
rConfirmed = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
T get () const {
|
||||||
|
return mValue;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
bool & rConfirmed;
|
||||||
|
T mValue{};
|
||||||
|
};
|
||||||
|
|
||||||
|
Property<string> Name{mConfirmed};
|
||||||
|
Property<string> Remark{mConfirmed};
|
||||||
|
Property<string> ServerParams{mConfirmed};
|
||||||
|
Property<string> SPITTypeID{mConfirmed};
|
||||||
|
// 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
|
||||||
|
// true = the action is triggered on the server. The server waits for the client to play objects of this SPITType.
|
||||||
|
Property<bool> ServerRemote{mConfirmed};
|
||||||
|
Property<bool> Fixed{mConfirmed};
|
||||||
|
Property<uint64_t> FrameStart{mConfirmed};
|
||||||
|
Property<uint64_t> FrameLength{mConfirmed};
|
||||||
|
Property<uint64_t> FrameFadeInLength{mConfirmed};
|
||||||
|
Property<uint64_t> FrameFadeOutLength{mConfirmed};
|
||||||
|
Property<char> ValueUse{mConfirmed};
|
||||||
|
Property<int> ValueFactor{mConfirmed};
|
||||||
|
Property<int> Track{mConfirmed};
|
||||||
|
Property<uint64_t> Delay{mConfirmed};
|
||||||
|
Property<uint64_t> Duration{mConfirmed};
|
||||||
|
|
||||||
|
static void clearUnconfirmedObjects(SpitRepo<SObject> &repo);
|
||||||
|
static void setConfirmedFalse(SpitRepo<SObject> &repo);
|
||||||
|
static void eventProjectClosed(SpitRepo<SObject> &repo, SpitRepo<SObject> &remoteRepo);
|
||||||
|
|
||||||
|
SObject(string iD) {
|
||||||
|
mID = iD;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
string mID;
|
||||||
|
bool mConfirmed{};
|
||||||
|
bool mCreatedByClient{};
|
||||||
|
bool mActionAssigned{};
|
||||||
|
bool mActionAssignedType{}; // Virtual construct
|
||||||
|
char mValueUse{0x01};
|
||||||
|
int mValueFactor{1000000}; // Values are given in ppm -> 1000000 = 1/1;
|
||||||
|
bool mPlayPrePosition;
|
||||||
|
uint64_t mPlayTimeInsideFrames;
|
||||||
|
int mPlayValue;
|
||||||
|
char mPlayValueFlag;
|
||||||
|
|
||||||
|
public:
|
||||||
|
string getID() const { return mID; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
bool getConfirmed() const { return mConfirmed; }
|
||||||
|
bool getCreatedByClient() const { return mCreatedByClient; }
|
||||||
|
/**
|
||||||
|
* 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 SObject with the SPITType.
|
||||||
|
* @return true = an action is assigned for the SPITType.
|
||||||
|
*/
|
||||||
|
bool getActionAssignedType() const { return mActionAssignedType; }
|
||||||
|
/** Returns if this SObject has an associated action or not.
|
||||||
|
* @return true = the user has asscociated an action with this SObject or
|
||||||
|
* the user has asscociated an action with the SPITType of this SObject
|
||||||
|
*/
|
||||||
|
bool getActionAssigned() const { return mActionAssigned || mActionAssignedType; }
|
||||||
|
|
||||||
|
bool getProjectIndepended(SpitRepo<SType> &repo, SpitRepo<SType> &remoteRepo) const {
|
||||||
|
SType *ptrSPITType;
|
||||||
|
if (ServerRemote.get() == false) {
|
||||||
|
ptrSPITType = repo.getEntry(SPITTypeID.get());
|
||||||
|
if (ptrSPITType == nullptr)
|
||||||
|
return true;
|
||||||
|
return ptrSPITType->ProjectIndepended.get();
|
||||||
|
} else {
|
||||||
|
ptrSPITType = remoteRepo.getEntry(SPITTypeID.get());
|
||||||
|
if (ptrSPITType == nullptr)
|
||||||
|
return true;
|
||||||
|
return ptrSPITType->ProjectIndepended.get();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool setConfirmed(bool confirmed);
|
||||||
|
void setCreatedByClient(bool createdByClient) { mCreatedByClient = createdByClient; }
|
||||||
|
bool setActionAssignedType(bool actionAssigned);
|
||||||
|
bool setActionAssigned(bool actionAssigned);
|
||||||
|
|
||||||
|
bool setMessageOP(Message::ReportObject *message);
|
||||||
|
void fillMessageOP(Message::ReportObject &message);
|
||||||
|
void fillMessageOP(Message::RemoveObject &message);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "spit_object.hpp"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace spit {
|
||||||
|
|
||||||
|
class SPlayer {
|
||||||
|
|
||||||
|
//----- PlayObject used in PlaySequences: PlaySPITStart, PlaySPITObject,..., PlaySPITEnd ------
|
||||||
|
public:
|
||||||
|
class PlayType {
|
||||||
|
public:
|
||||||
|
PlayType(SPlayer *spitPlayer, string spitObjectID);
|
||||||
|
PlayType(const PlayType &orig);
|
||||||
|
|
||||||
|
string getSPITTypeID() const { return mSpitTypeID; }
|
||||||
|
|
||||||
|
void startPlaySequence();
|
||||||
|
bool getIsNew() const { return mIsNew; }
|
||||||
|
void setIsNew(bool isNew) { mIsNew = isNew; }
|
||||||
|
bool getIsPlayed() const { return mIsPlayed; }
|
||||||
|
void setIsPlayed(bool p_IsFound) { mIsPlayed = p_IsFound; }
|
||||||
|
string getPlayerID() const { return mPlayerID; }
|
||||||
|
string getPlayerName() const { return mPlayerName; }
|
||||||
|
bool getPlayerIsRunning() const { return mPlayerRuns; }
|
||||||
|
void setPlayerIsRunning(bool playerRuns) { mPlayerRuns = playerRuns; }
|
||||||
|
void setValue(double value) { mValue = value; }
|
||||||
|
void addValue(double value, double valueFactor) { mValue += (value * valueFactor); }
|
||||||
|
double getValue() const { return mValue; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
string mPlayerID;
|
||||||
|
string mPlayerName;
|
||||||
|
bool mPlayerRuns;
|
||||||
|
string mSpitTypeID;
|
||||||
|
bool mIsPlayed;
|
||||||
|
bool mIsNew;
|
||||||
|
double mValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
//----- SPlayer ------
|
||||||
|
public:
|
||||||
|
// list the SPITPlayers
|
||||||
|
static unordered_map<string, unique_ptr<SPlayer>> sSpitPlayers; // all actual played objects
|
||||||
|
static SPlayer &getSPITPlayer(string pPlayerID); // if a player does not exist creates a new one
|
||||||
|
static void clearPlayers() { sSpitPlayers.clear(); }
|
||||||
|
|
||||||
|
SPlayer(string pPlayerID);
|
||||||
|
virtual ~SPlayer();
|
||||||
|
|
||||||
|
void startPlaySequence(); // called by SPIT_Client::parsePlaySPITStart
|
||||||
|
PlayType *addTypePlaying(string spitTypeID); // called by SPIT_Client::parsePlaySPITStart
|
||||||
|
void endPlaySequence(); // called by SPIT_Client::parsePlaySPITEnd
|
||||||
|
|
||||||
|
string getID() {
|
||||||
|
return mId;
|
||||||
|
}
|
||||||
|
|
||||||
|
unordered_map<string, unique_ptr<PlayType>> &getPlaySPITTypes() { return mPlaySPITTypes; }
|
||||||
|
void setIsRunning(bool isRunning) { mIsRunning = isRunning; }
|
||||||
|
void setName(string name) { mName = name; }
|
||||||
|
void setType(char type) { mType = type; }
|
||||||
|
void setTime(uint64_t frames) { mTimeFrames = frames; }
|
||||||
|
bool getIsRunning() const { return mIsRunning; }
|
||||||
|
string getName() const { return mName; }
|
||||||
|
char getType() const { return mType; }
|
||||||
|
uint64_t getTime() const { return mTimeFrames; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
string mId;
|
||||||
|
string mName;
|
||||||
|
char mType;
|
||||||
|
unordered_map<string, unique_ptr<PlayType>> mPlaySPITTypes;
|
||||||
|
|
||||||
|
bool mIsRunning;
|
||||||
|
uint64_t mTimeFrames;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|||||||
@@ -0,0 +1,149 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Task.hpp"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "esp_netif.h"
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <string>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace spit {
|
||||||
|
|
||||||
|
/** Returns an guid */
|
||||||
|
string createGUID();
|
||||||
|
/** Returns the name of the client's host computer*/
|
||||||
|
string getClientHostName();
|
||||||
|
|
||||||
|
class ISocket {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* IpAddress class is used to fetch all available IP addresses of the computer
|
||||||
|
* This is for internal usage
|
||||||
|
*/
|
||||||
|
struct IpAddress {
|
||||||
|
public:
|
||||||
|
IpAddress(const string &iPAddress, const string &subnetMask)
|
||||||
|
: mIpAddress(iPAddress), mSubnetMask(subnetMask) {}
|
||||||
|
const string mIpAddress;
|
||||||
|
const string mSubnetMask;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the broadcast address from a ip4 address
|
||||||
|
* @param iPAddress the ip4 address
|
||||||
|
* @return returns the broadcast address
|
||||||
|
*/
|
||||||
|
string getBroadcastIP4() const {
|
||||||
|
struct in_addr broadcast;
|
||||||
|
unsigned long ipAddress;
|
||||||
|
unsigned long subnetMask;
|
||||||
|
|
||||||
|
ipAddress = inet_addr(mIpAddress.data());
|
||||||
|
subnetMask = inet_addr(mSubnetMask.data());
|
||||||
|
broadcast.s_addr = ipAddress | ~subnetMask;
|
||||||
|
return inet_ntoa(broadcast);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const IpAddress mOwnIp;
|
||||||
|
|
||||||
|
ISocket(IpAddress ip)
|
||||||
|
: mOwnIp(ip) {}
|
||||||
|
|
||||||
|
virtual int sendMessage(const char *message, int length) = 0;
|
||||||
|
virtual int receiveMessage(char *bu1ffer, int bufferLength, string *serverIp) const =0;
|
||||||
|
virtual void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) =0;
|
||||||
|
virtual int bindSocket(string clientIp, string clientPort) =0;
|
||||||
|
virtual int setBroadcast(bool broadcast) const =0;
|
||||||
|
virtual int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) =0;
|
||||||
|
|
||||||
|
bool getIsBound() const { return mIsBound; }
|
||||||
|
protected:
|
||||||
|
bool mIsBound{};
|
||||||
|
};
|
||||||
|
|
||||||
|
class Socket : public ISocket {
|
||||||
|
public:
|
||||||
|
static const int FAMILY_IP4 = AF_INET;
|
||||||
|
|
||||||
|
|
||||||
|
static IpAddress getAdaptersInfo();
|
||||||
|
bool createSocketUdp();
|
||||||
|
static const int INVALID_SOCKET = -1;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int mUdpSocketIp4;
|
||||||
|
|
||||||
|
public:
|
||||||
|
//-------- class --------------
|
||||||
|
Socket(IpAddress ip) : ISocket(ip) {
|
||||||
|
mUdpSocketIp4 = INVALID_SOCKET;
|
||||||
|
createSocketUdp();
|
||||||
|
}
|
||||||
|
virtual ~Socket() {
|
||||||
|
ESP_LOGD("UDP", "Shutting down ...");
|
||||||
|
|
||||||
|
if (mUdpSocketIp4 != INVALID_SOCKET) {
|
||||||
|
shutdown(mUdpSocketIp4, 2);
|
||||||
|
close(mUdpSocketIp4);
|
||||||
|
mUdpSocketIp4 = INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
fos::Task::delayMs(100);
|
||||||
|
mIsBound = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
string mServerIP{};
|
||||||
|
string mServerPort{};
|
||||||
|
string mClientIp{};
|
||||||
|
string mClientPort{}; // port given by the user maybe "0"
|
||||||
|
string mBoundClientPort{}; // port set after bind
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Sets the ip address and port for server and client.
|
||||||
|
void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) override {
|
||||||
|
mServerIP = serverIp;
|
||||||
|
mServerPort = serverPort;
|
||||||
|
mClientIp = clientIp;
|
||||||
|
mClientPort = clientPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a message to the server as set by setConnectionParams
|
||||||
|
* @param message byte buffer containing the message
|
||||||
|
* @param length length of the message
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int sendMessage(const char *message, int length) override {
|
||||||
|
if (mServerPort.length() <= 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (mIsBound == false) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
int intResult = sendMessageTo(mServerIP, mServerPort, message, length);
|
||||||
|
return intResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
int receiveMessage(char *bu1ffer, int bufferLength, string *serverIp) const override;
|
||||||
|
int setBroadcast(bool broadcast) const override;
|
||||||
|
int bindSocket(string clientIp, string clientPort) override;
|
||||||
|
int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) override;
|
||||||
|
|
||||||
|
string getServerIP() const { return mServerIP; }
|
||||||
|
string getServerPort() const { return mServerPort; }
|
||||||
|
string getClientIP() const { return mClientIp; }
|
||||||
|
string getClientPort() const { return mClientPort; }
|
||||||
|
string getBoundClientPort() const { return mBoundClientPort; }
|
||||||
|
void setBoundClientPort(const string &port) { mBoundClientPort = port; }
|
||||||
|
void setIsBound(bool isBound) { mIsBound = isBound; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "spit_socket.hpp"
|
||||||
|
#include "spit_message.hpp"
|
||||||
|
#include "spit_repo.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
namespace spit {
|
||||||
|
|
||||||
|
class STypeListener;
|
||||||
|
|
||||||
|
class SType {
|
||||||
|
public:
|
||||||
|
template <typename T>
|
||||||
|
struct Property {
|
||||||
|
friend SType;
|
||||||
|
Property(bool &confirmed)
|
||||||
|
: rConfirmed(confirmed) {
|
||||||
|
}
|
||||||
|
bool set(const T& val) {
|
||||||
|
if (mValue == val)
|
||||||
|
return false;
|
||||||
|
mValue = val;
|
||||||
|
rConfirmed = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
T get () const {
|
||||||
|
return mValue;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
bool & rConfirmed;
|
||||||
|
T mValue{};
|
||||||
|
};
|
||||||
|
|
||||||
|
Property<string> GroupName{mConfirmed};
|
||||||
|
Property<string> Name{mConfirmed};
|
||||||
|
Property<bool> Fixed{mConfirmed};
|
||||||
|
Property<bool> ProjectIndepended{mConfirmed};
|
||||||
|
// Returns if the SType 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 SType
|
||||||
|
// true = the action is triggered on the server. The server waits for the client to play objects of this SType.
|
||||||
|
Property<bool> ServerRemote{mConfirmed};
|
||||||
|
Property<uint64_t> DefaultDelay{mConfirmed};
|
||||||
|
Property<uint64_t> DefaultDuration{mConfirmed};
|
||||||
|
// Virtual construct - means ActionAssigned for STypes is is not implemented in SPITProtocol.
|
||||||
|
// This can used to setActionAssigned to all SPITObjects with this SType.
|
||||||
|
// This may be used in the case when the same action should be done for every SPITObject with this SType associated.
|
||||||
|
// @return true = the user has associated an action with this SType.
|
||||||
|
Property<bool> ActionAssigned{mConfirmed};
|
||||||
|
|
||||||
|
// Sets confirmed = false for all STypes.
|
||||||
|
// This should be called when the client has loaded a project.
|
||||||
|
static void setConfirmedFalse(SpitRepo<SType> &repo) {
|
||||||
|
auto &entries = repo.getRepo();
|
||||||
|
for (auto i = entries.begin(); i != entries.end(); i++) {
|
||||||
|
i->second->setConfirmed(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void eventProjectClosed(SpitRepo<SType> &repo, SpitRepo<SType> &remoteRepo) {
|
||||||
|
auto &entries = repo.getRepo();
|
||||||
|
for (auto i = entries.begin(); i != entries.end();) {
|
||||||
|
SType *ptrSType = i->second.get();
|
||||||
|
if (ptrSType->getCreatedByClient() == true) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i = entries.erase(i);
|
||||||
|
}
|
||||||
|
// Remote
|
||||||
|
remoteRepo.clearEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
SType(string iD) {
|
||||||
|
mID = iD;
|
||||||
|
}
|
||||||
|
SType(string iD, string grpName, string name, bool fixed, bool projectIndependent, uint64_t delay, uint64_t duration) {
|
||||||
|
mConfirmed = false;
|
||||||
|
mID = iD;
|
||||||
|
ActionAssigned.set(false);
|
||||||
|
GroupName.set(grpName);
|
||||||
|
Name.set(name);
|
||||||
|
Fixed.set(fixed);
|
||||||
|
ProjectIndepended.set(projectIndependent);
|
||||||
|
DefaultDelay.set(delay);
|
||||||
|
DefaultDuration.set(duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool mConfirmed{};
|
||||||
|
string mID;
|
||||||
|
bool mCreatedByClient; // flag true = the SPITTyype is created by the client
|
||||||
|
// false = the SType is received from the server
|
||||||
|
|
||||||
|
public:
|
||||||
|
string getID() const { return mID; }
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
bool getConfirmed() const { return mConfirmed; }
|
||||||
|
bool getCreatedByClient() const { return mCreatedByClient; }
|
||||||
|
void setCreatedByClient(bool createdByClient) { mCreatedByClient = createdByClient; }
|
||||||
|
|
||||||
|
// Set the content of the SType as received from the server
|
||||||
|
// @param p_ReportSType
|
||||||
|
// @return true = the SType is changed
|
||||||
|
// false = the SType is NOT changed, because it is not allowed to change.
|
||||||
|
bool setMessageOP(Message::ReportType &message) {
|
||||||
|
bool changeAllowed;
|
||||||
|
|
||||||
|
if ((mCreatedByClient == true) && (Fixed.get() == true)) {
|
||||||
|
changeAllowed = false;
|
||||||
|
} else {
|
||||||
|
changeAllowed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirmation should be changeable
|
||||||
|
if (mCreatedByClient) {
|
||||||
|
// Server reports a client created SType -> the type is confirmed
|
||||||
|
mConfirmed = true;
|
||||||
|
} else {
|
||||||
|
// type is NOT client created -> the client has to confirm the SPITtype
|
||||||
|
mConfirmed = message.getConfirmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changeAllowed == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
if (DefaultDelay.mValue != message.getDelay()) {
|
||||||
|
DefaultDelay.mValue = message.getDelay();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (DefaultDuration.mValue != message.getDuration()) {
|
||||||
|
DefaultDuration.mValue = message.getDuration();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (Fixed.mValue != message.getFixed()) {
|
||||||
|
Fixed.mValue = message.getFixed();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (GroupName.mValue != message.getGroupName()) {
|
||||||
|
GroupName.mValue = message.getGroupName();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (mID != message.getID()) {
|
||||||
|
mID = message.getID();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (Name.mValue != message.getName()) {
|
||||||
|
Name.mValue = message.getName();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (ProjectIndepended.mValue != message.getServerProjectIndepended()) {
|
||||||
|
ProjectIndepended.mValue = message.getServerProjectIndepended();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (ServerRemote.mValue != message.getServerRemote()) {
|
||||||
|
ServerRemote.mValue = message.getServerRemote();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
void fillMessageOP(Message::ReportType &message) const {
|
||||||
|
message.setConfirmed(mConfirmed);
|
||||||
|
message.setDelay(DefaultDelay.mValue);
|
||||||
|
message.setDuration(DefaultDuration.mValue);
|
||||||
|
message.setFixed(Fixed.mValue);
|
||||||
|
message.setGroupName(GroupName.mValue);
|
||||||
|
message.setID(mID);
|
||||||
|
message.setName(Name.mValue);
|
||||||
|
message.setServerProjectIndepended(ProjectIndepended.mValue);
|
||||||
|
message.setServerRemote(ServerRemote.mValue);
|
||||||
|
}
|
||||||
|
void fillMessageOP(Message::RemoveType &message) const {
|
||||||
|
message.setID(mID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is used by the server and client to tell if the other side has registered the changes.
|
||||||
|
// @param confirmed
|
||||||
|
// @return if mConfirmed has changed
|
||||||
|
bool setConfirmed(bool confirmed) {
|
||||||
|
if (mConfirmed == confirmed)
|
||||||
|
return false;
|
||||||
|
mConfirmed = confirmed;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,364 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* SPITObject describes a SPIT Object
|
|
||||||
* File: SPITObject.cpp
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 9. April 2019, 12:11
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "SPITObject.h"
|
|
||||||
#include "SPITSocket.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clears all unconfirmed SPITObjects not created by this SPIT_Client.
|
|
||||||
*/
|
|
||||||
void SPITObject::clearUnconfirmedSPITObjects(SpitRepo<SPITObject> &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 = entries.erase(i);
|
|
||||||
} else {
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPITObject::eventProjectClosed(SpitRepo<SPITObject> &repo, SpitRepo<SPITObject> &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 = entries.erase(i);
|
|
||||||
}
|
|
||||||
// Remote
|
|
||||||
remoteRepo.clearEntries();
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* sets confirmed = false for all SPITObjects.
|
|
||||||
* This should be called when the client has loaded a project.
|
|
||||||
*/
|
|
||||||
void SPITObject::setConfirmedFalse(SpitRepo<SPITObject> &repo) {
|
|
||||||
auto &entries = repo.getRepo();
|
|
||||||
for (auto i = entries.begin(); i != entries.end(); i++) {
|
|
||||||
i->second->setConfirmed(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SPITObject::SPITObject(string p_ID) {
|
|
||||||
m_ID = p_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SPITObject::setMessageOP(Message::ReportObject *p_ReportSPITObject) {
|
|
||||||
bool boolChangeAllowed;
|
|
||||||
bool boolChanged = false;
|
|
||||||
|
|
||||||
if (m_CreatedByClient == true && m_Fixed == true) {
|
|
||||||
boolChangeAllowed = false;
|
|
||||||
} else {
|
|
||||||
boolChangeAllowed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Confirmation should be changable
|
|
||||||
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_ReportSPITObject->getConfirmed();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_Delay != p_ReportSPITObject->getDelay()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_Delay = p_ReportSPITObject->getDelay();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_Duration != p_ReportSPITObject->getDuration()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_Duration = p_ReportSPITObject->getDuration();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_Fixed != p_ReportSPITObject->getFixed()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_Fixed = p_ReportSPITObject->getFixed();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_FrameFadeInLength != p_ReportSPITObject->getFrameFadeInLength()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_FrameFadeInLength = p_ReportSPITObject->getFrameFadeInLength();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_FrameFadeOutLength != p_ReportSPITObject->getFrameFadeOutLength()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_FrameFadeOutLength = p_ReportSPITObject->getFrameFadeOutLength();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_FrameLength != p_ReportSPITObject->getFrameLength()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_FrameLength = p_ReportSPITObject->getFrameLength();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_FrameStart != p_ReportSPITObject->getFrameStart()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_FrameStart = p_ReportSPITObject->getFrameStart();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_Remark != p_ReportSPITObject->getRemark()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_Remark = p_ReportSPITObject->getRemark();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_ID != p_ReportSPITObject->getID()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_ID = p_ReportSPITObject->getID();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_Name != p_ReportSPITObject->getName()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_Name = p_ReportSPITObject->getName();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_SPITTypeID != p_ReportSPITObject->getSPITTypeID()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_SPITTypeID = p_ReportSPITObject->getSPITTypeID();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_ServerParams != p_ReportSPITObject->getServerParams()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_ServerParams = p_ReportSPITObject->getServerParams();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_ServerRemote != p_ReportSPITObject->getServerRemote()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_ServerRemote = p_ReportSPITObject->getServerRemote();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_Track != p_ReportSPITObject->getTrack()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_Track = p_ReportSPITObject->getTrack();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_ValueFactor != p_ReportSPITObject->getValueFactor()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_ValueFactor = p_ReportSPITObject->getValueFactor();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_ValueUse != p_ReportSPITObject->getValueUse()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_ValueUse = p_ReportSPITObject->getValueUse();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
return boolChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPITObject::fillMessageOP(Message::ReportObject &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(Message::RemoveObject &p_RemoveSPITObject) {
|
|
||||||
p_RemoveSPITObject.setID(m_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is used by the server and client to tell if the other side has registered the changes.
|
|
||||||
* @param p_Confirmed
|
|
||||||
* @return if m_Confirmed has changed
|
|
||||||
*/
|
|
||||||
bool SPITObject::setConfirmed(bool p_Confirmed) {
|
|
||||||
if (m_Confirmed == p_Confirmed)
|
|
||||||
return false;
|
|
||||||
m_Confirmed = p_Confirmed;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SPITObject::setName(string p_Name) {
|
|
||||||
if (m_Name == p_Name)
|
|
||||||
return false;
|
|
||||||
m_Name = p_Name;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setRemark(string p_Remark) {
|
|
||||||
if (m_Remark == p_Remark)
|
|
||||||
return false;
|
|
||||||
m_Remark = p_Remark;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setServerParams(string p_ServerParams) {
|
|
||||||
if (m_ServerParams == p_ServerParams)
|
|
||||||
return false;
|
|
||||||
m_ServerParams = p_ServerParams;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setSPITTypeID(string p_SPITTypeID) {
|
|
||||||
if (m_SPITTypeID == p_SPITTypeID)
|
|
||||||
return false;
|
|
||||||
m_SPITTypeID = p_SPITTypeID;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setServerRemote(bool p_BelongstoServer) {
|
|
||||||
if (m_ServerRemote == p_BelongstoServer)
|
|
||||||
return false;
|
|
||||||
m_ServerRemote = p_BelongstoServer;
|
|
||||||
m_Confirmed = false;
|
|
||||||
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.
|
|
||||||
* Then this action is done for every SPITObject with the SPITType.
|
|
||||||
* @return true = an action is assigned for the SPITType.
|
|
||||||
*/
|
|
||||||
bool SPITObject::setActionAssignedType(bool p_ActionAssigned) {
|
|
||||||
if (m_ActionAssignedType == p_ActionAssigned)
|
|
||||||
return false;
|
|
||||||
bool boolOldActionAssigend;
|
|
||||||
boolOldActionAssigend = getActionAssigned();
|
|
||||||
m_ActionAssignedType = p_ActionAssigned;
|
|
||||||
if (getActionAssigned() == boolOldActionAssigend)
|
|
||||||
return false;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setActionAssigned(bool p_ActionAssigned) {
|
|
||||||
if (m_ActionAssigned == p_ActionAssigned)
|
|
||||||
return false;
|
|
||||||
bool boolOldActionAssigend;
|
|
||||||
boolOldActionAssigend = getActionAssigned();
|
|
||||||
m_ActionAssigned = p_ActionAssigned;
|
|
||||||
if (getActionAssigned() == boolOldActionAssigend)
|
|
||||||
return false;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setFixed(bool p_Fixed) {
|
|
||||||
if (m_Fixed == p_Fixed)
|
|
||||||
return false;
|
|
||||||
m_Fixed = p_Fixed;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setFrameStart(long long p_FrameStart) {
|
|
||||||
if (m_FrameStart == p_FrameStart)
|
|
||||||
return false;
|
|
||||||
m_FrameStart = p_FrameStart;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setFrameLength(long long p_FrameLength) {
|
|
||||||
if (m_FrameLength == p_FrameLength)
|
|
||||||
return false;
|
|
||||||
m_FrameLength = p_FrameLength;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setFrameFadeInLength(long long p_FrameFadeInLength) {
|
|
||||||
if (m_FrameFadeInLength == p_FrameFadeInLength)
|
|
||||||
return false;
|
|
||||||
m_FrameFadeInLength = p_FrameFadeInLength;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setFrameFadeOutLength(long long p_FrameFadeOutLength) {
|
|
||||||
if (m_FrameFadeOutLength == p_FrameFadeOutLength)
|
|
||||||
return false;
|
|
||||||
m_FrameFadeOutLength = p_FrameFadeOutLength;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setValueUse(char p_ValueUse) {
|
|
||||||
if (m_ValueUse == p_ValueUse)
|
|
||||||
return false;
|
|
||||||
m_ValueUse = p_ValueUse;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setValueFactor(int p_ValueFactor) {
|
|
||||||
if (m_ValueFactor == p_ValueFactor)
|
|
||||||
return false;
|
|
||||||
m_ValueFactor = p_ValueFactor;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setTrack(int p_Track) {
|
|
||||||
if (m_Track == p_Track)
|
|
||||||
return false;
|
|
||||||
m_Track = p_Track;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setDelay(long long p_Delay) {
|
|
||||||
if (m_Delay == p_Delay)
|
|
||||||
return false;
|
|
||||||
m_Delay = p_Delay;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITObject::setDuration(long long p_Duration) {
|
|
||||||
if (m_Duration == p_Duration)
|
|
||||||
return false;
|
|
||||||
m_Duration = p_Duration;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,102 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* SPITPlayer describes a virtual SPIT Player.
|
|
||||||
* File: SPITPLayer.cpp
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 30. April 2019, 11:44
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "SPITPlayer.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
unordered_map<string, unique_ptr<SPITPlayer>> SPITPlayer::s_SPITPlayers;
|
|
||||||
|
|
||||||
SPITPlayer &SPITPlayer::getSPITPlayer(string p_PlayerID) {
|
|
||||||
auto i = s_SPITPlayers.find(p_PlayerID);
|
|
||||||
if (i == s_SPITPlayers.end()) {
|
|
||||||
s_SPITPlayers[p_PlayerID] = make_unique<SPITPlayer>(p_PlayerID);
|
|
||||||
}
|
|
||||||
return *s_SPITPlayers.at(p_PlayerID);
|
|
||||||
}
|
|
||||||
|
|
||||||
SPITPlayer::SPITPlayer(string p_PlayerID) {
|
|
||||||
m_ID = p_PlayerID;
|
|
||||||
}
|
|
||||||
|
|
||||||
SPITPlayer::~SPITPlayer() {
|
|
||||||
m_PlaySPITTypes.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param p_SPITObjectID
|
|
||||||
* @return true = new PlayObject added<br>
|
|
||||||
* false = PlayObject exists
|
|
||||||
*/
|
|
||||||
SPITPlayer::PlaySPITType *SPITPlayer::addSPITType_Playing(string p_SPITTypeID) {
|
|
||||||
PlaySPITType *ptrPlaySPITType;
|
|
||||||
auto i = m_PlaySPITTypes.find(p_SPITTypeID);
|
|
||||||
if (i == m_PlaySPITTypes.end()) {
|
|
||||||
auto playSpitType = make_unique<PlaySPITType>(this, p_SPITTypeID);
|
|
||||||
ptrPlaySPITType = playSpitType.get();
|
|
||||||
m_PlaySPITTypes[p_SPITTypeID] = move(playSpitType);
|
|
||||||
} else {
|
|
||||||
ptrPlaySPITType = i->second.get();
|
|
||||||
}
|
|
||||||
ptrPlaySPITType->setIsPlayed(true);
|
|
||||||
return ptrPlaySPITType;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPITPlayer::startPlaySequence() {
|
|
||||||
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
|
|
||||||
PlaySPITType *ptrPlaySPITType = i->second.get();
|
|
||||||
ptrPlaySPITType->startPlaySequence();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPITPlayer::endPlaySequence() {
|
|
||||||
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end();) {
|
|
||||||
if (i->second.get()->getIsPlayed() == false) {
|
|
||||||
i = m_PlaySPITTypes.erase(i);
|
|
||||||
} else {
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
|
||||||
startPlaySequence();
|
|
||||||
m_IsNew = true;
|
|
||||||
}
|
|
||||||
SPITPlayer::PlaySPITType::PlaySPITType(const PlaySPITType &orig) {
|
|
||||||
m_SPITTypeID = orig.getSPITTypeID();
|
|
||||||
m_IsPlayed = orig.getIsPlayed();
|
|
||||||
m_IsNew = orig.getIsNew();
|
|
||||||
|
|
||||||
m_PlayerID = orig.getPlayerID();
|
|
||||||
m_PlayerName = orig.getPlayerName();
|
|
||||||
m_PlayerRuns = orig.getPlayerIsRunning();
|
|
||||||
|
|
||||||
m_Value = orig.getValue();
|
|
||||||
}
|
|
||||||
void SPITPlayer::PlaySPITType::startPlaySequence() {
|
|
||||||
m_IsPlayed = false;
|
|
||||||
m_IsNew = false;
|
|
||||||
|
|
||||||
m_Value = 0;
|
|
||||||
}
|
|
||||||
@@ -1,239 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* SPITType describes a SPIT Type
|
|
||||||
* File: SPITType.cpp
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 8. April 2019, 08:40
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "SPITType.h"
|
|
||||||
#include "esp_log.h"
|
|
||||||
|
|
||||||
using namespace spit;
|
|
||||||
|
|
||||||
static const char *TAG = "SPIT";
|
|
||||||
|
|
||||||
void SPITType::eventProjectClosed(SpitRepo<SPITType> &repo, SpitRepo<SPITType> &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 = entries.erase(i);
|
|
||||||
}
|
|
||||||
// Remote
|
|
||||||
remoteRepo.clearEntries();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets confirmed = false for all SPITTypes.
|
|
||||||
* This should be called when the client has loaded a project.
|
|
||||||
*/
|
|
||||||
void SPITType::setConfirmedFalse(SpitRepo<SPITType> &repo) {
|
|
||||||
auto &entries = repo.getRepo();
|
|
||||||
for (auto i = entries.begin(); i != entries.end(); i++) {
|
|
||||||
i->second->setConfirmed(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SPITType::SPITType(string p_ID) {
|
|
||||||
m_ID = p_ID;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is used by the server and client to tell if the other side has registered the changes.
|
|
||||||
* @param p_Confirmed
|
|
||||||
* @return if m_Confirmed has changed
|
|
||||||
*/
|
|
||||||
bool SPITType::setConfirmed(bool p_Confirmed) {
|
|
||||||
if (m_Confirmed == p_Confirmed)
|
|
||||||
return false;
|
|
||||||
m_Confirmed = p_Confirmed;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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(const string &p_Name) {
|
|
||||||
if (m_Name == p_Name)
|
|
||||||
return false;
|
|
||||||
m_Name = p_Name;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITType::setServerRemote(bool p_BelongstoServer) {
|
|
||||||
if (m_ServerRemote == p_BelongstoServer)
|
|
||||||
return false;
|
|
||||||
m_ServerRemote = p_BelongstoServer;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITType::setProjectIndepended(bool p_ProjectIndepended) {
|
|
||||||
if (m_ServerProjectIndepended == p_ProjectIndepended)
|
|
||||||
return false;
|
|
||||||
m_ServerProjectIndepended = p_ProjectIndepended;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITType::setFixed(bool p_Fixed) {
|
|
||||||
if (m_Fixed == p_Fixed)
|
|
||||||
return false;
|
|
||||||
m_Fixed = p_Fixed;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITType::setDefaultDelay(long long p_Delay) {
|
|
||||||
if (m_DefaultDelay == p_Delay)
|
|
||||||
return false;
|
|
||||||
m_DefaultDelay = p_Delay;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
bool SPITType::setDefaultDuration(long long p_Duration) {
|
|
||||||
if (m_DefaultDuration == p_Duration)
|
|
||||||
return false;
|
|
||||||
m_DefaultDuration = p_Duration;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
if (m_ActionAssigned == p_ActionAssigned)
|
|
||||||
return false;
|
|
||||||
m_ActionAssigned = p_ActionAssigned;
|
|
||||||
m_Confirmed = false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the content of the SPITType as received from the server
|
|
||||||
* @param p_ReportSPITType
|
|
||||||
* @return true = the SPITType is changed
|
|
||||||
* false = the SPITType is NOT changed, because it is not allowed to change.
|
|
||||||
*/
|
|
||||||
bool SPITType::setMessageOP(Message::ReportType &reportSpitType) {
|
|
||||||
bool boolChangeAllowed;
|
|
||||||
bool boolChanged = false;
|
|
||||||
|
|
||||||
if (m_CreatedByClient == true && m_Fixed == true) {
|
|
||||||
boolChangeAllowed = false;
|
|
||||||
} else {
|
|
||||||
boolChangeAllowed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 = reportSpitType.getConfirmed();
|
|
||||||
}
|
|
||||||
if (m_DefaultDelay != reportSpitType.getDelay()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_DefaultDelay = reportSpitType.getDelay();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_DefaultDuration != reportSpitType.getDuration()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_DefaultDuration = reportSpitType.getDuration();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_Fixed != reportSpitType.getFixed()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_Fixed = reportSpitType.getFixed();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_GroupName != reportSpitType.getGroupName()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_GroupName = reportSpitType.getGroupName();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_ID != reportSpitType.getID()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_ID = reportSpitType.getID();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_Name != reportSpitType.getName()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_Name = reportSpitType.getName();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_ServerProjectIndepended != reportSpitType.getServerProjectIndepended()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_ServerProjectIndepended = reportSpitType.getServerProjectIndepended();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
if (m_ServerRemote != reportSpitType.getServerRemote()) {
|
|
||||||
if (boolChangeAllowed == false) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_ServerRemote = reportSpitType.getServerRemote();
|
|
||||||
boolChanged = true;
|
|
||||||
}
|
|
||||||
return boolChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SPITType::fillMessageOP(Message::ReportType &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(Message::RemoveType &smRemoveSpitType) const {
|
|
||||||
smRemoveSpitType.setID(m_ID);
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,18 +1,3 @@
|
|||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Message contains all SPIT messages.
|
|
||||||
* A Message contains a Header and an OPPart.
|
|
||||||
*
|
|
||||||
* File: Message.cpp
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 3. April 2019, 08:51
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "spit_message.hpp"
|
#include "spit_message.hpp"
|
||||||
|
|
||||||
@@ -47,76 +32,76 @@ bool Message::parse(std::vector<char> message) {
|
|||||||
// parse OP
|
// parse OP
|
||||||
switch (header->getType()) {
|
switch (header->getType()) {
|
||||||
case Message::Connect::OPFLAG: { // Connection
|
case Message::Connect::OPFLAG: { // Connection
|
||||||
m_OPPart = make_unique<Connect>(move(header));
|
oPPart = make_unique<Connect>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case Message::ConnectAnswer::OPFLAG: {
|
case Message::ConnectAnswer::OPFLAG: {
|
||||||
m_OPPart = make_unique<ConnectAnswer>(move(header));
|
oPPart = make_unique<ConnectAnswer>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case Disconnect::OPFLAG: {
|
case Disconnect::OPFLAG: {
|
||||||
m_OPPart = make_unique<Disconnect>(move(header));
|
oPPart = make_unique<Disconnect>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case Watchdog::OPFLAG: {
|
case Watchdog::OPFLAG: {
|
||||||
m_OPPart = make_unique<Watchdog>(move(header));
|
oPPart = make_unique<Watchdog>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case WatchdogAnswer::OPFLAG: {
|
case WatchdogAnswer::OPFLAG: {
|
||||||
m_OPPart = make_unique<WatchdogAnswer>(move(header));
|
oPPart = make_unique<WatchdogAnswer>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case ReportProject::OPFLAG: { // SpitProject
|
case ReportProject::OPFLAG: { // SpitProject
|
||||||
m_OPPart = make_unique<ReportProject>(move(header));
|
oPPart = make_unique<ReportProject>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case CloseProject::OPFLAG: {
|
case CloseProject::OPFLAG: {
|
||||||
m_OPPart = make_unique<CloseProject>(move(header));
|
oPPart = make_unique<CloseProject>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case RequestProjectTransfer::OPFLAG: {
|
case RequestProjectTransfer::OPFLAG: {
|
||||||
m_OPPart = make_unique<RequestProjectTransfer>(move(header));
|
oPPart = make_unique<RequestProjectTransfer>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case StartProjectTransfer::OPFLAG: {
|
case StartProjectTransfer::OPFLAG: {
|
||||||
m_OPPart = make_unique<StartProjectTransfer>(move(header));
|
oPPart = make_unique<StartProjectTransfer>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case EndProjectTransfer::OPFLAG: {
|
case EndProjectTransfer::OPFLAG: {
|
||||||
m_OPPart = make_unique<EndProjectTransfer>(move(header));
|
oPPart = make_unique<EndProjectTransfer>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case ReportType::OPFLAG: { // SpitType
|
case ReportType::OPFLAG: { // SpitType
|
||||||
m_OPPart = make_unique<ReportType>(move(header));
|
oPPart = make_unique<ReportType>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case RemoveType::OPFLAG: {
|
case RemoveType::OPFLAG: {
|
||||||
m_OPPart = make_unique<RemoveType>(move(header));
|
oPPart = make_unique<RemoveType>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case ReportObject::OPFLAG: { // SpitObject
|
case ReportObject::OPFLAG: { // SpitObject
|
||||||
m_OPPart = make_unique<ReportObject>(move(header));
|
oPPart = make_unique<ReportObject>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case RemoveObject::OPFLAG: {
|
case RemoveObject::OPFLAG: {
|
||||||
m_OPPart = make_unique<RemoveObject>(move(header));
|
oPPart = make_unique<RemoveObject>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case PlayStart::OPFLAG: { // PlaySpitObjects
|
case PlayStart::OPFLAG: { // PlaySpitObjects
|
||||||
m_OPPart = make_unique<PlayStart>(move(header));
|
oPPart = make_unique<PlayStart>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case PlayObject::OPFLAG: {
|
case PlayObject::OPFLAG: {
|
||||||
m_OPPart = make_unique<PlayObject>(move(header));
|
oPPart = make_unique<PlayObject>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case PlayEnd::OPFLAG: {
|
case PlayEnd::OPFLAG: {
|
||||||
m_OPPart = make_unique<PlayEnd>(move(header));
|
oPPart = make_unique<PlayEnd>(move(header));
|
||||||
} break;
|
} break;
|
||||||
case ReportPlayStatus::OPFLAG: {
|
case ReportPlayStatus::OPFLAG: {
|
||||||
m_OPPart = make_unique<ReportPlayStatus>(move(header));
|
oPPart = make_unique<ReportPlayStatus>(move(header));
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_OPPart->parse(message);
|
return oPPart->parse(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------- Send ----------
|
//---------- Send ----------
|
||||||
std::vector<char> Message::createMessage(OPPart &p_OPPart) {
|
std::vector<char> Message::createMessage(OPPart &oPPart) {
|
||||||
if (!p_OPPart.getHeader()) {
|
if (!oPPart.getHeader()) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int totalSize = Header::BYTESLENGTH + p_OPPart.getBytesCount();
|
int totalSize = Header::BYTESLENGTH + oPPart.getBytesCount();
|
||||||
std::vector<char> msgByts(totalSize);
|
std::vector<char> msgByts(totalSize);
|
||||||
p_OPPart.fillBytes(msgByts);
|
oPPart.fillBytes(msgByts);
|
||||||
return msgByts;
|
return msgByts;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "Failed to allocate memory");
|
ESP_LOGE(TAG, "Failed to allocate memory");
|
||||||
@@ -128,8 +113,8 @@ std::vector<char> Message::createMessage(OPPart &p_OPPart) {
|
|||||||
Message::Header::Header(const Header &orig) {
|
Message::Header::Header(const Header &orig) {
|
||||||
mID = &SPITID[0];
|
mID = &SPITID[0];
|
||||||
mMessageNumber = orig.getMessageNumber();
|
mMessageNumber = orig.getMessageNumber();
|
||||||
mServerID = orig.getServerID();
|
mServerId = orig.getServerID();
|
||||||
mClientID = orig.getClientID();
|
mClientId = orig.getClientID();
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::Header::Header() {
|
Message::Header::Header() {
|
||||||
@@ -152,8 +137,8 @@ bool Message::Header::parse(const std::vector<char> &message) {
|
|||||||
if (mBytesCount < 0) {
|
if (mBytesCount < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mServerID = getString(message, mParseOffset, 41).value();
|
mServerId = getString(message, mParseOffset, 41).value();
|
||||||
mClientID = getString(message, mParseOffset, 41).value();
|
mClientId = getString(message, mParseOffset, 41).value();
|
||||||
mOpFlag = message[mParseOffset++] & 0xFF;
|
mOpFlag = message[mParseOffset++] & 0xFF;
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse Header");
|
ESP_LOGE(TAG, "failed to parse Header");
|
||||||
@@ -176,8 +161,8 @@ bool Message::Header::fillBytes(std::vector<char> &message) {
|
|||||||
mParseOffset += setInt(SPITVERSION, message, mParseOffset);
|
mParseOffset += setInt(SPITVERSION, message, mParseOffset);
|
||||||
mParseOffset += setByte(mMessageNumber, message, mParseOffset);
|
mParseOffset += setByte(mMessageNumber, message, mParseOffset);
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(mServerID, message, mParseOffset, 41);
|
mParseOffset += setString(mServerId, message, mParseOffset, 41);
|
||||||
mParseOffset += setString(mClientID, message, mParseOffset, 41);
|
mParseOffset += setString(mClientId, message, mParseOffset, 41);
|
||||||
mParseOffset += setByte(mOpFlag, message, mParseOffset);
|
mParseOffset += setByte(mOpFlag, message, mParseOffset);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create Header");
|
ESP_LOGE(TAG, "failed to create Header");
|
||||||
@@ -226,12 +211,12 @@ bool Message::Connect::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_ClientComputerName = getString(message, mParseOffset, 64).value();
|
mClientComputerName = getString(message, mParseOffset, 64).value();
|
||||||
m_ClientName = getString(message, mParseOffset, 64).value();
|
mClientName = getString(message, mParseOffset, 64).value();
|
||||||
m_LoginName = getString(message, mParseOffset, 64).value();
|
mLoginName = getString(message, mParseOffset, 64).value();
|
||||||
m_LoginPassword = getString(message, mParseOffset, 64).value();
|
mLoginPassword = getString(message, mParseOffset, 64).value();
|
||||||
m_ServerIP = getString(message, mParseOffset, 40).value();
|
mServerIp = getString(message, mParseOffset, 40).value();
|
||||||
m_ServerPort = getInt(message, mParseOffset).value();
|
mServerPort = getInt(message, mParseOffset).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse Connect message");
|
ESP_LOGE(TAG, "failed to parse Connect message");
|
||||||
return false;
|
return false;
|
||||||
@@ -240,17 +225,17 @@ bool Message::Connect::parse(const std::vector<char> &message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
Message::Connect::Connect(string p_ComputerName, string p_ClientName)
|
Message::Connect::Connect(string pComputerName, string pClientName)
|
||||||
: OPPart(BYTESLENGTH),
|
: OPPart(BYTESLENGTH),
|
||||||
m_ClientComputerName(p_ComputerName),
|
mClientComputerName(pComputerName),
|
||||||
m_ClientName(p_ClientName) {
|
mClientName(pClientName) {
|
||||||
setHeader(OPFLAG);
|
setHeader(OPFLAG);
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
}
|
}
|
||||||
void Message::Connect::setServerPort(int p_ServerPort) {
|
void Message::Connect::setServerPort(int p_ServerPort) {
|
||||||
if (p_ServerPort < 0 || p_ServerPort > 65535)
|
if (p_ServerPort < 0 || p_ServerPort > 65535)
|
||||||
p_ServerPort = 0;
|
p_ServerPort = 0;
|
||||||
m_ServerPort = p_ServerPort;
|
mServerPort = p_ServerPort;
|
||||||
}
|
}
|
||||||
bool Message::Connect::fillBytes(std::vector<char> &message) {
|
bool Message::Connect::fillBytes(std::vector<char> &message) {
|
||||||
if (!mHeader) {
|
if (!mHeader) {
|
||||||
@@ -261,12 +246,12 @@ bool Message::Connect::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_ClientComputerName, message, mParseOffset, 64);
|
mParseOffset += setString(mClientComputerName, message, mParseOffset, 64);
|
||||||
mParseOffset += setString(m_ClientName, message, mParseOffset, 64);
|
mParseOffset += setString(mClientName, message, mParseOffset, 64);
|
||||||
mParseOffset += setString(m_LoginName, message, mParseOffset, 64);
|
mParseOffset += setString(mLoginName, message, mParseOffset, 64);
|
||||||
mParseOffset += setString(m_LoginPassword, message, mParseOffset, 64);
|
mParseOffset += setString(mLoginPassword, message, mParseOffset, 64);
|
||||||
mParseOffset += setString(m_ServerIP, message, mParseOffset, 40);
|
mParseOffset += setString(mServerIp, message, mParseOffset, 40);
|
||||||
mParseOffset += setInt(m_ServerPort, message, mParseOffset);
|
mParseOffset += setInt(mServerPort, message, mParseOffset);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create Connect message");
|
ESP_LOGE(TAG, "failed to create Connect message");
|
||||||
return false;
|
return false;
|
||||||
@@ -289,10 +274,10 @@ bool Message::ConnectAnswer::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_ServerComputerName = getString(message, mParseOffset, 64).value();
|
mServerComputerName = getString(message, mParseOffset, 64).value();
|
||||||
m_ServerName = getString(message, mParseOffset, 64).value();
|
mServerName = getString(message, mParseOffset, 64).value();
|
||||||
m_StepTime = getInt(message, mParseOffset).value();
|
mStepTime = getInt(message, mParseOffset).value();
|
||||||
m_Connected = getBoolean(message, mParseOffset).value();
|
mConnected = getBoolean(message, mParseOffset).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse ConnectAnswer message");
|
ESP_LOGE(TAG, "failed to parse ConnectAnswer message");
|
||||||
return false;
|
return false;
|
||||||
@@ -309,7 +294,7 @@ Message::ConnectAnswer::ConnectAnswer()
|
|||||||
void Message::ConnectAnswer::setStepTime(int p_StepTime_ms) {
|
void Message::ConnectAnswer::setStepTime(int p_StepTime_ms) {
|
||||||
if (p_StepTime_ms < 0)
|
if (p_StepTime_ms < 0)
|
||||||
p_StepTime_ms = 1;
|
p_StepTime_ms = 1;
|
||||||
m_StepTime = p_StepTime_ms;
|
mStepTime = p_StepTime_ms;
|
||||||
}
|
}
|
||||||
bool Message::ConnectAnswer::fillBytes(std::vector<char> &message) {
|
bool Message::ConnectAnswer::fillBytes(std::vector<char> &message) {
|
||||||
if (!mHeader) {
|
if (!mHeader) {
|
||||||
@@ -320,10 +305,10 @@ bool Message::ConnectAnswer::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_ServerComputerName, message, mParseOffset, 64);
|
mParseOffset += setString(mServerComputerName, message, mParseOffset, 64);
|
||||||
mParseOffset += setString(m_ServerName, message, mParseOffset, 64);
|
mParseOffset += setString(mServerName, message, mParseOffset, 64);
|
||||||
mParseOffset += setInt(m_StepTime, message, mParseOffset);
|
mParseOffset += setInt(mStepTime, message, mParseOffset);
|
||||||
mParseOffset += setBoolean(m_Connected, message, mParseOffset);
|
mParseOffset += setBoolean(mConnected, message, mParseOffset);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create ConnectAnswer message");
|
ESP_LOGE(TAG, "failed to create ConnectAnswer message");
|
||||||
return false;
|
return false;
|
||||||
@@ -478,9 +463,9 @@ bool Message::ReportProject::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_ProjectID = getString(message, mParseOffset, 41).value();
|
mProjectID = getString(message, mParseOffset, 41).value();
|
||||||
m_ProjectName = getString(message, mParseOffset, 64).value();
|
mProjectName = getString(message, mParseOffset, 64).value();
|
||||||
m_FramesPerSecond = getInt(message, mParseOffset).value();
|
mFramesPerSecond = getInt(message, mParseOffset).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse ReportProject message");
|
ESP_LOGE(TAG, "failed to parse ReportProject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -490,8 +475,8 @@ bool Message::ReportProject::parse(const std::vector<char> &message) {
|
|||||||
// Send
|
// Send
|
||||||
Message::ReportProject::ReportProject(string p_ProjectID, string p_ProjectName)
|
Message::ReportProject::ReportProject(string p_ProjectID, string p_ProjectName)
|
||||||
: OPPart(BYTESLENGTH),
|
: OPPart(BYTESLENGTH),
|
||||||
m_ProjectID(p_ProjectID),
|
mProjectID(p_ProjectID),
|
||||||
m_ProjectName(p_ProjectName) {
|
mProjectName(p_ProjectName) {
|
||||||
setHeader(OPFLAG);
|
setHeader(OPFLAG);
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
}
|
}
|
||||||
@@ -505,9 +490,9 @@ bool Message::ReportProject::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_ProjectID, message, mParseOffset, 41);
|
mParseOffset += setString(mProjectID, message, mParseOffset, 41);
|
||||||
mParseOffset += setString(m_ProjectName, message, mParseOffset, 64);
|
mParseOffset += setString(mProjectName, message, mParseOffset, 64);
|
||||||
mParseOffset += setInt(m_FramesPerSecond, message, mParseOffset);
|
mParseOffset += setInt(mFramesPerSecond, message, mParseOffset);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create ReportProject message");
|
ESP_LOGE(TAG, "failed to create ReportProject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -531,7 +516,7 @@ bool Message::CloseProject::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_ProjectID = getString(message, mParseOffset, 41).value();
|
mProjectID = getString(message, mParseOffset, 41).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse CloseProject message");
|
ESP_LOGE(TAG, "failed to parse CloseProject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -541,7 +526,7 @@ bool Message::CloseProject::parse(const std::vector<char> &message) {
|
|||||||
// Send
|
// Send
|
||||||
Message::CloseProject::CloseProject(string projectID)
|
Message::CloseProject::CloseProject(string projectID)
|
||||||
: OPPart(BYTESLENGTH),
|
: OPPart(BYTESLENGTH),
|
||||||
m_ProjectID(projectID) {
|
mProjectID(projectID) {
|
||||||
setHeader(OPFLAG);
|
setHeader(OPFLAG);
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
}
|
}
|
||||||
@@ -555,7 +540,7 @@ bool Message::CloseProject::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_ProjectID, message, mParseOffset, 41);
|
mParseOffset += setString(mProjectID, message, mParseOffset, 41);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create CloseProject message");
|
ESP_LOGE(TAG, "failed to create CloseProject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -714,15 +699,15 @@ bool Message::ReportType::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_Confirmed = getBoolean(message, mParseOffset).value();
|
mConfirmed = getBoolean(message, mParseOffset).value();
|
||||||
m_SPITTypeID = getString(message, mParseOffset, 41).value();
|
mSPITTypeID = getString(message, mParseOffset, 41).value();
|
||||||
m_Fixed = getBoolean(message, mParseOffset).value();
|
mFixed = getBoolean(message, mParseOffset).value();
|
||||||
m_ServerRemote = getBoolean(message, mParseOffset).value();
|
mServerRemote = getBoolean(message, mParseOffset).value();
|
||||||
m_ServerProjectIndepended = getBoolean(message, mParseOffset).value();
|
mServerProjectIndepended = getBoolean(message, mParseOffset).value();
|
||||||
m_SPITTypeGroupName = getString(message, mParseOffset, 39).value();
|
mTypeGroupName = getString(message, mParseOffset, 39).value();
|
||||||
m_SPITTypeName = getString(message, mParseOffset, 64).value();
|
mSPITTypeName = getString(message, mParseOffset, 64).value();
|
||||||
m_Delay = getLong(message, mParseOffset).value();
|
mDelay = getLong(message, mParseOffset).value();
|
||||||
m_Duration = getLong(message, mParseOffset).value();
|
mDuration = getLong(message, mParseOffset).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse ReportType message");
|
ESP_LOGE(TAG, "failed to parse ReportType message");
|
||||||
return false;
|
return false;
|
||||||
@@ -745,15 +730,15 @@ bool Message::ReportType::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = mHeader->BYTESLENGTH;
|
mParseOffset = mHeader->BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setBoolean(m_Confirmed, message, mParseOffset);
|
mParseOffset += setBoolean(mConfirmed, message, mParseOffset);
|
||||||
mParseOffset += setString(m_SPITTypeID, message, mParseOffset, 41);
|
mParseOffset += setString(mSPITTypeID, message, mParseOffset, 41);
|
||||||
mParseOffset += setBoolean(m_Fixed, message, mParseOffset);
|
mParseOffset += setBoolean(mFixed, message, mParseOffset);
|
||||||
mParseOffset += setBoolean(m_ServerRemote, message, mParseOffset);
|
mParseOffset += setBoolean(mServerRemote, message, mParseOffset);
|
||||||
mParseOffset += setBoolean(m_ServerProjectIndepended, message, mParseOffset);
|
mParseOffset += setBoolean(mServerProjectIndepended, message, mParseOffset);
|
||||||
mParseOffset += setString(m_SPITTypeGroupName, message, mParseOffset, 39);
|
mParseOffset += setString(mTypeGroupName, message, mParseOffset, 39);
|
||||||
mParseOffset += setString(m_SPITTypeName, message, mParseOffset, 64);
|
mParseOffset += setString(mSPITTypeName, message, mParseOffset, 64);
|
||||||
mParseOffset += setLong(m_Delay, message, mParseOffset);
|
mParseOffset += setLong(mDelay, message, mParseOffset);
|
||||||
mParseOffset += setLong(m_Duration, message, mParseOffset);
|
mParseOffset += setLong(mDuration, message, mParseOffset);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create ReportType message");
|
ESP_LOGE(TAG, "failed to create ReportType message");
|
||||||
return false;
|
return false;
|
||||||
@@ -777,7 +762,7 @@ bool Message::RemoveType::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_SPITTypeID = getString(message, mParseOffset, 41).value();
|
mSPITTypeID = getString(message, mParseOffset, 41).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse RemoveType message");
|
ESP_LOGE(TAG, "failed to parse RemoveType message");
|
||||||
return false;
|
return false;
|
||||||
@@ -800,7 +785,7 @@ bool Message::RemoveType::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_SPITTypeID, message, mParseOffset, 41);
|
mParseOffset += setString(mSPITTypeID, message, mParseOffset, 41);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create RemoveType message");
|
ESP_LOGE(TAG, "failed to create RemoveType message");
|
||||||
return false;
|
return false;
|
||||||
@@ -825,24 +810,24 @@ bool Message::ReportObject::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_Confirmed = getBoolean(message, mParseOffset).value();
|
mConfirmed = getBoolean(message, mParseOffset).value();
|
||||||
m_SPITObjectID = getString(message, mParseOffset, 41).value();
|
mSPITObjectID = getString(message, mParseOffset, 41).value();
|
||||||
m_Fixed = getBoolean(message, mParseOffset).value();
|
mFixed = getBoolean(message, mParseOffset).value();
|
||||||
m_ServerRemote = getBoolean(message, mParseOffset).value();
|
mServerRemote = getBoolean(message, mParseOffset).value();
|
||||||
m_SPITObjectName = getString(message, mParseOffset, 64).value();
|
mSPITObjectName = getString(message, mParseOffset, 64).value();
|
||||||
m_SPITTypeID = getString(message, mParseOffset, 41).value();
|
mSPITTypeID = getString(message, mParseOffset, 41).value();
|
||||||
m_ServerParams = getString(message, mParseOffset, 64).value();
|
mServerParams = getString(message, mParseOffset, 64).value();
|
||||||
m_FrameStart = getLong(message, mParseOffset).value();
|
mFrameStart = getLong(message, mParseOffset).value();
|
||||||
m_FrameLength = getLong(message, mParseOffset).value();
|
mFrameLength = getLong(message, mParseOffset).value();
|
||||||
m_FrameFadeInLength = getLong(message, mParseOffset).value();
|
mFrameFadeInLength = getLong(message, mParseOffset).value();
|
||||||
m_FrameFadeOutLength = getLong(message, mParseOffset).value();
|
mFrameFadeOutLength = getLong(message, mParseOffset).value();
|
||||||
m_ValueFactor = getInt(message, mParseOffset).value();
|
mValueFactor = getInt(message, mParseOffset).value();
|
||||||
m_ValueUse = getByte(message, mParseOffset).value();
|
mValueUse = getByte(message, mParseOffset).value();
|
||||||
m_Track = getInt(message, mParseOffset).value();
|
mTrack = getInt(message, mParseOffset).value();
|
||||||
m_Remark = getString(message, mParseOffset, 64).value();
|
mRemark = getString(message, mParseOffset, 64).value();
|
||||||
m_Delay = getLong(message, mParseOffset).value();
|
mDelay = getLong(message, mParseOffset).value();
|
||||||
m_Duration = getLong(message, mParseOffset).value();
|
mDuration = getLong(message, mParseOffset).value();
|
||||||
m_ActionAssigned = getBoolean(message, mParseOffset).value();
|
mActionAssigned = getBoolean(message, mParseOffset).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse ReportObject message");
|
ESP_LOGE(TAG, "failed to parse ReportObject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -858,12 +843,12 @@ Message::ReportObject::ReportObject() : OPPart(BYTESLENGTH) {
|
|||||||
void Message::ReportObject::setDelay(uint64_t p_Delay) {
|
void Message::ReportObject::setDelay(uint64_t p_Delay) {
|
||||||
if (p_Delay < 0)
|
if (p_Delay < 0)
|
||||||
p_Delay = 0;
|
p_Delay = 0;
|
||||||
m_Delay = p_Delay;
|
mDelay = p_Delay;
|
||||||
}
|
}
|
||||||
void Message::ReportObject::setDuration(uint64_t p_Duration) {
|
void Message::ReportObject::setDuration(uint64_t p_Duration) {
|
||||||
if (p_Duration < 0)
|
if (p_Duration < 0)
|
||||||
p_Duration = 0;
|
p_Duration = 0;
|
||||||
m_Duration = p_Duration;
|
mDuration = p_Duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Message::ReportObject::fillBytes(std::vector<char> &message) {
|
bool Message::ReportObject::fillBytes(std::vector<char> &message) {
|
||||||
@@ -875,24 +860,24 @@ bool Message::ReportObject::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setBoolean(m_Confirmed, message, mParseOffset);
|
mParseOffset += setBoolean(mConfirmed, message, mParseOffset);
|
||||||
mParseOffset += setString(m_SPITObjectID, message, mParseOffset, 41);
|
mParseOffset += setString(mSPITObjectID, message, mParseOffset, 41);
|
||||||
mParseOffset += setBoolean(m_Fixed, message, mParseOffset);
|
mParseOffset += setBoolean(mFixed, message, mParseOffset);
|
||||||
mParseOffset += setBoolean(m_ServerRemote, message, mParseOffset);
|
mParseOffset += setBoolean(mServerRemote, message, mParseOffset);
|
||||||
mParseOffset += setString(m_SPITObjectName, message, mParseOffset, 64);
|
mParseOffset += setString(mSPITObjectName, message, mParseOffset, 64);
|
||||||
mParseOffset += setString(m_SPITTypeID, message, mParseOffset, 41);
|
mParseOffset += setString(mSPITTypeID, message, mParseOffset, 41);
|
||||||
mParseOffset += setString(m_ServerParams, message, mParseOffset, 64);
|
mParseOffset += setString(mServerParams, message, mParseOffset, 64);
|
||||||
mParseOffset += setLong(m_FrameStart, message, mParseOffset);
|
mParseOffset += setLong(mFrameStart, message, mParseOffset);
|
||||||
mParseOffset += setLong(m_FrameLength, message, mParseOffset);
|
mParseOffset += setLong(mFrameLength, message, mParseOffset);
|
||||||
mParseOffset += setLong(m_FrameFadeInLength, message, mParseOffset);
|
mParseOffset += setLong(mFrameFadeInLength, message, mParseOffset);
|
||||||
mParseOffset += setLong(m_FrameFadeOutLength, message, mParseOffset);
|
mParseOffset += setLong(mFrameFadeOutLength, message, mParseOffset);
|
||||||
mParseOffset += setInt(m_ValueFactor, message, mParseOffset);
|
mParseOffset += setInt(mValueFactor, message, mParseOffset);
|
||||||
mParseOffset += setByte(m_ValueUse, message, mParseOffset);
|
mParseOffset += setByte(mValueUse, message, mParseOffset);
|
||||||
mParseOffset += setInt(m_Track, message, mParseOffset);
|
mParseOffset += setInt(mTrack, message, mParseOffset);
|
||||||
mParseOffset += setString(m_Remark, message, mParseOffset, 64);
|
mParseOffset += setString(mRemark, message, mParseOffset, 64);
|
||||||
mParseOffset += setLong(m_Delay, message, mParseOffset);
|
mParseOffset += setLong(mDelay, message, mParseOffset);
|
||||||
mParseOffset += setLong(m_Duration, message, mParseOffset);
|
mParseOffset += setLong(mDuration, message, mParseOffset);
|
||||||
mParseOffset += setBoolean(m_ActionAssigned, message, mParseOffset);
|
mParseOffset += setBoolean(mActionAssigned, message, mParseOffset);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create ReportObject message");
|
ESP_LOGE(TAG, "failed to create ReportObject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -915,7 +900,7 @@ bool Message::RemoveObject::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_SPITObjectID = getString(message, mParseOffset, 41).value();
|
mSPITObjectID = getString(message, mParseOffset, 41).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse RemoveObject message");
|
ESP_LOGE(TAG, "failed to parse RemoveObject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -938,7 +923,7 @@ bool Message::RemoveObject::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_SPITObjectID, message, mParseOffset, 41);
|
mParseOffset += setString(mSPITObjectID, message, mParseOffset, 41);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create RemoveObject message");
|
ESP_LOGE(TAG, "failed to create RemoveObject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -963,11 +948,11 @@ bool Message::PlayStart::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_PlayerID = getString(message, mParseOffset, 41).value();
|
mPlayerID = getString(message, mParseOffset, 41).value();
|
||||||
m_PlayerName = getString(message, mParseOffset, 64).value();
|
mPlayerName = getString(message, mParseOffset, 64).value();
|
||||||
m_PlayerType = getByte(message, mParseOffset).value();
|
mPlayerType = getByte(message, mParseOffset).value();
|
||||||
m_PlayerIsRunning = getBoolean(message, mParseOffset).value();
|
mPlayerIsRunning = getBoolean(message, mParseOffset).value();
|
||||||
m_Time = getLong(message, mParseOffset).value();
|
mTime = getLong(message, mParseOffset).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse PlayStart message");
|
ESP_LOGE(TAG, "failed to parse PlayStart message");
|
||||||
return false;
|
return false;
|
||||||
@@ -978,9 +963,9 @@ bool Message::PlayStart::parse(const std::vector<char> &message) {
|
|||||||
// Send
|
// Send
|
||||||
Message::PlayStart::PlayStart(string p_PlayerID, string p_PlayerName, char p_PlayerType)
|
Message::PlayStart::PlayStart(string p_PlayerID, string p_PlayerName, char p_PlayerType)
|
||||||
: OPPart(BYTESLENGTH),
|
: OPPart(BYTESLENGTH),
|
||||||
m_PlayerID(p_PlayerID),
|
mPlayerID(p_PlayerID),
|
||||||
m_PlayerName(p_PlayerName),
|
mPlayerName(p_PlayerName),
|
||||||
m_PlayerType(p_PlayerType) {
|
mPlayerType(p_PlayerType) {
|
||||||
setHeader(OPFLAG);
|
setHeader(OPFLAG);
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
}
|
}
|
||||||
@@ -994,11 +979,11 @@ bool Message::PlayStart::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_PlayerID, message, mParseOffset, 41);
|
mParseOffset += setString(mPlayerID, message, mParseOffset, 41);
|
||||||
mParseOffset += setString(m_PlayerName, message, mParseOffset, 64);
|
mParseOffset += setString(mPlayerName, message, mParseOffset, 64);
|
||||||
mParseOffset += setByte(m_PlayerType, message, mParseOffset);
|
mParseOffset += setByte(mPlayerType, message, mParseOffset);
|
||||||
mParseOffset += setBoolean(m_PlayerIsRunning, message, mParseOffset);
|
mParseOffset += setBoolean(mPlayerIsRunning, message, mParseOffset);
|
||||||
mParseOffset += setLong(m_Time, message, mParseOffset);
|
mParseOffset += setLong(mTime, message, mParseOffset);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create PlayStart message");
|
ESP_LOGE(TAG, "failed to create PlayStart message");
|
||||||
return false;
|
return false;
|
||||||
@@ -1022,12 +1007,12 @@ bool Message::PlayObject::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_PlayerID = getString(message, mParseOffset, 41).value();
|
mPlayerID = getString(message, mParseOffset, 41).value();
|
||||||
m_SPITObjectID = getString(message, mParseOffset, 41).value();
|
mSPITObjectID = getString(message, mParseOffset, 41).value();
|
||||||
m_FrameInsideObject = getLong(message, mParseOffset).value();
|
mFrameInsideObject = getLong(message, mParseOffset).value();
|
||||||
m_PlayPrePosition = getBoolean(message, mParseOffset).value();
|
mPlayPrePosition = getBoolean(message, mParseOffset).value();
|
||||||
m_Value = getInt(message, mParseOffset).value();
|
mValue = getInt(message, mParseOffset).value();
|
||||||
m_ValueFlag = getByte(message, mParseOffset).value();
|
mValueFlag = getByte(message, mParseOffset).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse PlayObject message");
|
ESP_LOGE(TAG, "failed to parse PlayObject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -1049,12 +1034,12 @@ bool Message::PlayObject::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_PlayerID, message, mParseOffset, 41);
|
mParseOffset += setString(mPlayerID, message, mParseOffset, 41);
|
||||||
mParseOffset += setString(m_SPITObjectID, message, mParseOffset, 41);
|
mParseOffset += setString(mSPITObjectID, message, mParseOffset, 41);
|
||||||
mParseOffset += setLong(m_FrameInsideObject, message, mParseOffset);
|
mParseOffset += setLong(mFrameInsideObject, message, mParseOffset);
|
||||||
mParseOffset += setBoolean(m_PlayPrePosition, message, mParseOffset);
|
mParseOffset += setBoolean(mPlayPrePosition, message, mParseOffset);
|
||||||
mParseOffset += setInt(m_Value, message, mParseOffset);
|
mParseOffset += setInt(mValue, message, mParseOffset);
|
||||||
mParseOffset += setByte(m_ValueFlag, message, mParseOffset);
|
mParseOffset += setByte(mValueFlag, message, mParseOffset);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create PlayObject message");
|
ESP_LOGE(TAG, "failed to create PlayObject message");
|
||||||
return false;
|
return false;
|
||||||
@@ -1078,7 +1063,7 @@ bool Message::PlayEnd::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_PlayerID = getString(message, mParseOffset, 41).value();
|
mPlayerID = getString(message, mParseOffset, 41).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse PlayEnd message");
|
ESP_LOGE(TAG, "failed to parse PlayEnd message");
|
||||||
return false;
|
return false;
|
||||||
@@ -1088,7 +1073,7 @@ bool Message::PlayEnd::parse(const std::vector<char> &message) {
|
|||||||
// Send
|
// Send
|
||||||
Message::PlayEnd::PlayEnd(string p_PlayerID)
|
Message::PlayEnd::PlayEnd(string p_PlayerID)
|
||||||
: OPPart(BYTESLENGTH),
|
: OPPart(BYTESLENGTH),
|
||||||
m_PlayerID(p_PlayerID) {
|
mPlayerID(p_PlayerID) {
|
||||||
setHeader(OPFLAG);
|
setHeader(OPFLAG);
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
}
|
}
|
||||||
@@ -1102,7 +1087,7 @@ bool Message::PlayEnd::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_PlayerID, message, mParseOffset, 41);
|
mParseOffset += setString(mPlayerID, message, mParseOffset, 41);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create PlayEnd message");
|
ESP_LOGE(TAG, "failed to create PlayEnd message");
|
||||||
return false;
|
return false;
|
||||||
@@ -1126,9 +1111,9 @@ bool Message::ReportPlayStatus::parse(const std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mBytesCount = getInt(message, mParseOffset).value();
|
mBytesCount = getInt(message, mParseOffset).value();
|
||||||
m_SPITObjectID = getString(message, mParseOffset, 41).value();
|
mSPITObjectID = getString(message, mParseOffset, 41).value();
|
||||||
m_FrameInsideObject = getLong(message, mParseOffset).value();
|
mFrameInsideObject = getLong(message, mParseOffset).value();
|
||||||
m_Value = getInt(message, mParseOffset).value();
|
mValue = getInt(message, mParseOffset).value();
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to parse ReportPlayStatus message");
|
ESP_LOGE(TAG, "failed to parse ReportPlayStatus message");
|
||||||
return false;
|
return false;
|
||||||
@@ -1142,13 +1127,13 @@ Message::ReportPlayStatus::ReportPlayStatus() : OPPart(BYTESLENGTH) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Message::ReportPlayStatus::setID(string p_ID) {
|
void Message::ReportPlayStatus::setID(string p_ID) {
|
||||||
m_SPITObjectID = p_ID;
|
mSPITObjectID = p_ID;
|
||||||
}
|
}
|
||||||
void Message::ReportPlayStatus::setFrameInsideObject(uint64_t p_TimeInside) {
|
void Message::ReportPlayStatus::setFrameInsideObject(uint64_t p_TimeInside) {
|
||||||
m_FrameInsideObject = p_TimeInside;
|
mFrameInsideObject = p_TimeInside;
|
||||||
}
|
}
|
||||||
void Message::ReportPlayStatus::setValue(int p_Value) {
|
void Message::ReportPlayStatus::setValue(int p_Value) {
|
||||||
m_Value = p_Value;
|
mValue = p_Value;
|
||||||
}
|
}
|
||||||
bool Message::ReportPlayStatus::fillBytes(std::vector<char> &message) {
|
bool Message::ReportPlayStatus::fillBytes(std::vector<char> &message) {
|
||||||
if (!mHeader) {
|
if (!mHeader) {
|
||||||
@@ -1159,9 +1144,9 @@ bool Message::ReportPlayStatus::fillBytes(std::vector<char> &message) {
|
|||||||
try {
|
try {
|
||||||
mParseOffset = Header::BYTESLENGTH;
|
mParseOffset = Header::BYTESLENGTH;
|
||||||
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
mParseOffset += setInt(mBytesCount, message, mParseOffset);
|
||||||
mParseOffset += setString(m_SPITObjectID, message, mParseOffset, 41);
|
mParseOffset += setString(mSPITObjectID, message, mParseOffset, 41);
|
||||||
mParseOffset += setLong(m_FrameInsideObject, message, mParseOffset);
|
mParseOffset += setLong(mFrameInsideObject, message, mParseOffset);
|
||||||
mParseOffset += setInt(m_Value, message, mParseOffset);
|
mParseOffset += setInt(mValue, message, mParseOffset);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
ESP_LOGE(TAG, "failed to create ReportPlayStatus message");
|
ESP_LOGE(TAG, "failed to create ReportPlayStatus message");
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
|
||||||
|
#include "spit_object.hpp"
|
||||||
|
#include "spit_socket.hpp"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
namespace spit {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* clears all unconfirmed SObjects not created by this SPIT_Client.
|
||||||
|
*/
|
||||||
|
void SObject::clearUnconfirmedObjects(SpitRepo<SObject> &repo) {
|
||||||
|
auto &entries = repo.getRepo();
|
||||||
|
for (auto i = entries.begin(); i != entries.end();) {
|
||||||
|
SObject *ptrSObject = i->second.get();
|
||||||
|
if (ptrSObject->getCreatedByClient() == false && ptrSObject->getConfirmed() == false) {
|
||||||
|
i = entries.erase(i);
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SObject::eventProjectClosed(SpitRepo<SObject> &repo, SpitRepo<SObject> &remoteRepo) {
|
||||||
|
auto &entries = repo.getRepo();
|
||||||
|
for (auto i = entries.begin(); i != entries.end(); ) {
|
||||||
|
SObject *ptrSObject = i->second.get();
|
||||||
|
if (ptrSObject->getCreatedByClient() == true) {
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
i = entries.erase(i);
|
||||||
|
}
|
||||||
|
// Remote
|
||||||
|
remoteRepo.clearEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets confirmed = false for all SObjects.
|
||||||
|
* This should be called when the client has loaded a project.
|
||||||
|
*/
|
||||||
|
void SObject::setConfirmedFalse(SpitRepo<SObject> &repo) {
|
||||||
|
auto &entries = repo.getRepo();
|
||||||
|
for (auto i = entries.begin(); i != entries.end(); i++) {
|
||||||
|
i->second->setConfirmed(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SObject::setMessageOP(Message::ReportObject *message) {
|
||||||
|
bool changeAllowed;
|
||||||
|
|
||||||
|
if ((mCreatedByClient == true) && (Fixed.mValue == true)) {
|
||||||
|
changeAllowed = false;
|
||||||
|
} else {
|
||||||
|
changeAllowed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirmation should be changable
|
||||||
|
if (mCreatedByClient) {
|
||||||
|
// Server reports a client created SPITType -> the type is confirmed
|
||||||
|
mConfirmed = true;
|
||||||
|
} else {
|
||||||
|
// type is NOT client created -> the client has to confirm the SPITtype
|
||||||
|
mConfirmed = message->getConfirmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changeAllowed == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
bool changed = false;
|
||||||
|
if (Delay.mValue != message->getDelay()) {
|
||||||
|
Delay.mValue = message->getDelay();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (Duration.mValue != message->getDuration()) {
|
||||||
|
Duration.mValue = message->getDuration();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (Fixed.mValue != message->getFixed()) {
|
||||||
|
Fixed.mValue = message->getFixed();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (FrameFadeInLength.mValue != message->getFrameFadeInLength()) {
|
||||||
|
FrameFadeInLength.mValue = message->getFrameFadeInLength();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (FrameFadeOutLength.mValue != message->getFrameFadeOutLength()) {
|
||||||
|
FrameFadeOutLength.mValue = message->getFrameFadeOutLength();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (FrameLength.mValue != message->getFrameLength()) {
|
||||||
|
FrameLength.mValue = message->getFrameLength();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (FrameStart.mValue != message->getFrameStart()) {
|
||||||
|
FrameStart.mValue = message->getFrameStart();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (Remark.mValue != message->getRemark()) {
|
||||||
|
Remark.mValue = message->getRemark();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (mID != message->getID()) {
|
||||||
|
mID = message->getID();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (Name.mValue != message->getName()) {
|
||||||
|
Name.mValue = message->getName();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (SPITTypeID.mValue != message->getSPITTypeID()) {
|
||||||
|
SPITTypeID.mValue = message->getSPITTypeID();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (ServerParams.mValue != message->getServerParams()) {
|
||||||
|
ServerParams.mValue = message->getServerParams();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (ServerRemote.mValue != message->getServerRemote()) {
|
||||||
|
ServerRemote.mValue = message->getServerRemote();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (Track.mValue != message->getTrack()) {
|
||||||
|
Track.mValue = message->getTrack();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (mValueFactor != message->getValueFactor()) {
|
||||||
|
mValueFactor = message->getValueFactor();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (mValueUse != message->getValueUse()) {
|
||||||
|
mValueUse = message->getValueUse();
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SObject::fillMessageOP(Message::ReportObject &message) {
|
||||||
|
message.setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object
|
||||||
|
message.setConfirmed(mConfirmed);
|
||||||
|
message.setDelay(Delay.mValue);
|
||||||
|
message.setDuration(Duration.mValue);
|
||||||
|
message.setFixed(Fixed.mValue);
|
||||||
|
message.setFrameFadeInLength(FrameFadeInLength.mValue);
|
||||||
|
message.setFrameFadeOutLength(FrameFadeOutLength.mValue);
|
||||||
|
message.setFrameLength(FrameLength.mValue);
|
||||||
|
message.setFrameStart(FrameStart.mValue);
|
||||||
|
message.setID(mID);
|
||||||
|
message.setName(Name.mValue);
|
||||||
|
message.setRemark(Remark.mValue);
|
||||||
|
message.setSPITTypeID(SPITTypeID.mValue);
|
||||||
|
message.setServerParams(ServerParams.mValue);
|
||||||
|
message.setServerRemote(ServerRemote.mValue);
|
||||||
|
message.setTrack(Track.mValue);
|
||||||
|
message.setValueFactor(mValueFactor);
|
||||||
|
message.setValueUse(mValueUse);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SObject::fillMessageOP(Message::RemoveObject &message) {
|
||||||
|
message.setID(mID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is used by the server and client to tell if the other side has registered the changes.
|
||||||
|
* @param p_Confirmed
|
||||||
|
* @return if mConfirmed has changed
|
||||||
|
*/
|
||||||
|
bool SObject::setConfirmed(bool p_Confirmed) {
|
||||||
|
if (mConfirmed == p_Confirmed)
|
||||||
|
return false;
|
||||||
|
mConfirmed = p_Confirmed;
|
||||||
|
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.
|
||||||
|
* Then this action is done for every SObject with the SPITType.
|
||||||
|
* @return true = an action is assigned for the SPITType.
|
||||||
|
*/
|
||||||
|
bool SObject::setActionAssignedType(bool p_ActionAssigned) {
|
||||||
|
if (mActionAssignedType == p_ActionAssigned)
|
||||||
|
return false;
|
||||||
|
bool oldActionAssigend = getActionAssigned();
|
||||||
|
mActionAssignedType = p_ActionAssigned;
|
||||||
|
if (getActionAssigned() == oldActionAssigend)
|
||||||
|
return false;
|
||||||
|
mConfirmed = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SObject::setActionAssigned(bool p_ActionAssigned) {
|
||||||
|
if (mActionAssigned == p_ActionAssigned)
|
||||||
|
return false;
|
||||||
|
bool oldActionAssigend = getActionAssigned();
|
||||||
|
mActionAssigned = p_ActionAssigned;
|
||||||
|
if (getActionAssigned() == oldActionAssigend)
|
||||||
|
return false;
|
||||||
|
mConfirmed = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
|
||||||
|
#include "spit_player.hpp"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
namespace spit {
|
||||||
|
|
||||||
|
unordered_map<string, unique_ptr<SPlayer>> SPlayer::sSpitPlayers;
|
||||||
|
|
||||||
|
SPlayer &SPlayer::getSPITPlayer(string playerID) {
|
||||||
|
auto i = sSpitPlayers.find(playerID);
|
||||||
|
if (i == sSpitPlayers.end()) {
|
||||||
|
sSpitPlayers[playerID] = make_unique<SPlayer>(playerID);
|
||||||
|
}
|
||||||
|
return *sSpitPlayers.at(playerID);
|
||||||
|
}
|
||||||
|
|
||||||
|
SPlayer::SPlayer(string playerID) {
|
||||||
|
mId = playerID;
|
||||||
|
}
|
||||||
|
|
||||||
|
SPlayer::~SPlayer() {
|
||||||
|
mPlaySPITTypes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param p_SPITObjectID
|
||||||
|
* @return true = new PlayObject added<br>
|
||||||
|
* false = PlayObject exists
|
||||||
|
*/
|
||||||
|
SPlayer::PlayType *SPlayer::addTypePlaying(string spitTypeID) {
|
||||||
|
PlayType *ptrPlaySPITType;
|
||||||
|
auto i = mPlaySPITTypes.find(spitTypeID);
|
||||||
|
if (i == mPlaySPITTypes.end()) {
|
||||||
|
auto playSpitType = make_unique<PlayType>(this, spitTypeID);
|
||||||
|
ptrPlaySPITType = playSpitType.get();
|
||||||
|
mPlaySPITTypes[spitTypeID] = move(playSpitType);
|
||||||
|
} else {
|
||||||
|
ptrPlaySPITType = i->second.get();
|
||||||
|
}
|
||||||
|
ptrPlaySPITType->setIsPlayed(true);
|
||||||
|
return ptrPlaySPITType;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SPlayer::startPlaySequence() {
|
||||||
|
for (auto i = mPlaySPITTypes.begin(); i != mPlaySPITTypes.end(); i++) {
|
||||||
|
PlayType *ptrPlaySPITType = i->second.get();
|
||||||
|
ptrPlaySPITType->startPlaySequence();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SPlayer::endPlaySequence() {
|
||||||
|
for (auto i = mPlaySPITTypes.begin(); i != mPlaySPITTypes.end();) {
|
||||||
|
if (i->second.get()->getIsPlayed() == false) {
|
||||||
|
i = mPlaySPITTypes.erase(i);
|
||||||
|
} else {
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SPlayer::PlayType::PlayType(SPlayer *p_SPITPlayer, string spitTypeID) {
|
||||||
|
mIsNew = true;
|
||||||
|
|
||||||
|
mSpitTypeID = spitTypeID;
|
||||||
|
mPlayerID = p_SPITPlayer->getID();
|
||||||
|
mPlayerName = p_SPITPlayer->getName();
|
||||||
|
startPlaySequence();
|
||||||
|
mIsNew = true;
|
||||||
|
}
|
||||||
|
SPlayer::PlayType::PlayType(const PlayType &orig) {
|
||||||
|
mSpitTypeID = orig.getSPITTypeID();
|
||||||
|
mIsPlayed = orig.getIsPlayed();
|
||||||
|
mIsNew = orig.getIsNew();
|
||||||
|
|
||||||
|
mPlayerID = orig.getPlayerID();
|
||||||
|
mPlayerName = orig.getPlayerName();
|
||||||
|
mPlayerRuns = orig.getPlayerIsRunning();
|
||||||
|
|
||||||
|
mValue = orig.getValue();
|
||||||
|
}
|
||||||
|
void SPlayer::PlayType::startPlaySequence() {
|
||||||
|
mIsPlayed = false;
|
||||||
|
mIsNew = false;
|
||||||
|
|
||||||
|
mValue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,45 +1,33 @@
|
|||||||
/*
|
#include "spit_socket.hpp"
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Unix implementation of a SPITSocket.
|
|
||||||
*
|
|
||||||
* File: UnixSocket.cpp
|
|
||||||
* Author: Hagi
|
|
||||||
*
|
|
||||||
* Created on 12. April 2019, 15:58
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "SPITSocket.h"
|
|
||||||
#include "Task.hpp"
|
#include "Task.hpp"
|
||||||
#include "esp/uuid.h"
|
#include "esp/uuid.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
namespace spit {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates socket. If there exist some, they will be closed.
|
* Creates socket. If there exist some, they will be closed.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
bool SPITSocket::createSocket_UDP() {
|
bool Socket::createSocketUdp() {
|
||||||
if (m_UDPSocketIP4 != INVALID_SOCKET) {
|
if (mUdpSocketIp4 != INVALID_SOCKET) {
|
||||||
close(m_UDPSocketIP4);
|
close(mUdpSocketIp4);
|
||||||
m_UDPSocketIP4 = INVALID_SOCKET;
|
mUdpSocketIp4 = INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_UDPSocketIP4 = socket(AF_INET, SOCK_DGRAM, 0);
|
mUdpSocketIp4 = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
int intResult = -1;
|
int intResult = -1;
|
||||||
bool success = true;
|
bool success = true;
|
||||||
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
if (mUdpSocketIp4 == INVALID_SOCKET) {
|
||||||
success = false;
|
success = false;
|
||||||
} else {
|
} else {
|
||||||
int intOptionValue4 = 1;
|
int intOptionValue4 = 1;
|
||||||
intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_REUSEADDR, (void *)&intOptionValue4, sizeof(intOptionValue4));
|
intResult = setsockopt(mUdpSocketIp4, SOL_SOCKET, SO_REUSEADDR, (void *)&intOptionValue4, sizeof(intOptionValue4));
|
||||||
}
|
}
|
||||||
if (intResult < 0) {
|
if (intResult < 0) {
|
||||||
success = false;
|
success = false;
|
||||||
@@ -50,17 +38,17 @@ bool SPITSocket::createSocket_UDP() {
|
|||||||
tv.tv_sec = 1; // seconds
|
tv.tv_sec = 1; // seconds
|
||||||
tv.tv_usec = 0; // microseconds (0.0 sec)
|
tv.tv_usec = 0; // microseconds (0.0 sec)
|
||||||
// This sets the receive timeout
|
// This sets the receive timeout
|
||||||
setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
setsockopt(mUdpSocketIp4, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
||||||
|
|
||||||
// set the m_UDPSocketIP4 in NON BLOCKING mode because
|
// set the mUdpSocketIp4 in NON BLOCKING mode because
|
||||||
// if the UDPSockets are in blocking mode the receiveMessage does not return in every constellation
|
// if the UDPSockets are in blocking mode the receiveMessage does not return in every constellation
|
||||||
// int intFlags;
|
// int intFlags;
|
||||||
// intFlags = fcntl(m_UDPSocketIP4, F_GETFL);
|
// intFlags = fcntl(mUdpSocketIp4, F_GETFL);
|
||||||
// fcntl(m_UDPSocketIP4, F_SETFL, intFlags | O_NONBLOCK);
|
// fcntl(mUdpSocketIp4, F_SETFL, intFlags | O_NONBLOCK);
|
||||||
|
|
||||||
// int intBufferSize = 2046 * 512;
|
// int intBufferSize = 2046 * 512;
|
||||||
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
// intResult = setsockopt(mUdpSocketIp4, SOL_SOCKET, SO_RCVBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
||||||
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_SNDBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
// intResult = setsockopt(mUdpSocketIp4, SOL_SOCKET, SO_SNDBUF, (void*)&intBufferSize, sizeof(intBufferSize));
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
@@ -73,7 +61,7 @@ bool SPITSocket::createSocket_UDP() {
|
|||||||
* @return -1 id bind fails, o if bind is ok
|
* @return -1 id bind fails, o if bind is ok
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int SPITSocket::bindSocket(string clientIp, string clientPort) {
|
int Socket::bindSocket(string clientIp, string clientPort) {
|
||||||
string stringClientPort;
|
string stringClientPort;
|
||||||
if (clientPort.length() <= 0)
|
if (clientPort.length() <= 0)
|
||||||
stringClientPort = "0";
|
stringClientPort = "0";
|
||||||
@@ -83,7 +71,7 @@ int SPITSocket::bindSocket(string clientIp, string clientPort) {
|
|||||||
if (getaddrinfo(clientIp.data(), clientPort.data(), nullptr, &clientAI) != 0) {
|
if (getaddrinfo(clientIp.data(), clientPort.data(), nullptr, &clientAI) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
if (mUdpSocketIp4 == INVALID_SOCKET) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
auto *socketAdr = (sockaddr_in *)(clientAI->ai_addr);
|
auto *socketAdr = (sockaddr_in *)(clientAI->ai_addr);
|
||||||
@@ -94,12 +82,12 @@ int SPITSocket::bindSocket(string clientIp, string clientPort) {
|
|||||||
o_IP4SocketAddress.sin_addr = socketAdr->sin_addr;
|
o_IP4SocketAddress.sin_addr = socketAdr->sin_addr;
|
||||||
o_IP4SocketAddress.sin_family = socketAdr->sin_family;
|
o_IP4SocketAddress.sin_family = socketAdr->sin_family;
|
||||||
o_IP4SocketAddress.sin_port = socketAdr->sin_port;
|
o_IP4SocketAddress.sin_port = socketAdr->sin_port;
|
||||||
int intResult = bind(m_UDPSocketIP4, (const sockaddr *)(socketAdr), (socklen_t)intSocklen);
|
int intResult = bind(mUdpSocketIp4, (const sockaddr *)(socketAdr), (socklen_t)intSocklen);
|
||||||
if (intResult < 0) {
|
if (intResult < 0) {
|
||||||
return intResult;
|
return intResult;
|
||||||
}
|
}
|
||||||
if ((intResult == 0) &&
|
if ((intResult == 0) &&
|
||||||
(getsockname(m_UDPSocketIP4, (sockaddr *)socketAdr, (socklen_t *)&intSocklen) != -1)) {
|
(getsockname(mUdpSocketIp4, (sockaddr *)socketAdr, (socklen_t *)&intSocklen) != -1)) {
|
||||||
setBoundClientPort(to_string((int)socketAdr->sin_port));
|
setBoundClientPort(to_string((int)socketAdr->sin_port));
|
||||||
}
|
}
|
||||||
freeaddrinfo(clientAI);
|
freeaddrinfo(clientAI);
|
||||||
@@ -114,9 +102,9 @@ int SPITSocket::bindSocket(string clientIp, string clientPort) {
|
|||||||
* false = SO_BROADCAST is not set
|
* false = SO_BROADCAST is not set
|
||||||
* @return 0 = ok, -1 = error
|
* @return 0 = ok, -1 = error
|
||||||
*/
|
*/
|
||||||
int SPITSocket::setBroadcast(bool broadcast) const {
|
int Socket::setBroadcast(bool broadcast) const {
|
||||||
int intOptionValue = broadcast ? 1 : 0;
|
int intOptionValue = broadcast ? 1 : 0;
|
||||||
int intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_BROADCAST, &intOptionValue, sizeof(int));
|
int intResult = setsockopt(mUdpSocketIp4, SOL_SOCKET, SO_BROADCAST, &intOptionValue, sizeof(int));
|
||||||
return intResult;
|
return intResult;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -127,8 +115,8 @@ int SPITSocket::setBroadcast(bool broadcast) const {
|
|||||||
* @return -1 send fails
|
* @return -1 send fails
|
||||||
* 0 send is done
|
* 0 send is done
|
||||||
*/
|
*/
|
||||||
int SPITSocket::sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) {
|
int Socket::sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) {
|
||||||
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
if (mUdpSocketIp4 == INVALID_SOCKET) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,14 +129,14 @@ int SPITSocket::sendMessageTo(const string &ip, const string &port, const char *
|
|||||||
|
|
||||||
auto *ptrIP4SocketAddress = (sockaddr_in *)(ptrAddressInfo->ai_addr);
|
auto *ptrIP4SocketAddress = (sockaddr_in *)(ptrAddressInfo->ai_addr);
|
||||||
int intSocklen = sizeof(*ptrIP4SocketAddress);
|
int intSocklen = sizeof(*ptrIP4SocketAddress);
|
||||||
if (m_UDPSocketIP4 != INVALID_SOCKET) {
|
if (mUdpSocketIp4 != INVALID_SOCKET) {
|
||||||
// copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo
|
// copy the ptrIP4SocketAddress, may be not filled correct by getaddrinfo
|
||||||
sockaddr_in o_IP4SocketAddress;
|
sockaddr_in o_IP4SocketAddress;
|
||||||
memset(&o_IP4SocketAddress, 0, intSocklen);
|
memset(&o_IP4SocketAddress, 0, intSocklen);
|
||||||
o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr;
|
o_IP4SocketAddress.sin_addr = ptrIP4SocketAddress->sin_addr;
|
||||||
o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family;
|
o_IP4SocketAddress.sin_family = ptrIP4SocketAddress->sin_family;
|
||||||
o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port;
|
o_IP4SocketAddress.sin_port = ptrIP4SocketAddress->sin_port;
|
||||||
intResult = sendto(m_UDPSocketIP4, message, msgLength, 0, (const sockaddr *)&o_IP4SocketAddress, (socklen_t)intSocklen);
|
intResult = sendto(mUdpSocketIp4, message, msgLength, 0, (const sockaddr *)&o_IP4SocketAddress, (socklen_t)intSocklen);
|
||||||
if (intResult < 0) {
|
if (intResult < 0) {
|
||||||
ESP_LOGE("SPIT", "sendMessageTo IP4 sendto %s FAILED %s\n", ip.data(), strerror(errno));
|
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);
|
ESP_LOGE("SPIT", "sendMessageTo ret=%d %s / %s / %d\n", intResult, port.data(), message, msgLength);
|
||||||
@@ -169,15 +157,15 @@ int SPITSocket::sendMessageTo(const string &ip, const string &port, const char *
|
|||||||
* if p_ServerIP is NULL - no detection of the server will be done.
|
* if p_ServerIP is NULL - no detection of the server will be done.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
int SPITSocket::receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const {
|
int Socket::receiveMessage(char *p_Buffer, int p_BufferLength, string *serverIp) const {
|
||||||
int intResult = -1;
|
int intResult = -1;
|
||||||
if (m_UDPSocketIP4 == INVALID_SOCKET) {
|
if (mUdpSocketIp4 == INVALID_SOCKET) {
|
||||||
return intResult;
|
return intResult;
|
||||||
}
|
}
|
||||||
sockaddr_in o_IP4SocketAddress;
|
sockaddr_in o_IP4SocketAddress;
|
||||||
int intSocklen = sizeof(o_IP4SocketAddress);
|
int intSocklen = sizeof(o_IP4SocketAddress);
|
||||||
memset(&o_IP4SocketAddress, 0, intSocklen);
|
memset(&o_IP4SocketAddress, 0, intSocklen);
|
||||||
intResult = recvfrom(m_UDPSocketIP4, (void *)p_Buffer, p_BufferLength, 0, (sockaddr *)&o_IP4SocketAddress, (socklen_t *)&intSocklen);
|
intResult = recvfrom(mUdpSocketIp4, (void *)p_Buffer, p_BufferLength, 0, (sockaddr *)&o_IP4SocketAddress, (socklen_t *)&intSocklen);
|
||||||
if (intResult >= 0 && serverIp != nullptr) {
|
if (intResult >= 0 && serverIp != nullptr) {
|
||||||
char bufferIP4[INET_ADDRSTRLEN];
|
char bufferIP4[INET_ADDRSTRLEN];
|
||||||
inet_ntop(AF_INET, &(o_IP4SocketAddress.sin_addr), bufferIP4, intSocklen);
|
inet_ntop(AF_INET, &(o_IP4SocketAddress.sin_addr), bufferIP4, intSocklen);
|
||||||
@@ -186,7 +174,7 @@ int SPITSocket::receiveMessage(char *p_Buffer, int p_BufferLength, string *serve
|
|||||||
return intResult;
|
return intResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPITSocket::IPAddress SPITSocket::getAdaptersInfo() {
|
ISocket::IpAddress Socket::getAdaptersInfo() {
|
||||||
// iterate over active interfaces, and print out IPs
|
// iterate over active interfaces, and print out IPs
|
||||||
esp_netif_t *netif = nullptr;
|
esp_netif_t *netif = nullptr;
|
||||||
if ((netif = esp_netif_next_unsafe(netif)) != nullptr) {
|
if ((netif = esp_netif_next_unsafe(netif)) != nullptr) {
|
||||||
@@ -221,3 +209,5 @@ string getClientHostName() {
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* @file spitRepoTest.cpp
|
||||||
|
* @author Gustice
|
||||||
|
* @brief
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "doctest/doctest.h"
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "spit_client.hpp"
|
||||||
|
|
||||||
|
using namespace spit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class ClientMock {
|
||||||
|
public:
|
||||||
|
void onServerEvent(SClient::ServerEvent event, const SadDetectedServer &detectedServer) {
|
||||||
|
}
|
||||||
|
void onConnectionStatus(string serverID, string serverComputerName, string serverName, int serverStepTime, SClient::Connection connectionStatus, SClient::Connection oldConnectionStatus) {
|
||||||
|
}
|
||||||
|
void onProjectUpdate(SClient::ProjUpdate state, string projectId) {
|
||||||
|
}
|
||||||
|
void onSpitType(SClient::ObjectEvent event, bool isRemote, const SType &spitType) {
|
||||||
|
}
|
||||||
|
void onSpitObject(SClient::ObjectEvent event, bool isRemote, const SType &spitType, const SObject &spitObject) {
|
||||||
|
}
|
||||||
|
void onPlay(string playerID, string playerName, char playerType, bool playerIsRunning, uint64_t timeFrames) {
|
||||||
|
}
|
||||||
|
void onPlaySpitType(string playerID, string spitTypeID, bool playerIsRunning, bool started, bool ended, double value) {
|
||||||
|
}
|
||||||
|
void onPlayRemoteObjectStatus(const SType &spitType, const SObject &spitObject, uint64_t p_FrameInsideObject, int value) {
|
||||||
|
}
|
||||||
|
bool onCheckSpitTypeVeto(bool knownType, bool createdByClient) {
|
||||||
|
}
|
||||||
|
bool onCheckSpitObjectVeto(bool knownType) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class SocketMock : public ISocket {
|
||||||
|
public:
|
||||||
|
SocketMock(IpAddress ip) : ISocket(ip) {}
|
||||||
|
|
||||||
|
int sendMessage(const char *message, int length) override {
|
||||||
|
}
|
||||||
|
int receiveMessage(char *bu1ffer, int bufferLength, string *serverIp) const override {
|
||||||
|
}
|
||||||
|
void setConnectionParams(const string &serverIp, const string &serverPort, const string &clientIp, const string &clientPort) override {
|
||||||
|
}
|
||||||
|
int bindSocket(string clientIp, string clientPort) override {
|
||||||
|
}
|
||||||
|
int setBroadcast(bool broadcast) const override {
|
||||||
|
}
|
||||||
|
int sendMessageTo(const string &ip, const string &port, const char *message, int msgLength) override {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class SpitClientFix {
|
||||||
|
protected:
|
||||||
|
static ClientMock client;
|
||||||
|
ISocket::IpAddress ip{"10.10.0.1", "255.255.255.0"};
|
||||||
|
SocketMock socket{ip};
|
||||||
|
SClient::Callbacks callbacks{
|
||||||
|
.onServerEvent = [&](SClient::ServerEvent event, const SadDetectedServer &detectedServer){client.onServerEvent(event, detectedServer);} ,
|
||||||
|
.onConnectionStatus = [&](string serverID, string serverComputerName, string serverName, int serverStepTime, SClient::Connection connectionStatus, SClient::Connection oldConnectionStatus){client.onConnectionStatus(serverID, serverComputerName, serverName, serverStepTime, connectionStatus, oldConnectionStatus);} ,
|
||||||
|
.onProjectUpdate = [&](SClient::ProjUpdate state, string projectId){client.onProjectUpdate(state, projectId);} ,
|
||||||
|
.onSpitType = [&](SClient::ObjectEvent event, bool isRemote, const SType &spitType){client.onSpitType(event, isRemote, spitType);} ,
|
||||||
|
.onSpitObject = [&](SClient::ObjectEvent event, bool isRemote, const SType &spitType, const SObject &spitObject){client.onSpitObject(event, isRemote, spitType, spitObject);} ,
|
||||||
|
.onPlay = [&](string playerID, string playerName, char playerType, bool playerIsRunning, uint64_t timeFrames){client.onPlay(playerID, playerName, playerType, playerIsRunning, timeFrames);} ,
|
||||||
|
.onPlaySpitType = [&](string playerID, string spitTypeID, bool playerIsRunning, bool started, bool ended, double value){client.onPlaySpitType(playerID, spitTypeID, playerIsRunning, started, ended, value);} ,
|
||||||
|
.onPlayRemoteObjectStatus = [&](const SType &spitType, const SObject &spitObject, uint64_t p_FrameInsideObject, int value){client.onPlayRemoteObjectStatus( spitType, spitObject, p_FrameInsideObject, value);} ,
|
||||||
|
.onCheckSpitTypeVeto = [&](bool knownType, bool createdByClient){return client.onCheckSpitTypeVeto(knownType, createdByClient);} ,
|
||||||
|
.onCheckSpitObjectVeto = [&](bool knownType){return client.onCheckSpitObjectVeto(knownType);}
|
||||||
|
};
|
||||||
|
SClient sut{"sut", "sutProj", socket, callbacks};
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(SpitClientFix, "Typical use case") {
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
/**
|
||||||
|
* @file spitRepoTest.cpp
|
||||||
|
* @author Gustice
|
||||||
|
* @brief
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "doctest/doctest.h"
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "spit_object.hpp"
|
||||||
|
|
||||||
|
using namespace spit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class SpitObjectFix {
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(SpitObjectFix, "Typical use case") {
|
||||||
|
{
|
||||||
|
SObject sut("#Id#123");
|
||||||
|
CHECK(sut.getID() == "#Id#123");
|
||||||
|
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.Name.set("G123") == true);
|
||||||
|
CHECK(sut.Name.get() == "G123");
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.Name.set("G123") == false);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.Name.set("G321") == true);
|
||||||
|
CHECK(sut.Name.get() == "G321");
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SObject sut("#Id#123");
|
||||||
|
CHECK(sut.getID() == "#Id#123");
|
||||||
|
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.Fixed.set(true) == true);
|
||||||
|
CHECK(sut.Fixed.get() == true);
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.Fixed.set(true) == false);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.Fixed.set(false) == true);
|
||||||
|
CHECK(sut.Fixed.get() == false);
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SObject sut("#Id#123");
|
||||||
|
CHECK(sut.getID() == "#Id#123");
|
||||||
|
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.FrameLength.set(123) == true);
|
||||||
|
CHECK(sut.FrameLength.get() == 123);
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.FrameLength.set(123) == false);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.FrameLength.set(321) == true);
|
||||||
|
CHECK(sut.FrameLength.get() == 321);
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// {
|
||||||
|
// SObject sut("#Id#123", "grp123", "name123", true, false, 1234, 4321);
|
||||||
|
// CHECK(sut.getID() == "#Id#123");
|
||||||
|
// CHECK(sut.GroupName.get() == "grp123");
|
||||||
|
// CHECK(sut.Name.get() == "name123");
|
||||||
|
// CHECK(sut.Fixed.get() == true);
|
||||||
|
// CHECK(sut.ProjectIndepended.get() == false);
|
||||||
|
|
||||||
|
// CHECK(sut.DefaultDelay.get() == 1234);
|
||||||
|
// CHECK(sut.DefaultDuration.get() == 4321);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
/**
|
||||||
|
* @file spitRepoTest.cpp
|
||||||
|
* @author Gustice
|
||||||
|
* @brief
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "doctest/doctest.h"
|
||||||
|
#include <fmt/core.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "spit_type.hpp"
|
||||||
|
|
||||||
|
using namespace spit;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class SpitTypetFix {
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_CASE_FIXTURE(SpitTypetFix, "check confirmend behaviour") {
|
||||||
|
{
|
||||||
|
SType sut("#Id#123");
|
||||||
|
CHECK(sut.getID() == "#Id#123");
|
||||||
|
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.GroupName.set("G123") == true);
|
||||||
|
CHECK(sut.GroupName.get() == "G123");
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.GroupName.set("G123") == false);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.GroupName.set("G321") == true);
|
||||||
|
CHECK(sut.GroupName.get() == "G321");
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SType sut("#Id#123");
|
||||||
|
CHECK(sut.getID() == "#Id#123");
|
||||||
|
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.Fixed.set(true) == true);
|
||||||
|
CHECK(sut.Fixed.get() == true);
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.Fixed.set(true) == false);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.Fixed.set(false) == true);
|
||||||
|
CHECK(sut.Fixed.get() == false);
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
SType sut("#Id#123");
|
||||||
|
CHECK(sut.getID() == "#Id#123");
|
||||||
|
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.DefaultDelay.set(123) == true);
|
||||||
|
CHECK(sut.DefaultDelay.get() == 123);
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
sut.setConfirmed(true);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.DefaultDelay.set(123) == false);
|
||||||
|
CHECK(sut.getConfirmed() == true);
|
||||||
|
CHECK(sut.DefaultDelay.set(321) == true);
|
||||||
|
CHECK(sut.DefaultDelay.get() == 321);
|
||||||
|
CHECK(sut.getConfirmed() == false);
|
||||||
|
}
|
||||||
|
// ...
|
||||||
|
|
||||||
|
{
|
||||||
|
SType sut("#Id#123", "grp123", "name123", true, false, 1234, 4321);
|
||||||
|
CHECK(sut.getID() == "#Id#123");
|
||||||
|
CHECK(sut.GroupName.get() == "grp123");
|
||||||
|
CHECK(sut.Name.get() == "name123");
|
||||||
|
CHECK(sut.Fixed.get() == true);
|
||||||
|
CHECK(sut.ProjectIndepended.get() == false);
|
||||||
|
|
||||||
|
CHECK(sut.DefaultDelay.get() == 1234);
|
||||||
|
CHECK(sut.DefaultDuration.get() == 4321);
|
||||||
|
}
|
||||||
|
}
|
||||||
+53
-49
@@ -14,6 +14,8 @@
|
|||||||
#include "watchMain.hpp"
|
#include "watchMain.hpp"
|
||||||
#include "interconConfig.hpp"
|
#include "interconConfig.hpp"
|
||||||
|
|
||||||
|
using namespace spit;
|
||||||
|
|
||||||
string ClientName = "CatasWatchDev";
|
string ClientName = "CatasWatchDev";
|
||||||
string ProjectName = "CatastrphicProj";
|
string ProjectName = "CatastrphicProj";
|
||||||
|
|
||||||
@@ -580,9 +582,9 @@ struct LocalSpitObj {
|
|||||||
std::map<string, MoveCommand> ProvidedSpitActions;
|
std::map<string, MoveCommand> ProvidedSpitActions;
|
||||||
std::map<string, string> ExpectedObjects;
|
std::map<string, string> ExpectedObjects;
|
||||||
|
|
||||||
void onServerEvent(SPIT_Client::ServerEvent event, const SAD_DetectedServer &p_DetectedServer) {
|
void onServerEvent(SClient::ServerEvent event, const SadDetectedServer &p_DetectedServer) {
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case SPIT_Client::ServerEvent::Detect:
|
case SClient::ServerEvent::Detect:
|
||||||
ESP_LOGI(TAG, "SERVER DETECTED");
|
ESP_LOGI(TAG, "SERVER DETECTED");
|
||||||
ESP_LOGI(TAG, " Name: %s", p_DetectedServer.getName().data());
|
ESP_LOGI(TAG, " Name: %s", p_DetectedServer.getName().data());
|
||||||
ESP_LOGI(TAG, " ID: %s", p_DetectedServer.getID().data());
|
ESP_LOGI(TAG, " ID: %s", p_DetectedServer.getID().data());
|
||||||
@@ -592,11 +594,11 @@ void onServerEvent(SPIT_Client::ServerEvent event, const SAD_DetectedServer &p_D
|
|||||||
ESP_LOGI(TAG, " Addition: %s", p_DetectedServer.getAdditions().data());
|
ESP_LOGI(TAG, " Addition: %s", p_DetectedServer.getAdditions().data());
|
||||||
ESP_LOGI(TAG, " ClientIP: %s", p_DetectedServer.getClientIP().data());
|
ESP_LOGI(TAG, " ClientIP: %s", p_DetectedServer.getClientIP().data());
|
||||||
break;
|
break;
|
||||||
case SPIT_Client::ServerEvent::Lost:
|
case SClient::ServerEvent::Lost:
|
||||||
ESP_LOGW(TAG, "Server lost Name: %s IP: %s", p_DetectedServer.getName().data(), p_DetectedServer.getIP().data());
|
ESP_LOGW(TAG, "Server lost Name: %s IP: %s", p_DetectedServer.getName().data(), p_DetectedServer.getIP().data());
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SPIT_Client::ServerEvent::Changed:
|
case SClient::ServerEvent::Changed:
|
||||||
ESP_LOGW(TAG, "Server lost Name: %s IP: %s", p_DetectedServer.getName().data(), p_DetectedServer.getIP().data());
|
ESP_LOGW(TAG, "Server lost Name: %s IP: %s", p_DetectedServer.getName().data(), p_DetectedServer.getIP().data());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -606,25 +608,25 @@ 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,
|
void onConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime,
|
||||||
SPIT_Client::Connection p_ConnectionStatus, SPIT_Client::Connection p_OldConnectionStatus) {
|
SClient::Connection p_ConnectionStatus, SClient::Connection p_OldConnectionStatus) {
|
||||||
ESP_LOGI(TAG, "MySPITApp: eventConnectionStatus %d->%d ", (int)p_OldConnectionStatus, (int)p_ConnectionStatus);
|
ESP_LOGI(TAG, "MySPITApp: eventConnectionStatus %d->%d ", (int)p_OldConnectionStatus, (int)p_ConnectionStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The transfer of the server's SPITTypes and SPITObjects is finished.
|
// The transfer of the server's SPITTypes and SPITObjects is finished.
|
||||||
void onProjectUpdate(SPIT_Client::ProjUpdate state, string projectId) {
|
void onProjectUpdate(SClient::ProjUpdate state, string projectId) {
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case SPIT_Client::ProjUpdate::ServerLoaded:
|
case SClient::ProjUpdate::ServerLoaded:
|
||||||
ESP_LOGI(TAG, "eventProjectReport ID: %s ", projectId.data());
|
ESP_LOGI(TAG, "eventProjectReport ID: %s ", projectId.data());
|
||||||
break;
|
break;
|
||||||
case SPIT_Client::ProjUpdate::StartTransfer:
|
case SClient::ProjUpdate::StartTransfer:
|
||||||
ESP_LOGI(TAG, "eventStartProjectTransfer");
|
ESP_LOGI(TAG, "eventStartProjectTransfer");
|
||||||
break;
|
break;
|
||||||
case SPIT_Client::ProjUpdate::EndTransfer:
|
case SClient::ProjUpdate::EndTransfer:
|
||||||
ESP_LOGI(TAG, "eventEndProjectTransfer");
|
ESP_LOGI(TAG, "eventEndProjectTransfer");
|
||||||
spitProjectFinish.give();
|
spitProjectFinish.give();
|
||||||
break;
|
break;
|
||||||
case SPIT_Client::ProjUpdate::ServerClosed:
|
case SClient::ProjUpdate::ServerClosed:
|
||||||
ESP_LOGI(TAG, "eventProjectClosed ID: %s", projectId.data());
|
ESP_LOGI(TAG, "eventProjectClosed ID: %s", projectId.data());
|
||||||
// If we don't save SPITServer's project specific information
|
// If we don't save SPITServer's project specific information
|
||||||
// perhaps close all SPITObjects and RemoteSPITObjects to avoid conflicts, when the SPITServer loads a new project
|
// perhaps close all SPITObjects and RemoteSPITObjects to avoid conflicts, when the SPITServer loads a new project
|
||||||
@@ -657,15 +659,15 @@ bool onCheckSpitObjectVeto(bool knownType) {
|
|||||||
// Called when the server has created, loaded, changed or deleted a (Remote) SPITType.
|
// 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.
|
// 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.
|
// May also occur when the server confirms a SPITType created or changed by the client.
|
||||||
void onSpitType(SPIT_Client::ObjectEvent event, bool isRemote, const SPITType &p_SPITType) {
|
void onSpitType(SClient::ObjectEvent event, bool isRemote, const SType &sType) {
|
||||||
if (isRemote) {
|
if (isRemote) {
|
||||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
if (event == SClient::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());
|
ESP_LOGI(TAG, "NEW SPIT-REMOTE-Type ID: %s GroupName: %s Name: %s confirmed: %d", sType.getID().data(), sType.GroupName.get().data(), sType.Name.get().data(), sType.getConfirmed());
|
||||||
auto typeName = p_SPITType.getName();
|
auto typeName = sType.Name.get();
|
||||||
if (ExpectedObjects.contains(typeName)) {
|
if (ExpectedObjects.contains(typeName)) {
|
||||||
ExpectedObjects[typeName] = p_SPITType.getID();
|
ExpectedObjects[typeName] = sType.getID();
|
||||||
}
|
}
|
||||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
} else if (event == SClient::ObjectEvent::Changed) {
|
||||||
// we had to inform all Remote SPITObjects using the p_SPITType
|
// we had to inform all Remote SPITObjects using the p_SPITType
|
||||||
// perhaps the SPITObject uses information from the SPITType
|
// perhaps the SPITObject uses information from the SPITType
|
||||||
// SPITObject *ptrSPITObject;
|
// SPITObject *ptrSPITObject;
|
||||||
@@ -677,22 +679,22 @@ void onSpitType(SPIT_Client::ObjectEvent event, bool isRemote, const SPITType &p
|
|||||||
// continue;
|
// continue;
|
||||||
// if (ptrSPITObject->getSPITTypeID() == p_SPITType.getID()) {
|
// if (ptrSPITObject->getSPITTypeID() == p_SPITType.getID()) {
|
||||||
// // call ecentSPITObjectRemote
|
// // call ecentSPITObjectRemote
|
||||||
// // onSpitObjectRemote(SPIT_Client::ObjectEvent::Changed, p_SPITType, *ptrSPITObject);
|
// // onSpitObjectRemote(SClient::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());
|
ESP_LOGI(TAG, "SPIT-REMOTE-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", sType.getID().data(), sType.GroupName.get().data(), sType.Name.get().data(), sType.getConfirmed());
|
||||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
} else if (event == SClient::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());
|
ESP_LOGD(TAG, "SPIT-REMOTE-Type Removed ID: %s GroupName: %s Name: %s\n", sType.getID().data(), sType.GroupName.get().data(), sType.Name.get().data());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
if (event == SClient::ObjectEvent::Created) {
|
||||||
// Whenever you provide an action for this SPITType take this over in your code.
|
// Whenever you provide an action for this SPITType take this over in your code.
|
||||||
// call _SpitClient.setActionSPITType(p_SPITType.getID(), true);
|
// call _SpitClient.setActionSPITType(sType.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());
|
ESP_LOGI(TAG, "NEW SPIT-Type ID: %s GroupName: %s Name: %s confirmed: %d", sType.getID().data(), sType.GroupName.get().data(), sType.Name.get().data(), sType.getConfirmed());
|
||||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
} else if (event == SClient::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());
|
ESP_LOGI(TAG, "SPIT-Type CHANGED ID: %s GroupName: %s Name: %s confirmed: %d", sType.getID().data(), sType.GroupName.get().data(), sType.Name.get().data(), sType.getConfirmed());
|
||||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
} else if (event == SClient::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-Type Removed ID: %s GroupName: %s Name: %s\n", sType.getID().data(), sType.GroupName.get().data(), sType.Name.get().data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -703,35 +705,35 @@ void onSpitType(SPIT_Client::ObjectEvent event, bool isRemote, const SPITType &p
|
|||||||
// false = server changed a existing SPITObject
|
// false = server changed a existing SPITObject
|
||||||
// @param p_SPITType a reference to a copy of the associated SPITType instance.
|
// @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.
|
// @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) {
|
void onSpitObject(SClient::ObjectEvent event, bool isRemote, const SType &sType, const SObject &sObject) {
|
||||||
if (isRemote) {
|
if (isRemote) {
|
||||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
if (event == SClient::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());
|
ESP_LOGI(TAG, "NEW SPIT-REMOTE-Object ID: %s Name: %s -> SPITType: %s", sObject.getID().data(), sObject.Name.get().data(), sType.Name.get().data());
|
||||||
// This is a remote SPITObject which can be used to remote control the server.
|
// This is a remote SPITObject which can be used to remote control the server.
|
||||||
// If you want you can list this for later use
|
// If you want you can list this for later use
|
||||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
} else if (event == SClient::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());
|
ESP_LOGI(TAG, "SPIT-REMOTE-Object CHANGED ID: %s Name: %s -> SPITType: %s", sObject.getID().data(), sObject.Name.get().data(), sType.Name.get().data());
|
||||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
} else if (event == SClient::ObjectEvent::Deleted) {
|
||||||
ESP_LOGD(TAG, "SPIT-REMOTE-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data());
|
ESP_LOGD(TAG, "SPIT-REMOTE-Object Removed ID: %s Name: %s\n", sObject.getID().data(), sObject.Name.get().data());
|
||||||
// This is a remote SPITObject
|
// This is a remote SPITObject
|
||||||
// If you have listet this prior you should remove it from the list
|
// If you have listet this prior you should remove it from the list
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (event == SPIT_Client::ObjectEvent::Created) {
|
if (event == SClient::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());
|
ESP_LOGI(TAG, "NEW SPIT-Object ID: %s Name: %s -> SPITType: %s", sObject.getID().data(), sObject.Name.get().data(), sType.Name.get().data());
|
||||||
// check your actions
|
// check your actions
|
||||||
// Whenever you provide an action for this SPITObject take this over in your code.
|
// Whenever you provide an action for this SPITObject take this over in your code.
|
||||||
// call _SpitClient.setActionSPITObject(p_SPITObject.getID(), true);
|
// call _SpitClient.setActionSPITObject(sObject.getID(), true);
|
||||||
|
|
||||||
// for our little excample as described in loadClientProject:
|
// 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
|
// 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
|
//-> 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
|
// SPITObjects with other SPITTypes asscciated will trigger no actions
|
||||||
|
|
||||||
} else if (event == SPIT_Client::ObjectEvent::Changed) {
|
} else if (event == SClient::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());
|
ESP_LOGI(TAG, "SPIT-Object CHANGED ID: %s Name: %s -> SPITType: %s", sObject.getID().data(), sObject.Name.get().data(), sType.Name.get().data());
|
||||||
} else if (event == SPIT_Client::ObjectEvent::Deleted) {
|
} else if (event == SClient::ObjectEvent::Deleted) {
|
||||||
ESP_LOGD(TAG, "SPIT-Object Removed ID: %s Name: %s\n", p_SPITObject.getID().data(), p_SPITObject.getName().data());
|
ESP_LOGD(TAG, "SPIT-Object Removed ID: %s Name: %s\n", sObject.getID().data(), sObject.Name.get().data());
|
||||||
// Check your actions
|
// Check your actions
|
||||||
// take the removal of the SPITObject over in your code
|
// take the removal of the SPITObject over in your code
|
||||||
|
|
||||||
@@ -744,18 +746,18 @@ void onSpitObject(SPIT_Client::ObjectEvent event, bool isRemote, const SPITType
|
|||||||
// SPITServer may use several methods for playing SPITObjects.
|
// SPITServer may use several methods for playing SPITObjects.
|
||||||
// e.g. liveSHOWsoftware has the timeline and jingles which plays objects, where the timeline the main player is.
|
// e.g. liveSHOWsoftware has the timeline and jingles which plays objects, where the timeline the main player is.
|
||||||
// SPIT distinguishes between the different players. All eventPlay... functions contain the information which player plays the SPIT object.
|
// SPIT distinguishes between the different players. All eventPlay... functions contain the information which player plays the SPIT object.
|
||||||
void onPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, long long p_TimeFrames) {
|
void onPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bool p_PlayerIsRunning, uint64_t p_TimeFrames) {
|
||||||
ESP_LOGD(TAG, "eventPlay Player: %s Runs: %d Time: %lld", p_PlayerName.data(), p_PlayerIsRunning, p_TimeFrames);
|
ESP_LOGD(TAG, "eventPlay Player: %s Runs: %d Time: %lld", p_PlayerName.data(), p_PlayerIsRunning, p_TimeFrames);
|
||||||
|
|
||||||
switch (p_PlayerType) {
|
switch (p_PlayerType) {
|
||||||
case SPIT_Client::PLAYERTYPE_MAIN:
|
case SClient::PLAYERTYPE_MAIN:
|
||||||
// p_FrameTimes contains the position inside the server's project, we can use it like a timecode
|
// p_FrameTimes contains the position inside the server's project, we can use it like a timecode
|
||||||
// int intMilliseconds = (int)(((double)p_TimeFrames / (double)m_ServerFramesPerSecond) * 1000);
|
// int intMilliseconds = (int)(((double)p_TimeFrames / (double)m_ServerFramesPerSecond) * 1000);
|
||||||
break;
|
break;
|
||||||
case SPIT_Client::PLAYERTYPE_CONTINOUS:
|
case SClient::PLAYERTYPE_CONTINOUS:
|
||||||
// The olayer is playing only single Object sequences sometime during the project
|
// The olayer is playing only single Object sequences sometime during the project
|
||||||
break;
|
break;
|
||||||
case SPIT_Client::PLAYERTYPE_DISCRETE:
|
case SClient::PLAYERTYPE_DISCRETE:
|
||||||
// Only discrete values where submitted, e.g the fader position of remote faders.
|
// Only discrete values where submitted, e.g the fader position of remote faders.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -791,8 +793,8 @@ void onPlaySpitType(string p_PlayerID, string spitTypeId, bool p_PlayerIsRunning
|
|||||||
* @param p_FrameInsideObject can be discarded
|
* @param p_FrameInsideObject can be discarded
|
||||||
* @param p_Value the new value
|
* @param p_Value the new value
|
||||||
*/
|
*/
|
||||||
void onPlayRemoteObjectStatus(const SPITType &p_SPITType, const SPITObject &p_SPITObject, long long p_FrameInsideObject, int p_Value) {
|
void onPlayRemoteObjectStatus(const SType &sType, const SObject &sObject, uint64_t frameInsideObject, int 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);
|
ESP_EARLY_LOGD(TAG, "eventPlayRemoteObjectStatus RemoteSPITType: %s RemoteSPITObject: %s Position: %lld Value: %d", sType.Name.get().data(), sObject.Name.get().data(), frameInsideObject, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpitClientApp() {
|
void SpitClientApp() {
|
||||||
@@ -810,7 +812,9 @@ void SpitClientApp() {
|
|||||||
ExpectedObjects[expected.inPosX[i]] = "";
|
ExpectedObjects[expected.inPosX[i]] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
SPIT_Client spitClient(ClientName, ProjectName,
|
auto ip = spit::Socket::getAdaptersInfo();
|
||||||
|
spit::Socket socket(ip);
|
||||||
|
SClient spitClient(ClientName, ProjectName, socket,
|
||||||
{
|
{
|
||||||
.onServerEvent = onServerEvent,
|
.onServerEvent = onServerEvent,
|
||||||
.onConnectionStatus = onConnectionStatus,
|
.onConnectionStatus = onConnectionStatus,
|
||||||
@@ -825,7 +829,7 @@ void SpitClientApp() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (auto &obj : ProvidedObj) {
|
for (auto &obj : ProvidedObj) {
|
||||||
SPITType *ptrSPITType1Fix = spitClient.createSPITTypeFixed(obj.iD, obj.groupName, obj.name, 0, 0);
|
SType *ptrSPITType1Fix = spitClient.createSPITTypeFixed(obj.iD, obj.groupName, obj.name, 0, 0);
|
||||||
spitClient.setActionSPITType(ptrSPITType1Fix->getID(), true); // should be executed whenever a SPITObject with this SPITType is played
|
spitClient.setActionSPITType(ptrSPITType1Fix->getID(), true); // should be executed whenever a SPITObject with this SPITType is played
|
||||||
}
|
}
|
||||||
spitClient.clientProjectLoaded();
|
spitClient.clientProjectLoaded();
|
||||||
|
|||||||
+5
-5
@@ -54,11 +54,11 @@
|
|||||||
// #include <sys/param.h>
|
// #include <sys/param.h>
|
||||||
// #include <unistd.h>
|
// #include <unistd.h>
|
||||||
|
|
||||||
#include "SAD_DetectedServer.hpp"
|
#include "sad_DetectedServer.hpp"
|
||||||
#include "SPITObject.h"
|
#include "spit_object.hpp"
|
||||||
#include "SPITPlayer.h"
|
#include "spit_player.hpp"
|
||||||
#include "SPITType.h"
|
#include "spit_type.hpp"
|
||||||
#include "SPIT_Client.h"
|
#include "spit_client.hpp"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|||||||
Reference in New Issue
Block a user