Skip to content

Commit bb112ac

Browse files
committed
m2k: signal generator infinite loop bug fix
Signed-off-by: IonutMuthi <ionut.muthi@analog.com>
1 parent 45c51b1 commit bb112ac

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

plugins/m2k/src/old/signal_generator.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ SignalGenerator::SignalGenerator(libm2k::context::M2k *m2k, QString uri, Filter
229229
fileAmplitude = new ScaleSpinButton({{tr("μVolts"), 1e-6}, {tr("mVolts"), 1e-3}, {tr("Volts"), 1e0}},
230230
tr("Amplitude"), 0.000001, 10, true, true, this);
231231

232-
mathSampleRate = new ScaleSpinButton({{"msps", 1e-3}, {"sps", 1e0}, {"ksps", 1e3}, {"Msps", 1e6}},
233-
tr("SampleRate"), 0.001, 75000000.0, true, false, this);
232+
mathSampleRate = new ScaleSpinButton({{"sps", 1e0}, {"ksps", 1e3}, {"Msps", 1e6}}, tr("SampleRate"), 0.001,
233+
75000000.0, true, false, this);
234234

235235
mathSampleRate->setIntegerDivider(75000000);
236236

@@ -553,6 +553,19 @@ void SignalGenerator::readPreferences()
553553
ui->instrumentNotes->setVisible(p->get("m2k_instrument_notes_active").toBool());
554554
}
555555

556+
void SignalGenerator::checkRunEnabled()
557+
{
558+
size_t size = (size_t)mathSampleRate->value() * mathRecordLength->value();
559+
if(size <= 0) {
560+
ui->run_button->setEnabled(false);
561+
if(m_running) {
562+
stop();
563+
}
564+
} else {
565+
ui->run_button->setEnabled(true);
566+
}
567+
}
568+
556569
void SignalGenerator::resetZoom()
557570
{
558571

@@ -781,6 +794,8 @@ void SignalGenerator::mathRecordLengthChanged(double value)
781794
ptr->math_record_length = value;
782795
resetZoom();
783796
}
797+
798+
checkRunEnabled();
784799
}
785800

786801
void SignalGenerator::mathSampleRateChanged(double value)
@@ -790,6 +805,8 @@ void SignalGenerator::mathSampleRateChanged(double value)
790805
ptr->math_sr = value;
791806
resetZoom();
792807
}
808+
809+
checkRunEnabled();
793810
}
794811

795812
void SignalGenerator::noiseTypeChanged(int index)
@@ -1000,6 +1017,11 @@ void SignalGenerator::tabChanged(int index)
10001017
if(ptr->type == SIGNAL_TYPE_BUFFER) {
10011018
loadFileCurrentChannelData();
10021019
}
1020+
if(ptr->type == SIGNAL_TYPE_MATH) {
1021+
checkRunEnabled();
1022+
} else {
1023+
ui->run_button->setEnabled(true);
1024+
}
10031025
resizeTabWidget(index); // causes small glitch on windows, to be investigated
10041026
resetZoom();
10051027
}
@@ -2272,6 +2294,12 @@ size_t SignalGenerator::get_samples_count(unsigned int chnIdx, double rate, bool
22722294
}
22732295

22742296
out_cleanup:
2297+
2298+
// for size 0 return 0 going further with this value will get stuck in an infinite loop
2299+
if(size == 0) {
2300+
return 0;
2301+
}
2302+
22752303
/* The buffer size must be a multiple of 4 */
22762304
if(ptr->type == SIGNAL_TYPE_BUFFER) {
22772305
size = size + size % 0x04;

plugins/m2k/src/old/signal_generator.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ private Q_SLOTS:
286286
void startStop(bool start);
287287
void setFunction(const QString &function);
288288
void readPreferences() override;
289+
void checkRunEnabled();
289290
Q_SIGNALS:
290291
void showTool();
291292
};

0 commit comments

Comments
 (0)