diff --git a/clients/tde/src/part/scope/part.cpp b/clients/tde/src/part/scope/part.cpp index 04fdb55..d6dda20 100644 --- a/clients/tde/src/part/scope/part.cpp +++ b/clients/tde/src/part/scope/part.cpp @@ -37,6 +37,22 @@ struct exit_exception { exit_exception(int c):c(c) { } }; +enum connectionStates { + ScopeState_InitialRequest = 0, + ScopeState_ResetRequest = 2, + ScopeState_HorizontalDivCountRequest = 4, + ScopeState_VerticalDivCountRequest = 6, + ScopeState_ChannelCountRequest = 8, + ScopeState_ChannelActiveStateRequest = 10, + ScopeState_TraceSampleCountRequest = 12, + ScopeState_TraceVoltsDivRequest = 14, + ScopeState_TraceSecondsDivRequest = 16, + ScopeState_TriggerChannelRequest = 18, + ScopeState_TriggerLevelRequest = 20, + ScopeState_TraceRequest = 50, + ScopeState_ExternalCommandRequest = 255 +}; + namespace RemoteLab { typedef KParts::GenericFactory Factory; @@ -78,23 +94,38 @@ ScopePart::ScopePart( TQWidget *parentWidget, const char *widgetName, TQObject * m_base = new ScopeBase(widget()); m_traceWidget = m_base->traceWidget; m_traceWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding)); - m_traceWidget->setNumberOfCursors(4); + m_traceWidget->setNumberOfCursors(5); + m_traceWidget->setZoomCursorStartIndex(1); + m_traceWidget->setCursorColor(0, TQColor(64, 255, 255)); + m_traceWidget->setCursorHighlightColor(0, TQColor(192, 255, 255)); m_traceWidget->setCursorOrientation(0, TQt::Horizontal); m_traceWidget->setCursorOrientation(1, TQt::Horizontal); - m_traceWidget->setCursorOrientation(2, TQt::Vertical); + m_traceWidget->setCursorOrientation(2, TQt::Horizontal); m_traceWidget->setCursorOrientation(3, TQt::Vertical); + m_traceWidget->setCursorOrientation(4, TQt::Vertical); m_traceWidget->setCursorEnabled(0, true); m_traceWidget->setCursorEnabled(1, true); m_traceWidget->setCursorEnabled(2, true); m_traceWidget->setCursorEnabled(3, true); - m_traceWidget->setCursorName(0, "Cursor H1"); - m_traceWidget->setCursorName(1, "Cursor H2"); - m_traceWidget->setCursorName(2, "Cursor V1"); - m_traceWidget->setCursorName(3, "Cursor V2"); - m_traceWidget->setCursorPosition(0, 25); - m_traceWidget->setCursorPosition(1, 75); - m_traceWidget->setCursorPosition(2, 25); - m_traceWidget->setCursorPosition(3, 75); + m_traceWidget->setCursorEnabled(4, true); + m_traceWidget->setCursorName(0, "Trigger"); + m_traceWidget->setCursorName(1, "Cursor H1"); + m_traceWidget->setCursorName(2, "Cursor H2"); + m_traceWidget->setCursorName(3, "Cursor V1"); + m_traceWidget->setCursorName(4, "Cursor V2"); + m_traceWidget->setCursorPosition(0, 40); + m_traceWidget->setCursorPosition(1, 25); + m_traceWidget->setCursorPosition(2, 75); + m_traceWidget->setCursorPosition(3, 25); + m_traceWidget->setCursorPosition(4, 75); + TraceNumberList activeTraces; + for (uint trace=0; tracesetCursorActiveTraceList(1, activeTraces); + m_traceWidget->setCursorActiveTraceList(2, activeTraces); + m_traceWidget->setCursorActiveTraceList(3, activeTraces); + m_traceWidget->setCursorActiveTraceList(4, activeTraces); m_traceWidget->setZoomBoxEnabled(true); m_base->traceZoomWidget->setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding)); @@ -231,7 +262,7 @@ void ScopePart::setTickerMessage(TQString message) { #define UPDATEDISPLAY_TIMEOUT m_connectionActiveAndValid = false; \ m_tickerState = 0; \ - m_commHandlerState = 2; \ + m_commHandlerState = ScopeState_ResetRequest; \ m_commHandlerMode = 0; \ m_socket->clearIncomingData(); \ setStatusMessage(i18n("Server ping timeout. Please verify the status of your network connection.")); \ @@ -241,7 +272,7 @@ void ScopePart::setTickerMessage(TQString message) { #define COMMUNICATIONS_FAILED m_connectionActiveAndValid = false; \ m_tickerState = 0; \ - m_commHandlerState = 2; \ + m_commHandlerState = ScopeState_ResetRequest; \ m_commHandlerMode = 0; \ m_socket->clearIncomingData(); \ setStatusMessage(i18n("Instrument communication failure. Please verify the status of your network connection.")); \ @@ -250,17 +281,13 @@ void ScopePart::setTickerMessage(TQString message) { return; #define SET_WATCHDOG_TIMER if (!m_updateTimeoutTimer->isActive()) m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); -#define PAT_WATCHDOG_TIMER m_updateTimeoutTimer->stop(); m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); \ - setTickerMessage(i18n("Connected")); +#define PAT_WATCHDOG_TIMER m_updateTimeoutTimer->stop(); m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); #define SET_NEXT_STATE(x) if (m_commHandlerMode == 0) { \ m_commHandlerState = x; \ } \ else { \ - m_commHandlerState = 255; \ - } \ - if (m_commHandlerState < 50) { \ - setTickerMessage(i18n("Loading")); \ + m_commHandlerState = ScopeState_ExternalCommandRequest; \ } #define EXEC_NEXT_STATE_IMMEDIATELY m_forcedUpdateTimer->start(0, TRUE); @@ -287,18 +314,19 @@ void ScopePart::mainEventLoop() { if (m_socket) { if ((m_commHandlerMode == 0) || (m_commHandlerMode == 1)) { - if (m_commHandlerState == 0) { + if (m_commHandlerState == ScopeState_InitialRequest) { // Request scope access ds << TQString("OSCILLOSCOPE"); m_socket->writeEndOfFrame(); - m_commHandlerState = 1; + m_commHandlerState = ScopeState_InitialRequest+1; EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 1) { + else if (m_commHandlerState == ScopeState_InitialRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Connected")); // Get command status TQString result; @@ -306,7 +334,7 @@ void ScopePart::mainEventLoop() { m_socket->clearFrameTail(); if (result == "ACK") { - SET_NEXT_STATE(2) + SET_NEXT_STATE(ScopeState_ResetRequest) EXEC_NEXT_STATE_IMMEDIATELY } else { @@ -319,18 +347,19 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 2) { + else if (m_commHandlerState == ScopeState_ResetRequest) { // Reset scope ds << TQString("RESET"); m_socket->writeEndOfFrame(); - SET_NEXT_STATE(3) + SET_NEXT_STATE(ScopeState_ResetRequest+1) EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 3) { + else if (m_commHandlerState == ScopeState_ResetRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Reset complete]")); // Get command status TQString result; @@ -338,7 +367,7 @@ void ScopePart::mainEventLoop() { m_socket->clearFrameTail(); if (result == "ACK") { - SET_NEXT_STATE(4) + SET_NEXT_STATE(ScopeState_HorizontalDivCountRequest) EXEC_NEXT_STATE_IMMEDIATELY } else { @@ -351,18 +380,19 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 4) { + else if (m_commHandlerState == ScopeState_HorizontalDivCountRequest) { // Get number of horizontal divisions, step 1 ds << TQString("GETHORIZONTALDIVCOUNT"); m_socket->writeEndOfFrame(); - SET_NEXT_STATE(5) + SET_NEXT_STATE(ScopeState_HorizontalDivCountRequest+1) EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 5) { + else if (m_commHandlerState == ScopeState_HorizontalDivCountRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Received horizontal division count]")); // Get number of horizontal divisions, step 2 TQString result; @@ -373,7 +403,7 @@ void ScopePart::mainEventLoop() { m_socket->clearFrameTail(); if (result == "ACK") { - SET_NEXT_STATE(6) + SET_NEXT_STATE(ScopeState_VerticalDivCountRequest) EXEC_NEXT_STATE_IMMEDIATELY } else { @@ -386,18 +416,19 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 6) { + else if (m_commHandlerState == ScopeState_VerticalDivCountRequest) { // Get number of vertical divisions, step 1 ds << TQString("GETVERTICALDIVCOUNT"); m_socket->writeEndOfFrame(); - SET_NEXT_STATE(7) + SET_NEXT_STATE(ScopeState_VerticalDivCountRequest+1) EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 7) { + else if (m_commHandlerState == ScopeState_VerticalDivCountRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Received vertical division count]")); // Get number of vertical divisions, step 2 TQString result; @@ -408,7 +439,7 @@ void ScopePart::mainEventLoop() { m_socket->clearFrameTail(); if (result == "ACK") { - SET_NEXT_STATE(8) + SET_NEXT_STATE(ScopeState_ChannelCountRequest) EXEC_NEXT_STATE_IMMEDIATELY } else { @@ -421,18 +452,19 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 8) { + else if (m_commHandlerState == ScopeState_ChannelCountRequest) { // Get number of channels, step 1 ds << TQString("GETNUMBEROFCHANNELS"); m_socket->writeEndOfFrame(); - SET_NEXT_STATE(9) + SET_NEXT_STATE(ScopeState_ChannelCountRequest+1) EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 9) { + else if (m_commHandlerState == ScopeState_ChannelCountRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Received number of channels]")); // Get number of channels, step 2 TQString result; @@ -447,7 +479,7 @@ void ScopePart::mainEventLoop() { if (result == "ACK") { m_currentOpChannel = 1; - SET_NEXT_STATE(10) + SET_NEXT_STATE(ScopeState_ChannelActiveStateRequest) EXEC_NEXT_STATE_IMMEDIATELY } else { @@ -460,19 +492,20 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 10) { + else if (m_commHandlerState == ScopeState_ChannelActiveStateRequest) { // Get channel status, step 1 ds << TQString("GETCHANNELACTIVE"); ds << m_currentOpChannel; m_socket->writeEndOfFrame(); - SET_NEXT_STATE(11) + SET_NEXT_STATE(ScopeState_ChannelActiveStateRequest+1) EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 11) { + else if (m_commHandlerState == ScopeState_ChannelActiveStateRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Received channel %1 activity status]").arg(m_currentOpChannel)); // Get channel status, step 2 TQString result; @@ -487,16 +520,16 @@ void ScopePart::mainEventLoop() { if (result == "ACK") { if (m_currentOpChannel < m_maxNumberOfTraces) { m_currentOpChannel++; - SET_NEXT_STATE(10) + SET_NEXT_STATE(ScopeState_ChannelActiveStateRequest) } else { m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces); if (m_currentOpChannel > 0) { - SET_NEXT_STATE(12) + SET_NEXT_STATE(ScopeState_TraceSampleCountRequest) } else { m_currentOpChannel = 1; - SET_NEXT_STATE(8) + SET_NEXT_STATE(ScopeState_ChannelCountRequest) } } EXEC_NEXT_STATE_IMMEDIATELY @@ -511,19 +544,20 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 12) { + else if (m_commHandlerState == ScopeState_TraceSampleCountRequest) { // Get number of samples in trace, step 1 ds << TQString("GETTRACESAMPLECOUNT"); ds << m_currentOpChannel; m_socket->writeEndOfFrame(); - SET_NEXT_STATE(13) + SET_NEXT_STATE(ScopeState_TraceSampleCountRequest+1) EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 13) { + else if (m_commHandlerState == ScopeState_TraceSampleCountRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Received trace sample count for channel %1]").arg(m_currentOpChannel)); // Get number of samples in trace, step 2 TQString result; @@ -536,11 +570,11 @@ void ScopePart::mainEventLoop() { if (result == "ACK") { m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces); if (m_currentOpChannel > 0) { - SET_NEXT_STATE(12) + SET_NEXT_STATE(ScopeState_TraceSampleCountRequest) } else { m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces); - SET_NEXT_STATE(14) + SET_NEXT_STATE(ScopeState_TraceVoltsDivRequest) } EXEC_NEXT_STATE_IMMEDIATELY } @@ -554,19 +588,20 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 14) { + else if (m_commHandlerState == ScopeState_TraceVoltsDivRequest) { // Get volts per division, step 1 ds << TQString("GETVOLTSDIV"); ds << m_currentOpChannel; m_socket->writeEndOfFrame(); - SET_NEXT_STATE(15) + SET_NEXT_STATE(ScopeState_TraceVoltsDivRequest+1) EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 15) { + else if (m_commHandlerState == ScopeState_TraceVoltsDivRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Received volts/div for channel %1]").arg(m_currentOpChannel)); // Get volts per division, step 2 TQString result; @@ -579,11 +614,11 @@ void ScopePart::mainEventLoop() { if (result == "ACK") { m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces); if (m_currentOpChannel > 0) { - SET_NEXT_STATE(14) + SET_NEXT_STATE(ScopeState_TraceVoltsDivRequest) } else { m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces); - SET_NEXT_STATE(16) + SET_NEXT_STATE(ScopeState_TraceSecondsDivRequest) } EXEC_NEXT_STATE_IMMEDIATELY } @@ -597,19 +632,20 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 16) { + else if (m_commHandlerState == ScopeState_TraceSecondsDivRequest) { // Get seconds per division, step 1 ds << TQString("GETSECONDSSDIV"); ds << m_currentOpChannel; m_socket->writeEndOfFrame(); - SET_NEXT_STATE(17) + SET_NEXT_STATE(ScopeState_TraceSecondsDivRequest+1) EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 17) { + else if (m_commHandlerState == ScopeState_TraceSecondsDivRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Received seconds/div]")); // Get seconds per division, step 2 TQString result; @@ -618,6 +654,86 @@ void ScopePart::mainEventLoop() { ds >> m_secsDiv[m_currentOpChannel]; } m_socket->clearFrameTail(); + + if (result == "ACK") { + m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces); + if (m_currentOpChannel > 0) { + SET_NEXT_STATE(ScopeState_TraceSecondsDivRequest) + } + else { + SET_NEXT_STATE(ScopeState_TriggerChannelRequest) + } + EXEC_NEXT_STATE_IMMEDIATELY + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } + } + } + else if (m_commHandlerState == ScopeState_TriggerChannelRequest) { + // Get trigger channel, step 1 + ds << TQString("GETTRIGGERCHANNEL"); + ds << m_currentOpChannel; + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(ScopeState_TriggerChannelRequest+1) + EXEC_NEXT_STATE_IMMEDIATELY + } + else if (m_commHandlerState == ScopeState_TriggerChannelRequest+1) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Received trigger channel]")); + + // Get trigger channel, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_triggerChannel; + } + m_socket->clearFrameTail(); + + if (result == "ACK") { + SET_NEXT_STATE(ScopeState_TriggerLevelRequest) + EXEC_NEXT_STATE_IMMEDIATELY + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } + } + } + else if (m_commHandlerState == ScopeState_TriggerLevelRequest) { + // Get trigger level, step 1 + ds << TQString("GETTRIGGERLEVEL"); + ds << m_currentOpChannel; + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(ScopeState_TriggerLevelRequest+1) + EXEC_NEXT_STATE_IMMEDIATELY + } + else if (m_commHandlerState == ScopeState_TriggerLevelRequest+1) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Loading [Received trigger level]")); + + // Get trigger level, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_triggerLevel; + } + m_socket->clearFrameTail(); if (result == "ACK") { // Update display widget(s) @@ -628,14 +744,8 @@ void ScopePart::mainEventLoop() { } if (result == "ACK") { - m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces); - if (m_currentOpChannel > 0) { - SET_NEXT_STATE(16) - } - else { - m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces); - SET_NEXT_STATE(50) - } + m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces); + SET_NEXT_STATE(ScopeState_TraceRequest) EXEC_NEXT_STATE_IMMEDIATELY } else { @@ -648,19 +758,20 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 50) { + else if (m_commHandlerState == ScopeState_TraceRequest) { // Get trace, step 1 ds << TQString("GETCHANNELTRACE"); ds << m_currentOpChannel; m_socket->writeEndOfFrame(); - SET_NEXT_STATE(51) + SET_NEXT_STATE(ScopeState_TraceRequest+1) EXEC_NEXT_STATE_IMMEDIATELY } - else if (m_commHandlerState == 51) { + else if (m_commHandlerState == ScopeState_TraceRequest+1) { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Running [Received trace for channel %1]").arg(m_currentOpChannel)); // Get trace, step 2 TQDoubleArray trace; @@ -687,11 +798,11 @@ void ScopePart::mainEventLoop() { if (result == "ACK") { m_currentOpChannel = getNextActiveChannel(m_currentOpChannel, m_channelActive, m_maxNumberOfTraces); if (m_currentOpChannel > 0) { - SET_NEXT_STATE(50) + SET_NEXT_STATE(ScopeState_TraceRequest) } else { m_currentOpChannel = getNextActiveChannel(0, m_channelActive, m_maxNumberOfTraces); - SET_NEXT_STATE(50) + SET_NEXT_STATE(ScopeState_TraceRequest) } EXEC_NEXT_STATE_IMMEDIATELY } @@ -705,7 +816,7 @@ void ScopePart::mainEventLoop() { } } } - else if (m_commHandlerState == 255) { + else if (m_commHandlerState == ScopeState_ExternalCommandRequest) { // Execute pending command m_commHandlerMode = 2; m_socket->clearIncomingData(); @@ -716,7 +827,7 @@ void ScopePart::mainEventLoop() { else if (m_commHandlerMode == 2) { if (m_commHandlerCommandState == 0) { m_commHandlerMode = 0; - m_commHandlerState = 10; + m_commHandlerState = ScopeState_ChannelActiveStateRequest; EXEC_NEXT_STATE_IMMEDIATELY } else if (m_commHandlerCommandState == 1) { @@ -733,6 +844,7 @@ void ScopePart::mainEventLoop() { // Get response data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER + setTickerMessage(i18n("Connected")); // Set channel active, step 2 TQString result; @@ -765,7 +877,7 @@ void ScopePart::mainEventLoop() { } } else { - m_commHandlerState = 0; + m_commHandlerState = ScopeState_ResetRequest; m_commHandlerCommandState = 0; } @@ -896,6 +1008,11 @@ void ScopePart::updateGraticule() { m_base->traceZoomWidget->setNumberOfHorizontalDivisions(m_hdivs); m_base->traceZoomWidget->setNumberOfVerticalDivisions(m_vdivs); + TraceNumberList activeTraces; + activeTraces.append(m_triggerChannel-1); + m_traceWidget->setCursorActiveTraceList(0, activeTraces); + m_traceWidget->setCursorPosition(0, (50.0-((m_triggerLevel*100.0)/(m_voltsDiv[m_triggerChannel]*m_vdivs)))); + m_traceWidget->setTraceColor(0, TQColor(255, 255, 255)); m_traceWidget->setTraceColor(1, TQColor(128, 255, 128)); m_traceWidget->setTraceColor(2, TQColor(255, 255, 128)); diff --git a/clients/tde/src/part/scope/part.h b/clients/tde/src/part/scope/part.h index 0032a3e..1e342da 100644 --- a/clients/tde/src/part/scope/part.h +++ b/clients/tde/src/part/scope/part.h @@ -71,6 +71,8 @@ namespace RemoteLab TQ_INT16 m_nextOpParameter16; TQ_INT16 m_hdivs; TQ_INT16 m_vdivs; + TQ_INT16 m_triggerChannel; + double m_triggerLevel; TQ_INT32 m_samplesInTrace[MAXTRACES+1]; bool m_channelActive[MAXTRACES+1]; double m_voltsDiv[MAXTRACES+1]; diff --git a/clients/tde/src/widgets/tracewidget.cpp b/clients/tde/src/widgets/tracewidget.cpp index e3803ed..e62bdb0 100644 --- a/clients/tde/src/widgets/tracewidget.cpp +++ b/clients/tde/src/widgets/tracewidget.cpp @@ -114,12 +114,15 @@ TraceData::TraceData(TraceWidget* parent, TQWidget* labelParent) : TQObject(), p paramLabel->setPaletteBackgroundColor(labelParent->paletteBackgroundColor()); paramLabel->setPaletteForegroundColor(color); paramLabel->setAlignment(TQt::AlignHCenter|TQt::AlignVCenter|TQt::SingleLine); + TQFont font; + font = paramLabel->font(); + font.setPointSize(font.pointSize()-1); + paramLabel->setFont(font); paramLabel->hide(); graphStatusLabel = new TQLabel(labelParent); graphStatusLabel->setPaletteBackgroundColor(labelParent->paletteBackgroundColor()); graphStatusLabel->setPaletteForegroundColor(color); graphStatusLabel->setAlignment(TQt::AlignHCenter|TQt::AlignVCenter|TQt::SingleLine); - TQFont font; font = graphStatusLabel->font(); font.setPointSize(font.pointSize()-1); graphStatusLabel->setFont(font); @@ -232,6 +235,7 @@ void TraceData::movePosOneTick() { emit(offsetChanged(offset)); parentWidget->updateTraceText(); + parentWidget->updateCursorText(); parentWidget->m_graticuleWidget->repaint(false); } @@ -242,6 +246,7 @@ void TraceData::moveNegOneTick() { emit(offsetChanged(offset)); parentWidget->updateTraceText(); + parentWidget->updateCursorText(); parentWidget->m_graticuleWidget->repaint(false); } @@ -250,6 +255,7 @@ void TraceData::resetVPosition() { emit(offsetChanged(offset)); parentWidget->updateTraceText(); + parentWidget->updateCursorText(); parentWidget->m_graticuleWidget->repaint(false); } @@ -267,11 +273,21 @@ CursorData::CursorData(TraceWidget* parent, TQWidget* labelParent) : TQObject(), paramLabel->setPaletteBackgroundColor(labelParent->paletteBackgroundColor()); paramLabel->setPaletteForegroundColor(color); paramLabel->setAlignment(TQt::AlignHCenter|TQt::AlignVCenter|TQt::SingleLine); + TQFont font; + font = paramLabel->font(); + font.setPointSize(font.pointSize()-1); + paramLabel->setFont(font); paramLabel->hide(); singleIncrBtn = new TQPushButton(labelParent); singleDecrBtn = new TQPushButton(labelParent); multiIncrBtn = new TQPushButton(labelParent); multiDecrBtn = new TQPushButton(labelParent); + font = singleIncrBtn->font(); + font.setPointSize(font.pointSize()-1); + singleIncrBtn->setFont(font); + singleDecrBtn->setFont(font); + multiIncrBtn->setFont(font); + multiDecrBtn->setFont(font); singleIncrBtn->setText("+"); singleDecrBtn->setText("-"); multiIncrBtn->setText("++"); @@ -788,6 +804,7 @@ TraceWidget::TraceWidget(TQWidget* parent, const char* name) : TQWidget(parent, m_vertDivs(0), m_cursorDarkness(CURSOR_DARKNESS_FACTOR), m_zoomBoxDarkness(ZOOM_SHADING_DARKNESS_FACTOR), + m_zoomCursorStartIndex(0), m_zoomBoxEnabled(false) { setBackgroundMode(NoBackground); setSizePolicy(TQSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding)); @@ -943,20 +960,23 @@ void TraceWidget::updateCursorText() { cursorText = TQString("%1").arg(m_cursorArray[cursor]->cursorName); // If this is a horizontal cursor, list all vertical positions for all channels // If this is a vertical cursor, list the horizontal positions for all channels + for (uint trace=0;traceenabled) { + if ((m_traceArray[trace]->enabled) && (m_cursorArray[cursor]->activeTraceLabelList.contains(trace) > 0)) { double horizontal_range = (m_traceArray[trace]->rightEdge-m_traceArray[trace]->leftEdge); double vertical_range = (m_traceArray[trace]->bottomEdge-m_traceArray[trace]->topEdge); if (m_cursorArray[cursor]->orientation == TQt::Horizontal) { - double realCursorPosition = (m_traceArray[trace]->topEdge+((m_cursorArray[cursor]->position/100.0)*vertical_range)); + double realCursorPosition = (m_traceArray[trace]->topEdge+((m_cursorArray[cursor]->position/100.0)*vertical_range)-m_traceArray[trace]->offset); TQString deltaText; - for (uint cursor2=0;cursor2orientation == m_cursorArray[cursor]->orientation) { - double realSecondaryCursorPosition = (m_traceArray[trace]->topEdge+((m_cursorArray[cursor2]->position/100.0)*vertical_range)); - deltaText = trUtf8("Δ") + prettyFormat(fabs(realCursorPosition-realSecondaryCursorPosition), vertical_range, m_traceArray[trace]->verticalUnits); - break; + if (cursor >= m_zoomCursorStartIndex) { + for (uint cursor2=m_zoomCursorStartIndex;cursor2orientation == m_cursorArray[cursor]->orientation) { + double realSecondaryCursorPosition = (m_traceArray[trace]->topEdge+((m_cursorArray[cursor2]->position/100.0)*vertical_range)); + deltaText = trUtf8("Δ") + prettyFormat(fabs(realCursorPosition-realSecondaryCursorPosition), vertical_range, m_traceArray[trace]->verticalUnits); + break; + } } } } @@ -965,12 +985,14 @@ void TraceWidget::updateCursorText() { else { double realCursorPosition = (m_traceArray[trace]->leftEdge+((m_cursorArray[cursor]->position/100.0)*horizontal_range)); TQString deltaText; - for (uint cursor2=0;cursor2orientation == m_cursorArray[cursor]->orientation) { - double realSecondaryCursorPosition = (m_traceArray[trace]->leftEdge+((m_cursorArray[cursor2]->position/100.0)*horizontal_range)); - deltaText = trUtf8("Δ") + prettyFormat(fabs(realCursorPosition-realSecondaryCursorPosition), horizontal_range, m_traceArray[trace]->horizontalUnits); - break; + if (cursor >= m_zoomCursorStartIndex) { + for (uint cursor2=m_zoomCursorStartIndex;cursor2orientation == m_cursorArray[cursor]->orientation) { + double realSecondaryCursorPosition = (m_traceArray[trace]->leftEdge+((m_cursorArray[cursor2]->position/100.0)*horizontal_range)); + deltaText = trUtf8("Δ") + prettyFormat(fabs(realCursorPosition-realSecondaryCursorPosition), horizontal_range, m_traceArray[trace]->horizontalUnits); + break; + } } } } @@ -1122,6 +1144,43 @@ void TraceWidget::setCursorPosition(uint cursorNumber, double position) { m_graticuleWidget->repaint(false); } +TQColor TraceWidget::cursorColor(uint cursorNumber) { + VERIFY_CURSOR_ARRAY_SIZE + + return m_cursorArray[cursorNumber]->color; +} + +void TraceWidget::setCursorColor(uint cursorNumber, TQColor color) { + VERIFY_CURSOR_ARRAY_SIZE + + m_cursorArray[cursorNumber]->color = color; + updateCursorText(); + m_graticuleWidget->updateGraticule(); + m_graticuleWidget->repaint(false); +} + +TQColor TraceWidget::cursorHighlightColor(uint cursorNumber) { + VERIFY_CURSOR_ARRAY_SIZE + + return m_cursorArray[cursorNumber]->highlightColor; +} + +void TraceWidget::setCursorHighlightColor(uint cursorNumber, TQColor color) { + VERIFY_CURSOR_ARRAY_SIZE + + m_cursorArray[cursorNumber]->highlightColor = color; + updateCursorText(); + m_graticuleWidget->updateGraticule(); + m_graticuleWidget->repaint(false); +} + +void TraceWidget::setCursorActiveTraceList(uint cursorNumber, TraceNumberList list) { + VERIFY_CURSOR_ARRAY_SIZE + + m_cursorArray[cursorNumber]->activeTraceLabelList = list; + updateCursorText(); +} + bool TraceWidget::cursorEnabled(uint cursorNumber) { VERIFY_CURSOR_ARRAY_SIZE @@ -1188,7 +1247,7 @@ void TraceWidget::setNumberOfCursors(uint cursorNumber) { TQRectF TraceWidget::zoomBox() { uint i; - if ((m_cursorArray.count() < 4) || (!m_zoomBoxEnabled)) { + if ((m_cursorArray.count() < (4+m_zoomCursorStartIndex)) || (!m_zoomBoxEnabled)) { if (!m_zoomBoxPrev.isNull()) { m_zoomBoxPrev = TQRectF(); emit(zoomBoxChanged(m_zoomBoxPrev)); @@ -1202,7 +1261,7 @@ TQRectF TraceWidget::zoomBox() { double vert[2]; int j = 0; int k = 0; - for (i=0;iorientation == TQt::Horizontal) { if (j<2) { vert[j] = m_cursorArray[i]->position; @@ -1243,7 +1302,7 @@ TQRectF TraceWidget::zoomBox() { TQRectF TraceWidget::zoomCursorBox() { uint i; - if ((m_cursorArray.count() < 4) || (!m_zoomBoxEnabled)) { + if ((m_cursorArray.count() < (4+m_zoomCursorStartIndex)) || (!m_zoomBoxEnabled)) { return TQRectF(); } else { @@ -1253,7 +1312,7 @@ TQRectF TraceWidget::zoomCursorBox() { double vert[2]; int j = 0; int k = 0; - for (i=0;iorientation == TQt::Horizontal) { if (j<2) { vert[j] = m_cursorArray[i]->position; @@ -1309,7 +1368,7 @@ void TraceWidget::setZoomCursorBox(const TQRectF rect) { boundedRect.setHeight(100.0); } - if ((m_cursorArray.count() < 4) || (!m_zoomBoxEnabled)) { + if ((m_cursorArray.count() < (4+m_zoomCursorStartIndex)) || (!m_zoomBoxEnabled)) { return; } else { @@ -1319,7 +1378,7 @@ void TraceWidget::setZoomCursorBox(const TQRectF rect) { CursorData* vert[2]; int j = 0; int k = 0; - for (i=0;iorientation == TQt::Horizontal) { if (j<2) { vert[j] = m_cursorArray[i]; @@ -1352,6 +1411,14 @@ void TraceWidget::setZoomCursorBox(const TQRectF rect) { } } +unsigned int TraceWidget::zoomCursorStartIndex() { + return m_zoomCursorStartIndex; +} + +void TraceWidget::setZoomCursorStartIndex(unsigned int index) { + m_zoomCursorStartIndex = index; +} + void TraceWidget::setZoomBoxEnabled(bool enabled) { m_zoomBoxEnabled = enabled; m_graticuleWidget->updateGraticule(); diff --git a/clients/tde/src/widgets/tracewidget.h b/clients/tde/src/widgets/tracewidget.h index 9a478ac..130904f 100644 --- a/clients/tde/src/widgets/tracewidget.h +++ b/clients/tde/src/widgets/tracewidget.h @@ -42,6 +42,8 @@ class TQRectF double m_h; }; +typedef TQValueList TraceNumberList; + class TraceData : public TQObject { Q_OBJECT @@ -114,6 +116,7 @@ class CursorData : public TQObject bool enabled; TQt::Orientation orientation; double position; + TraceNumberList activeTraceLabelList; TQString cursorName; TQLabel* paramLabel; TQPushButton* singleIncrBtn; @@ -199,6 +202,11 @@ class TraceWidget : public TQWidget double cursorPosition(uint cursorNumber); void setCursorPosition(uint cursorNumber, double position); + TQColor cursorColor(uint cursorNumber); + void setCursorColor(uint cursorNumber, TQColor); + TQColor cursorHighlightColor(uint cursorNumber); + void setCursorHighlightColor(uint cursorNumber, TQColor); + void setCursorActiveTraceList(uint cursorNumber, TraceNumberList list); bool cursorEnabled(uint cursorNumber); void setCursorEnabled(uint cursorNumber, bool enabled); TQString cursorName(uint cursorNumber); @@ -213,6 +221,8 @@ class TraceWidget : public TQWidget void setZoomBoxEnabled(bool enabled); TQRectF zoomCursorBox(); void setZoomCursorBox(const TQRectF rect); + unsigned int zoomCursorStartIndex(); + void setZoomCursorStartIndex(unsigned int index); static TQString prettyFormat(double value, double rangeDetectValue, TQString baseUnits, unsigned int precision=3); @@ -237,6 +247,7 @@ class TraceWidget : public TQWidget unsigned int m_vertDivs; unsigned int m_cursorDarkness; unsigned int m_zoomBoxDarkness; + unsigned int m_zoomCursorStartIndex; bool m_zoomBoxEnabled; TQRectF m_zoomBoxPrev; TraceList m_traceArray; diff --git a/servers/gpib_server_lin/src/gpib_conn.cpp b/servers/gpib_server_lin/src/gpib_conn.cpp index 6df70ec..b46f469 100644 --- a/servers/gpib_server_lin/src/gpib_conn.cpp +++ b/servers/gpib_server_lin/src/gpib_conn.cpp @@ -300,7 +300,6 @@ void GPIBSocket::commandLoop() { traceData[i] = scope_raw_trace_data[i]; positionData[i] = scope_raw_position_data[i]; } -printf("[RAJA DEBUG 680.0] traceData[10]: %E positionData[10]: %E\n\r", traceData[10], positionData[10]); fflush(stdout); ds << TQString("ACK"); ds << traceData; ds << positionData; @@ -395,7 +394,7 @@ printf("[RAJA DEBUG 680.0] traceData[10]: %E positionData[10]: %E\n\r", traceDat } } else if (m_instrumentCommand == "SETTRIGGERCHANNEL") { // Want to change trigger channel - TQ_INT32 value; + TQ_INT16 value; ds >> value; if (scope_set_trigger_channel(value, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { ds << TQString("ACK"); @@ -406,6 +405,19 @@ printf("[RAJA DEBUG 680.0] traceData[10]: %E positionData[10]: %E\n\r", traceDat writeEndOfFrame(); } } + else if (m_instrumentCommand == "GETTRIGGERCHANNEL") { // Want to get trigger channel + int channel; + if (scope_get_trigger_channel(&channel, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { + TQ_INT16 safeChannel = channel; + ds << TQString("ACK"); + ds << safeChannel; + writeEndOfFrame(); + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } else if (m_instrumentCommand == "SETTRIGGERLEVEL") { // Want to change trigger level double value; ds >> value; @@ -418,6 +430,18 @@ printf("[RAJA DEBUG 680.0] traceData[10]: %E positionData[10]: %E\n\r", traceDat writeEndOfFrame(); } } + else if (m_instrumentCommand == "GETTRIGGERLEVEL") { // Want to get trigger level + double triggerlevel; + if (scope_get_trigger_level(&triggerlevel, m_serverParent->m_scopeType.ascii(), m_serverParent->m_scopeDeviceSocket) == 0) { + ds << TQString("ACK"); + ds << triggerlevel; + writeEndOfFrame(); + } + else { + ds << TQString("NCK"); + writeEndOfFrame(); + } + } else if (m_instrumentCommand == "SETCHANVERTPOS") { // Want to change channel vertical position TQ_INT32 value1; ds >> value1; diff --git a/servers/gpib_server_lin/src/scope_functions.cpp b/servers/gpib_server_lin/src/scope_functions.cpp index 68f2274..ce5adcd 100644 --- a/servers/gpib_server_lin/src/scope_functions.cpp +++ b/servers/gpib_server_lin/src/scope_functions.cpp @@ -486,6 +486,62 @@ int scope_set_trigger_channel(int desired_channel,const char * scopeType, int gp } } +int scope_get_trigger_channel(int * retval, const char * scopeType, int gpibDevice) { + char floatstring[1024]; + long ai; + int max_num_bytes = 0; + + printf("[INFO] Getting trigger channel\n\r"); + if (strcmp("HP54600OS", scopeType) == 0) { + // FIXME + // Not supported (yet) + return -1; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + sprintf(falpha, "TRIGGER:MAIN:EDGE:SOURCE?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind + } + else { + return 2; + } + + // Read response + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); + #endif + + ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring); + if (ai == -1) { + return 1; + } + else { + floatstring[ai]=0; + TQString retchan(floatstring); + if (retchan.startsWith("CH1")) *retval = 1; + else if (retchan.startsWith("CH2")) *retval = 2; + else if (retchan.startsWith("CH3")) *retval = 3; + else if (retchan.startsWith("CH4")) *retval = 4; + else { + *retval = -1; + return -1; + } + } + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + return 0; + } + else { + return -1; + } +} + int scope_set_trigger_level(float desired_level,const char * scopeType, int gpibDevice) { if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { printf("[INFO] Setting scope trigger level to %f\n\r", desired_level); @@ -522,6 +578,55 @@ int scope_set_trigger_level(float desired_level,const char * scopeType, int gpib } } +int scope_get_trigger_level(double * retval, const char * scopeType, int gpibDevice) { + char floatstring[1024]; + long ai; + int max_num_bytes = 0; + + if (strcmp("HP54600OS", scopeType) == 0) { + // FIXME + // Not supported (yet) + return -1; + } + else if (strcmp("TDS744AOS", scopeType) == 0) { + // Send request + printf("[INFO] Getting trigger level\n\r"); + sprintf(falpha,"TRIGGER:MAIN:LEVEL?"); + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Writing: %s\n\r", falpha); + #endif + if (gpib_write(gpibDevice, falpha) == 0) { + max_num_bytes = 24; // Request more bytes than are possible to ensure no bytes are left behind + } + else { + return 2; + } + + // Read response + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Trying to read %i bytes from GPIB device...\n", max_num_bytes); + #endif + + ai = gpib_read_array(gpibDevice, max_num_bytes, floatstring); + if (ai == -1) { + return 1; + } + else { + floatstring[ai]=0; + *retval = atof(floatstring); + } + + #ifdef ENABLE_EXTRA_DEBUGGING + printf("[DEBG] Read %li bytes from GPIB device\n", ai); + #endif + + return 0; + } + else { + return -1; + } +} + int scope_set_channel_position(int desired_channel, float desired_level,const char * scopeType, int gpibDevice) { if ((strcmp("HP54600OS", scopeType) == 0) || (strcmp("TDS744AOS", scopeType) == 0)) { printf("[INFO] Setting scope channel %d level to %f\n\r", desired_channel, desired_level); diff --git a/servers/gpib_server_lin/src/scope_functions.h b/servers/gpib_server_lin/src/scope_functions.h index 4549b80..b38f821 100644 --- a/servers/gpib_server_lin/src/scope_functions.h +++ b/servers/gpib_server_lin/src/scope_functions.h @@ -44,6 +44,8 @@ long scope_get_channel_trace(int desired_channel, const char * scopeType, int gp int scope_get_number_of_horizontal_divisions(const char * scopeType, int gpibDevice); int scope_get_number_of_vertical_divisions(const char * scopeType, int gpibDevice); int scope_get_number_of_channels(const char * scopeType, int gpibDevice); +int scope_get_trigger_channel(int * retval, const char * scopeType, int gpibDevice); +int scope_get_trigger_level(double * retval, const char * scopeType, int gpibDevice); int scope_get_channel_volts_div(double * retval, int desired_channel, const char * scopeType, int gpibDevice); int scope_get_channel_seconds_div(double * retval, int desired_channel, const char * scopeType, int gpibDevice); int scope_get_channel_sample_count(unsigned long * retval, int desired_channel, const char * scopeType, int gpibDevice); \ No newline at end of file