Browse Source

update

master
zhaohe 1 year ago
parent
commit
c488e8cef3
  1. 3
      .vscode/settings.json
  2. BIN
      p_lusterinc_xsync - 快捷方式.lnk
  3. 82
      src/app/syncbox16ch/syncbox16ch.cpp
  4. 2
      src/app/syncbox16ch/syncbox16ch.ui
  5. 9
      src/app/syncbox16ch/syncbox16ch_sdk.cpp
  6. 25
      src/app/syncbox16ch/syncbox16ch_sdk.hpp
  7. 54
      src/protocol/zfpga_commander/zfpga_commander.cpp
  8. 10
      src/protocol/zfpga_commander/zfpga_commander.hpp
  9. 18
      src/qtutils/qtutils.hpp
  10. 7
      src/zqui/zqui/mainwindow.cpp
  11. 35
      src/zqui/zqui/mainwindow.ui
  12. 15
      src/zqui/zqui/zqui.cpp
  13. 10
      src/zqui/zqui/zqui.hpp
  14. 2
      zfpga_basic_protocol

3
.vscode/settings.json

@ -111,7 +111,8 @@
"xtr1common": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"qformlayout": "cpp"
"qformlayout": "cpp",
"qvariant": "cpp"
},
"files.autoGuessEncoding": false,
}

BIN
p_lusterinc_xsync - 快捷方式.lnk

82
src/app/syncbox16ch/syncbox16ch.cpp

@ -7,51 +7,35 @@
using namespace iflytop;
using namespace syncbox16chsdk;
#define TAG "SyncBox16CH"
typedef enum {
// 自定义
koutput_pluse_type_custom,
// 方波
koutput_pluse_type_square_wave,
} OutputPluseType_t;
static OutputPluseType_t outputPluseTypeStr2Enum(QString str) {
if (str == "自定义") {
return koutput_pluse_type_custom;
} else if (str == "方波") {
return koutput_pluse_type_square_wave;
} else {
return koutput_pluse_type_custom;
}
}
static QString outputPluseType2Str(OutputPluseType_t type) {
switch (type) {
case koutput_pluse_type_custom:
return "自定义";
case koutput_pluse_type_square_wave:
return "方波";
default:
return "自定义";
}
}
#define SDK SyncBox16ChSDK::ins()
SyncBox16CH::SyncBox16CH(QWidget *parent) : QWidget(parent), ui(new Ui::SyncBox16CH) {
ui->setupUi(this);
ZLOGI(TAG,"Hello");
{
//
// ui->StateGB->hide();
ui->OutputModeVal->addItems(QStringListValueOf(WorkModeStrList()));
ui->OutputPluseTypeVal->addItem(outputPluseType2Str(koutput_pluse_type_custom));
ui->OutputPluseTypeVal->addItem(outputPluseType2Str(koutput_pluse_type_square_wave));
// ui->OutputPluseTypeVal->addItem(outputPluseType2Str(koutput_pluse_type_custom));
// ui->OutputPluseTypeVal->addItem(outputPluseType2Str(koutput_pluse_type_square_wave));
ui->OutputPluseWidthVal->setText("1");
ui->OutputPluseNumVal->setText("1");
ui->OutputPluseFreqVal->setText("1000");
}
SDK->getCmder()->regStateCbFn([this](bool connect) {
if (connect) {
ZQUI::ins()->setDeviceConnectedStatus(true);
} else {
ZQUI::ins()->setDeviceConnectedStatus(false);
}
});
SDK->initialize();
ZQUI::ins()->mainW()->setVersionInfo(1, "APP_VERSION", "1.0.0");
// ZQUI::ins()->mainW()->setVersionInfo(1, "APP_VERSION", "1.0.0");
}
SyncBox16CH::~SyncBox16CH() { delete ui; }
@ -59,8 +43,8 @@ SyncBox16CH::~SyncBox16CH() { delete ui; }
void SyncBox16CH::on_OutputModeVal_currentIndexChanged(const QString &arg1) { onModeChange(); }
void SyncBox16CH::on_OutputPluseTypeVal_currentIndexChanged(const QString &arg1) { onModeChange(); }
void SyncBox16CH::onModeChange() {
WorkMode_t outputMode = syncbox16chsdk::WorkModeValueOf(ui->OutputModeVal->currentText().toStdString().c_str());
OutputPluseType_t outputPluseType = outputPluseTypeStr2Enum(ui->OutputPluseTypeVal->currentText());
WorkMode_t outputMode = syncbox16chsdk::WorkModeValueOf(ui->OutputModeVal->currentText().toStdString().c_str());
// OutputPluseType_t outputPluseType = outputPluseTypeStr2Enum(ui->OutputPluseTypeVal->currentText());
// kWorkMode_extCpyMode,
// kWorkMode_extTriMode,
@ -79,28 +63,38 @@ void SyncBox16CH::onModeChange() {
// 脉冲频率
ui->OutputPluseFreqTag->hide();
ui->OutputPluseFreqVal->hide();
} else if (outputMode == kWorkMode_manualTriMode || outputMode == kWorkMode_extTriMode) {
} else if (outputMode == kWorkMode_manualTriMode) {
// 脉冲数量
ui->OutputPluseNumVal->show();
ui->OutputPluseNumTag->show();
// 脉冲宽度
if (outputPluseType == koutput_pluse_type_custom) {
ui->OutputPluseWidthVal->show();
ui->OutputPluseWidthTag->show();
} else if (outputPluseType == koutput_pluse_type_square_wave) {
ui->OutputPluseWidthVal->hide();
ui->OutputPluseWidthTag->hide();
}
// 脉冲类型
ui->OutputPluseTypeVal->show();
ui->OutputPluseTypeTag->show();
ui->OutputPluseWidthVal->show();
ui->OutputPluseWidthTag->show();
// 脉冲频率
ui->OutputPluseFreqTag->show();
ui->OutputPluseFreqVal->show();
} else if (outputMode == kWorkMode_extTriMode) {
// 脉冲数量
ui->OutputPluseNumVal->show();
ui->OutputPluseNumTag->show();
// 脉冲宽度
ui->OutputPluseWidthVal->show();
ui->OutputPluseWidthTag->show();
// 脉冲频率
ui->OutputPluseFreqTag->hide();
ui->OutputPluseFreqVal->hide();
}
}
void SyncBox16CH::on_SendButton_clicked() {
ICLEAR();
ISHOW("on send button");
WorkMode_t outputMode = syncbox16chsdk::WorkModeValueOf(ui->OutputModeVal->currentText());
uint32_t outputPluseWidthUs = zstr2int(ui->OutputPluseWidthVal->text());
uint32_t outputPluseNum = zstr2int(ui->OutputPluseNumVal->text());
if (outputMode == kWorkMode_extTriMode && outputPluseNum == 0) {
ISHOW_ERROR("外部触发模式下,脉冲数量不能为0");
return;
}
}

