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

#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"
#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<void(XsyncTimecode_t *timecode_msg)> xsync_on_timecode_msg_t;
typedef function<void(uint32_t recordSig, XsyncTimecode_t *timecode_msg)> xsync_on_record_sig_change_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;
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 &regbackvalue, int32_t overtime_ms = 100);
xs_error_code_t reg_read(uint32_t regadd, uint32_t &regvalue, int32_t overtime_ms = 100);
xs_error_code_t reg_read_muti(uint32_t regadd, uint32_t nreg, vector<uint32_t> &regvalues, 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信号发生器,设置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 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);
xs_error_code_t RecordSigGenerator_getRecordExposureTime(uint32_t &us);
/**
* @brief 设置录制曝光信号的偏移
*
* @param us
* @return xs_error_code_t
*/
xs_error_code_t RecordSigGenerator_setRecordExposureOffsetTime(uint32_t us);
xs_error_code_t RecordSigGenerator_getRecordExposureOffsetTime(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:
void parseTimecodeMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length);
void parseCameraSyncMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length);
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);
xs_error_code_t doaction(uint32_t action, uint32_t actionval, uint32_t *ackreturn, int32_t overtime_ms);
xs_error_code_t storageConfig();
};
} // namespace xsync