拆包增加tcp协议

This commit is contained in:
yiyi 2025-09-14 14:51:38 +08:00
parent 551fbc575a
commit 5946037da7
236 changed files with 11843 additions and 827 deletions

View File

@ -0,0 +1,12 @@
TEMPLATE = subdirs
# 撕裂项目
SUBDIRS += BeltTearingConfig/BeltTearingConfig.pro
SUBDIRS += BeltTearingApp/BeltTearingApp.pro
SUBDIRS += BeltTearingServer/BeltTearingServer.pro
# 设置编译顺序依赖
BeltTearingApp.depends += ../../../VrNets/VrTcpClient.pro
BeltTearingApp.depends += BeltTearingConfig/BeltTearingConfig.pro
BeltTearingServer.depends += BeltTearingConfig/BeltTearingConfig.pro

View File

@ -13,22 +13,24 @@ win32-msvc {
# Include paths
INCLUDEPATH += $$PWD/Presenter/Inc
INCLUDEPATH += ../BeltTearingConfig/Inc
INCLUDEPATH += ../VrNets/tcpClient/Inc
INCLUDEPATH += ../VrUtils/Inc
INCLUDEPATH += ../../../VrNets/tcpClient/Inc
INCLUDEPATH += ../../../VrUtils/Inc
# Link libraries
win32:CONFIG(debug, debug|release) {
LIBS += -L../BeltTearingConfig/debug -lBeltTearingConfig
LIBS += -L../VrNets/debug -lVrTcpClient
LIBS += -L../VrUtils/debug -lVrUtils
LIBS += -L../../../VrNets/debug -lVrTcpClient
LIBS += -L../../../VrUtils/debug -lVrUtils
} else:win32:CONFIG(release, debug|release) {
LIBS += -L../BeltTearingConfig/release -lBeltTearingConfig
LIBS += -L../VrNets/release -lVrTcpClient
LIBS += -L../VrUtils/release -lVrUtils
LIBS += -L../../../VrNets/release -lVrTcpClient
LIBS += -L../../../VrUtils/release -lVrUtils
}else:unix:!macx {
LIBS += -L../BeltTearingConfig -lBeltTearingConfig
LIBS += -L../VrNets -lVrTcpClient
LIBS += -L../VrUtils -lVrUtils
LIBS += -L../BeltTearingConfig -lBeltTearingConfig
LIBS += -L../../../VrNets -lVrTcpClient
LIBS += -L../../../VrUtils -lVrUtils
}
# You can make your code fail to compile if it uses deprecated APIs.

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Before

Width:  |  Height:  |  Size: 312 B

After

Width:  |  Height:  |  Size: 312 B

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -26,13 +26,13 @@ SOURCES += \
$$PWD/Src/VrBeltTearingConfig.cpp
#utils
INCLUDEPATH += $$PWD/../VrUtils/Inc
INCLUDEPATH += $$PWD/../VrUtils/tinyxml2
INCLUDEPATH += $$PWD/../../../VrUtils/Inc
INCLUDEPATH += $$PWD/../../../VrUtils/tinyxml2
win32:CONFIG(debug, debug|release) {
LIBS += -L../VrUtils/Debug -lVrUtils
LIBS += -L../../../VrUtils/Debug -lVrUtils
}else:win32:CONFIG(release, debug|release){
LIBS += -L../VrUtils/release -lVrUtils
LIBS += -L../../../VrUtils/release -lVrUtils
}else:unix:!macx {
# Unix/Linux平台库链接(包括交叉编译)
LIBS += -L../VrUtils -lVrUtils

View File

@ -15,13 +15,13 @@ win32-msvc {
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += $$PWD/../VrCommon/Inc
INCLUDEPATH += $$PWD/../VrUtils/Inc
INCLUDEPATH += $$PWD/../../../VrCommon/Inc
INCLUDEPATH += $$PWD/../../../VrUtils/Inc
INCLUDEPATH += $$PWD/Presenter/Inc
INCLUDEPATH += $$PWD/Utils/Inc
INCLUDEPATH += $$PWD/../VrConfig/Inc
INCLUDEPATH += $$PWD/../VrEyeDevice/Inc
INCLUDEPATH += $$PWD/../../../VrConfig/Inc
INCLUDEPATH += $$PWD/../../../VrEyeDevice/Inc
INCLUDEPATH += $$PWD/../BeltTearingConfig/Inc
SOURCES += \
@ -45,18 +45,18 @@ FORMS +=
win32:CONFIG(debug, debug|release) {
LIBS += -L../BeltTearingConfig/debug -lBeltTearingConfig
LIBS += -L../VrEyeDevice/debug -lVrEyeDevice
LIBS += -L../VrUtils/debug -lVrUtils
LIBS += -L../../../VrEyeDevice/debug -lVrEyeDevice
LIBS += -L../../../VrUtils/debug -lVrUtils
}else:win32:CONFIG(release, debug|release){
LIBS += -L../BeltTearingConfig/release -lBeltTearingConfig
LIBS += -L../VrEyeDevice/release -lVrEyeDevice
LIBS += -L../VrUtils/release -lVrUtils
LIBS += -L../../../VrEyeDevice/release -lVrEyeDevice
LIBS += -L../../../VrUtils/release -lVrUtils
}else:unix:!macx {
# Unix/Linux平台库链接(包括交叉编译)
# 注意链接顺序:依赖关系从高到低
LIBS += -L../VrUtils -lVrUtils
LIBS += -L../../../VrUtils -lVrUtils
LIBS += -L../../../VrEyeDevice -lVrEyeDevice
LIBS += -L../BeltTearingConfig -lBeltTearingConfig
LIBS += -L../VrEyeDevice -lVrEyeDevice
# 添加系统库依赖
LIBS += -lpthread
@ -64,33 +64,33 @@ win32:CONFIG(debug, debug|release) {
#linux下的为unix windows下用的win32
INCLUDEPATH += ../SDK/VzNLSDK/_Inc
INCLUDEPATH += ../SDK/VzNLSDK/Inc
INCLUDEPATH += ../../../SDK/VzNLSDK/_Inc
INCLUDEPATH += ../../../SDK/VzNLSDK/Inc
win32:CONFIG(release, debug|release): {
LIBS += -L$$PWD/../SDK/VzNLSDK/Windows/x64/Release
LIBS += -L$$PWD/../../../SDK/VzNLSDK/Windows/x64/Release
LIBS += -lVzKernel -lVzNLDetect -lVzNLGraphics
}
else:win32:CONFIG(debug, debug|release): {
LIBS += -L$$PWD/../SDK/VzNLSDK/Windows/x64/Debug
LIBS += -L$$PWD/../../../SDK/VzNLSDK/Windows/x64/Debug
LIBS += -lVzKerneld -lVzNLDetectd -lVzNLGraphicsd
}
else:unix:!macx: {
LIBS += -L$$PWD/../SDK/VzNLSDK/Arm/aarch64
LIBS += -L$$PWD/../../../SDK/VzNLSDK/Arm/aarch64
LIBS += -lVzEyeSecurityLoader-shared -lVzKernel -lVzNLDetect -lVzNLGraphics
}
# 算法
INCLUDEPATH += ../SDK/OpenCV320/include
INCLUDEPATH += ../../../SDK/OpenCV320/include
win32:CONFIG(release, debug|release): {
LIBS += -L$$PWD/../SDK/OpenCV320/Windows/vc14/Release -lopencv_world320
LIBS += -L$$PWD/../../../SDK/OpenCV320/Windows/vc14/Release -lopencv_world320
}
else:win32:CONFIG(debug, debug|release): {
LIBS += -L$$PWD/../SDK/OpenCV320/Windows/vc14/Release -lopencv_world320
LIBS += -L$$PWD/../../../SDK/OpenCV320/Windows/vc14/Release -lopencv_world320
}
else:unix:!macx: {
LIBS += -L$$PWD/../SDK/OpenCV320/Arm/aarch64 -lopencv_core -lopencv_imgproc -lopencv_highgui
LIBS += -L$$PWD/../../../SDK/OpenCV320/Arm/aarch64 -lopencv_core -lopencv_imgproc -lopencv_highgui
}

View File

@ -0,0 +1,30 @@
通信方式:
工控机<->相机 tcp/ip
工控机<->码垛机控制器 tcp/ip
视觉系统与码垛机之间要交互的数据格式如下:
功能
设备名称
方向
设备名称
发送字符串
检测开始请求
码垛机
->
视觉系统
Trig
正常回复
视觉系统
->
码垛机
1Xyzrz
检测开始请求
码垛机
->
视觉系统
Trig
拆垛完成(检测无料)
视觉系统
->
码垛机
0

5
App/GrabBag/GrabBag.pro Normal file
View File

@ -0,0 +1,5 @@
TEMPLATE = subdirs
# 拆包项目
SUBDIRS += GrabBagConfig/GrabBagConfig.pro
SUBDIRS += GrabBagApp/GrabBagApp.pro
# SUBDIRS += GrabBagConfigCmd

View File

@ -0,0 +1,168 @@
QT += core gui
QT += serialport network
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TEMPLATE = app
CONFIG += c++17
# Add /utf-8 flag only for MSVC builds to enforce UTF-8 encoding
win32-msvc {
QMAKE_CXXFLAGS += /utf-8
}
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# 设置应用程序图标
RC_ICONS = resource/logo.ico
INCLUDEPATH += $$PWD/Presenter/Inc
INCLUDEPATH += $$PWD/Utils/Inc
INCLUDEPATH += $$PWD/../../../VrCommon/Inc
INCLUDEPATH += $$PWD/../../../VrUtils/Inc
INCLUDEPATH += $$PWD/../../../Module/ModbusTCPServer/Inc
INCLUDEPATH += $$PWD/../../../Module/ShareMem/Inc
INCLUDEPATH += $$PWD/../GrabBagConfig/Inc
INCLUDEPATH += $$PWD/../../../VrEyeDevice/Inc
INCLUDEPATH += $$PWD/../../../VrNets/TCPServer/Inc
SOURCES += \
Presenter/Src/DetectPresenter.cpp \
Presenter/Src/GrabBagPresenter.cpp \
Presenter/Src/RobotProtocol.cpp \
Presenter/Src/SerialProtocol.cpp \
Presenter/Src/ConfigManager.cpp \
Utils/Src/LaserDataLoader.cpp \
Utils/Src/PathManager.cpp \
Utils/Src/PointCloudImageUtils.cpp \
devstatus.cpp \
dialogcamera.cpp \
dialogcameralevel.cpp \
dialogconfig.cpp \
main.cpp \
mainwindow.cpp \
resultitem.cpp
HEADERS += \
Presenter/Inc/DetectPresenter.h \
Presenter/Inc/GrabBagPresenter.h \
Presenter/Inc/ProtocolCommon.h \
Presenter/Inc/RobotProtocol.h \
Presenter/Inc/SerialProtocol.h \
Presenter/Inc/ConfigManager.h \
Utils/Inc/LaserDataLoader.h \
Utils/Inc/PathManager.h \
IYGrabBagStatus.h \
Utils/Inc/PointCloudImageUtils.h \
Version.h \
devstatus.h \
dialogcamera.h \
dialogcameralevel.h \
dialogconfig.h \
mainwindow.h \
resultitem.h
FORMS += \
devstatus.ui \
dialogcamera.ui \
dialogcameralevel.ui \
dialogconfig.ui \
mainwindow.ui \
resultitem.ui
RESOURCES += \
resources.qrc
win32:CONFIG(debug, debug|release) {
LIBS += -L../../../VrUtils/debug -lVrUtils
LIBS += -L../GrabBagConfig/debug -lGrabBagConfig
LIBS += -L../../../VrEyeDevice/debug -lVrEyeDevice
LIBS += -L../../../Module/ModbusTCPServer/debug -lModbusTCPServer
LIBS += -L../../../Module/ShareMem/debug -lShareMem
LIBS += -L../../../VrNets/debug -lVrModbus
LIBS += -L../../../VrNets/debug -lVrTcpServer
}else:win32:CONFIG(release, debug|release){
LIBS += -L../../../VrUtils/release -lVrUtils
LIBS += -L../GrabBagConfig/release -lGrabBagConfig
LIBS += -L../../../VrEyeDevice/release -lVrEyeDevice
LIBS += -L../../../Module/ModbusTCPServer/release -lModbusTCPServer
LIBS += -L../../../Module/ShareMem/release -lShareMem
LIBS += -L../../../VrNets/release -lVrModbus
LIBS += -L../../../VrNets/release -lVrTcpServer
}else:unix:!macx {
# Unix/Linux平台库链接(包括交叉编译)
# 注意链接顺序:依赖关系从高到低
LIBS += -L../GrabBagConfig -lGrabBagConfig
LIBS += -L../../../VrEyeDevice -lVrEyeDevice
LIBS += -L../../../Module/ModbusTCPServer -lModbusTCPServer
LIBS += -L../../../VrNets -lVrModbus
LIBS += -L../../../Module/ShareMem -lShareMem
LIBS += -L../../../VrUtils -lVrUtils
LIBS += -L../../../VrNets -lVrTcpServer
# 添加系统库依赖
LIBS += -lpthread
}
#linux下的为unix windows下用的win32
INCLUDEPATH += ../../../SDK/VzNLSDK/_Inc
INCLUDEPATH += ../../../SDK/VzNLSDK/Inc
win32:CONFIG(release, debug|release): {
LIBS += -L$$PWD/../../../SDK/VzNLSDK/Windows/x64/Release
LIBS += -lVzKernel -lVzNLDetect -lVzNLGraphics
}
else:win32:CONFIG(debug, debug|release): {
LIBS += -L$$PWD/../../../SDK/VzNLSDK/Windows/x64/Debug
LIBS += -lVzKerneld -lVzNLDetectd -lVzNLGraphicsd
}
else:unix:!macx: {
LIBS += -L$$PWD/../../../SDK/VzNLSDK/Arm/aarch64
LIBS += -lVzEyeSecurityLoader-shared -lVzKernel -lVzNLDetect -lVzNLGraphics
}
# 算法
INCLUDEPATH += ../../../SDK/bagPosition/Inc
win32:CONFIG(release, debug|release): {
LIBS += -L$$PWD/../../../SDK/bagPosition/Windows/x64/Release -lbagPositioning -lbaseAlgorithm
LIBS += -L$$PWD/../../../SDK/OpenCV320/Windows/vc14/Release -lopencv_world320
}
else:win32:CONFIG(debug, debug|release): {
LIBS += -L$$PWD/../../../SDK/bagPosition/Windows/x64/Debug -lbagPositioning -lbaseAlgorithm
LIBS += -L$$PWD/../../../SDK/OpenCV320/Windows/vc14/Release -lopencv_world320
}
else:unix:!macx: {
LIBS += -L$$PWD/../../../SDK/bagPosition/Arm/aarch64 -lbagPositioning -lbaseAlgorithm
LIBS += -L$$PWD/../../../SDK/OpenCV320/Arm/aarch64 -lopencv_core -lopencv_imgproc -lopencv_highgui
}
# 添加libmodbus依赖
win32 {
LIBS += -lws2_32
LIBS += Advapi32.lib
}
# Default rules for deployment.
unix {
target.path = /usr/lib
# Link real-time library for POSIX shared memory functions
LIBS += -lrt
}
!isEmpty(target.path): INSTALLS += target
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

View File

@ -3,6 +3,8 @@
#include <condition_variable>
#include <thread>
#include <map>
#include <mutex>
#include "IVrConfig.h"
#include "IVrEyeDevice.h"
@ -15,15 +17,20 @@
#include "LaserDataLoader.h"
#include "PathManager.h"
#include "ConfigManager.h"
#include "IYTCPServer.h"
#include <QImage>
#include <QPainter>
#include <QColor>
#include <QObject>
#include <memory>
class GrabBagPresenter : public IVrConfigChangeNotify, public IConfigChangeListener
class GrabBagPresenter : public QObject, public IVrConfigChangeNotify, public IConfigChangeListener
{
Q_OBJECT
public:
GrabBagPresenter();
explicit GrabBagPresenter(QObject *parent = nullptr);
~GrabBagPresenter();
// 初始化
@ -66,7 +73,7 @@ public:
virtual void OnSystemConfigChanged(const SystemConfig& config) override;
virtual void OnCameraParamChanged(int cameraIndex, const CameraUIParam& cameraParam) override;
virtual void OnAlgorithmParamChanged(const VrAlgorithmParams& algorithmParams) override;
// 配置管理
ConfigManager* GetConfigManager() { return m_pConfigManager.get(); }
@ -81,6 +88,7 @@ public:
static void _StaticCameraNotify(EVzDeviceWorkStatus eStatus, void* pExtData, unsigned int nDataLength, void* pInfoParam);
static void _StaticDetectionCallback(EVzResultDataType eDataType, SVzLaserLineData* pLaserLinePoint, void* pParam);
private:
// 相机协议相关方法
@ -92,6 +100,15 @@ private:
// 串口协议相关方法
int InitSerialProtocol();
// TCP服务器相关方法
int InitTcpServer(int nPort);
// 初始化TCP服务器
bool startServer(quint16 port = 0); // port = 0 表示使用配置文件中的端口
void stopServer();
// TCP服务器回调处理方法
void onTcpDataReceivedFromCallback(const TCPClient* pClient, const char* pData, const unsigned int nLen);
// 算法初始化接口
int InitAlgorithmParams();
@ -140,7 +157,11 @@ private:
RobotProtocol* m_pRobotProtocol = nullptr;
SerialProtocol* m_pSerialProtocol = nullptr;
// TCP服务器相关
IYTCPServer* m_pTcpServer = nullptr;
quint16 m_port = 0;
// 连接状态标志
bool m_bCameraConnected = false; // 相机连接状态
bool m_bRobotConnected = false; // 机械臂连接状态

View File

@ -11,6 +11,7 @@
#include <algorithm>
#include <QImage>
#include <QThread>
#include <QUuid>
#include "Version.h"
#include "VrTimeUtils.h"
@ -20,22 +21,26 @@
#include "VrConvert.h"
#include "PointCloudImageUtils.h"
GrabBagPresenter::GrabBagPresenter()
: m_vrConfig(nullptr)
GrabBagPresenter::GrabBagPresenter(QObject *parent)
: QObject(parent)
, m_vrConfig(nullptr)
, m_pStatus(nullptr)
, m_pDetectPresenter(nullptr)
, m_pRobotProtocol(nullptr)
, m_pSerialProtocol(nullptr)
, m_pTcpServer(nullptr)
, m_port(0)
, m_bCameraConnected(false)
, m_bRobotConnected(false)
, m_currentWorkStatus(WorkStatus::Error)
{
{
m_detectionDataCache.clear();
}
GrabBagPresenter::~GrabBagPresenter()
{
// 停止配置管理器
if (m_pConfigManager) {
if (m_pConfigManager) {
m_pConfigManager->Shutdown();
m_pConfigManager.reset();
}
@ -66,6 +71,14 @@ GrabBagPresenter::~GrabBagPresenter()
m_pSerialProtocol = nullptr;
}
// 释放TCP服务器
if (m_pTcpServer) {
m_pTcpServer->Stop();
m_pTcpServer->Close();
delete m_pTcpServer;
m_pTcpServer = nullptr;
}
// 释放相机设备资源
for(auto it = m_vrEyeDeviceList.begin(); it != m_vrEyeDeviceList.end(); it++)
{
@ -153,6 +166,14 @@ int GrabBagPresenter::Init()
m_pStatus->OnSerialConnectionChanged(true);
}
// 初始化TCP服务器
nRet = InitTcpServer(configResult.tcpServerConfig.port);
if (nRet != 0) {
m_pStatus->OnStatusUpdate("TCP服务器初始化失败");
} else {
m_pStatus->OnStatusUpdate("TCP服务器初始化成功");
}
m_bAlgoDetectThreadRunning = true;
m_algoDetectThread = std::thread(&GrabBagPresenter::_AlgoDetectThread, this);
m_algoDetectThread.detach();
@ -237,8 +258,7 @@ int GrabBagPresenter::InitRobotProtocol()
// 设置工作信号回调
m_pRobotProtocol->SetWorkSignalCallback([this](bool startWork, int cameraIndex) {
return this->OnRobotWorkSignal(startWork, cameraIndex);
});
});
LOG_INFO("Robot protocol initialization completed successfully\n");
return nRet;
@ -298,6 +318,111 @@ int GrabBagPresenter::InitSerialProtocol()
}
}
// 初始化TCP服务器
int GrabBagPresenter::InitTcpServer(int nPort)
{
// 创建TCP服务器
if (!VrCreatYTCPServer(&m_pTcpServer)) {
LOG_ERROR("Failed to create VrNets TCPServer\n");
m_pTcpServer = nullptr;
}
if (!m_pTcpServer) {
LOG_ERROR("TCP server is not initialized\n");
return ERR_CODE(DEV_OPEN_ERR);
}
LOG_INFO("Initializing VrNets TCP server on port %d\n", nPort);
// 初始化TCP服务器
if (!m_pTcpServer->Init(nPort, false)) {
LOG_ERROR("Failed to initialize VrNets TCP server on port %d\n", nPort);
return ERR_CODE(DEV_OPEN_ERR);
}
// 创建lambda回调函数捕获this指针
FunTCPServerRecv recvCallback = [this](const TCPClient* pClient, const char* pData, const unsigned int nLen) {
this->onTcpDataReceivedFromCallback(pClient, pData, nLen);
};
// 启动TCP服务器使用lambda回调函数
if (!m_pTcpServer->Start(recvCallback, false)) {
LOG_ERROR("Failed to start VrNets TCP server\n");
return ERR_CODE(DEV_OPEN_ERR);
}
m_port = nPort;
LOG_INFO("VrNets TCP server started successfully on port %d\n", nPort);
return SUCCESS;
}
bool GrabBagPresenter::startServer(quint16 port)
{
// 这个方法现在由InitTcpServer处理
return InitTcpServer(port) == SUCCESS;
}
void GrabBagPresenter::stopServer()
{
if (!m_pTcpServer) {
return;
}
m_pTcpServer->Stop();
m_port = 0;
LOG_INFO("VrNets TCP server stopped\n");
}
// TCP服务器数据接收回调处理方法
void GrabBagPresenter::onTcpDataReceivedFromCallback(const TCPClient* pClient, const char* pData, const unsigned int nLen)
{
if (!pClient || !pData || nLen == 0) {
return;
}
std::string receivedData(pData, nLen);
QString qData = QString::fromStdString(receivedData).trimmed();
LOG_INFO("TCP data received from client %p: %s\n", pClient, qData.toStdString().c_str());
// 生成客户端ID用于标识
QString clientId = QString("Client_%1").arg(reinterpret_cast<intptr_t>(pClient));
if (m_pStatus) {
m_pStatus->OnStatusUpdate("收到TCP数据: " + qData.toStdString());
}
// 检查是否收到"Trig"命令
if (qData.contains("Trig")) {
LOG_INFO("Received Trig command, starting camera 1 detection\n");
if (m_pStatus) {
m_pStatus->OnStatusUpdate("收到触发命令,启动检测");
}
// 启动第一个相机检测
int result = StartDetection(1, false); // 启动相机1非自动模式
// 发送响应给客户端
QString response;
if (result != SUCCESS) {
response = QString("Error_%1").arg(result);
LOG_ERROR("Failed to start camera 1 detection, error: %d\n", result);
}
// 向客户端发送响应
m_pTcpServer->SendData(pClient, response.toStdString().c_str(), response.toStdString().length());
} else {
LOG_WARNING("Unknown TCP command received: %s\n", qData.toStdString().c_str());
if (m_pStatus) {
m_pStatus->OnStatusUpdate("未知TCP命令: " + qData.toStdString());
}
// 发送错误响应
std::string err = "Unknown_Command";
m_pTcpServer->SendData(pClient, err.c_str(), err.length());
}
}
// 初始化算法参数
int GrabBagPresenter::InitAlgorithmParams()
{
@ -1161,6 +1286,27 @@ void GrabBagPresenter::_SendDetectionResultToRobot(const DetectionResult& detect
} else {
LOG_WARNING("Serial protocol not available\n");
}
// 发送给TCP服务端
bool tcpipSent = false;
if(m_pTcpServer){
if(!multiTargetData.targets.empty()){
std::string result = "";
result.append("1,");
result.append(std::to_string(multiTargetData.targets[0].x));
result.append(",");
result.append(std::to_string(multiTargetData.targets[0].y));
result.append(",");
result.append(std::to_string(multiTargetData.targets[0].z));
result.append(",");
result.append(std::to_string(multiTargetData.targets[0].rz));
m_pTcpServer->SendAllData(result.c_str(), result.length());
}else {
std::string err = "0";
m_pTcpServer->SendAllData(err.c_str(), err.length());
}
}
// 总结发送状态
if (robotSent || serialSent) {

View File

@ -2,9 +2,9 @@
#define VERSION_H
#define GRABBAG_VERSION_STRING "1.1.3"
#define GRABBAG_BUILD_STRING "1"
#define GRABBAG_FULL_VERSION_STRING "V1.1.3_1"
#define GRABBAG_VERSION_STRING "1.1.4"
#define GRABBAG_BUILD_STRING "2"
#define GRABBAG_FULL_VERSION_STRING "V1.1.4_2"
// 获取版本信息的便捷函数
inline const char* GetGrabBagVersion() {

View File

@ -1,3 +1,10 @@
#1.1.4 2025-09-13
## build_2
1. 启动图标修复
## build_1
1. 增加TCP通信接口
# 1.1.3 2025-8-17
## build_1
1. 发现编织袋没有调用矫正接口

Some files were not shown because too many files have changed in this diff Show More