添加广播MDNS服务
This commit is contained in:
@@ -56,6 +56,20 @@
|
||||
|
||||
#define SET_LOG_LEVEL 0x0360
|
||||
|
||||
// 前后板设备信息
|
||||
#define GET_FRONT_V851_VERSION 0x0400
|
||||
#define GET_FRONT_MCU_VERSION 0x0401
|
||||
#define GET_FRONT_HW_VERSION 0x0402
|
||||
#define GET_FRONT_ALGO_VERSION 0x0403
|
||||
#define GET_FRONT_SN 0x0404
|
||||
|
||||
#define GET_FRONT_HW_INFO 0x0420
|
||||
#define WRITE_FRONT_LICENSE 0x0421
|
||||
|
||||
#define GET_BACK_V851_VERSION 0x0450
|
||||
#define GET_BACK_806_VERSION 0x0451
|
||||
#define GET_BACK_HW_VERSION 0x0452
|
||||
#define GET_BACK_SN 0x0453
|
||||
#define GET_BACK_UID 0x0454
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,16 +2,20 @@
|
||||
#include "RecvDataHandler.h"
|
||||
#include "../Network/ClientHandler.h"
|
||||
|
||||
DataHandler::DataHandler(QLabel* leftLens_imageLabel, QLabel* rightLens_imageLabel, QLabel* videoLabel, QObject* parent)
|
||||
DataHandler::DataHandler(QLabel* leftLens_imageLabel, QLabel* rightLens_imageLabel, QLabel* videoLabel,
|
||||
QTextEdit* licenseHwInfoEdit, QMap<QString, QLineEdit*>* devInfoLineEdits, QObject* parent)
|
||||
: QObject(parent),
|
||||
leftLens_m_imageLabel(leftLens_imageLabel),
|
||||
rightLens_m_imageLabel(rightLens_imageLabel),
|
||||
videoLabel(videoLabel),
|
||||
licenseHwInfoEdit(licenseHwInfoEdit),
|
||||
devInfoLineEdits(devInfoLineEdits),
|
||||
ffmpegDecoder(new FFmpegDecoder()), // 初始化FFmpeg解码器
|
||||
buffer(new QByteArray())
|
||||
{
|
||||
ffmpegDecoder->initialize(); // 初始化解码器
|
||||
ffmpegDecoder->initialize(); // 初始化解码器
|
||||
clearAllRecvData();
|
||||
initializeMsgIdToCmdMap();
|
||||
}
|
||||
|
||||
DataHandler::~DataHandler()
|
||||
@@ -26,7 +30,6 @@ DataHandler::~DataHandler()
|
||||
buffer = nullptr;
|
||||
}
|
||||
|
||||
// 将十六进制字符串转换为 QByteArray
|
||||
QByteArray DataHandler::hexStringToByteArray(const QString& hexString)
|
||||
{
|
||||
QByteArray byteArray;
|
||||
@@ -65,6 +68,19 @@ void DataHandler::showVideo(const QString& client, const QByteArray& valData)
|
||||
//ffmpegDecoder->decodeFile(filePath_1, videoLabel);
|
||||
}
|
||||
|
||||
void DataHandler::updateLineEdit(int msg_id, const QByteArray& actual_data) {
|
||||
QString dataStr = QString(actual_data.toHex(' '));
|
||||
licenseHwInfoEdit->setPlainText(dataStr);
|
||||
|
||||
if (msgIdToCmdMap.contains(msg_id)) {
|
||||
QString cmd = msgIdToCmdMap[msg_id];
|
||||
if (devInfoLineEdits->contains(cmd)) {
|
||||
QLineEdit* lineEdit = devInfoLineEdits->value(cmd);
|
||||
lineEdit->setText(dataStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DataHandler::clearAllRecvData() {
|
||||
allRecvData = QByteArray();
|
||||
remain = 0;
|
||||
@@ -93,12 +109,10 @@ void DataHandler::handleData(const QString& client, const QByteArray& recvData,
|
||||
#endif
|
||||
|
||||
//qDebug() << "---Received data size:" << recvData.size();
|
||||
|
||||
// 将接收到的数据追加到buffer
|
||||
buffer->append(recvData);
|
||||
|
||||
while (buffer->size() >= 11) { // 至少需要11个字节来解析数据头
|
||||
// 检查数据头
|
||||
if (buffer->mid(0, 4) == QByteArray::fromHex("aa55aa55")) {
|
||||
msg_id = (static_cast<unsigned char>(buffer->at(5)) << 8) |
|
||||
(static_cast<unsigned char>(buffer->at(4)));
|
||||
@@ -122,7 +136,7 @@ void DataHandler::handleData(const QString& client, const QByteArray& recvData,
|
||||
// 同一个client仅当 msg_id 不连续为 0x11/0x21 或第一次处理时才执行 emit statusUpdated
|
||||
if ((msg_id != 0x0011 || clientLastMsgId.value(client, 0) != 0x0011) &&
|
||||
(msg_id != 0x0021 || clientLastMsgId.value(client, 0) != 0x0021)){
|
||||
qDebug() << "Emitting statusUpdated for client:" << client << "with msg_id:" << msg_id;
|
||||
qDebug() << "Emitting statusUpdated for client:" << client << "with msg_id:" << QString::number(msg_id, 16).toUpper();
|
||||
emit statusUpdated(client, currentRecvItemIndex + 1, currentRecvFuncItemIndex + 1,
|
||||
true, itemData, funcItemData);
|
||||
}
|
||||
@@ -139,6 +153,33 @@ void DataHandler::handleData(const QString& client, const QByteArray& recvData,
|
||||
}
|
||||
}
|
||||
|
||||
void DataHandler::initializeMsgIdToCmdMap() {
|
||||
msgIdToCmdMap[GET_FRONT_V851_VERSION] = "GET_FRONT_V851_VERSION";
|
||||
msgIdToCmdMap[GET_FRONT_MCU_VERSION] = "GET_FRONT_MCU_VERSION";
|
||||
msgIdToCmdMap[GET_FRONT_HW_VERSION] = "GET_FRONT_HW_VERSION";
|
||||
msgIdToCmdMap[GET_FRONT_ALGO_VERSION] = "GET_FRONT_ALGO_VERSION";
|
||||
msgIdToCmdMap[GET_FRONT_SN] = "GET_FRONT_SN";
|
||||
|
||||
msgIdToCmdMap[GET_BACK_V851_VERSION] = "GET_BACK_V851_VERSION";
|
||||
msgIdToCmdMap[GET_BACK_806_VERSION] = "GET_BACK_806_VERSION";
|
||||
msgIdToCmdMap[GET_BACK_HW_VERSION] = "GET_BACK_HW_VERSION";
|
||||
msgIdToCmdMap[GET_BACK_SN] = "GET_BACK_SN";
|
||||
msgIdToCmdMap[GET_BACK_UID] = "GET_BACK_UID";
|
||||
}
|
||||
|
||||
void DataHandler::handleCmd(int msg_id, const QString& client, QByteArray actual_data)
|
||||
{
|
||||
if (msg_id < 0x0400) {
|
||||
handleFrontCmd(msg_id, client, actual_data);
|
||||
}
|
||||
else if (msg_id < 0x0500) {
|
||||
handleDevInfo(msg_id, client, actual_data);
|
||||
}
|
||||
else if (msg_id < 0x0800) {
|
||||
handleBackCmd(msg_id, client, actual_data);
|
||||
}
|
||||
}
|
||||
|
||||
void DataHandler::handleFrontCmd(int msg_id, const QString& client, QByteArray actual_data)
|
||||
{
|
||||
switch (msg_id) {
|
||||
@@ -381,26 +422,67 @@ void DataHandler::handleFrontCmd(int msg_id, const QString& client, QByteArray a
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case SET_LOG_LEVEL:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DataHandler::handleDevInfo(int msg_id, const QString& client, QByteArray actual_data)
|
||||
{
|
||||
switch (msg_id) {
|
||||
case GET_FRONT_V851_VERSION:
|
||||
case GET_FRONT_MCU_VERSION:
|
||||
case GET_FRONT_HW_VERSION:
|
||||
case GET_FRONT_ALGO_VERSION:
|
||||
case GET_FRONT_SN:
|
||||
|
||||
case GET_BACK_V851_VERSION:
|
||||
case GET_BACK_806_VERSION:
|
||||
case GET_BACK_HW_VERSION:
|
||||
case GET_BACK_SN:
|
||||
case GET_BACK_UID:
|
||||
{
|
||||
// aa55aa5503041d00000048464d3231305f4b3431343234395f423230323031305f41302e302e38
|
||||
qDebug() << "GET_DEV_INFO";
|
||||
QString dataStr = QString::fromUtf8(actual_data);
|
||||
if (msgIdToCmdMap.contains(msg_id)) {
|
||||
QString cmd = msgIdToCmdMap[msg_id];
|
||||
if (devInfoLineEdits->contains(cmd)) {
|
||||
QLineEdit* lineEdit = devInfoLineEdits->value(cmd);
|
||||
lineEdit->setText(dataStr);
|
||||
}
|
||||
}
|
||||
//qDebug() << "GET_DEV_INFO msg_id:" << QString::number(msg_id, 16).toUpper();
|
||||
}
|
||||
break;
|
||||
case GET_FRONT_HW_INFO:
|
||||
{
|
||||
qDebug() << "GET_FRONT_HW_INFO";
|
||||
QString dataStr = QString(actual_data.toHex(' '));
|
||||
QString displayText = "get_hw_info:\n" + dataStr;
|
||||
licenseHwInfoEdit->setPlainText(displayText);
|
||||
}
|
||||
break;
|
||||
case WRITE_FRONT_LICENSE:
|
||||
{
|
||||
qDebug() << "WRITE_FRONT_LICENSE";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DataHandler::handleBackCmd(int msg_id, const QString& client, QByteArray actual_data)
|
||||
{
|
||||
switch (msg_id) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void DataHandler::handleCmd(int msg_id, const QString& client, QByteArray actual_data)
|
||||
{
|
||||
if (msg_id < 0x0400) {
|
||||
handleFrontCmd(msg_id, client, actual_data);
|
||||
}
|
||||
else if (msg_id < 0x0800) {
|
||||
handleBackCmd(msg_id, client, actual_data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include <QFile>
|
||||
#include <QThread>
|
||||
#include <QElapsedTimer>
|
||||
#include <QLineEdit>
|
||||
#include <QTextEdit>
|
||||
#include "../Media/Media.h"
|
||||
#include "../ParseDataHandler/msgID.h"
|
||||
#include "../Media/VideoDecoder/FFmpegDecoder.h"
|
||||
@@ -30,7 +32,8 @@ class DataHandler : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DataHandler(QLabel* leftLens_imageLabel, QLabel* rightLens_imageLabel, QLabel* videoLabel, QObject* parent = nullptr);
|
||||
explicit DataHandler(QLabel* leftLens_imageLabel, QLabel* rightLens_imageLabel, QLabel* videoLabel,
|
||||
QTextEdit* licenseHwInfoEdit, QMap<QString, QLineEdit*>* devInfoLineEdits, QObject* parent = nullptr);
|
||||
~DataHandler();
|
||||
|
||||
public slots:
|
||||
@@ -45,6 +48,7 @@ private:
|
||||
QLabel* leftLens_m_imageLabel;
|
||||
QLabel* rightLens_m_imageLabel;
|
||||
QLabel* videoLabel;
|
||||
QTextEdit* licenseHwInfoEdit;
|
||||
QByteArray allRecvData; // 完整的一帧数据
|
||||
int remain = 0;
|
||||
int start_run = 0;
|
||||
@@ -52,6 +56,8 @@ private:
|
||||
FFmpegDecoder* ffmpegDecoder;
|
||||
QByteArray *buffer;
|
||||
QHash<QString, unsigned char> clientLastMsgId;
|
||||
QMap<QString, QLineEdit*>* devInfoLineEdits;
|
||||
QMap<int, QString> msgIdToCmdMap;
|
||||
|
||||
// 如果接收十六进制数据,转为二进制
|
||||
QByteArray hexStringToByteArray(const QString& hexString);
|
||||
@@ -59,7 +65,10 @@ private:
|
||||
void clearAllRecvData();
|
||||
void handleCmd(int msg_id, const QString& client, QByteArray actual_data);
|
||||
void handleFrontCmd(int msg_id, const QString& client, QByteArray actual_data);
|
||||
void handleDevInfo(int msg_id, const QString& client, QByteArray actual_data);
|
||||
void handleBackCmd(int msg_id, const QString& client, QByteArray actual_data);
|
||||
void initializeMsgIdToCmdMap();
|
||||
void updateLineEdit(int msg_id, const QByteArray& actual_data);
|
||||
};
|
||||
|
||||
#endif // DATAHANDLER_H
|
||||
|
||||
Reference in New Issue
Block a user