mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-19 16:27:13 +02:00
Merge branch 'refactor' of github.com:slsdetectorgroup/slsDetectorPackage into refactor
This commit is contained in:
@ -1,16 +1,6 @@
|
||||
#include "ClientInterface.h"
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <bitset>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
ClientInterface::ClientInterface(MySocketTCP *socket, int n, std::string t):
|
||||
mySocket(socket),
|
||||
index(n),
|
||||
@ -55,7 +45,7 @@ int ClientInterface::Client_Send(int fnum,
|
||||
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
if (Client_GetMesage(mess) == FAIL)
|
||||
return FAIL;
|
||||
return FAIL;
|
||||
}
|
||||
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
|
||||
|
||||
@ -63,33 +53,11 @@ int ClientInterface::Client_Send(int fnum,
|
||||
}
|
||||
|
||||
|
||||
int ClientInterface::Client_Send(int fnum,
|
||||
void* args, int sizeOfArgs,
|
||||
void* args2, int sizeOfArgs2,
|
||||
void* retval, int sizeOfRetval,
|
||||
char* mess) {
|
||||
|
||||
mySocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
mySocket->SendDataOnly(args, sizeOfArgs);
|
||||
mySocket->SendDataOnly(args2, sizeOfArgs2);
|
||||
|
||||
int ret = FAIL;
|
||||
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
if (ret == FAIL) {
|
||||
if (Client_GetMesage(mess) == FAIL)
|
||||
return FAIL;
|
||||
}
|
||||
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void ClientInterface::Server_SendResult(bool update, int ret,
|
||||
int ClientInterface::Server_SendResult(bool update, int ret,
|
||||
void* retval, int retvalSize, char* mess) {
|
||||
|
||||
// update if different clients
|
||||
if (update && mySocket->differentClients)
|
||||
if (update && ret == OK && mySocket->differentClients)
|
||||
ret = FORCE_UPDATE;
|
||||
|
||||
// send success of operation
|
||||
@ -104,6 +72,8 @@ void ClientInterface::Server_SendResult(bool update, int ret,
|
||||
}
|
||||
// send return value
|
||||
mySocket->SendDataOnly(retval, retvalSize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@ -112,7 +82,6 @@ int ClientInterface::Server_ReceiveArg(int& ret, char* mess, void* arg, int size
|
||||
if (sizeofArg && mySocket->ReceiveDataOnly(arg, sizeofArg) < 0)
|
||||
return Server_SocketCrash();
|
||||
|
||||
ret = OK;
|
||||
// check if server object created
|
||||
if (checkbase && base == NULL)
|
||||
Server_NullObjectError(ret, mess);
|
||||
@ -143,7 +112,6 @@ int ClientInterface::Server_VerifyLockAndIdle(int& ret, char* mess, int lockstat
|
||||
|
||||
|
||||
void ClientInterface::Server_NullObjectError(int& ret, char* mess) {
|
||||
// only for receiver
|
||||
ret=FAIL;
|
||||
strcpy(mess,"Receiver not set up. Please use rx_hostname first.\n");
|
||||
FILE_LOG(logERROR) << mess;
|
||||
@ -158,7 +126,7 @@ int ClientInterface::Server_SocketCrash() {
|
||||
|
||||
int ClientInterface::Server_LockedError(int& ret, char* mess) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"%s locked by %s\n",type.c_str(), mySocket->lastClientIP);
|
||||
sprintf(mess,"Receiver locked by %s\n", mySocket->lastClientIP);
|
||||
FILE_LOG(logERROR) << mess;
|
||||
return ret;
|
||||
}
|
||||
@ -166,8 +134,8 @@ int ClientInterface::Server_LockedError(int& ret, char* mess) {
|
||||
|
||||
int ClientInterface::Server_NotIdleError(int& ret, char* mess, int fnum) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Can not execute %s when %s is not idle\n",
|
||||
getFunctionNameFromEnum((enum detFuncs)fnum), type.c_str());
|
||||
sprintf(mess,"Can not execute %s when receiver is not idle\n",
|
||||
getFunctionNameFromEnum((enum detFuncs)fnum));
|
||||
FILE_LOG(logERROR) << mess;
|
||||
return ret;
|
||||
}
|
||||
|
@ -57,34 +57,19 @@ public:
|
||||
void* retval, int sizeOfRetval,
|
||||
char* mess = 0);
|
||||
|
||||
/**
|
||||
* Send Arguments (second set) to server and get result back
|
||||
* @param fnum function enum to determine what parameter
|
||||
* @param args pointer to arguments
|
||||
* @param sizeOfArgs argument size
|
||||
* @param args2 pointer to arguments 2
|
||||
* @param sizeOfArgs2 argument size 2
|
||||
* @param retval pointer to return value
|
||||
* @param sizeOfRetval return value size
|
||||
* @param mess pointer to message if message required externally
|
||||
*/
|
||||
int Client_Send(int fnum,
|
||||
void* args, int sizeOfArgs,
|
||||
void* args2, int sizeOfArgs2,
|
||||
void* retval, int sizeOfRetval,
|
||||
char* mess = 0);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Server sends result to client (also set ret to force_update if different clients)
|
||||
* @param update true if one must update if different clients, else false
|
||||
* @param ret success of operation
|
||||
* @param retval pointer to result
|
||||
* @param retvalSize size of result
|
||||
* @param mess message
|
||||
* @returns success of operation
|
||||
*/
|
||||
void Server_SendResult(bool update, int ret, void* retval, int retvalSize, char* mess = 0);
|
||||
int Server_SendResult(bool update, int ret, void* retval, int retvalSize, char* mess = 0);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Server receives arguments and checks if base object is null (if checkbase is true)
|
||||
* checking base object is null (for reciever only when it has not been configured yet)
|
||||
* @param ret pointer to success of operation
|
||||
@ -97,8 +82,9 @@ public:
|
||||
*/
|
||||
int Server_ReceiveArg(int& ret, char* mess, void* arg, int sizeofArg,bool checkbase=false, void* base=NULL);
|
||||
|
||||
/**
|
||||
* Server verifies if it is locked, sets and prints appropriate message if it is
|
||||
/** only Receiver
|
||||
* Server verifies if it is unlocked,
|
||||
* sets and prints appropriate message if it is locked and different clients
|
||||
* @param ret pointer to sucess
|
||||
* @param mess message
|
||||
* @param lockstatus status of lock
|
||||
@ -106,8 +92,9 @@ public:
|
||||
*/
|
||||
int Server_VerifyLock(int& ret, char* mess, int lockstatus);
|
||||
|
||||
/**
|
||||
* Server verifies if it is locked and idle, sets and prints appropriate message if it is
|
||||
/** only Receiver
|
||||
* Server verifies if it is unlocked and idle,
|
||||
* sets and prints appropriate message if it is locked and different clients
|
||||
* @param ret pointer to sucess
|
||||
* @param mess message
|
||||
* @param lockstatus status of lock
|
||||
@ -117,20 +104,20 @@ public:
|
||||
*/
|
||||
int Server_VerifyLockAndIdle(int& ret, char* mess, int lockstatus, slsDetectorDefs::runStatus status, int fnum);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Server sets and prints error message for null object error (receiver only)
|
||||
* @param ret pointer to sucess that will be set to FAIL
|
||||
* @param mess message
|
||||
*/
|
||||
void Server_NullObjectError(int& ret, char* mess);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Servers prints error message for socket crash when reading
|
||||
* @returns always FAIL
|
||||
*/
|
||||
int Server_SocketCrash();
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Servers sets and prints error message for locked server
|
||||
* @param ret pointer to sucess that will be set to FAIL
|
||||
* @param mess message
|
||||
@ -138,7 +125,7 @@ public:
|
||||
*/
|
||||
int Server_LockedError(int& ret, char* mess);
|
||||
|
||||
/**
|
||||
/** only Receiver
|
||||
* Servers sets and prints error message for server not being idle
|
||||
* @param ret pointer to sucess that will be set to FAIL
|
||||
* @param mess message
|
||||
@ -154,7 +141,7 @@ private:
|
||||
*/
|
||||
MySocketTCP *mySocket;
|
||||
|
||||
/** index for debugging purposes */
|
||||
/** index for client debugging purposes */
|
||||
int index;
|
||||
|
||||
/** string for type to differentiate between Detector & Receiver in printouts */
|
||||
|
@ -36,8 +36,9 @@
|
||||
|
||||
|
||||
inline std::string NowTime();
|
||||
|
||||
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5};
|
||||
// 1 normal debug, 3 function names, 5 fifodebug
|
||||
enum TLogLevel {logERROR, logWARNING, logINFOBLUE, logINFOGREEN, logINFORED, logINFO,
|
||||
logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5};
|
||||
|
||||
template <typename T> class Log{
|
||||
public:
|
||||
@ -63,20 +64,11 @@ public:
|
||||
static void Output(const std::string& msg, TLogLevel level);
|
||||
};
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
# if defined (BUILDING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllexport)
|
||||
# elif defined (USING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllimport)
|
||||
# else
|
||||
# define FILELOG_DECLSPEC
|
||||
# endif // BUILDING_DBSIMPLE_DLL
|
||||
#else
|
||||
# define FILELOG_DECLSPEC
|
||||
#endif // _WIN32
|
||||
|
||||
#define FILELOG_DECLSPEC
|
||||
|
||||
class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
|
||||
//typedef Log<Output2FILE> FILELog;
|
||||
|
||||
|
||||
#define FILE_LOG(level) \
|
||||
if (level > FILELOG_MAX_LEVEL) ; \
|
||||
@ -84,29 +76,6 @@ class FILELOG_DECLSPEC FILELog : public Log<Output2FILE> {};
|
||||
else FILELog().Get(level)
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
|
||||
inline std::string NowTime()
|
||||
|
||||
{
|
||||
const int MAX_LEN = 200;
|
||||
char buffer[MAX_LEN];
|
||||
if (GetTimeFormatA(LOCALE_USER_DEFAULT, 0, 0,
|
||||
"HH':'mm':'ss", buffer, MAX_LEN) == 0)
|
||||
return "Error in NowTime()";
|
||||
|
||||
char result[100] = {0};
|
||||
static DWORD first = GetTickCount();
|
||||
sprintf(result, "%s.%03ld", buffer, (long)(GetTickCount() - first) % 1000);
|
||||
return result;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
inline std::string NowTime()
|
||||
@ -127,8 +96,6 @@ inline std::string NowTime()
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif //WIN32
|
||||
|
||||
|
||||
template <typename T> Log<T>::Log():lev(logDEBUG){}
|
||||
|
||||
@ -138,7 +105,7 @@ template <typename T> std::ostringstream& Log<T>::Get(TLogLevel level)
|
||||
os << "- " << NowTime();
|
||||
os << " " << ToString(level) << ": ";
|
||||
if (level > logDEBUG)
|
||||
os << std::string(level - logDEBUG, '\t');
|
||||
os << std::string(level - logDEBUG, ' ');
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -156,7 +123,9 @@ template <typename T> TLogLevel& Log<T>::ReportingLevel()
|
||||
|
||||
template <typename T> std::string Log<T>::ToString(TLogLevel level)
|
||||
{
|
||||
static const char* const buffer[] = {"ERROR", "WARNING", "INFO", "DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4","DEBUG5"};
|
||||
static const char* const buffer[] = {
|
||||
"ERROR", "WARNING", "INFO", "INFO", "INFO", "INFO",
|
||||
"DEBUG", "DEBUG1", "DEBUG2", "DEBUG3", "DEBUG4","DEBUG5"};
|
||||
return buffer[level];
|
||||
}
|
||||
|
||||
@ -211,21 +180,10 @@ inline void Output2FILE::Output(const std::string& msg, TLogLevel level)
|
||||
case logERROR: cprintf(RED BOLD,"%s",msg.c_str()); break;
|
||||
case logWARNING: cprintf(YELLOW BOLD,"%s",msg.c_str()); break;
|
||||
case logINFO: cprintf(RESET,"%s",msg.c_str()); break;
|
||||
case logINFOBLUE: cprintf(BLUE,"%s",msg.c_str()); break;
|
||||
case logINFORED: cprintf(RED,"%s",msg.c_str()); break;
|
||||
case logINFOGREEN: cprintf(GREEN,"%s",msg.c_str()); break;
|
||||
default: fprintf(pStream,"%s",msg.c_str()); out = false; break;
|
||||
}
|
||||
fflush(out ? stdout : pStream);
|
||||
}
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
|
||||
# if defined (BUILDING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllexport)
|
||||
# elif defined (USING_FILELOG_DLL)
|
||||
# define FILELOG_DECLSPEC __declspec (dllimport)
|
||||
# else
|
||||
# define FILELOG_DECLSPEC
|
||||
# endif // BUILDING_DBSIMPLE_DLL
|
||||
#else
|
||||
# define FILELOG_DECLSPEC
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
|
@ -81,11 +81,8 @@ public:
|
||||
GENERIC, /**< generic sls detector */
|
||||
EIGER, /**< eiger */
|
||||
GOTTHARD, /**< gotthard */
|
||||
MOENCH, /**< moench */
|
||||
JUNGFRAU, /**< jungfrau */
|
||||
JUNGFRAUCTB, /**< jungfrauCTBversion */
|
||||
PROPIX, /**< propix */
|
||||
MYTHEN3 /**< mythen 3 */
|
||||
JUNGFRAUCTB /**< jungfrauCTBversion */
|
||||
};
|
||||
|
||||
|
||||
@ -95,7 +92,6 @@ public:
|
||||
enum {
|
||||
OK, /**< function succeeded */
|
||||
FAIL, /**< function failed */
|
||||
FINISHED, /**< acquisition finished */
|
||||
FORCE_UPDATE
|
||||
};
|
||||
|
||||
@ -244,16 +240,13 @@ public:
|
||||
int nchip; /**< is the number of chips on the module */
|
||||
int ndac; /**< is the number of dacs on the module */
|
||||
int nadc; /**< is the number of adcs on the module */
|
||||
int reg; /**< is the module register (e.g. dynamic range?)
|
||||
\see moduleRegisterBit */
|
||||
int reg; /**< is the module register settings (gain level) */
|
||||
int iodelay; /**< iodelay */
|
||||
int tau; /**< tau */
|
||||
int eV; /**< threshold energy */
|
||||
int *dacs; /**< is the pointer to the array of the dac values (in V) */
|
||||
int *adcs; /**< is the pointer to the array of the adc values (in V) FLAT_FIELD_CORRECTION*/
|
||||
int *chipregs; /**< is the pointer to the array of the chip registers
|
||||
\see ::chipRegisterBit */
|
||||
int *chanregs; /**< is the pointer to the array of the channel registers
|
||||
\see ::channelRegisterBit */
|
||||
double gain; /**< is the module gain (V/keV) */
|
||||
double offset; /**< is the module offset (V) */
|
||||
int *adcs; /**< is the pointer to the array of the adc values (in V) */
|
||||
int *chanregs; /**< is the pointer to the array of the channel registers */
|
||||
} sls_detector_module;
|
||||
|
||||
|
||||
@ -366,8 +359,6 @@ public:
|
||||
detector IDs/versions
|
||||
*/
|
||||
enum idMode{
|
||||
MODULE_SERIAL_NUMBER, /**<return module serial number */
|
||||
MODULE_FIRMWARE_VERSION, /**<return module firmware */
|
||||
DETECTOR_SERIAL_NUMBER, /**<return detector system serial number */
|
||||
DETECTOR_FIRMWARE_VERSION, /**<return detector system firmware version */
|
||||
DETECTOR_SOFTWARE_VERSION, /**<return detector system software version */
|
||||
|
@ -45,7 +45,6 @@ enum detFuncs{
|
||||
F_LOAD_IMAGE, /**< Loads Dark/Gain image to the Gotthard detector */
|
||||
F_READ_COUNTER_BLOCK, /**< reads the counter block memory for gotthard */
|
||||
F_RESET_COUNTER_BLOCK, /**< resets the counter block memory for gotthard */
|
||||
F_CALIBRATE_PEDESTAL, /**< starts acquistion, calibrates pedestal and write back to fpga */
|
||||
F_ENABLE_TEN_GIGA, /**< enable 10Gbe */
|
||||
F_SET_ALL_TRIMBITS, /** < set all trimbits to this value */
|
||||
F_SET_CTB_PATTERN, /** < loads a pattern in the CTB */
|
||||
@ -160,7 +159,6 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) {
|
||||
case F_LOAD_IMAGE: return "F_LOAD_IMAGE";
|
||||
case F_READ_COUNTER_BLOCK: return "F_READ_COUNTER_BLOCK";
|
||||
case F_RESET_COUNTER_BLOCK: return "F_RESET_COUNTER_BLOCK";
|
||||
case F_CALIBRATE_PEDESTAL: return "F_CALIBRATE_PEDESTAL";
|
||||
case F_ENABLE_TEN_GIGA: return "F_ENABLE_TEN_GIGA";
|
||||
case F_SET_ALL_TRIMBITS: return "F_SET_ALL_TRIMBITS";
|
||||
case F_SET_CTB_PATTERN: return "F_SET_CTB_PATTERN";
|
||||
|
Reference in New Issue
Block a user