Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sanny32 committed Sep 11, 2023
2 parents 1d191ed + 3b1a2cb commit 0ea3274
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 1 deletion.
32 changes: 31 additions & 1 deletion omodscan/datasimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void DataSimulator::startSimulation(DataDisplayMode mode, QModbusDataUnit::Regis
break;

case SimulationMode::Decrement:
value = params.IncrementParams.Range.to();
value = params.DecrementParams.Range.to();
emit dataSimulated(mode, type, addr, deviceId, value);
break;

Expand Down Expand Up @@ -208,6 +208,16 @@ void DataSimulator::randomSimulation(DataDisplayMode mode, QModbusDataUnit::Regi
value = generateRandom<quint16>(params.Range.from(), params.Range.to() + 1);
break;

case DataDisplayMode::LongInteger:
case DataDisplayMode::SwappedLI:
value = generateRandom<qint32>(params.Range);
break;

case DataDisplayMode::UnsignedLongInteger:
case DataDisplayMode::SwappedUnsignedLI:
value = generateRandom<quint32>(params.Range);
break;

case DataDisplayMode::FloatingPt:
case DataDisplayMode::SwappedFP:
value = generateRandom<float>(params.Range);
Expand Down Expand Up @@ -258,6 +268,16 @@ void DataSimulator::incrementSimulation(DataDisplayMode mode, QModbusDataUnit::R
value = incrementValue<quint16>(value.toUInt(), params.Step, params.Range);
break;

case DataDisplayMode::LongInteger:
case DataDisplayMode::SwappedLI:
value = incrementValue<qint32>(value.toInt(), params.Step, params.Range);
break;

case DataDisplayMode::UnsignedLongInteger:
case DataDisplayMode::SwappedUnsignedLI:
value = incrementValue<quint32>(value.toUInt(), params.Step, params.Range);
break;

case DataDisplayMode::FloatingPt:
case DataDisplayMode::SwappedFP:
value = incrementValue<float>(value.toFloat(), params.Step, params.Range);
Expand Down Expand Up @@ -304,6 +324,16 @@ void DataSimulator::decrementSimailation(DataDisplayMode mode, QModbusDataUnit::
value = decrementValue<quint16>(value.toUInt(), params.Step, params.Range);
break;

case DataDisplayMode::LongInteger:
case DataDisplayMode::SwappedLI:
value = decrementValue<qint32>(value.toInt(), params.Step, params.Range);
break;

case DataDisplayMode::UnsignedLongInteger:
case DataDisplayMode::SwappedUnsignedLI:
value = decrementValue<quint32>(value.toUInt(), params.Step, params.Range);
break;

case DataDisplayMode::FloatingPt:
case DataDisplayMode::SwappedFP:
value = decrementValue<float>(value.toFloat(), params.Step, params.Range);
Expand Down
17 changes: 17 additions & 0 deletions omodscan/dialogs/dialogautosimulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ DialogAutoSimulation::DialogAutoSimulation(DataDisplayMode mode, ModbusSimulatio
ui->lineEditHighLimit->setInputRange(SHRT_MIN, SHRT_MAX);
break;

case DataDisplayMode::LongInteger:
case DataDisplayMode::SwappedLI:
ui->lineEditStepValue->setInputRange(1, INT_MAX - 1);
ui->lineEditLowLimit->setInputRange(INT_MIN, INT_MAX);
ui->lineEditHighLimit->setInputRange(INT_MIN, INT_MAX);
break;

case DataDisplayMode::UnsignedLongInteger:
case DataDisplayMode::SwappedUnsignedLI:
ui->lineEditStepValue->setInputRange(1U, UINT_MAX - 1);
ui->lineEditStepValue->setInputMode(NumericLineEdit::UnsignedMode);
ui->lineEditLowLimit->setInputRange(0U, UINT_MAX);
ui->lineEditLowLimit->setInputMode(NumericLineEdit::UnsignedMode);
ui->lineEditHighLimit->setInputRange(0U, UINT_MAX);
ui->lineEditHighLimit->setInputMode(NumericLineEdit::UnsignedMode);
break;

case DataDisplayMode::Hex:
ui->lineEditStepValue->setInputRange(1, USHRT_MAX - 1);
ui->lineEditLowLimit->setInputRange(0, USHRT_MAX);
Expand Down
84 changes: 84 additions & 0 deletions omodscan/dialogs/dialogforcemultipleregisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,38 @@ void DialogForceMultipleRegisters::accept()
}
break;

case DataDisplayMode::LongInteger:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
auto numEdit = (NumericLineEdit*)ui->tableWidget->cellWidget(i, j);
breakLong(numEdit->value<qint32>(), _data[idx], _data[idx + 1], _writeParams.Order);
}
break;

case DataDisplayMode::SwappedLI:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
auto numEdit = (NumericLineEdit*)ui->tableWidget->cellWidget(i, j);
breakLong(numEdit->value<qint32>(), _data[idx + 1], _data[idx], _writeParams.Order);
}
break;

case DataDisplayMode::UnsignedLongInteger:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
auto numEdit = (NumericLineEdit*)ui->tableWidget->cellWidget(i, j);
breakULong(numEdit->value<quint32>(), _data[idx], _data[idx + 1], _writeParams.Order);
}
break;

case DataDisplayMode::SwappedUnsignedLI:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
auto numEdit = (NumericLineEdit*)ui->tableWidget->cellWidget(i, j);
breakULong(numEdit->value<quint32>(), _data[idx + 1], _data[idx], _writeParams.Order);
}
break;

