diff --git a/.vscode/settings.json b/.vscode/settings.json index 8f8faba..34b1ece 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -81,7 +81,12 @@ "qcoreapplication": "cpp", "qcategoryaxis": "cpp", "qaction": "cpp", - "qthread": "cpp" + "qthread": "cpp", + "zaf_ecode.h": "c", + "qserialport": "cpp", + "qserialportinfo": "cpp", + "qmessagebox": "cpp" }, "files.autoGuessEncoding": true, + "files.encoding": "gbk", } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 2738fc6..40ccb3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,15 +17,23 @@ find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets SerialPort Charts Concurre include_directories(libxsync/include) include_directories(src) +include_directories(./) +include_directories(libzqt) set(PROJECT_SOURCES - src/logger.cpp + libzqt/logger.cpp + libzqt/zqthread.cpp + libzqt/QFunction.cpp + src/main.cpp - src/zqthread.cpp - src/QFunction.cpp mainwindow.cpp mainwindow.h mainwindow.ui + + src/camera_light_src_timing_controller/clst_controler.cpp + src/camera_light_src_timing_controller/qt_serial_datachannel.cpp + zaf_protocol/zaf_ecode.c + zaf_protocol/zaf_protocol.c # libxsync/src/xsync_v2.cpp # src/xsync_udp_factory_impl.cpp # libxsync/src/xsync_v2_sig_type.cpp diff --git a/libzaf/include/zaf.hpp b/libzaf/include/zaf.hpp deleted file mode 100644 index e8e9e09..0000000 --- a/libzaf/include/zaf.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -namespace iflytop { -using namespace std; - - - -} // namespace iflytop \ No newline at end of file diff --git a/libzaf/src/zaf.cpp b/libzaf/src/zaf.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/QFunction.cpp b/libzqt/QFunction.cpp similarity index 100% rename from src/QFunction.cpp rename to libzqt/QFunction.cpp diff --git a/src/QFunction.hpp b/libzqt/QFunction.hpp similarity index 100% rename from src/QFunction.hpp rename to libzqt/QFunction.hpp diff --git a/src/logger.cpp b/libzqt/logger.cpp similarity index 100% rename from src/logger.cpp rename to libzqt/logger.cpp diff --git a/src/logger.hpp b/libzqt/logger.hpp similarity index 100% rename from src/logger.hpp rename to libzqt/logger.hpp diff --git a/src/zqthread.cpp b/libzqt/zqthread.cpp similarity index 100% rename from src/zqthread.cpp rename to libzqt/zqthread.cpp diff --git a/src/zqthread.hpp b/libzqt/zqthread.hpp similarity index 100% rename from src/zqthread.hpp rename to libzqt/zqthread.hpp diff --git a/mainwindow.cpp b/mainwindow.cpp index 59cafdc..586cb28 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,16 +1,18 @@ #include "mainwindow.h" #include +#include #include #include #include #include "./ui_mainwindow.h" +#include "camera_light_src_timing_controller/qt_serial_datachannel.hpp" #include "logger.hpp" #include "xsync_regs.hpp" using namespace iflytop; -using namespace xsync; +using namespace clst; using namespace std; static MainWindow *m_mainWindow; @@ -29,7 +31,6 @@ static const uint32_t str2int(QString str) { // 如果0x开头,按16进制转换 // 如果0b开头,按2进制转换 // 否则按10进制转换 - // 去除掉str中_ str.remove("_"); @@ -43,6 +44,8 @@ static const uint32_t str2int(QString str) { return str.toUInt(nullptr, 10); } } +static QSerialPort G_SerialPort; +static QTDataChannel G_QTDataChannel; void MainWindow::log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg) { // QString text; @@ -53,7 +56,73 @@ void MainWindow::doinui_slot(QFunction func) { if (func.get()) func.get()(); } +void MainWindow::constructUI() { + /******************************************************************************* + * serialPortCB * + *******************************************************************************/ + const auto infos = QSerialPortInfo::availablePorts(); + for (const QSerialPortInfo &info : infos) { + ui->serialPortCB->addItem(info.portName()); + } + + /******************************************************************************* + * 波特率填充 * + *******************************************************************************/ + ui->serialBaudrateCB->addItem("9600"); + ui->serialBaudrateCB->addItem("14400"); + ui->serialBaudrateCB->addItem("19200"); + ui->serialBaudrateCB->addItem("38400"); + ui->serialBaudrateCB->addItem("57600"); + ui->serialBaudrateCB->addItem("115200"); + ui->serialBaudrateCB->setCurrentIndex(5); + + /******************************************************************************* + * 刷新串口 * + *******************************************************************************/ + connect(ui->serialPortRefreshKey, &QPushButton::clicked, this, [this](bool check) { + ui->serialPortCB->clear(); + const auto infos = QSerialPortInfo::availablePorts(); + for (const QSerialPortInfo &info : infos) { + ui->serialPortCB->addItem(info.portName()); + } + }); + + /******************************************************************************* + * 打开串口 * + *******************************************************************************/ + connect(ui->serialOpenKey, &QPushButton::clicked, this, [=](bool check) { + // 打开串口 + if (ui->serialOpenKey->text() == "打开") { + G_SerialPort.setPortName(ui->serialPortCB->currentText()); + if (G_SerialPort.open(QIODevice::ReadWrite)) { + G_SerialPort.setBaudRate(ui->serialBaudrateCB->currentText().toInt()); + G_SerialPort.setDataBits(QSerialPort::Data8); + G_SerialPort.setParity(QSerialPort::NoParity); + G_SerialPort.setFlowControl(QSerialPort::NoFlowControl); + G_SerialPort.setStopBits(QSerialPort::OneStop); + } else { + QMessageBox::about(NULL, "提示", "串口无法打开,串口不存在或已被占用"); + return; + } + ui->serialOpenKey->setText("关闭"); + // 下拉菜单控件使能 + ui->serialBaudrateCB->setEnabled(false); + ui->serialPortCB->setEnabled(false); + ui->serialPortRefreshKey->setEnabled(false); + } else { + G_SerialPort.close(); + ui->serialOpenKey->setText("打开"); + ui->serialBaudrateCB->setEnabled(true); + ui->serialPortCB->setEnabled(true); + ui->serialPortRefreshKey->setEnabled(true); + } + }); +} + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { + G_QTDataChannel.bind(&G_SerialPort); + CLSTControler::ins()->initialize(&G_QTDataChannel); + ui->setupUi(this); m_mainWindow = this; @@ -63,32 +132,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi qRegisterMetaType("QFunction"); // qInstallMessageHandler(log_output); connect(this, SIGNAL(doinui_signal(QFunction)), this, SLOT(doinui_slot(QFunction))); - - /** - * @brief 填充部分UI - */ - - // ZLOG - // ZLOGI(TAG, "Hello"); - // QSerialPort *serialPort; - // const auto infos = QSerialPortInfo::availablePorts(); - // for(const QSerialPortInfo &info : infos) - // { - // ZLOGI(TAG,"PortName:%s",info.portName().toStdString().c_str()); - // QSerialPort serial; - // serial.setPort(info); - // if(serial.open(QIODevice::ReadWrite)) - // { - // // ui->PortBox->addItem(info.portName()); - // serial.close(); - // } - // } - - /******************************************************************************* - * 连接信号与槽 * - *******************************************************************************/ - - // XSyncUdpFactoryImpl::Ins()->initialize(); + constructUI(); } MainWindow::~MainWindow() { delete ui; } \ No newline at end of file diff --git a/mainwindow.h b/mainwindow.h index 08bed1d..c928469 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -29,10 +29,9 @@ #include // -#include "src/logger.hpp" -#include "src/qfunction.hpp" -#include "src/xsync_udp_factory_impl.hpp" -#include "src/zqthread.hpp" +#include "logger.hpp" +#include "qfunction.hpp" +#include "zqthread.hpp" QT_BEGIN_NAMESPACE namespace Ui { @@ -85,5 +84,6 @@ class MainWindow : public QMainWindow { private: static void log_output(QtMsgType type, const QMessageLogContext &context, const QString &msg); + void constructUI(); }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 43439b0..bd5d175 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 1135 - 897 + 1004 + 723 @@ -19,2616 +19,481 @@ MainWindow - + - + 0 - 1 + 0 - - - 0 - 50 - - - - - 16777215 - 50 - - - - - Connect2Xsync - - - - - - - - 150 - 16777215 - - - - - 75 - true - - - - 192.168.8.10 - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - timecode: - - - - - - - - 100 - 16777215 - - - - - - - - camera_sync: - - - - - - - - 50 - 16777215 - - - - - - - - workstate: - - - - - - - - 0 - 0 - - - + + - 50 - 16777215 + 200 + 0 - - - 75 - true - - - - - - - true - - - - - - 100 + 200 16777215 - - - - - - - - - - 0 - 30 - - - - 4 - - - - TTL - - - - - 20 - 10 - 321 - 181 - - - - TTL_IN - - - - - 10 - 20 - 101 - 31 - - - - ttl1_freq - - - - - - 10 - 60 - 101 - 31 - - - - ttl2_freq - - - - - - 10 - 100 - 91 - 31 - - - - ttl3_freq - - - - - - 10 - 140 - 91 - 31 - - - - ttl4_freq - - - - - - 100 - 20 - 111 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 100 - 60 - 111 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 100 - 100 - 111 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 100 - 140 - 111 - 31 - - - - - 75 - true - - - - - - - false - - - - - - - 20 - 210 - 401 - 211 - - - - TTL_OUT_1 - - - - - 20 - 30 - 61 - 31 - - - - source - - - - - - 70 - 30 - 211 - 31 - - - - -1 - - - - - - 70 - 70 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 70 - 110 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 70 - 61 - 31 - - - - 分频 - - - - - - 20 - 110 - 61 - 31 - - - - 倍频 - - - - - - 110 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 320 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 160 - 81 - 31 - - - - 输入信号频率 - - - - - - 230 - 160 - 81 - 31 - - - - 输出信号频率 - - - - - - - 440 - 210 - 401 - 211 - - - - TTL_OUT_2 - - - - - 20 - 30 - 61 - 31 - - - - source - - - - - - 70 - 30 - 211 - 31 - - - - -1 - - - - - - 70 - 70 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 70 - 110 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 70 - 61 - 31 - - - - 分频 - - - - - - 20 - 110 - 61 - 31 - - - - 倍频 - - - - - - 110 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 320 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 160 - 81 - 31 - - - - 输入信号频率 - - - - - - 230 - 160 - 81 - 31 - - - - 输出信号频率 - - - - - - - 20 - 430 - 401 - 211 - - - - TTL_OUT_3 - - - - - 20 - 30 - 61 - 31 - - - - source - - - - - - 70 - 30 - 211 - 31 - - - - -1 - - - - - - 70 - 70 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 70 - 110 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 70 - 61 - 31 - - - - 分频 - - - - - - 20 - 110 - 61 - 31 - - - - 倍频 - - - - - - 110 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 320 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 160 - 81 - 31 - - - - 输入信号频率 - - - - - - 230 - 160 - 81 - 31 - - - - 输出信号频率 - - - - - - - 440 - 430 - 401 - 211 - - - - TTL_OUT_4 - - - - - 20 - 30 - 61 - 31 - - - - source - - - - - - 70 - 30 - 211 - 31 - - - - -1 - - - - - - 70 - 70 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 70 - 110 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 70 - 61 - 31 - - - - 分频 - - - - - - 20 - 110 - 61 - 31 - - - - 倍频 - - - - - - 110 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 320 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 160 - 81 - 31 - - - - 输入信号频率 - - - - - - 230 - 160 - 81 - 31 - - - - 输出信号频率 - - - - - - - 440 - 30 - 101 - 31 - - - - Read - - - - - - 440 - 70 - 101 - 31 - - - - Write - - - - - - Timecode - - - - - 630 - 90 - 111 - 41 - - - - 写入配置 - - - - - - 630 - 50 - 111 - 41 - - - - 读出配置 - - - - - - 30 - 40 - 251 - 111 - - - - 内部时码 - - - - - 20 - 20 - 81 - 31 - - - - 时码格式 - - - - - - 20 - 60 - 81 - 31 - - - - 时码数值 - - - - - - 100 - 20 - 141 - 31 - - - - - - - 100 - 60 - 141 - 31 - - - - - 75 - true - - - - - - - false - - - - - - - 120 - 260 - 301 - 151 - - - - 系统时码 - - - - - 30 - 20 - 81 - 31 - - - - 系统时码_源 - - - - - - 30 - 60 - 81 - 31 - - - - 时码格式 - - - - - - 30 - 100 - 81 - 31 - - - - 时码数值 - - - - - - 130 - 20 - 141 - 31 - - - - - - - 130 - 100 - 141 - 31 - - - - - 75 - true - - - - - - - true - - - - - - 130 - 60 - 141 - 31 - - - - - 75 - true - - - - - - - true - - - - - - - 320 - 40 - 251 - 151 - - - - 外部时码 - - - - - 20 - 60 - 81 - 31 - - - - 时码格式 - - - - - - 100 - 60 - 141 - 31 - - - - - - - 100 - 100 - 141 - 31 - - - - - 75 - true - - - - - - - true - - - - - - 20 - 100 - 51 - 31 - - - - 时码数值 - - - - - - 100 - 20 - 141 - 31 - - - - - - - 20 - 20 - 81 - 31 - - - - 时码源 - - - - - - - 150 - 230 - 261 - 20 - - - - Qt::Horizontal - - - - - - 140 - 150 - 20 - 91 - - - - ArrowCursor - - - Qt::Vertical - - - - - - 400 - 190 - 20 - 51 - - - - ArrowCursor - - - Qt::Vertical - - - - - - 260 - 241 - 20 - 20 - - - - ArrowCursor - - - Qt::Vertical - - - - - - 160 - 170 - 16 - 21 - - - - 0 - - - - - - 390 - 200 - 16 - 21 - - - - 1 - - - - - - Genlock - - - - - 560 - 30 - 81 - 31 - - - - Read - - - - - - 560 - 70 - 81 - 31 - - - - Update - - - - - - 20 - 30 - 261 - 91 - - - - 内部GENLOCK - - - - - 100 - 20 - 151 - 31 - - - - -1 - - - - - - 20 - 20 - 41 - 31 - - - - Format - - - - - - - 300 - 30 - 221 - 91 - - - - 外部-GENLOCK - - - - - 20 - 20 - 41 - 31 - - - - Freq - - - - - - 60 - 20 - 151 - 31 - - - - - 75 - true - - - - - - - false - - - - - - - 160 - 160 - 271 - 121 - - - - SYS-GENLOCK - - - - - 100 - 20 - 151 - 31 - - - - -1 - - - - - - 20 - 20 - 41 - 31 - - - - SRC - - - - - - 20 - 60 - 41 - 31 - - - - Freq - - - - - - 100 - 60 - 151 - 31 - - - - - 75 - true - - - - - - - false - - - - - - - SysClock - - - - - 130 - 170 - 401 - 211 - - - - SYS_CLK - - - - - 20 - 30 - 61 - 31 - - - - source - - - - - - 70 - 30 - 211 - 31 - - - - -1 - - - - - - 70 - 70 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 70 - 110 - 211 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 70 - 61 - 31 - - - - 分频 - - - - - - 20 - 110 - 61 - 31 - - - - 倍频 - - - - - - 110 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 320 - 160 - 61 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 160 - 81 - 31 - - - - 输入信号频率 - - - - - - 230 - 160 - 81 - 31 - - - - 输出信号频率 - - - - - - - 390 - 40 - 221 - 81 - - - - 内部时钟发生器 - - - - - 10 - 20 - 41 - 31 - - - - Freq - - - - - - 50 - 20 - 151 - 31 - - - - - 75 - true - - - - - - - false - - - - - - - 40 - 40 - 71 - 41 - - - - TTL_IN - - - - - - 130 - 40 - 91 - 41 - - - - SYS_GENLOCK - - - - - - 230 - 40 - 101 - 41 - - - - SYS_TIMECODE - - - - - - 660 - 30 - 81 - 31 - - - - Read - - - - - - 660 - 70 - 81 - 31 - - - - Write - - - - - - RecordSigGen - - - - - 100 - 30 - 241 - 31 - - - - -1 - - - - - - 800 - 30 - 151 - 41 - - - - Read - - - - - - 30 - 30 - 101 - 31 - - - - 控制模式 - - - - - - 800 - 70 - 151 - 41 - - - - Write - - - - - - 20 - 230 - 261 - 141 - - - - 时码控制 - - - - - 20 - 20 - 81 - 31 - - - - 启动时间 - - - - - - 20 - 60 - 81 - 31 - - - - 停止时间 - - - - - - 110 - 60 - 141 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 110 - 20 - 141 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 20 - 110 - 71 - 16 - - - - 自动启动 - - - - - - 110 - 110 - 71 - 16 - - - - 自动停止 - - - - - - - 360 - 230 - 261 - 141 - - - - 手动控制 - - - - - 60 - 30 - 151 - 41 - - - - 启动录制 - - - - - - 60 - 80 - 151 - 41 - - - - 停止录制 - - - - - - - 670 - 230 - 261 - 141 - - - - 外部TTL触发控制 - - - - - 20 - 20 - 81 - 31 - - - - TTL_index - - - - - - 20 - 60 - 81 - 31 - - - - 触发电平 - - - - - - 110 - 60 - 141 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 110 - 20 - 141 - 31 - - - - -1 - - - - - - - 430 - 20 - 271 - 111 - - - - 曝光信号配置 - - - - - 20 - 20 - 81 - 31 - - - - 曝光时间(us) - - - - - - 20 - 60 - 81 - 31 - - - - 偏移时间(us) - - - - - - 110 - 60 - 141 - 31 - - - - - 75 - true - - - - - - - false - - - - - - 110 - 20 - 141 - 31 - - - - - 75 - true - - - - - - - false - - - - - - - 100 - 70 - 141 - 31 - - - - - 75 - true - - - - - - - true - - - - - - 30 - 70 - 101 - 31 - - - - 录制状态 - - - - - - 30 - 110 - 121 - 31 - - - - 启停事件时间戳快照 - - - - - - 160 - 110 - 141 - 31 - - - - - 75 - true - - - - - - - true - - - - - - 寄存器 - - - - - - - 0 - 0 - - - - - 0 - 30 - - - - RefreshRegs - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Qt::ScrollBarAlwaysOn - - - Qt::ScrollBarAlwaysOn - - - QAbstractScrollArea::AdjustIgnored - - - true - - - - - 0 - 0 - 1074 - 10000 - - - - - 0 - 10000 - - - - - - 20 - 10 - 581 - 91 - + + + + + + 16777215 + 16777215 + + + + 串口设置 - - - QLayout::SetNoConstraint - + + + + + + + + 打开 + + + + + + + + + + 波特率 + + + + + + + 串口 + + + + + + + 刷新 + + + - - - - - - - - IP配置 - - - - - 20 - 20 - 101 - 31 - - - - GenNewMac - - - - - - 20 - 60 - 101 - 31 - - - - FactoryReset - - - - - - 20 - 100 - 101 - 31 - - - - Reboot - - - - - - 20 - 140 - 101 - 31 - - - - ChangeNetCfg - - - - - - 130 - 140 - 111 - 31 - - - - - 75 - true - - - - 192.168.8.10 - - - false - - - - - - 250 - 140 - 111 - 31 - - - - - 75 - true - - - - 255.255.255.0 - - - false - - - - - - 370 - 140 - 111 - 31 - - - - - 75 - true - - - - 192.168.8.1 - - - false - - - - - - - - - - 0 - 8 - - - - - - - - 0 - 0 - - - - ClearLog - + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + false + + + 状态 + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 设备连接状态 + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 2 + + + + + + + + + + 信息栏 + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + false + + + + + + + + + + + 0 + 0 + + + + 功能按键 + + + + + + 刷新页面 + + + + + + + 保存配置 + + + + + + + 重启设备 + + + + + + + 恢复出厂设置 + + + + + + + + + + + 0 + 0 + + + + 寄存器操作 + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 读数值 + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 地址 + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 写数值 + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 2 + + + + + + + 读寄存器 + + + + + + + 写寄存器 + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 2 + + + + + + + + 0 + 0 + + + + + 0 + 25 + + + + + 16777215 + 25 + + + + 2 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + - + + + + + + + 0 + 10 + + + + 0 + + + + Tab 1 + + + + + Tab 2 + + + + + + + + + 0 + 1 + + + + + 0 + 100 + + + + + + + content + sidebar @@ -2638,7 +503,7 @@ 0 0 - 1135 + 1004 23 diff --git a/src/camera_light_src_timing_controller/clst.cpp b/src/camera_light_src_timing_controller/clst.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/camera_light_src_timing_controller/clst.hpp b/src/camera_light_src_timing_controller/clst.hpp deleted file mode 100644 index 805e23a..0000000 --- a/src/camera_light_src_timing_controller/clst.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace iflytop { -using namespace std; - -class IXsync { - public: - virtual ~IXsync() {} - - public: -// /*********************************************************************************************** -// * 设备基本操作 * -// ***********************************************************************************************/ - -// virtual xs_error_code_t changeXsyncIp(string xsync_ip) = 0; -// virtual bool ping() = 0; - -// virtual xs_error_code_t generatorNewMac() = 0; -// virtual xs_error_code_t factoryReset() = 0; -// virtual xs_error_code_t reboot() = 0; -// virtual xs_error_code_t changeNetworkConfig(string ip, string mask, string gateway) = 0; -// virtual xs_error_code_t readSn(string &sn) = 0; -// virtual xs_error_code_t readMac(string &mac) = 0; - -// public: -// virtual xs_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms = 100) = 0; -// virtual xs_error_code_t reg_read(uint32_t regadd, uint32_t ®value, int32_t overtime_ms = 100) = 0; - - public: -}; - -} // namespace xsync \ No newline at end of file diff --git a/src/camera_light_src_timing_controller/clst_controler.cpp b/src/camera_light_src_timing_controller/clst_controler.cpp new file mode 100644 index 0000000..fa658ff --- /dev/null +++ b/src/camera_light_src_timing_controller/clst_controler.cpp @@ -0,0 +1,313 @@ +#include "clst_controler.hpp" + +#include +#include + +#include "logger.hpp" +using namespace iflytop; +using namespace clst; + +#define TAG "CLSTControler" + +CLSTControler *CLSTControler::ins() { + static CLSTControler *ins = nullptr; + if (ins == nullptr) { + ins = new CLSTControler(); + } + return ins; +} + +void CLSTControler::initialize(IDataChannel *channel) { // + m_channel = channel; + m_channel->regRxListener([this](uint8_t *data, size_t len) { + { + lock_guard lock(lock_); + if (len + m_rxlen > sizeof(m_rxcache)) { + m_rxlen = 0; + } + memcpy(m_rxcache + m_rxlen, data, len); + m_rxlen += len; + } + }); + + m_thread.reset(new thread([this]() { + uint32_t last_rx_cnt = 0; + uint8_t rx_process_cache[1024]; + uint32_t rx_process_cache_len; + while (true) { + this_thread::sleep_for(chrono::milliseconds(5)); + + { + lock_guard lock(lock_); + if (last_rx_cnt == m_rxlen && m_rxlen != 0) { + memcpy(rx_process_cache, m_rxcache, m_rxlen); + rx_process_cache_len = m_rxlen; + + m_rxlen = 0; + last_rx_cnt = 0; + } + } + + if (rx_process_cache_len != 0) { + processRxData(rx_process_cache, rx_process_cache_len); + memset(rx_process_cache, 0, sizeof(rx_process_cache)); + rx_process_cache_len = 0; + } + + last_rx_cnt = m_rxlen; + } + })); +} + +void CLSTControler::regRawDataListener(raw_data_cb_t cb) { m_raw_data_cb = cb; } + +void CLSTControler::processRxData(uint8_t *rx, uint32_t rxlen) { + /** + * @brief + * 1. findHeader + * 2. processRx + * + * ָ: + * 5A 5A 02 00 01 00 01 00 01 00 01 00 00 00 06 A5 A5 + * + */ + // ZLOGI(TAG, "processRxData %d", rxlen); + + for (uint32_t i = 0; i < rxlen; i++) { + zaf_packet_header_t *header = (zaf_packet_header_t *)(&rx[i]); + uint8_t *packetu8 = &rx[i]; + + if (header->packet_header == PACKET_HEADER) { + uint8_t check = packetu8[header->ndata * 4 + sizeof(zaf_packet_header_t) + 0]; + uint8_t tail0 = packetu8[header->ndata * 4 + sizeof(zaf_packet_header_t) + 1]; + uint8_t tail1 = packetu8[header->ndata * 4 + sizeof(zaf_packet_header_t) + 2]; + + uint16_t tail = (tail1 << 8) | tail0; + + uint8_t expectcheck = 0; + for (uint32_t j = 2; j < header->ndata * 4 + sizeof(zaf_packet_header_t); j++) { + expectcheck += packetu8[j]; + } + + if (tail == PACKET_TAIL) { + if (expectcheck == check) { + processRxPacket(header); + } else { + ZLOGE(TAG, "Rx packet check error %d != %d", expectcheck, check); + } + } + } + } +} + +void CLSTControler::processRxPacket(zaf_packet_header_t *packet) { // + // ZLOGI(TAG, "RX packet"); + // ZLOGI(TAG, " type :%d", packet->packet_type); + // ZLOGI(TAG, " index :%d", packet->index); + // ZLOGI(TAG, " cmd :%d", packet->cmd); + // ZLOGI(TAG, " ndata :%d", packet->ndata); + // for (uint32_t i = 0; i < packet->ndata; i++) { + // ZLOGI(TAG, " data[%d]:%d", i, packet->data[i]); + // } + if (packet->packet_type == kzaf_packet_type_receipt) { + lock_guard lock(m_rxReceiptContext_lock); + if (m_rxReceiptContext.waittingForReceipt) { + if (m_rxReceiptContext.waittingIndex == packet->index) { + m_rxReceiptContext.receiptIsReady = true; + m_rxReceiptContext.receiptLen = packet->ndata; + memcpy(m_rxReceiptContext.receipt, packet->data, packet->ndata); + } + m_rxReceiptContext.waittingForReceipt = false; + } + } + + if (m_raw_data_cb) { + m_raw_data_cb(kuart_raw_rx, (uint8_t *)packet, sizeof(zaf_packet_header_t) + packet->ndata * 4 + 3); + } +} + +bool CLSTControler::ping() {} + +zaf_error_code_t CLSTControler::sendPacket(zaf_packet_header_t *packet, uint32_t len, uint32_t overtime) { + zaf_packet_header_t *rxpacket = (zaf_packet_header_t *)&m_rxReceiptContext.receipt[0]; + + { + lock_guard lock(m_rxReceiptContext_lock); + m_rxReceiptContext.waittingIndex = packet->index; + m_rxReceiptContext.waittingForReceipt = true; + m_rxReceiptContext.receiptIsReady = false; + m_rxReceiptContext.receiptLen = 0; + } + + if (!m_channel) { + return kaf_ec_overtime; + } + + if (m_raw_data_cb) { + m_raw_data_cb(kuart_raw_tx, (uint8_t *)packet, sizeof(zaf_packet_header_t) + packet->ndata * 4 + 3); + } + m_channel->send((uint8_t *)packet, len); + + for (size_t i = 0; i < overtime; i++) { + { + lock_guard lock(m_rxReceiptContext_lock); + if (m_rxReceiptContext.receiptIsReady) { + if (rxpacket->data[0] != 0) { + return (zaf_error_code_t)rxpacket->data[0]; + } else { + return kaf_ec_success; + } + } + } + + this_thread::sleep_for(chrono::milliseconds(1)); + } + return kaf_ec_overtime; +} + +#define PACKET_LEN(__packet) (sizeof(zaf_packet_header_t) + (__packet->ndata) * sizeof(uint32_t) + 1 /*checksum*/ + 2 /*tail*/) + +zaf_error_code_t CLSTControler::reg_write(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms) { // + lock_guard lock(m_tx_lock); + + uint8_t txdata[128] = {0}; + + zaf_packet_header_t *txpacket = (zaf_packet_header_t *)txdata; + zaf_packet_header_t *rxpacket = (zaf_packet_header_t *)&m_rxReceiptContext.receipt[0]; + + txpacket->packet_header = PACKET_HEADER; + txpacket->packet_type = kzaf_packet_type_cmd; + txpacket->index = ++txindex; + txpacket->cmd = kzaf_cmd_reg_write; + txpacket->ndata = 2; + txpacket->data[0] = regadd; + txpacket->data[1] = regvalue; + + uint32_t txpacklen = PACKET_LEN(txpacket); + uint8_t checksum = 0; + for (int i = 2; i < txpacklen - 3; i++) { + checksum += txdata[i]; + } + txdata[txpacklen - 3] = checksum; + txdata[txpacklen - 2] = PACKET_TAIL & 0xFF; + txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF; + + zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, overtime_ms); + if (ecode != kaf_ec_success) { + return ecode; + } + + regbackvalue = rxpacket->data[1]; + return kaf_ec_success; +} +zaf_error_code_t CLSTControler::reg_read(uint32_t regadd, uint32_t ®value, int32_t overtime_ms) { + lock_guard lock(m_tx_lock); + + uint8_t txdata[128] = {0}; + + zaf_packet_header_t *txpacket = (zaf_packet_header_t *)txdata; + zaf_packet_header_t *rxpacket = (zaf_packet_header_t *)&m_rxReceiptContext.receipt[0]; + + txpacket->packet_header = PACKET_HEADER; + txpacket->packet_type = kzaf_packet_type_cmd; + txpacket->index = ++txindex; + txpacket->cmd = kzaf_cmd_reg_read; + txpacket->ndata = 1; + txpacket->data[0] = regadd; + + uint32_t txpacklen = PACKET_LEN(txpacket); + uint8_t checksum = 0; + for (int i = 2; i < txpacklen - 3; i++) { + checksum += txdata[i]; + } + txdata[txpacklen - 3] = checksum; + txdata[txpacklen - 2] = PACKET_TAIL & 0xFF; + txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF; + + zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, overtime_ms); + if (ecode != kaf_ec_success) { + return ecode; + } + + regvalue = rxpacket->data[1]; + return kaf_ec_success; +} + +zaf_error_code_t CLSTControler::factoryReset() { + uint8_t txdata[128] = {0}; + + zaf_packet_header_t *txpacket = (zaf_packet_header_t *)txdata; + zaf_packet_header_t *rxpacket = (zaf_packet_header_t *)&m_rxReceiptContext.receipt[0]; + + txpacket->packet_header = PACKET_HEADER; + txpacket->packet_type = kzaf_packet_type_cmd; + txpacket->index = ++txindex; + txpacket->cmd = kzaf_cmd_factory_reset; + txpacket->ndata = 0; + + uint32_t txpacklen = PACKET_LEN(txpacket); + uint8_t checksum = 0; + for (int i = 2; i < txpacklen - 3; i++) { + checksum += txdata[i]; + } + txdata[txpacklen - 3] = checksum; + txdata[txpacklen - 2] = PACKET_TAIL & 0xFF; + txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF; + + zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 1000); + if (ecode != kaf_ec_success) return ecode; + + return kaf_ec_success; +} +zaf_error_code_t CLSTControler::reboot() { + uint8_t txdata[128] = {0}; + + zaf_packet_header_t *txpacket = (zaf_packet_header_t *)txdata; + zaf_packet_header_t *rxpacket = (zaf_packet_header_t *)&m_rxReceiptContext.receipt[0]; + + txpacket->packet_header = PACKET_HEADER; + txpacket->packet_type = kzaf_packet_type_cmd; + txpacket->index = ++txindex; + txpacket->cmd = kzaf_cmd_reboot; + txpacket->ndata = 0; + + uint32_t txpacklen = PACKET_LEN(txpacket); + uint8_t checksum = 0; + for (int i = 2; i < txpacklen - 3; i++) { + checksum += txdata[i]; + } + txdata[txpacklen - 3] = checksum; + txdata[txpacklen - 2] = PACKET_TAIL & 0xFF; + txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF; + + zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 100); + if (ecode != kaf_ec_success) return ecode; + + return kaf_ec_success; +} +zaf_error_code_t CLSTControler::storageConfigs() { + uint8_t txdata[128] = {0}; + + zaf_packet_header_t *txpacket = (zaf_packet_header_t *)txdata; + zaf_packet_header_t *rxpacket = (zaf_packet_header_t *)&m_rxReceiptContext.receipt[0]; + + txpacket->packet_header = PACKET_HEADER; + txpacket->packet_type = kzaf_packet_type_cmd; + txpacket->index = ++txindex; + txpacket->cmd = kzaf_cmd_storage_cfg; + txpacket->ndata = 0; + + uint32_t txpacklen = PACKET_LEN(txpacket); + uint8_t checksum = 0; + for (int i = 2; i < txpacklen - 3; i++) { + checksum += txdata[i]; + } + txdata[txpacklen - 3] = checksum; + txdata[txpacklen - 2] = PACKET_TAIL & 0xFF; + txdata[txpacklen - 1] = (PACKET_TAIL >> 8) & 0xFF; + + zaf_error_code_t ecode = sendPacket(txpacket, txpacklen, 100); + if (ecode != kaf_ec_success) return ecode; + + return kaf_ec_success; +} diff --git a/src/camera_light_src_timing_controller/clst_controler.hpp b/src/camera_light_src_timing_controller/clst_controler.hpp new file mode 100644 index 0000000..79c2787 --- /dev/null +++ b/src/camera_light_src_timing_controller/clst_controler.hpp @@ -0,0 +1,93 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "zaf_protocol/zaf_protocol.h" + +#define SDK_VERSION 1 + +namespace iflytop { +namespace clst { +using namespace std; + +typedef enum { + kuart_raw_tx, + kuart_raw_rx, +} uart_message_type_t; + +typedef function device_state_cb_t; +typedef function raw_data_cb_t; + +class IDataChannel { + public: + virtual ~IDataChannel(){}; + virtual bool isOpen() = 0; + virtual bool send(const uint8_t *data, size_t len) = 0; + virtual void regRxListener(function cb) = 0; +}; + +class RxReceiptContext { + public: + bool waittingForReceipt; + bool receiptIsReady; + uint16_t waittingIndex; + uint8_t receipt[1024]; + size_t receiptLen; +}; + +class CLSTControler { + CLSTControler() {} + + IDataChannel *m_channel = nullptr; + + uint8_t m_rxcache[1024]; + size_t m_rxlen = 0; + + mutex lock_; + + unique_ptr m_thread; + + RxReceiptContext m_rxReceiptContext; + mutex m_rxReceiptContext_lock; + + mutex m_tx_lock; + + + raw_data_cb_t m_raw_data_cb; + uint16_t txindex = 0; + + public: + static CLSTControler *ins(); + + void initialize(IDataChannel *channel); + void regRawDataListener(raw_data_cb_t cb); + + public: + bool ping(); + zaf_error_code_t factoryReset(); + zaf_error_code_t reboot(); + zaf_error_code_t storageConfigs(); + + public: + zaf_error_code_t reg_write(uint32_t regadd, uint32_t regvalue, uint32_t ®backvalue, int32_t overtime_ms); + zaf_error_code_t reg_read(uint32_t regadd, uint32_t ®value, int32_t overtime_ms); + + public: + void processRxData(uint8_t *rx, uint32_t rxlen); + void processRxPacket(zaf_packet_header_t *packet); + + zaf_error_code_t sendPacket(zaf_packet_header_t *packet, uint32_t len, uint32_t overtime); +}; + +} // namespace clst +} // namespace iflytop diff --git a/src/camera_light_src_timing_controller/qt_serial_datachannel.cpp b/src/camera_light_src_timing_controller/qt_serial_datachannel.cpp new file mode 100644 index 0000000..c81b950 --- /dev/null +++ b/src/camera_light_src_timing_controller/qt_serial_datachannel.cpp @@ -0,0 +1,37 @@ +#include "qt_serial_datachannel.hpp" + +#include +#include + +#include "logger.hpp" + +using namespace iflytop; +using namespace std; +using namespace clst; + +void QTDataChannel::bind(QSerialPort *serialPort) { // + m_serialPort = serialPort; + connect(m_serialPort, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); +} + +void QTDataChannel::readyReadSlot() { + if (!m_serialPort) return; + + QByteArray data = m_serialPort->readAll(); + // ZLOGI("QTDataChannel", "RX %d", data.size()); + if (m_rxcb) m_rxcb((uint8_t *)data.data(), data.size()); +} + +bool QTDataChannel::isOpen() { + if (!m_serialPort) return false; + return m_serialPort->isOpen(); +} +bool QTDataChannel::send(const uint8_t *data, size_t len) { + if (!m_serialPort) return false; + + QByteArray qdata; + qdata.append((char *)data, len); + m_serialPort->write(qdata); + return true; +} +void QTDataChannel::regRxListener(function cb) { m_rxcb = cb; } \ No newline at end of file diff --git a/src/camera_light_src_timing_controller/qt_serial_datachannel.hpp b/src/camera_light_src_timing_controller/qt_serial_datachannel.hpp new file mode 100644 index 0000000..e48a084 --- /dev/null +++ b/src/camera_light_src_timing_controller/qt_serial_datachannel.hpp @@ -0,0 +1,49 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include +#include +// +#include "clst_controler.hpp" +#include "zqthread.hpp" + +#define SDK_VERSION 1 + +namespace iflytop { +namespace clst { +using namespace std; +// QT_CHARTS_USE_NAMESPACE + +typedef function device_state_cb_t; + +class QTDataChannel : public QObject, public IDataChannel { + Q_OBJECT + + function m_rxcb; + + QSerialPort *m_serialPort = nullptr; + unique_ptr m_thread; + + public: + void bind(QSerialPort *serialPort); + + virtual bool isOpen() override; + virtual bool send(const uint8_t *data, size_t len) override; + virtual void regRxListener(function cb) override; + + public slots: + void readyReadSlot(); +}; +} // namespace clst +} // namespace iflytop \ No newline at end of file diff --git a/src/xsync_udp_factory_impl.cpp b/src/xsync_udp_factory_impl.cpp deleted file mode 100644 index 2fb937c..0000000 --- a/src/xsync_udp_factory_impl.cpp +++ /dev/null @@ -1,220 +0,0 @@ -#include "xsync_udp_factory_impl.hpp" - -#include "zqthread.hpp" -// -#include -// -#include - -#define ENABLE_LOG -#ifdef ENABLE_LOG -#include "../src/logger.hpp" -#endif -#define TAG "XSYNC_UDP" -#pragma comment(lib, "ws2_32") -using namespace xsync; -using namespace iflytop; - -/******************************************************************************* - * XSUDP * - *******************************************************************************/ - -#define USB_NO_BLOCK_UDP 0 - -class XSUDP : public I_XSUDP { - uint32_t m_ip; - int m_localport; - - struct sockaddr_in localadd = {}; - int m_sock_fd = 0; - unique_ptr m_zq_thread; - onMessage_t m_onMessage; - - char* m_rxbuf = nullptr; - size_t m_rxbufsize = 0; - - public: - virtual xs_error_code_t initialize(string ip, int localport) override; - virtual xs_error_code_t sendto(const XsyncNetAdd& to, const char* data, int32_t length, int32_t* sendlength) override; - virtual xs_error_code_t receive(char* data, int32_t& length, XsyncNetAdd& from, int overtimems) override; - virtual xs_error_code_t startReceive(onMessage_t onMessage) override; - virtual xs_error_code_t stopReceive() override; - virtual xs_error_code_t clearRxBuffer() override; - virtual ~XSUDP(); -}; - -const char* fmtip(uint32_t ip) { - static char ipstr[16]; - sprintf(ipstr, "%d.%d.%d.%d", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff); - return ipstr; -} - -xs_error_code_t XSUDP::initialize(string ip, int localport) { - localadd.sin_family = AF_INET; - localadd.sin_addr.s_addr = inet_addr(ip.c_str()); - localadd.sin_port = htons(localport); - - // 创建客户端用于通信的Socket - m_sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (m_sock_fd < 0) return kxs_ec_socket_fail; - - int ret = bind(m_sock_fd, (struct sockaddr*)&localadd, sizeof(localadd)); - if (ret < 0) return kxs_ec_bind_fail; - -#if USB_NO_BLOCK_UDP - u_long mode = 1; - if (ioctlsocket(m_sock_fd, FIONBIO, &mode) != NO_ERROR) { - return kxs_ec_setsockopt_rx_timeout_fail; - } -#endif - return kxs_ec_success; -} - -xs_error_code_t XSUDP::sendto(const XsyncNetAdd& to, const char* data, int32_t length, int32_t* sendlength) { - struct sockaddr_in sockaddr; - sockaddr.sin_family = AF_INET; - sockaddr.sin_addr.s_addr = inet_addr(to.ip.c_str()); - sockaddr.sin_port = htons(to.port); - int ret = ::sendto(m_sock_fd, data, length, 0, (struct sockaddr*)&sockaddr, sizeof(sockaddr)); - if (sendlength) *sendlength = ret; - if (ret >= 0) { - return kxs_ec_success; - } - return kxs_ec_send_fail; -} -xs_error_code_t XSUDP::receive(char* data, int32_t& length, XsyncNetAdd& from, int overtimems) { -#if USB_NO_BLOCK_UDP - struct sockaddr_in sockaddr = {0}; - int32_t overtime_10ms = overtimems / 10; - int ret = 0; - overtime_10ms += 1; - for (size_t i = 0;; i++) { - int senderAddressLen = sizeof(sockaddr); - ret = ::recvfrom(m_sock_fd, (char*)data, length, 0, (struct sockaddr*)&sockaddr, &senderAddressLen); - length = ret; - - if (ret > 0) break; - if (i >= overtime_10ms) break; - Sleep(10); - } - - if (ret <= 0) { - return kxs_ec_overtime; - } - - uint32_t ip = ntohl(sockaddr.sin_addr.s_addr); - from.ip = string(fmtip(ip)); - from.port = ntohs(sockaddr.sin_port); - - return kxs_ec_success; -#else - struct sockaddr_in sockaddr = {0}; - - timeval timeout; - timeout.tv_sec = overtimems; // 这个结构体的单位是ms,不是秒 - timeout.tv_usec = 0; - - if (timeout.tv_sec == 0) { - timeout.tv_sec = 1; - } - - if (setsockopt(m_sock_fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(timeout)) == -1) { - return kxs_ec_setsockopt_rx_timeout_fail; - } - int senderAddressLen = sizeof(sockaddr); - int ret = ::recvfrom(m_sock_fd, (char*)data, length, 0, (struct sockaddr*)&sockaddr, &senderAddressLen); - length = ret; - data[length] = 0; - - if (ret < 0) { - // ZLOGI(TAG, "recvfrom error %d %s", ret, strerror(errno)); - // if (errno == EWOULDBLOCK || errno == EAGAIN) { - return kxs_ec_overtime; - // } else { - // return kxs_ec_receive_fail; - // } - } - - // inet_ntop(AF_INET, &(sockaddr.sin_addr), ip, INET_ADDRSTRLEN); - uint32_t ip = ntohl(sockaddr.sin_addr.s_addr); - from.ip = string(fmtip(ip)); - from.port = ntohs(sockaddr.sin_port); - - return kxs_ec_success; -#endif -} - -xs_error_code_t XSUDP::startReceive(onMessage_t onMessage) { - m_onMessage = onMessage; - - if (m_zq_thread) { - return kxs_ec_success; - } - m_rxbuf = (char*)malloc(10240); - m_rxbufsize = 10240; - - m_zq_thread.reset(new ZQThread("udplistener_thread", [this]() { - while (!m_zq_thread->isTryExit()) { - memset(m_rxbuf, 0, m_rxbufsize); - int32_t length = m_rxbufsize; - XsyncNetAdd from; - xs_error_code_t ret = receive(m_rxbuf, length, from, 1000); - if (ret == kxs_ec_success) { - if (m_onMessage) m_onMessage(from, (uint8_t*)m_rxbuf, length); - } - } - })); - m_zq_thread->start(); - return kxs_ec_success; -} - -xs_error_code_t XSUDP::stopReceive() { - if (m_zq_thread) { - m_zq_thread->quit(); - m_zq_thread->wait(); - m_zq_thread.reset(nullptr); - } - - if (!m_rxbuf) { - free(m_rxbuf); - m_rxbuf = nullptr; - m_rxbufsize = 0; - } -} - -xs_error_code_t XSUDP::clearRxBuffer() { -#if USB_NO_BLOCK_UDP - char buf[1024]; - int32_t length = 1024; - XsyncNetAdd from; - xs_error_code_t ret = kxs_ec_success; - - while (ret == kxs_ec_success) { - ret = receive(buf, length, from, 1); - } -#endif - - return kxs_ec_success; -} - -XSUDP::~XSUDP() { - stopReceive(); - - if (m_sock_fd > 0) { - closesocket(m_sock_fd); - m_sock_fd = -1; - } -} - -/******************************************************************************* - * xSyncUdpFactoryImpl * - *******************************************************************************/ - -void XSyncUdpFactoryImpl::initialize() {} - -XSyncUdpFactoryImpl* XSyncUdpFactoryImpl::Ins() { - static XSyncUdpFactoryImpl instance; - return &instance; -} - -shared_ptr XSyncUdpFactoryImpl::createXSUDP() { return make_shared(); } \ No newline at end of file diff --git a/src/xsync_udp_factory_impl.hpp b/src/xsync_udp_factory_impl.hpp deleted file mode 100644 index 42409f1..0000000 --- a/src/xsync_udp_factory_impl.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "xsync_v2.hpp" -namespace xsync { -using namespace std; - -class XSyncUdpFactoryImpl : public I_XSUDPFactory { - private: - /* data */ - XSyncUdpFactoryImpl(){}; - - public: - static XSyncUdpFactoryImpl* Ins(); - - void initialize(); - virtual shared_ptr createXSUDP() override; -}; - -} // namespace xsync \ No newline at end of file diff --git a/zaf_protocol b/zaf_protocol index 1f37a71..7d27a34 160000 --- a/zaf_protocol +++ b/zaf_protocol @@ -1 +1 @@ -Subproject commit 1f37a710c5a4cb8fee30ced8e246488310f9017a +Subproject commit 7d27a34ee665cc3cba2d12ff357e774e34871b38