Skip to content

Commit 36be7cb

Browse files
committed
Merge remote-tracking branch 'origin/dev'
2 parents fa1a3fa + 72be609 commit 36be7cb

File tree

6 files changed

+69
-34
lines changed

6 files changed

+69
-34
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,19 @@ Below are the methods for installing the OpenModScan for different OS
122122
## <img src="docs/icons/logo_windows.svg" width="16" height="16"> Microsoft Windows
123123
Run the installer:
124124

125-
- For 32-bit Windows: `qt5-omodscan_1.14.0_x86.exe`
126-
- For 64-bit Windows: `qt5-omodscan_1.14.0_x64.exe` or `qt6-omodscan_1.14.0_x64.exe`
125+
- For 32-bit Windows: `qt5-omodscan_1.14.1_x86.exe`
126+
- For 64-bit Windows: `qt5-omodscan_1.14.1_x64.exe` or `qt6-omodscan_1.14.1_x64.exe`
127127

128128

129129
## <img src="docs/icons/logo_debian.svg" width="20" height="20"> Debian • <img src="docs/icons/logo_ubuntu.svg" width="20" height="20"> Ubuntu • <img width="20" height="20" src="docs/icons/logo_mint.png" /> Mint • <img src="docs/icons/logo_zorin.png" width="20" height="20"> Zorin • <img width="22" height="22" src="docs/icons/logo_astra.png" /> Astra Linux
130130
### Install
131131
Install the DEB package from the command line:
132132
```bash
133-
sudo apt install ./qt6-omodscan_1.14.0-1_amd64.deb
133+
sudo apt install ./qt6-omodscan_1.14.1-1_amd64.deb
134134
```
135135
or if you want to use Qt5 libraries:
136136
```bash
137-
sudo apt install ./qt5-omodscan_1.14.0-1_amd64.deb
137+
sudo apt install ./qt5-omodscan_1.14.1-1_amd64.deb
138138
```
139139

140140
### Remove
@@ -151,7 +151,7 @@ sudo apt remove qt5-omodscan
151151
### Install
152152
Install the RPM package from the command line:
153153
```bash
154-
sudo dnf install ./qt6-omodscan_1.14.0-1.x86_64.rpm
154+
sudo dnf install ./qt6-omodscan_1.14.1-1.x86_64.rpm
155155
```
156156

157157
### Remove
@@ -164,7 +164,7 @@ sudo dnf remove qt6-omodscan
164164
### Install
165165
Install the RPM package from the command line as root user:
166166
```bash
167-
apt-get install ./qt6-omodscan_1.14.0-1.x86_64.rpm
167+
apt-get install ./qt6-omodscan_1.14.1-1.x86_64.rpm
168168
```
169169

