当前位置:   article > 正文

FPGA端寄存器填写指定数值,转换引脚

FPGA端寄存器填写指定数值,转换引脚

设备器件控制定义

CDeviceComCtrl.h

  1. #pragma once
  2. #include "EMIOCtrl.h"
  3. #include "LumDataCtrl.h"
  4. #include "LEDCtrl.h"
  5. #include "AD9518Ctrl.h"
  6. #include "BramCtrl.h"
  7. #include "FPGAComCtrl.h"
  8. #include "TempVoltSampleCtrl.h"
  9. #include "MotorCtrl.h"
  10. #include "LaserCtrl.h"
  11. #include "ProberCtrl.h"
  12. class CDeviceComCtrl
  13. {
  14. public:
  15. // 析构函数
  16. ~CDeviceComCtrl();
  17. // 第一阶段初始化
  18. int iOneStageInit();
  19. // 第二阶段初始化
  20. int iTwoStageInit();
  21. // 获取单例指针
  22. static CDeviceComCtrl * GetInstance();
  23. public:
  24. //开始采集
  25. int iStartCapture();
  26. //开始行扫描
  27. int iStartRowScan(int iScanInnerRow);
  28. //停止采集
  29. int iStopCapture();
  30. // 设置行起始结束位置
  31. int iSetScanRowRange(int iScanInnerRowLowerLimit, int iScanInnerRowUpperLimit);
  32. // 探头使用次数加1
  33. int iProberUsedTimeAndOne();
  34. // 写探头信息
  35. int iWriteProberInfo(const stProberInfo &proberInfo);
  36. // 读探头信息
  37. int iReadProberInfo(stProberInfo & proberInfo);
  38. // 关闭激光器
  39. int iTurnOffLaser();
  40. // 打开激光器
  41. int iTurnOnLaser();
  42. // 设置激光功率
  43. int iSetLaserPower(int iLaserPower);
  44. // 获取激光器信息
  45. int iGetLaserInfo(stLaserInfo & laserInfo);
  46. // 设置激光器类别
  47. int iSetLaserTypes(int LaserType);
  48. // 打开LED灯
  49. int iTurnOnLED();
  50. // 关闭LED灯
  51. int iTurnOffLED();
  52. // 采集亮度数据
  53. int iSampleLumData(unsigned char * &lumData, int &iDataLen);
  54. // 设置电机位置
  55. int iSetMotorPos(int iPos);
  56. // 获取电机当前位置
  57. int iGetCurMotorPos();
  58. // 设置电机限制范围
  59. int iSetMotorPosRange(int iMotorPosLowerLimit, int iMotorPosUpperLimit);
  60. // 设置X振镜电压
  61. int iSetXMirrorControlVoltage(int iXMirrorControlVoltage);
  62. // 设置Y振镜电压
  63. int iSetYMirrorControlVoltage(int iYMirrorControlVoltage);
  64. // 设置PMT电压
  65. int iSetPMTControlVoltage(int iPMTControlVoltage);
  66. // 设置行偏移值
  67. int iSetYMirrorOffset(int iYMirrorOffset);
  68. // 设置扫描类型
  69. int iSetScanType(int iScanDirectionType);
  70. // 设置X振镜行列偏移
  71. int iSetXMirrorOffset(int iXMirrorOffset);
  72. // 设置X振镜偶数行列偏移
  73. int iSetXMirrorEvenOffset(int iXMirrorEvenOffset);
  74. // 设置奇数行列偏移
  75. int iSetXMirrorOddOffset(int iXMirrorOddOffset);
  76. // 设置畸变校正参数
  77. int iSetCorrectionParam(const stCorrectionParam & correctionParam);
  78. // 设置行对齐算法参数
  79. int iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam);
  80. // 设置亮度数据类型
  81. int iSetLumDataType(int iLumDataType);
  82. // 获取Fluorite版本信息
  83. int iGetFluoriteVer(string & sVer);
  84. // 获取Fluorite定制版本信息
  85. int iGetFluoriteCustomVer(string& sVer);
  86. // 开启扫描
  87. int iStartCapture(int iScanRowLowerLimit, int iScanRowUpperLimit);
  88. // 等待线程退出
  89. void wait();
  90. // 退出线程
  91. void ExitThread();
  92. protected:
  93. // 停止扫描
  94. int iStopCapture(int iScanRowLowerLimit, int iScanRowUpperLimit);
  95. private:
  96. // 构造函数
  97. CDeviceComCtrl();
  98. private:
  99. // 单例指针
  100. static CDeviceComCtrl * m_pInst;
  101. private:
  102. // FPGA器件控制
  103. CFPGAComCtrl * m_pFPGAComCtrl;
  104. // 电机控制
  105. CMotorCtrl * m_pMotorCtrl;
  106. // 激光器控制
  107. CLaserCtrl * m_pLaserCtrl;
  108. // 探头控制
  109. CProberCtrl * m_pProberCtrl;
  110. // 核心温度和电压采集控制
  111. CTempVoltSampleCtrl * m_pTempVoltSampleCtrl;
  112. // AD9518控制
  113. CAD9518Ctrl * m_pAD9518Ctrl;
  114. // LED灯控制
  115. CLEDCtrl * m_pLEDCtrl;
  116. // Bram接口
  117. CBramCtrl * m_pBramCtrl;
  118. // EMIO控制
  119. CEMIOCtrl * m_pEMIOCtrl;
  120. // 亮度数据采集控制
  121. CLumDataCtrl * m_pLumDataCtrl;
  122. };

