Fix a variety of issues

master
Timothy Pearson 13 years ago
parent 8cc7778d9f
commit 1b8ef84fb9

@ -57,7 +57,7 @@
//#define SERVER_TIMEOUT_MS 10000 //#define SERVER_TIMEOUT_MS 10000
// RAJA DEBUG ONLY // RAJA DEBUG ONLY
#define SERVER_TIMEOUT_MS 100000 #define SERVER_TIMEOUT_MS 100000
#define FPGA_COMM_TIMEOUT_MS 500 #define NETWORK_COMM_TIMEOUT_MS 2500
#define FPGA_DATA_PROCESSING_TIMEOUT_MS 2500 #define FPGA_DATA_PROCESSING_TIMEOUT_MS 2500
namespace RemoteLab { namespace RemoteLab {
@ -78,15 +78,19 @@ FPGAProgramPart::FPGAProgramPart(TQWidget *parentWidget, const char *widgetName,
setWidget(new TQVBox(parentWidget, widgetName)); setWidget(new TQVBox(parentWidget, widgetName));
// Create timers // Create timers
m_updateTimer = new TQTimer(this);
m_connectionTimer = new TQTimer(this); m_connectionTimer = new TQTimer(this);
connect(m_connectionTimer, SIGNAL(timeout()), this, SLOT(finishConnectingToServer())); connect(m_connectionTimer, SIGNAL(timeout()), this, SLOT(finishConnectingToServer()));
m_updateTimeoutTimer = new TQTimer(this);
connect(m_updateTimeoutTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop()));
m_pingDelayTimer = new TQTimer(this);
connect(m_pingDelayTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop()));
// Create widgets // Create widgets
m_base = new FPGAProgramBase(widget()); m_base = new FPGAProgramBase(widget());
// Initialize widgets // Initialize widgets
connect(m_base->programRunButton, SIGNAL(clicked()), this, SLOT(programRunButtonClicked())); connect(m_base->programRunButton, SIGNAL(clicked()), this, SLOT(programRunButtonClicked()));
connect(m_base->programmingInputFile, SIGNAL(textChanged(const TQString &)), this, SLOT(processLockouts()));
TQTimer::singleShot(0, this, TQT_SLOT(postInit())); TQTimer::singleShot(0, this, TQT_SLOT(postInit()));
} }
@ -139,7 +143,7 @@ void FPGAProgramPart::connectionClosed() {
} }
void FPGAProgramPart::postInit() { void FPGAProgramPart::postInit() {
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop())); //
} }
bool FPGAProgramPart::openURL(const KURL &url) { bool FPGAProgramPart::openURL(const KURL &url) {
@ -157,7 +161,7 @@ bool FPGAProgramPart::closeURL() {
void FPGAProgramPart::disconnectFromServer() { void FPGAProgramPart::disconnectFromServer() {
m_connectionTimer->stop(); m_connectionTimer->stop();
m_updateTimer->stop(); m_updateTimeoutTimer->stop();
if (m_socket) { if (m_socket) {
m_socket->clearPendingData(); m_socket->clearPendingData();
m_socket->close(); m_socket->close();
@ -246,16 +250,17 @@ void FPGAProgramPart::finishConnectingToServer() {
TQDataStream ds(m_socket); TQDataStream ds(m_socket);
TQString response; TQString response;
ds >> response; ds >> response;
printf("[RAJA DEBUG 400.0] Got '%s' from the server\n\r", response.ascii()); fflush(stdout);
if (response == "OK") { if (response == "OK") {
connToServerState = 4; connToServerState = 4;
connToServerConnecting = false; connToServerConnecting = false;
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData())); connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(mainEventLoop())); connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(mainEventLoop()));
m_tickerState = 0; m_tickerState = 0;
m_commHandlerState = 0; m_commHandlerState = 0;
m_commHandlerMode = 0; m_commHandlerMode = 0;
m_updateTimer->start(FPGA_COMM_TIMEOUT_MS, FALSE); m_socket->setDataTimeout(NETWORK_COMM_TIMEOUT_MS);
m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE);
processLockouts(); processLockouts();
mainEventLoop(); mainEventLoop();
return; return;
@ -311,13 +316,21 @@ void FPGAProgramPart::programRunButtonClicked() {
m_socket->readBlock(data, 64); \ m_socket->readBlock(data, 64); \
} \ } \
setStatusMessage(i18n("Server ping timeout. Please verify the status of your network connection.")); \ setStatusMessage(i18n("Server ping timeout. Please verify the status of your network connection.")); \
m_updateTimer->start(FPGA_COMM_TIMEOUT_MS, FALSE); \ m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); \
m_connectionMutex->unlock(); \
return; 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);
void FPGAProgramPart::mainEventLoop() { void FPGAProgramPart::mainEventLoop() {
m_updateTimer->stop();
TQDataStream ds(m_socket); TQDataStream ds(m_socket);
if (!m_connectionMutex->tryLock()) {
TQTimer::singleShot(0, this, SLOT(mainEventLoop())); // Handle the concurrently received call immediately after current execution
return;
}
if (m_socket) { if (m_socket) {
char data[64]; char data[64];
@ -329,16 +342,24 @@ void FPGAProgramPart::mainEventLoop() {
// RAJA FIXME // RAJA FIXME
ds << TQString("STATUS"); ds << TQString("STATUS");
m_updateTimer->start(FPGA_COMM_TIMEOUT_MS, FALSE);
m_commHandlerState = 1; m_commHandlerState = 1;
break; break;
case 1: case 1:
// Get all data // Get all data
if (m_socket->bytesAvailable() > 0) { if (m_socket->bytesAvailable() > 0) {
PAT_WATCHDOG_TIMER
// RAJA FIXME // RAJA FIXME
TQStringList statusDetails; TQString status;
ds >> statusDetails; ds >> status;
printf("[RAJA DEBUG 106.0] Status: '%s'\n\r", status.ascii()); fflush(stdout);
if (status == "") {
// Transfer probably failed
UPDATEDISPLAY_TIMEOUT
}
m_connectionActiveAndValid = true; m_connectionActiveAndValid = true;
TQString tickerChar; TQString tickerChar;
@ -361,16 +382,24 @@ void FPGAProgramPart::mainEventLoop() {
if (m_tickerState > 3) { if (m_tickerState > 3) {
m_tickerState = 0; m_tickerState = 0;
} }
m_updateTimer->start(FPGA_COMM_TIMEOUT_MS, FALSE);
m_commHandlerState = 0; m_pingDelayTimer->start(250, TRUE);
m_commHandlerState = 2;
} }
else { else {
if (!m_updateTimer->isActive()) { if (!m_updateTimeoutTimer->isActive()) {
UPDATEDISPLAY_TIMEOUT UPDATEDISPLAY_TIMEOUT
} }
} }
break;
case 2:
if (!m_pingDelayTimer->isActive()) {
// Fire next event loop immediately
TQTimer::singleShot(0, this, SLOT(mainEventLoop()));
// Execute query on next event loop
m_commHandlerState = 0;
}
PAT_WATCHDOG_TIMER
break; break;
} }
} }
@ -386,15 +415,14 @@ void FPGAProgramPart::mainEventLoop() {
m_base->programmingProgressBar->setTotalSteps(0); m_base->programmingProgressBar->setTotalSteps(0);
m_base->programmingProgressBar->setProgress(0); m_base->programmingProgressBar->setProgress(0);
m_base->programmingStatusLabel->setText(i18n("Sending data to server") + "...");
// Transmit file to remote server
m_base->programmingStatusLabel->setText(i18n("Sending data to server") + "...");
ds << TQString("FILE"); ds << TQString("FILE");
// RAJA FIXME m_programmingFileTotalSize = m_programmingFileData.size();
// Transmit file to remote server... m_programmingFileTransferredBytes = 0;
ds << m_programmingFileData; ds << m_programmingFileTotalSize;
m_base->programmingProgressBar->setTotalSteps(m_programmingFileTotalSize);
m_base->programmingStatusLabel->setText(i18n("Programming device") + "...");
ds << TQString("PROGRAM");
m_commHandlerState = 1; m_commHandlerState = 1;
} }
@ -408,14 +436,40 @@ void FPGAProgramPart::mainEventLoop() {
} }
} }
else if (m_commHandlerState == 1) { else if (m_commHandlerState == 1) {
TQ_ULONG bytesLeft = (m_programmingFileTotalSize-m_programmingFileTransferredBytes);
TQ_ULONG bytesToTransfer = bytesLeft;
if (bytesToTransfer > 512) {
bytesToTransfer = 512;
}
m_programmingFileTransferredBytes = m_programmingFileTransferredBytes + m_socket->writeBlock(m_programmingFileData.data()+m_programmingFileTransferredBytes, bytesToTransfer);
m_base->programmingProgressBar->setProgress(m_programmingFileTransferredBytes);
if (m_programmingFileTransferredBytes >= m_programmingFileTotalSize) {
// Initiate programming
m_base->programmingStatusLabel->setText(i18n("Programming device") + "...");
ds << TQString("PROGRAM");
// Request status
ds << TQString("STATUS");
m_commHandlerState = 2;
}
else {
// Fire next event loop immediately
TQTimer::singleShot(0, this, SLOT(mainEventLoop()));
}
}
else if (m_commHandlerState == 2) {
// Get response // Get response
if (m_socket->bytesAvailable() > 0) { if (m_socket->bytesAvailable() > 0) {
PAT_WATCHDOG_TIMER
// RAJA FIXME // RAJA FIXME
TQString result; TQString result;
ds >> result; ds >> result;
if (result == "PROGRAMMING") { if (result == "PROGRAMMING") {
// RAJA FIXME // Request status
ds << TQString("STATUS");
} }
else if (result == "DONE") { else if (result == "DONE") {
int retCode; int retCode;
@ -426,32 +480,63 @@ void FPGAProgramPart::mainEventLoop() {
// RAJA FIXME // RAJA FIXME
// Handle errors // Handle errors
// This does not update the log as it should!
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);
KMessageBox::error(0, i18n("<qt>Programming process failure<p>Please see log for details</qt>"), i18n("Program Failed"));
processLockouts();
}
// Done! // Done!
m_commHandlerMode = 0; m_commHandlerMode = 0;
m_commHandlerState = 0; m_commHandlerState = 0;
TQTimer::singleShot(0, this, SLOT(mainEventLoop()));
m_base->programmingProgressBar->setTotalSteps(1); m_base->programmingProgressBar->setTotalSteps(1);
m_base->programmingProgressBar->setProgress(0); m_base->programmingProgressBar->setProgress(0);
processLockouts(); processLockouts();
} }
} else if (result == "") {
else { // Transfer probably failed
if (!m_updateTimer->isActive()) { // Do nothing
}
else {
// Error!
m_commHandlerMode = 0;
m_commHandlerState = 0;
TQTimer::singleShot(0, this, SLOT(mainEventLoop()));
m_base->programmingProgressBar->setTotalSteps(1); m_base->programmingProgressBar->setTotalSteps(1);
m_base->programmingProgressBar->setProgress(0); m_base->programmingProgressBar->setProgress(0);
KMessageBox::error(0, i18n("<qt>Unknown error</qt>"), i18n("Program Failed"));
processLockouts();
}
}
else {
if (!m_updateTimeoutTimer->isActive()) {
m_commHandlerMode = 0; m_commHandlerMode = 0;
m_commHandlerState = 0; m_commHandlerState = 0;
TQTimer::singleShot(0, this, SLOT(mainEventLoop()));
m_base->programmingProgressBar->setTotalSteps(1);
m_base->programmingProgressBar->setProgress(0);
processLockouts(); processLockouts();
UPDATEDISPLAY_TIMEOUT UPDATEDISPLAY_TIMEOUT
} }
} }
} }
} }
SET_WATCHDOG_TIMER
} }
else { else {
m_commHandlerState = 0; m_commHandlerState = 0;
m_commHandlerMode = 0; m_commHandlerMode = 0;
} }
m_connectionMutex->unlock();
} }
KAboutData* FPGAProgramPart::createAboutData() { KAboutData* FPGAProgramPart::createAboutData() {

@ -80,7 +80,8 @@ namespace RemoteLab
FPGAProgramBase* m_base; FPGAProgramBase* m_base;
TQMutex* m_connectionMutex; TQMutex* m_connectionMutex;
TQTimer* m_connectionTimer; TQTimer* m_connectionTimer;
TQTimer* m_updateTimer; TQTimer* m_pingDelayTimer;
TQTimer* m_updateTimeoutTimer;
bool connToServerConnecting; bool connToServerConnecting;
int connToServerState; int connToServerState;
@ -91,6 +92,8 @@ namespace RemoteLab
bool m_connectionActiveAndValid; bool m_connectionActiveAndValid;
unsigned char m_tickerState; unsigned char m_tickerState;
TQByteArray m_programmingFileData; TQByteArray m_programmingFileData;
TQ_ULONG m_programmingFileTotalSize;
TQ_ULONG m_programmingFileTransferredBytes;
}; };
} }

