refactoring spit messages

This commit is contained in:
2025-04-05 20:03:21 +02:00
parent 16e7ba13f8
commit a3e487f2f1
6 changed files with 818 additions and 1401 deletions
+2 -2
View File
@@ -169,8 +169,8 @@ class SPITObject {
bool setDuration(long long p_Duration);
bool setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject);
void fillMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject);
void fillMessageOP(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject);
void fillMessageOP(SPIT_Message::ReportSPITObject &p_ReportSPITObject);
void fillMessageOP(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject);
};
#endif /* SPITOBJECT_H */
+12 -12
View File
@@ -68,34 +68,34 @@ class SPIT_Client : I_SAD_Client {
//----- Connection Status -----
public:
/** 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*/
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.*/
static const int CONNECTION_LOST = 2;
static constexpr int CONNECTION_LOST = 2;
/** 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.*/
static const int CONNECTION_TRYCONNECTION = 4;
static constexpr int CONNECTION_TRYCONNECTION = 4;
//------ PlayerType ------
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.*/
static const char PLAYERTYPE_MAIN = 0x02;
static constexpr char PLAYERTYPE_MAIN = 0x02;
/** continous player. This player plays SPIT objects sometime during the project.*/
static const char PLAYERTYPE_CONTINOUS = 0x01;
static constexpr char PLAYERTYPE_CONTINOUS = 0x01;
/** diescrete player. This player is used to transmit single discrete values.*/
static const char PLAYERTYPE_DISCRETE = 0x00;
static constexpr char PLAYERTYPE_DISCRETE = 0x00;
//------ Value Flag ------
//------ used by sendRemoteObject
public:
/**Set the given value directly*/
static const char VALUEFLAG_DIRECT = 0x00;
static constexpr char VALUEFLAG_DIRECT = 0x00;
/**Increase the existing value by the given value.<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*/
static const char VALUEFLAG_DECREASE = 0x02;
static constexpr char VALUEFLAG_DECREASE = 0x02;
//----- SPIT_Client -----
public:
@@ -182,7 +182,7 @@ class SPIT_Client : I_SAD_Client {
bool _doReconnect{}; // true = on eventServerDetected connect to the server identified by m_ServerID
public:
void fillHeader(SPIT_Message::Header *p_Header);
int sendSPITMessage(SPIT_Message::OPPart &p_SPITMessageOPPart);
int sendSPITMessage(unique_ptr<SPIT_Message::OPPart> spitMessageOPPart);
//--------------- ServerAutoDetection SAD ---------------
public:
File diff suppressed because it is too large Load Diff
+21 -21
View File
@@ -324,28 +324,28 @@ bool SPITObject::setMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject
return boolChanged;
}
void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject *p_ReportSPITObject) {
p_ReportSPITObject->setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object
p_ReportSPITObject->setConfirmed(m_Confirmed);
p_ReportSPITObject->setDelay(m_Delay);
p_ReportSPITObject->setDuration(m_Duration);
p_ReportSPITObject->setFixed(m_Fixed);
p_ReportSPITObject->setFrameFadeInLength(m_FrameFadeInLength);
p_ReportSPITObject->setFrameFadeOutLength(m_FrameFadeOutLength);
p_ReportSPITObject->setFrameLength(m_FrameLength);
p_ReportSPITObject->setFrameStart(m_FrameStart);
p_ReportSPITObject->setID(m_ID);
p_ReportSPITObject->setName(m_Name);
p_ReportSPITObject->setRemark(m_Remark);
p_ReportSPITObject->setSPITTypeID(m_SPITTypeID);
p_ReportSPITObject->setServerParams(m_ServerParams);
p_ReportSPITObject->setServerRemote(m_ServerRemote);
p_ReportSPITObject->setTrack(m_Track);
p_ReportSPITObject->setValueFactor(m_ValueFactor);
p_ReportSPITObject->setValueUse(m_ValueUse);
void SPITObject::fillMessageOP(SPIT_Message::ReportSPITObject &p_ReportSPITObject) {
p_ReportSPITObject.setActionAssigned(getActionAssigned()); // Action can be assigned to type or to this object
p_ReportSPITObject.setConfirmed(m_Confirmed);
p_ReportSPITObject.setDelay(m_Delay);
p_ReportSPITObject.setDuration(m_Duration);
p_ReportSPITObject.setFixed(m_Fixed);
p_ReportSPITObject.setFrameFadeInLength(m_FrameFadeInLength);
p_ReportSPITObject.setFrameFadeOutLength(m_FrameFadeOutLength);
p_ReportSPITObject.setFrameLength(m_FrameLength);
p_ReportSPITObject.setFrameStart(m_FrameStart);
p_ReportSPITObject.setID(m_ID);
p_ReportSPITObject.setName(m_Name);
p_ReportSPITObject.setRemark(m_Remark);
p_ReportSPITObject.setSPITTypeID(m_SPITTypeID);
p_ReportSPITObject.setServerParams(m_ServerParams);
p_ReportSPITObject.setServerRemote(m_ServerRemote);
p_ReportSPITObject.setTrack(m_Track);
p_ReportSPITObject.setValueFactor(m_ValueFactor);
p_ReportSPITObject.setValueUse(m_ValueUse);
}
void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject *p_RemoveSPITObject) {
p_RemoveSPITObject->setID(m_ID);
void SPITObject::fillMessageOP(SPIT_Message::RemoveSPITObject &p_RemoveSPITObject) {
p_RemoveSPITObject.setID(m_ID);
}
void SPITObject::setID(const string &id) {
+15 -26
View File
@@ -310,18 +310,13 @@ void SPIT_Client::stopReceiveSPITMessages() {
}
void SPIT_Client::receiveSPITMessage(SPIT_Client &rM) {
char buffer[MAXSPITMESSAGEBYTECOUNT];
int intResult;
char buffer[MAXSPITMESSAGEBYTECOUNT + 1];
int rdLen;
while (rM.m_StopReceiveSPITMessages == false) {
if (rM.m_StopReceiveSPITMessages == true) {
return;
}
intResult = rM.mSPITSocket->receiveMessage(buffer, MAXSPITMESSAGEBYTECOUNT, nullptr);
if (intResult < 0) {
rdLen = rM.mSPITSocket->receiveMessage(buffer, MAXSPITMESSAGEBYTECOUNT, nullptr);
if (rdLen < 0) {
if (rM.m_StopReceiveSPITMessages) {
return;
;
}
continue;
}
@@ -1496,22 +1491,18 @@ fos::Semaphore SPIT_Client::sStartSad;
void SPIT_Client::processSocketTask(SPIT_Client &instance) {
ESP_LOGI(TAG, "Starting Socket managing");
static const string SERVERAUTODETECT_PRECODE = "#SAD#";
static const string SERVERAUTODETECT_SEPERATOR = "#,#";
static const string SERVERAUTODETECT_TASKID = "#spit#"; // -> "#SAD##,##spit#"
static const string SERVERAUTODETECT_PORT = "15110";
static constexpr int WATCHDOGTIME = 3000;
string stringDatagram = SERVERAUTODETECT_PRECODE + SERVERAUTODETECT_SEPERATOR + SERVERAUTODETECT_TASKID;
int intDatagramLength = stringDatagram.length();
string stringPart;
string stringParts[10];
while (true) {
sStartSad.take();
bool searching = true;
instance.mSPITSocket->setBroadcast(true);
string stringDatagram = SERVERAUTODETECT_PRECODE + SERVERAUTODETECT_SEPERATOR + SERVERAUTODETECT_TASKID;
int intDatagramLength = stringDatagram.length();
while (searching) {
if (instance.abortSearch)
break;
@@ -1526,29 +1517,27 @@ void SPIT_Client::processSocketTask(SPIT_Client &instance) {
bool receiving = true;
while (receiving) {
if (instance.abortSearch)
if (instance.abortSearch) {
break;
char buffer[512 + 1];
}
constexpr int SIZE = 512;
char buffer[SIZE + 1];
string stringServerIP;
int intReceivedByteCount = instance.mSPITSocket->receiveMessage(buffer, 512, &stringServerIP);
int intReceivedByteCount = instance.mSPITSocket->receiveMessage(buffer, SIZE, &stringServerIP);
if (intReceivedByteCount <= 0) {
break;
}
// add null chararcter
if (intReceivedByteCount < 512) {
buffer[intReceivedByteCount] = '\0';
} else {
buffer[512] = '\0';
}
string stringMessage = buffer;
// Check if precode is ok
if (stringMessage.find(SERVERAUTODETECT_PRECODE.data(), 0) != 0) {
return;
break;
}
int intIndex = 0;
int intOldPos = 0;
string stringPart;
string stringParts[10];
while (intIndex < SAD_DetectedServer::PARAMINDEX_IP) {
int intPos = stringMessage.find(SERVERAUTODETECT_SEPERATOR.data(), intOldPos);
if (intPos == string::npos) {
File diff suppressed because it is too large Load Diff