CDeviceComCtrl.cpp

  1. #include "Log.h"
  2. #include "SettingParamMng.h"
  3. #include "DeviceComCtrl.h"
  4. #include "SysConfigMng.h"
  5. #include "DeviceStatusMng.h"
  6. // 单例指针
  7. CDeviceComCtrl * CDeviceComCtrl::m_pInst = nullptr;
  8. // 构造函数
  9. CDeviceComCtrl::CDeviceComCtrl()
  10. {
  11. // FPGA器件控制
  12. m_pFPGAComCtrl = nullptr;
  13. // 电机控制
  14. m_pMotorCtrl = nullptr;
  15. // 激光器控制
  16. m_pLaserCtrl = nullptr;
  17. // 探头控制
  18. m_pProberCtrl = nullptr;
  19. // 核心温度和电压采集控制
  20. m_pTempVoltSampleCtrl = nullptr;
  21. // EMIO控制
  22. m_pEMIOCtrl = nullptr;
  23. // 亮度数据采集控制
  24. m_pLumDataCtrl = nullptr;
  25. // AD9518控制
  26. m_pAD9518Ctrl = nullptr;
  27. // LED灯控制
  28. m_pLEDCtrl = nullptr;
  29. // Bram接口
  30. m_pBramCtrl = nullptr;
  31. return;
  32. }
  33. // 析构函数
  34. CDeviceComCtrl::~CDeviceComCtrl()
  35. {
  36. if (nullptr != m_pProberCtrl)
  37. {
  38. delete m_pProberCtrl;
  39. m_pProberCtrl = nullptr;
  40. }
  41. if (nullptr != m_pLaserCtrl)
  42. {
  43. delete m_pLaserCtrl;
  44. m_pLaserCtrl = nullptr;
  45. }
  46. if (nullptr != m_pMotorCtrl)
  47. {
  48. delete m_pMotorCtrl;
  49. m_pMotorCtrl = nullptr;
  50. }
  51. if (nullptr != m_pAD9518Ctrl)
  52. {
  53. delete m_pAD9518Ctrl;
  54. m_pAD9518Ctrl = nullptr;
  55. }
  56. if (nullptr != m_pTempVoltSampleCtrl)
  57. {
  58. delete m_pTempVoltSampleCtrl;
  59. m_pTempVoltSampleCtrl = nullptr;
  60. }
  61. if (nullptr != m_pLEDCtrl)
  62. {
  63. delete m_pLEDCtrl;
  64. m_pLEDCtrl = nullptr;
  65. }
  66. if (nullptr != m_pFPGAComCtrl)
  67. {
  68. delete m_pFPGAComCtrl;
  69. m_pFPGAComCtrl = nullptr;
  70. }
  71. if (nullptr != m_pBramCtrl)
  72. {
  73. delete m_pBramCtrl;
  74. m_pBramCtrl = nullptr;
  75. }
  76. if (nullptr != m_pEMIOCtrl)
  77. {
  78. delete m_pEMIOCtrl;
  79. m_pEMIOCtrl = nullptr;
  80. }
  81. if (nullptr != m_pLumDataCtrl)
  82. {
  83. delete m_pLumDataCtrl;
  84. m_pLumDataCtrl = nullptr;
  85. }
  86. return;
  87. }
  88. // 第一阶段初始化
  89. int CDeviceComCtrl::iOneStageInit()
  90. {
  91. stDeviceComCtrlConfig deviceComCtrlConfig = CSysConfigMng::GetInstance()->GetDeviceComCtrlConfig();
  92. m_pEMIOCtrl = new CEMIOCtrl();
  93. m_pBramCtrl = new CBramCtrl(deviceComCtrlConfig.m_sBramDriverFile);
  94. m_pAD9518Ctrl = new CAD9518Ctrl(deviceComCtrlConfig.m_emioConfig.m_AD9518SPICSEMIO.m_iEMIOCode, m_pEMIOCtrl, deviceComCtrlConfig.m_sAD9518SPIDriverFile);
  95. m_pTempVoltSampleCtrl = new CTempVoltSampleCtrl();
  96. m_pLumDataCtrl = new CLumDataCtrl(deviceComCtrlConfig.m_sDMADriverFile);
  97. m_pLEDCtrl = new CLEDCtrl(deviceComCtrlConfig.m_emioConfig.m_LEDEnableEMIO.m_iEMIOCode, m_pEMIOCtrl);
  98. m_pFPGAComCtrl = new CFPGAComCtrl(m_pBramCtrl);
  99. m_pMotorCtrl = new CMotorCtrl(m_pBramCtrl, deviceComCtrlConfig.m_emioConfig.m_motorMoveEnableEMIO.m_iEMIOCode, m_pEMIOCtrl);
  100. if (EXIT_FAILURE == m_pEMIOCtrl->iInitialize())
  101. {
  102. return EXIT_FAILURE;
  103. }
  104. if (EXIT_FAILURE == m_pBramCtrl->iInitialize())
  105. {
  106. return EXIT_FAILURE;
  107. }
  108. if (EXIT_FAILURE == m_pAD9518Ctrl->iInitialize())
  109. {
  110. return EXIT_FAILURE;
  111. }
  112. if (EXIT_FAILURE == m_pTempVoltSampleCtrl->iInitialize())
  113. {
  114. return EXIT_FAILURE;
  115. }
  116. if (EXIT_FAILURE == m_pLumDataCtrl->iInitilize())
  117. {
  118. return EXIT_FAILURE;
  119. }
  120. if (EXIT_FAILURE == m_pFPGAComCtrl->iInitialize())
  121. {
  122. return EXIT_FAILURE;
  123. }
  124. if (EXIT_FAILURE == m_pMotorCtrl->iInitialize())
  125. {
  126. return EXIT_FAILURE;
  127. }
  128. return EXIT_SUCCESS;
  129. }
  130. // 第二阶段初始化
  131. int CDeviceComCtrl::iTwoStageInit()
  132. {
  133. // 获取激光器和探头配置信息
  134. stDeviceComCtrlConfig deviceComCtrlConfig = CSysConfigMng::GetInstance()->GetDeviceComCtrlConfig();
  135. m_pLaserCtrl = new CLaserCtrl(deviceComCtrlConfig.m_laserUartConfigInfo, deviceComCtrlConfig.m_emioConfig.m_UartSendEnableEMIO.m_iEMIOCode\
  136. , deviceComCtrlConfig.m_emioConfig.m_UartRecvEnableEMIO.m_iEMIOCode, m_pEMIOCtrl, this);
  137. if (EXIT_FAILURE == m_pLaserCtrl->iInitialize())
  138. {
  139. return EXIT_FAILURE;
  140. }
  141. m_pProberCtrl = new CProberCtrl(deviceComCtrlConfig.m_proberUartConfigInfo, deviceComCtrlConfig.m_emioConfig.m_ProberLockingFlagEMIO.m_iEMIOCode\
  142. , m_pEMIOCtrl, this);
  143. // 初始化探头
  144. if (EXIT_FAILURE == m_pProberCtrl->iInitialize())
  145. {
  146. return EXIT_FAILURE;
  147. }
  148. return EXIT_SUCCESS;
  149. }
  150. // 获取单例指针
  151. CDeviceComCtrl * CDeviceComCtrl::GetInstance()
  152. {
  153. if (nullptr == m_pInst)
  154. {
  155. m_pInst = new CDeviceComCtrl;
  156. }
  157. return m_pInst;
  158. }
  159. //开始采集
  160. int CDeviceComCtrl::iStartCapture()
  161. {
  162. stIntTypeRange scanRowRange = CSettingParamMng::GetInstance()->GetScanRowRange();
  163. if (EXIT_FAILURE == iStartCapture(scanRowRange.m_iLowerLimit, scanRowRange.m_iUpperLimit))
  164. {
  165. return EXIT_FAILURE;
  166. }
  167. return EXIT_SUCCESS;
  168. }
  169. //开始行扫描
  170. int CDeviceComCtrl::iStartRowScan(int iScanInnerRow)
  171. {
  172. if (EXIT_FAILURE == iSetScanRowRange(iScanInnerRow, iScanInnerRow))
  173. {
  174. return EXIT_FAILURE;
  175. }
  176. // 打开LED灯
  177. iTurnOnLED();
  178. // 打开激光器
  179. iTurnOnLaser();
  180. int iPower;
  181. m_pLaserCtrl->iGetLaserPower(iPower);
  182. int iMaxLaserPower = CSettingParamMng::GetInstance()->iGetLaserMaxPower();
  183. int iPowerPercent = iPower * 100 / iMaxLaserPower;
  184. iPowerPercent = iPowerPercent > 100 ? 100 : iPowerPercent;
  185. if (0 == iPowerPercent)
  186. {
  187. ostringstream os;
  188. os << "StartRowScan turn on Laser faild, LaserPower[" << iPower << "]" << endl;;
  189. }
  190. stStateMsg stateMsg;
  191. stateMsg.m_enComType = enDeviceComType_Scanner;
  192. stateMsg.m_deviceStateCode.m_iCode = STATE_EMIT;
  193. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  194. stateMsg.m_deviceErrorCode.m_iCode = 0;
  195. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
  196. stateMsg.m_comStateCode.m_iCode = SCANNER_LINE;
  197. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperCopy;
  198. stateMsg.m_comErrorcode.m_iCode = 0;
  199. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
  200. CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
  201. CDeviceStatusMng::GetInstance()->iSetMessage("Working...", 0);
  202. return EXIT_SUCCESS;
  203. }
  204. //停止采集
  205. int CDeviceComCtrl::iStopCapture()
  206. {
  207. stIntTypeRange scanRowRange = CSettingParamMng::GetInstance()->GetScanRowRange();
  208. if (EXIT_FAILURE == iStopCapture(scanRowRange.m_iLowerLimit, scanRowRange.m_iUpperLimit))
  209. {
  210. return EXIT_FAILURE;
  211. }
  212. return EXIT_SUCCESS;
  213. }
  214. // 设置行起始结束位置
  215. int CDeviceComCtrl::iSetScanRowRange(int iScanInnerRowLowerLimit, int iScanInnerRowUpperLimit)
  216. {
  217. if (nullptr == m_pFPGAComCtrl)
  218. {
  219. ostringstream os;
  220. os << "FPGAComCtrl can't be empty" << endl;
  221. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  222. return EXIT_FAILURE;
  223. }
  224. if (EXIT_FAILURE == m_pFPGAComCtrl->iSetScanRowRange(iScanInnerRowLowerLimit, iScanInnerRowUpperLimit))
  225. {
  226. return EXIT_FAILURE;
  227. }
  228. return EXIT_SUCCESS;
  229. }
  230. // 探头使用次数加1
  231. int CDeviceComCtrl::iProberUsedTimeAndOne()
  232. {
  233. if (nullptr == m_pProberCtrl)
  234. {
  235. ostringstream os;
  236. os << "ProberCtrl can't be empty" << endl;
  237. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  238. return EXIT_FAILURE;
  239. }
  240. return m_pProberCtrl->iProberUsedTimeAndOne();
  241. }
  242. // 写探头信息
  243. int CDeviceComCtrl::iWriteProberInfo(const stProberInfo &proberInfo)
  244. {
  245. if (nullptr == m_pProberCtrl)
  246. {
  247. ostringstream os;
  248. os << "ProberCtrl can't be empty" << endl;
  249. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  250. return EXIT_FAILURE;
  251. }
  252. return m_pProberCtrl->iWriteProberInfo(proberInfo);
  253. }
  254. // 读探头信息
  255. int CDeviceComCtrl::iReadProberInfo(stProberInfo & proberInfo)
  256. {
  257. if (nullptr == m_pProberCtrl)
  258. {
  259. ostringstream os;
  260. os << "ProberCtrl can't be empty" << endl;
  261. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  262. return EXIT_FAILURE;
  263. }
  264. return m_pProberCtrl->iReadProberInfo(proberInfo);
  265. }
  266. // 关闭激光器
  267. int CDeviceComCtrl::iTurnOffLaser()
  268. {
  269. if (nullptr == m_pLaserCtrl)
  270. {
  271. ostringstream os;
  272. os << "LaserCtrl can't be empty" << endl;
  273. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  274. return EXIT_FAILURE;
  275. }
  276. return m_pLaserCtrl->iTurnOffLaser();
  277. }
  278. // 打开激光器
  279. int CDeviceComCtrl::iTurnOnLaser()
  280. {
  281. if (nullptr == m_pLaserCtrl)
  282. {
  283. ostringstream os;
  284. os << "LaserCtrl can't be empty" << endl;
  285. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  286. return EXIT_FAILURE;
  287. }
  288. return m_pLaserCtrl->iTurnOnLaser();
  289. }
  290. // 设置激光功率
  291. int CDeviceComCtrl::iSetLaserPower(int iLaserPower)
  292. {
  293. if (nullptr == m_pLaserCtrl)
  294. {
  295. ostringstream os;
  296. os << "LaserCtrl can't be empty" << endl;
  297. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  298. return EXIT_FAILURE;
  299. }
  300. return m_pLaserCtrl->iSetLaserPower(iLaserPower);
  301. }
  302. // 获取激光器信息
  303. int CDeviceComCtrl::iGetLaserInfo(stLaserInfo & laserInfo)
  304. {
  305. if (nullptr == m_pLaserCtrl)
  306. {
  307. ostringstream os;
  308. os << "LaserCtrl can't be empty" << endl;
  309. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  310. return EXIT_FAILURE;
  311. }
  312. return m_pLaserCtrl->iGetLaserInfo(laserInfo);
  313. }
  314. // 设置激光器类型
  315. int CDeviceComCtrl::iSetLaserTypes(int LaserType)
  316. {
  317. if (nullptr == m_pFPGAComCtrl)
  318. {
  319. ostringstream os;
  320. os << "FPGAComCtrl can't be empty" << endl;
  321. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  322. return EXIT_FAILURE;
  323. }
  324. return m_pFPGAComCtrl->iSetLaserType(LaserType);
  325. }
  326. // 打开LED灯
  327. int CDeviceComCtrl::iTurnOnLED()
  328. {
  329. if (nullptr == m_pLEDCtrl)
  330. {
  331. ostringstream os;
  332. os << "LEDCtrl can't be empty" << endl;
  333. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  334. return EXIT_FAILURE;
  335. }
  336. return m_pLEDCtrl->iTurnOn();
  337. }
  338. // 关闭LED灯
  339. int CDeviceComCtrl::iTurnOffLED()
  340. {
  341. if (nullptr == m_pLEDCtrl)
  342. {
  343. ostringstream os;
  344. os << "LEDCtrl can't be empty" << endl;
  345. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  346. return EXIT_FAILURE;
  347. }
  348. return m_pLEDCtrl->iTurnOff();
  349. }
  350. // 采集亮度数据
  351. int CDeviceComCtrl::iSampleLumData(unsigned char *&lumData, int &iDataLen)
  352. {
  353. if (nullptr == m_pLumDataCtrl)
  354. {
  355. ostringstream os;
  356. os << "LumDataCtrl can't be empty" << endl;
  357. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  358. return EXIT_FAILURE;
  359. }
  360. return m_pLumDataCtrl->iSampleLumData(lumData, iDataLen);
  361. }
  362. // 设置电机位置
  363. int CDeviceComCtrl::iSetMotorPos(int iPos)
  364. {
  365. if (nullptr == m_pMotorCtrl)
  366. {
  367. ostringstream os;
  368. os << "MotorCtrl can't be empty" << endl;
  369. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  370. return EXIT_FAILURE;
  371. }
  372. return m_pMotorCtrl->iSetMotorPos(iPos);
  373. }
  374. // 获取电机当前位置
  375. int CDeviceComCtrl::iGetCurMotorPos()
  376. {
  377. if (nullptr == m_pMotorCtrl)
  378. {
  379. ostringstream os;
  380. os << "MotorCtrl can't be empty" << endl;
  381. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  382. return EXIT_FAILURE;
  383. }
  384. return m_pMotorCtrl->iGetMotorPos();
  385. }
  386. // 设置电机限制范围
  387. int CDeviceComCtrl::iSetMotorPosRange(int iMotorPosLowerLimit, int iMotorPosUpperLimit)
  388. {
  389. if (nullptr == m_pMotorCtrl)
  390. {
  391. ostringstream os;
  392. os << "MotorCtrl can't be empty" << endl;
  393. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  394. return EXIT_FAILURE;
  395. }
  396. return m_pMotorCtrl->iSetMotorPosRange(iMotorPosLowerLimit, iMotorPosUpperLimit);
  397. }
  398. // 设置X振镜电压
  399. int CDeviceComCtrl::iSetXMirrorControlVoltage(int iXMirrorControlVoltage)
  400. {
  401. if (nullptr == m_pFPGAComCtrl)
  402. {
  403. ostringstream os;
  404. os << "FPGAComCtrl can't be empty" << endl;
  405. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  406. return EXIT_FAILURE;
  407. }
  408. return m_pFPGAComCtrl->iSetXMirrorControlVoltage(iXMirrorControlVoltage);
  409. }
  410. // 设置Y振镜电压
  411. int CDeviceComCtrl::iSetYMirrorControlVoltage(int iYMirrorControlVoltage)
  412. {
  413. if (nullptr == m_pFPGAComCtrl)
  414. {
  415. ostringstream os;
  416. os << "FPGAComCtrl can't be empty" << endl;
  417. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  418. return EXIT_FAILURE;
  419. }
  420. return m_pFPGAComCtrl->iSetYMirrorControlVoltage(iYMirrorControlVoltage);
  421. }
  422. // 设置PMT电压
  423. int CDeviceComCtrl::iSetPMTControlVoltage(int iPMTControlVoltage)
  424. {
  425. if (nullptr == m_pFPGAComCtrl)
  426. {
  427. ostringstream os;
  428. os << "FPGAComCtrl can't be empty" << endl;
  429. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  430. return EXIT_FAILURE;
  431. }
  432. return m_pFPGAComCtrl->iSetPMTControlVoltage(iPMTControlVoltage);
  433. }
  434. // 设置行偏移值
  435. int CDeviceComCtrl::iSetYMirrorOffset(int iYMirrorOffset)
  436. {
  437. if (nullptr == m_pFPGAComCtrl)
  438. {
  439. ostringstream os;
  440. os << "FPGAComCtrl can't be empty" << endl;
  441. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  442. return EXIT_FAILURE;
  443. }
  444. return m_pFPGAComCtrl->iSetYMirrorOffset(iYMirrorOffset);
  445. }
  446. // 设置扫描类型
  447. int CDeviceComCtrl::iSetScanType(int iScanDirectionType)
  448. {
  449. if (nullptr == m_pFPGAComCtrl)
  450. {
  451. ostringstream os;
  452. os << "FPGAComCtrl can't be empty" << endl;
  453. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  454. return EXIT_FAILURE;
  455. }
  456. return m_pFPGAComCtrl->iSetScanType(iScanDirectionType);
  457. }
  458. // 设置X振镜行列偏移
  459. int CDeviceComCtrl::iSetXMirrorOffset(int iXMirrorOffset)
  460. {
  461. if (nullptr == m_pFPGAComCtrl)
  462. {
  463. ostringstream os;
  464. os << "FPGAComCtrl can't be empty" << endl;
  465. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  466. return EXIT_FAILURE;
  467. }
  468. return m_pFPGAComCtrl->iSetXMirrorOffset(iXMirrorOffset);
  469. }
  470. // 设置X振镜偶数行列偏移
  471. int CDeviceComCtrl::iSetXMirrorEvenOffset(int iXMirrorEvenOffset)
  472. {
  473. if (nullptr == m_pFPGAComCtrl)
  474. {
  475. ostringstream os;
  476. os << "FPGAComCtrl can't be empty" << endl;
  477. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  478. return EXIT_FAILURE;
  479. }
  480. return m_pFPGAComCtrl->iSetXMirrorEvenOffset(iXMirrorEvenOffset);
  481. }
  482. // 设置奇数行列偏移
  483. int CDeviceComCtrl::iSetXMirrorOddOffset(int iXMirrorOddOffset)
  484. {
  485. if (nullptr == m_pFPGAComCtrl)
  486. {
  487. ostringstream os;
  488. os << "FPGAComCtrl can't be empty" << endl;
  489. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  490. return EXIT_FAILURE;
  491. }
  492. return m_pFPGAComCtrl->iSetXMirrorOddOffset(iXMirrorOddOffset);
  493. }
  494. // 设置畸变校正参数
  495. int CDeviceComCtrl::iSetCorrectionParam(const stCorrectionParam & correctionParam)
  496. {
  497. if (nullptr == m_pFPGAComCtrl)
  498. {
  499. ostringstream os;
  500. os << "FPGAComCtrl can't be empty" << endl;
  501. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  502. return EXIT_FAILURE;
  503. }
  504. return m_pFPGAComCtrl->iSetCorrectionParam(correctionParam);
  505. }
  506. // 设置行对齐算法参数
  507. int CDeviceComCtrl::iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam)
  508. {
  509. if (nullptr == m_pFPGAComCtrl)
  510. {
  511. ostringstream os;
  512. os << "FPGAComCtrl can't be empty" << endl;
  513. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  514. return EXIT_FAILURE;
  515. }
  516. return m_pFPGAComCtrl->iSetLineAlignAlgParam(lineAlignAlgParam);
  517. }
  518. // 设置亮度数据类型
  519. int CDeviceComCtrl::iSetLumDataType(int iLumDataType)
  520. {
  521. if (nullptr == m_pFPGAComCtrl)
  522. {
  523. ostringstream os;
  524. os << "FPGAComCtrl can't be empty" << endl;
  525. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  526. return EXIT_FAILURE;
  527. }
  528. return m_pFPGAComCtrl->iSetLumDataType(iLumDataType);
  529. }
  530. // 获取Fluorite版本信息
  531. int CDeviceComCtrl::iGetFluoriteVer(string & sVer)
  532. {
  533. if (nullptr == m_pFPGAComCtrl)
  534. {
  535. ostringstream os;
  536. os << "FPGAComCtrl can't be empty" << endl;
  537. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  538. return EXIT_FAILURE;
  539. }
  540. return m_pFPGAComCtrl->iGetFluoriteVer(sVer);
  541. }
  542. // 获取Fluorite定制版本信息
  543. int CDeviceComCtrl::iGetFluoriteCustomVer(string& sVer)
  544. {
  545. if (nullptr == m_pFPGAComCtrl)
  546. {
  547. ostringstream os;
  548. os << "FPGAComCtrl can't be empty" << endl;
  549. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  550. return EXIT_FAILURE;
  551. }
  552. return m_pFPGAComCtrl->iGetFluoriteCustomVer(sVer);
  553. }
  554. // 开启扫描
  555. int CDeviceComCtrl::iStartCapture(int iScanRowLowerLimit, int iScanRowUpperLimit)
  556. {
  557. if (nullptr == m_pFPGAComCtrl)
  558. {
  559. ostringstream os;
  560. os << "FPGAComCtrl can't be empty" << endl;
  561. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  562. return EXIT_FAILURE;
  563. }
  564. if (EXIT_FAILURE == m_pFPGAComCtrl->iStartCapture(iScanRowLowerLimit, iScanRowUpperLimit))
  565. {
  566. return EXIT_FAILURE;
  567. }
  568. // 打开LED灯
  569. iTurnOnLED();
  570. // 打开激光器
  571. iTurnOnLaser();
  572. int iPower;
  573. m_pLaserCtrl->iGetLaserPower(iPower);
  574. int iMaxLaserPower = CSettingParamMng::GetInstance()->iGetLaserMaxPower();
  575. int iPowerPercent = iPower * 100 / iMaxLaserPower;
  576. iPowerPercent = iPowerPercent > 100 ? 100 : iPowerPercent;
  577. if (0 == iPowerPercent)
  578. {
  579. ostringstream os;
  580. os << "startCapture turn on Laser faild, LaserPower[" << iPower << "]" << endl;;
  581. }
  582. stStateMsg stateMsg;
  583. stateMsg.m_enComType = enDeviceComType_Scanner;
  584. stateMsg.m_deviceStateCode.m_iCode = STATE_EMIT;
  585. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  586. stateMsg.m_deviceErrorCode.m_iCode = 0;
  587. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
  588. stateMsg.m_comStateCode.m_iCode = SCANNER_WORKING;
  589. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperCopy;
  590. stateMsg.m_comErrorcode.m_iCode = 0;
  591. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
  592. CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
  593. CDeviceStatusMng::GetInstance()->iSetScanRowRange(iScanRowLowerLimit, iScanRowUpperLimit);
  594. CDeviceStatusMng::GetInstance()->iSetMessage("Working...", 0);
  595. return EXIT_SUCCESS;
  596. }
  597. // 停止扫描
  598. int CDeviceComCtrl::iStopCapture(int iScanRowLowerLimit, int iScanRowUpperLimit)
  599. {
  600. if (nullptr == m_pFPGAComCtrl)
  601. {
  602. ostringstream os;
  603. os << "FPGAComCtrl can't be empty" << endl;
  604. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  605. return EXIT_FAILURE;
  606. }
  607. if (EXIT_FAILURE == m_pFPGAComCtrl->iStopCapture(iScanRowLowerLimit, iScanRowUpperLimit))
  608. {
  609. return EXIT_FAILURE;
  610. }
  611. // 关闭激光器
  612. iTurnOffLaser();
  613. // 关闭LED灯
  614. iTurnOffLED();
  615. stStateMsg stateMsg;
  616. stateMsg.m_enComType = enDeviceComType_Scanner;
  617. stateMsg.m_deviceStateCode.m_iCode = ~STATE_EMIT;
  618. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperAnd;
  619. stateMsg.m_deviceErrorCode.m_iCode = 0;
  620. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
  621. stateMsg.m_comStateCode.m_iCode = SCANNER_STOP;
  622. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperCopy;
  623. stateMsg.m_comErrorcode.m_iCode = 0;
  624. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
  625. CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
  626. CDeviceStatusMng::GetInstance()->iSetScanRowRange(iScanRowLowerLimit, iScanRowUpperLimit);
  627. CDeviceStatusMng::GetInstance()->iSetMessage("System Ready...", 0);
  628. return EXIT_SUCCESS;
  629. }
  630. // 等待线程退出
  631. void CDeviceComCtrl::wait()
  632. {
  633. if (nullptr != m_pProberCtrl)
  634. {
  635. m_pProberCtrl->wait();
  636. }
  637. if (nullptr != m_pLaserCtrl)
  638. {
  639. m_pLaserCtrl->wait();
  640. }
  641. if (nullptr != m_pMotorCtrl)
  642. {
  643. m_pMotorCtrl->wait();
  644. }
  645. if (nullptr != m_pFPGAComCtrl)
  646. {
  647. m_pFPGAComCtrl->wait();
  648. }
  649. if (nullptr != m_pTempVoltSampleCtrl)
  650. {
  651. m_pTempVoltSampleCtrl->wait();
  652. }
  653. return;
  654. }
  655. // 退出线程
  656. void CDeviceComCtrl::ExitThread()
  657. {
  658. if (nullptr != m_pProberCtrl)
  659. {
  660. m_pProberCtrl->SetExitFlag(true);
  661. }
  662. if (nullptr != m_pLaserCtrl)
  663. {
  664. m_pLaserCtrl->SetExitFlag(true);
  665. }
  666. if (nullptr != m_pMotorCtrl)
  667. {
  668. m_pMotorCtrl->SetExitFlag(true);
  669. }
  670. if (nullptr != m_pFPGAComCtrl)
  671. {
  672. m_pFPGAComCtrl->SetExitFlag(true);
  673. }
  674. if (nullptr != m_pTempVoltSampleCtrl)
  675. {
  676. m_pTempVoltSampleCtrl->SetExitFlag(true);
  677. }
  678. return;
  679. }

