Fix a variety of issues

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

@ -57,7 +57,7 @@
//#define SERVER_TIMEOUT_MS 10000
// RAJA DEBUG ONLY
#define SERVER_TIMEOUT_MS 100000
#define FPGA_COMM_TIMEOUT_MS 500
#define NETWORK_COMM_TIMEOUT_MS 2500
#define FPGA_DATA_PROCESSING_TIMEOUT_MS 2500
namespace RemoteLab {
@ -78,15 +78,19 @@ FPGAProgramPart::FPGAProgramPart(TQWidget *parentWidget, const char *widgetName,
setWidget(new TQVBox(parentWidget, widgetName));
// Create timers
m_updateTimer = new TQTimer(this);
m_connectionTimer = new TQTimer(this);
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
m_base = new FPGAProgramBase(widget());
// Initialize widgets
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()));
}
@ -139,7 +143,7 @@ void FPGAProgramPart::connectionClosed() {
}
void FPGAProgramPart::postInit() {
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop()));
//
}
bool FPGAProgramPart::openURL(const KURL &url) {
@ -157,7 +161,7 @@ bool FPGAProgramPart::closeURL() {
void FPGAProgramPart::disconnectFromServer() {
m_connectionTimer->stop();
m_updateTimer->stop();
m_updateTimeoutTimer->stop();
if (m_socket) {
m_socket->clearPendingData();
m_socket->close();
@ -246,16 +250,17 @@ void FPGAProgramPart::finishConnectingToServer() {
TQDataStream ds(m_socket);
TQString response;
ds >> response;
printf("[RAJA DEBUG 400.0] Got '%s' from the server\n\r", response.ascii()); fflush(stdout);
if (response == "OK") {
connToServerState = 4;
connToServerConnecting = false;
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(mainEventLoop()));
m_tickerState = 0;
m_commHandlerState = 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();
mainEventLoop();
return;
@ -311,13 +316,21 @@ void FPGAProgramPart::programRunButtonClicked() {
m_socket->readBlock(data, 64); \
} \
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;
#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() {
m_updateTimer->stop();
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) {
char data[64];
@ -329,16 +342,24 @@ void FPGAProgramPart::mainEventLoop() {
// RAJA FIXME
ds << TQString("STATUS");
m_updateTimer->start(FPGA_COMM_TIMEOUT_MS, FALSE);
m_commHandlerState = 1;
break;
case 1:
// Get all data
if (m_socket->bytesAvailable() > 0) {
PAT_WATCHDOG_TIMER
// RAJA FIXME
TQStringList statusDetails;
ds >> statusDetails;
TQString status;
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;
TQString tickerChar;
@ -361,16 +382,24 @@ void FPGAProgramPart::mainEventLoop() {
if (m_tickerState > 3) {
m_tickerState = 0;
}
m_updateTimer->start(FPGA_COMM_TIMEOUT_MS, FALSE);
m_commHandlerState = 0;
m_pingDelayTimer->start(250, TRUE);
m_commHandlerState = 2;
}
else {
if (!m_updateTimer->isActive()) {
if (!m_updateTimeoutTimer->isActive()) {
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;
}
}
@ -386,15 +415,14 @@ void FPGAProgramPart::mainEventLoop() {
m_base->programmingProgressBar->setTotalSteps(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");
// RAJA FIXME
// Transmit file to remote server...
ds << m_programmingFileData;
m_base->programmingStatusLabel->setText(i18n("Programming device") + "...");
ds << TQString("PROGRAM");
m_programmingFileTotalSize = m_programmingFileData.size();
m_programmingFileTransferredBytes = 0;
ds << m_programmingFileTotalSize;
m_base->programmingProgressBar->setTotalSteps(m_programmingFileTotalSize);
m_commHandlerState = 1;
}
@ -408,14 +436,40 @@ void FPGAProgramPart::mainEventLoop() {
}
}
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
if (m_socket->bytesAvailable() > 0) {
PAT_WATCHDOG_TIMER
// RAJA FIXME
TQString result;
ds >> result;
if (result == "PROGRAMMING") {
// RAJA FIXME
// Request status
ds << TQString("STATUS");
}
else if (result == "DONE") {
int retCode;
@ -426,32 +480,63 @@ void FPGAProgramPart::mainEventLoop() {
// RAJA FIXME
// 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!
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 (!m_updateTimer->isActive()) {
else if (result == "") {
// Transfer probably failed
// Do nothing
}
else {
// 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>Unknown error</qt>"), i18n("Program Failed"));
processLockouts();
}
}
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);
processLockouts();
UPDATEDISPLAY_TIMEOUT
}
}
}
}
SET_WATCHDOG_TIMER
}
else {
m_commHandlerState = 0;
m_commHandlerMode = 0;
}
m_connectionMutex->unlock();
}
KAboutData* FPGAProgramPart::createAboutData() {

@ -80,7 +80,8 @@ namespace RemoteLab
FPGAProgramBase* m_base;
TQMutex* m_connectionMutex;
TQTimer* m_connectionTimer;
TQTimer* m_updateTimer;
TQTimer* m_pingDelayTimer;
TQTimer* m_updateTimeoutTimer;
bool connToServerConnecting;
int connToServerState;
@ -91,6 +92,8 @@ namespace RemoteLab
bool m_connectionActiveAndValid;
unsigned char m_tickerState;
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->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();
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;
connToServerConnecting = false;
connect(m_socket, SIGNAL(readyRead()), m_socket, SLOT(processPendingData()));
m_socket->processPendingData();
connect(m_socket, SIGNAL(newDataReceived()), this, SLOT(updateDisplay()));
m_tickerState = 0;
m_commHandlerState = 0;

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

@ -270,7 +270,7 @@ int TDEKerberosServerSocket::ungetch(int ch) {
}
TQ_ULONG TDEKerberosServerSocket::bytesAvailable() const {
bool ret;
TQ_ULONG ret;
if (kerberosStatus() == KerberosInUse) {
ret = m_bufferLength;
@ -284,9 +284,9 @@ TQ_ULONG TDEKerberosServerSocket::bytesAvailable() const {
int TDEKerberosServerSocket::processPendingData() {
if (kerberosStatus() == KerberosInUse) {
int reclen;
int wrlen;
if (m_bufferLength <= 0) {
while (TQSocket::canReadLine()) {
int reclen;
int wrlen;
char* buf = (char*)malloc(m_negotiatedMaxBufferSize);
reclen = receiveEncryptedData(buf, m_negotiatedMaxBufferSize);
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) {
@ -716,7 +716,7 @@ TDEKerberosServerSocket::KerberosStatus TDEKerberosServerSocket::kerberosStatus(
}
bool TDEKerberosServerSocket::canReadData() {
return TQSocket::canReadLine();
return (TQSocket::canReadLine() || (m_bufferLength > 0));
}
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()));
setServiceName("remotefpga");
m_loopBuffer.resize(8192); // 8kB
line = 0;
connect(this, SIGNAL(connectionClosed()), SLOT(connectionClosedHandler()));
@ -262,17 +263,16 @@ int AuthSocket::servLoop() {
break;
case 4:
if (m_servClientSocket->state() == TQSocket::Connected) {
TQByteArray ba(8192);
TQ_ULONG reclen;
if (canReadData()) {
reclen = readBlock(ba.data(), 8192);
m_servClientSocket->writeBlock(ba.data(), reclen);
reclen = readBlock(m_loopBuffer.data(), m_loopBuffer.size());
m_servClientSocket->writeBlock(m_loopBuffer.data(), reclen);
transferred_data = true;
}
if (m_servClientSocket->canReadData()) {
reclen = m_servClientSocket->readBlock(ba.data(), 8192);
writeBlock(ba.data(), reclen);
reclen = m_servClientSocket->readBlock(m_loopBuffer.data(), m_loopBuffer.size());
writeBlock(m_loopBuffer.data(), reclen);
transferred_data = true;
}
}

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

@ -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--;

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

Loading…
Cancel
Save