Compare commits

...

3 Commits

Author SHA1 Message Date
wanghaoyu 2fc16d1383 fix :修改滚轮变倍功能 4 days ago
wanghaoyu e2bf903a68 feat:新增组播 4 weeks ago
wanghaoyu 8725cf2da6 feat:新增四医大光电吊舱控制 2 months ago

3
.gitignore vendored

@ -80,3 +80,6 @@ CMakeLists.txt.user*
.rcc/
.uic/
/build*/
.vs/
*.json
/out/

@ -13,7 +13,9 @@ qt_add_executable(VideoClient
videoControl.h videoControl.ui videoControl.cpp
wprogressbar.h wprogressbar.cpp
webmapwidget.h webmapwidget.cpp
utils/CUdpSocket.cpp utils/CUdpSocket.h
utils/protocolPodTJ.cpp utils/protocolPodTJ.h
utils/switchbutton.h utils/switchbutton.cpp
)
qt6_add_resources(VideoClient "resources"
@ -28,7 +30,7 @@ set(FFMPEG_DIR ${3RDPARTY_DIR}/ffmpeg)
# add_subdirectory(shared)
add_subdirectory(video)
add_subdirectory(3rdparty)
# add_subdirectory(utils)
target_link_libraries(VideoClient
PRIVATE

@ -1,6 +1,8 @@
#include "commandwidget.h"
#include "ui_commandwidget.h"
#include <QIntValidator>
#include "utils/switchbutton.h"
CommandWidget::CommandWidget(QWidget *parent)
: QWidget(parent), ui(new Ui::CommandWidget) {
@ -13,6 +15,10 @@ CommandWidget::CommandWidget(QWidget *parent)
} else {
qDebug() << "绑定 UDP 套接字失败";
}
//创建自定义套接字
m_CUdpSocket = new CUdpSocket(this);
initmUdpParam();
}
CommandWidget::~CommandWidget() {
@ -78,6 +84,21 @@ void CommandWidget::buttonResponse(quint8 cmd) {
}
}
void CommandWidget::receiveUavTypeIndex(int index)
{
switch (index)
{
case FP98:
ui->cmdStackedWidget->setCurrentWidget(ui->stackedWidgetPage1);
break;
case MEDICAL_UNIVERSITY:
ui->cmdStackedWidget->setCurrentWidget(ui->stackedWidgePage2);
break;
default:
break;
}
}
void CommandWidget::on_pushButton_clicked() {
buttonResponse(0x75);
}
@ -145,3 +166,467 @@ void CommandWidget::on_pushButton_16_clicked() {
void CommandWidget::on_pushButton_15_clicked() {
buttonResponse(0xC9);
}
/** 武汉天进吊舱 */
void CommandWidget::on_pushButton_left_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7000"),
m_protocolPodTJ.cmdLeft(ui->cmdSlider->value())));
}
void CommandWidget::on_pushButton_left_released()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7000"),
QByteArray::fromHex("00000000")));
}
void CommandWidget::on_pushButton_right_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7000"),
m_protocolPodTJ.cmdRight(ui->cmdSlider->value())));
}
void CommandWidget::on_pushButton_right_released()
{
on_pushButton_left_released();
}
void CommandWidget::on_pushButton_up_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7000"),
m_protocolPodTJ.cmdUp(ui->cmdSlider->value())));
}
void CommandWidget::on_pushButton_up_released()
{
on_pushButton_left_released();
}
void CommandWidget::on_pushButton_down_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7000"),
m_protocolPodTJ.cmdDown(ui->cmdSlider->value())));
}
void CommandWidget::on_pushButton_down_released()
{
on_pushButton_left_released();
}
void CommandWidget::on_pushButton_center_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7100")));
}
void CommandWidget::on_pushButton_guid_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7200"),
m_protocolPodTJ.digitalGuid(ui->guidLineEdit->text().toInt(), ui->poseLineEdit->text().toInt())));
}
void CommandWidget::on_pushButton_pose_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7C00"),
m_protocolPodTJ.digitalGuid(ui->guidLineEdit->text().toInt(), ui->poseLineEdit->text().toInt())));
}
void CommandWidget::on_pushButton_directL_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7A00")));
}
void CommandWidget::on_pushButton_directS_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7B00")));
}
void CommandWidget::on_pushButton_lookDown_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7300")));
}
void CommandWidget::on_pushButton_packUp_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7400")));
}
void CommandWidget::on_pushButton_scanning_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7900")));
}
void CommandWidget::on_pushButton_close_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7500")));
}
void CommandWidget::on_comboBox1_activated(int index)
{
if (index >= 0)
{
QByteArray data = ui->comboBox1->currentData().toByteArray();
//qDebug() << data.toHex();
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("2300"),data));
}
}
void CommandWidget::on_comboBox2_activated(int index)
{
if (index >= 0)
{
QByteArray data = ui->comboBox2->currentData().toByteArray();
//qDebug() << data.toHex();
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("2500"), data));
}
}
void CommandWidget::on_pushButton_videoSwitch_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("3100")));
}
void CommandWidget::on_pushButton_video_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("3300")));
}
void CommandWidget::on_pushButton_photo_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("3200")));
}
void CommandWidget::on_pushButton_zoomp_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4500"),
m_protocolPodTJ.cmdZoom(0x01,ui->comboBox3->currentIndex())));
}
void CommandWidget::on_pushButton_zoomp_released()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4500")));
}
void CommandWidget::on_pushButton_zoomd_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4500"),
m_protocolPodTJ.cmdZoom(0x02, ui->comboBox3->currentIndex())));
}
void CommandWidget::on_pushButton_zoomd_released()
{
on_pushButton_zoomp_released();
}
void CommandWidget::on_pushButton_focusP_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4500"),
m_protocolPodTJ.cmdZoom(0x03, ui->comboBox3->currentIndex())));
}
void CommandWidget::on_pushButton_focusP_released()
{
on_pushButton_zoomp_released();
}
void CommandWidget::on_pushButton_focusD_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4500"),
m_protocolPodTJ.cmdZoom(0x04, ui->comboBox3->currentIndex())));
}
void CommandWidget::on_pushButton_focusD_released()
{
on_pushButton_zoomp_released();
}
void CommandWidget::on_pushButton_auto_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4500"),
m_protocolPodTJ.cmdZoom(0x05, 0x00)));
}
void CommandWidget::on_pushButton_auto_released()
{
on_pushButton_zoomp_released();
}
void CommandWidget::on_pushButton_contrastP_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4100"),
QByteArray::fromHex("01010000")));
}
void CommandWidget::on_pushButton_contrastD_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4100"),
QByteArray::fromHex("01020000")));
}
void CommandWidget::on_pushButton_lightP_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4100"),
QByteArray::fromHex("02010000")));
}
void CommandWidget::on_pushButton_lightD_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4100"),
QByteArray::fromHex("02020000")));
}
void CommandWidget::on_comboBox4_activated(int index)
{
if (index >= 0)
{
QByteArray data = ui->comboBox4->currentData().toByteArray();
//qDebug() << data.toHex();
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4A00"), data));
}
}
void CommandWidget::on_pushButton_zoomp_2_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("5000"),
QByteArray::fromHex("0F000000")));
}
void CommandWidget::on_pushButton_zoomp_2_released()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("5000"),
QByteArray::fromHex("00000000")));
}
void CommandWidget::on_pushButton_zoomd_2_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("5000"),
QByteArray::fromHex("10000000")));
}
void CommandWidget::on_pushButton_zoomd_2_released()
{
on_pushButton_zoomp_2_released();
}
void CommandWidget::on_pushButton_contrastP_2_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("5A00")));
}
void CommandWidget::on_pushButton_contrastD_2_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("5A00"),
QByteArray::fromHex("01000000")));
}
void CommandWidget::on_pushButton_color_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("5300")));
}
void CommandWidget::on_comboBox5_activated(int index)
{
if (index >= 0)
{
QByteArray data = ui->comboBox5->currentData().toByteArray();
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("5300"), data));
}
}
void CommandWidget::on_pushButton_distance_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("3D00")));
}
void CommandWidget::on_pushButton_distanceC_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("3E00"),
m_protocolPodTJ.cmdLaser(ui->comboBox6->currentIndex() + 1)));
}
void CommandWidget::on_pushButton_distanceS_pressed()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("3F00")));
}
void CommandWidget::on_cmdLineEdit_textChanged(const QString text)
{
qDebug() << text;
if (text.toInt() < 10)//数据小于10不响应
{
return;
}
ui->cmdSlider->setMaximum(text.toInt());
}
void CommandWidget::wheelZoomCtrl(int value)
{
if (value > 0)//鼠标前滚
{
void on_pushButton_zoomp_pressed();
qDebug() << "滚轮变倍+" << value;
}
else if (value < 0)
{
void on_pushButton_zoomd_pressed();
qDebug() << "滚轮变倍-" << value;
}
else if (value == 0)
{
void on_pushButton_zoomp_released();
qDebug() << "停止变倍:" << value;
}
}
void CommandWidget::setPodIPConfig(NetworkIPStruct networkIP, bool isConnect)
{
qDebug() << "ip设置槽函数调用了";
if (!isConnect)
{
m_CUdpSocket->close();
return;
}
if (m_CUdpSocket->close())
{
if (!m_CUdpSocket->bind(networkIP.localIP, networkIP.localPort))
{
qDebug() << "端口号绑定失败";
}
if (!m_CUdpSocket->joinMulticast())
{
qDebug() << "加入组播失败";
}
//绑定目标IP Port
m_CUdpSocket->setTargetInfo(networkIP.remoteIP, networkIP.remotePort);
}
}
void CommandWidget::setMoveParm(QPointF size)
{
int x = std::clamp(static_cast<int>(size.x() / 10), -60, 60);
int y = std::clamp(static_cast<int>(-size.y() / 10), -60, 60);
qDebug() << "缩减之后的屏幕滑动参数==>" << "x:" << x << "y:" << y;
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("7000"),
m_protocolPodTJ.cmdServo(x, y)));
}
void CommandWidget::stopServo()
{
on_pushButton_left_released();
}
void CommandWidget::setTargetTracking(double dir, double pitch)
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("3A00"),
m_protocolPodTJ.targetTracking(static_cast<int>(std::round(dir)), static_cast<int>(std::round(pitch)))));
}
void CommandWidget::setStopTracking()
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("3B00")));
}
/***武汉天进吊舱控制***/
void CommandWidget::initmUdpParam()
{
QIntValidator* validator = new QIntValidator(0, 100, this);
ui->cmdLineEdit->setValidator(validator);
ui->cmdLineEdit->setText("40");
ui->cmdSlider->setValue(20);
//AI开关
connect(ui->switchButton1, &WBSwitchButton::sigSwitchChanged, this, [=](bool onOroff){
if (onOroff) //开关打开
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("9100"),
QByteArray::fromHex("01000000")));
}
else
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("9100")));
}
});
ui->comboBox1->addItem("16 * 16", QByteArray::fromHex("01000000"));
ui->comboBox1->addItem("32 * 32", QByteArray::fromHex("02000000"));
ui->comboBox1->addItem("64 * 64", QByteArray::fromHex("03000000"));
ui->comboBox1->addItem("128 * 128", QByteArray::fromHex("04000000"));
ui->comboBox2->addItem("红外", QByteArray::fromHex("00000000"));
ui->comboBox2->addItem("可见光", QByteArray::fromHex("01000000"));
ui->comboBox2->addItem("上下分屏", QByteArray::fromHex("02000000"));
ui->comboBox2->addItem("画中画1", QByteArray::fromHex("03000000"));
ui->comboBox2->addItem("画中画2", QByteArray::fromHex("04000000"));
ui->comboBox2->addItem("左右分屏", QByteArray::fromHex("05000000"));
ui->comboBox3->setCurrentIndex(4);
//低照度
connect(ui->btn_light, &WBSwitchButton::sigSwitchChanged, this, [=](bool onOroff) {
if (onOroff) //开关打开
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4B00"),
QByteArray::fromHex("01000000")));
}
else
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4B00")));
}
});
//电子稳像
connect(ui->btn_stable, &WBSwitchButton::sigSwitchChanged, this, [=](bool onOroff) {
if (onOroff) //开关打开
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4100"),
QByteArray::fromHex("04010000")));
}
else
{
m_CUdpSocket->sendData(ProtocolPodTJ::encode(QByteArray::fromHex("4100"),
QByteArray::fromHex("04020000")));
}
});
//图像去雾
ui->comboBox4->addItem("", QByteArray::fromHex("00000000"));
ui->comboBox4->addItem("", QByteArray::fromHex("01000000"));
ui->comboBox4->addItem("", QByteArray::fromHex("02000000"));
ui->comboBox4->addItem("", QByteArray::fromHex("03000000"));
//伪彩选择
ui->comboBox5->addItem("白热", QByteArray::fromHex("01000000"));
ui->comboBox5->addItem("黑热", QByteArray::fromHex("01010000"));
ui->comboBox5->addItem("蓝红黄", QByteArray::fromHex("01020000"));
ui->comboBox5->addItem("紫红黄", QByteArray::fromHex("01030000"));
ui->comboBox5->addItem("蓝绿红", QByteArray::fromHex("01040000"));
ui->comboBox5->addItem("彩虹1", QByteArray::fromHex("01050000"));
ui->comboBox5->addItem("彩虹2", QByteArray::fromHex("01060000"));
ui->comboBox5->addItem("黑-红", QByteArray::fromHex("01070000"));
ui->comboBox5->addItem("墨绿-红", QByteArray::fromHex("01080000"));
ui->comboBox5->addItem("蓝绿红-粉", QByteArray::fromHex("01090000"));
ui->comboBox5->addItem("混合色", QByteArray::fromHex("010A0000"));
ui->comboBox5->addItem("红头", QByteArray::fromHex("010B0000"));
}