2
src/app/syncbox16ch/syncbox16ch.ui

@ -187,7 +187,7 @@
</size>
</property>
<property name="text">
<string>脉冲数量</string>
<string>脉冲数量(0:无限脉冲)</string>
</property>
</widget>
</item>

9
src/app/syncbox16ch/syncbox16ch_sdk.cpp

@ -17,8 +17,9 @@ enummap_iterm_t output_mode_enummap[] = {
};
const char* WorkModeToStr(uint32_t mode) { return EnumMapValue2Str(output_mode_enummap, mode); }
WorkMode_t WorkModeValueOf(const char* str) { return (WorkMode_t)EnumMapStr2Value(output_mode_enummap, str); }
WorkMode_t WorkModeValueOf(const char* str) { return (WorkMode_t)EnumMapStr2Value(output_mode_enummap, str); }
list<string> WorkModeStrList() { return EnumMapStrList(output_mode_enummap); }
WorkMode_t WorkModeValueOf(QString str) { return WorkModeValueOf(str.toStdString().c_str()); }
} // namespace syncbox16chsdk
} // namespace iflytop
@ -28,4 +29,8 @@ list<string> WorkModeStrList() { return EnumMapStrList(output_mode_enummap); }
***********************************************************************************************************************/
using namespace iflytop;
using namespace syncbox16chsdk;
void SyncBox16ChSDK::initialize() { ZFPGACommander::ins()->initialize(); }
void SyncBox16ChSDK::initialize() {
ZFPGACommander::ins()->initialize();
}

25
src/app/syncbox16ch/syncbox16ch_sdk.hpp

