赞
踩
设备器件控制定义
CDeviceComCtrl.h
- #pragma once
- #include "EMIOCtrl.h"
- #include "LumDataCtrl.h"
- #include "LEDCtrl.h"
- #include "AD9518Ctrl.h"
- #include "BramCtrl.h"
- #include "FPGAComCtrl.h"
- #include "TempVoltSampleCtrl.h"
- #include "MotorCtrl.h"
- #include "LaserCtrl.h"
- #include "ProberCtrl.h"
- class CDeviceComCtrl
- {
- public:
- // 析构函数
- ~CDeviceComCtrl();
- // 第一阶段初始化
- int iOneStageInit();
- // 第二阶段初始化
- int iTwoStageInit();
- // 获取单例指针
- static CDeviceComCtrl * GetInstance();
- public:
- //开始采集
- int iStartCapture();
- //开始行扫描
- int iStartRowScan(int iScanInnerRow);
- //停止采集
- int iStopCapture();
- // 设置行起始结束位置
- int iSetScanRowRange(int iScanInnerRowLowerLimit, int iScanInnerRowUpperLimit);
- // 探头使用次数加1
- int iProberUsedTimeAndOne();
- // 写探头信息
- int iWriteProberInfo(const stProberInfo &proberInfo);
- // 读探头信息
- int iReadProberInfo(stProberInfo & proberInfo);
- // 关闭激光器
- int iTurnOffLaser();
- // 打开激光器
- int iTurnOnLaser();
- // 设置激光功率
- int iSetLaserPower(int iLaserPower);
- // 获取激光器信息
- int iGetLaserInfo(stLaserInfo & laserInfo);
- // 设置激光器类别
- int iSetLaserTypes(int LaserType);
- // 打开LED灯
- int iTurnOnLED();
- // 关闭LED灯
- int iTurnOffLED();
- // 采集亮度数据
- int iSampleLumData(unsigned char * &lumData, int &iDataLen);
- // 设置电机位置
- int iSetMotorPos(int iPos);
- // 获取电机当前位置
- int iGetCurMotorPos();
- // 设置电机限制范围
- int iSetMotorPosRange(int iMotorPosLowerLimit, int iMotorPosUpperLimit);
- // 设置X振镜电压
- int iSetXMirrorControlVoltage(int iXMirrorControlVoltage);
- // 设置Y振镜电压
- int iSetYMirrorControlVoltage(int iYMirrorControlVoltage);
- // 设置PMT电压
- int iSetPMTControlVoltage(int iPMTControlVoltage);
- // 设置行偏移值
- int iSetYMirrorOffset(int iYMirrorOffset);
- // 设置扫描类型
- int iSetScanType(int iScanDirectionType);
- // 设置X振镜行列偏移
- int iSetXMirrorOffset(int iXMirrorOffset);
- // 设置X振镜偶数行列偏移
- int iSetXMirrorEvenOffset(int iXMirrorEvenOffset);
- // 设置奇数行列偏移
- int iSetXMirrorOddOffset(int iXMirrorOddOffset);
- // 设置畸变校正参数
- int iSetCorrectionParam(const stCorrectionParam & correctionParam);
- // 设置行对齐算法参数
- int iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam);
- // 设置亮度数据类型
- int iSetLumDataType(int iLumDataType);
- // 获取Fluorite版本信息
- int iGetFluoriteVer(string & sVer);
- // 获取Fluorite定制版本信息
- int iGetFluoriteCustomVer(string& sVer);
- // 开启扫描
- int iStartCapture(int iScanRowLowerLimit, int iScanRowUpperLimit);
- // 等待线程退出
- void wait();
- // 退出线程
- void ExitThread();
- protected:
- // 停止扫描
- int iStopCapture(int iScanRowLowerLimit, int iScanRowUpperLimit);
- private:
- // 构造函数
- CDeviceComCtrl();
- private:
- // 单例指针
- static CDeviceComCtrl * m_pInst;
- private:
- // FPGA器件控制
- CFPGAComCtrl * m_pFPGAComCtrl;
- // 电机控制
- CMotorCtrl * m_pMotorCtrl;
- // 激光器控制
- CLaserCtrl * m_pLaserCtrl;
- // 探头控制
- CProberCtrl * m_pProberCtrl;
- // 核心温度和电压采集控制
- CTempVoltSampleCtrl * m_pTempVoltSampleCtrl;
- // AD9518控制
- CAD9518Ctrl * m_pAD9518Ctrl;
- // LED灯控制
- CLEDCtrl * m_pLEDCtrl;
- // Bram接口
- CBramCtrl * m_pBramCtrl;
- // EMIO控制
- CEMIOCtrl * m_pEMIOCtrl;
- // 亮度数据采集控制
- CLumDataCtrl * m_pLumDataCtrl;
- };
CDeviceComCtrl.cpp
- #include "Log.h"
- #include "SettingParamMng.h"
- #include "DeviceComCtrl.h"
- #include "SysConfigMng.h"
- #include "DeviceStatusMng.h"
-
- // 单例指针
- CDeviceComCtrl * CDeviceComCtrl::m_pInst = nullptr;
-
- // 构造函数
- CDeviceComCtrl::CDeviceComCtrl()
- {
- // FPGA器件控制
- m_pFPGAComCtrl = nullptr;
- // 电机控制
- m_pMotorCtrl = nullptr;
- // 激光器控制
- m_pLaserCtrl = nullptr;
- // 探头控制
- m_pProberCtrl = nullptr;
- // 核心温度和电压采集控制
- m_pTempVoltSampleCtrl = nullptr;
- // EMIO控制
- m_pEMIOCtrl = nullptr;
- // 亮度数据采集控制
- m_pLumDataCtrl = nullptr;
- // AD9518控制
- m_pAD9518Ctrl = nullptr;
- // LED灯控制
- m_pLEDCtrl = nullptr;
- // Bram接口
- m_pBramCtrl = nullptr;
- return;
- }
-
- // 析构函数
- CDeviceComCtrl::~CDeviceComCtrl()
- {
- if (nullptr != m_pProberCtrl)
- {
- delete m_pProberCtrl;
- m_pProberCtrl = nullptr;
- }
-
- if (nullptr != m_pLaserCtrl)
- {
- delete m_pLaserCtrl;
- m_pLaserCtrl = nullptr;
- }
-
- if (nullptr != m_pMotorCtrl)
- {
- delete m_pMotorCtrl;
- m_pMotorCtrl = nullptr;
- }
-
- if (nullptr != m_pAD9518Ctrl)
- {
- delete m_pAD9518Ctrl;
- m_pAD9518Ctrl = nullptr;
- }
-
- if (nullptr != m_pTempVoltSampleCtrl)
- {
- delete m_pTempVoltSampleCtrl;
- m_pTempVoltSampleCtrl = nullptr;
- }
-
- if (nullptr != m_pLEDCtrl)
- {
- delete m_pLEDCtrl;
- m_pLEDCtrl = nullptr;
- }
-
- if (nullptr != m_pFPGAComCtrl)
- {
- delete m_pFPGAComCtrl;
- m_pFPGAComCtrl = nullptr;
- }
-
- if (nullptr != m_pBramCtrl)
- {
- delete m_pBramCtrl;
- m_pBramCtrl = nullptr;
- }
-
- if (nullptr != m_pEMIOCtrl)
- {
- delete m_pEMIOCtrl;
- m_pEMIOCtrl = nullptr;
- }
-
- if (nullptr != m_pLumDataCtrl)
- {
- delete m_pLumDataCtrl;
- m_pLumDataCtrl = nullptr;
- }
- return;
- }
- // 第一阶段初始化
- int CDeviceComCtrl::iOneStageInit()
- {
- stDeviceComCtrlConfig deviceComCtrlConfig = CSysConfigMng::GetInstance()->GetDeviceComCtrlConfig();
- m_pEMIOCtrl = new CEMIOCtrl();
- m_pBramCtrl = new CBramCtrl(deviceComCtrlConfig.m_sBramDriverFile);
- m_pAD9518Ctrl = new CAD9518Ctrl(deviceComCtrlConfig.m_emioConfig.m_AD9518SPICSEMIO.m_iEMIOCode, m_pEMIOCtrl, deviceComCtrlConfig.m_sAD9518SPIDriverFile);
- m_pTempVoltSampleCtrl = new CTempVoltSampleCtrl();
- m_pLumDataCtrl = new CLumDataCtrl(deviceComCtrlConfig.m_sDMADriverFile);
- m_pLEDCtrl = new CLEDCtrl(deviceComCtrlConfig.m_emioConfig.m_LEDEnableEMIO.m_iEMIOCode, m_pEMIOCtrl);
- m_pFPGAComCtrl = new CFPGAComCtrl(m_pBramCtrl);
- m_pMotorCtrl = new CMotorCtrl(m_pBramCtrl, deviceComCtrlConfig.m_emioConfig.m_motorMoveEnableEMIO.m_iEMIOCode, m_pEMIOCtrl);
- if (EXIT_FAILURE == m_pEMIOCtrl->iInitialize())
- {
- return EXIT_FAILURE;
- }
-
- if (EXIT_FAILURE == m_pBramCtrl->iInitialize())
- {
- return EXIT_FAILURE;
- }
-
- if (EXIT_FAILURE == m_pAD9518Ctrl->iInitialize())
- {
- return EXIT_FAILURE;
- }
-
- if (EXIT_FAILURE == m_pTempVoltSampleCtrl->iInitialize())
- {
- return EXIT_FAILURE;
- }
-
- if (EXIT_FAILURE == m_pLumDataCtrl->iInitilize())
- {
- return EXIT_FAILURE;
- }
-
- if (EXIT_FAILURE == m_pFPGAComCtrl->iInitialize())
- {
- return EXIT_FAILURE;
- }
-
- if (EXIT_FAILURE == m_pMotorCtrl->iInitialize())
- {
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
-
-
- // 第二阶段初始化
- int CDeviceComCtrl::iTwoStageInit()
- {
- // 获取激光器和探头配置信息
- stDeviceComCtrlConfig deviceComCtrlConfig = CSysConfigMng::GetInstance()->GetDeviceComCtrlConfig();
-
- m_pLaserCtrl = new CLaserCtrl(deviceComCtrlConfig.m_laserUartConfigInfo, deviceComCtrlConfig.m_emioConfig.m_UartSendEnableEMIO.m_iEMIOCode\
- , deviceComCtrlConfig.m_emioConfig.m_UartRecvEnableEMIO.m_iEMIOCode, m_pEMIOCtrl, this);
- if (EXIT_FAILURE == m_pLaserCtrl->iInitialize())
- {
- return EXIT_FAILURE;
- }
- m_pProberCtrl = new CProberCtrl(deviceComCtrlConfig.m_proberUartConfigInfo, deviceComCtrlConfig.m_emioConfig.m_ProberLockingFlagEMIO.m_iEMIOCode\
- , m_pEMIOCtrl, this);
- // 初始化探头
- if (EXIT_FAILURE == m_pProberCtrl->iInitialize())
- {
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
-
- // 获取单例指针
- CDeviceComCtrl * CDeviceComCtrl::GetInstance()
- {
- if (nullptr == m_pInst)
- {
- m_pInst = new CDeviceComCtrl;
- }
- return m_pInst;
- }
-
-
- //开始采集
- int CDeviceComCtrl::iStartCapture()
- {
- stIntTypeRange scanRowRange = CSettingParamMng::GetInstance()->GetScanRowRange();
- if (EXIT_FAILURE == iStartCapture(scanRowRange.m_iLowerLimit, scanRowRange.m_iUpperLimit))
- {
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
-
- //开始行扫描
- int CDeviceComCtrl::iStartRowScan(int iScanInnerRow)
- {
- if (EXIT_FAILURE == iSetScanRowRange(iScanInnerRow, iScanInnerRow))
- {
- return EXIT_FAILURE;
- }
-
- // 打开LED灯
- iTurnOnLED();
-
- // 打开激光器
- iTurnOnLaser();
-
- int iPower;
- m_pLaserCtrl->iGetLaserPower(iPower);
- int iMaxLaserPower = CSettingParamMng::GetInstance()->iGetLaserMaxPower();
- int iPowerPercent = iPower * 100 / iMaxLaserPower;
- iPowerPercent = iPowerPercent > 100 ? 100 : iPowerPercent;
- if (0 == iPowerPercent)
- {
- ostringstream os;
- os << "StartRowScan turn on Laser faild, LaserPower[" << iPower << "]" << endl;;
- }
- stStateMsg stateMsg;
- stateMsg.m_enComType = enDeviceComType_Scanner;
- stateMsg.m_deviceStateCode.m_iCode = STATE_EMIT;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = 0;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comStateCode.m_iCode = SCANNER_LINE;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperCopy;
- stateMsg.m_comErrorcode.m_iCode = 0;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
- CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
- CDeviceStatusMng::GetInstance()->iSetMessage("Working...", 0);
- return EXIT_SUCCESS;
- }
-
- //停止采集
- int CDeviceComCtrl::iStopCapture()
- {
- stIntTypeRange scanRowRange = CSettingParamMng::GetInstance()->GetScanRowRange();
- if (EXIT_FAILURE == iStopCapture(scanRowRange.m_iLowerLimit, scanRowRange.m_iUpperLimit))
- {
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
- // 设置行起始结束位置
- int CDeviceComCtrl::iSetScanRowRange(int iScanInnerRowLowerLimit, int iScanInnerRowUpperLimit)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- if (EXIT_FAILURE == m_pFPGAComCtrl->iSetScanRowRange(iScanInnerRowLowerLimit, iScanInnerRowUpperLimit))
- {
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
- // 探头使用次数加1
- int CDeviceComCtrl::iProberUsedTimeAndOne()
- {
- if (nullptr == m_pProberCtrl)
- {
- ostringstream os;
- os << "ProberCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pProberCtrl->iProberUsedTimeAndOne();
- }
- // 写探头信息
- int CDeviceComCtrl::iWriteProberInfo(const stProberInfo &proberInfo)
- {
- if (nullptr == m_pProberCtrl)
- {
- ostringstream os;
- os << "ProberCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pProberCtrl->iWriteProberInfo(proberInfo);
- }
- // 读探头信息
- int CDeviceComCtrl::iReadProberInfo(stProberInfo & proberInfo)
- {
- if (nullptr == m_pProberCtrl)
- {
- ostringstream os;
- os << "ProberCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pProberCtrl->iReadProberInfo(proberInfo);
- }
-
- // 关闭激光器
- int CDeviceComCtrl::iTurnOffLaser()
- {
- if (nullptr == m_pLaserCtrl)
- {
- ostringstream os;
- os << "LaserCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pLaserCtrl->iTurnOffLaser();
- }
- // 打开激光器
- int CDeviceComCtrl::iTurnOnLaser()
- {
- if (nullptr == m_pLaserCtrl)
- {
- ostringstream os;
- os << "LaserCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pLaserCtrl->iTurnOnLaser();
- }
- // 设置激光功率
- int CDeviceComCtrl::iSetLaserPower(int iLaserPower)
- {
- if (nullptr == m_pLaserCtrl)
- {
- ostringstream os;
- os << "LaserCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pLaserCtrl->iSetLaserPower(iLaserPower);
- }
-
- // 获取激光器信息
- int CDeviceComCtrl::iGetLaserInfo(stLaserInfo & laserInfo)
- {
- if (nullptr == m_pLaserCtrl)
- {
- ostringstream os;
- os << "LaserCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pLaserCtrl->iGetLaserInfo(laserInfo);
- }
-
- // 设置激光器类型
- int CDeviceComCtrl::iSetLaserTypes(int LaserType)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetLaserType(LaserType);
- }
-
- // 打开LED灯
- int CDeviceComCtrl::iTurnOnLED()
- {
- if (nullptr == m_pLEDCtrl)
- {
- ostringstream os;
- os << "LEDCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pLEDCtrl->iTurnOn();
- }
- // 关闭LED灯
- int CDeviceComCtrl::iTurnOffLED()
- {
- if (nullptr == m_pLEDCtrl)
- {
- ostringstream os;
- os << "LEDCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pLEDCtrl->iTurnOff();
- }
-
- // 采集亮度数据
- int CDeviceComCtrl::iSampleLumData(unsigned char *&lumData, int &iDataLen)
- {
- if (nullptr == m_pLumDataCtrl)
- {
- ostringstream os;
- os << "LumDataCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pLumDataCtrl->iSampleLumData(lumData, iDataLen);
- }
- // 设置电机位置
- int CDeviceComCtrl::iSetMotorPos(int iPos)
- {
- if (nullptr == m_pMotorCtrl)
- {
- ostringstream os;
- os << "MotorCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pMotorCtrl->iSetMotorPos(iPos);
- }
-
-
- // 获取电机当前位置
- int CDeviceComCtrl::iGetCurMotorPos()
- {
- if (nullptr == m_pMotorCtrl)
- {
- ostringstream os;
- os << "MotorCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pMotorCtrl->iGetMotorPos();
- }
-
- // 设置电机限制范围
- int CDeviceComCtrl::iSetMotorPosRange(int iMotorPosLowerLimit, int iMotorPosUpperLimit)
- {
- if (nullptr == m_pMotorCtrl)
- {
- ostringstream os;
- os << "MotorCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pMotorCtrl->iSetMotorPosRange(iMotorPosLowerLimit, iMotorPosUpperLimit);
- }
-
- // 设置X振镜电压
- int CDeviceComCtrl::iSetXMirrorControlVoltage(int iXMirrorControlVoltage)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetXMirrorControlVoltage(iXMirrorControlVoltage);
- }
- // 设置Y振镜电压
- int CDeviceComCtrl::iSetYMirrorControlVoltage(int iYMirrorControlVoltage)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetYMirrorControlVoltage(iYMirrorControlVoltage);
- }
- // 设置PMT电压
- int CDeviceComCtrl::iSetPMTControlVoltage(int iPMTControlVoltage)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetPMTControlVoltage(iPMTControlVoltage);
- }
- // 设置行偏移值
- int CDeviceComCtrl::iSetYMirrorOffset(int iYMirrorOffset)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetYMirrorOffset(iYMirrorOffset);
- }
-
- // 设置扫描类型
- int CDeviceComCtrl::iSetScanType(int iScanDirectionType)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetScanType(iScanDirectionType);
- }
- // 设置X振镜行列偏移
- int CDeviceComCtrl::iSetXMirrorOffset(int iXMirrorOffset)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetXMirrorOffset(iXMirrorOffset);
- }
- // 设置X振镜偶数行列偏移
- int CDeviceComCtrl::iSetXMirrorEvenOffset(int iXMirrorEvenOffset)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetXMirrorEvenOffset(iXMirrorEvenOffset);
- }
- // 设置奇数行列偏移
- int CDeviceComCtrl::iSetXMirrorOddOffset(int iXMirrorOddOffset)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetXMirrorOddOffset(iXMirrorOddOffset);
- }
- // 设置畸变校正参数
- int CDeviceComCtrl::iSetCorrectionParam(const stCorrectionParam & correctionParam)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetCorrectionParam(correctionParam);
- }
- // 设置行对齐算法参数
- int CDeviceComCtrl::iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetLineAlignAlgParam(lineAlignAlgParam);
- }
-
- // 设置亮度数据类型
- int CDeviceComCtrl::iSetLumDataType(int iLumDataType)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iSetLumDataType(iLumDataType);
- }
-
- // 获取Fluorite版本信息
- int CDeviceComCtrl::iGetFluoriteVer(string & sVer)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iGetFluoriteVer(sVer);
- }
- // 获取Fluorite定制版本信息
- int CDeviceComCtrl::iGetFluoriteCustomVer(string& sVer)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_pFPGAComCtrl->iGetFluoriteCustomVer(sVer);
- }
-
-
- // 开启扫描
- int CDeviceComCtrl::iStartCapture(int iScanRowLowerLimit, int iScanRowUpperLimit)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
-
- if (EXIT_FAILURE == m_pFPGAComCtrl->iStartCapture(iScanRowLowerLimit, iScanRowUpperLimit))
- {
- return EXIT_FAILURE;
- }
- // 打开LED灯
- iTurnOnLED();
-
- // 打开激光器
- iTurnOnLaser();
-
- int iPower;
- m_pLaserCtrl->iGetLaserPower(iPower);
- int iMaxLaserPower = CSettingParamMng::GetInstance()->iGetLaserMaxPower();
- int iPowerPercent = iPower * 100 / iMaxLaserPower;
- iPowerPercent = iPowerPercent > 100 ? 100 : iPowerPercent;
- if (0 == iPowerPercent)
- {
- ostringstream os;
- os << "startCapture turn on Laser faild, LaserPower[" << iPower << "]" << endl;;
- }
- stStateMsg stateMsg;
- stateMsg.m_enComType = enDeviceComType_Scanner;
- stateMsg.m_deviceStateCode.m_iCode = STATE_EMIT;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = 0;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comStateCode.m_iCode = SCANNER_WORKING;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperCopy;
- stateMsg.m_comErrorcode.m_iCode = 0;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
- CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
- CDeviceStatusMng::GetInstance()->iSetScanRowRange(iScanRowLowerLimit, iScanRowUpperLimit);
- CDeviceStatusMng::GetInstance()->iSetMessage("Working...", 0);
- return EXIT_SUCCESS;
- }
-
- // 停止扫描
- int CDeviceComCtrl::iStopCapture(int iScanRowLowerLimit, int iScanRowUpperLimit)
- {
- if (nullptr == m_pFPGAComCtrl)
- {
- ostringstream os;
- os << "FPGAComCtrl can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- if (EXIT_FAILURE == m_pFPGAComCtrl->iStopCapture(iScanRowLowerLimit, iScanRowUpperLimit))
- {
- return EXIT_FAILURE;
- }
- // 关闭激光器
- iTurnOffLaser();
- // 关闭LED灯
- iTurnOffLED();
-
- stStateMsg stateMsg;
- stateMsg.m_enComType = enDeviceComType_Scanner;
- stateMsg.m_deviceStateCode.m_iCode = ~STATE_EMIT;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperAnd;
- stateMsg.m_deviceErrorCode.m_iCode = 0;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comStateCode.m_iCode = SCANNER_STOP;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperCopy;
- stateMsg.m_comErrorcode.m_iCode = 0;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
- CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
- CDeviceStatusMng::GetInstance()->iSetScanRowRange(iScanRowLowerLimit, iScanRowUpperLimit);
- CDeviceStatusMng::GetInstance()->iSetMessage("System Ready...", 0);
- return EXIT_SUCCESS;
- }
-
-
- // 等待线程退出
- void CDeviceComCtrl::wait()
- {
- if (nullptr != m_pProberCtrl)
- {
- m_pProberCtrl->wait();
- }
-
- if (nullptr != m_pLaserCtrl)
- {
- m_pLaserCtrl->wait();
- }
-
- if (nullptr != m_pMotorCtrl)
- {
- m_pMotorCtrl->wait();
- }
-
- if (nullptr != m_pFPGAComCtrl)
- {
- m_pFPGAComCtrl->wait();
- }
-
- if (nullptr != m_pTempVoltSampleCtrl)
- {
- m_pTempVoltSampleCtrl->wait();
- }
- return;
- }
-
-
-
- // 退出线程
- void CDeviceComCtrl::ExitThread()
- {
- if (nullptr != m_pProberCtrl)
- {
- m_pProberCtrl->SetExitFlag(true);
- }
-
- if (nullptr != m_pLaserCtrl)
- {
- m_pLaserCtrl->SetExitFlag(true);
- }
-
- if (nullptr != m_pMotorCtrl)
- {
- m_pMotorCtrl->SetExitFlag(true);
- }
-
- if (nullptr != m_pFPGAComCtrl)
- {
- m_pFPGAComCtrl->SetExitFlag(true);
- }
-
- if (nullptr != m_pTempVoltSampleCtrl)
- {
- m_pTempVoltSampleCtrl->SetExitFlag(true);
- }
- return;
- }
CFPGAComCtrl.h FPGA控制定义
- #pragma once
- #include "ThreadProc.h"
- #include "BramCtrl.h"
- class CFPGAComCtrl : public CThreadProc
- {
- public:
- // 构造函数
- CFPGAComCtrl(CBramCtrl * bramCtrl);
- // 析构函数
- ~CFPGAComCtrl();
- // 初始化
- int iInitialize();
- // 服务
- virtual int src(int id) override;
- public:
- // 设置X振镜电压
- int iSetXMirrorControlVoltage(int iXMirrorControlVoltage);
- // 设置Y振镜电压
- int iSetYMirrorControlVoltage(int iYMirrorControlVoltage);
- // 设置PMT电压
- int iSetPMTControlVoltage(int iPMTControlVoltage);
- // 设置行偏移
- int iSetYMirrorOffset(int iYMirrorOffset);
- // 开启扫描
- int iStartCapture(int iScanRowLowerLimit, int iScanRowUpperLimit);
- // 停止扫描
- int iStopCapture(int iScanRowLowerLimit, int iScanRowUpperLimit);
- // 设置行起始结束位置
- int iSetScanRowRange(int iScanInnerRowLowerLimit, int iScanInnerRowUpperLimit);
- // 设置扫描类型
- int iSetScanType(int iScanDirectionType);
- // 设置X振镜行列偏移
- int iSetXMirrorOffset(int iXMirrorOffset);
- // 设置X振镜偶数行列偏移
- int iSetXMirrorEvenOffset(int iXMirrorEvenOffset);
- // 设置X振镜基数行列偏移
- int iSetXMirrorOddOffset(int iXMirrorOddOffset);
- // 设置畸变校正参数
- int iSetCorrectionParam(const stCorrectionParam & correctionParam);
- // 设置行对齐算法参数
- int iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam);
- // 获取Fluorite版本信息
- int iGetFluoriteVer(string & sVer);
- // 获取Fluorite版本信息
- int iGetFluoriteVer(unsigned int &uiVer);
- // 获取定制版本信息
- int iGetFluoriteCustomVer(string& sVer);
- // 设置亮度数据类型
- int iSetLumDataType(int iLumDataType);
- // 获取行对齐参数
- int iGetLineAlignAlgParam(stLineAlignAlgParam & lineAlignAlgParam);
- // 获取FPGA错误状态
- int iGetFPGAErrorStatus(int & iErrorStatus);
- // 设置激光器类型
- int iSetLaserType(int LaserType);
-
- protected:
- // FPGA器件检查线程
- void FPGAComCheckThread();
- // 获取Syn周期
- int iGetSynPeriodAndDCLKperiod(float &fSYNCPeriod, int & iDCLKperiod);
- // 获取
- int iGetPixenableCount(int &iPixenableCount);
- private:
- // bram控制
- CBramCtrl * m_bramCtrl;
- // 运行开始时间
- time_t m_tStartTime;
- // 扫描操作互斥锁
- mutex m_mtxCaputre;
- };
CFPGAComCtrl.cpp
- #include <stdlib.h>
- #include <unistd.h>
- #include <iomanip>
- #include "Log.h"
- #include "FPGAComCtrl.h"
- #include "DeviceParamMng.h"
- #include "DeviceStatusMng.h"
- #include "SettingParamMng.h"
-
- #define SYNCSignalPeriod 250
- // FPGA检查的时间间隔
- const int cniCheckFPGAInterval = 3;
-
- // 构造函数
- CFPGAComCtrl::CFPGAComCtrl(CBramCtrl * bramCtrl)
- :CThreadProc(1)
- {
- m_bramCtrl = bramCtrl;
- m_tStartTime = 0;
- return;
- }
- // 析构函数
- CFPGAComCtrl::~CFPGAComCtrl()
- {
- return;
- }
- // 初始化
- int CFPGAComCtrl::iInitialize()
- {
- // 设置扫描方式
- int iScanDirectionType = CDeviceParamMng::GetInstance()->iGetScanType();
- if (EXIT_FAILURE == iSetScanType(iScanDirectionType))
- {
- ostringstream os;
- os << "failed to set ScanType[" << iScanDirectionType << "]" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- CDeviceStatusMng::GetInstance()->iSetScanType(iScanDirectionType);
-
- // 获取SYNC时钟周期
- float fSYNCPeriod;
- int iDCLKperiod;
- if (EXIT_FAILURE == iGetSynPeriodAndDCLKperiod(fSYNCPeriod, iDCLKperiod))
- {
- ostringstream os;
- os << "failed to get SYNPeriod" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- int iSYNCPeriod = fSYNCPeriod;
- CDeviceStatusMng::GetInstance()->iSetSYNCPeriod(iSYNCPeriod);
- m_tStartTime = time(NULL);
- return open();
- }
-
- // 服务
- int CFPGAComCtrl::src(int id)
- {
- if (0 == id)
- {
- FPGAComCheckThread();
- }
- return EXIT_SUCCESS;
- }
-
- int CFPGAComCtrl::iSetLaserType(int LaserType)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetLaser(LaserType);
- }
-
- // 设置X振镜电压
- int CFPGAComCtrl::iSetXMirrorControlVoltage(int iXMirrorControlVoltage)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetXMirrorControlVoltage(iXMirrorControlVoltage);
- }
- // 设置Y振镜电压
- int CFPGAComCtrl::iSetYMirrorControlVoltage(int iYMirrorControlVoltage)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetYMirrorControlVoltage(iYMirrorControlVoltage);
- }
- // 设置PMT电压
- int CFPGAComCtrl::iSetPMTControlVoltage(int iPMTControlVoltage)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetPMTControlVoltage(iPMTControlVoltage);
- }
- // 设置行偏移
- int CFPGAComCtrl::iSetYMirrorOffset(int iYMirrorOffset)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetYMirrorOffset(iYMirrorOffset);
- }
-
- // 开启扫描
- int CFPGAComCtrl::iStartCapture(int iScanRowLowerLimit, int iScanRowUpperLimit)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- int iRet = EXIT_SUCCESS;
- string sErr;
- {
- lock_guard<mutex>guard(m_mtxCaputre);
- if (EXIT_FAILURE == m_bramCtrl->iSetScanRowRangeOper(StopDMATransmitFlag, iScanRowLowerLimit, iScanRowUpperLimit))
- {
- ostringstream os;
- os << "failed to stop capture" << endl;
- sErr = os.str();
- iRet = EXIT_FAILURE;
- }
- else
- {
- if (EXIT_FAILURE == m_bramCtrl->iSetScanRowRangeOper(BeginDMATransmitFlag, iScanRowLowerLimit, iScanRowUpperLimit))
- {
- ostringstream os;
- os << "failed to start capture" << endl;
- sErr = os.str();
- iRet = EXIT_FAILURE;
- }
- }
- }
- if (EXIT_FAILURE == iRet)
- {
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, sErr, Log_Error);
- return EXIT_FAILURE;
- }
- else
- {
- return EXIT_SUCCESS;
- }
- }
-
- // 停止扫描
- int CFPGAComCtrl::iStopCapture(int iScanRowLowerLimit, int iScanRowUpperLimit)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- int iRet = EXIT_FAILURE;
- {
- lock_guard<mutex>guard(m_mtxCaputre);
- iRet = m_bramCtrl->iSetScanRowRangeOper(StopDMATransmitFlag, iScanRowLowerLimit, iScanRowUpperLimit);
- }
- return iRet;
- }
-
- // 设置行起始结束位置
- int CFPGAComCtrl::iSetScanRowRange(int iScanInnerRowLowerLimit, int iScanInnerRowUpperLimit)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- int iRet = EXIT_SUCCESS;
- string sErr;
- {
- lock_guard<mutex>guard(m_mtxCaputre);
- int iOper;
- int iOldScanInnerRowLowerLimit;
- int iOldScanInnerRowUpperLimit;
- if (EXIT_FAILURE == m_bramCtrl->iGetScanRowRangeOper(iOper, iOldScanInnerRowLowerLimit, iOldScanInnerRowUpperLimit))
- {
- ostringstream os;
- os << "failed to get ScanRowRangeOper" << endl;
- sErr = os.str();
- iRet = EXIT_FAILURE;
- }
- else
- {
- if (EXIT_FAILURE == m_bramCtrl->iSetScanRowRangeOper(iOper, iScanInnerRowLowerLimit, iScanInnerRowUpperLimit))
- {
- ostringstream os;
- os << "failed to set scanRowRange[" << iScanInnerRowLowerLimit << "," << iScanInnerRowUpperLimit << "]" << endl;
- sErr = os.str();
- iRet = EXIT_FAILURE;
- }
- }
- }
- if (EXIT_FAILURE == iRet)
- {
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, sErr, Log_Error);
- return EXIT_FAILURE;
- }
- else
- {
- return EXIT_SUCCESS;
- }
- }
-
- // 设置扫描类型
- int CFPGAComCtrl::iSetScanType(int iScanDirectionType)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetScanType(iScanDirectionType);
- }
- // 设置X振镜行列偏移
- int CFPGAComCtrl::iSetXMirrorOffset(int iXMirrorOffset)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetXMirrorOffset(iXMirrorOffset);
- }
- // 设置X振镜偶数行列偏移
- int CFPGAComCtrl::iSetXMirrorEvenOffset(int iXMirrorEvenOffset)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetXMirrorEvenOffset(iXMirrorEvenOffset);
- }
- // 设置X振镜基数行列偏移
- int CFPGAComCtrl::iSetXMirrorOddOffset(int iXMirrorOddOffset)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetXMirrorOddOffset(iXMirrorOddOffset);
- }
- // 设置畸变校正参数
- int CFPGAComCtrl::iSetCorrectionParam(const stCorrectionParam & correctionParam)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetCorrectionParam(correctionParam);
- }
- // 设置行对齐算法参数
- int CFPGAComCtrl::iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetLineAlignAlgParam(lineAlignAlgParam);
- }
- // 获取Fluorite版本信息
- int CFPGAComCtrl::iGetFluoriteVer(string & sVer)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iGetFluoriteVer(sVer);
- }
-
- // 获取Fluorite版本信息
- int CFPGAComCtrl::iGetFluoriteVer(unsigned int &uiVer)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iGetFluoriteVer(uiVer);
- }
-
- // 获取定制版本信息
- int CFPGAComCtrl::iGetFluoriteCustomVer(string& sVer)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iGetFluoriteCustomVer(sVer);
- }
-
- // 设置亮度数据类型
- int CFPGAComCtrl::iSetLumDataType(int iLumDataType)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iSetLumDataType(iLumDataType);
- }
-
- // 获取行对齐参数
- int CFPGAComCtrl::iGetLineAlignAlgParam(stLineAlignAlgParam & lineAlignAlgParam)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iGetLineAlignAlgParam(lineAlignAlgParam);
- }
-
-
- // 获取FPGA错误状态
- int CFPGAComCtrl::iGetFPGAErrorStatus(int & iErrorStatus)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iGetFPGAErrorStatus(iErrorStatus);
- }
-
- // FPGA器件检查线程
- void CFPGAComCtrl::FPGAComCheckThread()
- {
- bool bExitFlag = bGetExitFlag();
- int iDCLKperiod = 0;
- float fSYNCPeriod = 0.0;
- while (!bExitFlag)
- {
- // 获取设置模块就绪标识
- if (CSettingParamMng::GetInstance()->bGetInitFinishedFlag())
- {
- // 获取SYNCPeriod和iDCLKperiod
- int iNewDCLKperiod;
- if (EXIT_FAILURE == iGetSynPeriodAndDCLKperiod(fSYNCPeriod, iNewDCLKperiod))
- {
- ostringstream os;
- os << "failed to get SynPeriod And DCLKperiod" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- }
- else
- {
- int iSYNCPeriod = fSYNCPeriod;
- CDeviceStatusMng::GetInstance()->iSetSYNCPeriod(iSYNCPeriod);
- stStateMsg stateMsg;
- stateMsg.m_enComType = enDeviceComType_Scanner;
- if (0.0 == fSYNCPeriod)
- {
- stateMsg.m_deviceStateCode.m_iCode = STATE_SYS_ERR;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = DevError_SCANNER_CODE_ERR;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comStateCode.m_iCode = SCANNER_ERR;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comErrorcode.m_iCode = ~SYNCPeriodOVERFLOW_ERROR_CODE;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
- CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
- stateMsg.m_comErrorcode.m_iCode = NOSYNCPeriod_ERROR_CODE;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
- }
- else if ((fSYNCPeriod > SYNCSignalPeriod + 10) ||
- (fSYNCPeriod < SYNCSignalPeriod - 10))//当SYNC周期超过范围时
- {
- stateMsg.m_deviceStateCode.m_iCode = STATE_SYS_ERR;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = DevError_SCANNER_CODE_ERR;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comStateCode.m_iCode = SCANNER_ERR;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comErrorcode.m_iCode = SYNCPeriodOVERFLOW_ERROR_CODE;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
- CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
- stateMsg.m_comErrorcode.m_iCode = ~NOSYNCPeriod_ERROR_CODE;;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
- }
- else
- {
- stateMsg.m_deviceStateCode.m_iCode = 0;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = 0;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comStateCode.m_iCode = 0;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comErrorcode.m_iCode = (~SYNCPeriodOVERFLOW_ERROR_CODE & ~NOSYNCPeriod_ERROR_CODE);
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
- }
- CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
-
-
- if (iDCLKperiod != iNewDCLKperiod)
- {
- stateMsg.m_deviceStateCode.m_iCode = 0;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = 0;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comStateCode.m_iCode = 0;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comErrorcode.m_iCode = ~NOCRSClock_ERROR_CODE;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
- }
- else
- {
- stateMsg.m_deviceStateCode.m_iCode = STATE_SYS_ERR;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = DevError_SCANNER_CODE_ERR;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comStateCode.m_iCode = SCANNER_ERR;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comErrorcode.m_iCode = NOCRSClock_ERROR_CODE;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
- }
- CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
-
-
- if (((fSYNCPeriod <= SYNCSignalPeriod + 10) && (fSYNCPeriod >= SYNCSignalPeriod - 10)) && iDCLKperiod != iNewDCLKperiod)
- {
- stateMsg.m_deviceStateCode.m_iCode = 0;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = ~DevError_SCANNER_CODE_ERR;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperAnd;
- stateMsg.m_comStateCode.m_iCode = 0;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comErrorcode.m_iCode = 0;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
- CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
- }
- iDCLKperiod = iNewDCLKperiod;
- }
-
- // 获取行对齐算法参数并更新
- stLineAlignAlgParam lineAlignAlgParam;
- if (EXIT_SUCCESS == iGetLineAlignAlgParam(lineAlignAlgParam))
- {
- CDeviceStatusMng::GetInstance()->iSetLineAlignAlgParam(lineAlignAlgParam);
- }
-
- // 获取FPGA错误状态
- int iErrorStatus = 0;
- if (EXIT_SUCCESS == iGetFPGAErrorStatus(iErrorStatus))
- {
- ostringstream os;
- if (0 != (iErrorStatus & 0x1))
- {
- os << "[DMA full]";
- }
- if (0 != (iErrorStatus & 0x2))
- {
- os << "[SeqNo discontinuous,when writing DMA FIFO]";
- }
- if (0 != (iErrorStatus & 0x4))
- {
- os << "[SeqNo discontinuous,when reading DMA FIFO]";
- }
- if (0 != (iErrorStatus & 0x8))
- {
- os << "[SeqNo discontinuous,when Writing FIFO in Capturing-terminal]";
- }
- if (0 != (iErrorStatus & 0x10))
- {
- os << "[SeqNo discontinuous,when reading FIFO in Capturing-terminal]";
- }
- if (0 != (iErrorStatus & 0x20))
- {
- os << "[DCLK signal disappear]";
- }
- if (0 != (iErrorStatus & 0x40))
- {
- os << "[SYNC signal excception]";
- }
- string sFPGAErrorStatusInfo = os.str();
- if (!sFPGAErrorStatusInfo.empty())
- {
- ostringstream osNew;
- osNew << hex << "FPGAErrorStatus:0x" << setw(8) << setfill('0') << iErrorStatus << endl;
- osNew << sFPGAErrorStatusInfo << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, osNew.str(), Log_Error);
- }
- }
- }
-
- // 获取Fluorite版本号
- unsigned int uiFluoriteVer;
- if (EXIT_FAILURE == iGetFluoriteVer(uiFluoriteVer))
- {
- ostringstream os;
- os << "failed to get Fluorite Version" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- }
- else
- {
- stStateMsg stateMsg;
- stateMsg.m_enComType = enDeviceComType_Scanner;
- if (uiFluoriteVer < 0x1010000) //判断版本号是否匹配
- {
- stateMsg.m_deviceStateCode.m_iCode = STATE_SYS_ERR;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = DevErrorCode_FPGAVerNoMath_ERR;
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comStateCode.m_iCode = SCANNER_ERR;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comErrorcode.m_iCode = SCANNER_ERROR_CODE;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
- }
- else
- {
- stateMsg.m_deviceStateCode.m_iCode = 0;
- stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_deviceErrorCode.m_iCode = (~DevErrorCode_FPGAVerNoMath_ERR);
- stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperAnd;
- stateMsg.m_comStateCode.m_iCode = 0;
- stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
- stateMsg.m_comErrorcode.m_iCode = ~SCANNER_ERROR_CODE;
- stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
- }
- CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
- }
-
- // 运行时间计数
- sleep(cniCheckFPGAInterval);
- static int iRunningTimeBeforeUpdateDate = 0;
- static int iLastRunningTime = 0;
- int iCurRunningTime = time(NULL) - m_tStartTime;
- if (cniCheckFPGAInterval*3 < (iCurRunningTime - iLastRunningTime))
- {
- m_tStartTime = time(NULL);
- iRunningTimeBeforeUpdateDate = iLastRunningTime;
- iCurRunningTime = iRunningTimeBeforeUpdateDate + cniCheckFPGAInterval;
- }
- else
- {
- iCurRunningTime = iCurRunningTime + iRunningTimeBeforeUpdateDate;
- }
- CDeviceStatusMng::GetInstance()->iSetRunningTime(iCurRunningTime);
- iLastRunningTime = iCurRunningTime;
- bExitFlag = bGetExitFlag();
- }
- return;
- }
-
- // 获取Syn周期
- int CFPGAComCtrl::iGetSynPeriodAndDCLKperiod(float &fSYNCPeriod, int & iDCLKperiod)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iGetSynPeriodAndDCLKperiod(fSYNCPeriod, iDCLKperiod);
- }
- // 获取
- int CFPGAComCtrl::iGetPixenableCount(int &iPixenableCount)
- {
- if (nullptr == m_bramCtrl)
- {
- ostringstream os;
- os << "BramCtrlPointer can't be empty" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return m_bramCtrl->iGetPixenableCount(iPixenableCount);
- }
BRAM控制定义
CBramCtrl.h
- #pragma once
- #include <string>
- #include <mutex>
- #include "InnerDeviceInfo.h"
- #include "BramDef.h"
- using namespace std;
- class CBramCtrl
- {
- public:
- // 构造函数
- CBramCtrl(const string & sDriverFile);
- // 析构函数
- ~CBramCtrl();
- // 初始化
- int iInitialize();
- public:
- // 设置X振镜电压
- int iSetXMirrorControlVoltage(int iXMirrorControlVoltage);
- // 设置Y振镜电压
- int iSetYMirrorControlVoltage(int iYMirrorControlVoltage);
- // 设置PMT电压
- int iSetPMTControlVoltage(int iPMTControlVoltage);
- // 设置电机位置
- int iSetMotorPos(int iMotorPos);
- // 设置Y振镜偏移
- int iSetYMirrorOffset(int iYMirrorOffset);
- // 设置扫描方式
- int iSetScanType(int iScanDirectionType);
- // 设置X振镜行列偏移
- int iSetXMirrorOffset(int iXMirrorOffset);
- // 设置偶数行列偏移
- int iSetXMirrorEvenOffset(int iXMirrorEvenOffset);
- // 设置奇数行列偏移
- int iSetXMirrorOddOffset(int iXMirrorOddOffset);
- // 设置畸变校正参数
- int iSetCorrectionParam(const stCorrectionParam & correctionParam);
- // 设置行对齐算法参数
- int iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam);
- // 设置亮度数据类型
- int iSetLumDataType(int iLumDataType);
- // 获取电机位置
- int iGetMotorPosStatus(bool & bMotorMoveFlag, int &iStatus, int & iPos);
- // 获取Syn周期
- int iGetSynPeriodAndDCLKperiod(float &fSYNCPeriod, int & iDCLKperiod);
- // 获取Fluorite版本
- int iGetFluoriteVer(string & sVer);
- // 获取Fluorite版本
- int iGetFluoriteVer(unsigned int &uiVer);
- // 获取Fluorite定制版本
- int iGetFluoriteCustomVer(string& sVer);
- // 获取Pixenable计数
- int iGetPixenableCount(int &iPixenableCount);
- // 设置扫描起始行与接收行
- int iSetScanRowRangeOper(int iOper, int iScanRowLowerLimit, int iScanRowUpperLimit);
- // 设置电机限制范围
- int iSetMotorPosRange(int iMotorPosLowerLimit, int iMotorPosUpperLimit);
- // 获取扫描范围信息
- int iGetScanRowRangeOper(int &iOper, int &iScanRowLowerLimit, int &iScanRowUpperLimit);
- // 获取行对齐参数
- int iGetLineAlignAlgParam(stLineAlignAlgParam & lineAlignAlgParam);
- // 获取FPGA错误状态
- int iGetFPGAErrorStatus(int & iErrorStatus);
- // 设置激光器类型
- int iSetLaser(int iLaserType);
- protected:
- // 读取数据
- int iRead(stReg & reg);
- // 写入数据
- int iWrite(const stReg & reg);
- private:
- // 驱动文件
- string m_sDriverFile;
- // 驱动文件句柄
- int m_iFileHandle;
- // 访问互斥
- mutex m_mtxAcc;
-
- };
-
CBramCtrl.cpp
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <iomanip>
- #include "Log.h"
- #include "BramCtrl.h"
- #include "CommandInfo.h"
-
- // 构造函数
- CBramCtrl::CBramCtrl(const string & sDriverFile)
- {
- m_iFileHandle = -1;
- m_sDriverFile = sDriverFile;
- return;
- }
-
- // 析构函数
- CBramCtrl::~CBramCtrl()
- {
- if (-1 != m_iFileHandle)
- {
- close(m_iFileHandle);
- m_iFileHandle = -1;
- }
- return;
- }
-
- // 初始化
- int CBramCtrl::iInitialize()
- {
- m_iFileHandle = open(m_sDriverFile.c_str(), O_RDWR);
- if (m_iFileHandle < 0)
- {
- ostringstream os;
- os << "failed to open File[" << m_sDriverFile << "]" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
- // 设置激光器类型
- int CBramCtrl::iSetLaser(int iLaserType)
- {
- stReg reg;
- unsigned int backdata = 0;
- reg.address = LaserTypeAddr;
- backdata = AcitveFlag << 24 | iLaserType;
- reg.data = backdata;
- return iWrite(reg);
- }
-
- // 设置X振镜电压
- int CBramCtrl::iSetXMirrorControlVoltage(int iXMirrorControlVoltage)
- {
- int iXVoltageValue = iXMirrorControlVoltage * 4095; // 毫伏单位mV
- iXVoltageValue = iXVoltageValue / cniXMirrorControlVoltageUpperLimit;
- iXVoltageValue = iXVoltageValue << 2;
- stReg reg;
- unsigned int backdata = 0;
- reg.address = WriteXcrsVoltageAddr;
- backdata = AcitveFlag << 24 | iXVoltageValue;
- reg.data = backdata;
- return iWrite(reg);
- }
-
- // 设置Y振镜电压
- int CBramCtrl::iSetYMirrorControlVoltage(int iYMirrorControlVoltage)
- {
- int iYVoltageValue = iYMirrorControlVoltage * 4095; // 毫伏单位mV
- iYVoltageValue = iYVoltageValue / cniYMirrorControlVoltageUpperLimit;
- iYVoltageValue = iYVoltageValue << 2;
- stReg reg;
- unsigned int backdata = 0;
- reg.address = WriteYcrsVoltageAddr;
- backdata = AcitveFlag << 24 | iYVoltageValue;
- reg.data = backdata;
- return iWrite(reg);
- }
-
- // 设置PMT电压
- int CBramCtrl::iSetPMTControlVoltage(int iPMTControlVoltage)
- {
- int iPMTVoltageValue = iPMTControlVoltage * 4095; // 毫伏单位mV
- iPMTVoltageValue = iPMTVoltageValue / cniPMTControlVoltageUpperLimit;
- iPMTVoltageValue = iPMTVoltageValue << 2;
- stReg reg;
- reg.address = WritePMTVoltageAddr;
- reg.data = AcitveFlag << 24 | iPMTVoltageValue;
- return iWrite(reg);
- }
-
- // 设置电机位置
- int CBramCtrl::iSetMotorPos(int iMotorPos)
- {
- int iAbsMotorPos;
- unsigned char nDir;
- if (iMotorPos < 0)
- {
- iAbsMotorPos = -iMotorPos;
- nDir = 0;
-
- }
- else
- {
- iAbsMotorPos = iMotorPos;
- nDir = 1;
- }
- uint16_t IncDecSpeedstepLength = 0;
- uint8_t DirectionValue = 0;
- uint32_t dat = 0;
- uint8_t StepMotorFrequence = 0;
- uint8_t IncDecEnableFlag = 0;
-
- if (iAbsMotorPos > 400)
- {
- StepMotorFrequence = 150;
- IncDecEnableFlag = 1;
- IncDecSpeedstepLength = 100;
-
- }
- else if (iAbsMotorPos > 200)
- {
- StepMotorFrequence = 130;
- IncDecEnableFlag = 1;
- IncDecSpeedstepLength = 100;
-
- }
- else if (iAbsMotorPos > 100)
- {
- StepMotorFrequence = 80;
- IncDecEnableFlag = 1;
- IncDecSpeedstepLength = 50;
-
-
- }
- else if (iAbsMotorPos > 50)
- {
- StepMotorFrequence = 30;
- IncDecEnableFlag = 1;
- IncDecSpeedstepLength = 25;
-
-
- }
- else if (iAbsMotorPos > 20)
- {
- StepMotorFrequence = 20;
- IncDecEnableFlag = 1;
- IncDecSpeedstepLength = 10;
-
-
- }
- else if (iAbsMotorPos > 10)
- {
- StepMotorFrequence = 10;
- IncDecEnableFlag = 1;
- IncDecSpeedstepLength = 5;
-
-
- }
- else if (iAbsMotorPos > 5)
- {
- StepMotorFrequence = 2;
- IncDecEnableFlag = 5;
- IncDecSpeedstepLength = 3;
-
-
- }
- else
- {
- StepMotorFrequence = 1;//1
- IncDecEnableFlag = 5;
- IncDecSpeedstepLength = 2;
- }
-
- /************************如下是对焦电机移动控制命令********************************************/
- stReg reg;
- reg.address = SetStepMotorPositionAddr;
- if (nDir > 0) //设置方向
- {
- DirectionValue = 0x0f;
- }
- else
- {
- DirectionValue = 0;
- }
-
- reg.data = 0x5 << 28 | DirectionValue << 24 | StepMotorFrequence << 16 | iAbsMotorPos;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to write Motor position" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
-
- /************************如下是对焦电机加减速算法参数设置********************************************/
- reg.address = SetpMotorParameterAddr;
- reg.data = AcitveFlag << 24 | Flexible << 20 | IncDecEnableFlag << 16 | IncDecSpeedstepLength;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to write MotorParam" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
- // 设置Y振镜偏移
- int CBramCtrl::iSetYMirrorOffset(int iYMirrorOffset)
- {
- int iAbsYMirrorOffset;
- unsigned char nDir;
- if (iYMirrorOffset < 0)
- {
- iAbsYMirrorOffset = -iYMirrorOffset;
- nDir = 0;
-
- }
- else
- {
- iAbsYMirrorOffset = iYMirrorOffset;
- nDir = 1;
- }
- unsigned int backdata;
- uint8_t DirectionFlag;
- stReg reg;
- reg.address = SetRowCountOffsetAddr; //行号偏移数据地址.
- if (nDir) //正方向
- {
- DirectionFlag = 0xf;
- }
- else
- //负方向
- {
- DirectionFlag = 0; //8位有效标志(0x55), 8位序列号, 4位方向, 12位偏移值
- }
- backdata = AcitveFlag << 24 | (DirectionFlag << 16) | iAbsYMirrorOffset;
- reg.data = backdata;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to set YMirrorOffset[" << hex << backdata << "]" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
- // 设置扫描起始行与接收行
- int CBramCtrl::iSetScanRowRangeOper(int iOper, int iScanRowLowerLimit, int iScanRowUpperLimit)
- {
- stReg reg;
- reg.address = WriteCaptureStartEndPositionAddr; //BRAM地址 28
- reg.data = (iOper << 28) | (iScanRowLowerLimit << 16) | iScanRowUpperLimit;
- return iWrite(reg);
- }
-
- // 设置电机限制范围
- int CBramCtrl::iSetMotorPosRange(int iMotorPosLowerLimit, int iMotorPosUpperLimit)
- {
- stReg reg;
- reg.address = SetMotorRangeAddr; //BRAM地址 28
- reg.data = (iMotorPosUpperLimit << 16) | iMotorPosLowerLimit;
- return iWrite(reg);
- }
-
- // 获取扫描范围信息
- int CBramCtrl::iGetScanRowRangeOper(int &iOper, int &iScanRowLowerLimit, int &iScanRowUpperLimit)
- {
- stReg reg;
- reg.address = WriteCaptureStartEndPositionAddr; //BRAM地址 28
- if (EXIT_FAILURE == iRead(reg))
- {
- return EXIT_FAILURE;
- }
- iOper = (reg.data >> 28) & 0xf;
- iScanRowLowerLimit = (reg.data >> 16) & 0xfff;
- iScanRowUpperLimit = reg.data & 0xffff;
- return EXIT_SUCCESS;
- }
-
- // 获取行对齐参数
- int CBramCtrl::iGetLineAlignAlgParam(stLineAlignAlgParam & lineAlignAlgParam)
- {
- stReg reg;
- //reg.address = SetLineAlignAlgParamAddr; //行对齐参数地址
- reg.address = LineAlignAlgParamStatusAddr;
-
- if (EXIT_FAILURE == iRead(reg))
- {
- ostringstream os;
- os << "failed to set LineAlignAlgParam[" << hex << reg.data << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- lineAlignAlgParam.m_iLineAlignAlgEnable = ((reg.data >> 28)==5)? 1: 0;
- lineAlignAlgParam.m_iLineAlignOffset = (((reg.data >> 16)&0xfff)-512);
- lineAlignAlgParam.m_iLineAlignInterval = (reg.data & 0xffff);
- return EXIT_SUCCESS;
- }
-
-
- // 获取FPGA错误状态
- int CBramCtrl::iGetFPGAErrorStatus(int & iErrorStatus)
- {
- stReg reg;
- reg.address = FPGAErrorStatusAddr;
- if (EXIT_FAILURE == iRead(reg))
- {
- ostringstream os;
- os << "failed to set LineAlignAlgParam[" << hex << reg.data << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- iErrorStatus = reg.data;
- return EXIT_SUCCESS;
- }
-
- // 设置扫描方式
- int CBramCtrl::iSetScanType(int iScanDirectionType)
- {
- int iInnerScanType = 0;
- if (0 == iScanDirectionType)
- {
- iInnerScanType = 0;
- }
- else
- {
- iInnerScanType = 3;
- }
- stReg reg;
- reg.address = SetScanTypeAddr; //行号偏移数据地址.
- reg.data = AcitveFlag << 24 | iInnerScanType;;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to set scanType[" << hex << reg.data << "]" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- // 设置X振镜行列偏移
- int CBramCtrl::iSetXMirrorOffset(int iXMirrorOffset)
- {
- uint32_t backdata = 0;
- backdata = AcitveFlag << 24 | iXMirrorOffset;
- stReg reg;
- reg.address = SetOneDirSampleImageBeginFallingDelayValueAddr;
- reg.data = backdata;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to set One-direction scanType's iXMirrorOffset" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- // 设置偶数行列偏移
- int CBramCtrl::iSetXMirrorEvenOffset(int iXMirrorEvenOffset)
- {
- uint32_t backdata = 0;
- backdata = AcitveFlag << 24 | iXMirrorEvenOffset;
- stReg reg;
- reg.address = SetSampleImageBeginFallingDelayValueAddr;
- reg.data = backdata;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to set Two-direction scanType's XMirrorEvenOffset" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- // 设置奇数行列偏移
- int CBramCtrl::iSetXMirrorOddOffset(int iXMirrorOddOffset)
- {
- uint32_t backdata = 0;
- backdata = AcitveFlag << 24 | iXMirrorOddOffset;
- stReg reg;
- reg.address = SetSampleImageBeginRisingDelayValueAddr;
- reg.data = backdata;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to set Two-direction scanType's XMirrorOddOffset" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- // 设置畸变校正参数
- int CBramCtrl::iSetCorrectionParam(const stCorrectionParam & correctionParam)
- {
- int iEnableFlag;
- if (1 == correctionParam.m_iCorrectionEnable)
- {
- iEnableFlag = BeginDMATransmitFlag;
- }
- else
- {
- iEnableFlag = 0;
- }
- stReg reg;
- reg.address = SetCorrectionParamAddr; //畸变校正参数地址
- reg.data = iEnableFlag << 28 | correctionParam.m_iStretchCoef << 16 | correctionParam.m_iScanCenterCol;;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to set CorrectionParam[" << hex << reg.data << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- // 设置行对齐算法参数
- int CBramCtrl::iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam)
- {
- int iEnableFlag;
- if (1 == lineAlignAlgParam.m_iLineAlignAlgEnable)
- {
- iEnableFlag = BeginDMATransmitFlag;
- }
- else
- {
- iEnableFlag = 0;
- }
- int iLineAlignOffset = lineAlignAlgParam.m_iLineAlignOffset + 512;
-
- stReg reg;
- reg.address = SetLineAlignAlgParamAddr; //行对齐参数地址
- reg.data = iEnableFlag << 28 | iLineAlignOffset << 16 | lineAlignAlgParam.m_iLineAlignInterval;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to set LineAlignAlgParam[" << hex << reg.data << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- // 设置亮度数据类型
- int CBramCtrl::iSetLumDataType(int iLumDataType)
- {
- stReg reg;
- reg.address = SetLumDataTypeAddr; //畸变校正参数地址
- reg.data = AcitveFlag << 24 | iLumDataType;
- if (EXIT_FAILURE == iWrite(reg))
- {
- ostringstream os;
- os << "failed to set LumDataType[" << hex << reg.data << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
- // 获取电机位置
- int CBramCtrl::iGetMotorPosStatus(bool & bMotorMoveFlag, int &iStatus, int & iPos)
- {
- stReg reg;
- reg.address = ReadStepMotorPositionAddr;
- if (EXIT_FAILURE == iRead(reg))
- {
- ostringstream os;
- os << "failed to read Motor Position" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- iPos = (reg.data & 0xffff);
- iStatus = ((reg.data>>16) & 0x0f);
- bMotorMoveFlag = ((reg.data >> 20) & 0x01);
- return EXIT_SUCCESS;
- }
-
- // 获取DCLK
- int CBramCtrl::iGetSynPeriodAndDCLKperiod(float &fSYNCPeriod, int & iDCLKperiod)
- {
- stReg reg;
- reg.address = SYNCPeriodAddr;
- if (EXIT_FAILURE == iRead(reg))
- {
- ostringstream os;
- os << "failed to read SYNC signal Num" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- fSYNCPeriod = (reg.data & 0xffff);
- fSYNCPeriod = fSYNCPeriod * 0.01;
- iDCLKperiod = ((reg.data >> 16) & 0xffff);
- return EXIT_SUCCESS;
- }
-
- // 获取Fluorite版本
- int CBramCtrl::iGetFluoriteVer(string & sVer)
- {
-
- unsigned int uiVer = 0;
- if (EXIT_FAILURE == iGetFluoriteVer(uiVer))
- {
- return EXIT_FAILURE;
- }
- char *pVer = (char *)&uiVer;
- stringstream os;
- os << "V" << (int)pVer[3] << "." << (int)pVer[2] << "." << (int)pVer[1] << "." << (int)pVer[0];
- sVer = os.str();
- return EXIT_SUCCESS;
- }
-
- // 获取Fluorite版本
- int CBramCtrl::iGetFluoriteVer(unsigned int &uiVer)
- {
- stReg reg;
- reg.address = FPGAVerisionNumAddr;
- if (EXIT_FAILURE == iRead(reg))
- {
- ostringstream os;
- os << "failed to read Fluorite Version" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- uiVer = reg.data;
- return EXIT_SUCCESS;
- }
-
- // 获取Fluorite定制版本
- int CBramCtrl::iGetFluoriteCustomVer(string& sVer)
- {
- stReg reg;
- reg.address = FPGACustomVerisionNumAddr;
- if (EXIT_FAILURE == iRead(reg))
- {
- ostringstream os;
- os << "failed to read Fluorite CustomVersion" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- char *pVer = (char *)®.data;
- ostringstream os;
- os << (int)pVer[1] << "." << (int)pVer[0];
- sVer = os.str();
- return EXIT_SUCCESS;
- }
-
- // 获取Pixenable计数
- int CBramCtrl::iGetPixenableCount(int &iPixenableCount)
- {
- stReg reg;
- reg.address = FPGAPixenableAddr;
- if (EXIT_FAILURE == iRead(reg))
- {
- ostringstream os;
- os << "failed to read PixenableCount" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- iPixenableCount = (reg.data & 0xffff);
- return EXIT_SUCCESS;
- }
-
-
- // 读取数据
- int CBramCtrl::iRead(stReg & reg)
- {
- int iRet;
- {
- lock_guard<mutex> guard(m_mtxAcc);
- iRet = ioctl(m_iFileHandle, RD_COMMAND, ®);
- }
- if (iRet < 0)
- {
- ostringstream os;
- os << "failed to read addr[" << hex << reg.address << "]" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
-
- // 写入数据
- int CBramCtrl::iWrite(const stReg & reg)
- {
- int iRet;
- {
- lock_guard<mutex> guard(m_mtxAcc);
- iRet = ioctl(m_iFileHandle, WR_COMMAND, ®);
- }
- if (iRet < 0)
- {
- ostringstream os;
- os << "failed to write addr[" << hex << reg.address << "]" << endl;
- CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
main()
- int main()
- {
- LaserType = 1;
- LaserType = CDeviceComCtrl::GetInstance()->iSetLaserTypes(LaserType); //通过设计FPGA管脚设置激光器类型,设计为参数0时为旧激光器IBOS,设置参数为1时为新激光器(精英光电)
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。