@ -6,6 +6,8 @@
#include "communicationsettingdlg.h"
#include "global.h"
#include "utils/CUdpSocket.h"
#include "utils/protocolPodTJ.h"
typedef struct struProtocalKB {
quint8 head[2]; // 帧头0x
@ -71,6 +73,12 @@ const quint16 CRC8TAB[256] = {
0x0082, 0x00B3, 0x00E0, 0x00D1, 0x0046, 0x0077, 0x0024, 0x0015, 0x003B,
0x000A, 0x0059, 0x0068, 0x00FF, 0x00CE, 0x009D, 0x00AC};
enum uav_type
{
FP98=0,
MEDICAL_UNIVERSITY=5
};
namespace Ui {
class CommandWidget;
}
@ -122,18 +130,126 @@ private slots:
void on_pushButton_15_clicked();
/*武汉天进吊舱控制*/
void on_pushButton_left_pressed();
void on_pushButton_left_released();
void on_pushButton_right_pressed();
void on_pushButton_right_released();
void on_pushButton_up_pressed();
void on_pushButton_up_released();
void on_pushButton_down_pressed();
void on_pushButton_down_released();
void on_pushButton_center_pressed();
//姿态指引
void on_pushButton_guid_pressed();
void on_pushButton_pose_pressed();
//航向锁定
void on_pushButton_directL_pressed();
//航向随动
void on_pushButton_directS_pressed();
//垂直下视
void on_pushButton_lookDown_pressed();
//镜头收藏
void on_pushButton_packUp_pressed();
//扫描
void on_pushButton_scanning_pressed();
//关伺服
void on_pushButton_close_pressed();
//设置检测模板
void on_comboBox1_activated(int index);
//显示模式
void on_comboBox2_activated(int index);
//视频切换
void on_pushButton_videoSwitch_pressed();
//开始录像
void on_pushButton_video_pressed();
//拍照
void on_pushButton_photo_pressed();
//可见光变倍+
void on_pushButton_zoomp_pressed();
void on_pushButton_zoomp_released();
//可见光变倍-
void on_pushButton_zoomd_pressed();
void on_pushButton_zoomd_released();
//可见光变焦+
void on_pushButton_focusP_pressed();
void on_pushButton_focusP_released();
//可见光变焦-
void on_pushButton_focusD_pressed();
void on_pushButton_focusD_released();
//自动对焦
void on_pushButton_auto_pressed();
void on_pushButton_auto_released();
//对比度
void on_pushButton_contrastP_pressed();
void on_pushButton_contrastD_pressed();
//亮度
void on_pushButton_lightP_pressed();
void on_pushButton_lightD_pressed();
//图像去雾
void on_comboBox4_activated(int index);
//红外变倍+
void on_pushButton_zoomp_2_pressed();
void on_pushButton_zoomp_2_released();
//红外变倍-
void on_pushButton_zoomd_2_pressed();
void on_pushButton_zoomd_2_released();
//对比度
void on_pushButton_contrastP_2_pressed();
void on_pushButton_contrastD_2_pressed();
//伪彩循环切换
void on_pushButton_color_pressed();
//伪彩选择
void on_comboBox5_activated(int index);
//单次测距
void on_pushButton_distance_pressed();
//连续测距
void on_pushButton_distanceC_pressed();
//停止测距
void on_pushButton_distanceS_pressed();
void on_cmdLineEdit_textChanged(const QString text);
private:
Ui::CommandWidget *ui;
QUdpSocket *m_commandUdpSocket = nullptr;
QString m_remoteIP;
int m_remotePort;
CUdpSocket* m_CUdpSocket = nullptr;
ProtocolPodTJ m_protocolPodTJ;
unsigned char getCrc(quint8 *data, quint8 length);
ProtocalKB EncodeCommandCmd(quint8 cmd);
bool writeBufferToClient(const QByteArray &data);
void buttonResponse(quint8 cmd);
void initmUdpParam();
public slots:
void receiveUavTypeIndex(int index);
//设置通信IP及Port 连接udp
void setPodIPConfig(NetworkIPStruct networkIP, bool isConnect);
public:
//设置窗口传递参数
void setMoveParm(QPointF size);
//伺服停止
void stopServo();
//目标跟踪
void setTargetTracking(double dir, double pitch);
//停止跟踪
void setStopTracking();
//滚轮控制变倍
void wheelZoomCtrl(int value);
};
#endif // COMMANDWIDGET_H

