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
213 lines
8.3 KiB
#pragma once
|
|
#include <fstream>
|
|
#include <functional>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <set>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
//
|
|
#include "i_xsync_udp.hpp"
|
|
#include "iflytop_xsync_protocol/iflytop_xsync_protocol.h"
|
|
#include "xsync_errcode.hpp"
|
|
namespace xsync {
|
|
using namespace std;
|
|
|
|
typedef enum {
|
|
kxsync_net_state_disconnect,
|
|
kxsync_net_state_connecting,
|
|
kxsync_net_state_connected,
|
|
} xsync_net_state_t;
|
|
|
|
/*******************************************************************************
|
|
* TTL输出模块相关枚举 *
|
|
*******************************************************************************/
|
|
namespace ttlout_module {
|
|
typedef enum {
|
|
tri_logic0 = 0, // 逻辑0
|
|
tri_logic1 = 1, // 逻辑1
|
|
tri_ttlin1_module_ext = 2, // ttl1输入模块原始信号
|
|
tri_ttlin1_module_divide = 3, // ttl1输入模块分频信号
|
|
tri_ttlin2_module_ext = 4, // ttl2输入模块原始信号
|
|
tri_ttlin2_module_divide = 5, // ttl2输入模块分频信号
|
|
tri_ttlin3_module_ext = 6, // ttl3输入模块原始信号
|
|
tri_ttlin3_module_divide = 7, // ttl3输入模块分频信号
|
|
tri_ttlin4_module_ext = 8, // ttl4输入模块原始信号
|
|
tri_ttlin4_module_divide = 9, // ttl4输入模块分频信号
|
|
tri_internal_en_flag = 10, // 内部使能状态信号输出
|
|
tri_genlock_frame_sync_ext = 11, // 外部genlock帧同步信号
|
|
tri_genlock_frame_sync_internal = 12, // 内部genlock帧同步信号
|
|
tri_timecode_frame_sync_ext = 13, // 外部timecode帧同步信号
|
|
tri_timecode_frame_sync_internal = 14, // 内部timecode帧同步信号
|
|
tri_timecode_serial_data_ext = 15, // 外部timecode串行数据输入
|
|
tri_timecode_serial_data_internal = 16, // 内部timecode串行数据输入
|
|
tri_internal_100hz = 31 // 100hz测试信号
|
|
} TriggerSigType_t;
|
|
|
|
string TriggerSigType2Str(TriggerSigType_t type);
|
|
TriggerSigType_t Str2TriggerSigType(string type);
|
|
list<string> TriggerSigTypeStrSet();
|
|
|
|
typedef enum {
|
|
ot_logic0 = 0, // 0
|
|
ot_logic1 = 1, // 1
|
|
ot_test_signal = 2, // 测试信号,信号为ID*1000HZ方波信号
|
|
ot_input_signal = 3, // 输入信号
|
|
ot_input_signal_mirror = 4, // 翻转后的输入信号
|
|
ot_trigger_mode_signal = 5, // 触发模式下的触发信号
|
|
ot_trigger_mode_signal_mirror = 6, // 触发模式下的触发信号翻转
|
|
} OutputSigType_t;
|
|
|
|
string OutputSigType2Str(OutputSigType_t type);
|
|
OutputSigType_t Str2OutputSigType(string type);
|
|
list<string> OutputSigTypeStrSet();
|
|
|
|
} // namespace ttlout_module
|
|
|
|
typedef struct {
|
|
uint8_t hour;
|
|
uint8_t minute;
|
|
uint8_t second;
|
|
uint8_t frame;
|
|
} xysnc_timecode_t;
|
|
|
|
typedef struct {
|
|
uint32_t frameIndex;
|
|
} xysnc_camera_sync_data_t;
|
|
|
|
typedef function<void(xysnc_timecode_t *timecode_msg)> xsync_on_timecode_msg_t;
|
|
typedef function<void(xysnc_camera_sync_data_t *timecode_msg)> xsync_on_camera_sync_msg_t;
|
|
|
|
class Xsync {
|
|
public:
|
|
private:
|
|
/* data */
|
|
|
|
I_XSUDPFactory *m_xsync_udp_factory = nullptr;
|
|
shared_ptr<I_XSUDP> m_xsync_reg_udp = nullptr;
|
|
shared_ptr<I_XSUDP> m_xsync_timecode_udp_listener = nullptr;
|
|
shared_ptr<I_XSUDP> m_xsync_camera_sync_udp_listener = nullptr;
|
|
|
|
string m_xsync_ip;
|
|
bool m_is_connected = false;
|
|
|
|
xsync_on_camera_sync_msg_t m_on_camera_sync_msg_cb = nullptr;
|
|
xsync_on_timecode_msg_t m_on_timecode_msg_cb = nullptr;
|
|
|
|
int txpacket_index = 0;
|
|
|
|
uint8_t m_xync_cmd_rxdata_cache[2560];
|
|
|
|
xsync_net_state_t m_net_state = kxsync_net_state_disconnect;
|
|
|
|
std::recursive_mutex lock_;
|
|
|
|
Xsync(/* args */);
|
|
|
|
public:
|
|
static Xsync &Ins();
|
|
|
|
void initialize(I_XSUDPFactory *xsync_udp_factory);
|
|
|
|
/*******************************************************************************
|
|
* 设备连接操作 *
|
|
*******************************************************************************/
|
|
bool ping(string xsync_ip);
|
|
|
|
xs_error_code_t connect(string xsync_ip);
|
|
xs_error_code_t disConnect();
|
|
xsync_net_state_t getNetState();
|
|
|
|
/*******************************************************************************
|
|
* 上报消息监听 *
|
|
*******************************************************************************/
|
|
void Basic_registerOnTimecodeMsgCallback(xsync_on_timecode_msg_t on_timecode_msg_cb);
|
|
void Basic_registerOnCameraSyncMsgCallback(xsync_on_camera_sync_msg_t on_camera_sync_msg_cb);
|
|
|
|
/*******************************************************************************
|
|
* 寄存器直接读写操作 *
|
|
*******************************************************************************/
|
|
xs_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms = 100);
|
|
xs_error_code_t reg_read(uint32_t regadd, uint32_t ®value, int32_t overtime_ms = 100);
|
|
xs_error_code_t reg_read_muti(uint32_t regadd, uint32_t nreg, vector<uint32_t> ®values, int32_t overtime_ms = 100);
|
|
|
|
/*******************************************************************************
|
|
* 设备基础操作 *
|
|
*******************************************************************************/
|
|
xs_error_code_t Basic_generatorNewMac();
|
|
xs_error_code_t Basic_factoryReset();
|
|
xs_error_code_t Basic_reboot();
|
|
xs_error_code_t Basic_changeNetworkConfig(string ip, string mask, string gateway);
|
|
|
|
xs_error_code_t Basic_clearXsyncCameraSyncIndexCount();
|
|
|
|
/*******************************************************************************
|
|
* TTL输出模块控制 *
|
|
*******************************************************************************/
|
|
/**
|
|
*
|
|
* 1. 配置输入信号选择器
|
|
* 2. 配置输出信号选择器
|
|
* 3. 配置触发模式下触发信号脉冲宽度
|
|
* 4. 配置触发模式下触发信号脉冲延时
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* @brief 设置TTL输出模块的输入信号
|
|
*
|
|
* @param index
|
|
* @param source
|
|
* @return xs_error_code_t
|
|
*/
|
|
xs_error_code_t TTLOutputModule_setInputSigType(int32_t index, ttlout_module::TriggerSigType_t source);
|
|
xs_error_code_t TTLOutputModule_getInputSigType(int32_t index, ttlout_module::TriggerSigType_t &source);
|
|
|
|
/**
|
|
* @brief 设置TTL输出模块的输出信号
|
|
*
|
|
* @param index
|
|
* @param output_type
|
|
* @return xs_error_code_t
|
|
*/
|
|
xs_error_code_t TTLOutputModule_setOutputSigType(int32_t index, ttlout_module::OutputSigType_t output_type);
|
|
xs_error_code_t TTLOutputModule_getOutputSigType(int32_t index, ttlout_module::OutputSigType_t &output_type);
|
|
/**
|
|
* @brief 配置触发模式下触发信号脉冲宽度
|
|
*
|
|
* @param index
|
|
* @param pulse_width_ms
|
|
* @return xs_error_code_t
|
|
*/
|
|
xs_error_code_t TTLOutputModule_setTriggerModePulseWidth(int32_t index, uint32_t pulse_width_ms);
|
|
xs_error_code_t TTLOutputModule_getTriggerModePulseWidth(int32_t index, uint32_t &pulse_width_ms);
|
|
/**
|
|
* @brief 配置触发模式下触发信号脉冲延时
|
|
*
|
|
* @param index
|
|
* @param pulse_delay_ms
|
|
* @return xs_error_code_t
|
|
*/
|
|
xs_error_code_t TTLOutputModule_setTriggerModePulseDelay(int32_t index, uint32_t pulse_delay_ms);
|
|
xs_error_code_t TTLOutputModule_getTriggerModePulseDelay(int32_t index, uint32_t &pulse_delay_ms);
|
|
|
|
/**
|
|
* @brief
|
|
*/
|
|
private:
|
|
xs_error_code_t doaction(uint32_t action, uint32_t actionval, uint32_t *ackreturn, int32_t overtime_ms = 100);
|
|
xs_error_code_t storageConfig();
|
|
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);
|
|
|
|
void parseTimecodeMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length);
|
|
void parseCameraSyncMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length);
|
|
|
|
xs_error_code_t TTLOutputModule_getRegOff(int32_t index, uint32_t ®add);
|
|
};
|
|
|
|
} // namespace xsync
|