
QSerialPortTerminalにKOZOS用XMODEM送信機能追加
| Revision | ff58497b318e4611a382ff99a7d2099379bed005 (tree) |
|---|---|
| Time | 2012-05-17 20:51:15 |
| Author | arakaki <alucky4416@user...> |
| Commiter | arakaki |
ADD: XMODEM FileSend for KOZOS study
| @@ -1,48 +1,54 @@ | ||
| 1 | -unix : OBJECTS_DIR = build/.o/unix | |
| 2 | -win32 : OBJECTS_DIR = build/.o/win32 | |
| 3 | -mac : OBJECTS_DIR = build/.o/mac | |
| 4 | -UI_DIR = build/.ui | |
| 5 | -MOC_DIR = build/.moc | |
| 6 | -RCC_DIR = build/.rcc | |
| 7 | - | |
| 8 | -AUTHOR = VIANNEY-LIAUD Philippe | |
| 9 | -EMAIL = philippe.vianney.liaud gmail.com | |
| 10 | -LICENSE = GPL | |
| 11 | -LANGUAGE = C++ | |
| 12 | - | |
| 13 | -TEMPLATE = app | |
| 14 | -win32 : DEFINES += _TTY_WIN_ QWT_DLL QT_DLL | |
| 15 | -unix : DEFINES += _TTY_POSIX_ | |
| 16 | -QT = gui core | |
| 17 | -INCLUDEPATH = . src | |
| 18 | -CONFIG += qt warn_on debug app_bundle thread x11 | |
| 19 | - | |
| 20 | -SOURCES = src/QSerialPortTerminal/main.cpp \ | |
| 21 | - src/QSerialPortTerminal/ui/QSerialPortTerminal.cpp \ | |
| 22 | - src/SerialPort/qextserialbase.cpp \ | |
| 23 | - src/SerialPort/qextserialport.cpp \ | |
| 24 | - src/SerialPort/ManageSerialPort.cpp | |
| 25 | - | |
| 26 | -win32 : SOURCES += src/SerialPort/win_qextserialport.cpp | |
| 27 | - | |
| 28 | -unix : SOURCES += src/SerialPort/posix_qextserialport.cpp | |
| 29 | - | |
| 30 | -FORMS = src/QSerialPortTerminal/ui/QSerialPortTerminal.ui | |
| 31 | - | |
| 32 | -OPENEDFILES = src/QSerialPortTerminal/ui/QSerialPortTerminal.h \ | |
| 33 | - src/QSerialPortTerminal/ui/QSerialPortTerminal.cpp \ | |
| 34 | - src/SerialPort/ManageSerialPort.h \ | |
| 35 | - src/SerialPort/ManageSerialPort.cpp | |
| 36 | - | |
| 37 | -HEADERS = src/QSerialPortTerminal/ui/QSerialPortTerminal.h \ | |
| 38 | - src/SerialPort/qextserialbase.h \ | |
| 39 | - src/SerialPort/qextserialport.h \ | |
| 40 | - src/SerialPort/ManageSerialPort.h | |
| 41 | - | |
| 42 | -win32 : HEADERS += src/SerialPort/win_qextserialport.h | |
| 43 | - | |
| 44 | -unix : HEADERS += src/SerialPort/posix_qextserialport.h | |
| 45 | -SOURCES -= src/QSerialPortTerminal/ui/ConsoleTerminal.cpp | |
| 46 | - | |
| 47 | -HEADERS -= src/QSerialPortTerminal/ui/ConsoleTerminal.h | |
| 48 | - | |
| 1 | +unix : OBJECTS_DIR = build/.o/unix | |
| 2 | +win32 : OBJECTS_DIR = build/.o/win32 | |
| 3 | +mac : OBJECTS_DIR = build/.o/mac | |
| 4 | +UI_DIR = build/.ui | |
| 5 | +MOC_DIR = build/.moc | |
| 6 | +RCC_DIR = build/.rcc | |
| 7 | + | |
| 8 | +AUTHOR = VIANNEY-LIAUD Philippe | |
| 9 | +EMAIL = philippe.vianney.liaud gmail.com | |
| 10 | +LICENSE = GPL | |
| 11 | +LANGUAGE = C++ | |
| 12 | + | |
| 13 | +TEMPLATE = app | |
| 14 | +win32 : DEFINES += _TTY_WIN_ QWT_DLL QT_DLL | |
| 15 | +unix : DEFINES += _TTY_POSIX_ | |
| 16 | +QT = gui core | |
| 17 | +INCLUDEPATH = . src | |
| 18 | +CONFIG += qt warn_on debug app_bundle thread x11 | |
| 19 | + | |
| 20 | +SOURCES = src/QSerialPortTerminal/main.cpp \ | |
| 21 | + src/QSerialPortTerminal/ui/QSerialPortTerminal.cpp \ | |
| 22 | + src/QSerialPortTerminal/ui/sendfile_dialog.cpp \ | |
| 23 | + src/SerialPort/qextserialbase.cpp \ | |
| 24 | + src/SerialPort/qextserialport.cpp \ | |
| 25 | + src/SerialPort/ManageSerialPort.cpp | |
| 26 | + | |
| 27 | +win32 : SOURCES += src/SerialPort/win_qextserialport.cpp | |
| 28 | + | |
| 29 | +unix : SOURCES += src/SerialPort/posix_qextserialport.cpp | |
| 30 | + | |
| 31 | +FORMS = src/QSerialPortTerminal/ui/QSerialPortTerminal.ui \ | |
| 32 | + src/QSerialPortTerminal/ui/sendfile_dialog.ui | |
| 33 | + | |
| 34 | +OPENEDFILES = src/QSerialPortTerminal/ui/QSerialPortTerminal.h \ | |
| 35 | + src/SerialPort/ManageSerialPort.cpp \ | |
| 36 | + src/QSerialPortTerminal/ui/QSerialPortTerminal.cpp \ | |
| 37 | + src/SerialPort/ManageSerialPort.h | |
| 38 | + | |
| 39 | +HEADERS = src/QSerialPortTerminal/ui/QSerialPortTerminal.h \ | |
| 40 | + src/QSerialPortTerminal/ui/sendfile_dialog.h \ | |
| 41 | + src/SerialPort/qextserialbase.h \ | |
| 42 | + src/SerialPort/qextserialport.h \ | |
| 43 | + src/SerialPort/ManageSerialPort.h | |
| 44 | + | |
| 45 | +win32 : HEADERS += src/SerialPort/win_qextserialport.h | |
| 46 | + | |
| 47 | +unix : HEADERS += src/SerialPort/posix_qextserialport.h | |
| 48 | +SOURCES -= src/QSerialPortTerminal/ui/ConsoleTerminal.cpp | |
| 49 | + | |
| 50 | +HEADERS -= src/QSerialPortTerminal/ui/ConsoleTerminal.h | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + |
| @@ -16,16 +16,21 @@ QSerialPortTerminal::QSerialPortTerminal( QWidget* parent ) | ||
| 16 | 16 | |
| 17 | 17 | serialPort=serialPort = new ManageSerialPort; |
| 18 | 18 | connect(serialPort, SIGNAL(newDataReceived(const QByteArray &)), this, SLOT(slot_newDataReceived(const QByteArray &))); |
| 19 | + connect(serialPort, SIGNAL(sendEnded(int)), this, SLOT(slot_sendEnded(int))); | |
| 20 | + connect(serialPort, SIGNAL(progress_status(int)), this, SLOT(slot_progress_status(int))); | |
| 19 | 21 | |
| 20 | 22 | #ifdef _TTY_WIN_ |
| 21 | 23 | comboBoxPortName->addItem("COM1", QVariant::fromValue(QString("COM1"))); |
| 22 | 24 | comboBoxPortName->addItem("COM2", QVariant::fromValue(QString("COM2"))); |
| 25 | + comboBoxPortName->addItem("COM11", QVariant::fromValue(QString("COM11"))); | |
| 26 | + comboBoxPortName->addItem("COM21", QVariant::fromValue(QString("COM21"))); | |
| 23 | 27 | comboBoxPortName->setCurrentIndex(0); //COM1 |
| 24 | 28 | #endif |
| 25 | 29 | |
| 26 | 30 | #ifdef _TTY_POSIX_ |
| 27 | 31 | comboBoxPortName->addItem("ttyS0", QVariant::fromValue(QString("/dev/ttyS0"))); |
| 28 | 32 | comboBoxPortName->addItem("ttyS1", QVariant::fromValue(QString("/dev/ttyS1"))); |
| 33 | + comboBoxPortName->addItem("ttyUSB0", QVariant::fromValue(QString("/dev/ttyUSB0"))); | |
| 29 | 34 | comboBoxPortName->setCurrentIndex(0); //COM1 |
| 30 | 35 | #endif |
| 31 | 36 |
| @@ -67,6 +72,8 @@ QSerialPortTerminal::QSerialPortTerminal( QWidget* parent ) | ||
| 67 | 72 | connect(pushButtonOpen, SIGNAL(clicked()), this, SLOT(slot_openPort())); |
| 68 | 73 | connect(pushButtonClose, SIGNAL(clicked()), this, SLOT(slot_closePort())); |
| 69 | 74 | connect(pushButtonSend, SIGNAL(clicked()), this, SLOT(slot_sendPort())); |
| 75 | + connect(pushButtonSendFile, SIGNAL(clicked()), this, SLOT(slot_sendPortToFile())); | |
| 76 | + connect(pushButtonClear, SIGNAL(clicked()), this, SLOT(slot_clear())); | |
| 70 | 77 | |
| 71 | 78 | /*Codecs list*/ |
| 72 | 79 | QMap<QString, QTextCodec *> codecMap; |
| @@ -137,6 +144,7 @@ void QSerialPortTerminal::slot_openPort() | ||
| 137 | 144 | pushButtonOpen->setEnabled(false); |
| 138 | 145 | pushButtonClose->setEnabled(true); |
| 139 | 146 | pushButtonSend->setEnabled(true); |
| 147 | + pushButtonSendFile->setEnabled(true); | |
| 140 | 148 | |
| 141 | 149 | if (serialPort->isOpen()) |
| 142 | 150 | serialPort->close(); |
| @@ -168,7 +176,9 @@ void QSerialPortTerminal::slot_openPort() | ||
| 168 | 176 | |
| 169 | 177 | serialPort->open(); |
| 170 | 178 | serialPort->receiveData(); |
| 171 | -}; | |
| 179 | + | |
| 180 | +// this->slot_clear(); | |
| 181 | +} | |
| 172 | 182 | |
| 173 | 183 | |
| 174 | 184 | void QSerialPortTerminal::slot_closePort() |
| @@ -179,7 +189,8 @@ void QSerialPortTerminal::slot_closePort() | ||
| 179 | 189 | pushButtonOpen->setEnabled(true); |
| 180 | 190 | pushButtonClose->setEnabled(false); |
| 181 | 191 | pushButtonSend->setEnabled(false); |
| 182 | -}; | |
| 192 | + pushButtonSendFile->setEnabled(false); | |
| 193 | +} | |
| 183 | 194 | |
| 184 | 195 | void QSerialPortTerminal::slot_sendPort() |
| 185 | 196 | { |
| @@ -194,7 +205,8 @@ void QSerialPortTerminal::slot_sendPort() | ||
| 194 | 205 | if (checkBoxLF->checkState() == Qt::Checked) |
| 195 | 206 | Message += "\x0A"; |
| 196 | 207 | |
| 197 | - QByteArray temp(Message.toUtf8()); | |
| 208 | +// QByteArray temp(Message.toUtf8()); | |
| 209 | + QByteArray temp(Message.toLocal8Bit()); | |
| 198 | 210 | serialPort->sendData(temp); |
| 199 | 211 | |
| 200 | 212 | lineEditSend->clear(); |
| @@ -217,3 +229,58 @@ void QSerialPortTerminal::slot_newDataReceived(const QByteArray &dataReceived) | ||
| 217 | 229 | textEditReceive->insertPlainText(decodedStr); |
| 218 | 230 | } |
| 219 | 231 | |
| 232 | +void QSerialPortTerminal::slot_clear() | |
| 233 | +{ | |
| 234 | + textEditReceive->clear(); | |
| 235 | +} | |
| 236 | + | |
| 237 | +void QSerialPortTerminal::slot_sendPortToFile() | |
| 238 | +{ | |
| 239 | + // select FileDialog | |
| 240 | + QString filepath = QFileDialog::getOpenFileName(this, tr("Select Send File"),"",""); | |
| 241 | + if (filepath.isEmpty()) return; | |
| 242 | + | |
| 243 | +// pushButtonOpen->setEnabled(false); | |
| 244 | + pushButtonClose->setEnabled(false); | |
| 245 | + pushButtonSend->setEnabled(false); | |
| 246 | + pushButtonSendFile->setEnabled(false); | |
| 247 | + | |
| 248 | + status_dlg = new SendFile_Dialog(this, filepath); | |
| 249 | + connect(status_dlg, SIGNAL(stopSendFile()), this, SLOT(slot_stopSendPortToFile())); | |
| 250 | + status_dlg->open(); | |
| 251 | + | |
| 252 | + // Send File by XMODEM | |
| 253 | + serialPort->setFlagKOZOS(checkBox4KOZOS->isChecked()); | |
| 254 | + serialPort->startXferFile_XMODEM(filepath); | |
| 255 | +} | |
| 256 | + | |
| 257 | +void QSerialPortTerminal::slot_stopSendPortToFile() | |
| 258 | +{ | |
| 259 | + // if sending? | |
| 260 | + serialPort->stopXferFile_XMODEM(); | |
| 261 | +} | |
| 262 | + | |
| 263 | +// SerialPort -> MainPanel -> Dialog | |
| 264 | +void QSerialPortTerminal::slot_sendEnded(int result) | |
| 265 | +{ | |
| 266 | + qDebug() << QString("SendEnded, code = %1").arg(result); | |
| 267 | + | |
| 268 | + if (status_dlg) { | |
| 269 | + status_dlg->close(); | |
| 270 | + delete status_dlg; | |
| 271 | + status_dlg = NULL; | |
| 272 | + } | |
| 273 | + | |
| 274 | + // pushButtonOpen->setEnabled(false); | |
| 275 | + pushButtonClose->setEnabled(true); | |
| 276 | + pushButtonSend->setEnabled(true); | |
| 277 | + pushButtonSendFile->setEnabled(true); | |
| 278 | +} | |
| 279 | + | |
| 280 | +// SerialPort -> MainPanel -> Dialog | |
| 281 | +void QSerialPortTerminal::slot_progress_status(int progress) | |
| 282 | +{ | |
| 283 | + if (status_dlg) { | |
| 284 | + status_dlg->updateProgressbar(progress); | |
| 285 | + } | |
| 286 | +} |
| @@ -11,7 +11,8 @@ | ||
| 11 | 11 | // |
| 12 | 12 | #include <QMainWindow> |
| 13 | 13 | #include "ui_QSerialPortTerminal.h" |
| 14 | -#include "src/SerialPort/ManageSerialPort.h" | |
| 14 | +#include "sendfile_dialog.h" | |
| 15 | +#include "src/SerialPort/ManageSerialPort.h" | |
| 15 | 16 | |
| 16 | 17 | class QextSerialPort; |
| 17 | 18 |
| @@ -29,13 +30,20 @@ private slots: | ||
| 29 | 30 | void slot_openPort(); |
| 30 | 31 | void slot_closePort(); |
| 31 | 32 | void slot_sendPort(); |
| 33 | + void slot_clear(); | |
| 34 | + void slot_sendPortToFile(); | |
| 35 | + void slot_stopSendPortToFile(); | |
| 32 | 36 | |
| 33 | - //SerialPort | |
| 37 | + // SerialPort | |
| 34 | 38 | void slot_newDataReceived(const QByteArray &dataReceived); |
| 39 | + void slot_sendEnded(int); // SerialPort -> MainPanel | |
| 40 | + void slot_progress_status(int progress); // SerialPort -> MainPanel -> Dialog | |
| 35 | 41 | |
| 36 | 42 | private: |
| 37 | 43 | ManageSerialPort *serialPort; |
| 38 | 44 | QByteArray allDataReceived; |
| 45 | + | |
| 46 | + SendFile_Dialog *status_dlg; | |
| 39 | 47 | }; |
| 40 | 48 | |
| 41 | 49 | #endif // QSERIALPORTTERMINAL_H |
| @@ -1,285 +1,308 @@ | ||
| 1 | -<ui version="4.0" > | |
| 2 | - <class>QSerialPortTerminal</class> | |
| 3 | - <widget class="QMainWindow" name="QSerialPortTerminal" > | |
| 4 | - <property name="geometry" > | |
| 5 | - <rect> | |
| 6 | - <x>0</x> | |
| 7 | - <y>0</y> | |
| 8 | - <width>613</width> | |
| 9 | - <height>319</height> | |
| 10 | - </rect> | |
| 11 | - </property> | |
| 12 | - <property name="windowTitle" > | |
| 13 | - <string>QSerialPortTerminal</string> | |
| 14 | - </property> | |
| 15 | - <widget class="QWidget" name="centralwidget" > | |
| 16 | - <property name="geometry" > | |
| 17 | - <rect> | |
| 18 | - <x>0</x> | |
| 19 | - <y>0</y> | |
| 20 | - <width>613</width> | |
| 21 | - <height>319</height> | |
| 22 | - </rect> | |
| 23 | - </property> | |
| 24 | - <layout class="QHBoxLayout" name="horizontalLayout" > | |
| 25 | - <item> | |
| 26 | - <layout class="QVBoxLayout" name="verticalLayout" > | |
| 27 | - <item> | |
| 28 | - <widget class="QGroupBox" name="groupBoxSettings" > | |
| 29 | - <property name="title" > | |
| 30 | - <string>Settings...</string> | |
| 31 | - </property> | |
| 32 | - <layout class="QGridLayout" name="gridLayout" > | |
| 33 | - <item row="0" column="0" > | |
| 34 | - <widget class="QLabel" name="labelPort" > | |
| 35 | - <property name="sizePolicy" > | |
| 36 | - <sizepolicy vsizetype="Preferred" hsizetype="Fixed" > | |
| 37 | - <horstretch>0</horstretch> | |
| 38 | - <verstretch>0</verstretch> | |
| 39 | - </sizepolicy> | |
| 40 | - </property> | |
| 41 | - <property name="text" > | |
| 42 | - <string>Port :</string> | |
| 43 | - </property> | |
| 44 | - </widget> | |
| 45 | - </item> | |
| 46 | - <item row="0" column="1" > | |
| 47 | - <widget class="QComboBox" name="comboBoxPortName" /> | |
| 48 | - </item> | |
| 49 | - <item row="1" column="0" > | |
| 50 | - <widget class="QLabel" name="labelBaudRate" > | |
| 51 | - <property name="sizePolicy" > | |
| 52 | - <sizepolicy vsizetype="Preferred" hsizetype="Fixed" > | |
| 53 | - <horstretch>0</horstretch> | |
| 54 | - <verstretch>0</verstretch> | |
| 55 | - </sizepolicy> | |
| 56 | - </property> | |
| 57 | - <property name="text" > | |
| 58 | - <string>Baud rate :</string> | |
| 59 | - </property> | |
| 60 | - </widget> | |
| 61 | - </item> | |
| 62 | - <item row="1" column="1" > | |
| 63 | - <widget class="QComboBox" name="comboBoxBaudRate" /> | |
| 64 | - </item> | |
| 65 | - <item row="2" column="0" > | |
| 66 | - <widget class="QLabel" name="labelData" > | |
| 67 | - <property name="sizePolicy" > | |
| 68 | - <sizepolicy vsizetype="Preferred" hsizetype="Fixed" > | |
| 69 | - <horstretch>0</horstretch> | |
| 70 | - <verstretch>0</verstretch> | |
| 71 | - </sizepolicy> | |
| 72 | - </property> | |
| 73 | - <property name="text" > | |
| 74 | - <string>Data :</string> | |
| 75 | - </property> | |
| 76 | - </widget> | |
| 77 | - </item> | |
| 78 | - <item row="2" column="1" > | |
| 79 | - <widget class="QComboBox" name="comboBoxDataBits" /> | |
| 80 | - </item> | |
| 81 | - <item row="3" column="0" > | |
| 82 | - <widget class="QLabel" name="labelParity" > | |
| 83 | - <property name="sizePolicy" > | |
| 84 | - <sizepolicy vsizetype="Preferred" hsizetype="Fixed" > | |
| 85 | - <horstretch>0</horstretch> | |
| 86 | - <verstretch>0</verstretch> | |
| 87 | - </sizepolicy> | |
| 88 | - </property> | |
| 89 | - <property name="text" > | |
| 90 | - <string>Parity :</string> | |
| 91 | - </property> | |
| 92 | - </widget> | |
| 93 | - </item> | |
| 94 | - <item row="3" column="1" > | |
| 95 | - <widget class="QComboBox" name="comboBoxParity" /> | |
| 96 | - </item> | |
| 97 | - <item row="4" column="0" > | |
| 98 | - <widget class="QLabel" name="labelStop" > | |
| 99 | - <property name="sizePolicy" > | |
| 100 | - <sizepolicy vsizetype="Preferred" hsizetype="Fixed" > | |
| 101 | - <horstretch>0</horstretch> | |
| 102 | - <verstretch>0</verstretch> | |
| 103 | - </sizepolicy> | |
| 104 | - </property> | |
| 105 | - <property name="text" > | |
| 106 | - <string>Stop :</string> | |
| 107 | - </property> | |
| 108 | - </widget> | |
| 109 | - </item> | |
| 110 | - <item row="4" column="1" > | |
| 111 | - <widget class="QComboBox" name="comboBoxStopBits" /> | |
| 112 | - </item> | |
| 113 | - <item row="5" column="0" > | |
| 114 | - <widget class="QLabel" name="labelFlowControl" > | |
| 115 | - <property name="sizePolicy" > | |
| 116 | - <sizepolicy vsizetype="Preferred" hsizetype="Fixed" > | |
| 117 | - <horstretch>0</horstretch> | |
| 118 | - <verstretch>0</verstretch> | |
| 119 | - </sizepolicy> | |
| 120 | - </property> | |
| 121 | - <property name="text" > | |
| 122 | - <string>Flow control :</string> | |
| 123 | - </property> | |
| 124 | - </widget> | |
| 125 | - </item> | |
| 126 | - <item row="5" column="1" > | |
| 127 | - <widget class="QComboBox" name="comboBoxFlowControl" /> | |
| 128 | - </item> | |
| 129 | - </layout> | |
| 130 | - </widget> | |
| 131 | - </item> | |
| 132 | - <item> | |
| 133 | - <widget class="QGroupBox" name="groupBoxOptions" > | |
| 134 | - <property name="enabled" > | |
| 135 | - <bool>true</bool> | |
| 136 | - </property> | |
| 137 | - <property name="title" > | |
| 138 | - <string>Options</string> | |
| 139 | - </property> | |
| 140 | - <layout class="QGridLayout" name="gridLayout_2" > | |
| 141 | - <property name="topMargin" > | |
| 142 | - <number>4</number> | |
| 143 | - </property> | |
| 144 | - <property name="bottomMargin" > | |
| 145 | - <number>4</number> | |
| 146 | - </property> | |
| 147 | - <property name="horizontalSpacing" > | |
| 148 | - <number>5</number> | |
| 149 | - </property> | |
| 150 | - <property name="verticalSpacing" > | |
| 151 | - <number>4</number> | |
| 152 | - </property> | |
| 153 | - <item row="0" column="0" > | |
| 154 | - <widget class="QLabel" name="labelCodec" > | |
| 155 | - <property name="text" > | |
| 156 | - <string>Codec :</string> | |
| 157 | - </property> | |
| 158 | - </widget> | |
| 159 | - </item> | |
| 160 | - <item row="0" column="1" > | |
| 161 | - <widget class="QComboBox" name="comboBoxCodecs" /> | |
| 162 | - </item> | |
| 163 | - <item row="1" column="1" > | |
| 164 | - <spacer name="verticalSpacer" > | |
| 165 | - <property name="orientation" > | |
| 166 | - <enum>Qt::Vertical</enum> | |
| 167 | - </property> | |
| 168 | - <property name="sizeHint" stdset="0" > | |
| 169 | - <size> | |
| 170 | - <width>20</width> | |
| 171 | - <height>17</height> | |
| 172 | - </size> | |
| 173 | - </property> | |
| 174 | - </spacer> | |
| 175 | - </item> | |
| 176 | - </layout> | |
| 177 | - </widget> | |
| 178 | - </item> | |
| 179 | - </layout> | |
| 180 | - </item> | |
| 181 | - <item> | |
| 182 | - <widget class="QFrame" name="frame_2" > | |
| 183 | - <property name="frameShape" > | |
| 184 | - <enum>QFrame::NoFrame</enum> | |
| 185 | - </property> | |
| 186 | - <property name="frameShadow" > | |
| 187 | - <enum>QFrame::Raised</enum> | |
| 188 | - </property> | |
| 189 | - <layout class="QVBoxLayout" > | |
| 190 | - <property name="spacing" > | |
| 191 | - <number>4</number> | |
| 192 | - </property> | |
| 193 | - <property name="leftMargin" > | |
| 194 | - <number>0</number> | |
| 195 | - </property> | |
| 196 | - <property name="topMargin" > | |
| 197 | - <number>9</number> | |
| 198 | - </property> | |
| 199 | - <property name="rightMargin" > | |
| 200 | - <number>0</number> | |
| 201 | - </property> | |
| 202 | - <property name="bottomMargin" > | |
| 203 | - <number>0</number> | |
| 204 | - </property> | |
| 205 | - <item> | |
| 206 | - <layout class="QHBoxLayout" > | |
| 207 | - <item> | |
| 208 | - <widget class="QPushButton" name="pushButtonOpen" > | |
| 209 | - <property name="text" > | |
| 210 | - <string>Open</string> | |
| 211 | - </property> | |
| 212 | - </widget> | |
| 213 | - </item> | |
| 214 | - <item> | |
| 215 | - <spacer> | |
| 216 | - <property name="orientation" > | |
| 217 | - <enum>Qt::Horizontal</enum> | |
| 218 | - </property> | |
| 219 | - <property name="sizeHint" stdset="0" > | |
| 220 | - <size> | |
| 221 | - <width>40</width> | |
| 222 | - <height>20</height> | |
| 223 | - </size> | |
| 224 | - </property> | |
| 225 | - </spacer> | |
| 226 | - </item> | |
| 227 | - <item> | |
| 228 | - <widget class="QPushButton" name="pushButtonClose" > | |
| 229 | - <property name="enabled" > | |
| 230 | - <bool>false</bool> | |
| 231 | - </property> | |
| 232 | - <property name="text" > | |
| 233 | - <string>Close</string> | |
| 234 | - </property> | |
| 235 | - </widget> | |
| 236 | - </item> | |
| 237 | - </layout> | |
| 238 | - </item> | |
| 239 | - <item> | |
| 240 | - <widget class="QTextEdit" name="textEditReceive" > | |
| 241 | - <property name="readOnly" > | |
| 242 | - <bool>true</bool> | |
| 243 | - </property> | |
| 244 | - </widget> | |
| 245 | - </item> | |
| 246 | - <item> | |
| 247 | - <layout class="QHBoxLayout" > | |
| 248 | - <item> | |
| 249 | - <widget class="QLineEdit" name="lineEditSend" /> | |
| 250 | - </item> | |
| 251 | - <item> | |
| 252 | - <widget class="QCheckBox" name="checkBoxCR" > | |
| 253 | - <property name="text" > | |
| 254 | - <string>CR</string> | |
| 255 | - </property> | |
| 256 | - </widget> | |
| 257 | - </item> | |
| 258 | - <item> | |
| 259 | - <widget class="QCheckBox" name="checkBoxLF" > | |
| 260 | - <property name="text" > | |
| 261 | - <string>LF</string> | |
| 262 | - </property> | |
| 263 | - </widget> | |
| 264 | - </item> | |
| 265 | - </layout> | |
| 266 | - </item> | |
| 267 | - <item> | |
| 268 | - <widget class="QPushButton" name="pushButtonSend" > | |
| 269 | - <property name="enabled" > | |
| 270 | - <bool>false</bool> | |
| 271 | - </property> | |
| 272 | - <property name="text" > | |
| 273 | - <string>Send</string> | |
| 274 | - </property> | |
| 275 | - </widget> | |
| 276 | - </item> | |
| 277 | - </layout> | |
| 278 | - </widget> | |
| 279 | - </item> | |
| 280 | - </layout> | |
| 281 | - </widget> | |
| 282 | - </widget> | |
| 283 | - <resources/> | |
| 284 | - <connections/> | |
| 285 | -</ui> | |
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<ui version="4.0"> | |
| 3 | + <class>QSerialPortTerminal</class> | |
| 4 | + <widget class="QMainWindow" name="QSerialPortTerminal"> | |
| 5 | + <property name="geometry"> | |
| 6 | + <rect> | |
| 7 | + <x>0</x> | |
| 8 | + <y>0</y> | |
| 9 | + <width>613</width> | |
| 10 | + <height>352</height> | |
| 11 | + </rect> | |
| 12 | + </property> | |
| 13 | + <property name="windowTitle"> | |
| 14 | + <string>QSerialPortTerminal</string> | |
| 15 | + </property> | |
| 16 | + <widget class="QWidget" name="centralwidget"> | |
| 17 | + <layout class="QHBoxLayout" name="horizontalLayout"> | |
| 18 | + <item> | |
| 19 | + <layout class="QVBoxLayout" name="verticalLayout"> | |
| 20 | + <item> | |
| 21 | + <widget class="QGroupBox" name="groupBoxSettings"> | |
| 22 | + <property name="title"> | |
| 23 | + <string>Settings...</string> | |
| 24 | + </property> | |
| 25 | + <layout class="QGridLayout" name="gridLayout"> | |
| 26 | + <item row="0" column="0"> | |
| 27 | + <widget class="QLabel" name="labelPort"> | |
| 28 | + <property name="sizePolicy"> | |
| 29 | + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> | |
| 30 | + <horstretch>0</horstretch> | |
| 31 | + <verstretch>0</verstretch> | |
| 32 | + </sizepolicy> | |
| 33 | + </property> | |
| 34 | + <property name="text"> | |
| 35 | + <string>Port :</string> | |
| 36 | + </property> | |
| 37 | + </widget> | |
| 38 | + </item> | |
| 39 | + <item row="0" column="1"> | |
| 40 | + <widget class="QComboBox" name="comboBoxPortName"/> | |
| 41 | + </item> | |
| 42 | + <item row="1" column="0"> | |
| 43 | + <widget class="QLabel" name="labelBaudRate"> | |
| 44 | + <property name="sizePolicy"> | |
| 45 | + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> | |
| 46 | + <horstretch>0</horstretch> | |
| 47 | + <verstretch>0</verstretch> | |
| 48 | + </sizepolicy> | |
| 49 | + </property> | |
| 50 | + <property name="text"> | |
| 51 | + <string>Baud rate :</string> | |
| 52 | + </property> | |
| 53 | + </widget> | |
| 54 | + </item> | |
| 55 | + <item row="1" column="1"> | |
| 56 | + <widget class="QComboBox" name="comboBoxBaudRate"/> | |
| 57 | + </item> | |
| 58 | + <item row="2" column="0"> | |
| 59 | + <widget class="QLabel" name="labelData"> | |
| 60 | + <property name="sizePolicy"> | |
| 61 | + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> | |
| 62 | + <horstretch>0</horstretch> | |
| 63 | + <verstretch>0</verstretch> | |
| 64 | + </sizepolicy> | |
| 65 | + </property> | |
| 66 | + <property name="text"> | |
| 67 | + <string>Data :</string> | |
| 68 | + </property> | |
| 69 | + </widget> | |
| 70 | + </item> | |
| 71 | + <item row="2" column="1"> | |
| 72 | + <widget class="QComboBox" name="comboBoxDataBits"/> | |
| 73 | + </item> | |
| 74 | + <item row="3" column="0"> | |
| 75 | + <widget class="QLabel" name="labelParity"> | |
| 76 | + <property name="sizePolicy"> | |
| 77 | + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> | |
| 78 | + <horstretch>0</horstretch> | |
| 79 | + <verstretch>0</verstretch> | |
| 80 | + </sizepolicy> | |
| 81 | + </property> | |
| 82 | + <property name="text"> | |
| 83 | + <string>Parity :</string> | |
| 84 | + </property> | |
| 85 | + </widget> | |
| 86 | + </item> | |
| 87 | + <item row="3" column="1"> | |
| 88 | + <widget class="QComboBox" name="comboBoxParity"/> | |
| 89 | + </item> | |
| 90 | + <item row="4" column="0"> | |
| 91 | + <widget class="QLabel" name="labelStop"> | |
| 92 | + <property name="sizePolicy"> | |
| 93 | + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> | |
| 94 | + <horstretch>0</horstretch> | |
| 95 | + <verstretch>0</verstretch> | |
| 96 | + </sizepolicy> | |
| 97 | + </property> | |
| 98 | + <property name="text"> | |
| 99 | + <string>Stop :</string> | |
| 100 | + </property> | |
| 101 | + </widget> | |
| 102 | + </item> | |
| 103 | + <item row="4" column="1"> | |
| 104 | + <widget class="QComboBox" name="comboBoxStopBits"/> | |
| 105 | + </item> | |
| 106 | + <item row="5" column="0"> | |
| 107 | + <widget class="QLabel" name="labelFlowControl"> | |
| 108 | + <property name="sizePolicy"> | |
| 109 | + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> | |
| 110 | + <horstretch>0</horstretch> | |
| 111 | + <verstretch>0</verstretch> | |
| 112 | + </sizepolicy> | |
| 113 | + </property> | |
| 114 | + <property name="text"> | |
| 115 | + <string>Flow control :</string> | |
| 116 | + </property> | |
| 117 | + </widget> | |
| 118 | + </item> | |
| 119 | + <item row="5" column="1"> | |
| 120 | + <widget class="QComboBox" name="comboBoxFlowControl"/> | |
| 121 | + </item> | |
| 122 | + </layout> | |
| 123 | + </widget> | |
| 124 | + </item> | |
| 125 | + <item> | |
| 126 | + <widget class="QGroupBox" name="groupBoxOptions"> | |
| 127 | + <property name="enabled"> | |
| 128 | + <bool>true</bool> | |
| 129 | + </property> | |
| 130 | + <property name="title"> | |
| 131 | + <string>Options</string> | |
| 132 | + </property> | |
| 133 | + <layout class="QGridLayout" name="gridLayout_2"> | |
| 134 | + <property name="topMargin"> | |
| 135 | + <number>4</number> | |
| 136 | + </property> | |
| 137 | + <property name="bottomMargin"> | |
| 138 | + <number>4</number> | |
| 139 | + </property> | |
| 140 | + <property name="horizontalSpacing"> | |
| 141 | + <number>5</number> | |
| 142 | + </property> | |
| 143 | + <property name="verticalSpacing"> | |
| 144 | + <number>4</number> | |
| 145 | + </property> | |
| 146 | + <item row="0" column="0"> | |
| 147 | + <widget class="QLabel" name="labelCodec"> | |
| 148 | + <property name="text"> | |
| 149 | + <string>Codec :</string> | |
| 150 | + </property> | |
| 151 | + </widget> | |
| 152 | + </item> | |
| 153 | + <item row="0" column="1"> | |
| 154 | + <widget class="QComboBox" name="comboBoxCodecs"/> | |
| 155 | + </item> | |
| 156 | + <item row="1" column="1"> | |
| 157 | + <spacer name="verticalSpacer"> | |
| 158 | + <property name="orientation"> | |
| 159 | + <enum>Qt::Vertical</enum> | |
| 160 | + </property> | |
| 161 | + <property name="sizeHint" stdset="0"> | |
| 162 | + <size> | |
| 163 | + <width>20</width> | |
| 164 | + <height>17</height> | |
| 165 | + </size> | |
| 166 | + </property> | |
| 167 | + </spacer> | |
| 168 | + </item> | |
| 169 | + </layout> | |
| 170 | + </widget> | |
| 171 | + </item> | |
| 172 | + </layout> | |
| 173 | + </item> | |
| 174 | + <item> | |
| 175 | + <widget class="QFrame" name="frame_2"> | |
| 176 | + <property name="frameShape"> | |
| 177 | + <enum>QFrame::NoFrame</enum> | |
| 178 | + </property> | |
| 179 | + <property name="frameShadow"> | |
| 180 | + <enum>QFrame::Raised</enum> | |
| 181 | + </property> | |
| 182 | + <layout class="QVBoxLayout"> | |
| 183 | + <property name="spacing"> | |
| 184 | + <number>4</number> | |
| 185 | + </property> | |
| 186 | + <property name="leftMargin"> | |
| 187 | + <number>0</number> | |
| 188 | + </property> | |
| 189 | + <property name="topMargin"> | |
| 190 | + <number>9</number> | |
| 191 | + </property> | |
| 192 | + <property name="rightMargin"> | |
| 193 | + <number>0</number> | |
| 194 | + </property> | |
| 195 | + <property name="bottomMargin"> | |
| 196 | + <number>0</number> | |
| 197 | + </property> | |
| 198 | + <item> | |
| 199 | + <layout class="QHBoxLayout"> | |
| 200 | + <item> | |
| 201 | + <widget class="QPushButton" name="pushButtonOpen"> | |
| 202 | + <property name="text"> | |
| 203 | + <string>Open</string> | |
| 204 | + </property> | |
| 205 | + </widget> | |
| 206 | + </item> | |
| 207 | + <item> | |
| 208 | + <widget class="QPushButton" name="pushButtonClose"> | |
| 209 | + <property name="enabled"> | |
| 210 | + <bool>false</bool> | |
| 211 | + </property> | |
| 212 | + <property name="text"> | |
| 213 | + <string>Close</string> | |
| 214 | + </property> | |
| 215 | + </widget> | |
| 216 | + </item> | |
| 217 | + <item> | |
| 218 | + <widget class="QPushButton" name="pushButtonClear"> | |
| 219 | + <property name="text"> | |
| 220 | + <string>Clear</string> | |
| 221 | + </property> | |
| 222 | + </widget> | |
| 223 | + </item> | |
| 224 | + </layout> | |
| 225 | + </item> | |
| 226 | + <item> | |
| 227 | + <widget class="QTextEdit" name="textEditReceive"> | |
| 228 | + <property name="readOnly"> | |
| 229 | + <bool>true</bool> | |
| 230 | + </property> | |
| 231 | + </widget> | |
| 232 | + </item> | |
| 233 | + <item> | |
| 234 | + <layout class="QHBoxLayout"> | |
| 235 | + <item> | |
| 236 | + <widget class="QLineEdit" name="lineEditSend"/> | |
| 237 | + </item> | |
| 238 | + <item> | |
| 239 | + <widget class="QCheckBox" name="checkBoxCR"> | |
| 240 | + <property name="text"> | |
| 241 | + <string>CR</string> | |
| 242 | + </property> | |
| 243 | + </widget> | |
| 244 | + </item> | |
| 245 | + <item> | |
| 246 | + <widget class="QCheckBox" name="checkBoxLF"> | |
| 247 | + <property name="text"> | |
| 248 | + <string>LF</string> | |
| 249 | + </property> | |
| 250 | + <property name="checked"> | |
| 251 | + <bool>true</bool> | |
| 252 | + </property> | |
| 253 | + </widget> | |
| 254 | + </item> | |
| 255 | + </layout> | |
| 256 | + </item> | |
| 257 | + <item> | |
| 258 | + <widget class="QPushButton" name="pushButtonSend"> | |
| 259 | + <property name="enabled"> | |
| 260 | + <bool>false</bool> | |
| 261 | + </property> | |
| 262 | + <property name="text"> | |
| 263 | + <string>Send</string> | |
| 264 | + </property> | |
| 265 | + </widget> | |
| 266 | + </item> | |
| 267 | + <item> | |
| 268 | + <layout class="QHBoxLayout" name="horizontalLayout_2"> | |
| 269 | + <property name="topMargin"> | |
| 270 | + <number>0</number> | |
| 271 | + </property> | |
| 272 | + <item> | |
| 273 | + <widget class="QCheckBox" name="checkBox4KOZOS"> | |
| 274 | + <property name="sizePolicy"> | |
| 275 | + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> | |
| 276 | + <horstretch>0</horstretch> | |
| 277 | + <verstretch>0</verstretch> | |
| 278 | + </sizepolicy> | |
| 279 | + </property> | |
| 280 | + <property name="text"> | |
| 281 | + <string>forKOZOS</string> | |
| 282 | + </property> | |
| 283 | + <property name="checked"> | |
| 284 | + <bool>true</bool> | |
| 285 | + </property> | |
| 286 | + </widget> | |
| 287 | + </item> | |
| 288 | + <item> | |
| 289 | + <widget class="QPushButton" name="pushButtonSendFile"> | |
| 290 | + <property name="enabled"> | |
| 291 | + <bool>false</bool> | |
| 292 | + </property> | |
| 293 | + <property name="text"> | |
| 294 | + <string>XMODEM SendFile</string> | |
| 295 | + </property> | |
| 296 | + </widget> | |
| 297 | + </item> | |
| 298 | + </layout> | |
| 299 | + </item> | |
| 300 | + </layout> | |
| 301 | + </widget> | |
| 302 | + </item> | |
| 303 | + </layout> | |
| 304 | + </widget> | |
| 305 | + </widget> | |
| 306 | + <resources/> | |
| 307 | + <connections/> | |
| 308 | +</ui> |
| @@ -0,0 +1,35 @@ | ||
| 1 | + | |
| 2 | +#include <QFileInfo> | |
| 3 | +#include <QCloseEvent> | |
| 4 | + | |
| 5 | +#include "sendfile_dialog.h" | |
| 6 | +#include "ui_sendfile_dialog.h" | |
| 7 | + | |
| 8 | +SendFile_Dialog::SendFile_Dialog(QWidget *parent, QString path) : | |
| 9 | + QDialog(parent), | |
| 10 | + ui(new Ui::SendFile_Dialog) | |
| 11 | +{ | |
| 12 | + ui->setupUi(this); | |
| 13 | + | |
| 14 | + connect(ui->pushButtonCancel, SIGNAL(clicked()), this, SIGNAL(stopSendFile())); | |
| 15 | + | |
| 16 | + this->filepath = path; | |
| 17 | + QFileInfo fi(this->filepath); | |
| 18 | + ui->lineEditFileName->setText(fi.fileName()); | |
| 19 | + ui->label_3->setText(QString(tr("FileSize: %1 bytes")).arg(fi.size())); | |
| 20 | + ui->progressBar->setValue(0); | |
| 21 | +} | |
| 22 | + | |
| 23 | +SendFile_Dialog::~SendFile_Dialog() | |
| 24 | +{ | |
| 25 | + delete ui; | |
| 26 | +} | |
| 27 | + | |
| 28 | +void SendFile_Dialog::closeEvent(QCloseEvent* e){ | |
| 29 | + e->ignore(); // ignore window title bar close button | |
| 30 | +} | |
| 31 | + | |
| 32 | +void SendFile_Dialog::updateProgressbar(int progress) | |
| 33 | +{ | |
| 34 | + ui->progressBar->setValue(progress); | |
| 35 | +} |
| @@ -0,0 +1,32 @@ | ||
| 1 | +#ifndef SENDFILE_DIALOG_H | |
| 2 | +#define SENDFILE_DIALOG_H | |
| 3 | + | |
| 4 | +#include <QDialog> | |
| 5 | + | |
| 6 | +namespace Ui { | |
| 7 | + class SendFile_Dialog; | |
| 8 | +} | |
| 9 | + | |
| 10 | +class SendFile_Dialog : public QDialog | |
| 11 | +{ | |
| 12 | + Q_OBJECT | |
| 13 | + | |
| 14 | +public: | |
| 15 | + explicit SendFile_Dialog(QWidget *parent = 0, QString path = ""); | |
| 16 | + ~SendFile_Dialog(); | |
| 17 | + | |
| 18 | + void closeEvent(QCloseEvent* evt); | |
| 19 | + void updateProgressbar(int); | |
| 20 | + | |
| 21 | +private: | |
| 22 | + Ui::SendFile_Dialog *ui; | |
| 23 | + | |
| 24 | + QString filepath; | |
| 25 | + | |
| 26 | +private slots: | |
| 27 | + | |
| 28 | +signals: | |
| 29 | + void stopSendFile(); | |
| 30 | +}; | |
| 31 | + | |
| 32 | +#endif // SENDFILE_DIALOG_H |
| @@ -0,0 +1,130 @@ | ||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | |
| 2 | +<ui version="4.0"> | |
| 3 | + <class>SendFile_Dialog</class> | |
| 4 | + <widget class="QDialog" name="SendFile_Dialog"> | |
| 5 | + <property name="windowModality"> | |
| 6 | + <enum>Qt::ApplicationModal</enum> | |
| 7 | + </property> | |
| 8 | + <property name="geometry"> | |
| 9 | + <rect> | |
| 10 | + <x>0</x> | |
| 11 | + <y>0</y> | |
| 12 | + <width>292</width> | |
| 13 | + <height>186</height> | |
| 14 | + </rect> | |
| 15 | + </property> | |
| 16 | + <property name="minimumSize"> | |
| 17 | + <size> | |
| 18 | + <width>292</width> | |
| 19 | + <height>186</height> | |
| 20 | + </size> | |
| 21 | + </property> | |
| 22 | + <property name="maximumSize"> | |
| 23 | + <size> | |
| 24 | + <width>292</width> | |
| 25 | + <height>186</height> | |
| 26 | + </size> | |
| 27 | + </property> | |
| 28 | + <property name="contextMenuPolicy"> | |
| 29 | + <enum>Qt::NoContextMenu</enum> | |
| 30 | + </property> | |
| 31 | + <property name="windowTitle"> | |
| 32 | + <string>SendFile Status</string> | |
| 33 | + </property> | |
| 34 | + <widget class="QPushButton" name="pushButtonCancel"> | |
| 35 | + <property name="geometry"> | |
| 36 | + <rect> | |
| 37 | + <x>30</x> | |
| 38 | + <y>140</y> | |
| 39 | + <width>211</width> | |
| 40 | + <height>31</height> | |
| 41 | + </rect> | |
| 42 | + </property> | |
| 43 | + <property name="text"> | |
| 44 | + <string>Cancel</string> | |
| 45 | + </property> | |
| 46 | + </widget> | |
| 47 | + <widget class="QProgressBar" name="progressBar"> | |
| 48 | + <property name="geometry"> | |
| 49 | + <rect> | |
| 50 | + <x>30</x> | |
| 51 | + <y>102</y> | |
| 52 | + <width>241</width> | |
| 53 | + <height>21</height> | |
| 54 | + </rect> | |
| 55 | + </property> | |
| 56 | + <property name="value"> | |
| 57 | + <number>0</number> | |
| 58 | + </property> | |
| 59 | + </widget> | |
| 60 | + <widget class="QLineEdit" name="lineEditFileName"> | |
| 61 | + <property name="enabled"> | |
| 62 | + <bool>true</bool> | |
| 63 | + </property> | |
| 64 | + <property name="geometry"> | |
| 65 | + <rect> | |
| 66 | + <x>30</x> | |
| 67 | + <y>40</y> | |
| 68 | + <width>231</width> | |
| 69 | + <height>21</height> | |
| 70 | + </rect> | |
| 71 | + </property> | |
| 72 | + <property name="font"> | |
| 73 | + <font> | |
| 74 | + <pointsize>12</pointsize> | |
| 75 | + </font> | |
| 76 | + </property> | |
| 77 | + <property name="text"> | |
| 78 | + <string>filename</string> | |
| 79 | + </property> | |
| 80 | + </widget> | |
| 81 | + <widget class="QLabel" name="label"> | |
| 82 | + <property name="geometry"> | |
| 83 | + <rect> | |
| 84 | + <x>30</x> | |
| 85 | + <y>10</y> | |
| 86 | + <width>231</width> | |
| 87 | + <height>21</height> | |
| 88 | + </rect> | |
| 89 | + </property> | |
| 90 | + <property name="font"> | |
| 91 | + <font> | |
| 92 | + <pointsize>12</pointsize> | |
| 93 | + <weight>75</weight> | |
| 94 | + <bold>true</bold> | |
| 95 | + </font> | |
| 96 | + </property> | |
| 97 | + <property name="text"> | |
| 98 | + <string>Send...</string> | |
| 99 | + </property> | |
| 100 | + </widget> | |
| 101 | + <widget class="QLabel" name="label_2"> | |
| 102 | + <property name="geometry"> | |
| 103 | + <rect> | |
| 104 | + <x>30</x> | |
| 105 | + <y>90</y> | |
| 106 | + <width>50</width> | |
| 107 | + <height>12</height> | |
| 108 | + </rect> | |
| 109 | + </property> | |
| 110 | + <property name="text"> | |
| 111 | + <string>Progress</string> | |
| 112 | + </property> | |
| 113 | + </widget> | |
| 114 | + <widget class="QLabel" name="label_3"> | |
| 115 | + <property name="geometry"> | |
| 116 | + <rect> | |
| 117 | + <x>40</x> | |
| 118 | + <y>60</y> | |
| 119 | + <width>221</width> | |
| 120 | + <height>20</height> | |
| 121 | + </rect> | |
| 122 | + </property> | |
| 123 | + <property name="text"> | |
| 124 | + <string>FileSize: </string> | |
| 125 | + </property> | |
| 126 | + </widget> | |
| 127 | + </widget> | |
| 128 | + <resources/> | |
| 129 | + <connections/> | |
| 130 | +</ui> |
| @@ -441,14 +441,65 @@ void ManageSerialPort::stopReceiving() | ||
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | +// Transfer File by XMODEM protcol | |
| 445 | +void ManageSerialPort::startXferFile_XMODEM(QString filepath) | |
| 446 | +{ | |
| 447 | + // Enable Thread Send&Receive | |
| 448 | + this->stopSending(); | |
| 449 | + this->stopReceiving(); | |
| 450 | + | |
| 451 | + this->disableReceiving(); | |
| 452 | + this->disableSending(); | |
| 453 | + | |
| 454 | + char resp[1024]; | |
| 455 | + if (flagKOZOS) { | |
| 456 | + extSerialPort.write("load\n", 5); | |
| 457 | + extSerialPort.readLine(resp, sizeof(resp)); // read echo back, prompt | |
| 458 | + } | |
| 444 | 459 | |
| 460 | + thSendXModem = new ThreadSendXModem(extSerialPort); | |
| 445 | 461 | |
| 462 | + connect(thSendXModem, SIGNAL(sendEnded(int)), this, SLOT(slot_sendEnded(int))); | |
| 463 | + connect(thSendXModem, SIGNAL(progress_status(int)), this, SIGNAL(progress_status(int))); | |
| 446 | 464 | |
| 465 | + thSendXModem->setSendFilePath(filepath); | |
| 447 | 466 | |
| 467 | + thSendXModem->start(); | |
| 468 | + | |
| 469 | +} | |
| 448 | 470 | |
| 471 | +// Transfer File by XMODEM protcol | |
| 472 | +void ManageSerialPort::stopXferFile_XMODEM() | |
| 473 | +{ | |
| 474 | + thSendXModem->stopSendXModem(); | |
| 475 | +} | |
| 449 | 476 | |
| 477 | + // send KOZOS load command, before FileSend | |
| 478 | +void ManageSerialPort::setFlagKOZOS(bool flag) | |
| 479 | +{ | |
| 480 | + this->flagKOZOS = flag; // true is KOZOS option enable | |
| 481 | +} | |
| 450 | 482 | |
| 483 | +void ManageSerialPort::slot_sendEnded(int result) | |
| 484 | +{ | |
| 485 | + qDebug() << QString("slot_SendEnded. code = %1").arg(result); | |
| 451 | 486 | |
| 487 | + // Enable Thread Send&Receive | |
| 488 | + this->enableSending(); | |
| 489 | + this->enableReceiving(); | |
| 490 | + this->receiveData(); | |
| 491 | + | |
| 492 | + thSendXModem->stopSendXModem(); | |
| 493 | + thSendXModem->wait(); | |
| 494 | + delete (thSendXModem); | |
| 495 | + thSendXModem = NULL; | |
| 496 | + | |
| 497 | + emit sendEnded(result); | |
| 498 | +} | |
| 499 | +//void ManageSerialPort::slot_progress_status(int progress) | |
| 500 | +//{ | |
| 501 | +// qDebug() << QString("slot_progress_status : pregress = %1").arg(progress); | |
| 502 | +//} | |
| 452 | 503 | |
| 453 | 504 | |
| 454 | 505 | /******************************************************************************************************** |
| @@ -558,7 +609,212 @@ void ThreadReceive::run() | ||
| 558 | 609 | mutexReceive.unlock(); |
| 559 | 610 | |
| 560 | 611 | emit newDataReceived(dataReceived); |
| 561 | - } | |
| 612 | + } else { | |
| 613 | + this->msleep(100); | |
| 614 | + } | |
| 562 | 615 | } |
| 563 | 616 | } |
| 564 | 617 | |
| 618 | + | |
| 619 | +/******************************************************************************************************** | |
| 620 | + * Classe ThreadSendXModem | |
| 621 | + *****************************************************************************************************/ | |
| 622 | + | |
| 623 | +ThreadSendXModem::ThreadSendXModem(QextSerialPort &addressSerialPort) : extSerialPort(addressSerialPort) | |
| 624 | +{ | |
| 625 | + stopped=false; | |
| 626 | + filepath = ""; | |
| 627 | +} | |
| 628 | + | |
| 629 | +ThreadSendXModem::~ThreadSendXModem() | |
| 630 | +{ | |
| 631 | + if (isRunning()) | |
| 632 | + { | |
| 633 | + stopSendXModem(); | |
| 634 | + wait(); | |
| 635 | + } | |
| 636 | +} | |
| 637 | + | |
| 638 | +void ThreadSendXModem::stopSendXModem() | |
| 639 | +{ | |
| 640 | + stopped = true; | |
| 641 | +} | |
| 642 | + | |
| 643 | +void ThreadSendXModem::setSendFilePath(QString path) | |
| 644 | +{ | |
| 645 | + filepath = path; | |
| 646 | +} | |
| 647 | + | |
| 648 | +bool ThreadSendXModem::XMODEM_DataBlock(char *buff, unsigned char blknum, char *data, int datalen) | |
| 649 | +{ | |
| 650 | + memset(&buff[3], 0x1A, 128); // Padding EOF(0x1F) | |
| 651 | + buff[0] = 0x01; // SOH | |
| 652 | + buff[1] = blknum; | |
| 653 | + buff[2] = ~blknum; | |
| 654 | + memcpy(&buff[3], data, datalen); | |
| 655 | + unsigned char chksum = 0; | |
| 656 | + for (int i = 0; i < 128; i++) { | |
| 657 | + chksum += buff[i+3]; | |
| 658 | + } | |
| 659 | + buff[128+3] = chksum; | |
| 660 | + | |
| 661 | + return false; | |
| 662 | +} | |
| 663 | + | |
| 664 | +void ThreadSendXModem::run() | |
| 665 | +{ | |
| 666 | + enum { | |
| 667 | + CODE_SOH = 0x01, | |
| 668 | + CODE_STX = 0x02, | |
| 669 | + CODE_ETX = 0x03, | |
| 670 | + CODE_EOT = 0x04, | |
| 671 | + CODE_ACK = 0x06, | |
| 672 | + CODE_NAK = 0x15, | |
| 673 | + CODE_CAN = 0x18, | |
| 674 | + BLOCK_SIZE = 128 | |
| 675 | + }; | |
| 676 | + int ret = 0; | |
| 677 | + int numBytes=0; | |
| 678 | + | |
| 679 | + char buff[BLOCK_SIZE]; | |
| 680 | + char data[BLOCK_SIZE+4]; // SOH(1) + BLK#(1) + ~BLK#(1) + DATA(128) + CHKSUM(1) | |
| 681 | + char senddata[BLOCK_SIZE]; | |
| 682 | + int senddata_len; | |
| 683 | + | |
| 684 | + int i; | |
| 685 | + | |
| 686 | + int BlockCount = 1; | |
| 687 | + int LeastBytes = 0; | |
| 688 | + unsigned char BlockNumber; | |
| 689 | + bool flag_retry = false; | |
| 690 | + | |
| 691 | + // fileopen failed then return true; | |
| 692 | + qDebug() << filepath; | |
| 693 | + QFile file(filepath); | |
| 694 | + qint64 filesize = file.size(); | |
| 695 | + | |
| 696 | + qDebug() << QString("FileSize is %1 bytes").arg(filesize); | |
| 697 | + BlockCount = (int)((int)filesize / BLOCK_SIZE); | |
| 698 | + LeastBytes = (int)((int)filesize % BLOCK_SIZE); | |
| 699 | + if (LeastBytes) BlockCount++; | |
| 700 | + qDebug() << QString("BlockCount = %1, LeastBytes = %2").arg(BlockCount).arg(LeastBytes); | |
| 701 | + | |
| 702 | + if (!(file.open(QIODevice::ReadOnly))) { | |
| 703 | + qDebug() << "FileOpenError"; | |
| 704 | + buff[0] = CODE_CAN; // CAN | |
| 705 | + extSerialPort.write(buff, 1); // SendCAN | |
| 706 | + ret = 1; // FileOpen error | |
| 707 | + goto failure; | |
| 708 | + } | |
| 709 | + | |
| 710 | + // 1.Wait for NAK | |
| 711 | + while (1) { | |
| 712 | + if (stopped) { | |
| 713 | + buff[0] = CODE_CAN; // CAN | |
| 714 | + extSerialPort.write(buff, 1); // SendCAN | |
| 715 | + ret = 2; // 1stNAK error | |
| 716 | + goto failure; | |
| 717 | + } | |
| 718 | + numBytes = extSerialPort.bytesAvailable(); | |
| 719 | + if (numBytes > 0) { | |
| 720 | + data[0] = 0x00; | |
| 721 | + extSerialPort.read(data, 1); | |
| 722 | + if (data[0] == CODE_NAK) break; // Rcv NAK | |
| 723 | + } | |
| 724 | + this->msleep(100); | |
| 725 | + } | |
| 726 | + // this->sleep(1); | |
| 727 | + extSerialPort.flush(); // Flush Recv NAK | |
| 728 | + | |
| 729 | + // 2.SendData, Wait for ACK | |
| 730 | + flag_retry = false; | |
| 731 | + BlockNumber = 1; | |
| 732 | + for (i = 0; i < BlockCount;) { | |
| 733 | + if (stopped) { | |
| 734 | + buff[0] = CODE_CAN; // CAN | |
| 735 | + extSerialPort.write(buff, 1); // SendCAN | |
| 736 | + ret = 3; // Cancel | |
| 737 | + goto failure; | |
| 738 | + } | |
| 739 | + if (!flag_retry) { | |
| 740 | + if (LeastBytes != 0 && (i + 1) == BlockCount) { // LastData? | |
| 741 | + senddata_len = LeastBytes; | |
| 742 | + } else { | |
| 743 | + senddata_len = BLOCK_SIZE; | |
| 744 | + } | |
| 745 | + file.read(senddata, senddata_len); | |
| 746 | + this->XMODEM_DataBlock(data, BlockNumber, senddata, senddata_len); | |
| 747 | + } | |
| 748 | + extSerialPort.write(data, BLOCK_SIZE+4); // Send BlockData | |
| 749 | + | |
| 750 | + this->msleep(200); | |
| 751 | + | |
| 752 | + // WaitFor ACK | |
| 753 | + while (1) { | |
| 754 | + if (stopped) { | |
| 755 | + buff[0] = CODE_CAN; // CAN | |
| 756 | + extSerialPort.write(buff, 1); // SendCAN | |
| 757 | + ret = 4; // DataACK error | |
| 758 | + goto failure; | |
| 759 | + } | |
| 760 | + numBytes = extSerialPort.bytesAvailable(); | |
| 761 | + if (numBytes > 0) { | |
| 762 | + data[0] = 0x00; | |
| 763 | + extSerialPort.read(data, 1); | |
| 764 | + if (data[0] == CODE_ACK || data[0] == CODE_NAK) break; // Rcv ACK or NAK | |
| 765 | + } | |
| 766 | + this->msleep(100); | |
| 767 | + } | |
| 768 | + | |
| 769 | + if (data[0] == CODE_ACK) { // Rcv Ack, goto NextBlock | |
| 770 | + emit progress_status((int)((float)(i + 1)/(float)BlockCount*100.0)); | |
| 771 | + qDebug() << QString("Rcv DataAck, BlkNum = %1").arg(BlockNumber); | |
| 772 | + flag_retry = false; | |
| 773 | + BlockNumber++; | |
| 774 | + i++; | |
| 775 | + } else if (data[0] == CODE_NAK) { | |
| 776 | + qDebug() << "Rcv DataNAK"; | |
| 777 | + flag_retry = true; | |
| 778 | + } | |
| 779 | + } | |
| 780 | + | |
| 781 | + // 3.Send EOT, Wait for ACKorNAK | |
| 782 | + buff[0] = CODE_EOT; // EOT | |
| 783 | + extSerialPort.write(buff, 1); // SendEOT | |
| 784 | + qDebug() << QString("Send EOT"); | |
| 785 | + this->msleep(100); | |
| 786 | + | |
| 787 | + // WaitFor EndACK | |
| 788 | + while (1) { | |
| 789 | + if (stopped) { | |
| 790 | + buff[0] = CODE_CAN; // CAN | |
| 791 | + extSerialPort.write(buff, 1); // SendCAN | |
| 792 | + ret = 5; // EndACK error | |
| 793 | + goto failure; | |
| 794 | + } | |
| 795 | + numBytes = extSerialPort.bytesAvailable(); | |
| 796 | + if (numBytes > 0) { | |
| 797 | + extSerialPort.read(data, 1); | |
| 798 | + break; | |
| 799 | + } | |
| 800 | + this->msleep(100); | |
| 801 | + } | |
| 802 | + qDebug() << QString("RcvEOT Ack"); | |
| 803 | + | |
| 804 | + // File Close | |
| 805 | + file.close(); | |
| 806 | + extSerialPort.flush(); | |
| 807 | + | |
| 808 | + emit sendEnded(0); // NoError | |
| 809 | + stopped = false; | |
| 810 | + return; | |
| 811 | + | |
| 812 | +failure: | |
| 813 | + // File Close | |
| 814 | + file.close(); | |
| 815 | + extSerialPort.flush(); | |
| 816 | + | |
| 817 | + emit sendEnded(ret); // Error | |
| 818 | + stopped = false; | |
| 819 | +} | |
| 820 | + |
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | #include <QQueue> |
| 14 | 14 | #include <QMetaType> |
| 15 | 15 | #include <QMutex> |
| 16 | +#include <QString> | |
| 16 | 17 | #include "qextserialport.h" |
| 17 | 18 | |
| 18 | 19 | Q_DECLARE_METATYPE(BaudRateType); |
| @@ -23,6 +24,7 @@ Q_DECLARE_METATYPE(FlowType); | ||
| 23 | 24 | |
| 24 | 25 | class ThreadSend; |
| 25 | 26 | class ThreadReceive; |
| 27 | +class ThreadSendXModem; | |
| 26 | 28 | |
| 27 | 29 | |
| 28 | 30 | class ManageSerialPort : public QObject |
| @@ -242,14 +244,21 @@ public: | ||
| 242 | 244 | |
| 243 | 245 | void stopReceiving(); |
| 244 | 246 | |
| 247 | + void startXferFile_XMODEM(QString filepath); // Transfer File by XMODEM protcol | |
| 248 | + void stopXferFile_XMODEM(); // Transfer File by XMODEM protcol | |
| 249 | + void setFlagKOZOS(bool); // send KOZOS load command, before FileSend. | |
| 250 | + | |
| 245 | 251 | signals: |
| 246 | 252 | void newDataReceived(const QByteArray &dataReceived); |
| 253 | + void sendEnded(int); | |
| 254 | + void progress_status(int progress); | |
| 247 | 255 | |
| 248 | 256 | private: |
| 249 | 257 | //Variables privees |
| 250 | 258 | QextSerialPort extSerialPort; |
| 251 | 259 | ThreadSend *threadSend; |
| 252 | 260 | ThreadReceive *threadReceive; |
| 261 | + ThreadSendXModem *thSendXModem; | |
| 253 | 262 | |
| 254 | 263 | bool sendingEnabled; |
| 255 | 264 | bool receivingEnabled; |
| @@ -259,6 +268,11 @@ private: | ||
| 259 | 268 | bool saveStateReceivedEnabled; |
| 260 | 269 | bool saveStateReceiveData; |
| 261 | 270 | |
| 271 | + bool flagKOZOS; | |
| 272 | + | |
| 273 | +private slots: | |
| 274 | + void slot_sendEnded(int); // slot XMODEM Send End | |
| 275 | +// void slot_progress_status(int); | |
| 262 | 276 | }; |
| 263 | 277 | |
| 264 | 278 | #endif // MANAGESERIALPORT_H |
| @@ -320,3 +334,34 @@ private : | ||
| 320 | 334 | signals: |
| 321 | 335 | void newDataReceived(const QByteArray &dataReceived); |
| 322 | 336 | }; |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | +class ThreadSendXModem : public QThread | |
| 343 | +{ | |
| 344 | + Q_OBJECT | |
| 345 | + | |
| 346 | +public: | |
| 347 | + ThreadSendXModem(QextSerialPort &addressSerialPort); | |
| 348 | + ~ThreadSendXModem(); | |
| 349 | + void stopSendXModem(); | |
| 350 | + void setSendFilePath(QString); | |
| 351 | + | |
| 352 | +protected: | |
| 353 | + void run(); | |
| 354 | + | |
| 355 | +private : | |
| 356 | + QMutex mutexSendXModem; | |
| 357 | + QextSerialPort &extSerialPort; | |
| 358 | + bool stopped; | |
| 359 | + | |
| 360 | + QString filepath; | |
| 361 | + | |
| 362 | + bool XMODEM_DataBlock(char *buff, unsigned char blknum, char *data, int datalen); | |
| 363 | + | |
| 364 | +signals: | |
| 365 | + void sendEnded(int resultcode); | |
| 366 | + void progress_status(int progress); | |
| 367 | +}; |