撕裂增加实时上传功能

This commit is contained in:
yiyi 2026-02-21 13:53:33 +08:00
parent 51f519fa91
commit a88e30cb76
5 changed files with 2562 additions and 2512 deletions

View File

@ -351,6 +351,7 @@ void BeltTearingPresenter::sendSimulationData()
SendDetectionResultToRobot(simulationResults); // 发送检测结果到机械臂
m_tearingProtocol->sendDetectResult(simulationResults, QImage());
m_tearingProtocol->sendRealtimeResult(simulationResults, QImage());
}
bool BeltTearingPresenter::initializeCamera()

View File

@ -143,13 +143,44 @@ void TearingTcpProtocol::sendDetectResult(const std::vector<SSG_beltTearingInfo>
// 构造数据帧
QByteArray frame = buildFrame(jsonData);
// 发送给所有客户端
bool success = m_tcpServer->SendAllData(frame.constData(), frame.size());
if (success) {
LOG_DEBUG("Sent DETECT_RESULT to all clients, count=%d, historyMax=%d, historyMaxId=%d\n",
count, m_historyMaxLength, m_historyMaxId);
// 检查是否有客户端开启了实时传输
bool hasRealtimeClient = false;
for (auto it = m_clientRealtimeEnabled.begin(); it != m_clientRealtimeEnabled.end(); ++it) {
if (it.value()) {
hasRealtimeClient = true;
break;
}
}
if (!hasRealtimeClient) {
// 没有客户端开启实时传输,广播给所有客户端
bool success = m_tcpServer->SendAllData(frame.constData(), frame.size());
if (success) {
LOG_DEBUG("Sent DETECT_RESULT to all clients, count=%d, historyMax=%d, historyMaxId=%d\n",
count, m_historyMaxLength, m_historyMaxId);
} else {
LOG_WARNING("Failed to send DETECT_RESULT to clients\n");
}
} else {
LOG_WARNING("Failed to send DETECT_RESULT to clients\n");
// 有客户端开启了实时传输,逐个发送,跳过已开启实时传输的客户端
int sentCount = 0;
int skippedCount = 0;
for (auto it = m_clientPointers.begin(); it != m_clientPointers.end(); ++it) {
QString clientId = it.key();
if (m_clientRealtimeEnabled.value(clientId, false)) {
skippedCount++;
continue;
}
const TCPClient* pClient = it.value();
bool success = m_tcpServer->SendData(pClient, frame.constData(), frame.size());
if (success) {
sentCount++;
} else {
LOG_WARNING("Failed to send DETECT_RESULT to client %s\n", clientId.toStdString().c_str());
}
}
LOG_DEBUG("Sent DETECT_RESULT to %d clients (skipped %d realtime clients), count=%d, historyMax=%d, historyMaxId=%d\n",
sentCount, skippedCount, count, m_historyMaxLength, m_historyMaxId);
}
}

View File

@ -1,7 +1,7 @@
#ifndef VERSION_H
#define VERSION_H
#define BELT_TEARING_SERVER_VERSION_STRING "2.0.6"
#define BELT_TEARING_SERVER_VERSION_STRING "2.0.7"
#define BELT_TEARING_SERVER_VERSION_BUILD "1"
#define BELT_TEARING_SERVER_PRODUCT_NAME "BeltTearingServer"
#define BELT_TEARING_SERVER_COMPANY_NAME "VisionRobot"

View File

@ -1,3 +1,7 @@
# 2.0.7
## build_1 2026-02-21
1. 增加实时传输功能
# 2.0.6
## build_1 2026-02-03
1. 增加授权

View File

@ -1,14 +1,15 @@
# 皮带撕裂检测系统 TCP 通信协议
## 版本
版本: 1.3
日期: 2026-02-12
版本: 1.4
日期: 2026-02-21
---
### 版本历史
| 版本 | 日期 | 修改内容 | 作者 |
|------|------------|------------------|-------|
| 1.4 | 2026-02-21 | 开启实时上报时不再发送DETECT_RESULT避免重复输出增加CMD汇总表格 | |
| 1.3 | 2026-02-12 | 增加实时传输检测结果功能(SET_REALTIME/REALTIME_RESULT) | |
| 1.2 | 2025-11-30 | 增加最大撕裂ID字段(maxId) | |
| 1.1 | 2025-11-16 | 修改协议长度的格式 | |
@ -36,6 +37,19 @@
- 支持命令应答机制
- UTF-8编码
### 1.3 CMD 汇总表
| msgType | 方向 | 说明 | 详细章节 |
|---------|------|------|----------|
| `DETECT_RESULT` | 服务器 → 客户端 | 撕裂检测结果上报(历史最大值),仅发送给**未开启**实时传输的客户端 | 4.1 |
| `REALTIME_RESULT` | 服务器 → 客户端 | 实时检测结果上报(所有撕裂详细数据),仅发送给**已开启**实时传输的客户端 | 4.2 |
| `SET_SPEED` | 客户端 → 服务器 | 设置皮带速度mm/s | 5.1 |
| `SET_CONTROL` | 客户端 → 服务器 | 启动/停止检测 | 5.2 |
| `SET_REALTIME` | 客户端 → 服务器 | 开启/关闭实时传输 | 5.3 |
| `CMD_RESPONSE` | 服务器 → 客户端 | 控制命令的统一应答 | 6.1 |
| `HEARTBEAT` | 客户端 → 服务器 | 心跳消息 | 9.1 |
| `HEARTBEAT_ACK` | 服务器 → 客户端 | 心跳应答 | 9.1 |
---
## 2. 数据帧格式
@ -200,7 +214,7 @@
- 实时传输功能需要客户端通过 `SET_REALTIME` 命令开启
- 开启后,服务器每次完成一帧检测即上报一次结果
- 关闭实时传输后,服务器停止上报 `REALTIME_RESULT` 消息
- `REALTIME_RESULT``DETECT_RESULT` 独立,互不影响
- `REALTIME_RESULT``DETECT_RESULT` 互斥:开启实时传输的客户端只收到 `REALTIME_RESULT`,未开启的客户端只收到 `DETECT_RESULT`
- 当 count 为 0 时tears 为空数组 `[]`
**示例**(无撕裂时):