Files
autopilot/misc/camera/a8_remote/remoteControl.cpp
T
2024-07-04 15:51:04 +03:00

32 lines
956 B
C++

#include "remoteControl.hpp"
#include <QCoreApplication>
#include <QDebug>
#include <QHostAddress>
#include <QJsonDocument>
#include <QJsonObject>
#include <QThread>
#include <QTimer>
#include <QUdpSocket>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
uint8_t RemoteControl::sendData(uint16_t top, uint16_t left, uint16_t bottom, uint16_t right)
{
QUdpSocket udpSocket;
QJsonObject commandObject = {{"sender", UDP_WHO_AM_I}, {"top", top}, {"left", left}, {"bottom", bottom}, {"right", right}};
QJsonDocument commandDocument(commandObject);
QByteArray datagram = commandDocument.toJson(QJsonDocument::Compact);
qint64 bytesSent = udpSocket.writeDatagram(datagram, QHostAddress("127.0.0.1"), UDP_PORT);
if (bytesSent == -1) {
qWarning("Failed to send the datagram: %s", qPrintable(udpSocket.errorString()));
return 1;
} else {
qDebug("Datagram sent successfully");
}
return 0;
}