mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
gui client works for just getting status
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@149 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
@ -14,6 +14,7 @@
|
||||
#include "qTabDebugging.h"
|
||||
#include "qTabDeveloper.h"
|
||||
#include "qTabMessages.h"
|
||||
#include "qServer.h"
|
||||
// Project Class Headers
|
||||
#include "slsDetector.h"
|
||||
#include "multiSlsDetector.h"
|
||||
@ -112,6 +113,8 @@ void qDetectorMain::SetUpWidgetWindow(){
|
||||
tab_debugging = new qTabDebugging (this, myDet); cout<<"Debugging ready"<<endl;
|
||||
tab_developer = new qTabDeveloper (this, myDet); cout<<"Developer ready"<<endl;
|
||||
|
||||
myServer = new qServer(myDet, tab_measurement, myPlot);
|
||||
|
||||
// creating the scroll area widgets for the tabs
|
||||
for(int i=0;i<NumberOfTabs;i++){
|
||||
scroll[i] = new QScrollArea;
|
||||
@ -320,8 +323,14 @@ void qDetectorMain::LoadConfigFile(const string fName){
|
||||
void qDetectorMain::EnableModes(QAction *action){
|
||||
bool enable;
|
||||
|
||||
//listen to gui client
|
||||
if(action==actionListenGuiClient){
|
||||
disconnect(menuModes, SIGNAL(triggered(QAction*)), this,SLOT(EnableModes(QAction*)));
|
||||
actionListenGuiClient->setChecked(myServer->StartStopServer(actionListenGuiClient->isChecked()));
|
||||
connect(menuModes, SIGNAL(triggered(QAction*)), this,SLOT(EnableModes(QAction*)));
|
||||
}
|
||||
//Set DebugMode
|
||||
if(action==actionDebug){
|
||||
else if(action==actionDebug){
|
||||
enable = actionDebug->isChecked();
|
||||
tabs->setTabEnabled(Debugging,enable);
|
||||
#ifdef VERBOSE
|
||||
|
@ -2,7 +2,7 @@
|
||||
* qDrawPlot.cpp
|
||||
*
|
||||
* Created on: May 7, 2012
|
||||
* Author: Ian Johnson
|
||||
* Author: Dhanya Maliakal
|
||||
*/
|
||||
// Qt Project Class Headers
|
||||
#include "qDrawPlot.h"
|
||||
@ -174,9 +174,6 @@ void qDrawPlot::SetupWidgetWindow(){
|
||||
pedestalCount = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//widget related initialization
|
||||
|
||||
// clone
|
||||
@ -578,7 +575,6 @@ void qDrawPlot::SetupMeasurement(){
|
||||
|
||||
void* qDrawPlot::DataStartAcquireThread(void *this_pointer){
|
||||
((qDrawPlot*)this_pointer)->myDet->acquire(1);
|
||||
|
||||
return this_pointer;
|
||||
}
|
||||
|
||||
|
256
slsDetectorGui/src/qServer.cpp
Normal file
256
slsDetectorGui/src/qServer.cpp
Normal file
@ -0,0 +1,256 @@
|
||||
/*
|
||||
* qServer.cpp
|
||||
*
|
||||
* Created on: Feb 27, 2013
|
||||
* Author: Dhanya Maliakal
|
||||
*/
|
||||
// Qt Project Class Headers
|
||||
#include "qServer.h"
|
||||
#include "qTabMeasurement.h"
|
||||
#include "qDrawPlot.h"
|
||||
// Project Class Headers
|
||||
#include "slsDetector.h"
|
||||
#include "multiSlsDetector.h"
|
||||
#include "MySocketTCP.h"
|
||||
// C++ Include Headers
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qServer::gui_server_thread_running(0);
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
qServer::qServer(multiSlsDetector*& detector, qTabMeasurement* m, qDrawPlot *d):
|
||||
myDet(detector),tab_measurement(m),myPlot(d),mySocket(NULL),port_no(DEFAULT_GUI_PORTNO),lockStatus(0){
|
||||
|
||||
function_table();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
qServer::~qServer(){
|
||||
delete myDet;
|
||||
delete tab_measurement;
|
||||
delete myPlot;
|
||||
if(mySocket) delete mySocket;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qServer::function_table(){
|
||||
|
||||
for (int i=0;i<NUMBER_OF_FUNCTIONS;i++)
|
||||
flist[i]=&qServer::M_nofunc;
|
||||
|
||||
flist[F_GET_RUN_STATUS] = &qServer::get_status;
|
||||
flist[F_START_ACQUISITION] = &qServer::get_status;
|
||||
flist[F_STOP_ACQUISITION] = &qServer::get_status;
|
||||
flist[F_START_AND_READ_ALL] = &qServer::get_status;
|
||||
flist[F_EXIT_SERVER] = &qServer::get_status;
|
||||
|
||||
return qDefs::OK;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qServer::decode_function(){
|
||||
int ret = qDefs::FAIL;
|
||||
int n,fnum;
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "receive data" << endl;
|
||||
#endif
|
||||
n = mySocket->ReceiveDataOnly(&fnum,sizeof(fnum));
|
||||
if (n <= 0) {
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "ERROR reading from socket " << n << ", " << fnum << endl;
|
||||
#endif
|
||||
return qDefs::FAIL;
|
||||
}
|
||||
#ifdef VERYVERBOSE
|
||||
else
|
||||
cout << "size of data received " << n <<endl;
|
||||
#endif
|
||||
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "calling function fnum = "<< fnum << hex << ":"<< flist[fnum] << endl;
|
||||
#endif
|
||||
|
||||
if (fnum<0 || fnum>NUMBER_OF_FUNCTIONS-1)
|
||||
fnum = NUMBER_OF_FUNCTIONS-1;
|
||||
//calling function
|
||||
(this->*flist[fnum])();
|
||||
if (ret==qDefs::FAIL)
|
||||
cout << "Error executing the function = " << fnum << endl;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qServer::M_nofunc(){
|
||||
|
||||
int ret = qDefs::FAIL;
|
||||
sprintf(mess,"Unrecognized Function\n");
|
||||
cout << mess << endl;
|
||||
|
||||
mySocket->SendDataOnly(&ret,sizeof(ret));
|
||||
mySocket->SendDataOnly(mess,sizeof(mess));
|
||||
|
||||
return GOODBYE;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qServer::StartStopServer(int start){
|
||||
|
||||
//start server
|
||||
if(start){
|
||||
#ifdef VERBOSE
|
||||
cout << endl << "Starting Gui Server" << endl;
|
||||
#endif
|
||||
|
||||
if(!gui_server_thread_running){
|
||||
#ifdef VERBOSE
|
||||
cout << "Starting gui server thread ...." << endl;
|
||||
#endif
|
||||
gui_server_thread_running=1;
|
||||
checkStarted=1;
|
||||
//error creating thread
|
||||
if (pthread_create(&gui_server_thread, NULL,StartServerThread, (void*) this)){
|
||||
gui_server_thread_running=0;
|
||||
qDefs::Message(qDefs::WARNING,"Can't create gui server thread", "Server");
|
||||
return 0;
|
||||
}
|
||||
while(checkStarted);
|
||||
checkStarted=0;
|
||||
#ifdef VERBOSE
|
||||
if(gui_server_thread_running)
|
||||
cout << "Server thread created successfully." << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//stop server
|
||||
else{
|
||||
#ifdef VERBOSE
|
||||
cout << "Stopping Gui Server" << endl;
|
||||
#endif
|
||||
|
||||
if(gui_server_thread_running){
|
||||
#ifdef VERBOSE
|
||||
cout << "Stopping gui server thread ...." << endl;
|
||||
#endif
|
||||
gui_server_thread_running=0;
|
||||
mySocket->Disconnect();
|
||||
mySocket->ShutDownSocket();
|
||||
pthread_join(gui_server_thread,NULL);
|
||||
delete mySocket;
|
||||
mySocket = NULL;
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
cout << "Server stopped successfully." << endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
return gui_server_thread_running;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void* qServer::StartServerThread(void* this_pointer){
|
||||
((qServer*)this_pointer)->StartServer();
|
||||
return this_pointer;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
int qServer::StartServer(){
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "In StartServer()\n");
|
||||
#endif
|
||||
int ret = qDefs::OK;
|
||||
|
||||
mySocket = new MySocketTCP(port_no);
|
||||
if (mySocket->getErrorStatus()){
|
||||
gui_server_thread_running = 0;
|
||||
qDefs::Message(qDefs::WARNING,"Could not start gui server socket","Server");
|
||||
}
|
||||
checkStarted = 0;
|
||||
|
||||
while ((gui_server_thread_running) && (ret!=GOODBYE)) {
|
||||
#ifdef VERBOSE
|
||||
cout<< endl;
|
||||
#endif
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "Waiting for client call" << endl;
|
||||
#endif
|
||||
if(mySocket->Connect()>=0){
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "Conenction accepted" << endl;
|
||||
#endif
|
||||
ret = decode_function();
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "function executed" << endl;
|
||||
#endif
|
||||
mySocket->Disconnect();
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "connection closed" << endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
cout << "Stopped gui server thread" << endl;
|
||||
#endif
|
||||
gui_server_thread_running = 0;
|
||||
return qDefs::OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qServer::get_status(){
|
||||
|
||||
int ret = qDefs::OK;
|
||||
enum slsDetectorDefs::runStatus retval;
|
||||
|
||||
// execute action if the arguments correctly arrived
|
||||
if(myPlot->isRunning())
|
||||
retval = slsDetectorDefs::RUNNING;
|
||||
else
|
||||
retval = slsDetectorDefs::IDLE;
|
||||
|
||||
// send answer
|
||||
mySocket->SendDataOnly(&ret,sizeof(ret));
|
||||
mySocket->SendDataOnly(&retval,sizeof(retval));
|
||||
//return ok/fail
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -83,6 +83,7 @@ void qTabMeasurement::SetupWidgetWindow(){
|
||||
iconStart = new QIcon(":/icons/images/start.png");
|
||||
iconStop = new QIcon(":/icons/images/stop.png");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -323,6 +324,25 @@ void qTabMeasurement::startStopAcquisition(){
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
int qTabMeasurement::GetAcquisitionStarted(){
|
||||
|
||||
cout<<" acquisition started call back"<<endl;
|
||||
//if the acquisition started from client, the button wont be checked
|
||||
if(!btnStartStop->isChecked()){cout<<" hasnt started, so from client"<<endl;
|
||||
myPlot->SetAcqFromClient();
|
||||
btnStartStop->click();
|
||||
//wait till the gui is ready to execute the acquire(), but doesnt execute it
|
||||
//acqFromClient is reset when it is ready
|
||||
while(myPlot->GetAcqFromClient());
|
||||
}else
|
||||
cout<<" has started, so from gui"<<endl;
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user