Skip to content

Commit 9dbe667

Browse files
committed
Improve client's Scanner Window
1 parent c0b608f commit 9dbe667

File tree

9 files changed

+214
-4
lines changed

9 files changed

+214
-4
lines changed
-246 Bytes
Loading

src/client/gui/scanner/client_scanner.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ void mbClientScanner::clear()
424424
{
425425
QWriteLocker _(&m_lock);
426426
m_deviceInfoList.clear();
427+
setStatCountTx(0);
428+
setStatCountRx(0);
429+
setStatPercent(0);
427430
Q_EMIT cleared();
428431
}
429432

@@ -441,6 +444,33 @@ void mbClientScanner::stopScanning()
441444
m_thread->stop();
442445
}
443446

447+
void mbClientScanner::setStatCountTx(quint32 count)
448+
{
449+
if (m_stat.countTx != count)
450+
{
451+
m_stat.countTx = count;
452+
Q_EMIT statCountTxChanged(count);
453+
}
454+
}
455+
456+
void mbClientScanner::setStatCountRx(quint32 count)
457+
{
458+
if (m_stat.countRx != count)
459+
{
460+
m_stat.countRx = count;
461+
Q_EMIT statCountRxChanged(count);
462+
}
463+
}
464+
465+
void mbClientScanner::setStatPercent(quint32 percent)
466+
{
467+
if (m_stat.percent != percent)
468+
{
469+
m_stat.percent = percent;
470+
Q_EMIT statPercentChanged(percent);
471+
}
472+
}
473+
444474
void mbClientScanner::threadStarted()
445475
{
446476
Q_EMIT stateChanged(true);

src/client/gui/scanner/client_scanner.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,26 @@ class mbClientScanner : public QObject
127127
inline int deviceCount() const { return m_deviceInfoList.count(); }
128128
QString deviceInfoStr(int i) const;
129129
void deviceAdd(const Modbus::Settings &settings);
130+
inline quint32 statCountTx() const { return m_stat.countTx; }
131+
inline quint32 statCountRx() const { return m_stat.countRx; }
132+
inline quint32 statPercent() const { return m_stat.percent; }
130133

131134
public:
132135
void addToProject(const QList<int> &indexes = QList<int>());
133136
void clear();
134137
void startScanning(const Modbus::Settings &settings);
135138
void stopScanning();
139+
void setStatCountTx(quint32 count);
140+
void setStatCountRx(quint32 count);
141+
void setStatPercent(quint32 percent);
136142

137143
Q_SIGNALS:
138144
void deviceAdded(int index);
139145
void cleared();
140146
void stateChanged(bool run);
147+
void statCountTxChanged(quint32 count);
148+
void statCountRxChanged(quint32 count);
149+
void statPercentChanged(quint32 percent);
141150

142151
private Q_SLOTS:
143152
void threadStarted();
@@ -155,6 +164,22 @@ private Q_SLOTS:
155164
mutable QReadWriteLock m_lock;
156165
QList<DeviceInfo> m_deviceInfoList;
157166
mbClientScannerThread *m_thread;
167+
168+
private:
169+
struct Statistics
170+
{
171+
Statistics()
172+
{
173+
countTx = 0;
174+
countRx = 0;
175+
percent = 0;
176+
}
177+
178+
quint32 countTx;
179+
quint32 countRx;
180+
quint32 percent;
181+
};
182+
Statistics m_stat;
158183
};
159184

160185
#endif // MBCLIENTSCANNER_H

src/client/gui/scanner/client_scannerthread.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ void mbClientScannerThread::setSettings(const Modbus::Settings &settings)
9090
default:
9191
break;
9292
}
93+
m_combinationCountAll = m_combinationCount * (m_unitEnd - m_unitStart + 1);
94+
m_statTx = 0;
95+
m_statRx = 0;
9396
}
9497

