From 0c12bd69784b843631375a581e0d77432f502374 Mon Sep 17 00:00:00 2001 From: gztss <2269610337@qq.com> Date: Sun, 1 Jul 2018 05:39:32 +0800 Subject: [PATCH] V1.2.3 --- .gitignore | 3 + SerialTool/Makefile | 484 ++++++++++++++++++++++++ SerialTool/SerialTool.pro | 19 +- SerialTool/include/filetransmitview.h | 47 +++ SerialTool/include/optionsbox.h | 2 - SerialTool/include/serialport.h | 4 + SerialTool/include/terminalview.h | 25 +- SerialTool/include/textedit.h | 10 +- SerialTool/include/version.h | 6 +- SerialTool/language/serialtool_zh_CN.ts | 190 +++++----- SerialTool/language/zh_cn/serialtool.qm | Bin 8208 -> 8220 bytes SerialTool/resource/default.ini | 4 +- SerialTool/source/aboutbox.cpp | 2 +- SerialTool/source/defaultconfig.cpp | 2 +- SerialTool/source/filetransmitview.cpp | 186 +++++++++ SerialTool/source/mainwindow.cpp | 32 +- SerialTool/source/optionsbox.cpp | 39 +- SerialTool/source/portsetbox.cpp | 2 +- SerialTool/source/serialport.cpp | 79 +++- SerialTool/source/terminalview.cpp | 184 +++++++-- SerialTool/source/textedit.cpp | 122 ++++-- SerialTool/source/xmodem.cpp | 17 +- SerialTool/themes/default/style.css | 22 +- SerialTool/themes/original/style.css | 0 SerialTool/ui/aboutbox.ui | 4 +- SerialTool/ui/filetransmitview.ui | 270 +++++++++++++ SerialTool/ui/mainwindow.ui | 6 +- SerialTool/ui/optionsbox.ui | 104 +++-- SerialTool/ui/oscilloscope.ui | 2 +- SerialTool/ui/serialport.ui | 7 +- SerialTool/ver_temp.h | 4 +- 31 files changed, 1557 insertions(+), 321 deletions(-) create mode 100644 SerialTool/Makefile create mode 100644 SerialTool/include/filetransmitview.h create mode 100644 SerialTool/source/filetransmitview.cpp create mode 100644 SerialTool/themes/original/style.css create mode 100644 SerialTool/ui/filetransmitview.ui diff --git a/.gitignore b/.gitignore index 8d3b473..dbd16a5 100644 --- a/.gitignore +++ b/.gitignore @@ -246,3 +246,6 @@ ModelManifest.xml *-Debug/ *-Release/ + +.qmake.stash +*/.vscode/ diff --git a/SerialTool/Makefile b/SerialTool/Makefile new file mode 100644 index 0000000..372bb6f --- /dev/null +++ b/SerialTool/Makefile @@ -0,0 +1,484 @@ +############################################################################# +# Makefile for building: SerialTool +# Generated by qmake (2.01a) (Qt 4.8.7) on: ?? 6? 29 15:56:37 2018 +# Project: SerialTool.pro +# Template: app +# Command: /usr/lib/x86_64-linux-gnu/qt4/bin/qmake -o Makefile SerialTool.pro +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +DEFINES = -DQT_DEPRECATED_WARNINGS -DQSCINTILLA_DLL -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED +CFLAGS = -m64 -pipe -fno-pie -no-pie -O2 -Wall -W -D_REENTRANT $(DEFINES) +CXXFLAGS = -m64 -pipe -fno-pie -no-pie -O2 -Wall -W -D_REENTRANT $(DEFINES) +INCPATH = -I/usr/share/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtNetwork -I/usr/include/qt4/QtGui -I/usr/include/qt4 -Iinclude -I. -I. +LINK = g++ +LFLAGS = -m64 -Wl,-O1 +LIBS = $(SUBLIBS) -L/usr/lib/x86_64-linux-gnu -lqscintilla2_qt5 -lQtGui -lQtNetwork -lQtCore -lpthread +AR = ar cqs +RANLIB = +QMAKE = /usr/lib/x86_64-linux-gnu/qt4/bin/qmake +TAR = tar -cf +COMPRESS = gzip -9f +COPY = cp -f +SED = sed +COPY_FILE = $(COPY) +COPY_DIR = $(COPY) -r +STRIP = strip +INSTALL_FILE = install -m 644 -p +INSTALL_DIR = $(COPY_DIR) +INSTALL_PROGRAM = install -m 755 -p +DEL_FILE = rm -f +SYMLINK = ln -f -s +DEL_DIR = rmdir +MOVE = mv -f +CHK_DIR_EXISTS= test -d +MKDIR = mkdir -p + +####### Output directory + +OBJECTS_DIR = ./ + +####### Files + +SOURCES = source/aboutbox.cpp \ + source/channelitem.cpp \ + source/main.cpp \ + source/optionsbox.cpp \ + source/portsetbox.cpp \ + source/textedit.cpp \ + source/wavedecode.cpp \ + source/oscilloscope.cpp \ + source/filethread.cpp \ + source/xmodem.cpp \ + source/vediobox.cpp \ + source/tcpudpport.cpp \ + source/defaultconfig.cpp \ + source/oscopetimestamp.cpp \ + source/terminalview.cpp \ + source/serialport.cpp \ + source/pointdatabuffer.cpp \ + source/valuedisplay.cpp \ + source/mainwindow.cpp \ + source/filetransmitview.cpp moc_channelitem.cpp \ + moc_optionsbox.cpp \ + moc_portsetbox.cpp \ + moc_textedit.cpp \ + moc_oscilloscope.cpp \ + moc_filethread.cpp \ + moc_vediobox.cpp \ + moc_tcpudpport.cpp \ + moc_terminalview.cpp \ + moc_serialport.cpp \ + moc_valuedisplay.cpp \ + moc_mainwindow.cpp \ + moc_filetransmitview.cpp \ + qrc_serialtool.cpp +OBJECTS = aboutbox.o \ + channelitem.o \ + main.o \ + optionsbox.o \ + portsetbox.o \ + textedit.o \ + wavedecode.o \ + oscilloscope.o \ + filethread.o \ + xmodem.o \ + vediobox.o \ + tcpudpport.o \ + defaultconfig.o \ + oscopetimestamp.o \ + terminalview.o \ + serialport.o \ + pointdatabuffer.o \ + valuedisplay.o \ + mainwindow.o \ + filetransmitview.o \ + moc_channelitem.o \ + moc_optionsbox.o \ + moc_portsetbox.o \ + moc_textedit.o \ + moc_oscilloscope.o \ + moc_filethread.o \ + moc_vediobox.o \ + moc_tcpudpport.o \ + moc_terminalview.o \ + moc_serialport.o \ + moc_valuedisplay.o \ + moc_mainwindow.o \ + moc_filetransmitview.o \ + qrc_serialtool.o +DIST = resource/images/clear.png \ + resource/images/close.png \ + resource/images/connect.png \ + resource/images/port \ + config.png \ + resource/images/config.ico \ + resource/images/exit.ico \ + resource/images/icon.ico \ + resource/images/pause.ico \ + resource/images/save.ico \ + resource/images/start.ico \ + /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/common/gcc-base.conf \ + /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ + /usr/share/qt4/mkspecs/common/g++-base.conf \ + /usr/share/qt4/mkspecs/common/g++-unix.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/shared.prf \ + /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + SerialTool.pro +QMAKE_TARGET = SerialTool +DESTDIR = +TARGET = SerialTool + +first: all +####### Implicit rules + +.SUFFIXES: .o .c .cpp .cc .cxx .C + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" + +####### Build rules + +all: Makefile $(TARGET) + +$(TARGET): ui_aboutbox.h ui_optionsbox.h ui_portsetbox.h ui_oscilloscope.h ui_vediobox.h ui_tcpudpport.h ui_terminalview.h ui_valuedisplay.h ui_serialport.h ui_mainwindow.h ui_filetransmitview.h $(OBJECTS) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) + +Makefile: SerialTool.pro /usr/share/qt4/mkspecs/linux-g++-64/qmake.conf /usr/share/qt4/mkspecs/common/unix.conf \ + /usr/share/qt4/mkspecs/common/linux.conf \ + /usr/share/qt4/mkspecs/common/gcc-base.conf \ + /usr/share/qt4/mkspecs/common/gcc-base-unix.conf \ + /usr/share/qt4/mkspecs/common/g++-base.conf \ + /usr/share/qt4/mkspecs/common/g++-unix.conf \ + /usr/share/qt4/mkspecs/qconfig.pri \ + /usr/share/qt4/mkspecs/features/qt_functions.prf \ + /usr/share/qt4/mkspecs/features/qt_config.prf \ + /usr/share/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/share/qt4/mkspecs/features/default_pre.prf \ + /usr/share/qt4/mkspecs/features/release.prf \ + /usr/share/qt4/mkspecs/features/default_post.prf \ + /usr/share/qt4/mkspecs/features/shared.prf \ + /usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ + /usr/share/qt4/mkspecs/features/warn_on.prf \ + /usr/share/qt4/mkspecs/features/qt.prf \ + /usr/share/qt4/mkspecs/features/unix/thread.prf \ + /usr/share/qt4/mkspecs/features/moc.prf \ + /usr/share/qt4/mkspecs/features/resources.prf \ + /usr/share/qt4/mkspecs/features/uic.prf \ + /usr/share/qt4/mkspecs/features/yacc.prf \ + /usr/share/qt4/mkspecs/features/lex.prf \ + /usr/share/qt4/mkspecs/features/include_source_dir.prf \ + /usr/lib/x86_64-linux-gnu/libQtGui.prl \ + /usr/lib/x86_64-linux-gnu/libQtNetwork.prl \ + /usr/lib/x86_64-linux-gnu/libQtCore.prl + $(QMAKE) -o Makefile SerialTool.pro +/usr/share/qt4/mkspecs/common/unix.conf: +/usr/share/qt4/mkspecs/common/linux.conf: +/usr/share/qt4/mkspecs/common/gcc-base.conf: +/usr/share/qt4/mkspecs/common/gcc-base-unix.conf: +/usr/share/qt4/mkspecs/common/g++-base.conf: +/usr/share/qt4/mkspecs/common/g++-unix.conf: +/usr/share/qt4/mkspecs/qconfig.pri: +/usr/share/qt4/mkspecs/features/qt_functions.prf: +/usr/share/qt4/mkspecs/features/qt_config.prf: +/usr/share/qt4/mkspecs/features/exclusive_builds.prf: +/usr/share/qt4/mkspecs/features/default_pre.prf: +/usr/share/qt4/mkspecs/features/release.prf: +/usr/share/qt4/mkspecs/features/default_post.prf: +/usr/share/qt4/mkspecs/features/shared.prf: +/usr/share/qt4/mkspecs/features/unix/gdb_dwarf_index.prf: +/usr/share/qt4/mkspecs/features/warn_on.prf: +/usr/share/qt4/mkspecs/features/qt.prf: +/usr/share/qt4/mkspecs/features/unix/thread.prf: +/usr/share/qt4/mkspecs/features/moc.prf: +/usr/share/qt4/mkspecs/features/resources.prf: +/usr/share/qt4/mkspecs/features/uic.prf: +/usr/share/qt4/mkspecs/features/yacc.prf: +/usr/share/qt4/mkspecs/features/lex.prf: +/usr/share/qt4/mkspecs/features/include_source_dir.prf: +/usr/lib/x86_64-linux-gnu/libQtGui.prl: +/usr/lib/x86_64-linux-gnu/libQtNetwork.prl: +/usr/lib/x86_64-linux-gnu/libQtCore.prl: +qmake: FORCE + @$(QMAKE) -o Makefile SerialTool.pro + +dist: + @$(CHK_DIR_EXISTS) .tmp/SerialTool1.0.0 || $(MKDIR) .tmp/SerialTool1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/SerialTool1.0.0/ && $(COPY_FILE) --parents include/aboutbox.h include/channelitem.h include/optionsbox.h include/portsetbox.h include/textedit.h include/version.h include/wavedecode.h include/oscilloscope.h include/filethread.h include/xmodem.h include/xmodem_crc16.h include/vediobox.h include/tcpudpport.h include/defaultconfig.h include/oscopetimestamp.h include/terminalview.h include/serialport.h include/pointdatabuffer.h include/valuedisplay.h include/mainwindow.h include/filetransmitview.h .tmp/SerialTool1.0.0/ && $(COPY_FILE) --parents resource/serialtool.qrc .tmp/SerialTool1.0.0/ && $(COPY_FILE) --parents source/aboutbox.cpp source/channelitem.cpp source/main.cpp source/optionsbox.cpp source/portsetbox.cpp source/textedit.cpp source/wavedecode.cpp source/oscilloscope.cpp source/filethread.cpp source/xmodem.cpp source/vediobox.cpp source/tcpudpport.cpp source/defaultconfig.cpp source/oscopetimestamp.cpp source/terminalview.cpp source/serialport.cpp source/pointdatabuffer.cpp source/valuedisplay.cpp source/mainwindow.cpp source/filetransmitview.cpp .tmp/SerialTool1.0.0/ && $(COPY_FILE) --parents ui/aboutbox.ui ui/optionsbox.ui ui/portsetbox.ui ui/oscilloscope.ui ui/vediobox.ui ui/tcpudpport.ui ui/terminalview.ui ui/valuedisplay.ui ui/serialport.ui ui/mainwindow.ui ui/filetransmitview.ui .tmp/SerialTool1.0.0/ && $(COPY_FILE) --parents language/serialtool_zh_CN.ts .tmp/SerialTool1.0.0/ && (cd `dirname .tmp/SerialTool1.0.0` && $(TAR) SerialTool1.0.0.tar SerialTool1.0.0 && $(COMPRESS) SerialTool1.0.0.tar) && $(MOVE) `dirname .tmp/SerialTool1.0.0`/SerialTool1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/SerialTool1.0.0 + + +clean:compiler_clean + -$(DEL_FILE) $(OBJECTS) + -$(DEL_FILE) *~ core *.core + + +####### Sub-libraries + +distclean: clean + -$(DEL_FILE) $(TARGET) + -$(DEL_FILE) Makefile + + +check: first + +mocclean: compiler_moc_header_clean compiler_moc_source_clean + +mocables: compiler_moc_header_make_all compiler_moc_source_make_all + +compiler_moc_header_make_all: moc_channelitem.cpp moc_optionsbox.cpp moc_portsetbox.cpp moc_textedit.cpp moc_oscilloscope.cpp moc_filethread.cpp moc_vediobox.cpp moc_tcpudpport.cpp moc_terminalview.cpp moc_serialport.cpp moc_valuedisplay.cpp moc_mainwindow.cpp moc_filetransmitview.cpp +compiler_moc_header_clean: + -$(DEL_FILE) moc_channelitem.cpp moc_optionsbox.cpp moc_portsetbox.cpp moc_textedit.cpp moc_oscilloscope.cpp moc_filethread.cpp moc_vediobox.cpp moc_tcpudpport.cpp moc_terminalview.cpp moc_serialport.cpp moc_valuedisplay.cpp moc_mainwindow.cpp moc_filetransmitview.cpp +moc_channelitem.cpp: include/channelitem.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/channelitem.h -o moc_channelitem.cpp + +moc_optionsbox.cpp: include/optionsbox.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/optionsbox.h -o moc_optionsbox.cpp + +moc_portsetbox.cpp: include/portsetbox.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/portsetbox.h -o moc_portsetbox.cpp + +moc_textedit.cpp: include/textedit.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/textedit.h -o moc_textedit.cpp + +moc_oscilloscope.cpp: include/oscilloscope.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/oscilloscope.h -o moc_oscilloscope.cpp + +moc_filethread.cpp: include/filethread.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/filethread.h -o moc_filethread.cpp + +moc_vediobox.cpp: include/vediobox.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/vediobox.h -o moc_vediobox.cpp + +moc_tcpudpport.cpp: include/tcpudpport.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/tcpudpport.h -o moc_tcpudpport.cpp + +moc_terminalview.cpp: include/terminalview.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/terminalview.h -o moc_terminalview.cpp + +moc_serialport.cpp: include/serialport.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/serialport.h -o moc_serialport.cpp + +moc_valuedisplay.cpp: include/valuedisplay.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/valuedisplay.h -o moc_valuedisplay.cpp + +moc_mainwindow.cpp: include/mainwindow.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/mainwindow.h -o moc_mainwindow.cpp + +moc_filetransmitview.cpp: include/filethread.h \ + include/filetransmitview.h + /usr/lib/x86_64-linux-gnu/qt4/bin/moc $(DEFINES) $(INCPATH) include/filetransmitview.h -o moc_filetransmitview.cpp + +compiler_rcc_make_all: qrc_serialtool.cpp +compiler_rcc_clean: + -$(DEL_FILE) qrc_serialtool.cpp +qrc_serialtool.cpp: resource/serialtool.qrc \ + resource/images/exit.ico \ + resource/images/connect.ico \ + resource/images/open.ico \ + resource/images/config.ico \ + resource/images/save.ico \ + resource/images/start.ico \ + resource/images/close.ico \ + resource/images/pause.ico \ + resource/images/pin_up.ico \ + resource/images/icon.ico \ + resource/images/clear.ico \ + resource/images/pin_down.ico \ + resource/license.html \ + resource/default.ini + /usr/lib/x86_64-linux-gnu/qt4/bin/rcc -name serialtool resource/serialtool.qrc -o qrc_serialtool.cpp + +compiler_image_collection_make_all: qmake_image_collection.cpp +compiler_image_collection_clean: + -$(DEL_FILE) qmake_image_collection.cpp +compiler_moc_source_make_all: +compiler_moc_source_clean: +compiler_uic_make_all: ui_aboutbox.h ui_optionsbox.h ui_portsetbox.h ui_oscilloscope.h ui_vediobox.h ui_tcpudpport.h ui_terminalview.h ui_valuedisplay.h ui_serialport.h ui_mainwindow.h ui_filetransmitview.h +compiler_uic_clean: + -$(DEL_FILE) ui_aboutbox.h ui_optionsbox.h ui_portsetbox.h ui_oscilloscope.h ui_vediobox.h ui_tcpudpport.h ui_terminalview.h ui_valuedisplay.h ui_serialport.h ui_mainwindow.h ui_filetransmitview.h +ui_aboutbox.h: ui/aboutbox.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/aboutbox.ui -o ui_aboutbox.h + +ui_optionsbox.h: ui/optionsbox.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/optionsbox.ui -o ui_optionsbox.h + +ui_portsetbox.h: ui/portsetbox.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/portsetbox.ui -o ui_portsetbox.h + +ui_oscilloscope.h: ui/oscilloscope.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/oscilloscope.ui -o ui_oscilloscope.h + +ui_vediobox.h: ui/vediobox.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/vediobox.ui -o ui_vediobox.h + +ui_tcpudpport.h: ui/tcpudpport.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/tcpudpport.ui -o ui_tcpudpport.h + +ui_terminalview.h: ui/terminalview.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/terminalview.ui -o ui_terminalview.h + +ui_valuedisplay.h: ui/valuedisplay.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/valuedisplay.ui -o ui_valuedisplay.h + +ui_serialport.h: ui/serialport.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/serialport.ui -o ui_serialport.h + +ui_mainwindow.h: ui/mainwindow.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/mainwindow.ui -o ui_mainwindow.h + +ui_filetransmitview.h: ui/filetransmitview.ui + /usr/lib/x86_64-linux-gnu/qt4/bin/uic ui/filetransmitview.ui -o ui_filetransmitview.h + +compiler_yacc_decl_make_all: +compiler_yacc_decl_clean: +compiler_yacc_impl_make_all: +compiler_yacc_impl_clean: +compiler_lex_make_all: +compiler_lex_clean: +compiler_clean: compiler_moc_header_clean compiler_rcc_clean compiler_uic_clean + +####### Compile + +aboutbox.o: source/aboutbox.cpp ui_aboutbox.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o aboutbox.o source/aboutbox.cpp + +channelitem.o: source/channelitem.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o channelitem.o source/channelitem.cpp + +main.o: source/main.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o source/main.cpp + +optionsbox.o: source/optionsbox.cpp ui_optionsbox.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o optionsbox.o source/optionsbox.cpp + +portsetbox.o: source/portsetbox.cpp ui_portsetbox.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o portsetbox.o source/portsetbox.cpp + +textedit.o: source/textedit.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o textedit.o source/textedit.cpp + +wavedecode.o: source/wavedecode.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o wavedecode.o source/wavedecode.cpp + +oscilloscope.o: source/oscilloscope.cpp ui_oscilloscope.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o oscilloscope.o source/oscilloscope.cpp + +filethread.o: source/filethread.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o filethread.o source/filethread.cpp + +xmodem.o: source/xmodem.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o xmodem.o source/xmodem.cpp + +vediobox.o: source/vediobox.cpp ui_vediobox.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o vediobox.o source/vediobox.cpp + +tcpudpport.o: source/tcpudpport.cpp ui_tcpudpport.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o tcpudpport.o source/tcpudpport.cpp + +defaultconfig.o: source/defaultconfig.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o defaultconfig.o source/defaultconfig.cpp + +oscopetimestamp.o: source/oscopetimestamp.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o oscopetimestamp.o source/oscopetimestamp.cpp + +terminalview.o: source/terminalview.cpp ui_terminalview.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o terminalview.o source/terminalview.cpp + +serialport.o: source/serialport.cpp ui_serialport.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o serialport.o source/serialport.cpp + +pointdatabuffer.o: source/pointdatabuffer.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o pointdatabuffer.o source/pointdatabuffer.cpp + +valuedisplay.o: source/valuedisplay.cpp ui_valuedisplay.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o valuedisplay.o source/valuedisplay.cpp + +mainwindow.o: source/mainwindow.cpp ui_mainwindow.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o source/mainwindow.cpp + +filetransmitview.o: source/filetransmitview.cpp ui_filetransmitview.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o filetransmitview.o source/filetransmitview.cpp + +moc_channelitem.o: moc_channelitem.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_channelitem.o moc_channelitem.cpp + +moc_optionsbox.o: moc_optionsbox.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_optionsbox.o moc_optionsbox.cpp + +moc_portsetbox.o: moc_portsetbox.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_portsetbox.o moc_portsetbox.cpp + +moc_textedit.o: moc_textedit.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_textedit.o moc_textedit.cpp + +moc_oscilloscope.o: moc_oscilloscope.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_oscilloscope.o moc_oscilloscope.cpp + +moc_filethread.o: moc_filethread.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_filethread.o moc_filethread.cpp + +moc_vediobox.o: moc_vediobox.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_vediobox.o moc_vediobox.cpp + +moc_tcpudpport.o: moc_tcpudpport.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_tcpudpport.o moc_tcpudpport.cpp + +moc_terminalview.o: moc_terminalview.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_terminalview.o moc_terminalview.cpp + +moc_serialport.o: moc_serialport.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_serialport.o moc_serialport.cpp + +moc_valuedisplay.o: moc_valuedisplay.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_valuedisplay.o moc_valuedisplay.cpp + +moc_mainwindow.o: moc_mainwindow.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_mainwindow.o moc_mainwindow.cpp + +moc_filetransmitview.o: moc_filetransmitview.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_filetransmitview.o moc_filetransmitview.cpp + +qrc_serialtool.o: qrc_serialtool.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o qrc_serialtool.o qrc_serialtool.cpp + +####### Install + +install: FORCE + +uninstall: FORCE + +FORCE: + diff --git a/SerialTool/SerialTool.pro b/SerialTool/SerialTool.pro index 44fbc86..d79e3e4 100644 --- a/SerialTool/SerialTool.pro +++ b/SerialTool/SerialTool.pro @@ -3,10 +3,11 @@ # Project created by QtCreator 2017-02-01T17:03:23 # #------------------------------------------------- - QT += core gui widgets serialport network charts +QT -= console TARGET = SerialTool + TEMPLATE = app # The following define makes your compiler emit warnings if you use @@ -20,7 +21,9 @@ DEFINES += QT_DEPRECATED_WARNINGS QSCINTILLA_DLL # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -QMAKE_CFLAGS += +unix { + QMAKE_LFLAGS += -fno-pie -no-pie # create executable file +} TRANSLATIONS += language/serialtool_zh_CN.ts @@ -37,7 +40,6 @@ SOURCES += \ source/textedit.cpp \ source/wavedecode.cpp \ source/oscilloscope.cpp \ - source/filetransferview.cpp \ source/filethread.cpp \ source/xmodem.cpp \ source/vediobox.cpp \ @@ -48,7 +50,8 @@ SOURCES += \ source/serialport.cpp \ source/pointdatabuffer.cpp \ source/valuedisplay.cpp \ - source/mainwindow.cpp + source/mainwindow.cpp \ + source/filetransmitview.cpp HEADERS += \ include/aboutbox.h \ @@ -60,7 +63,6 @@ HEADERS += \ include/wavedecode.h \ include/oscilloscope.h \ include/filethread.h \ - include/filetransferview.h \ include/xmodem.h \ include/xmodem_crc16.h \ include/vediobox.h \ @@ -71,7 +73,8 @@ HEADERS += \ include/serialport.h \ include/pointdatabuffer.h \ include/valuedisplay.h \ - include/mainwindow.h + include/mainwindow.h \ + include/filetransmitview.h DISTFILES += \ resource/images/clear.png \ @@ -93,12 +96,12 @@ FORMS += \ ui/optionsbox.ui \ ui/portsetbox.ui \ ui/oscilloscope.ui \ - ui/filetransferview.ui \ ui/vediobox.ui \ ui/tcpudpport.ui \ ui/terminalview.ui \ ui/valuedisplay.ui \ ui/serialport.ui \ - ui/mainwindow.ui + ui/mainwindow.ui \ + ui/filetransmitview.ui LIBS += -lqscintilla2_qt5 diff --git a/SerialTool/include/filetransmitview.h b/SerialTool/include/filetransmitview.h new file mode 100644 index 0000000..8883535 --- /dev/null +++ b/SerialTool/include/filetransmitview.h @@ -0,0 +1,47 @@ +#ifndef __FILETRANSFERVIEW_H +#define __FILETRANSFERVIEW_H + +#include +#include "filethread.h" + +namespace Ui { + class FileTransmitView; +} +class QSettings; + +class FileTransmitView : public QWidget +{ + Q_OBJECT + +public: + FileTransmitView(QWidget *parent = Q_NULLPTR); + ~FileTransmitView(); + 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(); + void onTimeoutError(); + +signals: + void sendData(const QByteArray &); + +private: + Ui::FileTransmitView *ui; + FileThread thread; + QByteArray receiveArray; // 接收缓冲区 +}; + +#endif diff --git a/SerialTool/include/optionsbox.h b/SerialTool/include/optionsbox.h index ab79f75..1f279ed 100644 --- a/SerialTool/include/optionsbox.h +++ b/SerialTool/include/optionsbox.h @@ -25,8 +25,6 @@ private slots: void processOptions(QAbstractButton *button); void setTextFontAnsi(); void setTextFontMulti(); - void setRxFontColor(); - void setTxFontColor(); void setPlotBackgroundColor(); void setAxisColor(); void onCmdNewClick(); diff --git a/SerialTool/include/serialport.h b/SerialTool/include/serialport.h index 381d159..62d67f4 100644 --- a/SerialTool/include/serialport.h +++ b/SerialTool/include/serialport.h @@ -41,6 +41,10 @@ private slots: void onTimerUpdate(); void setBaudRate(const QString &string); +#if defined(Q_OS_LINUX) + void onPortTextEdited(); +#endif + private: Ui::SerialPort *ui; QSerialPort *serialPort; diff --git a/SerialTool/include/terminalview.h b/SerialTool/include/terminalview.h index 0976e87..b33890d 100644 --- a/SerialTool/include/terminalview.h +++ b/SerialTool/include/terminalview.h @@ -27,6 +27,8 @@ class TerminalView : public QWidget void setFontFamily(QString fonts, int size, QString style); void setEnabled(bool status); void setPaused(bool status); + void setHighlight(const QString &language); + void setTextCodec(const QString &name); void saveText(const QString &fname); signals: @@ -36,10 +38,15 @@ class TerminalView : public QWidget void keyPressEvent(QKeyEvent *event); void setSendButtonEnabled(bool status); void arrayToHex(QString &str, const QByteArray &arr, int countOfLine); - void arrayToAscii(QString &str, const QByteArray &arr); + void arrayToString(QString &str, const QByteArray &arr); void loadHistory(QSettings *config); void saveHistory(QSettings *config); + void arrayToUTF8(QString &str, const QByteArray &array); + void arrayToUTF16(QString &str, const QByteArray &array); + void arrayToDualByte(QString &str, const QByteArray &array); + void arrayToASCII(QString &str, const QByteArray &array); + private slots: void sendData(); void onWrapBoxChanged(int status); @@ -49,10 +56,20 @@ private slots: void onHistoryBoxChanged(const QString &string); private: + enum TextCodec { + ASCII, + GB2312, + GB18030, + UTF8, + UTF16 + }; + Ui::TerminalView *ui; - bool sendEnabled = false, paused = false; - QTimer *resendTimer; - QByteArray *asciiBuf; + bool m_sendEnabled = false, m_paused = false; + QTimer *m_resendTimer; + QByteArray *m_asciiBuf; + enum TextCodec m_textCodec; + QByteArray m_codecName; }; #endif // TERMINALVIEW_H diff --git a/SerialTool/include/textedit.h b/SerialTool/include/textedit.h index d86ded7..eb5d276 100644 --- a/SerialTool/include/textedit.h +++ b/SerialTool/include/textedit.h @@ -11,13 +11,18 @@ class TextEdit : public QsciScintilla TextEdit(QWidget *parent = NULL); void append(const QString &text); void setFonts(QString fonts, int size, QColor color = Qt::black, QString style = ""); - void setHighLight(bool mode); + void setHighLight(const QString &language); public slots: void setWrap(bool wrap); private: void setMarginsWidth(); + void highlightNone(); + void highlightCpp(); + void highlightBash(); + void highlightLua(); + void highlightJSON(); private slots: void onTextChanged(); @@ -26,13 +31,12 @@ private slots: void onVScrollBarValueChanged(); private: - QString fontFamily; + QString fontFamily, m_language; QFont lineNumFont; int fontSize; int lineCount = 1; bool isWrap = false; bool scrollEnd = true; - bool highLight = false; }; #endif diff --git a/SerialTool/include/version.h b/SerialTool/include/version.h index 68cd529..6dc2db4 100644 --- a/SerialTool/include/version.h +++ b/SerialTool/include/version.h @@ -1,15 +1,15 @@ #ifndef __VERSION_H #define __VERSION_H -#define MAIN_VERSION 1.2.2 +#define MAIN_VERSION 1.2.3 #define SOFTWARE_NAME "SerialTool" -#define COPYRIGHT "Copyleft 2017 by Wenliang" +#define COPYRIGHT "Copyleft 2017-2018, Wenliang Guan" #define _STR_(s) #s #define __STR(s) _STR_(s) -#define BUILD_VERSION _STR_(45248M) +#define BUILD_VERSION _STR_(492de) #define SOFTWARE_VERSION __STR(MAIN_VERSION) #endif diff --git a/SerialTool/language/serialtool_zh_CN.ts b/SerialTool/language/serialtool_zh_CN.ts index ddec93b..50bf5f6 100644 --- a/SerialTool/language/serialtool_zh_CN.ts +++ b/SerialTool/language/serialtool_zh_CN.ts @@ -18,120 +18,120 @@ - FileTransferView + FileTransmitView - + Mode 模式 - + Send 发送 - + Receive 接收 - + Before Send 预发送文本 - + + Use Berfor Send + 使用预发送文本 + + + Operations 操作 - - File - 文件 + + XModem + - - Protocol - 协议 + + YModem + - - Cancel - 取消 + + ZModem + - - XModem - + + File + 文件 - - Use Berfor Send - 使用预发送文本 + + Protocol + 协议 - - YModem - + + Cancel + 取消 - - ZModem - + + Browse... + 浏览... - + Progress 进度 - + Start 开始 - - Browse... - 浏览... - - - + Start transmit file: " 开始传输文件: " - + Can not open the file: " 无法打开文件: " - - + + Error: 错误: - - + + Error 错误 - + Cancel transfer. 取消传输. - + Transmit finished. 传输完成. - + Transmission timeout. 传输超时。 @@ -189,7 +189,7 @@ - + Save 保存 @@ -205,7 +205,7 @@ - + Open Port 打开端口 @@ -216,7 +216,7 @@ - + Pause Tx/Rx 暂停发送/接收 @@ -279,7 +279,7 @@ - + Open 打开 @@ -299,37 +299,37 @@ 置于顶层 - - + + Portable Network Graphic Format (*.png) 图像文件存储格式 (*.png) - - + + Bitmap (*.bmp) 位图文件 (*.bmp) - - - + + + Wave Plain Text File (*.txt) 波形纯文本文件 (*.txt) - - + + Terminal Text File (*.txt) 终端文本文件 (*.txt) - + Start Tx/Rx 开始发送/接收 - + Close Port 关闭端口 @@ -387,111 +387,109 @@ 不透明度 - + Terminal 终端 - + Font 字体 - - + + Fonts... 字体... - + Multi-Byte 多字节字符 - + ASCII ASCII字符 - - Text Color - 文本颜色 - - - - - - + + Color... 颜色... - - Rx Area - 接收区 + + Text Editor + 文本编辑器 + + + + Text Codec + 编码格式 - - Tx Area - 发送区 + + Highlight + 代码高亮 - + Plot 波形绘制 - + Color 颜色 - + Background 背景颜色 - + Grid 网格颜色 - + Graphics Options 图形选项 - + Update Interval (ms) 刷新时间(ms) - + Use Antialias 抗锯齿 - + Use OpenGL 使用OpenGL - + Command 命令 - + New 新建 - + Edit 编辑 - + Delete 删除 @@ -575,17 +573,17 @@ 端口 - + Baud Rate 波特率 - + Error 错误 - + Can not open the port! Port may be occupied or configured incorrectly! 无法打开端口! @@ -696,12 +694,12 @@ Please check the port number. 发送 - + Ctrl + Enter to send Ctrl + Enter发送 - + Connect port and start transmission to enable this button 连接端口并开启传输来启用此按钮 diff --git a/SerialTool/language/zh_cn/serialtool.qm b/SerialTool/language/zh_cn/serialtool.qm index 41d4e49b8b3b7f7caf932bd8565b675bb0d8b2dd..3853ef280c9f8e421eec87607bdd794a82b4cb32 100644 GIT binary patch delta 1057 zcmZ9KYe-XJ7{{Np?S0SL&NgSesjHl2SUD>ygP_#%LYkVvk|?c~J8mmW)1^X?A2jSn zIge(=%94mQk!txNC>vcVD#(f=!YI4YmFQwbNj;tue(=M~@4WAGd7uCPJxyuBw5IsT z5CEGF5K|1`ya}KW29jqoO#vY`yBA1lA4X3Dsd58wZkZ7=K&o2+A~I!~lVn=kfE>II zpq>UKm;sr@*Py7r7snZZ zz^!@!T{m>6+`)YVqcg+Z01mv3uF0E? z*=^M2K>?8_>N)lfeZ4}rQ6;*lkg5Mdx97wGnEc`qg*AICTe2Ys!19pY_4*K2f0SvX z?8QDe-Wg=WS$Y(-l$%nC9>*kd3lq=|*vI9c`+?n4xcclc=6w@~6$x==>W#$?0L6ez zYoB_{BUDC9HFKY$$;KivPib}ec*gt$fS)AOc7k8oumhtGUI|`q{{h)1Oo?+g5nTBZbuF^U`M*Fz%7b-GqU%0B! z)t}lyiHCKD_Gt9&zHZ)u5tp61T?JNrg`>K!Ar&gpi)K}h(qF4lFDMd&?nT07tIrNhAdy1;H-3Qt{SPDLuXPs zDsJJ&2Ak=0sl{bFOX62LW3<(8n|(|xCz~W?u@lEe&a#P8!@x{hG6J`Gd90;V1b$9KJbFTE&*rq}gP$YlKFRqt3EFQ0N^^;iZ&Jx6fZ**=#b4VN*iL IXdc%515R2bEC2ui delta 1041 zcmZ9KYfKbZ6vzL=aA#(BXNLuL7+BM=SPUvFR4t^E$|DvdTeMhL(pY>@7!bRyvKS$0 zf<`dZND1tqfrOT(QClf$1u-$PxRHXG*bgN(B@Hbh)EFpY()4BHhaP4OY5HOEn{&@S zum8C{`R)1bsj;5};ugTO6A0V|lwe0zCfD4dCl_4;s~RTnmtb|3fK+KwnFl-83B;%t z)f9``8L+NVz_tdg=QV)OvzT_>m@eX<)krz;hRKFnQ7=>_84+~dc;0P;?5arPdtVuNv(OOE}R z*E9M6Et`*Q$^{b78Kazc8!MYSN+C~J#TiN!o5K#a-vr_>vtx*-^I_KV*Y7lE32R;I zJ83`rtg{VJ=U9K=9ct+i`>OA2ns>~|ib{)>h3wr|sPKfaBPL9Z=Ns=uX~!j@`qMd5 zFD!f@@T66gMI|CM`cr7^gTkEu69D6)^A(BwKJoRdDz#lBRvhvJ3FG4Fhuu_b!J_9M z@z!u9)$9@@TNN54Pg)fsZ9U1-<}{K4ZPJc`Kd7D}H5EmGsF)`PYI}FDkIbJf zY6G^~?`brl%69(48A=zlzx*Sq9A9E==e6~l9Gp4{I96I*(dBrn`4oA*4n4Apn$B?? z@sgU+=?*j6)opylYsV*LmcJy|g#5 zsI=Gz03$uxme8pDIYdj)eu{bKTBKL>sD`v0GyKsJzDf@nPL^e|kQJNkWImH4EKekV zX^mcQT=Tr(bZxB(>VZ)C`*llE8-+~4@*1^{|2xCNS~JCM;U$y52^l6|6fFkCb*9}c zTKBGr>83p``c3+z0+UCc^SYF0+9@`-VYj)T|F2#?J7Ap+*4rLRgRODu8Zeu?Fl1Fc;_I34~3@zWV2lR%c-YtiN#*8~RQP}leJNMuC Nz;e7g=vAND{{{V$7YzUa diff --git a/SerialTool/resource/default.ini b/SerialTool/resource/default.ini index 3db712b..3eac595 100644 --- a/SerialTool/resource/default.ini +++ b/SerialTool/resource/default.ini @@ -2,8 +2,8 @@ FontFamily=Courier New FontStyle=normal FontSize=10 -ReceiveTextColor= -TransmitTextColor= +TerminalHighlight=Bash +TerminalTextCodec=GB-2312 PlotBackground=#053846 AxisColor=#9499a3 UpdateInterval=25 diff --git a/SerialTool/source/aboutbox.cpp b/SerialTool/source/aboutbox.cpp index f8fa923..1824cbc 100644 --- a/SerialTool/source/aboutbox.cpp +++ b/SerialTool/source/aboutbox.cpp @@ -29,7 +29,7 @@ AboutBox::AboutBox(QWidget *parent) : "SerialTool
" "Version: " SOFTWARE_VERSION " (" BUILD_VERSION ")
" "Email: 2269610337@qq.com
" - "Home Page: View Code On GitHub
" + "Home Page: View Code On GitHub
" "Build Date: " __DATE__ "
" // 编译时间 COPYRIGHT ); diff --git a/SerialTool/source/defaultconfig.cpp b/SerialTool/source/defaultconfig.cpp index 8d99ba9..0367116 100644 --- a/SerialTool/source/defaultconfig.cpp +++ b/SerialTool/source/defaultconfig.cpp @@ -17,7 +17,7 @@ void syncDefaultConfig(const QString &iniName) } QFile::copy(":/config/default.ini", iniName); - file.setPermissions(QFile::WriteOther); + file.setPermissions(QFile::ReadOwner | QFile::WriteOwner); } else { // 文件存在 QSettings config(iniName, QSettings::IniFormat); diff --git a/SerialTool/source/filetransmitview.cpp b/SerialTool/source/filetransmitview.cpp new file mode 100644 index 0000000..e96cf9f --- /dev/null +++ b/SerialTool/source/filetransmitview.cpp @@ -0,0 +1,186 @@ +#include "filetransmitview.h" +#include "ui_filetransmitview.h" +#include +#include +#include +#include +#include "xmodem.h" + +// 构造函数 +FileTransmitView::FileTransmitView(QWidget *parent) : + QWidget(parent), + ui(new Ui::FileTransmitView) +{ + ui->setupUi(this); + + connect(&thread, &FileThread::sendData, this, &FileTransmitView::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())); + connect(&thread, SIGNAL(timeout()), this, SLOT(onTimeoutError())); +} + +FileTransmitView::~FileTransmitView() +{ + delete ui; +} + +void FileTransmitView::retranslate() +{ + ui->retranslateUi(this); +} + +/* 读取配置文件 */ +void FileTransmitView::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 FileTransmitView::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 FileTransmitView::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 FileTransmitView::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.startTransmit(); + 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 FileTransmitView::portSendData(const QByteArray &array) +{ + QString string; + emit sendData(array); + + ui->progressBar->setValue(thread.progress()); +} + +// 接收数据 +void FileTransmitView::readData(const QByteArray &array) +{ + thread.readData(array); +} + +// 取消发送 +void FileTransmitView::cancelTransfer() +{ + thread.cancelTransmit(); + logOut(tr("Cancel transfer.\n"), Qt::darkGray); + ui->startButton->setEnabled(true); + ui->stopButton->setEnabled(false); +} + +// 显示一条log +void FileTransmitView::logOut(const QString &string, QColor color) +{ + QString time = QDateTime::currentDateTime().toString("hh:mm:ss"); + + ui->textEdit->setTextColor(color); + ui->textEdit->append("[" + time + "] " + string); +} + +// 传输完成槽 +void FileTransmitView::onTransFinsh() +{ + ui->startButton->setEnabled(true); + ui->stopButton->setEnabled(false); + logOut(tr("Transmit finished.\n"), Qt::darkGreen); +} + +// 预发送文本 +void FileTransmitView::beforceSend() +{ + // 只有在发送模式下才可以使用预发送模式 + if (ui->sendButton->isChecked() && ui->enableBerforSendBox->isChecked()) { + QTextCodec *code = QTextCodec::codecForName("GB-2312"); + QByteArray arr = code->fromUnicode(ui->beforeSendEdit->toPlainText()); + + emit sendData(arr); + } +} + +void FileTransmitView::onTimeoutError() +{ + QString string(tr("Transmission timeout.")); + + ui->startButton->setEnabled(true); + ui->stopButton->setEnabled(false); + logOut(tr("Error: ") + string, Qt::red); + QMessageBox err(QMessageBox::Critical, + tr("Error"), + string, + QMessageBox::Cancel, this); + err.exec(); +} diff --git a/SerialTool/source/mainwindow.cpp b/SerialTool/source/mainwindow.cpp index 99bbbe9..51c127d 100644 --- a/SerialTool/source/mainwindow.cpp +++ b/SerialTool/source/mainwindow.cpp @@ -22,7 +22,7 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { QString configPath(QStandardPaths::writableLocation( - QStandardPaths::AppConfigLocation) + "/m_config.ini"); + QStandardPaths::AppConfigLocation) + "/config.ini"); syncDefaultConfig(configPath); m_config = new QSettings(configPath, QSettings::IniFormat); @@ -73,7 +73,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(m_tabActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(tabActionGroupTriggered(QAction*))); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); connect(ui->actionWiki, SIGNAL(triggered()), this, SLOT(openWiki())); - connect(ui->fileTransfer, &FileTransferView::sendData, this, &MainWindow::writePort); + connect(ui->fileTransmit, &FileTransmitView::sendData, this, &MainWindow::writePort); connect(ui->actionVedioBox, SIGNAL(triggered()), this, SLOT(onVedioBoxTriggered())); connect(ui->actionValueDisplay, SIGNAL(triggered()), this, SLOT(onValueDisplayTriggered())); connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentTabChanged(int))); @@ -130,7 +130,7 @@ void MainWindow::setLanguage(const QString &string) ui->retranslateUi(this); ui->terminal->retranslate(); ui->oscPlot->retranslate(); - ui->fileTransfer->retranslate(); + ui->fileTransmit->retranslate(); m_tcpUdpPort->retranslate(); m_serialPort->retranslate(); } @@ -179,6 +179,11 @@ void MainWindow::loadSettings() m_vedioBox->setWindowOpacity(windowOpacity()); } + // highlight + ui->terminal->setHighlight(m_config->value("TerminalHighlight").toString()); + // text codec + ui->terminal->setTextCodec(m_config->value("TerminalTextCodec").toString()); + // 语言设置 setLanguage(m_config->value("Language").toString()); setStyleSheet(m_config->value("Theme").toString()); @@ -212,7 +217,7 @@ void MainWindow::loadConfig() ui->tabWidget->setCurrentIndex(m_config->value("TabIndex").toInt()); setTabActionIndex(ui->tabWidget->currentIndex()); ui->toolBar1->setVisible(m_config->value("ToolBarVisible").toBool()); - ui->actionVisibleToolbar->setChecked(ui->toolBar1->isVisible()); + ui->actionVisibleToolbar->setChecked(m_config->value("ToolBarVisible").toBool()); ui->statusBar->setVisible(m_config->value("StatusBarVisible").toBool()); // 这里如果直接速读取ui->statusBar->isVisible()会是false,原因不明 ui->actionVisibleStatusBar->setChecked(m_config->value("StatusBarVisible").toBool()); @@ -226,7 +231,7 @@ void MainWindow::loadConfig() ui->oscPlot->loadConfig(m_config); // 读取文件传输功能的设置 - ui->fileTransfer->loadConfig(m_config); + ui->fileTransmit->loadConfig(m_config); // 最后读取系统设置 loadSettings(); @@ -247,7 +252,7 @@ void MainWindow::saveConfig() QVariant(ui->tabWidget->currentIndex())); m_config->setValue("ToolBarVisible", QVariant(ui->toolBar1->isVisible())); m_config->setValue("StatusBarVisible", QVariant(ui->statusBar->isVisible())); - m_config->setValue("WindowStaysOnTop", QVariant(windowFlags() & Qt::WindowStaysOnTopHint)); + m_config->setValue("WindowStaysOnTop", QVariant((windowFlags() & Qt::WindowStaysOnTopHint) != 0)); m_config->endGroup(); // 调试终端配置 @@ -261,7 +266,7 @@ void MainWindow::saveConfig() m_config->endGroup(); // 文件传输配置 - ui->fileTransfer->saveConfig(m_config); + ui->fileTransmit->saveConfig(m_config); } void MainWindow::setOptions() @@ -502,7 +507,7 @@ void MainWindow::readPortData() } // 串口文件传输 if (ui->tabWidget->currentIndex() == 2) { - ui->fileTransfer->readData(buf); + ui->fileTransmit->readData(buf); } if (m_vedioBox != NULL) { m_vedioBox->append(buf); @@ -597,14 +602,15 @@ void MainWindow::onVedioBoxDelete() void MainWindow::setWindowStaysOnTop(bool enabled) { - Qt::WindowFlags flags = enabled ? - Qt::WindowStaysOnTopHint : Qt::Window; QString str = enabled ? ":/SerialTool/images/pin_down.ico" : ":/SerialTool/images/pin_up.ico"; - hide(); - setWindowFlags(flags); ui->actionStaysOnTop->setIcon(QIcon(str)); + if (enabled) { + setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint); + } else { + setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint); + } show(); } @@ -615,7 +621,7 @@ void MainWindow::onStaysOnTopTriggered() void MainWindow::openWiki() { - QDesktopServices::openUrl(QUrl("https://github.com/Le-Seul/Serial/wiki")); + QDesktopServices::openUrl(QUrl("https://github.com/gztss/SerialTool/wiki")); } void MainWindow::currentTabChanged(int index) diff --git a/SerialTool/source/optionsbox.cpp b/SerialTool/source/optionsbox.cpp index 634cf7b..9fb254b 100644 --- a/SerialTool/source/optionsbox.cpp +++ b/SerialTool/source/optionsbox.cpp @@ -60,7 +60,7 @@ OptionsBox::OptionsBox(MainWindow *parent) : setWindowFlags(flags); ui->setupUi(this); - setFixedSize(400, 300); // 不能伸缩的对话框 + setFixedSize(400, 400); // 不能伸缩的对话框 m_parent = parent; @@ -71,8 +71,6 @@ OptionsBox::OptionsBox(MainWindow *parent) : connect(ui->fontAnsiSetButton, SIGNAL(clicked()), this, SLOT(setTextFontAnsi())); connect(ui->fontMultiSetButton, SIGNAL(clicked()), this, SLOT(setTextFontMulti())); - connect(ui->rxColorButton, SIGNAL(clicked()), this, SLOT(setRxFontColor())); - connect(ui->txColorButton, SIGNAL(clicked()), this, SLOT(setTxFontColor())); connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton *)), this, SLOT(processOptions(QAbstractButton *))); connect(ui->plotBgColorButton, SIGNAL(clicked()), this, SLOT(setPlotBackgroundColor())); @@ -95,6 +93,7 @@ OptionsBox::~OptionsBox() // 初始化设置 void OptionsBox::setup() { + QString textCodec, highlight; QSettings *config = m_parent->getConfig(); // 字体和颜色设置 @@ -103,8 +102,8 @@ void OptionsBox::setup() fontFamily.replace("+", ","); fontStyle = config->value("FontStyle").toString(); fontSize = config->value("FontSize").toInt(); - rxColor = config->value("ReceiveTextColor").toString(); - txColor = config->value("TransmitTextColor").toString(); + textCodec = config->value("TerminalTextCodec").toString(); + highlight = config->value("TerminalHighlight").toString(); bgColor = config->value("PlotBackground").toString(); axColor = config->value("AxisColor").toString(); ui->opacitySlider->setValue(config->value("WindowOpacity").toInt()); @@ -122,8 +121,8 @@ void OptionsBox::setup() + "," + fontStyle + "," + QString::number(fontSize)); ui->lineEditFontMulti->setText(fontFamily.section(",", 1, 1).trimmed()); } - ui->lineEditRxColor->setText(rxColor); - ui->lineEditTxColor->setText(txColor); + ui->textCodecBox->setCurrentText(textCodec); + ui->highlightBox->setCurrentText(highlight); ui->lineEditPlotColor->setText(bgColor); ui->lineEditAxisColor->setText(axColor); @@ -142,6 +141,8 @@ void OptionsBox::processOptions(QAbstractButton *button) QDialogButtonBox::StandardButton btn = ui->buttonBox->standardButton(button); if (btn == QDialogButtonBox::Ok || btn == QDialogButtonBox::Apply) { + QString textCodec = ui->textCodecBox->currentText(); + QString highlight = ui->highlightBox->currentText(); QSettings *config = m_parent->getConfig(); // 字体和颜色设置 config->beginGroup("Settings"); @@ -150,8 +151,8 @@ void OptionsBox::processOptions(QAbstractButton *button) fontFamily.replace("+", ","); config->setValue("FontStyle", QVariant(fontStyle)); config->setValue("FontSize", QVariant(fontSize)); - config->setValue("ReceiveTextColor", QVariant(rxColor)); - config->setValue("TransmitTextColor", QVariant(txColor)); + config->setValue("TerminalTextCodec", QVariant(textCodec)); + config->setValue("TerminalHighlight", QVariant(highlight)); config->setValue("PlotBackground", QVariant(bgColor)); config->setValue("AxisColor", QVariant(axColor)); config->setValue("WindowOpacity", QVariant(ui->opacitySpinBox->value())); @@ -208,26 +209,6 @@ void OptionsBox::setTextFontMulti() } } -void OptionsBox::setRxFontColor() -{ - QColor color = QColorDialog::getColor(QColor(rxColor), this); - - if (color.isValid()) { - rxColor = color.name(); - ui->lineEditRxColor->setText(rxColor); - } -} - -void OptionsBox::setTxFontColor() -{ - QColor color = QColorDialog::getColor(QColor(txColor), this); - - if (color.isValid()) { - txColor = color.name(); - ui->lineEditTxColor->setText(txColor); - } -} - void OptionsBox::setPlotBackgroundColor() { QColor color = QColorDialog::getColor(QColor(bgColor), this); diff --git a/SerialTool/source/portsetbox.cpp b/SerialTool/source/portsetbox.cpp index a5d4644..03f1def 100644 --- a/SerialTool/source/portsetbox.cpp +++ b/SerialTool/source/portsetbox.cpp @@ -42,7 +42,7 @@ PortSetBox::PortSetBox(QSerialPort *port, QWidget *parent) : setWindowFlags(flags); ui->setupUi(this); - setFixedSize(200, 150); // 不能伸缩的对话框 + setFixedSize(200, 200); // 不能伸缩的对话框 serialPort = port; diff --git a/SerialTool/source/serialport.cpp b/SerialTool/source/serialport.cpp index 32dc270..b7a04f5 100644 --- a/SerialTool/source/serialport.cpp +++ b/SerialTool/source/serialport.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include SerialPort::SerialPort(QWidget *parent) : QWidget(parent), @@ -16,16 +18,23 @@ SerialPort::SerialPort(QWidget *parent) : serialPort = new QSerialPort; timer = new QTimer; - scanPort(); - timer->start(1000); - QRegExpValidator *pReg = new QRegExpValidator(QRegExp("^\\d{2,7}$")); ui->baudRateBox->lineEdit()->setValidator(pReg); +#if defined(Q_OS_LINUX) + ui->portNameBox->setEditable(true); +#endif + connect(serialPort, &QSerialPort::readyRead, this, &SerialPort::readyRead); connect(timer, &QTimer::timeout, this, &SerialPort::onTimerUpdate); connect(ui->baudRateBox, &QComboBox::currentTextChanged, this, &SerialPort::setBaudRate); connect(ui->portNameBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(portChanged())); +#if defined(Q_OS_LINUX) + connect(ui->portNameBox->lineEdit(), SIGNAL(editingFinished()), this, SLOT(onPortTextEdited())); +#endif + + scanPort(); + timer->start(1000); } SerialPort::~SerialPort() @@ -43,9 +52,12 @@ void SerialPort::retranslate() void SerialPort::loadConfig(QSettings *config) { config->beginGroup("SerialPort"); - serialPort->setBaudRate(config->value("BaudRate").toInt()); - ui->baudRateBox->setCurrentText(QString::number(serialPort->baudRate())); + int baudRate = config->value("BaudRate").toInt(); + QString str = QString::number(baudRate); config->endGroup(); + serialPort->setBaudRate(baudRate); + ui->baudRateBox->setCurrentIndex(ui->baudRateBox->findText(str)); + ui->baudRateBox->setCurrentText(str); } void SerialPort::saveConfig(QSettings *config) @@ -67,6 +79,12 @@ void SerialPort::setVisibleWidget(bool visible) bool SerialPort::open() { QString name = ui->portNameBox->currentText().section(' ', 0, 0); + +#if defined(Q_OS_LINUX) + if (name.indexOf("/dev/") != 0) { + name = "/dev/" + name; + } +#endif serialPort->setPortName(name); if (serialPort->open(QIODevice::ReadWrite)) { ui->portNameBox->setEnabled(false); // 禁止更改串口 @@ -133,45 +151,52 @@ bool SerialPort::isOpen() void SerialPort::portSetDialog() { - PortSetBox portSet(serialPort); + PortSetBox portSet(serialPort, this); portSet.exec(); } // 扫描端口 void SerialPort::scanPort() { - int i = 0; bool sync = false; + QComboBox *box = ui->portNameBox; QVector vec; + //查找可用的串口 foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { - // 端口名不在匹配说明端口列表变更 - if (ui->portNameBox->itemText(i++).indexOf(info.portName())) { + // 检测端口列表变更 + QString str = info.portName() + " (" + info.description() + ")"; + if (box->findText(str) == -1) { sync = true; } vec.append(info); } // 需要同步或者ui->portNameBox存在无效端口 - if (sync || !ui->portNameBox->itemText(i).isEmpty()) { + if (sync || box->count() != vec.count()) { int len = 0; - QFontMetrics fm(ui->portNameBox->font()); - QString str = ui->portNameBox->currentText(); - ui->portNameBox->clear(); - for (i = 0; i < vec.length(); ++i) { - QString t = vec[i].portName() + " (" + vec[i].description() + ")"; - ui->portNameBox->addItem(t); - int width = fm.boundingRect(t).width(); // 计算字符串的像素宽度 + QFontMetrics fm(box->font()); + QString text = box->currentText(); + bool edited = box->findText(text) == -1; // only edit enable (linux) + box->clear(); + for (int i = 0; i < vec.length(); ++i) { + QString name = vec[i].portName() + " (" + vec[i].description() + ")"; + box->addItem(name); + int width = fm.boundingRect(name).width(); // 计算字符串的像素宽度 if (width > len) { // 统计最长字符串 len = width; } } - if (!str.isEmpty()) { // 设置当前选中的端口 - ui->portNameBox->setCurrentText(str); + // 设置当前选中的端口 + if (!text.isEmpty() && (box->findText(text) != -1 || edited)) { + box->setCurrentText(text); } else { - ui->portNameBox->setCurrentIndex(0); + box->setCurrentIndex(0); } +#if defined(Q_OS_LINUX) + box->lineEdit()->setCursorPosition(0); +#endif // 自动控制下拉列表宽度 - ui->portNameBox->view()->setMinimumWidth(len + 9); + box->view()->setMinimumWidth(len + 16); } } @@ -190,3 +215,15 @@ void SerialPort::setBaudRate(const QString &string) { serialPort->setBaudRate(string.toInt()); } + +#if defined(Q_OS_LINUX) +void SerialPort::onPortTextEdited() +{ + QComboBox *box = ui->portNameBox; + QString text = box->currentText(); + if (box->findText(text) == -1) { // can't find text + qDebug() << "edit text edited"; + } + box->lineEdit()->setCursorPosition(0); +} +#endif diff --git a/SerialTool/source/terminalview.cpp b/SerialTool/source/terminalview.cpp index 4e785c9..1cd4d5c 100644 --- a/SerialTool/source/terminalview.cpp +++ b/SerialTool/source/terminalview.cpp @@ -4,6 +4,7 @@ #include #include #include +#include TerminalView::TerminalView(QWidget *parent) : QWidget(parent), @@ -11,20 +12,18 @@ TerminalView::TerminalView(QWidget *parent) : { ui->setupUi(this); - resendTimer = new QTimer; - asciiBuf = new QByteArray; + m_resendTimer = new QTimer; + m_asciiBuf = new QByteArray; ui->textEditRx->setReadOnly(true); ui->textEditTx->setWrap(true); // Send area auto wrap. - // Send and Receive area High Light. - ui->textEditTx->setHighLight(true); - ui->textEditRx->setHighLight(true); + setTextCodec("GB-2312"); // default connect(ui->wrapLineBox, SIGNAL(stateChanged(int)), this, SLOT(onWrapBoxChanged(int))); connect(ui->sendButton, &QPushButton::clicked, this, &TerminalView::onSendButtonClicked); connect(ui->resendBox, &QCheckBox::stateChanged, this, &TerminalView::updateResendTimerStatus); - QObject::connect(resendTimer, &QTimer::timeout, this, &TerminalView::sendData); + QObject::connect(m_resendTimer, &QTimer::timeout, this, &TerminalView::sendData); connect(ui->resendIntervalBox, SIGNAL(valueChanged(int)), this, SLOT(setResendInterval(int))); connect(ui->historyBox, SIGNAL(activated(const QString &)), this, SLOT(onHistoryBoxChanged(const QString &))); connect(ui->wrapLineBox, SIGNAL(stateChanged(int)), this, SLOT(onWrapBoxChanged(int))); @@ -33,8 +32,8 @@ TerminalView::TerminalView(QWidget *parent) : TerminalView::~TerminalView() { delete ui; - delete resendTimer; - delete asciiBuf; + delete m_resendTimer; + delete m_asciiBuf; } void TerminalView::keyPressEvent(QKeyEvent *event) @@ -133,12 +132,19 @@ void TerminalView::saveHistory(QSettings *config) config->endGroup(); } +void TerminalView::setHighlight(const QString &language) +{ + // Send and Receive area highlight. + ui->textEditTx->setHighLight(language); + ui->textEditRx->setHighLight(language); +} + void TerminalView::append(const QByteArray &array) { QString string; if (ui->portReadAscii->isChecked()) { - arrayToAscii(string, array); + arrayToString(string, array); } else { arrayToHex(string, array, 16); } @@ -148,7 +154,7 @@ void TerminalView::append(const QByteArray &array) void TerminalView::clear() { ui->textEditRx->clear(); - asciiBuf->clear(); + m_asciiBuf->clear(); } void TerminalView::setFontFamily(QString fontFamily, int size, QString style) @@ -159,8 +165,8 @@ void TerminalView::setFontFamily(QString fontFamily, int size, QString style) void TerminalView::setPaused(bool status) { - paused = status; - setSendButtonEnabled(!paused && sendEnabled); + m_paused = status; + setSendButtonEnabled(!m_paused && m_sendEnabled); updateResendTimerStatus(); } @@ -176,8 +182,8 @@ void TerminalView::setSendButtonEnabled(bool status) void TerminalView::setEnabled(bool status) { - sendEnabled = status; - setSendButtonEnabled(!paused && sendEnabled); + m_sendEnabled = status; + setSendButtonEnabled(!m_paused && m_sendEnabled); // auto resend updateResendTimerStatus(); } @@ -188,7 +194,7 @@ void TerminalView::sendData() QByteArray array; if (ui->portWriteAscii->isChecked() == true) { - QTextCodec *code = QTextCodec::codecForName("GB-2312"); + QTextCodec *code = QTextCodec::codecForName(m_codecName); array = code->fromUnicode(ui->textEditTx->text()); } else { array = QByteArray::fromHex(ui->textEditTx->text().toLatin1()); @@ -223,19 +229,42 @@ void TerminalView::onSendButtonClicked() void TerminalView::updateResendTimerStatus() { - bool status = sendEnabled && !paused && ui->resendBox->isChecked(); + bool status = m_sendEnabled && !m_paused && ui->resendBox->isChecked(); if (status) { - resendTimer->start(ui->resendIntervalBox->text().toInt()); + m_resendTimer->start(ui->resendIntervalBox->text().toInt()); } else { - resendTimer->stop(); + m_resendTimer->stop(); } } // set resend interval time void TerminalView::setResendInterval(int msc) { - resendTimer->setInterval(msc); + m_resendTimer->setInterval(msc); +} + +void TerminalView::setTextCodec(const QString &name) +{ + if (name == "GB-2312") { + m_textCodec = GB2312; + m_codecName = "GB-2312"; + } else if (name == "GB-18030") { + m_textCodec = GB18030; + m_codecName = "GB-18030"; + } else if (name == "UTF-8") { + m_textCodec = UTF8; + m_codecName = "UTF-8"; + } else if (name == "UTF-16BE") { + m_textCodec = UTF16; + m_codecName = "UTF-16BE"; + } else if (name == "UTF-16LE") { + m_textCodec = UTF16; + m_codecName = "UTF-16LE"; + } else { // ASCII + m_textCodec = ASCII; + m_codecName = "ASCII"; + } } void TerminalView::onHistoryBoxChanged(const QString &string) @@ -265,25 +294,112 @@ void TerminalView::arrayToHex(QString &str, const QByteArray &array, int countOf } } -// 这个函数可以避免中文接收的乱码 -void TerminalView::arrayToAscii(QString &str, const QByteArray &array) +// array转UTF8 +void TerminalView::arrayToUTF8(QString &str, const QByteArray &array) { - int cnt = 0; - int lastIndex = asciiBuf->length() - 1; + int lastIndex, cut = 0; + bool isCut = false; + + m_asciiBuf->append(array); + lastIndex = m_asciiBuf->length() - 1; + if (m_asciiBuf->at(lastIndex) & 0x80) { // 0xxx xxxx -> OK + // UTF8最大编码为4字节,因此向前搜寻三字节 + for (int i = lastIndex; i >= 0 && ++cut < 4; --i) { + uint8_t byte = m_asciiBuf->at(i); + if (((cut < 2) && (byte & 0xE0) == 0xC0) || + ((cut < 3) && (byte & 0xF0) == 0xE0) || + (byte & 0xF8) == 0xF0) { + isCut = true; + break; + } + } + } + lastIndex -= isCut ? cut - 1 : -1; + QByteArray cutArray = m_asciiBuf->mid(lastIndex); + m_asciiBuf->remove(lastIndex, cut); + QTextCodec *code = QTextCodec::codecForName(m_codecName); + str = code->toUnicode(*m_asciiBuf); + m_asciiBuf->clear(); + m_asciiBuf->append(cutArray); +} + +// array转双字节编码格式(GB2312等) +void TerminalView::arrayToDualByte(QString &str, const QByteArray &array) +{ + int lastIndex; + bool isCut = false; + + m_asciiBuf->append(array); + lastIndex = m_asciiBuf->length() - 1; + for (int i = lastIndex; i >= 0 && m_asciiBuf->at(i) & 0x80; --i) { + isCut = !isCut; + } + if (isCut) { // 字符串最末尾的非ASCII字节数不为2的整数倍 + char ch = m_asciiBuf->at(lastIndex); + m_asciiBuf->remove(lastIndex, 1); + QTextCodec *code = QTextCodec::codecForName(m_codecName); + str = code->toUnicode(*m_asciiBuf); + m_asciiBuf->clear(); + m_asciiBuf->append(ch); + } else { + QTextCodec *code = QTextCodec::codecForName(m_codecName); + str = code->toUnicode(*m_asciiBuf); + m_asciiBuf->clear(); + } +} - asciiBuf->append(array); - for (int i = lastIndex; i >= 0 && asciiBuf->at(i) & 0x80; --i) { - cnt++; +// array转Unicode +void TerminalView::arrayToUTF16(QString &str, const QByteArray &array) +{ + int lastIndex; + bool isCut = false;; + + m_asciiBuf->append(array); + lastIndex = m_asciiBuf->length() - 1; + isCut = (lastIndex + 1) & 0x01; + if (isCut) { // 字符串长度不为偶数 + char ch = m_asciiBuf->at(lastIndex); + m_asciiBuf->remove(lastIndex, 1); + QTextCodec *code = QTextCodec::codecForName(m_codecName); + str = code->toUnicode(*m_asciiBuf); + m_asciiBuf->clear(); + m_asciiBuf->append(ch); + } else { + QTextCodec *code = QTextCodec::codecForName(m_codecName); + str = code->toUnicode(*m_asciiBuf); + m_asciiBuf->clear(); } - if (cnt & 1) { // 字符串最末尾的非ASCII字节数不为2的整数倍 - char ch = asciiBuf->at(lastIndex); - asciiBuf->remove(lastIndex, 1); - str = QString::fromLocal8Bit(*asciiBuf); - asciiBuf->clear(); - asciiBuf->append(ch); +} + +// array转ASCII +void TerminalView::arrayToASCII(QString &str, const QByteArray &array) +{ + if (m_asciiBuf->isEmpty()) { + str = QString::fromLatin1(array); } else { - str = QString::fromLocal8Bit(*asciiBuf); - asciiBuf->clear(); + m_asciiBuf->append(array); + str = QString::fromLatin1(*m_asciiBuf); + m_asciiBuf->clear(); + } +} + +// 这个函数可以避免中文接收的乱码 +void TerminalView::arrayToString(QString &str, const QByteArray &array) +{ + switch (m_textCodec) { + case GB2312: + case GB18030: + arrayToDualByte(str, array); + break; + case UTF8: + arrayToUTF8(str, array); + break; + case UTF16: + arrayToUTF16(str, array); + break; + default: // ASCII + arrayToASCII(str, array); + break; } } diff --git a/SerialTool/source/textedit.cpp b/SerialTool/source/textedit.cpp index e054223..8e44714 100644 --- a/SerialTool/source/textedit.cpp +++ b/SerialTool/source/textedit.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include TextEdit::TextEdit(QWidget *parent) : QsciScintilla(parent) { @@ -65,9 +67,7 @@ void TextEdit::setFonts(QString fonts, int size, QColor color, QString style) */ SendScintilla(SCI_SETSCROLLWIDTHTRACKING, true); - if (highLight) { // 重新设置语法高亮 - setHighLight(true); - } + setHighLight(m_language); // 重新设置语法高亮 } void TextEdit::setMarginsWidth() @@ -135,25 +135,50 @@ void TextEdit::onVScrollBarValueChanged() void TextEdit::setWrap(bool wrap) { if (wrap) { - QsciScintilla::setWrapMode(WrapWhitespace); + setWrapMode(WrapWhitespace); } else { - QsciScintilla::setWrapMode(WrapNone); + setWrapMode(WrapNone); } isWrap = wrap; } -// 设置语法高亮 -void TextEdit::setHighLight(bool mode) +void TextEdit::highlightNone() { - if (mode) { - highLight = true; - } else { - highLight = false; - SendScintilla(SCI_SETLEXER, SCLEX_CONTAINER); - return; - } + SendScintilla(SCI_SETLEXER, SCLEX_CONTAINER); +} + +void TextEdit::highlightCpp() +{ + 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);// 设置关键字 -#if 1 + // 下面设置各种语法元素前景色 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::Default, 0x38312A); // 默认 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::Keyword, 0x8B8B00); // 关键字 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::DoubleQuotedString, 0x6666D4); // 字符串 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::SingleQuotedString, 0x6666D4); // 字符 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::Operator, 0xB48246); // 运算符 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::Number, 0x006F7F); // 数字 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::PreProcessor, 0x808080); // 预处理指令 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::Comment, 0x008000); // 块注释 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::CommentLine, 0x008000); // 行注释 + SendScintilla(SCI_STYLESETFORE, QsciLexerCPP::CommentDoc, 0x008000); // 文档注释(/**开头) +} + +void TextEdit::highlightBash() +{ QByteArray keyWords; QFile file(QStandardPaths::writableLocation( @@ -163,7 +188,7 @@ void TextEdit::setHighLight(bool mode) keyWords = file.readAll(); file.close(); } - //NULL + SendScintilla(SCI_SETLEXER, SCLEX_BASH); // bash解析器 SendScintilla(SCI_SETKEYWORDS, (unsigned long)0, keyWords.data());// 设置关键字 // 下面设置各种语法元素前景色 @@ -175,34 +200,55 @@ void TextEdit::setHighLight(bool mode) SendScintilla(SCI_STYLESETFORE, QsciLexerBash::Number, 0x006F7F); // 数字 SendScintilla(SCI_STYLESETFORE, QsciLexerBash::Comment, 0x008000); // 行注释 SendScintilla(SCI_STYLESETFORE, QsciLexerBash::Identifier, 0x38312A); // 识别符 -#else +} + +void TextEdit::highlightLua() +{ 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"; + "and break do else elseif end false for function " + "if in local nil not or repeat return then true until while"; - SendScintilla(SCI_SETLEXER, SCLEX_CPP); // C++解析器 + SendScintilla(SCI_SETLEXER, SCLEX_LUA); // lua解析器 SendScintilla(SCI_SETKEYWORDS, (unsigned long)0, g_szKeywords);// 设置关键字 + // 下面设置各种语法元素前景色 + SendScintilla(SCI_STYLESETFORE, QsciLexerLua::Default, 0x38312A); // 默认 + SendScintilla(SCI_STYLESETFORE, QsciLexerLua::Keyword, 0x8B8B00); // 关键字 + SendScintilla(SCI_STYLESETFORE, QsciLexerLua::String, 0x6666D4); // 字符串 + SendScintilla(SCI_STYLESETFORE, QsciLexerLua::Operator, 0xB48246); // 运算符 + SendScintilla(SCI_STYLESETFORE, QsciLexerLua::Number, 0x006F7F); // 数字 + SendScintilla(SCI_STYLESETFORE, QsciLexerLua::Comment, 0x008000); // 行注释 + SendScintilla(SCI_STYLESETFORE, QsciLexerLua::Identifier, 0x38312A); // 识别符 +} + +void TextEdit::highlightJSON() +{ + const char* g_szKeywords = "true false"; + SendScintilla(SCI_SETLEXER, SCLEX_JSON); // lua解析器 + 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); // 文档注释(/**开头) -#endif + SendScintilla(SCI_STYLESETFORE, QsciLexerJSON::Default, 0x38312A); // 默认 + SendScintilla(SCI_STYLESETFORE, QsciLexerJSON::Keyword, 0x8B8B00); // 关键字 + SendScintilla(SCI_STYLESETFORE, QsciLexerJSON::String, 0x6666D4); // 字符串 + SendScintilla(SCI_STYLESETFORE, QsciLexerJSON::Operator, 0xB48246); // 运算符 + SendScintilla(SCI_STYLESETFORE, QsciLexerJSON::Number, 0x006F7F); // 数字 +} +// 设置语法高亮 +void TextEdit::setHighLight(const QString &language) +{ + if (language == "C/C++") { + highlightCpp(); + } else if (language == "Bash") { + highlightBash(); + } else if (language == "Lua") { + highlightLua(); + } else if (language == "JSON") { + highlightJSON(); + } else { + highlightNone(); + } + m_language = language; SendScintilla(SCI_SETTABWIDTH, 4); // Tab宽度 // 当前行高亮 SendScintilla(SCI_SETCARETLINEVISIBLE, true); diff --git a/SerialTool/source/xmodem.cpp b/SerialTool/source/xmodem.cpp index 3c9eb80..6ec4c9a 100644 --- a/SerialTool/source/xmodem.cpp +++ b/SerialTool/source/xmodem.cpp @@ -85,23 +85,22 @@ int XModemClass::transmit(char ch, qint64 &bytes) if (ch == CAN) { // 取消传输 return 1; } + if (status == None && ch == NAK) { // 开始传输 + status = ACK; + memset(frame, 0, 132); // 初始化帧 + ch = ACK; // 为了下面传输第一帧 + status = Trans; + } 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) { + if (ch == ACK) { arr.clear(); arr.append(EOT); thread->sendPortData(arr); status = TransEOT; // 进入结束应答状态 - break; } + break; case Trans: // 传输数据 if (ch == ACK) { // 传输下一块数据 frame[0] = SOH; diff --git a/SerialTool/themes/default/style.css b/SerialTool/themes/default/style.css index bc2c5d7..46fd997 100644 --- a/SerialTool/themes/default/style.css +++ b/SerialTool/themes/default/style.css @@ -1,6 +1,6 @@ * { - font-family: 'Microsoft YaHei UI', '微软雅黑', '宋体'; - outline: none; /* 去掉虚线 */ + font-family: 'Microsoft YaHei UI', '微软雅黑'; + outline: none; } QMainWindow { @@ -8,14 +8,12 @@ QMainWindow { } QComboBox, QSpinBox, QDoubleSpinBox, QListWidget, QLineEdit, QTextEdit { - background: white; border: 1px solid gray; border-radius: 3px; - padding: 1px 2px 1px 2px; /* 针对于组合框中的文本内容 */ - min-width: 3em; /* 组合框的最小宽度 */ + min-width: 3em; + height: 20px; } -/* 定义串口接收数据显示控件的样式 */ QFrame#textEditRx, QFrame#textEditTx { border: 1px solid gray; border-radius: 3px; @@ -104,7 +102,7 @@ QTabBar::tab { border-top-left-radius: 3px; border-top-right-radius: 3px; min-width: 8ex; - padding: 0px 5px 0px; /* 上, 左右, 下边距 */ + padding: 0px 5px 0px; } QTabBar::tab:selected, QTabBar::tab:hover { @@ -131,9 +129,9 @@ QGroupBox{ QGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; - left: 10px; /* 线的偏离度 */ + left: 10px; margin-left: 0px; - padding:0 1px; /* 文字在方框中位置的偏离度 */ + padding:0 1px; } QScrollBar { @@ -238,8 +236,8 @@ QScrollBar::sub-line::vertical { QPushButton { border: 1px solid gray; border-radius: 3px; - padding: 1.5px 6px; /* 针对于组合框中的文本内容 */ - min-width: 4em; /* 组合框的最小宽度 */ + padding: 1.5px 6px; + min-width: 4em; background: #EAEAEA } @@ -266,7 +264,7 @@ QAction { QListView { border: 1px solid gray; border-radius: 3px; - padding: 1px 1px 1px 2px; /* 针对于组合框中的文本内容 */ + padding: 1px 1px 1px 2px; } QComboBox QAbstractItemView { diff --git a/SerialTool/themes/original/style.css b/SerialTool/themes/original/style.css new file mode 100644 index 0000000..e69de29 diff --git a/SerialTool/ui/aboutbox.ui b/SerialTool/ui/aboutbox.ui index 7a21ded..864295a 100644 --- a/SerialTool/ui/aboutbox.ui +++ b/SerialTool/ui/aboutbox.ui @@ -83,9 +83,7 @@ - - - + buttonBox diff --git a/SerialTool/ui/filetransmitview.ui b/SerialTool/ui/filetransmitview.ui new file mode 100644 index 0000000..0c82688 --- /dev/null +++ b/SerialTool/ui/filetransmitview.ui @@ -0,0 +1,270 @@ + + + FileTransmitView + + + + 0 + 0 + 569 + 246 + + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + true + + + + + + + 6 + + + + + + 0 + 0 + + + + Mode + + + + + + Send + + + true + + + + + + + Receive + + + + + + + + + + Before Send + + + + 2 + + + 4 + + + 4 + + + 2 + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Use Berfor Send + + + + + + + + + + Operations + + + + + + + 0 + 0 + + + + + 90 + 0 + + + + + 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/mainwindow.ui b/SerialTool/ui/mainwindow.ui index 7e936cb..28bac34 100644 --- a/SerialTool/ui/mainwindow.ui +++ b/SerialTool/ui/mainwindow.ui @@ -125,7 +125,7 @@ 0 - + @@ -405,9 +405,9 @@ 1 - FileTransferView + FileTransmitView QWidget -
filetransferview.h
+
filetransmitview.h
1
diff --git a/SerialTool/ui/optionsbox.ui b/SerialTool/ui/optionsbox.ui index 468dffe..d22f542 100644 --- a/SerialTool/ui/optionsbox.ui +++ b/SerialTool/ui/optionsbox.ui @@ -6,8 +6,8 @@ 0 0 - 431 - 312 + 430 + 370 @@ -152,6 +152,9 @@ 100 + + 100 + @@ -255,30 +258,13 @@ - Text Color + Text Editor - - - - Color... - - - - - - - - - - true - - - - Rx Area + Text Codec Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -288,7 +274,7 @@ - Tx Area + Highlight Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -296,20 +282,72 @@ - - - - - - true - + + + + None + + + + + Bash + + + + + C/C++ + + + + + Lua + + + + + JSON + + - - - - Color... + + + + + 0 + 0 + + + + ASCII + + + + + GB-2312 + + + + + GB-18030 + + + + + UTF-8 + + + + + UTF-16BE + + + + + UTF-16LE + + diff --git a/SerialTool/ui/oscilloscope.ui b/SerialTool/ui/oscilloscope.ui index ff80917..9b5d19a 100644 --- a/SerialTool/ui/oscilloscope.ui +++ b/SerialTool/ui/oscilloscope.ui @@ -254,7 +254,7 @@ QtCharts::QChartView QWidget -
QtCharts/QChartView.h
+
QtCharts/QChartView
1
diff --git a/SerialTool/ui/serialport.ui b/SerialTool/ui/serialport.ui index c5cc18c..3611f8d 100644 --- a/SerialTool/ui/serialport.ui +++ b/SerialTool/ui/serialport.ui @@ -6,8 +6,8 @@ 0 0 - 300 - 20 + 308 + 29
@@ -59,6 +59,9 @@ QComboBox { width: 120px } + + QComboBox::InsertAlphabetically + diff --git a/SerialTool/ver_temp.h b/SerialTool/ver_temp.h index 3dacdcc..515657d 100644 --- a/SerialTool/ver_temp.h +++ b/SerialTool/ver_temp.h @@ -1,10 +1,10 @@ #ifndef __VERSION_H #define __VERSION_H -#define MAIN_VERSION 1.2.2 +#define MAIN_VERSION 1.2.3 #define SOFTWARE_NAME "SerialTool" -#define COPYRIGHT "Copyleft 2017 by Wenliang" +#define COPYRIGHT "Copyleft 2017-2018, Wenliang Guan" #define _STR_(s) #s #define __STR(s) _STR_(s)