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.

213 lines
8.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years 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 "iflytop_xsync_protocol/iflytop_xsync_protocol.h"
  16. #include "xsync_errcode.hpp"
  17. namespace xsync {
  18. using namespace std;
  19. typedef enum {
  20. kxsync_net_state_disconnect,
  21. kxsync_net_state_connecting,
  22. kxsync_net_state_connected,
  23. } xsync_net_state_t;
  24. /*******************************************************************************
  25. * TTL输出模块相关枚举 *
  26. *******************************************************************************/
  27. namespace ttlout_module {
  28. typedef enum {
  29. tri_logic0 = 0, // 逻辑0
  30. tri_logic1 = 1, // 逻辑1
  31. tri_ttlin1_module_ext = 2, // ttl1输入模块原始信号
  32. tri_ttlin1_module_divide = 3, // ttl1输入模块分频信号
  33. tri_ttlin2_module_ext = 4, // ttl2输入模块原始信号
  34. tri_ttlin2_module_divide = 5, // ttl2输入模块分频信号
  35. tri_ttlin3_module_ext = 6, // ttl3输入模块原始信号
  36. tri_ttlin3_module_divide = 7, // ttl3输入模块分频信号
  37. tri_ttlin4_module_ext = 8, // ttl4输入模块原始信号
  38. tri_ttlin4_module_divide = 9, // ttl4输入模块分频信号
  39. tri_internal_en_flag = 10, // 内部使能状态信号输出
  40. tri_genlock_frame_sync_ext = 11, // 外部genlock帧同步信号
  41. tri_genlock_frame_sync_internal = 12, // 内部genlock帧同步信号
  42. tri_timecode_frame_sync_ext = 13, // 外部timecode帧同步信号
  43. tri_timecode_frame_sync_internal = 14, // 内部timecode帧同步信号
  44. tri_timecode_serial_data_ext = 15, // 外部timecode串行数据输入
  45. tri_timecode_serial_data_internal = 16, // 内部timecode串行数据输入
  46. tri_internal_100hz = 31 // 100hz测试信号
  47. } TriggerSigType_t;
  48. string TriggerSigType2Str(TriggerSigType_t type);
  49. TriggerSigType_t Str2TriggerSigType(string type);
  50. list<string> TriggerSigTypeStrSet();
  51. typedef enum {
  52. ot_logic0 = 0, // 0
  53. ot_logic1 = 1, // 1
  54. ot_test_signal = 2, // 测试信号,信号为ID*1000HZ方波信号
  55. ot_input_signal = 3, // 输入信号
  56. ot_input_signal_mirror = 4, // 翻转后的输入信号
  57. ot_trigger_mode_signal = 5, // 触发模式下的触发信号
  58. ot_trigger_mode_signal_mirror = 6, // 触发模式下的触发信号翻转
  59. } OutputSigType_t;
  60. string OutputSigType2Str(OutputSigType_t type);
  61. OutputSigType_t Str2OutputSigType(string type);
  62. list<string> OutputSigTypeStrSet();
  63. } // namespace ttlout_module
  64. typedef struct {
  65. uint8_t hour;
  66. uint8_t minute;
  67. uint8_t second;
  68. uint8_t frame;
  69. } xysnc_timecode_t;
  70. typedef struct {
  71. uint32_t frameIndex;
  72. } xysnc_camera_sync_data_t;
  73. typedef function<void(xysnc_timecode_t *timecode_msg)> xsync_on_timecode_msg_t;
  74. typedef function<void(xysnc_camera_sync_data_t *timecode_msg)> xsync_on_camera_sync_msg_t;
  75. class Xsync {
  76. public:
  77. private:
  78. /* data */
  79. I_XSUDPFactory *m_xsync_udp_factory = nullptr;
  80. shared_ptr<I_XSUDP> m_xsync_reg_udp = nullptr;
  81. shared_ptr<I_XSUDP> m_xsync_timecode_udp_listener = nullptr;
  82. shared_ptr<I_XSUDP> m_xsync_camera_sync_udp_listener = nullptr;
  83. string m_xsync_ip;
  84. bool m_is_connected = false;
  85. xsync_on_camera_sync_msg_t m_on_camera_sync_msg_cb = nullptr;
  86. xsync_on_timecode_msg_t m_on_timecode_msg_cb = nullptr;
  87. int txpacket_index = 0;
  88. uint8_t m_xync_cmd_rxdata_cache[2560];
  89. xsync_net_state_t m_net_state = kxsync_net_state_disconnect;
  90. std::recursive_mutex lock_;
  91. Xsync(/* args */);
  92. public:
  93. static Xsync &Ins();
  94. void initialize(I_XSUDPFactory *xsync_udp_factory);
  95. /*******************************************************************************
  96. * *
  97. *******************************************************************************/
  98. bool ping(string xsync_ip);
  99. xs_error_code_t connect(string xsync_ip);
  100. xs_error_code_t disConnect();
  101. xsync_net_state_t getNetState();
  102. /*******************************************************************************
  103. * *
  104. *******************************************************************************/
  105. void Basic_registerOnTimecodeMsgCallback(xsync_on_timecode_msg_t on_timecode_msg_cb);
  106. void Basic_registerOnCameraSyncMsgCallback(xsync_on_camera_sync_msg_t on_camera_sync_msg_cb);
  107. /*******************************************************************************
  108. * *
  109. *******************************************************************************/
  110. xs_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t &regbackvalue, int32_t overtime_ms = 100);
  111. xs_error_code_t reg_read(uint32_t regadd, uint32_t &regvalue, int32_t overtime_ms = 100);
  112. xs_error_code_t reg_read_muti(uint32_t regadd, uint32_t nreg, vector<uint32_t> &regvalues, int32_t overtime_ms = 100);
  113. /*******************************************************************************
  114. * *
  115. *******************************************************************************/
  116. xs_error_code_t Basic_generatorNewMac();
  117. xs_error_code_t Basic_factoryReset();
  118. xs_error_code_t Basic_reboot();
  119. xs_error_code_t Basic_changeNetworkConfig(string ip, string mask, string gateway);
  120. xs_error_code_t Basic_clearXsyncCameraSyncIndexCount();
  121. /*******************************************************************************
  122. * TTL输出模块控制 *
  123. *******************************************************************************/
  124. /**
  125. *
  126. * 1.
  127. * 2.
  128. * 3.
  129. * 4.
  130. *
  131. */
  132. /**
  133. * @brief TTL输出模块的输入信号
  134. *
  135. * @param index
  136. * @param source
  137. * @return xs_error_code_t
  138. */
  139. xs_error_code_t TTLOutputModule_setInputSigType(int32_t index, ttlout_module::TriggerSigType_t source);
  140. xs_error_code_t TTLOutputModule_getInputSigType(int32_t index, ttlout_module::TriggerSigType_t &source);
  141. /**
  142. * @brief TTL输出模块的输出信号
  143. *
  144. * @param index
  145. * @param output_type
  146. * @return xs_error_code_t
  147. */
  148. xs_error_code_t TTLOutputModule_setOutputSigType(int32_t index, ttlout_module::OutputSigType_t output_type);
  149. xs_error_code_t TTLOutputModule_getOutputSigType(int32_t index, ttlout_module::OutputSigType_t &output_type);
  150. /**
  151. * @brief
  152. *
  153. * @param index
  154. * @param pulse_width_ms
  155. * @return xs_error_code_t
  156. */
  157. xs_error_code_t TTLOutputModule_setTriggerModePulseWidth(int32_t index, uint32_t pulse_width_ms);
  158. xs_error_code_t TTLOutputModule_getTriggerModePulseWidth(int32_t index, uint32_t &pulse_width_ms);
  159. /**
  160. * @brief
  161. *
  162. * @param index
  163. * @param pulse_delay_ms
  164. * @return xs_error_code_t
  165. */
  166. xs_error_code_t TTLOutputModule_setTriggerModePulseDelay(int32_t index, uint32_t pulse_delay_ms);
  167. xs_error_code_t TTLOutputModule_getTriggerModePulseDelay(int32_t index, uint32_t &pulse_delay_ms);
  168. /**
  169. * @brief
  170. */
  171. private:
  172. xs_error_code_t doaction(uint32_t action, uint32_t actionval, uint32_t *ackreturn, int32_t overtime_ms = 100);
  173. xs_error_code_t storageConfig();
  174. 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);
  175. void parseTimecodeMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length);
  176. void parseCameraSyncMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length);
  177. xs_error_code_t TTLOutputModule_getRegOff(int32_t index, uint32_t &regadd);
  178. };
  179. } // namespace xsync