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.
962 lines
46 KiB
962 lines
46 KiB
#include "xsync_v2.hpp"
|
|
|
|
#include <string.h>
|
|
|
|
#include <map>
|
|
|
|
#include "xsync_errcode.hpp"
|
|
#include "xsync_regs.hpp"
|
|
#include "xsync_utils.hpp"
|
|
#include "xsync_v2_sig_type.hpp"
|
|
|
|
#define TAG "XSYNC"
|
|
|
|
using namespace xsync;
|
|
using namespace std;
|
|
|
|
/**
|
|
* @brief XSYNC协议端口
|
|
*/
|
|
#define IFLYTOP_XSYNC_SERVICE_XSYNC_PORT 19900 // xsync端端口
|
|
#define IFLYTOP_XSYNC_SERVICE_PC_PORT 19901 // pc 端端口
|
|
|
|
#define IFLYTOP_XSYNC_TIMECODE_REPORT_XSYNC_PORT 19902 // xsync端端口
|
|
#define IFLYTOP_XSYNC_TIMECODE_REPORT_PC_PORT 19903 // pc端端口
|
|
|
|
#define IFLYTOP_XSYNC_CAMERA_SYNC_PACKET_XSYNC_PORT 13013 // xsync端端口
|
|
#define IFLYTOP_XSYNC_CAMERA_SYNC_PACKET_PC_PORT 13014 // pc端端口
|
|
|
|
#define DO_XSYNC(exptr) \
|
|
{ \
|
|
xs_error_code_t ecode = exptr; \
|
|
if (ecode != kxs_ec_success) return ecode; \
|
|
}
|
|
|
|
#define REG_WRITE(reg, value) \
|
|
{ \
|
|
DO_XSYNC(reg_write(reg, value, 10)); \
|
|
return kxs_ec_success; \
|
|
}
|
|
|
|
#define REG_READ(reg, value) \
|
|
{ \
|
|
uint32_t readbak = 0; \
|
|
DO_XSYNC(reg_read(reg, readbak, 10)); \
|
|
value = (decltype(value))readbak; \
|
|
return kxs_ec_success; \
|
|
}
|
|
|
|
class Xsync : public IXsync {
|
|
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];
|
|
std::recursive_mutex lock_;
|
|
|
|
public:
|
|
static Xsync &Ins();
|
|
|
|
Xsync(/* args */);
|
|
virtual ~Xsync() {}
|
|
|
|
void initialize(I_XSUDPFactory *xsync_udp_factory);
|
|
|
|
xs_error_code_t connect(string xsync_ip);
|
|
xs_error_code_t disConnect();
|
|
|
|
virtual xs_error_code_t changeXsyncIp(string xsync_ip) override;
|
|
virtual bool ping() override;
|
|
|
|
virtual void registerOnTimecodeMsgCallback(xsync_on_timecode_msg_t cb) override;
|
|
virtual void registerOnCameraSyncMsgCallback(xsync_on_camera_sync_msg_t cb) override;
|
|
virtual void registerOnRecordSigChangeMsgCallback(xsync_on_record_sig_change_msg_t cb) override;
|
|
|
|
virtual xs_error_code_t generatorNewMac() override;
|
|
virtual xs_error_code_t factoryReset() override;
|
|
virtual xs_error_code_t reboot() override;
|
|
virtual xs_error_code_t changeNetworkConfig(string ip, string mask, string gateway) override;
|
|
virtual xs_error_code_t readSn(string &sn) override;
|
|
virtual xs_error_code_t readMac(string &mac) override;
|
|
|
|
public:
|
|
virtual xs_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms = 100) override;
|
|
virtual xs_error_code_t reg_read(uint32_t regadd, uint32_t ®value, int32_t overtime_ms = 100) override;
|
|
|
|
public:
|
|
virtual xs_error_code_t ExternalTimecode_setSource(InputInterface_t src) override;
|
|
virtual xs_error_code_t ExternalTimecode_getSource(InputInterface_t &timecode_select) override;
|
|
virtual xs_error_code_t ExternalTimecode_setFormat(TimecodeFormat_t format) override;
|
|
virtual xs_error_code_t ExternalTimecode_getFormat(TimecodeFormat_t &format) override;
|
|
virtual xs_error_code_t ExternalTimecode_readCode(XsyncTimecode_t &timecode) override;
|
|
|
|
virtual xs_error_code_t TTLInputModule1_detectFreq(float &freq) override;
|
|
virtual xs_error_code_t TTLInputModule2_detectFreq(float &freq) override;
|
|
virtual xs_error_code_t TTLInputModule3_detectFreq(float &freq) override;
|
|
virtual xs_error_code_t TTLInputModule4_detectFreq(float &freq) override;
|
|
|
|
virtual xs_error_code_t ExternalGenlock_detectFreq(float &freq) override;
|
|
|
|
virtual xs_error_code_t InternalTimecode_setFormat(TimecodeFormat_t format) override;
|
|
virtual xs_error_code_t InternalTimecode_getFormat(TimecodeFormat_t &format) override;
|
|
virtual xs_error_code_t InternalTimecode_setCode(XsyncTimecode_t timecode) override;
|
|
virtual xs_error_code_t InternalTimecode_getCode(XsyncTimecode_t &timecode) override;
|
|
|
|
virtual xs_error_code_t InternalGenlock_setFormat(GenlockFormat_t format) override;
|
|
virtual xs_error_code_t InternalGenlock_getFormat(GenlockFormat_t &format) override;
|
|
|
|
virtual xs_error_code_t InternalClock_setFreq(float freq) override;
|
|
virtual xs_error_code_t InternalClock_getFreq(float &freq) override;
|
|
|
|
virtual xs_error_code_t SysTimecode_setSource(uint32_t sig) override;
|
|
virtual xs_error_code_t SysTimecode_getSource(uint32_t &sig) override;
|
|
virtual xs_error_code_t SysTimecode_readFormat(TimecodeFormat_t &format) override;
|
|
virtual xs_error_code_t SysTimecode_readCode(XsyncTimecode_t &timecode) override;
|
|
|
|
virtual xs_error_code_t SysGenlock_setSrc(uint32_t source) override;
|
|
virtual xs_error_code_t SysGenlock_getSrc(uint32_t &source) override;
|
|
virtual xs_error_code_t SysGenlock_readFreq(float &freq) override;
|
|
|
|
virtual xs_error_code_t SysClock_setSrc(SignalType_t sig) override;
|
|
virtual xs_error_code_t SysClock_getSrc(SignalType_t &sig) override;
|
|
virtual xs_error_code_t SysClock_setTriggerEdge(TriggerEdge_t edge) override;
|
|
virtual xs_error_code_t SysClock_getTriggerEdge(TriggerEdge_t &edge) override;
|
|
virtual xs_error_code_t SysClock_setFreqDivision(uint32_t div) override;
|
|
virtual xs_error_code_t SysClock_geFreqtDivision(uint32_t &div) override;
|
|
virtual xs_error_code_t SysClock_setFreqMultiplication(uint32_t muti) override;
|
|
virtual xs_error_code_t SysClock_getFreqMultiplication(uint32_t &muti) override;
|
|
virtual xs_error_code_t SysClock_readOutSigFreq(float &freq) override;
|
|
virtual xs_error_code_t SysClock_readInSigFreq(float &freq) override;
|
|
|
|
virtual xs_error_code_t RecordSigGenerator_setContrlMode(ControlMode_t mode) override;
|
|
virtual xs_error_code_t RecordSigGenerator_getContrlMode(ControlMode_t &mode) override;
|
|
virtual xs_error_code_t RecordSigGenerator_manualStart() override;
|
|
virtual xs_error_code_t RecordSigGenerator_manualStop() override;
|
|
virtual xs_error_code_t RecordSigGenerator_setAutoStartTimecode(XsyncTimecode_t timecode) override;
|
|
virtual xs_error_code_t RecordSigGenerator_setAutoStopTimecode(XsyncTimecode_t timecode) override;
|
|
virtual xs_error_code_t RecordSigGenerator_getAutoStartTimecode(XsyncTimecode_t &timecode) override;
|
|
virtual xs_error_code_t RecordSigGenerator_getAutoStopTimecode(XsyncTimecode_t &timecode) override;
|
|
virtual xs_error_code_t RecordSigGenerator_setTimecodeCtrlFlag(uint32_t autoStart, uint32_t autoStop) override;
|
|
virtual xs_error_code_t RecordSigGenerator_getTimecodeCtrlFlag(uint32_t &autoStart, uint32_t &autoStop) override;
|
|
virtual xs_error_code_t RecordSigGenerator_setExternalTTLTriggerSrc(InputInterface_t ttlPortNum); // 1- override4
|
|
virtual xs_error_code_t RecordSigGenerator_getExternalTTLTriggerSrc(InputInterface_t &ttlPortNum) override;
|
|
virtual xs_error_code_t RecordSigGenerator_setExternalTTLTriggerPolarity(uint32_t polarity) override;
|
|
virtual xs_error_code_t RecordSigGenerator_getExternalTTLTriggerPolarity(uint32_t &polarity) override;
|
|
virtual xs_error_code_t RecordSigGenerator_setRecordExposureTime(uint32_t us) override;
|
|
virtual xs_error_code_t RecordSigGenerator_getRecordExposureTime(uint32_t &us) override;
|
|
virtual xs_error_code_t RecordSigGenerator_setRecordExposureOffsetTime(uint32_t us) override;
|
|
virtual xs_error_code_t RecordSigGenerator_getRecordExposureOffsetTime(uint32_t &us) override;
|
|
virtual xs_error_code_t RecordSigGenerator_getRecordState(uint32_t &state) override;
|
|
virtual xs_error_code_t RecordSigGenerator_readTimecodeSnapshot(XsyncTimecode_t &timecode) override;
|
|
|
|
xs_error_code_t TimecodeOutputModule_setBncOutputLevel(int level); // 0:line,1:mi overridec
|
|
xs_error_code_t TimecodeOutputModule_getBncOutputLevel(int &level);
|
|
xs_error_code_t TimecodeOutputModule_setHeadphoneOutputLevel(int level); // 0:line,1:mi overridec
|
|
xs_error_code_t TimecodeOutputModule_getHeadphoneOutputLevel(int &level);
|
|
|
|
virtual xs_error_code_t TTLOutputModule1_setSrcSigType(SignalType_t source) override;
|
|
virtual xs_error_code_t TTLOutputModule1_getSrcSigType(SignalType_t &source) override;
|
|
virtual xs_error_code_t TTLOutputModule1_setFreqDivision(uint32_t div) override;
|
|
virtual xs_error_code_t TTLOutputModule1_getFreqDivision(uint32_t &div) override;
|
|
virtual xs_error_code_t TTLOutputModule1_setFreqMultiplication(uint32_t multi) override;
|
|
virtual xs_error_code_t TTLOutputModule1_getFreqMultiplication(uint32_t &multi) override;
|
|
virtual xs_error_code_t TTLOutputModule1_readInFreq(float &freq) override;
|
|
virtual xs_error_code_t TTLOutputModule1_readOutFreq(float &freq) override;
|
|
|
|
virtual xs_error_code_t TTLOutputModule2_setSrcSigType(SignalType_t source) override;
|
|
virtual xs_error_code_t TTLOutputModule2_getSrcSigType(SignalType_t &source) override;
|
|
virtual xs_error_code_t TTLOutputModule2_setFreqDivision(uint32_t div) override;
|
|
virtual xs_error_code_t TTLOutputModule2_getFreqDivision(uint32_t &div) override;
|
|
virtual xs_error_code_t TTLOutputModule2_setFreqMultiplication(uint32_t multi) override;
|
|
virtual xs_error_code_t TTLOutputModule2_getFreqMultiplication(uint32_t &multi) override;
|
|
virtual xs_error_code_t TTLOutputModule2_readInFreq(float &freq) override;
|
|
virtual xs_error_code_t TTLOutputModule2_readOutFreq(float &freq) override;
|
|
|
|
virtual xs_error_code_t TTLOutputModule3_setSrcSigType(SignalType_t source) override;
|
|
virtual xs_error_code_t TTLOutputModule3_getSrcSigType(SignalType_t &source) override;
|
|
virtual xs_error_code_t TTLOutputModule3_setFreqDivision(uint32_t div) override;
|
|
virtual xs_error_code_t TTLOutputModule3_getFreqDivision(uint32_t &div) override;
|
|
virtual xs_error_code_t TTLOutputModule3_setFreqMultiplication(uint32_t multi) override;
|
|
virtual xs_error_code_t TTLOutputModule3_getFreqMultiplication(uint32_t &multi) override;
|
|
virtual xs_error_code_t TTLOutputModule3_readInFreq(float &freq) override;
|
|
virtual xs_error_code_t TTLOutputModule3_readOutFreq(float &freq) override;
|
|
|
|
virtual xs_error_code_t TTLOutputModule4_setSrcSigType(SignalType_t source) override;
|
|
virtual xs_error_code_t TTLOutputModule4_getSrcSigType(SignalType_t &source) override;
|
|
virtual xs_error_code_t TTLOutputModule4_setFreqDivision(uint32_t div) override;
|
|
virtual xs_error_code_t TTLOutputModule4_getFreqDivision(uint32_t &div) override;
|
|
virtual xs_error_code_t TTLOutputModule4_setFreqMultiplication(uint32_t multi) override;
|
|
virtual xs_error_code_t TTLOutputModule4_getFreqMultiplication(uint32_t &multi) override;
|
|
virtual xs_error_code_t TTLOutputModule4_readInFreq(float &freq) override;
|
|
virtual xs_error_code_t TTLOutputModule4_readOutFreq(float &freq) override;
|
|
|
|
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);
|
|
xs_error_code_t reg_write(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> ®values, int32_t overtime_ms = 100);
|
|
|
|
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);
|
|
};
|
|
|
|
/*******************************************************************************
|
|
* Xsync *
|
|
*******************************************************************************/
|
|
Xsync::Xsync(/* args */) {}
|
|
|
|
Xsync &Xsync::Ins() {
|
|
static Xsync xsync;
|
|
return xsync;
|
|
}
|
|
void Xsync::initialize(I_XSUDPFactory *xsync_udp_factory) { m_xsync_udp_factory = xsync_udp_factory; }
|
|
|
|
xs_error_code_t Xsync::changeXsyncIp(string xsync_ip) {
|
|
disConnect();
|
|
return connect(xsync_ip);
|
|
}
|
|
bool Xsync::ping() {
|
|
uint32_t readbak;
|
|
xs_error_code_t ecode = reg_read(reg::kproduct_type_id, readbak, 10);
|
|
if (ecode != kxs_ec_success) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
xs_error_code_t Xsync::connect(string xsync_ip) {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
|
|
m_xsync_ip = xsync_ip;
|
|
disConnect();
|
|
/**
|
|
* @brief 创建 m_xsync_reg_udp
|
|
*/
|
|
|
|
xs_error_code_t ecode = kxs_ec_success;
|
|
|
|
auto xsync_reg_udp = m_xsync_udp_factory->createXSUDP();
|
|
ecode = xsync_reg_udp->initialize("0.0.0.0", IFLYTOP_XSYNC_SERVICE_PC_PORT);
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
/**
|
|
* @brief 创建 m_xsync_timecode_udp_listener
|
|
*/
|
|
auto xsync_timecode_udp_listener = m_xsync_udp_factory->createXSUDP();
|
|
|
|
ecode = xsync_timecode_udp_listener->initialize("0.0.0.0", IFLYTOP_XSYNC_TIMECODE_REPORT_PC_PORT);
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
ecode = xsync_timecode_udp_listener->startReceive([this](XsyncNetAdd &from, uint8_t *data, size_t length) { parseTimecodeMsgAndReport(from, data, length); });
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
|
|
/**
|
|
* @brief 创建 m_xsync_camera_sync_udp_listener
|
|
*/
|
|
auto xsync_camera_sync_udp_listener = m_xsync_udp_factory->createXSUDP();
|
|
|
|
ecode = xsync_camera_sync_udp_listener->initialize("0.0.0.0", IFLYTOP_XSYNC_CAMERA_SYNC_PACKET_PC_PORT);
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
ecode = xsync_camera_sync_udp_listener->startReceive([this](XsyncNetAdd &from, uint8_t *data, size_t length) { parseCameraSyncMsgAndReport(from, data, length); });
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
|
|
m_xsync_reg_udp = xsync_reg_udp;
|
|
m_xsync_timecode_udp_listener = xsync_timecode_udp_listener;
|
|
m_xsync_camera_sync_udp_listener = xsync_camera_sync_udp_listener;
|
|
|
|
return ecode;
|
|
}
|
|
xs_error_code_t Xsync::disConnect() {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
|
|
if (m_xsync_reg_udp != nullptr) {
|
|
m_xsync_reg_udp->stopReceive();
|
|
m_xsync_reg_udp = nullptr;
|
|
}
|
|
|
|
if (m_xsync_timecode_udp_listener != nullptr) {
|
|
m_xsync_timecode_udp_listener->stopReceive();
|
|
m_xsync_timecode_udp_listener = nullptr;
|
|
}
|
|
|
|
if (m_xsync_camera_sync_udp_listener != nullptr) {
|
|
m_xsync_camera_sync_udp_listener->stopReceive();
|
|
m_xsync_camera_sync_udp_listener = nullptr;
|
|
}
|
|
|
|
return kxs_ec_success;
|
|
}
|
|
|
|
void Xsync::registerOnTimecodeMsgCallback(xsync_on_timecode_msg_t cb) { m_on_timecode_msg_cb = cb; }
|
|
void Xsync::registerOnCameraSyncMsgCallback(xsync_on_camera_sync_msg_t cb) { m_on_camera_sync_msg_cb = cb; }
|
|
void Xsync::registerOnRecordSigChangeMsgCallback(xsync_on_record_sig_change_msg_t cb) { m_on_record_sig_change_msg_cb = cb; }
|
|
|
|
xs_error_code_t Xsync::readSn(string &sn) {
|
|
sn = "X1001000000000";
|
|
return kxs_ec_success;
|
|
}
|
|
xs_error_code_t Xsync::readMac(string &mac) {
|
|
// mac = "";
|
|
uint32_t mac0;
|
|
uint32_t mac1;
|
|
|
|
DO_XSYNC(reg_read(reg::kmac0, mac0));
|
|
DO_XSYNC(reg_read(reg::kmac1, mac1));
|
|
|
|
char buf[128] = {0};
|
|
sprintf(buf, "%02x-%02x-%02x-%02x-%02x-%02x", (mac0 >> 0) & 0xff, (mac0 >> 8) & 0xff, (mac0 >> 16) & 0xff, (mac0 >> 24) & 0xff, (mac1 >> 0) & 0xff, (mac1 >> 8) & 0xff);
|
|
mac = buf;
|
|
|
|
return kxs_ec_success;
|
|
}
|
|
|
|
xs_error_code_t Xsync::xsync_send_cmd_block(iflytop_xsync_packet_header_t *cmd, iflytop_xsync_packet_header_t *rx_data, int32_t buffersize, int32_t overtime_ms) {
|
|
lock_guard<recursive_mutex> lock(lock_);
|
|
if (!m_xsync_reg_udp) return kxs_ec_lose_connect;
|
|
m_xsync_reg_udp->clearRxBuffer();
|
|
|
|
cmd->index = txpacket_index++;
|
|
|
|
XsyncNetAdd toadd = {m_xsync_ip, IFLYTOP_XSYNC_SERVICE_XSYNC_PORT};
|
|
xs_error_code_t ecode = //
|
|
m_xsync_reg_udp->sendto(toadd, (const char *)cmd, sizeof(iflytop_xsync_packet_header_t) + cmd->ndata * 4, nullptr);
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
|
|
XsyncNetAdd fromadd;
|
|
while (true) {
|
|
ecode = m_xsync_reg_udp->receive((char *)rx_data, buffersize, fromadd, overtime_ms);
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
if (rx_data->index != cmd->index) {
|
|
continue;
|
|
}
|
|
break;
|
|
}
|
|
|
|
return (xs_error_code_t)rx_data->data[0];
|
|
}
|
|
|
|
xs_error_code_t Xsync::reg_write(uint32_t regadd, uint32_t regvalue, int32_t overtime_ms) { //
|
|
uint32_t readbak = 0;
|
|
return reg_write(regadd, regvalue, readbak, overtime_ms);
|
|
}
|
|
xs_error_code_t Xsync::reg_write(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms) {
|
|
/**
|
|
* @brief
|
|
* 协议说明
|
|
*
|
|
* kxsync_packet_type_reg_write
|
|
* tx: regadd,regdata
|
|
* rx: ecode,regdata
|
|
*/
|
|
|
|
uint8_t txdata[128] = {0};
|
|
uint8_t rxdata[128] = {0};
|
|
|
|
iflytop_xsync_packet_header_t *txpacket = (iflytop_xsync_packet_header_t *)txdata;
|
|
iflytop_xsync_packet_header_t *rxpacket = (iflytop_xsync_packet_header_t *)rxdata;
|
|
|
|
txpacket->type = kxsync_packet_type_cmd;
|
|
txpacket->index = txpacket_index++;
|
|
txpacket->cmd = kxsync_packet_type_reg_write;
|
|
txpacket->ndata = 2;
|
|
txpacket->data[0] = regadd;
|
|
txpacket->data[1] = regvalue;
|
|
|
|
auto ecode = xsync_send_cmd_block(txpacket, rxpacket, sizeof(rxdata), overtime_ms);
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
|
|
regbackvalue = rxpacket->data[1];
|
|
return ecode;
|
|
}
|
|
|
|
xs_error_code_t Xsync::reg_read(uint32_t regadd, uint32_t ®value, int32_t overtime_ms) {
|
|
/**
|
|
* @brief
|
|
* 协议说明
|
|
*
|
|
* kxsync_packet_type_reg_write
|
|
* tx: regadd,regdata
|
|
* rx: ecode,regdata
|
|
*/
|
|
|
|
uint8_t txdata[128] = {0};
|
|
uint8_t rxdata[128] = {0};
|
|
|
|
iflytop_xsync_packet_header_t *txpacket = (iflytop_xsync_packet_header_t *)txdata;
|
|
iflytop_xsync_packet_header_t *rxpacket = (iflytop_xsync_packet_header_t *)rxdata;
|
|
|
|
txpacket->type = kxsync_packet_type_cmd;
|
|
txpacket->index = txpacket_index++;
|
|
txpacket->cmd = kxsync_packet_type_reg_read;
|
|
txpacket->ndata = 2;
|
|
txpacket->data[0] = regadd;
|
|
txpacket->data[1] = regvalue;
|
|
|
|
auto ecode = xsync_send_cmd_block(txpacket, rxpacket, sizeof(rxdata), overtime_ms);
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
regvalue = rxpacket->data[1];
|
|
return ecode;
|
|
}
|
|
xs_error_code_t Xsync::reg_read_muti(uint32_t regadd, uint32_t nreg, vector<uint32_t> ®values, int32_t overtime_ms) {
|
|
/**
|
|
* @brief
|
|
* 协议说明
|
|
*
|
|
* kxsync_packet_type_reg_read_regs
|
|
* tx: regstartadd,nreg
|
|
* rx: ecode,regdatas
|
|
*/
|
|
|
|
uint8_t txdata[128] = {0};
|
|
uint8_t rxdata[1280] = {0};
|
|
|
|
iflytop_xsync_packet_header_t *txpacket = (iflytop_xsync_packet_header_t *)txdata;
|
|
iflytop_xsync_packet_header_t *rxpacket = (iflytop_xsync_packet_header_t *)rxdata;
|
|
|
|
txpacket->type = kxsync_packet_type_cmd;
|
|
txpacket->index = txpacket_index++;
|
|
txpacket->cmd = kxsync_packet_type_reg_read_regs;
|
|
txpacket->ndata = 2;
|
|
txpacket->data[0] = regadd;
|
|
txpacket->data[1] = nreg;
|
|
|
|
auto ecode = xsync_send_cmd_block(txpacket, rxpacket, sizeof(rxdata), overtime_ms);
|
|
if (ecode != kxs_ec_success) {
|
|
return ecode;
|
|
}
|
|
|
|
if (rxpacket->ndata > 0) {
|
|
for (int i = 0; i < rxpacket->ndata - 1; i++) {
|
|
regvalues.push_back(rxpacket->data[i + 1]);
|
|
}
|
|
}
|
|
return ecode;
|
|
}
|
|
|
|
xs_error_code_t Xsync::readtimecode(uint32_t reg0, uint32_t reg1, XsyncTimecode_t &timecode) {
|
|
uint32_t readbak = 0;
|
|
xs_error_code_t ecode = kxs_ec_success;
|
|
|
|
uint32_t tc0 = 0;
|
|
uint32_t tc1 = 0;
|
|
|
|
ecode = reg_read(reg0, tc0, 10);
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
ecode = reg_read(reg1, tc1, 10);
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
|
|
Timecode64_t tc64;
|
|
tc64.tc0 = tc0;
|
|
tc64.tc1 = tc1;
|
|
|
|
timecode = timecode64ToXsyncTimeCode(tc64);
|
|
return ecode;
|
|
}
|
|
xs_error_code_t Xsync::writetimecode(uint32_t reg0, uint32_t reg1, XsyncTimecode_t timecode) {
|
|
uint32_t readbak = 0;
|
|
xs_error_code_t ecode = kxs_ec_success;
|
|
|
|
Timecode64_t tc64 = timecodeTo64(timecode);
|
|
|
|
ecode = reg_write(reg0, tc64.tc0, readbak, 10);
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
ecode = reg_write(reg1, tc64.tc1, readbak, 10);
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
|
|
return ecode;
|
|
}
|
|
|
|
xs_error_code_t Xsync::readfreq(uint32_t reg, float &freqfloat) {
|
|
uint32_t freq_cnt = 0;
|
|
DO_XSYNC(reg_read(reg, freq_cnt));
|
|
if (freq_cnt == 0) {
|
|
freqfloat = 0;
|
|
}
|
|
|
|
if (freq_cnt != 0) {
|
|
uint32_t freq_1000x = ((1.0 / (freq_cnt * 1.0 / (10 * 1000 * 1000))) * 1000 + 0.5); //+0.5是因为c++ 小数强转成整数时是取整,而非四舍五入
|
|
// ZLOGI(TAG, "freq_10x %f", freq_10x);
|
|
freqfloat = freq_1000x / 1000.0;
|
|
} else {
|
|
freqfloat = 0;
|
|
}
|
|
return kxs_ec_success;
|
|
}
|
|
|
|
void Xsync::parseTimecodeMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length) {
|
|
iflytop_xsync_event_report_packet_t *packet = (iflytop_xsync_event_report_packet_t *)data;
|
|
if (packet->eventid == ktimecode_report_event) {
|
|
Timecode64_t tc64;
|
|
tc64.tc0 = packet->data[0];
|
|
tc64.tc1 = packet->data[1];
|
|
XsyncTimecode_t timecode = timecode64ToXsyncTimeCode(tc64);
|
|
if (m_on_timecode_msg_cb) m_on_timecode_msg_cb(&timecode);
|
|
} else if (packet->eventid == kxsync_work_state_report_event) {
|
|
// 信号发生器状态改变
|
|
Timecode64_t tc64;
|
|
tc64.tc0 = packet->data[1];
|
|
tc64.tc1 = packet->data[2];
|
|
XsyncTimecode_t timecode = timecode64ToXsyncTimeCode(tc64);
|
|
|
|
if (m_on_record_sig_change_msg_cb) m_on_record_sig_change_msg_cb(packet->data[0], &timecode);
|
|
}
|
|
}
|
|
void Xsync::parseCameraSyncMsgAndReport(XsyncNetAdd &from, uint8_t *data, size_t length) {
|
|
uint32_t count = 0;
|
|
|
|
uint32_t data0 = data[7];
|
|
uint32_t data1 = data[6];
|
|
uint32_t data2 = data[5];
|
|
uint32_t data3 = data[4];
|
|
|
|
count = data0 + (data1 << 8) + (data2 << 16) + (data3 << 24);
|
|
|
|
xysnc_camera_sync_data_t camera_sync_data;
|
|
camera_sync_data.frameIndex = count;
|
|
|
|
if (m_on_camera_sync_msg_cb) m_on_camera_sync_msg_cb(&camera_sync_data);
|
|
}
|
|
|
|
xs_error_code_t Xsync::generatorNewMac() { return doaction(xsync_stm32_action_generator_new_mac, 0, nullptr, 2000); }
|
|
xs_error_code_t Xsync::factoryReset() { return doaction(xsync_stm32_action_factory_reset, 0, nullptr, 1000); }
|
|
xs_error_code_t Xsync::reboot() { return doaction(xsync_stm32_action_reboot, 0, nullptr); }
|
|
xs_error_code_t Xsync::storageConfig() { return doaction(xsync_stm32_action_storage_cfg, 0, nullptr, 1000); }
|
|
xs_error_code_t Xsync::changeNetworkConfig(string ip, string mask, string gateway) {
|
|
uint32_t ip32 = 0;
|
|
uint32_t mask32 = 0;
|
|
uint32_t gateway32 = 0;
|
|
xs_error_code_t ecode;
|
|
bool suc = false;
|
|
|
|
ip32 = (uint32_t)ipToUint32(ip.c_str(), suc);
|
|
if (!suc) return kxs_ec_param_error;
|
|
mask32 = (uint32_t)ipToUint32(mask.c_str(), suc);
|
|
if (!suc) return kxs_ec_param_error;
|
|
gateway32 = (uint32_t)ipToUint32(gateway.c_str(), suc);
|
|
if (!suc) return kxs_ec_param_error;
|
|
|
|
uint32_t readbak = 0;
|
|
|
|
ecode = reg_write(reg::kstm32_ip, ip32, readbak);
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
ecode = reg_write(reg::kstm32_netmask, mask32, readbak);
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
ecode = reg_write(reg::kstm32_gw, gateway32, readbak);
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
|
|
ecode = storageConfig();
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
|
|
return kxs_ec_success;
|
|
}
|
|
|
|
xs_error_code_t Xsync::doaction(uint32_t action, uint32_t actionval, uint32_t *ackreturn, int32_t overtime_ms) {
|
|
//
|
|
uint32_t readbak = 0;
|
|
xs_error_code_t ecode;
|
|
ecode = reg_write(reg::kstm32_action_val0, actionval, readbak);
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
|
|
ecode = reg_write(reg::kstm32_action0, action, readbak, overtime_ms);
|
|
if (ecode != kxs_ec_success) return ecode;
|
|
if (ackreturn) *ackreturn = readbak;
|
|
return ecode;
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* TTLInputModule *
|
|
*******************************************************************************/
|
|
#define FREQ_CNT_TO_FREQ(cnt) ((cnt != 0) ? (uint32_t)(1.0 / (cnt * 1.0 / (10 * 1000 * 1000)) + 0.5) : 0) //+0.5是因为c++ 小数强转成整数时是取整,而非四舍五入
|
|
|
|
xs_error_code_t Xsync::TTLInputModule1_detectFreq(float &freq) { return readfreq(reg::k_ttlin1_freq_detector_reg, freq); }
|
|
xs_error_code_t Xsync::TTLInputModule2_detectFreq(float &freq) { return readfreq(reg::k_ttlin2_freq_detector_reg, freq); }
|
|
xs_error_code_t Xsync::TTLInputModule3_detectFreq(float &freq) { return readfreq(reg::k_ttlin3_freq_detector_reg, freq); }
|
|
xs_error_code_t Xsync::TTLInputModule4_detectFreq(float &freq) { return readfreq(reg::k_ttlin4_freq_detector_reg, freq); }
|
|
|
|
/*******************************************************************************
|
|
* TTLOutputModule *
|
|
*******************************************************************************/
|
|
|
|
// 0:固定输出低电平,1:固定输出高电平,2:分频倍频模式,3:转发模式,4:测试模式
|
|
xs_error_code_t Xsync::TTLOutputModule1_setSrcSigType(SignalType_t source) {
|
|
if (source != SIGNAL_LOGIC0 && //
|
|
source != SIGNAL_LOGIC1 && //
|
|
source != SIGNAL_TTLIN1 && //
|
|
source != SIGNAL_TTLIN2 && //
|
|
source != SIGNAL_TTLIN3 && //
|
|
source != SIGNAL_TTLIN4 && //
|
|
source != SIGNAL_SYS_CLK_OUTPUT && //
|
|
source != SIGNAL_SYS_GENLOCK_OUTPUT && //
|
|
source != SIGNAL_SYS_TIMECODE_FREQ_OUTPUT && //
|
|
source != SIGNAL_BUSINESS_RECORD_SIG && //
|
|
source != SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG //
|
|
) {
|
|
return kxs_ec_param_error;
|
|
}
|
|
|
|
if (source == SIGNAL_TTLIN1 || //
|
|
source == SIGNAL_TTLIN2 || //
|
|
source == SIGNAL_TTLIN3 || //
|
|
source == SIGNAL_TTLIN4 || //
|
|
source == SIGNAL_SYS_CLK_OUTPUT || //
|
|
source == SIGNAL_SYS_GENLOCK_OUTPUT || //
|
|
source == SIGNAL_SYS_TIMECODE_FREQ_OUTPUT //
|
|
) {
|
|
DO_XSYNC(reg_write(reg::kreg_ttlout1_signal_process_mode, 2, 10)); // 分频倍频模式
|
|
} else {
|
|
DO_XSYNC(reg_write(reg::kreg_ttlout1_signal_process_mode, 3, 10)); // 转发模式
|
|
}
|
|
REG_WRITE(reg::kreg_ttlout1_input_signal_select, source);
|
|
}
|
|
xs_error_code_t Xsync::TTLOutputModule2_setSrcSigType(SignalType_t source) {
|
|
if (source != SIGNAL_LOGIC0 && //
|
|
source != SIGNAL_LOGIC1 && //
|
|
source != SIGNAL_TTLIN1 && //
|
|
source != SIGNAL_TTLIN2 && //
|
|
source != SIGNAL_TTLIN3 && //
|
|
source != SIGNAL_TTLIN4 && //
|
|
source != SIGNAL_SYS_CLK_OUTPUT && //
|
|
source != SIGNAL_SYS_GENLOCK_OUTPUT && //
|
|
source != SIGNAL_SYS_TIMECODE_FREQ_OUTPUT && //
|
|
source != SIGNAL_BUSINESS_RECORD_SIG && //
|
|
source != SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG //
|
|
) {
|
|
return kxs_ec_param_error;
|
|
}
|
|
if (source == SIGNAL_TTLIN1 || //
|
|
source == SIGNAL_TTLIN2 || //
|
|
source == SIGNAL_TTLIN3 || //
|
|
source == SIGNAL_TTLIN4 || //
|
|
source == SIGNAL_SYS_CLK_OUTPUT || //
|
|
source == SIGNAL_SYS_GENLOCK_OUTPUT || //
|
|
source == SIGNAL_SYS_TIMECODE_FREQ_OUTPUT //
|
|
) {
|
|
DO_XSYNC(reg_write(reg::kreg_ttlout2_signal_process_mode, 2, 10)); // 分频倍频模式
|
|
} else {
|
|
DO_XSYNC(reg_write(reg::kreg_ttlout2_signal_process_mode, 3, 10)); // 转发模式
|
|
}
|
|
REG_WRITE(reg::kreg_ttlout2_input_signal_select, source);
|
|
}
|
|
xs_error_code_t Xsync::TTLOutputModule3_setSrcSigType(SignalType_t source) {
|
|
if (source != SIGNAL_LOGIC0 && //
|
|
source != SIGNAL_LOGIC1 && //
|
|
source != SIGNAL_TTLIN1 && //
|
|
source != SIGNAL_TTLIN2 && //
|
|
source != SIGNAL_TTLIN3 && //
|
|
source != SIGNAL_TTLIN4 && //
|
|
source != SIGNAL_SYS_CLK_OUTPUT && //
|
|
source != SIGNAL_SYS_GENLOCK_OUTPUT && //
|
|
source != SIGNAL_SYS_TIMECODE_FREQ_OUTPUT && //
|
|
source != SIGNAL_BUSINESS_RECORD_SIG && //
|
|
source != SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG //
|
|
) {
|
|
return kxs_ec_param_error;
|
|
}
|
|
if (source == SIGNAL_TTLIN1 || //
|
|
source == SIGNAL_TTLIN2 || //
|
|
source == SIGNAL_TTLIN3 || //
|
|
source == SIGNAL_TTLIN4 || //
|
|
source == SIGNAL_SYS_CLK_OUTPUT || //
|
|
source == SIGNAL_SYS_GENLOCK_OUTPUT || //
|
|
source == SIGNAL_SYS_TIMECODE_FREQ_OUTPUT //
|
|
) {
|
|
DO_XSYNC(reg_write(reg::kreg_ttlout3_signal_process_mode, 2, 10)); // 分频倍频模式
|
|
} else {
|
|
DO_XSYNC(reg_write(reg::kreg_ttlout3_signal_process_mode, 3, 10)); // 转发模式
|
|
}
|
|
REG_WRITE(reg::kreg_ttlout3_input_signal_select, source);
|
|
}
|
|
xs_error_code_t Xsync::TTLOutputModule4_setSrcSigType(SignalType_t source) {
|
|
if (source != SIGNAL_LOGIC0 && //
|
|
source != SIGNAL_LOGIC1 && //
|
|
source != SIGNAL_TTLIN1 && //
|
|
source != SIGNAL_TTLIN2 && //
|
|
source != SIGNAL_TTLIN3 && //
|
|
source != SIGNAL_TTLIN4 && //
|
|
source != SIGNAL_SYS_CLK_OUTPUT && //
|
|
source != SIGNAL_SYS_GENLOCK_OUTPUT && //
|
|
source != SIGNAL_SYS_TIMECODE_FREQ_OUTPUT && //
|
|
source != SIGNAL_BUSINESS_RECORD_SIG && //
|
|
source != SIGNAL_BUSINESS_RECORD_EXPOSURE_SIG //
|
|
) {
|
|
return kxs_ec_param_error;
|
|
}
|
|
if (source == SIGNAL_TTLIN1 || source == SIGNAL_TTLIN2 || source == SIGNAL_TTLIN3 || source == SIGNAL_TTLIN4) {
|
|
DO_XSYNC(reg_write(reg::kreg_ttlout4_signal_process_mode, 2, 10)); // 分频倍频模式
|
|
} else {
|
|
DO_XSYNC(reg_write(reg::kreg_ttlout4_signal_process_mode, 3, 10)); // 转发模式
|
|
}
|
|
REG_WRITE(reg::kreg_ttlout4_input_signal_select, source);
|
|
}
|
|
|
|
xs_error_code_t Xsync::TTLOutputModule1_getSrcSigType(SignalType_t &source) { REG_READ(reg::kreg_ttlout1_input_signal_select, source); }
|
|
xs_error_code_t Xsync::TTLOutputModule2_getSrcSigType(SignalType_t &source) { REG_READ(reg::kreg_ttlout2_input_signal_select, source); }
|
|
xs_error_code_t Xsync::TTLOutputModule3_getSrcSigType(SignalType_t &source) { REG_READ(reg::kreg_ttlout3_input_signal_select, source); }
|
|
xs_error_code_t Xsync::TTLOutputModule4_getSrcSigType(SignalType_t &source) { REG_READ(reg::kreg_ttlout4_input_signal_select, source); }
|
|
|
|
xs_error_code_t Xsync::TTLOutputModule1_setFreqDivision(uint32_t div) { REG_WRITE(reg::kreg_ttlout1_pllout_freq_division_ctrl, div); }
|
|
xs_error_code_t Xsync::TTLOutputModule2_setFreqDivision(uint32_t div) { REG_WRITE(reg::kreg_ttlout2_pllout_freq_division_ctrl, div); }
|
|
xs_error_code_t Xsync::TTLOutputModule3_setFreqDivision(uint32_t div) { REG_WRITE(reg::kreg_ttlout3_pllout_freq_division_ctrl, div); }
|
|
xs_error_code_t Xsync::TTLOutputModule4_setFreqDivision(uint32_t div) { REG_WRITE(reg::kreg_ttlout4_pllout_freq_division_ctrl, div); }
|
|
|
|
xs_error_code_t Xsync::TTLOutputModule1_getFreqDivision(uint32_t &div) { REG_READ(reg::kreg_ttlout1_pllout_freq_division_ctrl, div); }
|
|
xs_error_code_t Xsync::TTLOutputModule2_getFreqDivision(uint32_t &div) { REG_READ(reg::kreg_ttlout2_pllout_freq_division_ctrl, div); }
|
|
xs_error_code_t Xsync::TTLOutputModule3_getFreqDivision(uint32_t &div) { REG_READ(reg::kreg_ttlout3_pllout_freq_division_ctrl, div); }
|
|
xs_error_code_t Xsync::TTLOutputModule4_getFreqDivision(uint32_t &div) { REG_READ(reg::kreg_ttlout4_pllout_freq_division_ctrl, div); }
|
|
|
|
xs_error_code_t Xsync::TTLOutputModule1_setFreqMultiplication(uint32_t multi) { REG_WRITE(reg::kreg_ttlout1_pllout_freq_multiplication_ctrl, multi); }
|
|
xs_error_code_t Xsync::TTLOutputModule2_setFreqMultiplication(uint32_t multi) { REG_WRITE(reg::kreg_ttlout2_pllout_freq_multiplication_ctrl, multi); }
|
|
xs_error_code_t Xsync::TTLOutputModule3_setFreqMultiplication(uint32_t multi) { REG_WRITE(reg::kreg_ttlout3_pllout_freq_multiplication_ctrl, multi); }
|
|
xs_error_code_t Xsync::TTLOutputModule4_setFreqMultiplication(uint32_t multi) { REG_WRITE(reg::kreg_ttlout4_pllout_freq_multiplication_ctrl, multi); }
|
|
|
|
xs_error_code_t Xsync::TTLOutputModule1_getFreqMultiplication(uint32_t &multi) { REG_READ(reg::kreg_ttlout1_pllout_freq_multiplication_ctrl, multi); }
|
|
xs_error_code_t Xsync::TTLOutputModule2_getFreqMultiplication(uint32_t &multi) { REG_READ(reg::kreg_ttlout2_pllout_freq_multiplication_ctrl, multi); }
|
|
xs_error_code_t Xsync::TTLOutputModule3_getFreqMultiplication(uint32_t &multi) { REG_READ(reg::kreg_ttlout3_pllout_freq_multiplication_ctrl, multi); }
|
|
xs_error_code_t Xsync::TTLOutputModule4_getFreqMultiplication(uint32_t &multi) { REG_READ(reg::kreg_ttlout4_pllout_freq_multiplication_ctrl, multi); }
|
|
|
|
xs_error_code_t Xsync::TTLOutputModule1_readInFreq(float &freq) { return readfreq(reg::kreg_ttlout1_sig_in_freq_detect, freq); }
|
|
xs_error_code_t Xsync::TTLOutputModule2_readInFreq(float &freq) { return readfreq(reg::kreg_ttlout2_sig_in_freq_detect, freq); }
|
|
xs_error_code_t Xsync::TTLOutputModule3_readInFreq(float &freq) { return readfreq(reg::kreg_ttlout3_sig_in_freq_detect, freq); }
|
|
xs_error_code_t Xsync::TTLOutputModule4_readInFreq(float &freq) { return readfreq(reg::kreg_ttlout4_sig_in_freq_detect, freq); }
|
|
|
|
xs_error_code_t Xsync::TTLOutputModule1_readOutFreq(float &freq) { return readfreq(reg::kreg_ttlout1_sig_out_freq_detect, freq); }
|
|
xs_error_code_t Xsync::TTLOutputModule2_readOutFreq(float &freq) { return readfreq(reg::kreg_ttlout2_sig_out_freq_detect, freq); }
|
|
xs_error_code_t Xsync::TTLOutputModule3_readOutFreq(float &freq) { return readfreq(reg::kreg_ttlout3_sig_out_freq_detect, freq); }
|
|
xs_error_code_t Xsync::TTLOutputModule4_readOutFreq(float &freq) { return readfreq(reg::kreg_ttlout4_sig_out_freq_detect, freq); }
|
|
|
|
/*******************************************************************************
|
|
* TimecodeInputModule *
|
|
*******************************************************************************/
|
|
xs_error_code_t Xsync::ExternalTimecode_setSource(InputInterface_t src) {
|
|
if (src == INPUT_IF_TIMECODE_BNC) {
|
|
DO_XSYNC(reg_write(reg::external_timecode_sig_selt, 1, 10)); // 0:off,1:bnc,2:headphone
|
|
} else if (src == INPUT_IF_TIMECODE_HEADPHONE) {
|
|
DO_XSYNC(reg_write(reg::external_timecode_sig_selt, 2, 10)); // 0:off,1:bnc,2:headphone
|
|
} else if (src == INPUT_IF_OFF) {
|
|
DO_XSYNC(reg_write(reg::external_timecode_sig_selt, 0, 10)); // 0:off,1:bnc,2:headphone
|
|
} else {
|
|
return kxs_ec_param_error;
|
|
}
|
|
return kxs_ec_success;
|
|
}
|
|
xs_error_code_t Xsync::ExternalTimecode_getSource(InputInterface_t &timecode_select) {
|
|
uint32_t readbak = 0;
|
|
DO_XSYNC(reg_read(reg::external_timecode_sig_selt, readbak, 10));
|
|
if (readbak == 1) {
|
|
timecode_select = INPUT_IF_TIMECODE_BNC;
|
|
} else if (readbak == 2) {
|
|
timecode_select = INPUT_IF_TIMECODE_HEADPHONE;
|
|
} else if (readbak == 0) {
|
|
timecode_select = INPUT_IF_OFF;
|
|
} else {
|
|
timecode_select = INPUT_IF_OFF;
|
|
}
|
|
return kxs_ec_success;
|
|
}
|
|
xs_error_code_t Xsync::ExternalTimecode_setFormat(TimecodeFormat_t format) { REG_WRITE(reg::external_timecode_format, format); }
|
|
xs_error_code_t Xsync::ExternalTimecode_getFormat(TimecodeFormat_t &format) { REG_READ(reg::external_timecode_format, format); }
|
|
xs_error_code_t Xsync::ExternalTimecode_readCode(XsyncTimecode_t &timecode) { return readtimecode(reg::external_timecode_code0, reg::external_timecode_code1, timecode); }
|
|
|
|
/*******************************************************************************
|
|
* InternalTimecode *
|
|
*******************************************************************************/
|
|
xs_error_code_t Xsync::InternalTimecode_setFormat(TimecodeFormat_t format) { REG_WRITE(reg::internal_timecode_format, format); }
|
|
xs_error_code_t Xsync::InternalTimecode_getFormat(TimecodeFormat_t &format) { REG_READ(reg::internal_timecode_format, format); }
|
|
xs_error_code_t Xsync::InternalTimecode_setCode(XsyncTimecode_t timecode) {
|
|
DO_XSYNC(reg_write(reg::internal_timecode_en, 0));
|
|
DO_XSYNC(writetimecode(reg::internal_timecode_data0, reg::internal_timecode_data1, timecode));
|
|
DO_XSYNC(reg_write(reg::internal_timecode_en, 1));
|
|
return kxs_ec_success;
|
|
}
|
|
xs_error_code_t Xsync::InternalTimecode_getCode(XsyncTimecode_t &timecode) { return readtimecode(reg::internal_timecode_data0, reg::internal_timecode_data1, timecode); }
|
|
|
|
/*******************************************************************************
|
|
* SysTimecode *
|
|
*******************************************************************************/
|
|
xs_error_code_t Xsync::SysTimecode_setSource(uint32_t sig) { REG_WRITE(reg::sys_timecode_select, sig); }
|
|
xs_error_code_t Xsync::SysTimecode_getSource(uint32_t &sig) { REG_READ(reg::sys_timecode_select, sig); }
|
|
xs_error_code_t Xsync::SysTimecode_readFormat(TimecodeFormat_t &format) { REG_READ(reg::sys_timecode_format, format); }
|
|
xs_error_code_t Xsync::SysTimecode_readCode(XsyncTimecode_t &timecode) { return readtimecode(reg::sys_timecode_data0, reg::sys_timecode_data1, timecode); }
|
|
/*******************************************************************************
|
|
* TimecodeOutputModule *
|
|
*******************************************************************************/
|
|
xs_error_code_t Xsync::TimecodeOutputModule_setBncOutputLevel(int level) { REG_WRITE(reg::timecode_output_bnc_outut_level_select, level); }
|
|
xs_error_code_t Xsync::TimecodeOutputModule_getBncOutputLevel(int &level) { REG_READ(reg::timecode_output_bnc_outut_level_select, level); }
|
|
xs_error_code_t Xsync::TimecodeOutputModule_setHeadphoneOutputLevel(int level) { REG_WRITE(reg::timecode_output_headphone_outut_level_select, level); }
|
|
xs_error_code_t Xsync::TimecodeOutputModule_getHeadphoneOutputLevel(int &level) { REG_READ(reg::timecode_output_headphone_outut_level_select, level); }
|
|
/*******************************************************************************
|
|
* GENLOCK *
|
|
*******************************************************************************/
|
|
xs_error_code_t Xsync::ExternalGenlock_detectFreq(float &freq) { return readfreq(reg::external_genlock_freq, freq); }
|
|
xs_error_code_t Xsync::InternalGenlock_setFormat(GenlockFormat_t format) { return reg_write(reg::internal_genlock_format, format); }
|
|
xs_error_code_t Xsync::InternalGenlock_getFormat(GenlockFormat_t &format) { REG_READ(reg::internal_genlock_format, format); }
|
|
|
|
xs_error_code_t Xsync::SysGenlock_setSrc(uint32_t source) { return reg_write(reg::sys_genlock_source, source); }
|
|
xs_error_code_t Xsync::SysGenlock_getSrc(uint32_t &extern_or_internal) {
|
|
REG_READ(reg::sys_genlock_source, extern_or_internal);
|
|
return kxs_ec_success;
|
|
}
|
|
|
|
xs_error_code_t Xsync::SysGenlock_readFreq(float &freq) { return readfreq(reg::sys_genlock_freq, freq); }
|
|
|
|
/*******************************************************************************
|
|
* INTERNAL_CLOCK *
|
|
*******************************************************************************/
|
|
xs_error_code_t Xsync::InternalClock_setFreq(float freq) {
|
|
double T = 1.0 / freq;
|
|
double T_ns = T * 1000 * 1000 * 1000;
|
|
double cnt = T_ns / 100 + 0.5; // 10MHZ <=> 100ns
|
|
|
|
uint32_t cnt_u32 = uint32_t(cnt);
|
|
return reg_write(reg::internal_clock_freq, cnt_u32);
|
|
return kxs_ec_success;
|
|
}
|
|
xs_error_code_t Xsync::InternalClock_getFreq(float &freq) { return readfreq(reg::internal_clock_freq, freq); }
|
|
/*******************************************************************************
|
|
* SysClock *
|
|
*******************************************************************************/
|
|
xs_error_code_t Xsync::SysClock_setSrc(SignalType_t sig) {
|
|
if (sig != SIGNAL_TTLIN1 && //
|
|
sig != SIGNAL_TTLIN2 && //
|
|
sig != SIGNAL_TTLIN3 && //
|
|
sig != SIGNAL_TTLIN4 && //
|
|
sig != SIGNAL_SYS_CLK_OUTPUT && //
|
|
sig != SIGNAL_SYS_GENLOCK_OUTPUT && //
|
|
sig != SIGNAL_SYS_TIMECODE_FREQ_OUTPUT) {
|
|
return kxs_ec_param_error;
|
|
}
|
|
return reg_write(reg::sys_clock_source, sig);
|
|
}
|
|
xs_error_code_t Xsync::SysClock_getSrc(SignalType_t &sig) { REG_READ(reg::sys_clock_source, sig); }
|
|
xs_error_code_t Xsync::SysClock_setTriggerEdge(TriggerEdge_t edge) {
|
|
if (edge != TRIGGER_EDGE_RISING && edge != TRIGGER_EDGE_FALLING) {
|
|
return kxs_ec_param_error;
|
|
}
|
|
return reg_write(reg::sys_clock_trigger_edge_select, edge);
|
|
}
|
|
xs_error_code_t Xsync::SysClock_getTriggerEdge(TriggerEdge_t &edge) { return _reg_read(reg::sys_clock_trigger_edge_select, edge); }
|
|
xs_error_code_t Xsync::SysClock_setFreqDivision(uint32_t div) { return reg_write(reg::sys_clock_freq_division_ctrl, div); }
|
|
xs_error_code_t Xsync::SysClock_geFreqtDivision(uint32_t &div) { return _reg_read(reg::sys_clock_freq_division_ctrl, div); }
|
|
xs_error_code_t Xsync::SysClock_setFreqMultiplication(uint32_t muti) { return reg_write(reg::sys_clock_freq_multiplication_ctrl, muti); }
|
|
xs_error_code_t Xsync::SysClock_getFreqMultiplication(uint32_t &muti) { return _reg_read(reg::sys_clock_freq_multiplication_ctrl, muti); }
|
|
xs_error_code_t Xsync::SysClock_readOutSigFreq(float &freq) { return readfreq(reg::sys_clock_outfreq_detect, freq); }
|
|
xs_error_code_t Xsync::SysClock_readInSigFreq(float &freq) { return readfreq(reg::sys_clock_infreq_detect, freq); }
|
|
|
|
xs_error_code_t Xsync::RecordSigGenerator_setContrlMode(ControlMode_t mode) {
|
|
if (mode != CONTROLMODE_MANUAL_TRIGGER && mode != CONTROLMODE_TIMECODE_TRIGGER && mode != CONTROLMODE_EXTERNALTTL_TRIGGER) {
|
|
return kxs_ec_param_error;
|
|
}
|
|
return reg_write(reg::record_sig_gen_ctrl_control_mode, mode);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_getContrlMode(ControlMode_t &mode) { //
|
|
return _reg_read(reg::record_sig_gen_ctrl_control_mode, mode);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_manualStart() { return reg_write(reg::record_sig_gen_manual_ctrl, 1, 10); }
|
|
xs_error_code_t Xsync::RecordSigGenerator_manualStop() { return reg_write(reg::record_sig_gen_manual_ctrl, 0, 10); }
|
|
xs_error_code_t Xsync::RecordSigGenerator_setAutoStartTimecode(XsyncTimecode_t timecode) { //
|
|
return writetimecode(reg::record_sig_gen_timecode_start0, reg::record_sig_gen_timecode_start1, timecode);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_setAutoStopTimecode(XsyncTimecode_t timecode) { //
|
|
return writetimecode(reg::record_sig_gen_timecode_stop0, reg::record_sig_gen_timecode_stop1, timecode);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_getAutoStartTimecode(XsyncTimecode_t &timecode) { //
|
|
return readtimecode(reg::record_sig_gen_timecode_start0, reg::record_sig_gen_timecode_start1, timecode);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_getAutoStopTimecode(XsyncTimecode_t &timecode) { return readtimecode(reg::record_sig_gen_timecode_stop0, reg::record_sig_gen_timecode_stop1, timecode); }
|
|
|
|
xs_error_code_t Xsync::RecordSigGenerator_setExternalTTLTriggerSrc(InputInterface_t ttlPortNum) {
|
|
if (ttlPortNum != INPUT_IF_TTL1 && ttlPortNum != INPUT_IF_TTL2 && ttlPortNum != INPUT_IF_TTL3 && ttlPortNum != INPUT_IF_TTL4) {
|
|
return kxs_ec_param_error;
|
|
}
|
|
return reg_write(reg::record_sig_gen_ttlin_trigger_sig_source, ttlPortNum);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_getExternalTTLTriggerSrc(InputInterface_t &ttlPortNum) { //
|
|
return _reg_read(reg::record_sig_gen_ttlin_trigger_sig_source, ttlPortNum);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_setExternalTTLTriggerPolarity(uint32_t polarity) { //
|
|
return reg_write(reg::record_sig_gen_ttlin_trigger_level, polarity);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_getExternalTTLTriggerPolarity(uint32_t &polarity) { //
|
|
return _reg_read(reg::record_sig_gen_ttlin_trigger_level, polarity);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_setRecordExposureTime(uint32_t us) { //
|
|
return reg_write(reg::record_sig_gen_exposure_time, us);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_getRecordExposureTime(uint32_t &us) {
|
|
auto ret = reg_read(reg::record_sig_gen_exposure_time, us);
|
|
// us = us / 10;1
|
|
return ret;
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_setRecordExposureOffsetTime(uint32_t us) { return reg_write(reg::record_sig_gen_exposure_offset_time, us); }
|
|
xs_error_code_t Xsync::RecordSigGenerator_getRecordExposureOffsetTime(uint32_t &us) {
|
|
auto ret = reg_read(reg::record_sig_gen_exposure_offset_time, us);
|
|
// us = us / 10;
|
|
return ret;
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_setTimecodeCtrlFlag(uint32_t autoStart, uint32_t autoStop) { //
|
|
uint32_t flag = (autoStart & 0x01) | ((autoStop & 0x01) << 1);
|
|
return reg_write(reg::record_sig_gen_timecode_control_flag, flag);
|
|
}
|
|
xs_error_code_t Xsync::RecordSigGenerator_getTimecodeCtrlFlag(uint32_t &autoStart, uint32_t &autoStop) {
|
|
uint32_t flag = 0;
|
|
auto ret = reg_read(reg::record_sig_gen_timecode_control_flag, flag);
|
|
autoStart = flag & 0x01;
|
|
autoStop = (flag >> 1) & 0x01;
|
|
return ret;
|
|
}
|
|
|
|
xs_error_code_t Xsync::RecordSigGenerator_getRecordState(uint32_t &state) { return _reg_read(reg::record_sig_gen_record_state, state); }
|
|
xs_error_code_t Xsync::RecordSigGenerator_readTimecodeSnapshot(XsyncTimecode_t &timecode) { //
|
|
return readtimecode(reg::record_sig_gen_timecode_snapshot0, reg::record_sig_gen_timecode_snapshot1, timecode);
|
|
}
|
|
|
|
namespace xsync {
|
|
|
|
void XsyncInit(I_XSUDPFactory *xsync_udp_factory, string xsyncIp) {
|
|
Xsync::Ins().initialize(xsync_udp_factory);
|
|
Xsync::Ins().changeXsyncIp(xsyncIp);
|
|
}
|
|
IXsync *XsyncIns() { return &Xsync::Ins(); }
|
|
} // namespace xsync
|