Browse Source

update

master
zhaohe 2 years ago
parent
commit
9eebbdd1ea
  1. 1
      CMakeLists.txt
  2. 17
      README.md
  3. 2
      libxsync
  4. 65
      mainwindow.cpp
  5. 9
      mainwindow.h
  6. 26
      mainwindow.ui
  7. 4
      src/QFunction.cpp
  8. 26
      src/QFunction.hpp
  9. 8
      src/xsync_udp_factory_impl.cpp

1
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

17
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
```

2
libxsync

@ -1 +1 @@
Subproject commit 5a720b8a84ea7f5aa7fdd269ffb125ef29fdbfad
Subproject commit 2cc98f9f617feb976e1f3f724489a1562dffb20d

65
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>("int32_t");
qRegisterMetaType<uint32_t>("uint32_t");
qRegisterMetaType<function<void()>>("function<void()>");
qRegisterMetaType<QFunction>("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 &reg : 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) {

9
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();

26
mainwindow.ui

@ -90,7 +90,7 @@
<rect>
<x>100</x>
<y>50</y>
<width>481</width>
<width>671</width>
<height>311</height>
</rect>
</property>
@ -129,7 +129,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>462</width>
<width>652</width>
<height>1000</height>
</rect>
</property>
@ -144,7 +144,7 @@
<rect>
<x>20</x>
<y>10</y>
<width>431</width>
<width>581</width>
<height>91</height>
</rect>
</property>
@ -156,6 +156,26 @@
</widget>
</widget>
</widget>
<widget class="QTextBrowser" name="TimecodeDisplayer">
<property name="geometry">
<rect>
<x>470</x>
<y>10</y>
<width>141</width>
<height>31</height>
</rect>
</property>
</widget>
<widget class="QTextBrowser" name="CameraSyncIndex">
<property name="geometry">
<rect>
<x>620</x>
<y>10</y>
<width>141</width>
<height>31</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">

4
src/QFunction.cpp

@ -0,0 +1,4 @@
#include "qfunction.hpp"
QFunction::QFunction() : QObject(nullptr) {}
QFunction::QFunction(std::function<void()> func, QObject *parent) : m_func(func), QObject(parent) {}
std::function<void()> &QFunction::get() { return m_func; }

26
src/QFunction.hpp

@ -0,0 +1,26 @@
#ifndef QFUNCTION_HPP
#define QFUNCTION_HPP
#include <QObject>
#include <functional>
class QFunction : public QObject {
Q_OBJECT
std::function<void()> m_func;
public:
explicit QFunction(std::function<void()> 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<void()> &get();
// 拷贝构造函数
signals:
};
#endif // QFUNCTION_HPP

8
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);

Loading…
Cancel
Save