CFPGAComCtrl.h  FPGA控制定义

  1. #pragma once
  2. #include "ThreadProc.h"
  3. #include "BramCtrl.h"
  4. class CFPGAComCtrl : public CThreadProc
  5. {
  6. public:
  7. // 构造函数
  8. CFPGAComCtrl(CBramCtrl * bramCtrl);
  9. // 析构函数
  10. ~CFPGAComCtrl();
  11. // 初始化
  12. int iInitialize();
  13. // 服务
  14. virtual int src(int id) override;
  15. public:
  16. // 设置X振镜电压
  17. int iSetXMirrorControlVoltage(int iXMirrorControlVoltage);
  18. // 设置Y振镜电压
  19. int iSetYMirrorControlVoltage(int iYMirrorControlVoltage);
  20. // 设置PMT电压
  21. int iSetPMTControlVoltage(int iPMTControlVoltage);
  22. // 设置行偏移
  23. int iSetYMirrorOffset(int iYMirrorOffset);
  24. // 开启扫描
  25. int iStartCapture(int iScanRowLowerLimit, int iScanRowUpperLimit);
  26. // 停止扫描
  27. int iStopCapture(int iScanRowLowerLimit, int iScanRowUpperLimit);
  28. // 设置行起始结束位置
  29. int iSetScanRowRange(int iScanInnerRowLowerLimit, int iScanInnerRowUpperLimit);
  30. // 设置扫描类型
  31. int iSetScanType(int iScanDirectionType);
  32. // 设置X振镜行列偏移
  33. int iSetXMirrorOffset(int iXMirrorOffset);
  34. // 设置X振镜偶数行列偏移
  35. int iSetXMirrorEvenOffset(int iXMirrorEvenOffset);
  36. // 设置X振镜基数行列偏移
  37. int iSetXMirrorOddOffset(int iXMirrorOddOffset);
  38. // 设置畸变校正参数
  39. int iSetCorrectionParam(const stCorrectionParam & correctionParam);
  40. // 设置行对齐算法参数
  41. int iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam);
  42. // 获取Fluorite版本信息
  43. int iGetFluoriteVer(string & sVer);
  44. // 获取Fluorite版本信息
  45. int iGetFluoriteVer(unsigned int &uiVer);
  46. // 获取定制版本信息
  47. int iGetFluoriteCustomVer(string& sVer);
  48. // 设置亮度数据类型
  49. int iSetLumDataType(int iLumDataType);
  50. // 获取行对齐参数
  51. int iGetLineAlignAlgParam(stLineAlignAlgParam & lineAlignAlgParam);
  52. // 获取FPGA错误状态
  53. int iGetFPGAErrorStatus(int & iErrorStatus);
  54. // 设置激光器类型
  55. int iSetLaserType(int LaserType);
  56. protected:
  57. // FPGA器件检查线程
  58. void FPGAComCheckThread();
  59. // 获取Syn周期
  60. int iGetSynPeriodAndDCLKperiod(float &fSYNCPeriod, int & iDCLKperiod);
  61. // 获取
  62. int iGetPixenableCount(int &iPixenableCount);
  63. private:
  64. // bram控制
  65. CBramCtrl * m_bramCtrl;
  66. // 运行开始时间
  67. time_t m_tStartTime;
  68. // 扫描操作互斥锁
  69. mutex m_mtxCaputre;
  70. };

