diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-11 01:44:02 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-11 01:44:02 -0500 |
commit | 89702662657667460d0e5914794366d190f11534 (patch) | |
tree | f5ea5b866bba0095675bcfe0190685b839d0ff4e /clients/tde/src/part/commanalyzer/part.cpp | |
parent | 8d3c1358eeaefec559c4a09995ff5b26393a9620 (diff) | |
download | ulab-89702662657667460d0e5914794366d190f11534.tar.gz ulab-89702662657667460d0e5914794366d190f11534.zip |
Fix commanalyzer functionality
Diffstat (limited to 'clients/tde/src/part/commanalyzer/part.cpp')
-rw-r--r-- | clients/tde/src/part/commanalyzer/part.cpp | 787 |
1 files changed, 482 insertions, 305 deletions
diff --git a/clients/tde/src/part/commanalyzer/part.cpp b/clients/tde/src/part/commanalyzer/part.cpp index dbee9be..5d339e3 100644 --- a/clients/tde/src/part/commanalyzer/part.cpp +++ b/clients/tde/src/part/commanalyzer/part.cpp @@ -13,7 +13,7 @@ #include <kstatusbar.h> #include <kstdaction.h> #include <tqfile.h> //encodeName() -#include <tqtimer.h> //postInit() hack +#include <tqtimer.h> #include <tqvbox.h> #include <tqsocket.h> #include <tqmutex.h> @@ -26,6 +26,8 @@ #include "floatspinbox.h" #include "layout.h" +#define NETWORK_COMM_TIMEOUT_MS 15000 + /* exception handling */ struct exit_exception { int c; @@ -35,12 +37,16 @@ struct exit_exception { namespace RemoteLab { typedef KParts::GenericFactory<RemoteLab::CommAnalyzerPart> Factory; +#define CLIENT_LIBRARY "libremotelab_commanalyzer" K_EXPORT_COMPONENT_FACTORY( libremotelab_commanalyzer, RemoteLab::Factory ) CommAnalyzerPart::CommAnalyzerPart( TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList& ) - : ReadOnlyPart( parent, name ), m_traceWidget(0), m_socket(0), m_base(0), stopTraceUpdate(false) + : RemoteInstrumentPart( parent, name ), m_traceWidget(0), m_commHandlerState(-1), m_commHandlerMode(0), m_commHandlerCommandState(0), m_base(0), stopTraceUpdate(false) { + // Initialize important base class variables + m_clientLibraryName = CLIENT_LIBRARY; + // Initialize mutex m_instrumentMutex = new TQMutex(false); @@ -48,6 +54,10 @@ CommAnalyzerPart::CommAnalyzerPart( TQWidget *parentWidget, const char *widgetNa setInstance(Factory::instance()); setWidget(new TQVBox(parentWidget, widgetName)); + // Create timers + m_updateTimeoutTimer = new TQTimer(this); + connect(m_updateTimeoutTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop())); + // Create widgets m_base = new CommAnalyzerBase(widget()); m_traceWidget = m_base->traceWidget; @@ -61,347 +71,529 @@ CommAnalyzerPart::CommAnalyzerPart( TQWidget *parentWidget, const char *widgetNa } CommAnalyzerPart::~CommAnalyzerPart() { - if (m_traceWidget) { - delete m_traceWidget; - } - if (m_socket) { - m_socket->close(); - while (m_socket->state() == TQSocket::Closing) { - tqApp->processEvents(); - } - delete m_socket; + if (m_instrumentMutex->locked()) { + printf("[WARNING] Exiting when data transfer still in progress!\n\r"); fflush(stdout); } + disconnectFromServer(); delete m_instrumentMutex; } void CommAnalyzerPart::postInit() { - m_updateTimer = new TQTimer(this); - connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTrace())); + // } bool CommAnalyzerPart::openURL(const KURL &url) { - connectToServer(url.url()); + int ret; + ret = connectToServer(url.url()); + processLockouts(); + return (ret != 0); } bool CommAnalyzerPart::closeURL() { - if (m_socket) { - m_socket->close(); - - while (m_socket->state() != TQSocket::Idle) { - tqApp->processEvents(); - } - } - + disconnectFromServer(); m_url = KURL(); + return true; +} - if (m_instrumentMutex->locked()) { - throw exit_exception(-1); - } +void CommAnalyzerPart::processLockouts() { +} - return true; +void CommAnalyzerPart::disconnectFromServerCallback() { + m_updateTimeoutTimer->stop(); } -TQString CommAnalyzerPart::callServerMethod(int command) { - if (m_instrumentMutex->locked() == true) { - printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); - return TQString::null; +void CommAnalyzerPart::connectionFinishedCallback() { + connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData())); + m_socket->processPendingData(); + connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(mainEventLoop())); + m_tickerState = 0; + m_commHandlerState = 0; + m_commHandlerMode = 0; + m_socket->setDataTimeout(NETWORK_COMM_TIMEOUT_MS); + m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); + processLockouts(); + mainEventLoop(); + return; +} + +#define UPDATEDISPLAY_TIMEOUT m_connectionActiveAndValid = false; \ + m_tickerState = 0; \ + m_commHandlerState = 2; \ + m_commHandlerMode = 0; \ + m_socket->clearIncomingData(); \ + setStatusMessage(i18n("Server ping timeout. Please verify the status of your network connection.")); \ + m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); \ + m_instrumentMutex->unlock(); \ + return; + +#define COMMUNICATIONS_FAILED m_connectionActiveAndValid = false; \ + m_tickerState = 0; \ + m_commHandlerState = 2; \ + m_commHandlerMode = 0; \ + m_socket->clearIncomingData(); \ + setStatusMessage(i18n("Instrument communication failure. Please verify the status of your network connection.")); \ + m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); \ + m_instrumentMutex->unlock(); \ + 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); + +#define SET_NEXT_STATE(x) if (m_commHandlerMode == 0) { \ + m_commHandlerState = x; \ + } \ + else { \ + m_commHandlerState = 255; \ + } + +void CommAnalyzerPart::mainEventLoop() { + TQDataStream ds(m_socket); + ds.setPrintableData(true); + + if (!m_instrumentMutex->tryLock()) { + TQTimer::singleShot(0, this, SLOT(mainEventLoop())); // Handle the concurrently received call immediately after current execution + return; } - try { - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + + if (m_socket) { + if ((m_commHandlerMode == 0) || (m_commHandlerMode == 1)) { + if (m_commHandlerState == 0) { + // Request communications analyzer access + ds << TQString("COMMUNICATIONS ANALYZER"); + m_socket->writeEndOfFrame(); + + m_commHandlerState = 1; + } + else if (m_commHandlerState == 1) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get command status + TQString result; + ds >> result; + m_socket->clearFrameTail(); + + if (result == "ACK") { + SET_NEXT_STATE(2) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - m_instrumentMutex->unlock(); - return serverRet; - } - else { - m_instrumentMutex->unlock(); - return TQString::null; - } - } - catch (exit_exception& e) { - m_instrumentMutex->unlock(); - return TQString::null; - } -} + else if (m_commHandlerState == 2) { + // Set spectrum analyzer mode + ds << TQString("SETMODESPECTRUMANALYZER"); + m_socket->writeEndOfFrame(); -int16_t CommAnalyzerPart::callServerMethodInt16(int command) { - if (m_instrumentMutex->locked() == true) { - printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); - return 0; - } - try { - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - int bytesread = 0; - int16_t data[1]; - while ((bytesread < 2) && (m_socket->state() == TQSocket::Connected)) { - int ret = m_socket->readBlock(((char*)data)+bytesread, 1); - if (ret > 0) { - bytesread += ret; + SET_NEXT_STATE(3) + } + else if (m_commHandlerState == 3) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get command status + TQString result; + ds >> result; + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Set spectrum analyzer mode + ds << TQString("SETMODESPECTRUMANALYZER"); + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(4) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + else if (m_commHandlerState == 4) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get command status + TQString result; + ds >> result; + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Get number of samples in trace, step 1 + ds << TQString("GETTRACESAMPLECOUNT"); + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(5) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - m_instrumentMutex->unlock(); - return data[0]; - } - else { - m_instrumentMutex->unlock(); - return 0; - } - } - catch (exit_exception& e) { - m_instrumentMutex->unlock(); - return 0; - } -} - -double CommAnalyzerPart::callServerMethodDouble(int command) { - if (m_instrumentMutex->locked() == true) { - printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); - return 0; - } - try { - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - unsigned int bytesread = 0; - double data[1]; - while ((bytesread < sizeof(double)) && (m_socket->state() == TQSocket::Connected)) { - int ret = m_socket->readBlock(((char*)data)+bytesread, 1); - if (ret > 0) { - bytesread += ret; + else if (m_commHandlerState == 5) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get number of samples in trace, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_samplesInTrace; + } + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Get number of horizontal divisions, step 1 + ds << TQString("GETHORIZONTALDIVCOUNT"); + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(6) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + else if (m_commHandlerState == 6) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get number of horizontal divisions, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_hdivs; + } + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Get number of vertical divisions, step 1 + ds << TQString("GETVERTICALDIVCOUNT"); + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(7) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - m_instrumentMutex->unlock(); - return data[0]; - } - else { - m_instrumentMutex->unlock(); - return 0; - } - } - catch (exit_exception& e) { - m_instrumentMutex->unlock(); - return 0; - } -} + else if (m_commHandlerState == 7) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get number of vertical divisions, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_vdivs; + } + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Get reference power level, step 1 + ds << TQString("GETREFERENCEPOWERLEVEL"); + m_socket->writeEndOfFrame(); -void CommAnalyzerPart::sendServerCommandWithParameter(int command, TQString param) { - if (m_instrumentMutex->locked() == true) { - printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); - return; - } - try { - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - param = TQString("%1%2%3").arg(param).arg(TQChar('°')).arg(TQChar('\r')); - cmd += param; - m_socket->writeBlock(cmd.ascii(), cmd.length()); - // Read from the server - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + SET_NEXT_STATE(8) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - } - m_instrumentMutex->unlock(); - return; - } - catch (exit_exception& e) { - m_instrumentMutex->unlock(); - return; - } -} - -void CommAnalyzerPart::sendServerCommand(int command) { - if (m_instrumentMutex->locked() == true) { - printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); - return; - } - try { - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + else if (m_commHandlerState == 8) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get reference power level, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_rpower; + } + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Get vertical division scale, step 1 + ds << TQString("GETVERTDIVSCALE"); + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(9) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - } - m_instrumentMutex->unlock(); - return; - } - catch (exit_exception& e) { - m_instrumentMutex->unlock(); - return; - } -} - -void CommAnalyzerPart::callServerMethodDoubleArray(int command, double * array, int arrayLen) { - if (m_instrumentMutex->locked() == true) { - printf("[WARN] An attempt was made to access the instrument asynchronously, and was rejected to prevent a lockup\n\r"); fflush(stdout); - return; - } - try { - m_instrumentMutex->lock(); - if (m_socket->state() == TQSocket::Connected) { - TQString cmd = TQChar(command); - cmd.append('\r'); - m_socket->writeBlock(cmd.latin1(), cmd.length()); - // Read from the server - TQString serverRet; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + else if (m_commHandlerState == 9) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get vertical division scale, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_vscale; + } + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Get center frequency, step 1 + ds << TQString("GETCENTERFREQUENCY"); + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(10) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - unsigned int bytesread = 0; - int16_t data[1]; - while ((bytesread < 2) && (m_socket->state() == TQSocket::Connected)) { - int ret = m_socket->readBlock(((char*)data)+bytesread, 1); - if (ret > 0) { - bytesread += ret; + else if (m_commHandlerState == 10) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get center frequency, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_centerfreq; + } + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Get frequency span, step 1 + ds << TQString("GETFREQUENCYSPAN"); + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(11) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - serverRet = ""; - while ((!serverRet.contains('\r')) && (m_socket->state() == TQSocket::Connected)) { - char data[1]; - if( m_socket->readBlock(data, 1) > 0) { - serverRet.append(data[0]); + else if (m_commHandlerState == 11) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get frequency span, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_spanfreq; + } + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Update display widget(s) + updateGraticule(); + } + + if (result == "ACK") { + // Get trace, step 1 + ds << TQString("GETSPECTRUMTRACE"); + m_socket->writeEndOfFrame(); + + SET_NEXT_STATE(12) + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } } - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); } - bytesread = 0; - int elementsread = 0; - for (elementsread=0;elementsread<arrayLen;elementsread++) { - bytesread = 0; - while ((bytesread < sizeof(double)) && (m_socket->state() == TQSocket::Connected)) { - if (m_socket->size() < 1) { - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); - } - int ret = m_socket->readBlock(((char*)array)+bytesread+(elementsread*sizeof(double)), 1); - if (ret > 0) { - bytesread += ret; + else if (m_commHandlerState == 12) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get trace, step 2 + TQDoubleArray trace; + TQString result; + ds >> result; + if (result == "ACK") { + ds >> trace; + } + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Update display widget(s) + m_traceWidget->setSamples(trace); + postProcessTrace(); + m_traceWidget->repaint(); + } + + if (result == "ACK") { + SET_NEXT_STATE(2) + } + else { + COMMUNICATIONS_FAILED } } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } + } + } + else if (m_commHandlerState == 255) { + // Execute pending command + m_commHandlerMode = 2; + m_socket->clearIncomingData(); } + SET_WATCHDOG_TIMER } - m_instrumentMutex->unlock(); - return; - } - catch (exit_exception& e) { - m_instrumentMutex->unlock(); - return; - } -} - -int CommAnalyzerPart::connectToServer(TQString server) { - if (!m_socket) { - m_socket = new TQSocket(this); - } - m_socket->connectToHost(server, 4002); - while ((m_socket->state() != TQSocket::Connected) && (m_socket->state() != TQSocket::Idle)) { - tqApp->eventLoop()->processEvents(TQEventLoop::AllEvents); - } - if (m_socket->state() != TQSocket::Connected) { - return -1; - } + else if (m_commHandlerMode == 2) { + if (m_commHandlerCommandState == 0) { + m_commHandlerMode = 0; + m_commHandlerState = 2; + } + else if (m_commHandlerCommandState == 1) { + // Set reference power level + ds << TQString("SETREFERENCEPOWERLEVEL"); + ds << m_rpower; + m_socket->writeEndOfFrame(); - // Gather information from the server - if (callServerMethod(41) == "NCK") { - // FIXME - // Display message and exit - return -1; - } - sendServerCommand(40); // Set spectrum analyzer mode - m_samplesInTrace = callServerMethodInt16(63); // Get number of samples in trace - m_traceWidget->setNumberOfSamples(m_samplesInTrace); - m_hdivs = callServerMethodInt16(62); // Get number of horizontal divisions - m_traceWidget->setNumberOfHorizontalDivisions(m_hdivs); - m_vdivs = callServerMethodInt16(64); // Get number of vertical divisions - m_traceWidget->setNumberOfVerticalDivisions(m_vdivs); + m_commHandlerCommandState = 2; + } + else if (m_commHandlerCommandState == 2) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Set reference power level, step 2 + TQString result; + ds >> result; + m_socket->clearFrameTail(); + + if (result == "ACK") { + // Get reference power level, step 1 + ds << TQString("GETREFERENCEPOWERLEVEL"); + m_socket->writeEndOfFrame(); - m_rpower = callServerMethodDouble(65); // Get reference power level - m_vscale = callServerMethodDouble(66); // Get vertical division scale + m_commHandlerCommandState = 3; + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } + } + } + else if (m_commHandlerCommandState == 3) { + // Get response data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + // Get reference power level, step 2 + TQString result; + ds >> result; + if (result == "ACK") { + ds >> m_rpower; + } + m_socket->clearFrameTail(); - m_centerfreq = callServerMethodDouble(67); // Get center frequency - m_spanfreq = callServerMethodDouble(68); // Get frequency span + // Update display as needed + updateGraticule(); - updateGraticule(); + if (result == "ACK") { + m_commHandlerCommandState = 0; + TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + } + else { + COMMUNICATIONS_FAILED + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } + } + } + } + } + else { + m_commHandlerState = 0; + m_commHandlerCommandState = 0; + } - // Start trace update timer - m_updateTimer->start(10, FALSE); + m_instrumentMutex->unlock(); } void CommAnalyzerPart::postProcessTrace() { return; } -void CommAnalyzerPart::updateTrace() { - m_updateTimer->stop(); - callServerMethodDoubleArray(42, m_traceWidget->samples(), m_samplesInTrace); - postProcessTrace(); - m_traceWidget->repaint(); - if (m_socket->state() == TQSocket::Connected) { - if (stopTraceUpdate == true) { - stopTraceUpdate = false; - } - else { - m_updateTimer->start(10, FALSE); - } - } -} - void CommAnalyzerPart::updateGraticule() { + m_traceWidget->setNumberOfSamples(m_samplesInTrace); + m_traceWidget->setNumberOfHorizontalDivisions(m_hdivs); + m_traceWidget->setNumberOfVerticalDivisions(m_vdivs); + m_leftFrequency = m_centerfreq - (m_spanfreq/2.0); m_rightFrequency = m_centerfreq + (m_spanfreq/2.0); m_traceWidget->setDisplayLimits(m_leftFrequency, m_rpower, m_rightFrequency, m_rpower-(m_vscale*m_hdivs)); @@ -413,25 +605,10 @@ void CommAnalyzerPart::updateGraticule() { } void CommAnalyzerPart::saRefLevelChanged(double newval) { - // We cannot directly send data to the remote instrument because the GUI event may have ocurred during a remote instrument transaction - // This "flaw" is a direct result of maximizing performance by processing GUI events during network transfers, as well as the fact that this client is a multithreaded application m_rpower = newval; - stopTraceUpdate = true; - TQTimer::singleShot(0, this, SLOT(changeSaRefLevel())); -} - -void CommAnalyzerPart::changeSaRefLevel() { - // Keep trying to set the new power level - if (m_instrumentMutex->locked() == false) { - sendServerCommandWithParameter(61, TQString("%1").arg(m_rpower, 0, 'E')); // Set reference power level - m_rpower = callServerMethodDouble(65); // Get reference power level - updateGraticule(); // Update the display grid - m_updateTimer->start(10, FALSE); // Restart trace update timer - } - else { - tqApp->eventLoop()->processEvents(TQEventLoop::ExcludeUserInput); - TQTimer::singleShot(0, this, SLOT(changeSaRefLevel())); - } + m_commHandlerMode = 1; + m_commHandlerCommandState = 1; + mainEventLoop(); } KAboutData* CommAnalyzerPart::createAboutData() { |