diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index 94c830ae3..207b5add6 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -306,7 +306,7 @@ int M_nofunc(int file_des) { while (n > 0) n = receiveData(file_des,mess,MAX_STR_LENGTH,OTHER); - strcpy(mess,"Unrecognized Function. Please do not proceed.\n"); + sprintf(mess,"Unrecognized Function enum %d. Please do not proceed.\n", fnum); FILE_LOG(logERROR, (mess)); return Server_SendResult(file_des, OTHER, 0, NULL, 0); } @@ -344,7 +344,7 @@ int exec_command(int file_des) { FILE_LOG(logINFO, ("Executing command (%s)\n", cmd)); // set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { FILE* sysFile = popen(cmd, "r"); const size_t tempsize = 256; char temp[tempsize]; @@ -398,7 +398,7 @@ int set_external_signal_flag(int file_des) { functionNotImplemented(); #else // set - if ((flag != GET_EXTERNAL_SIGNAL_FLAG) && (Server_VerifyLock() != FAIL)) { + if ((flag != GET_EXTERNAL_SIGNAL_FLAG) && (Server_VerifyLock() == OK)) { setExtSignal(signalindex, flag); } // get @@ -424,7 +424,7 @@ int set_external_communication_mode(int file_des) { FILE_LOG(logDEBUG5, ("Setting external communication mode to %d\n", arg)); // set - if ((arg != GET_EXTERNAL_COMMUNICATION_MODE) && (Server_VerifyLock() != FAIL)) { + if ((arg != GET_EXTERNAL_COMMUNICATION_MODE) && (Server_VerifyLock() == OK)) { switch (arg) { case AUTO_TIMING: case TRIGGER_EXPOSURE: @@ -501,7 +501,7 @@ int digital_test(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { switch (mode) { #ifdef GOTTHARDD case DIGITAL_BIT_TEST: @@ -634,7 +634,7 @@ int set_dac(int file_des) { (mV ? "mV" : "dac units"))); // set & get - if ((val == -1) || ((val != -1) && (Server_VerifyLock() != FAIL))) { + if ((val == -1) || ((val != -1) && (Server_VerifyLock() == OK))) { switch(ind) { // io delay @@ -793,7 +793,7 @@ int write_register(int file_des) { FILE_LOG(logDEBUG5, ("Writing to register 0x%x, data 0x%x\n", addr, val)); // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { retval = writeRegister(addr, val); // validate if (retval != val) { @@ -912,7 +912,7 @@ int set_module(int file_des) { } // only set - else if (Server_VerifyLock() != FAIL) { + else if (Server_VerifyLock() == OK) { // check index switch (module.reg) { #ifdef EIGERD @@ -1043,7 +1043,7 @@ int set_settings(int file_des) { FILE_LOG(logDEBUG5, ("Setting settings %d\n", isett)); //set & get - if ((isett == GET_SETTINGS) || ((isett != GET_SETTINGS) && (Server_VerifyLock() != FAIL))) { + if ((isett == GET_SETTINGS) || ((isett != GET_SETTINGS) && (Server_VerifyLock() == OK))) { // check index switch(isett) { @@ -1123,7 +1123,7 @@ int start_acquisition(int file_des) { FILE_LOG(logDEBUG5, ("Starting Acquisition\n")); // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = startStateMachine(); if (ret == FAIL) { sprintf(mess, "Could not start acquisition\n"); @@ -1142,7 +1142,7 @@ int stop_acquisition(int file_des) { FILE_LOG(logDEBUG5, ("Stopping Acquisition\n")); // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = stopStateMachine(); if (ret == FAIL) { sprintf(mess, "Could not stop acquisition\n"); @@ -1166,7 +1166,7 @@ int start_readout(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = startReadOut(); if (ret == FAIL) { sprintf(mess, "Could not start readout\n"); @@ -1207,7 +1207,7 @@ int start_and_read_all(int file_des) { // start state machine FILE_LOG(logDEBUG5, ("Stopping Acquisition\n")); // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = startStateMachine(); if (ret == FAIL) { sprintf(mess, "Could not start acquisition\n"); @@ -1234,7 +1234,7 @@ int read_all(int file_des) { FILE_LOG(logDEBUG5, ("Reading all frames\n")); // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { readFrame(&ret, mess); } return Server_SendResult(file_des, INT32, 1 , NULL, 0); @@ -1261,7 +1261,7 @@ int set_timer(int file_des) { FILE_LOG(logDEBUG5, ("Setting timer index %d to %lld ns\n", ind, tns)); // set & get - if ((tns == -1) || ((tns != -1) && (Server_VerifyLock() != FAIL))) { + if ((tns == -1) || ((tns != -1) && (Server_VerifyLock() == OK))) { // check index switch (ind) { @@ -1395,7 +1395,7 @@ int set_dynamic_range(int file_des) { FILE_LOG(logDEBUG5, ("Setting dr to %d\n", dr)); // set & get - if ((dr == -1) || ((dr != -1) && (Server_VerifyLock() != FAIL))) { + if ((dr == -1) || ((dr != -1) && (Server_VerifyLock() == OK))) { #ifdef EIGERD int old_dr = setDynamicRange(-1); @@ -1463,7 +1463,7 @@ int set_readout_flags(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == GET_READOUT_FLAGS) || ((arg != GET_READOUT_FLAGS) && (Server_VerifyLock() != FAIL))) { + if ((arg == GET_READOUT_FLAGS) || ((arg != GET_READOUT_FLAGS) && (Server_VerifyLock() == OK))) { switch(arg) { case STORE_IN_RAM: @@ -1516,7 +1516,7 @@ int set_roi(int file_des) { return printSocketReadError(); } } - FILE_LOG(logDEBUG5, ("Set ROI (nroi:%d)\n", narg)); + FILE_LOG(logDEBUG5, ("Set ROI (narg:%d)\n", narg)); { int iloop = 0; for (iloop = 0; iloop < narg; ++iloop) { @@ -1529,7 +1529,7 @@ int set_roi(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == GET_READOUT_FLAGS) || ((arg != GET_READOUT_FLAGS) && (Server_VerifyLock() != FAIL))) { + if ((arg == GET_READOUT_FLAGS) || ((arg != GET_READOUT_FLAGS) && (Server_VerifyLock() == OK))) { retval = setROI(narg, arg, &nretval, &ret); if (ret == FAIL) { sprintf(mess,"Could not set all roi. " @@ -1574,7 +1574,7 @@ int set_speed(int file_des) { FILE_LOG(logDEBUG5, ("Setting speed index %d to %d\n", ind, val)); // set & get - if ((val == -1) || ((val != -1) && (Server_VerifyLock() != FAIL))) { + if ((val == -1) || ((val != -1) && (Server_VerifyLock() == OK))) { // check index switch(ind) { #ifdef JUNGFRAUD @@ -1605,7 +1605,7 @@ int set_speed(int file_des) { int exit_server(int file_des) { - cprintf(BG_RED,"Closing Server\n"); + cprintf(BG_RED, "Closing Server\n"); ret = OK; memset(mess, 0, sizeof(mess)); Server_SendResult(file_des, INT32, 0, NULL, 0); @@ -1661,7 +1661,7 @@ int set_port(int file_des) { // set only int sd = -1; - if ((Server_VerifyLock() != FAIL)) { + if ((Server_VerifyLock() == OK)) { // port number too low if (p_number < 1024) { ret = FAIL; @@ -1701,68 +1701,67 @@ int update_client(int file_des) { int send_update(int file_des) { - int n = 0; // if (n<0) should fail to stop talking to a closed client socket - int nm = 0; - int64_t retval = 0; + int n = 0; + int i32 = -1; + int64_t i64 = -1; n = sendData(file_des,lastClientIP,sizeof(lastClientIP),OTHER); if (n < 0) return printSocketReadError(); - - nm = setDynamicRange(GET_FLAG); - n = sendData(file_des,&nm,sizeof(nm),INT32); + i32 = setDynamicRange(GET_FLAG); + n = sendData(file_des,&i32,sizeof(i32),INT32); if (n < 0) return printSocketReadError(); dataBytes = calculateDataBytes(); n = sendData(file_des,&dataBytes,sizeof(dataBytes),INT32); if (n < 0) return printSocketReadError(); - nm = (int)setSettings(GET_SETTINGS); - n = sendData(file_des,&nm,sizeof(nm),INT32); + i32 = (int)setSettings(GET_SETTINGS); + n = sendData(file_des,&i32,sizeof(i32),INT32); if (n < 0) return printSocketReadError(); #ifdef EIGERD - nm = getThresholdEnergy(GET_FLAG); - n = sendData(file_des,&nm,sizeof(nm),INT32); + i32 = getThresholdEnergy(GET_FLAG); + n = sendData(file_des,&i32,sizeof(i32),INT32); if (n < 0) return printSocketReadError(); #endif - retval = setTimer(FRAME_NUMBER,GET_FLAG); - n = sendData(file_des,&retval,sizeof(int64_t),INT64); + i64 = setTimer(FRAME_NUMBER,GET_FLAG); + n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); - retval = setTimer(ACQUISITION_TIME,GET_FLAG); - n = sendData(file_des,&retval,sizeof(int64_t),INT64); + i64 = setTimer(ACQUISITION_TIME,GET_FLAG); + n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); #ifdef EIGERD - retval = setTimer(SUBFRAME_ACQUISITION_TIME,GET_FLAG); - n = sendData(file_des,&retval,sizeof(int64_t),INT64); + i64 = setTimer(SUBFRAME_ACQUISITION_TIME,GET_FLAG); + n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); - retval = setTimer(SUBFRAME_DEADTIME,GET_FLAG); - n = sendData(file_des,&retval,sizeof(int64_t),INT64); + i64 = setTimer(SUBFRAME_DEADTIME,GET_FLAG); + n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); #endif - retval = setTimer(FRAME_PERIOD,GET_FLAG); - n = sendData(file_des,&retval,sizeof(int64_t),INT64); + i64 = setTimer(FRAME_PERIOD,GET_FLAG); + n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); #ifndef EIGERD - retval = setTimer(DELAY_AFTER_TRIGGER,GET_FLAG); - n = sendData(file_des,&retval,sizeof(int64_t),INT64); + i64 = setTimer(DELAY_AFTER_TRIGGER,GET_FLAG); + n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); #endif #if !defined(EIGERD) && !defined(JUNGFRAUD) - retval = setTimer(GATES_NUMBER,GET_FLAG); - n = sendData(file_des,&retval,sizeof(int64_t),INT64); + i64 = setTimer(GATES_NUMBER,GET_FLAG); + n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); #endif - retval = setTimer(CYCLES_NUMBER,GET_FLAG); - n = sendData(file_des,&retval,sizeof(int64_t),INT64); + i64 = setTimer(CYCLES_NUMBER,GET_FLAG); + n = sendData(file_des,&i64,sizeof(i64),INT64); if (n < 0) return printSocketReadError(); if (lockStatus == 0) { @@ -1851,7 +1850,7 @@ int configure_mac(int file_des) { #endif // set only - if ((Server_VerifyLock() != FAIL)) { + if ((Server_VerifyLock() == OK)) { // stop detector if it was running if (getRunStatus() != IDLE) { @@ -1947,7 +1946,7 @@ int load_image(int file_des) { #else // set only - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { switch (index) { case DARK_IMAGE : case GAIN_IMAGE : @@ -1988,7 +1987,7 @@ int read_counter_block(int file_des) { #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = readCounterBlock(startACQ, retval); if (ret == FAIL) { strcpy(mess, "Could not read counter block\n"); @@ -2017,7 +2016,7 @@ int reset_counter_block(int file_des) { #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = resetCounterBlock(startACQ); if (ret == FAIL) { strcpy(mess, "Could not reset counter block\n"); @@ -2046,7 +2045,7 @@ int enable_ten_giga(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() != FAIL))) { + if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) { retval = enableTenGigabitEthernet(arg); FILE_LOG(logDEBUG5, ("10GbE: %d\n", retval)); validate(arg, retval, "enable/disable 10GbE", 0); @@ -2073,7 +2072,7 @@ int set_all_trimbits(int file_des) { #else // set - if (arg >= 0 && Server_VerifyLock() != FAIL) { + if (arg >= 0 && Server_VerifyLock() == OK) { ret = setAllTrimbits(arg); //changes settings to undefined setSettings(UNDEFINED); @@ -2115,7 +2114,7 @@ int write_adc_register(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) + if (Server_VerifyLock() == OK) setAdc(addr, val); #endif return Server_SendResult(file_des, INT32, 1, NULL, 0); @@ -2139,7 +2138,7 @@ int set_counter_bit(int file_des) { #else // set - if (arg >= 0 && Server_VerifyLock() != FAIL) { + if (arg >= 0 && Server_VerifyLock() == OK) { setCounterBit(arg); } // get @@ -2167,7 +2166,7 @@ int pulse_pixel(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = pulsePixel(args[0], args[1], args[2]); if (ret == FAIL) { strcpy(mess, "Could not pulse pixel\n"); @@ -2195,7 +2194,7 @@ int pulse_pixel_and_move(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = pulsePixelNMove(args[0], args[1], args[2]); if (ret == FAIL) { strcpy(mess, "Could not pulse pixel and move\n"); @@ -2224,7 +2223,7 @@ int pulse_chip(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = pulseChip(arg); if (ret == FAIL) { strcpy(mess, "Could not pulse chip\n"); @@ -2252,7 +2251,7 @@ int set_rate_correct(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { int dr = setDynamicRange(-1); @@ -2320,7 +2319,7 @@ int set_network_parameter(int file_des) { functionNotImplemented(); #else // set & get - if ((value == -1) || ((value != -1) && (Server_VerifyLock() != FAIL))) { + if ((value == -1) || ((value != -1) && (Server_VerifyLock() == OK))) { // check index switch (mode) { #ifdef EIGERD @@ -2378,7 +2377,7 @@ int program_fpga(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { // not in programming mode if (debugflag != PROGRAMMING_MODE) { @@ -2499,7 +2498,7 @@ int reset_fpga(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { if (isControlServer) { basictests(debugflag); // mapping of control server at least if (debugflag != PROGRAMMING_MODE) @@ -2528,7 +2527,7 @@ int power_chip(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() != FAIL))) { + if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) { retval = powerChip(arg); FILE_LOG(logDEBUG5, ("Power chip: %d\n", retval)); validate(arg, retval, "power on/off chip", 0); @@ -2561,7 +2560,7 @@ int set_activate(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() != FAIL))) { + if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) { retval = activate(arg); FILE_LOG(logDEBUG5, ("Activate: %d\n", retval)); validate(arg, retval, "set activate", 0); @@ -2582,7 +2581,7 @@ int prepare_acquisition(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = prepareAcquisition(); if (ret == FAIL) { strcpy(mess, "Could not prepare acquisition\n"); @@ -2611,7 +2610,7 @@ int threshold_temp(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() != FAIL))) { + if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) { if (arg > MAX_THRESHOLD_TEMP_VAL) { ret = FAIL; sprintf(mess,"Threshold Temp %d should be in range: 0 - %d\n", @@ -2645,7 +2644,7 @@ int temp_control(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() != FAIL))) { + if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) { retval = setTemperatureControl(arg); FILE_LOG(logDEBUG5, ("Temperature control: %d\n", retval)); validate(arg, retval, "set temperature control", 0); @@ -2671,7 +2670,7 @@ int temp_event(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() != FAIL))) { + if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) { retval = setTemperatureEvent(arg); FILE_LOG(logDEBUG5, ("Temperature event: %d\n", retval)); validate(arg, retval, "set temperature event", 0); @@ -2698,7 +2697,7 @@ int auto_comp_disable(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() != FAIL))) { + if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) { retval = autoCompDisable(arg); FILE_LOG(logDEBUG5, ("Auto comp disable: %d\n", retval)); validate(arg, retval, "set auto comp disable", 0); @@ -2725,7 +2724,7 @@ int storage_cell_start(int file_des) { functionNotImplemented(); #else // set & get - if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() != FAIL))) { + if ((arg == -1) || ((arg != -1) && (Server_VerifyLock() == OK))) { if (arg > MAX_STORAGE_CELL_VAL) { ret = FAIL; strcpy(mess,"Max Storage cell number should not exceed 15\n"); @@ -2817,7 +2816,7 @@ int software_trigger(int file_des) { functionNotImplemented(); #else // only set - if (Server_VerifyLock() != FAIL) { + if (Server_VerifyLock() == OK) { ret = softwareTrigger(); if (ret == FAIL) { sprintf(mess, "Could not send software trigger\n"); diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp index f7e69bc84..6102a8dbe 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.cpp @@ -7,7 +7,6 @@ #include "multiSlsDetectorCommand.h" #include "utilities.h" #include "detectorData.h" -#include "logger.h" #include #include @@ -2497,7 +2496,8 @@ void multiSlsDetector::printReceiverConfiguration(int detPos) { } // multi - parallelCall(&slsDetector::printReceiverConfiguration); + for (auto& d : detectors) + d->printReceiverConfiguration(); } diff --git a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h index 9c64d1c61..7abe974df 100644 --- a/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h +++ b/slsDetectorSoftware/multiSlsDetector/multiSlsDetector.h @@ -9,6 +9,7 @@ #include "sls_detector_defs.h" #include "error_defs.h" +#include "logger.h" class slsDetector; class SharedMemory; diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 0adf416d2..ef3aab5c7 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -43,8 +43,8 @@ slsDetector::slsDetector(detectorType type, int multiId, int id, bool verify) // ensure shared memory was not created before auto shm = SharedMemory(multiId, id); if (shm.IsExisting()) { - FILE_LOG(logWARNING, ("Weird, this shared memory should have been " - "deleted before! %s. Freeing it again.\n", shm.GetName().c_str())); + FILE_LOG(logWARNING) << "Weird, this shared memory should have been " + "deleted before! " << shm.GetName() << ". Freeing it again"; freeSharedMemory(multiId, id); } @@ -125,7 +125,7 @@ int slsDetector::checkVersionCompatibility(portType t) { return FAIL; } FILE_LOG(logDEBUG5) << "Checking version compatibility with detector with " - "value " << std::hex << arg; + "value " << std::hex << arg << std::dec; // control server @@ -156,7 +156,7 @@ int slsDetector::checkVersionCompatibility(portType t) { fnum = F_RECEIVER_CHECK_VERSION; arg = APIRECEIVER; FILE_LOG(logDEBUG5) << "Checking version compatibility with receiver with " - "value " << std::hex << arg; + "value " << std::hex << arg << std::dec; if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), NULL, 0); @@ -226,7 +226,7 @@ int64_t slsDetector::getId( idMode mode) { } if (ret != FAIL) { - FILE_LOG(logDEBUG5) << "Id ("<< mode << "): 0x" << std::hex << retval << std::setbase(10); + FILE_LOG(logDEBUG5) << "Id ("<< mode << "): 0x" << std::hex << retval << std::dec; } return retval; @@ -284,10 +284,11 @@ void slsDetector::initSharedMemory(bool created, detectorType type, int multiId, else { thisDetector = (sharedSlsDetector*)sharedMemory->OpenSharedMemory(sz); if (verify && thisDetector->shmversion != SLS_SHMVERSION) { - FILE_LOG(logERROR, ("Single shared memory (%d-%d:)version mismatch " - "(expected 0x%x but got 0x%x)\n", - multiId, detId, SLS_SHMVERSION, - thisDetector->shmversion)); + FILE_LOG(logERROR) << "Single shared memory " + "(" << multiId << "-" << detId << ":) " + "version mismatch " + "(expected 0x" << std::hex << SLS_SHMVERSION << + " but got 0x" << thisDetector->shmversion << ")" << std::dec; throw SharedMemoryException(); } } @@ -354,7 +355,7 @@ void slsDetector::setDetectorSpecificParameters(detectorType type, detParameterL list.nGappixelsY = 1; break; default: - FILE_LOG(logERROR, ("Unknown detector type!\n")); + FILE_LOG(logERROR) << "Unknown detector type!"; throw std::exception(); } } @@ -728,8 +729,8 @@ int slsDetector::receiveModule(sls_detector_module* myMod) { if (thisDetector->myDetectorType == EIGER) { ts += controlSocket->ReceiveDataOnly(myMod->chanregs, sizeof(int)*(myMod->nchan)); FILE_LOG(logDEBUG5) << "nchans= " << thisDetector->nChans << " nchips= " << thisDetector->nChips - << "mod - nchans= " << myMod->nchan << " nchips= " <nchip; - << "received chans of size "<< ts; + << "mod - nchans= " << myMod->nchan << " nchips= " <nchip + << "received chans of size "<< ts; } FILE_LOG(logDEBUG5) << "received module of size "<< ts << " register " << myMod->reg; return ts; @@ -739,9 +740,8 @@ int slsDetector::receiveModule(sls_detector_module* myMod) { slsDetectorDefs::detectorType slsDetector::getDetectorTypeFromShm(int multiId, bool verify) { auto shm = SharedMemory(multiId, detId); if (!shm.IsExisting()) { - FILE_LOG(logERROR, ("Shared memory %s does not exist.\n" - "Corrupted Multi Shared memory. Please free shared memory.\n", - shm.GetName().c_str())); + FILE_LOG(logERROR) << "Shared memory " << shm.GetName() << " does not exist.\n" + "Corrupted Multi Shared memory. Please free shared memory."; throw SharedMemoryException(); } @@ -750,9 +750,10 @@ slsDetectorDefs::detectorType slsDetector::getDetectorTypeFromShm(int multiId, b // open, map, verify version auto sdet = (sharedSlsDetector*)shm.OpenSharedMemory(sz); if (verify && sdet->shmversion != SLS_SHMVERSION) { - FILE_LOG(logERROR, ("Single shared memory (%d-%d:)version mismatch " - "(expected 0x%x but got 0x%x)\n", - multiId, detId, SLS_SHMVERSION, sdet->shmversion)); + FILE_LOG(logERROR) << "Single shared memory " + "(" << multiId << "-" << detId << ":)version mismatch " + "(expected 0x" << std::hex << SLS_SHMVERSION << + " but got 0x" << sdet->shmversion << ")" << std::dec; // unmap and throw sharedMemory->UnmapSharedMemory(thisDetector); throw SharedMemoryException(); @@ -802,7 +803,7 @@ int slsDetector::setDetectorType(detectorType const type) { int fnum = F_GET_DETECTOR_TYPE; int ret = FAIL; detectorType retval = GENERIC; - FILE_LOG(logDEBUG5) << "Setting detector type to " << arg; + FILE_LOG(logDEBUG5) << "Setting detector type to " << type; // if unspecified, then get from detector if (type == GET_DETECTOR_TYPE) { @@ -892,12 +893,12 @@ int slsDetector::getTotalNumberOfChannels() { } thisDetector->nChans = thisDetector->nChan[X]; thisDetector->dataBytes = thisDetector->nChans * thisDetector->nChips * 2 - * thisDetector->timerValue[SAMPLES_JCTB]; + * thisDetector->timerValue[SAMPLES_JCTB]; } FILE_LOG(logDEBUG5) << "Total number of channels: " << thisDetector->nChans * thisDetector->nChips << - << ". Data bytes: " << thisDetector->dataBytes; + ". Data bytes: " << thisDetector->dataBytes; return thisDetector->nChans * thisDetector->nChips; } @@ -1205,7 +1206,7 @@ int slsDetector::setPort(portType index, int num) { } // set port - if (dataSocket && receiverOnlineFlag->onlineFlag == ONLINE_FLAG && connectData() == OK) { + if (dataSocket && thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { ret = thisReceiver->Client_Send(fnum, &num, sizeof(num), &retval, sizeof(retval)); disconnectData(); @@ -1405,8 +1406,9 @@ int slsDetector::updateDetectorNoWait() { getTotalNumberOfChannels(); } - if (!n) - FILE_LOG(logERROR) << "Could not update detector, received 0 bytes\n"; + if (!n) { + FILE_LOG(logERROR) << "Could not update detector, received 0 bytes"; + } return OK; } @@ -1447,7 +1449,10 @@ int slsDetector::writeConfigurationFile(std::string const fname, multiSlsDetecto int slsDetector::writeConfigurationFile(std::ofstream &outfile, multiSlsDetector* m) { - const std::vector names; + + FILE_LOG(logDEBUG5) << "Write configuration file"; + + std::vector names; // common config names.push_back("hostname"); names.push_back("port"); @@ -1496,10 +1501,10 @@ int slsDetector::writeConfigurationFile(std::ofstream &outfile, multiSlsDetector } auto cmd = slsDetectorCommand(m); - for (int iline = 0; iline < nvar; ++iline) { + for (unsigned int iline = 0; iline < names.size(); ++iline) { char* args[] = {(char*)names[iline].c_str()}; - outfile << detId << ":"; - outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) << std::endl; + outfile << detId << ":"; + outfile << names[iline] << " " << cmd.executeLine(1, args, GET_ACTION) << std::endl; } return OK; } @@ -1627,23 +1632,23 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti std::string ssettings; switch (is) { case STANDARD: - ssettings="/standard"; + ssettings = "/standard"; thisDetector->currentSettings=STANDARD; break; case HIGHGAIN: - ssettings="/highgain"; + ssettings = "/highgain"; thisDetector->currentSettings=HIGHGAIN; break; case LOWGAIN: - ssettings="/lowgain"; + ssettings = "/lowgain"; thisDetector->currentSettings=LOWGAIN; break; case VERYHIGHGAIN: - ssettings="/veryhighgain"; + ssettings = "/veryhighgain"; thisDetector->currentSettings=VERYHIGHGAIN; break; case VERYLOWGAIN: - ssettings="/verylowgain"; + ssettings = "/verylowgain"; thisDetector->currentSettings=VERYLOWGAIN; break; default: @@ -1683,9 +1688,10 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings isetti FILE_LOG(logDEBUG5) << "Settings File is " << settingsfname; //read the files - myMod=createModule(); + myMod = createModule(); // readSettings also checks if create module is null if (NULL == readSettingsFile(settingsfname, myMod, tb)) { - if (myMod)deleteModule(myMod); + if (myMod) + deleteModule(myMod); return FAIL; } } @@ -1819,7 +1825,7 @@ int slsDetector::saveSettingsFile(std::string fname) { // find specific file if it has detid in file name (.snxxx) if (thisDetector->myDetectorType == EIGER) { ostfn << ".sn" << std::setfill('0') << std::setw(3) << std::dec << - getId(DETECTOR_SERIAL_NUMBER); + getId(DETECTOR_SERIAL_NUMBER); } fn=ostfn.str(); @@ -2095,60 +2101,60 @@ int slsDetector::configureMAC() { } { //converting IPaddress to std::hex - std::stringstream ss(arg[0]); + std::stringstream ss(args[0]); char cword[50]=""; bzero(cword, 50); std::string s; while (getline(ss, s, '.')) { sprintf(cword,"%s%02x",cword,atoi(s.c_str())); } - bzero(arg[0], 50); - strcpy(arg[0],cword); - FILE_LOG(logDEBUG5) << "receiver udp ip:" << arg[0] << "-"; + bzero(args[0], 50); + strcpy(args[0],cword); + FILE_LOG(logDEBUG5) << "receiver udp ip:" << args[0] << "-"; } { //converting MACaddress to std::hex - std::stringstream ss(arg[1]); + std::stringstream ss(args[1]); char cword[50]=""; bzero(cword, 50); std::string s; while (getline(ss, s, ':')) { sprintf(cword,"%s%s",cword,s.c_str()); } - bzero(arg[1], 50); - strcpy(arg[1],cword); - FILE_LOG(logDEBUG5) << "receiver udp mac:" << arg[1] << "-"; + bzero(args[1], 50); + strcpy(args[1],cword); + FILE_LOG(logDEBUG5) << "receiver udp mac:" << args[1] << "-"; } - FILE_LOG(logDEBUG5) << "receiver udp port:" << arg[2] << "-"; + FILE_LOG(logDEBUG5) << "receiver udp port:" << args[2] << "-"; { - std::stringstream ss(arg[3]); + std::stringstream ss(args[3]); char cword[50]=""; bzero(cword, 50); std::string s; while (getline(ss, s, ':')) { sprintf(cword,"%s%s",cword,s.c_str()); } - bzero(arg[3], 50); - strcpy(arg[3],cword); - FILE_LOG(logDEBUG5) << "detecotor udp mac:" << arg[3] << "-"; + bzero(args[3], 50); + strcpy(args[3],cword); + FILE_LOG(logDEBUG5) << "detecotor udp mac:" << args[3] << "-"; } { //converting IPaddress to std::hex - std::stringstream ss(arg[4]); + std::stringstream ss(args[4]); char cword[50]=""; bzero(cword, 50); std::string s; while (getline(ss, s, '.')) { sprintf(cword,"%s%02x",cword,atoi(s.c_str())); } - bzero(arg[4], 50); - strcpy(arg[4],cword); - FILE_LOG(logDEBUG5) << "detecotor udp ip:" << arg[4] << "-"; + bzero(args[4], 50); + strcpy(args[4],cword); + FILE_LOG(logDEBUG5) << "detecotor udp ip:" << args[4] << "-"; } - FILE_LOG(logDEBUG5) << "receiver udp port2:" << arg[5] << "-"; - FILE_LOG(logDEBUG5) << "row:" << arg[6] << "-"; - FILE_LOG(logDEBUG5) << "col:" << arg[7] << "-"; - FILE_LOG(logDEBUG5) << "reserved:" << arg[8] << "-"; + FILE_LOG(logDEBUG5) << "receiver udp port2:" << args[5] << "-"; + FILE_LOG(logDEBUG5) << "row:" << args[6] << "-"; + FILE_LOG(logDEBUG5) << "col:" << args[7] << "-"; + FILE_LOG(logDEBUG5) << "reserved:" << args[8] << "-"; // send to server @@ -2163,32 +2169,32 @@ int slsDetector::configureMAC() { // get detectormac, detector ip uint64_t idetectormac = 0; uint32_t idetectorip = 0; - sscanf(retval[1], "%lx", &idetectormac); - sscanf(retval[2], "%x", &idetectorip); - sprintf(retval[1],"%02x:%02x:%02x:%02x:%02x:%02x", + sscanf(retvals[1], "%lx", &idetectormac); + sscanf(retvals[2], "%x", &idetectorip); + sprintf(retvals[1],"%02x:%02x:%02x:%02x:%02x:%02x", (unsigned int)((idetectormac>>40)&0xFF), (unsigned int)((idetectormac>>32)&0xFF), (unsigned int)((idetectormac>>24)&0xFF), (unsigned int)((idetectormac>>16)&0xFF), (unsigned int)((idetectormac>>8)&0xFF), (unsigned int)((idetectormac>>0)&0xFF)); - sprintf(retval[2],"%d.%d.%d.%d", + sprintf(retvals[2],"%d.%d.%d.%d", (idetectorip>>24)&0xff, (idetectorip>>16)&0xff, (idetectorip>>8)&0xff, (idetectorip)&0xff); // update if different - if (strcasecmp(retval[1],thisDetector->detectorMAC)) { + if (strcasecmp(retvals[1],thisDetector->detectorMAC)) { memset(thisDetector->detectorMAC, 0, MAX_STR_LENGTH); - strcpy(thisDetector->detectorMAC, retval[1]); - FILE_LOG(logINFO, ("%d: Detector MAC updated to %s\n", detId, - thisDetector->detectorMAC)); + strcpy(thisDetector->detectorMAC, retvals[1]); + FILE_LOG(logINFO) << detId << ": Detector MAC updated to " << + thisDetector->detectorMAC; } - if (strcasecmp(retval[2],thisDetector->detectorIP)) { + if (strcasecmp(retvals[2],thisDetector->detectorIP)) { memset(thisDetector->detectorIP, 0, MAX_STR_LENGTH); - strcpy(thisDetector->detectorIP, retval[2]); - FILE_LOG(logINFO, ("%d: Detector IP updated to %s\n", detId, - thisDetector->detectorIP)); + strcpy(thisDetector->detectorIP, retvals[2]); + FILE_LOG(logINFO) << detId << ": Detector IP updated to " << + thisDetector->detectorIP; } if (ret == FORCE_UPDATE) ret = updateDetector(); @@ -2203,7 +2209,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) { int ret = FAIL; int64_t args[2] = {(int64_t)index, t}; int64_t retval = -1; - FILE_LOG(logDEBUG5) << "Setting " << getTimerType(index) << " to " << t " ns/value"; + FILE_LOG(logDEBUG5) << "Setting " << getTimerType(index) << " to " << t << " ns/value"; // meausurement is only shm level if (index == MEASUREMENTS_NUMBER) { @@ -2282,8 +2288,8 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) { (((index == FRAME_NUMBER) || (index == CYCLES_NUMBER) || (index == STORAGE_CELL_NUMBER)) ? - "(#Frames) * (#cycles) * (#storage cells)" : getTimerType(index)) << - << " to receiver: " << args[1]; + "(#Frames) * (#cycles) * (#storage cells)" : getTimerType(index)) << + " to receiver: " << args[1]; if (connectData() == OK) { char mess[MAX_STR_LENGTH] = {0}; @@ -2383,7 +2389,8 @@ int slsDetector::setDynamicRange(int n) { // send to detector int olddr = thisDetector->dynamicRange; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { - ret = thisDetectorControl->Client_Send(fnum, &n, sizeof(n), &retval, sizeof(retval)); + char mess[MAX_STR_LENGTH] = {0}; + ret = thisDetectorControl->Client_Send(fnum, &n, sizeof(n), &retval, sizeof(retval), mess); disconnectControl(); // handle ret @@ -2434,7 +2441,7 @@ int slsDetector::setDynamicRange(int n) { retval = -1; FILE_LOG(logINFO) << "Sending dynamic range to receiver " << n; if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum2, &n, sizeof(n), &retval, sizeof(retval)); + ret=thisReceiver->Client_Send(fnum, &n, sizeof(n), &retval, sizeof(retval)); disconnectData(); // handle ret @@ -2480,14 +2487,14 @@ int slsDetector::setDAC(int val, dacIndex index, int mV) { setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); else { FILE_LOG(logDEBUG5) << "Dac index " << index << ": " - << retval[0] << " dac units (" << retval[1] << "mV)"; + << retvals[0] << " dac units (" << retvals[1] << "mV)"; if (ret == FORCE_UPDATE) ret = updateDetector(); } } if (mV) - return retval[1]; - return retval[0]; + return retvals[1]; + return retvals[0]; } @@ -2545,7 +2552,7 @@ slsDetectorDefs::externalSignalFlag slsDetector::setExternalSignalFlags( int fnum = F_SET_EXTERNAL_SIGNAL_FLAG; int ret = FAIL; int args[2] = {signalindex, pol}; - externalCommunicationMode retval = GET_EXTERNAL_SIGNAL_FLAG; + externalSignalFlag retval = GET_EXTERNAL_SIGNAL_FLAG; FILE_LOG(logDEBUG5) << "Setting signal " << signalindex << " to flag " << pol; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { @@ -2850,7 +2857,7 @@ std::string slsDetector::getReceiverRealUDPSocketBufferSize() { ret = updateReceiver(); } } - return std::string(retval); + return std::to_string(retval); } @@ -2868,7 +2875,7 @@ std::string slsDetector::setDetectorMAC(std::string detectorMAC) { strcpy(thisDetector->detectorMAC, detectorMAC.c_str()); if (!strcmp(thisDetector->receiver_hostname, "none")) { FILE_LOG(logDEBUG5) << "Receiver hostname not set yet"; - } else if (setUDPConnection() == FAIL) + } else if (setUDPConnection() == FAIL) { FILE_LOG(logWARNING) << "UDP connection set up failed"; } } @@ -2911,7 +2918,7 @@ std::string slsDetector::setReceiver(std::string receiverIP) { } // stop acquisition if running if (getRunStatus()==RUNNING) { - FILE_LOG(logWARNING, ("Acquisition already running, Stopping it.\n")); + FILE_LOG(logWARNING) << "Acquisition already running, Stopping it."; stopAcquisition(); } // update detector before receiver @@ -3347,8 +3354,8 @@ int slsDetector::loadImageToDetector(imageType index,std::string const fname) { short int args[thisDetector->nChans * thisDetector->nChips]; FILE_LOG(logDEBUG5) << "Loading " << (!index ? "Dark" : "Gain") << "image from file " << fname; - if (readDataFile(fname,arg,getTotalNumberOfChannels())) { - ret = sendImageToDetector(index,arg); + if (readDataFile(fname, args, getTotalNumberOfChannels())) { + ret = sendImageToDetector(index,args); return ret; } @@ -3361,7 +3368,6 @@ int slsDetector::loadImageToDetector(imageType index,std::string const fname) { int slsDetector::sendImageToDetector(imageType index,short int imageVals[]) { int fnum = F_LOAD_IMAGE; int ret = FAIL; - int arg = (int)isettings; FILE_LOG(logDEBUG5) << "Sending image to detector"; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { @@ -3373,7 +3379,7 @@ int slsDetector::sendImageToDetector(imageType index,short int imageVals[]) { if (ret == FAIL) { setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); } else if (ret == FORCE_UPDATE) - ret = updateDetector(); + ret = updateDetector(); } return ret; } @@ -3409,7 +3415,7 @@ int slsDetector::getCounterBlock(short int image[],int startACQ) { if (ret == FAIL) { setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); } else if (ret == FORCE_UPDATE) - ret = updateDetector(); + ret = updateDetector(); } return ret; } @@ -3429,7 +3435,7 @@ int slsDetector::resetCounterBlock(int startACQ) { if (ret == FAIL) { setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); } else if (ret == FORCE_UPDATE) - ret = updateDetector(); + ret = updateDetector(); } return ret; } @@ -3544,10 +3550,10 @@ int slsDetector::sendROI(int n, ROI roiLimits[]) { for (int i = 0; i < nretval; ++i) { thisDetector->roiLimits[i] = retval[i]; FILE_LOG(logDEBUG5) << "ROI [" << i << "] (" << - thisDetector->roiLimits[j].xmin << "," << - thisDetector->roiLimits[j].xmax << "," << - thisDetector->roiLimits[j].ymin << "," << - thisDetector->roiLimits[j].ymax << ")"; + thisDetector->roiLimits[i].xmin << "," << + thisDetector->roiLimits[i].xmax << "," << + thisDetector->roiLimits[i].ymin << "," << + thisDetector->roiLimits[i].ymax << ")"; } } @@ -3601,7 +3607,7 @@ int slsDetector::sendROI(int n, ROI roiLimits[]) { int slsDetector::writeAdcRegister(int addr, int val) { int fnum = F_WRITE_ADC_REG; int ret = FAIL; - uint32_t args[2] = {addr, val}; + uint32_t args[2] = {(uint32_t)addr, (uint32_t)val}; FILE_LOG(logDEBUG5) << "Writing to ADC register 0x" << std::hex << addr << "data: 0x" << std::hex << val << std::dec; @@ -3613,9 +3619,9 @@ int slsDetector::writeAdcRegister(int addr, int val) { if (ret == FAIL) setErrorMask((getErrorMask())|(REGISER_WRITE_READ)); else if (ret == FORCE_UPDATE) - ret = updateDetector(); + ret = updateDetector(); } - return retval; + return ret; } @@ -3651,7 +3657,7 @@ int slsDetector::activate(int const enable) { FILE_LOG(logDEBUG5) << "Setting activate flag " << arg << " to receiver"; if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum2, &arg, sizeof(arg), &retval, sizeof(retval)); + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); disconnectData(); // handle ret @@ -3673,8 +3679,8 @@ int slsDetector::setDeactivatedRxrPaddingMode(int padding) { FILE_LOG(logDEBUG5) << "Deactivated Receiver Padding Enable: " << arg; if (thisDetector->receiverOnlineFlag==ONLINE_FLAG && connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); + ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); // handle ret if (ret == FAIL) @@ -3715,8 +3721,8 @@ int slsDetector::setFlippedData(dimension d, int value) { FILE_LOG(logDEBUG5) << "Setting flipped data across axis " << d << " with value: " << value; if (thisDetector->receiverOnlineFlag==ONLINE_FLAG && connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, args, sizeof(args), &retval, sizeof(retval)); - disconnectData(); + ret=thisReceiver->Client_Send(fnum, args, sizeof(args), &retval, sizeof(retval)); + disconnectData(); // handle ret if (ret == FAIL) @@ -3943,9 +3949,9 @@ int slsDetector::setTemperatureEvent(int val) { int slsDetector::setStoragecellStart(int pos) { int fnum = F_STORAGE_CELL_START; int ret = FAIL; - int arg = val; + int arg = pos; int retval = -1; - FILE_LOG(logDEBUG5) << "Setting storage cell start to " << val; + FILE_LOG(logDEBUG5) << "Setting storage cell start to " << pos; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); @@ -4211,11 +4217,10 @@ int slsDetector::programFPGA(std::string fname) { int slsDetector::resetFPGA() { int fnum = F_RESET_FPGA; int ret = FAIL; - int arg = n; FILE_LOG(logDEBUG5) << "Sending reset FPGA"; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { - ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), NULL, 0); + ret = thisDetectorControl->Client_Send(fnum, NULL, 0, NULL, 0); disconnectControl(); // handle ret @@ -4231,9 +4236,9 @@ int slsDetector::resetFPGA() { int slsDetector::powerChip(int ival) { int fnum = F_POWER_CHIP; int ret = FAIL; - int arg = val; + int arg = ival; int retval = -1; - FILE_LOG(logDEBUG5) << "Setting power chip to " << val; + FILE_LOG(logDEBUG5) << "Setting power chip to " << ival; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); @@ -4255,9 +4260,9 @@ int slsDetector::powerChip(int ival) { int slsDetector::setAutoComparatorDisableMode(int ival) { int fnum = F_AUTO_COMP_DISABLE; int ret = FAIL; - int arg = val; + int arg = ival; int retval = -1; - FILE_LOG(logDEBUG5) << "Setting auto comp disable mode to " << val; + FILE_LOG(logDEBUG5) << "Setting auto comp disable mode to " << ival; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); @@ -4295,7 +4300,6 @@ int slsDetector::setModule(sls_detector_module module, int tb) { int fnum = F_SET_MODULE; int ret = FAIL; int retval = -1; - char mess[MAX_STR_LENGTH] = {0}; FILE_LOG(logDEBUG5) << "Setting module with tb:" << tb; //to exclude trimbits @@ -4328,7 +4332,7 @@ int slsDetector::setModule(sls_detector_module module, int tb) { } // update client structure - if (ret = OK) { + if (ret == OK) { if (detectorModules) { if (thisDetector->myDetectorType == EIGER && tb && chanregs) { for (int ichip = 0; ichip < thisDetector->nChips; ++ichip) { @@ -4341,20 +4345,21 @@ int slsDetector::setModule(sls_detector_module module, int tb) { if (adcs) { for (int i = 0; i < thisDetector->nAdcs; ++i) { adcs[i] = module.adcs[i]; + } + if (dacs) { + for (int i = 0; i < thisDetector->nDacs; ++i) + dacs[i] = module.dacs[i]; + } + (detectorModules)->serialnumber = module.serialnumber; + (detectorModules)->reg = module.reg; + (detectorModules)->iodelay = module.iodelay; + (detectorModules)->tau = module.tau; + (detectorModules)->eV = module.eV; } - if (dacs) { - for (int i = 0; i < thisDetector->nDacs; ++i) - dacs[i] = module.dacs[i]; - } - (detectorModules)->serialnumber = module.serialnumber; - (detectorModules)->reg = module.reg; - (detectorModules)->iodelay = module.iodelay; - (detectorModules)->tau = module.tau; - (detectorModules)->eV = module.eV; } - if (e_eV != -1) - thisDetector->currentThresholdEV = e_eV; - + if (module.eV != -1) { + thisDetector->currentThresholdEV = module.eV; + } } return ret; } @@ -4363,13 +4368,18 @@ int slsDetector::setModule(sls_detector_module module, int tb) { slsDetectorDefs::sls_detector_module *slsDetector::getModule() { int fnum = F_GET_MODULE; int ret = FAIL; - int arg = (int)isettings; FILE_LOG(logDEBUG5) << "Getting module"; sls_detector_module *myMod = createModule(); + if (myMod == NULL) { + FILE_LOG(logERROR) << "Could not create module"; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + return NULL; + + } if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { - ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), NULL, 0); + ret = thisDetectorControl->Client_Send(fnum,NULL, 0, NULL, 0); // handle ret if (ret == FAIL) { @@ -4423,7 +4433,8 @@ int slsDetector::setRateCorrection(int64_t t) { FILE_LOG(logDEBUG5) << "Setting Rate Correction to " << arg; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { - ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), NULL, 0); + char mess[MAX_STR_LENGTH] = {0}; + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), NULL, 0, mess); disconnectControl(); // handle ret @@ -4448,7 +4459,7 @@ int64_t slsDetector::getRateCorrection() { FILE_LOG(logDEBUG5) << "Getting rate correction"; if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { - ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + ret = thisDetectorControl->Client_Send(fnum, NULL, 0, &retval, sizeof(retval)); disconnectControl(); // handle ret @@ -4464,7 +4475,7 @@ int64_t slsDetector::getRateCorrection() { } -void slsDetector::printReceiverConfiguration(int level) { +void slsDetector::printReceiverConfiguration(TLogLevel level) { FILE_LOG(level) << "#Detector " << detId << ":\n" << "Receiver Hostname:\t" << getNetworkParameter(RECEIVER_HOSTNAME) << "Detector UDP IP (Source):\t\t" << getNetworkParameter(DETECTOR_IP) << @@ -4472,9 +4483,7 @@ void slsDetector::printReceiverConfiguration(int level) { "Receiver UDP IP:\t" << getNetworkParameter(RECEIVER_UDP_IP) << "Receiver UDP MAC:\t" << getNetworkParameter(RECEIVER_UDP_MAC) << "Receiver UDP Port:\t" << getNetworkParameter(RECEIVER_UDP_PORT) << - ((thisDetector->myDetectorType == EIGER) ? - ("Receiver UDP Port2:\t" << getNetworkParameter(RECEIVER_UDP_PORT2) << "\n") - : ("\n")); + "Receiver UDP Port2:\t" << getNetworkParameter(RECEIVER_UDP_PORT2); } @@ -4756,9 +4765,9 @@ int slsDetector::updateReceiverNoWait() { n += dataSocket->ReceiveDataOnly(&i32, sizeof(i32)); thisDetector->receiver_silentMode = i32; - if (!n) + if (!n) { FILE_LOG(logERROR) << "Could not update receiver, received 0 bytes\n"; - + } return OK; } @@ -4786,7 +4795,7 @@ int slsDetector::updateReceiver() { void slsDetector::sendMultiDetectorSize() { int fnum = F_SEND_RECEIVER_MULTIDETSIZE; int ret = FAIL; - int args[2] = thisDetector->multiSize; + int args[2] = {thisDetector->multiSize[0], thisDetector->multiSize[1]}; int retval = -1; FILE_LOG(logDEBUG5) << "Sending multi detector size to Receiver (" << thisDetector->multiSize[0] << "," << thisDetector->multiSize[1] << ")"; @@ -4804,7 +4813,6 @@ void slsDetector::sendMultiDetectorSize() { ret = updateReceiver(); } } - return retval; } @@ -4828,7 +4836,6 @@ void slsDetector::setDetectorId() { ret = updateReceiver(); } } - return retval; } @@ -4848,7 +4855,7 @@ void slsDetector::setDetectorHostname() { if (ret == FAIL) { setErrorMask((getErrorMask())|(RECEIVER_DET_HOSTNAME_NOT_SET)); } else { - FILE_LOG(logDEBUG5) << "Receiver set detector hostname: " << retval; + FILE_LOG(logDEBUG5) << "Receiver set detector hostname: " << retvals; if (ret == FORCE_UPDATE) ret = updateReceiver(); } @@ -4889,7 +4896,7 @@ std::string slsDetector::setFilePath(std::string s) { } } } - return getFilePath(); + return thisDetector->receiver_filePath; } @@ -4922,7 +4929,7 @@ std::string slsDetector::setFileName(std::string s) { } } } - return getFileName(); + return thisDetector->receiver_fileName; } @@ -5043,460 +5050,374 @@ int slsDetector::getFileIndex() { int slsDetector::setFileIndex(int i) { + if (i >= 0) { + int fnum = F_SET_RECEIVER_FILE_INDEX; + int ret = FAIL; + int arg = i; + int retval = -1; + FILE_LOG(logDEBUG5) << "Setting file index to " << arg; - if (i < 0) - return getFileIndex(); - - int fnum=F_SET_RECEIVER_FILE_INDEX; - int ret = FAIL; - int retval=-1; - int arg = i; - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending file index to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); disconnectData(); - } - if (ret == FAIL) - setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); - else - thisDetector->receiver_fileIndex = retval; - if (ret==FORCE_UPDATE) - updateReceiver(); - } - return getFileIndex(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver file index: " << retval; + thisDetector->receiver_fileIndex = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } + } + } + return thisDetector->receiver_fileIndex; } int slsDetector::incrementFileIndex() { if (thisDetector->receiver_fileWriteEnable) - return setFileIndex(thisDetector->receiver_fileIndex+1); + return setFileIndex(thisDetector->receiver_fileIndex + 1); return thisDetector->receiver_fileIndex; } - - int slsDetector::startReceiver() { - int fnum=F_START_RECEIVER; + int fnum = F_START_RECEIVER; int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; + char mess[MAX_STR_LENGTH] = {0}; + FILE_LOG(logDEBUG5) << "Starting Receiver"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Starting Receiver " << std::endl; -#endif + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0, mess); + disconnectData(); - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0, mess); - disconnectData(); - } - if (ret==FORCE_UPDATE) - ret=updateReceiver(); - else if (ret == FAIL) { + // handle ret + if (ret == FAIL) { if (strstr(mess,"UDP")!=NULL) setErrorMask((getErrorMask())|(COULDNOT_CREATE_UDP_SOCKET)); else if (strstr(mess,"file")!=NULL) setErrorMask((getErrorMask())|(COULDNOT_CREATE_FILE)); else setErrorMask((getErrorMask())|(COULDNOT_START_RECEIVER)); - } + } else if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - return ret; } - - int slsDetector::stopReceiver() { - int fnum=F_STOP_RECEIVER; + int fnum = F_STOP_RECEIVER; int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; + FILE_LOG(logDEBUG5) << "Stopping Receiver"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Stopping Receiver " << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0, mess); - disconnectData(); - } - if (ret==FORCE_UPDATE) - ret=updateReceiver(); - else if (ret == FAIL) + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0); + disconnectData(); + + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(COULDNOT_STOP_RECEIVER)); + } else if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - return ret; } - - - slsDetectorDefs::runStatus slsDetector::getReceiverStatus() { - int fnum=F_GET_RECEIVER_STATUS; + int fnum = F_GET_RECEIVER_STATUS; int ret = FAIL; - int retval=-1; - runStatus s = ERROR; + runStatus retval = ERROR; + FILE_LOG(logDEBUG5) << "Getting Receiver Status"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Getting Receiver Status" << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, NULL, 0, &retval, sizeof(retval)); - disconnectData(); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Receiver Status: " << runStatusType(retval); + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - if (retval!=-1) - s=(runStatus)retval; - if (ret==FORCE_UPDATE) - updateReceiver(); } - return s; + return retval; } - - int slsDetector::getFramesCaughtByReceiver() { - int fnum=F_GET_RECEIVER_FRAMES_CAUGHT; + int fnum = F_GET_RECEIVER_FRAMES_CAUGHT; int ret = FAIL; - int retval=-1; + int retval = -1; + FILE_LOG(logDEBUG5) << "Getting Frames Caught by Receiver"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Getting Frames Caught by Receiver " << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, NULL, 0, &retval, sizeof(retval)); - disconnectData(); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Frames Caught by Receiver: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - if (ret==FORCE_UPDATE) - ret=updateReceiver(); } - return retval; } - -int slsDetector::getFramesCaughtByAnyReceiver() { - return getFramesCaughtByReceiver(); -} - - - int slsDetector::getReceiverCurrentFrameIndex() { - int fnum=F_GET_RECEIVER_FRAME_INDEX; + int fnum = F_GET_RECEIVER_FRAME_INDEX; int ret = FAIL; - int retval=-1; + int retval = -1; + FILE_LOG(logDEBUG5) << "Getting Current Frame Index of Receiver"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Getting Current Frame Index of Receiver " << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, NULL, 0, &retval, sizeof(retval)); - disconnectData(); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Current Frame Index of Receiver: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - if (ret==FORCE_UPDATE) - ret=updateReceiver(); } - return retval; } - - int slsDetector::resetFramesCaught() { - int fnum=F_RESET_RECEIVER_FRAMES_CAUGHT; + int fnum = F_RESET_RECEIVER_FRAMES_CAUGHT; int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; + FILE_LOG(logDEBUG5) << "Reset Frames Caught by Receiver"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Reset Frames Caught by Receiver" << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0, mess); - disconnectData(); - } - if (ret==FORCE_UPDATE) - ret=updateReceiver(); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0); + disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - return ret; } - - - - - - - - int slsDetector::enableWriteToFile(int enable) { + if (enable >= 0) { + int fnum = F_ENABLE_RECEIVER_FILE_WRITE; + int ret = FAIL; + int arg = enable; + int retval = -1; + FILE_LOG(logDEBUG5) << "Sending enable file write to receiver: " << arg; - if (enable < 0) - return thisDetector->receiver_fileWriteEnable; - - int fnum=F_ENABLE_RECEIVER_FILE_WRITE; - int ret = FAIL; - int retval=-1; - int arg = enable; - - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending enable file write to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver file write enable: " << retval; + thisDetector->receiver_fileWriteEnable = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } } - if (ret == FAIL) - setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); - else - thisDetector->receiver_fileWriteEnable = retval; - if (ret==FORCE_UPDATE) - updateReceiver(); } - - return thisDetector->receiver_fileWriteEnable; } - - int slsDetector::overwriteFile(int enable) { + if (enable >= 0) { + int fnum = F_ENABLE_RECEIVER_OVERWRITE; + int ret = FAIL; + int arg = enable; + int retval = -1; + FILE_LOG(logDEBUG5) << "Sending enable file overwrite to receiver: " << arg; - if (enable < 0) - return thisDetector->receiver_overWriteEnable; - - int fnum=F_ENABLE_RECEIVER_OVERWRITE; - int ret = FAIL; - int retval=-1; - int arg = enable; - - - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending enable file write to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); disconnectData(); - } - if (ret == FAIL) - setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); - else - thisDetector->receiver_overWriteEnable = retval; - if (ret==FORCE_UPDATE) - updateReceiver(); - } + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); + } else { + FILE_LOG(logDEBUG5) << "Receiver file overwrite enable: " << retval; + thisDetector->receiver_overWriteEnable = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } + } + } return thisDetector->receiver_overWriteEnable; } - - - - - int slsDetector::setReceiverStreamingFrequency(int freq) { - if (freq >= 0) { - thisDetector->receiver_read_freq = freq; - - int fnum=F_RECEIVER_STREAMING_FREQUENCY; + int fnum = F_RECEIVER_STREAMING_FREQUENCY; int ret = FAIL; - int retval=-1; int arg = freq; + int retval = -1; + FILE_LOG(logDEBUG5) << "Sending read frequency to receiver: " << arg; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending read frequency to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); - } - if ((ret == FAIL) || (retval != freq)) { - FILE_LOG(logERROR) << "could not set receiver read frequency to " << freq - <<" Returned:" << retval << std::endl; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(RECEIVER_STREAMING_FREQUENCY)); + } else { + FILE_LOG(logDEBUG5) << "Receiver read frequency: " << retval; + thisDetector->receiver_read_freq = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - - if (ret==FORCE_UPDATE) - updateReceiver(); } } - return thisDetector->receiver_read_freq; } int slsDetector::setReceiverStreamingTimer(int time_in_ms) { - int fnum=F_RECEIVER_STREAMING_TIMER; + int fnum = F_RECEIVER_STREAMING_TIMER; int ret = FAIL; int arg = time_in_ms; int retval = -1; + FILE_LOG(logDEBUG5) << "Sending read timer to receiver: " << arg; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "Sending read timer to receiver " << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(RECEIVER_STREAMING_TIMER)); + } else { + FILE_LOG(logDEBUG5) << "Receiver read timer: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - if (ret==FORCE_UPDATE) - updateReceiver(); - } - - if ((time_in_ms > 0) && (retval != time_in_ms)) { - FILE_LOG(logERROR) << "could not set receiver read timer to " << time_in_ms - <<" Returned:" << retval << std::endl; - setErrorMask((getErrorMask())|(RECEIVER_STREAMING_TIMER)); } return retval; } -int slsDetector::enableDataStreamingToClient(int enable) { - FILE_LOG(logERROR, ("Must be called from the multi Detector level\n")); - return 0; -} - - - - - int slsDetector::enableDataStreamingFromReceiver(int enable) { - if (enable >= 0) { - int fnum=F_STREAM_DATA_FROM_RECEIVER; + int fnum = F_STREAM_DATA_FROM_RECEIVER; int ret = FAIL; - int retval=-1; int arg = enable; + int retval = -1; + FILE_LOG(logDEBUG5) << "Sending Data Streaming to receiver: " << arg; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "***************Sending Data Streaming in Receiver " - << arg << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); - disconnectData(); - } - if (ret==FAIL) { - retval = -1; - FILE_LOG(logERROR) << "could not set data streaming in receiver to " << - enable <<" Returned:" << retval << std::endl; + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(DATA_STREAMING)); } else { + FILE_LOG(logDEBUG5) << "Receiver Data Streaming: " << retval; thisDetector->receiver_upstream = retval; - if (ret==FORCE_UPDATE) - updateReceiver(); + if (ret == FORCE_UPDATE) + ret = updateReceiver(); } } } - return thisDetector->receiver_upstream; } - - int slsDetector::enableTenGigabitEthernet(int i) { - int ret=FAIL; + int fnum = F_ENABLE_TEN_GIGA; + int ret = FAIL; + int arg = i; int retval = -1; - int fnum=F_ENABLE_TEN_GIGA,fnum2 = F_ENABLE_RECEIVER_TEN_GIGA; - char mess[MAX_STR_LENGTH]=""; + FILE_LOG(logDEBUG5) << "Enabling / Disabling 10Gbe: " << arg; -#ifdef VERBOSE - std::cout<< std::endl<< "Enabling / Disabling 10Gbe" << std::endl; -#endif + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectControl(); - if (thisDetector->onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&i,sizeof(i)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret==FAIL) { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - setErrorMask((getErrorMask())|(DETECTOR_TEN_GIGA)); - } - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(DETECTOR_TEN_GIGA)); + } else { + FILE_LOG(logDEBUG5) << "10Gbe: " << retval; + thisDetector->tenGigaEnable = retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); + // have to configure mac after setting 10GbE + ret = configureMAC(); } } - if (ret!=FAIL) { - //must also configuremac - if ((i != -1)&&(retval == i)) - if (configureMAC() != FAIL) { - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { - ret = FAIL; - retval=-1; -#ifdef VERBOSE - FILE_LOG(logINFO) << "Enabling / Disabling 10Gbe in receiver: " - << i << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum2, &i, sizeof(i), &retval, sizeof(retval)); - disconnectData(); - } - if (ret==FAIL) - setErrorMask((getErrorMask())|(RECEIVER_TEN_GIGA)); - } - } - } + // receiver + if ((thisDetector->receiverOnlineFlag == ONLINE_FLAG) && ret == OK) { + fnum = F_ENABLE_RECEIVER_TEN_GIGA; + ret = FAIL; + arg = thisDetector->tenGigaEnable; + retval = -1; + FILE_LOG(logINFO) << "Sending 10Gbe enable to Receiver " << arg; - if (ret != FAIL) - thisDetector->tenGigaEnable=retval; - return retval; + if (connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); + + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(RECEIVER_TEN_GIGA)); + } else { + FILE_LOG(logDEBUG5) << "Receiver 10Gbe enable: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } + } + } + return thisDetector->tenGigaEnable; } - - int slsDetector::setReceiverFifoDepth(int i) { - int fnum=F_SET_RECEIVER_FIFO_DEPTH; + int fnum = F_SET_RECEIVER_FIFO_DEPTH; int ret = FAIL; - int retval=-1; + int arg = i; + int retval = -1; + FILE_LOG(logDEBUG5) << "Sending Receiver Fifo Depth: " << arg; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - if (i ==-1) - FILE_LOG(logINFO) << "Getting Receiver Fifo Depth" << std::endl; - else - FILE_LOG(logINFO) << "Setting Receiver Fifo Depth to " << i << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &i, sizeof(i), &retval, sizeof(retval)); - disconnectData(); - } - if (ret==FAIL) + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(COULD_NOT_SET_FIFO_DEPTH)); + } else { + FILE_LOG(logDEBUG5) << "Receiver Fifo Depth: " << retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } } return retval; } @@ -5504,26 +5425,25 @@ int slsDetector::setReceiverFifoDepth(int i) { int slsDetector::setReceiverSilentMode(int i) { - int fnum=F_SET_RECEIVER_SILENT_MODE; + int fnum = F_SET_RECEIVER_SILENT_MODE; int ret = FAIL; - int retval=-1; + int arg = i; + int retval = -1; + FILE_LOG(logDEBUG5) << "Sending Receiver Silent Mode: " << arg; + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); + disconnectData(); - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - if (i ==-1) - FILE_LOG(logINFO) << "Getting Receiver Silent Mode" << std::endl; - else - FILE_LOG(logINFO) << "Setting Receiver Silent Mode to " << i << std::endl; -#endif - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, &i, sizeof(i), &retval, sizeof(retval)); - disconnectData(); - } - if (ret==FAIL) + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(RECEIVER_PARAMETER_NOT_SET)); - else + } else { + FILE_LOG(logDEBUG5) << "Receiver Data Streaming: " << retval; thisDetector->receiver_silentMode = retval; + if (ret == FORCE_UPDATE) + ret = updateReceiver(); + } } return thisDetector->receiver_silentMode; } @@ -5532,231 +5452,144 @@ int slsDetector::setReceiverSilentMode(int i) { int slsDetector::restreamStopFromReceiver() { - int fnum=F_RESTREAM_STOP_FROM_RECEIVER; + int fnum = F_RESTREAM_STOP_FROM_RECEIVER; int ret = FAIL; - char mess[MAX_STR_LENGTH] = ""; + FILE_LOG(logDEBUG5) << "Restream stop dummy from Receiver via zmq"; - if (thisDetector->receiverOnlineFlag==ONLINE_FLAG) { -#ifdef VERBOSE - FILE_LOG(logINFO) << "To Restream stop dummy from Receiver via zmq" << std::endl; -#endif + if (thisDetector->receiverOnlineFlag == ONLINE_FLAG && connectData() == OK) { + ret = thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0); + disconnectData(); - if (connectData() == OK) { - ret=thisReceiver->Client_Send(fnum, NULL, 0, NULL, 0, mess); - disconnectData(); - } - if (ret==FORCE_UPDATE) - ret=updateReceiver(); - else if (ret == FAIL) { + // handle ret + if (ret == FAIL) { setErrorMask((getErrorMask())|(RESTREAM_STOP_FROM_RECEIVER)); - FILE_LOG(logERROR) << " Could not restream stop dummy packet from receiver" << std::endl; - } + } else if (ret == FORCE_UPDATE) + ret = updateReceiver(); } - return ret; } - int slsDetector::setCTBPattern(std::string fname) { - uint64_t word; - - int addr=0; - - FILE *fd=fopen(fname.c_str(),"r"); - if (fd>0) { - while (fread(&word, sizeof(word), 1,fd)) { - setCTBWord(addr,word); - // std::cout << std::hex << addr << " " << word << std::dec << std::endl; + int addr = 0; + FILE *fd = fopen(fname.c_str(),"r"); + if (fd > 0) { + while (fread(&word, sizeof(word), 1, fd)) { + setCTBWord(addr, word); ++addr; } - fclose(fd); } else return -1; - - - - - return addr; - - } -uint64_t slsDetector::setCTBWord(int addr,uint64_t word) { +uint64_t slsDetector::setCTBWord(int addr, uint64_t word) { + int fnum = F_SET_CTB_PATTERN; + int ret = FAIL; + int mode = 0; // sets word + uint64_t args[3] = {(uint64_t) mode, (uint64_t)addr, word}; + uint64_t retval = -1; + FILE_LOG(logDEBUG5) << "Setting CTB word, addr: 0x" << std::hex << addr << ", word: 0x" << word << std::dec; - //uint64_t ret; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, args, sizeof(args), &retval, sizeof(retval)); + disconnectControl(); - int ret=FAIL; - uint64_t retval=-1; - int fnum=F_SET_CTB_PATTERN; - int mode=0; //sets word - - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&mode,sizeof(mode)); - controlSocket->SendDataOnly(&addr,sizeof(addr)); - controlSocket->SendDataOnly(&word,sizeof(word)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Set CTB word: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } - return retval; - - } int slsDetector::setCTBPatLoops(int level,int &start, int &stop, int &n) { + int fnum = F_SET_CTB_PATTERN; + int ret = FAIL; + int mode = 1; // sets loop + uint64_t args[5] = {(uint64_t) mode, (uint64_t)level, (uint64_t)start, (uint64_t)stop, (uint64_t)n}; + uint64_t retvals[3] = {0, 0, 0}; + FILE_LOG(logDEBUG5) << "Setting CTB Pat Loops, " + "level: " << level << ", start: " << start << ", stop: " << stop << ", n: " << n; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, args, sizeof(args), retvals, sizeof(retvals)); + disconnectControl(); - int retval[3], args[4]; - - args[0]=level; - args[1]=start; - args[2]=stop; - args[3]=n; - - - int ret=FAIL; - int fnum=F_SET_CTB_PATTERN; - int mode=1; //sets loop - - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&mode,sizeof(mode)); - controlSocket->SendDataOnly(&args,sizeof(args)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - start=retval[0]; - stop=retval[1]; - n=retval[2]; - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Set CTB Pat Loops: " << + retvals[0] << ", " << retvals[1] << ", " << retvals[2]; + start = retvals[0]; + stop = retvals[1]; + n = retvals[2]; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } - return ret; - - } int slsDetector::setCTBPatWaitAddr(int level, int addr) { + int fnum = F_SET_CTB_PATTERN; + int ret = FAIL; + int mode = 2; // sets loop + uint64_t args[3] = {(uint64_t) mode, (uint64_t)level, (uint64_t)addr}; + uint64_t retval = -1; + FILE_LOG(logDEBUG5) << "Setting CTB Wait Addr, " + "level: " << level << ", addr: 0x" << std::hex << addr << std::dec; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, args, sizeof(args), &retval, sizeof(retval)); + disconnectControl(); - - - int retval=-1; - - - int ret=FAIL; - int fnum=F_SET_CTB_PATTERN; - int mode=2; //sets loop - - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&mode,sizeof(mode)); - controlSocket->SendDataOnly(&level,sizeof(level)); - controlSocket->SendDataOnly(&addr,sizeof(addr)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Set CTB Wait Addr: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } - return retval; - - - } int slsDetector::setCTBPatWaitTime(int level, uint64_t t) { + int fnum = F_SET_CTB_PATTERN; + int ret = FAIL; + int mode = 3; // sets loop + uint64_t args[3] = {(uint64_t) mode, (uint64_t)level, t}; + uint64_t retval = -1; + FILE_LOG(logDEBUG5) << "Setting CTB Wait Time, level: " << level << ", t: " << t; + if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { + ret = thisDetectorControl->Client_Send(fnum, args, sizeof(args), &retval, sizeof(retval)); + disconnectControl(); - uint64_t retval=-1; - - int ret=FAIL; - // uint64_t retval=-1; - int fnum=F_SET_CTB_PATTERN; - int mode=3; //sets loop - - char mess[MAX_STR_LENGTH]=""; - -#ifdef VERBOSE - std::cout<<"Setting CTB word" <onlineFlag==ONLINE_FLAG) { - if (connectControl() == OK) { - controlSocket->SendDataOnly(&fnum,sizeof(fnum)); - controlSocket->SendDataOnly(&mode,sizeof(mode)); - controlSocket->SendDataOnly(&level,sizeof(level)); - controlSocket->SendDataOnly(&t,sizeof(t)); - controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); - if (ret!=FAIL) { - controlSocket->ReceiveDataOnly(&retval,sizeof(retval)); - } else { - controlSocket->ReceiveDataOnly(mess,sizeof(mess)); - FILE_LOG(logERROR) << "Detector returned error: " << mess << std::endl; - } - disconnectControl(); - if (ret==FORCE_UPDATE) - updateDetector(); + // handle ret + if (ret == FAIL) { + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + } else { + FILE_LOG(logDEBUG5) << "Set CTB Wait Time: " << retval; + if (ret == FORCE_UPDATE) + ret = updateDetector(); } } - return retval; - - } @@ -5767,16 +5600,23 @@ slsDetectorDefs::sls_detector_module* slsDetector::interpolateTrim( // only implemented for eiger currently (in terms of which dacs) if (thisDetector->myDetectorType != EIGER) { - printf("Interpolation of Trim values not implemented for this detector!\n"); + FILE_LOG(logERROR) << "Interpolation of Trim values not implemented for this detector!"; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); return NULL; } sls_detector_module* myMod = createModule(thisDetector->myDetectorType); - enum eiger_DacIndex{SVP,VTR,VRF,VRS,SVN,VTGSTV,VCMP_LL,VCMP_LR,CAL, - VCMP_RL,RXB_RB,RXB_LB,VCMP_RR,VCP,VCN,VIS}; + if (myMod == NULL) { + FILE_LOG(logERROR) << "Could not create module"; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + return NULL; + + } + enum eiger_DacIndex{SVP, VTR, VRF, VRS, SVN, VTGSTV, VCMP_LL, VCMP_LR, CAL, + VCMP_RL, RXB_RB, RXB_LB, VCMP_RR, VCP, VCN, VIS}; //Copy other dacs - int dacs_to_copy[] = {SVP,VTR,SVN,VTGSTV,RXB_RB,RXB_LB,VCN,VIS}; + int dacs_to_copy[] = {SVP, VTR, SVN, VTGSTV, RXB_RB, RXB_LB, VCN, VIS}; int num_dacs_to_copy = sizeof(dacs_to_copy) / sizeof(dacs_to_copy[0]); for (int i = 0; i < num_dacs_to_copy; ++i) { if (a->dacs[dacs_to_copy[i]] != b->dacs[dacs_to_copy[i]]) { @@ -5789,15 +5629,15 @@ slsDetectorDefs::sls_detector_module* slsDetector::interpolateTrim( //Copy irrelevant dacs (without failing): CAL if (a->dacs[CAL] != b->dacs[CAL]) { - printf("Warning: DAC CAL differs in both energies (%d, %d)! ", - a->dacs[CAL], b->dacs[CAL]); - printf("Taking first: %d\n", a->dacs[CAL]); + FILE_LOG(logWARNING) << "DAC CAL differs in both energies " + "(" << a->dacs[CAL] << "," << b->dacs[CAL] << ")!\n" + "Taking first: " << a->dacs[CAL]; } myMod->dacs[CAL] = a->dacs[CAL]; //Interpolate vrf, vcmp, vcp - int dacs_to_interpolate[] = {VRF,VCMP_LL,VCMP_LR,VCMP_RL,VCMP_RR,VCP, VRS}; + int dacs_to_interpolate[] = {VRF, VCMP_LL, VCMP_LR, VCMP_RL, VCMP_RR, VCP, VRS}; int num_dacs_to_interpolate = sizeof(dacs_to_interpolate) / sizeof(dacs_to_interpolate[0]); for (int i = 0; i < num_dacs_to_interpolate; ++i) { myMod->dacs[dacs_to_interpolate[i]] = linearInterpolation(energy, e1, e2, @@ -5813,257 +5653,229 @@ slsDetectorDefs::sls_detector_module* slsDetector::interpolateTrim( } - - slsDetectorDefs::sls_detector_module* slsDetector::readSettingsFile(std::string fname, sls_detector_module* myMod, int tb) { + FILE_LOG(logDEBUG5) << "Read settings file " << fname; - int nflag=0; - if (myMod==NULL) { - myMod=createModule(thisDetector->myDetectorType); - nflag=1; + // flag creating module to delete later + bool modCreated = false; + if (myMod == NULL) { + myMod = createModule(thisDetector->myDetectorType); + if (myMod == NULL) { + FILE_LOG(logERROR) << "Could not create module"; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + return NULL; + + } + modCreated = true; } - int id=0,i; - std::string names[100]; - std::string myfname; - std::string str; + std::vector names; + switch (thisDetector->myDetectorType) { + case GOTTHARD: + names.push_back("Vref"); + names.push_back("VcascN"); + names.push_back("VcascP"); + names.push_back("Vout"); + names.push_back("Vcasc"); + names.push_back("Vin"); + names.push_back("Vref_comp"); + names.push_back("Vib_test"); + break; + case EIGER: + break; + case JUNGFRAU: + names.push_back("VDAC0"); + names.push_back("VDAC1"); + names.push_back("VDAC2"); + names.push_back("VDAC3"); + names.push_back("VDAC4"); + names.push_back("VDAC5"); + names.push_back("VDAC6"); + names.push_back("VDAC7"); + names.push_back("VDAC8"); + names.push_back("VDAC9"); + names.push_back("VDAC10"); + names.push_back("VDAC11"); + names.push_back("VDAC12"); + names.push_back("VDAC13"); + names.push_back("VDAC14"); + names.push_back("VDAC15"); + break; + default: + FILE_LOG(logERROR) << "Unknown detector type - unknown format for settings file"; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + return NULL; + } + + + // open file std::ifstream infile; - std::ostringstream oss; - int iline=0; - std::string sargname; - int ival; - int idac=0; - - //ascii settings/trim file - switch (thisDetector->myDetectorType) { - case GOTTHARD: - names[id++]="Vref"; - names[id++]="VcascN"; - names[id++]="VcascP"; - names[id++]="Vout"; - names[id++]="Vcasc"; - names[id++]="Vin"; - names[id++]="Vref_comp"; - names[id++]="Vib_test"; - break; - case EIGER: - break; - case JUNGFRAU: - names[id++]="VDAC0"; - names[id++]="VDAC1"; - names[id++]="VDAC2"; - names[id++]="VDAC3"; - names[id++]="VDAC4"; - names[id++]="VDAC5"; - names[id++]="VDAC6"; - names[id++]="VDAC7"; - names[id++]="VDAC8"; - names[id++]="VDAC9"; - names[id++]="VDAC10"; - names[id++]="VDAC11"; - names[id++]="VDAC12"; - names[id++]="VDAC13"; - names[id++]="VDAC14"; - names[id++]="VDAC15"; - break; - default: - FILE_LOG(logERROR) << "Unknown detector type - unknown format for settings file" << std::endl; + if (thisDetector->myDetectorType == EIGER) + infile.open(fname.c_str(), std::ifstream::binary); + else + infile.open(fname.c_str(), std::ios_base::in); + if (!infile.is_open()) { + FILE_LOG(logERROR) << "Could not open settings file for reading: " << fname; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + if (modCreated) + deleteModule(myMod); return NULL; } -#ifdef VERBOSE - std::cout<< "reading settings file" << std::endl; -#endif - myfname=fname; -#ifdef VERBOSE - FILE_LOG(logINFO) << "file name is "<< myfname << std::endl; -#endif - - switch (thisDetector->myDetectorType) { - - case EIGER: - infile.open(myfname.c_str(),std::ifstream::binary); - if (infile.is_open()) { - infile.read((char*) myMod->dacs,sizeof(int)*(myMod->ndac)); - infile.read((char*)&myMod->iodelay,sizeof(myMod->iodelay)); - infile.read((char*)&myMod->tau,sizeof(myMod->tau)); -#ifdef VERBOSE - for(int i=0;indac;++i) - FILE_LOG(logINFO) << "dac " << i << ":" << myMod->dacs[i] << std::endl; - FILE_LOG(logINFO) << "iodelay:" << myMod->iodelay << std::endl; - FILE_LOG(logINFO) << "tau:" << myMod->tau << std::endl; -#endif - if (tb) { - infile.read((char*) myMod->chanregs,sizeof(int)*(myMod->nchan)); - if (infile.eof()) { - std::cout<settingsFile,fname.c_str()); - printf("Settings file loaded: %s\n",thisDetector->settingsFile); - return myMod; - - } - - break; - - case GOTTHARD: - case JUNGFRAU: - //---------------dacs--------------- - infile.open(myfname.c_str(), std::ios_base::in); - if (infile.is_open()) { - while(infile.good()) { - getline(infile,str); - ++iline; -#ifdef VERBOSE - std::cout<< str << std::endl; -#endif - std::istringstream ssstr(str); - ssstr >> sargname >> ival; - for (i=0;idacs[i]=ival; - ++idac; -#ifdef VERBOSE - std::cout<< sargname << " dac nr. " << idac << " is " << ival << std::endl; -#endif - break; + // eiger + if (thisDetector->myDetectorType == EIGER) { + bool allread = false; + infile.read((char*) myMod->dacs, sizeof(int) * (myMod->ndac)); + if (infile.good()) { + infile.read((char*)&myMod->iodelay, sizeof(myMod->iodelay)); + if(infile.good()) { + infile.read((char*)&myMod->tau, sizeof(myMod->tau)); + if (tb) { + if(infile.good()) { + infile.read((char*) myMod->chanregs, sizeof(int) * (myMod->nchan)); + if (infile) + allread = true; } - } + } else if (infile) + allread = true; + } - if (i < id) { -#ifdef VERBOSE - std::cout<< sargname << " dac nr. " << idac << " is " << ival << std::endl; -#endif - } else - FILE_LOG(logERROR) << "Unknown dac " << sargname << std::endl; - - infile.close(); - strcpy(thisDetector->settingsFile,fname.c_str()); - printf("Settings file loaded: %s\n",thisDetector->settingsFile); - return myMod; - } - - //---------------------------------- - break; - - default: - FILE_LOG(logERROR) << "Unknown detector type - don't know how to read file" << myfname << std::endl; - infile.close(); - deleteModule(myMod); - return NULL; - + if (!allread) { + FILE_LOG(logERROR) << "Could not load all values for settings for " << fname; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + if (modCreated) + deleteModule(myMod); + return NULL; + } + for(int i = 0; i < myMod->ndac; ++i) + FILE_LOG(logDEBUG5) << "dac " << i << ":" << myMod->dacs[i]; + FILE_LOG(logDEBUG5) << "iodelay:" << myMod->iodelay; + FILE_LOG(logDEBUG5) << "tau:" << myMod->tau; } - printf("Error: Could not open settings file %s\n", myfname.c_str()); - if (nflag) - deleteModule(myMod); - - return NULL; - - + // gotthard, jungfrau + else { + size_t idac = 0; + std::string str; + while(infile.good()) { + getline(infile,str); + FILE_LOG(logDEBUG5) << str; + std::string sargname; + int ival = 0; + std::istringstream ssstr(str); + ssstr >> sargname >> ival; + bool found = false; + for (size_t i = 0; i < names.size(); ++i) { + if (sargname == names[i]) { + myMod->dacs[i] = ival; + found = true; + FILE_LOG(logDEBUG5) << names[i] << "(" << i << "): " << ival; + ++idac; + } + } + if (!found) { + FILE_LOG(logERROR) << "Unknown dac " << sargname; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + if (modCreated) + deleteModule(myMod); + return NULL; + } + } + // not all read + if (idac != names.size()) { + FILE_LOG(logERROR) << "Could read only " << idac << " dacs. Expected " << names.size() << "dacs"; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); + if (modCreated) + deleteModule(myMod); + return NULL; + } + } + infile.close(); + strcpy(thisDetector->settingsFile, fname.c_str()); + FILE_LOG(logINFO) << "Settings file loaded: " << thisDetector->settingsFile; + return myMod; } int slsDetector::writeSettingsFile(std::string fname, sls_detector_module mod) { - std::ofstream outfile; + FILE_LOG(logDEBUG5) << "Write settings file " << fname; - std::string names[100]; - int id=0; + std::vector names; switch (thisDetector->myDetectorType) { case GOTTHARD: - names[id++]="Vref"; - names[id++]="VcascN"; - names[id++]="VcascP"; - names[id++]="Vout"; - names[id++]="Vcasc"; - names[id++]="Vin"; - names[id++]="Vref_comp"; - names[id++]="Vib_test"; + names.push_back("Vref"); + names.push_back("VcascN"); + names.push_back("VcascP"); + names.push_back("Vout"); + names.push_back("Vcasc"); + names.push_back("Vin"); + names.push_back("Vref_comp"); + names.push_back("Vib_test"); break; case EIGER: break; case JUNGFRAU: - names[id++]="VDAC0"; - names[id++]="VDAC1"; - names[id++]="VDAC2"; - names[id++]="VDAC3"; - names[id++]="VDAC4"; - names[id++]="VDAC5"; - names[id++]="VDAC6"; - names[id++]="VDAC7"; - names[id++]="VDAC8"; - names[id++]="VDAC9"; - names[id++]="VDAC10"; - names[id++]="VDAC11"; - names[id++]="VDAC12"; - names[id++]="VDAC13"; - names[id++]="VDAC14"; - names[id++]="VDAC15"; + names.push_back("VDAC0"); + names.push_back("VDAC1"); + names.push_back("VDAC2"); + names.push_back("VDAC3"); + names.push_back("VDAC4"); + names.push_back("VDAC5"); + names.push_back("VDAC6"); + names.push_back("VDAC7"); + names.push_back("VDAC8"); + names.push_back("VDAC9"); + names.push_back("VDAC10"); + names.push_back("VDAC11"); + names.push_back("VDAC12"); + names.push_back("VDAC13"); + names.push_back("VDAC14"); + names.push_back("VDAC15"); break; default: - FILE_LOG(logERROR) << "Unknown detector type - unknown format for settings file" << std::endl; + FILE_LOG(logERROR) << "Unknown detector type - unknown format for settings file"; + setErrorMask((getErrorMask())|(OTHER_ERROR_CODE)); return FAIL; } - int iv; - int idac; - - switch (thisDetector->myDetectorType) { - case EIGER: + // open file + std::ofstream outfile; + if (thisDetector->myDetectorType == EIGER) outfile.open(fname.c_str(), std::ofstream::binary); - if (outfile.is_open()) { - iv = 1150; -#ifdef VERBOSE - for(int i=0;i(&mod.iodelay), sizeof(mod.iodelay)); - outfile.write(reinterpret_cast(&mod.tau), sizeof(mod.tau)); - outfile.write((char*)mod.chanregs, sizeof(int)*(mod.nchan)); - - outfile.close(); - return slsDetectorDefs::OK; - } - - printf("Could not open Settings file %s\n", fname.c_str()); - return slsDetectorDefs::FAIL; - default: - - + else outfile.open(fname.c_str(), std::ios_base::out); - - if (outfile.is_open()) { - for (idac=0; idacmyDetectorType == EIGER) { + for(int i = 0; i < mod.ndac; ++i) + FILE_LOG(logINFO) << "dac " << i << ":" << mod.dacs[i]; + FILE_LOG(logINFO) << "iodelay: " << mod.iodelay; + FILE_LOG(logINFO) << "tau: " << mod.tau; + + outfile.write((char*)mod.dacs, sizeof(int) * (mod.ndac)); + outfile.write(reinterpret_cast(&mod.iodelay), sizeof(mod.iodelay)); + outfile.write(reinterpret_cast(&mod.tau), sizeof(mod.tau)); + outfile.write((char*)mod.chanregs, sizeof(int) * (mod.nchan)); + } + + // gotthard, jungfrau + else { + for (int i = 0; i < mod.ndac; ++i) { + FILE_LOG(logDEBUG5) << "dac " << i << ": " << mod.dacs[i]; + outfile << names[i] << " " << (int)mod.dacs[i] << std::endl; + } + } + + outfile.close(); + return OK; } - - - - diff --git a/slsDetectorSoftware/slsDetector/slsDetector.h b/slsDetectorSoftware/slsDetector/slsDetector.h index 530e0e791..b3b908fd5 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.h +++ b/slsDetectorSoftware/slsDetector/slsDetector.h @@ -11,6 +11,8 @@ #include "sls_detector_defs.h" #include "error_defs.h" +#include "logger.h" + #include "math.h" class multiSlsDetector; @@ -1261,7 +1263,7 @@ public: * @param retval is the array with the trimbits * @returns total number of channels for the detector */ - int getChanRegs(double* retval,bool fromDetector); + int getChanRegs(double* retval); /** * Configure Module (Eiger) @@ -1300,7 +1302,7 @@ public: * Prints receiver configuration * #param level print level */ - void printReceiverConfiguration(int level = logINFO); + void printReceiverConfiguration(TLogLevel level = logINFO); /** * Checks if receiver is online and set flag @@ -1486,12 +1488,6 @@ public: */ int getFramesCaughtByReceiver(); - /** - * Gets the number of frames caught by any one receiver (to avoid using threadpool) - * @returns number of frames caught by any one receiver (master receiver if exists) - */ - int getFramesCaughtByAnyReceiver(); - /** * Gets the current frame index of receiver * @returns current frame index of receiver @@ -1538,13 +1534,6 @@ public: */ int setReceiverStreamingTimer(int time_in_ms=500); - /** - * Enable data streaming to client - * @param enable 0 to disable, 1 to enable, -1 to get the value - * @returns data streaming to client enable - */ - int enableDataStreamingToClient(int enable=-1); - /** * Enable or disable streaming data from receiver to client * @param enable 0 to disable 1 to enable -1 to only get the value diff --git a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp index b28868d8c..673876488 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorCommand.cpp @@ -2723,7 +2723,7 @@ string slsDetectorCommand::cmdRateCorr(int narg, char *args[], int action, int d myDet->setOnline(ONLINE_FLAG, detPos); if (action==PUT_ACTION) { - sscanf(args[1],"%lld",&ival); + sscanf(args[1], "%ld",&ival); myDet->setRateCorrection(ival, detPos); } sprintf(answer,"%lld",myDet->getRateCorrection(detPos)); @@ -4908,7 +4908,8 @@ string slsDetectorCommand::cmdConfiguration(int narg, char *args[], int action, myDet->setReceiverOnline(ONLINE_FLAG, detPos); if (action==PUT_ACTION) return string("cannot put"); - return string(""+myDet->printReceiverConfiguration(detPos)); + myDet->printReceiverConfiguration(detPos); + return string(""); }else if (cmd=="parameters") { myDet->setReceiverOnline(ONLINE_FLAG, detPos); if (action==PUT_ACTION) { diff --git a/slsReceiverSoftware/include/slsReceiverImplementation.h b/slsReceiverSoftware/include/slsReceiverImplementation.h index fc39c27a9..82f415482 100644 --- a/slsReceiverSoftware/include/slsReceiverImplementation.h +++ b/slsReceiverSoftware/include/slsReceiverImplementation.h @@ -57,7 +57,7 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { * Get detector hostname * @return hostname (max of 1000 characters) */ - char *getDetectorHostname() const; + std::string getDetectorHostname() const; /* * Get flipped data across 'axis' @@ -82,13 +82,13 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { * Get File Name Prefix (without frame index, file index and extension (_d0_f000000000000_8.raw)) * @return file name prefix */ - char *getFileName() const; + std::string getFileName() const; /** * Get File Path * @return file path */ - char *getFilePath() const; + std::string getFilePath() const; /** * Get File Index @@ -164,7 +164,7 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { * Get Ehernet Interface * @ethernet interface. eg. eth0 or "" if listening to all */ - char *getEthernetInterface() const; + std::string getEthernetInterface() const; //***acquisition parameters*** @@ -288,13 +288,13 @@ class slsReceiverImplementation: private virtual slsDetectorDefs { * Get streaming source ip * @return streaming source ip */ - char *getStreamingSourceIP() const; + std::string getStreamingSourceIP() const; /** * Get additional json header * @return additional json header */ - char *getAdditionalJsonHeader() const; + std::string getAdditionalJsonHeader() const; /** (not saved in client shared memory) * Get UDP Socket Buffer Size diff --git a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h index f24da2dff..00d6df141 100644 --- a/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h +++ b/slsReceiverSoftware/include/slsReceiverTCPIPInterface.h @@ -115,6 +115,13 @@ class slsReceiverTCPIPInterface : private virtual slsDetectorDefs { /** function not implemented for specific detector */ void functionNotImplemented(); + /** mode not implemented for specific detector */ + void modeNotImplemented(std::string modename, int mode); + + /** validate and set error */ + template + void validate(T arg, T retval, std::string modename, bool hex); + /** Unrecognized Function */ int M_nofunc(); diff --git a/slsReceiverSoftware/src/slsReceiverImplementation.cpp b/slsReceiverSoftware/src/slsReceiverImplementation.cpp index 01fa3e584..35c6813fc 100644 --- a/slsReceiverSoftware/src/slsReceiverImplementation.cpp +++ b/slsReceiverSoftware/src/slsReceiverImplementation.cpp @@ -144,9 +144,9 @@ int slsReceiverImplementation::getDetectorPositionId() const{ return detID; } -char *slsReceiverImplementation::getDetectorHostname() const{ +std::string slsReceiverImplementation::getDetectorHostname() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - return detHostname; + return std::string(detHostname); } int slsReceiverImplementation::getFlippedData(int axis) const{ @@ -167,14 +167,14 @@ slsDetectorDefs::fileFormat slsReceiverImplementation::getFileFormat() const{ } -char *slsReceiverImplementation::getFileName() const{ +std::string slsReceiverImplementation::getFileName() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - return fileName; + return std::string(fileName); } -char *slsReceiverImplementation::getFilePath() const{ +std::string slsReceiverImplementation::getFilePath() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - return filePath; + return std::string(filePath); } uint64_t slsReceiverImplementation::getFileIndex() const{ @@ -270,9 +270,9 @@ uint32_t slsReceiverImplementation::getUDPPortNumber2() const{ return udpPortNum[1]; } -char *slsReceiverImplementation::getEthernetInterface() const{ +std::string slsReceiverImplementation::getEthernetInterface() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - return eth; + return std::string(eth); } @@ -367,14 +367,14 @@ uint32_t slsReceiverImplementation::getStreamingPort() const{ return streamingPort; } -char *slsReceiverImplementation::getStreamingSourceIP() const{ +std::string slsReceiverImplementation::getStreamingSourceIP() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - return streamingSrcIP; + return std::string(streamingSrcIP); } -char *slsReceiverImplementation::getAdditionalJsonHeader() const{ +std::string slsReceiverImplementation::getAdditionalJsonHeader() const{ FILE_LOG(logDEBUG) << __AT__ << " starting"; - return additionalJsonHeader; + return std::string(additionalJsonHeader); } uint32_t slsReceiverImplementation::getUDPSocketBufferSize() const { diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 655c58094..92645edb0 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -229,7 +229,7 @@ int slsReceiverTCPIPInterface::function_table(){ flist[F_RECEIVER_DEACTIVATED_PADDING_ENABLE] = &slsReceiverTCPIPInterface::set_deactivated_receiver_padding_enable; for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { - FILE_LOG(logDEBUG1) << "function fnum: " << i << " (" << + FILE_LOG(logDEBUG5) << "function fnum: " << i << " (" << getFunctionNameFromEnum((enum detFuncs)i) << ") located at " << flist[i]; } @@ -277,19 +277,37 @@ void slsReceiverTCPIPInterface::functionNotImplemented() { FILE_LOG(logERROR) << mess; } +void slsReceiverTCPIPInterface::modeNotImplemented(std::string modename, int mode) { + ret = FAIL; + sprintf(mess, "%s (%d) is not implemented for this detector\n", modename.c_str(), mode); + FILE_LOG(logERROR) << mess; +} + +template +void slsReceiverTCPIPInterface::validate(T arg, T retval, std::string modename, bool hex) { + if (ret == OK && arg != -1 && retval != arg) { + ret = FAIL; + if (hex) + sprintf(mess, "Could not %s. Set 0x%x, but read 0x%x\n", + modename.c_str(), arg, retval); + else + sprintf(mess, "Could not %s. Set %d, but read %d\n", + modename.c_str(), arg, retval); + FILE_LOG(logERROR) << mess; + } +} int slsReceiverTCPIPInterface::M_nofunc(){ ret = FAIL; memset(mess, 0, sizeof(mess)); - int n = 0; // to receive any arguments + int n = 1; while (n > 0) - n = mySock->ReceiveDataOnly(mess,MAX_STR_LENGTH); + n = mySock->ReceiveDataOnly(mess, MAX_STR_LENGTH); - strcpy(mess,"Unrecognized Function. Please do not proceed.\n"); + sprintf(mess,"Unrecognized Function enum %d. Please do not proceed.\n", fnum); FILE_LOG(logERROR) << mess; - return interface->Server_SendResult(false, ret, NULL, 0, mess); } @@ -297,7 +315,7 @@ int slsReceiverTCPIPInterface::M_nofunc(){ int slsReceiverTCPIPInterface::exec_command() { - ret = FAIL; + ret = OK; memset(mess, 0, sizeof(mess)); char cmd[MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {0}; @@ -305,6 +323,7 @@ int slsReceiverTCPIPInterface::exec_command() { // get args, return if socket crashed if (interface->Server_ReceiveArg(ret, mess, cmd, MAX_STR_LENGTH) == FAIL) return FAIL; + FILE_LOG(logINFO) << "Executing command (" << cmd << ")"; // verify if receiver is unlocked if (interface->Server_VerifyLock(ret, mess, lockStatus) == OK) { @@ -324,18 +343,18 @@ int slsReceiverTCPIPInterface::exec_command() { } strncpy(retval, sresult.c_str(), MAX_STR_LENGTH); ret = OK; + FILE_LOG(logINFO) << "Result of cmd (" << cmd << "):\n" << retval; } } - return interface->Server_SendResult(false, ret, retval, MAX_STR_LENGTH, mess); } int slsReceiverTCPIPInterface::exit_server() { - cprintf(RED,"Closing server\n"); - memset(mess, 0, sizeof(mess)); + cprintf(BG_RED, "Closing server\n"); ret = OK; + memset(mess, 0, sizeof(mess)); interface->Server_SendResult(false, ret, NULL, 0); return GOODBYE; } @@ -421,7 +440,6 @@ int slsReceiverTCPIPInterface::set_port() { mySock = mySocket; interface->SetSocket(mySock); } - return ret; } @@ -446,86 +464,87 @@ int slsReceiverTCPIPInterface::update_client() { int slsReceiverTCPIPInterface::send_update() { - int ind = -1; - char path[MAX_STR_LENGTH] = {0}; int n = 0; + int i32 = -1; + char cstring[MAX_STR_LENGTH] = {0}; + n += mySock->SendDataOnly(mySock->lastClientIP,sizeof(mySock->lastClientIP)); // filepath - path = receiver->getFilePath(); - n += mySock->SendDataOnly(path, sizeof(path)); + strcpy(cstring, receiver->getFilePath().c_str()); + n += mySock->SendDataOnly(cstring, sizeof(cstring)); // filename - path = receiver->getFileName(); - n += mySock->SendDataOnly(path, sizeof(path)); + strcpy(cstring, receiver->getFileName().c_str()); + n += mySock->SendDataOnly(cstring, sizeof(cstring)); // index - ind=receiver->getFileIndex(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=receiver->getFileIndex(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); //file format - ind=(int)receiver->getFileFormat(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getFileFormat(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); //frames per file - ind=(int)receiver->getFramesPerFile(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getFramesPerFile(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); //frame discard policy - ind=(int)receiver->getFrameDiscardPolicy(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getFrameDiscardPolicy(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); //frame padding - ind=(int)receiver->getFramePaddingEnable(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getFramePaddingEnable(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); // file write enable - ind=(int)receiver->getFileWriteEnable(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getFileWriteEnable(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); // file overwrite enable - ind=(int)receiver->getOverwriteEnable(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getOverwriteEnable(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); // gap pixels - ind=(int)receiver->getGapPixelsEnable(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getGapPixelsEnable(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); // streaming frequency - ind=(int)receiver->getStreamingFrequency(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getStreamingFrequency(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); // streaming port - ind=(int)receiver->getStreamingPort(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getStreamingPort(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); // streaming source ip - path = receiver->getStreamingSourceIP(); - n += mySock->SendDataOnly(path, sizeof(path)); + strcpy(cstring, receiver->getStreamingSourceIP().c_str()); + n += mySock->SendDataOnly(cstring, sizeof(cstring)); // additional json header - path = receiver->getAdditionalJsonHeader(); - n += mySock->SendDataOnly(path, sizeof(path)); + strcpy(cstring, receiver->getAdditionalJsonHeader().c_str()); + n += mySock->SendDataOnly(cstring, sizeof(cstring)); // data streaming enable - ind=(int)receiver->getDataStreamEnable(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getDataStreamEnable(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); // activate - ind=(int)receiver->getActivate(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getActivate(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); // deactivated padding enable - ind=(int)receiver->getDeactivatedPadding(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getDeactivatedPadding(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); // silent mode - ind=(int)receiver->getSilentMode(); - n += mySock->SendDataOnly(&ind, sizeof(ind)); + i32=(int)receiver->getSilentMode(); + n += mySock->SendDataOnly(&i32, sizeof(i32)); if (!lockStatus) - strcpy(mySock->lastClientIP,mySock->thisClientIP); + strcpy(mySock->lastClientIP, mySock->thisClientIP); return OK; } @@ -542,23 +561,24 @@ int slsReceiverTCPIPInterface::get_id(){ int slsReceiverTCPIPInterface::set_detector_type(){ + ret = OK; memset(mess, 0, sizeof(mess)); - detectorType dr = GENERIC; + detectorType arg = GENERIC; detectorType retval = GENERIC; // get args, return if socket crashed - if (interface->Server_ReceiveArg(ret, mess, &dr, sizeof(dr)) == FAIL) + if (interface->Server_ReceiveArg(ret, mess, &arg, sizeof(arg)) == FAIL) return FAIL; // set - if (dr >= 0) { + if (arg >= 0) { // if object exists, verify unlocked and idle, else only verify lock (connecting first time) if (receiver == NULL) interface->Server_VerifyLock(ret, mess, lockStatus); else interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum); if (ret == OK) { - switch(dr) { + switch(arg) { case GOTTHARD: case EIGER: case JUNGFRAUCTB: @@ -566,7 +586,7 @@ int slsReceiverTCPIPInterface::set_detector_type(){ break; default: ret = FAIL; - sprintf(mess,"Unknown detector type: %d\n", dr); + sprintf(mess,"Unknown detector type: %d\n", arg); FILE_LOG(logERROR) << mess; break; } @@ -582,25 +602,27 @@ int slsReceiverTCPIPInterface::set_detector_type(){ if(rawDataModifyReadyCallBack) receiver->registerCallBackRawDataModifyReady(rawDataModifyReadyCallBack,pRawDataReady); } - myDetectorType = dr; + myDetectorType = arg; ret = receiver->setDetectorType(myDetectorType); retval = myDetectorType; // client has started updating receiver, update ip if (!lockStatus) - strcpy(mySock->lastClientIP,mySock->thisClientIP); + strcpy(mySock->lastClientIP, mySock->thisClientIP); } } } //get retval = myDetectorType; + validate((int)arg, (int)retval, std::string("set detector type"), 0); return interface->Server_SendResult(false, ret, &retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::set_detector_hostname() { + ret = OK; memset(mess, 0, sizeof(mess)); char hostname[MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {0}; @@ -618,8 +640,9 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { receiver->setDetectorHostname(hostname); } // get - retval = receiver->getDetectorHostname(); - if (strlen(retval)) { + std::string s = receiver->getDetectorHostname(); + strcpy(retval, s.c_str()); + if (s.length()) { ret = FAIL; sprintf(mess, "hostname not set\n"); FILE_LOG(logERROR) << mess; @@ -634,25 +657,29 @@ int slsReceiverTCPIPInterface::set_detector_hostname() { int slsReceiverTCPIPInterface::set_roi() { ret = OK; memset(mess, 0, sizeof(mess)); - int nroi = 0; + int narg = -1; + std::vector arg; // receive arguments - if (mySock->ReceiveDataOnly(&nroi,sizeof(nroi)) < 0 ) + if (mySock->ReceiveDataOnly(&narg,sizeof(narg)) < 0 ) return interface->Server_SocketCrash(); - - std::vector roiLimits; - int iloop = 0; - for (iloop = 0; iloop < nroi; iloop++) { + for (int iloop = 0; iloop < narg; ++iloop) { ROI temp; - if ( mySock->ReceiveDataOnly(&temp.xmin,sizeof(int)) < 0 ) + if ( mySock->ReceiveDataOnly(&temp.xmin, sizeof(int)) < 0 ) return interface->Server_SocketCrash(); - if ( mySock->ReceiveDataOnly(&temp.xmax,sizeof(int)) < 0 ) + if ( mySock->ReceiveDataOnly(&temp.xmax, sizeof(int)) < 0 ) return interface->Server_SocketCrash(); - if ( mySock->ReceiveDataOnly(&temp.ymin,sizeof(int)) < 0 ) + if ( mySock->ReceiveDataOnly(&temp.ymin, sizeof(int)) < 0 ) return interface->Server_SocketCrash(); - if ( mySock->ReceiveDataOnly(&temp.ymax,sizeof(int)) < 0 ) + if ( mySock->ReceiveDataOnly(&temp.ymax, sizeof(int)) < 0 ) return interface->Server_SocketCrash(); - roiLimits.push_back(temp); + arg.push_back(temp); + } + FILE_LOG(logDEBUG5) << "Set ROI narg: " << narg; + for (int iloop = 0; iloop < narg; ++iloop) { + FILE_LOG(logDEBUG5) << "(" << arg[iloop].xmin << ", " << + arg[iloop].xmax << ", " << arg[iloop].ymin << ", " << + arg[iloop].ymax << ")"; } // only for gotthard @@ -666,19 +693,16 @@ int slsReceiverTCPIPInterface::set_roi() { // only set // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) - ret = receiver->setROI(roiLimits); + ret = receiver->setROI(arg); } - - interface->Server_SendResult(true, ret, NULL, 0, mess); - - roiLimits.clear(); - - return ret; + arg.clear(); + return interface->Server_SendResult(true, ret, NULL, 0, mess); } int slsReceiverTCPIPInterface::setup_udp(){ + ret = OK; memset(mess, 0, sizeof(mess)); char args[3][MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {0}; @@ -737,13 +761,13 @@ int slsReceiverTCPIPInterface::setup_udp(){ } } } - return interface->Server_SendResult(true, ret, retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::set_timer() { + ret = OK; memset(mess, 0, sizeof(mess)); int64_t index[2] = {-1, -1}; int64_t retval = -1; @@ -754,8 +778,7 @@ int slsReceiverTCPIPInterface::set_timer() { // base object not null if (ret == OK) { - FILE_LOG(logDEBUG5, ("Setting timer index %d to %lld ns\n", index[0], index[1])); - char timername[100] = {0}; + FILE_LOG(logDEBUG5) << "Setting timer index " << index[0] << " to " << index[1]; // set if (index[1] >= 0) { @@ -763,42 +786,32 @@ int slsReceiverTCPIPInterface::set_timer() { if (interface->Server_VerifyLock(ret, mess, lockStatus) == OK) { switch (index[0]) { case ACQUISITION_TIME: - strcpy(timername, "exptime"); - ret = receiver->setAcquisitionTime(index[1]); + ret = receiver->setAcquisitionTime(index[1]); break; case FRAME_PERIOD: - strcpy(timername, "period"); ret = receiver->setAcquisitionPeriod(index[1]); break; case FRAME_NUMBER: case CYCLES_NUMBER: case STORAGE_CELL_NUMBER: - strcpy(timername, "frames_cycles_storagecells"); receiver->setNumberOfFrames(index[1]); break; case SUBFRAME_ACQUISITION_TIME: - strcpy(timername, "subexptime"); receiver->setSubExpTime(index[1]); break; case SUBFRAME_DEADTIME: - strcpy(timername, "subdeadtime"); receiver->setSubPeriod(index[1] + receiver->getSubExpTime()); break; case SAMPLES_JCTB: - strcpy(timername, "samples"); if (myDetectorType != JUNGFRAUCTB) { - ret = FAIL; - sprintf(mess,"This timer mode (%lld) does not exist for this receiver type\n", (long long int)index[0]); - FILE_LOG(logERROR) << "Warning: " << mess; + modeNotImplemented("(Samples) Timer index", (int)index[0]); break; } receiver->setNumberofSamples(index[1]); break; default: - strcpy(timername, "unknown"); - ret = FAIL; - sprintf(mess,"This timer mode (%lld) does not exist for receiver\n", (long long int)index[0]); - FILE_LOG(logERROR) << mess; + modeNotImplemented("Timer index", (int)index[0]); + break; } } } @@ -831,18 +844,11 @@ int slsReceiverTCPIPInterface::set_timer() { retval=receiver->getNumberofSamples(); break; default: - ret = FAIL; - sprintf(mess,"This timer mode (%lld) does not exist for receiver\n", (long long int)index[0]); - FILE_LOG(logERROR) << mess; + modeNotImplemented("Timer index", (int)index[0]); + break; } - - // check - if (ret == OK && index[1] >= 0 && retval != index[1]) { - ret = FAIL; - strcpy(mess,"Could not set timer %s\n", timername); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << slsDetectorDefs::getTimerType((timerIndex)(index[0])) << ":" << retval; + validate((int)index[1], (int)retval, std::string("set timer"), 0); + FILE_LOG(logDEBUG5) << slsDetectorDefs::getTimerType((timerIndex)(index[0])) << ":" << retval; } return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } @@ -850,6 +856,7 @@ int slsReceiverTCPIPInterface::set_timer() { int slsReceiverTCPIPInterface::set_dynamic_range() { + ret = OK; memset(mess, 0, sizeof(mess)); int dr = -1; int retval = -1; @@ -864,6 +871,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { if (dr >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting dynamic range: " << dr; bool exists = false; switch (dr) { case 16: @@ -880,9 +888,7 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } // invalid dr if (!exists) { - ret = FAIL; - sprintf(mess,"This dynamic range %d does not exist for this detector\n",dr); - FILE_LOG(logERROR) << mess; + modeNotImplemented("Dynamic range", dr); } // valid dr else { @@ -896,20 +902,16 @@ int slsReceiverTCPIPInterface::set_dynamic_range() { } // get retval = receiver->getDynamicRange(); - if(dr > 0 && retval != dr) { - ret = FAIL; - strcpy(mess, "Could not set dynamic range\n"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "dynamic range: " << retval; + validate(dr, retval, std::string("set dynamic range"), 0); + FILE_LOG(logDEBUG5) << "dynamic range: " << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } -int slsReceiverTCPIPInterface::set_streaming_frequency(){ +int slsReceiverTCPIPInterface::set_streaming_frequency() { + ret = OK; memset(mess, 0, sizeof(mess)); int index = -1; int retval = -1; @@ -924,6 +926,7 @@ int slsReceiverTCPIPInterface::set_streaming_frequency(){ if (index >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting streaming frequency: " << index; ret = receiver->setStreamingFrequency(index); if(ret == FAIL) { strcpy(mess, "Could not allocate memory for listening fifo\n"); @@ -932,15 +935,9 @@ int slsReceiverTCPIPInterface::set_streaming_frequency(){ } } // get - retval=receiver->getStreamingFrequency(); - // check retval for failure - if(ret == OK && index >= 0 && retval != index){ - ret = FAIL; - strcpy(mess,"Could not set streaming frequency"); - FILE_LOG(logERROR) << mess; - } + retval = receiver->getStreamingFrequency(); + validate(index, retval, std::string("set streaming frequency"), 0); } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } @@ -954,15 +951,18 @@ int slsReceiverTCPIPInterface::get_status(){ // no arg, check receiver is null interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver); - if (ret == OK) + if (ret == OK) { + FILE_LOG(logDEBUG5) << "Getting Status"; retval = receiver->getStatus(); - + FILE_LOG(logDEBUG5) << "Status:" << runStatusType(retval); + } return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::start_receiver(){ + ret = OK; memset(mess, 0, sizeof(mess)); // no arg, and check receiver is null @@ -980,20 +980,21 @@ int slsReceiverTCPIPInterface::start_receiver(){ sprintf(mess,"Cannot start Receiver as it is in %s state\n",runStatusType(s).c_str()); FILE_LOG(logERROR) << mess; }else { - ret=receiver->startReceiver(mess); + FILE_LOG(logDEBUG5) << "Starting Reciever"; + ret = receiver->startReceiver(mess); if (ret == FAIL) { FILE_LOG(logERROR) << mess; } } } } - return interface->Server_SendResult(true, ret, NULL, 0, mess); } int slsReceiverTCPIPInterface::stop_receiver(){ + ret = OK; memset(mess, 0, sizeof(mess)); // no arg, and check receiver is null @@ -1004,8 +1005,10 @@ int slsReceiverTCPIPInterface::stop_receiver(){ // only set // verify if receiver is unlocked if (interface->Server_VerifyLock(ret, mess, lockStatus) == OK) { - if(receiver->getStatus() != IDLE) + if(receiver->getStatus() != IDLE) { + FILE_LOG(logDEBUG5) << "Stopping Reciever"; receiver->stopReceiver(); + } enum runStatus s = receiver->getStatus(); if (s == IDLE) ret = OK; @@ -1016,16 +1019,13 @@ int slsReceiverTCPIPInterface::stop_receiver(){ } } } - return interface->Server_SendResult(true, ret, NULL, 0, mess); } - - - int slsReceiverTCPIPInterface::set_file_dir() { + ret = OK; memset(mess, 0, sizeof(mess)); char fPath[MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {0}; @@ -1038,24 +1038,26 @@ int slsReceiverTCPIPInterface::set_file_dir() { if (ret == OK) { // set if (strlen(fPath)) { + FILE_LOG(logDEBUG5) << "Setting file path: " << fPath; receiver->setFilePath(fPath); } // get - retval = receiver->getFilePath(); - if ((!strlen(retval)) || (strlen(fPath) && strcasecmp(fPath, retval))) { + std::string s = receiver->getFilePath(); + strcpy(retval, s.c_str()); + if ((s.length()) || (strlen(fPath) && strcasecmp(fPath, retval))) { ret = FAIL; strcpy(mess,"receiver file path does not exist\n"); FILE_LOG(logERROR) << mess; } else - FILE_LOG(logDEBUG1) << "file path:" << retval; + FILE_LOG(logDEBUG5) << "file path:" << retval; } - return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); } int slsReceiverTCPIPInterface::set_file_name() { + ret = OK; memset(mess, 0, sizeof(mess)); char fName[MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {0}; @@ -1068,24 +1070,26 @@ int slsReceiverTCPIPInterface::set_file_name() { if (ret == OK) { // set if (strlen(fName)) { + FILE_LOG(logDEBUG5) << "Setting file name: " << fName; receiver->setFileName(fName); } // get - retval = receiver->getFileName(); - if (strlen(retval)) { + std::string s = receiver->getFileName(); + strcpy(retval, s.c_str()); + if (s.length()) { ret = FAIL; strcpy(mess, "file name is empty\n"); FILE_LOG(logERROR) << mess; } else - FILE_LOG(logDEBUG1) << "file name:" << retval; + FILE_LOG(logDEBUG5) << "file name:" << retval; } - return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); } int slsReceiverTCPIPInterface::set_file_index() { + ret = OK; memset(mess, 0, sizeof(mess)); int index = -1; int retval = -1; @@ -1100,58 +1104,58 @@ int slsReceiverTCPIPInterface::set_file_index() { if (index >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting file index: " << index; receiver->setFileIndex(index); } } // get retval=receiver->getFileIndex(); - if(index >= 0 && retval != index) { - ret = FAIL; - strcpy(mess, "Could not set file index\n"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "file index:" << retval; + validate(index, retval, std::string("set file index"), 0); + FILE_LOG(logDEBUG5) << "file index:" << retval; } - return interface->Server_SendResult(true, ret, &retval,sizeof(retval), mess); } - - - int slsReceiverTCPIPInterface::get_frame_index(){ + ret = OK; memset(mess, 0, sizeof(mess)); int retval = -1; // no arg, check receiver is null interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver); - if (ret == OK) - retval=receiver->getAcquisitionIndex(); - + if (ret == OK) { + FILE_LOG(logDEBUG5) << "Getting frame index"; + retval = receiver->getAcquisitionIndex(); + FILE_LOG(logDEBUG5) << "frame index:" << retval; + } return interface->Server_SendResult(true, ret, &retval,sizeof(retval), mess); } int slsReceiverTCPIPInterface::get_frames_caught(){ + ret = OK; memset(mess, 0, sizeof(mess)); int retval = -1; // no arg, check receiver is null interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver); - if (ret == OK) - retval=receiver->getTotalFramesCaught(); - + if (ret == OK) { + FILE_LOG(logDEBUG5) << "Getting frames caught"; + retval = receiver->getTotalFramesCaught(); + FILE_LOG(logDEBUG5) << "frames caught:" << retval; + } return interface->Server_SendResult(true, ret, &retval,sizeof(retval), mess); } int slsReceiverTCPIPInterface::reset_frames_caught(){ + ret = OK; memset(mess, 0, sizeof(mess)); // no arg, and check receiver is null @@ -1162,16 +1166,17 @@ int slsReceiverTCPIPInterface::reset_frames_caught(){ // only set // verify if receiver is unlocked if (interface->Server_VerifyLock(ret, mess, lockStatus) == OK) { + FILE_LOG(logDEBUG5) << "Reset frames caught"; receiver->resetAcquisitionCount(); } } - return interface->Server_SendResult(true, ret, NULL, 0, mess); } int slsReceiverTCPIPInterface::enable_file_write(){ + ret = OK; memset(mess, 0, sizeof(mess)); int enable = -1; int retval = -1; @@ -1186,27 +1191,22 @@ int slsReceiverTCPIPInterface::enable_file_write(){ if (enable >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting File write enable:" << enable; receiver->setFileWriteEnable(enable); } } // get - retval=receiver->getFileWriteEnable(); - if(enable >= 0 && enable != retval) { - ret=FAIL; - strcpy(mess,"Could not set file write enable"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "file write enable:" << retval; + retval = receiver->getFileWriteEnable(); + validate(enable, retval, std::string("set file write enable"), 0); + FILE_LOG(logDEBUG5) << "file write enable:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - - int slsReceiverTCPIPInterface::enable_overwrite() { + ret = OK; memset(mess, 0, sizeof(mess)); int index = -1; int retval = -1; @@ -1221,25 +1221,22 @@ int slsReceiverTCPIPInterface::enable_overwrite() { if (index >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting File overwrite enable:" << index; receiver->setOverwriteEnable(index); } } // get - retval=receiver->getOverwriteEnable(); - if(index >=0 && retval != index) { - ret = FAIL; - strcpy(mess,"Could not set file over write enable\n"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "file overwrite enable:" << retval; + retval = receiver->getOverwriteEnable(); + validate(index, retval, std::string("set file overwrite enable"), 0); + FILE_LOG(logDEBUG5) << "file overwrite enable:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::enable_tengiga() { + ret = OK; memset(mess, 0, sizeof(mess)); int val = -1; int retval = -1; @@ -1257,26 +1254,22 @@ int slsReceiverTCPIPInterface::enable_tengiga() { if (val >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting 10GbE:" << val; ret = receiver->setTenGigaEnable(val); } } // get - retval=receiver->getTenGigaEnable(); - if((val >= 0) && (val != retval)) { - ret = FAIL; - strcpy(mess,"Could not set ten giga enable"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "10Gbe:" << retval; + retval = receiver->getTenGigaEnable(); + validate(val, retval, std::string("set 10GbE"), 0); + FILE_LOG(logDEBUG5) << "10Gbe:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - int slsReceiverTCPIPInterface::set_fifo_depth() { + ret = OK; memset(mess, 0, sizeof(mess)); int value = -1; int retval = -1; @@ -1291,6 +1284,7 @@ int slsReceiverTCPIPInterface::set_fifo_depth() { if (value >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting fifo depth:" << value; ret = receiver->setFifoDepth(value); if (ret == FAIL) { strcpy(mess,"Could not set fifo depth"); @@ -1300,20 +1294,16 @@ int slsReceiverTCPIPInterface::set_fifo_depth() { } // get retval = receiver->getFifoDepth(); - if(value >= 0 && retval != value) { - ret = FAIL; - strcpy(mess, "Could not set fifo depth\n"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "fifo depth:" << retval; + validate(value, retval, std::string("set fifo depth"), 0); + FILE_LOG(logDEBUG5) << "fifo depth:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::set_activate() { + ret = OK; memset(mess, 0, sizeof(mess)); int enable = -1; int retval = -1; @@ -1331,25 +1321,22 @@ int slsReceiverTCPIPInterface::set_activate() { if (enable >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting activate:" << enable; receiver->setActivate(enable > 0 ? true : false); } } // get retval = (int)receiver->getActivate(); - if(enable >= 0 && retval != enable){ - ret = FAIL; - sprintf(mess,"Could not set activate to %d, returned %d\n",enable,retval); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "Activate: " << retval; + validate(enable, retval, std::string("set activate"), 0); + FILE_LOG(logDEBUG5) << "Activate: " << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::set_data_stream_enable(){ + ret = OK; memset(mess, 0, sizeof(mess)); int index = -1; int retval = -1; @@ -1364,25 +1351,22 @@ int slsReceiverTCPIPInterface::set_data_stream_enable(){ if (index >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting data stream enable:" << index; ret = receiver->setDataStreamEnable(index); } } // get retval = receiver->getDataStreamEnable(); - if(index >= 0 && retval != index){ - ret = FAIL; - strcpy(mess,"Could not set data stream enable"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "data streaming enable:" << retval; + validate(index, retval, std::string("set data stream enable"), 0); + FILE_LOG(logDEBUG5) << "data streaming enable:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::set_streaming_timer(){ + ret = OK; memset(mess, 0, sizeof(mess)); int index = -1; int retval = -1; @@ -1397,25 +1381,22 @@ int slsReceiverTCPIPInterface::set_streaming_timer(){ if (index >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting streaming timer:" << index; receiver->setStreamingTimer(index); } } // get retval=receiver->getStreamingTimer(); - if(index >= 0 && retval != index){ - ret = FAIL; - strcpy(mess,"Could not set datastream timer"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "Streaming timer:" << retval; + validate(index, retval, std::string("set data stream timer"), 0); + FILE_LOG(logDEBUG5) << "Streaming timer:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::set_flipped_data(){ + ret = OK; memset(mess, 0, sizeof(mess)); int args[2] = {0,-1}; int retval = -1; @@ -1433,26 +1414,22 @@ int slsReceiverTCPIPInterface::set_flipped_data(){ if (args[1] >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting flipped data:" << args[1]; receiver->setFlippedData(args[0],args[1]); } } // get retval=receiver->getFlippedData(args[0]); - if (args[1] > -1 && retval != args[1]) { - ret = FAIL; - strcpy(mess, "Could not set flipped data\n"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "Flipped Data:" << retval; + validate(args[1], retval, std::string("set flipped data"), 0); + FILE_LOG(logDEBUG5) << "Flipped Data:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - int slsReceiverTCPIPInterface::set_file_format() { + ret = OK; memset(mess, 0, sizeof(mess)); fileFormat retval = GET_FILE_FORMAT; fileFormat f = GET_FILE_FORMAT; @@ -1467,26 +1444,22 @@ int slsReceiverTCPIPInterface::set_file_format() { if (f >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting file format:" << f; receiver->setFileFormat(f); } } // get retval = receiver->getFileFormat(); - if(f >= 0 && retval != f){ - ret = FAIL; - sprintf(mess,"Could not set file format to %s, returned %s\n", - getFileFormatType(f).c_str(),getFileFormatType(retval).c_str()); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "File Format: " << retval; + validate(f, retval, std::string("set file format"), 0); + FILE_LOG(logDEBUG5) << "File Format: " << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::set_detector_posid() { + ret = OK; memset(mess, 0, sizeof(mess)); int arg = -1; int retval = -1; @@ -1501,28 +1474,22 @@ int slsReceiverTCPIPInterface::set_detector_posid() { if (arg >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting detector position id:" << arg; receiver->setDetectorPositionId(arg); } } // get - retval=receiver->getDetectorPositionId(); - if (arg >= 0 && retval != arg) { - ret = FAIL; - strcpy(mess,"Could not set detector position id"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "Position Id:" << retval; + retval = receiver->getDetectorPositionId(); + validate(arg, retval, std::string("set detector position id"), 0); + FILE_LOG(logDEBUG5) << "Position Id:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - - - int slsReceiverTCPIPInterface::set_multi_detector_size() { + ret = OK; memset(mess, 0, sizeof(mess)); int arg[2] = {-1, -1}; int retval = -1; @@ -1537,6 +1504,7 @@ int slsReceiverTCPIPInterface::set_multi_detector_size() { if((arg[0] > 0) && (arg[1] > 0)) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting multi detector size:" << arg[0] << "," << arg[1]; receiver->setMultiDetectorSize(arg); } } @@ -1548,16 +1516,15 @@ int slsReceiverTCPIPInterface::set_multi_detector_size() { else retval *= temp[i]; } - FILE_LOG(logDEBUG1) << "Multi Detector Size:" << retval; + FILE_LOG(logDEBUG5) << "Multi Detector Size:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - int slsReceiverTCPIPInterface::set_streaming_port() { + ret = OK; memset(mess, 0, sizeof(mess)); int port = -1; int retval = -1; @@ -1572,22 +1539,22 @@ int slsReceiverTCPIPInterface::set_streaming_port() { if (port >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting streaming port:" << port; receiver->setStreamingPort(port); } } // get - retval=receiver->getStreamingPort(); - FILE_LOG(logDEBUG1) << "streaming port:" << retval; + retval = receiver->getStreamingPort(); + validate(port, retval, std::string("set streaming port"), 0); + FILE_LOG(logDEBUG5) << "streaming port:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - - int slsReceiverTCPIPInterface::set_streaming_source_ip() { + ret = OK; memset(mess, 0, sizeof(mess)); char arg[MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {0}; @@ -1601,23 +1568,20 @@ int slsReceiverTCPIPInterface::set_streaming_source_ip() { // only set // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting streaming source ip:" << arg; receiver->setStreamingSourceIP(arg); } // get - retval = receiver->getStreamingSourceIP(); - FILE_LOG(logDEBUG1) << "streaming source ip:" << retval; + strcpy(retval, receiver->getStreamingSourceIP().c_str()); + FILE_LOG(logDEBUG5) << "streaming source ip:" << retval; } - return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); } - - - - int slsReceiverTCPIPInterface::set_silent_mode() { + ret = OK; memset(mess, 0, sizeof(mess)); int value = -1; int retval = -1; @@ -1632,23 +1596,22 @@ int slsReceiverTCPIPInterface::set_silent_mode() { if (value >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting silent mode:" << value; receiver->setSilentMode(value); } } // get retval = (int)receiver->getSilentMode(); - FILE_LOG(logDEBUG1) << "silent mode:" << retval; + validate(value, retval, std::string("set silent mode"), 0); + FILE_LOG(logDEBUG5) << "silent mode:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - - - int slsReceiverTCPIPInterface::enable_gap_pixels() { + ret = OK; memset(mess, 0, sizeof(mess)); int enable = -1; int retval = -1; @@ -1666,26 +1629,22 @@ int slsReceiverTCPIPInterface::enable_gap_pixels() { if (enable >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting gap pixels enable:" << enable; receiver->setGapPixelsEnable(enable); } } // get retval = receiver->getGapPixelsEnable(); - if(enable >= 0 && retval != enable){ - ret = FAIL; - sprintf(mess,"Could not set gap pixels to %d, returned %d\n",enable,retval); - FILE_LOG(logERROR) << "Warning: " << mess; - } - FILE_LOG(logDEBUG1) << "Gap Pixels Enable: " << retval; + validate(enable, retval, std::string("set gap pixels enable"), 0); + FILE_LOG(logDEBUG5) << "Gap Pixels Enable: " << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - int slsReceiverTCPIPInterface::restream_stop(){ + ret = OK; memset(mess, 0, sizeof(mess)); // no arg, and check receiver is null @@ -1701,6 +1660,7 @@ int slsReceiverTCPIPInterface::restream_stop(){ sprintf(mess,"Could not restream stop packet as data Streaming is disabled.\n"); FILE_LOG(logERROR) << mess; } else { + FILE_LOG(logDEBUG5) << "Restreaming stop"; ret = receiver->restreamStop(); if (ret == FAIL) { sprintf(mess,"Could not restream stop packet.\n"); @@ -1709,13 +1669,13 @@ int slsReceiverTCPIPInterface::restream_stop(){ } } } - return interface->Server_SendResult(true, ret, NULL, 0, mess); } int slsReceiverTCPIPInterface::set_additional_json_header() { + ret = OK; memset(mess, 0, sizeof(mess)); char arg[MAX_STR_LENGTH] = {0}; char retval[MAX_STR_LENGTH] = {0}; @@ -1729,19 +1689,20 @@ int slsReceiverTCPIPInterface::set_additional_json_header() { // only set // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting additional json header: " << arg; receiver->setAdditionalJsonHeader(arg); } // get - retval = receiver->getAdditionalJsonHeader(); - FILE_LOG(logDEBUG1) << "additional json header:" << retval; + strcpy(retval, receiver->getAdditionalJsonHeader().c_str()); + FILE_LOG(logDEBUG5) << "additional json header:" << retval; } - return interface->Server_SendResult(true, ret, retval, MAX_STR_LENGTH, mess); } int slsReceiverTCPIPInterface::set_udp_socket_buffer_size() { + ret = OK; memset(mess, 0, sizeof(mess)); int index = -1; int retval = -1; @@ -1756,7 +1717,8 @@ int slsReceiverTCPIPInterface::set_udp_socket_buffer_size() { if (index >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { - if (receiver->setUDPSocketBufferSize(index) == FAIL) { + FILE_LOG(logDEBUG5) << "Setting UDP Socket Buffer size: " << index; + if (receiver->setUDPSocketBufferSize(index) == FAIL) { ret = FAIL; strcpy(mess, "Could not create dummy UDP Socket to test buffer size\n"); FILE_LOG(logERROR) << mess; @@ -1764,30 +1726,27 @@ int slsReceiverTCPIPInterface::set_udp_socket_buffer_size() { } } // get - retval=receiver->getUDPSocketBufferSize(); - if(index >= 0 && ((retval != index) || ((int)receiver->getActualUDPSocketBufferSize() != (index*2)))) { - ret = FAIL; - strcpy(mess, "Could not set UDP Socket buffer size (No CAP_NET_ADMIN privileges?)\n"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "UDP Socket Buffer Size:" << retval; + retval = receiver->getUDPSocketBufferSize(); + validate(index, retval, std::string("set udp socket buffer size (No CAP_NET_ADMIN privileges?)"), 0); + FILE_LOG(logDEBUG5) << "UDP Socket Buffer Size:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } int slsReceiverTCPIPInterface::get_real_udp_socket_buffer_size(){ + ret = OK; memset(mess, 0, sizeof(mess)); int retval = -1; // no arg, check receiver is null interface->Server_ReceiveArg(ret, mess, NULL, 0, true, receiver); - if (ret == OK) + if (ret == OK) { + FILE_LOG(logDEBUG5) << "Getting actual UDP buffer size"; retval = receiver->getActualUDPSocketBufferSize(); - + } return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } @@ -1809,35 +1768,29 @@ int slsReceiverTCPIPInterface::set_frames_per_file() { if (index >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting frames per file: " << index; receiver->setFramesPerFile(index); } } // get - retval=receiver->getFramesPerFile(); - if(index >= 0 && retval != index) { - ret = FAIL; - strcpy(mess, "Could not set frames per file\n"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "frames per file:" << retval; + retval = receiver->getFramesPerFile(); + validate(index, retval, std::string("set frames per file"), 0); + FILE_LOG(logDEBUG5) << "frames per file:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - - - int slsReceiverTCPIPInterface::check_version_compatibility() { + ret = OK; memset(mess, 0, sizeof(mess)); int64_t arg = -1; // get args, return if socket crashed if (interface->Server_ReceiveArg(ret, mess, &arg, sizeof(arg)) == FAIL) return FAIL; - FILE_LOG(logDEBUG1) << "Checking versioning compatibility with value " << arg; + FILE_LOG(logDEBUG5) << "Checking versioning compatibility with value " << arg; int64_t client_requiredVersion = arg; int64_t rx_apiVersion = APIRECEIVER; int64_t rx_version = getReceiverVersion(); @@ -1869,8 +1822,8 @@ int slsReceiverTCPIPInterface::check_version_compatibility() { - int slsReceiverTCPIPInterface::set_discard_policy() { + ret = OK; memset(mess, 0, sizeof(mess)); int index = -1; int retval = -1; @@ -1885,25 +1838,20 @@ int slsReceiverTCPIPInterface::set_discard_policy() { if (index >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting frames discard policy: " << index; receiver->setFrameDiscardPolicy((frameDiscardPolicy)index); } } // get - retval=receiver->getFrameDiscardPolicy(); - if(index >= 0 && retval != index) { - ret = FAIL; - strcpy(mess, "Could not set frame discard policy\n"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "frame discard policy:" << retval; + retval = receiver->getFrameDiscardPolicy(); + validate(index, retval, std::string("set discard policy"), 0); + FILE_LOG(logDEBUG5) << "frame discard policy:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - int slsReceiverTCPIPInterface::set_padding_enable() { ret = OK; memset(mess, 0, sizeof(mess)); @@ -1921,26 +1869,22 @@ int slsReceiverTCPIPInterface::set_padding_enable() { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { index = (index == 0) ? 0 : 1; + FILE_LOG(logDEBUG5) << "Setting frames padding enable: " << index; receiver->setFramePaddingEnable(index); } } // get - retval=(int)receiver->getFramePaddingEnable(); - if(index >= 0 && retval != index) { - ret = FAIL; - strcpy(mess, "Could not set frame padding enable\n"); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "Frame Padding Enable:" << retval; + retval = (int)receiver->getFramePaddingEnable(); + validate(index, retval, std::string("set frame padding enable"), 0); + FILE_LOG(logDEBUG5) << "Frame Padding Enable:" << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } - int slsReceiverTCPIPInterface::set_deactivated_receiver_padding_enable() { + ret = OK; memset(mess, 0, sizeof(mess)); int enable = -1; int retval = -1; @@ -1958,18 +1902,14 @@ int slsReceiverTCPIPInterface::set_deactivated_receiver_padding_enable() { if (enable >= 0) { // verify if receiver is unlocked and idle if (interface->Server_VerifyLockAndIdle(ret, mess, lockStatus, receiver->getStatus(), fnum) == OK) { + FILE_LOG(logDEBUG5) << "Setting deactivated padding enable: " << enable; receiver->setDeactivatedPadding(enable > 0 ? true : false); } } // get retval = (int)receiver->getDeactivatedPadding(); - if(enable >= 0 && retval != enable){ - ret = FAIL; - sprintf(mess,"Could not set deactivated padding enable to %d, returned %d\n",enable,retval); - FILE_LOG(logERROR) << mess; - } - FILE_LOG(logDEBUG1) << "Deactivated Padding Enable: " << retval; + validate(enable, retval, std::string("set deactivated padding enable"), 0); + FILE_LOG(logDEBUG5) << "Deactivated Padding Enable: " << retval; } - return interface->Server_SendResult(true, ret, &retval, sizeof(retval), mess); } diff --git a/slsSupportLib/include/ClientInterface.cpp b/slsSupportLib/include/ClientInterface.cpp index 4d387da76..92d3f89ee 100644 --- a/slsSupportLib/include/ClientInterface.cpp +++ b/slsSupportLib/include/ClientInterface.cpp @@ -82,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);