From 98fc8fbcb314c5e3068e9e5064230b5b23b9a2cd Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sat, 6 Sep 2014 14:01:43 -0500 Subject: [PATCH] Add math waveform support to scope viewer --- clients/tde/debian/control | 2 +- clients/tde/src/part/scope/Makefile.am | 2 +- clients/tde/src/part/scope/layout.ui | 17 +- clients/tde/src/part/scope/part.cpp | 669 ++++++++++++++++++++++++- clients/tde/src/part/scope/part.h | 87 +++- 5 files changed, 767 insertions(+), 10 deletions(-) diff --git a/clients/tde/debian/control b/clients/tde/debian/control index 8739149..c8edf21 100644 --- a/clients/tde/debian/control +++ b/clients/tde/debian/control @@ -3,7 +3,7 @@ Section: tde Priority: optional Maintainer: Timothy Pearson Standards-Version: 3.8.4 -Build-Depends: debhelper (>= 5.0), cdbs, tdelibs14-trinity-dev, libtqtrla-dev, libtdekrb-trinity-dev, libtdeldap-trinity-dev, xutils, chrpath, gettext, quilt (>= 0.40), automake, autoconf, libtool, libltdl-dev +Build-Depends: debhelper (>= 5.0), cdbs, tdelibs14-trinity-dev, libtqtrla-dev, libtdekrb-trinity-dev, libtdeldap-trinity-dev, libffts-dev, xutils, chrpath, gettext, quilt (>= 0.40), automake, autoconf, libtool, libltdl-dev Homepage: http://ulab.trinitydesktop.org/ Package: remote-laboratory-client-trinity diff --git a/clients/tde/src/part/scope/Makefile.am b/clients/tde/src/part/scope/Makefile.am index 8a3dbb6..52d22c0 100644 --- a/clients/tde/src/part/scope/Makefile.am +++ b/clients/tde/src/part/scope/Makefile.am @@ -7,6 +7,6 @@ KDE_ICON = libremotelab_scope #Part kde_module_LTLIBRARIES = libremotelab_scope.la libremotelab_scope_la_LIBADD = ../../widgets/libtracewidget.la ../../widgets/libfloatspinbox.la $(LIB_KFILE) $(LIB_TDEPARTS) $(LIB_TDEUI) $(LIB_QT) -libremotelab_scope_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -ltdecore -ltdeui -ltdeio -ltdefx -ltdekrbsocket -ltqtrla +libremotelab_scope_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) -ltdecore -ltdeui -ltdeio -ltdefx -ltdekrbsocket -ltqtrla -lffts libremotelab_scope_la_SOURCES = \ part.cpp layout.ui diff --git a/clients/tde/src/part/scope/layout.ui b/clients/tde/src/part/scope/layout.ui index 2a94997..5447780 100644 --- a/clients/tde/src/part/scope/layout.ui +++ b/clients/tde/src/part/scope/layout.ui @@ -115,6 +115,21 @@ + + groupOscilloscopeAnalysisControls + + + Analysis Controls + + + + + mathTraceControlLayoutWidget + + + + + groupOscilloscopeAcquisitionControls @@ -156,7 +171,7 @@ - + groupOscilloscopeTestNotes diff --git a/clients/tde/src/part/scope/part.cpp b/clients/tde/src/part/scope/part.cpp index fed1726..fb056cd 100644 --- a/clients/tde/src/part/scope/part.cpp +++ b/clients/tde/src/part/scope/part.cpp @@ -20,6 +20,8 @@ * http://www.raptorengineeringinc.com */ +#define ENABLE_FFT + #include "define.h" #include "part.h" @@ -48,6 +50,10 @@ #include #include +#ifdef ENABLE_FFT +#include +#endif // ENABLE_FFT + #include "tracewidget.h" #include "floatspinbox.h" #include "layout.h" @@ -183,6 +189,213 @@ void TraceControlWidget::triggerRequested() { emit(triggerChannelChangeRequested()); } +MathTraceControlWidget::MathTraceControlWidget(TQWidget *parent, const char *name) + : TQWidget(parent, name) +{ + TQGridLayout *topGrid = new TQGridLayout(this); + m_groupBox = new TQGroupBox(this); + m_groupBox->setColumnLayout(0, TQt::Vertical); + topGrid->addMultiCellWidget(m_groupBox, 0, 0, 0, 0); + m_groupBox->setTitle(i18n("Unknown Math Channel")); + m_primaryLayout = new TQGridLayout(m_groupBox->layout(), 1, 1, KDialog::spacingHint()); + + m_channelEnabledCheckBox = new TQCheckBox(m_groupBox); + connect(m_channelEnabledCheckBox, SIGNAL(clicked()), this, SLOT(enableClicked())); + m_channelEnabledCheckBox->setText(i18n("Enable")); + m_primaryLayout->addMultiCellWidget(m_channelEnabledCheckBox, 0, 0, 0, 0); + + m_voltsDivComboBox = new TQComboBox(m_groupBox); + connect(m_voltsDivComboBox, SIGNAL(activated(int)), this, SLOT(vdivChanged(int))); + m_primaryLayout->addMultiCellWidget(m_voltsDivComboBox, 0, 0, 1, 1); + + m_verticalUnitsLabel = new TQLabel(m_groupBox); + m_verticalUnitsLabel->setText(i18n("V/div")); + m_primaryLayout->addMultiCellWidget(m_verticalUnitsLabel, 0, 0, 2, 2); + + m_operandFirstComboBox = new TQComboBox(m_groupBox); + connect(m_operandFirstComboBox, SIGNAL(activated(int)), this, SLOT(operandFirstChanged(int))); + m_primaryLayout->addMultiCellWidget(m_operandFirstComboBox, 1, 1, 0, 0); + + m_operandSecondComboBox = new TQComboBox(m_groupBox); + connect(m_operandSecondComboBox, SIGNAL(activated(int)), this, SLOT(operandSecondChanged(int))); + m_primaryLayout->addMultiCellWidget(m_operandSecondComboBox, 1, 1, 2, 2); + + m_operatorComboBox = new TQComboBox(m_groupBox); + connect(m_operatorComboBox, SIGNAL(activated(int)), this, SLOT(operatorChanged(int))); + m_primaryLayout->addMultiCellWidget(m_operatorComboBox, 1, 1, 1, 1); +} + +MathTraceControlWidget::~MathTraceControlWidget() { + // +} + +void MathTraceControlWidget::setVoltsPerDivList(TQDoubleList list) { + m_voltsDivList = list; + + // Update drop down list + double prevValue = m_voltsDivComboBox->currentText().toDouble(); + m_voltsDivComboBox->clear(); + TQDoubleList::iterator it; + int i = 0; + for (it = m_voltsDivList.begin(); it != m_voltsDivList.end(); ++it) { + m_voltsDivComboBox->insertItem(TQString("%1").arg(*it), i); + if (prevValue == (*it)) { + m_voltsDivComboBox->setCurrentItem(i); + } + i++; + } +} + +void MathTraceControlWidget::setSelectedVoltsPerDiv(double vdiv) { + int i = 0; + for (i=0;icount();i++) { + if (m_voltsDivComboBox->text(i).toDouble() == vdiv) { + m_voltsDivComboBox->setCurrentItem(i); + } + } +} + +void MathTraceControlWidget::setFirstMathOperandList(TQInt16List list) { + m_firstMathOperandList = list; + + // Update drop down list + int prevValue = (m_operandFirstComboBox->currentText().replace("Ch", "")).toInt(); + m_operandFirstComboBox->clear(); + TQInt16List::iterator it; + int i = 0; + for (it = m_firstMathOperandList.begin(); it != m_firstMathOperandList.end(); ++it) { + m_operandFirstComboBox->insertItem(TQString("Ch%1").arg(*it), i); + if (prevValue == (*it)) { + m_operandFirstComboBox->setCurrentItem(i); + } + i++; + } +} + +void MathTraceControlWidget::setSelectedFirstMathOperand(int channel) { + int i = 0; + for (i=0;icount();i++) { + if ((m_operandFirstComboBox->text(i).replace("Ch", "")).toInt() == channel) { + m_operandFirstComboBox->setCurrentItem(i); + } + } +} + +void MathTraceControlWidget::setSecondMathOperandList(TQInt16List list) { + m_secondMathOperandList = list; + + // Update drop down list + int prevValue = (m_operandSecondComboBox->currentText().replace("Ch", "")).toInt(); + m_operandSecondComboBox->clear(); + TQInt16List::iterator it; + int i = 0; + for (it = m_secondMathOperandList.begin(); it != m_secondMathOperandList.end(); ++it) { + m_operandSecondComboBox->insertItem(TQString("Ch%1").arg(*it), i); + if (prevValue == (*it)) { + m_operandSecondComboBox->setCurrentItem(i); + } + i++; + } +} + +void MathTraceControlWidget::setSelectedSecondMathOperand(int channel) { + int i = 0; + for (i=0;icount();i++) { + if ((m_operandSecondComboBox->text(i).replace("Ch", "")).toInt() == channel) { + m_operandSecondComboBox->setCurrentItem(i); + } + } +} + +void MathTraceControlWidget::setMathOperatorList(MathOperatorList list) { + m_mathOperatorList = list; + + // Update drop down list + TQString prevValue = m_operatorComboBox->currentText(); + m_operatorComboBox->clear(); + MathOperatorList::iterator it; + int i = 0; + for (it = m_mathOperatorList.begin(); it != m_mathOperatorList.end(); ++it) { + m_operatorComboBox->insertItem((*it).first, i); + if (prevValue == (*it).first) { + m_operatorComboBox->setCurrentItem(i); + } + i++; + } +} + +void MathTraceControlWidget::setSelectedMathOperator(TQString op) { + int i = 0; + for (i=0;icount();i++) { + if (m_operatorComboBox->text(i) == op) { + m_operatorComboBox->setCurrentItem(i); + } + } + + updateMathOperatorOperandVisibility(); +} + +void MathTraceControlWidget::setTraceEnabled(bool enabled) { + m_channelEnabledCheckBox->setChecked(enabled); + m_voltsDivComboBox->setEnabled(enabled); + m_operandFirstComboBox->setEnabled(enabled); + m_operandSecondComboBox->setEnabled(enabled); + m_operatorComboBox->setEnabled(enabled); +} + +void MathTraceControlWidget::setTraceName(TQString name) { + m_groupBox->setTitle(name); +} + +void MathTraceControlWidget::setVerticalUnits(TQString units) { + m_verticalUnitsLabel->setText(i18n("%1/div").arg(units)); +} + +void MathTraceControlWidget::enableClicked() { + bool enabled = m_channelEnabledCheckBox->isOn(); + m_voltsDivComboBox->setEnabled(enabled); + emit(enableChanged(enabled)); +} + +void MathTraceControlWidget::vdivChanged(int index) { + Q_UNUSED(index) + double value = m_voltsDivComboBox->currentText().toDouble(); + emit(voltsPerDivChanged(value)); +} + +void MathTraceControlWidget::operandFirstChanged(int index) { + Q_UNUSED(index) + double value = (m_operandFirstComboBox->currentText().replace("Ch", "")).toInt(); + emit(firstMathOperandChanged(value)); +} + +void MathTraceControlWidget::operandSecondChanged(int index) { + Q_UNUSED(index) + double value = (m_operandSecondComboBox->currentText().replace("Ch", "")).toInt(); + emit(secondMathOperandChanged(value)); +} + +void MathTraceControlWidget::operatorChanged(int index) { + Q_UNUSED(index) + updateMathOperatorOperandVisibility(); + emit(mathOperatorChanged(m_operatorComboBox->currentText())); +} + +void MathTraceControlWidget::updateMathOperatorOperandVisibility() { + TQString value = m_operatorComboBox->currentText(); + MathOperatorList::iterator it; + for (it = m_mathOperatorList.begin(); it != m_mathOperatorList.end(); ++it) { + if (value == (*it).first) { + if ((*it).second < 2) { + m_operandSecondComboBox->hide(); + } + else { + m_operandSecondComboBox->show(); + } + } + } +} + TimebaseControlWidget::TimebaseControlWidget(TQWidget *parent, const char *name) : TQWidget(parent, name) { @@ -261,9 +474,19 @@ ScopePart::ScopePart( TQWidget *parentWidget, const char *widgetName, TQObject * // Initialize data m_hdivs = 0; m_vdivs = 0; + m_maxNumberOfTraces = 0; + m_maxNumberOfMathTraces = 1; + m_availableMathOperators.append(MathOperator("+", 2)); + m_availableMathOperators.append(MathOperator("-", 2)); + m_availableMathOperators.append(MathOperator("*", 2)); + m_availableMathOperators.append(MathOperator("/", 2)); +#ifdef ENABLE_FFT + m_availableMathOperators.append(MathOperator("FFT", 1)); +#endif // ENABLE_FFT for (int traceno=0; traceno<=MAXTRACES; traceno++) { m_samplesInTrace[traceno] = 0; m_channelActive[traceno] = false; + m_traceAllowedVoltsDiv[traceno].clear(); m_voltsDiv[traceno] = 0; m_secsDiv[traceno] = 0; m_traceControlWidgetList[traceno] = NULL; @@ -271,6 +494,19 @@ ScopePart::ScopePart( TQWidget *parentWidget, const char *widgetName, TQObject * m_voltsDivSet[traceno] = false; m_channelActiveSet[traceno] = false; } + for (int traceno=0; traceno<=MAXMATHTRACES; traceno++) { + m_samplesInMathTrace[traceno] = 0; + m_mathChannelActive[traceno] = false; + m_mathTraceAllowedVoltsDiv[traceno].clear(); + m_mathVoltsDiv[traceno] = 0; + m_mathSecsDiv[traceno] = 0; + m_mathFirstOperand[traceno] = 0; + m_mathSecondOperand[traceno] = 0; + m_mathOperator[traceno] = TQString::null; + m_mathHorizontalUnits[traceno] = "s"; + m_mathVerticalUnits[traceno] = "V"; + m_mathTraceControlWidgetList[traceno] = NULL; + } m_triggerLevelSet = false; m_triggerChannelSet = false; m_horizontalTimebaseSet = false; @@ -279,6 +515,7 @@ ScopePart::ScopePart( TQWidget *parentWidget, const char *widgetName, TQObject * // Create widgets m_base = new ScopeBase(widget()); m_traceControlWidgetGrid = new TQGridLayout(m_base->traceControlLayoutWidget); + m_mathTraceControlWidgetGrid = new TQGridLayout(m_base->mathTraceControlLayoutWidget); m_timebaseControlWidgetGrid = new TQGridLayout(m_base->timebaseControlLayoutWidget); m_timebaseControlWidget = new TimebaseControlWidget(m_base->timebaseControlLayoutWidget); connect(m_timebaseControlWidget, SIGNAL(secondsPerDivChanged(double)), this, SLOT(traceControlSDivChanged(double))); @@ -943,10 +1180,9 @@ void ScopePart::mainEventLoop() { TQString result; ds >> result; if (result == "ACK") { - TQDoubleList list; - ds >> list; + ds >> m_traceAllowedVoltsDiv[m_currentOpChannel]; if (m_traceControlWidgetList[m_currentOpChannel-1]) { - m_traceControlWidgetList[m_currentOpChannel-1]->setVoltsPerDivList(list); + m_traceControlWidgetList[m_currentOpChannel-1]->setVoltsPerDivList(m_traceAllowedVoltsDiv[m_currentOpChannel]); } } m_socket->clearFrameTail(); @@ -1324,6 +1560,7 @@ void ScopePart::mainEventLoop() { m_base->traceZoomWidget->setSamples(m_currentOpChannel-1, trace); m_base->traceZoomWidget->setPositions(m_currentOpChannel-1, positions); postProcessTrace(); + processMathTraces(); m_traceWidget->repaint(false); m_base->traceZoomWidget->repaint(false); } @@ -1839,7 +2076,7 @@ void ScopePart::stopDAQ() { } #define WAVEFORM_MAGIC_NUMBER 1 -#define WAVEFORM_FILE_VERSION 2 +#define WAVEFORM_FILE_VERSION 3 void ScopePart::saveWaveforms() { TQString saveFileName = KFileDialog::getSaveFileName(TQString::null, "*.wfm|Waveform Files (*.wfm)", 0, i18n("Save waveforms...")); @@ -1854,17 +2091,28 @@ void ScopePart::saveWaveforms() { ds << m_hdivs; ds << m_vdivs; ds << m_maxNumberOfTraces; + ds << m_maxNumberOfMathTraces; for (int traceno=1; traceno<=m_maxNumberOfTraces; traceno++) { TQ_UINT8 boolValue; boolValue = m_channelActive[traceno]; ds << boolValue; ds << m_samplesInTrace[traceno]; + ds << m_traceAllowedVoltsDiv[traceno]; ds << m_voltsDiv[traceno]; ds << m_secsDiv[traceno]; ds << m_base->traceZoomWidget->traceOffset(traceno-1); ds << m_traceWidget->samples(traceno-1); ds << m_traceWidget->positions(traceno-1); } + for (int traceno=1; traceno<=m_maxNumberOfMathTraces; traceno++) { + TQ_UINT8 boolValue; + boolValue = m_mathChannelActive[traceno]; + ds << boolValue; + ds << m_mathVoltsDiv[traceno]; + ds << m_mathFirstOperand[traceno]; + ds << m_mathSecondOperand[traceno]; + ds << m_mathOperator[traceno]; + } for (int cursorno=0; cursorno<5; cursorno++) { ds << m_traceWidget->cursorPosition(cursorno); } @@ -1887,11 +2135,17 @@ void ScopePart::recallWaveforms() { ds >> m_hdivs; ds >> m_vdivs; ds >> m_maxNumberOfTraces; + if (version >= 3) { + ds >> m_maxNumberOfMathTraces; + } for (int traceno=1; traceno<=m_maxNumberOfTraces; traceno++) { TQ_UINT8 boolValue; ds >> boolValue; m_channelActive[traceno] = (boolValue!=0)?true:false; ds >> m_samplesInTrace[traceno]; + if (version >= 3) { + ds >> m_traceAllowedVoltsDiv[traceno]; + } ds >> m_voltsDiv[traceno]; ds >> m_secsDiv[traceno]; double offset; @@ -1908,6 +2162,17 @@ void ScopePart::recallWaveforms() { m_base->traceZoomWidget->setPositions(traceno-1, positions); m_base->traceZoomWidget->setTraceOffset(traceno-1, offset); } + if (version >= 3) { + for (int traceno=1; traceno<=m_maxNumberOfMathTraces; traceno++) { + TQ_UINT8 boolValue; + ds >> boolValue; + m_mathChannelActive[traceno] = (boolValue!=0)?true:false; + ds >> m_mathVoltsDiv[traceno]; + ds >> m_mathFirstOperand[traceno]; + ds >> m_mathSecondOperand[traceno]; + ds >> m_mathOperator[traceno]; + } + } for (int cursorno=0; cursorno<5; cursorno++) { double cursorPos; ds >> cursorPos; @@ -1925,6 +2190,7 @@ void ScopePart::recallWaveforms() { m_triggerLevel = 0; updateGraticule(); postProcessTrace(); + processMathTraces(); m_traceWidget->repaint(false); m_base->traceZoomWidget->repaint(false); updateTraceControlWidgets(); @@ -1940,7 +2206,7 @@ void ScopePart::recallWaveforms() { } void ScopePart::updateZoomWidgetLimits(const TQRectF& zoomRect) { - for (int traceno=0; tracenodisplayLimits(traceno); double widthSpan = fullZoomRect.width()-fullZoomRect.x(); double heightSpan = fullZoomRect.height()-fullZoomRect.y(); @@ -2009,6 +2275,7 @@ void ScopePart::updateGraticule() { if (m_maxNumberOfTraces > 2) m_base->traceZoomWidget->setTraceColor(2, TQColor(255, 255, 128)); if (m_maxNumberOfTraces > 3) m_base->traceZoomWidget->setTraceColor(3, TQColor(128, 128, 255)); + TQInt16List activeChannels; for (int traceno=1; traceno<=m_maxNumberOfTraces; traceno++) { m_traceWidget->setTraceEnabled(traceno-1, m_channelActive[traceno], TraceWidget::FullText, true); m_traceWidget->setTraceName(traceno-1, TQString("Channel %1").arg(traceno), true); @@ -2025,9 +2292,44 @@ void ScopePart::updateGraticule() { m_traceWidget->setDisplayLimits(traceno-1, TQRectF(0.0, (m_voltsDiv[traceno]*m_vdivs)/2.0, (m_secsDiv[traceno]*m_hdivs), (m_voltsDiv[traceno]*m_vdivs)/-2.0), (tracenosetVoltsPerDivList(m_traceAllowedVoltsDiv[traceno]); m_traceControlWidgetList[traceno-1]->setSelectedVoltsPerDiv(m_voltsDiv[traceno]); m_traceControlWidgetList[traceno-1]->setTraceEnabled(m_channelActive[traceno]); } + + if (m_channelActive[traceno]) { + activeChannels.append(traceno); + } + } + for (int traceno=1; traceno<=m_maxNumberOfMathTraces; traceno++) { + updateMathTraceAllowedVoltsPerDivList(traceno); + + m_traceWidget->setTraceEnabled(traceno-1+m_maxNumberOfTraces, m_mathChannelActive[traceno], TraceWidget::FullText, true); + m_traceWidget->setTraceName(traceno-1+m_maxNumberOfTraces, TQString("Math %1").arg(traceno), true); + m_traceWidget->setTraceHorizontalUnits(traceno-1+m_maxNumberOfTraces, m_mathHorizontalUnits[traceno], true); + m_traceWidget->setTraceVerticalUnits(traceno-1+m_maxNumberOfTraces, m_mathVerticalUnits[traceno], true); + + m_base->traceZoomWidget->setTraceEnabled(traceno-1+m_maxNumberOfTraces, m_mathChannelActive[traceno], TraceWidget::SummaryText, true); + m_base->traceZoomWidget->setTraceName(traceno-1+m_maxNumberOfTraces, TQString("Math %1").arg(traceno), true); + m_base->traceZoomWidget->setTraceHorizontalUnits(traceno-1+m_maxNumberOfTraces, m_mathHorizontalUnits[traceno], true); + m_base->traceZoomWidget->setTraceVerticalUnits(traceno-1+m_maxNumberOfTraces, m_mathVerticalUnits[traceno], true); + + m_traceWidget->setNumberOfSamples(traceno-1+m_maxNumberOfTraces, m_samplesInMathTrace[traceno], true); + m_base->traceZoomWidget->setNumberOfSamples(traceno-1+m_maxNumberOfTraces, m_samplesInMathTrace[traceno], (tracenosetDisplayLimits(traceno-1+m_maxNumberOfTraces, TQRectF(0.0, (m_mathVoltsDiv[traceno]*m_vdivs)/2.0, (m_mathSecsDiv[traceno]*m_hdivs), (m_mathVoltsDiv[traceno]*m_vdivs)/-2.0), (tracenosetVerticalUnits(m_mathVerticalUnits[traceno]); + m_mathTraceControlWidgetList[traceno-1]->setVoltsPerDivList(m_mathTraceAllowedVoltsDiv[traceno]); + m_mathTraceControlWidgetList[traceno-1]->setSelectedVoltsPerDiv(m_mathVoltsDiv[traceno]); + m_mathTraceControlWidgetList[traceno-1]->setTraceEnabled(m_mathChannelActive[traceno]); + m_mathTraceControlWidgetList[traceno-1]->setFirstMathOperandList(activeChannels); + m_mathTraceControlWidgetList[traceno-1]->setSecondMathOperandList(activeChannels); + m_mathTraceControlWidgetList[traceno-1]->setMathOperatorList(m_availableMathOperators); + m_mathTraceControlWidgetList[traceno-1]->setSelectedFirstMathOperand(m_mathFirstOperand[traceno]); + m_mathTraceControlWidgetList[traceno-1]->setSelectedSecondMathOperand(m_mathSecondOperand[traceno]); + m_mathTraceControlWidgetList[traceno-1]->setSelectedMathOperator(m_mathOperator[traceno]); + } } updateZoomWidgetLimits(m_traceWidget->zoomBox()); } @@ -2052,6 +2354,25 @@ void ScopePart::updateTraceControlWidgets() { delete m_traceControlWidgetList[i]; } } + for (i=0; imathTraceControlLayoutWidget); + connect(m_mathTraceControlWidgetList[i], SIGNAL(enableChanged(bool)), this, SLOT(mathTraceControlEnableChanged(bool))); + connect(m_mathTraceControlWidgetList[i], SIGNAL(voltsPerDivChanged(double)), this, SLOT(mathTraceControlVDivChanged(double))); + connect(m_mathTraceControlWidgetList[i], SIGNAL(firstMathOperandChanged(int)), this, SLOT(mathTraceControlFirstOperandChanged(int))); + connect(m_mathTraceControlWidgetList[i], SIGNAL(secondMathOperandChanged(int)), this, SLOT(mathTraceControlSecondOperandChanged(int))); + connect(m_mathTraceControlWidgetList[i], SIGNAL(mathOperatorChanged(TQString)), this, SLOT(mathTraceControlOperatorChanged(TQString))); + m_mathTraceControlWidgetGrid->addMultiCellWidget(m_mathTraceControlWidgetList[i], i+m_maxNumberOfTraces, i+m_maxNumberOfTraces, 0, 0); + m_mathTraceControlWidgetList[i]->setTraceName(i18n("Math %1").arg(i+1)); + m_mathTraceControlWidgetList[i]->show(); + } + } + for (i=m_maxNumberOfMathTraces; iremove(m_mathTraceControlWidgetList[i]); + delete m_mathTraceControlWidgetList[i]; + } + } } void ScopePart::traceControlEnableChanged(bool enabled) { @@ -2105,6 +2426,344 @@ void ScopePart::traceControlSDivChanged(double sdiv) { m_horizontalTimebaseSet = true; } +void ScopePart::mathTraceControlEnableChanged(bool enabled) { + int i; + int channel = -1; + const MathTraceControlWidget* widget = dynamic_cast(sender()); + if (widget) { + for (i=0; i= 0) && (channel <=MAXMATHTRACES)) { + m_mathChannelActive[channel+1] = enabled; + } + } + + updateGraticule(); + m_traceWidget->repaint(false); + m_base->traceZoomWidget->repaint(false); + updateTraceControlWidgets(); + processMathTraces(); +} + +void ScopePart::mathTraceControlVDivChanged(double vdiv) { + int i; + int channel = -1; + const MathTraceControlWidget* widget = dynamic_cast(sender()); + if (widget) { + for (i=0; i= 0) && (channel <=MAXMATHTRACES)) { + m_mathVoltsDiv[channel+1] = vdiv; + } + } + + updateGraticule(); + m_traceWidget->repaint(false); + m_base->traceZoomWidget->repaint(false); + updateTraceControlWidgets(); +} + +void ScopePart::mathTraceControlFirstOperandChanged(int operand) { + int i; + int channel = -1; + const MathTraceControlWidget* widget = dynamic_cast(sender()); + if (widget) { + for (i=0; i= 0) && (channel <=MAXMATHTRACES)) { + m_mathFirstOperand[channel+1] = operand; + } + } + + updateGraticule(); + m_traceWidget->repaint(false); + m_base->traceZoomWidget->repaint(false); + updateTraceControlWidgets(); + processMathTraces(); +} + +void ScopePart::mathTraceControlSecondOperandChanged(int operand) { + int i; + int channel = -1; + const MathTraceControlWidget* widget = dynamic_cast(sender()); + if (widget) { + for (i=0; i= 0) && (channel <=MAXMATHTRACES)) { + m_mathSecondOperand[channel+1] = operand; + } + } + + updateGraticule(); + m_traceWidget->repaint(false); + m_base->traceZoomWidget->repaint(false); + updateTraceControlWidgets(); + processMathTraces(); +} + +void ScopePart::mathTraceControlOperatorChanged(TQString op) { + int i; + int channel = -1; + const MathTraceControlWidget* widget = dynamic_cast(sender()); + if (widget) { + for (i=0; i= 0) && (channel <=MAXMATHTRACES)) { + m_mathOperator[channel+1] = op; + } + } + + updateGraticule(); + m_traceWidget->repaint(false); + m_base->traceZoomWidget->repaint(false); + updateTraceControlWidgets(); + processMathTraces(); +} + +void ScopePart::updateMathTraceAllowedVoltsPerDivList(int traceno) { + if (m_mathFirstOperand[traceno] < 1) { + m_mathFirstOperand[traceno] = 1; + } + if (m_mathSecondOperand[traceno] < 1) { + m_mathSecondOperand[traceno] = 1; + } + if (m_mathFirstOperand[traceno] > MAXTRACES) { + m_mathFirstOperand[traceno] = MAXTRACES; + } + if (m_mathSecondOperand[traceno] > MAXTRACES) { + m_mathSecondOperand[traceno] = MAXTRACES; + } + if (m_mathOperator[traceno] == "") { + m_mathOperator[traceno] = "+"; + } + int firstOperandChannel = m_mathFirstOperand[traceno]; + int secondOperandChannel = m_mathSecondOperand[traceno]; + if ((m_mathOperator[traceno] == "+") + || (m_mathOperator[traceno] == "-") + || (m_mathOperator[traceno] == "*") + || (m_mathOperator[traceno] == "/")) { + // Compute intersection of both trace operand volt/div lists + m_mathTraceAllowedVoltsDiv[traceno].clear(); + TQDoubleList::iterator it; + for (it = m_traceAllowedVoltsDiv[firstOperandChannel].begin(); it != m_traceAllowedVoltsDiv[firstOperandChannel].end(); ++it) { + m_mathTraceAllowedVoltsDiv[traceno].append(*it); + } + for (it = m_traceAllowedVoltsDiv[secondOperandChannel].begin(); it != m_traceAllowedVoltsDiv[secondOperandChannel].end(); ++it) { + if (!m_mathTraceAllowedVoltsDiv[traceno].contains(*it)) { + m_mathTraceAllowedVoltsDiv[traceno].append(*it); + } + } + for (int i=1; i<=m_maxNumberOfTraces; i++) { + int vdiv = m_voltsDiv[i]; + if (!m_mathTraceAllowedVoltsDiv[traceno].contains(vdiv)) { + m_mathTraceAllowedVoltsDiv[traceno].append(vdiv); + } + } + qHeapSort(m_mathTraceAllowedVoltsDiv[traceno]); + + // Reset GUI if not set (e.g. after startup) + if ((m_mathVoltsDiv[traceno] == 0) && (m_mathTraceAllowedVoltsDiv[traceno].count() > 0)) { + m_mathVoltsDiv[traceno] = m_mathTraceAllowedVoltsDiv[traceno][0]; + } + + int firstTraceLength = m_samplesInTrace[m_mathFirstOperand[traceno]]; + m_samplesInMathTrace[traceno] = firstTraceLength; + m_mathSecsDiv[traceno] = m_secsDiv[traceno]; + + m_mathHorizontalUnits[traceno] = "s"; + m_mathVerticalUnits[traceno] = "V"; + } +#ifdef ENABLE_FFT + else if (m_mathOperator[traceno] == "FFT") { + int firstTraceLength = m_samplesInTrace[m_mathFirstOperand[traceno]]; + m_samplesInMathTrace[traceno] = firstTraceLength; + + // Calculate horizontal steps per division + // Full scale needs to be the sampling rate + TQDoubleArray inputPositions = m_traceWidget->positions(m_mathFirstOperand[traceno]-1); + double fs = 1.0 / (inputPositions[1] - inputPositions[0]); + fs = fs / 2.0; // Truncate waveform at the Nyquist frequency + m_mathSecsDiv[traceno] = fs/m_hdivs; + + // Add several dB/div settings + m_mathTraceAllowedVoltsDiv[traceno].clear(); + m_mathTraceAllowedVoltsDiv[traceno].append(0.1); + m_mathTraceAllowedVoltsDiv[traceno].append(1); + m_mathTraceAllowedVoltsDiv[traceno].append(10); + m_mathTraceAllowedVoltsDiv[traceno].append(100); + m_mathTraceAllowedVoltsDiv[traceno].append(1000); + qHeapSort(m_mathTraceAllowedVoltsDiv[traceno]); + + m_mathHorizontalUnits[traceno] = "Hz"; + m_mathVerticalUnits[traceno] = "dB"; + + // Get next highest power of 2 for the FFT algorithm + int fftLength = powf(2, ceilf(log2f(firstTraceLength))); + m_samplesInMathTrace[traceno] = fftLength; + } +#endif // ENABLE_FFT + else { + m_mathTraceAllowedVoltsDiv[traceno].clear(); + } +} + +void ScopePart::processMathTraces() { + for (int traceno=1; traceno<=m_maxNumberOfMathTraces; traceno++) { + if ((m_mathOperator[traceno] == "+") + || (m_mathOperator[traceno] == "-") + || (m_mathOperator[traceno] == "*") + || (m_mathOperator[traceno] == "/")) { + TQDoubleArray outputValues; + TQDoubleArray outputPositions; + TQDoubleArray firstValues = m_traceWidget->samples(m_mathFirstOperand[traceno]-1); + TQDoubleArray firstPositions = m_traceWidget->positions(m_mathFirstOperand[traceno]-1); + TQDoubleArray secondValues = m_traceWidget->samples(m_mathSecondOperand[traceno]-1); + TQDoubleArray secondPositions = m_traceWidget->positions(m_mathSecondOperand[traceno]-1); + outputValues.resize(m_samplesInMathTrace[traceno]); + outputPositions = firstPositions; + + if (m_mathOperator[traceno] == "+") { + for (int i=0; i < m_samplesInMathTrace[traceno]; i++) { + outputValues[i] = firstValues[i] + secondValues[i]; + } + } + else if (m_mathOperator[traceno] == "-") { + for (int i=0; i < m_samplesInMathTrace[traceno]; i++) { + outputValues[i] = firstValues[i] - secondValues[i]; + } + } + else if (m_mathOperator[traceno] == "*") { + for (int i=0; i < m_samplesInMathTrace[traceno]; i++) { + outputValues[i] = firstValues[i] * secondValues[i]; + } + } + else if (m_mathOperator[traceno] == "/") { + for (int i=0; i < m_samplesInMathTrace[traceno]; i++) { + if (secondValues[i] == 0) { + secondValues[i] = 1e-12; + } + outputValues[i] = firstValues[i] / secondValues[i]; + } + } + else { + for (int i=0; i < m_samplesInMathTrace[traceno]; i++) { + outputValues[i] = 0; + } + } + + m_traceWidget->setSamples(m_maxNumberOfTraces-1+m_currentOpChannel, outputValues); + m_traceWidget->setPositions(m_maxNumberOfTraces-1+m_currentOpChannel, outputPositions); + m_base->traceZoomWidget->setSamples(m_maxNumberOfTraces-1+m_currentOpChannel, outputValues); + m_base->traceZoomWidget->setPositions(m_maxNumberOfTraces-1+m_currentOpChannel, outputPositions); + } +#ifdef ENABLE_FFT + else if (m_mathOperator[traceno] == "FFT") { + TQDoubleArray outputValues; + TQDoubleArray outputPositions; + TQDoubleArray inputValues = m_traceWidget->samples(m_mathFirstOperand[traceno]-1); + TQDoubleArray inputPositions = m_traceWidget->positions(m_mathFirstOperand[traceno]-1); + int inputLength = m_samplesInTrace[m_mathFirstOperand[traceno]]; + int fftLength = m_samplesInMathTrace[traceno]; + + // Resize arrays + inputValues.resize(fftLength); + outputValues.resize(fftLength); + outputPositions.resize(fftLength); + + // Generate output positions + // The FFT starts at 0Hz and goes up in Fs/N steps + double pos = 0; + double fs = 1.0 / (inputPositions[1] - inputPositions[0]); + double step = fs / fftLength; + for (int i=0; isetSamples(m_maxNumberOfTraces-1+m_currentOpChannel, outputValues); + m_traceWidget->setPositions(m_maxNumberOfTraces-1+m_currentOpChannel, outputPositions); + m_base->traceZoomWidget->setSamples(m_maxNumberOfTraces-1+m_currentOpChannel, outputValues); + m_base->traceZoomWidget->setPositions(m_maxNumberOfTraces-1+m_currentOpChannel, outputPositions); + } +#endif // ENABLE_FFT + else { + TQDoubleArray outputValues; + TQDoubleArray outputPositions; + + for (int i=0; i < m_samplesInMathTrace[traceno]; i++) { + outputValues[i] = 0; + } + + m_traceWidget->setSamples(m_maxNumberOfTraces-1+m_currentOpChannel, outputValues); + m_traceWidget->setPositions(m_maxNumberOfTraces-1+m_currentOpChannel, outputPositions); + m_base->traceZoomWidget->setSamples(m_maxNumberOfTraces-1+m_currentOpChannel, outputValues); + m_base->traceZoomWidget->setPositions(m_maxNumberOfTraces-1+m_currentOpChannel, outputPositions); + } + } +} + void ScopePart::cursorLevelChanged(uint cursor, double level) { if (cursor == 0) { // Trigger level changed diff --git a/clients/tde/src/part/scope/part.h b/clients/tde/src/part/scope/part.h index db6fb7d..18d2e75 100644 --- a/clients/tde/src/part/scope/part.h +++ b/clients/tde/src/part/scope/part.h @@ -30,7 +30,8 @@ #include -#define MAXTRACES 255 +#define MAXTRACES 255 +#define MAXMATHTRACES 255 class TDEAboutData; using KParts::StatusBarExtension; @@ -39,12 +40,16 @@ class TQSocket; class TQTimer; class TQMutex; class TQRectF; +class TQLabel; class TQGridLayout; class TQCheckBox; class TQGroupBox; class TQPushButton; class ScopeBase; +typedef TQPair MathOperator; +typedef TQValueList MathOperatorList; + namespace RemoteLab { class TraceControlWidget : public TQWidget @@ -82,6 +87,60 @@ namespace RemoteLab TQDoubleList m_voltsDivList; }; + class MathTraceControlWidget : public TQWidget + { + Q_OBJECT + + public: + MathTraceControlWidget(TQWidget *parent=0, const char *name=0); + ~MathTraceControlWidget(); + + public: + void setVoltsPerDivList(TQDoubleList list); + void setFirstMathOperandList(TQInt16List list); + void setSecondMathOperandList(TQInt16List list); + void setMathOperatorList(MathOperatorList list); + void setSelectedVoltsPerDiv(double vdiv); + void setSelectedFirstMathOperand(int channel); + void setSelectedSecondMathOperand(int channel); + void setSelectedMathOperator(TQString op); + void setTraceEnabled(bool enabled); + void setTraceName(TQString name); + void setVerticalUnits(TQString units); + + signals: + void enableChanged(bool enabled); + void voltsPerDivChanged(double vdiv); + void firstMathOperandChanged(int channel); + void secondMathOperandChanged(int channel); + void mathOperatorChanged(TQString op); + + private slots: + void enableClicked(); + void vdivChanged(int index); + void operandFirstChanged(int index); + void operandSecondChanged(int index); + void operatorChanged(int index); + + private: + void updateMathOperatorOperandVisibility(); + + private: + TQGroupBox* m_groupBox; + TQGridLayout* m_primaryLayout; + TQComboBox* m_voltsDivComboBox; + TQCheckBox* m_channelEnabledCheckBox; + TQComboBox* m_operandFirstComboBox; + TQComboBox* m_operandSecondComboBox; + TQComboBox* m_operatorComboBox; + TQLabel* m_verticalUnitsLabel; + + TQDoubleList m_voltsDivList; + TQInt16List m_firstMathOperandList; + TQInt16List m_secondMathOperandList; + MathOperatorList m_mathOperatorList; + }; + class TimebaseControlWidget : public TQWidget { Q_OBJECT @@ -139,17 +198,27 @@ namespace RemoteLab void traceControlEnableChanged(bool enabled); void traceControlVDivChanged(double vdiv); void traceControlSDivChanged(double sdiv); + void mathTraceControlEnableChanged(bool enabled); + void mathTraceControlVDivChanged(double vdiv); + void mathTraceControlFirstOperandChanged(int operand); + void mathTraceControlSecondOperandChanged(int operand); + void mathTraceControlOperatorChanged(TQString op); void cursorLevelChanged(uint cursor, double level); void processTriggerButtons(); void startScope(); void stopScope(); void saveWaveforms(); void recallWaveforms(); + virtual void processMathTraces(); virtual void postProcessTrace(); + private: + void updateMathTraceAllowedVoltsPerDivList(int traceno); + private: TraceWidget* m_traceWidget; TQGridLayout* m_traceControlWidgetGrid; + TQGridLayout* m_mathTraceControlWidgetGrid; TQGridLayout* m_timebaseControlWidgetGrid; int m_commHandlerState; int m_commHandlerMode; @@ -159,6 +228,7 @@ namespace RemoteLab bool m_connectionActiveAndValid; unsigned char m_tickerState; TQ_INT16 m_maxNumberOfTraces; + TQ_INT16 m_maxNumberOfMathTraces; TQ_INT32 m_currentOpChannel; TQ_INT32 m_nextOpChannel; TQ_INT16 m_nextOpParameter16; @@ -169,10 +239,22 @@ namespace RemoteLab double m_triggerLevel; double m_horizontalTimebase; TQ_INT32 m_samplesInTrace[MAXTRACES+1]; + TQ_INT32 m_samplesInMathTrace[MAXMATHTRACES+1]; bool m_channelActive[MAXTRACES+1]; + bool m_mathChannelActive[MAXMATHTRACES+1]; + TQDoubleList m_traceAllowedVoltsDiv[MAXTRACES+1]; + TQDoubleList m_mathTraceAllowedVoltsDiv[MAXTRACES+1]; double m_voltsDiv[MAXTRACES+1]; + double m_mathVoltsDiv[MAXMATHTRACES+1]; double m_secsDiv[MAXTRACES+1]; - TraceControlWidget* m_traceControlWidgetList[MAXTRACES]; + double m_mathSecsDiv[MAXMATHTRACES+1]; + TQ_INT16 m_mathFirstOperand[MAXMATHTRACES+1]; + TQ_INT16 m_mathSecondOperand[MAXMATHTRACES+1]; + TQString m_mathOperator[MAXMATHTRACES+1]; + TQString m_mathHorizontalUnits[MAXMATHTRACES+1]; + TQString m_mathVerticalUnits[MAXMATHTRACES+1]; + TraceControlWidget* m_traceControlWidgetList[MAXTRACES+1]; + MathTraceControlWidget* m_mathTraceControlWidgetList[MAXMATHTRACES+1]; TimebaseControlWidget* m_timebaseControlWidget; bool m_triggerLevelSet; bool m_triggerChannelSet; @@ -181,6 +263,7 @@ namespace RemoteLab bool m_voltsDivSet[MAXTRACES+1]; bool m_channelActiveSet[MAXTRACES+1]; bool m_settingsChanged; + MathOperatorList m_availableMathOperators; ScopeBase* m_base; TQMutex* m_instrumentMutex; bool stopTraceUpdate;