You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

576 lines
20 KiB

1 year ago
  1. #pragma once
  2. #include <fstream>
  3. #include <functional>
  4. #include <iostream>
  5. #include <list>
  6. #include <map>
  7. #include <memory>
  8. #include <mutex>
  9. #include <set>
  10. #include <sstream>
  11. #include <string>
  12. #include <vector>
  13. //
  14. #include "i_xsync_udp.hpp"
  15. #include "xsync_errcode.hpp"
  16. #include "xsync_packet.hpp"
  17. #include "xsync_regs.hpp"
  18. #include "xsync_v2_sig_type.hpp"
  19. namespace xsync {
  20. using namespace std;
  21. /**
  22. * @brief
  23. *
  24. * :
  25. * Basic_xxxxx
  26. *
  27. * :
  28. * :
  29. * TimecodeInputModule_XXXXX
  30. *
  31. *
  32. * TTL输入模块:
  33. * TTLInputModule_XXXXX
  34. *
  35. * Genlock输入模块:
  36. * GenlockInputModule_XXXXX
  37. *
  38. * :
  39. *
  40. * InternalTimecode_xxxx
  41. * Genlock信号发生器
  42. * ISG_Genlock_xxxx
  43. *
  44. */
  45. typedef function<void(XsyncTimecode_t *timecode_msg)> xsync_on_timecode_msg_t;
  46. typedef function<void(uint32_t recordSig)> xsync_on_record_sig_change_msg_t;
  47. typedef function<void(xysnc_camera_sync_data_t *timecode_msg)> xsync_on_camera_sync_msg_t;
  48. class Xsync {
  49. public:
  50. private:
  51. /* data */
  52. I_XSUDPFactory *m_xsync_udp_factory = nullptr;
  53. shared_ptr<I_XSUDP> m_xsync_reg_udp = nullptr;
  54. shared_ptr<I_XSUDP> m_xsync_timecode_udp_listener = nullptr;
  55. shared_ptr<I_XSUDP> m_xsync_camera_sync_udp_listener = nullptr;
  56. string m_xsync_ip;
  57. bool m_is_connected = false;
  58. xsync_on_camera_sync_msg_t m_on_camera_sync_msg_cb = nullptr;
  59. xsync_on_timecode_msg_t m_on_timecode_msg_cb = nullptr;
  60. xsync_on_record_sig_change_msg_t m_on_record_sig_change_msg_cb = nullptr;
  61. int txpacket_index = 0;
  62. uint8_t m_xync_cmd_rxdata_cache[2560];
  63. xsync_net_state_t m_net_state = kxsync_net_state_disconnect;
  64. std::recursive_mutex lock_;
  65. Xsync(/* args */);
  66. public:
  67. static Xsync &Ins();
  68. void initialize(I_XSUDPFactory *xsync_udp_factory);
  69. /*******************************************************************************
  70. * *
  71. *******************************************************************************/
  72. bool ping(string xsync_ip);
  73. xs_error_code_t connect(string xsync_ip);
  74. xs_error_code_t disConnect();
  75. xsync_net_state_t getNetState();
  76. /*******************************************************************************
  77. * *
  78. *******************************************************************************/
  79. void Basic_registerOnTimecodeMsgCallback(xsync_on_timecode_msg_t on_timecode_msg_cb);
  80. void Basic_registerOnCameraSyncMsgCallback(xsync_on_camera_sync_msg_t on_camera_sync_msg_cb);
  81. void Basic_registerOnRecordSigChangeMsg(xsync_on_record_sig_change_msg_t on_record_sig_change_msg_cb);
  82. /*******************************************************************************
  83. * *
  84. *******************************************************************************/
  85. xs_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t &regbackvalue, int32_t overtime_ms = 100);
  86. xs_error_code_t reg_read(uint32_t regadd, uint32_t &regvalue, int32_t overtime_ms = 100);
  87. xs_error_code_t reg_read_muti(uint32_t regadd, uint32_t nreg, vector<uint32_t> &regvalues, int32_t overtime_ms = 100);
  88. /*******************************************************************************
  89. * *
  90. *******************************************************************************/
  91. xs_error_code_t Basic_generatorNewMac();
  92. xs_error_code_t Basic_factoryReset();
  93. xs_error_code_t Basic_reboot();
  94. xs_error_code_t Basic_changeNetworkConfig(string ip, string mask, string gateway);
  95. xs_error_code_t Basic_clearXsyncCameraSyncIndexCount();
  96. /***********************************************************************************************
  97. * *
  98. ***********************************************************************************************/
  99. /*******************************************************************************
  100. * *
  101. *******************************************************************************/
  102. /**
  103. * @brief
  104. *
  105. * @param src
  106. * INPUT_IF_TIMECODE_BNC
  107. * INPUT_IF_TIMECODE_HEADPHONE
  108. *
  109. * @return xs_error_code_t
  110. */
  111. xs_error_code_t TimecodeInputModule_setSrcSelect(InputInterface_t src);
  112. xs_error_code_t TimecodeInputModule_getSrcSelect(InputInterface_t &timecode_select);
  113. /**
  114. * @brief
  115. *
  116. * @param format
  117. * @return xs_error_code_t
  118. */
  119. xs_error_code_t TimecodeInputModule_setTimecodeFormat(TimecodeFormat_t format);
  120. xs_error_code_t TimecodeInputModule_getTimecodeFormat(TimecodeFormat_t &format);
  121. /*******************************************************************************
  122. * TTL输入模块 *
  123. *******************************************************************************/
  124. /**
  125. * @brief TTL输入模块的频率
  126. *
  127. * @param index
  128. * @param freq
  129. * @return xs_error_code_t
  130. */
  131. xs_error_code_t TTLInputModule1_detectFreq(uint32_t &freq);
  132. xs_error_code_t TTLInputModule2_detectFreq(uint32_t &freq);
  133. xs_error_code_t TTLInputModule3_detectFreq(uint32_t &freq);
  134. xs_error_code_t TTLInputModule4_detectFreq(uint32_t &freq);
  135. /*******************************************************************************
  136. * GENLOCK输入配置 *
  137. *******************************************************************************/
  138. /**
  139. * @brief Genlock输入模块的频率
  140. *
  141. * @param freq
  142. * @return xs_error_code_t
  143. */
  144. xs_error_code_t GenlockInputModule_detectFreq(uint32_t &freq);
  145. /***********************************************************************************************
  146. * *
  147. ***********************************************************************************************/
  148. /*******************************************************************************
  149. * *
  150. *******************************************************************************/
  151. /**
  152. * @brief Timecode信号发生器
  153. *
  154. * @param mode
  155. * :
  156. * CONTROLMODE_ALWAYS_START
  157. * @return xs_error_code_t
  158. */
  159. xs_error_code_t InternalTimecode_setContrlMode(ControlMode_t mode);
  160. xs_error_code_t InternalTimecode_getContrlMode(ControlMode_t &mode);
  161. /**
  162. * @brief Timecode信号发生器Timecode格式
  163. *
  164. * @param format
  165. *
  166. * TIMECODE_FPS2398
  167. * TIMECODE_FPS2400
  168. * TIMECODE_FPS2500
  169. * TIMECODE_FPS2997
  170. * TIMECODE_FPS2997Drop
  171. * TIMECODE_FPS3000
  172. *
  173. * @return xs_error_code_t
  174. */
  175. xs_error_code_t InternalTimecode_setTimecodeFormat(TimecodeFormat_t format);
  176. xs_error_code_t InternalTimecode_getTimecodeFormat(TimecodeFormat_t &format);
  177. /**
  178. * @brief Timecode信号发生器Timecode值
  179. *
  180. * @param timecode
  181. * @return xs_error_code_t
  182. */
  183. xs_error_code_t InternalTimecode_setTimecodeValue(XsyncTimecode_t timecode);
  184. xs_error_code_t InternalTimecode_getTimecodeValue(XsyncTimecode_t &timecode);
  185. /*******************************************************************************
  186. * Genlock信号发生器 *
  187. *******************************************************************************/
  188. /**
  189. * @brief Genlock信号发生器
  190. *
  191. * @param mode
  192. * :
  193. * CONTROLMODE_ALWAYS_START
  194. * @return xs_error_code_t
  195. */
  196. xs_error_code_t InternalGenlock_setContrlMode(ControlMode_t mode);
  197. xs_error_code_t InternalGenlock_getContrlMode(ControlMode_t &mode);
  198. /**
  199. * @brief Genlock信号发生器
  200. *
  201. * @param format
  202. * :
  203. * GENLOCK_FPS2397
  204. * GENLOCK_FPS2398
  205. * GENLOCK_FPS2400
  206. * GENLOCK_FPS2500
  207. * GENLOCK_FPS2997
  208. * GENLOCK_FPS3000
  209. * GENLOCK_FPS5000
  210. * GENLOCK_FPS5994
  211. * GENLOCK_FPS6000
  212. * @return xs_error_code_t
  213. */
  214. xs_error_code_t InternalGenlock_setFormat(GenlockFormat_t format);
  215. xs_error_code_t InternalGenlock_getFormat(GenlockFormat_t &format);
  216. /*******************************************************************************
  217. * *
  218. *******************************************************************************/
  219. /**
  220. * @brief
  221. *
  222. * @param mode
  223. * :
  224. * CONTROLMODE_ALWAYS_START
  225. * @return xs_error_code_t
  226. */
  227. xs_error_code_t InternalClockGenerator_setContrlMode(ControlMode_t mode);
  228. xs_error_code_t InternalClockGenerator_getContrlMode(ControlMode_t &mode);
  229. xs_error_code_t InternalClockGenerator_setFreq(uint32_t freq);
  230. xs_error_code_t InternalClockGenerator_getFreq(uint32_t &freq);
  231. /*******************************************************************************
  232. * *
  233. *******************************************************************************/
  234. /**
  235. * @brief
  236. *
  237. * @param mode
  238. * :
  239. * SIGNAL_TTLIN1
  240. * SIGNAL_TTLIN1
  241. * SIGNAL_TTLIN2
  242. * SIGNAL_TTLIN3
  243. * SIGNAL_TTLIN4
  244. * SIGNAL_INTERNAL_FREQ_SIG
  245. * SIGNAL_SYS_GENLOCK_OUTPUT
  246. *
  247. * @return xs_error_code_t
  248. */
  249. xs_error_code_t SysClock_setSrc(SignalType_t sig);
  250. xs_error_code_t SysClock_getSrc(SignalType_t &sig);
  251. /**
  252. * @brief 沿
  253. *
  254. * @param edge
  255. * TRIGGER_EDGE_RISING
  256. * TRIGGER_EDGE_FALLING
  257. * @return xs_error_code_t
  258. */
  259. xs_error_code_t SysClock_setTriggerEdge(TriggerEdge_t edge);
  260. xs_error_code_t SysClock_getTriggerEdge(TriggerEdge_t &edge);
  261. /**
  262. * @brief
  263. *
  264. * @param div
  265. * @return xs_error_code_t
  266. */
  267. xs_error_code_t SysClock_setFreqDivision(uint32_t div);
  268. xs_error_code_t SysClock_geFreqtDivision(uint32_t &div);
  269. /**
  270. * @brief
  271. *
  272. * @param freq
  273. * @return xs_error_code_t
  274. */
  275. xs_error_code_t SysClock_setFreqMultiplication(uint32_t freq);
  276. xs_error_code_t SysClock_getFreqMultiplication(uint32_t &freq);
  277. /**
  278. * @brief
  279. *
  280. * @param freq
  281. * @return xs_error_code_t
  282. */
  283. xs_error_code_t SysClock_readFreq(uint32_t &freq);
  284. /**
  285. * @brief
  286. *
  287. * @param freq
  288. * @return xs_error_code_t
  289. */
  290. xs_error_code_t SysClock_readInputFreq(uint32_t &freq);
  291. /*******************************************************************************
  292. * Genlock *
  293. *******************************************************************************/
  294. /**
  295. * @brief Genlock选择时钟源
  296. *
  297. * @param sig
  298. * :
  299. * SIGNAL_EXT_GENLOCK_FREQ
  300. * SIGNAL_INTERNAL_GENLOCK_FREQ
  301. *
  302. * @return xs_error_code_t
  303. */
  304. xs_error_code_t SysGenlock_setSrc(SignalType_t sig);
  305. xs_error_code_t SysGenlock_getSrc(SignalType_t &sig);
  306. /**
  307. * @brief Genlock频率
  308. *
  309. * @param freq
  310. * @return xs_error_code_t
  311. */
  312. xs_error_code_t SysGenlock_readFreq(uint32_t &freq);
  313. /*******************************************************************************
  314. * Timecode *
  315. *******************************************************************************/
  316. /**
  317. * @brief Timecode选择时钟源
  318. *
  319. * @param internal
  320. * 0: Timecode
  321. * 1: Timecode
  322. * @return xs_error_code_t
  323. */
  324. xs_error_code_t SysTimecode_setSrc(int32_t sig);
  325. xs_error_code_t SysTimecode_getSrc(int32_t &sig);
  326. /**
  327. * @brief Timecode频率
  328. *
  329. * @param freq
  330. * @return xs_error_code_t
  331. */
  332. xs_error_code_t SysTimecode_readFreq(uint32_t &freq);
  333. /**
  334. * @brief Timecode格式
  335. *
  336. * @param format
  337. * @return xs_error_code_t
  338. */
  339. xs_error_code_t SysTimecode_readFormat(TimecodeFormat_t &format);
  340. /**
  341. * @brief Timecode值
  342. *
  343. * @param timecode
  344. * @return xs_error_code_t
  345. */
  346. xs_error_code_t SysTimecode_readTimecode(XsyncTimecode_t &timecode);
  347. /*************************************************************************************************
  348. * *
  349. *************************************************************************************************/
  350. /*******************************************************************************
  351. * *
  352. *******************************************************************************/
  353. /**
  354. *
  355. *
  356. * :使
  357. * timecode控制源:使timecode
  358. * :
  359. * 1.
  360. *
  361. * :
  362. * SIGNAL_BUSINESS_RECORD_SIG
  363. * SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG
  364. */
  365. /**
  366. * @brief
  367. *
  368. * @param mode
  369. * :
  370. * CONTROLMODE_MANUAL_TRIGGER
  371. * CONTROLMODE_TIMECODE_TRIGGER
  372. * CONTROLMODE_EXTERNALTTL_TRIGGER
  373. * @return xs_error_code_t
  374. */
  375. xs_error_code_t RecordSigGenerator_setContrlMode(ControlMode_t mode);
  376. xs_error_code_t RecordSigGenerator_getContrlMode(ControlMode_t &mode);
  377. // 手动控制
  378. xs_error_code_t RecordSigGenerator_manualStart();
  379. xs_error_code_t RecordSigGenerator_manualStop();
  380. // timecode控制启停
  381. xs_error_code_t RecordSigGenerator_setAutoStartTimecode(XsyncTimecode_t timecode);
  382. xs_error_code_t RecordSigGenerator_setAutoStopTimecode(XsyncTimecode_t timecode);
  383. xs_error_code_t RecordSigGenerator_getAutoStartTimecode(XsyncTimecode_t &timecode);
  384. xs_error_code_t RecordSigGenerator_getAutoStopTimecode(XsyncTimecode_t &timecode);
  385. // 外部TTL触发控制
  386. /**
  387. * @brief
  388. *
  389. * @param ttlPortNum
  390. * INPUT_IF_TTL1
  391. * INPUT_IF_TTL2
  392. * INPUT_IF_TTL3
  393. * INPUT_IF_TTL4
  394. * @return xs_error_code_t
  395. */
  396. xs_error_code_t RecordSigGenerator_setExternalTTLTriggerSrc(InputInterface_t ttlPortNum); // 1-4
  397. xs_error_code_t RecordSigGenerator_getExternalTTLTriggerSrc(InputInterface_t &ttlPortNum);
  398. xs_error_code_t RecordSigGenerator_setExternalTTLTriggerPolarity(TriggerPolarity_t polarity);
  399. xs_error_code_t RecordSigGenerator_getExternalTTLTriggerPolarity(TriggerPolarity_t &polarity);
  400. /**
  401. * @brief
  402. *
  403. * @param us
  404. * @return xs_error_code_t
  405. */
  406. xs_error_code_t RecordSigGenerator_setRecordExposureTime(uint32_t us);
  407. /**
  408. * @brief
  409. *
  410. * @param us
  411. * @return xs_error_code_t
  412. */
  413. xs_error_code_t RecordSigGenerator_setRecordExposureOffsetTime(uint32_t us);
  414. /*************************************************************************************************
  415. * *
  416. *************************************************************************************************/
  417. /**
  418. * @brief TTLOutputModuleX_setSrcSigType TTL输出口设置信号源
  419. *
  420. * @param source
  421. * :
  422. * SIGNAL_TTLIN1
  423. * SIGNAL_TTLIN2
  424. * SIGNAL_TTLIN3
  425. * SIGNAL_TTLIN4
  426. * SIGNAL_SYS_CLK_OUTPUT
  427. * SIGNAL_SYS_GENLOCK_OUTPUT
  428. * SIGNAL_SYS_TIMECODE_FREQ_OUTPUT
  429. * SIGNAL_BUSINESS_RECORD_SIG
  430. * SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG
  431. *
  432. * @return xs_error_code_t
  433. */
  434. xs_error_code_t TTLOutputModule1_setSrcSigType(SignalType_t source);
  435. xs_error_code_t TTLOutputModule2_setSrcSigType(SignalType_t source);
  436. xs_error_code_t TTLOutputModule3_setSrcSigType(SignalType_t source);
  437. xs_error_code_t TTLOutputModule4_setSrcSigType(SignalType_t source);
  438. xs_error_code_t TTLOutputModule1_getSrcSigType(SignalType_t &source);
  439. xs_error_code_t TTLOutputModule2_getSrcSigType(SignalType_t &source);
  440. xs_error_code_t TTLOutputModule3_getSrcSigType(SignalType_t &source);
  441. xs_error_code_t TTLOutputModule4_getSrcSigType(SignalType_t &source);
  442. // 分频配置
  443. xs_error_code_t TTLOutputModule1_setFreqDivision(uint32_t div);
  444. xs_error_code_t TTLOutputModule2_setFreqDivision(uint32_t div);
  445. xs_error_code_t TTLOutputModule3_setFreqDivision(uint32_t div);
  446. xs_error_code_t TTLOutputModule4_setFreqDivision(uint32_t div);
  447. xs_error_code_t TTLOutputModule1_getFreqDivision(uint32_t &div);
  448. xs_error_code_t TTLOutputModule2_getFreqDivision(uint32_t &div);
  449. xs_error_code_t TTLOutputModule3_getFreqDivision(uint32_t &div);
  450. xs_error_code_t TTLOutputModule4_getFreqDivision(uint32_t &div);
  451. // 倍频配置
  452. xs_error_code_t TTLOutputModule1_setFreqMultiplication(uint32_t freq);
  453. xs_error_code_t TTLOutputModule2_setFreqMultiplication(uint32_t freq);
  454. xs_error_code_t TTLOutputModule3_setFreqMultiplication(uint32_t freq);
  455. xs_error_code_t TTLOutputModule4_setFreqMultiplication(uint32_t freq);
  456. xs_error_code_t TTLOutputModule1_getFreqMultiplication(uint32_t &freq);
  457. xs_error_code_t TTLOutputModule2_getFreqMultiplication(uint32_t &freq);
  458. xs_error_code_t TTLOutputModule3_getFreqMultiplication(uint32_t &freq);
  459. xs_error_code_t TTLOutputModule4_getFreqMultiplication(uint32_t &freq);
  460. /*******************************************************************************
  461. * Timecode输出口配置 *
  462. *******************************************************************************/
  463. /**
  464. * @brief TIMECODE输出模块
  465. *
  466. * : SYS_TIMECODE
  467. */
  468. /**
  469. * @brief BNC输出电平
  470. *
  471. * @param level
  472. * @return xs_error_code_t
  473. */
  474. xs_error_code_t TimecodeOutputModule_setBncOutputLevel(int level); // 0:line,1:mic
  475. xs_error_code_t TimecodeOutputModule_getBncOutputLevel(int &level);
  476. /**
  477. * @brief
  478. *
  479. * @param level
  480. * @return xs_error_code_t
  481. */
  482. xs_error_code_t TimecodeOutputModule_setHeadphoneOutputLevel(int level); // 0:line,1:mic
  483. xs_error_code_t TimecodeOutputModule_getHeadphoneOutputLevel(int &level);
  484. /*******************************************************************************
  485. * *
  486. *******************************************************************************/
  487. /**
  488. * @brief
  489. *
  490. *
  491. * : SYS_CLK
  492. * : 沿
  493. * 使 :
  494. */
  495. /**
  496. * @brief
  497. *
  498. * @param index
  499. * @return xs_error_code_t
  500. */
  501. xs_error_code_t CameraSyncPacketGeneratorModule_getPacketIndex(uint32_t &index);
  502. private:
  503. };
  504. } // namespace xsync