Skip to content

Commit

Permalink
V1.1.7b
Browse files Browse the repository at this point in the history
* 重构了大量代码,将SerialPort和Terminal分离成单独的类。
* 实现UDP协议,修复TCP/UDP模式的一些bug。
  • Loading branch information
gztss committed Nov 16, 2017
1 parent 38f1e90 commit 6d7f124
Show file tree
Hide file tree
Showing 24 changed files with 1,640 additions and 7,898 deletions.
12 changes: 9 additions & 3 deletions SerialTool/SerialTool.pro
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ SOURCES += \
source/vediobox.cpp \
source/tcpudpport.cpp \
source/defaultconfig.cpp \
source/oscopetimestamp.cpp
source/oscopetimestamp.cpp \
source/terminalview.cpp \
source/serialport.cpp

HEADERS += \
include/aboutbox.h \
Expand All @@ -65,7 +67,9 @@ HEADERS += \
include/vediobox.h \
include/tcpudpport.h \
include/defaultconfig.h \
include/oscopetimestamp.h
include/oscopetimestamp.h \
include/terminalview.h \
include/serialport.h

DISTFILES += \
resource/images/clear.png \
Expand All @@ -90,6 +94,8 @@ FORMS += \
ui/oscilloscope.ui \
ui/filetransferview.ui \
ui/vediobox.ui \
ui/tcpudpport.ui
ui/tcpudpport.ui \
ui/terminalview.ui \
ui/serialport.ui

