diff --git a/Src/GDDC/gddcSet.cpp b/Src/GDDC/gddcSet.cpp index fe40f5f..798d5b9 100644 --- a/Src/GDDC/gddcSet.cpp +++ b/Src/GDDC/gddcSet.cpp @@ -273,3 +273,15 @@ void GDDCSet::setNetCtrlText(QString param) { void GDDCSet::setPushStreamText(QString param) { ui->pushButton_pushURL->setText(param); } + +// uavID值改变事件 +void GDDCSet::on_uavIDSpinBox_valueChanged(int arg1) { + int uavID = arg1; + auto iter = g_mapAppName.find(uavID); + if (iter != g_mapAppName.end()) { + QString pushURL = + generatePushURL(uavID, QString::fromStdString(iter->second)); + ui->lineEdit_pushURL->setText(pushURL); + } else { + } +} diff --git a/Src/GDDC/gddcSet.h b/Src/GDDC/gddcSet.h index 9135104..ae15381 100644 --- a/Src/GDDC/gddcSet.h +++ b/Src/GDDC/gddcSet.h @@ -2,6 +2,7 @@ #define GDDCSET_H #include "Src/GDDC/structDefineMyslef.h" +#include "global.h" #include #include #include @@ -32,12 +33,11 @@ public: QString m_playURL2; // 光电吊舱-视频连接-显示窗口2-URL地址 QString m_pushURL; // 光电吊舱-推流URL地址 MyPairNetwork m_myPairNetwork; // 网络通信结构体 - QString m_FlowType; // 流类型 + QString m_FlowType; // 流类型 QString streamTypeToflowType(QString); QString flowTypeTostreamType(QString); - void setConnectURL1Text(QString); void setConnectURL2Text(QString); void setNetCtrlText(QString); @@ -61,7 +61,8 @@ private slots: void on_pushButton_serialControlConnect_clicked(); // 串口控制-连接 void on_pushButton_NetCtrlConnect_clicked(); // 网络控制-连接 void on_pushButton_pushURL_clicked(); // 推流 - //void on_comboBox_streamType_currentIndexChanged(int index); + // void on_comboBox_streamType_currentIndexChanged(int index); + void on_uavIDSpinBox_valueChanged(int arg1); }; #endif // GDDCSET_H diff --git a/Src/GDDC/gddcSet.ui b/Src/GDDC/gddcSet.ui index bb5b352..41370a4 100644 --- a/Src/GDDC/gddcSet.ui +++ b/Src/GDDC/gddcSet.ui @@ -34,7 +34,7 @@ - 440 + 500 60 61 21 @@ -47,9 +47,9 @@ - 510 + 560 60 - 72 + 61 23 @@ -70,7 +70,7 @@ - 20 + 10 60 71 21 @@ -83,9 +83,9 @@ - 90 + 80 60 - 331 + 411 23 @@ -93,9 +93,9 @@ - 600 + 630 60 - 80 + 61 23 @@ -155,7 +155,7 @@ - 20 + 10 100 71 21 @@ -168,19 +168,22 @@ - 90 + 80 100 - 491 + 411 23 + + true + - 600 + 630 100 - 80 + 61 23 @@ -188,6 +191,38 @@ 推送 + + + + 500 + 100 + 61 + 21 + + + + 飞机ID: + + + + + + 560 + 100 + 61 + 23 + + + + QAbstractSpinBox::ButtonSymbols::NoButtons + + + 255 + + + QAbstractSpinBox::StepType::DefaultStepType + + diff --git a/global.cpp b/global.cpp index 8b12e3c..954e3bf 100644 --- a/global.cpp +++ b/global.cpp @@ -154,3 +154,52 @@ uint16_t calCRC16(const uint8_t *cpu8Data, uint16_t u16Len) { } return u16CRC; } + +/** + * @brief 计算字符串MD5值 + * @param str:字符串 + * @return 字符串MD5值 + */ +QString calculateMD5(const QString &str) { + QByteArray hash = + QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Md5); + return hash.toHex(); +} + +/** + * @brief 生成推流地址 + * @param uavID: 飞控ID + * @param uavName: 飞机型号,默认981cs + * @param clientID: 客户端ID,0为地面端,1为载荷端。 + * @param pushDomain: 推流域名 + * @param appName: app名称 + * @param expireTime: 过期时间(单位是秒),默认1h。 + * @return 返回推流地址 + */ +QString generatePushURL(int uavID, QString appName, QString uavName, + int clientID, QString pushDomain, long expireTime, + QString pushKey) { + QString clientName = ""; + if (0 == clientID) { + clientName = "gcs"; // 地面端 + } else { + clientName = "uav"; // 载荷端 + } + QString streamName = + uavName + "_" + QString::number(uavID) + "_" + clientName; + QString pushURL = ""; + if (pushKey == "") { + pushURL = "rtmp://" + pushDomain + "/" + appName + "/" + streamName; + } else { + // 计算鉴权串 + long timeStamp = QDateTime::currentMSecsSinceEpoch() / 1000 + expireTime; + QString stringToMd5 = "/" + appName + "/" + streamName + "-" + + QString::number(timeStamp) + "-0-0-" + pushKey; + QString authKey = calculateMD5(stringToMd5); + pushURL = "rtmp://" + pushDomain + "/" + appName + "/" + streamName + + "?auth_key=" + QString::number(timeStamp) + "-0-0-" + authKey; + } + return pushURL; +} + +std::map g_mapAppName; diff --git a/global.h b/global.h index 11fd27c..918cd6a 100644 --- a/global.h +++ b/global.h @@ -2,8 +2,11 @@ #define GLOBAL_H #include +#include +#include +#include -extern QString g_SoftwareVersion; //软件版本号 +extern QString g_SoftwareVersion; // 软件版本号 /*******************系统颜色***************************************/ extern QColor g_themeColor; @@ -21,10 +24,35 @@ extern QString g_ToolBtnSelStyle; */ extern uint16_t calCRC16(const uint8_t *cpu8Data, uint16_t u16Len); -class global -{ +/** + * @brief 计算字符串MD5值 + * @param str:字符串 + * @return 字符串MD5值 + */ +extern QString calculateMD5(const QString &str); + +/** + * @brief 生成推流地址 + * @param uavID: 飞控ID + * @param uavName: 飞机型号,默认981cs + * @param clientID: 客户端ID,0为地面端,1为载荷端。 + * @param pushDomain: 推流域名 + * @param appName: app名称 + * @param expireTime: 过期时间(单位是秒),默认1h。 + * @param pushKey: 推流域名配置的鉴权Key + * @return 返回推流地址 + */ +extern QString generatePushURL(int uavID, QString appName = "nmyj", + QString uavName = "981cs", int clientID = 0, + QString pushDomain = "push.htsdfp.com", + long expireTime = 4 * 3600, + QString pushKey = "2G2Fu4MXO9D9Hrs7"); + +extern std::map g_mapAppName; + +class global { public: - global(); + global(); }; #endif // GLOBAL_H diff --git a/mainwindow.cpp b/mainwindow.cpp index 469628b..357f778 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -34,6 +34,8 @@ MainWindow::MainWindow(QWidget *parent) QString appDir = QCoreApplication::applicationDirPath() + "/app"; qDebug() << "Open file fail " << appDir; + + initUAVIDMap(); } MainWindow::~MainWindow() { @@ -357,3 +359,14 @@ void MainWindow::changeBtnColor(int num) { break; } } + +/** + * @brief 初始化UAVID与推流APPName的映射关系 + */ +void MainWindow::initUAVIDMap() { + g_mapAppName[5] = "nmyj"; + g_mapAppName[7] = "nmyj"; + for (int i = 8; i < 13; ++i) { + g_mapAppName[i] = "jsyj"; + } +} diff --git a/mainwindow.h b/mainwindow.h index 5b262f0..e5abac1 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -74,5 +74,11 @@ private: public: void changeBtnColor(int num); + +private: + /** + * @brief 初始化UAVID与推流APPName的映射关系 + */ + void initUAVIDMap(); }; #endif // MAINWINDOW_H