Browse Source

update

master
zhaohe 2 years ago
parent
commit
0ea2130167
  1. 4
      CMakeLists.txt
  2. 2
      libxsync
  3. 31
      mainwindow.cpp
  4. 9
      mainwindow.h
  5. 136
      mainwindow.ui
  6. 7
      src/xsync_udp_factory_impl.cpp

4
CMakeLists.txt

@ -13,7 +13,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets console REQUIRED) 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 set(PROJECT_SOURCES
src/logger.cpp src/logger.cpp
@ -32,7 +32,7 @@ add_executable(xsync
${PROJECT_SOURCES} ${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 set_target_properties(xsync PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com

2
libxsync

@ -1 +1 @@
Subproject commit f3d9fc167d1c8b30e9dba173ee81daddd3707b40
Subproject commit da1c2b91ecf79de858132d1eca04da7569961ac1

31
mainwindow.cpp

@ -1,10 +1,9 @@
#include "mainwindow.h" #include "mainwindow.h"
#include <QDateTime> #include <QDateTime>
#include <QtConcurrent>
#include "./ui_mainwindow.h" #include "./ui_mainwindow.h"
#include "src/logger.hpp"
#include "src/xsync_udp_factory_impl.hpp"
using namespace iflytop; using namespace iflytop;
using namespace std; 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.reset(new ZQThread("test", [this]() { mainWindowsRun(); }));
m_thread->start(); m_thread->start();
// m_xsync.reset(new Xsync());
Xsync::Ins().initialize(XSyncUdpFactoryImpl::Ins());
} }
MainWindow::~MainWindow() { delete ui; } 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() { // void MainWindow::mainWindowsRun() { //
XSyncUdpFactoryImpl::Ins()->initialize(); 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); // ZLOGI(TAG, "receive from <%s:%d> (%d) :%s", from.ip.c_str(), from.port, data, length);
// xsudp->sendto(from, "hello\n", 5, NULL); // xsudp->sendto(from, "hello\n", 5, NULL);
// }); // });
} }

9
mainwindow.h

@ -28,6 +28,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
//
#include "src/logger.hpp"
#include "src/xsync_udp_factory_impl.hpp"
#include "src/zqthread.hpp" #include "src/zqthread.hpp"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -67,12 +70,14 @@ class MainWindow : public QMainWindow {
static void log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg); static void log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg);
private slots: private slots:
void append_log_slot(QString); void append_log_slot(QString);
void on_RefreshRegsButton_clicked();
void on_ClearLogButton_clicked();
void on_Connect2XsyncButton_clicked();
signals: signals:
void append_log_signal(QString str); void append_log_signal(QString str);
private: private:
void mainWindowsRun(); void mainWindowsRun();
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

136
mainwindow.ui

@ -14,39 +14,147 @@
<string>MainWindow</string> <string>MainWindow</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<widget class="QWidget" name="gridLayoutWidget">
<widget class="QTextBrowser" name="logbrowser">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>110</x>
<y>40</y>
<width>431</width>
<height>61</height>
<x>10</x>
<y>420</y>
<width>951</width>
<height>191</height>
</rect> </rect>
</property> </property>
<layout class="QGridLayout" name="reg_table"/>
</widget> </widget>
<widget class="QPushButton" name="refresh_regs_button">
<widget class="QPushButton" name="ClearLogButton">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>10</x>
<y>40</y>
<y>380</y>
<width>91</width> <width>91</width>
<height>31</height> <height>31</height>
</rect> </rect>
</property> </property>
<property name="text"> <property name="text">
<string>刷新寄存器</string>
<string>ClearLog</string>
</property> </property>
</widget> </widget>
<widget class="QTextBrowser" name="logbrowser">
<widget class="QPushButton" name="Connect2XsyncButton">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>91</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Connect2Xsync</string>
</property>
</widget>
<widget class="QLineEdit" name="IpInput">
<property name="geometry">
<rect>
<x>100</x>
<y>10</y>
<width>111</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>192.168.8.10</string>
</property>
<property name="readOnly">
<bool>false</bool>
</property>
</widget>
<widget class="QPushButton" name="RefreshRegsButton">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>560</x>
<y>40</y>
<width>461</width>
<height>351</height>
<x>0</x>
<y>50</y>
<width>91</width>
<height>31</height>
</rect> </rect>
</property> </property>
<property name="text">
<string>RefreshRegs</string>
</property>
</widget>
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>100</x>
<y>50</y>
<width>481</width>
<height>311</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>462</width>
<height>1000</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>1000</height>
</size>
</property>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>10</y>
<width>431</width>
<height>91</height>
</rect>
</property>
<layout class="QGridLayout" name="reg_table">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
</layout>
</widget>
</widget>
</widget> </widget>
</widget> </widget>
<widget class="QMenuBar" name="menubar"> <widget class="QMenuBar" name="menubar">

7
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}; struct sockaddr_in sockaddr = {0};
timeval timeout; 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) { if (setsockopt(m_sock_fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)) == -1) {
return kxs_ec_setsockopt_rx_timeout_fail; return kxs_ec_setsockopt_rx_timeout_fail;
} }
@ -115,6 +117,7 @@ xs_error_code_t XSUDP::startReceive(onMessage_t onMessage) {
} }
})); }));
m_zq_thread->start(); m_zq_thread->start();
return kxs_ec_success;
} }
xs_error_code_t XSUDP::stopReceive() { xs_error_code_t XSUDP::stopReceive() {

Loading…
Cancel
Save