File diff suppressed because it is too large Load Diff

@ -18,6 +18,90 @@ CommunicationSettingDlg::~CommunicationSettingDlg() {
void CommunicationSettingDlg::showEvent(QShowEvent *event) {
setSaveSettingParms();
setPodIniSetting();
}
bool CommunicationSettingDlg::isValidIP()
{
QHostAddress addrLocal(ui->podLocalIP->currentText());
QHostAddress addrremote(ui->podRemoteIPEdit->text());
if (addrLocal.isNull() || addrLocal.protocol() != QAbstractSocket::IPv4Protocol)
{
emit sendErrorMessage("本地IP格式错误!", 2);
return false;
}
if (addrremote.isNull() || addrremote.protocol() != QAbstractSocket::IPv4Protocol)
{
emit sendErrorMessage("远端IP格式错误!", 2);
return false;
}
if (ui->podLocalPort->value() == 0 || ui->podRemotePort->value() == 0)
{
emit sendErrorMessage("请输入正确的端口号!", 2);
return false;
}
return true;
}
void CommunicationSettingDlg::savePodIniSetting()
{
g_networkSettingInfo->setValue("PodSetting/localIP",
ui->podLocalIP->currentText());
g_networkSettingInfo->setValue("PodSetting/remoteIP",
ui->podRemoteIPEdit->text());
g_networkSettingInfo->setValue("PodSetting/localPort",
ui->podLocalPort->value());
g_networkSettingInfo->setValue("PodSetting/remotePort",
ui->podRemotePort->value());
}
void CommunicationSettingDlg::setPodIniSetting()
{
ui->podRemoteIPEdit->setText(
g_networkSettingInfo->value("PodSetting/remoteIP", "192.168.1.160").toString());
ui->podRemotePort->setValue(
g_networkSettingInfo->value("PodSetting/remotePort", 10000).toInt());
ui->podLocalPort->setValue(
g_networkSettingInfo->value("PodSetting/localPort", 10001).toInt());
QString localIP =
g_networkSettingInfo->value("PodSetting/localIP").toString();
for (int i = 0; i < ui->podLocalIP->count(); ++i) {
if (localIP == ui->podLocalIP->itemText(i)) {
ui->podLocalIP->setCurrentIndex(i);
}
}
}
void CommunicationSettingDlg::on_podConnectBtn_clicked()
{
if (!isValidIP()) { return; }
savePodIniSetting();
NetworkIPStruct networkIP;
if (!_commIsConnect)//断开时点击连接
{
_commIsConnect = true;//状态为连接
networkIP.localIP = ui->podLocalIP->currentText();
networkIP.remoteIP = ui->podRemoteIPEdit->text();
networkIP.localPort = ui->podLocalPort->value();
networkIP.remotePort = ui->podRemotePort->value();
emit sendPodData(networkIP, _commIsConnect);
ui->podConnectBtn->setText("断开");
}
else
{
_commIsConnect = false;//状态为连接
emit sendPodData(networkIP, _commIsConnect);
ui->podConnectBtn->setText("连接");
}
}
void CommunicationSettingDlg::initCombobox() {
@ -31,10 +115,14 @@ void CommunicationSettingDlg::initNetworkSetting() {
QStringList localIPList;
getLocalIP(localIPList);
ui->localIP->addItems(localIPList);
ui->podLocalIP->addItems(localIPList);
ui->remoteIPEdit->setText(QStringLiteral("223.0.0.1"));
ui->remotePort->setValue(8080);
ui->localPort->setValue(8082);
ui->podRemotePort->setValue(10000);
ui->podLocalPort->setValue(10001);
}
void CommunicationSettingDlg::setSaveSettingParms() {
@ -64,7 +152,7 @@ void CommunicationSettingDlg::setSaveSettingParms() {
QString localIP =
g_networkSettingInfo->value(groupName + "/localIP").toString();
for (int i = 0; i < ui->dataSourceCombox->count(); ++i) {
for (int i = 0; i < ui->localIP->count(); ++i) {
if (localIP == ui->localIP->itemText(i)) {
ui->localIP->setCurrentIndex(i);
}

@ -23,9 +23,11 @@ protected:
signals:
void sendErrorMessage(QString message, int type);
void sendPodData(NetworkIPStruct networkIP, bool isConnect);
private slots:
void on_saveSettingBtn_clicked();
void on_podConnectBtn_clicked();
private:
void initCombobox();
@ -34,8 +36,14 @@ private:
void setSaveSettingParms();
bool isValidIP();
void savePodIniSetting();
void setPodIniSetting();
private:
Ui::CommunicationSettingDlg *ui;
bool _commIsConnect{ false };
};
#endif // COMMUNICATIONSETTINGDLG_H

@ -6,28 +6,34 @@
<rect>
<x>0</x>
<y>0</y>
<width>307</width>
<height>275</height>
<width>600</width>
<height>350</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>4</number>
<property name="minimumSize">
<size>
<width>600</width>
<height>350</height>
</size>
</property>
<property name="rightMargin">
<number>4</number>
<property name="maximumSize">
<size>
<width>600</width>
<height>350</height>
</size>
</property>
<property name="bottomMargin">
<number>4</number>
<property name="windowTitle">
<string>Dialog</string>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>551</width>
<height>171</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
@ -50,7 +56,7 @@
<number>2</number>
</property>
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="1,2">
<layout class="QGridLayout" name="gridLayout" columnstretch="1,0,0,0,0,0">
<property name="leftMargin">
<number>4</number>
</property>
@ -58,62 +64,215 @@
<number>4</number>
</property>
<property name="horizontalSpacing">
<number>7</number>
<number>6</number>
</property>
<item row="1" column="4">
<widget class="QSpinBox" name="remotePort">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum>
</property>
<property name="maximum">
<number>65534</number>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QSpinBox" name="localPort">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum>
</property>
<property name="maximum">
<number>65534</number>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="remoteIPEdit"/>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_4">
<property name="maximumSize">
<size>
<width>150</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>数据来源:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_2">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>本地IP</string>
<string>网络IP</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="localIP"/>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="remoteIPEdit"/>
<item row="0" column="2" colspan="3">
<widget class="QComboBox" name="dataSourceCombox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<item row="1" column="3">
<widget class="QLabel" name="label_12">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>网络IP</string>
<string>网络端口</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<item row="1" column="5" rowspan="2">
<widget class="QWidget" name="widget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="saveSettingBtn">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>数据来源:</string>
<string>保存设置</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="dataSourceCombox"/>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_12">
<item row="2" column="1">
<widget class="QLabel" name="label">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>网络端口:</string>
<string>本地IP</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="remotePort">
<item row="2" column="3">
<widget class="QLabel" name="label_13">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>本地端口:</string>
</property>
</widget>
</item>
<item row="0" column="5">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="2">
<widget class="QComboBox" name="localIP"/>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>20</x>
<y>190</y>
<width>551</width>
<height>131</height>
</rect>
</property>
<property name="title">
<string>吊舱网络设置</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="4">
<widget class="QSpinBox" name="podRemotePort">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum>
</property>
@ -122,8 +281,20 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_13">
<item row="1" column="3">
<widget class="QLabel" name="label_14">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
@ -134,65 +305,152 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="localPort">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum>
<item row="0" column="2">
<widget class="QLineEdit" name="podRemoteIPEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximum">
<number>65534</number>
</widget>
</item>
<item row="0" column="5" rowspan="2">
<widget class="QWidget" name="widget_2" native="true">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="podConnectBtn">
<property name="text">
<string>连接</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
<item row="1" column="2">
<widget class="QComboBox" name="podLocalIP"/>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_3">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>本地IP</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
<item row="1" column="4">
<widget class="QSpinBox" name="podLocalPort">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="sizeHint" stdset="0">
<property name="buttonSymbols">
<enum>QAbstractSpinBox::ButtonSymbols::NoButtons</enum>
</property>
<property name="maximum">
<number>65534</number>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="label_15">
<property name="minimumSize">
<size>
<width>40</width>
<height>20</height>
<width>60</width>
<height>0</height>
</size>
</property>
</spacer>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>远端端口:</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveSettingBtn">
<item row="0" column="1">
<widget class="QLabel" name="label_5">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>保存设置</string>
<string>远端P</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<item row="1" column="0">
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Policy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

@ -59,8 +59,10 @@ MainWindow::MainWindow(QWidget *parent)
initChangeVideoLayoutConnection();
initHideButton();
initWidget();
setSavedVideoDir();
initPodParam();
// ui->stackedWidget->setCurrentIndex(1);
// ui->videoWidget1->play(list.at(0));
// ui->videoWidget2->play(list.at(0));
@ -123,6 +125,9 @@ void MainWindow::initSignalConnection() {
connect(ui->videoControlWidget, &VideoControl::stopVideoSignal, this,
&MainWindow::closeVideoSlot);
connect(&streamAddrSettingsDlg, &StreamAddrSettingsDlg::sendUavTypeIndex, ui->commandWidget, &CommandWidget::receiveUavTypeIndex);
}
void MainWindow::initNotifyMessageConnection() {
@ -132,6 +137,8 @@ void MainWindow::initNotifyMessageConnection() {
&MainWindow::showMessageSlots);
connect(ui->commandWidget, &CommandWidget::sendErrorMessage, this,
&MainWindow::showMessageSlots);
connect(&settingDlg, &CommunicationSettingDlg::sendErrorMessage, this,
&MainWindow::showMessageSlots);
}
void MainWindow::initChangeVideoLayoutConnection() {
@ -319,6 +326,11 @@ void MainWindow::initHideButton() {
&MainWindow::hideCommandWidgetSlot);
}
void MainWindow::initWidget()
{
ui->commandWidget->receiveUavTypeIndex(g_networkSettingInfo->value("NetworkStreamSettings/uavType").toInt());
}
void MainWindow::showSettingDlgSlot() {
settingDlg.exec();
}
@ -506,3 +518,161 @@ void MainWindow::showMap3DSlot() {
m_mapWidget->show();
}
}
void MainWindow::initPodParam()
{
_wheelStopTime = new QTimer(this);
_wheelStopTime->setInterval(300);
_wheelStopTime->setSingleShot(true);
firstLocation = new QLabel(this);
firstLocation->setPixmap(QPixmap(":/images/c.png"));
firstLocation->setScaledContents(true);
firstLocation->resize(30, 30);
firstLocation->setStyleSheet("border: none; background: transparent;");
firstLocation->hide();
lastLocation = new QLabel(this);
lastLocation->setPixmap(QPixmap(":/images/circle.png"));
lastLocation->setScaledContents(true);
lastLocation->resize(25, 25);
lastLocation->setStyleSheet("border: none; background: transparent;");
lastLocation->hide();
connect(&settingDlg, &CommunicationSettingDlg::sendPodData, ui->commandWidget, &CommandWidget::setPodIPConfig);
connect(_wheelStopTime, &QTimer::timeout, this, [this]() {
ui->commandWidget->wheelZoomCtrl(0);
qDebug() << "滚轮停止了";
});
}
void MainWindow::mousePressEvent(QMouseEvent* event)
{
if (ui->videoWidget->underMouse())
{
if (event->button() == Qt::LeftButton)
{
//记录鼠标按下位置
_dragStartPositon = event->pos();
//QPointF b = event->globalPosition();
qDebug() << "局部坐标" << "x" << _dragStartPositon.x() << "y" << _dragStartPositon.y();
//qDebug() << "全局坐标" << "x" << b.x() << "y" << b.y();
_dragFlag = true;
}
else if (event->button() == Qt::RightButton)
{
//鼠标右键取消目标跟踪
ui->commandWidget->setStopTracking();
qDebug() << "取消跟踪";
}
}
}
void MainWindow::mouseMoveEvent(QMouseEvent* event)
{
if (_dragFlag)//点击并且移动
{
QPointF diff = event->pos() - _dragStartPositon;
qDebug() << "x:" << diff.x() << "y:" << diff.y();
ui->commandWidget->setMoveParm(diff);
if (qAbs(diff.x()) > 5 || qAbs(diff.y()) > 5)//像素点超过5ptx才算移动否则为跟踪
{
_moveFlag = true;
firstLocation->move((_dragStartPositon - QPoint(firstLocation->width() / 2, firstLocation->height() / 2)).toPoint());
lastLocation->move(event->pos() - QPoint(lastLocation->width() / 2, lastLocation->height() / 2));
firstLocation->show();
lastLocation->show();
}
QPointF widgetPos = mapFromGlobal(event->globalPosition());
//如果移动的时候超过了画面显示区域,则自动退出伺服控制
if (!ui->videoWidget->rect().contains(widgetPos.toPoint()))
{
_moveFlag = false;
_dragFlag = false;
ui->commandWidget->stopServo();
firstLocation->hide();
lastLocation->hide();
}
}
}
void MainWindow::mouseReleaseEvent(QMouseEvent* event)
{
if (ui->videoWidget->underMouse())
{
if (event->button() == Qt::LeftButton && _moveFlag)
{
_moveFlag = false;
ui->commandWidget->stopServo();
firstLocation->hide();
lastLocation->hide();
}
else if (event->button() == Qt::LeftButton && _dragFlag)
{
// 目标跟踪
QPointF sPoint1 = event->globalPosition();
QPointF widgetPoint = ui->videoWidget->mapFromGlobal(sPoint1);
double a = ui->videoWidget->width();
double b = ui->videoWidget->height();
double dir = 1920 / a * widgetPoint.rx() - 960;
double pitch = -(1080 / b * widgetPoint.ry() - 540);
ui->commandWidget->setTargetTracking(dir, pitch);
qDebug() << "=========>目标跟踪" << " dir:" << dir << " pitch:" << pitch << " a:" << a << " b:" << b;
}
}
}
void MainWindow::wheelEvent(QWheelEvent* event)
{
if (ui->videoWidget->underMouse())
{
// 获取滚轮的滚动方向和角度增量
_delta = event->angleDelta().y();
QPointF currentLocation = event->position();
// qDebug() << "当前位置:" << currentLocation;
if (_delta > 0)
{
// 向上滚动
qDebug() << "鼠标滚轮向上滚动" << " 步长:" << _delta;
// if(wheelSub->isVisible())
// {
// wheelSub->hide();
// }
// wheelPlus->move((currentLocation - QPoint(wheelPlus->width()/2, wheelPlus->height()/2)).toPoint());
// wheelPlus->show();
ui->commandWidget->wheelZoomCtrl(_delta);
}
else if (_delta < 0)
{
// 向下滚动
// if(wheelPlus->isVisible())
// {
// wheelPlus->hide();
// }
// wheelSub->move((currentLocation - QPoint(wheelSub->width()/2, wheelSub->height()/2)).toPoint());
// wheelSub->show();
ui->commandWidget->wheelZoomCtrl(_delta);
qDebug() << "鼠标滚轮事向下滚动" << " 步长:" << _delta;
}
if (!_wheelStopTime->isActive())
{
_wheelStopTime->start();
}
else
{
_wheelStopTime->stop();
_wheelStopTime->start();
}
}
QWidget::wheelEvent(event);
}

@ -22,6 +22,7 @@
#include "windowsx.h"
#pragma comment(lib, "user32.lib")
#endif
#include <QLabel>
namespace QWK {
class WidgetWindowAgent;
@ -54,6 +55,7 @@ protected:
signals:
void themeChanged();
void sendErrorMessage(QString message, int type);
void wheelSendData(int value);
private:
void initSignalConnection();
@ -68,6 +70,7 @@ private:
void setSavedVideoDir();
void initHideButton();
void initWidget();
private slots:
void showSettingDlgSlot();
@ -92,5 +95,23 @@ private:
QToolButton *hideCommandWidgetBtn = nullptr;
WebMapWidget *m_mapWidget = nullptr;
//吊舱人机交互变量
int _delta{0}; //滚轮滚动量
QTimer* _wheelStopTime;
QPointF _dragStartPositon; //记录滑动操作当前点击的局部坐标
bool _dragFlag{false}; //记录滑动初始标志
bool _moveFlag{false}; //记录正在滑动中的标志
QLabel* firstLocation;
QLabel* lastLocation;
void initPodParam();
public:
void mousePressEvent(QMouseEvent* event) override; // 事件过滤器
void mouseMoveEvent(QMouseEvent* event) override; // 事件过滤器
void mouseReleaseEvent(QMouseEvent* event) override;
protected:
void wheelEvent(QWheelEvent* event) override;
};
#endif // MAINWINDOW_H

@ -105,7 +105,14 @@
</layout>
</item>
<item>
<widget class="CommandWidget" name="commandWidget" native="true"/>
<widget class="CommandWidget" name="commandWidget" native="true">
<property name="minimumSize">
<size>
<width>300</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
@ -115,7 +122,7 @@
<x>0</x>
<y>0</y>
<width>1388</width>
<height>24</height>
<height>33</height>
</rect>
</property>
</widget>

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

@ -37,5 +37,7 @@
<file>images/play1.75X.png</file>
<file>images/play1X.png</file>
<file>images/play2X.png</file>
<file>images/c.png</file>
<file>images/circle.png</file>
</qresource>
</RCC>

@ -14,6 +14,7 @@ StreamAddrSettingsDlg::StreamAddrSettingsDlg(QWidget *parent)
uavTypeList.append("FP981C");
uavTypeList.append("FP981CS");
uavTypeList.append("FP981A");
uavTypeList.append("四医大");
ui->uavTypeCombox->insertItems(0, uavTypeList);
//
ui->pushStreamIPCombox->insertItem(0, QStringLiteral("航天飞鹏服务器"));
@ -157,3 +158,11 @@ void StreamAddrSettingsDlg::on_pushStreamBtn_clicked() {
ui->pushStreamBtn->setDisabled(false);
}
void StreamAddrSettingsDlg::on_uavTypeCombox_activated(int index)
{
qDebug() << index;
g_networkSettingInfo->setValue("NetworkStreamSettings/uavType",
ui->uavTypeCombox->currentIndex());
emit sendUavTypeIndex(index);
}

@ -22,6 +22,7 @@ protected:
signals:
void startPullStreamSignal(bool bPull);
void startPushStreamSignal(bool bPush);
void sendUavTypeIndex(int index);
private slots:
void on_pushStreamIPCombox_currentIndexChanged(int index);
@ -32,6 +33,8 @@ private slots:
void on_pushStreamBtn_clicked();
void on_uavTypeCombox_activated(int index);
private:
void initSavedParms();
void saveParms();

@ -0,0 +1,107 @@
#include "CUdpSocket.h"
#include "../global.h"
CUdpSocket::CUdpSocket(QObject* parent) : QObject(parent)
{
//创建UDP套接字内存空间
m_sock = new QUdpSocket;
// 连接数据读取信号槽
connect(m_sock, &QUdpSocket::readyRead, this, &CUdpSocket::on_readyReadData);
}
CUdpSocket::~CUdpSocket()
{
//离开所有加入的组播组
if (m_sock->state() == QAbstractSocket::BoundState) {
m_sock->leaveMulticastGroup(m_hostAddr);
}
// 释放UDP套接字内存空间
m_sock->close();
delete m_sock;
}
bool CUdpSocket::bind(QString ip, ushort port)
{
// 返回绑定函数返回值
m_localIP = ip;
m_localAddr = QHostAddress(ip);
m_localPort = port;
if (!m_sock->bind(QHostAddress(ip), port))
{
qDebug() << "Bind failed:" << m_sock->errorString();
isSocketBind = false;
return false;
}
isSocketBind = true;
return true;
}
void CUdpSocket::sendData(QByteArray data)
{
// 发送传入的数据到指定的信息的位置
if (isSocketBind)
{
m_sock->writeDatagram(data, m_hostAddr, m_port);
}
}
void CUdpSocket::setTargetInfo(QString ip, quint16 port)
{
//存储传入的IP和端口号
m_hostAddr = QHostAddress(ip);
m_port = port;
}
bool CUdpSocket::close()
{
//离开所有加入的组播组
if (m_sock->state() == QAbstractSocket::BoundState) {
m_sock->leaveMulticastGroup(m_hostAddr);
}
m_sock->close();
if (m_sock->state() == QUdpSocket::UnconnectedState) {
qDebug() << "Socket 已成功关闭";
return true;
}
qDebug() << "Socket 关闭失败,当前状态:" << m_sock->state();
return false;
}
bool CUdpSocket::joinMulticast()
{
bool a = isMulticastAddress(m_localIP);
if (m_localIP.isNull() || !isMulticastAddress(m_localIP)) { return false; }
if (!m_sock->joinMulticastGroup(m_localAddr)) {
qDebug() << "Join multicast group failed:" << m_sock->errorString();
return false;
}
return true;
}
QPair<QString, quint16> CUdpSocket::getSenderIPSetting()
{
return qMakePair(m_localIP, m_localPort);
}
void CUdpSocket::on_readyReadData()
{
//通过函数判断当前是否有等待读取的数据并循环获取
while (m_sock->hasPendingDatagrams())
{
//创建数据存储容器,并设置长度为将接收的数据长度
QByteArray data;
data.resize(m_sock->pendingDatagramSize());
//读取数据并保存信息发送者的地址和ip(方便发送时指定发送位置)
m_sock->readDatagram(data.data(), data.size(), &senderIP, &senderPort);
//发送接收数据的信号
emit recvDataSignal(data);
}
}

@ -0,0 +1,53 @@
#ifndef CUDPSOCKET_H
#define CUDPSOCKET_H
#include <QObject>
#include <QUdpSocket>
#include <QHostAddress>
#include <QPair>
class CUdpSocket : public QObject
{ Q_OBJECT
public:
explicit CUdpSocket(QObject* parent = nullptr);
~CUdpSocket();
//绑定本机的ip和端口号信息
bool bind(QString ip, ushort port);
//通过该函数发送数据
void sendData(QByteArray data);
//设置目标主机的ip和端口号
void setTargetInfo(QString ip, quint16 port);
//关闭socket
bool close();
//加入组播
bool joinMulticast();
//获取发送者的IP及端口号
QPair<QString, quint16> getSenderIPSetting();
signals:
//通过该信号传递接收到的数据
void recvDataSignal(QString data);
public slots:
//读取数据的槽函数
void on_readyReadData();
private:
QUdpSocket* m_sock{nullptr}; //UDP套接字指针
QHostAddress m_hostAddr; //保存目标的地址对象
quint16 m_port{0}; //保存目标的端口号(类型一致)
QString m_localIP{""}; //本地IP
QHostAddress m_localAddr; //保存本地的地址对象
quint16 m_localPort{0}; //保存本地的端口号(类型一致)
QHostAddress senderIP; //发送者IP
quint16 senderPort{0}; //发送者端口号
bool isSocketBind{false}; //数据绑定成功or失败
};
#endif

@ -0,0 +1,123 @@
#include "protocolPodTJ.h"
QByteArray ProtocolPodTJ::encode(const QByteArray& cmd, const QByteArray& loadData)
{
QByteArray buffer;
// 帧头
buffer.append(0xFB);
buffer.append(0x2C);
buffer.append(0xAA);
// 帧长指令2字节 + 数据)
quint8 length = 2 + loadData.size();
buffer.append(length);
// 指令(高位在前)
buffer.append(cmd);
// 数据体
buffer.append(loadData);
// 校验(从帧长开始 到最后一个数据字节)
quint8 xorSum = calculateXOR(buffer, 3, buffer.size() - 1);
buffer.append(xorSum);
return buffer;
}
QByteArray ProtocolPodTJ::cmdLeft(uint16_t sliderValue)
{
QByteArray param(4, 0x00);
//小端在前
param[0] = -sliderValue & 0xFF;
param[1] = ((-sliderValue >> 8) & 0xFF);
return param;
}
QByteArray ProtocolPodTJ::cmdRight(uint16_t sliderValue)
{
QByteArray param(4, 0x00);
//小端在前
param[0] = sliderValue & 0xFF;
param[1] = ((sliderValue >> 8) & 0xFF);
return param;
}
QByteArray ProtocolPodTJ::cmdUp(uint16_t sliderValue)
{
QByteArray param(4, 0x00);
//小端在前
param[2] = sliderValue & 0xFF;
param[3]= ((sliderValue >> 8) & 0xFF);
return param;
}
QByteArray ProtocolPodTJ::cmdDown(uint16_t sliderValue)
{
QByteArray param(4, 0x00);
//小端在前
param[2] = -sliderValue & 0xFF;
param[3] = ((-sliderValue >> 8) & 0xFF);
return param;
}
QByteArray ProtocolPodTJ::cmdZoom(uint8_t model, uint8_t speed)
{
QByteArray param(4, 0x00);
//小端在前
param[0] = model;
param[1] = speed;
return param;
}
QByteArray ProtocolPodTJ::cmdLaser(uint8_t fre)
{
QByteArray param(4, 0x00);
//小端在前
param[0] = fre;
return param;
}
QByteArray ProtocolPodTJ::digitalGuid(uint8_t directionAngle, uint8_t pitchAngle)
{
QByteArray param(4, 0x00);
//小端在前
param[0] = (directionAngle * 100) & 0xFF;
param[1] = (((directionAngle * 100) >> 8) & 0xFF);
param[2] = (pitchAngle * 100) & 0xFF;
param[3] = (((pitchAngle * 100) >> 8) & 0xFF);
return param;
}
QByteArray ProtocolPodTJ::cmdServo(int pointX, int pointY)
{
QByteArray param(4, 0x00);
//小端在前
param[0] = pointX & 0xFF;
param[1] = ((pointX >> 8) & 0xFF);
param[2] = pointY & 0xFF;
param[3] = ((pointY >> 8) & 0xFF);
return param;
}
QByteArray ProtocolPodTJ::targetTracking(uint16_t dir, uint16_t pitch)
{
QByteArray param(4, 0x00);
//小端在前
param[0] = dir & 0xFF;
param[1] = ((dir >> 8) & 0xFF);
param[2] = pitch & 0xFF;
param[3] = ((pitch >> 8) & 0xFF);
return param;
}
//数据校验
quint8 ProtocolPodTJ::calculateXOR(const QByteArray& data, int begin, int end)
{
quint8 xorVal = 0;
for (int i = begin; i <= end; ++i) {
xorVal ^= static_cast<quint8>(data[i]);
}
return xorVal;
}

@ -0,0 +1,28 @@
#include <QByteArray>
class ProtocolPodTJ
{
public:
static QByteArray encode(const QByteArray& cmd, const QByteArray& loadData = QByteArray::fromHex("00000000"));
public:
//控制指令
QByteArray cmdLeft(uint16_t sliderValue);
QByteArray cmdRight(uint16_t sliderValue);
QByteArray cmdUp(uint16_t sliderValue);
QByteArray cmdDown(uint16_t sliderValue);
QByteArray cmdZoom(uint8_t model, uint8_t speed);
QByteArray cmdLaser(uint8_t fre);
//数字引导
QByteArray digitalGuid(uint8_t directionAngle, uint8_t pitchAngle);
//伺服控制
QByteArray cmdServo(int pointX, int pointY);
//目标跟踪
QByteArray targetTracking(uint16_t dir, uint16_t pitch);
private:
static quint8 calculateXOR(const QByteArray& data, int begin, int end);
};

@ -0,0 +1,201 @@
#include "switchbutton.h"
#include <QDebug>
WBSwitchButton::WBSwitchButton(QWidget* parent)
: QWidget{ parent }
{
}
bool WBSwitchButton::getSwitch() {
return mOnOff;
}
void WBSwitchButton::setSwitch(bool onoff) {
if (mWaitSigModel) return;
/// 状态切换
mOnOff = onoff;
/// 发送信号
sigSwitchChanged(mOnOff);
/// 动画-背景颜色
QPropertyAnimation* colorAnimation = new QPropertyAnimation(this, "pBackColor");
colorAnimation->setDuration(mAnimationPeriod);
colorAnimation->setStartValue(mBackColor);
colorAnimation->setEndValue(mOnOff ? mBackOnColor : mBackOffColor);
colorAnimation->start(QAbstractAnimation::DeletionPolicy::DeleteWhenStopped); //停止后删除
/// 动画-开关按钮位置
QVariantAnimation* posAnimation = new QVariantAnimation(this);
posAnimation->setDuration(mAnimationPeriod);
posAnimation->setStartValue(mButtonRect.topLeft());
posAnimation->setEndValue(mOnOff ? mRightPos : mLeftPos);
connect(posAnimation, &QPropertyAnimation::valueChanged, [=](const QVariant& value) {
mButtonRect.moveTo(value.toPointF());
update();
});
posAnimation->start(QAbstractAnimation::DeletionPolicy::DeleteWhenStopped); //停止后删除
}
void WBSwitchButton::setSwitchForWaitModel(bool onoff)
{
if (!mWaitSigModel) return;
if (mOnOff == onoff) {
/// 表示值未改变先运行按钮位置动画
QVariantAnimation* posAnimation = new QVariantAnimation(this);
posAnimation->setDuration(mAnimationPeriod);
posAnimation->setStartValue(mOnOff ? mLeftPos : mRightPos);
posAnimation->setEndValue(mOnOff ? mRightPos : mLeftPos);
connect(posAnimation, &QVariantAnimation::valueChanged, [=](const QVariant& value) {
mButtonRect.moveTo(value.toPointF());
update();
});
posAnimation->start(QAbstractAnimation::DeletionPolicy::DeleteWhenStopped); //停止后删除
return;
}
/// 状态切换
mOnOff = onoff;
/// 发送信号
sigSwitchChanged(mOnOff);
/// 后运行背景颜色动画
QPropertyAnimation* colorAnimation = new QPropertyAnimation(this, "pBackColor");
colorAnimation->setDuration(mAnimationPeriod);
colorAnimation->setStartValue(mBackColor);
colorAnimation->setEndValue(mOnOff ? mBackOnColor : mBackOffColor);
colorAnimation->start(QAbstractAnimation::DeletionPolicy::DeleteWhenStopped); //停止后删除
connect(colorAnimation, &QPropertyAnimation::valueChanged, [=](const QVariant& value) {
update();
});
}
void WBSwitchButton::setEnabled(bool enable) {
QWidget::setEnabled(enable);
mEnable = enable;
emit sigEnableChanged(mEnable);
update();
}
bool WBSwitchButton::getEnabled()
{
return mEnable;
}
void WBSwitchButton::setAnimationPeriod(int period) {
mAnimationPeriod = period;
}
void WBSwitchButton::setPrecisionClick(bool flag) {
mPrecisionClickFlagh = flag;
}
void WBSwitchButton::setWaitModel(bool flag)
{
mWaitSigModel = flag;
}
void WBSwitchButton::setButtonColor(QColor color) {
mButtonColor = color;
update();
}
void WBSwitchButton::setBackOnColor(QColor color) {
mBackOnColor = color;
update();
}
void WBSwitchButton::setBackOffColor(QColor color) {
mBackOffColor = color;
update();
}
void WBSwitchButton::setEdgeColor(QColor color) {
mEdgeColor = color;
update();
}
void WBSwitchButton::paintEvent(QPaintEvent* event) {
Q_UNUSED(event)
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(Qt::NoPen);
/// 绘制边缘颜色
QPainterPath path;
path.addRect(this->rect());
path.addRoundedRect(this->rect(), mRadius, mRadius);
path.setFillRule(Qt::OddEvenFill);
painter.setBrush(mEdgeColor);
painter.drawPath(path);
/// 绘制背景颜色
painter.setBrush(mBackColor);
painter.drawRoundedRect(this->rect(), mRadius, mRadius);
/// 绘制圆形按钮
painter.setBrush(mButtonColor);
painter.drawEllipse(mButtonRect);
/// 绘制按钮阴影
painter.setBrush(Qt::NoBrush);
QColor color(Qt::black);
int count = (this->height() - mButtonRect.height()) / 2;
float stepColor = (0.15 - 0.0) / count;
for (int i = mButtonRect.height() / 2 + 1; i < this->height() / 2; i++) {
color.setAlphaF(0.15 - stepColor * (i - mButtonRect.height() / 2));
painter.setPen(color);
painter.drawEllipse(mButtonRect.center(), i, i);
}
/// 失能显示,添加一层蒙层
if (!mEnable) {
QColor disable(Qt::black);
disable.setAlphaF(0.5);
painter.setBrush(disable);
painter.drawRoundedRect(this->rect(), mRadius, mRadius);
}
}
void WBSwitchButton::resizeEvent(QResizeEvent* event) {
Q_UNUSED(event)
/// 更新按钮大小、圆角大小、动画两个位置
int size = qMin(this->width(), this->height());
mRadius = size / 2;
float width = size * 3 / 4;
float border = (size - width) / 2;
mLeftPos = QPoint(border, border);
mRightPos = QPoint(this->width() - border - width, border);
mButtonRect.setWidth(width);
mButtonRect.setHeight(width);
mButtonRect.moveTo(mOnOff ? mRightPos : mLeftPos);
mBackColor = mOnOff ? mBackOnColor : mBackOffColor;
update();
}
void WBSwitchButton::mouseReleaseEvent(QMouseEvent* event) {
if (mWaitSigModel) {
/// 先运行按钮位置动画
QVariantAnimation* posAnimation = new QVariantAnimation(this);
posAnimation->setDuration(mAnimationPeriod);
posAnimation->setStartValue(mOnOff ? mRightPos : mLeftPos);
posAnimation->setEndValue(mOnOff ? mLeftPos : mRightPos);
connect(posAnimation, &QVariantAnimation::valueChanged, [=](const QVariant& value) {
mButtonRect.moveTo(value.toPointF());
update();
});
posAnimation->start(QAbstractAnimation::DeletionPolicy::DeleteWhenStopped); //停止后删除
return;
}
if (!mEnable) return;
if (mButtonRect.contains(event->pos()) || !mPrecisionClickFlagh) {
setSwitch(!mOnOff);
}
}
void WBSwitchButton::enterEvent(QEvent* event) {
Q_UNUSED(event)
mHover = true;
}
void WBSwitchButton::leaveEvent(QEvent* event) {
Q_UNUSED(event)
mHover = false;
}

@ -0,0 +1,70 @@
#ifndef WBSWITCHBUTTON_H
#define WBSWITCHBUTTON_H
#include <QWidget>
#include <QPropertyAnimation>
#include <QPainterPath>
#include <QPainter>
#include <QRadialGradient>
#include <QMouseEvent>
///
/// \brief 基础控件-Switch开关按钮
///
class WBSwitchButton : public QWidget
{
Q_OBJECT
public:
Q_PROPERTY(QColor pBackColor MEMBER mBackColor) //新增背景颜色属性,用于动画
explicit WBSwitchButton(QWidget* parent = nullptr);
bool getSwitch(); /// 获取开关状态
public slots:
void setSwitch(bool onoff); /// 设置开关状态,default:0
void setEnabled(bool enable); /// 设置使能状态,default:1
bool getEnabled(); /// 获取使能状态
void setAnimationPeriod(int period); /// 设置切换状态周期
void setPrecisionClick(bool flag); /// 设置精确点击,即只有点中按钮的时候才开关
void setWaitModel(bool flag); /// 设置等待模式点击后不会主动切换开关需要setSwitch
void setSwitchForWaitModel(bool onoff); /// 设置开关状态,default:0
void setButtonColor(QColor color); /// 设置开关(圆形按钮)颜色
void setBackOnColor(QColor color); /// 设置背景颜色-开
void setBackOffColor(QColor color); /// 设置背景颜色-关
void setEdgeColor(QColor color); /// 设置边缘颜色,默认透明
signals:
void sigEnableChanged(bool enable); /// 使能状态变化信号
void sigSwitchChanged(bool onoff); /// 开关状态变化信号
protected:
void paintEvent(QPaintEvent* event);
void resizeEvent(QResizeEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
private:
bool mOnOff{ 0 }; //开关状态
bool mEnable{ 1 }; //使能状态
bool mPrecisionClickFlagh{ 0 }; //精确点击标志位
bool mWaitSigModel{ 0 }; //等待模式,点击后按钮位置会进行切换,但是颜色需要等待外部信号变动
bool mAnimationOnOff{ 1 }; //动画开关default1
bool mHover{ 0 };
QColor mButtonColor{ Qt::white }; //开关(圆形按钮)颜色
QColor mBackColor{ Qt::red };
QColor mEdgeColor{ Qt::transparent }; //边缘颜色
QRectF mButtonRect; //开关按钮rect
int mRadius{ 8 }; // 开关外观边缘圆角
int mAnimationPeriod{ 200 }; //动画周期
QPointF mRightPos; // 动画位置-开
QPointF mLeftPos; // 动画位置-关
QColor mBackOnColor{ Qt::green }; //背景颜色-开
QColor mBackOffColor{ Qt::darkGray }; //背景颜色-关
};
#endif // WBSWITCHBUTTON_H
Loading…
Cancel
Save