feat: Migrating features from newer implementation

This commit is contained in:
2025-03-29 10:50:16 +01:00
parent 171a48eb71
commit 810264aa71
15 changed files with 982 additions and 538 deletions
+78 -47
View File
@@ -12,8 +12,8 @@ MyApp::MyApp() :
_SpitClient (
s_ClientName, s_ProjectName,
{
.onServerDetect = onServerDetected,
.onServerLost = onServerLost,
.onServerEvent = onServerEvent,
.onConnectionStatus = onConnectionStatus,
.onStartProjectTransfer = onStartProjectTransfer,
.onEndProjectTransfer = onEndProjectTransfer,
.onProjectClosed = onProjectClosed,
@@ -27,10 +27,11 @@ MyApp::MyApp() :
.onSpitObjectRemoved = onSpitObjectRemoved,
.onSpitObjectRemoteRemoved = onSpitObjectRemoteRemoved,
.onPlay = onPlay,
.onPlayObject = onPlayObject,
.onPlaySpitType = onPlaySpitType,
.onPlayRemoteObjectStatus = onPlayRemoteObjectStatus,
.onCheckSpitTypeVeto = onCheckSpitTypeVeto,
.onCheckSpitObjectVeto = onCheckSpitObjectVeto,
}) {
}
string MyApp::m_ServerProjectID{};
@@ -38,10 +39,8 @@ string MyApp::m_ServerProjectName{};
int MyApp::m_ServerFramesPerSecond{44100}; // set when the server reports his project, see eventProjectReport
void MyApp::init() {
SPITType *ptrSPITType1Fix;
ptrSPITType1Fix = _SpitClient.createSPITTypeFixed("MySPITAPP_Action1ID", "ActionGroupName", "Action1Name", 0, 0);
SPITType *ptrSPITType2Fix;
ptrSPITType2Fix = _SpitClient.createSPITTypeFixed("MySPITAPP_Action2ID", "ActionGroupName", "Action2Name", 0, 0);
SPITType *ptrSPITType1Fix = _SpitClient.createSPITTypeFixed("MySPITAPP_Action1ID", "ActionGroupName", "Action1Name", 0, 0);
SPITType *ptrSPITType2Fix = _SpitClient.createSPITTypeFixed("MySPITAPP_Action2ID", "ActionGroupName", "Action2Name", 0, 0);
// When an action exist which should be done whenever a SPITObject with this SPITType is played,
// then you should 'setAssignedActionType' to true
@@ -51,24 +50,37 @@ void MyApp::init() {
_SpitClient.startServerAutoDetect();
}
void MyApp::onServerDetected(const SAD_DetectedServer &p_DetectedServer) {
ESP_LOGI(TAG, "SERVER DETECTED");
ESP_LOGD(TAG, " Name: %s", p_DetectedServer.getName().data());
ESP_LOGD(TAG, " ID: %s", p_DetectedServer.getID().data());
ESP_LOGD(TAG, " Computer: %s", p_DetectedServer.getComputerName().data());
ESP_LOGD(TAG, " IP: %s", p_DetectedServer.getIP().data());
ESP_LOGD(TAG, " Port: %s", p_DetectedServer.getPort().data());
ESP_LOGD(TAG, " Addition: %s", p_DetectedServer.getAdditions().data());
ESP_LOGD(TAG, " ClientIP: %s", p_DetectedServer.getClientIP().data());
}
void MyApp::onServerLost(const SAD_DetectedServer &p_DetectedServer) {
void MyApp::onServerEvent(SPIT_Client::ServerEvent event, const SAD_DetectedServer &p_DetectedServer) {
switch (event)
{
case SPIT_Client::ServerEvent::Detect:
ESP_LOGI(TAG, "SERVER DETECTED");
ESP_LOGI(TAG, " Name: %s", p_DetectedServer.getName().data());
ESP_LOGI(TAG, " ID: %s", p_DetectedServer.getID().data());
ESP_LOGI(TAG, " Computer: %s", p_DetectedServer.getComputerName().data());
ESP_LOGI(TAG, " IP: %s", p_DetectedServer.getIP().data());
ESP_LOGI(TAG, " Port: %s", p_DetectedServer.getPort().data());
ESP_LOGI(TAG, " Addition: %s", p_DetectedServer.getAdditions().data());
ESP_LOGI(TAG, " ClientIP: %s", p_DetectedServer.getClientIP().data());
break;
case SPIT_Client::ServerEvent::Lost:
ESP_LOGW(TAG, "Server lost Name: %s IP: %s", p_DetectedServer.getName().data(), p_DetectedServer.getIP().data());
break;
case SPIT_Client::ServerEvent::Changed:
ESP_LOGW(TAG, "Server lost Name: %s IP: %s", p_DetectedServer.getName().data(), p_DetectedServer.getIP().data());
break;
default:
break;
}
}
//---------------------------------------
//---------- Connecting event ----------
void MyApp::eventConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus) {
void MyApp::onConnectionStatus(string p_ServerID, string p_ServerComputerName, string p_ServerName, int p_ServerStepTime, int p_ConnectionStatus, int p_OldConnectionStatus) {
ESP_LOGI(TAG, "MySPITApp: eventConnectionStatus %d ", p_ConnectionStatus);
}
//-----------------------------------------------------------
@@ -117,6 +129,41 @@ void MyApp::onEndProjectTransfer() {
//----------------------------------------------------
//--------- SPITType events ----------
/**
* The SPITCLientInterface (implemented by this) will be asked to veto the SPITType while SPIT_Client.parseReportSPITType.<br>
* @param p_ReportSPITType
* @return false = the SPITType is denied, true = the SPITType is accepted
*/
bool MyApp::onCheckSpitTypeVeto(SPIT_Message::ReportSPITType* p_ReportSPITType) {
if (p_ReportSPITType == NULL) return true;
SPITType* ptrSPITType;
ptrSPITType = SPITType::getSPITType(p_ReportSPITType->getID());
//Don't allow foreign SPITTypes
if (ptrSPITType == NULL) return false;
if (ptrSPITType->getCreatedByClient() == false) return false;
return true;
}
bool MyApp::onCheckSpitObjectVeto(SPIT_Message::ReportSPITObject* p_ReportSPITObject) {
if (p_ReportSPITObject == NULL) return true;
SPITType* ptrSPITType;
ptrSPITType = SPITType::getSPITType(p_ReportSPITObject->getSPITTypeID());
if (ptrSPITType == NULL) return false;
//Don't allow SPITObjects which refers to a SPITType which is not created by this client - other SPITTypes cannot be handled here
//if (ptrSPITType->getCreatedByClient() == false) return false;
// SPITObject* ptrSPITObject;
// ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITOnject->getID());
//Don't allow foreign SPITTypes
// if (ptrSPITObject == NULL) return false;
return true;
}
/**
* Called when the server has created, loaded or changed a SPITType.
* May also occur when the server confirms a SPITType created or changed by the client.
@@ -336,45 +383,29 @@ void MyApp::onPlay(string p_PlayerID, string p_PlayerName, char p_PlayerType, bo
* whether the player is running or not
* the actual value of the SPITObject (in liveSHOWsoftware objects ma faded in or out or the main value is decreased, ..
*/
void MyApp::onPlayObject(string p_PlayerID, bool p_Started, bool p_Ended, const SPITType &p_SPITType, const SPITObject &p_SPITObject, const SPITPlayer::PlayObject &p_PlayObject) {
// p_PlayObject.getValue() contain the value in ppm (we can calculate value between 0.0 and 1.0)
// p_SPITObject.getValueFactor() or redundand p_PlayObject.getValueFactor()
// contains the factor the above value should be multiplicated to get the end value.
double doubleValue = ((double)p_PlayObject.getValue() / 1000000) * ((double)p_PlayObject.getValueFactor() / 1000000);
void MyApp::onPlaySpitType(string p_PlayerID, string p_SPITTypeID, bool p_PlayerIsRunning, bool p_Started, bool p_Ended, double p_Value) {
// double doubleValue = ((double)p_PlayObject.getValue() / 1000000) * ((double)p_PlayObject.getValueFactor() / 1000000);
// Other factors besides value may be of interest
// p_PlayObject.getFrameInside() contains the play position inside the SPITObject
// p_SPITObject.getFrameLength() contains the length of the SPITObject
//-> we can calculate the position 0.0 to 1.0 where the Object is played
ESP_LOGD(TAG, "eventPlayObject Player: %s is running: %d Object Started: %d Stopped: %d", p_PlayerID.data(), p_PlayerIsRunning, p_Started, p_Ended);
// ESP_LOGD(TAG, " SPITType: %s SPITObject: %s Position: %lld Value: %f\n", p_SPITTypeID.data(), p_SPITObject.getName().data(), p_PlayObject.getFrameInside(), doubleValue);
ESP_LOGD(TAG, " SPITType: %s Value: %f\n", p_SPITTypeID.data(), p_Value);
// in liveSHOWsoftware the player may play two different position in the SPITObject to mix them down, e.g. a SceneBridge is played
// We can get the second (pre played) position: p_PlayObject.getFrameInsidePrePosition();
ESP_LOGD(TAG, "eventPlayObject Player: %s is running: %d Object Started: %d Stopped: %d", p_PlayObject.getPlayerName().data(), p_PlayObject.getPlayerIsRunning(), p_Started, p_Ended);
ESP_LOGD(TAG, " SPITType: %s SPITObject: %s Position: %lld Value: %f\n", p_SPITType.getName().data(), p_SPITObject.getName().data(), p_PlayObject.getFrameInside(), doubleValue);
// check for your actions to do
// In our little excample decribed in loadClientProject:
// We want to react to SPIT types, no matter which SPIT object is currently being played.
//-> check not the SPITObject itself but the associated SPITType
bool boolPLayerIsRunning = p_PlayObject.getPlayerIsRunning();
if (p_SPITType.getID() == "MySPITAPP_Action1ID") { // do Action 1
if (p_SPITTypeID == "MySPITAPP_Action1ID") { // do Action 1
// we can get some information about the play status
if (p_Started == true) {
ESP_LOGI(TAG, "MyApp AKTION 1 started Value: %f and running: %d", doubleValue, boolPLayerIsRunning);
ESP_LOGI(TAG, "MyApp AKTION 1 started Value: %f and running: %d", p_Value, p_PlayerIsRunning);
} else if (p_Ended == true) {
ESP_LOGI(TAG, "MyApp AKTION 1 ended"); // p_PlayObject.getFrameInside() is -1
} else {
ESP_LOGD(TAG, "MyApp AKTION 1 is played Value: %f and running: %d", doubleValue, boolPLayerIsRunning);
ESP_LOGD(TAG, "MyApp AKTION 1 is played Value: %f and running: %d", p_Value, p_PlayerIsRunning);
}
} else if (p_SPITType.getID() == "MySPITAPP_Action2ID") { // do Action 2
} else if (p_SPITTypeID == "MySPITAPP_Action2ID") { // do Action 2
if (p_Started == true) {
ESP_LOGI(TAG, "AKTION 2 started Value: %f and running: %d", doubleValue, boolPLayerIsRunning);
ESP_LOGI(TAG, "AKTION 2 started Value: %f and running: %d", p_Value, p_PlayerIsRunning);
} else if (p_Ended == true) {
ESP_LOGI(TAG, "AKTION 2 ended"); // p_PlayObject.getFrameInside() is -1
} else {
ESP_LOGD(TAG, "AKTION 2 is played Value: %f and running: %d", doubleValue, boolPLayerIsRunning);
ESP_LOGD(TAG, "AKTION 2 is played Value: %f and running: %d", p_Value, p_PlayerIsRunning);
}
}
}
+27 -8
View File
@@ -32,14 +32,24 @@ SAD_DetectedServer::SAD_DetectedServer() {
m_IPIsIP4 = false;
}
void SAD_DetectedServer::setProjectName(string p_ServerProjectName) {
if (m_ServerProjectName.compare(p_ServerProjectName) != 0) {
if (m_New == false) {
m_Changed = true;
}
}
m_ServerProjectName = p_ServerProjectName;
}
void SAD_DetectedServer::cycleStart() {
for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) {
i->second->startCycleSAD();
}
}
void SAD_DetectedServer::cycleEnd(I_SAD_Client& sADClientInterface) {
void SAD_DetectedServer::cycleEnd(I_SAD_Client& sadClient) {
list<SAD_DetectedServer*> o_LostServers;
list<SAD_DetectedServer*> o_NewServers;
list<SAD_DetectedServer*> o_ChangedServers;
SAD_DetectedServer* ptrDetectedServer;
{
for (auto i = s_DetectedServers.begin(); i != s_DetectedServers.end(); i++) {
@@ -54,6 +64,7 @@ void SAD_DetectedServer::cycleEnd(I_SAD_Client& sADClientInterface) {
ptrDetectedServer->endCycleSAD();
}
else if (ptrDetectedServer->getChanged()) {
o_ChangedServers.push_back(ptrDetectedServer);
ptrDetectedServer->endCycleSAD();
}
else {
@@ -64,8 +75,8 @@ void SAD_DetectedServer::cycleEnd(I_SAD_Client& sADClientInterface) {
//Notify client interface about lost servers
for (auto i = o_LostServers.begin(); i != o_LostServers.end(); i++) {
ptrDetectedServer = *i;
sADClientInterface.eventServerLost(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),
sadClient.eventServerLost(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),ptrDetectedServer->getProjectName(),
ptrDetectedServer->getClientIP(),
ptrDetectedServer->getIpIsIP4());
}
@@ -78,13 +89,20 @@ void SAD_DetectedServer::cycleEnd(I_SAD_Client& sADClientInterface) {
for (auto i = o_NewServers.begin(); i != o_NewServers.end(); i++) {
ptrDetectedServer = *i;
sADClientInterface.eventServerDetected(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),
sadClient.eventServerDetected(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),ptrDetectedServer->getProjectName(),
ptrDetectedServer->getClientIP(),
ptrDetectedServer->getIpIsIP4());
}
o_NewServers.clear();
for (auto i = o_ChangedServers.begin(); i != o_ChangedServers.end(); i++) {
ptrDetectedServer = *i;
sadClient.eventServerChanged(ptrDetectedServer->getID(), ptrDetectedServer->getName(),
ptrDetectedServer->getComputerName(), ptrDetectedServer->getIP(), ptrDetectedServer->getPort(), ptrDetectedServer->getAdditions(),ptrDetectedServer->getProjectName(),
ptrDetectedServer->getClientIP(),
ptrDetectedServer->getIpIsIP4());
}
o_ChangedServers.clear();
}
/**
* Used by SAD_Client to add a found SPITServer - don't use this manually
@@ -92,7 +110,7 @@ void SAD_DetectedServer::cycleEnd(I_SAD_Client& sADClientInterface) {
* @param p_ServerID the id of the server, every instance of a SPITServer has an own id
* @param p_ServerParams the server's parameter
*/
void SAD_DetectedServer::addDetectedServer(bool p_IsIP4, string p_ServerID, string p_ServerParams[]) {
void SAD_DetectedServer::addDetectedServer(bool p_IsIP4, string p_ServerID, string p_ServerParams[]) {
SAD_DetectedServer* ptrDetectedServer;
{
auto i = s_DetectedServers.find(p_ServerID);
@@ -103,7 +121,7 @@ void SAD_DetectedServer::addDetectedServer(bool p_IsIP4, string p_ServerID, stri
ptrDetectedServer = new SAD_DetectedServer();
ptrDetectedServer->setID(p_ServerParams[PARAMINDEX_ID]);
ptrDetectedServer->setNew(true);
}
}
ptrDetectedServer->setFoundAgain();
//second prefer IP4
@@ -120,6 +138,7 @@ void SAD_DetectedServer::addDetectedServer(bool p_IsIP4, string p_ServerID, stri
ptrDetectedServer->setComputerName(p_ServerParams[PARAMINDEX_COMPUTERNAME]);
ptrDetectedServer->setPort(p_ServerParams[PARAMINDEX_PORT]);
ptrDetectedServer->setAdditions(p_ServerParams[PARAMINDEX_ADDITIONS]);
ptrDetectedServer->setProjectName(p_ServerParams[PARAMINDEX_SERVERPROJECTNAME]);
s_DetectedServers[ptrDetectedServer->getID()] = ptrDetectedServer;
}
+153 -46
View File
@@ -84,8 +84,11 @@
}
bool SPITObject::removeSPITObject(SPITObject* p_ptrSPITObject) {
if (p_ptrSPITObject == NULL) return false;
return removeSPITObject(p_ptrSPITObject->getID());
}
bool SPITObject::removeSPITObject(string p_SPITObjectID) {
{
auto i = s_SPITObjects.find(p_ptrSPITObject->getID());
auto i = s_SPITObjects.find(p_SPITObjectID);
if (i == s_SPITObjects.end()) {
return false;
}
@@ -95,8 +98,11 @@
}
bool SPITObject::removeSPITObjectRemote(SPITObject* p_ptrSPITObject) {
if (p_ptrSPITObject == NULL) return false;
return removeSPITObjectRemote(p_ptrSPITObject->getID());
}
bool SPITObject::removeSPITObjectRemote(string p_ptrSPITObject) {
{
auto i = s_SPITObjectsRemote.find(p_ptrSPITObject->getID());
auto i = s_SPITObjectsRemote.find(p_ptrSPITObject);
if (i == s_SPITObjectsRemote.end()) {
return false;
}
@@ -203,8 +209,44 @@
}
}
/**
* clears all unconfirmed SPITObjects not created by this SPIT_Client.
*/
void SPITObject::clearUnconfirmedSPITObjects() {
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) {
SPITObject* ptrSPITObject = i->second;
if (ptrSPITObject->getCreatedByClient() == false && ptrSPITObject->getConfirmed() == false) {
i = s_SPITObjects.erase(i);
delete ptrSPITObject;
}
if (i == s_SPITObjects.end()) {
break;
}
}
}
void SPITObject::eventProjectClosed() {
for (auto i = s_SPITObjects.begin(); i != s_SPITObjects.end(); i++) {
SPITObject* ptrSPITObject = i->second;
if (ptrSPITObject->getCreatedByClient() == true) {
continue;
}
i = s_SPITObjects.erase(i);
delete ptrSPITObject;
if (i == s_SPITObjects.end()) {
break;
}
}
//Remote
for (auto i = s_SPITObjectsRemote.begin(); i != s_SPITObjectsRemote.end(); i++) {
SPITObject* ptrSPITObject = i->second;
i = s_SPITObjectsRemote.erase(i);
delete ptrSPITObject;
if (i == s_SPITObjectsRemote.end()) {
break;
}
}
}
/**
* sets confirmed = false for all SPITObjects.<br>
* This should be called when the client has loaded a project.<br>
@@ -231,6 +273,7 @@ void SPITObject::initMembers() {
m_Delay = 0;
m_Duration = 0;
m_Fixed = false;
m_CreatedByClient = false;
m_FrameFadeInLength = 0;
m_FrameFadeOutLength = 0;
m_FrameLength = 0;
@@ -245,51 +288,112 @@ void SPITObject::initMembers() {
m_ValueFactor = 1000000; //Values are given in ppm -> 1000000 = 1/1;
m_ValueUse = 0x01;
}
/*
SPITObject::SPITObject(const SPITObject& orig) {
m_ActionAssigned = orig.getActionAssigned();
m_Confirmed = orig.getConfirmed();
m_Delay = orig.getDelay();
m_Duration = orig.getDuration();
m_Fixed = orig.getFixed();
m_FrameFadeInLength = orig.getFrameFadeInLength();
m_FrameFadeOutLength = orig.getFrameFadeOutLength();
m_FrameLength = orig.getFrameLength();
m_FrameStart = orig.getFrameStart();
m_Remark = orig.getRemark();
m_ID = orig.getID();
m_Name = orig.getName();
m_SPITTypeID = orig.getSPITTypeID();
m_ServerParams = orig.getServerParams();
m_ServerRemote = orig.getServerRemote();
m_Track = orig.getTrack();
m_ValueFactor = orig.getValueFactor();
m_ValueUse = orig.getValueUse();
}
*/
SPITObject::~SPITObject() {
}
SPITObject::~SPITObject() { }
void SPITObject::setMessageOP(SPIT_Message::ReportSPITObject* p_ReportSPITObject) {
//m_ActionAssigned = p_ReportSPITObject->getActionAssigned(); //Should only be set by the client
m_Confirmed = p_ReportSPITObject->getConfirmed();
m_Delay = p_ReportSPITObject->getDelay();
m_Duration = p_ReportSPITObject->getDuration();
m_Fixed = p_ReportSPITObject->getFixed();
m_FrameFadeInLength = p_ReportSPITObject->getFrameFadeInLength();
m_FrameFadeOutLength = p_ReportSPITObject->getFrameFadeOutLength();
m_FrameLength = p_ReportSPITObject->getFrameLength();
m_FrameStart = p_ReportSPITObject->getFrameStart();
m_Remark = p_ReportSPITObject->getRemark();
m_ID = p_ReportSPITObject->getID();
m_Name = p_ReportSPITObject->getName();
m_SPITTypeID = p_ReportSPITObject->getSPITTypeID();
m_ServerParams = p_ReportSPITObject->getServerParams();
m_ServerRemote = p_ReportSPITObject->getServerRemote();
m_Track = p_ReportSPITObject->getTrack();
m_ValueFactor = p_ReportSPITObject->getValueFactor();
m_ValueUse = p_ReportSPITObject->getValueUse();
bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject* 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) throw new exception();
m_Delay = p_ReportSPITObject->getDelay();
boolChanged = true;
}
if (m_Duration != p_ReportSPITObject->getDuration()) {
if (boolChangeAllowed == false) throw new exception();
m_Duration = p_ReportSPITObject->getDuration();
boolChanged = true;
}
if (m_Fixed != p_ReportSPITObject->getFixed()) {
if (boolChangeAllowed == false) throw new exception();
m_Fixed = p_ReportSPITObject->getFixed();
boolChanged = true;
}
if (m_FrameFadeInLength != p_ReportSPITObject->getFrameFadeInLength()) {
if (boolChangeAllowed == false) throw new exception();
m_FrameFadeInLength = p_ReportSPITObject->getFrameFadeInLength();
boolChanged= true;
}
if (m_FrameFadeOutLength != p_ReportSPITObject->getFrameFadeOutLength()) {
if (boolChangeAllowed == false) throw new exception();
m_FrameFadeOutLength = p_ReportSPITObject->getFrameFadeOutLength();
boolChanged = true;
}
if (m_FrameLength != p_ReportSPITObject->getFrameLength()) {
if (boolChangeAllowed == false) throw new exception();
m_FrameLength = p_ReportSPITObject->getFrameLength();
boolChanged = true;
}
if (m_FrameStart != p_ReportSPITObject->getFrameStart()) {
if (boolChangeAllowed == false) throw new exception();
m_FrameStart = p_ReportSPITObject->getFrameStart();
boolChanged = true;
}
if (m_Remark != p_ReportSPITObject->getRemark()) {
if (boolChangeAllowed == false) throw new exception();
m_Remark = p_ReportSPITObject->getRemark();
boolChanged = true;
}
if (m_ID != p_ReportSPITObject->getID()) {
if (boolChangeAllowed == false) throw new exception();
m_ID = p_ReportSPITObject->getID();
boolChanged = true;
}
if (m_Name != p_ReportSPITObject->getName()) {
if (boolChangeAllowed == false) throw new exception();
m_Name = p_ReportSPITObject->getName();
boolChanged = true;
}
if (m_SPITTypeID != p_ReportSPITObject->getSPITTypeID()) {
if (boolChangeAllowed == false) throw new exception();
m_SPITTypeID = p_ReportSPITObject->getSPITTypeID();
boolChanged = true;
}
if (m_ServerParams != p_ReportSPITObject->getServerParams()) {
if (boolChangeAllowed == false) throw new exception();
m_ServerParams = p_ReportSPITObject->getServerParams();
boolChanged = true;
}
if (m_ServerRemote != p_ReportSPITObject->getServerRemote()) {
if (boolChangeAllowed == false) throw new exception();
m_ServerRemote = p_ReportSPITObject->getServerRemote();
boolChanged = true;
}
if (m_Track != p_ReportSPITObject->getTrack()) {
if (boolChangeAllowed == false) throw new exception();
m_Track = p_ReportSPITObject->getTrack();
boolChanged = true;
}
if (m_ValueFactor != p_ReportSPITObject->getValueFactor()) {
if (boolChangeAllowed == false) throw new exception();
m_ValueFactor = p_ReportSPITObject->getValueFactor();
boolChanged = true;
}
if (m_ValueUse != p_ReportSPITObject->getValueUse()) {
if (boolChangeAllowed == false) throw new exception();
m_ValueUse = p_ReportSPITObject->getValueUse();
boolChanged = true;
}
return boolChanged;
}
void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject* p_ReportSPITObject) {
@@ -319,6 +423,9 @@ void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject* p_RemoveSPITObjec
void SPITObject::setID(string p_ID) {
m_ID = p_ID;
}
void SPITObject::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.
+55 -80
View File
@@ -13,6 +13,7 @@
*/
#include "SPITPlayer.h"
#include <vector>
unordered_map<string, SPITPlayer*> SPITPlayer::s_SPITPlayers;
@@ -29,18 +30,17 @@ SPITPlayer* SPITPlayer::getSPITPlayer(string p_PlayerID) {
}
void SPITPlayer::clearPlayers() {
SPITPlayer* ptrSPITPlayer;
{
for (auto i = s_SPITPlayers.begin(); i != s_SPITPlayers.end(); i++) {
ptrSPITPlayer = i->second;
i = s_SPITPlayers.erase(i);
delete ptrSPITPlayer;
if (i == s_SPITPlayers.end()) {
break;
}
}
;
vector<SPITPlayer*> o_SPITPlayers;
for (auto i = s_SPITPlayers.begin(); i != s_SPITPlayers.end(); i++) {
SPITPlayer* ptrSPITPlayer = i->second;
o_SPITPlayers.push_back(ptrSPITPlayer);
}
for (auto i = o_SPITPlayers.begin(); i != o_SPITPlayers.end(); i++) {
SPITPlayer* ptrSPITPlayer = *i;
delete ptrSPITPlayer;
}
o_SPITPlayers.clear();
}
SPITPlayer::SPITPlayer(string p_PlayerID) {
@@ -48,19 +48,17 @@ SPITPlayer::SPITPlayer(string p_PlayerID) {
s_SPITPlayers[p_PlayerID] = this;
}
SPITPlayer::~SPITPlayer() {
{
PlayObject* ptrPlayObject;
for (auto i = m_PlayObjects.begin(); i != m_PlayObjects.end(); i++) {
ptrPlayObject = i->second;
i = m_PlayObjects.erase(i);
delete ptrPlayObject;
if (i == m_PlayObjects.end()) {
break;
}
PlaySPITType* ptrPlaySPITType;
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
ptrPlaySPITType = i->second;
i = m_PlaySPITTypes.erase(i);
delete ptrPlaySPITType;
if (i == m_PlaySPITTypes.end()) {
break;
}
}
}
void SPITPlayer::setIsRunning(bool p_IsRunning) {
@@ -76,8 +74,8 @@ void SPITPlayer::setTime(long long p_Frames) {
m_TimeFrames = p_Frames;
}
unordered_map<string, SPITPlayer::PlayObject*>* SPITPlayer::getPlayObjects() {
return &m_PlayObjects;
unordered_map<string, SPITPlayer::PlaySPITType*>* SPITPlayer::getPlaySPITTypes() {
return &m_PlaySPITTypes;
}
/**
*
@@ -85,72 +83,59 @@ unordered_map<string, SPITPlayer::PlayObject*>* SPITPlayer::getPlayObjects() {
* @return true = new PlayObject added<br>
* false = PlayObject exists
*/
SPITPlayer::PlayObject* SPITPlayer::addSPITObject_Playing (string p_SPITObjectID) {
PlayObject* ptrPlayObject;
{
auto i = m_PlayObjects.find(p_SPITObjectID);
if (i == m_PlayObjects.end()) {
ptrPlayObject = new PlayObject(this, p_SPITObjectID);
ptrPlayObject->setIsPlayed(true);
ptrPlayObject->setIsNew(true);
m_PlayObjects[p_SPITObjectID] = ptrPlayObject;
SPITPlayer::PlaySPITType* SPITPlayer::addSPITType_Playing (string p_SPITTypeID) {
PlaySPITType* ptrPlaySPITType;
auto i = m_PlaySPITTypes.find(p_SPITTypeID);
if (i == m_PlaySPITTypes.end()) {
ptrPlaySPITType = new PlaySPITType(this, p_SPITTypeID);
ptrPlaySPITType->setIsPlayed(true);
ptrPlaySPITType->setIsNew(true);
m_PlaySPITTypes[p_SPITTypeID] = ptrPlaySPITType;
}
else {
ptrPlayObject = i->second;
ptrPlayObject->setIsPlayed(true);
ptrPlaySPITType = i->second;
ptrPlaySPITType->setIsPlayed(true);
}
return ptrPlayObject;
}
return ptrPlaySPITType;
}
void SPITPlayer::startPlaySequence() {
PlayObject* ptrPlayObject;
{
for (auto i = m_PlayObjects.begin(); i != m_PlayObjects.end(); i++) {
ptrPlayObject = i->second;
ptrPlayObject->startPlaySequence();
}
PlaySPITType* ptrPlaySPITType;
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
ptrPlaySPITType = i->second;
ptrPlaySPITType->startPlaySequence();
}
}
/*
SPITPlayer::PlayObject* SPITPlayer::getPlayObject(string p_SPITObjectID) {
auto i = m_SPITObjectsPlaying.find(p_SPITObjectID);
if (i == m_SPITObjectsPlaying.end()) {
return NULL;
}
return i->second;
}
*/
void SPITPlayer::endPlaySequence() {
PlayObject* ptrPlayObject;
{
for (auto i = m_PlayObjects.begin(); i != m_PlayObjects.end(); i++) {
ptrPlayObject = i->second;
if (ptrPlayObject->getIsPlayed() == false) {
i = m_PlayObjects.erase(i);
delete ptrPlayObject;
if (i == m_PlayObjects.end()) {
PlaySPITType* ptrPlaySPITType;
for (auto i = m_PlaySPITTypes.begin(); i != m_PlaySPITTypes.end(); i++) {
ptrPlaySPITType = i->second;
if (ptrPlaySPITType->getIsPlayed() == false) {
i = m_PlaySPITTypes.erase(i);
delete ptrPlaySPITType;
if (i == m_PlaySPITTypes.end()) {
break;
}
}
}
}
}
SPITPlayer::PlayObject::PlayObject() {
SPITPlayer::PlaySPITType::PlaySPITType() {
}
SPITPlayer::PlayObject::PlayObject(SPITPlayer* p_SPITPlayer, string p_SPITObjectID) {
m_SPITObjectID = p_SPITObjectID;
SPITPlayer::PlaySPITType::PlaySPITType(SPITPlayer* p_SPITPlayer, string p_SPITTypeID) {
m_SPITTypeID = p_SPITTypeID;
m_PlayerID = p_SPITPlayer->getID();
m_PlayerName = p_SPITPlayer->getName();
startPlaySequence();
m_IsNew = true;
}
SPITPlayer::PlayObject::PlayObject(const PlayObject& orig) {
m_SPITObjectID = orig.getSPITObjectID();
SPITPlayer::PlaySPITType::PlaySPITType(const PlaySPITType& orig) {
m_SPITTypeID = orig.getSPITTypeID();
m_IsPlayed = orig.getIsPlayed();
m_IsNew = orig.getIsNew();
@@ -158,21 +143,11 @@ SPITPlayer::PlayObject::PlayObject(const PlayObject& orig) {
m_PlayerName = orig.getPlayerName();
m_PlayerRuns = orig.getPlayerIsRunning();
m_Value = orig.getValueFade();
m_ValuePrePosition = getValueFadePrePosition();
m_ValueFactor = orig.getValueFactor();
m_ValueFlag = orig.getValueFlag();
m_FrameInsidePrePosition = orig.getFrameInsidePrePosition();
m_FrameInside = orig.getFrameInside();
m_Value = orig.getValue();
}
void SPITPlayer::PlayObject::startPlaySequence() {
void SPITPlayer::PlaySPITType::startPlaySequence() {
m_IsPlayed = false;
m_IsNew = false;
m_FrameInside = -1;
m_FrameInsidePrePosition = -1;
m_Value = 0;
m_ValuePrePosition = 0;
m_ValueFlag = 0x00;
}
}
+21 -18
View File
@@ -43,23 +43,26 @@ bool SPITSocket::createSocket_UDP() {
} else {
intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_REUSEADDR, (void *)&intOptionValue4, sizeof(intOptionValue4));
}
if (intResult < 0) {
boolSuccess = false;
}
// // set the m_UDPSocketIP4 in NON BLOCKING mode because
// // if the UDPSockets are in blocking mode the receiveMessage does not return in every constellation
// int intFlags;
// intFlags = fcntl(m_UDPSocketIP4, F_GETFL);
// fcntl(m_UDPSocketIP4, F_SETFL, intFlags | O_NONBLOCK);
if (boolSuccess == true) {
struct timeval tv;
tv.tv_sec = 1; // seconds
tv.tv_usec = 0; // microseconds (0.0 sec)
// This sets the receive timeout
setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
struct timeval tv;
tv.tv_sec = 1; // seconds
tv.tv_usec = 0; // microseconds (0.0 sec)
// set the m_UDPSocketIP4 in NON BLOCKING mode because
// if the UDPSockets are in blocking mode the receiveMessage does not return in every constellation
// int intFlags;
// intFlags = fcntl(m_UDPSocketIP4, F_GETFL);
// fcntl(m_UDPSocketIP4, F_SETFL, intFlags | O_NONBLOCK);
// This sets the receive timeout
setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
if (intResult < 0) {
boolSuccess = false;
// int intBufferSize = 2046 * 512;
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_RCVBUF, (void*)&intBufferSize, sizeof(intBufferSize));
// intResult = setsockopt(m_UDPSocketIP4, SOL_SOCKET, SO_SNDBUF, (void*)&intBufferSize, sizeof(intBufferSize));
}
return boolSuccess;
}
@@ -72,7 +75,7 @@ bool SPITSocket::createSocket_UDP() {
* @return -1 id bind fails, o if bind is ok
*
*/
int SPITSocket::bindSocket(string p_ClientIP, string p_ClientPort) {
int SPITSocket::bindSocket(string p_ServerIP, string p_ClientIP, string p_ClientPort) {
addrinfo *clientAI;
struct sockaddr_in *ptrIP4SocketAddress;
struct sockaddr_in o_IP4SocketAddress;
@@ -193,9 +196,9 @@ int SPITSocket::sendMessageTo(int p_InetFamily, string p_ServerIP, string p_Serv
intResult = -1;
}
if (intResult == -1) {
return -1;
}
if (intResult < 0) {
return -1;
}
return 0;
}
/**
+42 -9
View File
@@ -200,6 +200,30 @@ static const char * TAG = "SPIT";
}
}
void SPITType::eventProjectClosed() {
SPITType* ptrSPITType;
for (auto i = s_SPITTypes.begin(); i != s_SPITTypes.end(); i++) {
ptrSPITType = i->second;
if (ptrSPITType->getCreatedByClient() == true) {
continue;
}
i = s_SPITTypes.erase(i);
delete ptrSPITType;
if (i == s_SPITTypes.end()) {
break;
}
}
//Remote
for (auto i = s_SPITTypesRemote.begin(); i != s_SPITTypesRemote.end(); i++) {
ptrSPITType = i->second;
i = s_SPITTypesRemote.erase(i);
delete ptrSPITType;
if (i == s_SPITTypesRemote.end()) {
break;
}
}
}
/**
* Sets confirmed = false for all SPITTypes.<br>
* This should be called when the client has loaded a project.<br>
@@ -349,6 +373,7 @@ void SPITType::setCreatedByClient(bool p_CreatedByClient) {
*/
bool SPITType::setMessageOP(SPIT_Message::ReportSPITType* p_ReportSPITType) {
bool boolChangeAllowed;
bool boolChanged = false;
if (m_CreatedByClient == true && m_Fixed == true) {
boolChangeAllowed = false;
@@ -367,38 +392,46 @@ void SPITType::setCreatedByClient(bool p_CreatedByClient) {
m_Confirmed = p_ReportSPITType->getConfirmed();
}
if (m_DefaultDelay != p_ReportSPITType->getDelay()) {
if (boolChangeAllowed == false) return false;
if (boolChangeAllowed == false) throw new exception();
m_DefaultDelay = p_ReportSPITType->getDelay();
boolChanged = true;
}
if (m_DefaultDuration != p_ReportSPITType->getDuration()) {
if (boolChangeAllowed == false) return false;
if (boolChangeAllowed == false) throw new exception();
m_DefaultDuration = p_ReportSPITType->getDuration();
boolChanged = true;
}
if (m_Fixed != p_ReportSPITType->getFixed()) {
if (boolChangeAllowed == false) return false;
if (boolChangeAllowed == false) throw new exception();
m_Fixed = p_ReportSPITType->getFixed();
boolChanged = true;
}
if (m_GroupName != p_ReportSPITType->getGroupName()) {
if (boolChangeAllowed == false) return false;
if (boolChangeAllowed == false) throw new exception();
m_GroupName = p_ReportSPITType->getGroupName();
boolChanged = true;
}
if (m_ID != p_ReportSPITType->getID()) {
if (boolChangeAllowed == false) return false;
if (boolChangeAllowed == false) throw new exception();
m_ID = p_ReportSPITType->getID();
boolChanged = true;
}
if (m_Name != p_ReportSPITType->getName()) {
if (boolChangeAllowed == false) return false;
if (boolChangeAllowed == false) throw new exception();
m_Name = p_ReportSPITType->getName();
boolChanged = true;
}
if (m_ServerProjectIndepended != p_ReportSPITType->getServerProjectIndepended()) {
if (boolChangeAllowed == false) return false;
if (boolChangeAllowed == false) throw new exception();
m_ServerProjectIndepended = p_ReportSPITType->getServerProjectIndepended();
boolChanged = true;
}
if (m_ServerRemote != p_ReportSPITType->getServerRemote()) {
if (boolChangeAllowed == false) return false;
if (boolChangeAllowed == false) throw new exception();
m_ServerRemote = p_ReportSPITType->getServerRemote();
boolChanged = true;
}
return true;
return boolChanged;
}
void SPITType::fillMessageOP(SPIT_Message::ReportSPITType* ptrSMReportSPITType) {
+477 -132
View File
@@ -42,37 +42,10 @@ SPIT_Client::~SPIT_Client() {
}
/** The ID of the client. Every client instance should set an unique id.*/
string SPIT_Client::getID() { return m_ID; }
/** The name of the client's host computer*/
string SPIT_Client::getComputerName() { return m_ComputerName; }
/**
* Sets the name of the client. This should be done by the user app.
* @param p_Name the anme of the user's app
*/
/** The name of the client, as set by the user's app*/
string SPIT_Client::getName() { return m_Name; }
//connected Server Infos
/**If a connection is established. THis returns the SPITServer's ID*/
string SPIT_Client::getServerID() { return m_ServerID; }
/**If a connection is established. THis returns the SPITServer's computer/host name*/
string SPIT_Client::getServerComputerName() { return m_ServerComputerName; }
/**If a connection is established. THis returns the SPITServer's name*/
string SPIT_Client::getServerName() { return m_ServerName; }
/** Expected Refreah Rate of the connectd SPITServer.<br>
* When the server plays objects, it will do so at discrete time steps.<br>
* Play events will take place in these time steps..
*/
int SPIT_Client::getServerStepTime() { return m_ServerStepTime; }
void SPIT_Client::clientProjectClose() {
if (m_ConnectionStatus == CONNECTION_OK) {
ESP_LOGI(TAG, " ... tidy up ressources");
SPIT_Message::CloseSPITProject sMCloseSPITProject;
fillHeader(sMCloseSPITProject.getHeader());
sMCloseSPITProject.setProjectID(m_ProjName);
if (sendSPITMessage(sMCloseSPITProject) < 0) {
ESP_LOGD(TAG, "SPIT_Client could not send Client's ReportSPITProject");
@@ -88,7 +61,6 @@ void SPIT_Client::clientProjectLoaded() {
if (m_ConnectionStatus == CONNECTION_OK) {
//send ReportSPITProject to the server
SPIT_Message::ReportSPITProject sMReportSPITProject;
fillHeader(sMReportSPITProject.getHeader());
sMReportSPITProject.setProjectID(m_ProjName);
sMReportSPITProject.setProjectName(m_ProjName);
sMReportSPITProject.setFramesPerSecond(0);
@@ -98,7 +70,6 @@ void SPIT_Client::clientProjectLoaded() {
//send RequestProjectTransfer
SPIT_Message::RequestProjectTransfer sMRequestProjectTransfer;
fillHeader(sMRequestProjectTransfer.getHeader());
if (sendSPITMessage(sMRequestProjectTransfer) < 0) {
ESP_LOGD(TAG, "SPIT_CLient::clientProjectLoaded could not send RequestProjectTransfer");
}
@@ -125,7 +96,7 @@ void SPIT_Client::setActionSPITType(string p_SPITTypeID, bool p_ActionAssigned)
for (int i = 0; i < SPITObject::getSPITObjectCount(); i++) {
ptrSPITObject = SPITObject::getSPITObject(i);
if (ptrSPITObject == NULL) break;
if (ptrSPITObject == NULL) continue;
if (ptrSPITObject->getSPITTypeID() == ptrSPITType->getID()) {
if (ptrSPITObject->setActionAssignedType(p_ActionAssigned) == true) {
sendSPITObjectInternal(ptrSPITObject);
@@ -165,7 +136,7 @@ void SPIT_Client::startServerAutoDetect() {
SAD_DetectedServer::clearDetectedServers();
if (!sThread) {
sThread = new fos::TaskT<SPIT_Client &>(SPIT_Client::processSocketTask, *this, "spitSock");
sThread = new fos::TaskT<SPIT_Client &>(SPIT_Client::processSocketTask, *this, "spitSock", fos::Task::DefaultStackSize*2 );
}
abortSearch = false;
sStartSad.give();
@@ -193,10 +164,10 @@ void SPIT_Client::stopServerAutoDetect() {
* @param p_Addition sometimes server may have additional informations
* @param p_IsIP4 the server ip is a ip4 address
*/
void SPIT_Client::eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4) {
void SPIT_Client::eventServerDetected(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4) {
try {
SAD_DetectedServer o_RefDetectedServer = SAD_DetectedServer::getRefDetectedServer(p_ID);
mCallbacks.onServerDetect(o_RefDetectedServer);
mCallbacks.onServerEvent(ServerEvent::Detect, o_RefDetectedServer);
// If a connection has been established and the connection is lost -> reconnect
if (_doReconnect) {
@@ -235,10 +206,21 @@ void SPIT_Client::eventServerDetected(string p_ID, string p_Name, string p_Compu
* @param p_Addition sometimes server may have additional informations
* @param p_IsIP4 the server ip is a ip4 address
*/
void SPIT_Client::eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ClientIP, bool p_IsIP4) {
void SPIT_Client::eventServerLost(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4) {
try {
SAD_DetectedServer o_RefDetectedServer = SAD_DetectedServer::getRefDetectedServer(p_ID);
mCallbacks.onServerLost(o_RefDetectedServer);
mCallbacks.onServerEvent(ServerEvent::Lost, o_RefDetectedServer);
}
catch (...) {
return;
}
}
void SPIT_Client::eventServerChanged(string p_ID, string p_Name, string p_ComputerName, string p_IP, string p_Port, string p_Addition, string p_ProjectName, string p_ClientIP, bool p_IsIP4) {
try {
SAD_DetectedServer o_RefDetectedServer = SAD_DetectedServer::getRefDetectedServer(p_ID);
mCallbacks.onServerEvent(ServerEvent::Changed, o_RefDetectedServer);
// tryConnection(p_DetectedServer);
}
catch (...) {
return;
@@ -246,6 +228,56 @@ void SPIT_Client::eventServerLost(string p_ID, string p_Name, string p_ComputerN
}
// void MyApp::tryConnection(const SAD_DetectedServer& p_DetectedServer) {
// //fetch the infoemations from the p_DetectedServer
// bool boolPossibleConnect;
// bool boolSuccess;
// boolPossibleConnect = checkPossibleConnection(p_DetectedServer);
// if (boolPossibleConnect == false) return;
// // --------------------------------------
// // You have three Options to use the detected server
// // OPTION 1 Use the first server found
// // OPTION 2 Use the first server found that fulfills specific conditions
// // OPTION 3 take a copy of the p_DetectedServer and do connection later
// // SAD_DetectedServer o_DetectedServer = p_DetectedServer; //this will call the copy constructor
// // ---------------------------------------
// //Excample use the first detected LOOPBACK server, means the server runs on the same computer as this client
// //if (p_DetectedServer.getIpIsLoopback() == true) { //omit the if condition if you want to use the first server found
// boolSuccess = false;
// //Stop auto detection because a suitable server was found
// stopServerAutoDetect();
// if (m_SPIT_Client != NULL) {
// m_ServerProjectName = p_DetectedServer.getProjectName();
// m_ServerIP = p_DetectedServer.getIP();
// #if defined(DEBUGOUTPUT)
// printf("MySPITApp: connect to %s ", p_DetectedServer.getIP().data());
// #endif
// //Use the m_BoardNumber as login name
// string stringLoginName = "";
// string stringLoginPassword = "";
// boolSuccess = m_SPIT_Client->connect(p_DetectedServer.getIP(), p_DetectedServer.getPort(), p_DetectedServer.getClientIP(), stringLoginName, stringLoginPassword); //ClientPort = "0" meeans use any port
// }
// if (boolSuccess == false) {
// //connection message could not be sent
// //perhaps restart AutoDetection
// startServerAutoDetect();
// }
// else {
// //WAITING FOR CONNECTION ANSWER
// //If the Server is closed in the meantime no answer will return
// //-> connect(..) has started the watchdog
// }
// // } //Excample
// }
void SPIT_Client::fillHeader(SPIT_Message::Header* p_Header) {
if (p_Header == NULL) return;
p_Header->setClientID(m_ID);
@@ -257,6 +289,8 @@ int SPIT_Client::sendSPITMessage(SPIT_Message::OPPart& spitMessageOPPart) {
return -1;
}
fillHeader(spitMessageOPPart.getHeader());
if (m_MessageNumber_Send == 255) m_MessageNumber_Send = 1;
else m_MessageNumber_Send++;
spitMessageOPPart.getHeader()->setMessageNumber(m_MessageNumber_Send);
@@ -312,11 +346,114 @@ void SPIT_Client::receiveSPITMessage(SPIT_Client& rM) {
continue;
}
auto ptrSPIT_Message = make_unique<SPIT_Message>(buffer, intResult);
unsigned int intActualMessageNumber = (int)(ptrSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
rM.parseSPIT_Message(move(ptrSPIT_Message));
// rM.checkParseSPIT_Message(move(ptrSPIT_Message));
}
}
void SPIT_Client::resetMessageNumberReceived() {
SPIT_Message* ptrOvertakingSPIT_Message;
m_MessageNumber_Received = -1;
for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); it++) {
ptrOvertakingSPIT_Message = *it;
delete ptrOvertakingSPIT_Message;
// m_OvertakingSPIT_Messages.erase(it);
}
m_OvertakingSPIT_Messages.clear();
}
void SPIT_Client::checkParseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) {
answerWatchdog();
if (p_SPITMessage == NULL) {
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message Parameter == NULL\n");
return;
}
if (p_SPITMessage->getHeader() == NULL) {
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no Header\n");
return;
}
if (p_SPITMessage->getOPPart() == NULL) {
ESP_LOGD(TAG, "SPIT_Client::parseSPIT_Message no OPPart\n");
return;
}
int intActualMessageNumber;
int intNextMessageNumber;
SPIT_Message* ptrOvertakingSPIT_Message;
intActualMessageNumber = (int)(p_SPITMessage->getHeader()->getMessageNumber() & 0xFF);
if (intActualMessageNumber == 0) {
parseSPIT_Message(std::move(p_SPITMessage));
return;
}
if (m_MessageNumber_Received < 0) {
m_MessageNumber_Received = intActualMessageNumber;
parseSPIT_Message(std::move(p_SPITMessage));
return;
}
intNextMessageNumber = m_MessageNumber_Received +1;
if (intNextMessageNumber > 255 || intNextMessageNumber < 1) intNextMessageNumber = 1;
if (intActualMessageNumber == intNextMessageNumber) {
m_MessageNumber_Received = intActualMessageNumber;
parseSPIT_Message(std::move(p_SPITMessage));
//check overtaking messages
auto it = m_OvertakingSPIT_Messages.begin();
while (m_OvertakingSPIT_Messages.size() > 0) {
intNextMessageNumber = m_MessageNumber_Received +1;
if (intNextMessageNumber > 255 || intNextMessageNumber < 1) intNextMessageNumber = 1;
ptrOvertakingSPIT_Message = *it;
intActualMessageNumber = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
if (intActualMessageNumber == intNextMessageNumber) {
m_MessageNumber_Received = intActualMessageNumber;
// parseSPIT_Message(ptrOvertakingSPIT_Message);
m_OvertakingSPIT_Messages.erase(it);
it = m_OvertakingSPIT_Messages.begin();
}
else {
break;
}
}
}
else {
//p_SPITMessage has overtaken another message
addOvertakingSPIT_Message(p_SPITMessage.get());
}
}
int SPIT_Client::s_MAX_OVERTAKING_SPIT_MESSAGES = 10;
void SPIT_Client::addOvertakingSPIT_Message(SPIT_Message* p_SPIT_Message) {
if (p_SPIT_Message == nullptr) return;
int intMessageNumber;
SPIT_Message* ptrOvertakingSPIT_Message;
int intOvertakingMessageNumber;
if (m_OvertakingSPIT_Messages.size() > s_MAX_OVERTAKING_SPIT_MESSAGES) {
printf("SPIT_Client receiveing: perhaps message lost !!!!!");
}
intMessageNumber = (int)(p_SPIT_Message->getHeader()->getMessageNumber() & 0xFF);
for (auto it = m_OvertakingSPIT_Messages.begin(); it != m_OvertakingSPIT_Messages.end(); it++) {
ptrOvertakingSPIT_Message = *it;
intOvertakingMessageNumber = (int)(ptrOvertakingSPIT_Message->getHeader()->getMessageNumber() & 0xFF);
if (intMessageNumber < intOvertakingMessageNumber) {
m_OvertakingSPIT_Messages.insert(it, p_SPIT_Message);
return;
}
}
m_OvertakingSPIT_Messages.push_back(p_SPIT_Message);
}
void SPIT_Client::parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) {
answerWatchdog();
@@ -431,14 +568,13 @@ bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_Clien
disconnect();
{
mSPITSocket->setConnectionParams(p_ServerIP, p_ServerPort, p_ClientIP, p_ClientPort);
intResult = mSPITSocket->bindSocket(p_ClientIP, p_ClientPort);
intResult = mSPITSocket->bindSocket(p_ServerIP, p_ClientIP, p_ClientPort);
if (intResult < 0) {
m_StopReceiveSPITMessages = true;
return false;
}
}
SPIT_Message::Connect sMConnect;
fillHeader(sMConnect.getHeader());
sMConnect.setClientComputerName(m_ComputerName);
sMConnect.setClientName(m_Name);
sMConnect.setLoginName(p_LoginName);
@@ -455,7 +591,12 @@ bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_Clien
m_StopReceiveSPITMessages = true;
return false;
}
resetMessageNumberReceived();
int intOldConnectionStatus = m_ConnectionStatus;
m_ConnectionStatus = CONNECTION_TRYCONNECTION;
mCallbacks.onConnectionStatus(m_ServerID, m_ServerComputerName, m_ServerName, m_ServerStepTime,
m_ConnectionStatus, intOldConnectionStatus);
//sleep a little to make sure that the reception of the messages is started
fos::Task::delayMs(500);
@@ -485,7 +626,6 @@ void SPIT_Client::disconnectInternal(int p_Cause) {
case CONNECTION_NONE:
{
SPIT_Message::Disconnect sMDisconnect;
fillHeader(sMDisconnect.getHeader());
intResult = sendSPITMessage(sMDisconnect);
if (intResult < 0) {
}
@@ -495,7 +635,9 @@ void SPIT_Client::disconnectInternal(int p_Cause) {
break;
}
stopReceiveSPITMessages();
mCallbacks.onConnectionStatus(m_ServerID, m_ServerComputerName, m_ServerName, m_ServerStepTime,
m_ConnectionStatus, intOldConnectionStatus);
if (intOldConnectionStatus != CONNECTION_NONE && intOldConnectionStatus != CONNECTION_NONESERVER) {
ESP_LOGI(TAG, "eventConnectionStatus %d ", m_ConnectionStatus);
switch (m_ConnectionStatus) {
@@ -577,9 +719,8 @@ void SPIT_Client::parseDisconnect(SPIT_Message::Disconnect* p_Disconnect) {
void SPIT_Client::parseWatchdog(SPIT_Message::Watchdog* p_Watchdog) {
// printf("parse Watchdog \n");
SPIT_Message::WatchdogAnswer o_WatchdogAnswer;
fillHeader(o_WatchdogAnswer.getHeader());
int intResult;
intResult = sendSPITMessage(o_WatchdogAnswer);
;
int intResult = sendSPITMessage(o_WatchdogAnswer);
if (intResult < 0) {
}
}
@@ -595,19 +736,24 @@ void SPIT_Client::parseWatchdogAnswer(SPIT_Message::WatchdogAnswer* p_WatchdogAn
void SPIT_Client::sendWatchdog() {
int intResult;
SPIT_Message::Watchdog sMWatchdog;
fillHeader(sMWatchdog.getHeader());
intResult = sendSPITMessage(sMWatchdog);
if (intResult < 0) {
ESP_LOGW("WDT", "Failed to send Watchdog msg");
}
}
void SPIT_Client::eventWatchdogLost() {
disconnectInternal(CONNECTION_LOST);
if (m_ConnectionStatus == CONNECTION_TRYCONNECTION) {
disconnectInternal(CONNECTION_NONESERVER);
}
else {
disconnectInternal(CONNECTION_LOST);
}
}
//----- SPIT Project ------
void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject* p_ReportSPITProject) {
// printf("parse ReportSPITProject \n");
if (p_ReportSPITProject == NULL) return;
m_ServerProjectID = p_ReportSPITProject->getProjectID();
m_ServerProjectName = p_ReportSPITProject->getProjectName();
m_ServerFramesPerSecond = p_ReportSPITProject->getFramesPerSecond();
@@ -620,24 +766,24 @@ void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject* p_Repo
//Send RequestProjectTransfer
SPIT_Message::RequestProjectTransfer sMRequestProjectTransfer;
fillHeader(sMRequestProjectTransfer.getHeader());
if (sendSPITMessage(sMRequestProjectTransfer) < 0) {
printf("SPIT_Client::parseReportSPITProject could not send RequestProjectTransfer\n");
}
// todo Don't send the ReportSPITProject here it should be sended after parseEndProjectTransfer
//Send client's ReportSPITProject
SPIT_Message::ReportSPITProject sMReportSPITProject;
fillHeader(sMReportSPITProject.getHeader());
sMReportSPITProject.setProjectID(m_ProjName);
sMReportSPITProject.setProjectName(m_ProjName);
sMReportSPITProject.setFramesPerSecond(0);
if (sendSPITMessage(sMReportSPITProject) < 0) {
printf("SPIT_Client::parseReportSPITProject could not send Client's ReportSPITProject");
}
}
void SPIT_Client::parseCloseSPITProject(SPIT_Message::CloseSPITProject* p_CloseSPITProject) {
// printf("parse CloseSPITProject \n");
if (p_CloseSPITProject == NULL) return;
string stringProjectID;
mCallbacks.onProjectClosed(p_CloseSPITProject->getProjectID());
}
@@ -648,24 +794,19 @@ int SPIT_Client::getServerFramesPerSecond() { return m_ServerFramesPerSecond; }
void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer* p_RequestProjectTransfer) {
// printf("parse RequestProjectTransfer \n");
int intResult;
int intCount;
SPITType* ptrSPITType;
SPITObject* ptrSPITObject;
//StartProjectTransfer
SPIT_Message::StartProjectTransfer sMStartProjectTransfer;
fillHeader(sMStartProjectTransfer.getHeader());
intResult = sendSPITMessage(sMStartProjectTransfer);
int intResult = sendSPITMessage(sMStartProjectTransfer);
if (intResult < 0) {
return;
}
{
//send all listes SPITTypes
intCount = SPITType::getSPITTypeCount();
int intCount = SPITType::getSPITTypeCount();
for (int i = 0; i < intCount; i++) {
ptrSPITType = SPITType::getSPITType(i);
SPITType* ptrSPITType = SPITType::getSPITType(i);
if (ptrSPITType == NULL) break;
sendSPITTypeInternal(ptrSPITType);
fos::Task::delayMs(10);
@@ -673,9 +814,9 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf
}
{
intCount = SPITObject::getSPITObjectCount();
int intCount = SPITObject::getSPITObjectCount();
for (int i = 0; i < intCount; i++) {
ptrSPITObject = SPITObject::getSPITObject(i);
SPITObject* ptrSPITObject = SPITObject::getSPITObject(i);
if (ptrSPITObject == NULL) break;
sendSPITObjectInternal(ptrSPITObject);
fos::Task::delayMs(10);
@@ -688,13 +829,151 @@ void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransf
intResult = sendSPITMessage(sMEndProjectTransfer);
if (intResult < 0) {
}
}
/* NEW IMPLEMENTATION
void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer* p_RequestProjectTransfer) {
// printf("parse RequestProjectTransfer \n");
thread* o_ThreadSend;
o_ThreadSend = new thread(&this->sendProject, this);
// int intResult;
// SPIT_Message::StartProjectTransfer* ptrSMStartProjectTransfer;
// SPIT_Message::EndProjectTransfer* ptrSMEndProjectTransfer;
// int intCount;
// SPITType* ptrSPITType;
// SPITObject* ptrSPITObject;
// //StartProjectTransfer
// NotifyStartProjectTransfer_Client* o_RunnableStart = new NotifyStartProjectTransfer_Client(m_SPITClientInterface);
// SPIT_Handler::addRunnable(o_RunnableStart);
// ptrSMStartProjectTransfer = new SPIT_Message::StartProjectTransfer();
// intResult = sendSPITMessage(ptrSMStartProjectTransfer);
// if (intResult < 0) {
// return;
// }
// m_Watchdog->answerWatchdog();
// {
// //send all listes SPITTypes
// unique_lock<recursive_mutex> o_LockType(*SPITType::getMutex());
// intCount = SPITType::getSPITTypeCount();
// for (int i = 0; i < intCount; i++) {
// ptrSPITType = SPITType::getSPITType(i);
// if (ptrSPITType == NULL) continue;
// intResult = sendSPITTypeInternal(ptrSPITType);
// if (intResult < 0) return;
// m_Watchdog->answerWatchdog();
// this_thread::sleep_for(chrono::milliseconds(7));
// }
// }
// {
// unique_lock<recursive_mutex> o_LockObject(*SPITObject::getMutex());
// intCount = SPITObject::getSPITObjectCount();
// for (int i = 0; i < intCount; i++) {
// ptrSPITObject = SPITObject::getSPITObject(i);
// if (ptrSPITObject == NULL) continue;
// intResult = sendSPITObjectInternal(ptrSPITObject);
// if (intResult < 0) return;
// m_Watchdog->answerWatchdog();
// this_thread::sleep_for(chrono::milliseconds(7));
// }
// }
// //EndProjectTransfer
// ptrSMEndProjectTransfer = new SPIT_Message::EndProjectTransfer();
// intResult = sendSPITMessage(ptrSMEndProjectTransfer);
// if (intResult < 0) {
// return;
// }
// m_Watchdog->answerWatchdog();
// NotifyEndProjectTransfer_Client* o_RunnableEnd = new NotifyEndProjectTransfer_Client(m_SPITClientInterface);
// SPIT_Handler::addRunnable(o_RunnableEnd);
// //Send act
}
*/
void SPIT_Client::sendProject(SPIT_Client* p_PtrSPIT_Client) {
// int intResult;
// SPIT_Message::StartProjectTransfer* ptrSMStartProjectTransfer;
// SPIT_Message::EndProjectTransfer* ptrSMEndProjectTransfer;
// int intCount;
// SPITType* ptrSPITType;
// SPITObject* ptrSPITObject;
// //StartProjectTransfer
// NotifyStartProjectTransfer_Client* o_RunnableStart = new NotifyStartProjectTransfer_Client(p_PtrSPIT_Client->getSPITClientInterface());
// SPIT_Handler::addRunnable(o_RunnableStart);
// ptrSMStartProjectTransfer = new SPIT_Message::StartProjectTransfer();
// intResult = p_PtrSPIT_Client->sendSPITMessage(ptrSMStartProjectTransfer);
// if (intResult < 0) {
// return;
// }
// // m_Watchdog->answerWatchdog();
// // {
// //send all listes SPITTypes
// // unique_lock<recursive_mutex> o_LockType(*SPITType::getMutex());
// intCount = SPITType::getSPITTypeCount();
// for (int i = 0; i < intCount; i++) {
// ptrSPITType = SPITType::getSPITType(i);
// if (ptrSPITType == NULL) continue;
// if (ptrSPITType->getCreatedByClient() == false) continue;
// intResult = p_PtrSPIT_Client->sendSPITTypeInternal(ptrSPITType);
// if (intResult < 0) return;
// // m_Watchdog->answerWatchdog();
// this_thread::sleep_for(chrono::milliseconds(7));
// }
// // }
// // {
// // unique_lock<recursive_mutex> o_LockObject(*SPITObject::getMutex());
// intCount = SPITObject::getSPITObjectCount();
// for (int i = 0; i < intCount; i++) {
// ptrSPITObject = SPITObject::getSPITObject(i);
// if (ptrSPITObject == NULL) continue;
// if (ptrSPITObject->getCreatedByClient() == false) continue;
// intResult = p_PtrSPIT_Client->sendSPITObjectInternal(ptrSPITObject);
// if (intResult < 0) return;
// // m_Watchdog->answerWatchdog();
// this_thread::sleep_for(chrono::milliseconds(7));
// }
// // }
// //EndProjectTransfer
// ptrSMEndProjectTransfer = new SPIT_Message::EndProjectTransfer();
// intResult = p_PtrSPIT_Client->sendSPITMessage(ptrSMEndProjectTransfer);
// if (intResult < 0) {
// return;
// }
// // m_Watchdog->answerWatchdog();
// NotifyEndProjectTransfer_Client* o_RunnableEnd = new NotifyEndProjectTransfer_Client(p_PtrSPIT_Client->getSPITClientInterface());
// SPIT_Handler::addRunnable(o_RunnableEnd);
// //Send act
}
void SPIT_Client::parseStartProjectTransfer(SPIT_Message::StartProjectTransfer* p_StartProjectTransfer) {
mCallbacks.onStartProjectTransfer();
}
void SPIT_Client::parseEndProjectTransfer(SPIT_Message::EndProjectTransfer* p_EndProjectTransfer) {
SPITObject::clearUnconfirmedSPITObjects();
mCallbacks.onEndProjectTransfer();
//Send SPIT_Message::ReportSPITProject after the m_SPITClientInterface is notfied of EndProjectTransfer
SPIT_Message::ReportSPITProject ptrSMReportSPITProject;
ptrSMReportSPITProject.setProjectID(m_ProjName);
ptrSMReportSPITProject.setProjectName(m_ProjName);
ptrSMReportSPITProject.setFramesPerSecond(0);
if (sendSPITMessage(ptrSMReportSPITProject) < 0) {
printf("SPIT_Client::parseReportSPITProject could not send Client's ReportSPITProject");
}
}
//----- SPIT Types ------
@@ -703,11 +982,15 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType* p_ReportSPIT
if (p_ReportSPITType == NULL) return;
SPITType* ptrSPITType;
bool boolNew = false;
bool boolChanged = false;
{
if (p_ReportSPITType->getServerRemote() == false) {
ptrSPITType = SPITType::getSPITType(p_ReportSPITType->getID());
if (ptrSPITType == NULL) {
//The user's app my veto the SPITType
if (mCallbacks.onCheckSpitTypeVeto(p_ReportSPITType) == false) {
return;
}
ptrSPITType = new SPITType();
boolNew = true;
}
@@ -719,7 +1002,10 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType* p_ReportSPIT
boolNew = true;
}
}
if (ptrSPITType->setMessageOP(p_ReportSPITType) == false) {
try {
boolChanged = ptrSPITType->setMessageOP(p_ReportSPITType);
}
catch (...) {
//SPITType is not changable -> send back to the server
sendSPITTypeInternal(ptrSPITType);
return;
@@ -736,7 +1022,7 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType* p_ReportSPIT
}
if (ptrSPITType != NULL) {
if (ptrSPITType->setConfirmed(true) == true) {
if (ptrSPITType->setConfirmed(true) == true || boolChanged == true) {
sendSPITTypeInternal(ptrSPITType);
}
}
@@ -796,7 +1082,6 @@ int SPIT_Client::sendSPITTypeInternal(SPITType* p_SPITType) {
if (p_SPITType == NULL) return -1;
SPIT_Message::ReportSPITType ptrSMReportSPITType;
p_SPITType->fillMessageOP(&ptrSMReportSPITType);
fillHeader(ptrSMReportSPITType.getHeader());
return sendSPITMessage(ptrSMReportSPITType);
}
@@ -841,7 +1126,6 @@ int SPIT_Client::removeSPITType(string p_SPITTypeID) {
if (ptrSPITType == NULL) return -1;
SPIT_Message::RemoveSPITType sMRemoveSPITType;
ptrSPITType->fillMessageOP(&sMRemoveSPITType);
fillHeader(sMRemoveSPITType.getHeader());
mCallbacks.onSpitTypeRemoved(*ptrSPITType);
SPITType::removeSPITType(ptrSPITType);
delete ptrSPITType;
@@ -891,29 +1175,67 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject* p_Report
SPITType* ptrSPITType;
bool boolNew = false;
bool boolRemote = false;
bool boolChanged = false;
{
if (p_ReportSPITObject->getServerRemote() == false) {
boolRemote = false;
ptrSPITObject = SPITObject::getSPITObject(p_ReportSPITObject->getID());
ptrSPITType = SPITType::getSPITType(p_ReportSPITObject->getSPITTypeID());
if (ptrSPITType == NULL) {
//No associated SPITType found
if (ptrSPITObject != NULL) {
//SpitObject exists but has no corresponding SPITType -> remove the SPITObject without sending a message
//Maybe the SPITObject has changed the SPITTypeID to a SPITTypeID of another board
SPITObject::removeSPITObject(ptrSPITObject);
delete ptrSPITObject;
}
return;
}
if (ptrSPITObject == NULL) {
//The user's app my veto the SPITType
if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) {
return;
}
ptrSPITObject = new SPITObject();
boolNew = true;
}
else {
//The user's app my veto the SPITType
if (mCallbacks.onCheckSpitObjectVeto(p_ReportSPITObject) == false) {
//SpitObject exists and User APp denied the SPITObject -> remove the SPITObject without sending a message
SPITObject::removeSPITObject(ptrSPITObject);
delete ptrSPITObject;
return;
}
}
}
else {
boolRemote = true;
ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportSPITObject->getID());
ptrSPITType = SPITType::getSPITTypeRemote(p_ReportSPITObject->getSPITTypeID());
if (ptrSPITType == NULL) {
//No associated SPITType found
return;
}
if (ptrSPITObject == NULL) {
ptrSPITObject = new SPITObject();
boolNew = true;
}
}
if (ptrSPITType == NULL) {
//No associated SPITType found
try {
boolChanged = ptrSPITObject->setMessageOP(p_ReportSPITObject);
}
catch (...) {
//setMessageOP error - the SPITObject can't be changed, it may be fixed and crated by this client
sendSPITObjectInternal(ptrSPITObject);
return;
}
if (ptrSPITObject == NULL) {
ptrSPITObject = new SPITObject();
boolNew = true;
}
ptrSPITObject->setMessageOP(p_ReportSPITObject);
if (boolRemote == false) {
//set the virtual action assignment
ptrSPITObject->setActionAssignedType(ptrSPITType->getActionAssigned());
@@ -930,7 +1252,7 @@ void SPIT_Client::parseReportSPITObject(SPIT_Message::ReportSPITObject* p_Report
mCallbacks.onSpitObject(boolNew, *ptrSPITType, *ptrSPITObject);
}
if (ptrSPITObject->setConfirmed(true) == true) {
if (ptrSPITObject->setConfirmed(true) == true || boolChanged == true) {
//Confirmation has changed
sendSPITObjectInternal(ptrSPITObject);
}
@@ -976,7 +1298,6 @@ int SPIT_Client::sendSPITObjectInternal(SPITObject* ptrSPITObject) {
if (ptrSPITObject == NULL) return -1;
SPIT_Message::ReportSPITObject ptrSMReportSPITObject;
ptrSPITObject->fillMessageOP(&ptrSMReportSPITObject);
fillHeader(ptrSMReportSPITObject.getHeader());
return sendSPITMessage(ptrSMReportSPITObject);
}
@@ -1041,7 +1362,6 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) {
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
if (ptrSPITType == NULL) return -1;
ptrSPITObject->fillMessageOP(&sMRemoveSPITObject);
fillHeader(sMRemoveSPITObject.getHeader());
mCallbacks.onSpitObjectRemoved(*ptrSPITType, *ptrSPITObject);
SPITObject::removeSPITObject(ptrSPITObject);
delete ptrSPITObject;
@@ -1071,30 +1391,24 @@ void SPIT_Client::parsePlaySPITStart(SPIT_Message::PlaySPITStart* p_PlaySPITStar
void SPIT_Client::parsePlaySPITObject(SPIT_Message::PlaySPITObject* p_PlaySPITObject) {
// printf("parse RPlaySPITObject Object:%s\n", p_PlaySPITObject->getSPITObjectID());
SPITPlayer* ptrSPITPlayer;
SPITPlayer::PlayObject* ptrPlayObject;
SPITPlayer::PlaySPITType* ptrPlaySPITType;
SPITObject* ptrSPITObject;
{
ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITObject->getPlayerID());
if (ptrSPITPlayer == NULL) return;
ptrPlayObject = ptrSPITPlayer->addSPITObject_Playing(p_PlaySPITObject->getSPITObjectID());
//Fetch infoemations from SPITObject
{
ptrSPITObject = SPITObject::getSPITObject(p_PlaySPITObject->getSPITObjectID());
if (ptrSPITObject == NULL) {
return;
}
if (ptrPlayObject == NULL) {
return;
}
ptrPlayObject->setPlayerIsRunning(ptrSPITPlayer->getIsRunning());
ptrPlayObject->setFrameInside(p_PlaySPITObject->getFrameInsideObject(), p_PlaySPITObject->getPlayPrePosition());
ptrPlayObject->setValue(p_PlaySPITObject->getValue(), p_PlaySPITObject->getPlayPrePosition());
ptrPlayObject->setValueFactor(ptrSPITObject->getValueFactor());
ptrPlayObject->setValueFlag(p_PlaySPITObject->getValueFlag());
ptrSPITObject = SPITObject::getSPITObject(p_PlaySPITObject->getSPITObjectID());
if (ptrSPITObject == NULL) {
return;
}
ptrPlaySPITType = ptrSPITPlayer->addSPITType_Playing(ptrSPITObject->getSPITTypeID());
if (ptrPlaySPITType == NULL) {
return;
}
ptrPlaySPITType->setPlayerIsRunning(ptrSPITPlayer->getIsRunning());
ptrPlaySPITType->addValue(((double)p_PlaySPITObject->getValue()/1000000), ((double)ptrSPITObject->getValueFactor()/1000000));
}
}
@@ -1102,44 +1416,69 @@ void SPIT_Client::parsePlaySPITEnd(SPIT_Message::PlaySPITEnd* p_PlaySPITEnd) {
// printf("parse PlaySPITEnd \n");
SPITPlayer* ptrSPITPlayer;
SPITType* ptrSPITType = NULL;
SPITObject* ptrSPITObject = NULL;
{
ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
if (ptrSPITPlayer == NULL) return;
// {
// ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
// if (ptrSPITPlayer == NULL) return;
unordered_map<string, SPITPlayer::PlayObject*>* ptrPlayObjects;
SPITPlayer::PlayObject* ptrPlayObject;
bool boolStarted;
bool boolStopped;
// unordered_map<string, SPITPlayer::PlayObject*>* ptrPlayObjects;
// SPITPlayer::PlayObject* ptrPlayObject;
// bool boolStarted;
// bool boolStopped;
ptrPlayObjects = ptrSPITPlayer->getPlayObjects();
for (auto i = ptrPlayObjects->begin(); i != ptrPlayObjects->end(); i++) {
ptrPlayObject = i->second;
boolStarted = false;
boolStopped = false;
if (ptrPlayObject->getIsNew()) {
boolStarted = true;
}
if (ptrPlayObject->getIsPlayed() == false) {
boolStopped = true;
}
{
ptrSPITObject = SPITObject::getSPITObject(ptrPlayObject->getSPITObjectID());
if (ptrSPITObject == NULL) {
return;
}
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
if (ptrSPITType == NULL) {
return;
}
// ptrPlayObjects = ptrSPITPlayer->getPlayObjects();
// for (auto i = ptrPlayObjects->begin(); i != ptrPlayObjects->end(); i++) {
// ptrPlayObject = i->second;
// boolStarted = false;
// boolStopped = false;
// if (ptrPlayObject->getIsNew()) {
// boolStarted = true;
// }
// if (ptrPlayObject->getIsPlayed() == false) {
// boolStopped = true;
// }
// {
// ptrSPITObject = SPITObject::getSPITObject(ptrPlayObject->getSPITObjectID());
// if (ptrSPITObject == NULL) {
// return;
// }
// ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
// if (ptrSPITType == NULL) {
// return;
// }
mCallbacks.onPlayObject(ptrPlayObject->getPlayerID(), boolStarted, boolStopped, *ptrSPITType, *ptrSPITObject, *ptrPlayObject);
}
// mCallbacks.onPlaySpitType(ptrPlayObject->getPlayerID(), boolStarted, boolStopped, *ptrSPITType, *ptrSPITObject, *ptrPlayObject);
// }
// }
// ptrSPITPlayer->endPlaySequence();
// }
ptrSPITPlayer = SPITPlayer::getSPITPlayer(p_PlaySPITEnd->getPlayerID());
if (ptrSPITPlayer == NULL) return;
unordered_map<string, SPITPlayer::PlaySPITType*>* ptrPlaySPITTypes = ptrSPITPlayer->getPlaySPITTypes();
for (auto i = ptrPlaySPITTypes->begin(); i != ptrPlaySPITTypes->end(); i++) {
SPITPlayer::PlaySPITType* ptrPlaySPITType = i->second;
bool boolStarted = false;
bool boolStopped = false;
if (ptrPlaySPITType->getIsNew()) {
boolStarted = true;
}
if (ptrPlaySPITType->getIsPlayed() == false) {
boolStopped = true;
}
{
ptrSPITType = SPITType::getSPITType(ptrPlaySPITType->getSPITTypeID());
if (ptrSPITType == NULL) {
//set isplayed to false, the ptrPlayObject will be removed by ptrSPITPlayer->endPlaySequence()
ptrPlaySPITType->setIsPlayed(false);
continue;
}
mCallbacks.onPlaySpitType(ptrPlaySPITType->getPlayerID(), ptrPlaySPITType->getSPITTypeID(), ptrPlaySPITType->getPlayerIsRunning(), boolStarted, boolStopped, ptrPlaySPITType->getValue() );
}
ptrSPITPlayer->endPlaySequence();
}
ptrSPITPlayer->endPlaySequence();
}
void SPIT_Client::parseReportPlayStatus(SPIT_Message::ReportPlayStatus* p_ReportPlayStatus) {
@@ -1152,9 +1491,18 @@ void SPIT_Client::parseReportPlayStatus(SPIT_Message::ReportPlayStatus* p_Report
ptrSPITObject = SPITObject::getSPITObjectRemote(p_ReportPlayStatus->getID());
if (ptrSPITObject == NULL) {
return;
ptrSPITObject = SPITObject::getSPITObject(p_ReportPlayStatus->getID());
if (ptrSPITObject == NULL) {
return;
}
}
ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID());
if (ptrSPITObject->getServerRemote() == false) {
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
}
else {
ptrSPITType = SPITType::getSPITTypeRemote(ptrSPITObject->getSPITTypeID());
}
if (ptrSPITType == NULL) {
return;
}
@@ -1185,7 +1533,6 @@ void SPIT_Client::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p
if (ptrRemoteSPITObject == NULL) return;
SPIT_Message::PlaySPITStart playSPITStart;
fillHeader(playSPITStart.getHeader());
playSPITStart.setPlayerID(m_ID);
playSPITStart.setPlayerName(m_ProjName);
playSPITStart.setPlayerIsRunning(false);
@@ -1194,7 +1541,6 @@ void SPIT_Client::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p
sendSPITMessage(playSPITStart);
SPIT_Message::PlaySPITObject playSPITObject;
fillHeader(playSPITObject.getHeader());
playSPITObject.setID(ptrRemoteSPITObject->getID());
playSPITObject.setPlayPrePosition(false);
playSPITObject.setPlayerID(m_ID);
@@ -1203,7 +1549,6 @@ void SPIT_Client::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p
sendSPITMessage(playSPITObject);
SPIT_Message::PlaySPITEnd playSPITEnd;
fillHeader(playSPITEnd.getHeader());
playSPITEnd.setPlayerID(m_ID);
sendSPITMessage(playSPITEnd);
}
@@ -1223,7 +1568,7 @@ static constexpr int WATCHDOGTIME = 3000;
string stringDatagram = SERVERAUTODETECT_PRECODE + SERVERAUTODETECT_SEPERATOR + SERVERAUTODETECT_TASKID;
int intDatagramLength = stringDatagram.length();
string stringPart;
string stringParts[9];
string stringParts[10];
while (true) {
sStartSad.take();
@@ -1266,7 +1611,7 @@ static constexpr int WATCHDOGTIME = 3000;
}
int intIndex = 0;
int intOldPos = 0;
while (intIndex < 8) {
while (intIndex < SAD_DetectedServer::PARAMINDEX_IP) {
int intPos = stringMessage.find(SERVERAUTODETECT_SEPERATOR.data(), intOldPos);
if (intPos == string::npos) {
stringPart = "";
@@ -1277,7 +1622,7 @@ static constexpr int WATCHDOGTIME = 3000;
stringParts[intIndex] = stringPart;
intIndex++;
}
stringParts[8] = stringServerIP;
stringParts[SAD_DetectedServer::PARAMINDEX_IP] = stringServerIP;
SAD_DetectedServer::addDetectedServer(true, stringParts[SAD_DetectedServer::PARAMINDEX_ID], stringParts);
}
fos::Task::delayMs(100);