|
|
#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 "xsync_errcode.hpp"
#include "xsync_packet.hpp"
#include "xsync_regs.hpp"
namespace xsync { using namespace std;
typedef enum { kxsync_net_state_disconnect, kxsync_net_state_connecting, kxsync_net_state_connected, } xsync_net_state_t;
typedef enum { TIMECODE_FPS2398 = 0, TIMECODE_FPS2400 = 1, TIMECODE_FPS2500 = 2, TIMECODE_FPS2997 = 3, TIMECODE_FPS2997Drop = 4, TIMECODE_FPS3000 = 5, } TimecodeFormat_t;
typedef enum { GENLOCK_FPS2397 = 0, GENLOCK_FPS2398 = 1, GENLOCK_FPS2400 = 2, GENLOCK_FPS2500 = 3, GENLOCK_FPS2997 = 4, GENLOCK_FPS3000 = 5, GENLOCK_FPS5000 = 6, GENLOCK_FPS5994 = 7, GENLOCK_FPS6000 = 8, } GenlockFormat_t;
string GenlockFormatToStr(GenlockFormat_t fomrat); string TimecodeFormatToStr(TimecodeFormat_t fomrat); GenlockFormat_t Str2GenlockFormat(string format); TimecodeFormat_t Str2TimecodeFormat(string format); list<string> GenlockFormatStrSet(); list<string> TimecodeFormatStrSet();
typedef struct { uint8_t hour; uint8_t minute; uint8_t second; uint8_t frame; } XsyncTimecode_t;
string XsyncTimecodeToStr(XsyncTimecode_t timecode); XsyncTimecode_t Str2XsyncTimecode(string timecode);
typedef struct { uint32_t tc0; uint32_t tc1; } Timecode64_t;
typedef struct { uint32_t frameIndex; } xysnc_camera_sync_data_t;
typedef function<void(XsyncTimecode_t *timecode_msg)> xsync_on_timecode_msg_t; typedef function<void(xysnc_camera_sync_data_t *timecode_msg)> xsync_on_camera_sync_msg_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 { OutSigType_logic0 = 0, // 0
OutSigType_logic1 = 1, // 1
OutSigType_test_signal = 2, // 测试信号,信号为ID*1000HZ方波信号
OutSigType_input_signal = 3, // 输入信号
OutSigType_input_signal_mirror = 4, // 翻转后的输入信号
OutSigType_trigger_mode_signal = 5, // 触发模式下的触发信号
OutSigType_trigger_mode_signal_mirror = 6, // 触发模式下的触发信号翻转
} OutputSigType_t;
string OutputSigType2Str(OutputSigType_t type); OutputSigType_t Str2OutputSigType(string type); list<string> OutputSigTypeStrSet();
} // namespace ttlout_module
/*******************************************************************************
* 信号发生器模块相关枚举 * *******************************************************************************/ namespace sig_generator_module {
typedef enum { kControlMode_manualTrigger, // 0.手动,启动停止
kControlMode_externalTimecodeTrigger, // 1.外部TIMECODE触发启动
kControlMode_externalTTL1Trigger, // 2.外部TTL输入1_高电平触发,低电平停止
kControlMode_externalTTL2Trigger, // 3.外部TTL输入2_高电平触发,低电平停止
kControlMode_externalTTL3Trigger, // 4.外部TTL输入3_高电平触发,低电平停止
kControlMode_externalTTL4Trigger, // 5.外部TTL输入4_高电平触发,低电平停止
} ControlMode_t;
string ControlMode2Str(ControlMode_t mode); ControlMode_t Str2ControlMode(string mode); list<string> ControlModeStrSet();
} // namespace sig_generator_module
namespace timecode_output_module { typedef enum { koff = 0, // 关闭输出
kinternal_timecode_sig = 1, // 外部timecode信号
kext_timecode_sig = 2, // 内部timecode信号
} TriggerSigType_t;
typedef enum { kline, kmic, } OutputSigLevelType_t;
string TriggerSigType2Str(TriggerSigType_t type); TriggerSigType_t Str2TriggerSigType(string type); list<string> TriggerSigTypeStrSet();
string OutputSigLevelType2Str(OutputSigLevelType_t type); OutputSigLevelType_t Str2OutputSigLevelType(string type); list<string> OutputSigLevelTypeStrSet();
} // namespace timecode_output_module
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();
xs_error_code_t Basic_setGenlockFormat(GenlockFormat_t format); xs_error_code_t Basic_getGenlockFormat(GenlockFormat_t &format); xs_error_code_t Basic_setTimecodeFormat(TimecodeFormat_t format); xs_error_code_t Basic_getTimecodeFormat(TimecodeFormat_t &format);
/*******************************************************************************
* 信号生成器模块 * *******************************************************************************/ /**
* 可配置项: * 0. 启动模式配置 * 1. TIMECODE触发模式下,自动启动时间配置 */
/**
* @brief 设置控制模式 * * @param mode * @return xs_error_code_t */ xs_error_code_t SigGenerator_setControlMode(sig_generator_module::ControlMode_t mode); /**
* @brief 获取控制模式 * * @param mode * @return xs_error_code_t */ xs_error_code_t SigGenerator_getControlMode(sig_generator_module::ControlMode_t &mode);
/**
* @brief 手动启动信号发生器 * * @return xs_error_code_t */ xs_error_code_t SigGenerator_manualStart(); /**
* @brief 手动关闭信号发生器 * * @return xs_error_code_t */ xs_error_code_t SigGenerator_manualStop();
/**
* @brief 设置时码时间 * * @param timecode * @return xs_error_code_t */ xs_error_code_t SigGenerator_setTimecode(XsyncTimecode_t timecode); /**
* @brief 获取时码时间 * * @param timecode * @return xs_error_code_t */ xs_error_code_t SigGenerator_getTimecode(XsyncTimecode_t &timecode);
/**
* @brief 设置时码触发模式下,自动启动时间 * * @param timecode * @return xs_error_code_t */ xs_error_code_t SigGenerator_setAutoStartTimecode(XsyncTimecode_t timecode); /**
* @brief 获取时码触发模式下,自动启动时间 * * @param timecode * @return xs_error_code_t */ xs_error_code_t SigGenerator_getAutoStartTimecode(XsyncTimecode_t &timecode); /**
* @brief 获取当前信号发生器工作状态 * * @param work_state * @return xs_error_code_t */ xs_error_code_t SigGenerator_getWorkState(uint32_t &work_state);
/**
* @brief 设置信号发生器的genlock格式 * * @param format * @return xs_error_code_t */ xs_error_code_t SigGenerator_setGenlockFormat(GenlockFormat_t format); // 不建议使用这个方法,用Basic_setGenlockFormat
xs_error_code_t SigGenerator_getGenlockFormat(GenlockFormat_t &format); // 不建议使用这个方法,用Basic_getGenlockFormat
/**
* @brief 设置信号发生器的timecode格式 * * @param format * @return xs_error_code_t */ xs_error_code_t SigGenerator_setTimecodeFormat(TimecodeFormat_t format); // 不建议使用这个方法,用Basic_setTimecodeFormat
xs_error_code_t SigGenerator_getTimecodeFormat(TimecodeFormat_t &format); // 不建议使用这个方法,用Basic_getTimecodeFormat
public: /*******************************************************************************
* 时码输出控制模块 * *******************************************************************************/
/**
* @brief 时码输出源选择 * * @param timecode_select * @return xs_error_code_t */ xs_error_code_t TimecodeOutputModule_setTimecodeSrcSelect(timecode_output_module::TriggerSigType_t timecode_select); xs_error_code_t TimecodeOutputModule_getTimecodeSrcSelect(timecode_output_module::TriggerSigType_t &timecode_select);
/**
* @brief 时码输出模块的时码 * * @param timecode_now * @return xs_error_code_t */ xs_error_code_t TimecodeOutputModule_getTimecodeNow(XsyncTimecode_t &timecode_now); /**
* @brief 获取时码输出模块的时码格式 * * @param timecode_format * @return xs_error_code_t */ xs_error_code_t TimecodeOutputModule_getTimecodeFormat(TimecodeFormat_t &timecode_format);
/**
* @brief 设置时码输出模块的BNC输出电平 * * @param level * @return xs_error_code_t */ xs_error_code_t TimecodeOutputModule_setBncOutputLevel(timecode_output_module::OutputSigLevelType_t &level); xs_error_code_t TimecodeOutputModule_getBncOutputLevel(timecode_output_module::OutputSigLevelType_t &level); /**
* @brief 设置时码输出模块的耳机输出电平 * * @param level * @return xs_error_code_t */ xs_error_code_t TimecodeOutputModule_setHeadphoneOutputLevel(timecode_output_module::OutputSigLevelType_t &level); xs_error_code_t TimecodeOutputModule_getHeadphoneOutputLevel(timecode_output_module::OutputSigLevelType_t &level);
public: /*******************************************************************************
* 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);
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); };
} // namespace xsync
|