GrabBag/Module/WDRemoteReceiver/Inc/IWDRemoteReceiver.h
2026-06-26 17:49:32 +08:00

119 lines
4.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef IWDREMOTERECEIVER_H
#define IWDREMOTERECEIVER_H
#include "WDRemoteDataTypes.h"
#include <functional>
#include <string>
#include <vector>
// 导出宏定义
#ifdef _WIN32
# ifdef WDREMOTERECEIVER_LIBRARY
# define WDREMOTERECEIVER_EXPORT __declspec(dllexport)
# else
# define WDREMOTERECEIVER_EXPORT __declspec(dllimport)
# endif
#else
# define WDREMOTERECEIVER_EXPORT __attribute__((visibility("default")))
#endif
/**
* @brief 远程接收器接口
*
* 把对 ZMQ 控制通道 + 结果订阅 + 原始图像订阅的访问封装为一个动态库,
* 不绑定到具体业务,下游项目可以直接复用。
*
* 内部使用:
* - IVrZeroMQClient (控制 REQ-REP)
* - IVrZeroMQSubscriber (结果 PUB-SUBtopic="result")
* - IVrZeroMQSubscriber (原始图像 PUB-SUBtopic="raw")
*
* 典型用法:
* IWDRemoteReceiver* p = nullptr;
* IWDRemoteReceiver::CreateInstance(&p);
* p->SetEventCallback(...);
* p->SetDetectionCallback(...);
* p->SetRawImageCallback(...); // 双目图像
* std::vector<WDRemoteDeviceInfo> devices;
* p->SearchDevices(devices); // UDP 广播发现设备
* p->Open(devices[0].machineCode); // 按机器码打开指定设备
* p->StartWork(WDRemoteWorkMode::Detection);
* ...
* p->StopWork(); // 发送停止指令
* p->Disconnect(); // 断开所有通道
*/
class WDREMOTERECEIVER_EXPORT IWDRemoteReceiver
{
public:
virtual ~IWDRemoteReceiver() = default;
/**
* @brief 连接参数
*/
struct ConnectConfig
{
std::string serverIp{"127.0.0.1"};
int controlPort{5555}; // ZMQ REQ-REP 控制
int resultPort{5556}; // ZMQ PUB 检测结果
int rawImagePort{5557}; // ZMQ PUB 原始图像0 表示不启用
};
// 回调类型
using DetectionCallback = std::function<void(const WDRemoteDetectionFrame& frame)>;
using RawImageCallback = std::function<void(const WDRemoteBinocularRawImage& image)>;
using EventCallback = std::function<void(WDRemoteEventType ev,
const std::string& msg)>;
// 连接 / 断开。推荐使用 SearchDevices + OpenConnect 保留给兼容旧调用。
virtual int Connect(const ConnectConfig& cfg) = 0;
virtual int SearchDevices(std::vector<WDRemoteDeviceInfo>& devices,
int timeoutMs = 150) = 0;
virtual int Open(const std::string& machineCode,
int timeoutMs = 3000) = 0;
virtual int Disconnect() = 0;
virtual bool IsConnected() const = 0;
// 控制接口(内部同步走 ZMQ REQ-REP
virtual int StartWork(int timeoutMs = 3000) = 0;
virtual int StartWork(WDRemoteWorkMode mode, int timeoutMs = 3000) = 0;
virtual int StopWork (int timeoutMs = 3000) = 0;
virtual int StopWork (WDRemoteWorkMode mode, int timeoutMs = 3000) = 0;
virtual int RequestSingleDetection(int timeoutMs = 15000) = 0;
virtual int SetExposure(double exposureTime, int timeoutMs = 3000) = 0;
virtual int SetGain (double gain, int timeoutMs = 3000) = 0;
virtual int SetAlgoParams(const WDRemoteAlgoParams& params, int timeoutMs = 3000) = 0;
virtual WDRemoteServerInfo GetServerInfo(int timeoutMs = 3000) = 0;
/**
* @brief 设置检测模式下的图像传输模式
* @param mode "binocular"(默认,发送左右目)或 "mono"(仅发送左目)
*
* 在调用 StartWork(Detection) 之前设置;
* 仅在检测模式下生效,实时传图模式不受影响。
*/
virtual void SetDetectMode(const std::string& mode) = 0;
/**
* @brief 自定义控制命令(透传 JSON 给服务端 ZMQ REP socket
*
* 服务端目前不识别的命令会回 "unknown cmd"。
* 上层可借此扩展,无需修改库本身。
*/
virtual int SendCustomCommand(const std::string& jsonReq,
std::string& jsonResp,
int timeoutMs = 3000) = 0;
// 回调注入
virtual void SetDetectionCallback(DetectionCallback cb) = 0;
virtual void SetRawImageCallback (RawImageCallback cb) = 0; // 双目图像
virtual void SetEventCallback (EventCallback cb) = 0;
/**
* @brief 创建实例
*/
static int CreateInstance(IWDRemoteReceiver** ppReceiver);
};
#endif // IWDREMOTERECEIVER_H