9598
void mbClientScannerThread::run()
@@ -102,6 +105,8 @@ void mbClientScannerThread::run()
102105
Modbus::Settings settings = m_settings;
103106
uint8_t dummy[MB_MAX_BYTES];
104107
memset(dummy, 0, sizeof(dummy));
108+
109+
quint32 deviceCount = 0;
105110
for (int c = 0; m_ctrlRun && (c < m_combinationCount); c++)
106111
{
107112
// Get comibation number for each setting
@@ -218,6 +223,7 @@ void mbClientScannerThread::run()
218223
if (!m_ctrlRun)
219224
break;
220225
}
226+
m_scanner->setStatPercent(++deviceCount*100/m_combinationCountAll);
221227
}
222228
clientPort->close();
223229
mbClient::LogInfo(s.name, QString("End scanning '%1'").arg(sName));
@@ -229,19 +235,35 @@ void mbClientScannerThread::run()
229235
void mbClientScannerThread::slotBytesTx(const Modbus::Char *source, const uint8_t *buff, uint16_t size)
230236
{
231237
mbClient::LogTxRx(mbClientScanner::Strings::instance().name + QString(" ") + source, QStringLiteral("Tx: ") + Modbus::bytesToString(buff, size).data());
238+
incStatTx();
232239
}
233240

234241
void mbClientScannerThread::slotBytesRx(const Modbus::Char *source, const uint8_t *buff, uint16_t size)
235242
{
236243
mbClient::LogTxRx(mbClientScanner::Strings::instance().name + QString(" ") + source, QStringLiteral("Rx: ") + Modbus::bytesToString(buff, size).data());
244+
incStatRx();
237245
}
238246

239247
void mbClientScannerThread::slotAsciiTx(const Modbus::Char *source, const uint8_t *buff, uint16_t size)
240248
{
241249
mbClient::LogTxRx(mbClientScanner::Strings::instance().name + QString(" ") + source, QStringLiteral("Tx: ") + Modbus::asciiToString(buff, size).data());
250+
incStatTx();
242251
}
243252

244253
void mbClientScannerThread::slotAsciiRx(const Modbus::Char *source, const uint8_t *buff, uint16_t size)
245254
{
246255
mbClient::LogTxRx(mbClientScanner::Strings::instance().name + QString(" ") + source, QStringLiteral("Rx: ") + Modbus::asciiToString(buff, size).data());
256+
incStatRx();
257+
}
258+
259+
void mbClientScannerThread::incStatTx()
260+
{
261+
m_statTx++;
262+
m_scanner->setStatCountTx(m_statTx);
263+
}
264+
265+
void mbClientScannerThread::incStatRx()
266+
{
267+
m_statRx++;
268+
m_scanner->setStatCountRx(m_statRx);
247269
}

src/client/gui/scanner/client_scannerthread.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ private Q_SLOTS:
4848
void slotAsciiTx(const Modbus::Char *source, const uint8_t* buff, uint16_t size);
4949
void slotAsciiRx(const Modbus::Char *source, const uint8_t* buff, uint16_t size);
5050

51+
private:
52+
void incStatTx();
53+
void incStatRx();
54+
5155
private:
5256
bool m_ctrlRun;
5357

@@ -72,7 +76,10 @@ private Q_SLOTS:
7276
DivMods_t m_divMods ;
7377
Names_t m_names ;
7478
ValuesList_t m_valuesList;
75-
int m_combinationCount;
79+
quint32 m_combinationCount;
80+
quint32 m_combinationCountAll;
81+
quint32 m_statTx;
82+
quint32 m_statRx;
7683
};
7784

7885
#endif // CLIENT_SCANNERTHREAD_H

src/client/gui/scanner/client_scannerui.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ mbClientScannerUi::mbClientScannerUi(QWidget *parent) :
4949
const Modbus::Defaults &md = Modbus::Defaults::instance();
5050

5151
m_scanner = new mbClientScanner(this);
52+
setStatCountTx(m_scanner->statCountTx());
53+
setStatCountRx(m_scanner->statCountRx());
54+
setStatPercent(m_scanner->statPercent());
5255
connect(m_scanner, &mbClientScanner::stateChanged, this, &mbClientScannerUi::stateChange);
56+
connect(m_scanner, &mbClientScanner::statCountTxChanged, this, &mbClientScannerUi::setStatCountTx);
57+
connect(m_scanner, &mbClientScanner::statCountRxChanged, this, &mbClientScannerUi::setStatCountRx);
58+
connect(m_scanner, &mbClientScanner::statPercentChanged, this, &mbClientScannerUi::setStatPercent);
5359

5460
QVariantList vls;
5561
QLineEdit *ln;
@@ -325,6 +331,21 @@ void mbClientScannerUi::stateChange(bool run)
325331
ui->btnStart ->setEnabled(enable);
326332
}
327333

