diff --git a/xsync.cpp b/xsync.cpp index 3ea704e..7f91dfc 100644 --- a/xsync.cpp +++ b/xsync.cpp @@ -75,7 +75,7 @@ static map TriggerSigType2StrMap = { {"ttlin3_module_divide", tri_ttlin3_module_divide}, {"ttlin4_module_ext", tri_ttlin4_module_ext}, {"ttlin4_module_divide", tri_ttlin4_module_divide}, - {"internal_en_flag", tri_internal_en_flag}, + {"recorded_sig", tri_recorded_sig}, {"genlock_frame_sync_ext", tri_genlock_frame_sync_ext}, {"genlock_frame_sync_internal", tri_genlock_frame_sync_internal}, {"timecode_frame_sync_ext", tri_timecode_frame_sync_ext}, diff --git a/xsync.hpp b/xsync.hpp index ab25ae4..25740f1 100644 --- a/xsync.hpp +++ b/xsync.hpp @@ -91,14 +91,16 @@ typedef enum { tri_ttlin3_module_divide = 7, // ttl3输入模块分频信号 tri_ttlin4_module_ext = 8, // ttl4输入模块原始信号 tri_ttlin4_module_divide = 9, // ttl4输入模块分频信号 - tri_internal_en_flag = 10, // 内部使能状态信号输出 + tri_recorded_sig = 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测试信号 + tri_internal_clk_1hz = 17, // 内部 + + tri_internal_100hz = 31 // 100hz测试信号 } TriggerSigType_t; string TriggerSigType2Str(TriggerSigType_t type); diff --git a/xsync_v2.cpp b/xsync_v2.cpp new file mode 100644 index 0000000..e69de29 diff --git a/xsync_v2.hpp b/xsync_v2.hpp new file mode 100644 index 0000000..9ce993e --- /dev/null +++ b/xsync_v2.hpp @@ -0,0 +1,576 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// +#include "i_xsync_udp.hpp" +#include "xsync_errcode.hpp" +#include "xsync_packet.hpp" +#include "xsync_regs.hpp" +#include "xsync_v2_sig_type.hpp" +namespace xsync { +using namespace std; + +/** + * @brief 接口列表 + * + * 设备基本操作: + * Basic_xxxxx + * + * 输入模块: + * 时码输入模块: + * TimecodeInputModule_XXXXX + * + * + * TTL输入模块: + * TTLInputModule_XXXXX + * + * Genlock输入模块: + * GenlockInputModule_XXXXX + * + * 信号发生器模块: + * 内部信号时码信号发生器 + * InternalTimecode_xxxx + * 内部信号Genlock信号发生器 + * ISG_Genlock_xxxx + * + */ + +typedef function xsync_on_timecode_msg_t; +typedef function xsync_on_record_sig_change_msg_t; +typedef function xsync_on_camera_sync_msg_t; + +class Xsync { + public: + private: + /* data */ + + I_XSUDPFactory *m_xsync_udp_factory = nullptr; + shared_ptr m_xsync_reg_udp = nullptr; + shared_ptr m_xsync_timecode_udp_listener = nullptr; + shared_ptr 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; + xsync_on_record_sig_change_msg_t m_on_record_sig_change_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); + void Basic_registerOnRecordSigChangeMsg(xsync_on_record_sig_change_msg_t on_record_sig_change_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 ®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(); + + /*********************************************************************************************** + * 输入组件 * + ***********************************************************************************************/ + + /******************************************************************************* + * 时码输入 * + *******************************************************************************/ + + /** + * @brief 选择时码输入源 + * + * @param src + * INPUT_IF_TIMECODE_BNC + * INPUT_IF_TIMECODE_HEADPHONE + * + * @return xs_error_code_t + */ + xs_error_code_t TimecodeInputModule_setSrcSelect(InputInterface_t src); + xs_error_code_t TimecodeInputModule_getSrcSelect(InputInterface_t &timecode_select); + + /** + * @brief 设置时码格式 + * + * @param format + * @return xs_error_code_t + */ + xs_error_code_t TimecodeInputModule_setTimecodeFormat(TimecodeFormat_t format); + xs_error_code_t TimecodeInputModule_getTimecodeFormat(TimecodeFormat_t &format); + + /******************************************************************************* + * TTL输入模块 * + *******************************************************************************/ + + /** + * @brief 读取TTL输入模块的频率 + * + * @param index + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t TTLInputModule1_detectFreq(uint32_t &freq); + xs_error_code_t TTLInputModule2_detectFreq(uint32_t &freq); + xs_error_code_t TTLInputModule3_detectFreq(uint32_t &freq); + xs_error_code_t TTLInputModule4_detectFreq(uint32_t &freq); + + /******************************************************************************* + * GENLOCK输入配置 * + *******************************************************************************/ + + /** + * @brief 读取Genlock输入模块的频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t GenlockInputModule_detectFreq(uint32_t &freq); + + /*********************************************************************************************** + * 内部信号发生器 * + ***********************************************************************************************/ + + /******************************************************************************* + * 内部时码发生器 * + *******************************************************************************/ + /** + * @brief 内部Timecode信号发生器,设置启停控制方式 + * + * @param mode + * 支持列表: + * CONTROLMODE_ALWAYS_START + * @return xs_error_code_t + */ + xs_error_code_t InternalTimecode_setContrlMode(ControlMode_t mode); + xs_error_code_t InternalTimecode_getContrlMode(ControlMode_t &mode); + /** + * @brief 内部Timecode信号发生器,设置Timecode格式 + * + * @param format + * 支持列表 + * TIMECODE_FPS2398 + * TIMECODE_FPS2400 + * TIMECODE_FPS2500 + * TIMECODE_FPS2997 + * TIMECODE_FPS2997Drop + * TIMECODE_FPS3000 + * + * @return xs_error_code_t + */ + xs_error_code_t InternalTimecode_setTimecodeFormat(TimecodeFormat_t format); + xs_error_code_t InternalTimecode_getTimecodeFormat(TimecodeFormat_t &format); + + /** + * @brief 内部Timecode信号发生器,设置Timecode值 + * + * @param timecode + * @return xs_error_code_t + */ + xs_error_code_t InternalTimecode_setTimecodeValue(XsyncTimecode_t timecode); + xs_error_code_t InternalTimecode_getTimecodeValue(XsyncTimecode_t &timecode); + + /******************************************************************************* + * 内部Genlock信号发生器 * + *******************************************************************************/ + + /** + * @brief 内部Genlock信号发生器,设置启停控制方式 + * + * @param mode + * 支持列表: + * CONTROLMODE_ALWAYS_START + * @return xs_error_code_t + */ + xs_error_code_t InternalGenlock_setContrlMode(ControlMode_t mode); + xs_error_code_t InternalGenlock_getContrlMode(ControlMode_t &mode); + + /** + * @brief 内部Genlock信号发生器,设置格式 + * + * @param format + * 支持列表: + * GENLOCK_FPS2397 + * GENLOCK_FPS2398 + * GENLOCK_FPS2400 + * GENLOCK_FPS2500 + * GENLOCK_FPS2997 + * GENLOCK_FPS3000 + * GENLOCK_FPS5000 + * GENLOCK_FPS5994 + * GENLOCK_FPS6000 + * @return xs_error_code_t + */ + xs_error_code_t InternalGenlock_setFormat(GenlockFormat_t format); + xs_error_code_t InternalGenlock_getFormat(GenlockFormat_t &format); + + /******************************************************************************* + * 内部频率发生器 * + *******************************************************************************/ + + /** + * @brief 设置内部频率发生器的启停控制方式 + * + * @param mode + * 支持列表: + * CONTROLMODE_ALWAYS_START + * @return xs_error_code_t + */ + xs_error_code_t InternalClockGenerator_setContrlMode(ControlMode_t mode); + xs_error_code_t InternalClockGenerator_getContrlMode(ControlMode_t &mode); + + xs_error_code_t InternalClockGenerator_setFreq(uint32_t freq); + xs_error_code_t InternalClockGenerator_getFreq(uint32_t &freq); + + /******************************************************************************* + * 系统时钟 * + *******************************************************************************/ + + /** + * @brief 系统时钟选择时钟源 + * + * @param mode + * 支持列表: + * SIGNAL_TTLIN1 + * SIGNAL_TTLIN1 + * SIGNAL_TTLIN2 + * SIGNAL_TTLIN3 + * SIGNAL_TTLIN4 + * SIGNAL_INTERNAL_FREQ_SIG + * SIGNAL_SYS_GENLOCK_OUTPUT + * + * @return xs_error_code_t + */ + xs_error_code_t SysClock_setSrc(SignalType_t sig); + xs_error_code_t SysClock_getSrc(SignalType_t &sig); + + /** + * @brief 设置触发边沿 + * + * @param edge + * TRIGGER_EDGE_RISING + * TRIGGER_EDGE_FALLING + * @return xs_error_code_t + */ + xs_error_code_t SysClock_setTriggerEdge(TriggerEdge_t edge); + xs_error_code_t SysClock_getTriggerEdge(TriggerEdge_t &edge); + + /** + * @brief 设置主时钟分频系数 + * + * @param div + * @return xs_error_code_t + */ + xs_error_code_t SysClock_setFreqDivision(uint32_t div); + xs_error_code_t SysClock_geFreqtDivision(uint32_t &div); + + /** + * @brief 设置主时钟倍频系数 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysClock_setFreqMultiplication(uint32_t freq); + xs_error_code_t SysClock_getFreqMultiplication(uint32_t &freq); + + /** + * @brief 读取主时钟频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysClock_readFreq(uint32_t &freq); + /** + * @brief 读取系统时钟输入频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysClock_readInputFreq(uint32_t &freq); + + /******************************************************************************* + * 系统Genlock * + *******************************************************************************/ + + /** + * @brief 系统Genlock选择时钟源 + * + * @param sig + * 支持列表: + * SIGNAL_EXT_GENLOCK_FREQ + * SIGNAL_INTERNAL_GENLOCK_FREQ + * + * @return xs_error_code_t + */ + xs_error_code_t SysGenlock_setSrc(SignalType_t sig); + xs_error_code_t SysGenlock_getSrc(SignalType_t &sig); + + /** + * @brief 读取系统Genlock频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysGenlock_readFreq(uint32_t &freq); + + /******************************************************************************* + * 系统Timecode * + *******************************************************************************/ + + /** + * @brief 系统Timecode选择时钟源 + * + * @param internal + * 0: 内部Timecode + * 1: 外部Timecode + * @return xs_error_code_t + */ + xs_error_code_t SysTimecode_setSrc(int32_t sig); + xs_error_code_t SysTimecode_getSrc(int32_t &sig); + + /** + * @brief 读取系统Timecode频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysTimecode_readFreq(uint32_t &freq); + /** + * @brief 读取系统Timecode格式 + * + * @param format + * @return xs_error_code_t + */ + xs_error_code_t SysTimecode_readFormat(TimecodeFormat_t &format); + /** + * @brief 读取系统Timecode值 + * + * @param timecode + * @return xs_error_code_t + */ + xs_error_code_t SysTimecode_readTimecode(XsyncTimecode_t &timecode); + + /************************************************************************************************* + * 业务信号发生器 * + *************************************************************************************************/ + /******************************************************************************* + * 录制信号发生器 * + *******************************************************************************/ + + /** + * 录制信号发生器指标 + * + * 频率源 :使用系统时钟 + * timecode控制源:使用系统timecode + * 支持配置项: + * 1.启动模式 + * + * 输出信号: + * SIGNAL_BUSINESS_RECORD_SIG + * SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG + */ + + /** + * @brief 业务信号发生器,设置启停控制方式 + * + * @param mode + * 支持列表: + * CONTROLMODE_MANUAL_TRIGGER + * CONTROLMODE_TIMECODE_TRIGGER + * CONTROLMODE_EXTERNALTTL_TRIGGER + * @return xs_error_code_t + */ + xs_error_code_t RecordSigGenerator_setContrlMode(ControlMode_t mode); + xs_error_code_t RecordSigGenerator_getContrlMode(ControlMode_t &mode); + + // 手动控制 + xs_error_code_t RecordSigGenerator_manualStart(); + xs_error_code_t RecordSigGenerator_manualStop(); + + // timecode控制启停 + xs_error_code_t RecordSigGenerator_setAutoStartTimecode(XsyncTimecode_t timecode); + xs_error_code_t RecordSigGenerator_setAutoStopTimecode(XsyncTimecode_t timecode); + + xs_error_code_t RecordSigGenerator_getAutoStartTimecode(XsyncTimecode_t &timecode); + xs_error_code_t RecordSigGenerator_getAutoStopTimecode(XsyncTimecode_t &timecode); + + // 外部TTL触发控制 + /** + * @brief + * + * @param ttlPortNum + * INPUT_IF_TTL1 + * INPUT_IF_TTL2 + * INPUT_IF_TTL3 + * INPUT_IF_TTL4 + * @return xs_error_code_t + */ + xs_error_code_t RecordSigGenerator_setExternalTTLTriggerSrc(InputInterface_t ttlPortNum); // 1-4 + xs_error_code_t RecordSigGenerator_getExternalTTLTriggerSrc(InputInterface_t &ttlPortNum); + + xs_error_code_t RecordSigGenerator_setExternalTTLTriggerPolarity(TriggerPolarity_t polarity); + xs_error_code_t RecordSigGenerator_getExternalTTLTriggerPolarity(TriggerPolarity_t &polarity); + + /** + * @brief 设置录制曝光信号的曝光时间 + * + * @param us + * @return xs_error_code_t + */ + xs_error_code_t RecordSigGenerator_setRecordExposureTime(uint32_t us); + /** + * @brief 设置录制曝光信号的偏移 + * + * @param us + * @return xs_error_code_t + */ + xs_error_code_t RecordSigGenerator_setRecordExposureOffsetTime(uint32_t us); + + /************************************************************************************************* + * 输出口配置 * + *************************************************************************************************/ + + /** + * @brief TTLOutputModuleX_setSrcSigType TTL输出口设置信号源 + * + * @param source + * 支持列表: + * SIGNAL_TTLIN1 + * SIGNAL_TTLIN2 + * SIGNAL_TTLIN3 + * SIGNAL_TTLIN4 + * SIGNAL_SYS_CLK_OUTPUT + * SIGNAL_SYS_GENLOCK_OUTPUT + * SIGNAL_SYS_TIMECODE_FREQ_OUTPUT + * SIGNAL_BUSINESS_RECORD_SIG + * SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG + * + * @return xs_error_code_t + */ + xs_error_code_t TTLOutputModule1_setSrcSigType(SignalType_t source); + xs_error_code_t TTLOutputModule2_setSrcSigType(SignalType_t source); + xs_error_code_t TTLOutputModule3_setSrcSigType(SignalType_t source); + xs_error_code_t TTLOutputModule4_setSrcSigType(SignalType_t source); + + xs_error_code_t TTLOutputModule1_getSrcSigType(SignalType_t &source); + xs_error_code_t TTLOutputModule2_getSrcSigType(SignalType_t &source); + xs_error_code_t TTLOutputModule3_getSrcSigType(SignalType_t &source); + xs_error_code_t TTLOutputModule4_getSrcSigType(SignalType_t &source); + + // 分频配置 + xs_error_code_t TTLOutputModule1_setFreqDivision(uint32_t div); + xs_error_code_t TTLOutputModule2_setFreqDivision(uint32_t div); + xs_error_code_t TTLOutputModule3_setFreqDivision(uint32_t div); + xs_error_code_t TTLOutputModule4_setFreqDivision(uint32_t div); + + xs_error_code_t TTLOutputModule1_getFreqDivision(uint32_t &div); + xs_error_code_t TTLOutputModule2_getFreqDivision(uint32_t &div); + xs_error_code_t TTLOutputModule3_getFreqDivision(uint32_t &div); + xs_error_code_t TTLOutputModule4_getFreqDivision(uint32_t &div); + + // 倍频配置 + xs_error_code_t TTLOutputModule1_setFreqMultiplication(uint32_t freq); + xs_error_code_t TTLOutputModule2_setFreqMultiplication(uint32_t freq); + xs_error_code_t TTLOutputModule3_setFreqMultiplication(uint32_t freq); + xs_error_code_t TTLOutputModule4_setFreqMultiplication(uint32_t freq); + + xs_error_code_t TTLOutputModule1_getFreqMultiplication(uint32_t &freq); + xs_error_code_t TTLOutputModule2_getFreqMultiplication(uint32_t &freq); + xs_error_code_t TTLOutputModule3_getFreqMultiplication(uint32_t &freq); + xs_error_code_t TTLOutputModule4_getFreqMultiplication(uint32_t &freq); + + /******************************************************************************* + * Timecode输出口配置 * + *******************************************************************************/ + + /** + * @brief TIMECODE输出模块 + * + * 信号源: SYS_TIMECODE + */ + + /** + * @brief 设置时码输出模块的BNC输出电平 + * + * @param level + * @return xs_error_code_t + */ + xs_error_code_t TimecodeOutputModule_setBncOutputLevel(int level); // 0:line,1:mic + xs_error_code_t TimecodeOutputModule_getBncOutputLevel(int &level); + /** + * @brief 设置时码输出模块的耳机输出电平 + * + * @param level + * @return xs_error_code_t + */ + xs_error_code_t TimecodeOutputModule_setHeadphoneOutputLevel(int level); // 0:line,1:mic + xs_error_code_t TimecodeOutputModule_getHeadphoneOutputLevel(int &level); + + /******************************************************************************* + * 相机同步信号上报控制模块 * + *******************************************************************************/ + + /** + * @brief + * 相机同步信号输出模块 + * + * 信号源 : 系统时钟 SYS_CLK + * 归零触发信号 : 录制信号上升沿 + * 使能信号 : 录制信号 + */ + + + /** + * @brief 获取当前相机同步信号上报的包序号 + * + * @param index + * @return xs_error_code_t + */ + xs_error_code_t CameraSyncPacketGeneratorModule_getPacketIndex(uint32_t &index); + private: +}; + +} // namespace xsync diff --git a/xsync_v2_sdk/xsync_v2.hpp b/xsync_v2_sdk/xsync_v2.hpp new file mode 100644 index 0000000..9ce993e --- /dev/null +++ b/xsync_v2_sdk/xsync_v2.hpp @@ -0,0 +1,576 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// +#include "i_xsync_udp.hpp" +#include "xsync_errcode.hpp" +#include "xsync_packet.hpp" +#include "xsync_regs.hpp" +#include "xsync_v2_sig_type.hpp" +namespace xsync { +using namespace std; + +/** + * @brief 接口列表 + * + * 设备基本操作: + * Basic_xxxxx + * + * 输入模块: + * 时码输入模块: + * TimecodeInputModule_XXXXX + * + * + * TTL输入模块: + * TTLInputModule_XXXXX + * + * Genlock输入模块: + * GenlockInputModule_XXXXX + * + * 信号发生器模块: + * 内部信号时码信号发生器 + * InternalTimecode_xxxx + * 内部信号Genlock信号发生器 + * ISG_Genlock_xxxx + * + */ + +typedef function xsync_on_timecode_msg_t; +typedef function xsync_on_record_sig_change_msg_t; +typedef function xsync_on_camera_sync_msg_t; + +class Xsync { + public: + private: + /* data */ + + I_XSUDPFactory *m_xsync_udp_factory = nullptr; + shared_ptr m_xsync_reg_udp = nullptr; + shared_ptr m_xsync_timecode_udp_listener = nullptr; + shared_ptr 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; + xsync_on_record_sig_change_msg_t m_on_record_sig_change_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); + void Basic_registerOnRecordSigChangeMsg(xsync_on_record_sig_change_msg_t on_record_sig_change_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 ®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(); + + /*********************************************************************************************** + * 输入组件 * + ***********************************************************************************************/ + + /******************************************************************************* + * 时码输入 * + *******************************************************************************/ + + /** + * @brief 选择时码输入源 + * + * @param src + * INPUT_IF_TIMECODE_BNC + * INPUT_IF_TIMECODE_HEADPHONE + * + * @return xs_error_code_t + */ + xs_error_code_t TimecodeInputModule_setSrcSelect(InputInterface_t src); + xs_error_code_t TimecodeInputModule_getSrcSelect(InputInterface_t &timecode_select); + + /** + * @brief 设置时码格式 + * + * @param format + * @return xs_error_code_t + */ + xs_error_code_t TimecodeInputModule_setTimecodeFormat(TimecodeFormat_t format); + xs_error_code_t TimecodeInputModule_getTimecodeFormat(TimecodeFormat_t &format); + + /******************************************************************************* + * TTL输入模块 * + *******************************************************************************/ + + /** + * @brief 读取TTL输入模块的频率 + * + * @param index + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t TTLInputModule1_detectFreq(uint32_t &freq); + xs_error_code_t TTLInputModule2_detectFreq(uint32_t &freq); + xs_error_code_t TTLInputModule3_detectFreq(uint32_t &freq); + xs_error_code_t TTLInputModule4_detectFreq(uint32_t &freq); + + /******************************************************************************* + * GENLOCK输入配置 * + *******************************************************************************/ + + /** + * @brief 读取Genlock输入模块的频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t GenlockInputModule_detectFreq(uint32_t &freq); + + /*********************************************************************************************** + * 内部信号发生器 * + ***********************************************************************************************/ + + /******************************************************************************* + * 内部时码发生器 * + *******************************************************************************/ + /** + * @brief 内部Timecode信号发生器,设置启停控制方式 + * + * @param mode + * 支持列表: + * CONTROLMODE_ALWAYS_START + * @return xs_error_code_t + */ + xs_error_code_t InternalTimecode_setContrlMode(ControlMode_t mode); + xs_error_code_t InternalTimecode_getContrlMode(ControlMode_t &mode); + /** + * @brief 内部Timecode信号发生器,设置Timecode格式 + * + * @param format + * 支持列表 + * TIMECODE_FPS2398 + * TIMECODE_FPS2400 + * TIMECODE_FPS2500 + * TIMECODE_FPS2997 + * TIMECODE_FPS2997Drop + * TIMECODE_FPS3000 + * + * @return xs_error_code_t + */ + xs_error_code_t InternalTimecode_setTimecodeFormat(TimecodeFormat_t format); + xs_error_code_t InternalTimecode_getTimecodeFormat(TimecodeFormat_t &format); + + /** + * @brief 内部Timecode信号发生器,设置Timecode值 + * + * @param timecode + * @return xs_error_code_t + */ + xs_error_code_t InternalTimecode_setTimecodeValue(XsyncTimecode_t timecode); + xs_error_code_t InternalTimecode_getTimecodeValue(XsyncTimecode_t &timecode); + + /******************************************************************************* + * 内部Genlock信号发生器 * + *******************************************************************************/ + + /** + * @brief 内部Genlock信号发生器,设置启停控制方式 + * + * @param mode + * 支持列表: + * CONTROLMODE_ALWAYS_START + * @return xs_error_code_t + */ + xs_error_code_t InternalGenlock_setContrlMode(ControlMode_t mode); + xs_error_code_t InternalGenlock_getContrlMode(ControlMode_t &mode); + + /** + * @brief 内部Genlock信号发生器,设置格式 + * + * @param format + * 支持列表: + * GENLOCK_FPS2397 + * GENLOCK_FPS2398 + * GENLOCK_FPS2400 + * GENLOCK_FPS2500 + * GENLOCK_FPS2997 + * GENLOCK_FPS3000 + * GENLOCK_FPS5000 + * GENLOCK_FPS5994 + * GENLOCK_FPS6000 + * @return xs_error_code_t + */ + xs_error_code_t InternalGenlock_setFormat(GenlockFormat_t format); + xs_error_code_t InternalGenlock_getFormat(GenlockFormat_t &format); + + /******************************************************************************* + * 内部频率发生器 * + *******************************************************************************/ + + /** + * @brief 设置内部频率发生器的启停控制方式 + * + * @param mode + * 支持列表: + * CONTROLMODE_ALWAYS_START + * @return xs_error_code_t + */ + xs_error_code_t InternalClockGenerator_setContrlMode(ControlMode_t mode); + xs_error_code_t InternalClockGenerator_getContrlMode(ControlMode_t &mode); + + xs_error_code_t InternalClockGenerator_setFreq(uint32_t freq); + xs_error_code_t InternalClockGenerator_getFreq(uint32_t &freq); + + /******************************************************************************* + * 系统时钟 * + *******************************************************************************/ + + /** + * @brief 系统时钟选择时钟源 + * + * @param mode + * 支持列表: + * SIGNAL_TTLIN1 + * SIGNAL_TTLIN1 + * SIGNAL_TTLIN2 + * SIGNAL_TTLIN3 + * SIGNAL_TTLIN4 + * SIGNAL_INTERNAL_FREQ_SIG + * SIGNAL_SYS_GENLOCK_OUTPUT + * + * @return xs_error_code_t + */ + xs_error_code_t SysClock_setSrc(SignalType_t sig); + xs_error_code_t SysClock_getSrc(SignalType_t &sig); + + /** + * @brief 设置触发边沿 + * + * @param edge + * TRIGGER_EDGE_RISING + * TRIGGER_EDGE_FALLING + * @return xs_error_code_t + */ + xs_error_code_t SysClock_setTriggerEdge(TriggerEdge_t edge); + xs_error_code_t SysClock_getTriggerEdge(TriggerEdge_t &edge); + + /** + * @brief 设置主时钟分频系数 + * + * @param div + * @return xs_error_code_t + */ + xs_error_code_t SysClock_setFreqDivision(uint32_t div); + xs_error_code_t SysClock_geFreqtDivision(uint32_t &div); + + /** + * @brief 设置主时钟倍频系数 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysClock_setFreqMultiplication(uint32_t freq); + xs_error_code_t SysClock_getFreqMultiplication(uint32_t &freq); + + /** + * @brief 读取主时钟频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysClock_readFreq(uint32_t &freq); + /** + * @brief 读取系统时钟输入频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysClock_readInputFreq(uint32_t &freq); + + /******************************************************************************* + * 系统Genlock * + *******************************************************************************/ + + /** + * @brief 系统Genlock选择时钟源 + * + * @param sig + * 支持列表: + * SIGNAL_EXT_GENLOCK_FREQ + * SIGNAL_INTERNAL_GENLOCK_FREQ + * + * @return xs_error_code_t + */ + xs_error_code_t SysGenlock_setSrc(SignalType_t sig); + xs_error_code_t SysGenlock_getSrc(SignalType_t &sig); + + /** + * @brief 读取系统Genlock频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysGenlock_readFreq(uint32_t &freq); + + /******************************************************************************* + * 系统Timecode * + *******************************************************************************/ + + /** + * @brief 系统Timecode选择时钟源 + * + * @param internal + * 0: 内部Timecode + * 1: 外部Timecode + * @return xs_error_code_t + */ + xs_error_code_t SysTimecode_setSrc(int32_t sig); + xs_error_code_t SysTimecode_getSrc(int32_t &sig); + + /** + * @brief 读取系统Timecode频率 + * + * @param freq + * @return xs_error_code_t + */ + xs_error_code_t SysTimecode_readFreq(uint32_t &freq); + /** + * @brief 读取系统Timecode格式 + * + * @param format + * @return xs_error_code_t + */ + xs_error_code_t SysTimecode_readFormat(TimecodeFormat_t &format); + /** + * @brief 读取系统Timecode值 + * + * @param timecode + * @return xs_error_code_t + */ + xs_error_code_t SysTimecode_readTimecode(XsyncTimecode_t &timecode); + + /************************************************************************************************* + * 业务信号发生器 * + *************************************************************************************************/ + /******************************************************************************* + * 录制信号发生器 * + *******************************************************************************/ + + /** + * 录制信号发生器指标 + * + * 频率源 :使用系统时钟 + * timecode控制源:使用系统timecode + * 支持配置项: + * 1.启动模式 + * + * 输出信号: + * SIGNAL_BUSINESS_RECORD_SIG + * SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG + */ + + /** + * @brief 业务信号发生器,设置启停控制方式 + * + * @param mode + * 支持列表: + * CONTROLMODE_MANUAL_TRIGGER + * CONTROLMODE_TIMECODE_TRIGGER + * CONTROLMODE_EXTERNALTTL_TRIGGER + * @return xs_error_code_t + */ + xs_error_code_t RecordSigGenerator_setContrlMode(ControlMode_t mode); + xs_error_code_t RecordSigGenerator_getContrlMode(ControlMode_t &mode); + + // 手动控制 + xs_error_code_t RecordSigGenerator_manualStart(); + xs_error_code_t RecordSigGenerator_manualStop(); + + // timecode控制启停 + xs_error_code_t RecordSigGenerator_setAutoStartTimecode(XsyncTimecode_t timecode); + xs_error_code_t RecordSigGenerator_setAutoStopTimecode(XsyncTimecode_t timecode); + + xs_error_code_t RecordSigGenerator_getAutoStartTimecode(XsyncTimecode_t &timecode); + xs_error_code_t RecordSigGenerator_getAutoStopTimecode(XsyncTimecode_t &timecode); + + // 外部TTL触发控制 + /** + * @brief + * + * @param ttlPortNum + * INPUT_IF_TTL1 + * INPUT_IF_TTL2 + * INPUT_IF_TTL3 + * INPUT_IF_TTL4 + * @return xs_error_code_t + */ + xs_error_code_t RecordSigGenerator_setExternalTTLTriggerSrc(InputInterface_t ttlPortNum); // 1-4 + xs_error_code_t RecordSigGenerator_getExternalTTLTriggerSrc(InputInterface_t &ttlPortNum); + + xs_error_code_t RecordSigGenerator_setExternalTTLTriggerPolarity(TriggerPolarity_t polarity); + xs_error_code_t RecordSigGenerator_getExternalTTLTriggerPolarity(TriggerPolarity_t &polarity); + + /** + * @brief 设置录制曝光信号的曝光时间 + * + * @param us + * @return xs_error_code_t + */ + xs_error_code_t RecordSigGenerator_setRecordExposureTime(uint32_t us); + /** + * @brief 设置录制曝光信号的偏移 + * + * @param us + * @return xs_error_code_t + */ + xs_error_code_t RecordSigGenerator_setRecordExposureOffsetTime(uint32_t us); + + /************************************************************************************************* + * 输出口配置 * + *************************************************************************************************/ + + /** + * @brief TTLOutputModuleX_setSrcSigType TTL输出口设置信号源 + * + * @param source + * 支持列表: + * SIGNAL_TTLIN1 + * SIGNAL_TTLIN2 + * SIGNAL_TTLIN3 + * SIGNAL_TTLIN4 + * SIGNAL_SYS_CLK_OUTPUT + * SIGNAL_SYS_GENLOCK_OUTPUT + * SIGNAL_SYS_TIMECODE_FREQ_OUTPUT + * SIGNAL_BUSINESS_RECORD_SIG + * SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG + * + * @return xs_error_code_t + */ + xs_error_code_t TTLOutputModule1_setSrcSigType(SignalType_t source); + xs_error_code_t TTLOutputModule2_setSrcSigType(SignalType_t source); + xs_error_code_t TTLOutputModule3_setSrcSigType(SignalType_t source); + xs_error_code_t TTLOutputModule4_setSrcSigType(SignalType_t source); + + xs_error_code_t TTLOutputModule1_getSrcSigType(SignalType_t &source); + xs_error_code_t TTLOutputModule2_getSrcSigType(SignalType_t &source); + xs_error_code_t TTLOutputModule3_getSrcSigType(SignalType_t &source); + xs_error_code_t TTLOutputModule4_getSrcSigType(SignalType_t &source); + + // 分频配置 + xs_error_code_t TTLOutputModule1_setFreqDivision(uint32_t div); + xs_error_code_t TTLOutputModule2_setFreqDivision(uint32_t div); + xs_error_code_t TTLOutputModule3_setFreqDivision(uint32_t div); + xs_error_code_t TTLOutputModule4_setFreqDivision(uint32_t div); + + xs_error_code_t TTLOutputModule1_getFreqDivision(uint32_t &div); + xs_error_code_t TTLOutputModule2_getFreqDivision(uint32_t &div); + xs_error_code_t TTLOutputModule3_getFreqDivision(uint32_t &div); + xs_error_code_t TTLOutputModule4_getFreqDivision(uint32_t &div); + + // 倍频配置 + xs_error_code_t TTLOutputModule1_setFreqMultiplication(uint32_t freq); + xs_error_code_t TTLOutputModule2_setFreqMultiplication(uint32_t freq); + xs_error_code_t TTLOutputModule3_setFreqMultiplication(uint32_t freq); + xs_error_code_t TTLOutputModule4_setFreqMultiplication(uint32_t freq); + + xs_error_code_t TTLOutputModule1_getFreqMultiplication(uint32_t &freq); + xs_error_code_t TTLOutputModule2_getFreqMultiplication(uint32_t &freq); + xs_error_code_t TTLOutputModule3_getFreqMultiplication(uint32_t &freq); + xs_error_code_t TTLOutputModule4_getFreqMultiplication(uint32_t &freq); + + /******************************************************************************* + * Timecode输出口配置 * + *******************************************************************************/ + + /** + * @brief TIMECODE输出模块 + * + * 信号源: SYS_TIMECODE + */ + + /** + * @brief 设置时码输出模块的BNC输出电平 + * + * @param level + * @return xs_error_code_t + */ + xs_error_code_t TimecodeOutputModule_setBncOutputLevel(int level); // 0:line,1:mic + xs_error_code_t TimecodeOutputModule_getBncOutputLevel(int &level); + /** + * @brief 设置时码输出模块的耳机输出电平 + * + * @param level + * @return xs_error_code_t + */ + xs_error_code_t TimecodeOutputModule_setHeadphoneOutputLevel(int level); // 0:line,1:mic + xs_error_code_t TimecodeOutputModule_getHeadphoneOutputLevel(int &level); + + /******************************************************************************* + * 相机同步信号上报控制模块 * + *******************************************************************************/ + + /** + * @brief + * 相机同步信号输出模块 + * + * 信号源 : 系统时钟 SYS_CLK + * 归零触发信号 : 录制信号上升沿 + * 使能信号 : 录制信号 + */ + + + /** + * @brief 获取当前相机同步信号上报的包序号 + * + * @param index + * @return xs_error_code_t + */ + xs_error_code_t CameraSyncPacketGeneratorModule_getPacketIndex(uint32_t &index); + private: +}; + +} // namespace xsync diff --git a/xsync_v2_sdk/xsync_v2_sig_type.hpp b/xsync_v2_sdk/xsync_v2_sig_type.hpp new file mode 100644 index 0000000..01c313d --- /dev/null +++ b/xsync_v2_sdk/xsync_v2_sig_type.hpp @@ -0,0 +1,189 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// +#include "i_xsync_udp.hpp" +#include "xsync_errcode.hpp" +#include "xsync_packet.hpp" +#include "xsync_regs.hpp" +namespace xsync { +using namespace std; +/******************************************************************************* + * XSYNC_STATE * + *******************************************************************************/ + +typedef enum { + kxsync_net_state_disconnect, + kxsync_net_state_connecting, + kxsync_net_state_connected, +} xsync_net_state_t; + +/******************************************************************************* + * TIMECODE * + *******************************************************************************/ +typedef struct { + uint32_t tc0; + uint32_t tc1; +} Timecode64_t; + +typedef enum { + TIMECODE_FPS2398 = 0, + TIMECODE_FPS2400 = 1, + TIMECODE_FPS2500 = 2, + TIMECODE_FPS2997 = 3, + TIMECODE_FPS2997Drop = 4, + TIMECODE_FPS3000 = 5, +} TimecodeFormat_t; + +string TimecodeFormatToStr(TimecodeFormat_t fomrat); +TimecodeFormat_t Str2TimecodeFormat(string format); +list 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); + +/******************************************************************************* + * GENLOCK * + *******************************************************************************/ +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); +GenlockFormat_t Str2GenlockFormat(string format); +list GenlockFormatStrSet(); + +/******************************************************************************* + * camera_sync_data * + *******************************************************************************/ + +typedef struct { + uint32_t frameIndex; +} xysnc_camera_sync_data_t; + +/******************************************************************************* + * 信号类别 * + *******************************************************************************/ + +typedef enum { + + /******************************************************************************* + * 物理接口信号 * + *******************************************************************************/ + + SIGNAL_TTLIN1, // ttl1输入模块输出信号 + SIGNAL_TTLIN2, // ttl2输入模块输出信号 + SIGNAL_TTLIN3, // ttl3输入模块输出信号 + SIGNAL_TTLIN4, // isolate 输入模块输出输出信号 + + SIGNAL_EXT_GENLOCK_FREQ, // 外部genlock频率信号 + SIGNAL_EXT_TIMECODE_FREQ, // 外部timecode频率信号 + + /******************************************************************************* + * 内部频率信号发生器 * + *******************************************************************************/ + + SIGNAL_INTERNAL_TIMECODE_FREQ, // 内部timecode频率信号 + SIGNAL_INTERNAL_GENLOCK_FREQ, // 内部genlock频率信号 + SIGNAL_INTERNAL_FREQ_SIG, // 内部信号发生器内部频率信号 + + /******************************************************************************* + * SYS时钟 * + *******************************************************************************/ + + SIGNAL_SYS_CLK_OUTPUT, // 系统时钟输出,系统时钟可能来源,内部频率信号发生器,外部genlock,外部timecode,外部ttl + SIGNAL_SYS_GENLOCK_OUTPUT, // 系统genlock输出,系统genlock可能来源,内部genlock 外部genlock + SIGNAL_SYS_TIMECODE_FREQ_OUTPUT, // 系统timecode输出,系统timecode可能来源,内部timecode 外部timecode + + /******************************************************************************* + * 业务信号发生器 * + *******************************************************************************/ + SIGNAL_BUSINESS_RECORD_SIG, // 录像机触发信号 + SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG, // 曝光触发信号 + +} SignalType_t; + +string SignalType2Str(SignalType_t type); +SignalType_t Str2SignalType(string type); +list SignalTypeStrSet(); + +/******************************************************************************* + * 控制模式 * + *******************************************************************************/ + +typedef enum { + CONTROLMODE_ALWAYS_START, // 总是启动 + CONTROLMODE_MANUAL_TRIGGER, // 手动,启动停止 + CONTROLMODE_TIMECODE_TRIGGER, // TIMECODE触发启动,手动控制停止 + CONTROLMODE_EXTERNALTTL_TRIGGER, // 外部TTL输入触发,高电平开始,低电平停止 +} ControlMode_t; + +string ControlMode2Str(ControlMode_t mode); +ControlMode_t Str2ControlMode(string mode); +list ControlModeStrSet(); + +/******************************************************************************* + * 输入接口列表 * + *******************************************************************************/ + +typedef enum { + INPUT_IF_TTL1, + INPUT_IF_TTL2, + INPUT_IF_TTL3, + INPUT_IF_TTL4, + INPUT_IF_GENLOCK, + INPUT_IF_TIMECODE_BNC, + INPUT_IF_TIMECODE_HEADPHONE, +} InputInterface_t; + +string InputInterface2Str(InputInterface_t input); +InputInterface_t Str2InputInterface(string input); +list InputInterfaceStrSet(); + +/******************************************************************************* + * 触发边沿 * + *******************************************************************************/ + +typedef enum { + TRIGGER_EDGE_RISING, // 上升沿触发 + TRIGGER_EDGE_FALLING, // 下降沿触发 + TRIGGER_EDGE_BOTH, // 上升沿和下降沿触发 +} TriggerEdge_t; + +TriggerEdge_t Str2TriggerEdge(string edge); +string TriggerEdge2Str(TriggerEdge_t edge); +list TriggerEdgeStrSet(); + +// TriggerPolarity_t + +typedef enum { + kTriggerPolarityPositive, // 高电平触发 + kTriggerPolarityNegative, // 低电平触发 +} TriggerPolarity_t; + +} // namespace xsync diff --git a/xsync_v2_sig_type.cpp b/xsync_v2_sig_type.cpp new file mode 100644 index 0000000..89a03fb --- /dev/null +++ b/xsync_v2_sig_type.cpp @@ -0,0 +1,210 @@ +#include "xsync_v2_sig_type.hpp" + +#include + +using namespace xsync; +/******************************************************************************* + * TIMECODE * + *******************************************************************************/ +static map TimecodeFormatMap = { + {"TIMECODE_FPS2398", TIMECODE_FPS2398}, // + {"TIMECODE_FPS2400", TIMECODE_FPS2400}, // + {"TIMECODE_FPS2500", TIMECODE_FPS2500}, // + {"TIMECODE_FPS2997", TIMECODE_FPS2997}, // + {"TIMECODE_FPS2997Drop", TIMECODE_FPS2997Drop}, // + {"TIMECODE_FPS3000", TIMECODE_FPS3000}, // +}; + +string TimecodeFormatToStr(TimecodeFormat_t type) { + for (auto &item : TimecodeFormatMap) { + if (item.second == type) return item.first; + } + return "unkown"; +} +TimecodeFormat_t Str2TimecodeFormat(string val) { + if (TimecodeFormatMap.find(val) != TimecodeFormatMap.end()) { + return TimecodeFormatMap[val]; + } + return TIMECODE_FPS2997; +} +list TimecodeFormatStrSet() { + list ret; + for (auto &item : TimecodeFormatMap) { + ret.push_back(item.first); + } + return ret; +} + +string XsyncTimecodeToStr(XsyncTimecode_t timecode) { + char buf[32] = {0}; + sprintf(buf, "%02d:%02d:%02d:%02d", timecode.hour, timecode.minute, timecode.second, timecode.frame); + return string(buf); +} +XsyncTimecode_t Str2XsyncTimecode(string timecode) { + XsyncTimecode_t ret; + char buf[128] = {0}; + strncpy(buf, timecode.c_str(), 127); + sscanf(buf, "%02d:%02d:%02d:%02d", &ret.hour, &ret.minute, &ret.second, &ret.frame); + return ret; +} + +/******************************************************************************* + * GENLOCK * + *******************************************************************************/ + +static map GenlockFormatMap = { + {"GENLOCK_FPS2397", GENLOCK_FPS2397}, // + {"GENLOCK_FPS2398", GENLOCK_FPS2398}, // + {"GENLOCK_FPS2400", GENLOCK_FPS2400}, // + {"GENLOCK_FPS2500", GENLOCK_FPS2500}, // + {"GENLOCK_FPS2997", GENLOCK_FPS2997}, // + {"GENLOCK_FPS3000", GENLOCK_FPS3000}, // + {"GENLOCK_FPS5000", GENLOCK_FPS5000}, // + {"GENLOCK_FPS5994", GENLOCK_FPS5994}, // + {"GENLOCK_FPS6000", GENLOCK_FPS6000}, // +}; + +string GenlockFormatToStr(GenlockFormat_t fomrat) { + for (auto &item : GenlockFormatMap) { + if (item.second == fomrat) return item.first; + } + return "unkown"; +} +GenlockFormat_t Str2GenlockFormat(string format) { + if (GenlockFormatMap.find(format) != GenlockFormatMap.end()) { + return GenlockFormatMap[format]; + } + return GENLOCK_FPS2997; +} +list GenlockFormatStrSet() { + list ret; + for (auto &item : GenlockFormatMap) { + ret.push_back(item.first); + } + return ret; +} +/******************************************************************************* + * Signal_Type * + *******************************************************************************/ + +static map SignalTypeMap = { + {"SIGNAL_TTLIN1", SIGNAL_TTLIN1}, + {"SIGNAL_TTLIN2", SIGNAL_TTLIN2}, + {"SIGNAL_TTLIN3", SIGNAL_TTLIN3}, + {"SIGNAL_TTLIN4", SIGNAL_TTLIN4}, + {"SIGNAL_EXT_GENLOCK_FREQ", SIGNAL_EXT_GENLOCK_FREQ}, + {"SIGNAL_EXT_TIMECODE_FREQ", SIGNAL_EXT_TIMECODE_FREQ}, + {"SIGNAL_INTERNAL_TIMECODE_FREQ", SIGNAL_INTERNAL_TIMECODE_FREQ}, + {"SIGNAL_INTERNAL_GENLOCK_FREQ", SIGNAL_INTERNAL_GENLOCK_FREQ}, + {"SIGNAL_INTERNAL_FREQ_SIG", SIGNAL_INTERNAL_FREQ_SIG}, + {"SIGNAL_SYS_CLK_OUTPUT", SIGNAL_SYS_CLK_OUTPUT}, + {"SIGNAL_SYS_GENLOCK_OUTPUT", SIGNAL_SYS_GENLOCK_OUTPUT}, + {"SIGNAL_SYS_TIMECODE_FREQ_OUTPUT", SIGNAL_SYS_TIMECODE_FREQ_OUTPUT}, +}; + +string SignalType2Str(SignalType_t type) { + for (auto &item : SignalTypeMap) { + if (item.second == type) return item.first; + } + return "unkown"; +} +SignalType_t Str2SignalType(string type) { + if (SignalTypeMap.find(type) != SignalTypeMap.end()) { + return SignalTypeMap[type]; + } + return SIGNAL_TTLIN1; +} +list SignalTypeStrSet() { + list ret; + for (auto &item : SignalTypeMap) { + ret.push_back(item.first); + } + return ret; +} + +/******************************************************************************* + * 控制模式 * + *******************************************************************************/ +static map ControlModeMap = { + {"CONTROLMODE_ALWAYS_START", CONTROLMODE_ALWAYS_START}, // + {"CONTROLMODE_MANUAL_TRIGGER", CONTROLMODE_MANUAL_TRIGGER}, // + {"CONTROLMODE_TIMECODE_TRIGGER", CONTROLMODE_TIMECODE_TRIGGER}, // + {"CONTROLMODE_EXTERNALTTL_TRIGGER", CONTROLMODE_EXTERNALTTL_TRIGGER}, // +}; + +string ControlMode2Str(ControlMode_t mode) { + for (auto &item : ControlModeMap) { + if (item.second == mode) return item.first; + } + return "unkown"; +} +ControlMode_t Str2ControlMode(string mode) { + if (ControlModeMap.find(mode) != ControlModeMap.end()) { + return ControlModeMap[mode]; + } + return CONTROLMODE_MANUAL_TRIGGER; +} +list ControlModeStrSet() { + list ret; + for (auto &item : ControlModeMap) { + ret.push_back(item.first); + } + return ret; +} + +static map InputInterfaceMap = { + {"INPUT_IF_TTL1", INPUT_IF_TTL1}, // + {"INPUT_IF_TTL2", INPUT_IF_TTL2}, // + {"INPUT_IF_TTL3", INPUT_IF_TTL3}, // + {"INPUT_IF_TTL4", INPUT_IF_TTL4}, // + {"INPUT_IF_GENLOCK", INPUT_IF_GENLOCK}, // + {"INPUT_IF_TIMECODE_BNC", INPUT_IF_TIMECODE_BNC}, // + {"INPUT_IF_TIMECODE_HEADPHONE", INPUT_IF_TIMECODE_HEADPHONE}, // +}; + +string InputInterface2Str(InputInterface_t input) { + for (auto &item : InputInterfaceMap) { + if (item.second == input) return item.first; + } + return "unkown"; +} +InputInterface_t Str2InputInterface(string input) { + if (InputInterfaceMap.find(input) != InputInterfaceMap.end()) { + return InputInterfaceMap[input]; + } + return INPUT_IF_TTL1; +} +list InputInterfaceStrSet() { + list ret; + for (auto &item : InputInterfaceMap) { + ret.push_back(item.first); + } + return ret; +} + +static map TriggerEdgeMap = { + {"TRIGGER_EDGE_RISING", TRIGGER_EDGE_RISING}, // + {"TRIGGER_EDGE_FALLING", TRIGGER_EDGE_FALLING}, // + {"TRIGGER_EDGE_BOTH", TRIGGER_EDGE_BOTH}, // +}; + +TriggerEdge_t Str2TriggerEdge(string edge) { + if (TriggerEdgeMap.find(edge) != TriggerEdgeMap.end()) { + return TriggerEdgeMap[edge]; + } + return TRIGGER_EDGE_RISING; +} + +string TriggerEdge2Str(TriggerEdge_t edge) { + for (auto &item : TriggerEdgeMap) { + if (item.second == edge) return item.first; + } + return "unkown"; +} +list TriggerEdgeStrSet() { + list ret; + for (auto &item : TriggerEdgeMap) { + ret.push_back(item.first); + } + return ret; +} \ No newline at end of file diff --git a/xsync_v2_sig_type.hpp b/xsync_v2_sig_type.hpp new file mode 100644 index 0000000..01c313d --- /dev/null +++ b/xsync_v2_sig_type.hpp @@ -0,0 +1,189 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// +#include "i_xsync_udp.hpp" +#include "xsync_errcode.hpp" +#include "xsync_packet.hpp" +#include "xsync_regs.hpp" +namespace xsync { +using namespace std; +/******************************************************************************* + * XSYNC_STATE * + *******************************************************************************/ + +typedef enum { + kxsync_net_state_disconnect, + kxsync_net_state_connecting, + kxsync_net_state_connected, +} xsync_net_state_t; + +/******************************************************************************* + * TIMECODE * + *******************************************************************************/ +typedef struct { + uint32_t tc0; + uint32_t tc1; +} Timecode64_t; + +typedef enum { + TIMECODE_FPS2398 = 0, + TIMECODE_FPS2400 = 1, + TIMECODE_FPS2500 = 2, + TIMECODE_FPS2997 = 3, + TIMECODE_FPS2997Drop = 4, + TIMECODE_FPS3000 = 5, +} TimecodeFormat_t; + +string TimecodeFormatToStr(TimecodeFormat_t fomrat); +TimecodeFormat_t Str2TimecodeFormat(string format); +list 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); + +/******************************************************************************* + * GENLOCK * + *******************************************************************************/ +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); +GenlockFormat_t Str2GenlockFormat(string format); +list GenlockFormatStrSet(); + +/******************************************************************************* + * camera_sync_data * + *******************************************************************************/ + +typedef struct { + uint32_t frameIndex; +} xysnc_camera_sync_data_t; + +/******************************************************************************* + * 信号类别 * + *******************************************************************************/ + +typedef enum { + + /******************************************************************************* + * 物理接口信号 * + *******************************************************************************/ + + SIGNAL_TTLIN1, // ttl1输入模块输出信号 + SIGNAL_TTLIN2, // ttl2输入模块输出信号 + SIGNAL_TTLIN3, // ttl3输入模块输出信号 + SIGNAL_TTLIN4, // isolate 输入模块输出输出信号 + + SIGNAL_EXT_GENLOCK_FREQ, // 外部genlock频率信号 + SIGNAL_EXT_TIMECODE_FREQ, // 外部timecode频率信号 + + /******************************************************************************* + * 内部频率信号发生器 * + *******************************************************************************/ + + SIGNAL_INTERNAL_TIMECODE_FREQ, // 内部timecode频率信号 + SIGNAL_INTERNAL_GENLOCK_FREQ, // 内部genlock频率信号 + SIGNAL_INTERNAL_FREQ_SIG, // 内部信号发生器内部频率信号 + + /******************************************************************************* + * SYS时钟 * + *******************************************************************************/ + + SIGNAL_SYS_CLK_OUTPUT, // 系统时钟输出,系统时钟可能来源,内部频率信号发生器,外部genlock,外部timecode,外部ttl + SIGNAL_SYS_GENLOCK_OUTPUT, // 系统genlock输出,系统genlock可能来源,内部genlock 外部genlock + SIGNAL_SYS_TIMECODE_FREQ_OUTPUT, // 系统timecode输出,系统timecode可能来源,内部timecode 外部timecode + + /******************************************************************************* + * 业务信号发生器 * + *******************************************************************************/ + SIGNAL_BUSINESS_RECORD_SIG, // 录像机触发信号 + SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG, // 曝光触发信号 + +} SignalType_t; + +string SignalType2Str(SignalType_t type); +SignalType_t Str2SignalType(string type); +list SignalTypeStrSet(); + +/******************************************************************************* + * 控制模式 * + *******************************************************************************/ + +typedef enum { + CONTROLMODE_ALWAYS_START, // 总是启动 + CONTROLMODE_MANUAL_TRIGGER, // 手动,启动停止 + CONTROLMODE_TIMECODE_TRIGGER, // TIMECODE触发启动,手动控制停止 + CONTROLMODE_EXTERNALTTL_TRIGGER, // 外部TTL输入触发,高电平开始,低电平停止 +} ControlMode_t; + +string ControlMode2Str(ControlMode_t mode); +ControlMode_t Str2ControlMode(string mode); +list ControlModeStrSet(); + +/******************************************************************************* + * 输入接口列表 * + *******************************************************************************/ + +typedef enum { + INPUT_IF_TTL1, + INPUT_IF_TTL2, + INPUT_IF_TTL3, + INPUT_IF_TTL4, + INPUT_IF_GENLOCK, + INPUT_IF_TIMECODE_BNC, + INPUT_IF_TIMECODE_HEADPHONE, +} InputInterface_t; + +string InputInterface2Str(InputInterface_t input); +InputInterface_t Str2InputInterface(string input); +list InputInterfaceStrSet(); + +/******************************************************************************* + * 触发边沿 * + *******************************************************************************/ + +typedef enum { + TRIGGER_EDGE_RISING, // 上升沿触发 + TRIGGER_EDGE_FALLING, // 下降沿触发 + TRIGGER_EDGE_BOTH, // 上升沿和下降沿触发 +} TriggerEdge_t; + +TriggerEdge_t Str2TriggerEdge(string edge); +string TriggerEdge2Str(TriggerEdge_t edge); +list TriggerEdgeStrSet(); + +// TriggerPolarity_t + +typedef enum { + kTriggerPolarityPositive, // 高电平触发 + kTriggerPolarityNegative, // 低电平触发 +} TriggerPolarity_t; + +} // namespace xsync