@ -15,6 +15,20 @@
#include "protocol/zfpga_commander/zfpga_commander.hpp"
#include "zfpga_basic_protocol/zaf_protocol.h"
#include "zfpga_basic_protocol/zaf_regs.hpp"
//
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QWidget>
//
#define REGADDOFF__FPGA_APP 0x1020
namespace iflytop {
namespace syncbox16chsdk {
@ -26,14 +40,21 @@ typedef enum {
kWorkMode_manualTriMode,
} WorkMode_t;
typedef struct {
typedef enum {
kreg_app = REGADDOFF__FPGA_APP,
kreg_workmode = REGADDOFF__FPGA_APP + 1,
kreg_pluse_gen_num = REGADDOFF__FPGA_APP + 2,
kreg_pluse_pluse_width = REGADDOFF__FPGA_APP + 3,
} reg_t;
const char* WorkModeToStr(uint32_t mode);
WorkMode_t WorkModeValueOf(const char* str);
WorkMode_t WorkModeValueOf(QString str);
list<string> WorkModeStrList();
class SyncBox16ChSDK {
unique_ptr<thread> m_thread;
public:
static SyncBox16ChSDK* ins() {
static SyncBox16ChSDK cmder;
@ -47,6 +68,8 @@ class SyncBox16ChSDK {
void setPluseFreq(uint32_t freq);
void setPluseGeneratorMode();
ZFPGACommander* getCmder() { return ZFPGACommander::ins(); }
public:
};
} // namespace syncbox16chsdk

54
src/protocol/zfpga_commander/zfpga_commander.cpp

@ -10,10 +10,12 @@
using namespace iflytop;
#define TAG "Syncbox16ch"
#define TAG "ZFPGACommander"
QTSerialChannel *serial_ch;
#define DEBUG
#define PACKET_LEN(__packet) (sizeof(zaf_packet_header_t) + (__packet->ndata) * sizeof(uint32_t) + 1 /*checksum*/ + 2 /*tail*/)
#define DO_CMD(exptr) \
{ \
@ -21,6 +23,16 @@ QTSerialChannel *serial_ch;
if (ecode != kaf_ec_success) return ecode; \
}
static string hex2str(uint8_t *hex, size_t len) {
string str;
for (size_t i = 0; i < len; i++) {
char buf[3];
sprintf(buf, "%02X", hex[i]);
str += buf;
}
return str;
}
void ZFPGACommander::initialize() {
//
serial_ch = &ChannelMgr::ins()->serialCh;
@ -38,7 +50,7 @@ void ZFPGACommander::initialize() {
m_thread.reset(new thread([this]() {
uint32_t last_rx_cnt = 0;
uint8_t rx_process_cache[1024];
uint32_t rx_process_cache_len;
uint32_t rx_process_cache_len = 0;
while (true) {
this_thread::sleep_for(chrono::milliseconds(4));
@ -62,10 +74,38 @@ void ZFPGACommander::initialize() {
last_rx_cnt = m_rxlen;
}
}));
m_online_detect_thread.reset(new thread([this]() {
while (true) {
this_thread::sleep_for(chrono::milliseconds(500));
bool tostate = false;
if (ping()) {
tostate = true;
} else {
tostate = false;
}
if (tostate != isconnected) {
if (tostate) {
ZLOGI(TAG, "device connected.");
} else {
ZLOGI(TAG, "device disconnected.");
}
isconnected = tostate;
if (m_stateCbFn) m_stateCbFn(isconnected);
}
}
}));
}
void ZFPGACommander::regRawDataListener(binary_cb_t cb) {}
void ZFPGACommander::regRawDataListener(binary_cb_t cb) { m_raw_data_cb = cb; }
void ZFPGACommander::regStateCbFn(StateCbFn_t cbfn) { this->m_stateCbFn = cbfn; }
bool ZFPGACommander::chIsOn() { return serial_ch->isOpen(); }
void ZFPGACommander::processRxData(uint8_t *rx, uint32_t rxlen) {
#ifdef DEBUG
ZLOGI(TAG, "RX %s", hex2str((uint8_t *)rx, rxlen).c_str());
#endif
for (uint32_t i = 0; i < rxlen; i++) {
zaf_packet_header_t *header = (zaf_packet_header_t *)(&rx[i]);
uint8_t *packetu8 = &rx[i];
@ -141,6 +181,9 @@ void ZFPGACommander::sendPacket(zaf_packet_header_t *packet, uint32_t len, uint3
if (m_raw_data_cb) {
m_raw_data_cb(kuart_raw_tx, (uint8_t *)packet, PACKET_LEN(packet));
}
#ifdef DEBUG
ZLOGI(TAG, "TX %s", hex2str((uint8_t *)packet, len).c_str());
#endif
serial_ch->send((uint8_t *)packet, len);
for (size_t i = 0; i < overtime; i++) {
{
@ -281,13 +324,12 @@ void ZFPGACommander::readFPGAVersion(Version &version) {
}
void ZFPGACommander::readStm32Version(Version &version) {
uint32_t version32;
readReg(kreg_software_version, version32, 100);
readReg(kreg_software_version, version32, 10);
}
bool ZFPGACommander::ping() {
try {
Version version;
readStm32Version(version);
callcmd(kzaf_cmd_ping, 10);
} catch (const std::exception &e) {
return false;
}

10
src/protocol/zfpga_commander/zfpga_commander.hpp

@ -24,7 +24,7 @@ typedef enum {
kuart_raw_rx,
} uart_message_type_t;
typedef function<void(bool connect)> device_state_cb_t;
typedef function<void(bool connect)> StateCbFn_t;
typedef function<void(uart_message_type_t type, uint8_t *data, size_t len)> binary_cb_t;
@ -74,12 +74,16 @@ class ZFPGACommander {
unique_ptr<thread> m_thread;
unique_ptr<thread> m_online_detect_thread;
ZFPGARxReceiptContext m_rxReceiptContext;
mutex m_rxReceiptContext_lock;
mutex m_tx_lock;
binary_cb_t m_raw_data_cb;
uint16_t txindex = 0;
StateCbFn_t m_stateCbFn;
uint16_t txindex = 0;
bool isconnected = false;
map<uint32_t, Reginfo> m_reginfoMap;
@ -91,6 +95,8 @@ class ZFPGACommander {
void initialize();
void regRawDataListener(binary_cb_t cb);
void regStateCbFn(StateCbFn_t cbfn);
bool chIsOn();
public:
void writeReg(uint32_t regadd, uint32_t regvalue, uint32_t &regbackvalue, int32_t overtime_ms);

18
src/qtutils/qtutils.hpp

@ -26,4 +26,22 @@ namespace iflytop {
using namespace std;
QStringList QStringListValueOf(list<string> strlist);
static inline const uint32_t zstr2int(QString str) {
// 如果0x开头,??16进制转换
// 如果0b开头,??2进制转换
// 否则??10进制转换
// 去除掉str中_
str.remove("_");
if (str.startsWith("0x")) {
return str.toUInt(nullptr, 16);
} else if (str.startsWith("0b")) {
// remove 0b
str.remove(0, 2);
return str.toUInt(nullptr, 2);
} else {
return str.toUInt(nullptr, 10);
}
}
} // namespace iflytop

7
src/zqui/zqui/mainwindow.cpp

@ -28,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
void MainWindow::buildUI() {
QTSerialChannel *serialch = &ChannelMgr::ins()->serialCh;
serialch->init();
/**
* @brief UI
@ -38,6 +39,9 @@ void MainWindow::buildUI() {
ui->serialBaudrateCB->addItem("500000");
ui->serialBaudrateCB->addItem("2000000");
ui->serialBaudrateCB->setCurrentIndex(0);
ui->serialRefreshKey->hide();
connect(ui->serialRefreshKey, &QPushButton::clicked, this, [=](bool check) { fillinSerialPort(); });
connect(ui->serialOpenKey, &QPushButton::clicked, this, [=](bool check) {
// 打开串口
@ -99,8 +103,9 @@ void MainWindow::fillinSerialPort() {
// int curIndex = ui->serialPortCB->currentIndex();
ui->serialPortCB->clear();
const auto infos = QSerialPortInfo::availablePorts();
for (const QSerialPortInfo &info : infos) {
if (info.isBusy()) continue;
// if (info.isBusy()) continue;
ui->serialPortCB->addItem(info.portName());
}
}

35
src/zqui/zqui/mainwindow.ui

@ -685,34 +685,41 @@ background-color: rgb(245, 245, 245);
<string>端口</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="serialBaudrateLable">
<item row="0" column="0">
<widget class="QLabel" name="serialPortLable">
<property name="text">
<string>波特率</string>
<string>串口号</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="serialPortLable">
<item row="0" column="1">
<widget class="QComboBox" name="serialPortCB">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="serialBaudrateCB"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="serialBaudrateLable">
<property name="text">
<string>串口号</string>
<string>波特率</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<item row="3" column="0" colspan="2">
<widget class="QPushButton" name="serialOpenKey">
<property name="text">
<string>打开</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="serialBaudrateCB"/>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="serialPortCB">
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
<item row="2" column="0" colspan="2">
<widget class="QPushButton" name="serialRefreshKey">
<property name="text">
<string>刷新</string>
</property>
</widget>
</item>

15
src/zqui/zqui/zqui.cpp

@ -26,8 +26,7 @@ void ZQUI::iShow(const char *fmt, ...) {
va_end(args);
QString text(buf);
doinui([this,text](){ pmainW->iShow(text); });
doinui([this, text]() { pmainW->iShow(text); });
}
void ZQUI::iRawShow(const char *fmt, ...) {
va_list args;
@ -37,7 +36,7 @@ void ZQUI::iRawShow(const char *fmt, ...) {
va_end(args);
QString text(buf);
pmainW->iShow(text);
doinui([this,text](){ pmainW->iShow(text); });
doinui([this, text]() { pmainW->iShow(text); });
}
void ZQUI::iClear() { pmainW->iClear(); }
@ -48,8 +47,7 @@ void ZQUI::reportShow(const char *fmt, ...) {
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
QString text(buf);
doinui([this,text](){ pmainW->reportShow(text); });
doinui([this, text]() { pmainW->reportShow(text); });
}
void ZQUI::reportClear() { pmainW->reportClear(); }
@ -60,8 +58,7 @@ void ZQUI::binaryShow(const char *fmt, ...) {
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
QString text(buf);
doinui([this,text](){ pmainW->binaryShow(text); });
doinui([this, text]() { pmainW->binaryShow(text); });
}
void ZQUI::binaryClear() { pmainW->binaryClear(); }
@ -112,4 +109,6 @@ void ZQUI::doinui_slot(QFunction func) {
if (func.get()) func.get()();
}
void ZQUI::setDeviceConnectedStatus(bool connect) { pmainW->setConnectedStatus(connect); }
void ZQUI::setDeviceConnectedStatus(bool connect) {
DOINUI(([this, connect]() { pmainW->setConnectedStatus(connect); }));
}

10
src/zqui/zqui/zqui.hpp

@ -34,6 +34,7 @@
#include <string>
#include <vector>
#include "../base/logger.hpp"
#include "mainwindow.h"
#include "zqui/base/QFunction.hpp"
@ -78,9 +79,10 @@ class ZQUI : public QObject {
void doinui_signal(QFunction);
};
#define ISHOW(fmt, ...) ZQUI::ins()->iShow(fmt, ##__VA_ARGS__)
#define IRSHOW(fmt, ...) ZQUI::ins()->iRawShow(fmt, ##__VA_ARGS__)
#define ICLEAR() ZQUI::ins()->iClear()
#define ISHOW(fmt, ...) ZQUI::ins()->iShow(fmt, ##__VA_ARGS__)
#define ISHOW_ERROR(fmt, ...) ZQUI::ins()->iShow("错误: ", fmt, ##__VA_ARGS__)
#define IRSHOW(fmt, ...) ZQUI::ins()->iRawShow(fmt, ##__VA_ARGS__)
#define ICLEAR() ZQUI::ins()->iClear()
#define RSHOW(fmt, ...) ZQUI::ins()->reportShow(fmt, ##__VA_ARGS__)
#define RCLEAR() ZQUI::ins()->reportClear()
@ -88,4 +90,4 @@ class ZQUI : public QObject {
#define BSHOW(fmt, ...) ZQUI::ins()->binaryShow(fmt, ##__VA_ARGS__)
#define BCLEAR() ZQUI::ins()->binaryClear()
#define DOINUI(fn) ZQUI::ins()->doinui(fn)
#define DOINUI(fn) ZQUI::ins()->doinui(fn)

2
zfpga_basic_protocol

@ -1 +1 @@
Subproject commit 9e7042b03742e5d8985b977f4457cbaf2b04c909
Subproject commit e3db34bff7e93791f78fc1c8d6fa6333561f1037
Loading…
Cancel
Save