diff --git a/SerialTool/SerialTool.pro b/SerialTool/SerialTool.pro
index b8c8ab7..8e80215 100644
--- a/SerialTool/SerialTool.pro
+++ b/SerialTool/SerialTool.pro
@@ -38,7 +38,10 @@ SOURCES += \
source/serialtool.cpp\
source/textedit.cpp \
source/wavedecode.cpp \
- source/oscilloscope.cpp
+ source/oscilloscope.cpp \
+ source/filetransferview.cpp \
+ source/filethread.cpp \
+ source/xmodem.cpp
HEADERS += \
include/aboutbox.h \
@@ -50,7 +53,11 @@ HEADERS += \
include/textedit.h \
include/version.h \
include/wavedecode.h \
- include/oscilloscope.h
+ include/oscilloscope.h \
+ include/filethread.h \
+ include/filetransferview.h \
+ include/xmodem.h \
+ include/xmodem_crc16.h
DISTFILES += \
resource/images/clear.png \
@@ -72,6 +79,7 @@ FORMS += \
ui/optionsbox.ui \
ui/portsetbox.ui \
ui/serialtool.ui \
- ui/oscilloscope.ui
+ ui/oscilloscope.ui \
+ ui/filetransferview.ui
LIBS += -lqscintilla2
diff --git a/SerialTool/SerialTool.vcxproj b/SerialTool/SerialTool.vcxproj
index 98ccd24..9f7974c 100644
--- a/SerialTool/SerialTool.vcxproj
+++ b/SerialTool/SerialTool.vcxproj
@@ -90,64 +90,34 @@
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
-
- true
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -213,8 +183,25 @@
+
+
+
+
+
+
+
+ $(QTDIR)\bin\moc.exe;%(FullPath)
+ Moc%27ing filethread.h...
+ .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp
+ "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_SERIALPORT_LIB -DQT_DLL -DQSCINTILLA_DLL "-I.\GeneratedFiles" "-I." "-I.\include" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtPrintSupport" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtSerialPort"
+ $(QTDIR)\bin\moc.exe;%(FullPath)
+ Moc%27ing filethread.h...
+ .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp
+ "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_SERIALPORT_LIB -DQT_DLL -DQSCINTILLA_DLL -D_MBCS "-I.\GeneratedFiles" "-I." "-I.\include" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtPrintSupport" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtSerialPort"
+
+
$(QTDIR)\bin\moc.exe;%(FullPath)
Moc%27ing oscilloscope.h...
@@ -225,6 +212,16 @@
.\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp
"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_SERIALPORT_LIB -DQT_DLL -DQSCINTILLA_DLL -D_MBCS "-I.\GeneratedFiles" "-I." "-I.\include" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtPrintSupport" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtSerialPort"
+
+ $(QTDIR)\bin\moc.exe;%(FullPath)
+ Moc%27ing filetransferview.h...
+ .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp
+ "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_SERIALPORT_LIB -DQT_DLL -DQSCINTILLA_DLL "-I.\GeneratedFiles" "-I." "-I.\include" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtPrintSupport" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtSerialPort"
+ $(QTDIR)\bin\moc.exe;%(FullPath)
+ Moc%27ing filetransferview.h...
+ .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp
+ "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_SERIALPORT_LIB -DQT_DLL -DQSCINTILLA_DLL -D_MBCS "-I.\GeneratedFiles" "-I." "-I.\include" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtPrintSupport" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtSerialPort"
+
Moc%27ing textedit.h...
@@ -300,6 +297,16 @@
.\GeneratedFiles\ui_%(Filename).h;%(Outputs)
"$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)"
+
+ $(QTDIR)\bin\uic.exe;%(AdditionalInputs)
+ Uic%27ing %(Identity)...
+ .\GeneratedFiles\ui_%(Filename).h;%(Outputs)
+ "$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)"
+ $(QTDIR)\bin\uic.exe;%(AdditionalInputs)
+ Uic%27ing %(Identity)...
+ .\GeneratedFiles\ui_%(Filename).h;%(Outputs)
+ "$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)"
+
diff --git a/SerialTool/SerialTool.vcxproj.filters b/SerialTool/SerialTool.vcxproj.filters
index f391773..6b15b22 100644
--- a/SerialTool/SerialTool.vcxproj.filters
+++ b/SerialTool/SerialTool.vcxproj.filters
@@ -18,25 +18,18 @@
qrc;*
false
+
+ {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}
+ ts
+ false
+
{71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}
moc;h;cpp
- False
-
-
- {2f3eb98f-613a-44cd-bd30-e690d4fbdf37}
- cpp;moc
- False
+ true
- {b45b4993-3244-4b95-b793-0db82181128e}
- cpp;moc
- False
-
-
- {639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}
- ts
- false
+ {19712614-0aeb-46d6-89f4-8689ba34d2be}
@@ -61,60 +54,54 @@
Source Files
-
- Generated Files\Debug
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Generated Files
Generated Files\Release
-
- Generated Files\Debug
+
+ Generated Files\Release
+
+
+ Generated Files\Release
Generated Files\Release
-
- Generated Files\Debug
+
+ Generated Files\Release
Generated Files\Release
-
- Generated Files\Debug
-
Generated Files\Release
-
- Generated Files\Debug
-
Generated Files\Release
-
- Generated Files
-
-
- Source Files
-
-
- Generated Files\Debug
-
Generated Files\Release
-
- Source Files
-
-
- Source Files
-
-
- Generated Files\Debug
-
-
- Generated Files\Release
-
@@ -156,6 +143,15 @@
Form Files
+
+ Header Files
+
+
+ Header Files
+
+
+ Form Files
+
@@ -172,9 +168,30 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
+
+ Generated Files
+
+
+ Generated Files
+
+
+ Generated Files
+
Generated Files
+
+ Generated Files
+
+
+ Generated Files
+
diff --git a/SerialTool/include/filethread.h b/SerialTool/include/filethread.h
new file mode 100644
index 0000000..013c02a
--- /dev/null
+++ b/SerialTool/include/filethread.h
@@ -0,0 +1,60 @@
+#ifndef __FILETHREAD_H
+#define __FILETHREAD_H
+
+#include
+#include
+#include
+#include
+#include
+
+class FileThread : public QThread
+{
+ Q_OBJECT
+
+public:
+ enum Protocol {
+ XModem,
+ YModem,
+ ZModem
+ };
+
+ enum TransMode {
+ StopMode,
+ SendMode,
+ ReceiveMode
+ };
+
+public :
+ FileThread();
+ void setFileName(const QString &fileName);
+ void setProtocol(Protocol mode);
+ void setTransMode(TransMode mode);
+ bool startTransfer();
+ bool cancelTransfer();
+ qint64 fileSize();
+ qint64 filePos();
+ char progress();
+ void writeFile(const char* buffer, int size);
+ int readFile(char* buffer, int size);
+ void sendPortData(const QByteArray &array);
+
+public slots:
+ void readData(const QByteArray &array);
+
+signals:
+ void sendData(const QByteArray &);
+ void transFinsh(void);
+
+protected:
+ void run();
+
+private:
+ Protocol protocol;
+ TransMode transMode;
+ qint64 fSize, fPos;
+ QByteArray receiveArray; // 接收缓冲区
+ QString fileName;
+ QFile *file;
+};
+
+#endif
diff --git a/SerialTool/include/filetransferview.h b/SerialTool/include/filetransferview.h
new file mode 100644
index 0000000..ad0ebff
--- /dev/null
+++ b/SerialTool/include/filetransferview.h
@@ -0,0 +1,41 @@
+#ifndef __FILETRANSFERVIEW_H
+#define __FILETRANSFERVIEW_H
+
+#include "ui_filetransferview.h"
+#include
+#include "filethread.h"
+
+class FileTransferView : public QWidget
+{
+ Q_OBJECT
+
+public:
+ FileTransferView(QWidget *parent = Q_NULLPTR);
+ void retranslate();
+ void loadConfig(QSettings *config);
+ void saveConfig(QSettings *config);
+
+public slots:
+ void readData(const QByteArray &array);
+ void cancelTransfer();
+ void logOut(const QString &string, QColor color = Qt::black);
+
+private:
+ void beforceSend();
+
+private slots:
+ void browseButtonClicked();
+ void portSendData(const QByteArray &array);
+ void sendFile();
+ void onTransFinsh();
+
+signals:
+ void sendData(const QByteArray &);
+
+private:
+ Ui_FileTransferView ui;
+ FileThread thread;
+ QByteArray receiveArray; // 接收缓冲区
+};
+
+#endif
diff --git a/SerialTool/include/oscilloscope.h b/SerialTool/include/oscilloscope.h
index 5111613..9984732 100644
--- a/SerialTool/include/oscilloscope.h
+++ b/SerialTool/include/oscilloscope.h
@@ -42,6 +42,7 @@ class Oscilloscope : public QWidget {
void savePdf(const QString &fileName);
private:
+ void setupPlot();
void setupChannel();
void listViewInit();
diff --git a/SerialTool/include/serialtool.h b/SerialTool/include/serialtool.h
index 87e9845..ab4e81d 100644
--- a/SerialTool/include/serialtool.h
+++ b/SerialTool/include/serialtool.h
@@ -36,6 +36,7 @@ private slots:
void onSendButtonClicked();
void readPortData();
void writePortData();
+ void writePort(const QByteArray &array);
void onResendBoxChanged(int status);
void resendTimeChange(int msc);
void cleanData();
@@ -61,7 +62,7 @@ private slots:
int rxCount, txCount;
QLabel *rxCntLabel, *txCntLabel, *portInfoLabel;
QByteArray asciiBuf;
- QTranslator appTranslator, qtTranslator;
+ QTranslator appTranslator, qtTranslator, qsciTranslator;
};
#endif // SERIALTOOL_H
diff --git a/SerialTool/include/textedit.h b/SerialTool/include/textedit.h
index 6112069..bad64a6 100644
--- a/SerialTool/include/textedit.h
+++ b/SerialTool/include/textedit.h
@@ -12,6 +12,7 @@ class TextEdit : public QsciScintilla
void setText(const QString &text);
void append(const QString &text);
void setFonts(QString fonts, int size, QColor color = Qt::black, QString style = "");
+ void setHighLight();
public slots:
void setWrap(bool wrap);
diff --git a/SerialTool/include/version.h b/SerialTool/include/version.h
index 4ce2079..107e37b 100644
--- a/SerialTool/include/version.h
+++ b/SerialTool/include/version.h
@@ -1,7 +1,7 @@
#ifndef __VERSION_H
#define __VERSION_H
-#define MAIN_VERSION 1.0.11
+#define MAIN_VERSION 1.1.1b
#define SOFTWARE_NAME "SerialTool"
#define COPYRIGHT "Copyleft 2017 by Wenliang"
@@ -9,7 +9,7 @@
#define _STR_(s) #s
#define __STR(s) _STR_(s)
-#define BUILD_VERSION _STR_(15fddM)
+#define BUILD_VERSION _STR_(220c3M)
#define SOFTWARE_VERSION __STR(MAIN_VERSION)
#endif
diff --git a/SerialTool/include/xmodem.h b/SerialTool/include/xmodem.h
new file mode 100644
index 0000000..7e34d0d
--- /dev/null
+++ b/SerialTool/include/xmodem.h
@@ -0,0 +1,35 @@
+#ifndef __XMODEM_H
+#define __XMODEM_H
+
+#define XMODEM_SOH 0x01
+#define XMODEM_EOT 0x04
+#define XMODEM_ACK 0x06
+#define XMODEM_NAK 0x15
+#define XMODEM_CAN 0x18
+
+#include "filethread.h"
+
+class XModemClass {
+public :
+ XModemClass(FileThread *thread = NULL);
+ void setThread(FileThread *thread);
+ int transmit(char ch, qint64 &bytes);
+ int receive(const QByteArray &arr, qint64 &bytes);
+ void startTransmit();
+ void startReceive();
+ bool cancelTrans();
+
+private:
+ char calcVerifi(const char *frame);
+
+private:
+ bool transMode;
+ char status;
+ char lastCount;
+ uint8_t packCount; // 包计数
+ char frame[132]; // 数据帧
+ FileThread *thread;
+ QByteArray rxBuf; // 接收缓冲
+};
+
+#endif
diff --git a/SerialTool/include/xmodem_crc16.h b/SerialTool/include/xmodem_crc16.h
new file mode 100644
index 0000000..0ecf35c
--- /dev/null
+++ b/SerialTool/include/xmodem_crc16.h
@@ -0,0 +1,43 @@
+static const unsigned short crc16tab[256] = {
+ 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
+ 0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
+ 0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
+ 0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
+ 0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
+ 0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
+ 0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
+ 0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
+ 0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
+ 0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
+ 0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
+ 0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
+ 0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
+ 0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
+ 0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
+ 0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
+ 0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
+ 0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
+ 0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
+ 0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
+ 0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
+ 0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
+ 0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
+ 0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
+ 0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
+ 0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
+ 0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
+ 0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
+ 0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
+ 0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
+ 0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
+ 0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
+};
+
+unsigned short crc16_ccitt(const unsigned char *buf, int len)
+{
+ register int counter;
+ register unsigned short crc = 0;
+ for (counter = 0; counter < len; counter++)
+ crc = (crc << 8) ^ crc16tab[((crc >> 8) ^ *(char *)buf++) & 0x00FF];
+ return crc;
+}
diff --git a/SerialTool/language/qscintilla_zh_CN.qm b/SerialTool/language/qscintilla_zh_CN.qm
new file mode 100644
index 0000000..70f2aea
Binary files /dev/null and b/SerialTool/language/qscintilla_zh_CN.qm differ
diff --git a/SerialTool/language/zh_CN.qm b/SerialTool/language/zh_CN.qm
index 91128f7..5df3e40 100644
Binary files a/SerialTool/language/zh_CN.qm and b/SerialTool/language/zh_CN.qm differ
diff --git a/SerialTool/language/zh_CN.ts b/SerialTool/language/zh_CN.ts
index 4935540..c16807b 100644
--- a/SerialTool/language/zh_CN.ts
+++ b/SerialTool/language/zh_CN.ts
@@ -17,6 +17,123 @@
淇敼缁樺埗绾挎潯鐨勯鑹
+
+ FileTransferView
+
+
+
+
+
+
+
+
+ 妯″紡
+
+
+
+
+ 鍙戦
+
+
+
+
+ 鎺ユ敹
+
+
+
+
+ 棰勫彂閫佹枃鏈
+
+
+
+
+ 浣跨敤棰勫彂閫佹枃鏈
+
+
+
+
+ 鎿嶄綔
+
+
+
+
+ 鍙栨秷
+
+
+
+
+ 杩涘害锛
+
+
+
+
+ 鏂囦欢锛
+
+
+
+
+ 鍗忚锛
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 寮濮
+
+
+
+
+ 娴忚...
+
+
+
+
+ 寮濮嬩紶杈撴枃浠: "
+
+
+
+
+ 鏃犳硶鎵撳紑鏂囦欢: "
+
+
+
+
+ 閿欒锛
+
+
+
+
+ 閿欒
+
+
+
+
+ 鍙栨秷浼犺緭.
+
+
+
+
+
+ 浼犺緭瀹屾垚.
+
+
+
Oscilloscope
@@ -71,39 +188,39 @@
SerialTool
-
+
寮濮嬪彂閫/鎺ユ敹
-
-
+
+
鏆傚仠鍙戦/鎺ユ敹
-
-
+
+
鎵撳紑绔彛
-
+
鍥惧儚鏂囦欢瀛樺偍鏍煎紡 (*.png);;浣嶅浘鏂囦欢 (*.bmp);;渚挎惡寮忔枃妗f牸寮 (*.pdf)
-
+
鍏抽棴绔彛
-
+
閿欒
-
+
鏃犳硶鎵撳紑绔彛锛
@@ -120,146 +237,151 @@ Port may be occupied or configured incorrectly!
娉㈢壒鐜
-
-
-
+
+
+
璋冭瘯鍔╂墜
-
+
鎺ユ敹璁剧疆
-
+
鍙戦佽缃
-
+
鑷姩鍙戦
-
+
ms
-
+
鍙戦
-
+
Ctrl+Return
-
-
+
+
娉㈠舰缁樺埗
-
+
鏂囦欢
-
+
宸ュ叿
-
+
缂栬緫
-
+
瑙嗗浘
-
+
甯姪
-
+
淇濆瓨
-
+
-
+
閫夐」
-
+
-
+
-
+
娓呯┖缂撳啿
-
+
-
+
绔彛璁剧疆
-
+
鍏抽棴
-
-
+
+
宸ュ叿鏍
-
+
鑷姩鎹㈣
-
+
Ctrl+Enter
-
+
+
+ 鏂囦欢浼犺緭
+
+
+
鐘舵佹爮
-
+
鍏充簬
-
+
diff --git a/SerialTool/source/filethread.cpp b/SerialTool/source/filethread.cpp
new file mode 100644
index 0000000..05662aa
--- /dev/null
+++ b/SerialTool/source/filethread.cpp
@@ -0,0 +1,151 @@
+#include "filethread.h"
+#include "xmodem.h"
+
+static XModemClass xmodem;
+
+FileThread::FileThread()
+{
+ xmodem.setThread(this);
+ transMode = StopMode;
+}
+
+// 发送文件
+void FileThread::setFileName(const QString &fileName)
+{
+ this->fileName = fileName;
+}
+
+// 设置传输协议
+void FileThread::setProtocol(Protocol mode)
+{
+ protocol = mode;
+}
+
+// 设置收发模式
+void FileThread::setTransMode(TransMode mode)
+{
+ transMode = mode;
+}
+
+// 启动传输
+bool FileThread::startTransfer()
+{
+ bool res;
+ file = new QFile(fileName);
+ if (transMode == SendMode) {
+ res = file->open(QFile::ReadOnly);
+ switch (protocol) {
+ case XModem:
+ xmodem.startTransmit();
+ break;
+ default:
+ break;
+ }
+ } else {
+ res = file->open(QFile::WriteOnly);
+ switch (protocol) {
+ case XModem:
+ xmodem.startReceive();
+ break;
+ default:
+ break;
+ }
+ }
+ fSize = file->size();
+ fPos = 0;
+ return res;
+}
+
+// 取消传输
+bool FileThread::cancelTransfer()
+{
+ bool res = true;
+
+ switch (protocol) {
+ case XModem:
+ res = xmodem.cancelTrans();
+ break;
+ default:
+ break;
+ }
+ if (res) {
+ file->close();
+ transMode = StopMode;
+ }
+ return res;
+}
+
+// 获取文件大小
+qint64 FileThread::fileSize()
+{
+ return fSize;
+}
+
+// 获取文件偏移
+qint64 FileThread::filePos()
+{
+ return fPos;
+}
+
+// 获取传输进度
+char FileThread::progress()
+{
+ if (fSize == 0) {
+ return 0;
+ }
+ return (char)(fPos * 100 / fSize);
+}
+
+// 读取数据槽函数
+void FileThread::readData(const QByteArray &array)
+{
+ char result = 0;
+
+ if (transMode == SendMode) { // 发送模式
+ switch (protocol) {
+ case XModem:
+ result = xmodem.transmit(array[0], fPos);
+ break;
+ default:
+ break;
+ }
+ } else if (transMode == ReceiveMode) { // 接收模式
+ switch (protocol) {
+ case XModem:
+ result = xmodem.receive(array, fPos);
+ break;
+ default:
+ break;
+ }
+ fSize = fPos;
+ }
+ if (result) { // 传输结束
+ file->close();
+ delete file;
+ file = nullptr;
+ transMode = StopMode;
+ emit transFinsh();
+ }
+}
+
+// 发送数据
+void FileThread::sendPortData(const QByteArray &array)
+{
+ emit sendData(array);
+}
+
+// 线程函数
+void FileThread::run()
+{
+ exec();
+}
+
+void FileThread::writeFile(const char* buffer, int size)
+{
+ file->write(buffer, size);
+}
+
+int FileThread::readFile(char* buffer, int size)
+{
+ return file->read(buffer, size);
+}
diff --git a/SerialTool/source/filetransferview.cpp b/SerialTool/source/filetransferview.cpp
new file mode 100644
index 0000000..b543648
--- /dev/null
+++ b/SerialTool/source/filetransferview.cpp
@@ -0,0 +1,163 @@
+#include "filetransferview.h"
+#include
+#include
+#include
+#include "xmodem.h"
+
+// 构造函数
+FileTransferView::FileTransferView(QWidget *parent) : QWidget(parent)
+{
+ ui.setupUi(this);
+
+ connect(&thread, &FileThread::sendData, this, &FileTransferView::portSendData);
+ connect(ui.stopButton, SIGNAL(clicked()), this, SLOT(cancelTransfer()));
+ connect(ui.browseButton, SIGNAL(clicked()), this, SLOT(browseButtonClicked()));
+ connect(ui.startButton, SIGNAL(clicked()), this, SLOT(sendFile()));
+ connect(&thread, SIGNAL(transFinsh()), this, SLOT(onTransFinsh()));
+}
+
+void FileTransferView::retranslate()
+{
+ ui.retranslateUi(this);
+}
+
+/* 读取配置文件 */
+void FileTransferView::loadConfig(QSettings *config)
+{
+ config->beginGroup("FileTransmit");
+ ui.beforeSendEdit->setText(config->value("BeforeSendText").toString());
+ ui.enableBerforSendBox->setChecked(config->value("BeforeSend").toBool());
+ ui.pathBox->setText(config->value("FileName").toString());
+ ui.protocolBox->setCurrentText(config->value("Protocol").toString());
+ if (config->value("SendMode").toBool()) {
+ ui.sendButton->setChecked(true);
+ } else {
+ ui.receiveButton->setChecked(true);
+ }
+ config->endGroup();
+}
+
+// 保存配置
+void FileTransferView::saveConfig(QSettings *config)
+{
+ config->beginGroup("FileTransmit");
+ config->setValue("BeforeSendText", QVariant(ui.beforeSendEdit->toPlainText()));
+ config->setValue("BeforeSend", QVariant(ui.enableBerforSendBox->isChecked()));
+ config->setValue("FileName", QVariant(ui.pathBox->text()));
+ config->setValue("Protocol", QVariant(ui.protocolBox->currentText()));
+ config->setValue("SendMode", QVariant(ui.sendButton->isChecked()));
+ config->endGroup();
+}
+
+// 打开文件按钮按下
+void FileTransferView::browseButtonClicked()
+{
+ QString fname;
+ if (ui.sendButton->isChecked()) {
+ fname = QFileDialog::getOpenFileName(this, "Open File", ui.pathBox->text());
+ } else {
+ fname = QFileDialog::getSaveFileName(this, "Open File", ui.pathBox->text());
+ }
+ if (!fname.isEmpty()) { // 文件名有效
+ ui.pathBox->setText(fname);
+ }
+}
+
+// 发送文件
+void FileTransferView::sendFile()
+{
+ bool res = true;
+ FileThread::TransMode mode[] {
+ FileThread::SendMode,
+ FileThread::ReceiveMode
+ };
+ QFile file(ui.pathBox->text());
+
+ if (ui.sendButton->isChecked()) { // 发送模式要求文件可以以只读方式打开
+ res = file.open(QFile::ReadOnly);
+ if (res) {
+ file.close();
+ }
+ } else { // 接收模式要求文件可以以只写方式打开
+ res = file.open(QFile::WriteOnly);
+ if (res) {
+ file.close();
+ }
+ }
+ if (res) {
+ thread.setFileName(ui.pathBox->text());
+ thread.setProtocol(FileThread::XModem);
+ thread.setTransMode(mode[!ui.sendButton->isChecked()]);
+ beforceSend(); // 预发送文本
+ thread.startTransfer();
+ ui.startButton->setEnabled(false);
+ ui.stopButton->setEnabled(true);
+ QString string(tr("Start transmit file: \"")
+ + ui.pathBox->text() + "\".");
+ logOut(string, Qt::blue);
+ } else { // 无法打开文件
+ QString string(tr("Can not open the file: \"")
+ + ui.pathBox->text() + "\".\n");
+
+ logOut(tr("Error: ") + string, Qt::red);
+ QMessageBox err(QMessageBox::Critical,
+ tr("Error"),
+ string,
+ QMessageBox::Cancel, this);
+ err.exec();
+ }
+}
+
+// 发送数据
+void FileTransferView::portSendData(const QByteArray &array)
+{
+ QString string;
+ emit sendData(array);
+
+ ui.progressBar->setValue(thread.progress());
+}
+
+// 接收数据
+void FileTransferView::readData(const QByteArray &array)
+{
+ thread.readData(array);
+}
+
+// 取消发送
+void FileTransferView::cancelTransfer()
+{
+ if (thread.cancelTransfer()) {
+ logOut(tr("Cancel transfer.\n"), Qt::blue);
+ ui.startButton->setEnabled(true);
+ ui.stopButton->setEnabled(false);
+ }
+}
+
+// 显示一条log
+void FileTransferView::logOut(const QString &string, QColor color)
+{
+ QString time = QDateTime::currentDateTime().toString("hh:mm:ss");
+
+ ui.textEdit->setTextColor(color);
+ ui.textEdit->append("[" + time + "] " + string);
+}
+
+// 传输完成槽
+void FileTransferView::onTransFinsh()
+{
+ ui.startButton->setEnabled(true);
+ ui.stopButton->setEnabled(false);
+ logOut(tr("Transmit finished.\n"), Qt::darkGreen);
+}
+
+// 预发送文本
+void FileTransferView::beforceSend()
+{
+ // 只有在发送模式下才可以使用预发送模式
+ if (ui.sendButton->isChecked() && ui.enableBerforSendBox->isChecked()) {
+ QTextCodec *code = QTextCodec::codecForName("GB-2312");
+ QByteArray arr = code->fromUnicode(ui.beforeSendEdit->toPlainText());
+
+ emit sendData(arr);
+ }
+}
diff --git a/SerialTool/source/oscilloscope.cpp b/SerialTool/source/oscilloscope.cpp
index 0ffc5ed..561ef68 100644
--- a/SerialTool/source/oscilloscope.cpp
+++ b/SerialTool/source/oscilloscope.cpp
@@ -6,8 +6,7 @@ Oscilloscope::Oscilloscope(QWidget *parent)
{
ui.setupUi(parent);
- // 拖动时不抗锯齿
- ui.customPlot->setNoAntialiasingOnDrag(true);
+ setupPlot();
setupChannel();
listViewInit();
@@ -15,7 +14,7 @@ Oscilloscope::Oscilloscope(QWidget *parent)
QRegExpValidator *pReg = new QRegExpValidator(rx, this);
ui.xRangeBox->lineEdit()->setValidator(pReg);
- updataTimer.setInterval(20);
+ updataTimer.setInterval(15);
updataTimer.start();
connect(ui.customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange)));
@@ -38,6 +37,27 @@ void Oscilloscope::retranslate()
ui.retranslateUi(this);
}
+
+// 初始化示波器界面
+void Oscilloscope::setupPlot()
+{
+ // 拖动时不抗锯齿
+ ui.customPlot->setNoAntialiasingOnDrag(true);
+
+ // 设置刻度线
+ QSharedPointer< QCPAxisTicker> xTicker(new QCPAxisTicker);
+ QSharedPointer< QCPAxisTicker> yTicker(new QCPAxisTicker);
+ xTicker->setTickCount(5);
+ ui.customPlot->xAxis->setTicker(xTicker);
+ ui.customPlot->xAxis2->setTicker(xTicker);
+ yTicker->setTickCount(5);
+ ui.customPlot->yAxis->setTicker(yTicker);
+ ui.customPlot->yAxis2->setTicker(yTicker);
+ // 显示小网格
+ ui.customPlot->xAxis->grid()->setSubGridVisible(true);
+ ui.customPlot->yAxis->grid()->setSubGridVisible(true);
+}
+
// 初始化通道
void Oscilloscope::setupChannel()
{
@@ -52,6 +72,7 @@ void Oscilloscope::setupChannel()
ui.customPlot->yAxis->setRange(0, 2, Qt::AlignCenter);
}
+// 通道列表初始化
void Oscilloscope::listViewInit()
{
ui.channelList->setModelColumn(2); // 两列
@@ -142,23 +163,14 @@ void Oscilloscope::setXRange(const QString &str)
// 设置波形绘制抗锯齿
void Oscilloscope::setPlotAntialiased(bool status)
{
- if (status) {
- ui.customPlot->setAntialiasedElement(QCP::aePlottables, true);
- } else {
- ui.customPlot->setNotAntialiasedElement(QCP::aePlottables, true);
- }
+ ui.customPlot->setNotAntialiasedElement(QCP::aePlottables, !status);
}
// 设置网格抗锯齿
void Oscilloscope::setGridAntialiased(bool status)
{
- if (status) {
- ui.customPlot->setAntialiasedElement(QCP::aeGrid, true);
- ui.customPlot->setAntialiasedElement(QCP::aeAxes, true);
- } else {
- ui.customPlot->setNotAntialiasedElement(QCP::aeGrid, true);
- ui.customPlot->setNotAntialiasedElement(QCP::aeAxes, true);
- }
+ ui.customPlot->setAntialiasedElement(QCP::aeGrid, status);
+ ui.customPlot->setAntialiasedElement(QCP::aeAxes, status);
}
// 设置背景颜色
@@ -171,6 +183,7 @@ void Oscilloscope::setBackground(QColor color)
void Oscilloscope::setGridColor(QColor color)
{
QPen pen(color);
+
ui.customPlot->xAxis->setBasePen(pen);
ui.customPlot->xAxis->setTickPen(pen);
ui.customPlot->xAxis->grid()->setPen(pen);
@@ -191,6 +204,12 @@ void Oscilloscope::setGridColor(QColor color)
ui.customPlot->yAxis2->setBasePen(pen);
ui.customPlot->yAxis2->setTickPen(pen);
ui.customPlot->yAxis2->setSubTickPen(pen);
+
+ // 网格颜色
+ color.setAlpha(0x30);
+ pen.setColor(color);
+ ui.customPlot->xAxis->grid()->setSubGridPen(pen);
+ ui.customPlot->yAxis->grid()->setSubGridPen(pen);
}
// 设置通道颜色
diff --git a/SerialTool/source/serialtool.cpp b/SerialTool/source/serialtool.cpp
index ec7d0ae..68b048e 100644
--- a/SerialTool/source/serialtool.cpp
+++ b/SerialTool/source/serialtool.cpp
@@ -24,6 +24,7 @@ SerialTool::SerialTool(QWidget *parent)
// 瀵圭晫闈㈢殑鍒濆鍖栫粨鏉熶箣鍚庡啀璁剧疆璇█鍜屾牱寮忚〃
qApp->installTranslator(&appTranslator);
qApp->installTranslator(&qtTranslator);
+ qApp->installTranslator(&qsciTranslator);
setLanguage("zh_CN");
setStyleSheet("default");
@@ -74,6 +75,7 @@ SerialTool::SerialTool(QWidget *parent)
connect(ui.actionAbout, SIGNAL(triggered()), this, SLOT(about()));
connect(ui.comboBox, SIGNAL(activated(const QString &)), this, SLOT(onComboBoxChanged(const QString &)));
connect(ui.wrapLineBox, SIGNAL(stateChanged(int)), this, SLOT(onWrapBoxChanged(int)));
+ connect(ui.fileTransfer, &FileTransferView::sendData, this, &SerialTool::writePort);
secTimer.start(1000);
}
@@ -94,8 +96,10 @@ void SerialTool::setLanguage(const QString &string)
{
appTranslator.load("language/" + string + ".qm");
qtTranslator.load("language/qt_" + string + ".qm");
+ qsciTranslator.load("language/qscintilla_" + string + ".qm");
ui.retranslateUi(this);
ui.oscPlot->retranslate(); // 绀烘尝鍣ㄧ晫闈㈤噸鏂扮炕璇
+ ui.fileTransfer->retranslate(); // 鏂囦欢浼犺緭鐣岄潰閲嶆柊缈昏瘧
}
// 鍔犺浇鏍峰紡琛
@@ -207,6 +211,9 @@ void SerialTool::loadConfig()
}
config->endGroup();
+ // 璇诲彇鏂囦欢浼犺緭鍔熻兘鐨勮缃
+ ui.fileTransfer->loadConfig(config);
+
// 鏈鍚庤鍙栫郴缁熻缃
loadSettings();
}
@@ -223,7 +230,7 @@ void SerialTool::saveConfig()
// 鎵撳紑椤甸潰閰嶇疆
config->beginGroup("Workspace");
config->setValue("TabIndex",
- QVariant(QString::number(ui.tabWidget->currentIndex())));
+ QVariant(ui.tabWidget->currentIndex()));
config->setValue("ToolBarVisible", QVariant(ui.toolBar1->isVisible()));
config->setValue("StatusBarVisible", QVariant(ui.statusBar->isVisible()));
config->endGroup();
@@ -278,6 +285,9 @@ void SerialTool::saveConfig()
}
config->endGroup();
config->endGroup();
+
+ // 璇诲彇鏂囦欢浼犺緭鍔熻兘鐨勮缃
+ ui.fileTransfer->saveConfig(config);
}
void SerialTool::setOptions()
@@ -576,6 +586,10 @@ void SerialTool::readPortData()
}
}
}
+ // 涓插彛鏂囦欢浼犺緭
+ if (ui.tabWidget->currentIndex() == 2) {
+ ui.fileTransfer->readData(buf);
+ }
}
buf.clear();
}
@@ -591,11 +605,17 @@ void SerialTool::writePortData()
} else {
arr = QByteArray::fromHex(ui.textEditTx->text().toLatin1());
}
- txCount += arr.length(); // 鍙戦佽鏁
- serialPort->write(arr.data(), arr.length());
+ writePort(arr);
}
}
+// 鎯充覆鍙e彂閫佹暟鎹,甯﹀弬鏁
+void SerialTool::writePort(const QByteArray &array)
+{
+ txCount += array.length(); // 鍙戦佽鏁
+ serialPort->write(array.data(), array.length());
+}
+
void SerialTool::cleanData()
{
switch (ui.tabWidget->currentIndex()) {
diff --git a/SerialTool/source/textedit.cpp b/SerialTool/source/textedit.cpp
index 742f34c..42538bf 100644
--- a/SerialTool/source/textedit.cpp
+++ b/SerialTool/source/textedit.cpp
@@ -1,5 +1,6 @@
#include "textedit.h"
#include
+#include
TextEdit::TextEdit(QWidget *parent) : QsciScintilla(parent)
{
@@ -33,11 +34,11 @@ void TextEdit::setFonts(QString fonts, int size, QColor color, QString style)
{
fontFamily = fonts;
fontSize = size;
- lineNumFont = QFont(fonts.section('+', 0, 0), size);
+ lineNumFont = QFont(fonts.section(',', 0, 0), size);
// 文本显示
- SendScintilla(SCI_STYLESETFONT, fonts.toStdString().c_str());
- SendScintilla(SCI_STYLESETSIZE, 0, size);
- SendScintilla(SCI_STYLESETFORE, 0, color);
+ SendScintilla(SCI_STYLESETFONT, STYLE_DEFAULT, fonts.toStdString().c_str());
+ SendScintilla(SCI_STYLESETSIZE, STYLE_DEFAULT, size);
+ SendScintilla(SCI_STYLESETFORE, STYLE_DEFAULT, color);
if (style.indexOf("bold") != -1) { // 粗体字
SendScintilla(SCI_STYLESETBOLD, (int)0, true);
} else {
@@ -48,15 +49,16 @@ void TextEdit::setFonts(QString fonts, int size, QColor color, QString style)
} else {
SendScintilla(SCI_STYLESETITALIC, (int)0, (long)false);
}
+ SendScintilla(SCI_STYLECLEARALL); // 设置全局风格
// 光标颜色
SendScintilla(SCI_SETCARETFORE, color);
// 页边显示行号
SendScintilla(SCI_STYLESETFONT, STYLE_LINENUMBER,
- fonts.section('+', 0, 0).toStdString().c_str());
+ fonts.section(',', 0, 0).toStdString().c_str());
SendScintilla(SCI_STYLESETSIZE, STYLE_LINENUMBER, size);
- SendScintilla(SCI_STYLESETFORE, STYLE_LINENUMBER, 0xFF4030);
+ SendScintilla(SCI_STYLESETFORE, STYLE_LINENUMBER, 0xFF8050);
SendScintilla(SCI_SETMARGINTYPEN, 1, SC_MARGIN_NUMBER);
setMarginsWidth();
@@ -139,3 +141,38 @@ void TextEdit::setWrap(bool wrap)
}
isWrap = wrap;
}
+
+// 设置语法高亮
+void TextEdit::setHighLight()
+{
+ const char* g_szKeywords =
+ "asm auto bool break case catch char class const "
+ "const_cast continue default delete do double "
+ "dynamic_cast else enum explicit extern false finally "
+ "float for friend goto if inline int long mutable "
+ "namespace new operator private protected public "
+ "register reinterpret_cast register return short signed "
+ "sizeof static static_cast struct switch template "
+ "this throw true try typedef typeid typename "
+ "union unsigned using virtual void volatile "
+ "wchar_t while";
+ //...
+ SendScintilla(SCI_SETLEXER, SCLEX_CPP); // C++语法解析
+ SendScintilla(SCI_SETKEYWORDS, (unsigned long)0, g_szKeywords);// 设置关键字
+ // 下面设置各种语法元素前景色
+
+ SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::Keyword, 0xFF4030); // 关键字
+ SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::DoubleQuotedString, 0x1515A3); // 字符串
+ SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::SingleQuotedString, 0x1515A3); // 字符
+ SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::Operator, 0xB48246); // 运算符
+ SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::Number, 0x4F4F2F); // 数字
+ SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::PreProcessor, 0x808080); // 预编译开关
+ SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::Comment, 0x008000); // 块注释
+ SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::CommentLine, 0x008000); // 行注释
+ SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::CommentDoc, 0x008000); // 文档注释(/**开头)
+ SendScintilla(SCI_SETTABWIDTH, 4); // Tab宽度
+
+ // 当前行高亮
+ SendScintilla(SCI_SETCARETLINEVISIBLE, true);
+ SendScintilla(SCI_SETCARETLINEBACK, 0xb0ffff);
+}
diff --git a/SerialTool/source/xmodem.cpp b/SerialTool/source/xmodem.cpp
new file mode 100644
index 0000000..abdc7ae
--- /dev/null
+++ b/SerialTool/source/xmodem.cpp
@@ -0,0 +1,173 @@
+#include "xmodem.h"
+
+// 状态机使用的字符
+#define NONE 0x00 // 空闲状态
+#define TRAN 0x01 // 传输状态
+
+enum {
+ None, // 空闲状态
+ Trans, // 传输状态
+ TransEnd, // 传输结束状态
+ TransEOT // EOT字符的应答状态
+};
+
+#define SOH 0x01
+#define EOT 0x04
+#define ACK 0x06
+#define NAK 0x15
+#define CAN 0x18
+
+XModemClass::XModemClass(FileThread *thread)
+{
+ this->thread = thread;
+}
+
+void XModemClass::setThread(FileThread *thread)
+{
+ this->thread = thread;
+}
+
+// 计算校验值
+char XModemClass::calcVerifi(const char *frame)
+{
+ int value = 0;
+
+ // 只实现了校验和算法
+ for (int i = 3; i < 128 + 3; ++i) {
+ value += frame[i];
+ }
+ return (char)(value & 0xFF);
+}
+
+// 开始传输
+void XModemClass::startTransmit()
+{
+ status = None;
+ transMode = true;
+}
+
+// 开始接收
+void XModemClass::startReceive()
+{
+ QByteArray arr;
+ rxBuf.clear();
+ lastCount = 0;
+ transMode = false;
+
+ arr.append(NAK);
+ thread->sendPortData(arr);
+}
+
+// 取消传输
+bool XModemClass::cancelTrans()
+{
+ QByteArray arr;
+
+ if (transMode) { // 发送模式下取消传输
+ if (status == None) {
+ arr.clear();
+ arr.append(EOT);
+ thread->sendPortData(arr);
+ } else { // 接受模式下取消传输
+ arr.clear();
+ arr.append(CAN);
+ thread->sendPortData(arr);
+ }
+ }
+ return true;
+}
+
+// 发送模式每次接收一个字节
+int XModemClass::transmit(char ch, qint64 &bytes)
+{
+ int rBytes;
+ QByteArray arr;
+
+ if (ch == CAN) { // 取消传输
+ return 1;
+ }
+ switch (status) {
+ case None:
+ if (ch == NAK) { // 开始传输
+ status = ACK;
+ memset(frame, 0, 132); // 初始化帧
+ ch = ACK; // 为了下面传输第一帧
+ status = Trans;
+ }
+ case TransEnd: // 传输结束
+ // 接收到ACK说明最后一帧数据传输完成, 此时传输EOT
+ if (ch == ACK && status == TransEnd) {
+ arr.clear();
+ arr.append(EOT);
+ thread->sendPortData(arr);
+ status = TransEOT; // 进入结束应答状态
+ break;
+ }
+ case Trans: // 传输数据
+ if (ch == ACK) { // 传输下一块数据
+ frame[0] = SOH;
+ ++frame[1];
+ frame[2] = ~frame[1];
+ rBytes = thread->readFile(frame + 3, 128);
+ bytes += rBytes;
+ if (rBytes < 128) { // 说明是最后一帧数据
+ // 多余的字节填充0x1A
+ for (int i = rBytes + 3; i < 131; ++i) {
+ frame[i] = 0x1A;
+ }
+ status = TransEnd;
+ }
+ frame[131] = calcVerifi(frame); // 计算校验字符
+ }
+ arr.clear();
+ arr.append(frame, 132);
+ thread->sendPortData(arr); // 发送数据
+ break;
+ case TransEOT:
+ if (ch == ACK) { // EOT被对方应答, 传输结束
+ status = None;
+ return 1;
+ }
+ break;
+ }
+ return 0;
+}
+
+// 接收模式
+int XModemClass::receive(const QByteArray &arr, qint64 &bytes)
+{
+ int size, pos;
+ const char *pdata;
+ QByteArray tbuf;
+
+ rxBuf.append(arr);
+ size = rxBuf.size();
+ pdata = rxBuf.data();
+ if (pdata[0] == EOT) { // 传输结束
+ tbuf.append(ACK);
+ thread->sendPortData(tbuf); // 发送应答标志
+ return 1;
+ }
+ // 寻找SOH字符
+ for (pos = 0; pos < size && pdata[pos] != SOH; ++pos);
+ if (size - pos < 131) { // 接收区缓冲长度小于132bytes说明不是完整的帧
+ return 0;
+ }
+ pdata += pos; // 获取帧数据
+ // 校验
+ qDebug("last: %d, pdata[1]: %d", lastCount, pdata[1]);
+ if (calcVerifi(pdata) == pdata[131] // 检查校验字节
+ && pdata[1] == ~pdata[2] // 帧计数校验
+ && ((char)(lastCount + 1) == pdata[1] || lastCount == pdata[1])) { // 帧数是否正常
+ thread->writeFile(pdata + 3, 128);
+ bytes += 128;
+ lastCount = pdata[1];
+ tbuf.append(ACK);
+ thread->sendPortData(tbuf); // 发送应答标志
+ } else {
+ tbuf.append(NAK);
+ thread->sendPortData(tbuf); // 发送应答标志
+ }
+ rxBuf = rxBuf.mid(pos + 132); // 保留余下内容
+ return 0;
+}
diff --git a/SerialTool/themes/default.css b/SerialTool/themes/default.css
index 4292703..075b15f 100644
--- a/SerialTool/themes/default.css
+++ b/SerialTool/themes/default.css
@@ -8,7 +8,7 @@ QMainWindow {
background: white;
}
-QComboBox, QSpinBox, QDoubleSpinBox, QListWidget, QLineEdit {
+QComboBox, QSpinBox, QDoubleSpinBox, QListWidget, QLineEdit, QTextEdit {
background: white;
border: 1px solid gray;
border-radius: 3px;
@@ -286,3 +286,17 @@ QToolBar::handle {
background: lightgray;
width: 5px;
}
+
+QProgressBar, QLineEdit {
+ height: 1em;
+}
+
+QProgressBar {
+ background-color: #E0E0E0;
+ border: 1px solid gray;
+ border-radius: 3px;
+}
+
+QProgressBar::chunk{
+ background-color: #05B8CC;
+}
diff --git a/SerialTool/ui/filetransferview.ui b/SerialTool/ui/filetransferview.ui
new file mode 100644
index 0000000..8ef32ed
--- /dev/null
+++ b/SerialTool/ui/filetransferview.ui
@@ -0,0 +1,276 @@
+
+
+ FileTransferView
+
+
+
+ 0
+ 0
+ 586
+ 246
+
+
+
+ Form
+
+
+
+ 2
+
+
+ 2
+
+
+ 2
+
+
+ 2
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ 6
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ Mode
+
+
+
-
+
+
+ Send
+
+
+ true
+
+
+
+ -
+
+
+ Receive
+
+
+
+
+
+
+ -
+
+
+ Before Send
+
+
+
+ 2
+
+
+ 4
+
+
+ 4
+
+
+ 2
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Enable Berfor Send
+
+
+
+
+
+
+ -
+
+
+ Operations
+
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 100
+ 0
+
+
+
+ width: 100px
+
+
-
+
+ XModem
+
+
+ -
+
+ YModem
+
+
+ -
+
+ ZModem
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ File:
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+ Protocol:
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+ false
+
+
+
+ 0
+ 0
+
+
+
+ Cancel
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Browse...
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Progress:
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+ -
+
+
+ 0
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Start
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/SerialTool/ui/serialtool.ui b/SerialTool/ui/serialtool.ui
index d6349d4..7990397 100644
--- a/SerialTool/ui/serialtool.ui
+++ b/SerialTool/ui/serialtool.ui
@@ -87,7 +87,7 @@
-
-
+
0
0
@@ -130,9 +130,24 @@
0
+
+
+ 90
+ 0
+
+
+
+
+ 90
+ 16777215
+
+
1200
+
+ 20
+
-
1200
@@ -173,6 +188,46 @@
115200
+ -
+
+ 128000
+
+
+ -
+
+ 230400
+
+
+ -
+
+ 256000
+
+
+ -
+
+ 345600
+
+
+ -
+
+ 460800
+
+
+ -
+
+ 576000
+
+
+ -
+
+ 921600
+
+
+ -
+
+ 1843200
+
+
@@ -193,7 +248,7 @@
Tester
-
+
2
@@ -210,224 +265,232 @@
2
-
-
-
-
- 0
- 0
-
+
+
+ Qt::Vertical
-
-
- -
-
-
-
-
-
-
- 0
- 0
-
-
-
-
- 3
-
-
- 4
-
-
- 0
-
-
- 2
-
-
- 1
-
-
-
-
-
-
- 0
- 0
-
+
+
+
+ 0
+ 1
+
+
+
+
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+
+ 3
-
- Rx Settings
+
+ 0
-
-
- 2
-
-
- 4
-
-
- 4
-
-
- 4
-
-
-
-
-
-
-
-
- ASCII
-
-
- true
-
-
-
- -
-
-
- Hex
-
-
-
-
-
- -
-
-
- true
-
-
- Wrap Line
-
-
-
-
-
-
- -
-
-
-
- 0
- 0
-
+
+ 0
-
- Tx Settings
+
+ 0
-
-
- 2
-
-
- 4
-
-
- 4
-
-
- 4
-
-
-
-
+
+ 0
+
+
-
+
+
+
+ 0
+ 0
+
+
+
+ Rx Settings
+
+
+
+ 2
+
+
+ 4
+
+
+ 4
+
+
+ 4
+
-
-
-
- ASCII
-
-
- true
-
-
+
+
-
+
+
+ ASCII
+
+
+ true
+
+
+
+ -
+
+
+ Hex
+
+
+
+
-
-
+
+
+ true
+
- Hex
+ Wrap Line
-
- -
-
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Tx Settings
+
+
2
+
+ 4
+
+
+ 4
+
+
+ 4
+
-
-
-
- Resend
-
-
-
- -
-
-
- 10
-
-
- 120000
-
-
- 1000
-
-
+
+
-
+
+
+ ASCII
+
+
+ true
+
+
+
+ -
+
+
+ Hex
+
+
+
+
-
-
-
- ms
+
+
+ 2
-
+
-
+
+
+ Resend
+
+
+
+ -
+
+
+ 10
+
+
+ 120000
+
+
+ 1000
+
+
+
+ -
+
+
+ ms
+
+
+
+
-
-
-
-
-
-
-
- -
-
-
-
-
-
- -
-
-
- false
-
-
-
- 0
- 0
-
-
-
- Ctrl+Enter
-
-
- Send
-
-
- Ctrl+Return
-
+
+
+
- -
-
-
-
- 0
- 0
-
+
-
+
+
+ 3
-
+ -
+
+
+ false
+
+
+
+ 0
+ 0
+
+
+
+ Ctrl+Enter
+
+
+ Send
+
+
+ Ctrl+Return
+
+
+
+ -
+
+
+ -
+
+
+
+ 0
+ 1
+
+
+
+
+
-
-
+
+
@@ -446,6 +509,31 @@
+
+
+ File Transmit
+
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+
+ 0
+
+ -
+
+
+
+
@@ -670,6 +758,12 @@
1
+
+ FileTransferView
+ QWidget
+
+ 1
+
diff --git a/SerialTool/ver_temp.h b/SerialTool/ver_temp.h
index cc561e6..76e469f 100644
--- a/SerialTool/ver_temp.h
+++ b/SerialTool/ver_temp.h
@@ -1,7 +1,7 @@
#ifndef __VERSION_H
#define __VERSION_H
-#define MAIN_VERSION 1.0.11
+#define MAIN_VERSION 1.1.1b
#define SOFTWARE_NAME "SerialTool"
#define COPYRIGHT "Copyleft 2017 by Wenliang"