# mainReceiver.cpp File Reference

`#include "sls_receiver_defs.h"`
`#include "slsReceiverUsers.h"`
`#include <iostream>`
`#include <string.h>`
`#include <signal.h>`
`#include <cstdlib>`
`#include <sys/types.h>`
`#include <sys/wait.h>`
`#include <string>`

Go to the source code of this file.

## Defines
#define | NUM_RECEIVERS 1
#define | START_TCP_PORT 1954
#define | PRINT_IN_COLOR(c, f,...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)
## Functions
void | sigChildExitedHandler (int sig)
void | sigInterruptHandler (int p)
int | StartAcq (char *filepath, char *filename, uint64_t fileindex, uint32_t datasize, void *p)
void | AcquisitionFinished (uint64_t frames, void *p)
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)
int | main (int argc, char *argv[])
## Variables
pid_t | childPid [NUM_RECEIVERS]
bool | keeprunning
int | numrunning

## Detailed Description

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 ]

Definition in file mainReceiver.cpp.

## Define Documentation

#define NUM_RECEIVERS 1

Definition at line 34 of file mainReceiver.cpp.

#define PRINT_IN_COLOR | ( | c,
|  | f,
|  | ... |  | ) | printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)

Define Colors to print data call back in different colors for different recievers

Definition at line 38 of file mainReceiver.cpp.

#define START_TCP_PORT 1954

Define TCP Port of First Receiver, others are incremented by 1

Definition at line 36 of file mainReceiver.cpp.

## Function Documentation

void AcquisitionFinished | ( | uint64_t | frames,
|  | void * | p |
| ) |  |  |

Acquisition Finished Call back

Parameters:

  | frames | Number of frames caught
  | p | pointer to object

Definition at line 93 of file mainReceiver.cpp.

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 |
| ) |  |  |

Get Receiver Data Call back Prints in different colors(for each receiver process) the different headers for each image call back.

Parameters:

  | frameNumber | frame number
  | expLength | real time exposure length (in 100ns) or sub frame number (Eiger 32 bit mode only)
  | packetNumber | number of packets caught for this frame
  | bunchId | bunch id from beamline
  | timestamp | time stamp in 10MHz clock (not implemented for most)
  | modId | module id (not implemented for most)
  | xCoord | x coordinates (detector id in 1D)
  | yCoord | y coordinates (not implemented)
  | zCoord | z coordinates (not implemented)
  | debug | debug values if any
  | roundRNumber | (not implemented)
  | detType | detector type see :: detectorType
  | version | version of standard header (structure format)
  | datapointer | pointer to data
  | datasize | data size in bytes
  | p | pointer to object

Definition at line 117 of file mainReceiver.cpp.

int main | ( | int | argc,
|  | char * | argv[] |
| ) |  |  |

Example of main program using the slsReceiverUsers class

- Defines in file for:
  - Default Number of receivers is 1
  - Default Start TCP port is 1954

- set default values: child process pid values to -1, keeprunning to true, numrunning to 0

- Catch signal SIGINT to close files and call destructors properly

- wait for all the SIGCHILD signals and decrease numrunningeach time a child process exits

- loop over number of receivers

- fork process to create child process

- if fork failed, raise SIGINT and kill all receiver objects

- if child process

- create slsReceiverUsers object with appropriate arguments (START_TCP_PORT incrementing by 1

- 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

- Call back for acquisition finished

- start tcp server thread

- as long as keeprunning is true, usleep for a second

- interrupt caught, delete slsReceiverUsers object and exit

- parent process, increment number of running processes

- Print Ready and Instructions how to exit

- Parent process waits for all child processes to exit by sleeping till numrunning is 0

Definition at line 140 of file mainReceiver.cpp.

void sigChildExitedHandler | ( | int | sig | ) |

Child Exit Signal Interrupt Handler When a child process exits, this function is called, blocks until all child processes exit & decreases the variable indicating number of running processes

Parameters:

  | sig | signal enum

Definition at line 55 of file mainReceiver.cpp.

void sigInterruptHandler | ( | int | p | ) |

Control+C Interrupt Handler Sets the variable keeprunning to false, to let all the processes know to exit properly

Definition at line 65 of file mainReceiver.cpp.

int StartAcq | ( | char * | filepath,
|  | char * | filename,
|  | uint64_t | fileindex,
|  | uint32_t | datasize,
|  | void * | p |
| ) |  |  |

Start Acquisition Call back slsReceiver writes data if file write enabled. Users get data to write using call back if registerCallBackRawDataReady is registered.

Parameters:

  | filepath | file path
  | filename | file name
  | fileindex | file index
  | datasize | data size in bytes
  | p | pointer to object

Returns:
  ignored

Definition at line 80 of file mainReceiver.cpp.

## Variable Documentation

pid_t childPid[NUM_RECEIVERS]

Definition at line 41 of file mainReceiver.cpp.

bool keeprunning

Variable is true to continue running, set to false upon interrupt

Definition at line 43 of file mainReceiver.cpp.

int numrunning

Variable indicating number of child processes running

Definition at line 45 of file mainReceiver.cpp.

All Classes Files Functions Variables Defines