diff --git a/CMakeLists.txt b/CMakeLists.txt index 45b16b5..22a4a0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ set(PROJECT_SOURCES src/logger.cpp src/main.cpp src/zqthread.cpp + src/QFunction.cpp mainwindow.cpp mainwindow.h mainwindow.ui diff --git a/README.md b/README.md new file mode 100644 index 0000000..db6e597 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +``` +Timecode测试 +端口:19903 +协议:UDP +消息 :01 00 00 00 05 02 08 00 +解析结果:08:25:00:01 + +xync测试 +端口:13014 +协议:UDP +消息 : +F0 00 20 00 00 00 00 FF 00 00 F0 42 17 00 00 00 E1 FF FF FF 01 00 00 00 78 00 00 00 00 00 00 00 E6 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 00 + + + + +``` \ No newline at end of file diff --git a/libxsync b/libxsync index 5a720b8..2cc98f9 160000 --- a/libxsync +++ b/libxsync @@ -1 +1 @@ -Subproject commit 5a720b8a84ea7f5aa7fdd269ffb125ef29fdbfad +Subproject commit 2cc98f9f617feb976e1f3f724489a1562dffb20d diff --git a/mainwindow.cpp b/mainwindow.cpp index ab6cca7..d05804e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -47,6 +47,19 @@ void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, c void MainWindow::append_log_slot(QString text) { ui->logbrowser->append(text); } +void MainWindow::updateUI_timeCodeInfo_slot(QString text) { ui->TimecodeDisplayer->setText(text); } +void MainWindow::updateUI_cameraSyncInfo_slot(QString text) { ui->CameraSyncIndex->setText(text); } +void MainWindow::updateUI_reg_slot(int32_t regadd, uint32_t regval) { + auto it = m_regdisplayer.find(regadd); + if (it != m_regdisplayer.end()) { + ZLOGI(TAG, "updateUI_reg_slot %x %d", regadd, regval); + it->second->regBrowser->setText(QString::number(regval, 16)); + } +} +void MainWindow::doinui_slot(QFunction func) { + if (func.get()) func.get()(); +} + void MainWindow::push_reg(QWidget *parent, int off, const char *regname, int32_t regadd, int32_t rwflag) { DispalyRegIterm *regitem = new DispalyRegIterm(); { @@ -58,7 +71,7 @@ void MainWindow::push_reg(QWidget *parent, int off, const char *regname, int32_t sizePolicy1.setVerticalStretch(0); sizePolicy1.setHeightForWidth(label->sizePolicy().hasHeightForWidth()); label->setSizePolicy(sizePolicy1); - label->setMinimumSize(QSize(100, 0)); + label->setMinimumSize(QSize(200, 0)); label->setMaximumSize(QSize(16777215, 16777215)); ui->reg_table->addWidget(label, off, 0, 1, 1); regitem->label = label; @@ -132,11 +145,16 @@ void MainWindow::push_reg(QWidget *parent, int off, const char *regname, int32_t void MainWindow::construct_reg_table() { // int regoff = 1; - push_reg(ui->gridLayoutWidget, regoff++, "reg1", 0x1000, 0); - push_reg(ui->gridLayoutWidget, regoff++, "reg1", 0x1001, 0); - push_reg(ui->gridLayoutWidget, regoff++, "reg1", 0x1002, 0); - push_reg(ui->gridLayoutWidget, regoff++, "reg1", 0x1003, 0); - push_reg(ui->gridLayoutWidget, regoff++, "reg1", 0x1004, 0); + + push_reg(ui->gridLayoutWidget, regoff++, "software_version", kxsync_reg_software_version, 0); + push_reg(ui->gridLayoutWidget, regoff++, "manufacturer0", kxsync_reg_manufacturer0, 0); + push_reg(ui->gridLayoutWidget, regoff++, "manufacturer1", kxsync_reg_manufacturer1, 0); + push_reg(ui->gridLayoutWidget, regoff++, "product_type_id", kxsync_reg_product_type_id, 0); + push_reg(ui->gridLayoutWidget, regoff++, "sn_id0", kxsync_reg_sn_id0, 0); + push_reg(ui->gridLayoutWidget, regoff++, "sn_id1", kxsync_reg_sn_id1, 0); + push_reg(ui->gridLayoutWidget, regoff++, "sn_id2", kxsync_reg_sn_id2, 0); + push_reg(ui->gridLayoutWidget, regoff++, "mac0", kxsync_reg_mac0, 0); + push_reg(ui->gridLayoutWidget, regoff++, "mac1", kxsync_reg_mac1, 0); // 设置table的高度 auto qrect = ui->gridLayoutWidget->geometry(); @@ -148,14 +166,36 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->setupUi(this); m_mainWindow = this; construct_reg_table(); - connect(this, SIGNAL(append_log_signal(QString)), this, SLOT(append_log_slot(QString))); qInstallMessageHandler(log_output); + qRegisterMetaType("int32_t"); + qRegisterMetaType("uint32_t"); + qRegisterMetaType>("function"); + qRegisterMetaType("QFunction"); + + XSyncUdpFactoryImpl::Ins()->initialize(); + connect(this, SIGNAL(append_log_signal(QString)), this, SLOT(append_log_slot(QString))); + connect(this, SIGNAL(updateUI_timeCodeInfo_signal(QString)), this, SLOT(updateUI_timeCodeInfo_slot(QString))); + connect(this, SIGNAL(updateUI_cameraSyncInfo_signal(QString)), this, SLOT(updateUI_cameraSyncInfo_slot(QString))); + connect(this, SIGNAL(updateUI_reg_signal(int32_t, uint32_t)), this, SLOT(updateUI_reg_slot(int32_t, uint32_t))); + connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); + m_thread.reset(new ZQThread("test", [this]() { mainWindowsRun(); })); m_thread->start(); // m_xsync.reset(new Xsync()); + Xsync::Ins().initialize(XSyncUdpFactoryImpl::Ins()); + Xsync::Ins().regOnTimecodeMsg([this](xysnc_timecode_t *timecode_msg) { // + xysnc_timecode_t timecode = *timecode_msg; + QString text = QString(fmt("%02d:%02d:%02d:%02d", timecode.hour, timecode.minute, timecode.second, timecode.frame)); + updateUI_timeCodeInfo_signal(text); + }); + + Xsync::Ins().regOnCameraSyncMsg([this](xysnc_camera_sync_data_t *camera_sync_msg) { // + xysnc_camera_sync_data_t camera_sync_data = *camera_sync_msg; + updateUI_cameraSyncInfo_signal(QString(fmt("%d", camera_sync_data.frameIndex))); + }); } MainWindow::~MainWindow() { delete ui; } @@ -171,16 +211,21 @@ MainWindow::~MainWindow() { delete ui; } void MainWindow::on_RefreshRegsButton_clicked() { // ZLOGI(TAG, "on_refreshRegsButton_clicked"); + // int32_t _t1, uint32_t _t2 QtConcurrent::run([this]() { bool suc = true; for (auto ® : m_regdisplayer) { uint32_t regValue = 0; auto ecode = Xsync::Ins().reg_read(reg.first, regValue); + int regoff = reg.first; + if (ecode == kxs_ec_success) { ZLOGI(TAG, "reg_read %x success", reg.first); - reg.second->regvalcache = regValue; - reg.second->regBrowser->setText(QString::number(regValue, 16)); + emit doinui_signal(QFunction([this, regoff, regValue]() { + m_regdisplayer[regoff]->regvalcache = regValue; + m_regdisplayer[regoff]->regBrowser->setText("0x" + QString::number(regValue, 16)); + })); } else { ZLOGE(TAG, "reg_read %x fail,ecode:%s", reg.first, xs_error_code_2_str(ecode)); suc = false; @@ -207,7 +252,7 @@ void MainWindow::on_Connect2XsyncButton_clicked() { // ZLOGI(TAG, "connect %s ecode:%s", ui->IpInput->text().toStdString().c_str(), xs_error_code_2_str(ecode)); } void MainWindow::mainWindowsRun() { // - XSyncUdpFactoryImpl::Ins()->initialize(); + // auto xsudp = XSyncUdpFactoryImpl::Ins()->createXSUDP(); // XS_ASSERT(xsudp->initialize("0.0.0.0", 9999)); // xsudp->startReceive([this, xsudp](XsyncNetAdd &from, uint8_t *data, size_t length) { diff --git a/mainwindow.h b/mainwindow.h index 2cb48a6..fe277b9 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -30,6 +30,7 @@ // #include "src/logger.hpp" +#include "src/qfunction.hpp" #include "src/xsync_udp_factory_impl.hpp" #include "src/zqthread.hpp" @@ -74,9 +75,17 @@ class MainWindow : public QMainWindow { void on_RefreshRegsButton_clicked(); void on_ClearLogButton_clicked(); void on_Connect2XsyncButton_clicked(); + void updateUI_timeCodeInfo_slot(QString); + void updateUI_cameraSyncInfo_slot(QString); + void updateUI_reg_slot(int32_t regadd, uint32_t regval); + void doinui_slot(QFunction); signals: void append_log_signal(QString str); + void updateUI_timeCodeInfo_signal(QString); + void updateUI_cameraSyncInfo_signal(QString); + void updateUI_reg_signal(int32_t regadd, uint32_t regval); + void doinui_signal(QFunction); private: void mainWindowsRun(); diff --git a/mainwindow.ui b/mainwindow.ui index 2ebc14e..ae83b0f 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -90,7 +90,7 @@ 100 50 - 481 + 671 311 @@ -129,7 +129,7 @@ 0 0 - 462 + 652 1000 @@ -144,7 +144,7 @@ 20 10 - 431 + 581 91 @@ -156,6 +156,26 @@ + + + + 470 + 10 + 141 + 31 + + + + + + + 620 + 10 + 141 + 31 + + + diff --git a/src/QFunction.cpp b/src/QFunction.cpp new file mode 100644 index 0000000..7a73688 --- /dev/null +++ b/src/QFunction.cpp @@ -0,0 +1,4 @@ +#include "qfunction.hpp" +QFunction::QFunction() : QObject(nullptr) {} +QFunction::QFunction(std::function func, QObject *parent) : m_func(func), QObject(parent) {} +std::function &QFunction::get() { return m_func; } diff --git a/src/QFunction.hpp b/src/QFunction.hpp new file mode 100644 index 0000000..d5fe2c3 --- /dev/null +++ b/src/QFunction.hpp @@ -0,0 +1,26 @@ +#ifndef QFUNCTION_HPP +#define QFUNCTION_HPP + +#include +#include +class QFunction : public QObject { + Q_OBJECT + + std::function m_func; + + public: + explicit QFunction(std::function func, QObject *parent = nullptr); + QFunction(); + QFunction(const QFunction &other) { m_func = other.m_func; } + QFunction &operator=(const QFunction &other) { + m_func = other.m_func; + return *this; + } + std::function &get(); + + // 拷贝构造函数 + + signals: +}; + +#endif // QFUNCTION_HPP diff --git a/src/xsync_udp_factory_impl.cpp b/src/xsync_udp_factory_impl.cpp index 3102cbe..f598b0d 100644 --- a/src/xsync_udp_factory_impl.cpp +++ b/src/xsync_udp_factory_impl.cpp @@ -120,11 +120,11 @@ xs_error_code_t XSUDP::receive(char* data, int32_t& length, XsyncNetAdd& from, i data[length] = 0; if (ret < 0) { - if (errno == EWOULDBLOCK || errno == EAGAIN) { + // if (errno == EWOULDBLOCK || errno == EAGAIN) { return kxs_ec_overtime; - } else { - return kxs_ec_receive_fail; - } + // } else { + // return kxs_ec_receive_fail; + // } } // inet_ntop(AF_INET, &(sockaddr.sin_addr), ip, INET_ADDRSTRLEN);