Small improvements.

This commit is contained in:
Nffj84
2024-07-04 11:29:39 +03:00
parent dfe3c7c561
commit 25c8f6c605
4 changed files with 30 additions and 21 deletions
+13 -10
View File
@@ -84,9 +84,11 @@ void RemoteControl::sendResponse(void)
QJsonDocument responseDocument(mResponseObject);
std::string response = responseDocument.toJson(QJsonDocument::Compact).toStdString();
// qDebug().noquote().nospace() << "Sending responce: " << response;
write(mFifoFdOut, response.c_str(), response.size());
size_t bytesWritten = write(mFifoFdOut, response.c_str(), response.size());
if (bytesWritten < 1) {
qWarning().noquote().nospace() << "Error writing response: " << bytesWritten;
}
qDebug().noquote().nospace() << "Responded: " << response;
mIsBusy = false;
}
@@ -255,22 +257,24 @@ void RemoteControl::run()
buffer[bytesRead] = '\0';
QJsonDocument commandDoc = QJsonDocument::fromJson(buffer);
QString message = QString::fromUtf8(buffer);
// Ignore non json messages
if (commandDoc.isNull() == false) {
qDebug().noquote().nospace() << "Received: " << message;
QJsonObject commandObject = commandDoc.object();
// Ignore own messages and messages that don't have sender
if (commandObject.contains("sender") == false || commandObject["sender"] == FIFO_WHO_AM_I) {
// Ignore messages that don't have sender
if (commandObject.contains("sender") == false) {
qDebug().noquote().nospace() << "No sender info: " << message;
mIsBusy = false;
continue;
}
QString message = QString::fromUtf8(buffer);
qDebug().noquote().nospace() << "Received: " << message;
// Exit with exit message
if (commandObject.contains("extra") == true && commandObject["extra"] == "EXIT") {
qDebug().noquote().nospace() << "Exit message received: Exiting...";
exit(EXIT_SUCCESS);
}
@@ -296,8 +300,6 @@ void RemoteControl::run()
qInfo() << "target_pixel_height: " << commandObject["target_pixel_height"];
qInfo() << "target_pixel_width: " << commandObject["target_pixel_width"];
mIsBusy = true;
// Prepare responce object
mResponseObject = QJsonObject();
mResponseObject["sender"] = FIFO_WHO_AM_I;
@@ -308,6 +310,7 @@ void RemoteControl::run()
QTimer::singleShot(0, this, [this, commandObject]() mutable { turnToTarget(commandObject); });
} else {
qDebug().noquote().nospace() << "Non JSON message received: " << message;
mIsBusy = false;
}
} else {