Removed blocking code from a8 and a8 remote.

This commit is contained in:
Nffj84
2024-07-03 18:16:59 +03:00
parent df6352fe92
commit f77e2d3661
4 changed files with 65 additions and 36 deletions
+2 -2
View File
@@ -6,8 +6,8 @@ CONFIG += c++17 console
TARGET = a8
QMAKE_CXXFLAGS = -O0 -g -ggdb -fsanitize=address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
QMAKE_LFLAGS = -O0 -g -ggdb -fsanitize=address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
QMAKE_CXXFLAGS = -O0 -g -ggdb -fsanitize=undefined,address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
QMAKE_LFLAGS = -O0 -g -ggdb -fsanitize=undefined,address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
QMAKE_CXX = clang++
QMAKE_CC = clang
+31 -3
View File
@@ -48,7 +48,7 @@ void RemoteControl::openNamedPipe()
}
}
mFifoFdIn = open(FIFO_TO_GIMBAL, O_RDONLY | O_NONBLOCK);
mFifoFdIn = open(FIFO_TO_GIMBAL, O_RDWR | O_NONBLOCK);
if (mFifoFdIn == -1) {
qCritical().noquote().nospace() << "Error opening pipe for reading: " << FIFO_TO_GIMBAL;
} else {
@@ -206,14 +206,38 @@ void RemoteControl::zoomToTarget(QJsonObject &commandObject)
RectangleProperties RemoteControl::calculateRectangleProperties(uint16_t top, uint16_t left, uint16_t bottom, uint16_t right)
{
RectangleProperties properties;
// Sanity check
// top cannot be greater than bottom
// left cannot be greater than right
if (top > bottom) {
uint16_t temp = top;
top = bottom;
bottom = temp;
qWarning().noquote().nospace() << "calculateRectangleProperties(): top and bottom mixed?";
}
if (left > right) {
uint16_t temp = left;
left = right;
right = temp;
qWarning().noquote().nospace() << "calculateRectangleProperties(): left and right mixed?";
}
RectangleProperties properties;
properties.width = right - left;
properties.height = bottom - top;
properties.middleX = static_cast<uint16_t>(left + properties.width / 2);
properties.middleY = static_cast<uint16_t>(top + properties.height / 2);
// Sanity check, none cannot be 0
// If that is the case, we will not turn or zoom
if (properties.height == 0 || properties.width == 0 || properties.middleX == 0 || properties.middleY == 0) {
properties.height = CAMERA_RESOLUTION_HEIGHT;
properties.width = CAMERA_RESOLUTION_WIDTH;
properties.middleX = CAMERA_RESOLUTION_WIDTH / 2;
properties.middleY = CAMERA_RESOLUTION_HEIGHT / 2;
qWarning().noquote().nospace() << "calculateRectangleProperties(): Something was zero -> No zoom, no turn!";
}
return properties;
}
@@ -265,6 +289,10 @@ void RemoteControl::run()
commandObject["target_y"] = rectangle.middleY;
commandObject["target_pixel_height"] = rectangle.height;
commandObject["target_pixel_width"] = rectangle.width;
qInfo() << "target_x: " << commandObject["target_x"];
qInfo() << "target_y: " << commandObject["target_y"];
qInfo() << "target_pixel_height: " << commandObject["target_pixel_height"];
qInfo() << "target_pixel_width: " << commandObject["target_pixel_width"];
mIsBusy = true;
+2 -2
View File
@@ -5,8 +5,8 @@ CONFIG += c++17 console
TARGET = a8_remote
QMAKE_CXXFLAGS = -O0 -g -ggdb -fsanitize=undefined,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
QMAKE_LFLAGS = -O0 -g -ggdb -fsanitize=undefined,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
QMAKE_CXXFLAGS = -O0 -g -ggdb -fsanitize=undefined,address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
QMAKE_LFLAGS = -O0 -g -ggdb -fsanitize=undefined,address,bounds,float-divide-by-zero,integer-divide-by-zero,null,return,signed-integer-overflow,unreachable,shift,alignment,nonnull-attribute,returns-nonnull-attribute,enum
QMAKE_CXX = clang++
QMAKE_CC = clang
+30 -29
View File
@@ -85,13 +85,7 @@ void RemoteControl::createNamedPipe()
void RemoteControl::sendData(uint16_t top, uint16_t left, uint16_t bottom, uint16_t right)
{
qInfo().noquote().nospace() << "Enter a command (0 to exit): ";
std::string input;
std::cin >> input;
// Send command
QJsonObject commandObject = {{"sender", FIFO_WHO_AM_I}, {"top", top}, {"left", left}, {"bottom", bottom}, {"right", right}};
QJsonDocument commandDocument(commandObject);
std::string command = commandDocument.toJson(QJsonDocument::Compact).toStdString();
write(mFifoFdOut, command.c_str(), command.size());
@@ -101,31 +95,38 @@ void RemoteControl::sendData(uint16_t top, uint16_t left, uint16_t bottom, uint1
#ifdef FIFO_TEST
void RemoteControl::startTest()
{
qInfo().noquote().nospace() << "Enter a command (0 to exit): ";
std::string input;
std::cin >> input;
QJsonObject commandObject;
for (uint8_t i = 0; i < 5; i++) {
qInfo().noquote().nospace() << "Enter a command (EXIT to exit): ";
std::string input;
std::cin >> input;
// Send command
QJsonObject commandObject = {
{"sender", FIFO_WHO_AM_I},
{"latitude", 63.155653611},
{"longitude", 23.827191389},
{"altitude", randomFloatBetween(10, 11)},
{"yaw", randomFloatBetween(0.0f, 360.0f)},
{"pitch", 0.0},
{"target_x", (uint16_t) randomFloatBetween(300, 979)},
{"target_y", (uint16_t) randomFloatBetween(200, 519)},
{"target_pixel_width", 20},
{"target_pixel_height", 10},
{"target_real_width", 5},
{"target_real_height", 2.5},
{"extra", input.c_str()},
};
// Send command
QJsonObject commandObject = {
{"sender", FIFO_WHO_AM_I},
{"latitude", 63.155653611},
{"longitude", 23.827191389},
{"altitude", randomFloatBetween(10, 11)},
{"yaw", randomFloatBetween(0.0f, 360.0f)},
{"pitch", 0.0},
{"target_x", (uint16_t) randomFloatBetween(300, 979)},
{"target_y", (uint16_t) randomFloatBetween(200, 519)},
{"target_pixel_width", 20},
{"target_pixel_height", 10},
{"target_real_width", 5},
{"target_real_height", 2.5},
{"extra", input.c_str()},
{"top", 100},
{"left", 100},
{"bottom", 200},
{"right", 200},
};
QJsonDocument commandDocument(commandObject);
std::string command = commandDocument.toJson(QJsonDocument::Compact).toStdString();
write(mFifoFdOut, command.c_str(), command.size());
qDebug().noquote().nospace() << "Sent: " << command;
QJsonDocument commandDocument(commandObject);
std::string command = commandDocument.toJson(QJsonDocument::Compact).toStdString();
write(mFifoFdOut, command.c_str(), command.size());
qDebug().noquote().nospace() << "Sent: " << command;
}
if (commandObject["extra"] == "EXIT") {
exit(EXIT_SUCCESS);