Dev/server malloc check (#1023)

* usleep in communication to actually relay the err message of memory allocation to the client (weird but test for now), function in server to handle memory allcoation issues (updates mess, ret and sendsit to the client and returns prior from function implementatin, setting fnum in client for the speicific functions that send to detector each argument separtely, they need to remember the fnum else they throw with the incorrect fnum
* server: every malloc must check if it succeeded, rearranging so that the free is clear as well (only in funcs so far)
* fixed malloc checks in other places other than funcs.c
This commit is contained in:
maliakal_d 2024-11-18 09:46:21 +01:00 committed by GitHub
parent 5088e5a205
commit e1497f9cb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 353 additions and 282 deletions

View File

@ -51,12 +51,12 @@ int dataBytes = 0;
int analogDataBytes = 0; int analogDataBytes = 0;
int digitalDataBytes = 0; int digitalDataBytes = 0;
int transceiverDataBytes = 0; int transceiverDataBytes = 0;
char *analogData = 0; char *analogData = NULL;
char *digitalData = 0; char *digitalData = NULL;
char *transceiverData = 0; char *transceiverData = NULL;
char volatile *analogDataPtr = 0; char volatile *analogDataPtr = NULL;
char volatile *digitalDataPtr = 0; char volatile *digitalDataPtr = NULL;
char volatile *transceiverDataPtr = 0; char volatile *transceiverDataPtr = NULL;
char udpPacketData[UDP_PACKET_DATA_BYTES + sizeof(sls_detector_header)]; char udpPacketData[UDP_PACKET_DATA_BYTES + sizeof(sls_detector_header)];
uint32_t adcEnableMask_1g = BIT32_MSK; uint32_t adcEnableMask_1g = BIT32_MSK;
// 10g readout // 10g readout
@ -475,21 +475,15 @@ void setupDetector() {
analogDataBytes = 0; analogDataBytes = 0;
digitalDataBytes = 0; digitalDataBytes = 0;
transceiverDataBytes = 0; transceiverDataBytes = 0;
if (analogData) {
free(analogData); free(analogData);
analogData = 0; analogData = NULL;
}
if (digitalData) {
free(digitalData); free(digitalData);
digitalData = 0; digitalData = NULL;
}
if (transceiverData) {
free(transceiverData); free(transceiverData);
transceiverData = 0; transceiverData = NULL;
} analogDataPtr = NULL;
analogDataPtr = 0; digitalDataPtr = NULL;
digitalDataPtr = 0; transceiverData = NULL;
transceiverData = 0;
{ {
for (int i = 0; i < NUM_CLOCKS; ++i) { for (int i = 0; i < NUM_CLOCKS; ++i) {
clkPhase[i] = 0; clkPhase[i] = 0;
@ -640,22 +634,15 @@ int updateDatabytesandAllocateRAM() {
return FAIL; return FAIL;
} }
// clear RAM // clear RAM
if (analogData) {
free(analogData); free(analogData);
analogData = 0; analogData = NULL;
}
if (digitalData) {
free(digitalData); free(digitalData);
digitalData = 0; digitalData = NULL;
}
if (transceiverData) {
free(transceiverData); free(transceiverData);
transceiverData = 0; transceiverData = NULL;
}
// allocate RAM // allocate RAM
if (analogDataBytes) { if (analogDataBytes) {
analogData = malloc(analogDataBytes); analogData = malloc(analogDataBytes);
// cannot malloc
if (analogData == NULL) { if (analogData == NULL) {
LOG(logERROR, ("Can not allocate analog data RAM for even 1 frame. " LOG(logERROR, ("Can not allocate analog data RAM for even 1 frame. "
"Probable cause: Memory Leak.\n")); "Probable cause: Memory Leak.\n"));
@ -665,7 +652,6 @@ int updateDatabytesandAllocateRAM() {
} }
if (digitalDataBytes) { if (digitalDataBytes) {
digitalData = malloc(digitalDataBytes); digitalData = malloc(digitalDataBytes);
// cannot malloc
if (digitalData == NULL) { if (digitalData == NULL) {
LOG(logERROR, LOG(logERROR,
("Can not allocate digital data RAM for even 1 frame. " ("Can not allocate digital data RAM for even 1 frame. "
@ -677,7 +663,6 @@ int updateDatabytesandAllocateRAM() {
} }
if (transceiverDataBytes) { if (transceiverDataBytes) {
transceiverData = malloc(transceiverDataBytes); transceiverData = malloc(transceiverDataBytes);
// cannot malloc
if (transceiverData == NULL) { if (transceiverData == NULL) {
LOG(logERROR, LOG(logERROR,
("Can not allocate transceiver data RAM for even 1 frame. " ("Can not allocate transceiver data RAM for even 1 frame. "

View File

@ -46,17 +46,27 @@ int Beb_deactivated_left_datastream = 1;
int Beb_deactivated_right_datastream = 1; int Beb_deactivated_right_datastream = 1;
int Beb_deactivated_num_destinations = 1; int Beb_deactivated_num_destinations = 1;
void Beb_Beb() { int Beb_Beb() {
Beb_send_ndata = 0; Beb_send_ndata = 0;
Beb_send_buffer_size = 1026; Beb_send_buffer_size = 1026;
Beb_send_data_raw = Beb_send_data_raw =
malloc((Beb_send_buffer_size + 1) * sizeof(unsigned int)); malloc((Beb_send_buffer_size + 1) * sizeof(unsigned int));
if (Beb_send_data_raw == NULL) {
LOG(logERROR, ("Could not allocate memory for beb (send_data_raw)\n"));
return 0;
}
Beb_send_data = &Beb_send_data_raw[1]; Beb_send_data = &Beb_send_data_raw[1];
Beb_recv_ndata = 0; Beb_recv_ndata = 0;
Beb_recv_buffer_size = 1026; Beb_recv_buffer_size = 1026;
Beb_recv_data_raw = Beb_recv_data_raw =
malloc((Beb_recv_buffer_size + 1) * sizeof(unsigned int)); malloc((Beb_recv_buffer_size + 1) * sizeof(unsigned int));
if (Beb_recv_data_raw == NULL) {
LOG(logERROR, ("Could not allocate memory for beb (recv_data_raw)\n"));
return 0;
}
Beb_recv_data = &Beb_recv_data_raw[1]; Beb_recv_data = &Beb_recv_data_raw[1];
udp_header = (struct udp_header_type){ udp_header = (struct udp_header_type){
@ -83,6 +93,7 @@ void Beb_Beb() {
Beb_ClearHeaderData(1); Beb_ClearHeaderData(1);
Beb_bit_mode = 4; Beb_bit_mode = 4;
return 1;
} }
void Beb_ClearHeaderData(int ten_gig) { void Beb_ClearHeaderData(int ten_gig) {

View File

@ -6,7 +6,7 @@
#include "slsDetectorServer_defs.h" #include "slsDetectorServer_defs.h"
#include <stdlib.h> #include <stdlib.h>
void Beb_Beb(); int Beb_Beb();
void Beb_ClearHeaderData(int ten_gig); void Beb_ClearHeaderData(int ten_gig);
int Beb_SetUpUDPHeader(unsigned int header_number, int ten_gig, int Beb_SetUpUDPHeader(unsigned int header_number, int ten_gig,
uint64_t src_mac, uint32_t src_ip, uint16_t src_port, uint64_t src_mac, uint32_t src_ip, uint16_t src_port,

View File

@ -57,11 +57,19 @@ int Feb_Control_FebControl(int normal) {
Feb_Control_externalEnableMode = 0; Feb_Control_externalEnableMode = 0;
Feb_Control_subFrameMode = 0; Feb_Control_subFrameMode = 0;
Feb_Control_trimbit_size = 263680; Feb_Control_trimbit_size = 263680;
Feb_Control_last_downloaded_trimbits = Feb_Control_last_downloaded_trimbits =
malloc(Feb_Control_trimbit_size * sizeof(int)); malloc(Feb_Control_trimbit_size * sizeof(int));
if (Feb_Control_last_downloaded_trimbits == NULL) {
LOG(logERROR,
("Could not allocate memory for last downloaded trimbits\n"));
return 0;
}
Feb_Control_normal = normal; Feb_Control_normal = normal;
Feb_Interface_SetAddress(Feb_Control_rightAddress, Feb_Control_leftAddress); if (!Feb_Interface_SetAddress(Feb_Control_rightAddress,
Feb_Control_leftAddress))
return 0;
if (Feb_Control_activated) { if (Feb_Control_activated) {
return Feb_Interface_SetByteOrder(); return Feb_Interface_SetByteOrder();
} }

View File

@ -22,34 +22,57 @@ unsigned int Feb_Interface_recv_buffer_size;
unsigned int *Feb_Interface_recv_data_raw; unsigned int *Feb_Interface_recv_data_raw;
unsigned int *Feb_Interface_recv_data; unsigned int *Feb_Interface_recv_data;
void Feb_Interface_FebInterface() { int Feb_Interface_FebInterface() {
ll = &ll_local; ll = &ll_local;
Feb_Interface_nfebs = 0; Feb_Interface_nfebs = 0;
Feb_Interface_feb_numb = 0; Feb_Interface_feb_numb = 0;
Feb_Interface_send_ndata = 0; Feb_Interface_send_ndata = 0;
Feb_Interface_send_buffer_size = 1026; Feb_Interface_send_buffer_size = 1026;
Feb_Interface_send_data_raw = Feb_Interface_send_data_raw =
malloc((Feb_Interface_send_buffer_size + 1) * sizeof(unsigned int)); malloc((Feb_Interface_send_buffer_size + 1) * sizeof(unsigned int));
if (Feb_Interface_send_data_raw == NULL) {
LOG(logERROR,
("Could not allocate memory for feb interface (send_data_raw)\n"));
return 0;
}
Feb_Interface_send_data = &Feb_Interface_send_data_raw[1]; Feb_Interface_send_data = &Feb_Interface_send_data_raw[1];
Feb_Interface_recv_ndata = 0; Feb_Interface_recv_ndata = 0;
Feb_Interface_recv_buffer_size = 1026; Feb_Interface_recv_buffer_size = 1026;
Feb_Interface_recv_data_raw = Feb_Interface_recv_data_raw =
malloc((Feb_Interface_recv_buffer_size + 1) * sizeof(unsigned int)); malloc((Feb_Interface_recv_buffer_size + 1) * sizeof(unsigned int));
if (Feb_Interface_recv_data_raw == NULL) {
LOG(logERROR,
("Could not allocate memory for feb interface (recv_data_raw)\n"));
return 0;
}
Feb_Interface_recv_data = &Feb_Interface_recv_data_raw[1]; Feb_Interface_recv_data = &Feb_Interface_recv_data_raw[1];
Local_LocalLinkInterface( Local_LocalLinkInterface(
ll, XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR); ll, XPAR_PLB_LL_FIFO_AURORA_DUAL_CTRL_FEB_RIGHT_BASEADDR);
return 1;
} }
void Feb_Interface_SetAddress(unsigned int leftAddr, unsigned int rightAddr) { int Feb_Interface_SetAddress(unsigned int leftAddr, unsigned int rightAddr) {
if (Feb_Interface_feb_numb)
free(Feb_Interface_feb_numb); free(Feb_Interface_feb_numb);
Feb_Interface_nfebs = 2; Feb_Interface_nfebs = 2;
Feb_Interface_feb_numb = malloc(2 * sizeof(unsigned int)); Feb_Interface_feb_numb = malloc(2 * sizeof(unsigned int));
if (Feb_Interface_feb_numb == NULL) {
LOG(logERROR,
("Could not allocate memory for feb interface (feb_numb)\n"));
Feb_Interface_nfebs = 0;
return 0;
}
Feb_Interface_feb_numb[0] = leftAddr; Feb_Interface_feb_numb[0] = leftAddr;
Feb_Interface_feb_numb[1] = rightAddr; Feb_Interface_feb_numb[1] = rightAddr;
return 1;
} }
int Feb_Interface_WriteTo(unsigned int ch) { int Feb_Interface_WriteTo(unsigned int ch) {

View File

@ -4,8 +4,8 @@
int Feb_Interface_WriteTo(unsigned int ch); int Feb_Interface_WriteTo(unsigned int ch);
int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys); int Feb_Interface_ReadFrom(unsigned int ch, unsigned int ntrys);
void Feb_Interface_FebInterface(); int Feb_Interface_FebInterface();
void Feb_Interface_SetAddress(unsigned int leftAddr, unsigned int rightAddr); int Feb_Interface_SetAddress(unsigned int leftAddr, unsigned int rightAddr);
int Feb_Interface_SetByteOrder(); int Feb_Interface_SetByteOrder();
int Feb_Interface_ReadRegister(unsigned int sub_num, unsigned int reg_num, int Feb_Interface_ReadRegister(unsigned int sub_num, unsigned int reg_num,
unsigned int *value_read); unsigned int *value_read);

View File

@ -662,7 +662,15 @@ int checkCommandLineConfiguration() {
#ifndef VIRTUAL #ifndef VIRTUAL
void setupFebBeb() { void setupFebBeb() {
sharedMemory_lockLocalLink(); sharedMemory_lockLocalLink();
Feb_Interface_FebInterface(); if (!Feb_Interface_FebInterface()) {
initError = FAIL;
sprintf(initErrorMessage,
"Could not intitalize eiger detector sever: feb interface\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
sharedMemory_unlockLocalLink();
return;
}
if (!Feb_Control_FebControl(normal)) { if (!Feb_Control_FebControl(normal)) {
initError = FAIL; initError = FAIL;
sprintf(initErrorMessage, sprintf(initErrorMessage,
@ -686,7 +694,14 @@ void setupFebBeb() {
LOG(logDEBUG1, ("%s server: FEB Initialization done\n", LOG(logDEBUG1, ("%s server: FEB Initialization done\n",
isControlServer ? "Control" : "Stop")); isControlServer ? "Control" : "Stop"));
Beb_SetTopVariable(top); Beb_SetTopVariable(top);
Beb_Beb(); if (!Beb_Beb()) {
initError = FAIL;
sprintf(initErrorMessage,
"Could not intitalize eiger detector sever: beb\n");
LOG(logERROR, (initErrorMessage));
initCheckDone = 1;
return;
}
LOG(logDEBUG1, ("%s server: BEB Initialization done\n", LOG(logDEBUG1, ("%s server: BEB Initialization done\n",
isControlServer ? "Control" : "Stop")); isControlServer ? "Control" : "Stop"));
@ -724,17 +739,23 @@ void setupFebBeb() {
} }
#endif #endif
void allocateDetectorStructureMemory() { int allocateDetectorStructureMemory() {
LOG(logINFO, ("This Server is for 1 Eiger half module (250k)\n\n"));
// Allocation of memory
detectorModules = malloc(sizeof(sls_detector_module)); detectorModules = malloc(sizeof(sls_detector_module));
detectorChans = malloc(NCHIP * NCHAN * sizeof(int)); detectorChans = malloc(NCHIP * NCHAN * sizeof(int));
detectorDacs = malloc(NDAC * sizeof(int)); detectorDacs = malloc(NDAC * sizeof(int));
if (detectorModules == NULL || detectorChans == NULL ||
detectorDacs == NULL) {
initError = FAIL;
strcpy(initErrorMessage,
"Could not allocate memory for dacs or channels in detector\n");
LOG(logERROR, (initErrorMessage));
return FAIL;
}
LOG(logDEBUG1, LOG(logDEBUG1,
("modules from 0x%x to 0x%x\n", detectorModules, detectorModules)); ("modules from 0x%x to 0x%x\n", detectorModules, detectorModules));
LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans)); LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans));
LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n", detectorDacs, detectorDacs)); LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n", detectorDacs, detectorDacs));
detectorModules->dacs = detectorDacs; detectorModules->dacs = detectorDacs;
detectorModules->chanregs = detectorChans; detectorModules->chanregs = detectorChans;
detectorModules->ndac = NDAC; detectorModules->ndac = NDAC;
@ -748,14 +769,21 @@ void allocateDetectorStructureMemory() {
detectorModules->eV[2] = -1; detectorModules->eV[2] = -1;
thisSettings = UNINITIALIZED; thisSettings = UNINITIALIZED;
// if trimval requested, should return -1 to acknowledge unknown // initialize (trimbits at -1 for unknown)
for (int idac = 0; idac < (detectorModules)->ndac; ++idac) {
detectorDacs[idac] = 0;
}
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) { for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((detectorModules->chanregs) + ichan) = -1; *((detectorModules->chanregs) + ichan) = -1;
} }
return OK;
} }
void setupDetector() { void setupDetector() {
allocateDetectorStructureMemory(); LOG(logINFO, ("This Server is for 1 Eiger half module (250k)\n\n"));
if (allocateDetectorStructureMemory() == FAIL)
return;
// force top or master if in config file // force top or master if in config file
if (readConfigFile() == FAIL) if (readConfigFile() == FAIL)

View File

@ -3326,11 +3326,12 @@ int *getBadChannels(int *numChannels) {
if (*numChannels > 0) { if (*numChannels > 0) {
// get list of bad channels // get list of bad channels
retvals = malloc(*numChannels * sizeof(int)); retvals = malloc(*numChannels * sizeof(int));
memset(retvals, 0, *numChannels * sizeof(int));
if (retvals == NULL) { if (retvals == NULL) {
LOG(logERROR, ("Could not allocate memory to get bad channels\n"));
*numChannels = -1; *numChannels = -1;
return NULL; return NULL;
} }
memset(retvals, 0, *numChannels * sizeof(int));
int chIndex = 0; int chIndex = 0;
int numAddr = MASK_STRIP_NUM_REGS; int numAddr = MASK_STRIP_NUM_REGS;
// loop through registers // loop through registers

View File

@ -404,18 +404,24 @@ void initStopServer() {
/* set up detector */ /* set up detector */
void allocateDetectorStructureMemory() { int allocateDetectorStructureMemory() {
// Allocation of memory
detectorModules = malloc(sizeof(sls_detector_module)); detectorModules = malloc(sizeof(sls_detector_module));
detectorChans = malloc(NCHAN_PER_MODULE * sizeof(int)); detectorChans = malloc(NCHAN_PER_MODULE * sizeof(int));
badChannelMask = malloc(NCHAN_PER_MODULE * sizeof(char));
memset(badChannelMask, 0, NCHAN_PER_MODULE * sizeof(char));
detectorDacs = malloc(NDAC * sizeof(int)); detectorDacs = malloc(NDAC * sizeof(int));
badChannelMask = malloc(NCHAN_PER_MODULE * sizeof(char));
if (detectorModules == NULL || detectorChans == NULL ||
detectorDacs == NULL || badChannelMask == NULL) {
initError = FAIL;
strcpy(initErrorMessage, "Could not allocate memory for dacs, channels "
"or bad channel mask in detector\n");
LOG(logERROR, (initErrorMessage));
return FAIL;
}
LOG(logDEBUG1, LOG(logDEBUG1,
("modules from 0x%x to 0x%x\n", detectorModules, detectorModules)); ("modules from 0x%x to 0x%x\n", detectorModules, detectorModules));
LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans)); LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans));
LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n", detectorDacs, detectorDacs)); LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n", detectorDacs, detectorDacs));
(detectorModules)->dacs = detectorDacs; (detectorModules)->dacs = detectorDacs;
(detectorModules)->chanregs = detectorChans; (detectorModules)->chanregs = detectorChans;
(detectorModules)->ndac = NDAC; (detectorModules)->ndac = NDAC;
@ -429,21 +435,22 @@ void allocateDetectorStructureMemory() {
(detectorModules)->eV[2] = 0; (detectorModules)->eV[2] = 0;
thisSettings = UNINITIALIZED; thisSettings = UNINITIALIZED;
// initialize dacs // initialize
for (int idac = 0; idac < (detectorModules)->ndac; ++idac) { for (int idac = 0; idac < (detectorModules)->ndac; ++idac) {
detectorDacs[idac] = 0; detectorDacs[idac] = 0;
} }
// trimbits start at 0
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) { for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((detectorModules->chanregs) + ichan) = 0; *((detectorModules->chanregs) + ichan) = 0;
} }
memset(badChannelMask, 0, NCHAN_PER_MODULE * sizeof(char));
return OK;
} }
void setupDetector() { void setupDetector() {
LOG(logINFO, ("This Server is for 1 Mythen3 module \n")); LOG(logINFO, ("This Server is for 1 Mythen3 module \n"));
allocateDetectorStructureMemory(); if (allocateDetectorStructureMemory() == FAIL)
return;
if (checkCommandLineConfiguration() == FAIL) if (checkCommandLineConfiguration() == FAIL)
return; return;
@ -1412,6 +1419,10 @@ int setTrimbits(int *trimbits) {
int setAllTrimbits(int val) { int setAllTrimbits(int val) {
LOG(logINFO, ("Setting all trimbits to %d\n", val)); LOG(logINFO, ("Setting all trimbits to %d\n", val));
int *trimbits = malloc(sizeof(int) * ((detectorModules)->nchan)); int *trimbits = malloc(sizeof(int) * ((detectorModules)->nchan));
if (trimbits == NULL) {
LOG(logERROR, ("Could not allocate memory to set all trimbits\n"));
return FAIL;
}
for (int ichan = 0; ichan < ((detectorModules)->nchan); ++ichan) { for (int ichan = 0; ichan < ((detectorModules)->nchan); ++ichan) {
trimbits[ichan] = val; trimbits[ichan] = val;
} }
@ -2469,11 +2480,12 @@ int *getBadChannels(int *numChannels) {
} }
if (*numChannels > 0) { if (*numChannels > 0) {
retvals = malloc(*numChannels * sizeof(int)); retvals = malloc(*numChannels * sizeof(int));
memset(retvals, 0, *numChannels * sizeof(int));
if (retvals == NULL) { if (retvals == NULL) {
LOG(logERROR, ("Could not allocate memory to get bad channels\n"));
*numChannels = -1; *numChannels = -1;
return NULL; return NULL;
} }
memset(retvals, 0, *numChannels * sizeof(int));
// return only 1 channel for all counters // return only 1 channel for all counters
int ich = 0; int ich = 0;
for (int i = 0; i != NCHAN_PER_MODULE; i = i + NCOUNTERS) { for (int i = 0; i != NCHAN_PER_MODULE; i = i + NCOUNTERS) {

View File

@ -140,7 +140,7 @@ void checkVirtual9MFlag();
void setupFebBeb(); void setupFebBeb();
#endif #endif
#if defined(EIGERD) || defined(MYTHEN3D) #if defined(EIGERD) || defined(MYTHEN3D)
void allocateDetectorStructureMemory(); int allocateDetectorStructureMemory();
#endif #endif
void setupDetector(); void setupDetector();
#if defined(CHIPTESTBOARDD) #if defined(CHIPTESTBOARDD)

View File

@ -11,6 +11,8 @@
// initialization functions // initialization functions
int updateModeAllowedFunction(int file_des); int updateModeAllowedFunction(int file_des);
int printSocketReadError(); int printSocketReadError();
int sendError(int file_des);
void setMemoryAllocationErrorMessage();
void init_detector(); void init_detector();
int decode_function(int); int decode_function(int);
const char *getRetName(); const char *getRetName();

View File

@ -590,14 +590,17 @@ int Server_SendResult(int fileDes, intType itype, void *retval,
sendData(fileDes, &ret1, sizeof(ret1), INT32); sendData(fileDes, &ret1, sizeof(ret1), INT32);
if (ret == FAIL) { if (ret == FAIL) {
// send error message // send error message
if (strlen(mess)) if (strlen(mess)) {
sendData(fileDes, mess, MAX_STR_LENGTH, OTHER); sendData(fileDes, mess, MAX_STR_LENGTH, OTHER);
usleep(0); // test
}
// debugging feature. should not happen. // debugging feature. should not happen.
else else {
LOG(logERROR, ("No error message provided for this failure in %s " LOG(logERROR, ("No error message provided for this failure in %s "
"server. Will mess up TCP.\n", "server. Will mess up TCP.\n",
(isControlServer ? "control" : "stop"))); (isControlServer ? "control" : "stop")));
} }
}
// send return value // send return value
sendData(fileDes, retval, retvalSize, itype); sendData(fileDes, retval, retvalSize, itype);

View File

@ -115,6 +115,28 @@ int printSocketReadError() {
return FAIL; return FAIL;
} }
int sendError(int file_des) {
ret = FAIL;
LOG(logERROR, (mess));
Server_SendResult(file_des, INT32, NULL, 0);
return ret;
}
void setMemoryAllocationErrorMessage() {
struct sysinfo info;
sysinfo(&info);
sprintf(
mess,
"Memory allocation error (%s). Available space: %d MB. Please reboot",
getFunctionNameFromEnum((enum detFuncs)fnum),
(int)(info.freeram / (1024 * 1024)));
#ifdef EIGERD
strcat(mess, ".\n");
#else
strcat(mess, " using sls_detector_put rebootcontroller.\n");
#endif
}
void init_detector() { void init_detector() {
memset(udpDetails, 0, sizeof(udpDetails)); memset(udpDetails, 0, sizeof(udpDetails));
#ifdef VIRTUAL #ifdef VIRTUAL
@ -1728,67 +1750,45 @@ int get_module(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
sls_detector_module module;
int *myDac = NULL;
int *myChan = NULL;
module.dacs = NULL;
module.chanregs = NULL;
#if !defined(MYTHEN3D) && !defined(EIGERD) #if !defined(MYTHEN3D) && !defined(EIGERD)
functionNotImplemented(); functionNotImplemented();
return Server_SendResult(file_des, INT32, NULL, 0);
#else #else
int ndac = getNumberOfDACs();
// allocate to receive module structure int nchan = getTotalNumberOfChannels();
// allocate dacs if (ndac <= 0 || nchan <= 0) {
myDac = malloc(getNumberOfDACs() * sizeof(int)); strcpy(mess, "Invalid number of dacs/channels to set module\n");
// error return sendError(file_des);
if (getNumberOfDACs() > 0 && myDac == NULL) {
ret = FAIL;
sprintf(mess, "Could not allocate dacs\n");
LOG(logERROR, (mess));
} else
module.dacs = myDac;
// allocate chans
if (ret == OK) {
myChan = malloc(getTotalNumberOfChannels() * sizeof(int));
if (getTotalNumberOfChannels() > 0 && myChan == NULL) {
ret = FAIL;
strcpy(mess, "Could not allocate chans\n");
LOG(logERROR, (mess));
} else
module.chanregs = myChan;
} }
// receive module structure sls_detector_module module;
if (ret == OK) { module.dacs = NULL;
module.nchip = getNumberOfChips(); module.chanregs = NULL;
module.nchan = getTotalNumberOfChannels(); int *myDac = malloc(ndac * sizeof(int));
module.ndac = getNumberOfDACs(); int *myChan = malloc(nchan * sizeof(int));
if (myDac == NULL || myChan == NULL) {
// ensure nchan is not 0, else trimbits not copied free(myDac);
if (module.nchan == 0) { free(myChan);
strcpy(mess, "Could not get module as the number of channels to " setMemoryAllocationErrorMessage();
"copy is 0\n"); return sendError(file_des);
LOG(logERROR, (mess)); }
return FAIL; module.dacs = myDac;
} module.ndac = ndac;
getModule(&module); module.chanregs = myChan;
} module.nchan = nchan;
#endif module.nchip = getNumberOfChips();
Server_SendResult(file_des, INT32, NULL, 0); getModule(&module);
if (ret != FAIL) {
if (sendModule(file_des, &module) < 0) { Server_SendResult(file_des, INT32, NULL, 0);
ret = FAIL; if (ret == OK && sendModule(file_des, &module) < 0) {
strcpy(mess, "Could not send module data\n"); strcpy(mess, "Could not send module data\n");
LOG(logERROR, (mess)); ret = FAIL;
} LOG(logERROR, (mess));
} }
if (myChan != NULL)
free(myChan); free(myChan);
if (myDac != NULL)
free(myDac); free(myDac);
return ret; return ret;
#endif
} }
int set_module(int file_des) { int set_module(int file_des) {
@ -1798,39 +1798,30 @@ int set_module(int file_des) {
#if !(defined(MYTHEN3D) || defined(EIGERD)) #if !(defined(MYTHEN3D) || defined(EIGERD))
functionNotImplemented(); functionNotImplemented();
#else #else
int ndac = getNumberOfDACs();
int nchan = getTotalNumberOfChannels();
if (ndac <= 0 || nchan <= 0) {
strcpy(mess, "Invalid number of dacs/channels to set module\n");
return sendError(file_des);
}
sls_detector_module module; sls_detector_module module;
int *myDac = NULL;
int *myChan = NULL;
module.dacs = NULL; module.dacs = NULL;
module.chanregs = NULL; module.chanregs = NULL;
int *myDac = malloc(ndac * sizeof(int));
// allocate to receive arguments int *myChan = malloc(nchan * sizeof(int));
// allocate dacs if (myDac == NULL || myChan == NULL) {
myDac = malloc(getNumberOfDACs() * sizeof(int)); free(myDac);
// error free(myChan);
if (getNumberOfDACs() > 0 && myDac == NULL) { setMemoryAllocationErrorMessage();
ret = FAIL; return sendError(file_des);
strcpy(mess, "Could not allocate dacs\n");
LOG(logERROR, (mess));
} else
module.dacs = myDac;
// allocate chans
if (ret == OK) {
myChan = malloc(getTotalNumberOfChannels() * sizeof(int));
if (getTotalNumberOfChannels() > 0 && myChan == NULL) {
ret = FAIL;
strcpy(mess, "Could not allocate chans\n");
LOG(logERROR, (mess));
} else
module.chanregs = myChan;
} }
// receive arguments module.dacs = myDac;
if (ret == OK) { module.ndac = ndac;
module.chanregs = myChan;
module.nchan = nchan;
module.nchip = getNumberOfChips(); module.nchip = getNumberOfChips();
module.nchan = getTotalNumberOfChannels();
module.ndac = getNumberOfDACs();
int ts = receiveModule(file_des, &module); int ts = receiveModule(file_des, &module);
if (ts < 0) { if (ts < 0) {
free(myChan); free(myChan);
@ -1843,18 +1834,17 @@ int set_module(int file_des) {
module.iodelay, module.tau, module.eV[0])); module.iodelay, module.tau, module.eV[0]));
// should at least have a dac // should at least have a dac
if (ts <= (int)sizeof(sls_detector_module)) { if (ts <= (int)sizeof(sls_detector_module)) {
ret = FAIL;
strcpy(mess, "Cannot set module. Received incorrect number of " strcpy(mess, "Cannot set module. Received incorrect number of "
"dacs or channels\n"); "dacs or channels\n");
LOG(logERROR, (mess)); free(myChan);
} free(myDac);
return sendError(file_des);
} }
// only set // only set
if (ret == OK && Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
// check index // check index
// setsettings
// setsettings
#ifndef MYTHEN3D #ifndef MYTHEN3D
// m3 uses reg for chip (not settings) // m3 uses reg for chip (not settings)
validate_settings((enum detectorSettings)(module.reg)); validate_settings((enum detectorSettings)(module.reg));
@ -1867,9 +1857,7 @@ int set_module(int file_des) {
#endif #endif
LOG(logDEBUG1, ("Settings: %d\n", retval)); LOG(logDEBUG1, ("Settings: %d\n", retval));
} }
if (myChan != NULL)
free(myChan); free(myChan);
if (myDac != NULL)
free(myDac); free(myDac);
#endif #endif
@ -2957,6 +2945,7 @@ int get_frames_left(int file_des) {
retval = getNumFramesLeft(); retval = getNumFramesLeft();
LOG(logDEBUG1, ("retval num frames left %lld\n", (long long int)retval)); LOG(logDEBUG1, ("retval num frames left %lld\n", (long long int)retval));
#endif #endif
return Server_SendResult(file_des, INT64, &retval, sizeof(retval)); return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
} }
@ -6549,6 +6538,10 @@ int set_veto_photon(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
int args[2] = {-1, -1}; int args[2] = {-1, -1};
if (receiveData(file_des, args, sizeof(args), INT32) < 0) if (receiveData(file_des, args, sizeof(args), INT32) < 0)
return printSocketReadError(); return printSocketReadError();
@ -6556,14 +6549,17 @@ int set_veto_photon(int file_des) {
const int numChannels = args[1]; const int numChannels = args[1];
int *gainIndices = malloc(sizeof(int) * numChannels); int *gainIndices = malloc(sizeof(int) * numChannels);
if (receiveData(file_des, gainIndices, sizeof(int) * numChannels, INT32) < int *values = malloc(sizeof(int) * numChannels);
0) { if (gainIndices == NULL || values == NULL) {
free(gainIndices); free(gainIndices);
return printSocketReadError(); free(values);
setMemoryAllocationErrorMessage();
return sendError(file_des);
} }
int *values = malloc(sizeof(int) * numChannels); if ((receiveData(file_des, gainIndices, sizeof(int) * numChannels, INT32) <
if (receiveData(file_des, values, sizeof(int) * numChannels, INT32) < 0) { 0) ||
(receiveData(file_des, values, sizeof(int) * numChannels, INT32)) < 0) {
free(gainIndices); free(gainIndices);
free(values); free(values);
return printSocketReadError(); return printSocketReadError();
@ -6572,9 +6568,6 @@ int set_veto_photon(int file_des) {
LOG(logINFO, ("Setting Veto Photon: [chipIndex:%d, nch:%d]\n", chipIndex, LOG(logINFO, ("Setting Veto Photon: [chipIndex:%d, nch:%d]\n", chipIndex,
numChannels)); numChannels));
#ifndef GOTTHARD2D
functionNotImplemented();
#else
// only set // only set
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
if (numChannels != NCHAN) { if (numChannels != NCHAN) {
@ -6621,42 +6614,38 @@ int set_veto_photon(int file_des) {
} }
} }
} }
#endif
if (gainIndices != NULL) {
free(gainIndices); free(gainIndices);
}
if (values != NULL) {
free(values); free(values);
} #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
} }
int get_veto_photon(int file_des) { int get_veto_photon(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
int arg = -1;
int *retvals = NULL;
int *gainRetvals = NULL;
#ifndef GOTTHARD2D
functionNotImplemented();
return Server_SendResult(file_des, INT32, NULL, 0);
#else
int arg = -1;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError(); return printSocketReadError();
LOG(logDEBUG1, ("Getting veto photon [chip Index:%d]\n", arg)); LOG(logDEBUG1, ("Getting veto photon [chip Index:%d]\n", arg));
#ifndef GOTTHARD2D int *retvals = malloc(sizeof(int) * NCHAN);
functionNotImplemented(); int *gainRetvals = malloc(sizeof(int) * NCHAN);
#else if (gainRetvals == NULL || retvals == NULL) {
retvals = malloc(sizeof(int) * NCHAN); free(gainRetvals);
gainRetvals = malloc(sizeof(int) * NCHAN); free(retvals);
setMemoryAllocationErrorMessage();
return sendError(file_des);
}
memset(retvals, 0, sizeof(int) * NCHAN); memset(retvals, 0, sizeof(int) * NCHAN);
memset(gainRetvals, 0, sizeof(int) * NCHAN); memset(gainRetvals, 0, sizeof(int) * NCHAN);
if (retvals == NULL || gainRetvals == NULL) {
ret = FAIL;
strcpy(
mess,
"Could not get veto photon. Could not allocate memory in server\n");
LOG(logERROR, (mess));
} else {
// get only // get only
int chipIndex = arg; int chipIndex = arg;
if (chipIndex < -1 || chipIndex >= NCHIP) { if (chipIndex < -1 || chipIndex >= NCHIP) {
@ -6667,8 +6656,7 @@ int get_veto_photon(int file_des) {
} else { } else {
ret = getVetoPhoton(chipIndex, retvals, gainRetvals); ret = getVetoPhoton(chipIndex, retvals, gainRetvals);
if (ret == FAIL) { if (ret == FAIL) {
strcpy(mess, strcpy(mess, "Could not get veto photon for chipIndex -1. Not the "
"Could not get veto photon for chipIndex -1. Not the "
"same for all chips. Select specific chip index " "same for all chips. Select specific chip index "
"instead.\n"); "instead.\n");
LOG(logERROR, (mess)); LOG(logERROR, (mess));
@ -6679,8 +6667,7 @@ int get_veto_photon(int file_des) {
} }
} }
} }
}
#endif
Server_SendResult(file_des, INT32, NULL, 0); Server_SendResult(file_des, INT32, NULL, 0);
if (ret != FAIL) { if (ret != FAIL) {
int nch = NCHAN; int nch = NCHAN;
@ -6688,13 +6675,10 @@ int get_veto_photon(int file_des) {
sendData(file_des, gainRetvals, sizeof(int) * NCHAN, INT32); sendData(file_des, gainRetvals, sizeof(int) * NCHAN, INT32);
sendData(file_des, retvals, sizeof(int) * NCHAN, INT32); sendData(file_des, retvals, sizeof(int) * NCHAN, INT32);
} }
if (retvals != NULL) {
free(retvals); free(retvals);
}
if (gainRetvals != NULL) {
free(gainRetvals); free(gainRetvals);
}
return ret; return ret;
#endif
} }
int set_veto_reference(int file_des) { int set_veto_reference(int file_des) {
@ -7864,15 +7848,18 @@ int set_pattern(int file_des) {
functionNotImplemented(); functionNotImplemented();
#else #else
patternParameters *pat = malloc(sizeof(patternParameters)); patternParameters *pat = malloc(sizeof(patternParameters));
if (pat == NULL) {
setMemoryAllocationErrorMessage();
return sendError(file_des);
}
memset(pat, 0, sizeof(patternParameters)); memset(pat, 0, sizeof(patternParameters));
// ignoring endianness for eiger // ignoring endianness for eiger
if (receiveData(file_des, pat, sizeof(patternParameters), INT32) < 0) { if (receiveData(file_des, pat, sizeof(patternParameters), INT32) < 0) {
if (pat != NULL)
free(pat); free(pat);
return printSocketReadError(); return printSocketReadError();
} }
if (receiveData(file_des, args, MAX_STR_LENGTH, OTHER) < 0) { if (receiveData(file_des, args, MAX_STR_LENGTH, OTHER) < 0) {
if (pat != NULL)
free(pat); free(pat);
return printSocketReadError(); return printSocketReadError();
} }
@ -7881,7 +7868,6 @@ int set_pattern(int file_des) {
LOG(logDEBUG1, ("Setting Pattern from structure\n")); LOG(logDEBUG1, ("Setting Pattern from structure\n"));
ret = loadPattern(mess, logINFO, pat, args); ret = loadPattern(mess, logINFO, pat, args);
} }
if (pat != NULL)
free(pat); free(pat);
#endif #endif
@ -7918,6 +7904,10 @@ int get_pattern(int file_des) {
#else #else
patternParameters *pat = malloc(sizeof(patternParameters)); patternParameters *pat = malloc(sizeof(patternParameters));
if (pat == NULL) {
setMemoryAllocationErrorMessage();
return sendError(file_des);
}
memset(pat, 0, sizeof(patternParameters)); memset(pat, 0, sizeof(patternParameters));
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
@ -7927,7 +7917,6 @@ int get_pattern(int file_des) {
// ignoring endianness for eiger // ignoring endianness for eiger
int ret = int ret =
Server_SendResult(file_des, INT32, pat, sizeof(patternParameters)); Server_SendResult(file_des, INT32, pat, sizeof(patternParameters));
if (pat != NULL)
free(pat); free(pat);
return ret; return ret;
#endif #endif
@ -8036,10 +8025,13 @@ int set_scan(int file_des) {
if (ret == OK) { if (ret == OK) {
scan = 1; scan = 1;
numScanSteps = (abs(stop - start) / abs(step)) + 1; numScanSteps = (abs(stop - start) / abs(step)) + 1;
if (scanSteps != NULL) { // freed only at startup of the next scan
free(scanSteps); free(scanSteps);
}
scanSteps = malloc(numScanSteps * sizeof(int)); scanSteps = malloc(numScanSteps * sizeof(int));
if (scanSteps == NULL) {
setMemoryAllocationErrorMessage();
return sendError(file_des);
}
for (int i = 0; i != numScanSteps; ++i) { for (int i = 0; i != numScanSteps; ++i) {
scanSteps[i] = start + i * step; scanSteps[i] = start + i * step;
LOG(logDEBUG1, ("scansteps[%d]:%d\n", i, scanSteps[i])); LOG(logDEBUG1, ("scansteps[%d]:%d\n", i, scanSteps[i]));
@ -8313,55 +8305,54 @@ int set_adc_config(int file_des) {
int get_bad_channels(int file_des) { int get_bad_channels(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
int nretvals = 0;
int *retvals = NULL;
LOG(logDEBUG1, ("Getting bad channels\n")); LOG(logDEBUG1, ("Getting bad channels\n"));
#if !defined(GOTTHARD2D) && !defined(MYTHEN3D) #if !defined(GOTTHARD2D) && !defined(MYTHEN3D)
functionNotImplemented(); functionNotImplemented();
return Server_SendResult(file_des, INT32, NULL, 0);
#else #else
// get only // get only
retvals = getBadChannels(&nretvals); int nretvals = 0;
int *retvals = getBadChannels(&nretvals);
if (nretvals == -1) { if (nretvals == -1) {
ret = FAIL; setMemoryAllocationErrorMessage();
strcpy(mess, "Could not get bad channels. Memory allcoation error\n"); return sendError(file_des);
LOG(logERROR, (mess));
} }
#endif
Server_SendResult(file_des, INT32, NULL, 0); Server_SendResult(file_des, INT32, NULL, 0);
if (ret != FAIL) {
sendData(file_des, &nretvals, sizeof(nretvals), INT32); sendData(file_des, &nretvals, sizeof(nretvals), INT32);
if (nretvals > 0) { if (nretvals > 0) {
sendData(file_des, retvals, sizeof(int) * nretvals, INT32); sendData(file_des, retvals, sizeof(int) * nretvals, INT32);
} }
}
if (retvals != NULL) {
free(retvals); free(retvals);
}
return ret; return ret;
#endif
} }
int set_bad_channels(int file_des) { int set_bad_channels(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
int nargs = 0;
int *args = NULL;
if (receiveData(file_des, &nargs, sizeof(nargs), INT32) < 0)
return printSocketReadError();
if (nargs > 0) {
args = malloc(nargs * sizeof(int));
if (receiveData(file_des, args, nargs * sizeof(int), INT32) < 0)
return printSocketReadError();
}
LOG(logDEBUG1, ("Setting %d bad channels\n", nargs));
#if !defined(GOTTHARD2D) && !defined(MYTHEN3D) #if !defined(GOTTHARD2D) && !defined(MYTHEN3D)
functionNotImplemented(); functionNotImplemented();
#else #else
int nargs = 0;
if (receiveData(file_des, &nargs, sizeof(nargs), INT32) < 0)
return printSocketReadError();
int *args = NULL;
if (nargs > 0) {
args = malloc(nargs * sizeof(int));
if (args == NULL) {
setMemoryAllocationErrorMessage();
return sendError(file_des);
}
if (receiveData(file_des, args, nargs * sizeof(int), INT32) < 0) {
free(args);
return printSocketReadError();
}
}
LOG(logDEBUG1, ("Setting %d bad channels\n", nargs));
// only set // only set
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
// validate bad channel number // validate bad channel number
@ -8390,11 +8381,11 @@ int set_bad_channels(int file_des) {
int nretvals = 0; int nretvals = 0;
int *retvals = getBadChannels(&nretvals); int *retvals = getBadChannels(&nretvals);
if (nretvals == -1) { if (nretvals == -1) {
ret = FAIL; free(args);
strcpy(mess, "Could not get bad channels. Memory " setMemoryAllocationErrorMessage();
"allcoation error\n"); return sendError(file_des);
LOG(logERROR, (mess)); }
} else if (nretvals != nargs) { if (nretvals != nargs) {
ret = FAIL; ret = FAIL;
sprintf(mess, sprintf(mess,
"Could not set bad channels. Set %d channels, but " "Could not set bad channels. Set %d channels, but "
@ -8403,15 +8394,11 @@ int set_bad_channels(int file_des) {
nargs, nretvals); nargs, nretvals);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} }
if (retvals != NULL) {
free(retvals); free(retvals);
} }
} }
} }
}
if (args != NULL) {
free(args); free(args);
}
#endif #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
} }
@ -9940,14 +9927,9 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index,
src = malloc(MAX_BLACKFIN_PROGRAM_SIZE); src = malloc(MAX_BLACKFIN_PROGRAM_SIZE);
if (src == NULL) { if (src == NULL) {
fclose(fd); fclose(fd);
struct sysinfo info; setMemoryAllocationErrorMessage();
sysinfo(&info);
sprintf(mess,
"Could not %s. Memory allocation failure. Free "
"space: %d MB\n",
functionType, (int)(info.freeram / (1024 * 1024)));
LOG(logERROR, (mess));
ret = FAIL; ret = FAIL;
LOG(logERROR, (mess));
} }
} }
Server_SendResult(file_des, INT32, NULL, 0); Server_SendResult(file_des, INT32, NULL, 0);
@ -10090,6 +10072,7 @@ void receive_program_default(int file_des, enum PROGRAM_INDEX index,
} }
Server_SendResult(file_des, INT32, NULL, 0); Server_SendResult(file_des, INT32, NULL, 0);
if (ret == FAIL) { if (ret == FAIL) {
free(src);
return; return;
} }

View File

@ -161,6 +161,7 @@ Module::getTypeFromDetector(const std::string &hostname, uint16_t cport) {
LOG(logDEBUG1) << "Getting Module type "; LOG(logDEBUG1) << "Getting Module type ";
ClientSocket socket("Detector", hostname, cport); ClientSocket socket("Detector", hostname, cport);
socket.Send(F_GET_DETECTOR_TYPE); socket.Send(F_GET_DETECTOR_TYPE);
socket.setFnum(F_GET_DETECTOR_TYPE);
if (socket.Receive<int>() == FAIL) { if (socket.Receive<int>() == FAIL) {
throw RuntimeError("Detector (" + hostname + ", " + throw RuntimeError("Detector (" + hostname + ", " +
std::to_string(cport) + std::to_string(cport) +
@ -555,6 +556,7 @@ void Module::setSynchronization(const bool value) {
std::vector<int> Module::getBadChannels() const { std::vector<int> Module::getBadChannels() const {
auto client = DetectorSocket(shm()->hostname, shm()->controlPort); auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_GET_BAD_CHANNELS); client.Send(F_GET_BAD_CHANNELS);
client.setFnum(F_GET_BAD_CHANNELS);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
throw DetectorError("Detector " + std::to_string(moduleIndex) + throw DetectorError("Detector " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage()); " returned error: " + client.readErrorMessage());
@ -576,6 +578,7 @@ void Module::setBadChannels(std::vector<int> list) {
LOG(logDEBUG1) << "Sending bad channels to detector, nch:" << nch; LOG(logDEBUG1) << "Sending bad channels to detector, nch:" << nch;
auto client = DetectorSocket(shm()->hostname, shm()->controlPort); auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_SET_BAD_CHANNELS); client.Send(F_SET_BAD_CHANNELS);
client.setFnum(F_SET_BAD_CHANNELS);
client.Send(nch); client.Send(nch);
if (nch > 0) { if (nch > 0) {
client.Send(list); client.Send(list);
@ -966,6 +969,7 @@ std::vector<int64_t> Module::getFramesCaughtByReceiver() const {
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_RECEIVER_FRAMES_CAUGHT); client.Send(F_GET_RECEIVER_FRAMES_CAUGHT);
client.setFnum(F_GET_RECEIVER_FRAMES_CAUGHT);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
throw ReceiverError( throw ReceiverError(
"Receiver " + std::to_string(moduleIndex) + "Receiver " + std::to_string(moduleIndex) +
@ -988,6 +992,7 @@ std::vector<int64_t> Module::getNumMissingPackets() const {
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_NUM_MISSING_PACKETS); client.Send(F_GET_NUM_MISSING_PACKETS);
client.setFnum(F_GET_NUM_MISSING_PACKETS);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
throw ReceiverError( throw ReceiverError(
"Receiver " + std::to_string(moduleIndex) + "Receiver " + std::to_string(moduleIndex) +
@ -1010,6 +1015,7 @@ std::vector<int64_t> Module::getReceiverCurrentFrameIndex() const {
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_RECEIVER_FRAME_INDEX); client.Send(F_GET_RECEIVER_FRAME_INDEX);
client.setFnum(F_GET_RECEIVER_FRAME_INDEX);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
throw ReceiverError( throw ReceiverError(
"Receiver " + std::to_string(moduleIndex) + "Receiver " + std::to_string(moduleIndex) +
@ -1726,6 +1732,7 @@ void Module::sendReceiverRateCorrections(const std::vector<int64_t> &t) {
<< ']'; << ']';
auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
receiver.Send(F_SET_RECEIVER_RATE_CORRECT); receiver.Send(F_SET_RECEIVER_RATE_CORRECT);
receiver.setFnum(F_SET_RECEIVER_RATE_CORRECT);
receiver.Send(static_cast<int>(t.size())); receiver.Send(static_cast<int>(t.size()));
receiver.Send(t); receiver.Send(t);
if (receiver.Receive<int>() == FAIL) { if (receiver.Receive<int>() == FAIL) {
@ -2022,6 +2029,7 @@ void Module::sendVetoPhoton(const int chipIndex,
const int args[]{chipIndex, nch}; const int args[]{chipIndex, nch};
auto client = DetectorSocket(shm()->hostname, shm()->controlPort); auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_SET_VETO_PHOTON); client.Send(F_SET_VETO_PHOTON);
client.setFnum(F_SET_VETO_PHOTON);
client.Send(args); client.Send(args);
client.Send(gainIndices); client.Send(gainIndices);
client.Send(values); client.Send(values);
@ -2036,6 +2044,7 @@ void Module::getVetoPhoton(const int chipIndex,
LOG(logDEBUG1) << "Getting veto photon [" << chipIndex << "]\n"; LOG(logDEBUG1) << "Getting veto photon [" << chipIndex << "]\n";
auto client = DetectorSocket(shm()->hostname, shm()->controlPort); auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_GET_VETO_PHOTON); client.Send(F_GET_VETO_PHOTON);
client.setFnum(F_GET_VETO_PHOTON);
client.Send(chipIndex); client.Send(chipIndex);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
throw DetectorError("Detector " + std::to_string(moduleIndex) + throw DetectorError("Detector " + std::to_string(moduleIndex) +
@ -2542,6 +2551,7 @@ std::string Module::getPatterFileName() const {
void Module::setPattern(const Pattern &pat, const std::string &fname) { void Module::setPattern(const Pattern &pat, const std::string &fname) {
auto client = DetectorSocket(shm()->hostname, shm()->controlPort); auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_SET_PATTERN); client.Send(F_SET_PATTERN);
client.setFnum(F_SET_PATTERN);
client.Send(pat.data(), pat.size()); client.Send(pat.data(), pat.size());
char args[MAX_STR_LENGTH]{}; char args[MAX_STR_LENGTH]{};
strcpy_safe(args, fname.c_str()); strcpy_safe(args, fname.c_str());
@ -2652,6 +2662,7 @@ std::map<std::string, std::string> Module::getAdditionalJsonHeader() const {
} }
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_ADDITIONAL_JSON_HEADER); client.Send(F_GET_ADDITIONAL_JSON_HEADER);
client.setFnum(F_GET_ADDITIONAL_JSON_HEADER);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
throw ReceiverError("Receiver " + std::to_string(moduleIndex) + throw ReceiverError("Receiver " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage()); " returned error: " + client.readErrorMessage());
@ -2697,6 +2708,7 @@ void Module::setAdditionalJsonHeader(
<< ToString(jsonHeader); << ToString(jsonHeader);
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_SET_ADDITIONAL_JSON_HEADER); client.Send(F_SET_ADDITIONAL_JSON_HEADER);
client.setFnum(F_SET_ADDITIONAL_JSON_HEADER);
client.Send(size); client.Send(size);
if (size > 0) if (size > 0)
client.Send(&buff[0], buff.size()); client.Send(&buff[0], buff.size());
@ -2892,6 +2904,7 @@ std::string Module::executeCommand(const std::string &cmd) {
<< "): Sending command " << cmd; << "): Sending command " << cmd;
auto client = DetectorSocket(shm()->hostname, shm()->controlPort); auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_EXEC_COMMAND); client.Send(F_EXEC_COMMAND);
client.setFnum(F_EXEC_COMMAND);
client.Send(arg); client.Send(arg);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
std::cout << '\n'; std::cout << '\n';
@ -3504,6 +3517,7 @@ void Module::setModule(sls_detector_module &module, bool trimbits) {
} }
auto client = DetectorSocket(shm()->hostname, shm()->controlPort); auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_SET_MODULE); client.Send(F_SET_MODULE);
client.setFnum(F_SET_MODULE);
sendModule(&module, client); sendModule(&module, client);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
throw DetectorError("Module " + std::to_string(moduleIndex) + throw DetectorError("Module " + std::to_string(moduleIndex) +
@ -3516,6 +3530,7 @@ sls_detector_module Module::getModule() {
sls_detector_module module(shm()->detType); sls_detector_module module(shm()->detType);
auto client = DetectorSocket(shm()->hostname, shm()->controlPort); auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_GET_MODULE); client.Send(F_GET_MODULE);
client.setFnum(F_GET_MODULE);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
throw DetectorError("Module " + std::to_string(moduleIndex) + throw DetectorError("Module " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage()); " returned error: " + client.readErrorMessage());