CFPGAComCtrl.cpp

  1. #include <stdlib.h>
  2. #include <unistd.h>
  3. #include <iomanip>
  4. #include "Log.h"
  5. #include "FPGAComCtrl.h"
  6. #include "DeviceParamMng.h"
  7. #include "DeviceStatusMng.h"
  8. #include "SettingParamMng.h"
  9. #define SYNCSignalPeriod 250
  10. // FPGA检查的时间间隔
  11. const int cniCheckFPGAInterval = 3;
  12. // 构造函数
  13. CFPGAComCtrl::CFPGAComCtrl(CBramCtrl * bramCtrl)
  14. :CThreadProc(1)
  15. {
  16. m_bramCtrl = bramCtrl;
  17. m_tStartTime = 0;
  18. return;
  19. }
  20. // 析构函数
  21. CFPGAComCtrl::~CFPGAComCtrl()
  22. {
  23. return;
  24. }
  25. // 初始化
  26. int CFPGAComCtrl::iInitialize()
  27. {
  28. // 设置扫描方式
  29. int iScanDirectionType = CDeviceParamMng::GetInstance()->iGetScanType();
  30. if (EXIT_FAILURE == iSetScanType(iScanDirectionType))
  31. {
  32. ostringstream os;
  33. os << "failed to set ScanType[" << iScanDirectionType << "]" << endl;
  34. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  35. return EXIT_FAILURE;
  36. }
  37. CDeviceStatusMng::GetInstance()->iSetScanType(iScanDirectionType);
  38. // 获取SYNC时钟周期
  39. float fSYNCPeriod;
  40. int iDCLKperiod;
  41. if (EXIT_FAILURE == iGetSynPeriodAndDCLKperiod(fSYNCPeriod, iDCLKperiod))
  42. {
  43. ostringstream os;
  44. os << "failed to get SYNPeriod" << endl;
  45. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  46. return EXIT_FAILURE;
  47. }
  48. int iSYNCPeriod = fSYNCPeriod;
  49. CDeviceStatusMng::GetInstance()->iSetSYNCPeriod(iSYNCPeriod);
  50. m_tStartTime = time(NULL);
  51. return open();
  52. }
  53. // 服务
  54. int CFPGAComCtrl::src(int id)
  55. {
  56. if (0 == id)
  57. {
  58. FPGAComCheckThread();
  59. }
  60. return EXIT_SUCCESS;
  61. }
  62. int CFPGAComCtrl::iSetLaserType(int LaserType)
  63. {
  64. if (nullptr == m_bramCtrl)
  65. {
  66. ostringstream os;
  67. os << "BramCtrlPointer can't be empty" << endl;
  68. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  69. return EXIT_FAILURE;
  70. }
  71. return m_bramCtrl->iSetLaser(LaserType);
  72. }
  73. // 设置X振镜电压
  74. int CFPGAComCtrl::iSetXMirrorControlVoltage(int iXMirrorControlVoltage)
  75. {
  76. if (nullptr == m_bramCtrl)
  77. {
  78. ostringstream os;
  79. os << "BramCtrlPointer can't be empty" << endl;
  80. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  81. return EXIT_FAILURE;
  82. }
  83. return m_bramCtrl->iSetXMirrorControlVoltage(iXMirrorControlVoltage);
  84. }
  85. // 设置Y振镜电压
  86. int CFPGAComCtrl::iSetYMirrorControlVoltage(int iYMirrorControlVoltage)
  87. {
  88. if (nullptr == m_bramCtrl)
  89. {
  90. ostringstream os;
  91. os << "BramCtrlPointer can't be empty" << endl;
  92. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  93. return EXIT_FAILURE;
  94. }
  95. return m_bramCtrl->iSetYMirrorControlVoltage(iYMirrorControlVoltage);
  96. }
  97. // 设置PMT电压
  98. int CFPGAComCtrl::iSetPMTControlVoltage(int iPMTControlVoltage)
  99. {
  100. if (nullptr == m_bramCtrl)
  101. {
  102. ostringstream os;
  103. os << "BramCtrlPointer can't be empty" << endl;
  104. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  105. return EXIT_FAILURE;
  106. }
  107. return m_bramCtrl->iSetPMTControlVoltage(iPMTControlVoltage);
  108. }
  109. // 设置行偏移
  110. int CFPGAComCtrl::iSetYMirrorOffset(int iYMirrorOffset)
  111. {
  112. if (nullptr == m_bramCtrl)
  113. {
  114. ostringstream os;
  115. os << "BramCtrlPointer can't be empty" << endl;
  116. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  117. return EXIT_FAILURE;
  118. }
  119. return m_bramCtrl->iSetYMirrorOffset(iYMirrorOffset);
  120. }
  121. // 开启扫描
  122. int CFPGAComCtrl::iStartCapture(int iScanRowLowerLimit, int iScanRowUpperLimit)
  123. {
  124. if (nullptr == m_bramCtrl)
  125. {
  126. ostringstream os;
  127. os << "BramCtrlPointer can't be empty" << endl;
  128. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  129. return EXIT_FAILURE;
  130. }
  131. int iRet = EXIT_SUCCESS;
  132. string sErr;
  133. {
  134. lock_guard<mutex>guard(m_mtxCaputre);
  135. if (EXIT_FAILURE == m_bramCtrl->iSetScanRowRangeOper(StopDMATransmitFlag, iScanRowLowerLimit, iScanRowUpperLimit))
  136. {
  137. ostringstream os;
  138. os << "failed to stop capture" << endl;
  139. sErr = os.str();
  140. iRet = EXIT_FAILURE;
  141. }
  142. else
  143. {
  144. if (EXIT_FAILURE == m_bramCtrl->iSetScanRowRangeOper(BeginDMATransmitFlag, iScanRowLowerLimit, iScanRowUpperLimit))
  145. {
  146. ostringstream os;
  147. os << "failed to start capture" << endl;
  148. sErr = os.str();
  149. iRet = EXIT_FAILURE;
  150. }
  151. }
  152. }
  153. if (EXIT_FAILURE == iRet)
  154. {
  155. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, sErr, Log_Error);
  156. return EXIT_FAILURE;
  157. }
  158. else
  159. {
  160. return EXIT_SUCCESS;
  161. }
  162. }
  163. // 停止扫描
  164. int CFPGAComCtrl::iStopCapture(int iScanRowLowerLimit, int iScanRowUpperLimit)
  165. {
  166. if (nullptr == m_bramCtrl)
  167. {
  168. ostringstream os;
  169. os << "BramCtrlPointer can't be empty" << endl;
  170. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  171. return EXIT_FAILURE;
  172. }
  173. int iRet = EXIT_FAILURE;
  174. {
  175. lock_guard<mutex>guard(m_mtxCaputre);
  176. iRet = m_bramCtrl->iSetScanRowRangeOper(StopDMATransmitFlag, iScanRowLowerLimit, iScanRowUpperLimit);
  177. }
  178. return iRet;
  179. }
  180. // 设置行起始结束位置
  181. int CFPGAComCtrl::iSetScanRowRange(int iScanInnerRowLowerLimit, int iScanInnerRowUpperLimit)
  182. {
  183. if (nullptr == m_bramCtrl)
  184. {
  185. ostringstream os;
  186. os << "BramCtrlPointer can't be empty" << endl;
  187. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  188. return EXIT_FAILURE;
  189. }
  190. int iRet = EXIT_SUCCESS;
  191. string sErr;
  192. {
  193. lock_guard<mutex>guard(m_mtxCaputre);
  194. int iOper;
  195. int iOldScanInnerRowLowerLimit;
  196. int iOldScanInnerRowUpperLimit;
  197. if (EXIT_FAILURE == m_bramCtrl->iGetScanRowRangeOper(iOper, iOldScanInnerRowLowerLimit, iOldScanInnerRowUpperLimit))
  198. {
  199. ostringstream os;
  200. os << "failed to get ScanRowRangeOper" << endl;
  201. sErr = os.str();
  202. iRet = EXIT_FAILURE;
  203. }
  204. else
  205. {
  206. if (EXIT_FAILURE == m_bramCtrl->iSetScanRowRangeOper(iOper, iScanInnerRowLowerLimit, iScanInnerRowUpperLimit))
  207. {
  208. ostringstream os;
  209. os << "failed to set scanRowRange[" << iScanInnerRowLowerLimit << "," << iScanInnerRowUpperLimit << "]" << endl;
  210. sErr = os.str();
  211. iRet = EXIT_FAILURE;
  212. }
  213. }
  214. }
  215. if (EXIT_FAILURE == iRet)
  216. {
  217. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, sErr, Log_Error);
  218. return EXIT_FAILURE;
  219. }
  220. else
  221. {
  222. return EXIT_SUCCESS;
  223. }
  224. }
  225. // 设置扫描类型
  226. int CFPGAComCtrl::iSetScanType(int iScanDirectionType)
  227. {
  228. if (nullptr == m_bramCtrl)
  229. {
  230. ostringstream os;
  231. os << "BramCtrlPointer can't be empty" << endl;
  232. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  233. return EXIT_FAILURE;
  234. }
  235. return m_bramCtrl->iSetScanType(iScanDirectionType);
  236. }
  237. // 设置X振镜行列偏移
  238. int CFPGAComCtrl::iSetXMirrorOffset(int iXMirrorOffset)
  239. {
  240. if (nullptr == m_bramCtrl)
  241. {
  242. ostringstream os;
  243. os << "BramCtrlPointer can't be empty" << endl;
  244. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  245. return EXIT_FAILURE;
  246. }
  247. return m_bramCtrl->iSetXMirrorOffset(iXMirrorOffset);
  248. }
  249. // 设置X振镜偶数行列偏移
  250. int CFPGAComCtrl::iSetXMirrorEvenOffset(int iXMirrorEvenOffset)
  251. {
  252. if (nullptr == m_bramCtrl)
  253. {
  254. ostringstream os;
  255. os << "BramCtrlPointer can't be empty" << endl;
  256. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  257. return EXIT_FAILURE;
  258. }
  259. return m_bramCtrl->iSetXMirrorEvenOffset(iXMirrorEvenOffset);
  260. }
  261. // 设置X振镜基数行列偏移
  262. int CFPGAComCtrl::iSetXMirrorOddOffset(int iXMirrorOddOffset)
  263. {
  264. if (nullptr == m_bramCtrl)
  265. {
  266. ostringstream os;
  267. os << "BramCtrlPointer can't be empty" << endl;
  268. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  269. return EXIT_FAILURE;
  270. }
  271. return m_bramCtrl->iSetXMirrorOddOffset(iXMirrorOddOffset);
  272. }
  273. // 设置畸变校正参数
  274. int CFPGAComCtrl::iSetCorrectionParam(const stCorrectionParam & correctionParam)
  275. {
  276. if (nullptr == m_bramCtrl)
  277. {
  278. ostringstream os;
  279. os << "BramCtrlPointer can't be empty" << endl;
  280. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  281. return EXIT_FAILURE;
  282. }
  283. return m_bramCtrl->iSetCorrectionParam(correctionParam);
  284. }
  285. // 设置行对齐算法参数
  286. int CFPGAComCtrl::iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam)
  287. {
  288. if (nullptr == m_bramCtrl)
  289. {
  290. ostringstream os;
  291. os << "BramCtrlPointer can't be empty" << endl;
  292. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  293. return EXIT_FAILURE;
  294. }
  295. return m_bramCtrl->iSetLineAlignAlgParam(lineAlignAlgParam);
  296. }
  297. // 获取Fluorite版本信息
  298. int CFPGAComCtrl::iGetFluoriteVer(string & sVer)
  299. {
  300. if (nullptr == m_bramCtrl)
  301. {
  302. ostringstream os;
  303. os << "BramCtrlPointer can't be empty" << endl;
  304. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  305. return EXIT_FAILURE;
  306. }
  307. return m_bramCtrl->iGetFluoriteVer(sVer);
  308. }
  309. // 获取Fluorite版本信息
  310. int CFPGAComCtrl::iGetFluoriteVer(unsigned int &uiVer)
  311. {
  312. if (nullptr == m_bramCtrl)
  313. {
  314. ostringstream os;
  315. os << "BramCtrlPointer can't be empty" << endl;
  316. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  317. return EXIT_FAILURE;
  318. }
  319. return m_bramCtrl->iGetFluoriteVer(uiVer);
  320. }
  321. // 获取定制版本信息
  322. int CFPGAComCtrl::iGetFluoriteCustomVer(string& sVer)
  323. {
  324. if (nullptr == m_bramCtrl)
  325. {
  326. ostringstream os;
  327. os << "BramCtrlPointer can't be empty" << endl;
  328. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  329. return EXIT_FAILURE;
  330. }
  331. return m_bramCtrl->iGetFluoriteCustomVer(sVer);
  332. }
  333. // 设置亮度数据类型
  334. int CFPGAComCtrl::iSetLumDataType(int iLumDataType)
  335. {
  336. if (nullptr == m_bramCtrl)
  337. {
  338. ostringstream os;
  339. os << "BramCtrlPointer can't be empty" << endl;
  340. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  341. return EXIT_FAILURE;
  342. }
  343. return m_bramCtrl->iSetLumDataType(iLumDataType);
  344. }
  345. // 获取行对齐参数
  346. int CFPGAComCtrl::iGetLineAlignAlgParam(stLineAlignAlgParam & lineAlignAlgParam)
  347. {
  348. if (nullptr == m_bramCtrl)
  349. {
  350. ostringstream os;
  351. os << "BramCtrlPointer can't be empty" << endl;
  352. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  353. return EXIT_FAILURE;
  354. }
  355. return m_bramCtrl->iGetLineAlignAlgParam(lineAlignAlgParam);
  356. }
  357. // 获取FPGA错误状态
  358. int CFPGAComCtrl::iGetFPGAErrorStatus(int & iErrorStatus)
  359. {
  360. if (nullptr == m_bramCtrl)
  361. {
  362. ostringstream os;
  363. os << "BramCtrlPointer can't be empty" << endl;
  364. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  365. return EXIT_FAILURE;
  366. }
  367. return m_bramCtrl->iGetFPGAErrorStatus(iErrorStatus);
  368. }
  369. // FPGA器件检查线程
  370. void CFPGAComCtrl::FPGAComCheckThread()
  371. {
  372. bool bExitFlag = bGetExitFlag();
  373. int iDCLKperiod = 0;
  374. float fSYNCPeriod = 0.0;
  375. while (!bExitFlag)
  376. {
  377. // 获取设置模块就绪标识
  378. if (CSettingParamMng::GetInstance()->bGetInitFinishedFlag())
  379. {
  380. // 获取SYNCPeriod和iDCLKperiod
  381. int iNewDCLKperiod;
  382. if (EXIT_FAILURE == iGetSynPeriodAndDCLKperiod(fSYNCPeriod, iNewDCLKperiod))
  383. {
  384. ostringstream os;
  385. os << "failed to get SynPeriod And DCLKperiod" << endl;
  386. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  387. }
  388. else
  389. {
  390. int iSYNCPeriod = fSYNCPeriod;
  391. CDeviceStatusMng::GetInstance()->iSetSYNCPeriod(iSYNCPeriod);
  392. stStateMsg stateMsg;
  393. stateMsg.m_enComType = enDeviceComType_Scanner;
  394. if (0.0 == fSYNCPeriod)
  395. {
  396. stateMsg.m_deviceStateCode.m_iCode = STATE_SYS_ERR;
  397. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  398. stateMsg.m_deviceErrorCode.m_iCode = DevError_SCANNER_CODE_ERR;
  399. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
  400. stateMsg.m_comStateCode.m_iCode = SCANNER_ERR;
  401. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
  402. stateMsg.m_comErrorcode.m_iCode = ~SYNCPeriodOVERFLOW_ERROR_CODE;
  403. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
  404. CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
  405. stateMsg.m_comErrorcode.m_iCode = NOSYNCPeriod_ERROR_CODE;
  406. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
  407. }
  408. else if ((fSYNCPeriod > SYNCSignalPeriod + 10) ||
  409. (fSYNCPeriod < SYNCSignalPeriod - 10))//当SYNC周期超过范围时
  410. {
  411. stateMsg.m_deviceStateCode.m_iCode = STATE_SYS_ERR;
  412. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  413. stateMsg.m_deviceErrorCode.m_iCode = DevError_SCANNER_CODE_ERR;
  414. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
  415. stateMsg.m_comStateCode.m_iCode = SCANNER_ERR;
  416. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
  417. stateMsg.m_comErrorcode.m_iCode = SYNCPeriodOVERFLOW_ERROR_CODE;
  418. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
  419. CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
  420. stateMsg.m_comErrorcode.m_iCode = ~NOSYNCPeriod_ERROR_CODE;;
  421. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
  422. }
  423. else
  424. {
  425. stateMsg.m_deviceStateCode.m_iCode = 0;
  426. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  427. stateMsg.m_deviceErrorCode.m_iCode = 0;
  428. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
  429. stateMsg.m_comStateCode.m_iCode = 0;
  430. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
  431. stateMsg.m_comErrorcode.m_iCode = (~SYNCPeriodOVERFLOW_ERROR_CODE & ~NOSYNCPeriod_ERROR_CODE);
  432. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
  433. }
  434. CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
  435. if (iDCLKperiod != iNewDCLKperiod)
  436. {
  437. stateMsg.m_deviceStateCode.m_iCode = 0;
  438. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  439. stateMsg.m_deviceErrorCode.m_iCode = 0;
  440. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
  441. stateMsg.m_comStateCode.m_iCode = 0;
  442. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
  443. stateMsg.m_comErrorcode.m_iCode = ~NOCRSClock_ERROR_CODE;
  444. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
  445. }
  446. else
  447. {
  448. stateMsg.m_deviceStateCode.m_iCode = STATE_SYS_ERR;
  449. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  450. stateMsg.m_deviceErrorCode.m_iCode = DevError_SCANNER_CODE_ERR;
  451. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
  452. stateMsg.m_comStateCode.m_iCode = SCANNER_ERR;
  453. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
  454. stateMsg.m_comErrorcode.m_iCode = NOCRSClock_ERROR_CODE;
  455. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
  456. }
  457. CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
  458. if (((fSYNCPeriod <= SYNCSignalPeriod + 10) && (fSYNCPeriod >= SYNCSignalPeriod - 10)) && iDCLKperiod != iNewDCLKperiod)
  459. {
  460. stateMsg.m_deviceStateCode.m_iCode = 0;
  461. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  462. stateMsg.m_deviceErrorCode.m_iCode = ~DevError_SCANNER_CODE_ERR;
  463. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperAnd;
  464. stateMsg.m_comStateCode.m_iCode = 0;
  465. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
  466. stateMsg.m_comErrorcode.m_iCode = 0;
  467. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
  468. CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
  469. }
  470. iDCLKperiod = iNewDCLKperiod;
  471. }
  472. // 获取行对齐算法参数并更新
  473. stLineAlignAlgParam lineAlignAlgParam;
  474. if (EXIT_SUCCESS == iGetLineAlignAlgParam(lineAlignAlgParam))
  475. {
  476. CDeviceStatusMng::GetInstance()->iSetLineAlignAlgParam(lineAlignAlgParam);
  477. }
  478. // 获取FPGA错误状态
  479. int iErrorStatus = 0;
  480. if (EXIT_SUCCESS == iGetFPGAErrorStatus(iErrorStatus))
  481. {
  482. ostringstream os;
  483. if (0 != (iErrorStatus & 0x1))
  484. {
  485. os << "[DMA full]";
  486. }
  487. if (0 != (iErrorStatus & 0x2))
  488. {
  489. os << "[SeqNo discontinuous,when writing DMA FIFO]";
  490. }
  491. if (0 != (iErrorStatus & 0x4))
  492. {
  493. os << "[SeqNo discontinuous,when reading DMA FIFO]";
  494. }
  495. if (0 != (iErrorStatus & 0x8))
  496. {
  497. os << "[SeqNo discontinuous,when Writing FIFO in Capturing-terminal]";
  498. }
  499. if (0 != (iErrorStatus & 0x10))
  500. {
  501. os << "[SeqNo discontinuous,when reading FIFO in Capturing-terminal]";
  502. }
  503. if (0 != (iErrorStatus & 0x20))
  504. {
  505. os << "[DCLK signal disappear]";
  506. }
  507. if (0 != (iErrorStatus & 0x40))
  508. {
  509. os << "[SYNC signal excception]";
  510. }
  511. string sFPGAErrorStatusInfo = os.str();
  512. if (!sFPGAErrorStatusInfo.empty())
  513. {
  514. ostringstream osNew;
  515. osNew << hex << "FPGAErrorStatus:0x" << setw(8) << setfill('0') << iErrorStatus << endl;
  516. osNew << sFPGAErrorStatusInfo << endl;
  517. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, osNew.str(), Log_Error);
  518. }
  519. }
  520. }
  521. // 获取Fluorite版本号
  522. unsigned int uiFluoriteVer;
  523. if (EXIT_FAILURE == iGetFluoriteVer(uiFluoriteVer))
  524. {
  525. ostringstream os;
  526. os << "failed to get Fluorite Version" << endl;
  527. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  528. }
  529. else
  530. {
  531. stStateMsg stateMsg;
  532. stateMsg.m_enComType = enDeviceComType_Scanner;
  533. if (uiFluoriteVer < 0x1010000) //判断版本号是否匹配
  534. {
  535. stateMsg.m_deviceStateCode.m_iCode = STATE_SYS_ERR;
  536. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  537. stateMsg.m_deviceErrorCode.m_iCode = DevErrorCode_FPGAVerNoMath_ERR;
  538. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperOr;
  539. stateMsg.m_comStateCode.m_iCode = SCANNER_ERR;
  540. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
  541. stateMsg.m_comErrorcode.m_iCode = SCANNER_ERROR_CODE;
  542. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperOr;
  543. }
  544. else
  545. {
  546. stateMsg.m_deviceStateCode.m_iCode = 0;
  547. stateMsg.m_deviceStateCode.m_enCodeOperType = enCodeOperOr;
  548. stateMsg.m_deviceErrorCode.m_iCode = (~DevErrorCode_FPGAVerNoMath_ERR);
  549. stateMsg.m_deviceErrorCode.m_enCodeOperType = enCodeOperAnd;
  550. stateMsg.m_comStateCode.m_iCode = 0;
  551. stateMsg.m_comStateCode.m_enCodeOperType = enCodeOperOr;
  552. stateMsg.m_comErrorcode.m_iCode = ~SCANNER_ERROR_CODE;
  553. stateMsg.m_comErrorcode.m_enCodeOperType = enCodeOperAnd;
  554. }
  555. CDeviceStatusMng::GetInstance()->SendStateMsg(stateMsg);
  556. }
  557. // 运行时间计数
  558. sleep(cniCheckFPGAInterval);
  559. static int iRunningTimeBeforeUpdateDate = 0;
  560. static int iLastRunningTime = 0;
  561. int iCurRunningTime = time(NULL) - m_tStartTime;
  562. if (cniCheckFPGAInterval*3 < (iCurRunningTime - iLastRunningTime))
  563. {
  564. m_tStartTime = time(NULL);
  565. iRunningTimeBeforeUpdateDate = iLastRunningTime;
  566. iCurRunningTime = iRunningTimeBeforeUpdateDate + cniCheckFPGAInterval;
  567. }
  568. else
  569. {
  570. iCurRunningTime = iCurRunningTime + iRunningTimeBeforeUpdateDate;
  571. }
  572. CDeviceStatusMng::GetInstance()->iSetRunningTime(iCurRunningTime);
  573. iLastRunningTime = iCurRunningTime;
  574. bExitFlag = bGetExitFlag();
  575. }
  576. return;
  577. }
  578. // 获取Syn周期
  579. int CFPGAComCtrl::iGetSynPeriodAndDCLKperiod(float &fSYNCPeriod, int & iDCLKperiod)
  580. {
  581. if (nullptr == m_bramCtrl)
  582. {
  583. ostringstream os;
  584. os << "BramCtrlPointer can't be empty" << endl;
  585. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  586. return EXIT_FAILURE;
  587. }
  588. return m_bramCtrl->iGetSynPeriodAndDCLKperiod(fSYNCPeriod, iDCLKperiod);
  589. }
  590. // 获取
  591. int CFPGAComCtrl::iGetPixenableCount(int &iPixenableCount)
  592. {
  593. if (nullptr == m_bramCtrl)
  594. {
  595. ostringstream os;
  596. os << "BramCtrlPointer can't be empty" << endl;
  597. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  598. return EXIT_FAILURE;
  599. }
  600. return m_bramCtrl->iGetPixenableCount(iPixenableCount);
  601. }

