mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-08 22:00:03 +02:00
added users to the package
This commit is contained in:
parent
d9016c95de
commit
983f517e07
25
users/Makefile
Normal file
25
users/Makefile
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
WD = $(shell pwd)
|
||||||
|
LIBDIR = $(WD)/../bin
|
||||||
|
LIBRARYRXRDIR = $(WD)/../slsReceiverSoftware
|
||||||
|
LIBRARYDETDIR = $(WD)/../slsDetectorSoftware
|
||||||
|
LDFLAGRXR = -L$(LIBDIR) -lSlsReceiver -L/usr/lib64/ -lpthread
|
||||||
|
LDFLAGDET = -L$(LIBDIR) -lSlsDetector -L/usr/lib64/ -lpthread
|
||||||
|
INCLUDESRXR = -I $(LIBRARYRXRDIR)/include
|
||||||
|
INCLUDESDET = -I $(LIBRARYRXRDIR)/include -I $(LIBRARYDETDIR)/slsDetector -I $(LIBRARYDETDIR)/slsDetectorAnalysis
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all: receivers users
|
||||||
|
|
||||||
|
receivers:
|
||||||
|
@echo $(WD)
|
||||||
|
g++ mainReceiver.cpp $(INCLUDESRXR) $(LDFLAGRXR) -o userReceiver
|
||||||
|
|
||||||
|
users:
|
||||||
|
@echo $(WD)
|
||||||
|
g++ mainClient.cpp $(INCLUDESDET) $(LDFLAGDET) -o userClient
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm userReceiver userClient
|
||||||
|
|
24
users/Makefile_new
Normal file
24
users/Makefile_new
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
WD = $(shell pwd)
|
||||||
|
LIBDIR = $(WD)/../bin
|
||||||
|
LIBRARYRXRDIR = $(WD)/../slsReceiverSoftware
|
||||||
|
LIBRARYDETDIR = $(WD)/../slsDetectorSoftware
|
||||||
|
LDFLAGRXR = -L$(LIBDIR) -lSlsReceiver -L/usr/lib64/ -lpthread
|
||||||
|
LDFLAGDET = -L$(LIBDIR) -lSlsDetector -L/usr/lib64/ -lpthread
|
||||||
|
INCLUDESRXR = -I $(LIBRARYRXRDIR)/include
|
||||||
|
INCLUDESDET = -I $(LIBRARYDETDIR)/slsDetector -I $(LIBRARYDETDIR)/slsDetectorAnalysis
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all: receivers users
|
||||||
|
|
||||||
|
receivers:
|
||||||
|
@echo $(WD)
|
||||||
|
g++ mainReceiver.cpp $(INCLUDESRXR) $(LDFLAGRXR) -o userReceiver
|
||||||
|
|
||||||
|
users:
|
||||||
|
@echo $(WD)
|
||||||
|
g++ mainClient.cpp $(INCLUDESDET) $(LDFLAGDET) -o userClient
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm userReceiver userClient
|
78
users/mainClient.cpp
Normal file
78
users/mainClient.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/**
|
||||||
|
\file mainClient.cpp
|
||||||
|
|
||||||
|
This file is an example of how to implement the slsDetectorUsers class
|
||||||
|
You can compile it linking it to the slsDetector library
|
||||||
|
|
||||||
|
gcc mainClient.cpp -L lib -l SlsDetector -lm -lpthread
|
||||||
|
|
||||||
|
where lib is the location of libSlsDetector.so
|
||||||
|
gcc mainClient.cpp -L . -l SlsDetector -lm -lpthread -o users
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "slsDetectorUsers.h"
|
||||||
|
#include "detectorData.h"
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
/** Definition of the data callback which simply prints out the number of points received and teh frame number */
|
||||||
|
int dataCallback(detectorData *pData, int iframe, int isubframe, void *pArg)
|
||||||
|
{
|
||||||
|
std::cout << "dataCallback: " << pData->npoints << " " << pData->npy << "Frame number: " << iframe << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**example of a main program using the slsDetectorUsers class */
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int id=0;
|
||||||
|
/** if specified, argv[3] is used as detector ID (default is 0)*/
|
||||||
|
if (argc>=4)
|
||||||
|
id=atoi(argv[3]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** slsDetectorUsers is instantiated */
|
||||||
|
slsDetectorUsers *pDetector = new slsDetectorUsers (id);
|
||||||
|
|
||||||
|
|
||||||
|
/** if specified, argv[1] is used as detector config file (necessary at least the first time it is called to properly configure advanced settings in the shared memory)*/
|
||||||
|
if (argc>=2){
|
||||||
|
pDetector->readConfigurationFile(argv[1]);
|
||||||
|
cout<<"Detector configured" << endl;
|
||||||
|
}
|
||||||
|
/** registering data callback */
|
||||||
|
//pDetector->registerDataCallback(&dataCallback, NULL);
|
||||||
|
//pDetector->enableDataStreamingFromReceiver(1);
|
||||||
|
|
||||||
|
/** checking detector status and exiting if not idle */
|
||||||
|
int status = pDetector->getDetectorStatus();
|
||||||
|
if (status != 0){
|
||||||
|
std::cout << "Detector not ready: " << slsDetectorUsers::runStatusType(status) << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** load detector settings */
|
||||||
|
if (argc>=3){
|
||||||
|
pDetector->retrieveDetectorSetup(argv[2]);
|
||||||
|
cout<<"Detector measurement set-up done" << endl;
|
||||||
|
}
|
||||||
|
/** start measurement */
|
||||||
|
pDetector->startMeasurement();
|
||||||
|
cout<<"started measurement"<<endl;
|
||||||
|
|
||||||
|
/* while (1) {
|
||||||
|
usleep(100000);
|
||||||
|
status = pDetector->getDetectorStatus();
|
||||||
|
if (status == 0 || status == 1|| status == 3)
|
||||||
|
break;
|
||||||
|
}*/
|
||||||
|
cout<<"measurement finished"<<endl;
|
||||||
|
/** returning when acquisition is finished or data are avilable */
|
||||||
|
|
||||||
|
|
||||||
|
delete pDetector;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
86
users/mainClient_new.cpp
Normal file
86
users/mainClient_new.cpp
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
\file mainClient.cpp
|
||||||
|
|
||||||
|
This file is an example of how to implement the slsDetectorUsers class
|
||||||
|
You can compile it linking it to the slsDetector library
|
||||||
|
|
||||||
|
gcc mainClient.cpp -L lib -l SlsDetector -lm -lpthread
|
||||||
|
|
||||||
|
where lib is the location of libSlsDetector.so
|
||||||
|
gcc mainClient.cpp -L . -l SlsDetector -lm -lpthread -o users
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "slsDetectorUsers.h"
|
||||||
|
#include "detectorData.h"
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
/** Definition of the data callback which simply prints out the number of points received and teh frame number */
|
||||||
|
int dataCallback(detectorData *pData, int iframe, void *pArg)
|
||||||
|
{
|
||||||
|
std::cout << "dataCallback: " << pData->npoints << " " << pData->npy << "Frame number: " << iframe << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**example of a main program using the slsDetectorUsers class */
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int id=0;
|
||||||
|
/** if specified, argv[3] is used as detector ID (default is 0)*/
|
||||||
|
if (argc>=4)
|
||||||
|
id=atoi(argv[3]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/** slsDetectorUsers is instantiated */
|
||||||
|
slsDetectorUsers *pDetector = new slsDetectorUsers (id);
|
||||||
|
|
||||||
|
|
||||||
|
char* argse[1];
|
||||||
|
argse[0] = (char*)"free";
|
||||||
|
pDetector->getCommand(1, argse, 0);
|
||||||
|
|
||||||
|
/** if specified, argv[1] is used as detector config file (necessary at least the first time it is called to properly configure advanced settings in the shared memory)*/
|
||||||
|
if (argc>=2){
|
||||||
|
pDetector->readConfigurationFile(argv[1]);
|
||||||
|
cout<<"Detector configured" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** registering data callback */
|
||||||
|
// pDetector->registerDataCallback(&dataCallback, NULL);
|
||||||
|
|
||||||
|
/** checking detector status and exiting if not idle */
|
||||||
|
/* int status = pDetector->getDetectorStatus();
|
||||||
|
if (status != 0){
|
||||||
|
std::cout << "Detector not ready: " << slsDetectorUsers::runStatusType(status) << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/** load detector settings */
|
||||||
|
/* if (argc>=3){
|
||||||
|
pDetector->retrieveDetectorSetup(argv[2]);
|
||||||
|
cout<<"Detector measurement set-up done" << endl;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/** start measurement */
|
||||||
|
/* pDetector->startMeasurement();
|
||||||
|
cout<<"started measurement"<<endl;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
usleep(100000);
|
||||||
|
status = pDetector->getDetectorStatus();
|
||||||
|
if (status == 0 || status == 1|| status == 3)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cout<<"measurement finished"<<endl;
|
||||||
|
*/
|
||||||
|
/** returning when acquisition is finished or data are avilable */
|
||||||
|
|
||||||
|
|
||||||
|
delete pDetector;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
138
users/mainReceiver.cpp
Normal file
138
users/mainReceiver.cpp
Normal file
@ -0,0 +1,138 @@
|
|||||||
|
/* A simple server in the internet domain using TCP
|
||||||
|
The port number is passed as an argument */
|
||||||
|
|
||||||
|
#include "sls_receiver_defs.h"
|
||||||
|
#include "slsReceiverUsers.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string.h>
|
||||||
|
#include <signal.h> //SIGINT
|
||||||
|
#include <cstdlib> //system
|
||||||
|
|
||||||
|
#include "utilities.h"
|
||||||
|
#include "logger.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
slsReceiverUsers *receiver;
|
||||||
|
|
||||||
|
void deleteReceiver(slsReceiverUsers* r){
|
||||||
|
if(r){delete r;r=0;}
|
||||||
|
}
|
||||||
|
|
||||||
|
void closeFile(int p){
|
||||||
|
deleteReceiver(receiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int StartAcq(char* filepath, char*filename,int fileindex, int datasize, void*p){
|
||||||
|
printf("--StartAcq: filepath:%s filename:%s fileindex:%d datasize:%d\n",
|
||||||
|
filepath, filename, fileindex, datasize);
|
||||||
|
|
||||||
|
printf("--StartAcq: returning 0\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void AcquisitionFinished(int frames, void*p){
|
||||||
|
printf("AcquisitionFinished: frames:%d \n",frames);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GetData(int framenum, char* datapointer, int datasize, FILE* descriptor, char* gui, void* p){
|
||||||
|
printf("GetData: framenum: %d(%d)\n", framenum, *(int*)datapointer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
|
//Catch signal SIGINT to close files properly
|
||||||
|
signal(SIGINT,closeFile);
|
||||||
|
|
||||||
|
int ret = slsReceiverDefs::OK;
|
||||||
|
receiver = new slsReceiverUsers(argc, argv, ret);
|
||||||
|
|
||||||
|
if(ret==slsReceiverDefs::FAIL){
|
||||||
|
deleteReceiver(receiver);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//register callbacks
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
callback arguments are
|
||||||
|
filepath
|
||||||
|
filename
|
||||||
|
fileindex
|
||||||
|
datasize
|
||||||
|
|
||||||
|
return value is
|
||||||
|
0 raw data ready callback takes care of open,close,write file
|
||||||
|
1 callback writes file, we have to open, close it
|
||||||
|
2 we open, close, write file, callback does not do anything
|
||||||
|
|
||||||
|
registerCallBackStartAcquisition(int (*func)(char*, char*,int, int, void*),void *arg);
|
||||||
|
*/
|
||||||
|
//receiver->registerCallBackStartAcquisition(func,arg);
|
||||||
|
|
||||||
|
printf("Registering StartAcq()\n");
|
||||||
|
receiver->registerCallBackStartAcquisition(StartAcq, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
callback argument is
|
||||||
|
total farmes caught
|
||||||
|
registerCallBackAcquisitionFinished(void (*func)(int, void*),void *arg);
|
||||||
|
*/
|
||||||
|
//receiver->registerCallBackAcquisitionFinished(func,arg);
|
||||||
|
|
||||||
|
printf("Registering AcquisitionFinished()\n");
|
||||||
|
receiver->registerCallBackAcquisitionFinished(AcquisitionFinished, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
args to raw data ready callback are
|
||||||
|
framenum
|
||||||
|
datapointer
|
||||||
|
file descriptor
|
||||||
|
guidatapointer (NULL, no data required)
|
||||||
|
|
||||||
|
NEVER DELETE THE DATA POINTER
|
||||||
|
REMEMBER THAT THE CALLBACK IS BLOCKING
|
||||||
|
|
||||||
|
registerCallBackRawDataReady(void (*func)(int, char*, FILE*, char*, void*),void *arg);
|
||||||
|
|
||||||
|
*/
|
||||||
|
//receiver->registerCallBackRawDataReady(func,arg);
|
||||||
|
|
||||||
|
printf("Registering GetData() \n");
|
||||||
|
receiver->registerCallBackRawDataReady(GetData,NULL);
|
||||||
|
|
||||||
|
|
||||||
|
/* start receiver to listen for commands from the client (and data from detectors when expected */
|
||||||
|
receiver->start();
|
||||||
|
|
||||||
|
//start tcp server thread
|
||||||
|
if(receiver->start() == slsReceiverDefs::OK){
|
||||||
|
FILE_LOG(logDEBUG1) << "DONE!" << endl;
|
||||||
|
string str;
|
||||||
|
cin>>str;
|
||||||
|
//wait and look for an exit keyword
|
||||||
|
while(str.find("exit") == string::npos)
|
||||||
|
cin>>str;
|
||||||
|
//stop tcp server thread, stop udp socket
|
||||||
|
receiver->stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
BIN
users/userClient
Executable file
BIN
users/userClient
Executable file
Binary file not shown.
BIN
users/userReceiver
Executable file
BIN
users/userReceiver
Executable file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user