LIBS += -lqscintilla2
19 changes: 8 additions & 11 deletions SerialTool/include/oscilloscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,18 @@ class Oscilloscope : public QWidget {
~Oscilloscope();

void retranslate();
void loadConfig(QSettings *config);
void saveConfig(QSettings *config);

void start();
void stop();
double yOffset();
double yRange();
double xRange();
bool channelVisible(int channel);
QColor channelColor(int channel);
bool holdReceive();

void setYOffset(double offset);
void setYRange(double range);
void setXRange(double range);
void setXRange(const QString &str);
void setPlotAntialiased(bool status);
void setGridAntialiased(bool status);
void setBackground(QColor color);
void setGridColor(QColor color);
void setChannelColor(int channel, const QColor &color);
void setChannelVisible(int chanel, bool visible);
void addData(const WaveDataType& data);
void clear();

Expand All @@ -52,6 +44,11 @@ class Oscilloscope : public QWidget {
void setupChannel();
void listViewInit();
uint64_t maxCount();
void setChannelVisible(int channel, bool visible);

ChannelItem* channelWidget(int channel) {
return (ChannelItem *)(ui.channelList->itemWidget(ui.channelList->item(channel)));
}

private slots:
void yOffsetChanged(double offset);
Expand All @@ -67,7 +64,7 @@ private slots:
Ui_Oscilloscope ui;
bool replotFlag = 1;
uint64_t count[CH_NUM], _xRange;
QTimer updataTimer; // ¸üж¨Ê±Æ÷
QTimer updataTimer;
OscopeTimeStamp* timeStamp;
};

Expand Down
50 changes: 50 additions & 0 deletions SerialTool/include/serialport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef SERIALPORT_H
#define SERIALPORT_H

#include <QWidget>

class QSerialPort;
class QSettings;

namespace Ui {
class SerialPort;
}

class SerialPort : public QWidget
{
Q_OBJECT

public:
explicit SerialPort(QWidget *parent = 0);
~SerialPort();
void retranslate();
void loadConfig(QSettings *config);
void saveConfig(QSettings *config);
void setVisibleWidget(bool status);
bool open();
void close();
QByteArray readAll();
void write(const QByteArray &data);
bool portStatus(QString &string);
bool isOpen();
void portSetDialog();

signals:
void readyRead();
void portError();
void portChanged();

private:
void scanPort();

private slots:
void onTimerUpdate();
void setBaudRate(const QString &string);

private:
Ui::SerialPort *ui;
QSerialPort *serialPort;
QTimer *timer;
};

#endif // SERIALPORT_H
16 changes: 3 additions & 13 deletions SerialTool/include/serialtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class TcpUdpPort;
class WaveDecode;
class SerialPort;

class SerialTool : public QMainWindow
{
Expand All @@ -35,25 +36,17 @@ private slots:
void tabIndexChanged(int index);
void tabActionGroupTriggered(QAction *action);
void changeRunFlag();
void scanPort();
void onSecTimerTimeout();
void openPort();
void closePort();
void onPortSwitchActionTriggered();
void openSetPortInfoBox();
void setPortBaudRate(const QString &string);
void onSendButtonClicked();
void readPortData();
void writePortData();
void writePort(const QByteArray &array);
void onResendBoxChanged(int status);
void resendTimeChange(int msc);
void cleanData();
void setOptions();
void saveFile();
void about();
void onComboBoxChanged(const QString &string);
void onWrapBoxChanged(int status);
void onVedioBoxTriggered();
void onVedioBoxDelete();
void currentTabChanged(int index);
Expand All @@ -65,26 +58,23 @@ private slots:
bool openComPort();
bool openTcpUdpPort();
void loadPortTool();
void dispComPortStatus(QLabel *label);
void dispTcpUdpPortStatus(QLabel *label);
void setTabActionIndex(int index);

private:
Ui_SerialTool ui;
QString docPath;
QTimer resendTimer; // 重发时间
QTimer secTimer; // 秒定时器
TcpUdpPort *tcpUdpPort; // TCP/UDP端口
QSerialPort *serialPort;
QSettings *config;
bool runFlag = true;
QActionGroup *tabActionGroup;
int rxCount, txCount;
QLabel *rxCntLabel, *txCntLabel, *portInfoLabel;
QByteArray asciiBuf;
QVector<QTranslator*> translator;
VedioBox *vedioBox = NULL;
PortType portType;
WaveDecode* waveDecode;
SerialPort *serialPort;
};

#endif // SERIALTOOL_H
26 changes: 18 additions & 8 deletions SerialTool/include/tcpudpport.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
#define TCPUDPPORT_H

#include <QWidget>
#include <QAbstractSocket>

namespace Ui {
class TcpUdpPort;
}

class QSettings;
class QTcpSocket;
class QTcpServer;
class QUdpSocket;
class QHostAddress;

class TcpUdpPort : public QWidget
{
Expand All @@ -23,37 +27,43 @@ class TcpUdpPort : public QWidget
public:
explicit TcpUdpPort(QWidget *parent = 0);
~TcpUdpPort();

void loadConfig(QSettings *config);
void saveConfig(QSettings *config);
void setVisibleWidget(bool status);
bool open();
void close();
QByteArray readAll();
void write(const QByteArray &array);
bool isOpen(void);
QString serverAddress();
QString portAddress();
int portNumber();
QString portProtocol();
void setServerAddress(const QString & string);
void setPortNumber(int port);
void setPortProtocol(const QString & string);
void retranslate();
bool portStatus(QString &string);

signals:
void protocolChanged();
void readyRead();
void connectionError();

private:
QString localHost();
bool openTcpClient();
bool openTcpServer();
bool openUdpScoket();
void readUdpDatagrams();
QHostAddress hostAddress();

private slots:
void newConnectSlot();
void readMessage();
void onProtocolChanged();
void ipAddressEdited();
void removeUserFormList();
void onError();

private:
Ui::TcpUdpPort *ui;
QTcpSocket *tcpClient = NULL;
QTcpServer *tcpServer = NULL;
QUdpSocket *udpSocket = NULL;
QList<QTcpSocket *> listClient;
Protocol protocol;
QString serverIP;
Expand Down
56 changes: 56 additions & 0 deletions SerialTool/include/terminalview.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef TERMINALVIEW_H
#define TERMINALVIEW_H

#include <QWidget>

namespace Ui {
class TerminalView;
}

class QTimer;
class QSettings;
class QByteArray;

class TerminalView : public QWidget
{
Q_OBJECT

public:
explicit TerminalView(QWidget *parent = 0);
~TerminalView();

void retranslate();
void loadConfig(QSettings *config);
void saveConfig(QSettings *config);
void append(const QByteArray &array);
void clear();
void setFontFamily(QString fonts, int size, QString style);
void setEnabled(bool status);
void setPaused(bool status);

signals:
void sendDataRequest(const QByteArray &array);

private:
void setSendButtonEnabled(bool status);
void arrayToHex(QString &str, const QByteArray &arr, int countOfLine);
void arrayToAscii(QString &str, const QByteArray &arr);
void loadHistory(QSettings *config);
void saveHistory(QSettings *config);

private slots:
void sendData();
void onWrapBoxChanged(int status);
void onSendButtonClicked();
void updateResendTimerStatus();
void setResendInterval(int msc);
void onHistoryBoxChanged(const QString &string);

private:
Ui::TerminalView *ui;
bool sendEnabled = false, paused = false;
QTimer *resendTimer;
QByteArray *asciiBuf;
};

#endif // TERMINALVIEW_H
4 changes: 2 additions & 2 deletions SerialTool/include/version.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#ifndef __VERSION_H
#define __VERSION_H

#define MAIN_VERSION 1.1.6
#define MAIN_VERSION 1.1.7b

#define SOFTWARE_NAME "SerialTool"
#define COPYRIGHT "Copyleft 2017 by Wenliang"

#define _STR_(s) #s
#define __STR(s) _STR_(s)

#define BUILD_VERSION _STR_(31806)
#define BUILD_VERSION _STR_(3396eM)
#define SOFTWARE_VERSION __STR(MAIN_VERSION)

#endif
Loading

0 comments on commit 6d7f124

Please sign in to comment.