170170
### Remove
@@ -181,7 +181,7 @@ sudo rpm --import qt6-omodscan.rpm.pubkey
181181
```
182182
Install the RPM package using Zypper:
183183
```bash
184-
sudo zypper install ./qt6-omodscan_1.14.0-1.x86_64.rpm
184+
sudo zypper install ./qt6-omodscan_1.14.1-1.x86_64.rpm
185185
```
186186

187187
### Remove

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.16)
22

33
project(omodscan
4-
VERSION 1.14.0
4+
VERSION 1.14.1
55
DESCRIPTION "An Open Source Modbus Master (Client) Utility"
66
LANGUAGES CXX)
77

src/controls/numericlineedit.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,6 @@ void NumericLineEdit::internalSetValue(QVariant value)
297297
if(text != QLineEdit::text())
298298
QLineEdit::setText(text);
299299
}
300-
else if(_leadingZeroes)
301-
{
302-
const auto text = QStringLiteral("%1").arg(value.toInt(), _leadingZeroWidth, 10, QLatin1Char('0'));
303-
if(text != QLineEdit::text())
304-
QLineEdit::setText(text);
305-
}
306300
else
307301
{
308302
const auto text = QString::number(value.toInt());
@@ -391,12 +385,6 @@ void NumericLineEdit::internalSetValue(QVariant value)
391385
if(text != QLineEdit::text())
392386
QLineEdit::setText(text);
393387
}
394-
else if(_leadingZeroes)
395-
{
396-
const auto text = QStringLiteral("%1").arg(value.toLongLong(), _leadingZeroWidth, 10, QLatin1Char('0'));
397-
if(text != QLineEdit::text())
398-
QLineEdit::setText(text);
399-
}
400388
else
401389
{
402390
const auto text = QString::number(value.toLongLong());
@@ -760,7 +748,6 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to
760748
else
761749
{
762750
const int nums = QString::number(top.toInt()).length();
763-
_leadingZeroWidth = qMax(1, nums);
764751
setMaxLength(qMax(2, nums + 1));
765752
setValidator(new QIntValidator(bottom.toInt(), top.toInt(), this));
766753
}
@@ -814,7 +801,6 @@ void NumericLineEdit::on_rangeChanged(const QVariant& bottom, const QVariant& to
814801
else
815802
{
816803
const int nums = QString::number(top.toLongLong()).length();
817-
_leadingZeroWidth = qMax(1, nums);
818804
setMaxLength(qMax(2, nums + 1));
819805
setValidator(new QInt64Validator(bottom.toLongLong(), top.toLongLong(), this));
820806
}

src/dialogs/dialogwriteholdingregister.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ DialogWriteHoldingRegister::DialogWriteHoldingRegister(ModbusWriteParams& params
170170
ui->groupBoxBitPattern->setCheckState(toCheckState(_writeParams.Value.toUInt()));
171171

172172
connect(ui->lineEditValue, QOverload<const QVariant&>::of(&NumericLineEdit::valueChanged), this, [this](const QVariant& value) {
173+
QSignalBlocker blocker(ui->controlBitPattern);
173174
ui->controlBitPattern->setValue(value.toUInt());
174175
});
175176

src/qmodbusadurtu.h

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
class QModbusAduRtu : public QModbusAdu
1111
{
1212
public:
13+
/// Minimum RTU frame size: address(1) + function(1) + data(0+) + CRC(2)
14+
static constexpr int MinRtuFrameSize = 4;
15+
1316
explicit QModbusAduRtu(const QByteArray& rawData)
1417
: QModbusAdu()
1518
{
@@ -21,6 +24,8 @@ class QModbusAduRtu : public QModbusAdu
2124
/// \return
2225
///
2326
bool isValid() const override {
27+
if (_data.size() < MinRtuFrameSize)
28+
return false;
2429
return matchingChecksum() && _pdu.isValid();
2530
}
2631

@@ -30,15 +35,23 @@ class QModbusAduRtu : public QModbusAdu
3035
///
3136
void setRawData(const QByteArray& data) override {
3237
_data = data;
33-
_pdu.setFunctionCode(QModbusPdu::FunctionCode((quint8)_data[1]));
34-
_pdu.setData(_data.mid(2, _data.size() - 4));
38+
if (_data.size() >= MinRtuFrameSize) {
39+
_pdu.setFunctionCode(QModbusPdu::FunctionCode(quint8(_data[1])));
40+
_pdu.setData(_data.mid(2, _data.size() - MinRtuFrameSize));
41+
} else {
42+
_pdu.setFunctionCode(QModbusPdu::Invalid); // reset to invalid state
43+
_pdu.setData(QByteArray());
44+
}
3545
}
3646

3747
///
3848
/// \brief serverAddress
3949
/// \return
4050
///
4151
quint8 serverAddress() const override {
52+
if (_data.isEmpty())
53+
return 0;
54+
4255
return quint8(_data[0]);
4356
}
4457

@@ -47,17 +60,23 @@ class QModbusAduRtu : public QModbusAdu
4760
/// \return
4861
///
4962
quint16 checksum() const {
50-
return makeUInt16(_data[_data.size() - 1], _data[_data.size() - 2], ByteOrder::Direct);
63+
if (_data.size() >= MinRtuFrameSize) {
64+
return makeUInt16(_data[_data.size() - 1], _data[_data.size() - 2], ByteOrder::Direct);
65+
}
66+
return 0;
5167
}
5268

5369
///
5470
/// \brief calcChecksum
5571
/// \return
5672
///
5773
quint16 calcChecksum() const {
58-
const auto size = _data.size() - 2; // two bytes, CRC
59-
const auto data = _data.left(size);
60-
return calculateCRC(data, size);
74+
if (_data.size() < MinRtuFrameSize)
75+
return 0;
76+
77+
const int crcDataSize = _data.size() - 2;
78+
const QByteArray crcData = _data.left(crcDataSize);
79+
return calculateCRC(crcData.constData(), crcDataSize);
6180
}
6281

6382
///
@@ -68,7 +87,10 @@ class QModbusAduRtu : public QModbusAdu
6887
return checksum() == calcChecksum();
6988
}
7089

71-
inline static quint16 calculateCRC(const char* data, qint32 len){
90+
inline static quint16 calculateCRC(const char* data, qint32 len) {
91+
if (len <= 0 || data == nullptr)
92+
return 0;
93+
7294
quint16 crc = 0xFFFF;
7395
while (len--) {
7496
const quint8 c = *data++;
@@ -82,12 +104,12 @@ class QModbusAduRtu : public QModbusAdu
82104
}
83105
crc &= 0xFFFF;
84106
}
85-
crc = crc_reflect(crc & 0xFFFF, 16) ^ 0x0000;
86-
return (crc >> 8) | (crc << 8); // swap bytes
107+
crc = crc_reflect(crc, 16);
108+
return (crc >> 8) | (crc << 8); // swap bytes
87109
}
88110

89111
private:
90-
inline static quint16 crc_reflect(quint16 data, qint32 len){
112+
inline static quint16 crc_reflect(quint16 data, qint32 len) {
91113
quint16 ret = data & 0x01;
92114
for (qint32 i = 1; i < len; i++) {
93115
data >>= 1;

src/qmodbusadutcp.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
class QModbusAduTcp : public QModbusAdu
1111
{
1212
public:
13+
/// Minimum TCP frame size: header(6) + unitId(1) + function(1) = 8 bytes
14+
static constexpr int MinTcpFrameSize = 8;
15+
1316
explicit QModbusAduTcp(const QByteArray& rawData)
1417
: QModbusAdu()
1518
{
@@ -21,6 +24,9 @@ class QModbusAduTcp : public QModbusAdu
2124
/// \return
2225
///
2326
bool isValid() const override {
27+
if (_data.size() < MinTcpFrameSize)
28+
return false;
29+
2430
return _pdu.isValid() && length() == _pdu.size() + 1;
2531
}
2632

@@ -30,15 +36,23 @@ class QModbusAduTcp : public QModbusAdu
3036
///
3137
void setRawData(const QByteArray& data) override {
3238
_data = data;
33-
_pdu.setFunctionCode(QModbusPdu::FunctionCode((quint8)_data[7]));
34-
_pdu.setData(_data.mid(8));
39+
if (_data.size() >= MinTcpFrameSize) {
40+
_pdu.setFunctionCode(QModbusPdu::FunctionCode(quint8(_data[7])));
41+
_pdu.setData(_data.mid(8, _data.size() - MinTcpFrameSize));
42+
} else {
43+
_pdu.setFunctionCode(QModbusPdu::Invalid); // reset to invalid state
44+
_pdu.setData(QByteArray());
45+
}
3546
}
3647

3748
///
3849
/// \brief transactionId
3950
/// \return
4051
///
4152
quint16 transactionId() const {
53+
if (_data.size() < MinTcpFrameSize)
54+
return 0;
55+
4256
return makeUInt16(_data[1], _data[0], ByteOrder::Direct);
4357
}
4458

@@ -47,6 +61,9 @@ class QModbusAduTcp : public QModbusAdu
4761
/// \param id
4862
///
4963
void setTransactionId(quint16 id) {
64+
if (_data.size() < MinTcpFrameSize)
65+
return;
66+
5067
quint8 lo,hi;
5168
breakUInt16(id, lo, hi, ByteOrder::Direct);
5269
_data[1] = lo; _data[0] = hi;
@@ -57,6 +74,9 @@ class QModbusAduTcp : public QModbusAdu
5774
/// \return
5875
///
5976
quint16 protocolId() const {
77+
if (_data.size() < MinTcpFrameSize)
78+
return 0;
79+
6080
return makeUInt16(_data[3], _data[2], ByteOrder::Direct);
6181
}
6282

@@ -65,6 +85,9 @@ class QModbusAduTcp : public QModbusAdu
6585
/// \return
6686
///
6787
quint16 length() const {
88+
if (_data.size() < MinTcpFrameSize)
89+
return 0;
90+
6891
return makeUInt16(_data[5], _data[4], ByteOrder::Direct);
6992
}
7093

@@ -73,6 +96,9 @@ class QModbusAduTcp : public QModbusAdu
7396
/// \return
7497
///
7598
quint8 serverAddress() const override {
99+
if (_data.size() < MinTcpFrameSize)
100+
return 0;
101+
76102
return quint8(_data[6]);
77103
}
78104

0 commit comments

Comments
 (0)