GrabBag/Device/GlLineLaserDevice/_Inc/GlLineLaserDevice.h
2026-02-11 00:53:51 +08:00

156 lines
5.5 KiB
C++
Raw Permalink 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 CGLLINELASERDEVICE_H
#define CGLLINELASERDEVICE_H
#include "IGlLineLaserDevice.h"
#include "phoskey_ss.h"
#include <atomic>
#include <vector>
#include <string>
/**
* @brief CGlLineLaserDevice 实现类
*
* 将 gl_linelaser_sdk (phoskey_ss) 的接口适配到 IVrEyeDevice 接口。
* 使用 SDK 回调模式GLX8_2_SetBatchOneTimeDataHandler获取批处理数据。
*
* 完整闭环流程:
* OpenDevice → 配置批处理参数 + 注册SDK回调
* StartDetect → GLX8_2_StartMeasureWithCallback 启动采集
* SDK回调 → BatchOneTimeCallback → ProcessBatchData → 逐行转换并回调上层
* StopDetect → GLX8_2_StopMeasure 停止采集
* CloseDevice → GLX8_2_CommClose 关闭设备
*
* 数据转换gl_linelaser_sdk 的 int32_t 轮廓数据单位0.01um)转换为
* SVzLaserLineData 的 SVzNL3DPosition 格式单位mm
*/
class CGlLineLaserDevice : public IGlLineLaserDevice
{
public:
CGlLineLaserDevice();
~CGlLineLaserDevice();
// ============ 实现 IVrEyeDevice 接口 ============
int InitDevice() override;
int SetStatusCallback(VzNL_OnNotifyStatusCBEx fNotify, void *param) override;
int OpenDevice(const char* sIP, bool bRGBD = false, bool bSwing = true, bool bFillLaser = true) override;
int GetVersion(SVzNLVersionInfo& sVersionInfo) override;
int GetDevInfo(SVzNLEyeDeviceInfoEx& sDeviceInfo) override;
int CloseDevice() override;
int StartDetect(VzNL_AutoOutputLaserLineExCB fCallFunc, EVzResultDataType eDataType, void *param) override;
bool IsDetectIng() override;
int StopDetect() override;
int SetDetectROI(SVzNLRect& leftROI, SVzNLRect& rightROI) override;
int GetDetectROI(SVzNLRect& leftROI, SVzNLRect& rightROI) override;
int SetEyeExpose(unsigned int& exposeTime) override;
int GetEyeExpose(unsigned int& exposeTime) override;
int SetEyeGain(unsigned int& gain) override;
int GetEyeGain(unsigned int& gain) override;
int SetFrame(int& frame) override;
int GetFrame(int& frame) override;
bool IsSupport() override;
int SetRGBDExposeThres(float& value) override;
int GetRGBDExposeThres(float& value) override;
int SetFilterHeight(double& dHeight) override;
int GetFilterHeight(double& dHeight) override;
int GetSwingSpeed(float& fSpeed) override;
int SetSwingSpeed(float& fSpeed) override;
int SetSwingAngle(float& fMin, float& fMax) override;
int GetSwingAngle(float& fMin, float& fMax) override;
int SetWorkRange(double& dMin, double& dMax) override;
int GetWorkRange(double& dMin, double& dMax) override;
// ============ 实现 IGlLineLaserDevice 专用接口 ============
int GetProfileDataWidth() override;
double GetXPitch() override;
double GetYPitch() override;
int SetYPitch(double pitch) override;
int SetBatchLines(unsigned int batchLines) override;
unsigned int GetBatchLines() override;
int SwitchProgram(int programNo) override;
int GetModelInfo(char* model, char* serialNumber) override;
int GetMeasureRange(double& xMin, double& xMax, double& zMin, double& zMax) override;
int SetBaseDistance(double distance) override;
private:
// 设备状态
int m_nDeviceId = 0; // 设备ID
bool m_bDeviceOpen = false; // 设备是否打开
std::string m_strDeviceIP; // 设备IP
// 设备信息
GLX8_2_ModelInfo m_modelInfo; // 型号信息
int m_nProfileWidth = 4096; // 轮廓数据宽度
double m_dXPitch = 0.01; // X方向间距 (mm)
double m_dYPitch = 1.0; // Y方向间距 (mm),用户设置
double m_dBaseDistance = 300.0; // 基准距离 (mm)Z偏移校正
// 批处理参数
unsigned int m_nBatchLines = 200; // 批处理行数
// 上层回调相关
VzNL_AutoOutputLaserLineExCB m_pDetectCallback = nullptr;
void* m_pDetectCallbackParam = nullptr;
EVzResultDataType m_eDataType = keResultDataType_Position;
VzNL_OnNotifyStatusCBEx m_pStatusCallback = nullptr;
void* m_pStatusCallbackParam = nullptr;
// 检测状态
std::atomic<bool> m_bDetecting{false};
// 帧计数
unsigned long long m_ullFrameIndex = 0;
// 内部方法
/**
* @brief 配置批处理模式
*/
int ConfigureBatchMode();
/**
* @brief 注册SDK批处理回调
*/
int RegisterBatchCallback();
/**
* @brief SDK 批处理回调函数静态由SDK线程调用
* @param info 批处理信息
* @param DataObj 批处理数据对象,用于提取轮廓/亮度/编码器
*/
static void BatchOneTimeCallback(const GLX8_2_STR_CALLBACK_INFO* info, const GLX8_2_Data DataObj);
/**
* @brief 处理一次批处理回调数据,逐行转换并回调给上层
* @param info 批处理信息
* @param DataObj 批处理数据对象
*/
void ProcessBatchData(const GLX8_2_STR_CALLBACK_INFO* info, const GLX8_2_Data DataObj);
// 静态回调需要通过实例指针访问成员保存this指针供回调使用
static CGlLineLaserDevice* s_pInstance;
};
#endif // CGLLINELASERDEVICE_H