summaryrefslogtreecommitdiffstats
path: root/clients/tde/src
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-07-20 14:10:10 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-07-20 14:10:10 -0500
commit9c3d84d0df528e8463906ac6399d651792b7ade6 (patch)
tree499ef6438918f70f499fb0661ceb9c3382cf5107 /clients/tde/src
parent0f3b0430e86e45b4a2fca4bc68b013c7f1b484aa (diff)
downloadulab-9c3d84d0df528e8463906ac6399d651792b7ade6.tar.gz
ulab-9c3d84d0df528e8463906ac6399d651792b7ade6.zip
Fix FPGA programmer
Diffstat (limited to 'clients/tde/src')
-rw-r--r--clients/tde/src/app/views/instrumentview.cpp18
-rw-r--r--clients/tde/src/app/views/instrumentview.h2
-rw-r--r--clients/tde/src/part/fpgaprogram/layout.ui20
-rw-r--r--clients/tde/src/part/fpgaprogram/part.cpp177
-rw-r--r--clients/tde/src/part/fpgaprogram/part.h3
5 files changed, 145 insertions, 75 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;