mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-06 18:10:40 +02:00
Merge branch 'developer' into gui
This commit is contained in:
commit
3db09bc0cd
Binary file not shown.
@ -799,6 +799,8 @@ int getSpeed(enum speedVariable ind, int mode) {
|
||||
return getFrequency(ADC_CLK);
|
||||
case DBIT_CLOCK:
|
||||
return getFrequency(DBIT_CLK);
|
||||
case SYNC_CLOCK:
|
||||
return getFrequency(SYNC_CLK);
|
||||
case CLOCK_DIVIDER:
|
||||
return getFrequency(RUN_CLK);
|
||||
case ADC_PIPELINE:
|
||||
|
@ -146,6 +146,7 @@ const char* getSpeedName(enum speedVariable ind) {
|
||||
case DBIT_PIPELINE: return "dbit_pipeline";
|
||||
case MAX_ADC_PHASE_SHIFT: return "max_adc_phase_shift";
|
||||
case MAX_DBIT_PHASE_SHIFT: return "max_dbit_phase_shift";
|
||||
case SYNC_CLOCK: return "sync_clock";
|
||||
default: return "unknown_speed";
|
||||
}
|
||||
}
|
||||
@ -1975,6 +1976,7 @@ int set_speed(int file_des) {
|
||||
case MAX_DBIT_PHASE_SHIFT:
|
||||
case ADC_CLOCK:
|
||||
case DBIT_CLOCK:
|
||||
case SYNC_CLOCK:
|
||||
case CLOCK_DIVIDER:
|
||||
case ADC_PIPELINE:
|
||||
case DBIT_PIPELINE:
|
||||
@ -1985,6 +1987,7 @@ int set_speed(int file_des) {
|
||||
case MAX_DBIT_PHASE_SHIFT:
|
||||
case ADC_CLOCK:
|
||||
case DBIT_CLOCK:
|
||||
case SYNC_CLOCK:
|
||||
case CLOCK_DIVIDER:
|
||||
case ADC_PIPELINE:
|
||||
case DBIT_PIPELINE:
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
|
||||
#include <vector>
|
||||
class multiSlsDetector;
|
||||
|
||||
|
||||
@ -31,6 +31,9 @@ class slsDetectorCommand : public virtual slsDetectorDefs {
|
||||
*/
|
||||
std::string executeLine(int narg, const char * const args[], int action, int detPos = -1);
|
||||
|
||||
|
||||
std::vector<std::string> getAllCommands();
|
||||
|
||||
/* /\** */
|
||||
/* returns the help for the executeLine command */
|
||||
/* \param os output stream to return the help to */
|
||||
|
@ -752,19 +752,26 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) {
|
||||
++i;
|
||||
|
||||
/*! \page config
|
||||
- <b>adcclk [i]</b> sets/gets the ADC clock frequency in MHz. CTB & Moench only. It also resets adcphase. \c Returns \c (int)
|
||||
- <b>adcclk [i]</b> sets/gets the ADC clock frequency in MHz. CTB & Moench only. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "adcclk";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdSpeed;
|
||||
++i;
|
||||
|
||||
/*! \page config
|
||||
- <b>dbitclk [i]</b> Sets/gets the clock frequency of the latching of the digital bits in MHz. CTB & Moench only. It also resets dbit phase. \c Returns \c (int)
|
||||
- <b>dbitclk [i]</b> Sets/gets the clock frequency of the latching of the digital bits in MHz. CTB & Moench only. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "dbitclk";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdSpeed;
|
||||
++i;
|
||||
|
||||
/*! \page config
|
||||
- <b>syncclk </b> Gets the clock frequency of the sync clock in MHz. CTB & Moench only. Get only. \c Returns \c (int)
|
||||
*/
|
||||
descrToFuncMap[i].m_pFuncName = "syncclk";
|
||||
descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdSpeed;
|
||||
++i;
|
||||
|
||||
/*! \page config
|
||||
- <b>adcphase [i] [deg]</b> Sets/gets phase of the ADC clock to i. i is the shift or in degrees if deg is used. deg is optional & only for CTB, Moench and Jungfrau. For CTB & Moench, adcphase is reset if adcclk is changed. For Jungfrau, adcphase changed to defaults if clkdivider changed. Jungfrau, CTB & Moench, these are absolute values with limits. Gotthard, relative phase shift. Not for Eiger. \c Returns \c (int)
|
||||
*/
|
||||
@ -2162,12 +2169,19 @@ std::string slsDetectorCommand::executeLine(int narg, const char * const args[],
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::cmdUnknown(int narg, const char * const args[], int action, int detPos) {
|
||||
return std::string("Unknown command ") + std::string(args[0]) + std::string("\n") + helpLine(0, args, action, detPos);
|
||||
return std::string("Unknown command, use list to list all commands ");
|
||||
}
|
||||
std::string slsDetectorCommand::cmdUnderDevelopment(int narg, const char * const args[], int action, int detPos) {
|
||||
return std::string("Must still develop ") + std::string(args[0]) + std::string(" ( ") + cmd + std::string(" )\n");
|
||||
}
|
||||
|
||||
std::vector<std::string> slsDetectorCommand::getAllCommands(){
|
||||
std::vector<std::string> commands;
|
||||
for (int i = 0; i!= numberOfCommands; ++i)
|
||||
commands.emplace_back(descrToFuncMap[i].m_pFuncName);
|
||||
return commands;
|
||||
}
|
||||
|
||||
std::string slsDetectorCommand::helpLine(int narg, const char * const args[], int action, int detPos) {
|
||||
|
||||
std::ostringstream os;
|
||||
@ -4673,6 +4687,12 @@ std::string slsDetectorCommand::cmdSpeed(int narg, const char * const args[], in
|
||||
else if (cmd == "dbitclk") {
|
||||
index = DBIT_CLOCK;
|
||||
}
|
||||
else if (cmd == "syncclk") {
|
||||
index = SYNC_CLOCK;
|
||||
if (action == PUT_ACTION) {
|
||||
return std::string("cannot put");
|
||||
}
|
||||
}
|
||||
else if (cmd == "adcphase") {
|
||||
index = ADC_PHASE;
|
||||
if ((action == PUT_ACTION && narg > 2 && std::string(args[2]) == "deg") ||
|
||||
@ -4728,8 +4748,8 @@ std::string slsDetectorCommand::helpSpeed(int action) {
|
||||
std::ostringstream os;
|
||||
if (action == PUT_ACTION || action == HELP_ACTION) {
|
||||
os << "clkdivider c \t sets readout clock divider. EIGER, JUNGFRAU [0(fast speed), 1(half speed), 2(quarter speed)]. Jungfrau, full speed is not implemented and overwrites adcphase to recommended default. Not for Gotthard." << std::endl;
|
||||
os << "adcclk c \tSets ADC clock frequency in MHz. CTB & Moench only. It also resets adcphase." << std::endl;
|
||||
os << "dbitclk c \tSets the clock frequency of the latching of the digital bits in MHz. CTB & Moench only. It also resets dbit phase." << std::endl;
|
||||
os << "adcclk c \tSets ADC clock frequency in MHz. CTB & Moench only. " << std::endl;
|
||||
os << "dbitclk c \tSets the clock frequency of the latching of the digital bits in MHz. CTB & Moench only. " << std::endl;
|
||||
os << "adcphase c [deg]\t Sets phase of the ADC clock to i. i is the shift or in degrees if deg is used. deg is optional & only for CTB, Moench & Jungfrau. For CTB & Moench, adcphase is reset if adcclk is changed. For Jungfrau, adcphase changed to defaults if clkdivider changed. Jungfrau, CTB & Moench, these are absolute values with limits. Gotthard, relative phase shift. Not for Eiger." << std::endl;
|
||||
os << "dbitphase c [deg]\t Sets the phase of the clock for latching of the digital bits to i. i is the shift or in degrees if deg is used. deg is optional. dbitphase is also reset if dbitclk is changed. These are absolute values with limits. for CTB & Moench only." << std::endl;
|
||||
os << "adcpipeline c \t Sets the pipeline of the ADC. For CTB & Moench only." << std::endl;
|
||||
@ -4738,8 +4758,9 @@ std::string slsDetectorCommand::helpSpeed(int action) {
|
||||
}
|
||||
if (action == GET_ACTION || action == HELP_ACTION) {
|
||||
os << "clkdivider \t Gets readout clock divider. EIGER, JUNGFRAU [0(fast speed), 1(half speed), 2(quarter speed)]. Jungfrau, full speed is not implemented and overwrites adcphase to recommended default. Not for Gotthard." << std::endl;
|
||||
os << "adcclk \tGets ADC clock frequency in MHz. CTB & Moench only. It also resets adcphase." << std::endl;
|
||||
os << "dbitclk \tGets the clock frequency of the latching of the digital bits in MHz. CTB & Moench only. It also resets dbit phase." << std::endl;
|
||||
os << "adcclk \tGets ADC clock frequency in MHz. CTB & Moench only. " << std::endl;
|
||||
os << "dbitclk \tGets the clock frequency of the latching of the digital bits in MHz. CTB & Moench only. " << std::endl;
|
||||
os << "syncclk \t Gets the clock frequency of the sync clock in MHz. CTB & Moench only." << std::endl;
|
||||
os << "adcphase [deg]\t Gets phase of the ADC clock. unit is number of shifts or in degrees if deg is used. deg is optional & only for CTB, Moench & Jungfrau. For CTB & Moench, adcphase is reset if adcclk is changed. For Jungfrau, adcphase changed to defaults if clkdivider changed. Jungfrau, CTB & Moench, these are absolute values with limits. Gotthard, relative phase shift. Not for Eiger." << std::endl;
|
||||
os << "dbitphase [deg]\t Gets the phase of the clock for latching of the digital bits. unit is number of shifts or in degrees if deg is used. deg is optional. dbitphase is also reset if dbitclk is changed. These are absolute values with limits. for CTB & Moench only." << std::endl;
|
||||
os << "adcpipeline \t Gets the pipeline of the ADC. For CTB & Moench only." << std::endl;
|
||||
|
@ -5,7 +5,6 @@ set(SOURCES
|
||||
src/ClientSocket.cpp
|
||||
src/DataSocket.cpp
|
||||
src/ServerSocket.cpp
|
||||
src/ServerInterface.cpp
|
||||
src/ServerInterface2.cpp
|
||||
src/network_utils.cpp
|
||||
)
|
||||
@ -22,7 +21,6 @@ set(PUBLICHEADERS
|
||||
include/file_utils.h
|
||||
include/container_utils.h
|
||||
include/string_utils.h
|
||||
include/MySocketTCP.h
|
||||
include/genericSocket.h
|
||||
include/logger.h
|
||||
include/ClientSocket.h
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
@ -7,7 +8,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "logger.h"
|
||||
#include "slsDetectorCommand.h"
|
||||
#include "sls_detector_exceptions.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
namespace sls {
|
||||
|
||||
@ -58,7 +61,7 @@ template <typename T> class CmdProxy {
|
||||
using StringMap = std::map<std::string, std::string>;
|
||||
|
||||
// Initialize maps for translating name and function
|
||||
FunctionMap functions{{"newfunc", &CmdProxy::NewFunction}};
|
||||
FunctionMap functions{{"list", &CmdProxy::ListCommands}};
|
||||
|
||||
StringMap depreciated_functions{{"r_readfreq", "rx_readfreq"},
|
||||
{"r_padding", "rx_padding"},
|
||||
@ -80,34 +83,43 @@ template <typename T> class CmdProxy {
|
||||
{"fileformat", "fformat"},
|
||||
{"overwrite", "foverwrite"}};
|
||||
|
||||
template <typename U> std::string ResultToString(const U &ret) {
|
||||
std::ostringstream os;
|
||||
if (det_id != -1)
|
||||
os << det_id << ":";
|
||||
os << cmd << " " << ret << "\n";
|
||||
return os.str();
|
||||
}
|
||||
|
||||
void WrongNumberOfParameters(size_t expected) {
|
||||
throw RuntimeError("ERROR: Expected " + std::to_string(expected) +
|
||||
" parameters but got " +
|
||||
std::to_string(args.size()) + "\n");
|
||||
throw RuntimeError(
|
||||
"Command " + cmd + " expected <=" + std::to_string(expected) +
|
||||
" parameter/s but got " + std::to_string(args.size()) + "\n");
|
||||
}
|
||||
|
||||
// Mapped functions
|
||||
|
||||
// example
|
||||
std::string NewFunction() {
|
||||
std::string ListCommands() {
|
||||
if (args.size() == 0) {
|
||||
std::cout << "This is the new function function\n";
|
||||
return ResultToString(det->setExposureTime(-1, true));
|
||||
auto commands = slsDetectorCommand(nullptr).getAllCommands();
|
||||
for (const auto &it : functions)
|
||||
commands.emplace_back(it.first);
|
||||
std::sort(begin(commands), end(commands));
|
||||
|
||||
std::cout << "These " << commands.size()
|
||||
<< " commands are available\n";
|
||||
for (auto &c : commands)
|
||||
std::cout << c << '\n';
|
||||
return "";
|
||||
} else if (args.size() == 1) {
|
||||
std::cout << "Setting exposure time to " << args[0] << "s\n";
|
||||
return ResultToString(
|
||||
det->setExposureTime(std::stod(args[0]), true, det_id));
|
||||
if (args[0] == "deprecated") {
|
||||
std::cout << "The following " << depreciated_functions.size()
|
||||
<< " commands are deprecated\n";
|
||||
size_t field_width = 20;
|
||||
for (const auto &it : depreciated_functions) {
|
||||
std::cout << std::right << std::setw(field_width)
|
||||
<< it.first << " -> " << it.second << '\n';
|
||||
}
|
||||
return "";
|
||||
} else {
|
||||
throw RuntimeError(
|
||||
"Could not decode argument. Possible options: deprecated");
|
||||
}
|
||||
} else {
|
||||
WrongNumberOfParameters(1);
|
||||
return {};
|
||||
return "";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1,42 +0,0 @@
|
||||
#pragma once
|
||||
/**
|
||||
*
|
||||
* @libdoc The MySocketTCP class provides a simple interface for creating and sending/receiving data over a TCP socket.
|
||||
*
|
||||
* @short This class provides a simple interface for creating and sending/receiving data over a TCP socket.
|
||||
* @author Ian Johnson
|
||||
* @version 1.0
|
||||
*/
|
||||
//version 1.0, base development, Ian 19/01/09
|
||||
/* Modified by anna on 19.01.2009 */
|
||||
/*
|
||||
canceled SetupParameters() and varaibles intialized in the constructors' headers;
|
||||
defined SEND_REC_MAX_SIZE (for compatibilty with mythen (and possibly other) pure C servers (i would move it to the common header file)
|
||||
added #ifndef C_ONLY... to cutout class definition when including in pure C servers (can be removed if SEND_REC_MAX_SIZE is moved to the common header file)
|
||||
defined private variables char hostname[1000] and int portno to store connection informations;
|
||||
defined public functions int getHostname(char *name) and int getPortNumber() to retrieve connection informations
|
||||
added public function int getErrorStatus() returning 1 if socketDescriptor<0
|
||||
remove exits in the constructors and replace them with socketDescriptor=-1
|
||||
replaced the argument of send/receive data with void (to avoid too much casting or compiler errors/warnings)
|
||||
added a function which really does not close the socket between send/receive (senddataonly, receivedataonly)
|
||||
|
||||
Modified by Anna on 31.10.2012 developed and
|
||||
*/
|
||||
|
||||
#include "genericSocket.h"
|
||||
#define TCP_PACKET_SIZE 4096
|
||||
|
||||
class MySocketTCP : public genericSocket {
|
||||
public:
|
||||
// sender (client): where to? ip
|
||||
MySocketTCP(const char *const host_ip_or_name, uint16_t port_number)
|
||||
: genericSocket(host_ip_or_name, port_number, TCP) {
|
||||
setPacketSize(TCP_PACKET_SIZE);
|
||||
}
|
||||
// receiver (server) local no need for ip
|
||||
MySocketTCP(uint16_t port_number)
|
||||
: genericSocket(port_number, TCP) {
|
||||
setPacketSize(TCP_PACKET_SIZE);
|
||||
}
|
||||
virtual ~MySocketTCP(){};
|
||||
};
|
@ -1,152 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include "sls_detector_defs.h"
|
||||
#include "MySocketTCP.h"
|
||||
|
||||
|
||||
/**
|
||||
* @short the ServerInterface class is the interface between the client and the server
|
||||
*/
|
||||
// Do not overload to make it easier for manual comparison between client and server functions
|
||||
|
||||
class ServerInterface: public virtual slsDetectorDefs{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* (default) constructor
|
||||
* @param socket tcp socket between client and receiver
|
||||
* @param n for debugging purposes (useful only for client side)
|
||||
* @param t string to identify type (Detector, Receiver) for printouts (useful only for client side)
|
||||
*/
|
||||
ServerInterface(MySocketTCP *socket, int n=-1, std::string t="");
|
||||
|
||||
/**
|
||||
* destructor
|
||||
*/
|
||||
virtual ~ServerInterface() = default;
|
||||
|
||||
/**
|
||||
* Set the datasocket
|
||||
* @param socket the data socket
|
||||
*/
|
||||
void SetSocket(MySocketTCP *socket);
|
||||
|
||||
/**
|
||||
* Receive ret, mess or retval from Server
|
||||
* @param ret result of operation
|
||||
* @param mess pointer to message
|
||||
* @param retval pointer to retval
|
||||
* @param sizeOfRetval size of retval
|
||||
*/
|
||||
void Client_Receive(int& ret, char* mess, void* retval, int sizeOfRetval);
|
||||
|
||||
/**
|
||||
* Send Arguments to server and receives result back
|
||||
* @param fnum function enum to determine what parameter
|
||||
* @param args pointer to arguments
|
||||
* @param sizeOfArgs argument size
|
||||
* @param retval pointer to return value
|
||||
* @param sizeOfRetval return value size
|
||||
* @param mess pointer to message if message required externally
|
||||
* @returns success of operation
|
||||
*/
|
||||
int Client_Send(int fnum,
|
||||
void* args, int sizeOfArgs,
|
||||
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
|
||||
*/
|
||||
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 receiver only when it has not been configured yet)
|
||||
* @param ret pointer to success of operation
|
||||
* @param mess message
|
||||
* @param arg pointer to argument
|
||||
* @param sizeofArg size of argument
|
||||
* @param checkbase if true, checks if base object is null and sets ret and mess accordingly
|
||||
* @param base pointer to base object
|
||||
* @returns fail if socket crashes while reading arguments, else fail
|
||||
*/
|
||||
int Server_ReceiveArg(int& ret, char* mess, void* arg, int sizeofArg,bool checkbase=false, void* base=NULL);
|
||||
|
||||
/** only Receiver
|
||||
* Server verifies if it is unlocked,
|
||||
* sets and prints appropriate message if it is locked and different clients
|
||||
* @param ret pointer to success
|
||||
* @param mess message
|
||||
* @param lockstatus status of lock
|
||||
* @returns success of operaton
|
||||
*/
|
||||
int Server_VerifyLock(int& ret, char* mess, int lockstatus);
|
||||
|
||||
/** 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 success
|
||||
* @param mess message
|
||||
* @param lockstatus status of lock
|
||||
* @param status status of server
|
||||
* @param fnum function number for error message
|
||||
* @returns success of operaton
|
||||
*/
|
||||
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 success 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 success that will be set to FAIL
|
||||
* @param mess message
|
||||
* @returns success of operaton
|
||||
*/
|
||||
int Server_LockedError(int& ret, char* mess);
|
||||
|
||||
/** only Receiver
|
||||
* Servers sets and prints error message for server not being idle
|
||||
* @param ret pointer to success that will be set to FAIL
|
||||
* @param mess message
|
||||
* @param fnum function number for error message
|
||||
* @returns success of operaton
|
||||
*/
|
||||
int Server_NotIdleError(int& ret, char* mess, int fnum);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* socket for data acquisition
|
||||
*/
|
||||
MySocketTCP *mySocket;
|
||||
|
||||
/** index for client debugging purposes */
|
||||
int index;
|
||||
|
||||
/** string for type to differentiate between Detector & Receiver in printouts */
|
||||
std::string type;
|
||||
|
||||
};
|
||||
|
||||
|
@ -67,7 +67,7 @@
|
||||
|
||||
#define DEFAULT_STREAMING_TIMER_IN_MS 200
|
||||
|
||||
typedef char mystring[MAX_STR_LENGTH];
|
||||
// typedef char mystring[MAX_STR_LENGTH];
|
||||
|
||||
#ifdef __cplusplus
|
||||
class slsDetectorDefs {
|
||||
@ -496,6 +496,7 @@ format
|
||||
DBIT_PIPELINE, /**< adc pipeline */
|
||||
MAX_ADC_PHASE_SHIFT, /** max adc phase shift */
|
||||
MAX_DBIT_PHASE_SHIFT, /** max adc phase shift */
|
||||
SYNC_CLOCK,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -1,143 +0,0 @@
|
||||
#include "ServerInterface.h"
|
||||
|
||||
ServerInterface::ServerInterface(MySocketTCP *socket, int n, std::string t): mySocket(socket),
|
||||
index(n),
|
||||
type(t){}
|
||||
|
||||
void ServerInterface::SetSocket(MySocketTCP *socket) {
|
||||
mySocket = socket;
|
||||
}
|
||||
|
||||
|
||||
void ServerInterface::Client_Receive(int& ret, char* mess, void* retval, int sizeOfRetval) {
|
||||
// get result of operation
|
||||
mySocket->ReceiveDataOnly(&ret,sizeof(ret));
|
||||
|
||||
bool unrecognizedFunction = false;
|
||||
if (ret == FAIL) {
|
||||
bool created = false;
|
||||
// allocate mess if null
|
||||
if (!mess){
|
||||
created = true;
|
||||
mess = new char[MAX_STR_LENGTH];
|
||||
memset(mess, 0, MAX_STR_LENGTH);
|
||||
}
|
||||
// get error message
|
||||
mySocket->ReceiveDataOnly(mess,MAX_STR_LENGTH);
|
||||
cprintf(RED, "%s %d returned error: %s", type.c_str(), index, mess);
|
||||
|
||||
// unrecognized function, do not ask for retval
|
||||
if(strstr(mess,"Unrecognized Function") != nullptr)
|
||||
unrecognizedFunction = true;
|
||||
// delete allocated mess
|
||||
if (created)
|
||||
delete [] mess;
|
||||
}
|
||||
// get retval
|
||||
if (!unrecognizedFunction)
|
||||
mySocket->ReceiveDataOnly(retval, sizeOfRetval);
|
||||
}
|
||||
|
||||
|
||||
int ServerInterface::Client_Send(int fnum,
|
||||
void* args, int sizeOfArgs,
|
||||
void* retval, int sizeOfRetval,
|
||||
char* mess) {
|
||||
int ret = FAIL;
|
||||
mySocket->SendDataOnly(&fnum,sizeof(fnum));
|
||||
mySocket->SendDataOnly(args, sizeOfArgs);
|
||||
Client_Receive(ret, mess, retval, sizeOfRetval);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ServerInterface::Server_SendResult(bool update, int ret,
|
||||
void* retval, int retvalSize, char* mess) {
|
||||
|
||||
// update if different clients
|
||||
if (update && ret == OK && mySocket->differentClients)
|
||||
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);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ServerInterface::Server_ReceiveArg(int& ret, char* mess, void* arg, int sizeofArg, bool checkbase, void* base) {
|
||||
// client socket crash, cannot receive arguments
|
||||
if (sizeofArg && mySocket->ReceiveDataOnly(arg, sizeofArg) < 0)
|
||||
return Server_SocketCrash();
|
||||
|
||||
// check if server object created
|
||||
if (checkbase && base == nullptr)
|
||||
Server_NullObjectError(ret, mess);
|
||||
|
||||
// no crash
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int ServerInterface::Server_VerifyLock(int& ret, char* mess, int lockstatus) {
|
||||
// server locked
|
||||
if (mySocket->differentClients && lockstatus)
|
||||
return Server_LockedError(ret, mess);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ServerInterface::Server_VerifyLockAndIdle(int& ret, char* mess, int lockstatus, slsDetectorDefs::runStatus status, int fnum) {
|
||||
// server locked
|
||||
if (mySocket->differentClients && lockstatus)
|
||||
return Server_LockedError(ret, mess);
|
||||
|
||||
// server not idle for this command
|
||||
if (status != slsDetectorDefs::IDLE)
|
||||
return Server_NotIdleError(ret, mess, fnum);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void ServerInterface::Server_NullObjectError(int& ret, char* mess) {
|
||||
ret=FAIL;
|
||||
strcpy(mess,"Receiver not set up. Please use rx_hostname first.\n");
|
||||
FILE_LOG(logERROR) << mess;
|
||||
}
|
||||
|
||||
|
||||
int ServerInterface::Server_SocketCrash() {
|
||||
FILE_LOG(logERROR) << "Reading from socket failed. Possible socket crash";
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
|
||||
int ServerInterface::Server_LockedError(int& ret, char* mess) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Receiver locked by %s\n", mySocket->lastClientIP);
|
||||
FILE_LOG(logERROR) << mess;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ServerInterface::Server_NotIdleError(int& ret, char* mess, int fnum) {
|
||||
ret = FAIL;
|
||||
sprintf(mess,"Can not execute %s when receiver is not idle\n",
|
||||
getFunctionNameFromEnum((enum detFuncs)fnum));
|
||||
FILE_LOG(logERROR) << mess;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user