diff options
Diffstat (limited to 'clients/tde/src/part/fpgaprogram/part.cpp')
-rw-r--r-- | clients/tde/src/part/fpgaprogram/part.cpp | 206 |
1 files changed, 140 insertions, 66 deletions
diff --git a/clients/tde/src/part/fpgaprogram/part.cpp b/clients/tde/src/part/fpgaprogram/part.cpp index d1a19df..f70ab49 100644 --- a/clients/tde/src/part/fpgaprogram/part.cpp +++ b/clients/tde/src/part/fpgaprogram/part.cpp @@ -26,6 +26,7 @@ #include <kaboutdata.h> //::createAboutData() #include <kaction.h> #include <klocale.h> +#include <ktextedit.h> #include <kmessagebox.h> //::start() #include <kparts/genericfactory.h> #include <kstatusbar.h> @@ -89,6 +90,7 @@ FPGAProgramPart::FPGAProgramPart(TQWidget *parentWidget, const char *widgetName, m_base = new FPGAProgramBase(widget()); // Initialize widgets + m_base->programmingLogBox->setReadOnly(true); connect(m_base->programRunButton, SIGNAL(clicked()), this, SLOT(programRunButtonClicked())); connect(m_base->programmingInputFile, SIGNAL(textChanged(const TQString &)), this, SLOT(processLockouts())); @@ -229,17 +231,21 @@ void FPGAProgramPart::finishConnectingToServer() { // Connection established! // Read magic number and proto version from server m_socket->processPendingData(); - if (m_socket->bytesAvailable() > 0) { + if (m_socket->canReadFrame()) { TQDataStream ds(m_socket); + ds.setPrintableData(true); TQ_UINT32 magicnum; TQ_UINT32 protover; ds >> magicnum; ds >> protover; + m_socket->clearFrameTail(); printf("[DEBUG] Got magic number %d and protocol version %d\n\r", magicnum, protover); fflush(stdout); // Request connection to backend server ds << TQString("SERV"); + m_socket->writeEndOfFrame(); ds << TQString(CLIENT_LIBRARY); + m_socket->writeEndOfFrame(); connToServerState = 3; } break; @@ -248,8 +254,10 @@ void FPGAProgramPart::finishConnectingToServer() { m_socket->processPendingData(); if (m_socket->bytesAvailable() > 0) { TQDataStream ds(m_socket); + ds.setPrintableData(true); TQString response; ds >> response; + m_socket->clearFrameTail(); if (response == "OK") { connToServerState = 4; connToServerConnecting = false; @@ -312,9 +320,7 @@ void FPGAProgramPart::programRunButtonClicked() { m_tickerState = 0; \ m_commHandlerState = 0; \ m_commHandlerMode = 0; \ - while (m_socket->bytesAvailable() > 0) { \ - m_socket->readBlock(data, 64); \ - } \ + 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_connectionMutex->unlock(); \ @@ -323,8 +329,33 @@ void FPGAProgramPart::programRunButtonClicked() { #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); +void FPGAProgramPart::setTickerMessage(TQString message) { + m_connectionActiveAndValid = true; + TQString tickerChar; + switch (m_tickerState) { + case 0: + tickerChar = "-"; + break; + case 1: + tickerChar = "\\"; + break; + case 2: + tickerChar = "|"; + break; + case 3: + tickerChar = "/"; + break; + } + setStatusMessage(message + TQString("... %1").arg(tickerChar)); + m_tickerState++; + if (m_tickerState > 3) { + m_tickerState = 0; + } +} + void FPGAProgramPart::mainEventLoop() { TQDataStream ds(m_socket); + ds.setPrintableData(true); if (!m_connectionMutex->tryLock()) { TQTimer::singleShot(0, this, SLOT(mainEventLoop())); // Handle the concurrently received call immediately after current execution @@ -332,59 +363,49 @@ void FPGAProgramPart::mainEventLoop() { } if (m_socket) { - char data[64]; - if (m_commHandlerMode == 0) { // Normal operation switch (m_commHandlerState) { case 0: // Get status of remote system - // RAJA FIXME - + // Clear buffers to synchronize frames in case of data corruption + m_socket->clearIncomingData(); ds << TQString("STATUS"); + m_socket->writeEndOfFrame(); m_commHandlerState = 1; break; case 1: // Get all data - if (m_socket->bytesAvailable() > 0) { + if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER - // RAJA FIXME TQString status; ds >> status; - -printf("[RAJA DEBUG 106.0] Status: '%s'\n\r", status.ascii()); fflush(stdout); + m_socket->clearFrameTail(); if (status == "") { // Transfer probably failed UPDATEDISPLAY_TIMEOUT } - - m_connectionActiveAndValid = true; - TQString tickerChar; - switch (m_tickerState) { - case 0: - tickerChar = "-"; - break; - case 1: - tickerChar = "\\"; - break; - case 2: - tickerChar = "|"; - break; - case 3: - tickerChar = "/"; - break; + else if (status == "IDLE") { + // Do nothing } - setStatusMessage(i18n("Running") + TQString("... %1").arg(tickerChar)); - m_tickerState++; - if (m_tickerState > 3) { - m_tickerState = 0; + else if (status == "LOGMESSAGES") { + // Fire next event loop immediately + TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + // Retrieve messages on next event loop + m_commHandlerState = 3; + m_commHandlerNextState = 2; + m_commHandlerNextMode = 0; } - m_pingDelayTimer->start(250, TRUE); - m_commHandlerState = 2; + setTickerMessage(i18n("Connected")); + + if (m_commHandlerState == 1) { + m_pingDelayTimer->start(250, TRUE); + m_commHandlerState = 2; + } } else { if (!m_updateTimeoutTimer->isActive()) { @@ -393,6 +414,7 @@ printf("[RAJA DEBUG 106.0] Status: '%s'\n\r", status.ascii()); fflush(stdout); } break; case 2: + // Let the client and server rest for a bit to lower CPU/network overhead if (!m_pingDelayTimer->isActive()) { // Fire next event loop immediately TQTimer::singleShot(0, this, SLOT(mainEventLoop())); @@ -401,11 +423,37 @@ printf("[RAJA DEBUG 106.0] Status: '%s'\n\r", status.ascii()); fflush(stdout); } PAT_WATCHDOG_TIMER break; + case 3: + // Get new log messages + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + TQString messages; + ds >> messages; + m_socket->clearFrameTail(); + + if (messages == "") { + // Transfer probably failed + UPDATEDISPLAY_TIMEOUT + } + else { + m_base->programmingLogBox->append(messages); + + m_pingDelayTimer->start(250, TRUE); + m_commHandlerState = m_commHandlerNextState; + m_commHandlerMode = m_commHandlerNextMode; + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } + } + break; } } else if (m_commHandlerMode == 1) { // Program mode! - // RAJA FIXME if (m_commHandlerState == 0) { m_base->programmingStatusLabel->setText(i18n("Reading input file") + "..."); TQFile file(m_base->programmingInputFile->url()); @@ -413,15 +461,18 @@ printf("[RAJA DEBUG 106.0] Status: '%s'\n\r", status.ascii()); fflush(stdout); m_programmingFileData = file.readAll(); file.close(); + // Busy indicator m_base->programmingProgressBar->setTotalSteps(0); m_base->programmingProgressBar->setProgress(0); // Transmit file to remote server m_base->programmingStatusLabel->setText(i18n("Sending data to server") + "..."); ds << TQString("FILE"); + m_socket->writeEndOfFrame(); m_programmingFileTotalSize = m_programmingFileData.size(); m_programmingFileTransferredBytes = 0; ds << m_programmingFileTotalSize; + m_socket->writeEndOfFrame(); m_base->programmingProgressBar->setTotalSteps(m_programmingFileTotalSize); m_commHandlerState = 1; @@ -430,16 +481,17 @@ printf("[RAJA DEBUG 106.0] Status: '%s'\n\r", status.ascii()); fflush(stdout); KMessageBox::error(0, i18n("<qt>Unable to open selected programming file</qt>"), i18n("Program Failed")); m_commHandlerMode = 0; m_commHandlerState = 0; - m_base->programmingProgressBar->setTotalSteps(1); - m_base->programmingProgressBar->setProgress(0); + m_base->programmingProgressBar->reset(); processLockouts(); } + PAT_WATCHDOG_TIMER } else if (m_commHandlerState == 1) { TQ_ULONG bytesLeft = (m_programmingFileTotalSize-m_programmingFileTransferredBytes); TQ_ULONG bytesToTransfer = bytesLeft; - if (bytesToTransfer > 512) { - bytesToTransfer = 512; + TQ_ULONG maxTransferChunk = maximumSocketDataChunkSize(); + if (bytesToTransfer > maxTransferChunk) { + bytesToTransfer = maxTransferChunk; } m_programmingFileTransferredBytes = m_programmingFileTransferredBytes + m_socket->writeBlock(m_programmingFileData.data()+m_programmingFileTransferredBytes, bytesToTransfer); m_base->programmingProgressBar->setProgress(m_programmingFileTransferredBytes); @@ -447,86 +499,108 @@ printf("[RAJA DEBUG 106.0] Status: '%s'\n\r", status.ascii()); fflush(stdout); // Initiate programming m_base->programmingStatusLabel->setText(i18n("Programming device") + "..."); ds << TQString("PROGRAM"); + m_socket->writeEndOfFrame(); // Request status ds << TQString("STATUS"); + m_socket->writeEndOfFrame(); + + // Busy indicator + m_base->programmingProgressBar->setTotalSteps(0); + m_base->programmingProgressBar->setProgress(0); m_commHandlerState = 2; } else { + setTickerMessage(i18n("Transmitting data")); // Fire next event loop immediately TQTimer::singleShot(0, this, SLOT(mainEventLoop())); } + PAT_WATCHDOG_TIMER } else if (m_commHandlerState == 2) { // Get response - if (m_socket->bytesAvailable() > 0) { + if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER - // RAJA FIXME TQString result; ds >> result; + m_socket->clearFrameTail(); if (result == "PROGRAMMING") { + setTickerMessage(i18n("Programming device")); // Request status ds << TQString("STATUS"); + m_socket->writeEndOfFrame(); + } + else if (result == "LOGMESSAGES") { + // Fire next event loop immediately + TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + // Retrieve messages on next event loop + m_commHandlerState = 3; + m_commHandlerMode = 0; + m_commHandlerNextState = 3; + m_commHandlerNextMode = 1; } else if (result == "DONE") { - int retCode; + TQ_INT32 retCode; TQString log; ds >> retCode; - ds >> log; + m_socket->clearFrameTail(); - // RAJA FIXME - // Handle errors - // This does not update the log as it should! - if (retCode < 0) { + if (retCode != 0) { // Error! m_commHandlerMode = 0; m_commHandlerState = 0; TQTimer::singleShot(0, this, SLOT(mainEventLoop())); - m_base->programmingProgressBar->setTotalSteps(1); - m_base->programmingProgressBar->setProgress(0); + m_base->programmingProgressBar->reset(); KMessageBox::error(0, i18n("<qt>Programming process failure<p>Please see log for details</qt>"), i18n("Program Failed")); processLockouts(); } - - // Done! - m_commHandlerMode = 0; - m_commHandlerState = 0; - TQTimer::singleShot(0, this, SLOT(mainEventLoop())); - m_base->programmingProgressBar->setTotalSteps(1); - m_base->programmingProgressBar->setProgress(0); - processLockouts(); - } - else if (result == "") { - // Transfer probably failed - // Do nothing + else { + // Done! + m_commHandlerMode = 0; + m_commHandlerState = 0; + TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + m_base->programmingProgressBar->reset(); + processLockouts(); + } } - else { + else if (result == "ERROR") { // Error! m_commHandlerMode = 0; m_commHandlerState = 0; TQTimer::singleShot(0, this, SLOT(mainEventLoop())); - m_base->programmingProgressBar->setTotalSteps(1); - m_base->programmingProgressBar->setProgress(0); + m_base->programmingProgressBar->reset(); KMessageBox::error(0, i18n("<qt>Unknown error</qt>"), i18n("Program Failed")); processLockouts(); } + else { + // Unknown response + // Request status + ds << TQString("STATUS"); + m_socket->writeEndOfFrame(); + } } else { if (!m_updateTimeoutTimer->isActive()) { m_commHandlerMode = 0; m_commHandlerState = 0; TQTimer::singleShot(0, this, SLOT(mainEventLoop())); - m_base->programmingProgressBar->setTotalSteps(1); - m_base->programmingProgressBar->setProgress(0); + m_base->programmingProgressBar->reset(); processLockouts(); UPDATEDISPLAY_TIMEOUT } } } + else if (m_commHandlerState == 3) { + // Request status + ds << TQString("STATUS"); + m_socket->writeEndOfFrame(); + m_commHandlerState = 2; + PAT_WATCHDOG_TIMER + } } SET_WATCHDOG_TIMER |