|
|
#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;
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);
xs_error_code_t connect(string xsync_ip); xs_error_code_t disConnect(); xsync_net_state_t getNetState(); bool ping(string xsync_ip);
void registerOnTimecodeMsgCallback(xsync_on_timecode_msg_t cb); void registerOnCameraSyncMsgCallback(xsync_on_camera_sync_msg_t cb); void registerOnRecordSigChangeMsgCallback(xsync_on_record_sig_change_msg_t 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_write(uint32_t regadd, uint32_t regvalue, 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 readSN(string &sn); xs_error_code_t readMAC(string &mac);
xs_error_code_t generatorNewMac(); xs_error_code_t factoryReset(); xs_error_code_t reboot(); xs_error_code_t changeNetworkConfig(string ip, string mask, string gateway);
public: /*******************************************************************************
* 内部时码发生器 * *******************************************************************************/ /**
* @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_setFormat(TimecodeFormat_t format); xs_error_code_t InternalTimecode_getFormat(TimecodeFormat_t &format);
/**
* @brief 内部Timecode信号发生器,设置Timecode值 * * @param timecode * @return xs_error_code_t */ xs_error_code_t InternalTimecode_setCode(XsyncTimecode_t timecode); xs_error_code_t InternalTimecode_getCode(XsyncTimecode_t &timecode);
/*******************************************************************************
* 时码输入 * *******************************************************************************/
/**
* @brief 选择时码输入源 * * @param src * INPUT_IF_TIMECODE_BNC * INPUT_IF_TIMECODE_HEADPHONE * * @return xs_error_code_t */ xs_error_code_t ExternalTimecode_setSource(InputInterface_t src); xs_error_code_t ExternalTimecode_getSource(InputInterface_t &timecode_select);
/**
* @brief 设置时码格式 * * @param format * @return xs_error_code_t */ xs_error_code_t ExternalTimecode_setFormat(TimecodeFormat_t format); xs_error_code_t ExternalTimecode_getFormat(TimecodeFormat_t &format);
// ExternalTimecode_readCode
xs_error_code_t ExternalTimecode_readCode(XsyncTimecode_t &timecode);
/**
* @brief 系统Timecode选择时钟源 * * @param internal * 0: 内部Timecode * 1: 外部Timecode * @return xs_error_code_t */ xs_error_code_t SysTimecode_setSource(uint32_t sig); xs_error_code_t SysTimecode_getSource(uint32_t &sig);
/**
* @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_readCode(XsyncTimecode_t &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 读取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);
/**
* @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 multi); xs_error_code_t TTLOutputModule2_setFreqMultiplication(uint32_t multi); xs_error_code_t TTLOutputModule3_setFreqMultiplication(uint32_t multi); xs_error_code_t TTLOutputModule4_setFreqMultiplication(uint32_t multi);
xs_error_code_t TTLOutputModule1_getFreqMultiplication(uint32_t &multi); xs_error_code_t TTLOutputModule2_getFreqMultiplication(uint32_t &multi); xs_error_code_t TTLOutputModule3_getFreqMultiplication(uint32_t &multi); xs_error_code_t TTLOutputModule4_getFreqMultiplication(uint32_t &multi);
xs_error_code_t TTLOutputModule1_readInFreq(float &freq); xs_error_code_t TTLOutputModule2_readInFreq(float &freq); xs_error_code_t TTLOutputModule3_readInFreq(float &freq); xs_error_code_t TTLOutputModule4_readInFreq(float &freq);
xs_error_code_t TTLOutputModule1_readOutFreq(float &freq); xs_error_code_t TTLOutputModule2_readOutFreq(float &freq); xs_error_code_t TTLOutputModule3_readOutFreq(float &freq); xs_error_code_t TTLOutputModule4_readOutFreq(float &freq);
/**
* @brief 读取Genlock输入模块的频率 * * @param freq * @return xs_error_code_t */ xs_error_code_t ExternalGenlock_detectFreq(float &freq); /**
* @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 系统Genlock选择时钟源 * * @param sig * 支持列表: * 0: 内部 * 1: 外部 * * @return xs_error_code_t */ xs_error_code_t SysGenlock_setSrc(uint32_t source); xs_error_code_t SysGenlock_getSrc(uint32_t &source);
/**
* @brief 读取系统Genlock频率 * * @param freq * @return xs_error_code_t */ xs_error_code_t SysGenlock_readFreq(float &freq);
/**
* @brief 设备内部时钟发生器频率 * * @param freq 单位为HZ,最小频率变化支持0.1HZ * @return xs_error_code_t */ xs_error_code_t InternalClock_setFreq(float freq); xs_error_code_t InternalClock_getFreq(float &freq);
/**
* @brief 系统时钟选择时钟源 * * @param mode * 支持列表: * SIGNAL_TTLIN1 * SIGNAL_TTLIN1 * SIGNAL_TTLIN2 * SIGNAL_TTLIN3 * SIGNAL_TTLIN4 * SIGNAL_INTERNAL_CLOCK_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 muti * @return xs_error_code_t */ xs_error_code_t SysClock_setFreqMultiplication(uint32_t muti); xs_error_code_t SysClock_getFreqMultiplication(uint32_t &muti);
/**
* @brief 读取主时钟频率 * * @param freq * @return xs_error_code_t */ xs_error_code_t SysClock_readOutSigFreq(float &freq); /**
* @brief 读取系统时钟输入频率 * * @param freq * @return xs_error_code_t */ xs_error_code_t SysClock_readInSigFreq(float &freq);
/**
* @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);
xs_error_code_t RecordSigGenerator_setTimecodeCtrlFlag(uint32_t autoStart, uint32_t autoStop); xs_error_code_t RecordSigGenerator_getTimecodeCtrlFlag(uint32_t &autoStart, uint32_t &autoStop);
// 外部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);
/**
* @brief 设置外部触发电平,有效电平 * * @param polarity 0:低电平 1:高电平 * @return xs_error_code_t */ xs_error_code_t RecordSigGenerator_setExternalTTLTriggerPolarity(uint32_t polarity); xs_error_code_t RecordSigGenerator_getExternalTTLTriggerPolarity(uint32_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 录制信号生成器,读取录制状态 * * @param state 0:没有录制,1:录制中 * @return xs_error_code_t */ xs_error_code_t RecordSigGenerator_getRecordState(uint32_t &state); xs_error_code_t RecordSigGenerator_readTimecodeSnapshot(XsyncTimecode_t &timecode);
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);
xs_error_code_t readtimecode(uint32_t reg0, uint32_t reg1, XsyncTimecode_t &timecode); xs_error_code_t writetimecode(uint32_t reg0, uint32_t reg1, XsyncTimecode_t timecode); xs_error_code_t readfreq(uint32_t reg, float &freq);
template <typename T> xs_error_code_t _reg_read(uint32_t regadd, T ®value, int32_t overtime_ms = 100) { uint32_t regvalue_u32; xs_error_code_t ret = reg_read(regadd, regvalue_u32, overtime_ms); if (ret == kxs_ec_success) { regvalue = (T)regvalue_u32; } return ret; }
void parseTimecodeMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length); void parseCameraSyncMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length); };
} // namespace xsync
|