@ -704,6 +704,11 @@ FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObj
connect(m_base->batchTestRunButton, SIGNAL(clicked()), this, SLOT(batchTestRunButtonClicked())); connect(m_base->batchTestRunButton, SIGNAL(clicked()), this, SLOT(batchTestRunButtonClicked()));
connect(m_base->dataProcessingRunButton, SIGNAL(clicked()), this, SLOT(dataProcessingRunButtonClicked())); connect(m_base->dataProcessingRunButton, SIGNAL(clicked()), this, SLOT(dataProcessingRunButtonClicked()));
connect(m_base->batchTestInputFile, SIGNAL(textChanged(const TQString &)), this, SLOT(processLockouts()));
connect(m_base->batchTestOutputFile, SIGNAL(textChanged(const TQString &)), this, SLOT(processLockouts()));
connect(m_base->dataProcessingInputFile, SIGNAL(textChanged(const TQString &)), this, SLOT(processLockouts()));
connect(m_base->dataProcessingOutputFile, SIGNAL(textChanged(const TQString &)), this, SLOT(processLockouts()));
processAllGraphicsUpdates(); processAllGraphicsUpdates();
TQTimer::singleShot(0, this, TQT_SLOT(postInit())); TQTimer::singleShot(0, this, TQT_SLOT(postInit()));
@ -1082,6 +1087,7 @@ printf("[RAJA DEBUG 400.0] Got '%s' from the server\n\r", response.ascii()); ffl
connToServerState = 4; connToServerState = 4;
connToServerConnecting = false; connToServerConnecting = false;
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData())); connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(updateDisplay())); connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(updateDisplay()));
m_tickerState = 0; m_tickerState = 0;
m_commHandlerState = 0; m_commHandlerState = 0;