334+
void mbClientScannerUi::setStatCountTx(quint32 count)
335+
{
336+
ui->lnStatTx->setText(QString::number(count));
337+
}
338+
339+
void mbClientScannerUi::setStatCountRx(quint32 count)
340+
{
341+
ui->lnStatRx->setText(QString::number(count));
342+
}
343+
344+
void mbClientScannerUi::setStatPercent(quint32 p)
345+
{
346+
ui->progressBar->setValue(p);
347+
}
348+
328349
void mbClientScannerUi::closeEvent(QCloseEvent *)
329350
{
330351
//m_scanner->stopScanning();

src/client/gui/scanner/client_scannerui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ private Q_SLOTS:
6767
private Q_SLOTS:
6868
void setType(int type);
6969
void stateChange(bool run);
70+
void setStatCountTx(quint32 count);
71+
void setStatCountRx(quint32 count);
72+
void setStatPercent(quint32 p);
7073

7174
private:
7275
void closeEvent(QCloseEvent*) override;

src/client/gui/scanner/client_scannerui.ui

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>609</width>
10-
<height>468</height>
10+
<height>516</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -366,7 +366,109 @@
366366
<widget class="QWidget" name="layoutWidget2">
367367
<layout class="QVBoxLayout" name="verticalLayout_2">
368368
<item>
369-
<widget class="QTableView" name="tableView"/>
369+
<widget class="QWidget" name="widget" native="true">
370+
<layout class="QHBoxLayout" name="horizontalLayout_6">
371+
<property name="spacing">
372+
<number>2</number>
373+
</property>
374+
<property name="leftMargin">
375+
<number>1</number>
376+
</property>
377+
<property name="topMargin">
378+
<number>1</number>
379+
</property>
380+
<property name="rightMargin">
381+
<number>1</number>
382+
</property>
383+
<property name="bottomMargin">
384+
<number>1</number>
385+
</property>
386+
<item>
387+
<widget class="QLabel" name="label_8">
388+
<property name="text">
389+
<string>Tx:</string>
390+
</property>
391+
</widget>
392+
</item>
393+
<item>
394+
<widget class="QLineEdit" name="lnStatTx">
395+
<property name="enabled">
396+
<bool>false</bool>
397+
</property>
398+
<property name="maximumSize">
399+
<size>
400+
<width>70</width>
401+
<height>16777215</height>
402+
</size>
403+
</property>
404+
<property name="text">
405+
<string>0</string>
406+
</property>
407+
<property name="frame">
408+
<bool>true</bool>
409+
</property>
410+
<property name="readOnly">
411+
<bool>true</bool>
412+
</property>
413+
<property name="cursorMoveStyle">
414+
<enum>Qt::LogicalMoveStyle</enum>
415+
</property>
416+
<property name="clearButtonEnabled">
417+
<bool>false</bool>
418+
</property>
419+
</widget>
420+
</item>
421+
<item>
422+
<widget class="QLabel" name="label_13">
423+
<property name="text">
424+
<string>Rx:</string>
425+
</property>
426+
</widget>
427+
</item>
428+
<item>
429+
<widget class="QLineEdit" name="lnStatRx">
430+
<property name="enabled">
431+
<bool>false</bool>
432+
</property>
433+
<property name="maximumSize">
434+
<size>
435+
<width>70</width>
436+
<height>16777215</height>
437+
</size>
438+
</property>
439+
<property name="text">
440+
<string>0</string>
441+
</property>
442+
<property name="frame">
443+
<bool>true</bool>
444+
</property>
445+
</widget>
446+
</item>
447+
<item>
448+
<widget class="QProgressBar" name="progressBar">
449+
<property name="value">
450+
<number>75</number>
451+
</property>
452+
<property name="textVisible">
453+
<bool>true</bool>
454+
</property>
455+
<property name="invertedAppearance">
456+
<bool>false</bool>
457+
</property>
458+
<property name="textDirection">
459+
<enum>QProgressBar::TopToBottom</enum>
460+
</property>
461+
</widget>
462+
</item>
463+
</layout>
464+
</widget>
465+
</item>
466+
<item>
467+
<widget class="QTableView" name="tableView">
468+
<property name="enabled">
469+
<bool>true</bool>
470+
</property>
471+
</widget>
370472
</item>
371473
<item>
372474
<layout class="QHBoxLayout" name="horizontalLayout_2">

0 commit comments

Comments
 (0)