diff options
Diffstat (limited to 'servers/fpga_programming_server_lin/src/fpga_conn.cpp')
-rw-r--r-- | servers/fpga_programming_server_lin/src/fpga_conn.cpp | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/servers/fpga_programming_server_lin/src/fpga_conn.cpp b/servers/fpga_programming_server_lin/src/fpga_conn.cpp index 2d02964..330e747 100644 --- a/servers/fpga_programming_server_lin/src/fpga_conn.cpp +++ b/servers/fpga_programming_server_lin/src/fpga_conn.cpp @@ -35,6 +35,7 @@ #include <sys/types.h> #include <tqtimer.h> +#include <tqfile.h> #include <klocale.h> @@ -45,6 +46,9 @@ delete s; \ s = NULL; +//#define NETWORK_COMM_TIMEOUT_MS 2000 +#define NETWORK_COMM_TIMEOUT_MS 4000 + /* exception handling */ struct exit_exception { int c; @@ -62,6 +66,7 @@ FPGASocket::FPGASocket(int sock, TQObject *parent, const char *name) : // Initialize timers m_kerberosInitTimer = new TQTimer(); connect(m_kerberosInitTimer, SIGNAL(timeout()), this, SLOT(finishKerberosHandshake())); + m_servClientTimeout = new TQTimer(); setServiceName("remotefpga"); @@ -72,6 +77,11 @@ FPGASocket::FPGASocket(int sock, TQObject *parent, const char *name) : } FPGASocket::~FPGASocket() { + if (m_servClientTimeout) { + m_servClientTimeout->stop(); + delete m_servClientTimeout; + m_servClientTimeout = NULL; + } if (m_kerberosInitTimer) { m_kerberosInitTimer->stop(); delete m_kerberosInitTimer; @@ -123,6 +133,8 @@ void FPGASocket::finishKerberosHandshake() { return; } + setDataTimeout(NETWORK_COMM_TIMEOUT_MS); + TQDataStream ds(this); ds << TQString("OK"); @@ -144,7 +156,71 @@ void FPGASocket::commandLoop() { transferred_data = false; if (state() == TQSocket::Connected) { if (m_commandLoopState == 0) { - // RAJA FIXME +printf("[RAJA DEBUG 499.0] Waiting for command...\n\r"); fflush(stdout); + if (canReadLine()) { +printf("[RAJA DEBUG 499.1] Processing pending data (buffer: %d)...\n\r", bytesAvailable()); fflush(stdout); + processPendingData(); + } + if (bytesAvailable() > 0) { + TQDataStream ds(this); + TQString command; + ds >> command; + printf("[DEBUG] Received command '%s'\n\r", command.ascii()); + if (command == "STATUS") { + ds << TQString("IDLE"); + } + else if (command == "FILE") { + m_commandLoopState = 1; + } + else { + printf("[WARNING] Received unknown command '%s'\n\r", command.ascii()); + } + transferred_data = true; + } + } + else if (m_commandLoopState == 1) { + if (canReadLine()) { + processPendingData(); + } +printf("[RAJA DEBUG 500.0] Waiting for file...\n\r"); fflush(stdout); + if (bytesAvailable() > 0) { +printf("[RAJA DEBUG 500.1] Waiting for file (buffer: %d)...\n\r", bytesAvailable()); fflush(stdout); + TQDataStream ds(this); + ds >> m_programmingFileSize; + m_servClientTimeout->start(NETWORK_COMM_TIMEOUT_MS, TRUE); + m_commandLoopState = 2; + } + } + else if (m_commandLoopState == 2) { + if (canReadLine()) { +printf("[RAJA DEBUG 500.2] Processing pending data (buffer: %d)...\n\r", bytesAvailable()); fflush(stdout); + m_servClientTimeout->start(NETWORK_COMM_TIMEOUT_MS, TRUE); + processPendingData(); + } +printf("[RAJA DEBUG 500.3] Waiting for file contents (buffer: %d)...\n\r", bytesAvailable()); fflush(stdout); + if (bytesAvailable() >= m_programmingFileSize) { + TQByteArray fileContents(m_programmingFileSize); + readBlock(fileContents.data(), fileContents.size()); +printf("[RAJA DEBUG 500.4] Received file!\n\r"); fflush(stdout); +printf("[RAJA DEBUG 500.5] fileContents size: %d\n\r", fileContents.size()); fflush(stdout); + m_programmingFileName = TQString("/tmp/%1#%2.dat").arg(m_remoteHost).arg(port()); + TQFile outputFile(m_programmingFileName); + if (outputFile.open(IO_ReadWrite)) { + outputFile.writeBlock(fileContents); + outputFile.flush(); + outputFile.close(); + } + transferred_data = true; + m_commandLoopState = 0; + } + else { + if (!m_servClientTimeout->isActive()) { + TQDataStream ds(this); + ds << TQString("ERROR"); + transferred_data = true; + m_commandLoopState = 0; + } + } } } m_criticalSection--; |