19 #include "sls_receiver_defs.h"
28 #include <sys/types.h>
38 #define PRINT_IN_COLOR(c,f, ...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)
56 cprintf(RESET,
"Usage:\n"
57 "./slsMultiReceiver(detReceiver) [start_tcp_port] [num_receivers] [1 for call back, 0 for none]\n\n");
72 int StartAcq(
char* filepath,
char* filename, uint64_t fileindex, uint32_t datasize,
void*p){
73 cprintf(BLUE,
"#### StartAcq: filepath:%s filename:%s fileindex:%llu datasize:%u ####\n",
74 filepath, filename, (
long long unsigned int)fileindex, datasize);
76 cprintf(BLUE,
"--StartAcq: returning 0\n");
86 cprintf(BLUE,
"#### AcquisitionFinished: frames:%llu ####\n",(
long long unsigned int)frames);
98 void GetData(
char* metadata,
char* datapointer, uint32_t datasize,
void* p){
99 slsReceiverDefs::sls_receiver_header* header = (slsReceiverDefs::sls_receiver_header*)metadata;
100 slsReceiverDefs::sls_detector_header detectorHeader = header->detHeader;
102 PRINT_IN_COLOR (detectorHeader.modId?detectorHeader.modId:detectorHeader.row,
103 "#### %d GetData: ####\n"
104 "frameNumber: %llu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %llu"
105 "\t\ttimestamp: %llu\t\tmodId: %u\t\t"
106 "row: %u\t\tcolumn: %u\t\treserved: %u\t\tdebug: %u"
107 "\t\troundRNumber: %u\t\tdetType: %u\t\tversion: %u"
109 "\t\tfirstbytedata: 0x%x\t\tdatsize: %u\n\n",
110 detectorHeader.row, (
long long unsigned int)detectorHeader.frameNumber,
111 detectorHeader.expLength, detectorHeader.packetNumber, (
long long unsigned int)detectorHeader.bunchId,
112 (
long long unsigned int)detectorHeader.timestamp, detectorHeader.modId,
113 detectorHeader.row, detectorHeader.column, detectorHeader.reserved,
114 detectorHeader.debug, detectorHeader.roundRNumber,
115 detectorHeader.detType, detectorHeader.version,
117 ((uint8_t)(*((uint8_t*)(datapointer)))), datasize);
132 void GetData(
char* metadata,
char* datapointer, uint32_t &revDatasize,
void* p){
133 slsReceiverDefs::sls_receiver_header* header = (slsReceiverDefs::sls_receiver_header*)metadata;
134 slsReceiverDefs::sls_detector_header detectorHeader = header->detHeader;
136 PRINT_IN_COLOR (detectorHeader.modId?detectorHeader.modId:detectorHeader.row,
137 "#### %d GetData: ####\n"
138 "frameNumber: %llu\t\texpLength: %u\t\tpacketNumber: %u\t\tbunchId: %llu"
139 "\t\ttimestamp: %llu\t\tmodId: %u\t\t"
140 "row: %u\t\tcolumn: %u\t\treserved: %u\t\tdebug: %u"
141 "\t\troundRNumber: %u\t\tdetType: %u\t\tversion: %u"
143 "\t\tfirstbytedata: 0x%x\t\tdatsize: %u\n\n",
144 detectorHeader.row, (
long long unsigned int)detectorHeader.frameNumber,
145 detectorHeader.expLength, detectorHeader.packetNumber, (
long long unsigned int)detectorHeader.bunchId,
146 (
long long unsigned int)detectorHeader.timestamp, detectorHeader.modId,
147 detectorHeader.row, detectorHeader.column, detectorHeader.reserved,
148 detectorHeader.debug, detectorHeader.roundRNumber,
149 detectorHeader.detType, detectorHeader.version,
151 ((uint8_t)(*((uint8_t*)(datapointer)))), revDatasize);
167 int main(
int argc,
char *argv[]) {
170 int numReceivers = 1;
171 int startTCPPort = 1954;
172 int withCallback = 0;
176 if ( (argc != 4) || (!sscanf(argv[1],
"%d", &startTCPPort)) || (!sscanf(argv[2],
"%d", &numReceivers)) || (!sscanf(argv[3],
"%d", &withCallback)) )
178 cprintf(BLUE,
"Parent Process Created [ Tid: %ld ]\n", (
long)syscall(SYS_gettid));
179 cprintf(RESET,
"Number of Receivers: %d\n", numReceivers);
180 cprintf(RESET,
"Start TCP Port: %d\n", startTCPPort);
181 cprintf(RESET,
"Callback Enable: %d\n", withCallback);
189 sigemptyset(&sa.sa_mask);
190 if (sigaction(SIGINT, &sa, NULL) == -1) {
191 cprintf(RED,
"Could not set handler function for SIGINT\n");
196 struct sigaction asa;
198 asa.sa_handler=SIG_IGN;
199 sigemptyset(&asa.sa_mask);
200 if (sigaction(SIGPIPE, &asa, NULL) == -1) {
201 cprintf(RED,
"Could not set handler function for SIGPIPE\n");
206 for (
int i = 0; i < numReceivers; ++i) {
213 cprintf(RED,
"fork() failed. Killing all the receiver objects\n");
219 cprintf(BLUE,
"Child process %d [ Tid: %ld ]\n", i, (
long)syscall(SYS_gettid));
222 sprintf(temp,
"%d",startTCPPort + i);
223 char* args[] = {(
char*)
"ignored", (
char*)
"--rx_tcpport", temp};
224 int ret = slsReceiverDefs::OK;
227 if(ret==slsReceiverDefs::FAIL){
238 cprintf(BLUE,
"Registering StartAcq()\n");
242 cprintf(BLUE,
"Registering AcquisitionFinished()\n");
246 cprintf(BLUE,
"Registering GetData() \n");
254 if (receiver->
start() == slsReceiverDefs::FAIL){
256 cprintf(BLUE,
"Exiting Child Process [ Tid: %ld ]\n", (
long)syscall(SYS_gettid));
265 cprintf(BLUE,
"Exiting Child Process [ Tid: %ld ]\n", (
long)syscall(SYS_gettid));
273 sa.sa_handler=SIG_IGN;
274 sigemptyset(&sa.sa_mask);
275 if (sigaction(SIGINT, &sa, NULL) == -1) {
276 cprintf(RED,
"Could not set handler function for SIGINT\n");
281 cout <<
"Ready ... " << endl;
282 cprintf(RESET,
"\n[ Press \'Ctrl+c\' to exit ]\n");
286 pid_t childPid = waitpid (-1, NULL, 0);
289 if (childPid == -1) {
290 if (errno == ECHILD) {
291 cprintf(GREEN,
"All Child Processes have been closed\n");
294 cprintf(RED,
"Unexpected error from waitpid(): (%s)\n",strerror(errno));
300 cprintf(BLUE,
"Exiting Child Process [ Tid: %ld ]\n", (
long int) childPid);
303 cout <<
"Goodbye!" << endl;
void registerCallBackRawDataReady(void(*func)(char *header, char *datapointer, uint32_t datasize, void *), void *arg)
register callback to be called when data are available (to process and/or save the data)...
int StartAcq(char *filepath, char *filename, uint64_t fileindex, uint32_t datasize, void *p)
int main(int argc, char **argv)
void registerCallBackAcquisitionFinished(void(*func)(uint64_t nf, void *), void *arg)
register callback for end of acquisition
void AcquisitionFinished(uint64_t frames, void *p)
Class for implementing the SLS data receiver in the users application. Callbacks can be defined for p...
#define PRINT_IN_COLOR(c, f,...)
void sigInterruptHandler(int p)
void GetData(char *metadata, char *datapointer, uint32_t datasize, void *p)
void registerCallBackStartAcquisition(int(*func)(char *filepath, char *filename, uint64_t fileindex, uint32_t datasize, void *), void *arg)
register calbback for starting the acquisition
void registerCallBackRawDataModifyReady(void(*func)(char *header, char *datapointer, uint32_t &revDatasize, void *), void *arg)
register callback to be called when data are available (to process and/or save the data)...