BRAM控制定义

CBramCtrl.h

  1. #pragma once
  2. #include <string>
  3. #include <mutex>
  4. #include "InnerDeviceInfo.h"
  5. #include "BramDef.h"
  6. using namespace std;
  7. class CBramCtrl
  8. {
  9. public:
  10. // 构造函数
  11. CBramCtrl(const string & sDriverFile);
  12. // 析构函数
  13. ~CBramCtrl();
  14. // 初始化
  15. int iInitialize();
  16. public:
  17. // 设置X振镜电压
  18. int iSetXMirrorControlVoltage(int iXMirrorControlVoltage);
  19. // 设置Y振镜电压
  20. int iSetYMirrorControlVoltage(int iYMirrorControlVoltage);
  21. // 设置PMT电压
  22. int iSetPMTControlVoltage(int iPMTControlVoltage);
  23. // 设置电机位置
  24. int iSetMotorPos(int iMotorPos);
  25. // 设置Y振镜偏移
  26. int iSetYMirrorOffset(int iYMirrorOffset);
  27. // 设置扫描方式
  28. int iSetScanType(int iScanDirectionType);
  29. // 设置X振镜行列偏移
  30. int iSetXMirrorOffset(int iXMirrorOffset);
  31. // 设置偶数行列偏移
  32. int iSetXMirrorEvenOffset(int iXMirrorEvenOffset);
  33. // 设置奇数行列偏移
  34. int iSetXMirrorOddOffset(int iXMirrorOddOffset);
  35. // 设置畸变校正参数
  36. int iSetCorrectionParam(const stCorrectionParam & correctionParam);
  37. // 设置行对齐算法参数
  38. int iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam);
  39. // 设置亮度数据类型
  40. int iSetLumDataType(int iLumDataType);
  41. // 获取电机位置
  42. int iGetMotorPosStatus(bool & bMotorMoveFlag, int &iStatus, int & iPos);
  43. // 获取Syn周期
  44. int iGetSynPeriodAndDCLKperiod(float &fSYNCPeriod, int & iDCLKperiod);
  45. // 获取Fluorite版本
  46. int iGetFluoriteVer(string & sVer);
  47. // 获取Fluorite版本
  48. int iGetFluoriteVer(unsigned int &uiVer);
  49. // 获取Fluorite定制版本
  50. int iGetFluoriteCustomVer(string& sVer);
  51. // 获取Pixenable计数
  52. int iGetPixenableCount(int &iPixenableCount);
  53. // 设置扫描起始行与接收行
  54. int iSetScanRowRangeOper(int iOper, int iScanRowLowerLimit, int iScanRowUpperLimit);
  55. // 设置电机限制范围
  56. int iSetMotorPosRange(int iMotorPosLowerLimit, int iMotorPosUpperLimit);
  57. // 获取扫描范围信息
  58. int iGetScanRowRangeOper(int &iOper, int &iScanRowLowerLimit, int &iScanRowUpperLimit);
  59. // 获取行对齐参数
  60. int iGetLineAlignAlgParam(stLineAlignAlgParam & lineAlignAlgParam);
  61. // 获取FPGA错误状态
  62. int iGetFPGAErrorStatus(int & iErrorStatus);
  63. // 设置激光器类型
  64. int iSetLaser(int iLaserType);
  65. protected:
  66. // 读取数据
  67. int iRead(stReg & reg);
  68. // 写入数据
  69. int iWrite(const stReg & reg);
  70. private:
  71. // 驱动文件
  72. string m_sDriverFile;
  73. // 驱动文件句柄
  74. int m_iFileHandle;
  75. // 访问互斥
  76. mutex m_mtxAcc;
  77. };

