fixing issues from refactoring
This commit is contained in:
+135
-168
@@ -43,9 +43,8 @@ SPIT_Client::~SPIT_Client() {
|
||||
void SPIT_Client::clientProjectClose() {
|
||||
if (m_ConnectionStatus == CONNECTION_OK) {
|
||||
ESP_LOGI(TAG, " ... tidy up ressources");
|
||||
SPIT_Message::CloseSPITProject sMCloseSPITProject;
|
||||
sMCloseSPITProject.setProjectID(m_ProjName);
|
||||
if (sendSPITMessage(sMCloseSPITProject) < 0) {
|
||||
auto msg = make_unique<SPIT_Message::CloseSPITProject>(m_ProjName);
|
||||
if (sendSPITMessage(move(msg)) < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_Client could not send Client's ReportSPITProject");
|
||||
}
|
||||
}
|
||||
@@ -58,17 +57,15 @@ void SPIT_Client::clientProjectLoaded() {
|
||||
|
||||
if (m_ConnectionStatus == CONNECTION_OK) {
|
||||
// send ReportSPITProject to the server
|
||||
SPIT_Message::ReportSPITProject sMReportSPITProject;
|
||||
sMReportSPITProject.setProjectID(m_ProjName);
|
||||
sMReportSPITProject.setProjectName(m_ProjName);
|
||||
sMReportSPITProject.setFramesPerSecond(0);
|
||||
if (sendSPITMessage(sMReportSPITProject) < 0) {
|
||||
auto sMReportSPITProject = make_unique<SPIT_Message::ReportSPITProject>(m_ProjName, m_ProjName);
|
||||
sMReportSPITProject->setFramesPerSecond(0);
|
||||
if (sendSPITMessage(move(sMReportSPITProject)) < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_CLient::clientProjectLoaded could not send Client's ReportSPITProject");
|
||||
}
|
||||
|
||||
// send RequestProjectTransfer
|
||||
SPIT_Message::RequestProjectTransfer sMRequestProjectTransfer;
|
||||
if (sendSPITMessage(sMRequestProjectTransfer) < 0) {
|
||||
auto sMRequestProjectTransfer = make_unique<SPIT_Message::RequestProjectTransfer>();
|
||||
if (sendSPITMessage(move(sMRequestProjectTransfer)) < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_CLient::clientProjectLoaded could not send RequestProjectTransfer");
|
||||
}
|
||||
}
|
||||
@@ -83,23 +80,19 @@ void SPIT_Client::clientProjectLoaded() {
|
||||
* @param p_ActionAssigned
|
||||
*/
|
||||
void SPIT_Client::setActionSPITType(string p_SPITTypeID, bool p_ActionAssigned) {
|
||||
SPITType *ptrSPITType;
|
||||
SPITObject *ptrSPITObject;
|
||||
{
|
||||
ptrSPITType = SPITType::getSPITType(p_SPITTypeID);
|
||||
if (ptrSPITType == nullptr)
|
||||
return;
|
||||
if (ptrSPITType->setActionAssigned(p_ActionAssigned) == true) {
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
SPITType *ptrSPITType = SPITType::getSPITType(p_SPITTypeID);
|
||||
if (ptrSPITType == nullptr)
|
||||
return;
|
||||
if (ptrSPITType->setActionAssigned(p_ActionAssigned) == true) {
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
|
||||
for (int i = 0; i < SPITObject::getSPITObjectCount(); i++) {
|
||||
ptrSPITObject = SPITObject::getSPITObject(i);
|
||||
if (ptrSPITObject == nullptr)
|
||||
continue;
|
||||
if (ptrSPITObject->getSPITTypeID() == ptrSPITType->getID()) {
|
||||
if (ptrSPITObject->setActionAssignedType(p_ActionAssigned) == true) {
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
}
|
||||
for (int i = 0; i < SPITObject::getSPITObjectCount(); i++) {
|
||||
SPITObject *ptrSPITObject = SPITObject::getSPITObject(i);
|
||||
if (ptrSPITObject == nullptr)
|
||||
continue;
|
||||
if (ptrSPITObject->getSPITTypeID() == ptrSPITType->getID()) {
|
||||
if (ptrSPITObject->setActionAssignedType(p_ActionAssigned) == true) {
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,8 +161,7 @@ void SPIT_Client::eventServerDetected(SAD_DetectedServer &server) {
|
||||
if (_doReconnect) {
|
||||
if (m_ServerID == server.getID()) {
|
||||
stopServerAutoDetect();
|
||||
ESP_LOGI(TAG, "reconnect to %s", server.getIP().data());
|
||||
// ClientPort = "0" meeans use any port
|
||||
ESP_LOGI(TAG, "reconnect to %s / %s", server.getIP().data(), server.getPort().data());
|
||||
if (connect(server.getIP(), server.getPort(), server.getClientIP(), "0")) {
|
||||
return;
|
||||
}
|
||||
@@ -178,9 +170,9 @@ void SPIT_Client::eventServerDetected(SAD_DetectedServer &server) {
|
||||
|
||||
// Stop auto detection because a suitable server was found
|
||||
stopServerAutoDetect();
|
||||
ESP_LOGI(TAG, "connect to %s", server.getIP().data());
|
||||
ESP_LOGI(TAG, "connect to %s / %s", server.getIP().data(), server.getPort().data());
|
||||
// ClientPort = "0" meeans use any port
|
||||
if (not connect(server.getIP(), server.getPort(), server.getClientIP(), "0")) {
|
||||
if (!connect(server.getIP(), server.getPort(), server.getClientIP(), "0")) {
|
||||
// connection message could not be sent -> better to restart AutoDetection
|
||||
startServerAutoDetect();
|
||||
}
|
||||
@@ -260,37 +252,39 @@ void SPIT_Client::fillHeader(SPIT_Message::Header *p_Header) {
|
||||
p_Header->setServerID(m_ServerID);
|
||||
}
|
||||
|
||||
int SPIT_Client::sendSPITMessage(SPIT_Message::OPPart &spitMessageOPPart) {
|
||||
if (m_StopReceiveSPITMessages == true) {
|
||||
int SPIT_Client::sendSPITMessage(unique_ptr<SPIT_Message::OPPart> spitMessageOPPart) {
|
||||
if (!spitMessageOPPart) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fillHeader(spitMessageOPPart.getHeader());
|
||||
auto &opPart = *spitMessageOPPart.get();
|
||||
fillHeader(opPart.getHeader());
|
||||
|
||||
if (m_MessageNumber_Send == 255)
|
||||
m_MessageNumber_Send = 1;
|
||||
else
|
||||
m_MessageNumber_Send++;
|
||||
spitMessageOPPart.getHeader()->setMessageNumber(m_MessageNumber_Send);
|
||||
|
||||
opPart.getHeader()->setMessageNumber(m_MessageNumber_Send);
|
||||
|
||||
SPIT_Message *ptrSPIT_Message;
|
||||
ptrSPIT_Message = new SPIT_Message(&spitMessageOPPart);
|
||||
const char *ptrMessageBytes = ptrSPIT_Message->getMessageBytes();
|
||||
int intByteCount = ptrSPIT_Message->getMesageByteCount();
|
||||
|
||||
if (ptrMessageBytes == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
int opFlag = 0;
|
||||
try {
|
||||
int intResult = mSPITSocket->sendMessage(ptrMessageBytes, intByteCount);
|
||||
auto spitMessage = make_unique<SPIT_Message>(move(spitMessageOPPart));
|
||||
opFlag = spitMessage->getOPFlag();
|
||||
auto optMessageBytes = spitMessage->getMessageBytes();
|
||||
if (optMessageBytes == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
const auto &messageBytes = *optMessageBytes;
|
||||
int intResult = mSPITSocket->sendMessage(messageBytes.data(), messageBytes.size());
|
||||
if (intResult < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_Client::sendSPITMessage could not send message OPFlage: %d", ptrSPIT_Message->getOPFlag());
|
||||
ESP_LOGD(TAG, "client could not send message OPFlage: %d", opFlag);
|
||||
}
|
||||
return intResult;
|
||||
} catch (...) {
|
||||
ESP_LOGD(TAG, "Exception SPIT_Client::sendSPITMessage OPFlag: %d", ptrSPIT_Message->getOPFlag());
|
||||
return -1;
|
||||
ESP_LOGD(TAG, "Exception client OPFlag: %d", opFlag);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
bool SPIT_Client::startReceiveSPITMessages() {
|
||||
{
|
||||
@@ -302,11 +296,7 @@ bool SPIT_Client::startReceiveSPITMessages() {
|
||||
return true;
|
||||
}
|
||||
void SPIT_Client::stopReceiveSPITMessages() {
|
||||
{
|
||||
if (m_StopReceiveSPITMessages == true)
|
||||
return;
|
||||
m_StopReceiveSPITMessages = true;
|
||||
}
|
||||
}
|
||||
|
||||
void SPIT_Client::receiveSPITMessage(SPIT_Client &rM) {
|
||||
@@ -320,10 +310,10 @@ 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));
|
||||
auto vec = vector<char>(buffer, buffer + rdLen);
|
||||
auto spitMsg = make_unique<SPIT_Message>(vec);
|
||||
rM.parseSPIT_Message(move(spitMsg));
|
||||
// rM.checkParseSPIT_Message(move(spitMsg));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,26 +517,22 @@ void SPIT_Client::parseSPIT_Message(unique_ptr<SPIT_Message> p_SPITMessage) {
|
||||
bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_ClientIP, string p_ClientPort, string p_LoginName, string p_LoginPassword) {
|
||||
int intResult;
|
||||
disconnect();
|
||||
{
|
||||
mSPITSocket->setConnectionParams(p_ServerIP, p_ServerPort, p_ClientIP, p_ClientPort);
|
||||
intResult = mSPITSocket->bindSocket(p_ClientIP, p_ClientPort);
|
||||
if (intResult < 0) {
|
||||
m_StopReceiveSPITMessages = true;
|
||||
return false;
|
||||
}
|
||||
mSPITSocket->setConnectionParams(p_ServerIP, p_ServerPort, p_ClientIP, p_ClientPort);
|
||||
intResult = mSPITSocket->bindSocket(p_ClientIP, p_ClientPort);
|
||||
if (intResult < 0) {
|
||||
m_StopReceiveSPITMessages = true;
|
||||
return false;
|
||||
}
|
||||
SPIT_Message::Connect sMConnect;
|
||||
sMConnect.setClientComputerName(m_ComputerName);
|
||||
sMConnect.setClientName(m_Name);
|
||||
sMConnect.setLoginName(p_LoginName);
|
||||
sMConnect.setLoginPassword(p_LoginPassword);
|
||||
sMConnect.setServerIP(p_ServerIP);
|
||||
auto sMConnect = make_unique<SPIT_Message::Connect>(m_ComputerName, m_Name);
|
||||
sMConnect->setLoginName(p_LoginName);
|
||||
sMConnect->setLoginPassword(p_LoginPassword);
|
||||
sMConnect->setServerIP(p_ServerIP);
|
||||
if (p_ServerPort.length() <= 0) {
|
||||
p_ServerPort = "0";
|
||||
}
|
||||
int intServerPort;
|
||||
intServerPort = stoi(p_ServerPort);
|
||||
sMConnect.setServerPort(intServerPort);
|
||||
sMConnect->setServerPort(intServerPort);
|
||||
|
||||
if (startReceiveSPITMessages() == false) {
|
||||
m_StopReceiveSPITMessages = true;
|
||||
@@ -561,7 +547,7 @@ bool SPIT_Client::connect(string p_ServerIP, string p_ServerPort, string p_Clien
|
||||
|
||||
// sleep a little to make sure that the reception of the messages is started
|
||||
fos::Task::delayMs(500);
|
||||
intResult = sendSPITMessage(sMConnect);
|
||||
intResult = sendSPITMessage(move(sMConnect));
|
||||
if (intResult < 0) {
|
||||
m_ConnectionStatus = CONNECTION_NONE;
|
||||
m_StopReceiveSPITMessages = true;
|
||||
@@ -585,9 +571,10 @@ void SPIT_Client::disconnectInternal(int p_Cause) {
|
||||
case CONNECTION_LOST:
|
||||
break;
|
||||
case CONNECTION_NONE: {
|
||||
SPIT_Message::Disconnect sMDisconnect;
|
||||
intResult = sendSPITMessage(sMDisconnect);
|
||||
auto sMDisconnect = make_unique<SPIT_Message::Disconnect>();
|
||||
intResult = sendSPITMessage(move(sMDisconnect));
|
||||
if (intResult < 0) {
|
||||
// ESP_LOGD(TAG, "Failed to disconnect");
|
||||
}
|
||||
} break;
|
||||
case CONNECTION_NONESERVER:
|
||||
@@ -676,11 +663,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;
|
||||
;
|
||||
int intResult = sendSPITMessage(o_WatchdogAnswer);
|
||||
if (intResult < 0) {
|
||||
}
|
||||
auto o_WatchdogAnswer = make_unique<SPIT_Message::WatchdogAnswer>();
|
||||
sendSPITMessage(move(o_WatchdogAnswer));
|
||||
}
|
||||
/**
|
||||
* The SPIT server sends a watchdog message at regular intervals. The client responds immediately with WatchdogAnswer<br>
|
||||
@@ -694,8 +678,8 @@ void SPIT_Client::parseWatchdogAnswer(SPIT_Message::WatchdogAnswer *p_WatchdogAn
|
||||
}
|
||||
void SPIT_Client::sendWatchdog() {
|
||||
int intResult;
|
||||
SPIT_Message::Watchdog sMWatchdog;
|
||||
intResult = sendSPITMessage(sMWatchdog);
|
||||
auto sMWatchdog = make_unique<SPIT_Message::Watchdog>();
|
||||
intResult = sendSPITMessage(move(sMWatchdog));
|
||||
if (intResult < 0) {
|
||||
ESP_LOGW("WDT", "Failed to send Watchdog msg");
|
||||
}
|
||||
@@ -723,18 +707,16 @@ void SPIT_Client::parseReportSPITProject(SPIT_Message::ReportSPITProject *p_Repo
|
||||
SPITObject::setConfirmedFalse();
|
||||
|
||||
// Send RequestProjectTransfer
|
||||
SPIT_Message::RequestProjectTransfer sMRequestProjectTransfer;
|
||||
if (sendSPITMessage(sMRequestProjectTransfer) < 0) {
|
||||
auto sMRequestProjectTransfer = make_unique<SPIT_Message::RequestProjectTransfer>();
|
||||
if (sendSPITMessage(move(sMRequestProjectTransfer)) < 0) {
|
||||
ESP_LOGD(TAG, "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;
|
||||
sMReportSPITProject.setProjectID(m_ProjName);
|
||||
sMReportSPITProject.setProjectName(m_ProjName);
|
||||
sMReportSPITProject.setFramesPerSecond(0);
|
||||
if (sendSPITMessage(sMReportSPITProject) < 0) {
|
||||
auto sMReportSPITProject = make_unique<SPIT_Message::ReportSPITProject>(m_ProjName, m_ProjName);
|
||||
sMReportSPITProject->setFramesPerSecond(0);
|
||||
if (sendSPITMessage(move(sMReportSPITProject)) < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_Client::parseReportSPITProject could not send Client's ReportSPITProject");
|
||||
}
|
||||
}
|
||||
@@ -753,40 +735,36 @@ int SPIT_Client::getServerFramesPerSecond() { return m_ServerFramesPerSecond; }
|
||||
void SPIT_Client::parseRequestProjectTransfer(SPIT_Message::RequestProjectTransfer *p_RequestProjectTransfer) {
|
||||
// printf("parse RequestProjectTransfer \n");
|
||||
// StartProjectTransfer
|
||||
SPIT_Message::StartProjectTransfer sMStartProjectTransfer;
|
||||
fillHeader(sMStartProjectTransfer.getHeader());
|
||||
int intResult = sendSPITMessage(sMStartProjectTransfer);
|
||||
auto sMStartProjectTransfer = make_unique<SPIT_Message::StartProjectTransfer>();
|
||||
fillHeader(sMStartProjectTransfer->getHeader());
|
||||
int intResult = sendSPITMessage(move(sMStartProjectTransfer));
|
||||
if (intResult < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
// send all listes SPITTypes
|
||||
int intCount = SPITType::getSPITTypeCount();
|
||||
for (int i = 0; i < intCount; i++) {
|
||||
SPITType *ptrSPITType = SPITType::getSPITType(i);
|
||||
if (ptrSPITType == nullptr)
|
||||
break;
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
fos::Task::delayMs(10);
|
||||
}
|
||||
// send all listes SPITTypes
|
||||
int cntT = SPITType::getSPITTypeCount();
|
||||
for (int i = 0; i < cntT; i++) {
|
||||
SPITType *ptrSPITType = SPITType::getSPITType(i);
|
||||
if (ptrSPITType == nullptr)
|
||||
break;
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
fos::Task::delayMs(10);
|
||||
}
|
||||
|
||||
{
|
||||
int intCount = SPITObject::getSPITObjectCount();
|
||||
for (int i = 0; i < intCount; i++) {
|
||||
SPITObject *ptrSPITObject = SPITObject::getSPITObject(i);
|
||||
if (ptrSPITObject == nullptr)
|
||||
break;
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
fos::Task::delayMs(10);
|
||||
}
|
||||
int cntO = SPITObject::getSPITObjectCount();
|
||||
for (int i = 0; i < cntO; i++) {
|
||||
SPITObject *ptrSPITObject = SPITObject::getSPITObject(i);
|
||||
if (ptrSPITObject == nullptr)
|
||||
break;
|
||||
sendSPITObjectInternal(ptrSPITObject);
|
||||
fos::Task::delayMs(10);
|
||||
}
|
||||
|
||||
// EndProjectTransfer
|
||||
SPIT_Message::EndProjectTransfer sMEndProjectTransfer;
|
||||
fillHeader(sMEndProjectTransfer.getHeader());
|
||||
intResult = sendSPITMessage(sMEndProjectTransfer);
|
||||
auto sMEndProjectTransfer = make_unique<SPIT_Message::EndProjectTransfer>();
|
||||
fillHeader(sMEndProjectTransfer->getHeader());
|
||||
intResult = sendSPITMessage(move(sMEndProjectTransfer));
|
||||
if (intResult < 0) {
|
||||
}
|
||||
}
|
||||
@@ -925,11 +903,9 @@ void SPIT_Client::parseEndProjectTransfer(SPIT_Message::EndProjectTransfer *p_En
|
||||
mCallbacks.onProjectUpdate(ProjUpdate::EndTransfer, m_ServerProjectID);
|
||||
|
||||
// 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) {
|
||||
auto sMReportSPITProject = make_unique<SPIT_Message::ReportSPITProject>(m_ProjName, m_ProjName);
|
||||
sMReportSPITProject->setFramesPerSecond(0);
|
||||
if (sendSPITMessage(move(sMReportSPITProject)) < 0) {
|
||||
ESP_LOGD(TAG, "SPIT_Client::parseReportSPITProject could not send Client's ReportSPITProject");
|
||||
}
|
||||
}
|
||||
@@ -962,7 +938,7 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPIT
|
||||
}
|
||||
if (!ptrSPITType->setMessageOP(*p_ReportSPITType)) {
|
||||
// SPITType is not changable -> send back to the server
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -978,7 +954,7 @@ void SPIT_Client::parseReportSPITType(SPIT_Message::ReportSPITType *p_ReportSPIT
|
||||
|
||||
if (ptrSPITType != nullptr) {
|
||||
if (ptrSPITType->setConfirmed(true) == true || boolChanged == true) {
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1009,7 +985,7 @@ void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPIT
|
||||
if (ptrSPITType->getCreatedByClient() && ptrSPITType->getFixed()) {
|
||||
// the SPITyte is created by client himself and it is fixed -> don't remove the SPITType!!
|
||||
// Send the SPITTyp back to the server
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1030,12 +1006,10 @@ void SPIT_Client::parseRemoveSPITType(SPIT_Message::RemoveSPITType *p_RemoveSPIT
|
||||
* @param p_SPITType the pointer to the changed SPITType
|
||||
* @return 0 = is sended, -1 = is not sended
|
||||
*/
|
||||
int SPIT_Client::sendSPITTypeInternal(SPITType *p_SPITType) {
|
||||
if (p_SPITType == nullptr)
|
||||
return -1;
|
||||
SPIT_Message::ReportSPITType ptrSMReportSPITType;
|
||||
p_SPITType->fillMessageOP(ptrSMReportSPITType);
|
||||
return sendSPITMessage(ptrSMReportSPITType);
|
||||
int SPIT_Client::sendSPITTypeInternal(SPITType &p_SPITType) {
|
||||
auto sMReportSPITType = make_unique<SPIT_Message::ReportSPITType>();
|
||||
p_SPITType.fillMessageOP(*sMReportSPITType);
|
||||
return sendSPITMessage(move(sMReportSPITType));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1046,22 +1020,20 @@ int SPIT_Client::sendSPITTypeInternal(SPITType *p_SPITType) {
|
||||
bool SPIT_Client::changeSPITType(SPITType *p_SPITType) {
|
||||
if (p_SPITType == nullptr)
|
||||
return false;
|
||||
SPITType *ptrSPITType;
|
||||
{
|
||||
ptrSPITType = SPITType::getSPITType(p_SPITType->getID());
|
||||
if (ptrSPITType == nullptr)
|
||||
return false;
|
||||
SPITType *ptrSPITType = SPITType::getSPITType(p_SPITType->getID());
|
||||
if (ptrSPITType == nullptr)
|
||||
return false;
|
||||
|
||||
ptrSPITType->setDefaultDelay(p_SPITType->getDefaultDelay());
|
||||
ptrSPITType->setDefaultDuration(p_SPITType->getDefaultDuration());
|
||||
ptrSPITType->setFixed(p_SPITType->getFixed());
|
||||
ptrSPITType->setGroupName(p_SPITType->getGroupName());
|
||||
ptrSPITType->setName(p_SPITType->getName());
|
||||
ptrSPITType->setProjectIndepended(p_SPITType->getProjectIndepended());
|
||||
ptrSPITType->setDefaultDelay(p_SPITType->getDefaultDelay());
|
||||
ptrSPITType->setDefaultDuration(p_SPITType->getDefaultDuration());
|
||||
ptrSPITType->setFixed(p_SPITType->getFixed());
|
||||
ptrSPITType->setGroupName(p_SPITType->getGroupName());
|
||||
ptrSPITType->setName(p_SPITType->getName());
|
||||
ptrSPITType->setProjectIndepended(p_SPITType->getProjectIndepended());
|
||||
|
||||
mCallbacks.onSpitType(ObjectEvent::Changed, *ptrSPITType);
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
|
||||
mCallbacks.onSpitType(ObjectEvent::Changed, *ptrSPITType);
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
@@ -1081,12 +1053,12 @@ int SPIT_Client::removeSPITType(string p_SPITTypeID) {
|
||||
ptrSPITType = SPITType::getSPITType(p_SPITTypeID);
|
||||
if (ptrSPITType == nullptr)
|
||||
return -1;
|
||||
SPIT_Message::RemoveSPITType sMRemoveSPITType;
|
||||
ptrSPITType->fillMessageOP(sMRemoveSPITType);
|
||||
auto sMRemoveSPITType = make_unique<SPIT_Message::RemoveSPITType>();
|
||||
ptrSPITType->fillMessageOP(*sMRemoveSPITType);
|
||||
mCallbacks.onSpitType(ObjectEvent::Deleted, *ptrSPITType);
|
||||
SPITType::removeSPITType(*ptrSPITType);
|
||||
delete ptrSPITType;
|
||||
return sendSPITMessage(sMRemoveSPITType);
|
||||
return sendSPITMessage(move(sMRemoveSPITType));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1096,9 +1068,8 @@ SPITType *SPIT_Client::createSPITTypeFixed(string p_ID, string p_GroupName, stri
|
||||
}
|
||||
|
||||
SPITType *SPIT_Client::createSPITType(string p_ID, string p_GroupName, string p_Name, long long p_DefaultDelay, long long p_DefaultDuration, bool p_FIxed, bool p_ProjectIndepended) {
|
||||
SPITType *ptrSPITType;
|
||||
bool boolNew;
|
||||
ptrSPITType = SPITType::getSPITType(p_ID);
|
||||
SPITType *ptrSPITType = SPITType::getSPITType(p_ID);
|
||||
if (ptrSPITType == nullptr) {
|
||||
ptrSPITType = new SPITType(p_ID, p_GroupName, p_Name, p_FIxed, p_ProjectIndepended, p_DefaultDelay, p_DefaultDuration);
|
||||
ptrSPITType->setCreatedByClient(true);
|
||||
@@ -1117,7 +1088,7 @@ SPITType *SPIT_Client::createSPITType(string p_ID, string p_GroupName, string p_
|
||||
auto eventType = boolNew ? ObjectEvent::Created : ObjectEvent::Changed;
|
||||
SPITType::addSPITType(*ptrSPITType);
|
||||
mCallbacks.onSpitType(eventType, *ptrSPITType);
|
||||
sendSPITTypeInternal(ptrSPITType);
|
||||
sendSPITTypeInternal(*ptrSPITType);
|
||||
return ptrSPITType;
|
||||
}
|
||||
|
||||
@@ -1242,10 +1213,10 @@ void SPIT_Client::parseRemoveSPITObject(SPIT_Message::RemoveSPITObject *p_Remove
|
||||
int SPIT_Client::sendSPITObjectInternal(SPITObject *ptrSPITObject) {
|
||||
if (ptrSPITObject == nullptr)
|
||||
return -1;
|
||||
SPIT_Message::ReportSPITObject ptrSMReportSPITObject;
|
||||
ptrSPITObject->fillMessageOP(&ptrSMReportSPITObject);
|
||||
auto sMReportSPITObject = make_unique<SPIT_Message::ReportSPITObject>();
|
||||
ptrSPITObject->fillMessageOP(*sMReportSPITObject);
|
||||
|
||||
return sendSPITMessage(ptrSMReportSPITObject);
|
||||
return sendSPITMessage(move(sMReportSPITObject));
|
||||
}
|
||||
/**
|
||||
* When the client changes an existing SPITObject (normally the client should not do this), then he should send the changes to the SPITServer.<br>
|
||||
@@ -1306,7 +1277,7 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) {
|
||||
SPITType *ptrSPITType;
|
||||
SPITObject *ptrSPITObject;
|
||||
{
|
||||
SPIT_Message::RemoveSPITObject sMRemoveSPITObject;
|
||||
auto sMRemoveSPITObject = make_unique<SPIT_Message::RemoveSPITObject>();
|
||||
|
||||
ptrSPITObject = SPITObject::getSPITObject(p_SPITObjectID);
|
||||
if (ptrSPITObject == nullptr)
|
||||
@@ -1314,11 +1285,11 @@ int SPIT_Client::removeSPITObject(string p_SPITObjectID) {
|
||||
ptrSPITType = SPITType::getSPITType(ptrSPITObject->getSPITTypeID());
|
||||
if (ptrSPITType == nullptr)
|
||||
return -1;
|
||||
ptrSPITObject->fillMessageOP(&sMRemoveSPITObject);
|
||||
ptrSPITObject->fillMessageOP(*sMRemoveSPITObject);
|
||||
mCallbacks.onSpitObject(ObjectEvent::Deleted, *ptrSPITType, *ptrSPITObject);
|
||||
SPITObject::removeSPITObject(*ptrSPITObject);
|
||||
delete ptrSPITObject;
|
||||
return sendSPITMessage(sMRemoveSPITObject);
|
||||
return sendSPITMessage(move(sMRemoveSPITObject));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1465,25 +1436,21 @@ void SPIT_Client::sendRemoteObject(string p_SPITObjectID, int p_Valueppm, char p
|
||||
if (ptrRemoteSPITObject == nullptr)
|
||||
return;
|
||||
|
||||
SPIT_Message::PlaySPITStart playSPITStart;
|
||||
playSPITStart.setPlayerID(m_ID);
|
||||
playSPITStart.setPlayerName(m_ProjName);
|
||||
playSPITStart.setPlayerIsRunning(false);
|
||||
playSPITStart.setPlayerType(PLAYERTYPE_DISCRETE);
|
||||
playSPITStart.setTime(0);
|
||||
sendSPITMessage(playSPITStart);
|
||||
auto playSPITStart = make_unique<SPIT_Message::PlaySPITStart>(m_ID, m_ProjName, PLAYERTYPE_DISCRETE);
|
||||
playSPITStart->setPlayerIsRunning(false);
|
||||
playSPITStart->setTime(0);
|
||||
sendSPITMessage(move(playSPITStart));
|
||||
|
||||
SPIT_Message::PlaySPITObject playSPITObject;
|
||||
playSPITObject.setID(ptrRemoteSPITObject->getID());
|
||||
playSPITObject.setPlayPrePosition(false);
|
||||
playSPITObject.setPlayerID(m_ID);
|
||||
playSPITObject.setValue(p_Valueppm);
|
||||
playSPITObject.setValueFlag(p_ValueFlag);
|
||||
sendSPITMessage(playSPITObject);
|
||||
auto playSPITObject = make_unique<SPIT_Message::PlaySPITObject>();
|
||||
playSPITObject->setID(ptrRemoteSPITObject->getID());
|
||||
playSPITObject->setPlayPrePosition(false);
|
||||
playSPITObject->setPlayerID(m_ID);
|
||||
playSPITObject->setValue(p_Valueppm);
|
||||
playSPITObject->setValueFlag(p_ValueFlag);
|
||||
sendSPITMessage(move(playSPITObject));
|
||||
|
||||
SPIT_Message::PlaySPITEnd playSPITEnd;
|
||||
playSPITEnd.setPlayerID(m_ID);
|
||||
sendSPITMessage(playSPITEnd);
|
||||
auto playSPITEnd = make_unique<SPIT_Message::PlaySPITEnd>(m_ID);
|
||||
sendSPITMessage(move(playSPITEnd));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1528,7 +1495,7 @@ void SPIT_Client::processSocketTask(SPIT_Client &instance) {
|
||||
if (intReceivedByteCount <= 0) {
|
||||
break;
|
||||
}
|
||||
buffer[intReceivedByteCount] = '\0';
|
||||
buffer[intReceivedByteCount] = '\0';
|
||||
string stringMessage = buffer;
|
||||
// Check if precode is ok
|
||||
if (stringMessage.find(SERVERAUTODETECT_PRECODE.data(), 0) != 0) {
|
||||
|
||||
@@ -129,7 +129,7 @@ bool SPIT_Message::fillBytes() {
|
||||
try {
|
||||
if (m_MessageBytes.empty()) {
|
||||
int totalSize = Header::BYTESLENGTH + m_OPPart->getBytesCount();
|
||||
std::vector<char> buffer(totalSize);
|
||||
m_MessageBytes = std::vector<char>(totalSize);
|
||||
}
|
||||
return m_OPPart->fillBytes(m_MessageBytes);
|
||||
} catch (...) {
|
||||
@@ -178,7 +178,7 @@ bool SPIT_Message::Header::parse(const std::vector<char> &message) {
|
||||
m_ClientID = getString(message, m_ParseOffset, 41).value();
|
||||
m_OPFlag = message[m_ParseOffset++] & 0xFF;
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse Header");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -202,7 +202,7 @@ bool SPIT_Message::Header::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setString(m_ClientID, message, m_ParseOffset, 41);
|
||||
m_ParseOffset += setByte(m_OPFlag, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create Header");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -219,11 +219,9 @@ SPIT_Message::OPPart::OPPart(unique_ptr<Header> p_Header, int p_OPFlag, int size
|
||||
m_Header->setOPFlag(p_OPFlag);
|
||||
}
|
||||
}
|
||||
void SPIT_Message::OPPart::setHeader(unique_ptr<Header> p_Header) {
|
||||
m_Header = move(p_Header);
|
||||
if (m_Header != nullptr) {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
void SPIT_Message::OPPart::setHeader(int opFlag) {
|
||||
m_Header = make_unique<Header>(SPITVERSION, opFlag);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
// Send
|
||||
@@ -238,8 +236,9 @@ SPIT_Message::Connect::Connect(unique_ptr<Header> p_Header)
|
||||
}
|
||||
|
||||
bool SPIT_Message::Connect::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -253,7 +252,7 @@ bool SPIT_Message::Connect::parse(const std::vector<char> &message) {
|
||||
m_ServerIP = getString(message, m_ParseOffset, 40).value();
|
||||
m_ServerPort = getInt(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse Connect message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -264,7 +263,7 @@ SPIT_Message::Connect::Connect(string p_ComputerName, string p_ClientName)
|
||||
: OPPart(BYTESLENGTH),
|
||||
m_ClientComputerName(p_ComputerName),
|
||||
m_ClientName(p_ClientName) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
void SPIT_Message::Connect::setServerPort(int p_ServerPort) {
|
||||
@@ -273,8 +272,9 @@ void SPIT_Message::Connect::setServerPort(int p_ServerPort) {
|
||||
m_ServerPort = p_ServerPort;
|
||||
}
|
||||
bool SPIT_Message::Connect::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -287,7 +287,7 @@ bool SPIT_Message::Connect::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setString(m_ServerIP, message, m_ParseOffset, 40);
|
||||
m_ParseOffset += setInt(m_ServerPort, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create Connect message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -299,8 +299,9 @@ bool SPIT_Message::Connect::fillBytes(std::vector<char> &message) {
|
||||
SPIT_Message::ConnectAnswer::ConnectAnswer(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {}
|
||||
bool SPIT_Message::ConnectAnswer::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -312,16 +313,16 @@ bool SPIT_Message::ConnectAnswer::parse(const std::vector<char> &message) {
|
||||
m_StepTime = getInt(message, m_ParseOffset).value();
|
||||
m_Connected = getBoolean(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse ConnectAnswer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send
|
||||
SPIT_Message::ConnectAnswer::ConnectAnswer()
|
||||
: OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
SPIT_Message::ConnectAnswer::ConnectAnswer()
|
||||
: OPPart(BYTESLENGTH) {
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
void SPIT_Message::ConnectAnswer::setStepTime(int p_StepTime_ms) {
|
||||
@@ -330,8 +331,9 @@ void SPIT_Message::ConnectAnswer::setStepTime(int p_StepTime_ms) {
|
||||
m_StepTime = p_StepTime_ms;
|
||||
}
|
||||
bool SPIT_Message::ConnectAnswer::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -342,7 +344,7 @@ bool SPIT_Message::ConnectAnswer::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setInt(m_StepTime, message, m_ParseOffset);
|
||||
m_ParseOffset += setBoolean(m_Connected, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create ConnectAnswer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -354,8 +356,9 @@ bool SPIT_Message::ConnectAnswer::fillBytes(std::vector<char> &message) {
|
||||
SPIT_Message::Disconnect::Disconnect(unique_ptr<Header> p_Header) : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::Disconnect::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -363,28 +366,29 @@ bool SPIT_Message::Disconnect::parse(const std::vector<char> &message) {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse Disconnect message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Send
|
||||
SPIT_Message::Disconnect::Disconnect() : OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
SPIT_Message::Disconnect::Disconnect()
|
||||
: OPPart(BYTESLENGTH) {
|
||||
setHeader(OPFLAG);
|
||||
}
|
||||
|
||||
bool SPIT_Message::Disconnect::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
setInt(m_BytesCount, message, m_ParseOffset);
|
||||
m_ParseOffset += 4;
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create Disconnect message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -396,8 +400,9 @@ SPIT_Message::Watchdog::Watchdog(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::Watchdog::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -405,7 +410,7 @@ bool SPIT_Message::Watchdog::parse(const std::vector<char> &message) {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse Watchdog message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -413,20 +418,20 @@ bool SPIT_Message::Watchdog::parse(const std::vector<char> &message) {
|
||||
|
||||
// Send
|
||||
SPIT_Message::Watchdog::Watchdog() : OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
bool SPIT_Message::Watchdog::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
setInt(m_BytesCount, message, m_ParseOffset);
|
||||
m_ParseOffset += 4;
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create Watchdog message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -438,8 +443,9 @@ bool SPIT_Message::Watchdog::fillBytes(std::vector<char> &message) {
|
||||
SPIT_Message::WatchdogAnswer::WatchdogAnswer(unique_ptr<Header> p_Header) : OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::WatchdogAnswer::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -447,7 +453,7 @@ bool SPIT_Message::WatchdogAnswer::parse(const std::vector<char> &message) {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse WatchdogAnswer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -455,20 +461,20 @@ bool SPIT_Message::WatchdogAnswer::parse(const std::vector<char> &message) {
|
||||
|
||||
// Send
|
||||
SPIT_Message::WatchdogAnswer::WatchdogAnswer() : OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
bool SPIT_Message::WatchdogAnswer::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
setInt(m_BytesCount, message, m_ParseOffset);
|
||||
m_ParseOffset += 4;
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create WatchdogAnswer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -482,8 +488,9 @@ SPIT_Message::ReportSPITProject::ReportSPITProject(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::ReportSPITProject::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -494,7 +501,7 @@ bool SPIT_Message::ReportSPITProject::parse(const std::vector<char> &message) {
|
||||
m_ProjectName = getString(message, m_ParseOffset, 64).value();
|
||||
m_FramesPerSecond = getInt(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse ReportSPITProject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -504,13 +511,14 @@ SPIT_Message::ReportSPITProject::ReportSPITProject(string p_ProjectID, string p_
|
||||
: OPPart(BYTESLENGTH),
|
||||
m_ProjectID(p_ProjectID),
|
||||
m_ProjectName(p_ProjectName) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
bool SPIT_Message::ReportSPITProject::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -520,7 +528,7 @@ bool SPIT_Message::ReportSPITProject::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setString(m_ProjectName, message, m_ParseOffset, 64);
|
||||
m_ParseOffset += setInt(m_FramesPerSecond, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create ReportSPITProject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -533,8 +541,9 @@ SPIT_Message::CloseSPITProject::CloseSPITProject(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::CloseSPITProject::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -543,7 +552,7 @@ bool SPIT_Message::CloseSPITProject::parse(const std::vector<char> &message) {
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
m_ProjectID = getString(message, m_ParseOffset, 41).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse CloseSPITProject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -552,13 +561,14 @@ bool SPIT_Message::CloseSPITProject::parse(const std::vector<char> &message) {
|
||||
SPIT_Message::CloseSPITProject::CloseSPITProject(string projectID)
|
||||
: OPPart(BYTESLENGTH),
|
||||
m_ProjectID(projectID) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
bool SPIT_Message::CloseSPITProject::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -566,7 +576,7 @@ bool SPIT_Message::CloseSPITProject::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
m_ParseOffset += setString(m_ProjectID, message, m_ParseOffset, 41);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create CloseSPITProject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -579,8 +589,9 @@ SPIT_Message::RequestProjectTransfer::RequestProjectTransfer(unique_ptr<Header>
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::RequestProjectTransfer::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -588,7 +599,7 @@ bool SPIT_Message::RequestProjectTransfer::parse(const std::vector<char> &messag
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse RequestProjectTransfer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -596,19 +607,20 @@ bool SPIT_Message::RequestProjectTransfer::parse(const std::vector<char> &messag
|
||||
// Send
|
||||
SPIT_Message::RequestProjectTransfer::RequestProjectTransfer()
|
||||
: OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
bool SPIT_Message::RequestProjectTransfer::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create RequestProjectTransfer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -621,8 +633,9 @@ SPIT_Message::StartProjectTransfer::StartProjectTransfer(unique_ptr<Header> p_He
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::StartProjectTransfer::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -630,7 +643,7 @@ bool SPIT_Message::StartProjectTransfer::parse(const std::vector<char> &message)
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse StartProjectTransfer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -638,20 +651,21 @@ bool SPIT_Message::StartProjectTransfer::parse(const std::vector<char> &message)
|
||||
// Send
|
||||
SPIT_Message::StartProjectTransfer::StartProjectTransfer()
|
||||
: OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
bool SPIT_Message::StartProjectTransfer::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create StartProjectTransfer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -664,8 +678,9 @@ SPIT_Message::EndProjectTransfer::EndProjectTransfer(unique_ptr<Header> p_Header
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::EndProjectTransfer::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -673,7 +688,7 @@ bool SPIT_Message::EndProjectTransfer::parse(const std::vector<char> &message) {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse EndProjectTransfer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -681,19 +696,20 @@ bool SPIT_Message::EndProjectTransfer::parse(const std::vector<char> &message) {
|
||||
// Send
|
||||
SPIT_Message::EndProjectTransfer::EndProjectTransfer()
|
||||
: OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
bool SPIT_Message::EndProjectTransfer::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create EndProjectTransfer message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -708,8 +724,9 @@ SPIT_Message::ReportSPITType::ReportSPITType(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::ReportSPITType::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -726,7 +743,7 @@ bool SPIT_Message::ReportSPITType::parse(const std::vector<char> &message) {
|
||||
m_Delay = getLong(message, m_ParseOffset).value();
|
||||
m_Duration = getLong(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse ReportSPITType message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -734,13 +751,14 @@ bool SPIT_Message::ReportSPITType::parse(const std::vector<char> &message) {
|
||||
// Send
|
||||
SPIT_Message::ReportSPITType::ReportSPITType()
|
||||
: OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
bool SPIT_Message::ReportSPITType::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -756,7 +774,7 @@ bool SPIT_Message::ReportSPITType::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setLong(m_Delay, message, m_ParseOffset);
|
||||
m_ParseOffset += setLong(m_Duration, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create ReportSPITType message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -769,8 +787,9 @@ SPIT_Message::RemoveSPITType::RemoveSPITType(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::RemoveSPITType::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -779,7 +798,7 @@ bool SPIT_Message::RemoveSPITType::parse(const std::vector<char> &message) {
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
m_SPITTypeID = getString(message, m_ParseOffset, 41).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse RemoveSPITType message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -787,13 +806,14 @@ bool SPIT_Message::RemoveSPITType::parse(const std::vector<char> &message) {
|
||||
// Send
|
||||
SPIT_Message::RemoveSPITType::RemoveSPITType()
|
||||
: OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
bool SPIT_Message::RemoveSPITType::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -801,7 +821,7 @@ bool SPIT_Message::RemoveSPITType::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
m_ParseOffset += setString(m_SPITTypeID, message, m_ParseOffset, 41);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create RemoveSPITType message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -815,8 +835,9 @@ SPIT_Message::ReportSPITObject::ReportSPITObject(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::ReportSPITObject::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -842,14 +863,14 @@ bool SPIT_Message::ReportSPITObject::parse(const std::vector<char> &message) {
|
||||
m_Duration = getLong(message, m_ParseOffset).value();
|
||||
m_ActionAssigned = getBoolean(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse ReportSPITObject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Send
|
||||
SPIT_Message::ReportSPITObject::ReportSPITObject() : OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
@@ -865,8 +886,9 @@ void SPIT_Message::ReportSPITObject::setDuration(long long p_Duration) {
|
||||
}
|
||||
|
||||
bool SPIT_Message::ReportSPITObject::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -891,7 +913,7 @@ bool SPIT_Message::ReportSPITObject::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setLong(m_Duration, message, m_ParseOffset);
|
||||
m_ParseOffset += setBoolean(m_ActionAssigned, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create ReportSPITObject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -903,8 +925,9 @@ SPIT_Message::RemoveSPITObject::RemoveSPITObject(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::RemoveSPITObject::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -913,7 +936,7 @@ bool SPIT_Message::RemoveSPITObject::parse(const std::vector<char> &message) {
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
m_SPITObjectID = getString(message, m_ParseOffset, 41).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse RemoveSPITObject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -921,13 +944,14 @@ bool SPIT_Message::RemoveSPITObject::parse(const std::vector<char> &message) {
|
||||
|
||||
// Send
|
||||
SPIT_Message::RemoveSPITObject::RemoveSPITObject() : OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
bool SPIT_Message::RemoveSPITObject::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -935,7 +959,7 @@ bool SPIT_Message::RemoveSPITObject::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
m_ParseOffset += setString(m_SPITObjectID, message, m_ParseOffset, 41);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create RemoveSPITObject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -949,8 +973,9 @@ SPIT_Message::PlaySPITStart::PlaySPITStart(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::PlaySPITStart::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -963,7 +988,7 @@ bool SPIT_Message::PlaySPITStart::parse(const std::vector<char> &message) {
|
||||
m_PlayerIsRunning = getBoolean(message, m_ParseOffset).value();
|
||||
m_Time = getLong(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse PlaySPITStart message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -975,13 +1000,14 @@ SPIT_Message::PlaySPITStart::PlaySPITStart(string p_PlayerID, string p_PlayerNam
|
||||
m_PlayerID(p_PlayerID),
|
||||
m_PlayerName(p_PlayerName),
|
||||
m_PlayerType(p_PlayerType) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
bool SPIT_Message::PlaySPITStart::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -993,7 +1019,7 @@ bool SPIT_Message::PlaySPITStart::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setBoolean(m_PlayerIsRunning, message, m_ParseOffset);
|
||||
m_ParseOffset += setLong(m_Time, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create PlaySPITStart message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1006,8 +1032,9 @@ SPIT_Message::PlaySPITObject::PlaySPITObject(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::PlaySPITObject::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -1021,7 +1048,7 @@ bool SPIT_Message::PlaySPITObject::parse(const std::vector<char> &message) {
|
||||
m_Value = getInt(message, m_ParseOffset).value();
|
||||
m_ValueFlag = getByte(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse PlaySPITObject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1029,12 +1056,13 @@ bool SPIT_Message::PlaySPITObject::parse(const std::vector<char> &message) {
|
||||
// Send
|
||||
SPIT_Message::PlaySPITObject::PlaySPITObject()
|
||||
: OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
bool SPIT_Message::PlaySPITObject::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -1047,7 +1075,7 @@ bool SPIT_Message::PlaySPITObject::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setInt(m_Value, message, m_ParseOffset);
|
||||
m_ParseOffset += setByte(m_ValueFlag, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create PlaySPITObject message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1060,8 +1088,9 @@ SPIT_Message::PlaySPITEnd::PlaySPITEnd(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::PlaySPITEnd::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -1070,7 +1099,7 @@ bool SPIT_Message::PlaySPITEnd::parse(const std::vector<char> &message) {
|
||||
m_BytesCount = getInt(message, m_ParseOffset).value();
|
||||
m_PlayerID = getString(message, m_ParseOffset, 41).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse PlaySPITEnd message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1079,13 +1108,14 @@ bool SPIT_Message::PlaySPITEnd::parse(const std::vector<char> &message) {
|
||||
SPIT_Message::PlaySPITEnd::PlaySPITEnd(string p_PlayerID)
|
||||
: OPPart(BYTESLENGTH),
|
||||
m_PlayerID(p_PlayerID) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
bool SPIT_Message::PlaySPITEnd::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -1093,7 +1123,7 @@ bool SPIT_Message::PlaySPITEnd::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setInt(m_BytesCount, message, m_ParseOffset);
|
||||
m_ParseOffset += setString(m_PlayerID, message, m_ParseOffset, 41);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create PlaySPITEnd message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1106,8 +1136,9 @@ SPIT_Message::ReportPlayStatus::ReportPlayStatus(unique_ptr<Header> p_Header)
|
||||
: OPPart(move(p_Header), OPFLAG, BYTESLENGTH) {
|
||||
}
|
||||
bool SPIT_Message::ReportPlayStatus::parse(const std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
int intOPFlag = m_Header->getOPFlag();
|
||||
if (intOPFlag != OPFLAG)
|
||||
return false;
|
||||
@@ -1118,14 +1149,14 @@ bool SPIT_Message::ReportPlayStatus::parse(const std::vector<char> &message) {
|
||||
m_FrameInsideObject = getLong(message, m_ParseOffset).value();
|
||||
m_Value = getInt(message, m_ParseOffset).value();
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to parse message");
|
||||
ESP_LOGE(TAG, "failed to parse ReportPlayStatus message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Send
|
||||
SPIT_Message::ReportPlayStatus::ReportPlayStatus() : OPPart(BYTESLENGTH) {
|
||||
setHeader(make_unique<Header>(SPITVERSION, OPFLAG));
|
||||
setHeader(OPFLAG);
|
||||
m_ParseOffset = Header::BYTESLENGTH;
|
||||
}
|
||||
|
||||
@@ -1139,8 +1170,9 @@ void SPIT_Message::ReportPlayStatus::setValue(int p_Value) {
|
||||
m_Value = p_Value;
|
||||
}
|
||||
bool SPIT_Message::ReportPlayStatus::fillBytes(std::vector<char> &message) {
|
||||
if (m_Header == nullptr)
|
||||
if (!m_Header) {
|
||||
return false;
|
||||
}
|
||||
if (m_Header->fillBytes(message) == false)
|
||||
return false;
|
||||
try {
|
||||
@@ -1150,7 +1182,7 @@ bool SPIT_Message::ReportPlayStatus::fillBytes(std::vector<char> &message) {
|
||||
m_ParseOffset += setLong(m_FrameInsideObject, message, m_ParseOffset);
|
||||
m_ParseOffset += setInt(m_Value, message, m_ParseOffset);
|
||||
} catch (...) {
|
||||
ESP_LOGE(TAG, "failed to create message");
|
||||
ESP_LOGE(TAG, "failed to create ReportPlayStatus message");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user