Added server side code.

This commit is contained in:
Nffj84
2024-07-25 17:49:30 +03:00
parent 8e88cb6fe1
commit 147213cec6
15 changed files with 951 additions and 11 deletions
+52 -8
View File
@@ -1,31 +1,75 @@
#include <QDebug>
#include <QTimer>
#include "aienginegimbalserver.h"
#include "aienginegimbalserveractions.h"
AiEngineGimbalServer::AiEngineGimbalServer(QObject *parent)
: QObject{parent}
{
mSerialPort = new QSerialPort(this);
// TODO!! Setup and use serial port....
mIsAvailable = true;
mActions.setup(&mSerialPort, &mSerialCommand, &mSerialResponse, &mGimbalStatus);
connect(&mActions, &AiEngineGimbalServerActions::aiTargetZoomed, this, &AiEngineGimbalServer::aiTargetZoomed);
}
// TODO!! Client doesn't really send any signal yet to this slot.
void AiEngineGimbalServer::dronePositionSlot(AiEngineDronePosition position)
void AiEngineGimbalServer::dronePositionSlot(AiEngineDronePosition dronePosition)
{
qDebug() << "AiEngineGimbalServer::dronePositionSlot() Server got new drone position:"
<< position.position.lat
<< position.position.lon
<< position.position.alt;
<< dronePosition.position.lat
<< dronePosition.position.lon
<< dronePosition.position.alt
<< dronePosition.pitch
<< dronePosition.yaw;
mDronePosition = dronePosition;
}
// This is actually called from the client.
void AiEngineGimbalServer::zoomToAiTargetSlot(AiEngineCameraTarget target)
{
qDebug() << "AiEngineGimbalServer::zoomToAiTargetSlot() Move camera to the new target:"
<< "index:" << target.index
<< "pos:" << target.rectangle.top << target.rectangle.left << target.rectangle.bottom << target.rectangle.right;
if (mIsAvailable == true) {
mIsAvailable = false;
qDebug() << "AiEngineGimbalServer::zoomToAiTargetSlot() Move camera to the new target:"
<< "index:" << target.index
<< "pos:" << target.rectangle.top << target.rectangle.left << target.rectangle.bottom << target.rectangle.right;
// Rectangle calculation for having proper zoom on group / target
AiEngineRectangleProperties rectangle = mActions.calculateRectangleProperties(target.rectangle.top, target.rectangle.left, target.rectangle.bottom, target.rectangle.right);
// Turn
mActions.turnToTarget(rectangle);
// Calculate location
int delay1 = 1000; // Adjust this value as needed
AiEngineDronePosition dronePosition = mDronePosition;
int targetIndex = target.index;
QTimer::singleShot(delay1, this, [this, dronePosition, targetIndex]() { mActions.getLocation(dronePosition, targetIndex); });
// Zoom
int delay2 = delay1 + 100; // Adjust this value as needed
QTimer::singleShot(delay2, this, [this, rectangle]() { mActions.zoomToTarget(rectangle); });
// Return to previous position
int delay3 = delay2 + 10000; // Adjust this value as needed
AiEngineGimbalStatus gimbalStatus = mGimbalStatus;
QTimer::singleShot(delay3, this, [this, gimbalStatus]() { mActions.restoreOrientationAndZoom(gimbalStatus); });
// Allow calls
int delay4 = delay3 + 100; // Adjust this value as needed
QTimer::singleShot(delay4, this, [this]() { mIsAvailable = true; });
}
}
bool AiEngineGimbalServer::isAvailable(void)
{
return mIsAvailable;
}