diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-20 14:10:10 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-07-20 14:10:10 -0500 |
commit | 9c3d84d0df528e8463906ac6399d651792b7ade6 (patch) | |
tree | 499ef6438918f70f499fb0661ceb9c3382cf5107 /servers/fpga_programming_server_lin | |
parent | 0f3b0430e86e45b4a2fca4bc68b013c7f1b484aa (diff) | |
download | ulab-9c3d84d0df528e8463906ac6399d651792b7ade6.tar.gz ulab-9c3d84d0df528e8463906ac6399d651792b7ade6.zip |
Fix FPGA programmer
Diffstat (limited to 'servers/fpga_programming_server_lin')
-rw-r--r-- | servers/fpga_programming_server_lin/src/fpga_conn.cpp | 52 |
1 files changed, 30 insertions, 22 deletions
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())); |