diff options
-rw-r--r-- | clients/tde/src/app/views/instrumentview.cpp | 18 | ||||
-rw-r--r-- | clients/tde/src/app/views/instrumentview.h | 2 | ||||
-rw-r--r-- | clients/tde/src/part/fpgaprogram/layout.ui | 20 | ||||
-rw-r--r-- | clients/tde/src/part/fpgaprogram/part.cpp | 177 | ||||
-rw-r--r-- | clients/tde/src/part/fpgaprogram/part.h | 3 | ||||
-rw-r--r-- | servers/auth_server_lin/src/auth_conn.cpp | 24 | ||||
-rw-r--r-- | servers/fpga_programming_server_lin/src/fpga_conn.cpp | 52 |
7 files changed, 192 insertions, 104 deletions
diff --git a/clients/tde/src/app/views/instrumentview.cpp b/clients/tde/src/app/views/instrumentview.cpp index 3182bc1..9f4b061 100644 --- a/clients/tde/src/app/views/instrumentview.cpp +++ b/clients/tde/src/app/views/instrumentview.cpp @@ -62,7 +62,7 @@ bool InstrumentView::eventFilter(TQObject *o, TQEvent *e) { if (childPartWidget) { if (o == childPartWidget) { if (e->type() == TQEvent::Resize) { - setChildSizeToHint(); + setChildSizeData(); } } } @@ -71,7 +71,7 @@ bool InstrumentView::eventFilter(TQObject *o, TQEvent *e) { return FALSE; } -void InstrumentView::setChildSizeToHint() { +void InstrumentView::setChildSizeData() { if (m_instrumentPart) { TQWidget *childPartWidget = m_instrumentPart->widget(); if (childPartWidget) { @@ -79,8 +79,14 @@ void InstrumentView::setChildSizeToHint() { setFixedSize(childPartWidget->sizeHint()); } else { - TQSize childSizeHint = childPartWidget->sizeHint(); - setMinimumSize(childSizeHint.width(), childSizeHint.height()); + TQSize minimumSizeHint; + if (childPartWidget->layout()) { + minimumSizeHint = childPartWidget->layout()->minimumSize(); + } + else { + minimumSizeHint = childPartWidget->minimumSize(); + } + setMinimumSize(minimumSizeHint.width(), minimumSizeHint.height()); resize(childPartWidget->size()); } } @@ -93,11 +99,11 @@ void InstrumentView::setUsingFixedSize(bool fixed) { setMinimumSize(0, 0); setMaximumSize(TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX); } - setChildSizeToHint(); + setChildSizeData(); } void InstrumentView::resizeEvent(TQResizeEvent *) { - setChildSizeToHint(); + setChildSizeData(); } TQPtrList<KAction> InstrumentView::menuActionList() { diff --git a/clients/tde/src/app/views/instrumentview.h b/clients/tde/src/app/views/instrumentview.h index ed592dd..fa4551a 100644 --- a/clients/tde/src/app/views/instrumentview.h +++ b/clients/tde/src/app/views/instrumentview.h @@ -39,7 +39,7 @@ class InstrumentView : public KMdiChildView private slots: void setStatusMessage(const TQString& message); void setUsingFixedSize(bool fixed); - void setChildSizeToHint(); + void setChildSizeData(); signals: void statusMessageSet(const TQString&); diff --git a/clients/tde/src/part/fpgaprogram/layout.ui b/clients/tde/src/part/fpgaprogram/layout.ui index 3f528bb..0d88f42 100644 --- a/clients/tde/src/part/fpgaprogram/layout.ui +++ b/clients/tde/src/part/fpgaprogram/layout.ui @@ -51,7 +51,7 @@ <cstring>programRunButton</cstring> </property> <property name="text"> - <cstring>Upload File</cstring> + <cstring>Program FPGA</cstring> </property> </widget> <widget class="TQProgressBar" row="2" column="0" colspan="3"> @@ -77,11 +77,27 @@ <string>Log</string> </property> <grid> - <widget class="KTextEdit" row="0" column="0" colspan="0"> + <widget class="KTextEdit" row="0" column="0" colspan="2"> <property name="name"> <cstring>programmingLogBox</cstring> </property> </widget> + <widget class="TQPushButton" row="1" column="0"> + <property name="name"> + <cstring>saveProgrammingLogButton</cstring> + </property> + <property name="text"> + <cstring>Save</cstring> + </property> + </widget> + <widget class="TQPushButton" row="1" column="1"> + <property name="name"> + <cstring>clearProgrammingLogButton</cstring> + </property> + <property name="text"> + <cstring>Clear</cstring> + </property> + </widget> </grid> </widget> </grid> diff --git a/clients/tde/src/part/fpgaprogram/part.cpp b/clients/tde/src/part/fpgaprogram/part.cpp index aa87145..cf35dcf 100644 --- a/clients/tde/src/part/fpgaprogram/part.cpp +++ b/clients/tde/src/part/fpgaprogram/part.cpp @@ -27,6 +27,7 @@ #include <kaction.h> #include <klocale.h> #include <ktextedit.h> +#include <kfiledialog.h> #include <kmessagebox.h> //::start() #include <kparts/genericfactory.h> #include <kstatusbar.h> @@ -56,6 +57,22 @@ #define NETWORK_COMM_TIMEOUT_MS 2500 +enum connectionModes { + ModeIdle = 0, + ModeProgramming = 1 +}; + +enum connectionStates { + ModeIdle_StateStatusRequest = 0, + ModeIdle_StateProcessStatus = 1, + ModeIdle_StateDelay = 2, + ModeIdle_StateGetLogMessages = 3, + ModeProgramming_StateReadFile = 100, + ModeProgramming_StateInitProgramming = 101, + ModeProgramming_StateWaitForCompletion = 102, + ModeProgramming_StateRequestStatus = 103 +}; + namespace RemoteLab { typedef KParts::GenericFactory<RemoteLab::FPGAProgramPart> Factory; @@ -76,6 +93,8 @@ FPGAProgramPart::FPGAProgramPart(TQWidget *parentWidget, const char *widgetName, setWidget(new TQVBox(parentWidget, widgetName)); // Create timers + m_forcedUpdateTimer = new TQTimer(this); + connect(m_forcedUpdateTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop())); m_updateTimeoutTimer = new TQTimer(this); connect(m_updateTimeoutTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop())); m_pingDelayTimer = new TQTimer(this); @@ -87,6 +106,8 @@ FPGAProgramPart::FPGAProgramPart(TQWidget *parentWidget, const char *widgetName, // Initialize widgets m_base->programmingLogBox->setReadOnly(true); connect(m_base->programRunButton, SIGNAL(clicked()), this, SLOT(programRunButtonClicked())); + connect(m_base->clearProgrammingLogButton, SIGNAL(clicked()), this, SLOT(clearProgrammingLogBox())); + connect(m_base->saveProgrammingLogButton, SIGNAL(clicked()), this, SLOT(saveProgrammingLogBox())); connect(m_base->programmingInputFile, SIGNAL(textChanged(const TQString &)), this, SLOT(processLockouts())); TQTimer::singleShot(0, this, TQT_SLOT(postInit())); @@ -140,7 +161,7 @@ void FPGAProgramPart::connectionClosed() { } void FPGAProgramPart::postInit() { - setUsingFixedSize(true); + setUsingFixedSize(false); } bool FPGAProgramPart::openURL(const KURL &url) { @@ -157,6 +178,7 @@ bool FPGAProgramPart::closeURL() { } void FPGAProgramPart::disconnectFromServerCallback() { + m_forcedUpdateTimer->stop(); m_updateTimeoutTimer->stop(); } @@ -165,8 +187,8 @@ void FPGAProgramPart::connectionFinishedCallback() { m_socket->processPendingData(); connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(mainEventLoop())); m_tickerState = 0; - m_commHandlerState = 0; - m_commHandlerMode = 0; + m_commHandlerState = ModeIdle_StateStatusRequest; + m_commHandlerMode = ModeIdle; m_socket->setDataTimeout(NETWORK_COMM_TIMEOUT_MS); m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); processLockouts(); @@ -179,23 +201,46 @@ void FPGAProgramPart::connectionStatusChangedCallback() { } void FPGAProgramPart::programRunButtonClicked() { - m_commHandlerState = 0; - m_commHandlerMode = 1; + m_commHandlerState = ModeProgramming_StateReadFile; + m_commHandlerMode = ModeProgramming; processLockouts(); } -#define UPDATEDISPLAY_TIMEOUT m_connectionActiveAndValid = false; \ - m_tickerState = 0; \ - m_commHandlerState = 0; \ - 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_connectionMutex->unlock(); \ - return; +void FPGAProgramPart::clearProgrammingLogBox() { + m_base->programmingLogBox->setText(""); +} + +void FPGAProgramPart::saveProgrammingLogBox() { + TQString saveFileName = KFileDialog::getSaveFileName(TQString::null, "*.txt|Text Files (*.txt)", 0, i18n("Save log file...")); + if (saveFileName != "") { + TQFile file(saveFileName); + if (file.open(IO_WriteOnly)) { + TQCString logFile = m_base->programmingLogBox->text().ascii(); + m_programmingFileData = file.writeBlock(logFile.data(), logFile.size()); + file.close(); + } + else { + KMessageBox::error(0, i18n("<qt>Unable to save log file<p>Please check permissions and try again</qt>"), i18n("Save Failed")); + } + } +} -#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 UPDATEDISPLAY_TIMEOUT m_connectionActiveAndValid = false; \ + m_tickerState = 0; \ + m_commHandlerState = ModeIdle_StateStatusRequest; \ + m_commHandlerMode = ModeIdle; \ + 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(); \ + 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) m_commHandlerState = x; + +#define EXEC_NEXT_STATE_IMMEDIATELY m_forcedUpdateTimer->start(0, TRUE); void FPGAProgramPart::setTickerMessage(TQString message) { m_connectionActiveAndValid = true; @@ -226,24 +271,24 @@ void FPGAProgramPart::mainEventLoop() { ds.setPrintableData(true); if (!m_connectionMutex->tryLock()) { - TQTimer::singleShot(0, this, SLOT(mainEventLoop())); // Handle the concurrently received call immediately after current execution + EXEC_NEXT_STATE_IMMEDIATELY return; } if (m_socket) { - if (m_commHandlerMode == 0) { + if (m_commHandlerMode == ModeIdle) { // Normal operation switch (m_commHandlerState) { - case 0: + case ModeIdle_StateStatusRequest: // Get status of remote system // Clear buffers to synchronize frames in case of data corruption m_socket->clearIncomingData(); ds << TQString("STATUS"); m_socket->writeEndOfFrame(); - m_commHandlerState = 1; + SET_NEXT_STATE(ModeIdle_StateProcessStatus) break; - case 1: + case ModeIdle_StateProcessStatus: // Get all data if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER @@ -260,19 +305,18 @@ void FPGAProgramPart::mainEventLoop() { // Do nothing } else if (status == "LOGMESSAGES") { - // Fire next event loop immediately - TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + EXEC_NEXT_STATE_IMMEDIATELY // Retrieve messages on next event loop - m_commHandlerState = 3; - m_commHandlerNextState = 2; - m_commHandlerNextMode = 0; + SET_NEXT_STATE(ModeIdle_StateGetLogMessages); + m_commHandlerNextState = ModeIdle_StateDelay; + m_commHandlerNextMode = ModeIdle; } setTickerMessage(i18n("Connected")); - if (m_commHandlerState == 1) { + if (m_commHandlerState == ModeIdle_StateProcessStatus) { m_pingDelayTimer->start(250, TRUE); - m_commHandlerState = 2; + SET_NEXT_STATE(ModeIdle_StateDelay); } } else { @@ -281,17 +325,16 @@ void FPGAProgramPart::mainEventLoop() { } } break; - case 2: + case ModeIdle_StateDelay: // 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())); + EXEC_NEXT_STATE_IMMEDIATELY // Execute query on next event loop - m_commHandlerState = 0; + SET_NEXT_STATE(ModeIdle_StateStatusRequest); } PAT_WATCHDOG_TIMER break; - case 3: + case ModeIdle_StateGetLogMessages: // Get new log messages if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER @@ -308,7 +351,7 @@ void FPGAProgramPart::mainEventLoop() { m_base->programmingLogBox->append(messages); m_pingDelayTimer->start(250, TRUE); - m_commHandlerState = m_commHandlerNextState; + SET_NEXT_STATE(m_commHandlerNextState); m_commHandlerMode = m_commHandlerNextMode; } } @@ -322,7 +365,7 @@ void FPGAProgramPart::mainEventLoop() { } else if (m_commHandlerMode == 1) { // Program mode! - if (m_commHandlerState == 0) { + if (m_commHandlerState == ModeProgramming_StateReadFile) { m_base->programmingStatusLabel->setText(i18n("Reading input file") + "..."); TQFile file(m_base->programmingInputFile->url()); if (file.open(IO_ReadOnly)) { @@ -343,18 +386,18 @@ void FPGAProgramPart::mainEventLoop() { m_socket->writeEndOfFrame(); m_base->programmingProgressBar->setTotalSteps(m_programmingFileTotalSize); - m_commHandlerState = 1; + SET_NEXT_STATE(ModeProgramming_StateInitProgramming); } else { KMessageBox::error(0, i18n("<qt>Unable to open selected programming file</qt>"), i18n("Program Failed")); - m_commHandlerMode = 0; - m_commHandlerState = 0; + m_commHandlerMode = ModeIdle; + SET_NEXT_STATE(ModeIdle_StateStatusRequest); m_base->programmingProgressBar->reset(); processLockouts(); } PAT_WATCHDOG_TIMER } - else if (m_commHandlerState == 1) { + else if (m_commHandlerState == ModeProgramming_StateInitProgramming) { TQ_ULONG bytesLeft = (m_programmingFileTotalSize-m_programmingFileTransferredBytes); TQ_ULONG bytesToTransfer = bytesLeft; TQ_ULONG maxTransferChunk = maximumSocketDataChunkSize(); @@ -362,6 +405,7 @@ void FPGAProgramPart::mainEventLoop() { bytesToTransfer = maxTransferChunk; } m_programmingFileTransferredBytes = m_programmingFileTransferredBytes + m_socket->writeBlock(m_programmingFileData.data()+m_programmingFileTransferredBytes, bytesToTransfer); + m_socket->flush(); m_base->programmingProgressBar->setProgress(m_programmingFileTransferredBytes); if (m_programmingFileTransferredBytes >= m_programmingFileTotalSize) { // Initiate programming @@ -377,38 +421,37 @@ void FPGAProgramPart::mainEventLoop() { m_base->programmingProgressBar->setTotalSteps(0); m_base->programmingProgressBar->setProgress(0); - m_commHandlerState = 2; + SET_NEXT_STATE(ModeProgramming_StateWaitForCompletion); } else { setTickerMessage(i18n("Transmitting data")); - // Fire next event loop immediately - TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + EXEC_NEXT_STATE_IMMEDIATELY } PAT_WATCHDOG_TIMER } - else if (m_commHandlerState == 2) { + else if (m_commHandlerState == ModeProgramming_StateWaitForCompletion) { // Get response if (m_socket->canReadFrame()) { PAT_WATCHDOG_TIMER TQString result; ds >> result; - m_socket->clearFrameTail(); if (result == "PROGRAMMING") { + m_socket->clearFrameTail(); 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())); + m_socket->clearFrameTail(); + EXEC_NEXT_STATE_IMMEDIATELY // Retrieve messages on next event loop - m_commHandlerState = 3; - m_commHandlerMode = 0; - m_commHandlerNextState = 3; - m_commHandlerNextMode = 1; + SET_NEXT_STATE(ModeIdle_StateGetLogMessages); + m_commHandlerMode = ModeIdle; + m_commHandlerNextState = ModeProgramming_StateRequestStatus; + m_commHandlerNextMode = ModeProgramming; } else if (result == "DONE") { TQ_INT32 retCode; @@ -419,27 +462,28 @@ void FPGAProgramPart::mainEventLoop() { if (retCode != 0) { // Error! - m_commHandlerMode = 0; - m_commHandlerState = 0; - TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + m_commHandlerMode = ModeIdle; + SET_NEXT_STATE(ModeIdle_StateStatusRequest); + EXEC_NEXT_STATE_IMMEDIATELY m_base->programmingProgressBar->reset(); KMessageBox::error(0, i18n("<qt>Programming process failure<p>Please see log for details</qt>"), i18n("Program Failed")); processLockouts(); } else { // Done! - m_commHandlerMode = 0; - m_commHandlerState = 0; - TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + m_commHandlerMode = ModeIdle; + SET_NEXT_STATE(ModeIdle_StateStatusRequest); + EXEC_NEXT_STATE_IMMEDIATELY m_base->programmingProgressBar->reset(); processLockouts(); } } else if (result == "ERROR") { // Error! - m_commHandlerMode = 0; - m_commHandlerState = 0; - TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + m_socket->clearFrameTail(); + m_commHandlerMode = ModeIdle; + SET_NEXT_STATE(ModeIdle_StateStatusRequest); + EXEC_NEXT_STATE_IMMEDIATELY m_base->programmingProgressBar->reset(); KMessageBox::error(0, i18n("<qt>Unknown error</qt>"), i18n("Program Failed")); processLockouts(); @@ -447,26 +491,27 @@ void FPGAProgramPart::mainEventLoop() { else { // Unknown response // Request status + m_socket->clearFrameTail(); ds << TQString("STATUS"); m_socket->writeEndOfFrame(); } } else { if (!m_updateTimeoutTimer->isActive()) { - m_commHandlerMode = 0; - m_commHandlerState = 0; - TQTimer::singleShot(0, this, SLOT(mainEventLoop())); + m_commHandlerMode = ModeIdle; + SET_NEXT_STATE(ModeIdle_StateStatusRequest); + EXEC_NEXT_STATE_IMMEDIATELY m_base->programmingProgressBar->reset(); processLockouts(); UPDATEDISPLAY_TIMEOUT } } } - else if (m_commHandlerState == 3) { + else if (m_commHandlerState == ModeProgramming_StateRequestStatus) { // Request status ds << TQString("STATUS"); m_socket->writeEndOfFrame(); - m_commHandlerState = 2; + SET_NEXT_STATE(ModeProgramming_StateWaitForCompletion); PAT_WATCHDOG_TIMER } } @@ -474,8 +519,8 @@ void FPGAProgramPart::mainEventLoop() { SET_WATCHDOG_TIMER } else { - m_commHandlerState = 0; - m_commHandlerMode = 0; + SET_NEXT_STATE(ModeIdle_StateStatusRequest); + m_commHandlerMode = ModeIdle; } m_connectionMutex->unlock(); diff --git a/clients/tde/src/part/fpgaprogram/part.h b/clients/tde/src/part/fpgaprogram/part.h index 2a0880c..9242ae1 100644 --- a/clients/tde/src/part/fpgaprogram/part.h +++ b/clients/tde/src/part/fpgaprogram/part.h @@ -75,11 +75,14 @@ namespace RemoteLab void setTickerMessage(TQString message); void programRunButtonClicked(); + void clearProgrammingLogBox(); + void saveProgrammingLogBox(); private: FPGAProgramBase* m_base; TQMutex* m_connectionMutex; TQTimer* m_pingDelayTimer; + TQTimer* m_forcedUpdateTimer; TQTimer* m_updateTimeoutTimer; int m_commHandlerState; diff --git a/servers/auth_server_lin/src/auth_conn.cpp b/servers/auth_server_lin/src/auth_conn.cpp index c9a377f..e073e12 100644 --- a/servers/auth_server_lin/src/auth_conn.cpp +++ b/servers/auth_server_lin/src/auth_conn.cpp @@ -275,19 +275,29 @@ int AuthSocket::servLoop() { break; case 4: if (m_servClientSocket->state() == TQSocket::Connected) { - TQ_ULONG reclen; + TQ_LONG reclen; if (canReadData()) { reclen = readBlock(m_loopBuffer.data(), m_loopBuffer.size()); - m_servClientSocket->writeBlock(m_loopBuffer.data(), reclen); - m_servClientSocket->flush(); - transferred_data = true; + if (reclen > 0) { + m_servClientSocket->writeBlock(m_loopBuffer.data(), reclen); + m_servClientSocket->flush(); + transferred_data = true; + } + else { + printf("[WARNING] Remote server advertised data available but no data was able to be read!\n\r"); + } } if (m_servClientSocket->canReadData()) { reclen = m_servClientSocket->readBlock(m_loopBuffer.data(), m_loopBuffer.size()); - writeBlock(m_loopBuffer.data(), reclen); - flush(); - transferred_data = true; + if (reclen > 0) { + writeBlock(m_loopBuffer.data(), reclen); + flush(); + transferred_data = true; + } + else { + printf("[WARNING] Remote client advertised data available but no data was able to be read!\n\r"); + } } } else { diff --git a/servers/fpga_programming_server_lin/src/fpga_conn.cpp b/servers/fpga_programming_server_lin/src/fpga_conn.cpp index 341d14a..406c76c 100644 --- a/servers/fpga_programming_server_lin/src/fpga_conn.cpp +++ b/servers/fpga_programming_server_lin/src/fpga_conn.cpp @@ -55,13 +55,22 @@ struct exit_exception { exit_exception(int c):c(c) { } }; +enum connectionStates { + StateIdle = 0, + StateGetFileSize = 1, + StateGetFileContents = 2, + StateStartProgramming = 3, + StateCheckProgrammingStatus = 4, + StateProgammingFinished = 5 +}; + /* The FPGASocket class provides a socket that is connected with a client. For every client that connects to the server, the server creates a new instance of this class. */ FPGASocket::FPGASocket(int sock, TQObject *parent, const char *name) : - TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_loopTimer(NULL), m_config(static_cast<FPGAServer*>(parent)->m_config), m_commandLoopState(0), + TDEKerberosServerSocket(parent, name), m_criticalSection(0), m_loopTimer(NULL), m_config(static_cast<FPGAServer*>(parent)->m_config), m_commandLoopState(StateIdle), m_progpipe(NULL), m_progpipefd(-1), m_progErrorFlag(false), m_progDoneFlag(false) { @@ -159,7 +168,7 @@ void FPGASocket::commandLoop() { try { transferred_data = false; if (state() == TQSocket::Connected) { - if ((m_commandLoopState == 0) || (m_commandLoopState == 3) || (m_commandLoopState == 4) || (m_commandLoopState == 5)) { + if ((m_commandLoopState == StateIdle) || (m_commandLoopState == StateStartProgramming) || (m_commandLoopState == StateCheckProgrammingStatus) || (m_commandLoopState == StateProgammingFinished)) { // Certain commands can come in at any time during some operations if (canReadLine()) { processPendingData(); @@ -185,16 +194,15 @@ void FPGASocket::commandLoop() { } else if (m_progDoneFlag) { ds << TQString("DONE"); - m_progDoneFlag = false; - writeEndOfFrame(); ds << m_progRetCode; + m_progDoneFlag = false; writeEndOfFrame(); } - else if (m_commandLoopState == 0) { + else if (m_commandLoopState == StateIdle) { ds << TQString("IDLE"); writeEndOfFrame(); } - else if ((m_commandLoopState == 3) || (m_commandLoopState == 4) || (m_commandLoopState == 5)) { + else if ((m_commandLoopState == StateStartProgramming) || (m_commandLoopState == StateCheckProgrammingStatus) || (m_commandLoopState == StateProgammingFinished)) { ds << TQString("PROGRAMMING"); writeEndOfFrame(); } @@ -203,12 +211,12 @@ void FPGASocket::commandLoop() { writeEndOfFrame(); } } - else if (m_commandLoopState == 0) { + else if (m_commandLoopState == StateIdle) { if (command == "FILE") { - m_commandLoopState = 1; + m_commandLoopState = StateGetFileSize; } else if (command == "PROGRAM") { - m_commandLoopState = 3; + m_commandLoopState = StateStartProgramming; } else { printf("[WARNING] Received unknown command '%s'\n\r", command.ascii()); @@ -217,7 +225,7 @@ void FPGASocket::commandLoop() { transferred_data = true; } } - if (m_commandLoopState == 1) { + if (m_commandLoopState == StateGetFileSize) { if (canReadLine()) { processPendingData(); } @@ -227,10 +235,10 @@ void FPGASocket::commandLoop() { ds >> m_programmingFileSize; clearFrameTail(); m_servClientTimeout->start(NETWORK_COMM_TIMEOUT_MS, TRUE); - m_commandLoopState = 2; + m_commandLoopState = StateGetFileContents; } } - else if (m_commandLoopState == 2) { + else if (m_commandLoopState == StateGetFileContents) { if (canReadLine()) { m_servClientTimeout->start(NETWORK_COMM_TIMEOUT_MS, TRUE); processPendingData(); @@ -246,17 +254,17 @@ void FPGASocket::commandLoop() { outputFile.close(); } transferred_data = true; - m_commandLoopState = 0; + m_commandLoopState = StateIdle; } else { if (!m_servClientTimeout->isActive()) { m_progErrorFlag = true; transferred_data = true; - m_commandLoopState = 0; + m_commandLoopState = StateIdle; } } } - else if (m_commandLoopState == 3) { + else if (m_commandLoopState == StateStartProgramming) { // Start programming! // Open programming process @@ -270,15 +278,15 @@ void FPGASocket::commandLoop() { m_logMessages.append(TQString("The system was unable to execute '%1'\nPlease contact your system administrator with this information").arg(programmingScript)); m_progErrorFlag = true; transferred_data = true; - m_commandLoopState = 0; + m_commandLoopState = StateIdle; } else { m_progpipefd = fileno(m_progpipe); fcntl(m_progpipefd, F_SETFL, O_NONBLOCK); } - m_commandLoopState = 4; + m_commandLoopState = StateCheckProgrammingStatus; } - else if (m_commandLoopState == 4) { + else if (m_commandLoopState == StateCheckProgrammingStatus) { // Check programming status TQCString buf; buf.resize(8192); @@ -293,10 +301,10 @@ void FPGASocket::commandLoop() { } else { // Process terminated - m_commandLoopState = 5; + m_commandLoopState = StateProgammingFinished; } } - else if (m_commandLoopState == 5) { + else if (m_commandLoopState == StateProgammingFinished) { // Programming process terminated; get exit code and clean up if (m_progpipe) { m_progRetCode = pclose(m_progpipe); @@ -308,7 +316,7 @@ void FPGASocket::commandLoop() { m_progpipefd = -1; m_progDoneFlag = true; - m_commandLoopState = 0; + m_commandLoopState = StateIdle; } } m_criticalSection--; @@ -327,7 +335,7 @@ void FPGASocket::commandLoop() { } int FPGASocket::enterCommandLoop() { - m_commandLoopState = 0; + m_commandLoopState = StateIdle; if (!m_loopTimer) { m_loopTimer = new TQTimer(); connect(m_loopTimer, SIGNAL(timeout()), this, SLOT(commandLoop())); |