From 192a06da8df1bf95e96d77d2fa0736bb7d2fe58b Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Mon, 16 Jul 2012 23:57:45 -0500 Subject: Add trigger display --- clients/tde/src/part/scope/part.cpp | 263 ++++++++++++++++++++++++++---------- 1 file changed, 190 insertions(+), 73 deletions(-) (limited to 'clients/tde/src/part/scope/part.cpp') 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)); -- cgit v1.2.1