提交 5e9c47d4 编写于 作者: 代码海贼团船长's avatar 代码海贼团船长

单挑发送功能基本完成,除了hexsend界面的输入验证

上级 9831a5df
......@@ -23,7 +23,7 @@ add_executable(ZTTY main.cpp
control/serialport/zserialport.cpp control/serialport/zserialport.h
control/zcontrol.cpp control/zcontrol.h
control/data/zsettings.cpp control/data/zsettings.h
ui/home.cpp ui/home.h ui/home.ui)
ui/home.cpp ui/home.h ui/home.ui control/data/zpagedata.cpp control/data/zpagedata.h)
target_link_libraries(ZTTY
Qt5::Core
......
......@@ -369,7 +369,7 @@ that material) supplement the terms of this License with terms:
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
c) Prohibiting misrepresentation of the qPoint of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
......
//
// Created by 11518 on 2022/11/10.
//
#include <QFile>
#include <QDataStream>
#include "zpagedata.h"
bool ZPageData::savePageData(const QVector<Page> &pageDatas,int currentPage,const QString &fileName) {
QFile file(fileName);
if(!file.open(QIODevice::WriteOnly))
{
return false;
}
QDataStream out(&file);
out << pageDatas <<currentPage;
file.close();
return true;
}
bool ZPageData::openPageData(QVector<Page> &pageDatas,int &currentPage,const QString &fileName) {
QFile file(fileName);
if(!file.open(QIODevice::ReadOnly))
{
return false;
}
QDataStream in(&file);
in >> pageDatas >>currentPage;
file.close();
return true;
}
//
// Created by 11518 on 2022/11/10.
//
#ifndef ZTTY_ZPAGEDATA_H
#define ZTTY_ZPAGEDATA_H
#include <QByteArray>
#include <QPair>
#include <QVector>
typedef QVector<QPair<bool,QByteArray>> Page;
class ZPageData {
public:
//! 保存文件到本地
bool savePageData(const QVector<Page> &pageDatas,int currentPage,const QString &fileName = "data.dat");
//! 读取文件从本地
bool openPageData(QVector<Page> &pageDatas,int &currentPage,const QString &fileName = "data.dat");
private:
};
#endif //ZTTY_ZPAGEDATA_H
......@@ -140,3 +140,29 @@ void ZSettings::setHexFormalRec(bool checked) {
this->setValue("REC_HEX",checked);
this->endGroup();
}
int ZSettings::getSumPage() const {
int index = this->value("MULTIPLE/PAGE").toInt();
if(index==0)
{
index = 1;
}
return index;
}
void ZSettings::setSumPage(int index) {
this->beginGroup("MULTIPLE");
this->setValue("PAGE",index);
this->endGroup();
}
int ZSettings::getCurrentPage() const {
int index = this->value("MULTIPLE/CURRENT").toInt();
return index;
}
void ZSettings::setCurrentPage(int index) {
this->beginGroup("MULTIPLE");
this->setValue("CURRENT",index);
this->endGroup();
}
......@@ -63,6 +63,14 @@ public:
bool getRts() const;
//! 设置Rts功能开关
void setRts(bool icChecked);
//! 获取多条发送有多少页
int getSumPage() const;
//! 设置多条发送有多少页
void setSumPage(int index);
//! 获取多条发送有多少页
int getCurrentPage() const;
//! 设置多条发送有多少页
void setCurrentPage(int index);
//! 析构函数
virtual ~ZSettings();
};
......
......@@ -13,6 +13,7 @@ ZSerialPort::ZSerialPort(QObject *parent) :
m_TimerIdSerialPort = startTimer(1500);
// qDebug()<<this->readBufferSize();
this->setReadBufferSize(256);
}
ZSerialPort::~ZSerialPort() {
......@@ -87,6 +88,10 @@ QStringList ZSerialPort::getDataList() const {
bool ZSerialPort::openTty(const QString &tty, int baud,
QString stopBit, QString dataBit,QString parityBit) {
if(tty.isEmpty())
{
return false;
}
this->setPortName(tty);
this->setBaudRate(baud);
QMetaEnum metaEnum = QMetaEnum::fromType<QSerialPort::StopBits>();
......
......@@ -26,3 +26,7 @@ ZSerialPort *ZControl::getMpSerialPort() const {
ZSettings *ZControl::getMpSettings() const {
return mpSettings;
}
ZPageData *ZControl::getMpPageData() const {
return mpPageData;
}
......@@ -9,6 +9,7 @@
#include <QDebug>
#include "serialport/zserialport.h"
#include "data/zsettings.h"
#include "data/zpagedata.h"
class ZControl : public QObject{
Q_OBJECT
......@@ -19,6 +20,10 @@ private:
ZControl();
ZSerialPort *mpSerialPort;
ZSettings *mpSettings;
ZPageData *mpPageData;
public:
ZPageData *getMpPageData() const;
public:
ZSettings *getMpSettings() const;
......
......@@ -13,7 +13,12 @@
#include "ui_Home.h"
Home::Home(QWidget *parent) : QWidget(parent), ui(new Ui::Home),mpZControl(ZControl::instance()),m_SendNumber(0),m_RecNumber(0) {
Home::Home(QWidget *parent) : QWidget(parent),
ui(new Ui::Home),
mpZControl(ZControl::instance()),
m_SendNumber(0),
m_RecNumber(0),
mpRubberBand(new QRubberBand(QRubberBand::Rectangle, this)){
ui->setupUi(this);
m_TimerId = startTimer(1000);
......@@ -28,6 +33,7 @@ Home::Home(QWidget *parent) : QWidget(parent), ui(new Ui::Home),mpZControl(ZCont
mpMultipleSend = new MultipleSend();
ui->tabWidget->addTab(mpMultipleSend, tr("多条发送"));
//connect(mpMultipleSend,SIGNAL(signalSerialWrite(QByteArray,bool,bool)),this,SLOT(slotSerialWrite(QByteArray, bool,bool)));
ui->cbBox_Tty->addItems(mpZControl->getMpSerialPort()->getTtyList());
connect(ui->cbBox_Tty, SIGNAL(currentTextChanged(const QString &)),this,SLOT(slotTtyNameTextChanged(const QString &)));
......@@ -83,6 +89,8 @@ Home::Home(QWidget *parent) : QWidget(parent), ui(new Ui::Home),mpZControl(ZCont
});
ui->ckBox_HexShow->setChecked(mpZControl->getMpSettings()->getHexFormalRec());
connect(ui->ckBox_HexShow,SIGNAL(stateChanged(int)),this, SLOT(slotHexShowStateChanged(int)));
}
Home::~Home() {
......@@ -100,15 +108,17 @@ void Home::timerEvent(QTimerEvent *event) {
}
void Home::slotPBnTtySetClicked() {
if(mpZControl->getMpSerialPort()->isOpen()){
mpZControl->getMpSerialPort()->close();
ui->pBn_TtySet->setText(tr("打开串口"));
qDebug()<<mpZControl->getMpSerialPort()->isBreakEnabled();
return;
}
bool info = mpZControl->getMpSerialPort()->openTty(ui->cbBox_Tty->currentText(),ui->cbBox_Baud->currentText().toInt(),
ui->cbBox_Stop->currentText(),ui->cbBox_Data->currentText(),ui->cbBox_Parity->currentText());
// mpZControl->getMpSerialPort()->setBreakEnabled(true);
if(!info){
QMessageBox::warning(this,tr("提示"),tr("串口打开失败。"));
}else{
......@@ -257,3 +267,21 @@ void Home::slotHexShowStateChanged(int state) {
}
}
void Home::mousePressEvent(QMouseEvent *event) {
m_Start = event->pos();
mpRubberBand->setGeometry(QRect(m_Start, QSize()));
mpRubberBand->show();
QWidget::mousePressEvent(event);
}
void Home::mouseReleaseEvent(QMouseEvent *event) {
if(mpRubberBand)
mpRubberBand->hide();
QWidget::mouseReleaseEvent(event);
}
void Home::mouseMoveEvent(QMouseEvent *event) {
if(mpRubberBand)
mpRubberBand->setGeometry(QRect(m_Start, event->pos()).normalized());
QWidget::mouseMoveEvent(event);
}
\ No newline at end of file
......@@ -6,6 +6,8 @@
#define ZCOM_HOME_H
#include <QWidget>
#include <QMouseEvent>
#include <QRubberBand>
#include "singlesend.h"
#include "multiplesend.h"
#include "../control/zcontrol.h"
......@@ -20,7 +22,10 @@ Q_OBJECT
protected:
//! 重写定时器
void timerEvent(QTimerEvent *event) override;
//! 重写鼠标事件
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
public:
explicit Home(QWidget *parent = nullptr);
~Home() override;
......@@ -56,7 +61,10 @@ private:
ZControl *mpZControl; //总控界面
uint64_t m_SendNumber; //发送计数
uint64_t m_RecNumber; //接收计数
QByteArray m_RecShow;
QByteArray m_RecShow; //接收展示
QRubberBand *mpRubberBand;//橡皮筋
QPoint m_Start; //橡皮筋起点
};
......
......@@ -9,10 +9,131 @@
MultipleSend::MultipleSend(QWidget *parent) :
QWidget(parent), ui(new Ui::MultipleSend) {
QWidget(parent), ui(new Ui::MultipleSend) ,mpControl(ZControl::instance()){
if(mpControl->getMpPageData()->openPageData(m_PageDatas,m_CurrentPageIndex)){
m_SumPage = m_PageDatas.size();
}else{
m_SumPage = 1;
m_CurrentPageIndex = 0;
m_PageDatas={Page(10)};
}
ui->setupUi(this);
for (int i = 0; i < 10; ++i) {
mpCkBoxList<<this->findChild<QCheckBox*>(QString("cBox_%0").arg(i));
}
for (int i = 0; i < 10; ++i) {
mpSendEditList<<this->findChild<QLineEdit*>(QString("lEdit_%0").arg(i));
}
for (int i = 0; i < 10; ++i) {
mpPbnList<<this->findChild<QPushButton*>(QString("pBn_%0").arg(i));
}
setCurrentPageData();
connect(ui->pBn_HomePage,SIGNAL(clicked()),this,SLOT(slotFirstPage()));
connect(ui->pBn_AddPage,SIGNAL(clicked()),this,SLOT(slotAddPage()));
connect(ui->pBn_LastPage,SIGNAL(clicked()),this,SLOT(slotLastPage()));
connect(ui->pBn_NextPage,SIGNAL(clicked()),this,SLOT(slotNextPage()));
connect(ui->pBn_PrePage,SIGNAL(clicked()),this,SLOT(slotPrePage()));
connect(ui->pBn_Jump,SIGNAL(clicked()),this,SLOT(slotJumpPage()));
connect(ui->pBn_DelPage,SIGNAL(clicked()),this,SLOT(slotRemovePage()));
}
MultipleSend::~MultipleSend() {
if(!mpControl->getMpPageData()->savePageData(m_PageDatas,m_CurrentPageIndex)){
std::remove("data.dat");
}
delete ui;
}
void MultipleSend::slotFirstPage() {
m_CurrentPageIndex = 0;
setCurrentPageData();
}
void MultipleSend::slotLastPage() {
m_CurrentPageIndex = m_SumPage-1;
setCurrentPageData();
}
void MultipleSend::slotNextPage() {
if(m_CurrentPageIndex==m_SumPage-1)
{
return;
}
m_CurrentPageIndex++;
setCurrentPageData();
}
void MultipleSend::slotPrePage() {
if(m_CurrentPageIndex==0)
{
return;
}
m_CurrentPageIndex--;
setCurrentPageData();
}
void MultipleSend::slotRemovePage() {
if(m_SumPage==1)
{
return;
}
m_PageDatas.remove(m_CurrentPageIndex);
m_SumPage--;
if(m_SumPage==m_CurrentPageIndex)
{
m_CurrentPageIndex--;
}
setCurrentPageData();
}
void MultipleSend::slotAddPage() {
m_SumPage++;
m_PageDatas.append(Page (10));
m_CurrentPageIndex++;
setCurrentPageData();
}
void MultipleSend::slotJumpPage() {
m_CurrentPageIndex = ui->spin_Page->value()-1;
setCurrentPageData();
}
void MultipleSend::setCurrentPageData() {
for (int i = 0; i < 10; ++i) {
disconnect(mpCkBoxList[i], nullptr, nullptr, nullptr);
disconnect(mpSendEditList[i], nullptr, nullptr, nullptr);
disconnect(mpPbnList[i], nullptr, nullptr, nullptr);
}
Page&page = m_PageDatas[m_CurrentPageIndex];
//qDebug()<<page <<m_CurrentPageIndex;
for (int i = 0; i < 10; ++i) {
connect(mpCkBoxList[i], &QCheckBox::clicked, [=,&page](bool checked) {
page[i].first = checked;
});
connect(mpSendEditList[i], &QLineEdit::textChanged, [=,&page](const QString &text) {
page[i].second = text.toLocal8Bit();
});
connect(mpPbnList[i], &QPushButton::clicked, [=,&page]() {
emit signalMultipleSerialWrite(page[i].second,ui->ckBox_SendEnter->isChecked());
});
}
for (int i = 0; i < 10; ++i) {
mpCkBoxList[i]->setChecked(page[i].first);
mpSendEditList[i]->setText(page[i].second.trimmed());
}
ui->spin_Page->setMaximum(m_SumPage);
ui->label_PageNumber->setText(QString("页码:%1/%2").arg(m_CurrentPageIndex+1).arg(m_SumPage));
}
......@@ -6,22 +6,42 @@
#define ZTTY_MULTIPLESEND_H
#include <QWidget>
#include <QCheckBox>
#include <QLineEdit>
#include <QPushButton>
#include "control/zcontrol.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MultipleSend; }
QT_END_NAMESPACE
class MultipleSend : public QWidget {
Q_OBJECT
signals:
void signalMultipleSerialWrite(QByteArray array, bool isEnter);
public:
explicit MultipleSend(QWidget *parent = nullptr);
~MultipleSend() override;
private slots:
void slotFirstPage();
void slotLastPage();
void slotNextPage();
void slotPrePage();
void slotRemovePage();
void slotAddPage();
void slotJumpPage();
private:
Ui::MultipleSend *ui;
QVector<QCheckBox*> mpCkBoxList;
QVector<QLineEdit*> mpSendEditList;
QVector<QPushButton*> mpPbnList;
ZControl *mpControl;
QVector<Page> m_PageDatas;
int m_CurrentPageIndex;
int m_SumPage;
void setCurrentPageData();
};
......
此差异已折叠。
......@@ -17,6 +17,8 @@ SingleSend::SingleSend(QWidget *parent) :
connect(ui->pBn_Clear,&QPushButton::clicked,[=](){
ui->tEdit_Send->clear();
ui->progressBar->setValue(0);
ui->lineEdit_FileName->clear();
emit signalClearSendInfo();
});
......@@ -46,21 +48,52 @@ SingleSend::SingleSend(QWidget *parent) :
});
connect(ui->pBn_SendFile,&QPushButton::clicked,[=](){
if(!mpControl->getMpSerialPort()->isOpen()||mpControl->getMpSerialPort()->error()!=QSerialPort::SerialPortError::NoError)
{
QMessageBox::warning(this,tr("提示"),tr("串口没有打开。"));
return ;
}
QFile file(ui->lineEdit_FileName->text());
if(!file.open(QIODevice::ReadOnly))
{
QMessageBox::warning(this,tr("提示"),tr("文件打开失败。"));
return;
}
m_IsSendFile = true;
m_FileArray = file.readAll();
file.close();
//QtConcurrent::run([this](){
// QTimer timer;
// timer.callOnTimeout(this, [=](){
emit signalSerialWrite(m_FileArray,ui->ckBox_HexSend->isChecked(),ui->ckBox_SendEnter->isChecked());
// });
// timer.start(1000);
// });
QtConcurrent::run([this](){
int step = 4096;
QList<QByteArray> byteArrayList;
QByteArray byteArray;
int size = m_FileArray.size();
int quotient = size/step;
int remainder = size%step;
for (int i = 0; i < quotient; ++i) {
byteArrayList << m_FileArray.mid(step*i,step);
}
byteArrayList << m_FileArray.mid(step*quotient,remainder);
for (int i = 0; i < quotient; ++i) {
if(!m_IsSendFile)
{
break;
}
emit signalSerialWrite(byteArrayList[i],ui->ckBox_HexSend->isChecked(),0);
ui->progressBar->setValue(100*i/quotient);
QThread::msleep(ui->spin_Cycle->value());
}
if(m_IsSendFile){
emit signalSerialWrite(byteArrayList[quotient],ui->ckBox_HexSend->isChecked(),ui->ckBox_SendEnter->isChecked());
ui->progressBar->setValue(100);
}
});
});
connect(ui->pBn_StopSendFile,&QPushButton::clicked,[=](){
bool temp = m_IsSendFile;
m_IsSendFile = false;
if(temp)
QMessageBox::warning(this,tr("提示"),tr("已停止发送文件。"));
});
}
......
......@@ -47,7 +47,7 @@ private:
QByteArray m_CurrentArray;
QByteArray m_FileArray;
int m_TimerCycleSend;
bool m_IsSendFile;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册