GrabBag/Module/WDRemoteReceiver/Inc/IWDRemoteReceiver.h

119 lines
4.4 KiB
C
Raw Normal View History

2026-06-26 17:49:32 +08:00
#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