case DataDisplayMode::FloatingPt:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
Expand Down Expand Up @@ -136,6 +168,26 @@ void DialogForceMultipleRegisters::on_pushButtonRandom_clicked()
_data[i] = QRandomGenerator::global()->bounded(SHRT_MIN, SHRT_MAX);
break;

case DataDisplayMode::LongInteger:
if(!(i % 2) && (i + 1 < _data.size()))
breakLong(QRandomGenerator::global()->bounded(INT_MIN, INT_MAX), _data[i], _data[i + 1], _writeParams.Order);
break;

case DataDisplayMode::SwappedLI:
if(!(i % 2) && (i + 1 < _data.size()))
breakLong(QRandomGenerator::global()->bounded(INT_MIN, INT_MAX), _data[i + 1], _data[i], _writeParams.Order);
break;

case DataDisplayMode::UnsignedLongInteger:
if(!(i % 2) && (i + 1 < _data.size()))
breakULong(QRandomGenerator::global()->bounded(0U, UINT_MAX), _data[i], _data[i + 1], _writeParams.Order);
break;

case DataDisplayMode::SwappedUnsignedLI:
if(!(i % 2) && (i + 1 < _data.size()))
breakULong(QRandomGenerator::global()->bounded(0U, UINT_MAX), _data[i + 1], _data[i], _writeParams.Order);
break;

case DataDisplayMode::FloatingPt:
if(!(i % 2) && (i + 1 < _data.size()))
breakFloat(QRandomGenerator::global()->bounded(100.), _data[i], _data[i + 1], _writeParams.Order);
Expand Down Expand Up @@ -191,6 +243,38 @@ NumericLineEdit* DialogForceMultipleRegisters::createNumEdit(int idx)
numEdit->setValue((qint16)toByteOrderValue(_data[idx], _writeParams.Order));
break;

case DataDisplayMode::LongInteger:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
numEdit = new NumericLineEdit(NumericLineEdit::DecMode, ui->tableWidget);
numEdit->setValue(makeLong(_data[idx], _data[idx + 1], _writeParams.Order));
}
break;

case DataDisplayMode::SwappedLI:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
numEdit = new NumericLineEdit(NumericLineEdit::DecMode, ui->tableWidget);
numEdit->setValue(makeLong(_data[idx + 1], _data[idx], _writeParams.Order));
}
break;

case DataDisplayMode::UnsignedLongInteger:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
numEdit = new NumericLineEdit(NumericLineEdit::UnsignedMode, ui->tableWidget);
numEdit->setValue(makeULong(_data[idx], _data[idx + 1], _writeParams.Order));
}
break;

case DataDisplayMode::SwappedUnsignedLI:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
numEdit = new NumericLineEdit(NumericLineEdit::UnsignedMode, ui->tableWidget);
numEdit->setValue(makeULong(_data[idx + 1], _data[idx], _writeParams.Order));
}
break;

case DataDisplayMode::FloatingPt:
if(!(idx % 2) && (idx + 1 < _data.size()))
{
Expand Down
12 changes: 12 additions & 0 deletions omodscan/floatutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ inline void breakLong(qint32 value, quint16& lo, quint16& hi, ByteOrder order)
hi = toByteOrderValue(v.asUint16[1], order);
}

///
/// \brief breakULong
/// \param value
/// \param lo
/// \param hi
/// \param order
///
inline void breakULong(quint32 value, quint16& lo, quint16& hi, ByteOrder order)
{
breakLong((qint32)value, lo, hi, order);
}

///
/// \brief breakDouble
/// \param value
Expand Down

0 comments on commit 0ea3274

Please sign in to comment.