@ -69,11 +69,13 @@ enum connectionStates {
ModeIdle_StateProcessSensorList = 1 ,
ModeIdle_StateStatusRequest = 2 ,
ModeIdle_StateProcessStatus = 3 ,
ModeIdle_StateDelay = 4 ,
ModeIdle_StatePaused = 5 ,
ModeIdle_StateExternalRequest = 6 ,
ModeGetSample_StateSampleRequest = 7 ,
ModeGetSample_StateProcessSample = 8
ModeIdle_StateResetRequest = 4 ,
ModeIdle_StateProcessReset = 5 ,
ModeIdle_StateDelay = 6 ,
ModeIdle_StatePaused = 7 ,
ModeIdle_StateExternalRequest = 8 ,
ModeGetSample_StateSampleRequest = 9 ,
ModeGetSample_StateProcessSample = 10
} ;
namespace RemoteLab {
@ -119,10 +121,31 @@ TraceControlWidget::TraceControlWidget(TQWidget *parent, const char *name)
m_channelEnabledCheckBox - > setText ( i18n ( " Enable " ) ) ;
m_primaryLayout - > addMultiCellWidget ( m_channelEnabledCheckBox , 0 , 0 , 0 , 0 ) ;
m_valueLabel = new TQLabel ( m_groupBox ) ;
m_valueLabel - > setText ( i18n ( " <qt><nobr>Value: <b>%1</b></qt> " ) . arg ( i18n ( " <unknown> " ) ) ) ;
m_primaryLayout - > addMultiCellWidget ( m_valueLabel , 1 , 1 , 0 , 1 ) ;
m_valueLabel - > hide ( ) ;
m_timestampLabel = new TQLabel ( m_groupBox ) ;
m_timestampLabel - > setText ( i18n ( " <qt><nobr>Sampled: <b>%1</b></qt> " ) . arg ( i18n ( " <unknown> " ) ) ) ;
m_primaryLayout - > addMultiCellWidget ( m_timestampLabel , 2 , 2 , 0 , 1 ) ;
m_timestampLabel - > hide ( ) ;
m_timestepLabel1 = new TQLabel ( m_groupBox ) ;
m_timestepLabel1 - > setText ( i18n ( " Sample every: " ) ) ;
m_primaryLayout - > addMultiCellWidget ( m_timestepLabel1 , 3 , 3 , 0 , 0 ) ;
m_timestepLabel1 - > hide ( ) ;
m_timestepSpinBox = new FloatSpinBox ( m_groupBox ) ;
m_timestepSpinBox - > setFloatMax ( 60 * 60 * 24 ) ; // 1 day
connect ( m_timestepSpinBox , SIGNAL ( floatValueChanged ( double ) ) , this , SLOT ( timestepChanged ( double ) ) ) ;
m_primaryLayout - > addMultiCellWidget ( m_timestepSpinBox , 0 , 0 , 1 , 1 ) ;
m_primaryLayout - > addMultiCellWidget ( m_timestepSpinBox , 4 , 4 , 0 , 0 ) ;
m_timestepSpinBox - > hide ( ) ;
m_timestepLabel2 = new TQLabel ( m_groupBox ) ;
m_timestepLabel2 - > setText ( i18n ( " seconds " ) ) ;
m_primaryLayout - > addMultiCellWidget ( m_timestepLabel2 , 4 , 4 , 1 , 1 ) ;
m_timestepLabel2 - > hide ( ) ;
m_sampleTimer = new TQTimer ( ) ;
connect ( m_sampleTimer , SIGNAL ( timeout ( ) ) , this , SIGNAL ( newSampleDesired ( ) ) ) ;
@ -149,12 +172,30 @@ void TraceControlWidget::stopSampleTimer() {
void TraceControlWidget : : setTraceEnabled ( bool enabled ) {
m_channelEnabledCheckBox - > setChecked ( enabled ) ;
if ( enabled ) {
m_timestepLabel1 - > show ( ) ;
m_timestepLabel2 - > show ( ) ;
m_timestepSpinBox - > show ( ) ;
m_valueLabel - > show ( ) ;
m_timestampLabel - > show ( ) ;
}
else {
m_timestepLabel1 - > hide ( ) ;
m_timestepLabel2 - > hide ( ) ;
m_timestepSpinBox - > hide ( ) ;
m_valueLabel - > hide ( ) ;
m_timestampLabel - > hide ( ) ;
}
}
void TraceControlWidget : : setTraceName ( TQString name ) {
m_groupBox - > setTitle ( name ) ;
}
double TraceControlWidget : : timestep ( ) {
return m_nominalTimeStep ;
}
void TraceControlWidget : : setTimestep ( double seconds ) {
m_nominalTimeStep = seconds ;
m_timestepSpinBox - > setFloatValue ( m_nominalTimeStep ) ;
@ -177,6 +218,14 @@ void TraceControlWidget::timestepChanged(double value) {
startSampleTimer ( value * 1.0e3 ) ;
}
void TraceControlWidget : : setCurrentSampleValue ( double value , TQString units ) {
m_valueLabel - > setText ( i18n ( " <qt><nobr>Value: <b>%1%2</b></qt> " ) . arg ( value ) . arg ( units ) ) ;
}
void TraceControlWidget : : setCurrentSampleTimestamp ( TQDateTime timestamp ) {
m_timestampLabel - > setText ( i18n ( " <qt><nobr>Sampled: <b>%1</b></qt> " ) . arg ( timestamp . toString ( ) ) ) ;
}
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 ) , stopTraceUpdate ( false )
{
@ -249,6 +298,9 @@ SensorMonitorPart::SensorMonitorPart(TQWidget *parentWidget, const char *widgetN
// Initialize widgets
connect ( m_base - > runControlStartButton , SIGNAL ( clicked ( ) ) , this , SLOT ( acquisitionStartButtonClicked ( ) ) ) ;
connect ( m_base - > runControlStopButton , SIGNAL ( clicked ( ) ) , this , SLOT ( acquisitionStopButtonClicked ( ) ) ) ;
connect ( m_base - > waveformSave , SIGNAL ( clicked ( ) ) , this , SLOT ( saveWaveforms ( ) ) ) ;
connect ( m_base - > waveformRecall , SIGNAL ( clicked ( ) ) , this , SLOT ( recallWaveforms ( ) ) ) ;
connect ( m_base - > autoSave , SIGNAL ( clicked ( ) ) , this , SLOT ( processLockouts ( ) ) ) ;
TQTimer : : singleShot ( 0 , this , TQT_SLOT ( postInit ( ) ) ) ;
}
@ -275,10 +327,23 @@ void SensorMonitorPart::processLockouts() {
if ( stopTraceUpdate ) {
m_base - > runControlStartButton - > setEnabled ( true ) ;
m_base - > runControlStopButton - > setEnabled ( false ) ;
m_base - > waveformSave - > setEnabled ( true ) ;
m_base - > waveformRecall - > setEnabled ( true ) ;
m_base - > autoSave - > setEnabled ( true ) ;
if ( m_base - > autoSave - > isOn ( ) ) {
m_base - > autoSaveFile - > setEnabled ( true ) ;
}
else {
m_base - > autoSaveFile - > setEnabled ( false ) ;
}
}
else {
m_base - > runControlStartButton - > setEnabled ( false ) ;
m_base - > runControlStopButton - > setEnabled ( true ) ;
m_base - > waveformSave - > setEnabled ( false ) ;
m_base - > waveformRecall - > setEnabled ( false ) ;
m_base - > autoSave - > setEnabled ( false ) ;
m_base - > autoSaveFile - > setEnabled ( false ) ;
}
}
@ -332,7 +397,9 @@ void SensorMonitorPart::connectionStatusChangedCallback() {
# define UPDATEDISPLAY_TIMEOUT m_connectionActiveAndValid = false; \
m_tickerState = 0 ; \
m_commHandlerState = ModeIdle_StateStatusRequest ; \
if ( m_commHandlerState ! = ModeIdle_StateProcessReset ) { \
m_commHandlerState = ModeIdle_StateResetRequest ; \
} \
m_commHandlerMode = ModeIdle ; \
for ( int traceno = 0 ; traceno < = MAXTRACES ; traceno + + ) { \
m_sampleRequestInProgress [ traceno ] = false ; \
@ -456,6 +523,33 @@ void SensorMonitorPart::mainEventLoop() {
}
}
break ;
case ModeIdle_StateResetRequest :
// Reset remote system
ds < < TQString ( " RESET " ) ;
m_socket - > writeEndOfFrame ( ) ;
SET_NEXT_STATE_DATA_WAITING ( ModeIdle_StateProcessReset )
break ;
case ModeIdle_StateProcessReset :
// Get all data
if ( m_socket - > canReadFrame ( ) ) {
PAT_WATCHDOG_TIMER
TQString status ;
ds > > status ;
m_socket - > clearFrameTail ( ) ;
if ( status = = " RESET " ) {
SET_NEXT_STATE ( ModeIdle_StateStatusRequest )
EXEC_NEXT_STATE_IMMEDIATELY
}
}
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 ( ) ) {
@ -509,11 +603,15 @@ void SensorMonitorPart::mainEventLoop() {
m_base - > traceZoomWidget - > setSamples ( m_sampleRequestIndex , sampleArray ) ;
m_base - > traceZoomWidget - > setPositions ( m_sampleRequestIndex , positionArray ) ;
m_traceControlWidgetList [ m_sampleRequestIndex ] - > setCurrentSampleValue ( newValue , m_sensorList [ m_sampleRequestIndex ] . units ) ;
m_traceControlWidgetList [ m_sampleRequestIndex ] - > setCurrentSampleTimestamp ( timestamp ) ;
updateGraticule ( ) ;
m_traceWidget - > repaint ( false ) ;
m_base - > traceZoomWidget - > repaint ( false ) ;
}
processAutosave ( ) ;
m_socket - > clearFrameTail ( ) ;
m_sampleRequestInProgress [ m_sampleRequestIndex ] = false ;
m_commHandlerMode = ModeIdle ;
@ -569,12 +667,12 @@ void SensorMonitorPart::updateGraticule() {
for ( int traceno = 0 ; traceno < m_maxNumberOfTraces ; traceno + + ) {
m_traceWidget - > setTraceEnabled ( traceno , m_channelActive [ traceno ] ) ;
m_traceWidget - > setTraceName ( traceno , m_sensorList[ traceno ] . name ) ;
m_traceWidget - > setTraceName ( traceno , i18n( " Sensor %1 " ) . arg ( m_sensorList[ traceno ] . name ) ) ;
m_traceWidget - > setTraceHorizontalUnits ( traceno , " s " ) ;
m_traceWidget - > setTraceVerticalUnits ( traceno , m_sensorList [ traceno ] . units ) ;
m_base - > traceZoomWidget - > setTraceEnabled ( traceno , m_channelActive [ traceno ] , false ) ;
m_base - > traceZoomWidget - > setTraceName ( traceno , m_sensorList[ traceno ] . name ) ;
m_base - > traceZoomWidget - > setTraceName ( traceno , i18n( " Sensor %1 " ) . arg ( m_sensorList[ traceno ] . name ) ) ;
m_base - > traceZoomWidget - > setTraceHorizontalUnits ( traceno , " s " ) ;
m_base - > traceZoomWidget - > setTraceVerticalUnits ( traceno , m_sensorList [ traceno ] . units ) ;
@ -604,7 +702,7 @@ void SensorMonitorPart::updateTraceControlWidgets() {
connect ( m_traceControlWidgetList [ i ] , SIGNAL ( enableChanged ( bool ) ) , this , SLOT ( traceControlEnableChanged ( bool ) ) ) ;
connect ( m_traceControlWidgetList [ i ] , SIGNAL ( newSampleDesired ( ) ) , this , SLOT ( processNewSampleRequest ( ) ) ) ;
m_traceControlWidgetGrid - > addMultiCellWidget ( m_traceControlWidgetList [ i ] , i , i , 0 , 0 ) ;
m_traceControlWidgetList [ i ] - > setTraceName ( m_sensorList[ i ] . name ) ;
m_traceControlWidgetList [ i ] - > setTraceName ( i18n( " Sensor %1 " ) . arg ( m_sensorList[ i ] . name ) ) ;
m_traceControlWidgetList [ i ] - > show ( ) ;
// Set sample rate
m_traceControlWidgetList [ i ] - > setMinTimestep ( m_sensorList [ i ] . mininterval ) ;
@ -653,13 +751,13 @@ void SensorMonitorPart::processNewSampleRequest() {
}
}
if ( ( channel > = 0 ) & & ( channel < = MAXTRACES ) ) {
if ( ! stopTraceUpdate ) {
if ( ( ! stopTraceUpdate ) & & ( m_commHandlerState ! = ModeIdle_StateProcessReset ) & & ( m_commHandlerState ! = ModeIdle_StateResetRequest ) ) {
if ( ! m_sampleRequestInProgress [ channel ] ) {
m_sampleRequestInProgress [ channel ] = true ;
processNewSampleRequest ( channel ) ;
}
else {
printf( " [WARNING] Sample request made while previous sample not collected. Some data was not captured (therefore lost)...\n \r " ) ;
setStatusMessage( i18n ( " Sample request made while previous sample not collected. Some data was not captured (therefore lost) for sensor %1" ) . arg ( m_sensorList [ channel ] . name ) ) ;
}
}
}
@ -688,11 +786,13 @@ void SensorMonitorPart::processNewSampleRequest(int channel) {
else {
// The main loop is already getting a sample
// Resubmit the request later on
if ( ( ! stopTraceUpdate ) & & ( m_commHandlerState ! = ModeIdle_StateProcessReset ) & & ( m_commHandlerState ! = ModeIdle_StateResetRequest ) ) {
TQValueTimer * timer = new TQValueTimer ;
timer - > setValue ( channel ) ;
connect ( timer , SIGNAL ( valueTimeout ( int ) ) , this , SLOT ( processNewSampleRequest ( int ) ) ) ;
timer - > start ( 10 , TRUE ) ;
}
}
}
void SensorMonitorPart : : acquisitionStartButtonClicked ( ) {
@ -716,6 +816,112 @@ void SensorMonitorPart::acquisitionStopButtonClicked() {
mainEventLoop ( ) ;
}
void SensorMonitorPart : : processAutosave ( ) {
if ( m_base - > autoSave - > isOn ( ) ) {
if ( m_base - > autoSaveFile - > url ( ) ! = " " ) {
saveWaveforms ( m_base - > autoSaveFile - > url ( ) ) ;
}
}
}
# define WAVEFORM_MAGIC_NUMBER 2
# define WAVEFORM_FILE_VERSION 1
void SensorMonitorPart : : saveWaveforms ( ) {
saveWaveforms ( TQString : : null ) ;
}
void SensorMonitorPart : : saveWaveforms ( TQString fileName ) {
TQString saveFileName ;
if ( fileName ! = " " ) {
saveFileName = fileName ;
}
else {
saveFileName = KFileDialog : : getSaveFileName ( TQString : : null , " *.wfm|Waveform Files (*.wfm) " , 0 , i18n ( " Save waveforms... " ) ) ;
}
if ( saveFileName ! = " " ) {
TQFile file ( saveFileName ) ;
file . open ( IO_WriteOnly ) ;
TQDataStream ds ( & file ) ;
TQ_INT32 magicNumber = WAVEFORM_MAGIC_NUMBER ;
TQ_INT32 version = WAVEFORM_FILE_VERSION ;
ds < < magicNumber ;
ds < < version ;
ds < < m_sensorList ;
ds < < m_hdivs ;
ds < < m_vdivs ;
ds < < m_maxNumberOfTraces ;
for ( int traceno = 0 ; traceno < m_maxNumberOfTraces ; traceno + + ) {
TQ_UINT8 boolValue ;
boolValue = m_channelActive [ traceno ] ;
ds < < boolValue ;
ds < < m_traceControlWidgetList [ traceno ] - > timestep ( ) ;
ds < < m_samplesInTrace [ traceno ] ;
ds < < m_traceUnits [ traceno ] ;
ds < < m_traceWidget - > samples ( traceno ) ;
ds < < m_traceWidget - > positions ( traceno ) ;
}
for ( int cursorno = 0 ; cursorno < 4 ; cursorno + + ) {
ds < < m_traceWidget - > cursorPosition ( cursorno ) ;
}
}
}
void SensorMonitorPart : : recallWaveforms ( ) {
TQString openFileName = KFileDialog : : getOpenFileName ( TQString : : null , " *.wfm|Waveform Files (*.wfm) " , 0 , i18n ( " Open waveforms... " ) ) ;
if ( openFileName ! = " " ) {
TQFile file ( openFileName ) ;
file . open ( IO_ReadOnly ) ;
TQDataStream ds ( & file ) ;
TQ_INT32 magicNumber ;
TQ_INT32 version ;
ds > > magicNumber ;
if ( magicNumber = = WAVEFORM_MAGIC_NUMBER ) {
ds > > version ;
if ( version = = WAVEFORM_FILE_VERSION ) {
ds > > m_sensorList ;
ds > > m_hdivs ;
ds > > m_vdivs ;
ds > > m_maxNumberOfTraces ;
updateTraceControlWidgets ( ) ;
for ( int traceno = 0 ; traceno < m_maxNumberOfTraces ; traceno + + ) {
TQ_UINT8 boolValue ;
ds > > boolValue ;
m_channelActive [ traceno ] = ( boolValue ! = 0 ) ? true : false ;
double timestep ;
ds > > timestep ;
m_traceControlWidgetList [ traceno ] - > setTimestep ( timestep ) ;
ds > > m_samplesInTrace [ traceno ] ;
ds > > m_traceUnits [ traceno ] ;
TQDoubleArray values ;
TQDoubleArray positions ;
ds > > values ;
ds > > positions ;
m_traceWidget - > setSamples ( traceno , values ) ;
m_traceWidget - > setPositions ( traceno , positions ) ;
m_base - > traceZoomWidget - > setSamples ( traceno , values ) ;
m_base - > traceZoomWidget - > setPositions ( traceno , positions ) ;
}
for ( int cursorno = 0 ; cursorno < 4 ; cursorno + + ) {
double cursorPos ;
ds > > cursorPos ;
m_traceWidget - > setCursorPosition ( cursorno , cursorPos ) ;
}
updateGraticule ( ) ;
m_traceWidget - > repaint ( false ) ;
m_base - > traceZoomWidget - > repaint ( false ) ;
updateTraceControlWidgets ( ) ;
}
else {
KMessageBox : : error ( 0 , i18n ( " <qt>The selected waveform file version does not match this client</qt> " ) , i18n ( " Invalid File " ) ) ;
}
}
else {
KMessageBox : : error ( 0 , i18n ( " <qt>Invalid waveform file selected</qt> " ) , i18n ( " Invalid File " ) ) ;
}
}
}
KAboutData * SensorMonitorPart : : createAboutData ( ) {
return new KAboutData ( APP_NAME , I18N_NOOP ( APP_PRETTYNAME ) , APP_VERSION ) ;
}