From 0ea213016751f28c9af745568273cfdcb2de8621 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Fri, 5 Jan 2024 14:46:16 +0800 Subject: [PATCH] update --- CMakeLists.txt | 4 +- libxsync | 2 +- mainwindow.cpp | 31 ++++++++-- mainwindow.h | 9 ++- mainwindow.ui | 136 ++++++++++++++++++++++++++++++++++++----- src/xsync_udp_factory_impl.cpp | 7 ++- 6 files changed, 164 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0030f36..45b16b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets console REQUIRED) -find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Charts REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Charts Concurrent REQUIRED) set(PROJECT_SOURCES src/logger.cpp @@ -32,7 +32,7 @@ add_executable(xsync ${PROJECT_SOURCES} ) -target_link_libraries(xsync PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Charts wsock32) +target_link_libraries(xsync PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Charts Qt${QT_VERSION_MAJOR}::Concurrent wsock32) set_target_properties(xsync PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com diff --git a/libxsync b/libxsync index f3d9fc1..da1c2b9 160000 --- a/libxsync +++ b/libxsync @@ -1 +1 @@ -Subproject commit f3d9fc167d1c8b30e9dba173ee81daddd3707b40 +Subproject commit da1c2b91ecf79de858132d1eca04da7569961ac1 diff --git a/mainwindow.cpp b/mainwindow.cpp index e070288..0dc4d8d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,10 +1,9 @@ #include "mainwindow.h" #include +#include #include "./ui_mainwindow.h" -#include "src/logger.hpp" -#include "src/xsync_udp_factory_impl.hpp" using namespace iflytop; using namespace std; @@ -105,6 +104,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi m_thread.reset(new ZQThread("test", [this]() { mainWindowsRun(); })); m_thread->start(); + + // m_xsync.reset(new Xsync()); + Xsync::Ins().initialize(XSyncUdpFactoryImpl::Ins()); } MainWindow::~MainWindow() { delete ui; } @@ -118,6 +120,29 @@ MainWindow::~MainWindow() { delete ui; } } \ } +void MainWindow::on_RefreshRegsButton_clicked() { // + ZLOGI(TAG, "on_refreshRegsButton_clicked"); + + // QtConcurrent::run([this]() { + // while (true) { + // ZLOGI(TAG, "on_refreshRegsButton_clicked......"); + // ZQThread::sleep(1); + // auto ecode = Xsync::Ins().reg_write(0xABCDDCBA, 0x12345678); + // ZLOGI(TAG, "reg_read ecode:%s", xs_error_code_2_str(ecode)); + // } + // }); + + // xs_error_code_t ecode = Xsync::Ins().reg_write(0xABCDDCBA, 0x12345678); + // ZLOGI(TAG, "reg_write ecode:%s", xs_error_code_2_str(ecode)); +} +void MainWindow::on_ClearLogButton_clicked() { // + ui->logbrowser->clear(); +} +void MainWindow::on_Connect2XsyncButton_clicked() { // + ZLOGI(TAG, "connect %s", ui->IpInput->text().toStdString().c_str()); + xs_error_code_t ecode = Xsync::Ins().connect(ui->IpInput->text().toStdString()); + ZLOGI(TAG, "connect %s ecode:%s", ui->IpInput->text().toStdString().c_str(), xs_error_code_2_str(ecode)); +} void MainWindow::mainWindowsRun() { // XSyncUdpFactoryImpl::Ins()->initialize(); @@ -127,6 +152,4 @@ void MainWindow::mainWindowsRun() { // // ZLOGI(TAG, "receive from <%s:%d> (%d) :%s", from.ip.c_str(), from.port, data, length); // xsudp->sendto(from, "hello\n", 5, NULL); // }); - - } diff --git a/mainwindow.h b/mainwindow.h index 77e9b70..4e6edd5 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -28,6 +28,9 @@ #include #include +// +#include "src/logger.hpp" +#include "src/xsync_udp_factory_impl.hpp" #include "src/zqthread.hpp" QT_BEGIN_NAMESPACE @@ -67,12 +70,14 @@ class MainWindow : public QMainWindow { static void log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg); private slots: void append_log_slot(QString); + void on_RefreshRegsButton_clicked(); + void on_ClearLogButton_clicked(); + void on_Connect2XsyncButton_clicked(); + signals: void append_log_signal(QString str); private: - void mainWindowsRun(); - }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index f230311..2ebc14e 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -14,39 +14,147 @@ MainWindow - + - 110 - 40 - 431 - 61 + 10 + 420 + 951 + 191 - - + 10 - 40 + 380 91 31 - 刷新寄存器 + ClearLog - + + + + 0 + 10 + 91 + 31 + + + + Connect2Xsync + + + + + + 100 + 10 + 111 + 31 + + + + + 75 + true + + + + 192.168.8.10 + + + false + + + - 560 - 40 - 461 - 351 + 0 + 50 + 91 + 31 + + RefreshRegs + + + + + + 100 + 50 + 481 + 311 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::ScrollBarAlwaysOn + + + Qt::ScrollBarAlwaysOn + + + QAbstractScrollArea::AdjustIgnored + + + true + + + + + 0 + 0 + 462 + 1000 + + + + + 0 + 1000 + + + + + + 20 + 10 + 431 + 91 + + + + + QLayout::SetNoConstraint + + + + diff --git a/src/xsync_udp_factory_impl.cpp b/src/xsync_udp_factory_impl.cpp index b10ed38..9248011 100644 --- a/src/xsync_udp_factory_impl.cpp +++ b/src/xsync_udp_factory_impl.cpp @@ -69,8 +69,10 @@ xs_error_code_t XSUDP::receive(char* data, int32_t& length, XsyncNetAdd& from, i struct sockaddr_in sockaddr = {0}; timeval timeout; - timeout.tv_sec = overtimems / 1000; - timeout.tv_usec = overtimems % 1000 * 1000; + // timeout.tv_sec = overtimems / 1000; + timeout.tv_sec = 1; + // timeout.tv_usec = overtimems % 1000 * 1000; + timeout.tv_usec = 0; if (setsockopt(m_sock_fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)) == -1) { return kxs_ec_setsockopt_rx_timeout_fail; } @@ -115,6 +117,7 @@ xs_error_code_t XSUDP::startReceive(onMessage_t onMessage) { } })); m_zq_thread->start(); + return kxs_ec_success; } xs_error_code_t XSUDP::stopReceive() {