diff options
Diffstat (limited to 'clients')
-rw-r--r-- | clients/tde/src/part/Makefile.am | 2 | ||||
-rw-r--r-- | clients/tde/src/part/fpgaprogram/part.cpp | 2 | ||||
-rw-r--r-- | clients/tde/src/part/sensormonitor/Makefile.am | 11 | ||||
-rw-r--r-- | clients/tde/src/part/sensormonitor/hi16-action-libremotelab_sensormonitor.png | bin | 0 -> 913 bytes | |||
-rw-r--r-- | clients/tde/src/part/sensormonitor/layout.ui | 146 | ||||
-rw-r--r-- | clients/tde/src/part/sensormonitor/part.cpp | 297 | ||||
-rw-r--r-- | clients/tde/src/part/sensormonitor/part.h | 96 |
7 files changed, 552 insertions, 2 deletions
diff --git a/clients/tde/src/part/Makefile.am b/clients/tde/src/part/Makefile.am index cdb75aa..55afedd 100644 --- a/clients/tde/src/part/Makefile.am +++ b/clients/tde/src/part/Makefile.am @@ -1 +1 @@ -SUBDIRS = scope commanalyzer fpgaview fpgaprogram +SUBDIRS = scope commanalyzer fpgaview fpgaprogram sensormonitor diff --git a/clients/tde/src/part/fpgaprogram/part.cpp b/clients/tde/src/part/fpgaprogram/part.cpp index cf35dcf..a9dd169 100644 --- a/clients/tde/src/part/fpgaprogram/part.cpp +++ b/clients/tde/src/part/fpgaprogram/part.cpp @@ -363,7 +363,7 @@ void FPGAProgramPart::mainEventLoop() { break; } } - else if (m_commHandlerMode == 1) { + else if (m_commHandlerMode == ModeProgramming) { // Program mode! if (m_commHandlerState == ModeProgramming_StateReadFile) { m_base->programmingStatusLabel->setText(i18n("Reading input file") + "..."); diff --git a/clients/tde/src/part/sensormonitor/Makefile.am b/clients/tde/src/part/sensormonitor/Makefile.am new file mode 100644 index 0000000..7a0fb82 --- /dev/null +++ b/clients/tde/src/part/sensormonitor/Makefile.am @@ -0,0 +1,11 @@ +INCLUDES = $(all_includes) -I$(top_srcdir)/src -I$(top_srcdir)/src/widgets $(KDE_INCLUDES)/tde +KDE_CXXFLAGS = $(USE_EXCEPTIONS) +METASOURCES = AUTO + +KDE_ICON = libremotelab_sensormonitor + +# Part +kde_module_LTLIBRARIES = libremotelab_sensormonitor.la +libremotelab_sensormonitor_la_LIBADD = ../../widgets/libtracewidget.la ../../widgets/libfloatspinbox.la $(LIB_KFILE) $(LIB_KPARTS) $(LIB_TDEUI) $(LIB_QT) -ltdekrbsocket -ltqtrla +libremotelab_sensormonitor_la_LDFLAGS = $(all_libraries) $(KDE_PLUGIN) $(LIB_TDECORE) $(LIB_TDEUI) -lkio -ltdefx +libremotelab_sensormonitor_la_SOURCES = part.cpp layout.ui diff --git a/clients/tde/src/part/sensormonitor/hi16-action-libremotelab_sensormonitor.png b/clients/tde/src/part/sensormonitor/hi16-action-libremotelab_sensormonitor.png Binary files differnew file mode 100644 index 0000000..1c2e678 --- /dev/null +++ b/clients/tde/src/part/sensormonitor/hi16-action-libremotelab_sensormonitor.png diff --git a/clients/tde/src/part/sensormonitor/layout.ui b/clients/tde/src/part/sensormonitor/layout.ui new file mode 100644 index 0000000..f6dacfc --- /dev/null +++ b/clients/tde/src/part/sensormonitor/layout.ui @@ -0,0 +1,146 @@ +<!DOCTYPE UI><UI version="3.0" stdsetdef="1"> + <class>SensorMonitorBase</class> + <widget class="TQWidget"> + <property name="name"> + <cstring>SensorMonitorBase</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>519</width> + <height>356</height> + </rect> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQTabWidget" row="0" column="0"> + <property name="name"> + <cstring>TabWidget2</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <widget class="TQWidget"> + <property name="name"> + <cstring>tab</cstring> + </property> + <attribute name="title"> + <string>Monitor</string> + </attribute> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQGroupBox" row="0" column="0"> + <property name="name"> + <cstring>groupMonitor</cstring> + </property> + <property name="title"> + <string>Monitor</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQGroupBox" row="0" column="0" rowspan="10"> + <property name="name"> + <cstring>groupMonitorView</cstring> + </property> + <property name="title"> + <string>Trace Viewer</string> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>7</hsizetype> + <vsizetype>7</vsizetype> + <horstretch>1</horstretch> + <verstretch>1</verstretch> + </sizepolicy> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQSplitter" row="0" column="0" colspan="1"> + <property name="name"> + <cstring>splitter1</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <widget class="TraceWidget" row="0" column="0" colspan="1"> + <property name="name"> + <cstring>traceWidget</cstring> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + </widget> + <widget class="TraceWidget" row="1" column="0" colspan="1"> + <property name="name"> + <cstring>traceZoomWidget</cstring> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>0</height> + </size> + </property> + </widget> + </widget> + </grid> + </widget> + <widget class="TQGroupBox" row="0" column="1"> + <property name="name"> + <cstring>groupMonitorCaptureControls</cstring> + </property> + <property name="title"> + <string>Capture Controls</string> + </property> + <grid> + <widget class="TQPushButton" row="0" column="0" colspan="1"> + <property name="name"> + <cstring>runControlStartButton</cstring> + </property> + <property name="text"> + <string>Run</string> + </property> + </widget> + <widget class="TQPushButton" row="0" column="1" colspan="1"> + <property name="name"> + <cstring>runControlStopButton</cstring> + </property> + <property name="text"> + <string>Stop</string> + </property> + </widget> + <widget class="TQWidget" row="1" column="0" colspan="2"> + <property name="name"> + <cstring>traceControlLayoutWidget</cstring> + </property> + </widget> + </grid> + </widget> + </grid> + </widget> + </grid> + </widget> + </widget> + </grid> + </widget> + <includes> + <include location="local" impldecl="in implementation">SensorMonitorBase.ui.h</include> + </includes> + <includes> + <include location="local" impldecl="in implementation">tracewidget.h</include> + <include location="local" impldecl="in implementation">floatspinbox.h</include> + </includes> + <layoutdefaults spacing="3" margin="6"/> + <layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/> +</UI> diff --git a/clients/tde/src/part/sensormonitor/part.cpp b/clients/tde/src/part/sensormonitor/part.cpp new file mode 100644 index 0000000..469f24d --- /dev/null +++ b/clients/tde/src/part/sensormonitor/part.cpp @@ -0,0 +1,297 @@ +/* + * Remote Laboratory FPGA Programming Part + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2012 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#include "define.h" +#include "part.h" + +#include <kaboutdata.h> //::createAboutData() +#include <kaction.h> +#include <klocale.h> +#include <ktextedit.h> +#include <kfiledialog.h> +#include <kmessagebox.h> //::start() +#include <kparts/genericfactory.h> +#include <kstatusbar.h> +#include <kstdaction.h> +#include <knuminput.h> +#include <kmdcodec.h> +#include <kurlrequester.h> +#include <tqfile.h> //encodeName() +#include <tqtimer.h> //postInit() hack +#include <tqvbox.h> +#include <tqsocket.h> +#include <tqmutex.h> +#include <tqeventloop.h> +#include <tqapplication.h> +#include <tqgroupbox.h> +#include <tqcheckbox.h> +#include <tqpushbutton.h> +#include <tqprogressbar.h> +#include <unistd.h> //access() +#include <stdint.h> + +#include <tqpainter.h> + +#include "tracewidget.h" +#include "floatspinbox.h" +#include "layout.h" + +#define NETWORK_COMM_TIMEOUT_MS 2500 + +enum connectionModes { + ModeIdle = 0 +}; + +enum connectionStates { + ModeIdle_StateStatusRequest = 0, + ModeIdle_StateProcessStatus = 1, + ModeIdle_StateDelay = 2 +}; + +namespace RemoteLab { + +typedef KParts::GenericFactory<RemoteLab::SensorMonitorPart> Factory; +#define CLIENT_LIBRARY "libremotelab_sensormonitor" +K_EXPORT_COMPONENT_FACTORY(libremotelab_sensormonitor, RemoteLab::Factory) + +SensorMonitorPart::SensorMonitorPart(TQWidget *parentWidget, const char *widgetName, TQObject *parent, const char *name, const TQStringList&) + : RemoteInstrumentPart( parent, name ), m_base(NULL), m_commHandlerState(0), m_connectionActiveAndValid(false), m_tickerState(0) +{ + // Initialize important base class variables + m_clientLibraryName = CLIENT_LIBRARY; + + // Initialize mutex + m_connectionMutex = new TQMutex(false); + + // Initialize kpart + setInstance(Factory::instance()); + 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); + connect(m_pingDelayTimer, SIGNAL(timeout()), this, SLOT(mainEventLoop())); + + // Create widgets + m_base = new SensorMonitorBase(widget()); + + // Initialize widgets + connect(m_base->runControlStartButton, SIGNAL(clicked()), this, SLOT(programStartButtonClicked())); + connect(m_base->runControlStopButton, SIGNAL(clicked()), this, SLOT(programStopButtonClicked())); + + TQTimer::singleShot(0, this, TQT_SLOT(postInit())); +} + +SensorMonitorPart::~SensorMonitorPart() { + if (m_connectionMutex->locked()) { + printf("[WARNING] Exiting when data transfer still in progress!\n\r"); fflush(stdout); + } + + disconnectFromServer(); + delete m_connectionMutex; +} + +void SensorMonitorPart::processLockouts() { + TQWidget* mainWidget = widget(); + if (mainWidget) { + if ((m_socket) && (m_socket->state() == TQSocket::Connected) && (connToServerState > 0) && (connToServerConnecting == false)) { + mainWidget->setEnabled(true); + } + else { + mainWidget->setEnabled(false); + } + } +} + +void SensorMonitorPart::resizeToHint() { + resize(widget()->sizeHint()); +} + +void SensorMonitorPart::connectionClosed() { + closeURL(); +} + +void SensorMonitorPart::postInit() { + setUsingFixedSize(false); +} + +bool SensorMonitorPart::openURL(const KURL &url) { + int ret; + ret = connectToServer(url.url()); + processLockouts(); + return (ret != 0); +} + +bool SensorMonitorPart::closeURL() { + disconnectFromServer(); + m_url = KURL(); + return true; +} + +void SensorMonitorPart::disconnectFromServerCallback() { + m_forcedUpdateTimer->stop(); + m_updateTimeoutTimer->stop(); +} + +void SensorMonitorPart::connectionFinishedCallback() { + 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 = ModeIdle_StateStatusRequest; + m_commHandlerMode = ModeIdle; + m_socket->setDataTimeout(NETWORK_COMM_TIMEOUT_MS); + m_updateTimeoutTimer->start(NETWORK_COMM_TIMEOUT_MS, TRUE); + processLockouts(); + mainEventLoop(); + return; +} + +void SensorMonitorPart::connectionStatusChangedCallback() { + processLockouts(); +} + +#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 SensorMonitorPart::setTickerMessage(TQString message) { + m_connectionActiveAndValid = true; + TQString tickerChar; + switch (m_tickerState) { + case 0: + tickerChar = "-"; + break; + case 1: + tickerChar = "\\"; + break; + case 2: + tickerChar = "|"; + break; + case 3: + tickerChar = "/"; + break; + } + setStatusMessage(message + TQString("... %1").arg(tickerChar)); + m_tickerState++; + if (m_tickerState > 3) { + m_tickerState = 0; + } +} + +void SensorMonitorPart::mainEventLoop() { + TQDataStream ds(m_socket); + ds.setPrintableData(true); + + if (!m_connectionMutex->tryLock()) { + EXEC_NEXT_STATE_IMMEDIATELY + return; + } + + if (m_socket) { + if (m_commHandlerMode == ModeIdle) { + // Normal operation + switch (m_commHandlerState) { + 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(); + + SET_NEXT_STATE(ModeIdle_StateProcessStatus) + break; + case ModeIdle_StateProcessStatus: + // Get all data + if (m_socket->canReadFrame()) { + PAT_WATCHDOG_TIMER + + TQString status; + ds >> status; + m_socket->clearFrameTail(); + + if (status == "") { + // Transfer probably failed + UPDATEDISPLAY_TIMEOUT + } + else if (status == "IDLE") { + // Do nothing + } + + setTickerMessage(i18n("Connected")); + + if (m_commHandlerState == ModeIdle_StateProcessStatus) { + m_pingDelayTimer->start(250, TRUE); + SET_NEXT_STATE(ModeIdle_StateDelay); + } + } + else { + if (!m_updateTimeoutTimer->isActive()) { + UPDATEDISPLAY_TIMEOUT + } + } + break; + case ModeIdle_StateDelay: + // Let the client and server rest for a bit to lower CPU/network overhead + if (!m_pingDelayTimer->isActive()) { + EXEC_NEXT_STATE_IMMEDIATELY + // Execute query on next event loop + SET_NEXT_STATE(ModeIdle_StateStatusRequest); + } + PAT_WATCHDOG_TIMER + break; + } + } + + SET_WATCHDOG_TIMER + } + else { + SET_NEXT_STATE(ModeIdle_StateStatusRequest); + m_commHandlerMode = ModeIdle; + } + + m_connectionMutex->unlock(); +} + +KAboutData* SensorMonitorPart::createAboutData() { + return new KAboutData( APP_NAME, I18N_NOOP( APP_PRETTYNAME ), APP_VERSION ); +} + +} //namespace RemoteLab + +#include "part.moc" diff --git a/clients/tde/src/part/sensormonitor/part.h b/clients/tde/src/part/sensormonitor/part.h new file mode 100644 index 0000000..a6c176c --- /dev/null +++ b/clients/tde/src/part/sensormonitor/part.h @@ -0,0 +1,96 @@ +/* + * Remote Laboratory FPGA Programming Part + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * (c) 2012 Timothy Pearson + * Raptor Engineering + * http://www.raptorengineeringinc.com + */ + +#ifndef REMOTELAB_FPGAPROGRAMPART_H +#define REMOTELAB_FPGAPROGRAMPART_H + +#include <tdekrbclientsocket.h> + +#include <tqcstring.h> +#include <tqframe.h> +#include <tqimage.h> + +#include <kparts/browserextension.h> +#include <kparts/statusbarextension.h> +#include <kparts/part.h> +#include <kurl.h> +#include <kled.h> + +#include <tqtrla.h> + +class KAboutData; +using KParts::StatusBarExtension; +class TraceWidget; +class TQSocket; +class TQTimer; +class TQMutex; +class TQFile; +class SensorMonitorBase; + +namespace RemoteLab +{ + class SensorMonitorPart : public KParts::RemoteInstrumentPart + { + Q_OBJECT + + public: + SensorMonitorPart(TQWidget *, const char *, TQObject *, const char *, const TQStringList&); + ~SensorMonitorPart(); + + virtual bool openFile() { return false; } // pure virtual in the base class + virtual bool closeURL(); + static KAboutData *createAboutData(); + + public slots: + virtual bool openURL(const KURL &url); + + private slots: + void postInit(); + void resizeToHint(); + void mainEventLoop(); + void processLockouts(); + void connectionClosed(); + void connectionFinishedCallback(); + void disconnectFromServerCallback(); + void connectionStatusChangedCallback(); + void setTickerMessage(TQString message); + + private: + SensorMonitorBase* m_base; + TQMutex* m_connectionMutex; + TQTimer* m_pingDelayTimer; + TQTimer* m_forcedUpdateTimer; + TQTimer* m_updateTimeoutTimer; + + int m_commHandlerState; + int m_commHandlerMode; + int m_commHandlerNextState; + int m_commHandlerNextMode; + bool m_connectionActiveAndValid; + unsigned char m_tickerState; + TQByteArray m_programmingFileData; + TQ_ULONG m_programmingFileTotalSize; + TQ_ULONG m_programmingFileTransferredBytes; + }; +} + +#endif |