From 97d077aef042942b6726c561ae63aae5d82965f1 Mon Sep 17 00:00:00 2001 From: hm-thinkbook14p Date: Mon, 13 Feb 2023 21:55:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B6=88=E6=81=AF=E8=BE=93?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/CommandUI/CommandUI.cpp | 11 +- App/CommandUI/CommandUI.h | 2 + App/Config/Config.cpp | 55 +- App/Config/Config.h | 10 +- App/Setting/Index0/Global/GlobalSetting.cpp | 129 ++++- App/Setting/Index0/Global/GlobalSetting.h | 15 + App/Setting/Index0/Global/GlobalSetting.ui | 559 ++++++++++++-------- App/Setting/Index0/Index0.qss | 3 + App/mainwindow.cpp | 67 ++- App/mainwindow.h | 5 + MavLinkNode/mavlinknode.cpp | 182 +++++++ MavLinkNode/mavlinknode.h | 22 +- dlink/dlink.cpp | 89 ++++ dlink/dlink.h | 12 +- 14 files changed, 907 insertions(+), 254 deletions(-) diff --git a/App/CommandUI/CommandUI.cpp b/App/CommandUI/CommandUI.cpp index 59f814b..e165c1a 100644 --- a/App/CommandUI/CommandUI.cpp +++ b/App/CommandUI/CommandUI.cpp @@ -742,9 +742,9 @@ void CommandUI::commandAccepted(bool flag,uint16_t command,uint8_t result) if(string.size() > 0) { - QTextToSpeech *tts = new QTextToSpeech(); - tts->say(string); - tts->deleteLater(); + + emit say(string); + emit showMessage(string); } @@ -758,9 +758,8 @@ void CommandUI::commandAccepted(bool flag,uint16_t command,uint8_t result) { if(string.size() > 0) { - QTextToSpeech *tts = new QTextToSpeech(); - tts->say(string); - tts->deleteLater(); + emit say(string); + emit showMessage(string); } diff --git a/App/CommandUI/CommandUI.h b/App/CommandUI/CommandUI.h index 176ee8d..764a41e 100644 --- a/App/CommandUI/CommandUI.h +++ b/App/CommandUI/CommandUI.h @@ -110,6 +110,8 @@ signals: void getAllPoint(int); + void say(QString str); + private slots: void updateUI(void); diff --git a/App/Config/Config.cpp b/App/Config/Config.cpp index 55e1ebb..3a22ed1 100644 --- a/App/Config/Config.cpp +++ b/App/Config/Config.cpp @@ -277,8 +277,59 @@ void Config::setMapType(QVariant type) setJsonObject("Map",obj); } - - +void Config::getBeep(QVariant *value) +{ + QJsonObject obj = getJsonObject("Warnning"); + + *value = obj.value("Beep").toBool(); +} + +void Config::setBeep(QVariant value) +{ + QJsonObject obj; + + obj["Beep"] = value.toBool(); + + setJsonObject("Warnning",obj); +} + +void Config::getTTS(QVariant *value) +{ + QJsonObject obj = getJsonObject("Sound"); + + *value = obj.value("tts").toBool(); +} + +void Config::setTTS(QVariant value) +{ + QJsonObject obj; + + obj["tts"] = value.toBool(); + + setJsonObject("Sound",obj); +} + +void Config::get_ExportInfo(QVariant *state, QVariant *flag, QHostAddress *addr, QVariant *port) +{ + QJsonObject obj = getJsonObject("ExportInfo"); + + *state = obj.value("state").toBool(); + *flag = obj.value("flag").toInt(); + *addr = obj.value("addr").toString(); + *port = obj.value("port").toInt(); +} + +void Config::set_ExportInfo(QVariant state, QVariant flag, QHostAddress addr, QVariant port) +{ + QJsonObject obj; + + obj["state"] = state.toBool(); + obj["flag"] = flag.toInt(); + obj["addr"] = addr.toString(); + obj["port"] = port.toInt(); + + setJsonObject("ExportInfo",obj); +} diff --git a/App/Config/Config.h b/App/Config/Config.h index 263ccb6..7634852 100644 --- a/App/Config/Config.h +++ b/App/Config/Config.h @@ -7,7 +7,7 @@ #include "QJsonDocument" #include "QJsonObject" #include "QJsonParseError" - +#include "QHostAddress" #include "QDebug" class Config : public QObject @@ -44,6 +44,14 @@ public slots: void get_GCS_ID(QVariant *id); void set_GCS_ID(QVariant id); + void get_ExportInfo(QVariant *state, QVariant *flag, QHostAddress *addr, QVariant *port); + void set_ExportInfo(QVariant state, QVariant flag, QHostAddress addr, QVariant port); + + void getBeep(QVariant *value); + void setBeep(QVariant value); + + void getTTS(QVariant *value); + void setTTS(QVariant value); void getServoOffset(QVariant *dirla, QVariant *dirra, QVariant *dirle, QVariant *dirre, QVariant *dirru, QVariant *maxla, QVariant *maxra, QVariant *maxle, QVariant *maxre, QVariant *maxru, diff --git a/App/Setting/Index0/Global/GlobalSetting.cpp b/App/Setting/Index0/Global/GlobalSetting.cpp index d8daac0..5adb3b4 100644 --- a/App/Setting/Index0/Global/GlobalSetting.cpp +++ b/App/Setting/Index0/Global/GlobalSetting.cpp @@ -31,20 +31,14 @@ GlobalSetting::GlobalSetting(QWidget *parent) : ui->doubleSpinBox_right_lng->setValue(135); -// ui->label_mapcache_info->hide(); -// ui->label_maplat->hide(); -// ui->label_maplevel->hide(); -// ui->label_maplng->hide(); -// ui->label_leftmap->hide(); -// ui->label_rightmap->hide(); + ui->comboBox_Beep->addItem(tr("开"),true); + ui->comboBox_Beep->addItem(tr("关"),false); -// ui->doubleSpinBox_left_lat->hide(); -// ui->doubleSpinBox_left_lng->hide(); -// ui->doubleSpinBox_right_lat->hide(); -// ui->doubleSpinBox_right_lng->hide(); + ui->comboBox_TTS->addItem(tr("开"),true); + ui->comboBox_TTS->addItem(tr("关"),false); -// ui->pushButton_map_cache->hide(); -// ui->comboBox_map_level->hide(); + ui->comboBox_export_state->addItem(tr("输出开启"),true); + ui->comboBox_export_state->addItem(tr("输出关闭"),false); @@ -70,6 +64,18 @@ GlobalSetting::GlobalSetting(QWidget *parent) : emit setGCSID(id.toInt());//设置全局ID + QVariant beep; + cfg->getBeep(&beep); + ui->comboBox_Beep->setCurrentIndex(ui->comboBox_Beep->findData(beep.toBool())); + + getBeep(); + + QVariant tts; + cfg->getTTS(&tts); + ui->comboBox_TTS->setCurrentIndex(ui->comboBox_TTS->findData(tts.toBool())); + + emit setTTS(tts.toBool()); + ui->comboBox_dir_la->addItem("1",1); ui->comboBox_dir_la->addItem("-1",-1); @@ -111,11 +117,31 @@ GlobalSetting::GlobalSetting(QWidget *parent) : ui->comboBox_HeartBeat_State->addItem(tr("发送心跳包"),true); ui->comboBox_HeartBeat_State->addItem(tr("关闭心跳包"),false); - ui->comboBox_HeartBeat_State->setCurrentIndex(ui->comboBox_HeartBeat_Frq->findData(state)); + ui->comboBox_HeartBeat_State->setCurrentIndex(ui->comboBox_HeartBeat_State->findData(state)); on_pushButton_getHeartBeat_clicked(); + QVariant flag; + QHostAddress addr; + QVariant port; + + cfg->get_ExportInfo(&state, &flag, &addr, &port); + + ui->comboBox_export_state->setCurrentIndex(ui->comboBox_export_state->findData(state)); + + bool ss = false; + ui->lineEdit_export_flag->setText(QString::number(flag.toUInt())); + ui->lineEdit_export_addr->setText(addr.toString()); + ui->lineEdit_export_port->setText(QString::number(port.toInt())); + + emit setExportInfo(state,flag,addr,port.toInt()); + + + + + + QVariant maptype; cfg->getMapType(&maptype); @@ -588,6 +614,83 @@ void GlobalSetting::SetNumberOfTiles(const int &total, const int &actual) ui->label_mapcache_info->setText(QString(tr("Downloading tile %1 of %2")).arg(actual).arg(total)); } +void GlobalSetting::getExportInfo(void) +{ + on_pushButton_setExport_clicked(); +} + + +void GlobalSetting::on_pushButton_setExport_clicked() +{ + QVariant state,flag; + QHostAddress addr; + qint32 port; + + state = ui->comboBox_export_state->currentData(); + flag = ui->lineEdit_export_flag->text().toInt(); + addr = ui->lineEdit_export_addr->text(); + port = ui->lineEdit_export_port->text().toInt(); + + emit setExportInfo(state,flag,addr,port); + + + Config *cfg = new Config(); + + cfg->set_ExportInfo(state, flag, addr, port); + + cfg->deleteLater(); + delete cfg; + emit showMessage((state.toBool())?(tr("入网输出开启")):(tr("入网输出关闭"))); +} + +void GlobalSetting::getBeep(void) +{ + on_pushButton_Beep_clicked(); +} + +void GlobalSetting::on_pushButton_Beep_clicked() +{ + QVariant state; + + state = ui->comboBox_Beep->currentData(); + + emit setBeep(state.toBool()); + + Config *cfg = new Config(); + + cfg->setBeep(state); + + cfg->deleteLater(); + delete cfg; + + + emit showMessage((state.toBool())?(tr("心跳声音开启")):(tr("心跳声音关闭"))); +} + +void GlobalSetting::getTTS(void) +{ + on_pushButton_TTS_clicked(); +} + +void GlobalSetting::on_pushButton_TTS_clicked() +{ + QVariant state; + + state = ui->comboBox_TTS->currentData(); + + emit setTTS(state.toBool()); + + Config *cfg = new Config(); + + cfg->setTTS(state); + + cfg->deleteLater(); + delete cfg; + + + emit showMessage((state.toBool())?(tr("语音提示开启")):(tr("语音提示关闭"))); +} + diff --git a/App/Setting/Index0/Global/GlobalSetting.h b/App/Setting/Index0/Global/GlobalSetting.h index e95c74c..69ab1f9 100644 --- a/App/Setting/Index0/Global/GlobalSetting.h +++ b/App/Setting/Index0/Global/GlobalSetting.h @@ -5,6 +5,7 @@ #include "QDebug" #include "Config/Config.h" #include "Selector.h" +#include "QHostAddress" namespace Ui { class GlobalSetting; @@ -22,6 +23,9 @@ public: void getGCSID(void); void getServo(void); void getHeartBeat(void); + void getTTS(void); + void getExportInfo(void); + void getBeep(void); public slots: void MapTypes(QStringList list); @@ -57,6 +61,12 @@ private slots: void on_pushButton_map_cache_clicked(); + void on_pushButton_setExport_clicked(); + + void on_pushButton_Beep_clicked(); + + void on_pushButton_TTS_clicked(); + signals: void showMessage(const QString &message,int TimeOut = 0); @@ -70,6 +80,9 @@ signals: void setHeartBeat(QVariant state,QVariant frq); + void setBeep(QVariant beep); + + void setTTS(QVariant flag); void setMapTypes(QVariant value); void getMapTypes(void); @@ -78,6 +91,8 @@ signals: void mapCache(bool start,qreal lat_l,qreal lng_l,qreal lat_r,qreal lng_r,qint8 zoom); void mapCacheCancel(); + void setExportInfo(QVariant value,QVariant id, QHostAddress addr, qint32 port); + private: Ui::GlobalSetting *ui; diff --git a/App/Setting/Index0/Global/GlobalSetting.ui b/App/Setting/Index0/Global/GlobalSetting.ui index d1a0fc6..09b760c 100644 --- a/App/Setting/Index0/Global/GlobalSetting.ui +++ b/App/Setting/Index0/Global/GlobalSetting.ui @@ -6,47 +6,341 @@ 0 0 - 467 - 588 + 772 + 465 Form - - - - - Qt::Horizontal - - - - 40 - 20 - - - + + + + + + + + + 系统设置 + + + + + + 心跳声 + + + + + + + + + + 设置 + + + + + + + 提示声 + + + + + + + + + + 设置 + + + + + + + 设置 + + + + + + + + + + 系统号 + + + + + + + + + + 上传心跳 + + + + + + + + + 频率 + + + + + + + 状态 + + + + + + + 读取 + + + + + + + 保存 + + + + + + + + + + + + + + + 入网输出设置 + + + + + + 标识码 + + + + + + + 1 + + + + + + + IP地址 + + + + + + + 192.168.5.72 + + + + + + + 端口 + + + + + + + 10049 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + 设置 + + + + + + + + + + + + + + + 地图设置 + + + + + + 地图等级 + + + + + + + 8 + + + -90.000000000000000 + + + 90.000000000000000 + + + + + + + 地图缓存信息 + + + + + + + 右下坐标 + + + + + + + 8 + + + -180.000000000000000 + + + 180.000000000000000 + + + + + + + 选择地图 + + + + + + + 左上坐标 + + + + + + + 8 + + + -90.000000000000000 + + + 90.000000000000000 + + + + + + + 0 + + + %v + + + + + + + 地图信息 + + + + + + + + + + 纬度 + + + + + + + 经度 + + + + + + + 8 + + + -180.000000000000000 + + + 180.000000000000000 + + + + + + + start cache + + + + + + + - - - - ID设置 - - - - - - - - - 设置 - - - - - - - + 舵机显示设置 @@ -371,7 +665,20 @@ - + + + + Qt::Horizontal + + + + 40 + 20 + + + + + Qt::Vertical @@ -384,186 +691,6 @@ - - - - 上传心跳 - - - - - - - - - 频率 - - - - - - - 状态 - - - - - - - 读取 - - - - - - - 保存 - - - - - - - - - - - - - 地图设置 - - - - - - 0 - - - %v - - - - - - - 左上坐标 - - - - - - - 地图等级 - - - - - - - 经度 - - - - - - - 纬度 - - - - - - - 右下坐标 - - - - - - - 8 - - - -90.000000000000000 - - - 90.000000000000000 - - - - - - - start cache - - - - - - - 8 - - - -90.000000000000000 - - - 90.000000000000000 - - - - - - - - - - 选择地图 - - - - - - - 8 - - - -180.000000000000000 - - - 180.000000000000000 - - - - - - - 地图缓存信息 - - - - - - - 8 - - - -180.000000000000000 - - - 180.000000000000000 - - - - - - - 地图信息 - - - - - - diff --git a/App/Setting/Index0/Index0.qss b/App/Setting/Index0/Index0.qss index 06328f7..b034f71 100644 --- a/App/Setting/Index0/Index0.qss +++ b/App/Setting/Index0/Index0.qss @@ -18,4 +18,7 @@ font-weight:bold; } +.QLineEdit{ + font :15px "黑体"; +} diff --git a/App/mainwindow.cpp b/App/mainwindow.cpp index df55f57..ec80a8e 100644 --- a/App/mainwindow.cpp +++ b/App/mainwindow.cpp @@ -560,12 +560,6 @@ MainWindow::MainWindow(QWidget *parent) -/* - connect(dlink->mavlinknode->Mission,SIGNAL(currentPoint(int,int)), - toolsui->diagram,SLOT(setTargetPoint(int,int))); - */ - - //=======setting=====tools==== connect(setting->index1->paramInspect,SIGNAL(APversion(QString)), toolsui->servosystem,SLOT(setAPversion(QString))); @@ -577,6 +571,14 @@ MainWindow::MainWindow(QWidget *parent) connect(setting->index0->globalsetting,&GlobalSetting::setServo, toolsui->servosystem,&ServoSystem::setServoOffset); + connect(setting->index0->globalsetting,&GlobalSetting::setBeep, + this,&MainWindow::setBeep); + + connect(setting->index0->globalsetting,&GlobalSetting::setTTS, + this,&MainWindow::setTTS); + + connect(setting->index0->globalsetting,&GlobalSetting::setExportInfo, + dlink,&DLink::setExportInfo); //==== showmessage===== connect(toolsui->servosystem,SIGNAL(showMessage(QString,int)),this,SLOT(showMessage(QString,int))); @@ -588,7 +590,7 @@ MainWindow::MainWindow(QWidget *parent) connect(setting->index0->globalsetting,SIGNAL(showMessage(QString,int)),this,SLOT(showMessage(QString,int))); - + connect(commandUI,&CommandUI::say,this,&MainWindow::TTSsay); //connect(menuBarUI,SIGNAL(NewMessage(QString)),toolsui->index1,SLOT(setLog(QString)),Qt::DirectConnection); @@ -629,8 +631,10 @@ MainWindow::MainWindow(QWidget *parent) //设置地面站ID setting->index0->globalsetting->getGCSID(); setting->index0->globalsetting->getServo(); - setting->index0->globalsetting->getHeartBeat(); + setting->index0->globalsetting->getBeep(); + setting->index0->globalsetting->getTTS(); + setting->index0->globalsetting->getExportInfo(); } @@ -1006,13 +1010,48 @@ void MainWindow::showMessage(const QString &message, int TimeOut) void MainWindow::beep(int id) { - if(map->getUAVCurrent() == id) + if(isEnableBeep) { - QApplication::beep(); + if(map->getUAVCurrent() == id) + { + QApplication::beep(); + //Beep(455,50); + } } } +void MainWindow::setBeep(QVariant state) +{ + isEnableBeep = state.toBool(); +} + +void MainWindow::setTTS(QVariant state) +{ + isEnableTTS = state.toBool(); +} + +void MainWindow::TTSsay(QString str) +{ + //qDebug() << u8"播报语音"; + //把要说的话加入队列 + if(isEnableTTS) + { + //qDebug() << u8"把要说的话加入到队列"; + if(!tts) + { + tts = new QTextToSpeech(); + } + + if(tts->state() == QTextToSpeech::Ready) + { + //qDebug() << u8"准备开始播放语音"; + //TTS有问题,可能会导致死机 + tts->say(str); + } + } +} + void MainWindow::setCommunicationLostState(bool flag) { @@ -1027,7 +1066,7 @@ void MainWindow::setCommunicationLostState(bool flag) if(last != flag) { showMessage(tr("Communication Lost"),3000); - tts->say(tr("Communication Lost")); + TTSsay(tr("Communication Lost")); } healthui->setState(1,HealthUI::state::failure); @@ -1082,7 +1121,7 @@ void MainWindow::setCommunicationLostState(bool flag) if(last != flag) { showMessage(tr("Communication Regain"),3000); - tts->say(tr("Communication Regain")); + TTSsay(tr("Communication Regain")); } } @@ -1426,13 +1465,13 @@ void MainWindow::updateUI()//事件驱动式更新数据 if(isStateChanged == true) { - tts->say(arm_str); + TTSsay(arm_str); } if(isCustomChanged == true) { mode_str.append(tr("flight mode")); - tts->say(mode_str); + TTSsay(mode_str); } diff --git a/App/mainwindow.h b/App/mainwindow.h index ef67eac..279043e 100644 --- a/App/mainwindow.h +++ b/App/mainwindow.h @@ -75,7 +75,10 @@ public slots: void setCommunicationLostState(bool flag); void beep(int id); + void setBeep(QVariant state); + void TTSsay(QString str); + void setTTS(QVariant state); void setServoOffset(QVariant dirla, QVariant dirra, QVariant dirle, QVariant dirre, QVariant dirru, QVariant maxla, QVariant maxra, QVariant maxle, QVariant maxre, QVariant maxru, @@ -168,6 +171,8 @@ protected: bool isEngineStartUp = false; + bool isEnableBeep = true; + bool isEnableTTS = true; QVariant dir_la; QVariant dir_ra; diff --git a/MavLinkNode/mavlinknode.cpp b/MavLinkNode/mavlinknode.cpp index 3aff732..c330533 100644 --- a/MavLinkNode/mavlinknode.cpp +++ b/MavLinkNode/mavlinknode.cpp @@ -1276,7 +1276,26 @@ void MavLinkNode::StatusParse(mavlink_message_t msg) gpsTimer.min = min; gpsTimer.sec = sec; + _showinfo info; + info.flag = 0x23F8; + info.id = infoExportID;//1 + info.time = (int32_t)vehicle.ins1.time;//(second+min*60+hour*3600)*1000 + info.lng = vehicle.ins1.lon * 10000000;//*10000000 + info.lat = vehicle.ins1.lat * 10000000;//*10000000 + info.alt = vehicle.ins1.alt * 100;//*100 + info.ve = vehicle.ins1.v_east * 100;//*100 + info.vn = vehicle.ins1.v_north * 100;//*100 + info.vu = vehicle.ins1.v_up * 100;//*100 + info.v = sqrt(vehicle.ins1.v_east * vehicle.ins1.v_east + + vehicle.ins1.v_north * vehicle.ins1.v_north + + vehicle.ins1.v_up * vehicle.ins1.v_up) * 100;//*100 + info.course = vehicle.ins1.yaw * 100;//*100 + + + //qDebug() << "infoExportID" << infoExportID; + + infoExport(info); @@ -1938,3 +1957,166 @@ void MavLinkNode::serial_control(void) } + +void MavLinkNode::infoExport(_showinfo info) +{ + uint8_t buff[250]; + int dataCount = 0; + + union {uint8_t B[4];uint16_t D[2];int32_t H;}src; + +#if 0 + src.D[0] = info.flag; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.D[0] = info.id; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = info.time; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = info.lng; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = info.lat; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = info.alt; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = info.ve; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = info.vn; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = info.vu; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = info.v; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = info.course; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = 0; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; + + src.H = 0; + buff[dataCount++] = src.B[3]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[0]; +#else + src.D[0] = info.flag; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + + src.D[0] = info.id; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + + src.H = info.time; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = info.lng; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = info.lat; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = info.alt; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = info.ve; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = info.vn; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = info.vu; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = info.v; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = info.course; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = 0; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + + src.H = 0; + buff[dataCount++] = src.B[0]; + buff[dataCount++] = src.B[1]; + buff[dataCount++] = src.B[2]; + buff[dataCount++] = src.B[3]; + +#endif + + emit SendMessageToExport(0,buff,dataCount); +} + + diff --git a/MavLinkNode/mavlinknode.h b/MavLinkNode/mavlinknode.h index e125ba0..212af63 100644 --- a/MavLinkNode/mavlinknode.h +++ b/MavLinkNode/mavlinknode.h @@ -81,6 +81,22 @@ public: }_vehicle; + typedef struct + { + uint16_t flag;//0x24a8 + uint16_t id;//1 + int32_t time;//(second+min*60+hour*3600)*1000 + int32_t lng;//*10000000 + int32_t lat;//*10000000 + int32_t alt;//*100 + int32_t ve;//*100 + int32_t vn;//*100 + int32_t vu;//*100 + int32_t v;//*100 + int32_t course;//*100 + int32_t backup1;//*100 + int32_t backup2;//*100 + }_showinfo;//192.168.5.72:10049 @@ -153,7 +169,7 @@ public: QFile * ccmstate_file = nullptr; QFile * serial_control_file = nullptr; - + int infoExportID = 1; signals: void signal_autopilot_version(mavlink_autopilot_version_t); @@ -210,6 +226,8 @@ signals: void heartbeatTimeStamp(quint32 time); + + void SendMessageToExport(quint8 ch, quint8 *data,quint16 len); public slots: //线程对外接口 void CreateCSV(void); @@ -232,6 +250,8 @@ public slots: void serial_control(void); void Transmit(QString msg); + void infoExport(_showinfo info); + private slots: //线程私有接口 void process(); diff --git a/dlink/dlink.cpp b/dlink/dlink.cpp index e5abff8..f0a98f7 100644 --- a/dlink/dlink.cpp +++ b/dlink/dlink.cpp @@ -15,6 +15,10 @@ DLink::DLink(QObject *parent) : QObject(parent) connect(mavlinknode,SIGNAL(SendMessageTo(quint8,quint8*,quint16)), this,SLOT(SendMessageTo(quint8,quint8*,quint16)),Qt::BlockingQueuedConnection);//BlockingQueuedConnection);//信号和槽必须在不同的线程中,否则就产生死锁 + connect(mavlinknode,SIGNAL(SendMessageToExport(quint8,quint8*,quint16)), + this,SLOT(SendMessageToExport(quint8,quint8*,quint16)),Qt::BlockingQueuedConnection);//BlockingQueuedConnection);//信号和槽必须在不同的线程中,否则就产生死锁 + + //在当前线程运行 connect(mavlinknode,SIGNAL(showMessage(QString,int)), this,SIGNAL(showMessage(QString,int))); @@ -24,6 +28,16 @@ DLink::DLink(QObject *parent) : QObject(parent) mavlinknode,SLOT(setbuff(quint32,QByteArray)),Qt::DirectConnection); + Exportsock = new QUdpSocket(this); + int rst = Exportsock->bind(QHostAddress::AnyIPv4,10000); + if(rst) + { + if(Exportsock->open(QIODevice::ReadWrite)) + { + qDebug() << "信息输出端口打开正常"; + } + } + PPSTimer = new QTimer(); PPSTimer->setInterval(1000); @@ -64,6 +78,14 @@ DLink::~DLink() delete mavlinknode; mavlinknode = nullptr; + if(Exportsock) + { + Exportsock->abort(); + delete Exportsock; + Exportsock = nullptr; + } + + if(PPSTimer) { PPSTimer->stop(); @@ -91,6 +113,73 @@ void DLink::timeout() } } + + + +void DLink::setExportInfo(QVariant value,QVariant id, QHostAddress addr, qint32 port) +{ + isExportInfo = value.toBool(); + + if(isExportInfo) + { + if(!Exportsock) + { + Exportsock = new QUdpSocket(this); + int rst = Exportsock->bind(QHostAddress::AnyIPv4,10000); + if(rst) + { + if(Exportsock->open(QIODevice::ReadWrite)) + { + qDebug() << "信息输出端口打开正常"; + } + } + } + } + else + { + if(Exportsock) + { + Exportsock->abort(); + delete Exportsock; + Exportsock = nullptr; + } + } + + + if(mavlinknode) + { + mavlinknode->infoExportID = id.toInt(); + } + + Export_addr = addr; + Export_port = port; + + qDebug() << "isExportInfo" << value + << id + << addr + << port; +} + +int DLink::SendMessageToExport(quint8 ch, quint8 *msg, quint16 len) +{ + Q_UNUSED(ch) + + if(isExportInfo)//使能输出再输出 + { + if(Exportsock) + { + qint64 flag = Exportsock->writeDatagram((const char *)msg,len,Export_addr, Export_port); + if(flag != -1) + { + qDebug() << "export Client Send Msg" << Export_addr < clientSockets; QList serials; @@ -160,6 +165,11 @@ protected: qint32 multicast_transmit_port; + QHostAddress Export_addr; + qint32 Export_port; + + + QTimer *PPSTimer = nullptr; };