@ -269,7 +269,7 @@ int TDEKerberosClientSocket::ungetch(int ch) {
} }
TQ_ULONG TDEKerberosClientSocket::bytesAvailable() const { TQ_ULONG TDEKerberosClientSocket::bytesAvailable() const {
bool ret; TQ_ULONG ret;
if (kerberosStatus() == KerberosInUse) { if (kerberosStatus() == KerberosInUse) {
ret = m_bufferLength; ret = m_bufferLength;
@ -283,9 +283,9 @@ TQ_ULONG TDEKerberosClientSocket::bytesAvailable() const {
int TDEKerberosClientSocket::processPendingData() { int TDEKerberosClientSocket::processPendingData() {
if (kerberosStatus() == KerberosInUse) { if (kerberosStatus() == KerberosInUse) {
int reclen; while (TQSocket::canReadLine()) {
int wrlen; int reclen;
if (m_bufferLength <= 0) { int wrlen;
char* buf = (char*)malloc(m_negotiatedMaxBufferSize); char* buf = (char*)malloc(m_negotiatedMaxBufferSize);
reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize);
if (reclen < 0) { if (reclen < 0) {
@ -662,7 +662,7 @@ int TDEKerberosClientSocket::transmitEncryptedData(const char* readbuf, int cc)
} }
} }
return 0; return cc;
} }
int TDEKerberosClientSocket::receiveEncryptedData(char *buf, unsigned int trunclen, bool shouldblock) { int TDEKerberosClientSocket::receiveEncryptedData(char *buf, unsigned int trunclen, bool shouldblock) {
@ -707,7 +707,7 @@ TDEKerberosClientSocket::KerberosStatus TDEKerberosClientSocket::kerberosStatus(
} }
bool TDEKerberosClientSocket::canReadData() { bool TDEKerberosClientSocket::canReadData() {
return TQSocket::canReadLine(); return (TQSocket::canReadLine() || (m_bufferLength > 0));
} }
void TDEKerberosClientSocket::setStatusMessage(TQString message) { void TDEKerberosClientSocket::setStatusMessage(TQString message) {

@ -270,7 +270,7 @@ int TDEKerberosServerSocket::ungetch(int ch) {
} }
TQ_ULONG TDEKerberosServerSocket::bytesAvailable() const { TQ_ULONG TDEKerberosServerSocket::bytesAvailable() const {
bool ret; TQ_ULONG ret;
if (kerberosStatus() == KerberosInUse) { if (kerberosStatus() == KerberosInUse) {
ret = m_bufferLength; ret = m_bufferLength;
@ -284,9 +284,9 @@ TQ_ULONG TDEKerberosServerSocket::bytesAvailable() const {
int TDEKerberosServerSocket::processPendingData() { int TDEKerberosServerSocket::processPendingData() {
if (kerberosStatus() == KerberosInUse) { if (kerberosStatus() == KerberosInUse) {
int reclen; while (TQSocket::canReadLine()) {
int wrlen; int reclen;
if (m_bufferLength <= 0) { int wrlen;
char* buf = (char*)malloc(m_negotiatedMaxBufferSize); char* buf = (char*)malloc(m_negotiatedMaxBufferSize);
reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize); reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize);
if (reclen < 0) { if (reclen < 0) {
@ -671,7 +671,7 @@ int TDEKerberosServerSocket::transmitEncryptedData(const char* readbuf, int cc)
} }
} }
return 0; return cc;
} }
int TDEKerberosServerSocket::receiveEncryptedData(char *buf, unsigned int trunclen, bool shouldblock) { int TDEKerberosServerSocket::receiveEncryptedData(char *buf, unsigned int trunclen, bool shouldblock) {
@ -716,7 +716,7 @@ TDEKerberosServerSocket::KerberosStatus TDEKerberosServerSocket::kerberosStatus(
} }
bool TDEKerberosServerSocket::canReadData() { bool TDEKerberosServerSocket::canReadData() {
return TQSocket::canReadLine(); return (TQSocket::canReadLine() || (m_bufferLength > 0));
} }
void TDEKerberosServerSocket::setStatusMessage(TQString message) { void TDEKerberosServerSocket::setStatusMessage(TQString message) {

@ -49,6 +49,7 @@ AuthSocket::AuthSocket(int sock, TQObject *parent, const char *name) :
connect(m_kerberosInitTimer, SIGNAL(timeout()), this, SLOT(finishKerberosHandshake())); connect(m_kerberosInitTimer, SIGNAL(timeout()), this, SLOT(finishKerberosHandshake()));
setServiceName("remotefpga"); setServiceName("remotefpga");
m_loopBuffer.resize(8192); // 8kB
line = 0; line = 0;
connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler())); connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler()));
@ -262,17 +263,16 @@ int AuthSocket::servLoop() {
break; break;
case 4: case 4:
if (m_servClientSocket->state() == TQSocket::Connected) { if (m_servClientSocket->state() == TQSocket::Connected) {
TQByteArray ba(8192);
TQ_ULONG reclen; TQ_ULONG reclen;
if (canReadData()) { if (canReadData()) {
reclen = readBlock(ba.data(), 8192); reclen = readBlock(m_loopBuffer.data(), m_loopBuffer.size());
m_servClientSocket->writeBlock(ba.data(), reclen); m_servClientSocket->writeBlock(m_loopBuffer.data(), reclen);
transferred_data = true; transferred_data = true;
} }
if (m_servClientSocket->canReadData()) { if (m_servClientSocket->canReadData()) {
reclen = m_servClientSocket->readBlock(ba.data(), 8192); reclen = m_servClientSocket->readBlock(m_loopBuffer.data(), m_loopBuffer.size());
writeBlock(ba.data(), reclen); writeBlock(m_loopBuffer.data(), reclen);
transferred_data = true; transferred_data = true;
} }
} }

@ -77,6 +77,7 @@ class AuthSocket : public TDEKerberosServerSocket
TQTimer* m_kerberosInitTimer; TQTimer* m_kerberosInitTimer;
TQTimer* m_loopTimer; TQTimer* m_loopTimer;
TQByteArray m_loopBuffer;
KSimpleConfig* m_config; KSimpleConfig* m_config;
TQSqlDatabase* m_database; TQSqlDatabase* m_database;

@ -35,6 +35,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <tqtimer.h> #include <tqtimer.h>
#include <tqfile.h>
#include <klocale.h> #include <klocale.h>
@ -45,6 +46,9 @@
delete s; \ delete s; \
s = NULL; s = NULL;
//#define NETWORK_COMM_TIMEOUT_MS 2000
#define NETWORK_COMM_TIMEOUT_MS 4000
/* exception handling */ /* exception handling */
struct exit_exception { struct exit_exception {
int c; int c;
@ -62,6 +66,7 @@ FPGASocket::FPGASocket(int sock, TQObject *parent, const char *name) :
// Initialize timers // Initialize timers
m_kerberosInitTimer = new TQTimer(); m_kerberosInitTimer = new TQTimer();
connect(m_kerberosInitTimer, SIGNAL(timeout()), this, SLOT(finishKerberosHandshake())); connect(m_kerberosInitTimer, SIGNAL(timeout()), this, SLOT(finishKerberosHandshake()));
m_servClientTimeout = new TQTimer();
setServiceName("remotefpga"); setServiceName("remotefpga");
@ -72,6 +77,11 @@ FPGASocket::FPGASocket(int sock, TQObject *parent, const char *name) :
} }
FPGASocket::~FPGASocket() { FPGASocket::~FPGASocket() {
if (m_servClientTimeout) {
m_servClientTimeout->stop();
delete m_servClientTimeout;
m_servClientTimeout = NULL;
}
if (m_kerberosInitTimer) { if (m_kerberosInitTimer) {
m_kerberosInitTimer->stop(); m_kerberosInitTimer->stop();
delete m_kerberosInitTimer; delete m_kerberosInitTimer;
@ -123,6 +133,8 @@ void FPGASocket::finishKerberosHandshake() {
return; return;
} }
setDataTimeout(NETWORK_COMM_TIMEOUT_MS);
TQDataStream ds(this); TQDataStream ds(this);
ds << TQString("OK"); ds << TQString("OK");
@ -144,7 +156,71 @@ void FPGASocket::commandLoop() {
transferred_data = false; transferred_data = false;
if (state() == TQSocket::Connected) { if (state() == TQSocket::Connected) {
if (m_commandLoopState == 0) { 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--; m_criticalSection--;

@ -63,10 +63,14 @@ class FPGASocket : public TDEKerberosServerSocket
TQTimer* m_kerberosInitTimer; TQTimer* m_kerberosInitTimer;
TQTimer* m_loopTimer; TQTimer* m_loopTimer;
TQTimer* m_servClientTimeout;
KSimpleConfig* m_config; KSimpleConfig* m_config;
int m_commandLoopState; int m_commandLoopState;
TQ_ULONG m_programmingFileSize;
TQString m_programmingFileName;
friend class FPGAServer; friend class FPGAServer;
}; };

Loading…
Cancel
Save