@ -564,8 +564,9 @@ K_EXPORT_COMPONENT_FACTORY(libremotelab_fpgaviewer, RemoteLab::Factory)
FPGAViewPart : : FPGAViewPart ( TQWidget * parentWidget , const char * widgetName , TQObject * parent , const char * name , const TQStringList & )
FPGAViewPart : : FPGAViewPart ( TQWidget * parentWidget , const char * widgetName , TQObject * parent , const char * name , const TQStringList & )
: RemoteInstrumentPart ( parent , name ) , m_socket ( 0 ) , m_base ( 0 ) , connToServerConnecting ( false ) , connToServerState ( - 1 ) , connToServerTimeoutTimer ( NULL ) , m_interfaceMode ( BasicInterfaceMode ) ,
: RemoteInstrumentPart ( parent , name ) , m_socket ( 0 ) , m_base ( 0 ) , connToServerConnecting ( false ) , connToServerState ( - 1 ) , connToServerTimeoutTimer ( NULL ) , m_interfaceMode ( BasicInterfaceMode ) ,
m_commHandlerState ( 0 ) , m_connectionActiveAndValid ( false ) , m_tickerState ( 0 ) , m_remoteInputModeEnabled ( false ) , m_4bitInputValue ( 0 ) , m_4bitOutputValue ( 0 ) , m_8bitInputValue ( 0 ) , m_8bitOutputValue ( 0 ) ,
m_commHandlerState ( 0 ) , m_commHandlerMode ( 0 ) , m_connectionActiveAndValid ( false ) , m_tickerState ( 0 ) , m_remoteInputModeEnabled ( false ) , m_4bitInputValue ( 0 ) , m_4bitOutputValue ( 0 ) ,
m_16bitInputValue ( 0 ) , m_16bitOutputValue ( 0 ) , m_7segDigit3OutputValue ( 0xffffffff ) , m_7segDigit2OutputValue ( 0xffffffff ) , m_7segDigit1OutputValue ( 0xffffffff ) , m_7segDigit0OutputValue ( 0xffffffff ) ,
m_8bitInputValue ( 0 ) , m_8bitOutputValue ( 0 ) , m_16bitInputValue ( 0 ) , m_16bitOutputValue ( 0 ) , m_7segDigit3OutputValue ( 0xffffffff ) ,
m_7segDigit2OutputValue ( 0xffffffff ) , m_7segDigit1OutputValue ( 0xffffffff ) , m_7segDigit0OutputValue ( 0xffffffff ) ,
m_batchOutputFile ( NULL ) , m_dataOutputFile ( NULL )
m_batchOutputFile ( NULL ) , m_dataOutputFile ( NULL )
{
{
// Initialize mutex
// Initialize mutex
@ -577,6 +578,8 @@ FPGAViewPart::FPGAViewPart(TQWidget *parentWidget, const char *widgetName, TQObj
// Create timers
// Create timers
m_updateTimer = new TQTimer ( this ) ;
m_updateTimer = new TQTimer ( this ) ;
m_connectionTimer = new TQTimer ( this ) ;
connect ( m_connectionTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( finishConnectingToServer ( ) ) ) ;
// Create widgets
// Create widgets
m_base = new FPGAViewBase ( widget ( ) ) ;
m_base = new FPGAViewBase ( widget ( ) ) ;
@ -984,6 +987,8 @@ bool FPGAViewPart::closeURL() {
}
}
void FPGAViewPart : : disconnectFromServer ( ) {
void FPGAViewPart : : disconnectFromServer ( ) {
m_connectionTimer - > stop ( ) ;
m_updateTimer - > stop ( ) ;
if ( m_socket ) {
if ( m_socket ) {
m_socket - > clearPendingData ( ) ;
m_socket - > clearPendingData ( ) ;
m_socket - > close ( ) ;
m_socket - > close ( ) ;
@ -1050,45 +1055,56 @@ void FPGAViewPart::finishConnectingToServer() {
case 2 :
case 2 :
// Connection established!
// Connection established!
// Read magic number and proto version from server
// Read magic number and proto version from server
TQDataStream ds ( m_socket ) ;
m_socket - > processPendingData ( ) ;
TQ_UINT32 magicnum ;
if ( m_socket - > bytesAvailable ( ) > 0 ) {
TQ_UINT32 protover ;
TQDataStream ds ( m_socket ) ;
ds > > magicnum ;
TQ_UINT32 magicnum ;
ds > > protover ;
TQ_UINT32 protover ;
printf ( " [DEBUG] Got magic number %d and protocol version %d \n \r " , magicnum , protover ) ; fflush ( stdout ) ;
ds > > magicnum ;
ds > > protover ;
// Request connection to backend server
printf ( " [DEBUG] Got magic number %d and protocol version %d \n \r " , magicnum , protover ) ; fflush ( stdout ) ;
TQString response ;
ds < < TQString ( " SERV " ) ;
// Request connection to backend server
ds < < TQString ( CLIENT_LIBRARY ) ;
ds < < TQString ( " SERV " ) ;
ds > > response ;
ds < < TQString ( CLIENT_LIBRARY ) ;
printf ( " [RAJA DEBUG 400.0] Got '%s' from the server \n \r " , response . ascii ( ) ) ; fflush ( stdout ) ;
if ( response = = " OK " ) {
connToServerState = 3 ;
connToServerState = 3 ;
connToServerConnecting = false ;
connect ( m_socket , SIGNAL ( readyRead ( ) ) , m_socket , SLOT ( processPendingData ( ) ) ) ;
connect ( m_socket , SIGNAL ( newDataReceived ( ) ) , this , SLOT ( updateDisplay ( ) ) ) ;
m_tickerState = 0 ;
m_commHandlerState = 0 ;
m_commHandlerMode = 0 ;
m_updateTimer - > start ( FPGA_COMM_TIMEOUT_MS , FALSE ) ;
processLockouts ( ) ;
updateDisplay ( ) ;
return ;
}
}
else {
break ;
TQStringList errorStrings = textForServerError ( response ) ;
case 3 :
connToServerState = - 1 ;
// Read response from server
connToServerConnecting = false ;
m_socket - > processPendingData ( ) ;
disconnectFromServer ( ) ;
if ( m_socket - > bytesAvailable ( ) > 0 ) {
KMessageBox : : error ( 0 , errorStrings [ 0 ] , errorStrings [ 1 ] ) ;
TQDataStream ds ( m_socket ) ;
close ( ) ;
TQString response ;
return ;
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 ( ) ) ) ;
connect ( m_socket , SIGNAL ( newDataReceived ( ) ) , this , SLOT ( updateDisplay ( ) ) ) ;
m_tickerState = 0 ;
m_commHandlerState = 0 ;
m_commHandlerMode = 0 ;
m_updateTimer - > start ( FPGA_COMM_TIMEOUT_MS , FALSE ) ;
processLockouts ( ) ;
updateDisplay ( ) ;
return ;
}
else {
TQStringList errorStrings = textForServerError ( response ) ;
connToServerState = - 1 ;
connToServerConnecting = false ;
disconnectFromServer ( ) ;
KMessageBox : : error ( 0 , errorStrings [ 0 ] , errorStrings [ 1 ] ) ;
close ( ) ;
return ;
}
}
}
break ;
break ;
}
}
TQTimer : : singleShot ( 0 , this , SLOT ( finishConnectingToServer ( ) ) ) ;
m_connectionTimer- > start ( 100 , TRUE ) ;
}
}
}
}
@ -1107,7 +1123,7 @@ int FPGAViewPart::connectToServer(TQString server) {
// Finish connecting when appropriate
// Finish connecting when appropriate
connToServerState = 0 ;
connToServerState = 0 ;
connToServerConnecting = true ;
connToServerConnecting = true ;
TQTimer: : singleShot ( 0 , this , SLOT ( finishConnectingToServer ( ) ) ) ;
m_connectionTimer- > start ( 100 , TRUE ) ;
return 0 ;
return 0 ;
}
}