fix(media): fix backboard camera display and mdns connection."

This commit is contained in:
2025-09-18 17:05:23 +08:00
parent 4a25fb0e80
commit aa1d0a6579
12 changed files with 98 additions and 34 deletions

View File

@@ -88,14 +88,20 @@
{
"cmd": "VIDEO_TEST",
"val": 0,
"lable": "开启视频",
"timeout": 0
"lable": "关闭视频",
"timeout": 2000
},
{
"cmd": "VIDEO_TEST",
"val": 1,
"lable": "关闭视频",
"timeout": 0
"lable": "开启RGB视频",
"timeout": 2000
},
{
"cmd": "VIDEO_TEST",
"val": 2,
"lable": "开启IR视频",
"timeout": 2000
},
{
"cmd": "WIFI_SIGNAL_TEST",

View File

@@ -232,7 +232,7 @@ void FFmpegDecoder::run()
labelSize = currentVideoLabel->size();
}
mutex.unlock();
qWarning() << "-------currentVideoLabel";
//qWarning() << "-------currentVideoLabel";
QImage img = avFrameToQImage(frame);
QImage scaledImage = img.scaled(labelSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
//currentVideoLabel->setPixmap(QPixmap::fromImage(scaledImage));

View File

@@ -176,14 +176,14 @@ void ClientHandler::sendJsonItem(const QJsonArray& jsonArray, int itemIndex, con
if (jsonArray == backBoardTest) {
QJsonObject tempItem = jsonArray[itemIndex].toObject();
if (tempItem["cmd"] == "VIDEO_TEST") {
if (tempItem["val"] == 0) {
if (tempItem["val"] == 1 || tempItem["val"] == 2) {
isSingleSend = false;
isClickedSend = false;
isRecvVideoData = true;
isStartVideo = true;
startReadVideoDataTimer(isBackBoardOrAllBoard);
}
else if (tempItem["val"] == 1) {
else if (tempItem["val"] == 0) {
isRecvVideoData = false;
isStartVideo = false;
stopReadVideoDataTimer(isBackBoardOrAllBoard);

View File

@@ -145,7 +145,7 @@ void DataHandler::handleData(const QString& client, const QByteArray& recv
(static_cast<unsigned char>(buffer->at(7)) << 8) |
(static_cast<unsigned char>(buffer->at(6)));
//qDebug() << "---Received dataSize:" << dataSize;
qDebug() << "---Received buffer->size():" << buffer->size();
//qDebug() << "---Received buffer->size():" << buffer->size();
//qDebug() << "---msg_id:" << QString::number(msg_id, 16).toUpper();
// 第11字节为返回 OK/NG
bool success = (static_cast<unsigned char>(buffer->at(10)) != 0x00);
@@ -159,7 +159,7 @@ void DataHandler::handleData(const QString& client, const QByteArray& recv
break;
}
}
qDebug() << "---Received totalSize:" << totalSize;
//qDebug() << "---Received totalSize:" << totalSize;
if (buffer->size() >= totalSize) {
// 调试查看收到的前19个字节
/*for (int i = 0; i < 19; i++) {
@@ -233,7 +233,9 @@ std::map<QString, int> commandValueMap = {
{"FACE_ANGLE_RANGE", FACE_ANGLE_RANGE},
{"GET_BACK_MAC", GET_BACK_MAC},
{"WRITE_BACK_UID_SN", WRITE_BACK_UID_SN}
{"WRITE_BACK_UID_SN", WRITE_BACK_UID_SN},
{"VIDEO_TEST", VIDEO_TEST},
};
bool DataHandler::getCommandNameFromValue(int receivedValue) {
@@ -559,10 +561,10 @@ void DataHandler::handleBackCmd(int msg_id, const QString& client, QByteArray ac
}
}
QJsonObject jsonObject = jsonArray[itemJsonIndex].toObject();
if (jsonObject["val"] == 0) {
if (jsonObject["val"] == 1 || jsonObject["val"] == 2) {
showVideo(client, actual_data);
}
else if (jsonObject["val"] == 1) {
else if (jsonObject["val"] == 0) {
isStartVideo = false;
emit statusUpdated(1, client, true, jsonArray, itemJsonIndex);
qDebug() << "--- STOP_VIDEO";

View File

@@ -1756,6 +1756,34 @@ void MainWidget::saveStatusListToFile(const QString& filePath)
file.close();
}
void MainWidget::saveDeviceInfoToFile(const QString& filePath, const QString& info)
{
QString actualFilePath = filePath;
if (actualFilePath.isEmpty()) {
QString defaultDirPath = QDir::currentPath() + "/TestLog";
QDir dir(defaultDirPath);
if (!dir.exists()) {
if (!dir.mkpath(defaultDirPath)) {
qWarning() << "Failed to create directory:" << defaultDirPath;
return;
}
}
//QString currentTime = QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss");
QString currentTime = QDateTime::currentDateTime().toString("yyyyMMdd");
actualFilePath = defaultDirPath + "/device_info_" + currentTime + ".txt";
}
QFile file(actualFilePath);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
qWarning() << "Failed to open file:" << actualFilePath;
return;
}
QTextStream out(&file);
out << info;
file.close();
}
void MainWidget::onCheckSerialRecvStatus() {
}
@@ -2087,6 +2115,7 @@ void MainWidget::onUuidButtonClicked()
UuidHwInfoEdit->setPlainText(displayText);
qDebug() << "HTTP Server backBoardUuid is:" << backBoardUuid;
qDebug() << "HTTP Server backBoardSn is:" << backBoardSn;
saveDeviceInfoToFile(filePathLineEdit->text(), QString("MAC:") + cur_mac_addr + displayText);
isRequestSuccessful = 0;
return;
}
@@ -2412,7 +2441,7 @@ void MainWidget::onOpenFocusWindowClicked()
QPushButton* button = qobject_cast<QPushButton*>(sender());
if (button) {
int itemIndex = button->property("getVideoIndex").toInt();
qDebug() << "New Button clicked with itemIndex:" << itemIndex;
qDebug() << "New Button clicked with itemIndex:" << itemIndex << " bord_id: " << isBackBoardOrAllBoard;
if (itemIndex == FOCUS_WINDOWS_BUTTON) {
if (isBackBoardOrAllBoard) {
for (ClientHandler* handler : clients) {
@@ -2652,14 +2681,18 @@ void MainWidget::onSendBackItemClicked()
{
qDebug() << "onSendBackItemClicked";
if (connectedClientsCount) {
qDebug() << "onSendBackItemClicked -- start 000";
if (isBackBoardOrAllBoard == 0) {
onHandleInvalidOperate("当前连接的是前板,请勿操作后板或整机页面的按键!!!");
return;
}
qDebug() << "onSendBackItemClicked -- start 111";
QPushButton* button = qobject_cast<QPushButton*>(sender());
int itemIndex = button->property("backBoardTest").toInt();
for (ClientHandler* handler : clients) {
qDebug() << "onSendBackItemClicked -- start 222";
if (isReplyOrTimeout && ((isBackBoardOrAllBoard) || (handler->getClientId() == handler->controlClientId))) {
qDebug() << "onSendBackItemClicked -- start 333";
handler->sendBackItem(itemIndex);
isReplyOrTimeout = false;
break;

View File

@@ -212,6 +212,8 @@ private:
QGroupBox* createBackConnectServerGroupBox();
// 保存日志到文件
void saveStatusListToFile(const QString& filePath);
// 保存服务器获取的信息
void saveDeviceInfoToFile(const QString& filePath, const QString& info);
// 用于更新按键文本的函数
void updateServerButtonText();
void updateGetVideoButtonState(int state, int connectedDevices, const QVector<QPushButton*>& buttons);

View File

@@ -150,9 +150,9 @@ void SerialPortHandler::onSendHeartBeatData(const QByteArray& data, bool heartBe
serialPort->flush(); // 确保数据立即发送
}
else {
qDebug() << "Serial port is not open!";
//qDebug() << "Serial port is not open!";
}
qDebug() << "当前时间:" << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz");
//qDebug() << "当前时间:" << QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss.zzz");
}
void readBmpFile_1(const QString& filePath) {
@@ -370,7 +370,7 @@ void SerialPortHandler::updateAvailablePorts() {
QStringList currentPorts;
foreach(const QSerialPortInfo & info, QSerialPortInfo::availablePorts()) {
currentPorts.append(info.portName());
qDebug() << "info.portName(): " << info.portName();
//qDebug() << "info.portName(): " << info.portName();
}
//qDebug() << "Available ports: " << currentPorts;
@@ -550,16 +550,32 @@ void SerialPortHandler::sendJsonItem(const QJsonArray& jsonArray, int itemIndex,
QJsonObject tempItem = jsonArray[itemIndex].toObject();
if (tempItem["cmd"] == "VIDEO_TEST") {
if (tempItem["val"] == 0) {
#if 0
isSingleSend = false;
isClickedSend = false;
isRecvVideoData = true;
isStartVideo = true;
//startReadVideoDataTimer(isBackBoardOrAllBoard);
#endif
isRecvVideoData = false;
isStartVideo = false;
}
else if (tempItem["val"] == 1) {
#if 0
isRecvVideoData = false;
isStartVideo = false;
//stopReadVideoDataTimer(isBackBoardOrAllBoard);
#endif
isSingleSend = false;
isClickedSend = false;
isRecvVideoData = true;
isStartVideo = true;
}
else if (tempItem["val"] == 2) {
isSingleSend = false;
isClickedSend = false;
isRecvVideoData = true;
isStartVideo = true;
}
}
}

View File

@@ -1,3 +1,4 @@
#include "crc32.h"
#include <stdio.h>
static const unsigned int crc_table[256] = {

View File

@@ -1,6 +1,8 @@
#ifndef _crc32_h_
#ifndef _crc32_h_
#define _crc32_h_
#include <stdint.h>
#pragma pack(push, 1)
struct BMPHeader {
char bfType[2];
@@ -21,17 +23,17 @@ struct BMPHeader {
uint32_t biClrImportant;
};
#pragma pack(pop)
#ifdef __cplusplus
extern "C" {
#endif
unsigned int crc32(unsigned int crc, const void *buf, size_t len);
void crc32init(unsigned int *crc);
void crc32update(unsigned int *crc, const void * b, size_t len);
void crc32final(unsigned int *crc);
unsigned int crcsimple(const void *buf, size_t len);
#ifdef __cplusplus
}
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
unsigned int crc32(unsigned int crc, const void *buf, size_t len);
void crc32init(unsigned int *crc);
void crc32update(unsigned int *crc, const void * b, size_t len);
void crc32final(unsigned int *crc);
unsigned int crcsimple(const void *buf, size_t len);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -47,7 +47,7 @@ UI_config loadUIConfig(const QString& filePath)
config.SL100_FACTORY_TOOL_W = settings.value("Window/width", "1340").toInt();
config.SL100_FACTORY_TOOL_H = settings.value("Window/height", "900").toInt();
config.LOG_LEVEL = settings.value("LogLevel/log_level", "2").toInt();
config.TOOL_VERSION = settings.value("Labels/tool_version", "SL100 工厂产测工具 - V0.0.18");
config.TOOL_VERSION = settings.value("Labels/tool_version", "SL100 工厂产测工具 - V0.0.19");
config.START_LISTENING = settings.value("Labels/start_listening", "开始监听\n(Start Listening...)");
config.ONE_CLICKED_TEST = settings.value("Labels/one_clicked_test", "一键功能测试");
config.SELECT_MDSN_IP = settings.value("Labels/select_mdns_ip", "Select MDns IP:");
@@ -94,7 +94,7 @@ UI_config loadUIConfig(const QString& filePath)
config.THIS_DEV_DISCONNECT = settings.value("Labels/this_device_disconnect", "This device is not connected !!!");
config.PLEASE_SELECT_IMG_LENS = settings.value("Labels/please_select_img_lens", "Please select \"左边镜头\" or \"右边镜头\" to get image!!!");
config.PLEASE_SELECT_VID_LENS = settings.value("Labels/please_select_vid_lens", "Please select lens to get video!!!");
config.MDNS_HOSE_NAME = settings.value("Labels/mdns_host_name", "SL100-FactoryTool-Mdns");
config.MDNS_HOSE_NAME = settings.value("Labels/mdns_host_name", "sl100");
config.MDNS_SERVICE_NAME = settings.value("Labels/mdns_service_name", "_myservice._tcp.local.");
quint16 port = settings.value("Labels/tcp_connect_port", "12412").toUInt();
config.TCP_CONNECT_PORT = (port > 0 && port <= 65535) ? port : 12412; // 防止异常值

View File

@@ -25,6 +25,8 @@ int main(int argc, char* argv[]) {
//FreeConsole(); // 关闭控制台窗口
QApplication app(argc, argv);
qSetMessagePattern("%{time yyyy-MM-dd HH:mm:ss.zzz} %{message}");
// **注册 QItemSelection 和 SelectionFlags 以支持 QueuedConnection**
qRegisterMetaType<QItemSelection>("QItemSelection");
qRegisterMetaType<QItemSelectionModel::SelectionFlags>("QItemSelectionModel::SelectionFlags");

View File

@@ -67,6 +67,6 @@ no_device_connected = No device is connected !!!
this_device_disconnect = This device is not connected !!!
please_select_img_lens = Please select \"左边镜头\" or \"右边镜头\" to get image!!!
please_select_vid_lens = Please select lens to get video!!!
mdns_host_name = SL100-FactoryTool-Mdns
mdns_host_name = sl100
mdns_service_name = _myservice._tcp.local.
tcp_connect_port = 12412