CBramCtrl.cpp

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <fcntl.h>
  6. #include <sys/ioctl.h>
  7. #include <iomanip>
  8. #include "Log.h"
  9. #include "BramCtrl.h"
  10. #include "CommandInfo.h"
  11. // 构造函数
  12. CBramCtrl::CBramCtrl(const string & sDriverFile)
  13. {
  14. m_iFileHandle = -1;
  15. m_sDriverFile = sDriverFile;
  16. return;
  17. }
  18. // 析构函数
  19. CBramCtrl::~CBramCtrl()
  20. {
  21. if (-1 != m_iFileHandle)
  22. {
  23. close(m_iFileHandle);
  24. m_iFileHandle = -1;
  25. }
  26. return;
  27. }
  28. // 初始化
  29. int CBramCtrl::iInitialize()
  30. {
  31. m_iFileHandle = open(m_sDriverFile.c_str(), O_RDWR);
  32. if (m_iFileHandle < 0)
  33. {
  34. ostringstream os;
  35. os << "failed to open File[" << m_sDriverFile << "]" << endl;
  36. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  37. return EXIT_FAILURE;
  38. }
  39. return EXIT_SUCCESS;
  40. }
  41. // 设置激光器类型
  42. int CBramCtrl::iSetLaser(int iLaserType)
  43. {
  44. stReg reg;
  45. unsigned int backdata = 0;
  46. reg.address = LaserTypeAddr;
  47. backdata = AcitveFlag << 24 | iLaserType;
  48. reg.data = backdata;
  49. return iWrite(reg);
  50. }
  51. // 设置X振镜电压
  52. int CBramCtrl::iSetXMirrorControlVoltage(int iXMirrorControlVoltage)
  53. {
  54. int iXVoltageValue = iXMirrorControlVoltage * 4095; // 毫伏单位mV
  55. iXVoltageValue = iXVoltageValue / cniXMirrorControlVoltageUpperLimit;
  56. iXVoltageValue = iXVoltageValue << 2;
  57. stReg reg;
  58. unsigned int backdata = 0;
  59. reg.address = WriteXcrsVoltageAddr;
  60. backdata = AcitveFlag << 24 | iXVoltageValue;
  61. reg.data = backdata;
  62. return iWrite(reg);
  63. }
  64. // 设置Y振镜电压
  65. int CBramCtrl::iSetYMirrorControlVoltage(int iYMirrorControlVoltage)
  66. {
  67. int iYVoltageValue = iYMirrorControlVoltage * 4095; // 毫伏单位mV
  68. iYVoltageValue = iYVoltageValue / cniYMirrorControlVoltageUpperLimit;
  69. iYVoltageValue = iYVoltageValue << 2;
  70. stReg reg;
  71. unsigned int backdata = 0;
  72. reg.address = WriteYcrsVoltageAddr;
  73. backdata = AcitveFlag << 24 | iYVoltageValue;
  74. reg.data = backdata;
  75. return iWrite(reg);
  76. }
  77. // 设置PMT电压
  78. int CBramCtrl::iSetPMTControlVoltage(int iPMTControlVoltage)
  79. {
  80. int iPMTVoltageValue = iPMTControlVoltage * 4095; // 毫伏单位mV
  81. iPMTVoltageValue = iPMTVoltageValue / cniPMTControlVoltageUpperLimit;
  82. iPMTVoltageValue = iPMTVoltageValue << 2;
  83. stReg reg;
  84. reg.address = WritePMTVoltageAddr;
  85. reg.data = AcitveFlag << 24 | iPMTVoltageValue;
  86. return iWrite(reg);
  87. }
  88. // 设置电机位置
  89. int CBramCtrl::iSetMotorPos(int iMotorPos)
  90. {
  91. int iAbsMotorPos;
  92. unsigned char nDir;
  93. if (iMotorPos < 0)
  94. {
  95. iAbsMotorPos = -iMotorPos;
  96. nDir = 0;
  97. }
  98. else
  99. {
  100. iAbsMotorPos = iMotorPos;
  101. nDir = 1;
  102. }
  103. uint16_t IncDecSpeedstepLength = 0;
  104. uint8_t DirectionValue = 0;
  105. uint32_t dat = 0;
  106. uint8_t StepMotorFrequence = 0;
  107. uint8_t IncDecEnableFlag = 0;
  108. if (iAbsMotorPos > 400)
  109. {
  110. StepMotorFrequence = 150;
  111. IncDecEnableFlag = 1;
  112. IncDecSpeedstepLength = 100;
  113. }
  114. else if (iAbsMotorPos > 200)
  115. {
  116. StepMotorFrequence = 130;
  117. IncDecEnableFlag = 1;
  118. IncDecSpeedstepLength = 100;
  119. }
  120. else if (iAbsMotorPos > 100)
  121. {
  122. StepMotorFrequence = 80;
  123. IncDecEnableFlag = 1;
  124. IncDecSpeedstepLength = 50;
  125. }
  126. else if (iAbsMotorPos > 50)
  127. {
  128. StepMotorFrequence = 30;
  129. IncDecEnableFlag = 1;
  130. IncDecSpeedstepLength = 25;
  131. }
  132. else if (iAbsMotorPos > 20)
  133. {
  134. StepMotorFrequence = 20;
  135. IncDecEnableFlag = 1;
  136. IncDecSpeedstepLength = 10;
  137. }
  138. else if (iAbsMotorPos > 10)
  139. {
  140. StepMotorFrequence = 10;
  141. IncDecEnableFlag = 1;
  142. IncDecSpeedstepLength = 5;
  143. }
  144. else if (iAbsMotorPos > 5)
  145. {
  146. StepMotorFrequence = 2;
  147. IncDecEnableFlag = 5;
  148. IncDecSpeedstepLength = 3;
  149. }
  150. else
  151. {
  152. StepMotorFrequence = 1;//1
  153. IncDecEnableFlag = 5;
  154. IncDecSpeedstepLength = 2;
  155. }
  156. /************************如下是对焦电机移动控制命令********************************************/
  157. stReg reg;
  158. reg.address = SetStepMotorPositionAddr;
  159. if (nDir > 0) //设置方向
  160. {
  161. DirectionValue = 0x0f;
  162. }
  163. else
  164. {
  165. DirectionValue = 0;
  166. }
  167. reg.data = 0x5 << 28 | DirectionValue << 24 | StepMotorFrequence << 16 | iAbsMotorPos;
  168. if (EXIT_FAILURE == iWrite(reg))
  169. {
  170. ostringstream os;
  171. os << "failed to write Motor position" << endl;
  172. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  173. return EXIT_FAILURE;
  174. }
  175. /************************如下是对焦电机加减速算法参数设置********************************************/
  176. reg.address = SetpMotorParameterAddr;
  177. reg.data = AcitveFlag << 24 | Flexible << 20 | IncDecEnableFlag << 16 | IncDecSpeedstepLength;
  178. if (EXIT_FAILURE == iWrite(reg))
  179. {
  180. ostringstream os;
  181. os << "failed to write MotorParam" << endl;
  182. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  183. return EXIT_FAILURE;
  184. }
  185. return EXIT_SUCCESS;
  186. }
  187. // 设置Y振镜偏移
  188. int CBramCtrl::iSetYMirrorOffset(int iYMirrorOffset)
  189. {
  190. int iAbsYMirrorOffset;
  191. unsigned char nDir;
  192. if (iYMirrorOffset < 0)
  193. {
  194. iAbsYMirrorOffset = -iYMirrorOffset;
  195. nDir = 0;
  196. }
  197. else
  198. {
  199. iAbsYMirrorOffset = iYMirrorOffset;
  200. nDir = 1;
  201. }
  202. unsigned int backdata;
  203. uint8_t DirectionFlag;
  204. stReg reg;
  205. reg.address = SetRowCountOffsetAddr; //行号偏移数据地址.
  206. if (nDir) //正方向
  207. {
  208. DirectionFlag = 0xf;
  209. }
  210. else
  211. //负方向
  212. {
  213. DirectionFlag = 0; //8位有效标志(0x55), 8位序列号, 4位方向, 12位偏移值
  214. }
  215. backdata = AcitveFlag << 24 | (DirectionFlag << 16) | iAbsYMirrorOffset;
  216. reg.data = backdata;
  217. if (EXIT_FAILURE == iWrite(reg))
  218. {
  219. ostringstream os;
  220. os << "failed to set YMirrorOffset[" << hex << backdata << "]" << endl;
  221. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  222. return EXIT_FAILURE;
  223. }
  224. return EXIT_SUCCESS;
  225. }
  226. // 设置扫描起始行与接收行
  227. int CBramCtrl::iSetScanRowRangeOper(int iOper, int iScanRowLowerLimit, int iScanRowUpperLimit)
  228. {
  229. stReg reg;
  230. reg.address = WriteCaptureStartEndPositionAddr; //BRAM地址 28
  231. reg.data = (iOper << 28) | (iScanRowLowerLimit << 16) | iScanRowUpperLimit;
  232. return iWrite(reg);
  233. }
  234. // 设置电机限制范围
  235. int CBramCtrl::iSetMotorPosRange(int iMotorPosLowerLimit, int iMotorPosUpperLimit)
  236. {
  237. stReg reg;
  238. reg.address = SetMotorRangeAddr; //BRAM地址 28
  239. reg.data = (iMotorPosUpperLimit << 16) | iMotorPosLowerLimit;
  240. return iWrite(reg);
  241. }
  242. // 获取扫描范围信息
  243. int CBramCtrl::iGetScanRowRangeOper(int &iOper, int &iScanRowLowerLimit, int &iScanRowUpperLimit)
  244. {
  245. stReg reg;
  246. reg.address = WriteCaptureStartEndPositionAddr; //BRAM地址 28
  247. if (EXIT_FAILURE == iRead(reg))
  248. {
  249. return EXIT_FAILURE;
  250. }
  251. iOper = (reg.data >> 28) & 0xf;
  252. iScanRowLowerLimit = (reg.data >> 16) & 0xfff;
  253. iScanRowUpperLimit = reg.data & 0xffff;
  254. return EXIT_SUCCESS;
  255. }
  256. // 获取行对齐参数
  257. int CBramCtrl::iGetLineAlignAlgParam(stLineAlignAlgParam & lineAlignAlgParam)
  258. {
  259. stReg reg;
  260. //reg.address = SetLineAlignAlgParamAddr; //行对齐参数地址
  261. reg.address = LineAlignAlgParamStatusAddr;
  262. if (EXIT_FAILURE == iRead(reg))
  263. {
  264. ostringstream os;
  265. os << "failed to set LineAlignAlgParam[" << hex << reg.data << endl;
  266. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  267. return EXIT_FAILURE;
  268. }
  269. lineAlignAlgParam.m_iLineAlignAlgEnable = ((reg.data >> 28)==5)? 1: 0;
  270. lineAlignAlgParam.m_iLineAlignOffset = (((reg.data >> 16)&0xfff)-512);
  271. lineAlignAlgParam.m_iLineAlignInterval = (reg.data & 0xffff);
  272. return EXIT_SUCCESS;
  273. }
  274. // 获取FPGA错误状态
  275. int CBramCtrl::iGetFPGAErrorStatus(int & iErrorStatus)
  276. {
  277. stReg reg;
  278. reg.address = FPGAErrorStatusAddr;
  279. if (EXIT_FAILURE == iRead(reg))
  280. {
  281. ostringstream os;
  282. os << "failed to set LineAlignAlgParam[" << hex << reg.data << endl;
  283. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  284. return EXIT_FAILURE;
  285. }
  286. iErrorStatus = reg.data;
  287. return EXIT_SUCCESS;
  288. }
  289. // 设置扫描方式
  290. int CBramCtrl::iSetScanType(int iScanDirectionType)
  291. {
  292. int iInnerScanType = 0;
  293. if (0 == iScanDirectionType)
  294. {
  295. iInnerScanType = 0;
  296. }
  297. else
  298. {
  299. iInnerScanType = 3;
  300. }
  301. stReg reg;
  302. reg.address = SetScanTypeAddr; //行号偏移数据地址.
  303. reg.data = AcitveFlag << 24 | iInnerScanType;;
  304. if (EXIT_FAILURE == iWrite(reg))
  305. {
  306. ostringstream os;
  307. os << "failed to set scanType[" << hex << reg.data << "]" << endl;
  308. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  309. return EXIT_FAILURE;
  310. }
  311. return EXIT_SUCCESS;
  312. }
  313. // 设置X振镜行列偏移
  314. int CBramCtrl::iSetXMirrorOffset(int iXMirrorOffset)
  315. {
  316. uint32_t backdata = 0;
  317. backdata = AcitveFlag << 24 | iXMirrorOffset;
  318. stReg reg;
  319. reg.address = SetOneDirSampleImageBeginFallingDelayValueAddr;
  320. reg.data = backdata;
  321. if (EXIT_FAILURE == iWrite(reg))
  322. {
  323. ostringstream os;
  324. os << "failed to set One-direction scanType's iXMirrorOffset" << endl;
  325. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  326. return EXIT_FAILURE;
  327. }
  328. return EXIT_SUCCESS;
  329. }
  330. // 设置偶数行列偏移
  331. int CBramCtrl::iSetXMirrorEvenOffset(int iXMirrorEvenOffset)
  332. {
  333. uint32_t backdata = 0;
  334. backdata = AcitveFlag << 24 | iXMirrorEvenOffset;
  335. stReg reg;
  336. reg.address = SetSampleImageBeginFallingDelayValueAddr;
  337. reg.data = backdata;
  338. if (EXIT_FAILURE == iWrite(reg))
  339. {
  340. ostringstream os;
  341. os << "failed to set Two-direction scanType's XMirrorEvenOffset" << endl;
  342. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  343. return EXIT_FAILURE;
  344. }
  345. return EXIT_SUCCESS;
  346. }
  347. // 设置奇数行列偏移
  348. int CBramCtrl::iSetXMirrorOddOffset(int iXMirrorOddOffset)
  349. {
  350. uint32_t backdata = 0;
  351. backdata = AcitveFlag << 24 | iXMirrorOddOffset;
  352. stReg reg;
  353. reg.address = SetSampleImageBeginRisingDelayValueAddr;
  354. reg.data = backdata;
  355. if (EXIT_FAILURE == iWrite(reg))
  356. {
  357. ostringstream os;
  358. os << "failed to set Two-direction scanType's XMirrorOddOffset" << endl;
  359. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  360. return EXIT_FAILURE;
  361. }
  362. return EXIT_SUCCESS;
  363. }
  364. // 设置畸变校正参数
  365. int CBramCtrl::iSetCorrectionParam(const stCorrectionParam & correctionParam)
  366. {
  367. int iEnableFlag;
  368. if (1 == correctionParam.m_iCorrectionEnable)
  369. {
  370. iEnableFlag = BeginDMATransmitFlag;
  371. }
  372. else
  373. {
  374. iEnableFlag = 0;
  375. }
  376. stReg reg;
  377. reg.address = SetCorrectionParamAddr; //畸变校正参数地址
  378. reg.data = iEnableFlag << 28 | correctionParam.m_iStretchCoef << 16 | correctionParam.m_iScanCenterCol;;
  379. if (EXIT_FAILURE == iWrite(reg))
  380. {
  381. ostringstream os;
  382. os << "failed to set CorrectionParam[" << hex << reg.data << endl;
  383. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  384. return EXIT_FAILURE;
  385. }
  386. return EXIT_SUCCESS;
  387. }
  388. // 设置行对齐算法参数
  389. int CBramCtrl::iSetLineAlignAlgParam(const stLineAlignAlgParam & lineAlignAlgParam)
  390. {
  391. int iEnableFlag;
  392. if (1 == lineAlignAlgParam.m_iLineAlignAlgEnable)
  393. {
  394. iEnableFlag = BeginDMATransmitFlag;
  395. }
  396. else
  397. {
  398. iEnableFlag = 0;
  399. }
  400. int iLineAlignOffset = lineAlignAlgParam.m_iLineAlignOffset + 512;
  401. stReg reg;
  402. reg.address = SetLineAlignAlgParamAddr; //行对齐参数地址
  403. reg.data = iEnableFlag << 28 | iLineAlignOffset << 16 | lineAlignAlgParam.m_iLineAlignInterval;
  404. if (EXIT_FAILURE == iWrite(reg))
  405. {
  406. ostringstream os;
  407. os << "failed to set LineAlignAlgParam[" << hex << reg.data << endl;
  408. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  409. return EXIT_FAILURE;
  410. }
  411. return EXIT_SUCCESS;
  412. }
  413. // 设置亮度数据类型
  414. int CBramCtrl::iSetLumDataType(int iLumDataType)
  415. {
  416. stReg reg;
  417. reg.address = SetLumDataTypeAddr; //畸变校正参数地址
  418. reg.data = AcitveFlag << 24 | iLumDataType;
  419. if (EXIT_FAILURE == iWrite(reg))
  420. {
  421. ostringstream os;
  422. os << "failed to set LumDataType[" << hex << reg.data << endl;
  423. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  424. return EXIT_FAILURE;
  425. }
  426. return EXIT_SUCCESS;
  427. }
  428. // 获取电机位置
  429. int CBramCtrl::iGetMotorPosStatus(bool & bMotorMoveFlag, int &iStatus, int & iPos)
  430. {
  431. stReg reg;
  432. reg.address = ReadStepMotorPositionAddr;
  433. if (EXIT_FAILURE == iRead(reg))
  434. {
  435. ostringstream os;
  436. os << "failed to read Motor Position" << endl;
  437. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  438. return EXIT_FAILURE;
  439. }
  440. iPos = (reg.data & 0xffff);
  441. iStatus = ((reg.data>>16) & 0x0f);
  442. bMotorMoveFlag = ((reg.data >> 20) & 0x01);
  443. return EXIT_SUCCESS;
  444. }
  445. // 获取DCLK
  446. int CBramCtrl::iGetSynPeriodAndDCLKperiod(float &fSYNCPeriod, int & iDCLKperiod)
  447. {
  448. stReg reg;
  449. reg.address = SYNCPeriodAddr;
  450. if (EXIT_FAILURE == iRead(reg))
  451. {
  452. ostringstream os;
  453. os << "failed to read SYNC signal Num" << endl;
  454. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  455. return EXIT_FAILURE;
  456. }
  457. fSYNCPeriod = (reg.data & 0xffff);
  458. fSYNCPeriod = fSYNCPeriod * 0.01;
  459. iDCLKperiod = ((reg.data >> 16) & 0xffff);
  460. return EXIT_SUCCESS;
  461. }
  462. // 获取Fluorite版本
  463. int CBramCtrl::iGetFluoriteVer(string & sVer)
  464. {
  465. unsigned int uiVer = 0;
  466. if (EXIT_FAILURE == iGetFluoriteVer(uiVer))
  467. {
  468. return EXIT_FAILURE;
  469. }
  470. char *pVer = (char *)&uiVer;
  471. stringstream os;
  472. os << "V" << (int)pVer[3] << "." << (int)pVer[2] << "." << (int)pVer[1] << "." << (int)pVer[0];
  473. sVer = os.str();
  474. return EXIT_SUCCESS;
  475. }
  476. // 获取Fluorite版本
  477. int CBramCtrl::iGetFluoriteVer(unsigned int &uiVer)
  478. {
  479. stReg reg;
  480. reg.address = FPGAVerisionNumAddr;
  481. if (EXIT_FAILURE == iRead(reg))
  482. {
  483. ostringstream os;
  484. os << "failed to read Fluorite Version" << endl;
  485. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  486. return EXIT_FAILURE;
  487. }
  488. uiVer = reg.data;
  489. return EXIT_SUCCESS;
  490. }
  491. // 获取Fluorite定制版本
  492. int CBramCtrl::iGetFluoriteCustomVer(string& sVer)
  493. {
  494. stReg reg;
  495. reg.address = FPGACustomVerisionNumAddr;
  496. if (EXIT_FAILURE == iRead(reg))
  497. {
  498. ostringstream os;
  499. os << "failed to read Fluorite CustomVersion" << endl;
  500. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  501. return EXIT_FAILURE;
  502. }
  503. char *pVer = (char *)&reg.data;
  504. ostringstream os;
  505. os << (int)pVer[1] << "." << (int)pVer[0];
  506. sVer = os.str();
  507. return EXIT_SUCCESS;
  508. }
  509. // 获取Pixenable计数
  510. int CBramCtrl::iGetPixenableCount(int &iPixenableCount)
  511. {
  512. stReg reg;
  513. reg.address = FPGAPixenableAddr;
  514. if (EXIT_FAILURE == iRead(reg))
  515. {
  516. ostringstream os;
  517. os << "failed to read PixenableCount" << endl;
  518. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  519. return EXIT_FAILURE;
  520. }
  521. iPixenableCount = (reg.data & 0xffff);
  522. return EXIT_SUCCESS;
  523. }
  524. // 读取数据
  525. int CBramCtrl::iRead(stReg & reg)
  526. {
  527. int iRet;
  528. {
  529. lock_guard<mutex> guard(m_mtxAcc);
  530. iRet = ioctl(m_iFileHandle, RD_COMMAND, &reg);
  531. }
  532. if (iRet < 0)
  533. {
  534. ostringstream os;
  535. os << "failed to read addr[" << hex << reg.address << "]" << endl;
  536. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  537. return EXIT_FAILURE;
  538. }
  539. return EXIT_SUCCESS;
  540. }
  541. // 写入数据
  542. int CBramCtrl::iWrite(const stReg & reg)
  543. {
  544. int iRet;
  545. {
  546. lock_guard<mutex> guard(m_mtxAcc);
  547. iRet = ioctl(m_iFileHandle, WR_COMMAND, &reg);
  548. }
  549. if (iRet < 0)
  550. {
  551. ostringstream os;
  552. os << "failed to write addr[" << hex << reg.address << "]" << endl;
  553. CLog::GetInstance()->WriteLog(__FUNCTION__, __LINE__, os.str(), Log_Error);
  554. return EXIT_FAILURE;
  555. }
  556. return EXIT_SUCCESS;
  557. }

main()

  1. int main()
  2. {
  3. LaserType = 1;
  4. LaserType = CDeviceComCtrl::GetInstance()->iSetLaserTypes(LaserType); //通过设计FPGA管脚设置激光器类型,设计为参数0时为旧激光器IBOS,设置参数为1时为新激光器(精英光电)
  5. return 0;
  6. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/531365
推荐阅读
相关标签
  

闽ICP备14008679号