1.更新MDNS广播的服务类型命名规范,防止出现多设备打开找不到MDNS的广播的问题 2.更新区分前后板的TAG

This commit is contained in:
2024-09-02 10:22:41 +08:00
parent e0c1e37191
commit 09c5843358
22 changed files with 501 additions and 304 deletions

View File

@@ -9,7 +9,7 @@ ClientHandler::ClientHandler(QTcpSocket* socket,
QJsonArray frontBoardDevInfoJson, QJsonArray frontBoardLicenseJson,
QJsonArray backBoardOneClickTest, QJsonArray backBoardTest, QJsonArray backBoardFuncConfig,
QJsonArray backBoardDevInfoJson, QJsonArray backBoardUuidJson,
QJsonArray getPicJson, QJsonArray getVideoJson, int clientId, QObject* parent)
QJsonArray getPicJson, QJsonArray getVideoJson, int clientId, int isBackBoardOrAllBoard, QObject* parent)
: QObject(parent), socket(socket),
frontBoardOneClickTest(frontBoardOneClickTest), frontBoardTest(frontBoardTest),
frontBoardFuncConfig(frontBoardFuncConfig), frontBoardDevInfoJson(frontBoardDevInfoJson),
@@ -17,7 +17,7 @@ ClientHandler::ClientHandler(QTcpSocket* socket,
backBoardOneClickTest(backBoardOneClickTest), backBoardTest(backBoardTest),
backBoardFuncConfig(backBoardFuncConfig), backBoardDevInfoJson(backBoardDevInfoJson),
backBoardUuidJson(backBoardUuidJson), getPicJson(getPicJson), getVideoJson(getVideoJson),
currentItemIndex(0), clientId(clientId),
currentItemIndex(0), clientId(clientId), isBackBoardOrAllBoard(isBackBoardOrAllBoard),
isManualSend(false), isSingleSend(false), isClickedSend(false), size(0),
isFirstDataReceived(true), processDataFunction(nullptr),
isDataStuck(false), dataProcessingActive(false), isRecvVideoData(true),
@@ -35,6 +35,37 @@ ClientHandler::~ClientHandler() {
qDebug() << "ClientHandler destroyed for clientId:" << clientId;
}
// 实现 QRunnable 的 run 函数,在线程池中执行
void ClientHandler::run()
{
start();
}
// 重置索引
void ClientHandler::resetCurrentItemIndex()
{
currentItemIndex = 0;
currentFuncItemIndex = 0;
itemsProcessedCount = 0;
emit startTimeout(0);
}
// 开始处理客户端
void ClientHandler::start()
{
resetCurrentItemIndex(); // 初始化计数器和索引
sendNextItem();
}
// 处理客户端断开连接
void ClientHandler::onDisconnected() {
qDebug() << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
qDebug() << "> A device is disconnected. ID:" << clientId;
qDebug() << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
emit clientDisconnected(this);
socket->deleteLater();
}
void ClientHandler::startReadVideoDataTimer(int client_Id)
{
//emit startReadTimer(clientId);
@@ -94,31 +125,9 @@ QString ClientHandler::getClientAddress() const
return socket->peerAddress().toString() + ":" + QString::number(socket->peerPort());
}
// 实现 QRunnable 的 run 函数,在线程池中执行
void ClientHandler::run()
{
start();
}
// 重置索引
void ClientHandler::resetCurrentItemIndex()
{
currentItemIndex = 0;
currentFuncItemIndex = 0;
itemsProcessedCount = 0;
emit startTimeout(0);
}
// 开始处理客户端
void ClientHandler::start()
{
resetCurrentItemIndex(); // 初始化计数器和索引
sendNextItem();
}
void ClientHandler::sendDataToClient(const QByteArray& data)
{
emit sendData(data);
emit sendData(data, isBackBoardOrAllBoard);
}
void ClientHandler::sendJsonItem(const QJsonArray& jsonArray, int itemIndex, const QString text, const QString& itemType)
@@ -470,6 +479,8 @@ bool ClientHandler::RNDISFirstData(QByteArray& data) {
setThreadPriority(QThread::LowPriority);
socket->setReadBufferSize(20 * 1024);
controlClientId = clientId;
// 前板有设备连接自动发送获取设备信息
//sendDevInfoItem();
break;
default:
qWarning() << "Unhandled client type:" << clientType;
@@ -671,15 +682,6 @@ void ClientHandler::processPendingData()
}
}
// 处理客户端断开连接
void ClientHandler::onDisconnected() {
qDebug() << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
qDebug() << "> A device is disconnected. ID:" << clientId;
qDebug() << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
emit clientDisconnected(this);
socket->deleteLater();
}
// 处理超时
void ClientHandler::onTimeout()
{

View File

@@ -33,7 +33,7 @@ public:
QJsonArray frontBoardFuncConfig, QJsonArray frontBoardDevInfoJson, QJsonArray frontBoardLicenseJson,
QJsonArray backBoardOneClickTest, QJsonArray backBoardTest, QJsonArray backBoardFuncConfig, QJsonArray backBoardDevInfoJson,
QJsonArray backBoardUuidJson, QJsonArray getPicJson, QJsonArray getVideoJson,
int clientId, QObject* parent = nullptr);
int clientId, int isBackBoardOrAllBoard, QObject* parent = nullptr);
~ClientHandler();
int preVideoClientId = 0;
@@ -92,7 +92,7 @@ signals:
const QJsonArray& jsonArray, int itemJsonIndex);
void handleData(QByteArray& data);
// 数据发送信号
void sendData(const QByteArray& data);
void sendData(const QByteArray& data, int isBoardType);
// 状态更新信号
void statusUpdated(const QString& client, int itemIndex, int funcItemIndex,
bool success, const QString& itemData, const QString& funcItemData,
@@ -144,6 +144,7 @@ private:
int currentItemIndex; // 当前处理的测试 JSON 项目索引
int currentFuncItemIndex; // 当前处理的功能 JSON 项目索引
int clientId; // 新增的客户端编号
int isBackBoardOrAllBoard;
int itemsProcessedCount; // 跟踪处理项目的数量

View File

@@ -27,6 +27,8 @@
#include <QtCore/qglobal.h>
#define BUILD_SHARED_LIBS
#define QMDNSENGINE_LIBRARY
#if defined(BUILD_SHARED_LIBS)
# if defined(QMDNSENGINE_LIBRARY)
# define QMDNSENGINE_EXPORT Q_DECL_EXPORT

View File

@@ -339,7 +339,10 @@ void toPacket(const Message &message, QByteArray &packet)
{
quint16 offset = 0;
quint16 flags = (message.isResponse() ? 0x8400 : 0) |
(message.isTruncated() ? 0x200 : 0);
(message.isTruncated() ? 0x200 : 0);
qDebug() << "Flags set in toPacket:" << QString::number(flags, 16);
writeInteger<quint16>(packet, offset, message.transactionId());
writeInteger<quint16>(packet, offset, flags);
writeInteger<quint16>(packet, offset, message.queries().length());

View File

@@ -71,7 +71,6 @@ void ProberPrivate::assertRecord()
message.addQuery(query);
message.addRecord(proposedRecord);
server->sendMessageToAll(message);
// Wait two seconds to confirm it is unique
timer.stop();
timer.start(2 * 1000);
@@ -80,14 +79,15 @@ void ProberPrivate::assertRecord()
void ProberPrivate::onMessageReceived(const Message &message)
{
// If the response matches the proposed record, increment the suffix and
// try with the new name
if (confirmed || !message.isResponse()) {
// try with the new name
//if (confirmed || !message.isResponse()) {
if (confirmed) {
return;
}
const auto records = message.records();
for (const Record &record : records) {
if (record.name() == proposedRecord.name() && record.type() == proposedRecord.type()) {
qDebug() << "Conflict detected for name:" << proposedRecord.name() << "with type:" << record.type();
++suffix;
assertRecord();
}

View File

@@ -79,8 +79,8 @@ void ProviderPrivate::confirm()
delete prober;
}
prober = new Prober(server, srvProposed, this);
connect(prober, &Prober::nameConfirmed, [this](const QByteArray &name) {
connect(prober, &Prober::nameConfirmed, [this](const QByteArray &name) {
// If existing records were confirmed, indicate that they are no
// longer valid
if (confirmed) {
@@ -128,7 +128,7 @@ void ProviderPrivate::onMessageReceived(const Message &message)
if (!confirmed || message.isResponse()) {
return;
}
//qDebug() << "Failed to start server. Error:" << server->errorString();
bool sendBrowsePtr = false;
bool sendPtr = false;
bool sendSrv = false;
@@ -227,13 +227,16 @@ void Provider::update(const Service &service)
return;
}
bool registered = d->hostname->isRegistered();
//qDebug() << "Hostname registered:" << registered;
if(registered) {
// 不确认服务名称,直接进行广播
d->publish();
//if (d->hostname->isRegistered()) {
if (!d->confirmed || fqName != d->srvRecord.name()) {
/*if (!d->confirmed || fqName != d->srvRecord.name()) {
qDebug() << "confirm()";
d->confirm();
} else {
qDebug() << "publish()";
d->publish();
}
}*/
}
}

View File

@@ -129,8 +129,6 @@ void Server::sendMessageToAll(const Message &message)
{
QByteArray packet;
toPacket(message, packet);
//qDebug() << "MdnsMsg :" << packet.toHex();
qDebug() << "MdnsPort:" << MdnsPort;
qint64 sentBytes = d->ipv4Socket.writeDatagram(packet, MdnsIpv4Address, MdnsPort);
qDebug() << "ipv4Socket sentBytes:" << sentBytes;
sentBytes = d->ipv6Socket.writeDatagram(packet, MdnsIpv6Address, MdnsPort);

View File

@@ -1,4 +1,4 @@
// #include "servicemodel.cpp"
// servicemodel.cpp
#include "servicemodel.h"
Q_DECLARE_METATYPE(QMdnsEngine::Service)

View File

@@ -1,3 +1,4 @@
// servicemodel.h
#ifndef SERVICEMODEL_H
#define SERVICEMODEL_H
@@ -7,7 +8,8 @@
#include "qmdnsengine/include/hostname.h"
#include "qmdnsengine/include/provider.h"
#include "qmdnsengine/include/service.h"
#include "qmdnsengine/include/message.h"
#include "qmdnsengine/include/query.h"
class ServiceProvider : public QObject
{