Compare commits
No commits in common. "ebaf64b034aca524339d74054882b2bab4d5f23b" and "87af325c5385180b271415e7c76d206806d56b22" have entirely different histories.
ebaf64b034
...
87af325c53
@ -10,7 +10,6 @@ CONFIG += c++17
|
|||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
dialogcalibrate.cpp \
|
dialogcalibrate.cpp \
|
||||||
src/sources/framehandler.cpp \
|
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp \
|
mainwindow.cpp \
|
||||||
src/sources/crc.cpp \
|
src/sources/crc.cpp \
|
||||||
@ -19,7 +18,6 @@ SOURCES += \
|
|||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
dialogcalibrate.h \
|
dialogcalibrate.h \
|
||||||
src/headers/framehandler.h \
|
|
||||||
mainwindow.h \
|
mainwindow.h \
|
||||||
src/headers/CH347DLL.H \
|
src/headers/CH347DLL.H \
|
||||||
src/headers/crc.h \
|
src/headers/crc.h \
|
||||||
|
|||||||
178
mainwindow.cpp
178
mainwindow.cpp
@ -1,6 +1,5 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
@ -9,7 +8,6 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
drvSPI = new DRV_Spi(this);
|
drvSPI = new DRV_Spi(this);
|
||||||
drvUart = new DRV_Uart(this);
|
drvUart = new DRV_Uart(this);
|
||||||
fHandler = new FrameHandler(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -108,7 +106,6 @@ void MainWindow::on_pushButton_5_clicked()
|
|||||||
ui->lineEdit->setEnabled(false);
|
ui->lineEdit->setEnabled(false);
|
||||||
ui->pushButton_5->setEnabled(false);
|
ui->pushButton_5->setEnabled(false);
|
||||||
ui->pushButton_7->setEnabled(true);
|
ui->pushButton_7->setEnabled(true);
|
||||||
ui->btnSpiSaveSetting->setEnabled(false);
|
|
||||||
onLogPrint("Close device success");
|
onLogPrint("Close device success");
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("Close device failed");
|
onLogPrint("Close device failed");
|
||||||
@ -137,17 +134,15 @@ void MainWindow::on_pushButton_2_clicked()
|
|||||||
|
|
||||||
// 判断打开串口设备是否成功
|
// 判断打开串口设备是否成功
|
||||||
if(status == TRUE){
|
if(status == TRUE){
|
||||||
ui->comboSpiMode->setEnabled(true);
|
ui->comboBox_3->setEnabled(true);
|
||||||
ui->comboSpiClock->setEnabled(true);
|
ui->comboBox_4->setEnabled(true);
|
||||||
ui->comboSpiByteOrder->setEnabled(true);
|
ui->comboBox_5->setEnabled(true);
|
||||||
ui->comboSpiDataBits->setEnabled(true);
|
ui->comboBox_6->setEnabled(true);
|
||||||
ui->comboSpiCS1Pol->setEnabled(true);
|
ui->comboBox_16->setEnabled(true);
|
||||||
ui->comboSpiCS2Pol->setEnabled(true);
|
ui->comboBox_17->setEnabled(true);
|
||||||
ui->pushButton_3->setEnabled(true);
|
ui->pushButton_3->setEnabled(true);
|
||||||
ui->pushButton_2->setEnabled(false);
|
ui->pushButton_2->setEnabled(false);
|
||||||
ui->btnSpiSaveSetting->setEnabled(true);
|
|
||||||
onLogPrint("Open device success");
|
onLogPrint("Open device success");
|
||||||
on_btnSpiSaveSetting_clicked(); // 初始化SPI参数
|
|
||||||
}else{
|
}else{
|
||||||
onLogPrint("Open device failed");
|
onLogPrint("Open device failed");
|
||||||
}
|
}
|
||||||
@ -162,12 +157,12 @@ void MainWindow::on_pushButton_3_clicked()
|
|||||||
|
|
||||||
// 判断打开串口设备是否成功
|
// 判断打开串口设备是否成功
|
||||||
if(status == TRUE){
|
if(status == TRUE){
|
||||||
ui->comboSpiMode->setEnabled(false);
|
ui->comboBox_3->setEnabled(false);
|
||||||
ui->comboSpiClock->setEnabled(false);
|
ui->comboBox_4->setEnabled(false);
|
||||||
ui->comboSpiByteOrder->setEnabled(false);
|
ui->comboBox_5->setEnabled(false);
|
||||||
ui->comboSpiDataBits->setEnabled(false);
|
ui->comboBox_6->setEnabled(false);
|
||||||
ui->comboSpiCS1Pol->setEnabled(false);
|
ui->comboBox_16->setEnabled(false);
|
||||||
ui->comboSpiCS2Pol->setEnabled(false);
|
ui->comboBox_17->setEnabled(false);
|
||||||
ui->pushButton_3->setEnabled(false);
|
ui->pushButton_3->setEnabled(false);
|
||||||
ui->pushButton_2->setEnabled(true);
|
ui->pushButton_2->setEnabled(true);
|
||||||
|
|
||||||
@ -177,152 +172,3 @@ void MainWindow::on_pushButton_3_clicked()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_9_clicked() {
|
|
||||||
unsigned char REG[4] = { 0 };
|
|
||||||
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
|
||||||
unsigned char ucChannel = 0;
|
|
||||||
QString tmp = ui->lineEdit_2->text();
|
|
||||||
if (tmp.toInt() < 0 || tmp.toInt() > 256) {
|
|
||||||
onLogPrint("Wrong channel #");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (tmp.toUInt()) {
|
|
||||||
case 256:
|
|
||||||
ucChannel = 0;
|
|
||||||
ucDAC = ucDAC | 0x80;
|
|
||||||
REG[1] = REG[1] | 0x02;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ucChannel = tmp.toUInt();
|
|
||||||
REG[3] = ucChannel;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char ucFun1 = 0;
|
|
||||||
//EN_TADC
|
|
||||||
if (ui->checkBox->isChecked()) {
|
|
||||||
ucFun1 = ucFun1 | 0x01;
|
|
||||||
REG[1] = REG[1] | 0x80;
|
|
||||||
}
|
|
||||||
//FBK_EN
|
|
||||||
if (ui->checkBox_2->isChecked()) {
|
|
||||||
ucFun1 = ucFun1 | 0x02;
|
|
||||||
REG[1] = REG[1] | 0x01;
|
|
||||||
|
|
||||||
}
|
|
||||||
//TEMPTEST_EN
|
|
||||||
if (ui->checkBox_4->isChecked()) {
|
|
||||||
ucFun1 = ucFun1 | 0x04;
|
|
||||||
REG[2] = REG[2] | 0x80;
|
|
||||||
qDebug() << REG[2];
|
|
||||||
}
|
|
||||||
//TEST_EN
|
|
||||||
if (ui->checkBox_3->isChecked()) {
|
|
||||||
ucFun1 = ucFun1 | 0x08;
|
|
||||||
REG[2] = REG[2] | 0x20;
|
|
||||||
}
|
|
||||||
//TRIG_TADC
|
|
||||||
if (ui->checkBox_5->isChecked()) {
|
|
||||||
ucFun1 = ucFun1 | 0x10;
|
|
||||||
REG[2] = REG[2] | 0x40;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char ucFun2 = 0;
|
|
||||||
ucFun2 = ucFun2 | ui->comboBox_12->currentText().toUInt(NULL, 10); //N_CLKDIV18
|
|
||||||
ucFun2 = ucFun2 | (ui->comboBox_14->currentText().toUInt(NULL, 2) << 4); //ICON8
|
|
||||||
REG[1] = REG[1] | (ui->comboBox_12->currentText().toUInt(NULL, 10) << 5);
|
|
||||||
REG[2] = REG[2] | (ui->comboBox_14->currentText().toUInt(NULL, 2));
|
|
||||||
|
|
||||||
QString sendRegData;
|
|
||||||
for (auto i : REG) {
|
|
||||||
sendRegData += "0x" + QString::number(i, 16) + " ";
|
|
||||||
}
|
|
||||||
onLogPrint("Ready to write REG[1] - REG[4] : " + sendRegData);
|
|
||||||
|
|
||||||
QByteArray tmp1 = fHandler->genREGWrite(ucDAC, ucChannel, ucFun1, ucFun2);
|
|
||||||
switch (ui->comboBox->currentIndex()) {
|
|
||||||
case 0:
|
|
||||||
if (drvUart->Uart_Write(tmp1)) {
|
|
||||||
onLogPrint("Send data success");
|
|
||||||
} else {
|
|
||||||
onLogPrint("Send data fail");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
onLogPrint("write data is " + tmp1.toHex());
|
|
||||||
if (drvSPI->spi_Write(tmp1)) {
|
|
||||||
onLogPrint("Send data success");
|
|
||||||
} else {
|
|
||||||
onLogPrint("Send data failed");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_pushButton_10_clicked() {
|
|
||||||
unsigned char ucDAC = ui->comboBox_15->currentText().toUInt(NULL, 10);
|
|
||||||
QByteArray tmp = fHandler->genREGRead(ucDAC);
|
|
||||||
switch (ui->comboBox->currentIndex()) {
|
|
||||||
case 0:
|
|
||||||
if (drvUart->Uart_Write(tmp)) {
|
|
||||||
onLogPrint("Send data success");
|
|
||||||
} else {
|
|
||||||
onLogPrint("Send data fail");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
onLogPrint("write data is " + tmp.toHex());
|
|
||||||
if (drvSPI->spi_Write(tmp)) {
|
|
||||||
onLogPrint("Send data success");
|
|
||||||
QTimer::singleShot(1000, [this]() {
|
|
||||||
QByteArray ba;
|
|
||||||
drvSPI->spi_Read(ba);
|
|
||||||
ui->textBrowser->append("SPI read: " + ba.toHex());
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
onLogPrint("Send data fail");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_btnSpiSaveSetting_clicked() {
|
|
||||||
drvSPI->spi_Init(
|
|
||||||
ui->comboSpiMode->currentIndex(),
|
|
||||||
ui->comboSpiClock->currentIndex(),
|
|
||||||
ui->comboSpiByteOrder->currentIndex(),
|
|
||||||
ui->comboSpiDataBits->currentIndex(),
|
|
||||||
ui->comboSpiCS1Pol->currentIndex(),
|
|
||||||
ui->comboSpiCS2Pol->currentIndex()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onWriteRegButtonClicked() {
|
|
||||||
QByteArray tmp = fHandler->genREGWrite(0x01, 0x01, 0x09, 0x81);
|
|
||||||
ui->textBrowser->append("SPI write: " + tmp.toHex());
|
|
||||||
drvSPI->spi_Write(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::onReadRegButtonClicked() {
|
|
||||||
QByteArray tmp = fHandler->genREGRead(0x01);
|
|
||||||
ui->textBrowser->append("SPI write: " + tmp.toHex());
|
|
||||||
QTimer::singleShot(2000, [this]() {
|
|
||||||
QByteArray ba;
|
|
||||||
drvSPI->spi_Read(ba);
|
|
||||||
ui->textBrowser->append("SPI read: " + ba.toHex());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::on_comboBox_currentTextChanged(const QString& text) {
|
|
||||||
// if (text.toLower() == "spi") {
|
|
||||||
// connect(ui->pushButton_4, &QPushButton::clicked, this, &MainWindow::onWriteRegButtonClicked);
|
|
||||||
// connect(ui->pushButton_10, &QPushButton::clicked, this, &MainWindow::onReadRegButtonClicked);
|
|
||||||
// } else {
|
|
||||||
// disconnect(ui->pushButton_4, &QPushButton::clicked, this, &MainWindow::onWriteRegButtonClicked);
|
|
||||||
// disconnect(ui->pushButton_10, &QPushButton::clicked, this, &MainWindow::onReadRegButtonClicked);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
14
mainwindow.h
14
mainwindow.h
@ -6,7 +6,7 @@
|
|||||||
#include "src/headers/drv_uart.h"
|
#include "src/headers/drv_uart.h"
|
||||||
#include "src/headers/drv_spi.h"
|
#include "src/headers/drv_spi.h"
|
||||||
#include "QDateTime"
|
#include "QDateTime"
|
||||||
#include "src/headers/framehandler.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -49,23 +49,11 @@ private slots:
|
|||||||
|
|
||||||
void on_pushButton_3_clicked();
|
void on_pushButton_3_clicked();
|
||||||
|
|
||||||
void on_pushButton_9_clicked();
|
|
||||||
|
|
||||||
void on_pushButton_10_clicked();
|
|
||||||
|
|
||||||
void on_btnSpiSaveSetting_clicked();
|
|
||||||
void onWriteRegButtonClicked();
|
|
||||||
void onReadRegButtonClicked();
|
|
||||||
|
|
||||||
void on_comboBox_currentTextChanged(const QString& text);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
DialogCalibrate *dc;
|
DialogCalibrate *dc;
|
||||||
DRV_Uart *drvUart;
|
DRV_Uart *drvUart;
|
||||||
DRV_Spi *drvSPI;
|
DRV_Spi *drvSPI;
|
||||||
FrameHandler *fHandler;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@ -90,7 +90,7 @@
|
|||||||
<string>Timeout(ms):</string>
|
<string>Timeout(ms):</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -149,7 +149,7 @@
|
|||||||
<string>Data Bits:</string>
|
<string>Data Bits:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -159,7 +159,7 @@
|
|||||||
<string>Stop Bits:</string>
|
<string>Stop Bits:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -258,7 +258,7 @@
|
|||||||
<string>Baud Rate:</string>
|
<string>Baud Rate:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -268,7 +268,7 @@
|
|||||||
<string>Parity Bits:</string>
|
<string>Parity Bits:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -288,7 +288,7 @@
|
|||||||
<string>UART Device List:</string>
|
<string>UART Device List:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -311,18 +311,15 @@
|
|||||||
<string>SPI Device List:</string>
|
<string>SPI Device List:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QComboBox" name="comboSpiByteOrder">
|
<widget class="QComboBox" name="comboBox_4">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
|
||||||
<number>1</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>LSB</string>
|
<string>LSB</string>
|
||||||
@ -336,7 +333,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="3">
|
<item row="2" column="3">
|
||||||
<widget class="QComboBox" name="comboSpiDataBits">
|
<widget class="QComboBox" name="comboBox_6">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -358,15 +355,12 @@
|
|||||||
<string>SPI Mode:</string>
|
<string>SPI Mode:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="5" rowspan="2">
|
<item row="1" column="5" rowspan="2">
|
||||||
<widget class="QPushButton" name="btnSpiSaveSetting">
|
<widget class="QPushButton" name="pushButton_4">
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
@ -389,13 +383,10 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="3">
|
<item row="1" column="3">
|
||||||
<widget class="QComboBox" name="comboSpiClock">
|
<widget class="QComboBox" name="comboBox_5">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentIndex">
|
|
||||||
<number>1</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>60MHz</string>
|
<string>60MHz</string>
|
||||||
@ -444,7 +435,7 @@
|
|||||||
<string>Clock:</string>
|
<string>Clock:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -454,12 +445,12 @@
|
|||||||
<string>LSB/MSB</string>
|
<string>LSB/MSB</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QComboBox" name="comboSpiMode">
|
<widget class="QComboBox" name="comboBox_3">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -491,12 +482,12 @@
|
|||||||
<string>DataBits:</string>
|
<string>DataBits:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignmentFlag::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="4">
|
<item row="1" column="4">
|
||||||
<widget class="QComboBox" name="comboSpiCS1Pol">
|
<widget class="QComboBox" name="comboBox_16">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -513,7 +504,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="4">
|
<item row="2" column="4">
|
||||||
<widget class="QComboBox" name="comboSpiCS2Pol">
|
<widget class="QComboBox" name="comboBox_17">
|
||||||
<property name="enabled">
|
<property name="enabled">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -641,10 +632,10 @@
|
|||||||
<item row="0" column="6">
|
<item row="0" column="6">
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeType">
|
<property name="sizeType">
|
||||||
<enum>QSizePolicy::Policy::MinimumExpanding</enum>
|
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
@ -1100,7 +1091,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>839</width>
|
<width>839</width>
|
||||||
<height>33</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
|||||||
@ -57,8 +57,7 @@ public:
|
|||||||
bool spi_openDevice(ULONG SpiI2cGpioDevIndex); // 打开设备
|
bool spi_openDevice(ULONG SpiI2cGpioDevIndex); // 打开设备
|
||||||
bool spi_closeDevice(); // 关闭设备
|
bool spi_closeDevice(); // 关闭设备
|
||||||
bool spi_Write(QByteArray &sendData); // SPI写数据
|
bool spi_Write(QByteArray &sendData); // SPI写数据
|
||||||
bool spi_Read(QByteArray &revData); // SPI读数据
|
BOOL spi_Read(QByteArray &revData); // SPI读数据
|
||||||
bool spi_Init(int mode, int clock, int byteOrder, int CS1Pol, int CS2Pol, int dataBits);
|
|
||||||
|
|
||||||
/*************变量定义*************/
|
/*************变量定义*************/
|
||||||
mDRV_Spi_Infors m_DRV_Spi_Infors; //Spi驱动相关信息
|
mDRV_Spi_Infors m_DRV_Spi_Infors; //Spi驱动相关信息
|
||||||
@ -70,6 +69,7 @@ signals:
|
|||||||
private:
|
private:
|
||||||
// 私有成员变量
|
// 私有成员变量
|
||||||
// double m_currentValues[]; // 当前各通道输出值(假设有多个通道)
|
// double m_currentValues[]; // 当前各通道输出值(假设有多个通道)
|
||||||
|
|
||||||
// 私有方法
|
// 私有方法
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,25 +0,0 @@
|
|||||||
#ifndef FRAMEHANDLER_H
|
|
||||||
#define FRAMEHANDLER_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include "QByteArray"
|
|
||||||
#include "qdebug.h"
|
|
||||||
|
|
||||||
class FrameHandler : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit FrameHandler(QObject *parent = nullptr);
|
|
||||||
QByteArray genREGWrite(unsigned char ucDAC,unsigned char ucChannel,unsigned char ucFun1,unsigned char ucFun2);
|
|
||||||
QByteArray genREGRead(unsigned char ucDAC);
|
|
||||||
QByteArray genCrc16(const QByteArray& data);
|
|
||||||
QByteArray genSum(const QByteArray& data);
|
|
||||||
static void genCrc16table(quint16 table[256], quint16 poly);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
private:
|
|
||||||
unsigned char nFrameCount;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // FRAMEHANDLER_H
|
|
||||||
@ -4,4 +4,39 @@
|
|||||||
// void generate_crc16_reverse_table(quint16 *table);
|
// void generate_crc16_reverse_table(quint16 *table);
|
||||||
// QByteArray crc16Reverse(const QByteArray& data);
|
// QByteArray crc16Reverse(const QByteArray& data);
|
||||||
|
|
||||||
|
static void generate_crc16_reverse_table(quint16 table[256], quint16 poly = 0x8408)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 256; ++i) {
|
||||||
|
quint16 crc = static_cast<quint16>(i);
|
||||||
|
for (int j = 0; j < 8; ++j) {
|
||||||
|
if (crc & 0x0001)
|
||||||
|
crc = (crc >> 1) ^ poly;
|
||||||
|
else
|
||||||
|
crc >>= 1;
|
||||||
|
}
|
||||||
|
table[i] = crc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算反射型CRC16-CCITT
|
||||||
|
QByteArray crc16Reverse(const QByteArray& data)
|
||||||
|
{
|
||||||
|
static quint16 table[256];
|
||||||
|
static bool tableInited = false;
|
||||||
|
if (!tableInited) {
|
||||||
|
generate_crc16_reverse_table(table);
|
||||||
|
tableInited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
quint16 crc = 0x6363;
|
||||||
|
for (auto b : data)
|
||||||
|
crc = (crc >> 8) ^ table[(crc ^ static_cast<quint8>(b)) & 0xFF];
|
||||||
|
|
||||||
|
QByteArray result;
|
||||||
|
// 经过和python程序对比,说明CRC16的两个byte位置需调换
|
||||||
|
// result.append(static_cast<char>((crc >> 8) & 0xFF));
|
||||||
|
// result.append(static_cast<char>(crc & 0xFF));
|
||||||
|
result.append(static_cast<char>(crc & 0xFF));
|
||||||
|
result.append(static_cast<char>((crc >> 8) & 0xFF));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@ -79,6 +79,7 @@ bool DRV_Spi::spi_openDevice(ULONG SpiI2cGpioDevIndex)
|
|||||||
// 设置当前打开设备的索引号
|
// 设置当前打开设备的索引号
|
||||||
this->m_DRV_Spi_Infors.opendDevIndex = SpiI2cGpioDevIndex;
|
this->m_DRV_Spi_Infors.opendDevIndex = SpiI2cGpioDevIndex;
|
||||||
return true;
|
return true;
|
||||||
|
// CH347InitSpi();
|
||||||
}
|
}
|
||||||
|
|
||||||
//关闭设备
|
//关闭设备
|
||||||
@ -106,67 +107,35 @@ bool DRV_Spi::spi_Write(QByteArray &sendData)
|
|||||||
// 获取数据包的长度
|
// 获取数据包的长度
|
||||||
ULONG OutLen = sendData.length();
|
ULONG OutLen = sendData.length();
|
||||||
// 将QByteArray转化为UCHAR
|
// 将QByteArray转化为UCHAR
|
||||||
UCHAR *OutBuf = reinterpret_cast<unsigned char*>(sendData.data());
|
const UCHAR *OutBuf = reinterpret_cast<const unsigned char*>(sendData.constData());
|
||||||
|
|
||||||
BOOL RetVal = FALSE;
|
BOOL RetVal = FALSE;
|
||||||
// 调用底层串口发送函数发送数据
|
// 调用底层串口发送函数发送数据
|
||||||
//RetVal = CH347SPI_Write(this->m_DRV_Spi_Infors.opendDevIndex, SPI_WRITE_CS, OutLen, SPI_WRITE_BLOCK_SIZE, (UCHAR *)OutBuf);
|
RetVal = CH347SPI_Write(this->m_DRV_Spi_Infors.opendDevIndex, SPI_WRITE_CS, OutLen, SPI_WRITE_BLOCK_SIZE, (UCHAR *)OutBuf);
|
||||||
RetVal = CH347SPI_WriteRead(this->m_DRV_Spi_Infors.opendDevIndex, 0x80, sendData.count(), OutBuf);
|
|
||||||
// 日志窗口输出调试信息
|
// 日志窗口输出调试信息
|
||||||
DbgPrint("Spi_Write %dBytes %s.", OutLen,RetVal?"succ":"failure");
|
DbgPrint("frame:%d,Spi_Write %dBytes %s.",sendData.at(14), OutLen,RetVal?"succ":"failure");
|
||||||
|
|
||||||
return RetVal ? true : false;
|
return RetVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DRV_Spi::spi_Read(QByteArray &revData)
|
BOOL DRV_Spi::spi_Read(QByteArray &revData)
|
||||||
{
|
{
|
||||||
ULONG InLen = 7;
|
ULONG InLen = 512; // 设置读取的长度,读取完后会将该值赋值为真实的长度
|
||||||
// ULONG OutLen = 0;
|
ULONG OutLen = 0; // 设置读取的长度,读取完后会将该值赋值为真实的长度
|
||||||
// UCHAR InBuf[512] = {0x00};
|
UCHAR InBuf[512] = {0x00};
|
||||||
revData.clear();
|
|
||||||
revData.append(InLen, 0x00);
|
|
||||||
|
|
||||||
BOOL RetVal = FALSE;
|
BOOL RetVal = FALSE;
|
||||||
|
|
||||||
// 读取串口数据
|
// 读取串口数据
|
||||||
//RetVal = CH347SPI_Read(this->m_DRV_Spi_Infors.opendDevIndex, SPI_READ_CS, OutLen, &InLen, InBuf);
|
RetVal = CH347SPI_Read(this->m_DRV_Spi_Infors.opendDevIndex, SPI_READ_CS, OutLen, &InLen, InBuf);
|
||||||
RetVal = CH347SPI_WriteRead(this->m_DRV_Spi_Infors.opendDevIndex, 0x80, InLen, revData.data());
|
|
||||||
|
|
||||||
DbgPrint("CH347Spi_Read %dB %s.", InLen, RetVal ? "succ" : "failure");
|
DbgPrint("CH347Spi_Read %dB %s.",InLen,RetVal?"succ":"failure");
|
||||||
|
|
||||||
// if(RetVal)
|
if(RetVal)
|
||||||
// {
|
{
|
||||||
// //将数据存入revData变量中,返回给调用的函数
|
//将数据存入revData变量中,返回给调用的函数
|
||||||
// revData = QByteArray::fromRawData(static_cast<char*>(InBuf), InLen);
|
revData = QByteArray::fromRawData(reinterpret_cast<const char*>(InBuf), InLen);
|
||||||
// }
|
}
|
||||||
return RetVal ? true : false;
|
return RetVal;
|
||||||
}
|
|
||||||
|
|
||||||
bool DRV_Spi::spi_Init(int mode, int clock, int byteOrder, int CS1Pol, int CS2Pol, int dataBits) {
|
|
||||||
mSpiCfgS spiCon;
|
|
||||||
BOOL rv = FALSE;
|
|
||||||
rv = CH347SPI_GetCfg(m_DRV_Spi_Infors.opendDevIndex, &spiCon);
|
|
||||||
DbgPrint("CH347SPI_GetCfg %s.", rv ? "succ" : "failure");
|
|
||||||
if (rv == FALSE)
|
|
||||||
return false;
|
|
||||||
spiCon.iMode = mode;
|
|
||||||
spiCon.iClock = clock;
|
|
||||||
spiCon.iByteOrder = byteOrder;
|
|
||||||
spiCon.iSpiOutDefaultData = 0xFF;
|
|
||||||
spiCon.iChipSelect = 0x80;
|
|
||||||
spiCon.CS1Polarity = CS1Pol;
|
|
||||||
spiCon.CS2Polarity = CS2Pol;
|
|
||||||
spiCon.iIsAutoDeativeCS = 0;
|
|
||||||
spiCon.iActiveDelay = 0;
|
|
||||||
spiCon.iDelayDeactive = 0;
|
|
||||||
rv = CH347SPI_Init(m_DRV_Spi_Infors.opendDevIndex, &spiCon);
|
|
||||||
DbgPrint("CH347SPI_Init %s.", rv ? "succ" : "failure");
|
|
||||||
if (rv == FALSE)
|
|
||||||
return false;
|
|
||||||
rv = CH347SPI_SetDataBits(m_DRV_Spi_Infors.opendDevIndex, dataBits);
|
|
||||||
DbgPrint("CH347SPI_SetDataBits %s.", rv ? "succ" : "failure");
|
|
||||||
if (rv == FALSE)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,93 +0,0 @@
|
|||||||
#include "framehandler.h"
|
|
||||||
|
|
||||||
FrameHandler::FrameHandler(QObject *parent)
|
|
||||||
: QObject{parent}
|
|
||||||
{
|
|
||||||
nFrameCount=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void FrameHandler::genCrc16table(quint16 table[256], quint16 poly = 0x8408)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 256; ++i) {
|
|
||||||
quint16 crc = static_cast<quint16>(i);
|
|
||||||
for (int j = 0; j < 8; ++j) {
|
|
||||||
if (crc & 0x0001)
|
|
||||||
crc = (crc >> 1) ^ poly;
|
|
||||||
else
|
|
||||||
crc >>= 1;
|
|
||||||
}
|
|
||||||
table[i] = crc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算反射型CRC16-CCITT
|
|
||||||
QByteArray FrameHandler::genCrc16(const QByteArray& data)
|
|
||||||
{
|
|
||||||
static quint16 table[256];
|
|
||||||
static bool tableInited = false;
|
|
||||||
if (!tableInited) {
|
|
||||||
FrameHandler::genCrc16table(table);
|
|
||||||
tableInited = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
quint16 crc = 0x6363;
|
|
||||||
for (auto b : data)
|
|
||||||
crc = (crc >> 8) ^ table[(crc ^ static_cast<quint8>(b)) & 0xFF];
|
|
||||||
|
|
||||||
QByteArray result;
|
|
||||||
// 经过和python程序对比,说明CRC16的两个byte位置需调换
|
|
||||||
// result.append(static_cast<char>((crc >> 8) & 0xFF));
|
|
||||||
// result.append(static_cast<char>(crc & 0xFF));
|
|
||||||
result.append(static_cast<char>(crc & 0xFF));
|
|
||||||
result.append(static_cast<char>((crc >> 8) & 0xFF));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray FrameHandler::genSum(const QByteArray &data)
|
|
||||||
{
|
|
||||||
quint8 sum = 0;
|
|
||||||
for (int i = 0; i < data.length(); ++i) {
|
|
||||||
sum += static_cast<quint8>(data.at(i)); // 自动处理溢出
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray tmp;
|
|
||||||
tmp.append(sum);
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QByteArray FrameHandler::genREGWrite(unsigned char ucDAC, unsigned char ucChannel, unsigned char ucFun1, unsigned char ucFun2)
|
|
||||||
{
|
|
||||||
QByteArray cmd1(16,0);
|
|
||||||
cmd1[0]=0x9F;
|
|
||||||
cmd1[1]=0xE4;
|
|
||||||
cmd1[2]=0x04;
|
|
||||||
cmd1[3]=ucDAC;
|
|
||||||
cmd1[4]=ucChannel;
|
|
||||||
cmd1[5]=ucFun1;
|
|
||||||
cmd1[6]=ucFun2;
|
|
||||||
cmd1[14]=nFrameCount;
|
|
||||||
QByteArray sumResult = genSum(cmd1);
|
|
||||||
cmd1[15] = static_cast<char>(sumResult.at(0));
|
|
||||||
|
|
||||||
nFrameCount++;
|
|
||||||
|
|
||||||
return cmd1;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray FrameHandler::genREGRead(unsigned char ucDAC)
|
|
||||||
{
|
|
||||||
QByteArray cmd1(16,0);
|
|
||||||
cmd1[0]=0x9F;
|
|
||||||
cmd1[1]=0xE4;
|
|
||||||
cmd1[2]=0x05;
|
|
||||||
cmd1[3]=ucDAC;
|
|
||||||
cmd1[14]=nFrameCount;
|
|
||||||
QByteArray sumResult = genSum(cmd1);
|
|
||||||
cmd1[15] = static_cast<char>(sumResult.at(0));
|
|
||||||
|
|
||||||
|
|
||||||
nFrameCount++;
|
|
||||||
return cmd1;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user