# 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>`
`#include <unistd.h>`
`#include <errno.h>`
`#include <syscall.h>`

Go to the source code of this file.

## Defines
#define | PRINT_IN_COLOR(c, f,...) printf ("\033[%dm" f RESET, 30 + c+1, ##__VA_ARGS__)
## Functions
void | sigInterruptHandler (int p)
void | printHelp ()
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
bool | keeprunning

## 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 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.

## 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 85 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 109 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

- get number of receivers and start tcp port from command line arguments

- Catch signal SIGINT to close files and call destructors properly

- Ignore SIG_PIPE, prevents global signal handler, handle locally, instead of a server crashing due to client crash when writing, it just gives error

- loop over number of receivers

- fork process to create child process

- if fork failed, raise SIGINT and properly destroy all child processes

- if child process

- create slsReceiverUsers object with appropriate arguments

- 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 (changes with Ctrl+C)

- interrupt caught, delete slsReceiverUsers object and exit

- Parent process ignores SIGINT (exits only when all child process exits)

- Print Ready and Instructions how to exit

- Parent process waits for all child processes to exit

Definition at line 132 of file mainReceiver.cpp.

void printHelp | ( |  | ) |

prints usage of this example program

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 48 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 72 of file mainReceiver.cpp.

## Variable Documentation

bool keeprunning

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

Definition at line 42 of file mainReceiver.cpp.

All Classes Files Functions Variables Defines