refactoring spit messages
This commit is contained in:
@@ -169,8 +169,8 @@ class SPITObject {
|
|||||||
bool setDuration(long long p_Duration);
|
bool setDuration(long long p_Duration);
|
||||||
|
|
||||||
bool setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject);
|
bool setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject);
|
||||||
void fillMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject);
|
void fillMessageOP(SPIT_Message::ReportSPITObject &p_ReportSPITObject);
|
||||||
void fillMessageOP(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject);
|
void fillMessageOP(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SPITOBJECT_H */
|
#endif /* SPITOBJECT_H */
|
||||||
|
|||||||
@@ -68,34 +68,34 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
//----- Connection Status -----
|
//----- Connection Status -----
|
||||||
public:
|
public:
|
||||||
/** No Connection established.<br>Either no connect tried or disconnected*/
|
/** No Connection established.<br>Either no connect tried or disconnected*/
|
||||||
static const int CONNECTION_NONE = 0;
|
static constexpr int CONNECTION_NONE = 0;
|
||||||
/** Server has disconnected*/
|
/** Server has disconnected*/
|
||||||
static const int CONNECTION_NONESERVER = 1;
|
static constexpr int CONNECTION_NONESERVER = 1;
|
||||||
/** The connection is lost<br>Either because of a network crash or because the server no longer responds.*/
|
/** The connection is lost<br>Either because of a network crash or because the server no longer responds.*/
|
||||||
static const int CONNECTION_LOST = 2;
|
static constexpr int CONNECTION_LOST = 2;
|
||||||
/** Connection to the serv er is established.*/
|
/** Connection to the serv er is established.*/
|
||||||
static const int CONNECTION_OK = 3;
|
static constexpr int CONNECTION_OK = 3;
|
||||||
/** A connection to the server is tried.*/
|
/** A connection to the server is tried.*/
|
||||||
static const int CONNECTION_TRYCONNECTION = 4;
|
static constexpr int CONNECTION_TRYCONNECTION = 4;
|
||||||
|
|
||||||
//------ PlayerType ------
|
//------ PlayerType ------
|
||||||
public:
|
public:
|
||||||
/** continous main player, time value can be used like a timecode.<br>The time value is the position in server's project.<br>A server should use only one main player.*/
|
/** continous main player, time value can be used like a timecode.<br>The time value is the position in server's project.<br>A server should use only one main player.*/
|
||||||
static const char PLAYERTYPE_MAIN = 0x02;
|
static constexpr char PLAYERTYPE_MAIN = 0x02;
|
||||||
/** continous player. This player plays SPIT objects sometime during the project.*/
|
/** continous player. This player plays SPIT objects sometime during the project.*/
|
||||||
static const char PLAYERTYPE_CONTINOUS = 0x01;
|
static constexpr char PLAYERTYPE_CONTINOUS = 0x01;
|
||||||
/** diescrete player. This player is used to transmit single discrete values.*/
|
/** diescrete player. This player is used to transmit single discrete values.*/
|
||||||
static const char PLAYERTYPE_DISCRETE = 0x00;
|
static constexpr char PLAYERTYPE_DISCRETE = 0x00;
|
||||||
|
|
||||||
//------ Value Flag ------
|
//------ Value Flag ------
|
||||||
//------ used by sendRemoteObject
|
//------ used by sendRemoteObject
|
||||||
public:
|
public:
|
||||||
/**Set the given value directly*/
|
/**Set the given value directly*/
|
||||||
static const char VALUEFLAG_DIRECT = 0x00;
|
static constexpr char VALUEFLAG_DIRECT = 0x00;
|
||||||
/**Increase the existing value by the given value.<br>This is usefull e.g. when instead of a fader a endless wheel is used*/
|
/**Increase the existing value by the given value.<br>This is usefull e.g. when instead of a fader a endless wheel is used*/
|
||||||
static const char VALUEFLAG_INCREASE = 0x01;
|
static constexpr char VALUEFLAG_INCREASE = 0x01;
|
||||||
/**Decrease the existing value by the given value.<br>This is usefull e.g. when instead of a fader a endless wheel is used*/
|
/**Decrease the existing value by the given value.<br>This is usefull e.g. when instead of a fader a endless wheel is used*/
|
||||||
static const char VALUEFLAG_DECREASE = 0x02;
|
static constexpr char VALUEFLAG_DECREASE = 0x02;
|
||||||
|
|
||||||
//----- SPIT_Client -----
|
//----- SPIT_Client -----
|
||||||
public:
|
public:
|
||||||
@@ -182,7 +182,7 @@ class SPIT_Client : I_SAD_Client {
|
|||||||
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by m_ServerID
|
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by m_ServerID
|
||||||
public:
|
public:
|
||||||
void fillHeader(SPIT_Message::Header *p_Header);
|
void fillHeader(SPIT_Message::Header *p_Header);
|
||||||
int sendSPITMessage(SPIT_Message::OPPart &p_SPITMessageOPPart);
|
int sendSPITMessage(unique_ptr<SPIT_Message::OPPart> spitMessageOPPart);
|
||||||
|
|
||||||
//--------------- ServerAutoDetection SAD ---------------
|
//--------------- ServerAutoDetection SAD ---------------
|
||||||
public:
|
public:
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -324,28 +324,28 @@ bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject
|
|||||||
return boolChanged;
|
return boolChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
|
void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject &p_ReportSPITObject) {
|
||||||
p_ReportSPITObject->setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object
|
p_ReportSPITObject.setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object
|
||||||
p_ReportSPITObject->setConfirmed(m_Confirmed);
|
p_ReportSPITObject.setConfirmed(m_Confirmed);
|
||||||
p_ReportSPITObject->setDelay(m_Delay);
|
p_ReportSPITObject.setDelay(m_Delay);
|
||||||
p_ReportSPITObject->setDuration(m_Duration);
|
p_ReportSPITObject.setDuration(m_Duration);
|
||||||
p_ReportSPITObject->setFixed(m_Fixed);
|
p_ReportSPITObject.setFixed(m_Fixed);
|
||||||
p_ReportSPITObject->setFrameFadeInLength(m_FrameFadeInLength);
|
p_ReportSPITObject.setFrameFadeInLength(m_FrameFadeInLength);
|
||||||
p_ReportSPITObject->setFrameFadeOutLength(m_FrameFadeOutLength);
|
p_ReportSPITObject.setFrameFadeOutLength(m_FrameFadeOutLength);
|
||||||
p_ReportSPITObject->setFrameLength(m_FrameLength);
|
p_ReportSPITObject.setFrameLength(m_FrameLength);
|
||||||
p_ReportSPITObject->setFrameStart(m_FrameStart);
|
p_ReportSPITObject.setFrameStart(m_FrameStart);
|
||||||
p_ReportSPITObject->setID(m_ID);
|
p_ReportSPITObject.setID(m_ID);
|
||||||
p_ReportSPITObject->setName(m_Name);
|
p_ReportSPITObject.setName(m_Name);
|
||||||
p_ReportSPITObject->setRemark(m_Remark);
|
p_ReportSPITObject.setRemark(m_Remark);
|
||||||
p_ReportSPITObject->setSPITTypeID(m_SPITTypeID);
|
p_ReportSPITObject.setSPITTypeID(m_SPITTypeID);
|
||||||
p_ReportSPITObject->setServerParams(m_ServerParams);
|
p_ReportSPITObject.setServerParams(m_ServerParams);
|
||||||
p_ReportSPITObject->setServerRemote(m_ServerRemote);
|
p_ReportSPITObject.setServerRemote(m_ServerRemote);
|
||||||
p_ReportSPITObject->setTrack(m_Track);
|
p_ReportSPITObject.setTrack(m_Track);
|
||||||
p_ReportSPITObject->setValueFactor(m_ValueFactor);
|
p_ReportSPITObject.setValueFactor(m_ValueFactor);
|
||||||
p_ReportSPITObject->setValueUse(m_ValueUse);
|
p_ReportSPITObject.setValueUse(m_ValueUse);
|
||||||
}
|
}
|
||||||
void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject) {
|
void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject) {
|
||||||
p_RemoveSPITObject->setID(m_ID);
|
p_RemoveSPITObject.setID(m_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPITObject::setID(const string &id) {
|
void SPITObject::setID(const string &id) {
|
||||||
|
|||||||
@@ -310,18 +310,13 @@ void SPIT_Client::stopReceiveSPITMessages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SPIT_Client::receiveSPITMessage(SPIT_Client &rM) {
|
void SPIT_Client::receiveSPITMessage(SPIT_Client &rM) {
|
||||||
|
char buffer[MAXSPITMESSAGEBYTECOUNT + 1];
|
||||||
char buffer[MAXSPITMESSAGEBYTECOUNT];
|
int rdLen;
|
||||||
int intResult;
|
|
||||||
while (rM.m_StopReceiveSPITMessages == false) {
|
while (rM.m_StopReceiveSPITMessages == false) {
|
||||||
if (rM.m_StopReceiveSPITMessages == true) {
|
rdLen = rM.mSPITSocket->receiveMessage(buffer, MAXSPITMESSAGEBYTECOUNT, nullptr);
|
||||||
return;
|
if (rdLen < 0) {
|
||||||
}
|
|
||||||
intResult = rM.mSPITSocket->receiveMessage(buffer, MAXSPITMESSAGEBYTECOUNT, nullptr);
|
|
||||||
if (intResult < 0) {
|
|
||||||
if (rM.m_StopReceiveSPITMessages) {
|
if (rM.m_StopReceiveSPITMessages) {
|
||||||
return;
|
return;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1496,22 +1491,18 @@ fos::Semaphore SPIT_Client::sStartSad;
|
|||||||
|
|
||||||
void SPIT_Client::processSocketTask(SPIT_Client &instance) {
|
void SPIT_Client::processSocketTask(SPIT_Client &instance) {
|
||||||
ESP_LOGI(TAG, "Starting Socket managing");
|
ESP_LOGI(TAG, "Starting Socket managing");
|
||||||
|
|
||||||
static const string SERVERAUTODETECT_PRECODE = "#SAD#";
|
static const string SERVERAUTODETECT_PRECODE = "#SAD#";
|
||||||
static const string SERVERAUTODETECT_SEPERATOR = "#,#";
|
static const string SERVERAUTODETECT_SEPERATOR = "#,#";
|
||||||
static const string SERVERAUTODETECT_TASKID = "#spit#"; // -> "#SAD##,##spit#"
|
static const string SERVERAUTODETECT_TASKID = "#spit#"; // -> "#SAD##,##spit#"
|
||||||
static const string SERVERAUTODETECT_PORT = "15110";
|
static const string SERVERAUTODETECT_PORT = "15110";
|
||||||
static constexpr int WATCHDOGTIME = 3000;
|
static constexpr int WATCHDOGTIME = 3000;
|
||||||
|
|
||||||
string stringDatagram = SERVERAUTODETECT_PRECODE + SERVERAUTODETECT_SEPERATOR + SERVERAUTODETECT_TASKID;
|
|
||||||
int intDatagramLength = stringDatagram.length();
|
|
||||||
string stringPart;
|
|
||||||
string stringParts[10];
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
sStartSad.take();
|
sStartSad.take();
|
||||||
bool searching = true;
|
bool searching = true;
|
||||||
instance.mSPITSocket->setBroadcast(true);
|
instance.mSPITSocket->setBroadcast(true);
|
||||||
|
string stringDatagram = SERVERAUTODETECT_PRECODE + SERVERAUTODETECT_SEPERATOR + SERVERAUTODETECT_TASKID;
|
||||||
|
int intDatagramLength = stringDatagram.length();
|
||||||
while (searching) {
|
while (searching) {
|
||||||
if (instance.abortSearch)
|
if (instance.abortSearch)
|
||||||
break;
|
break;
|
||||||
@@ -1526,29 +1517,27 @@ void SPIT_Client::processSocketTask(SPIT_Client &instance) {
|
|||||||
|
|
||||||
bool receiving = true;
|
bool receiving = true;
|
||||||
while (receiving) {
|
while (receiving) {
|
||||||
if (instance.abortSearch)
|
if (instance.abortSearch) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
char buffer[512 + 1];
|
constexpr int SIZE = 512;
|
||||||
|
char buffer[SIZE + 1];
|
||||||
string stringServerIP;
|
string stringServerIP;
|
||||||
int intReceivedByteCount = instance.mSPITSocket->receiveMessage(buffer, 512, &stringServerIP);
|
int intReceivedByteCount = instance.mSPITSocket->receiveMessage(buffer, SIZE, &stringServerIP);
|
||||||
if (intReceivedByteCount <= 0) {
|
if (intReceivedByteCount <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add null chararcter
|
|
||||||
if (intReceivedByteCount < 512) {
|
|
||||||
buffer[intReceivedByteCount] = '\0';
|
buffer[intReceivedByteCount] = '\0';
|
||||||
} else {
|
|
||||||
buffer[512] = '\0';
|
|
||||||
}
|
|
||||||
string stringMessage = buffer;
|
string stringMessage = buffer;
|
||||||
// Check if precode is ok
|
// Check if precode is ok
|
||||||
if (stringMessage.find(SERVERAUTODETECT_PRECODE.data(), 0) != 0) {
|
if (stringMessage.find(SERVERAUTODETECT_PRECODE.data(), 0) != 0) {
|
||||||
return;
|
break;
|
||||||
}
|
}
|
||||||
int intIndex = 0;
|
int intIndex = 0;
|
||||||
int intOldPos = 0;
|
int intOldPos = 0;
|
||||||
|
string stringPart;
|
||||||
|
string stringParts[10];
|
||||||
|
|
||||||
while (intIndex < SAD_DetectedServer::PARAMINDEX_IP) {
|
while (intIndex < SAD_DetectedServer::PARAMINDEX_IP) {
|
||||||
int intPos = stringMessage.find(SERVERAUTODETECT_SEPERATOR.data(), intOldPos);
|
int intPos = stringMessage.find(SERVERAUTODETECT_SEPERATOR.data(), intOldPos);
|
||||||
if (intPos == string::npos) {
|
if (intPos == string::npos) {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user