refactoring spit messages
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user