mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
refactor receiver client interface, moved defs into one sls_detector_defs.h
This commit is contained in:
@ -30,8 +30,24 @@ int ClientInterface::PrintSocketReadError() {
|
||||
}
|
||||
|
||||
|
||||
void ClientInterface::Server_SendResult(int ret, void* retval, int retvalSize) {
|
||||
void ClientInterface::Server_SendResult(bool diffClients, int ret,
|
||||
void* retval, int retvalSize, char* mess) {
|
||||
|
||||
// update if different clients
|
||||
if (diffClients)
|
||||
ret = FORCE_UPDATE;
|
||||
|
||||
// send success of operation
|
||||
mySocket->SendDataOnly(&ret,sizeof(ret));
|
||||
if(ret == FAIL) {
|
||||
// send error message
|
||||
if (mess)
|
||||
mySocket->SendDataOnly(mess, MAX_STR_LENGTH);
|
||||
// debugging feature. should not happen.
|
||||
else
|
||||
FILE_LOG(logERROR) << "No error message provided for this failure. Will mess up TCP\n";
|
||||
}
|
||||
// send return value
|
||||
mySocket->SendDataOnly(retval, retvalSize);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "sls_receiver_defs.h"
|
||||
#include "sls_detector_defs.h"
|
||||
#include "MySocketTCP.h"
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
*/
|
||||
// Do not overload to make it easier for manual comparison between client and server functions
|
||||
|
||||
class ClientInterface: public virtual slsReceiverDefs{
|
||||
class ClientInterface: public virtual slsDetectorDefs{
|
||||
|
||||
public:
|
||||
|
||||
@ -39,12 +39,14 @@ public:
|
||||
int PrintSocketReadError();
|
||||
|
||||
/**
|
||||
* Server sends result to client
|
||||
* Server sends result to client (also set ret to force_update if different clients)
|
||||
* @param diffClients true if different clients, else false
|
||||
* @param ret success of operation
|
||||
* @param retval pointer to result
|
||||
* @param retvalSize size of result
|
||||
* @param mess message
|
||||
*/
|
||||
void Server_SendResult(int ret, void* retval, int retvalSize);
|
||||
void Server_SendResult(bool diffClients, int ret, void* retval, int retvalSize, char* mess = 0);
|
||||
|
||||
/**
|
||||
* Get message from server
|
||||
@ -54,7 +56,7 @@ public:
|
||||
* @param mess message
|
||||
* @returns FAIL if unrecognized function found in message, else OK
|
||||
*/
|
||||
int Client_GetMesage(char* mess=0);
|
||||
int Client_GetMesage(char* mess = 0);
|
||||
|
||||
/**
|
||||
* Send Arguments to server and get result back
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,312 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#ifdef __CINT__
|
||||
#define MYROOT
|
||||
#define __cplusplus
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#ifdef __cplusplus
|
||||
#include <bitset>
|
||||
#include <string>
|
||||
#endif
|
||||
#include "ansi.h"
|
||||
|
||||
|
||||
typedef double double32_t;
|
||||
typedef float float32_t;
|
||||
typedef int int32_t;
|
||||
|
||||
/** default maximum string length */
|
||||
#define MAX_STR_LENGTH 1000
|
||||
#define MAX_FRAMES_PER_FILE 20000
|
||||
#define SHORT_MAX_FRAMES_PER_FILE 100000
|
||||
#define MOENCH_MAX_FRAMES_PER_FILE 1000
|
||||
#define EIGER_MAX_FRAMES_PER_FILE 10000
|
||||
#define JFRAU_MAX_FRAMES_PER_FILE 10000
|
||||
#define JFCTB_MAX_FRAMES_PER_FILE 100000
|
||||
|
||||
|
||||
#define DEFAULT_STREAMING_TIMER_IN_MS 200
|
||||
|
||||
/** default ports */
|
||||
#define DEFAULT_PORTNO 1952
|
||||
#define DEFAULT_UDP_PORTNO 50001
|
||||
#define DEFAULT_GUI_PORTNO 65001
|
||||
#define DEFAULT_ZMQ_CL_PORTNO 30001
|
||||
#define DEFAULT_ZMQ_RX_PORTNO 30001
|
||||
|
||||
#define SLS_DETECTOR_HEADER_VERSION 0x2
|
||||
#define SLS_DETECTOR_JSON_HEADER_VERSION 0x3
|
||||
|
||||
/**
|
||||
\file sls_receiver_defs.h
|
||||
This file contains all the basic definitions common to the slsReceiver class
|
||||
and to the server programs running on the receiver
|
||||
* @author Anna Bergamaschi
|
||||
* @version 0.1alpha (any string)
|
||||
* @see slsDetector
|
||||
$Revision: 809 $
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
/** @short class containing all the constants and enum definitions */
|
||||
class slsReceiverDefs {
|
||||
public:
|
||||
|
||||
slsReceiverDefs(){};
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
Type of the detector
|
||||
*/
|
||||
enum detectorType {
|
||||
GET_DETECTOR_TYPE=-1, /**< the detector will return its type */
|
||||
GENERIC, /**< generic sls detector */
|
||||
EIGER, /**< eiger */
|
||||
GOTTHARD, /**< gotthard */
|
||||
MOENCH, /**< moench */
|
||||
JUNGFRAU, /**< jungfrau */
|
||||
JUNGFRAUCTB, /**< jungfrauCTBversion */
|
||||
PROPIX, /**< propix */
|
||||
MYTHEN3 /**< mythen 3 */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
return values
|
||||
*/
|
||||
enum {
|
||||
OK, /**< function succeeded */
|
||||
FAIL, /**< function failed */
|
||||
FINISHED, /**< acquisition finished */
|
||||
FORCE_UPDATE
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
indexes for the acquisition timers
|
||||
*/
|
||||
enum timerIndex {
|
||||
FRAME_NUMBER, /**< number of real time frames: total number of acquisitions is number or frames*number of cycles */
|
||||
ACQUISITION_TIME, /**< exposure time */
|
||||
FRAME_PERIOD, /**< period between exposures */
|
||||
DELAY_AFTER_TRIGGER, /**< delay between trigger and start of exposure or readout (in triggered mode) */
|
||||
GATES_NUMBER, /**< number of gates per frame (in gated mode) */
|
||||
CYCLES_NUMBER, /**< number of cycles: total number of acquisitions is number or frames*number of cycles */
|
||||
ACTUAL_TIME, /**< Actual time of the detector's internal timer */
|
||||
MEASUREMENT_TIME, /**< Time of the measurement from the detector (fifo) */
|
||||
|
||||
PROGRESS, /**< fraction of measurement elapsed - only get! */
|
||||
MEASUREMENTS_NUMBER,
|
||||
FRAMES_FROM_START,
|
||||
FRAMES_FROM_START_PG,
|
||||
SAMPLES_JCTB,
|
||||
SUBFRAME_ACQUISITION_TIME, /**< subframe exposure time */
|
||||
STORAGE_CELL_NUMBER, /**<number of storage cells */
|
||||
SUBFRAME_DEADTIME, /**< subframe deadtime */
|
||||
MEASURED_PERIOD, /**< measured period */
|
||||
MEASURED_SUBPERIOD, /**< measured subperiod */
|
||||
MAX_TIMERS
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
staus mask
|
||||
*/
|
||||
enum runStatus {
|
||||
IDLE, /**< detector ready to start acquisition - no data in memory */
|
||||
ERROR, /**< error i.e. normally fifo full */
|
||||
WAITING, /**< waiting for trigger or gate signal */
|
||||
RUN_FINISHED, /**< acquisition not running but data in memory */
|
||||
TRANSMITTING, /**< acquisition running and data in memory */
|
||||
RUNNING, /**< acquisition running, no data in memory */
|
||||
STOPPED /**< acquisition stopped externally */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@short structure for a Detector Packet or Image Header
|
||||
@li frameNumber is the frame number
|
||||
@li expLength is the subframe number (32 bit eiger) or real time exposure time in 100ns (others)
|
||||
@li packetNumber is the packet number
|
||||
@li bunchId is the bunch id from beamline
|
||||
@li timestamp is the time stamp with 10 MHz clock
|
||||
@li modId is the unique module id (unique even for left, right, top, bottom)
|
||||
@li row is the row index in the complete detector system
|
||||
@li column is the column index in the complete detector system
|
||||
@li reserved is reserved
|
||||
@li debug is for debugging purposes
|
||||
@li roundRNumber is the round robin set number
|
||||
@li detType is the detector type see :: detectorType
|
||||
@li version is the version number of this structure format
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
uint64_t frameNumber; /**< is the frame number */
|
||||
uint32_t expLength; /**< is the subframe number (32 bit eiger) or real time exposure time in 100ns (others) */
|
||||
uint32_t packetNumber; /**< is the packet number */
|
||||
uint64_t bunchId; /**< is the bunch id from beamline */
|
||||
uint64_t timestamp; /**< is the time stamp with 10 MHz clock */
|
||||
uint16_t modId; /**< is the unique module id (unique even for left, right, top, bottom) */
|
||||
uint16_t row; /**< is the row index in the complete detector system */
|
||||
uint16_t column; /**< is the column index in the complete detector system */
|
||||
uint16_t reserved; /**< is reserved */
|
||||
uint32_t debug; /**< is for debugging purposes */
|
||||
uint16_t roundRNumber; /**< is the round robin set number */
|
||||
uint8_t detType; /**< is the detector type see :: detectorType */
|
||||
uint8_t version; /**< is the version number of this structure format */
|
||||
} sls_detector_header;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define MAX_NUM_PACKETS 512
|
||||
|
||||
typedef std::bitset<MAX_NUM_PACKETS> sls_bitset;
|
||||
|
||||
typedef struct {
|
||||
sls_detector_header detHeader; /**< is the detector header */
|
||||
sls_bitset packetsMask; /**< is the packets caught bit mask */
|
||||
} sls_receiver_header;
|
||||
|
||||
typedef uint8_t bitset_storage[MAX_NUM_PACKETS/8];
|
||||
|
||||
#endif
|
||||
/**
|
||||
* frameDiscardPolicy
|
||||
*/
|
||||
enum frameDiscardPolicy {
|
||||
GET_FRAME_DISCARD_POLICY = -1, /**< to get the missing packet mode */
|
||||
NO_DISCARD, /**< pad incomplete packets with -1, default mode */
|
||||
DISCARD_EMPTY_FRAMES, /**< discard incomplete frames, fastest mode, save space, not suitable for multiple modules */
|
||||
DISCARD_PARTIAL_FRAMES, /**< ignore missing packets, must check with packetsMask for data integrity, fast mode and suitable for multiple modules */
|
||||
NUM_DISCARD_POLICIES
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
format
|
||||
*/
|
||||
enum fileFormat {
|
||||
GET_FILE_FORMAT=-1,/**< the receiver will return its file format */
|
||||
BINARY, /**< binary format */
|
||||
ASCII, /**< ascii format */
|
||||
HDF5, /**< hdf5 format */
|
||||
NUM_FILE_FORMATS
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@short structure for a region of interest
|
||||
xmin,xmax,ymin,ymax define the limits of the region
|
||||
*/
|
||||
typedef struct {
|
||||
int xmin; /**< is the roi xmin (in channel number) */
|
||||
int xmax; /**< is the roi xmax (in channel number)*/
|
||||
int ymin; /**< is the roi ymin (in channel number)*/
|
||||
int ymax; /**< is the roi ymax (in channel number)*/
|
||||
} ROI ;
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
/** returns string from enabled/disabled
|
||||
\param b true or false
|
||||
\returns string enabled, disabled
|
||||
*/
|
||||
static std::string stringEnable(bool b){\
|
||||
if(b) return std::string("enabled"); \
|
||||
else return std::string("disabled"); \
|
||||
};
|
||||
|
||||
/** returns detector type string from detector type index
|
||||
\param t string can be Mythen, Pilatus, Eiger, Gotthard, Agipd, Unknown
|
||||
\returns MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, MÖNCH, GENERIC
|
||||
*/
|
||||
static std::string getDetectorType(detectorType t){ \
|
||||
switch (t) { \
|
||||
case EIGER: return std::string("Eiger"); \
|
||||
case GOTTHARD: return std::string("Gotthard"); \
|
||||
case MOENCH: return std::string("Moench"); \
|
||||
case JUNGFRAU: return std::string("Jungfrau"); \
|
||||
case JUNGFRAUCTB: return std::string("JungfrauCTB"); \
|
||||
case PROPIX: return std::string("Propix"); \
|
||||
case MYTHEN3: return std::string("Mythen3"); \
|
||||
default: return std::string("Unknown"); \
|
||||
}};
|
||||
|
||||
/** returns detector type index from detector type string
|
||||
\param type can be MYTHEN, PILATUS, EIGER, GOTTHARD, AGIPD, GENERIC
|
||||
\returns Mythen, Pilatus, Eiger, Gotthard, Agipd, Mönch, Unknown
|
||||
*/
|
||||
static detectorType getDetectorType(std::string const type){\
|
||||
if (type=="Eiger") return EIGER; \
|
||||
if (type=="Gotthard") return GOTTHARD; \
|
||||
if (type=="Moench") return MOENCH; \
|
||||
if (type=="Jungfrau") return JUNGFRAU; \
|
||||
if (type=="JungfrauCTB") return JUNGFRAUCTB; \
|
||||
if (type=="Propix") return PROPIX; \
|
||||
if (type=="Mythen3") return MYTHEN3; \
|
||||
return GENERIC; \
|
||||
};
|
||||
|
||||
|
||||
/** returns string from run status index
|
||||
\param s can be ERROR, WAITING, RUNNING, TRANSMITTING, RUN_FINISHED
|
||||
\returns string error, waiting, running, data, finished
|
||||
*/
|
||||
static std::string runStatusType(runStatus s){\
|
||||
switch (s) { \
|
||||
case ERROR: return std::string("error"); \
|
||||
case WAITING: return std::string("waiting"); \
|
||||
case RUNNING: return std::string("running"); \
|
||||
case TRANSMITTING: return std::string("data"); \
|
||||
case RUN_FINISHED: return std::string("finished"); \
|
||||
case STOPPED: return std::string("stopped"); \
|
||||
default: return std::string("idle"); \
|
||||
}};
|
||||
|
||||
|
||||
/** returns string from file format index
|
||||
\param s can be BINARY, ASCII, HDF5
|
||||
\returns string binary, ascii, hdf5
|
||||
*/
|
||||
static std::string getFileFormatType(fileFormat f){\
|
||||
switch (f) { \
|
||||
case ASCII: return std::string("ascii"); \
|
||||
case HDF5: return std::string("hdf5"); \
|
||||
case BINARY: return std::string("binary"); \
|
||||
default: return std::string("unknown"); \
|
||||
}};
|
||||
|
||||
/**
|
||||
* Returns string of frame discard policy index
|
||||
* @param f can be NO_DISCARD, DISCARD_EMPTY_FRAMES, DISCARD_PARTIAL_FRAMES
|
||||
* @returns No Discard, Discard Empty Frames, Discard Partial Frames, unknown
|
||||
*/
|
||||
static std::string getFrameDiscardPolicyType(frameDiscardPolicy f) { \
|
||||
switch (f) { \
|
||||
case NO_DISCARD: return std::string("No Discard"); \
|
||||
case DISCARD_EMPTY_FRAMES: return std::string("Discard Empty Frames"); \
|
||||
case DISCARD_PARTIAL_FRAMES: return std::string("Discard Partial Frames"); \
|
||||
default: return std::string("unknown"); \
|
||||
}}; \
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
protected:
|
||||
#endif
|
||||
|
||||
#ifndef MYROOT
|
||||
#include "sls_receiver_funcs.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
;
|
@ -13,7 +13,7 @@ int read_config_file(std::string fname, int *tcpip_port_no,
|
||||
std::ifstream infile;
|
||||
std::string sLine,sargname, sargvalue;
|
||||
int iline = 0;
|
||||
int success = slsReceiverDefs::OK;
|
||||
int success = slsDetectorDefs::OK;
|
||||
|
||||
|
||||
FILE_LOG(logINFO) << "config file name " << fname;
|
||||
@ -21,10 +21,10 @@ int read_config_file(std::string fname, int *tcpip_port_no,
|
||||
infile.open(fname.c_str(), std::ios_base::in);
|
||||
} catch(...) {
|
||||
FILE_LOG(logERROR) << "Could not open configuration file " << fname ;
|
||||
success = slsReceiverDefs::FAIL;
|
||||
success = slsDetectorDefs::FAIL;
|
||||
}
|
||||
|
||||
if (success == slsReceiverDefs::OK && infile.is_open()) {
|
||||
if (success == slsDetectorDefs::OK && infile.is_open()) {
|
||||
while(infile.good()){
|
||||
getline(infile,sLine);
|
||||
iline++;
|
||||
@ -58,7 +58,7 @@ int read_config_file(std::string fname, int *tcpip_port_no,
|
||||
cprintf(RESET, "dataport: %d\n" , *tcpip_port_no);
|
||||
else{
|
||||
cprintf(RED, "could not decode port in config file. Exiting.\n");
|
||||
success = slsReceiverDefs::FAIL;
|
||||
success = slsDetectorDefs::FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,25 +120,25 @@ int readDataFile(std::string fname, short int *data, int nch) {
|
||||
|
||||
int writeDataFile(std::ofstream &outfile,int nch, short int *data, int offset) {
|
||||
if (data==NULL)
|
||||
return slsReceiverDefs::FAIL;
|
||||
return slsDetectorDefs::FAIL;
|
||||
for (int ichan=0; ichan<nch; ichan++)
|
||||
outfile << ichan+offset << " " << *(data+ichan) << std::endl;
|
||||
return slsReceiverDefs::OK;
|
||||
return slsDetectorDefs::OK;
|
||||
}
|
||||
|
||||
|
||||
int writeDataFile(std::string fname,int nch, short int *data) {
|
||||
std::ofstream outfile;
|
||||
if (data==NULL)
|
||||
return slsReceiverDefs::FAIL;
|
||||
return slsDetectorDefs::FAIL;
|
||||
outfile.open (fname.c_str(),std::ios_base::out);
|
||||
if (outfile.is_open()) {
|
||||
writeDataFile(outfile, nch, data, 0);
|
||||
outfile.close();
|
||||
return slsReceiverDefs::OK;
|
||||
return slsDetectorDefs::OK;
|
||||
} else {
|
||||
FILE_LOG(logERROR) << "Could not open file " << fname << "for writing";
|
||||
return slsReceiverDefs::FAIL;
|
||||
return slsDetectorDefs::FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "sls_receiver_defs.h"
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
Reference in New Issue
Block a user