mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-23 06:50:02 +02:00
added one without call back
This commit is contained in:
parent
ae066fab93
commit
6b6ad6efe0
@ -72,8 +72,8 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
<a name="l00055"></a><a class="code" href="mainReceiver_8cpp.html#a0d20b69b0ad703df78459e1033d5c1d4">00055</a> <span class="keywordtype">void</span> <a class="code" href="mainReceiver_8cpp.html#a0d20b69b0ad703df78459e1033d5c1d4">printHelp</a>() {
|
||||
<a name="l00056"></a>00056 bprintf(GRAY, <span class="stringliteral">"Usage:\n"</span>
|
||||
<a name="l00057"></a>00057 <span class="stringliteral">"./detReceiver\n"</span>
|
||||
<a name="l00058"></a>00058 <span class="stringliteral">"or ./detReceiver [num_receivers] [start_tcp_port]\n"</span>
|
||||
<a name="l00059"></a>00059 <span class="stringliteral">"Default values: num_receivers - 1, start_tcp_port - 1954\n\n"</span>);
|
||||
<a name="l00058"></a>00058 <span class="stringliteral">"or ./detReceiver [start_tcp_port] [num_receivers]\n"</span>
|
||||
<a name="l00059"></a>00059 <span class="stringliteral">"Default values: start_tcp_port - 1954, num_receivers - 1\n\n"</span>);
|
||||
<a name="l00060"></a>00060 }
|
||||
<a name="l00061"></a>00061
|
||||
<a name="l00073"></a><a class="code" href="mainReceiver_8cpp.html#a1ec49915ff49957985ebfe6ccc5cd1b3">00073</a> <span class="keywordtype">int</span> <a class="code" href="mainReceiver_8cpp.html#a1ec49915ff49957985ebfe6ccc5cd1b3">StartAcq</a>(<span class="keywordtype">char</span>* filepath, <span class="keywordtype">char</span>* filename, uint64_t fileindex, uint32_t datasize, <span class="keywordtype">void</span>*p){
|
||||
@ -110,7 +110,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
<a name="l00137"></a>00137 <span class="keywordtype">int</span> startTCPPort = 1954;
|
||||
<a name="l00138"></a>00138 <a class="code" href="mainReceiver_8cpp.html#a0d26a166bb416ff34512de6fe9e098bd">keeprunning</a> = <span class="keyword">true</span>;
|
||||
<a name="l00139"></a>00139
|
||||
<a name="l00141"></a>00141 <span class="keywordflow">if</span> (argc > 1 && ((argc < 3) || (!sscanf(argv[1],<span class="stringliteral">"%d"</span>, &numReceivers)) || (!sscanf(argv[2],<span class="stringliteral">"%d"</span>, &startTCPPort)) ))
|
||||
<a name="l00141"></a>00141 <span class="keywordflow">if</span> (argc > 1 && ((argc < 3) || (!sscanf(argv[1],<span class="stringliteral">"%d"</span>, &startTCPPort)) || (!sscanf(argv[2],<span class="stringliteral">"%d"</span>, &numReceivers)) ))
|
||||
<a name="l00142"></a>00142 <a class="code" href="mainReceiver_8cpp.html#a0d20b69b0ad703df78459e1033d5c1d4">printHelp</a>();
|
||||
<a name="l00143"></a>00143 bprintf(BLUE,<span class="stringliteral">"Parent Process Created [ Tid: %ld ]\n"</span>, (<span class="keywordtype">long</span>)syscall(SYS_gettid));
|
||||
<a name="l00144"></a>00144 bprintf(GRAY, <span class="stringliteral">"Number of Receivers: %d\n"</span>, numReceivers);
|
||||
@ -131,7 +131,7 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||||
<a name="l00162"></a>00162 asa.sa_handler=SIG_IGN; <span class="comment">// handler function</span>
|
||||
<a name="l00163"></a>00163 sigemptyset(&asa.sa_mask); <span class="comment">// dont block additional signals during invocation of handler</span>
|
||||
<a name="l00164"></a>00164 <span class="keywordflow">if</span> (sigaction(SIGPIPE, &asa, NULL) == -1) {
|
||||
<a name="l00165"></a>00165 bprintf(RED, <span class="stringliteral">"Could not set handler function for SIGCHILD\n"</span>);
|
||||
<a name="l00165"></a>00165 bprintf(RED, <span class="stringliteral">"Could not set handler function for SIGPIPE\n"</span>);
|
||||
<a name="l00166"></a>00166 }
|
||||
<a name="l00167"></a>00167
|
||||
<a name="l00168"></a>00168
|
||||
|
Binary file not shown.
@ -1,6 +1,7 @@
|
||||
INCLUDES = -I .
|
||||
SRC_DET = mainClient.cpp
|
||||
SRC_REC = mainReceiver.cpp
|
||||
SRC_REC_NO = mainReceiver_withoutcallback.cpp
|
||||
LIBDIR = .
|
||||
LDFLAG_DET = -I. -L$(LIBDIR) -lSlsDetector -L/usr/lib64/ -pthread -lrt -L. -lzmq
|
||||
LDFLAG_REC = -I. -L$(LIBDIR) -lSlsReceiver -L/usr/lib64/ -pthread -lrt -L. -lzmq
|
||||
@ -38,6 +39,10 @@ detReceiver:$(SRC_REC)
|
||||
echo "creating receiver"
|
||||
g++ -o detReceiver $(SRC_REC) $(INCLUDES) $(LDFLAG_REC) -lm -lstdc++
|
||||
|
||||
detReceiverNocall:$(SRC_REC_NO)
|
||||
echo "creating receiver with no call backs"
|
||||
g++ -o detReceiverNocall $(SRC_REC_NO) $(INCLUDES) $(LDFLAG_REC) -lm -lstdc++
|
||||
|
||||
clean:
|
||||
echo "cleaning for manual-api"
|
||||
rm -rf detUser detReceiver slsDetectorUsersDocs
|
||||
|
Binary file not shown.
BIN
manual/manual-api/detReceiverNocall
Executable file
BIN
manual/manual-api/detReceiverNocall
Executable file
Binary file not shown.
@ -55,8 +55,8 @@ void sigInterruptHandler(int p){
|
||||
void printHelp() {
|
||||
bprintf(GRAY, "Usage:\n"
|
||||
"./detReceiver\n"
|
||||
"or ./detReceiver [num_receivers] [start_tcp_port]\n"
|
||||
"Default values: num_receivers - 1, start_tcp_port - 1954\n\n");
|
||||
"or ./detReceiver [start_tcp_port] [num_receivers]\n"
|
||||
"Default values: start_tcp_port - 1954, num_receivers - 1\n\n");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -138,7 +138,7 @@ int main(int argc, char *argv[]) {
|
||||
keeprunning = true;
|
||||
|
||||
/** - get number of receivers and start tcp port from command line arguments */
|
||||
if (argc > 1 && ((argc < 3) || (!sscanf(argv[1],"%d", &numReceivers)) || (!sscanf(argv[2],"%d", &startTCPPort)) ))
|
||||
if (argc > 1 && ((argc < 3) || (!sscanf(argv[1],"%d", &startTCPPort)) || (!sscanf(argv[2],"%d", &numReceivers)) ))
|
||||
printHelp();
|
||||
bprintf(BLUE,"Parent Process Created [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
|
||||
bprintf(GRAY, "Number of Receivers: %d\n", numReceivers);
|
||||
|
265
manual/manual-api/mainReceiver_withoutcallback.cpp
Normal file
265
manual/manual-api/mainReceiver_withoutcallback.cpp
Normal file
@ -0,0 +1,265 @@
|
||||
/**
|
||||
\file mainReceiver.cpp
|
||||
|
||||
This file is an example of how to implement the slsReceiverUsers class
|
||||
You can compile it linking it to the slsReceiver library
|
||||
|
||||
g++ mainReceiver.cpp -L lib -lSlsReceiver -L/usr/lib64/ -L lib2 -lzmq -pthread -lrt -lm -lstdc++
|
||||
|
||||
where,
|
||||
|
||||
lib is the location of lSlsReceiver.so
|
||||
|
||||
lib2 is the location of the libzmq.a.
|
||||
[ libzmq.a is required only when using data call backs and enabling data streaming from receiver to client.
|
||||
It is linked in manual/manual-api from slsReceiverSoftware/include ]
|
||||
|
||||
*/
|
||||
|
||||
#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"
|
||||
#include <sys/types.h> //wait
|
||||
#include <sys/wait.h> //wait
|
||||
#include <string>
|
||||
#include <unistd.h> //usleep
|
||||
#include <errno.h>
|
||||
#include <syscall.h> //tid
|
||||
using namespace std;
|
||||
|
||||
|
||||
/** Define Colors to print data call back in different colors for different recievers */
|
||||
#define PRINT_IN_COLOR(c,f, ...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)
|
||||
|
||||
|
||||
/** Variable is true to continue running, set to false upon interrupt */
|
||||
bool keeprunning;
|
||||
|
||||
/**
|
||||
* Control+C Interrupt Handler
|
||||
* Sets the variable keeprunning to false, to let all the processes know to exit properly
|
||||
*/
|
||||
void sigInterruptHandler(int p){
|
||||
keeprunning = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* prints usage of this example program
|
||||
*/
|
||||
void printHelp() {
|
||||
bprintf(GRAY, "Usage:\n"
|
||||
"./detReceiver\n"
|
||||
"or ./detReceiver [start_tcp_port] [num_receivers]\n"
|
||||
"Default values: start_tcp_port - 1954, num_receivers - 1\n\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Acquisition Call back
|
||||
* slsReceiver writes data if file write enabled.
|
||||
* Users get data to write using call back if registerCallBackRawDataReady is registered.
|
||||
* @param filepath file path
|
||||
* @param filename file name
|
||||
* @param fileindex file index
|
||||
* @param datasize data size in bytes
|
||||
* @param p pointer to object
|
||||
* \returns ignored
|
||||
*/
|
||||
int StartAcq(char* filepath, char* filename, uint64_t fileindex, uint32_t datasize, void*p){
|
||||
bprintf(BLUE, "#### StartAcq: filepath:%s filename:%s fileindex:%llu datasize:%u ####\n",
|
||||
filepath, filename, fileindex, datasize);
|
||||
|
||||
bprintf(BLUE, "--StartAcq: returning 0\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquisition Finished Call back
|
||||
* @param frames Number of frames caught
|
||||
* @param p pointer to object
|
||||
*/
|
||||
void AcquisitionFinished(uint64_t frames, void*p){
|
||||
bprintf(BLUE, "#### AcquisitionFinished: frames:%llu ####\n",frames);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Receiver Data Call back
|
||||
* Prints in different colors(for each receiver process) the different headers for each image call back.
|
||||
* @param frameNumber frame number
|
||||
* @param expLength real time exposure length (in 100ns) or sub frame number (Eiger 32 bit mode only)
|
||||
* @param packetNumber number of packets caught for this frame
|
||||
* @param bunchId bunch id from beamline
|
||||
* @param timestamp time stamp in 10MHz clock (not implemented for most)
|
||||
* @param modId module id (not implemented for most)
|
||||
* @param xCoord x coordinates (detector id in 1D)
|
||||
* @param yCoord y coordinates (not implemented)
|
||||
* @param zCoord z coordinates (not implemented)
|
||||
* @param debug debug values if any
|
||||
* @param roundRNumber (not implemented)
|
||||
* @param detType detector type see :: detectorType
|
||||
* @param version version of standard header (structure format)
|
||||
* @param datapointer pointer to data
|
||||
* @param datasize data size in bytes
|
||||
* @param p pointer to object
|
||||
*/
|
||||
void GetData(uint64_t frameNumber, uint32_t expLength, uint32_t packetNumber, uint64_t bunchId, uint64_t timestamp,
|
||||
uint16_t modId, uint16_t xCoord, uint16_t yCoord, uint16_t zCoord, uint32_t debug, uint16_t roundRNumber, uint8_t detType, uint8_t version,
|
||||
char* datapointer, uint32_t datasize, void* p){
|
||||
|
||||
PRINT_IN_COLOR (xCoord,
|
||||
"#### %d GetData: ####\n"
|
||||
"frameNumber: %llu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %llu\t\ttimestamp: %llu\t\tmodId: %u\t\t"
|
||||
"xCoord: %u\t\tyCoord: %u\t\tzCoord: %u\t\tdebug: %u\t\troundRNumber: %u\t\tdetType: %u\t\t"
|
||||
"version: %u\t\tfirstbytedata: 0x%x\t\tdatsize: %u\n\n",
|
||||
xCoord, frameNumber, expLength, packetNumber, bunchId, timestamp, modId,
|
||||
xCoord, yCoord, zCoord, debug, roundRNumber, detType, version,
|
||||
((uint8_t)(*((uint8_t*)(datapointer)))), datasize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Example of main program using the slsReceiverUsers class
|
||||
*
|
||||
* - Defines in file for:
|
||||
* - Default Number of receivers is 1
|
||||
* - Default Start TCP port is 1954
|
||||
*/
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
/** - set default values */
|
||||
int numReceivers = 1;
|
||||
int startTCPPort = 1954;
|
||||
keeprunning = true;
|
||||
|
||||
/** - get number of receivers and start tcp port from command line arguments */
|
||||
if (argc > 1 && ((argc < 3) || (!sscanf(argv[1],"%d", &startTCPPort)) || (!sscanf(argv[2],"%d", &numReceivers)) ))
|
||||
printHelp();
|
||||
bprintf(BLUE,"Parent Process Created [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
|
||||
bprintf(GRAY, "Number of Receivers: %d\n", numReceivers);
|
||||
bprintf(GRAY, "Start TCP Port: %d\n", startTCPPort);
|
||||
|
||||
|
||||
|
||||
/** - Catch signal SIGINT to close files and call destructors properly */
|
||||
struct sigaction sa;
|
||||
sa.sa_flags=0; // no flags
|
||||
sa.sa_handler=sigInterruptHandler; // handler function
|
||||
sigemptyset(&sa.sa_mask); // dont block additional signals during invocation of handler
|
||||
if (sigaction(SIGINT, &sa, NULL) == -1) {
|
||||
bprintf(RED, "Could not set handler function for SIGINT\n");
|
||||
}
|
||||
|
||||
/** - Ignore SIG_PIPE, prevents global signal handler, handle locally,
|
||||
instead of a server crashing due to client crash when writing, it just gives error */
|
||||
struct sigaction asa;
|
||||
asa.sa_flags=0; // no flags
|
||||
asa.sa_handler=SIG_IGN; // handler function
|
||||
sigemptyset(&asa.sa_mask); // dont block additional signals during invocation of handler
|
||||
if (sigaction(SIGPIPE, &asa, NULL) == -1) {
|
||||
bprintf(RED, "Could not set handler function for SIGPIPE\n");
|
||||
}
|
||||
|
||||
|
||||
/** - loop over number of receivers */
|
||||
for (int i = 0; i < numReceivers; ++i) {
|
||||
|
||||
/** - fork process to create child process */
|
||||
pid_t pid = fork();
|
||||
|
||||
/** - if fork failed, raise SIGINT and properly destroy all child processes */
|
||||
if (pid < 0) {
|
||||
bprintf(RED,"fork() failed. Killing all the receiver objects\n");
|
||||
raise(SIGINT);
|
||||
}
|
||||
|
||||
/** - if child process */
|
||||
else if (pid == 0) {
|
||||
bprintf(BLUE,"Child process %d [ Tid: %ld ]\n", i, (long)syscall(SYS_gettid));
|
||||
|
||||
char temp[10];
|
||||
sprintf(temp,"%d",startTCPPort + i);
|
||||
char* args[] = {(char*)"ignored", (char*)"--rx_tcpport", temp};
|
||||
int ret = slsReceiverDefs::OK;
|
||||
/** - create slsReceiverUsers object with appropriate arguments */
|
||||
slsReceiverUsers *receiver = new slsReceiverUsers(3, args, ret);
|
||||
if(ret==slsReceiverDefs::FAIL){
|
||||
delete receiver;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/** - register callbacks. remember to set file write enable to 0 (using the client)
|
||||
if we should not write files and you will write data using the callbacks */
|
||||
|
||||
/** - Call back for start acquisition */
|
||||
//bprintf(BLUE, "Registering StartAcq()\n");
|
||||
//receiver->registerCallBackStartAcquisition(StartAcq, NULL);
|
||||
|
||||
/** - Call back for acquisition finished */
|
||||
//bprintf(BLUE, "Registering AcquisitionFinished()\n");
|
||||
//receiver->registerCallBackAcquisitionFinished(AcquisitionFinished, NULL);
|
||||
|
||||
/* - Call back for raw data */
|
||||
//bprintf(BLUE, "Registering GetData() \n");
|
||||
//receiver->registerCallBackRawDataReady(GetData,NULL);
|
||||
|
||||
|
||||
/** - start tcp server thread */
|
||||
if (receiver->start() == slsReceiverDefs::FAIL){
|
||||
delete receiver;
|
||||
bprintf(BLUE,"Exiting Child Process [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/** - as long as keeprunning is true (changes with Ctrl+C) */
|
||||
while(keeprunning)
|
||||
pause();
|
||||
/** - interrupt caught, delete slsReceiverUsers object and exit */
|
||||
delete receiver;
|
||||
bprintf(BLUE,"Exiting Child Process [ Tid: %ld ]\n", (long)syscall(SYS_gettid));
|
||||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** - Parent process ignores SIGINT (exits only when all child process exits) */
|
||||
sa.sa_flags=0; // no flags
|
||||
sa.sa_handler=SIG_IGN; // handler function
|
||||
sigemptyset(&sa.sa_mask); // dont block additional signals during invocation of handler
|
||||
if (sigaction(SIGINT, &sa, NULL) == -1) {
|
||||
bprintf(RED, "Could not set handler function for SIGINT\n");
|
||||
}
|
||||
|
||||
|
||||
/** - Print Ready and Instructions how to exit */
|
||||
cout << "Ready ... " << endl;
|
||||
bprintf(GRAY, "\n[ Press \'Ctrl+c\' to exit ]\n");
|
||||
|
||||
/** - Parent process waits for all child processes to exit */
|
||||
for(;;) {
|
||||
pid_t childPid = waitpid (-1, NULL, 0);
|
||||
|
||||
// no child closed
|
||||
if (childPid == -1) {
|
||||
if (errno == ECHILD) {
|
||||
bprintf(GREEN,"All Child Processes have been closed\n");
|
||||
break;
|
||||
} else {
|
||||
bprintf(RED, "Unexpected error from waitpid(): (%s)\n",strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//child closed
|
||||
bprintf(BLUE,"Exiting Child Process [ Tid: %ld ]\n", (long int) childPid);
|
||||
}
|
||||
|
||||
cout << "Goodbye!" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user