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.

562 lines
20 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
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, XsyncTimecode_t *timecode_msg)> 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信号发生器Timecode格式
  153. *
  154. * @param format
  155. *
  156. * TIMECODE_FPS2398
  157. * TIMECODE_FPS2400
  158. * TIMECODE_FPS2500
  159. * TIMECODE_FPS2997
  160. * TIMECODE_FPS2997Drop
  161. * TIMECODE_FPS3000
  162. *
  163. * @return xs_error_code_t
  164. */
  165. xs_error_code_t InternalTimecode_setTimecodeFormat(TimecodeFormat_t format);
  166. xs_error_code_t InternalTimecode_getTimecodeFormat(TimecodeFormat_t &format);
  167. /**
  168. * @brief Timecode信号发生器Timecode值
  169. *
  170. * @param timecode
  171. * @return xs_error_code_t
  172. */
  173. xs_error_code_t InternalTimecode_setTimecodeValue(XsyncTimecode_t timecode);
  174. xs_error_code_t InternalTimecode_getTimecodeValue(XsyncTimecode_t &timecode);
  175. /*******************************************************************************
  176. * Genlock信号发生器 *
  177. *******************************************************************************/
  178. /**
  179. * @brief Genlock信号发生器
  180. *
  181. * @param format
  182. * :
  183. * GENLOCK_FPS2397
  184. * GENLOCK_FPS2398
  185. * GENLOCK_FPS2400
  186. * GENLOCK_FPS2500
  187. * GENLOCK_FPS2997
  188. * GENLOCK_FPS3000
  189. * GENLOCK_FPS5000
  190. * GENLOCK_FPS5994
  191. * GENLOCK_FPS6000
  192. * @return xs_error_code_t
  193. */
  194. xs_error_code_t InternalGenlock_setFormat(GenlockFormat_t format);
  195. xs_error_code_t InternalGenlock_getFormat(GenlockFormat_t &format);
  196. /*******************************************************************************
  197. * *
  198. *******************************************************************************/
  199. /**
  200. * @brief
  201. *
  202. * @param mode
  203. * :
  204. * CONTROLMODE_ALWAYS_START
  205. * @return xs_error_code_t
  206. */
  207. xs_error_code_t InternalClockGenerator_setContrlMode(ControlMode_t mode);
  208. xs_error_code_t InternalClockGenerator_getContrlMode(ControlMode_t &mode);
  209. xs_error_code_t InternalClockGenerator_setFreq(uint32_t freq);
  210. xs_error_code_t InternalClockGenerator_getFreq(uint32_t &freq);
  211. /*******************************************************************************
  212. * *
  213. *******************************************************************************/
  214. /**
  215. * @brief
  216. *
  217. * @param mode
  218. * :
  219. * SIGNAL_TTLIN1
  220. * SIGNAL_TTLIN1
  221. * SIGNAL_TTLIN2
  222. * SIGNAL_TTLIN3
  223. * SIGNAL_TTLIN4
  224. * SIGNAL_INTERNAL_FREQ_SIG
  225. * SIGNAL_SYS_GENLOCK_OUTPUT
  226. *
  227. * @return xs_error_code_t
  228. */
  229. xs_error_code_t SysClock_setSrc(SignalType_t sig);
  230. xs_error_code_t SysClock_getSrc(SignalType_t &sig);
  231. /**
  232. * @brief 沿
  233. *
  234. * @param edge
  235. * TRIGGER_EDGE_RISING
  236. * TRIGGER_EDGE_FALLING
  237. * @return xs_error_code_t
  238. */
  239. xs_error_code_t SysClock_setTriggerEdge(TriggerEdge_t edge);
  240. xs_error_code_t SysClock_getTriggerEdge(TriggerEdge_t &edge);
  241. /**
  242. * @brief
  243. *
  244. * @param div
  245. * @return xs_error_code_t
  246. */
  247. xs_error_code_t SysClock_setFreqDivision(uint32_t div);
  248. xs_error_code_t SysClock_geFreqtDivision(uint32_t &div);
  249. /**
  250. * @brief
  251. *
  252. * @param freq
  253. * @return xs_error_code_t
  254. */
  255. xs_error_code_t SysClock_setFreqMultiplication(uint32_t freq);
  256. xs_error_code_t SysClock_getFreqMultiplication(uint32_t &freq);
  257. /**
  258. * @brief
  259. *
  260. * @param freq
  261. * @return xs_error_code_t
  262. */
  263. xs_error_code_t SysClock_readFreq(uint32_t &freq);
  264. /**
  265. * @brief
  266. *
  267. * @param freq
  268. * @return xs_error_code_t
  269. */
  270. xs_error_code_t SysClock_readInputFreq(uint32_t &freq);
  271. /*******************************************************************************
  272. * Genlock *
  273. *******************************************************************************/
  274. /**
  275. * @brief Genlock选择时钟源
  276. *
  277. * @param sig
  278. * :
  279. * SIGNAL_EXT_GENLOCK_FREQ
  280. * SIGNAL_INTERNAL_GENLOCK_FREQ
  281. *
  282. * @return xs_error_code_t
  283. */
  284. xs_error_code_t SysGenlock_setSrc(SignalType_t sig);
  285. xs_error_code_t SysGenlock_getSrc(SignalType_t &sig);
  286. /**
  287. * @brief Genlock频率
  288. *
  289. * @param freq
  290. * @return xs_error_code_t
  291. */
  292. xs_error_code_t SysGenlock_readFreq(uint32_t &freq);
  293. /*******************************************************************************
  294. * Timecode *
  295. *******************************************************************************/
  296. /**
  297. * @brief Timecode选择时钟源
  298. *
  299. * @param internal
  300. * 0: Timecode
  301. * 1: Timecode
  302. * @return xs_error_code_t
  303. */
  304. xs_error_code_t SysTimecode_setSrc(int32_t sig);
  305. xs_error_code_t SysTimecode_getSrc(int32_t &sig);
  306. /**
  307. * @brief Timecode频率
  308. *
  309. * @param freq
  310. * @return xs_error_code_t
  311. */
  312. xs_error_code_t SysTimecode_readFreq(uint32_t &freq);
  313. /**
  314. * @brief Timecode格式
  315. *
  316. * @param format
  317. * @return xs_error_code_t
  318. */
  319. xs_error_code_t SysTimecode_readFormat(TimecodeFormat_t &format);
  320. /**
  321. * @brief Timecode值
  322. *
  323. * @param timecode
  324. * @return xs_error_code_t
  325. */
  326. xs_error_code_t SysTimecode_readTimecode(XsyncTimecode_t &timecode);
  327. /*************************************************************************************************
  328. * *
  329. *************************************************************************************************/
  330. /*******************************************************************************
  331. * *
  332. *******************************************************************************/
  333. /**
  334. *
  335. *
  336. * :使
  337. * timecode控制源:使timecode
  338. * :
  339. * 1.
  340. *
  341. * :
  342. * SIGNAL_BUSINESS_RECORD_SIG
  343. * SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG
  344. */
  345. /**
  346. * @brief
  347. *
  348. * @param mode
  349. * :
  350. * CONTROLMODE_MANUAL_TRIGGER
  351. * CONTROLMODE_TIMECODE_TRIGGER
  352. * CONTROLMODE_EXTERNALTTL_TRIGGER
  353. * @return xs_error_code_t
  354. */
  355. xs_error_code_t RecordSigGenerator_setContrlMode(ControlMode_t mode);
  356. xs_error_code_t RecordSigGenerator_getContrlMode(ControlMode_t &mode);
  357. // 手动控制
  358. xs_error_code_t RecordSigGenerator_manualStart();
  359. xs_error_code_t RecordSigGenerator_manualStop();
  360. // timecode控制启停
  361. xs_error_code_t RecordSigGenerator_setAutoStartTimecode(XsyncTimecode_t timecode);
  362. xs_error_code_t RecordSigGenerator_setAutoStopTimecode(XsyncTimecode_t timecode);
  363. xs_error_code_t RecordSigGenerator_getAutoStartTimecode(XsyncTimecode_t &timecode);
  364. xs_error_code_t RecordSigGenerator_getAutoStopTimecode(XsyncTimecode_t &timecode);
  365. // 外部TTL触发控制
  366. /**
  367. * @brief
  368. *
  369. * @param ttlPortNum
  370. * INPUT_IF_TTL1
  371. * INPUT_IF_TTL2
  372. * INPUT_IF_TTL3
  373. * INPUT_IF_TTL4
  374. * @return xs_error_code_t
  375. */
  376. xs_error_code_t RecordSigGenerator_setExternalTTLTriggerSrc(InputInterface_t ttlPortNum); // 1-4
  377. xs_error_code_t RecordSigGenerator_getExternalTTLTriggerSrc(InputInterface_t &ttlPortNum);
  378. xs_error_code_t RecordSigGenerator_setExternalTTLTriggerPolarity(TriggerPolarity_t polarity);
  379. xs_error_code_t RecordSigGenerator_getExternalTTLTriggerPolarity(TriggerPolarity_t &polarity);
  380. /**
  381. * @brief
  382. *
  383. * @param us
  384. * @return xs_error_code_t
  385. */
  386. xs_error_code_t RecordSigGenerator_setRecordExposureTime(uint32_t us);
  387. xs_error_code_t RecordSigGenerator_getRecordExposureTime(uint32_t &us);
  388. /**
  389. * @brief
  390. *
  391. * @param us
  392. * @return xs_error_code_t
  393. */
  394. xs_error_code_t RecordSigGenerator_setRecordExposureOffsetTime(uint32_t us);
  395. xs_error_code_t RecordSigGenerator_getRecordExposureOffsetTime(uint32_t &us);
  396. /*************************************************************************************************
  397. * *
  398. *************************************************************************************************/
  399. /**
  400. * @brief TTLOutputModuleX_setSrcSigType TTL输出口设置信号源
  401. *
  402. * @param source
  403. * :
  404. * SIGNAL_TTLIN1
  405. * SIGNAL_TTLIN2
  406. * SIGNAL_TTLIN3
  407. * SIGNAL_TTLIN4
  408. * SIGNAL_SYS_CLK_OUTPUT
  409. * SIGNAL_SYS_GENLOCK_OUTPUT
  410. * SIGNAL_SYS_TIMECODE_FREQ_OUTPUT
  411. * SIGNAL_BUSINESS_RECORD_SIG
  412. * SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG
  413. *
  414. * @return xs_error_code_t
  415. */
  416. xs_error_code_t TTLOutputModule1_setSrcSigType(SignalType_t source);
  417. xs_error_code_t TTLOutputModule2_setSrcSigType(SignalType_t source);
  418. xs_error_code_t TTLOutputModule3_setSrcSigType(SignalType_t source);
  419. xs_error_code_t TTLOutputModule4_setSrcSigType(SignalType_t source);
  420. xs_error_code_t TTLOutputModule1_getSrcSigType(SignalType_t &source);
  421. xs_error_code_t TTLOutputModule2_getSrcSigType(SignalType_t &source);
  422. xs_error_code_t TTLOutputModule3_getSrcSigType(SignalType_t &source);
  423. xs_error_code_t TTLOutputModule4_getSrcSigType(SignalType_t &source);
  424. // 分频配置
  425. xs_error_code_t TTLOutputModule1_setFreqDivision(uint32_t div);
  426. xs_error_code_t TTLOutputModule2_setFreqDivision(uint32_t div);
  427. xs_error_code_t TTLOutputModule3_setFreqDivision(uint32_t div);
  428. xs_error_code_t TTLOutputModule4_setFreqDivision(uint32_t div);
  429. xs_error_code_t TTLOutputModule1_getFreqDivision(uint32_t &div);
  430. xs_error_code_t TTLOutputModule2_getFreqDivision(uint32_t &div);
  431. xs_error_code_t TTLOutputModule3_getFreqDivision(uint32_t &div);
  432. xs_error_code_t TTLOutputModule4_getFreqDivision(uint32_t &div);
  433. // 倍频配置
  434. xs_error_code_t TTLOutputModule1_setFreqMultiplication(uint32_t freq);
  435. xs_error_code_t TTLOutputModule2_setFreqMultiplication(uint32_t freq);
  436. xs_error_code_t TTLOutputModule3_setFreqMultiplication(uint32_t freq);
  437. xs_error_code_t TTLOutputModule4_setFreqMultiplication(uint32_t freq);
  438. xs_error_code_t TTLOutputModule1_getFreqMultiplication(uint32_t &freq);
  439. xs_error_code_t TTLOutputModule2_getFreqMultiplication(uint32_t &freq);
  440. xs_error_code_t TTLOutputModule3_getFreqMultiplication(uint32_t &freq);
  441. xs_error_code_t TTLOutputModule4_getFreqMultiplication(uint32_t &freq);
  442. /*******************************************************************************
  443. * Timecode输出口配置 *
  444. *******************************************************************************/
  445. /**
  446. * @brief TIMECODE输出模块
  447. *
  448. * : SYS_TIMECODE
  449. */
  450. /**
  451. * @brief BNC输出电平
  452. *
  453. * @param level
  454. * @return xs_error_code_t
  455. */
  456. xs_error_code_t TimecodeOutputModule_setBncOutputLevel(int level); // 0:line,1:mic
  457. xs_error_code_t TimecodeOutputModule_getBncOutputLevel(int &level);
  458. /**
  459. * @brief
  460. *
  461. * @param level
  462. * @return xs_error_code_t
  463. */
  464. xs_error_code_t TimecodeOutputModule_setHeadphoneOutputLevel(int level); // 0:line,1:mic
  465. xs_error_code_t TimecodeOutputModule_getHeadphoneOutputLevel(int &level);
  466. /*******************************************************************************
  467. * *
  468. *******************************************************************************/
  469. /**
  470. * @brief
  471. *
  472. *
  473. * : SYS_CLK
  474. * : 沿
  475. * 使 :
  476. */
  477. /**
  478. * @brief
  479. *
  480. * @param index
  481. * @return xs_error_code_t
  482. */
  483. xs_error_code_t CameraSyncPacketGeneratorModule_getPacketIndex(uint32_t &index);
  484. private:
  485. void parseTimecodeMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length);
  486. void parseCameraSyncMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length);
  487. xs_error_code_t xsync_send_cmd_block(iflytop_xsync_packet_header_t *cmd, iflytop_xsync_packet_header_t *rx_data, int32_t buffersize, int32_t overtime_ms);
  488. xs_error_code_t doaction(uint32_t action, uint32_t actionval, uint32_t *ackreturn, int32_t overtime_ms);
  489. xs_error_code_t storageConfig();
  490. };
  491. } // namespace xsync