diff --git a/manual/manual-api/CMakeLists.txt b/manual/manual-api/CMakeLists.txt index c58af3b0d..23945d636 100644 --- a/manual/manual-api/CMakeLists.txt +++ b/manual/manual-api/CMakeLists.txt @@ -18,13 +18,10 @@ target_link_libraries(slsMultiReceiver pthread zmq rt - ${HDF5_LIBRARIES} ) if (HDF5_FOUND) - target_link_libraries(slsMultiReceiver - ${HDF5_LIBRARIES} - ) + target_link_libraries(slsMultiReceiver ${HDF5_LIBRARIES}) endif () diff --git a/slsDetectorServers/eigerDetectorServer/Beb.c b/slsDetectorServers/eigerDetectorServer/Beb.c index c81fcafcb..6ed288e9a 100644 --- a/slsDetectorServers/eigerDetectorServer/Beb.c +++ b/slsDetectorServers/eigerDetectorServer/Beb.c @@ -1,13 +1,8 @@ -#include "xfs_types.h" -#include "xparameters.h" -#include "FebRegisterDefs.h" #include "logger.h" #include "Beb.h" +#include "FebRegisterDefs.h" +#include "xparameters.h" - -#include -#include -#include #include #include #include diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.c b/slsDetectorServers/eigerDetectorServer/FebControl.c index 538825f90..25d2f6a81 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.c +++ b/slsDetectorServers/eigerDetectorServer/FebControl.c @@ -1,18 +1,15 @@ -#include "FebRegisterDefs.h" #include "FebControl.h" -#include "Beb.h" +#include "FebRegisterDefs.h" #include "slsDetectorServer_defs.h" #include "logger.h" +#include "Beb.h" -#include -#include #include #include #include #include #include // POSIX terminal control definitions(CS8, CREAD, CLOCAL..) #include -#include #include diff --git a/slsDetectorServers/eigerDetectorServer/FebControl.h b/slsDetectorServers/eigerDetectorServer/FebControl.h index ba3cc4a55..2e65666fd 100644 --- a/slsDetectorServers/eigerDetectorServer/FebControl.h +++ b/slsDetectorServers/eigerDetectorServer/FebControl.h @@ -1,8 +1,6 @@ #pragma once #include "FebInterface.h" - #include -#include struct Module{ diff --git a/slsDetectorServers/eigerDetectorServer/FebInterface.c b/slsDetectorServers/eigerDetectorServer/FebInterface.c index 9ed524a57..9c7d33051 100644 --- a/slsDetectorServers/eigerDetectorServer/FebInterface.c +++ b/slsDetectorServers/eigerDetectorServer/FebInterface.c @@ -3,8 +3,6 @@ #include "xparameters.h" #include "logger.h" -#include -#include #include diff --git a/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h b/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h index 1885dd08b..a9b2f2459 100644 --- a/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h +++ b/slsDetectorServers/eigerDetectorServer/FebRegisterDefs.h @@ -1,10 +1,4 @@ -/** - * @author Ian Johnson - * @version 1.0 - */ - - //daq register definitions #define DAQ_REG_CTRL 1 #define DAQ_REG_CHIP_CMDS 2 diff --git a/slsDetectorServers/eigerDetectorServer/LocalLinkInterface.c b/slsDetectorServers/eigerDetectorServer/LocalLinkInterface.c index d180a729c..3e47cd61a 100644 --- a/slsDetectorServers/eigerDetectorServer/LocalLinkInterface.c +++ b/slsDetectorServers/eigerDetectorServer/LocalLinkInterface.c @@ -1,9 +1,7 @@ #include "LocalLinkInterface.h" #include "HardwareMMappingDefs.h" #include "logger.h" -#include "ansi.h" -#include #include #include #include diff --git a/slsDetectorServers/eigerDetectorServer/Makefile b/slsDetectorServers/eigerDetectorServer/Makefile index 6bc0fbebc..b76a695d8 100755 --- a/slsDetectorServers/eigerDetectorServer/Makefile +++ b/slsDetectorServers/eigerDetectorServer/Makefile @@ -8,7 +8,7 @@ DESTDIR ?= bin INSTMODE = 0777 -SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c FebControl.c Beb.c HardwareIO.c LocalLinkInterface.c FebInterface.c +SRC_CLNT = communication_funcs.c slsDetectorServer.c slsDetectorServer_funcs.c slsDetectorFunctionList.c HardwareIO.c LocalLinkInterface.c FebInterface.c FebControl.c Beb.c OBJS = $(SRC_CLNT:.c=.o) diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_virtualMaster b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_virtualMaster index 54e5a843f..358c4c0bf 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_virtualMaster and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_virtualMaster differ diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_virtualSlave b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_virtualSlave index 4b777d026..5aa6e27cc 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_virtualSlave and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_virtualSlave differ diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 8511a024d..538cb0ac9 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -1,14 +1,13 @@ #include "slsDetectorFunctionList.h" #include "gitInfoEiger.h" +#include "versionAPI.h" +#include "logger.h" + #ifndef VIRTUAL #include "FebControl.h" #include "Beb.h" -#include "versionAPI.h" #endif -#include "logger.h" - -#include #include //to gethostname #include #ifdef VIRTUAL @@ -20,6 +19,11 @@ extern int debugflag; extern int isControlServer; +int firmware_compatibility = OK; +int firmware_check_done = 0; +char firmware_message[MAX_STR_LENGTH]; + + const char* dac_names[16] = {"SvP","Vtr","Vrf","Vrs","SvN","Vtgstv","Vcmp_ll","Vcmp_lr","cal","Vcmp_rl","rxb_rb","rxb_lb","Vcmp_rr","Vcp","Vcn","Vis"}; int default_tau_from_file= -1; enum detectorSettings thisSettings; @@ -42,12 +46,6 @@ int normal = 0; uint32_t detid = 0; #endif - -int firmware_compatibility = OK; -int firmware_check_done = 0; -char firmware_message[MAX_STR_LENGTH]; - - int eiger_highvoltage = 0; int eiger_theo_highvoltage = 0; int eiger_iodelay = 0; @@ -60,8 +58,6 @@ int eiger_readoutspeed = 0; int eiger_triggermode = 0; int eiger_extgating = 0; int eiger_extgatingpolarity = 0; - - int eiger_nexposures = 1; int eiger_ncycles = 1; @@ -381,25 +377,25 @@ void allocateDetectorStructureMemory() { FILE_LOG(logINFO, ("This Server is for 1 Eiger half module (250k)\n\n")); //Allocation of memory - detectorModules=malloc(sizeof(sls_detector_module)); - detectorChans=malloc(NCHIP*NCHAN*sizeof(int)); - detectorDacs=malloc(NDAC*sizeof(int)); - detectorAdcs=malloc(NADC*sizeof(int)); + detectorModules = malloc(sizeof(sls_detector_module)); + detectorChans = malloc(NCHIP*NCHAN*sizeof(int)); + detectorDacs = malloc(NDAC*sizeof(int)); + detectorAdcs = malloc(NADC*sizeof(int)); FILE_LOG(logDEBUG1, ("modules from 0x%x to 0x%x\n",detectorModules, detectorModules)); FILE_LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n",detectorChans, detectorChans)); FILE_LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs)); FILE_LOG(logDEBUG1, ("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs)); - (detectorModules)->dacs=detectorDacs; - (detectorModules)->adcs=detectorAdcs; - (detectorModules)->chanregs=detectorChans; - (detectorModules)->ndac=NDAC; - (detectorModules)->nadc=NADC; - (detectorModules)->nchip=NCHIP; - (detectorModules)->nchan=NCHIP*NCHAN; - (detectorModules)->reg=0; - (detectorModules)->iodelay=0; - (detectorModules)->tau=0; - (detectorModules)->eV=0; + (detectorModules)->dacs = detectorDacs; + (detectorModules)->adcs = detectorAdcs; + (detectorModules)->chanregs = detectorChans; + (detectorModules)->ndac = NDAC; + (detectorModules)->nadc = NADC; + (detectorModules)->nchip = NCHIP; + (detectorModules)->nchan = NCHIP * NCHAN; + (detectorModules)->reg = 0; + (detectorModules)->iodelay = 0; + (detectorModules)->tau = 0; + (detectorModules)->eV = 0; thisSettings = UNINITIALIZED; // if trimval requested, should return -1 to acknowledge unknown @@ -1196,6 +1192,7 @@ enum externalCommunicationMode getTiming() { int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t sourceip, uint32_t udpport, uint32_t udpport2) { #ifndef VIRTUAL + FILE_LOG(logINFO, ("Configuring MAC\n")); char src_mac[50], src_ip[50],dst_mac[50], dst_ip[50]; int src_port = 0xE185; sprintf(src_ip,"%d.%d.%d.%d",(sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff); @@ -1215,12 +1212,14 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t - FILE_LOG(logINFO, ("src_port:%d\n" - "\tsrc_ip:%s\n" - "\tdst_ip:%s\n" - "\tsrc_mac:%s\n" - "\tdst_mac:%s\n", - src_port, src_ip, dst_ip, src_mac, dst_mac)); + FILE_LOG(logINFO, ( + "\tSource IP : %s\n" + "\tSource MAC : %s\n" + "\tSource Port : %d\n" + "\tDest IP : %s\n" + "\tDest MAC : %s\n", + src_ip, src_mac, src_port, + dst_ip, dst_mac)); int beb_num = detid; @@ -1229,13 +1228,13 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t if (!top) dst_port = udpport2; - FILE_LOG(logINFO, ("\tdst_port:%d\n", dst_port)); + FILE_LOG(logINFO, ("\tDest Port : %d\n", dst_port)); int i=0; /* for(i=0;i<32;i++) { modified for Aldo*/ if (Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) && Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) { - FILE_LOG(logINFO, ("set up left ok\n")); + FILE_LOG(logDEBUG1, ("\tset up left ok\n")); } else { return -1; } @@ -1245,12 +1244,12 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t dst_port = udpport2; if (!top) dst_port = udpport; - FILE_LOG(logINFO, ("dst_port:%d\n",dst_port)); + FILE_LOG(logINFO, ("\tDest Port : %d\n",dst_port)); /*for(i=0;i<32;i++) {*//** modified for Aldo*/ if (Beb_SetBebSrcHeaderInfos(beb_num,send_to_ten_gig,src_mac,src_ip,src_port) && Beb_SetUpUDPHeader(beb_num,send_to_ten_gig,header_number+i,dst_mac,dst_ip, dst_port)) { - FILE_LOG(logINFO, ("set up right ok\n")); + FILE_LOG(logDEBUG1, (" set up right ok\n")); } else { return -1; } @@ -1654,7 +1653,7 @@ void* start_timer(void* arg) { int stopStateMachine() { - FILE_LOG(logERROR, ("Going to stop acquisition\n")); + FILE_LOG(logINFORED, ("Going to stop acquisition\n")); #ifdef VIRTUAL eiger_virtual_stop = 0; return OK; @@ -1722,13 +1721,13 @@ enum runStatus getRunStatus() { int i = Feb_Control_AcquisitionInProgress(); switch (i) { case STATUS_ERROR: - FILE_LOG(logINFO, ("Status: ERROR reading status register\n")); + FILE_LOG(logERROR, ("Status: ERROR reading status register\n")); return ERROR; case STATUS_IDLE: - FILE_LOG(logINFO, ("Status: IDLE\n")); + FILE_LOG(logINFOBLUE, ("Status: IDLE\n")); return IDLE; default: - FILE_LOG(logINFO, ("Status: RUNNING...\n")); + FILE_LOG(logINFOBLUE, ("Status: RUNNING...\n")); return RUNNING; } diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h index 8788688c5..6200e38c2 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h @@ -9,7 +9,6 @@ #define SLSDETECTORSERVER_DEFS_H_ #include "sls_detector_defs.h" -#include #define GOODBYE (-200) #define REQUIRED_FIRMWARE_VERSION (22) diff --git a/slsDetectorServers/jungfrauDetectorServer/gitInfo.txt b/slsDetectorServers/jungfrauDetectorServer/gitInfo.txt index 3de37899c..116c0f37e 100644 --- a/slsDetectorServers/jungfrauDetectorServer/gitInfo.txt +++ b/slsDetectorServers/jungfrauDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorPackage/slsDetectorServers/jungfrauDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: ee20932392a576a700f48140be02acb94b7eb6de -Revision: 1 +Repsitory UUID: 92123069ce045314a12416a7e8b308875d7f9f21 +Revision: 7 Branch: refactor Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4103 -Last Changed Date: 2018-10-11 13:46:09.000000002 +0200 ./RegisterDefs.h +Last Changed Rev: 4158 +Last Changed Date: 2018-11-02 12:00:46.000000002 +0100 ./Makefile diff --git a/slsDetectorServers/jungfrauDetectorServer/gitInfoJungfrau.h b/slsDetectorServers/jungfrauDetectorServer/gitInfoJungfrau.h index 99a0a7b3d..90af7896d 100644 --- a/slsDetectorServers/jungfrauDetectorServer/gitInfoJungfrau.h +++ b/slsDetectorServers/jungfrauDetectorServer/gitInfoJungfrau.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "ee20932392a576a700f48140be02acb94b7eb6de" +#define GITREPUUID "92123069ce045314a12416a7e8b308875d7f9f21" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4103 -#define GITDATE 0x20181011 +#define GITREV 0x4158 +#define GITDATE 0x20181102 #define GITBRANCH "refactor" diff --git a/slsDetectorServers/jungfrauDetectorServer/logger.h b/slsDetectorServers/jungfrauDetectorServer/logger.h new file mode 120000 index 000000000..ff1930ce3 --- /dev/null +++ b/slsDetectorServers/jungfrauDetectorServer/logger.h @@ -0,0 +1 @@ +../slsDetectorServer/logger.h \ No newline at end of file diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 76cefd079..18108db22 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -1,26 +1,26 @@ #include "slsDetectorFunctionList.h" #include "gitInfoJungfrau.h" -#ifndef VIRTUAL -#include "AD9257.h" // include "commonServerFunctions.h", which in turn includes "blackfin.h" -#include "programfpga.h" #include "versionAPI.h" +#include "logger.h" -#ifdef VIRTUAL +#ifndef VIRTUAL +#include "AD9257.h" // commonServerFunctions.h, blackfin.h, ansi.h +#include "programfpga.h" +#else #include #include #endif -/* global variables */ -//jungfrau doesnt require chips and chans (save memory) -sls_detector_module *detectorModules=NULL; -int *detectorDacs=NULL; -int *detectorAdcs=NULL; -enum detectorSettings thisSettings; -enum masterFlags masterMode = NO_MASTER; +// Global variable from slsDetectorServer +extern int debugflag; -int highvoltage = 0; -int dacValues[NDAC]; -int32_t clkPhase[2] = {0, 0}; +int firmware_compatibility = OK; +int firmware_check_done = 0; +char firmware_message[MAX_STR_LENGTH]; + +sls_detector_module *detectorModules = NULL; +int *detectorDacs = NULL; +int *detectorAdcs =NULL; #ifdef VIRTUAL pthread_t pthread_virtual_tid; @@ -28,12 +28,11 @@ int virtual_status = 0; int virtual_stop = 0; #endif +enum detectorSettings thisSettings; +int highvoltage = 0; +int dacValues[NDAC] = {0}; +int32_t clkPhase[2] = {0, 0}; -/* basic tests */ - -int firmware_compatibility = OK; -int firmware_check_done = 0; -char firmware_message[MAX_STR_LENGTH]; int isFirmwareCheckDone() { return firmware_check_done; @@ -44,16 +43,16 @@ int getFirmwareCheckResult(char** mess) { return firmware_compatibility; } -void checkFirmwareCompatibility(int flag) { +void checkFirmwareCompatibility() { + firmware_compatibility = OK; + firmware_check_done = 0; + memset(firmware_message, 0, MAX_STR_LENGTH); #ifdef VIRTUAL - cprintf(BLUE,"\n\n" - "********************************************************\n" - "************** Jungfrau Virtual Server *****************\n" - "********************************************************\n\n"); + FILE_LOG(logINFOBLUE, ("******** Jungfrau Virtual Server *****************\n")); if (mapCSP0() == FAIL) { strcpy(firmware_message, - "FATAL ERROR: Could not map to memory. Dangerous to continue.\n"); - cprintf(RED,"%s\n\n", firmware_message); + "Could not map to memory. Dangerous to continue.\n"); + FILE_LOG(logERROR, (firmware_message)); firmware_compatibility = FAIL; firmware_check_done = 1; return; @@ -66,18 +65,18 @@ void checkFirmwareCompatibility(int flag) { resetFPGA(); if (mapCSP0() == FAIL) { strcpy(firmware_message, - "FATAL ERROR: Could not map to memory. Dangerous to continue.\n"); - cprintf(RED,"%s\n\n", firmware_message); + "Could not map to memory. Dangerous to continue.\n"); + FILE_LOG(logERROR, ("%s\n\n", firmware_message)); firmware_compatibility = FAIL; firmware_check_done = 1; return; } // does check only if flag is 0 (by default), set by command line - if ((!flag) && ((checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL))) { + if ((!debugflag) && ((checkType() == FAIL) || (testFpga() == FAIL) || (testBus() == FAIL))) { strcpy(firmware_message, - "FATAL ERROR: Could not pass basic tests of FPGA and bus. Dangerous to continue.\n"); - cprintf(RED,"%s\n\n", firmware_message); + "Could not pass basic tests of FPGA and bus. Dangerous to continue.\n"); + FILE_LOG(logERROR, ("%s\n\n", firmware_message)); firmware_compatibility = FAIL; firmware_check_done = 1; return; @@ -95,10 +94,7 @@ void checkFirmwareCompatibility(int flag) { if (fwversion >= MIN_REQRD_VRSN_T_RD_API) sw_fw_apiversion = getDetectorId(SOFTWARE_FIRMWARE_API_VERSION); - cprintf(BLUE,"\n\n" - "********************************************************\n" - "****************** Jungfrau Server *********************\n" - "********************************************************\n\n" + FILE_LOG(logINFOBLUE, ("************ Jungfrau Server *********************\n" "Hardware Version:\t\t 0x%x\n" "Hardware Serial Nr:\t\t 0x%x\n" @@ -110,7 +106,6 @@ void checkFirmwareCompatibility(int flag) { "F/w-S/w API Version:\t\t 0x%llx\n" "Required Firmware Version:\t 0x%x\n" "Client-Software API Version:\t 0x%llx\n" - "\n" "********************************************************\n", hversion, hsnumber, ipadd, @@ -120,21 +115,21 @@ void checkFirmwareCompatibility(int flag) { (long long int)sw_fw_apiversion, REQRD_FRMWR_VRSN, (long long int)client_sw_apiversion - ); + )); // return if flag is not zero, debug mode - if (flag) { + if (debugflag) { firmware_check_done = 1; return; } //cant read versions - printf("Testing Firmware-software compatibility ...\n"); + FILE_LOG(logINFO, ("Testing Firmware-software compatibility:\n")); if(!fwversion || !sw_fw_apiversion){ strcpy(firmware_message, - "FATAL ERROR: Cant read versions from FPGA. Please update firmware.\n"); - cprintf(RED,"%s\n\n", firmware_message); + "Cant read versions from FPGA. Please update firmware.\n"); + FILE_LOG(logERROR, (firmware_message)); firmware_compatibility = FAIL; firmware_check_done = 1; return; @@ -143,29 +138,29 @@ void checkFirmwareCompatibility(int flag) { //check for API compatibility - old server if(sw_fw_apiversion > REQRD_FRMWR_VRSN){ sprintf(firmware_message, - "FATAL ERROR: This detector software software version (0x%llx) is incompatible.\n" + "This detector software software version (0x%llx) is incompatible.\n" "Please update detector software (min. 0x%llx) to be compatible with this firmware.\n", (long long int)sw_fw_apiversion, (long long int)REQRD_FRMWR_VRSN); - cprintf(RED,"%s\n\n", firmware_message); + FILE_LOG(logERROR, (firmware_message)); firmware_compatibility = FAIL; firmware_check_done = 1; return; } //check for firmware compatibility - old firmware - if( REQRD_FRMWR_VRSN > fwversion){ + if( REQRD_FRMWR_VRSN > fwversion) { sprintf(firmware_message, - "FATAL ERROR: This firmware version (0x%llx) is incompatible.\n" + "This firmware version (0x%llx) is incompatible.\n" "Please update firmware (min. 0x%llx) to be compatible with this server.\n", (long long int)fwversion, (long long int)REQRD_FRMWR_VRSN); - cprintf(RED,"%s\n\n", firmware_message); + FILE_LOG(logERROR, (firmware_message)); firmware_compatibility = FAIL; firmware_check_done = 1; return; } - printf("Compatibility - success\n"); + FILE_LOG(logINFO, ("Compatibility - success\n")); firmware_check_done = 1; } @@ -175,8 +170,8 @@ int checkType() { return OK; #endif volatile u_int32_t type = ((bus_r(FPGA_VERSION_REG) & DETECTOR_TYPE_MSK) >> DETECTOR_TYPE_OFST); - if (type != JUNGFRAU){ - cprintf(BG_RED,"This is not a Jungfrau Server (read %d, expected %d)\n",type, JUNGFRAU); + if (type != BOARD_JUNGFRAU_TYPE){ + FILE_LOG(logERROR, ("This is not a Jungfrau Server (read %d, expected %d)\n", type, BOARD_JUNGFRAU_TYPE)); return FAIL; } @@ -189,15 +184,15 @@ u_int32_t testFpga(void) { #ifdef VIRTUAL return OK; #endif - printf("\nTesting FPGA...\n"); + FILE_LOG(logINFO, ("Testing FPGA:\n")); //fixed pattern int ret = OK; volatile u_int32_t val = bus_r(FIX_PATT_REG); if (val == FIX_PATT_VAL) { - printf("Fixed pattern: successful match 0x%08x\n",val); + FILE_LOG(logINFO, ("Fixed pattern: successful match 0x%08x\n",val)); } else { - cprintf(RED,"Fixed pattern does not match! Read 0x%08x, expected 0x%08x\n", val, FIX_PATT_VAL); + FILE_LOG(logERROR, ("Fixed pattern does not match! Read 0x%08x, expected 0x%08x\n", val, FIX_PATT_VAL)); ret = FAIL; } return ret; @@ -208,7 +203,7 @@ int testBus() { #ifdef VIRTUAL return OK; #endif - printf("\nTesting Bus...\n"); + FILE_LOG(logINFO, ("Testing Bus:\n")); int ret = OK; u_int32_t addr = SET_TRIGGER_DELAY_LSB_REG; @@ -218,16 +213,17 @@ int testBus() { for (i = 0; i < times; ++i) { bus_w(addr, i * 100); if (i * 100 != bus_r(addr)) { - cprintf(RED,"ERROR: Mismatch! Wrote 0x%x, read 0x%x\n", - i * 100, bus_r(addr)); + FILE_LOG(logERROR, ("Mismatch! Wrote 0x%x, read 0x%x\n", + i * 100, bus_r(addr))); ret = FAIL; } } bus_w(addr, 0); - if (ret == OK) - printf("Successfully tested bus %d times\n", times); + if (ret == OK) { + FILE_LOG(logINFO, ("Successfully tested bus %d times\n", times)); + } return ret; } @@ -243,7 +239,7 @@ int detectorTest( enum digitalTestMode arg){ //DETECTOR_MEMORY_TEST:testRAM //DETECTOR_SOFTWARE_TEST: default: - cprintf(RED,"Warning: Test not implemented for this detector %d\n", (int)arg); + FILE_LOG(logERROR, ("Test not implemented for this detector %d\n", (int)arg)); break; } return OK; @@ -351,7 +347,7 @@ u_int32_t getDetectorIP(){ } strcpy(output,temp); sscanf(output, "%x", &res); - //printf("ip:%x\n",res); + //FILE_LOG(logINFO, ("ip:%x\n",res); return res; } @@ -368,7 +364,6 @@ u_int32_t getDetectorIP(){ void initControlServer(){ clkPhase[0] = 0; clkPhase[1] = 0; setupDetector(); - printf("\n"); } @@ -377,7 +372,7 @@ void initStopServer() { usleep(CTRL_SRVR_INIT_TIME_US); if (mapCSP0() == FAIL) { - cprintf(BG_RED, "Stop Server: Map Fail. Dangerous to continue. Goodbye!\n"); + FILE_LOG(logERROR, ("Stop Server: Map Fail. Dangerous to continue. Goodbye!\n")); exit(EXIT_FAILURE); } } @@ -390,29 +385,28 @@ void initStopServer() { /* set up detector */ void allocateDetectorStructureMemory(){ - printf("This Server is for 1 Jungfrau module (500k)\n"); + FILE_LOG(logINFO, ("This Server is for 1 Jungfrau module (500k)\n")); //Allocation of memory - if (detectorModules!=NULL) free(detectorModules); - if (detectorDacs!=NULL) free(detectorDacs); - if (detectorAdcs!=NULL) free(detectorAdcs); - detectorModules=malloc(sizeof(sls_detector_module)); - detectorDacs=malloc(NDAC*sizeof(int)); - detectorAdcs=malloc(NADC*sizeof(int)); -#ifdef VERBOSE - printf("modules from 0x%x to 0x%x\n",detectorModules, detectorModules+n); - printf("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs+n*NDAC); - printf("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs+n*NADC); -#endif - (detectorModules)->dacs=detectorDacs; - (detectorModules)->adcs=detectorAdcs; - (detectorModules)->ndac=NDAC; - (detectorModules)->nadc=NADC; - (detectorModules)->nchip=NCHIP; - (detectorModules)->nchan=NCHIP*NCHAN; - (detectorModules)->gain=0; - (detectorModules)->offset=0; - (detectorModules)->reg=0; + if (detectorModules != NULL) free(detectorModules); + if (detectorDacs != NULL) free(detectorDacs); + if (detectorAdcs != NULL) free(detectorAdcs); + detectorModules = malloc(sizeof(sls_detector_module)); + detectorDacs = malloc(NDAC*sizeof(int)); + detectorAdcs = malloc(NADC*sizeof(int)); + FILE_LOG(logDEBUG1, ("modules from 0x%x to 0x%x\n",detectorModules, detectorModules)); + FILE_LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n",detectorDacs, detectorDacs)); + FILE_LOG(logDEBUG1, ("adcs from 0x%x to 0x%x\n",detectorAdcs, detectorAdcs)); + (detectorModules)->dacs = detectorDacs; + (detectorModules)->adcs = detectorAdcs; + (detectorModules)->ndac = NDAC; + (detectorModules)->nadc = NADC; + (detectorModules)->nchip = NCHIP; + (detectorModules)->nchan = NCHIP * NCHAN; + (detectorModules)->reg = 0; + (detectorModules)->iodelay = 0; + (detectorModules)->tau = 0; + (detectorModules)->eV = 0; thisSettings = UNINITIALIZED; { // initialize to -1 @@ -429,7 +423,6 @@ void setupDetector() { allocateDetectorStructureMemory(); - printf("Resetting PLL\n"); resetPLL(); resetCore(); resetPeripheral(); @@ -446,6 +439,7 @@ void setupDetector() { bus_w(DAQ_REG, 0x0); /* Only once at server startup */ + FILE_LOG(logINFOBLUE, ("Setting Default parameters\n")); setSpeed(HALF_SPEED); cleanFifos(); resetCore(); @@ -479,7 +473,7 @@ void setupDetector() { int setDefaultDacs() { int ret = OK; - printf("Setting Default Dac values\n"); + FILE_LOG(logINFOBLUE, ("Setting Default Dac values\n")); { int i = 0; int retval[2]={-1,-1}; @@ -489,7 +483,7 @@ int setDefaultDacs() { if (dacValues[i] != defaultvals[i]) { setDAC((enum DACINDEX)i,defaultvals[i],0,retval); if (retval[0] != defaultvals[i]) { - cprintf(RED, "Warning: Setting dac %d failed, wrote %d, read %d\n",i ,defaultvals[i], retval[0]); + FILE_LOG(logERROR, ("Setting dac %d failed, wrote %d, read %d\n",i ,defaultvals[i], retval[0])); ret = FAIL; } } @@ -506,17 +500,15 @@ int setDefaultDacs() { int powerChip (int on){ if(on != -1){ if(on){ - cprintf(BLUE, "\n*** Powering on the chip ***\n"); + FILE_LOG(logINFO, ("Powering chip: on\n")); bus_w(CHIP_POWER_REG, bus_r(CHIP_POWER_REG) | CHIP_POWER_ENABLE_MSK); } else{ - cprintf(BLUE, "\n*** Powering off the chip*** \n"); + FILE_LOG(logINFO, ("Powering chip: off\n")); bus_w(CHIP_POWER_REG, bus_r(CHIP_POWER_REG) & ~CHIP_POWER_ENABLE_MSK); } } - //return ((bus_r(CHIP_POWER_REG) & CHIP_POWER_ENABLE_MSK) >> CHIP_POWER_ENABLE_OFST); - /**temporary fix until power reg status can be read */ return ((bus_r(CHIP_POWER_REG) & CHIP_POWER_STATUS_MSK) >> CHIP_POWER_STATUS_OFST); } @@ -525,11 +517,11 @@ int powerChip (int on){ int autoCompDisable(int on) { if(on != -1){ if(on){ - cprintf(BLUE, "\n*** Auto comp disable mode: enabling ***\n"); + FILE_LOG(logINFO, ("Auto comp disable mode: on\n")); bus_w(VREF_COMP_MOD_REG, bus_r(VREF_COMP_MOD_REG) | VREF_COMP_MOD_ENABLE_MSK); } else{ - cprintf(BLUE, "\n*** Auto comp disable mode: disabling *** \n"); + FILE_LOG(logINFO, ("Auto comp disable mode: off\n")); bus_w(VREF_COMP_MOD_REG, bus_r(VREF_COMP_MOD_REG) & ~VREF_COMP_MOD_ENABLE_MSK); } } @@ -542,7 +534,7 @@ void cleanFifos() { #ifdef VIRTUAL return; #endif - printf("\nClearing Acquisition Fifos\n"); + FILE_LOG(logINFO, ("Clearing Acquisition Fifos\n")); bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_ACQ_FIFO_CLR_MSK); bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_ACQ_FIFO_CLR_MSK); } @@ -551,7 +543,7 @@ void resetCore() { #ifdef VIRTUAL return; #endif - printf("\nResetting Core\n"); + FILE_LOG(logINFO, ("Resetting Core\n")); bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_CORE_RST_MSK); bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_CORE_RST_MSK); } @@ -560,13 +552,13 @@ void resetPeripheral() { #ifdef VIRTUAL return; #endif - printf("\nResetting Peripheral\n"); + FILE_LOG(logINFO, ("Resetting Peripheral\n")); bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_PERIPHERAL_RST_MSK); bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_PERIPHERAL_RST_MSK); } int adcPhase(int st){ /**carlos needed clkphase 1 and 2? cehck with Aldo */ - printf("Setting ADC Phase to %d\n",st); + FILE_LOG(logINFO, ("Setting ADC Phase to %d\n", st)); if (st > 65535 || st < -65535) return clkPhase[0]; @@ -584,7 +576,7 @@ int getPhase() { } void configureASICTimer() { - printf("\nConfiguring ASIC Timer\n"); + FILE_LOG(logINFO, ("Configuring ASIC Timer\n")); bus_w(ASIC_CTRL_REG, (bus_r(ASIC_CTRL_REG) & ~ASIC_CTRL_PRCHRG_TMR_MSK) | ASIC_CTRL_PRCHRG_TMR_VAL); bus_w(ASIC_CTRL_REG, (bus_r(ASIC_CTRL_REG) & ~ASIC_CTRL_DS_TMR_MSK) | ASIC_CTRL_DS_TMR_VAL); } @@ -624,58 +616,57 @@ enum speedVariable setSpeed(int val) { // todo in firmware, for now setting half speed case FULL_SPEED://40 - printf("\nSetting Half Speed (20 MHz):\n"); + FILE_LOG(logINFO, ("Setting Half Speed (20 MHz):\n")); - printf("Setting Sample Reg to 0x%x\n", SAMPLE_ADC_HALF_SPEED); + FILE_LOG(logINFO, ("\tSetting Sample Reg to 0x%x\n", SAMPLE_ADC_HALF_SPEED)); bus_w(SAMPLE_REG, SAMPLE_ADC_HALF_SPEED); txndelay_msk = (bus_r(CONFIG_REG) & CONFIG_TDMA_TIMESLOT_MSK); // read config tdma timeslot value - printf("Setting Config Reg to 0x%x\n", CONFIG_HALF_SPEED | txndelay_msk); + FILE_LOG(logINFO, ("\tSetting Config Reg to 0x%x\n", CONFIG_HALF_SPEED | txndelay_msk)); bus_w(CONFIG_REG, CONFIG_HALF_SPEED | txndelay_msk); - printf("Setting ADC Ofst Reg to 0x%x\n", ADC_OFST_HALF_SPEED_VAL); + FILE_LOG(logINFO, ("\tSetting ADC Ofst Reg to 0x%x\n", ADC_OFST_HALF_SPEED_VAL)); bus_w(ADC_OFST_REG, ADC_OFST_HALF_SPEED_VAL); - printf("Setting ADC Phase Reg to 0x%x\n", ADC_PHASE_HALF_SPEED); + FILE_LOG(logINFO, ("\tSetting ADC Phase Reg to 0x%x\n", ADC_PHASE_HALF_SPEED)); adcPhase(ADC_PHASE_HALF_SPEED); break; case HALF_SPEED: - printf("\nSetting Half Speed (20 MHz):\n"); + FILE_LOG(logINFO, ("Setting Half Speed (20 MHz):\n")); - printf("Setting Sample Reg to 0x%x\n", SAMPLE_ADC_HALF_SPEED); + FILE_LOG(logINFO, ("\tSetting Sample Reg to 0x%x\n", SAMPLE_ADC_HALF_SPEED)); bus_w(SAMPLE_REG, SAMPLE_ADC_HALF_SPEED); txndelay_msk = (bus_r(CONFIG_REG) & CONFIG_TDMA_TIMESLOT_MSK); // read config tdma timeslot value - printf("Setting Config Reg to 0x%x\n", CONFIG_HALF_SPEED | txndelay_msk); + FILE_LOG(logINFO, ("\tSetting Config Reg to 0x%x\n", CONFIG_HALF_SPEED | txndelay_msk)); bus_w(CONFIG_REG, CONFIG_HALF_SPEED | txndelay_msk); - printf("Setting ADC Ofst Reg to 0x%x\n", ADC_OFST_HALF_SPEED_VAL); + FILE_LOG(logINFO, ("\tSetting ADC Ofst Reg to 0x%x\n", ADC_OFST_HALF_SPEED_VAL)); bus_w(ADC_OFST_REG, ADC_OFST_HALF_SPEED_VAL); - printf("Setting ADC Phase Reg to 0x%x\n", ADC_PHASE_HALF_SPEED); + FILE_LOG(logINFO, ("\tSetting ADC Phase Reg to 0x%x\n", ADC_PHASE_HALF_SPEED)); adcPhase(ADC_PHASE_HALF_SPEED); break; case QUARTER_SPEED: - printf("\nSetting Half Speed (10 MHz):\n"); + FILE_LOG(logINFO, ("Setting Half Speed (10 MHz):\n")); - printf("Setting Sample Reg to 0x%x\n", SAMPLE_ADC_QUARTER_SPEED); + FILE_LOG(logINFO, ("\tSetting Sample Reg to 0x%x\n", SAMPLE_ADC_QUARTER_SPEED)); bus_w(SAMPLE_REG, SAMPLE_ADC_QUARTER_SPEED); txndelay_msk = (bus_r(CONFIG_REG) & CONFIG_TDMA_TIMESLOT_MSK); // read config tdma timeslot value - printf("Setting Config Reg to 0x%x\n", CONFIG_QUARTER_SPEED | txndelay_msk); + FILE_LOG(logINFO, ("\tSetting Config Reg to 0x%x\n", CONFIG_QUARTER_SPEED | txndelay_msk)); bus_w(CONFIG_REG, CONFIG_QUARTER_SPEED | txndelay_msk); - printf("Setting ADC Ofst Reg to 0x%x\n", ADC_OFST_QUARTER_SPEED_VAL); + FILE_LOG(logINFO, ("\tSetting ADC Ofst Reg to 0x%x\n", ADC_OFST_QUARTER_SPEED_VAL)); bus_w(ADC_OFST_REG, ADC_OFST_QUARTER_SPEED_VAL); - printf("Setting ADC Phase Reg to 0x%x\n", ADC_PHASE_QUARTER_SPEED); + FILE_LOG(logINFO, ("\tSetting ADC Phase Reg to 0x%x\n", ADC_PHASE_QUARTER_SPEED)); adcPhase(ADC_PHASE_QUARTER_SPEED); break; } - printf("\n"); } //getting @@ -700,6 +691,7 @@ enum speedVariable setSpeed(int val) { /* parameters - timer */ int selectStoragecellStart(int pos) { if (pos >= 0) { + FILE_LOG(logINFO, ("Setting storage cell start: %d\n", pos)); bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_STRG_CELL_SLCT_MSK); bus_w(DAQ_REG, bus_r(DAQ_REG) | ((pos << DAQ_STRG_CELL_SLCT_OFST) & DAQ_STRG_CELL_SLCT_MSK)); } @@ -714,60 +706,62 @@ int64_t setTimer(enum timerIndex ind, int64_t val) { switch(ind){ case FRAME_NUMBER: - if(val >= 0) - printf("\nSetting #frames: %lld\n",(long long int)val); + if(val >= 0) { + FILE_LOG(logINFO, ("Setting #frames: %lld\n",(long long int)val)); + } retval = set64BitReg(val, SET_FRAMES_LSB_REG, SET_FRAMES_MSB_REG); - printf("Getting #frames: %lld\n",(long long int)retval); + FILE_LOG(logDEBUG1, ("Getting #frames: %lld\n", (long long int)retval)); break; case ACQUISITION_TIME: if(val >= 0){ - printf("\nSetting exptime: %lldns\n", (long long int)val); + FILE_LOG(logINFO, ("Setting exptime: %lldns\n", (long long int)val)); val *= (1E-3 * CLK_RUN); val -= ACQ_TIME_MIN_CLOCK; if(val < 0) val = 0; } retval = (set64BitReg(val, SET_EXPTIME_LSB_REG, SET_EXPTIME_MSB_REG) + ACQ_TIME_MIN_CLOCK) / (1E-3 * CLK_RUN); - printf("Getting exptime: %lldns\n", (long long int)retval); + FILE_LOG(logDEBUG1, ("Getting exptime: %lldns\n", (long long int)retval)); break; case FRAME_PERIOD: if(val >= 0){ - printf("\nSetting period to %lldns\n",(long long int)val); + FILE_LOG(logINFO, ("Setting period: %lldns\n",(long long int)val)); val *= (1E-3 * CLK_SYNC); } retval = set64BitReg(val, SET_PERIOD_LSB_REG, SET_PERIOD_MSB_REG )/ (1E-3 * CLK_SYNC); - printf("Getting period: %lldns\n", (long long int)retval); + FILE_LOG(logDEBUG1, ("Getting period: %lldns\n", (long long int)retval)); break; case DELAY_AFTER_TRIGGER: if(val >= 0){ - printf("\nSetting delay to %lldns\n", (long long int)val); + FILE_LOG(logINFO, ("Setting delay: %lldns\n", (long long int)val)); val *= (1E-3 * CLK_SYNC); } retval = set64BitReg(val, SET_TRIGGER_DELAY_LSB_REG, SET_TRIGGER_DELAY_MSB_REG) / (1E-3 * CLK_SYNC); - printf("Getting delay: %lldns\n", (long long int)retval); + FILE_LOG(logDEBUG1, ("Getting delay: %lldns\n", (long long int)retval)); break; case CYCLES_NUMBER: - if(val >= 0) - printf("\nSetting #cycles to %lld\n", (long long int)val); + if(val >= 0) { + FILE_LOG(logINFO, ("Setting #cycles: %lld\n", (long long int)val)); + } retval = set64BitReg(val, SET_CYCLES_LSB_REG, SET_CYCLES_MSB_REG); - printf("Getting #cycles: %lld\n", (long long int)retval); + FILE_LOG(logDEBUG1, ("Getting #cycles: %lld\n", (long long int)retval)); break; case STORAGE_CELL_NUMBER: if(val >= 0) { - printf("\nSetting #storage cells to %lld\n", (long long int)val); + FILE_LOG(logINFO, ("Setting #storage cells: %lld\n", (long long int)val)); bus_w(CONTROL_REG, (bus_r(CONTROL_REG) & ~CONTROL_STORAGE_CELL_NUM_MSK) | ((val << CONTROL_STORAGE_CELL_NUM_OFST) & CONTROL_STORAGE_CELL_NUM_MSK)); } retval = ((bus_r(CONTROL_REG) & CONTROL_STORAGE_CELL_NUM_MSK) >> CONTROL_STORAGE_CELL_NUM_OFST); - printf("Getting #storage cells: %lld\n", (long long int)retval); + FILE_LOG(logDEBUG1, ("Getting #storage cells: %lld\n", (long long int)retval)); break; default: - cprintf(RED,"Warning: Timer Index not implemented for this detector: %d\n", ind); + FILE_LOG(logERROR, ("Timer Index not implemented for this detector: %d\n", ind)); break; } @@ -786,42 +780,42 @@ int64_t getTimeLeft(enum timerIndex ind){ case FRAME_NUMBER: retval = get64BitReg(GET_FRAMES_LSB_REG, GET_FRAMES_MSB_REG); - printf("Getting number of frames left: %lld\n",(long long int)retval); + FILE_LOG(logINFO, ("Getting number of frames left: %lld\n",(long long int)retval)); break; case FRAME_PERIOD: retval = get64BitReg(GET_PERIOD_LSB_REG, GET_PERIOD_MSB_REG) / (1E-3 * CLK_SYNC); - printf("Getting period left: %lldns\n", (long long int)retval); + FILE_LOG(logINFO, ("Getting period left: %lldns\n", (long long int)retval)); break; /* case DELAY_AFTER_TRIGGER: retval = get64BitReg(xxx) / (1E-3 * CLK_SYNC); - printf("Getting delay left: %lldns\n", (long long int)retval); + FILE_LOG(logINFO, ("Getting delay left: %lldns\n", (long long int)retval)); break; */ case CYCLES_NUMBER: retval = get64BitReg(GET_CYCLES_LSB_REG, GET_CYCLES_MSB_REG); - printf("Getting number of cycles left: %lld\n", (long long int)retval); + FILE_LOG(logINFO, ("Getting number of cycles left: %lld\n", (long long int)retval)); break; case ACTUAL_TIME: retval = get64BitReg(TIME_FROM_START_LSB_REG, TIME_FROM_START_MSB_REG) / (1E-9 * CLK_SYNC); - printf("Getting actual time (time from start): %lld\n", (long long int)retval); + FILE_LOG(logINFO, ("Getting actual time (time from start): %lld\n", (long long int)retval)); break; case MEASUREMENT_TIME: retval = get64BitReg(START_FRAME_TIME_LSB_REG, START_FRAME_TIME_MSB_REG) / (1E-9 * CLK_SYNC); - printf("Getting measurement time (timestamp/ start frame time): %lld\n", (long long int)retval); + FILE_LOG(logINFO, ("Getting measurement time (timestamp/ start frame time): %lld\n", (long long int)retval)); break; case FRAMES_FROM_START: case FRAMES_FROM_START_PG: retval = get64BitReg(FRAMES_FROM_START_PG_LSB_REG, FRAMES_FROM_START_PG_MSB_REG); - printf("Getting frames from start run control %lld\n", (long long int)retval); + FILE_LOG(logINFO, ("Getting frames from start run control %lld\n", (long long int)retval)); break; default: - cprintf(RED, "Warning: Remaining Timer index not implemented for this detector: %d\n", ind); + FILE_LOG(logERROR, ("Remaining Timer index not implemented for this detector: %d\n", ind)); break; } @@ -836,25 +830,29 @@ int64_t getTimeLeft(enum timerIndex ind){ /* parameters - channel, chip, module, settings */ -int setModule(sls_detector_module myMod){ - int retval[2]; - int i; +int setModule(sls_detector_module myMod, char* mess){ - //#ifdef VERBOSE - printf("Setting module with settings %d\n",myMod.reg); - //#endif + FILE_LOG(logINFO, ("Setting module with settings %d\n",myMod.reg)); + // settings setSettings( (enum detectorSettings)myMod.reg); //copy module locally - if (detectorModules) - copyModule(detectorModules,&myMod); + if (detectorModules) { + if (copyModule(detectorModules, &myMod) == FAIL) { + sprintf(mess, "Could not copy module\n"); + FILE_LOG(logERROR, (mess)); + return FAIL; + } + } - //set dac values - for(i=0;i vmax)) { - cprintf(RED,"Voltage value (to convert to dac value) is outside bounds: %d\n", value); + FILE_LOG(logERROR, ("Voltage value (to convert to dac value) is outside bounds: %d\n", value)); return -1; } return (int)(((value - vmin) / (vmax - vmin)) * (nsteps - 1) + 0.5); @@ -1022,7 +1021,7 @@ int dacToVoltage(unsigned int digital){ int nsteps = 4096; int v = vmin + (vmax - vmin) * digital / (nsteps - 1); if((v < 0) || (v > nsteps - 1)) { - cprintf(RED,"Voltage value (converted from dac value) is outside bounds: %d\n", v); + FILE_LOG(logERROR, ("Voltage value (converted from dac value) is outside bounds: %d\n", v)); return -1; } return v; @@ -1046,21 +1045,21 @@ void setDAC(enum DACINDEX ind, int val, int mV, int retval[]){ int csdx = ind / NDAC + DAC_SERIAL_CS_OUT_OFST; // old board (16 dacs),so can be DAC_SERIAL_CS_OUT_OFST or +1 int dacchannel = ind % NDAC; // 0-8, dac channel number (also for dacnum 9-15 in old board) - printf("\nSetting of DAC %d : %d dac units (%d mV)\n",ind, dacval, val); + FILE_LOG(logINFO, ("Setting DAC %d: %d dac (%d mV)\n",ind, dacval, val)); // command if (val >= 0) { - printf(" Write to Input Register and Update\n"); + FILE_LOG(logDEBUG1,("\tWrite to Input Register and Update\n")); codata = LTC2620_DAC_CMD_SET; } else if (val == -100) { - printf(" POWER DOWN\n"); + FILE_LOG(logDEBUG1, ("\tPOWER DOWN\n")); codata = LTC2620_DAC_CMD_POWER_DOWN; } // address - printf(" Chip select bit:%d\n" - " Dac Channel:0x%x\n" - " Dac Value:0x%x\n", - csdx, dacchannel, val); + FILE_LOG(logDEBUG1, ("\tChip select bit:%d\n" + "\tDac Channel:0x%x\n" + "\tDac Value:0x%x\n", + csdx, dacchannel, val)); codata += ((dacchannel << LTC2620_DAC_ADDR_OFST) & LTC2620_DAC_ADDR_MSK) + ((val << LTC2620_DAC_DATA_OFST) & LTC2620_DAC_DATA_MSK); // to spi @@ -1076,9 +1075,9 @@ void setDAC(enum DACINDEX ind, int val, int mV, int retval[]){ #endif } - printf("Getting DAC %d : ",ind); - retval[0] = dacValues[ind]; printf("%d dac units ", retval[0]); - retval[1] = dacToVoltage(retval[0]);printf("(%d mV)\n", retval[1]); + retval[0] = dacValues[ind]; + retval[1] = dacToVoltage(retval[0]); + FILE_LOG(logDEBUG1, ("Getting DAC %d : %d dac (%d mV)\n",ind, retval[0], retval[1])); } @@ -1087,7 +1086,7 @@ int getADC(enum ADCINDEX ind){ return 0; #endif char tempnames[2][40]={"VRs/FPGAs Temperature", "ADCs/ASICs Temperature"}; - printf("Getting Temperature for %s\n",tempnames[ind]); + FILE_LOG(logDEBUG1, ("Getting Temperature for %s\n", tempnames[ind])); u_int32_t addr = GET_TEMPERATURE_TMP112_REG; uint32_t regvalue = bus_r(addr); uint32_t value = regvalue & TEMPERATURE_VALUE_MSK; @@ -1104,7 +1103,7 @@ int getADC(enum ADCINDEX ind){ // conversion retval *= 625.0/10.0; - printf("\nReal Temperature %s: %f °C\n",tempnames[ind],retval/1000.00); + FILE_LOG(logINFO, ("Temperature %s: %f °C\n",tempnames[ind],retval/1000.00)); return retval; } @@ -1131,7 +1130,7 @@ int setHighVoltage(int val){ dacvalue = 1. + (200.-val) / alpha; val=200.-(dacvalue-1)*alpha; } - printf ("\nSetting High voltage to %d (dacval %d)\n",val, dacvalue); + FILE_LOG(logINFO, ("Setting High voltage: %d (dacval %d)\n",val, dacvalue)); dacvalue &= MAX1932_HV_DATA_MSK; serializeToSPI(SPI_REG, dacvalue, HV_SERIAL_CS_OUT_MSK, MAX1932_HV_NUMBITS, HV_SERIAL_CLK_OUT_MSK, HV_SERIAL_DIGITAL_OUT_MSK, HV_SERIAL_DIGITAL_OUT_OFST); @@ -1148,23 +1147,31 @@ int setHighVoltage(int val){ /* parameters - timing, extsig */ -enum externalCommunicationMode setTiming( enum externalCommunicationMode arg){ +void setTiming( enum externalCommunicationMode arg){ if(arg != GET_EXTERNAL_COMMUNICATION_MODE){ switch((int)arg){ - case AUTO_TIMING: bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) & ~EXT_SIGNAL_MSK); break; - case TRIGGER_EXPOSURE: bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) | EXT_SIGNAL_MSK); break; + case AUTO_TIMING: + FILE_LOG(logINFO, ("Set Timing: Auto\n")); + bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) & ~EXT_SIGNAL_MSK); + break; + case TRIGGER_EXPOSURE: + FILE_LOG(logINFO, ("Set Timing: Trigger\n")); + bus_w(EXT_SIGNAL_REG, bus_r(EXT_SIGNAL_REG) | EXT_SIGNAL_MSK); + break; default: - cprintf(RED,"Unknown timing mode %d\n", arg); - return GET_EXTERNAL_COMMUNICATION_MODE; + FILE_LOG(logERROR, ("Unknown timing mode %d\n", arg)); + return; } } - if (bus_r(EXT_SIGNAL_REG) == EXT_SIGNAL_MSK) - return TRIGGER_EXPOSURE; - return AUTO_TIMING; } +enum externalCommunicationMode getTiming() { + if (bus_r(EXT_SIGNAL_REG) == EXT_SIGNAL_MSK) + return TRIGGER_EXPOSURE; + return AUTO_TIMING; +} @@ -1192,7 +1199,7 @@ long int calcChecksum(int sourceip, int destip) { ip.ip_destip = destip; count = sizeof(ip); - addr =& (ip); /* warning: assignment from incompatible pointer type */ + addr = (unsigned short*) &(ip); /* warning: assignment from incompatible pointer type */ while( count > 1 ) { sum += *addr++; count -= 2; @@ -1201,90 +1208,73 @@ long int calcChecksum(int sourceip, int destip) { while (sum>>16) sum = (sum & 0xffff) + (sum >> 16);// Fold 32-bit sum to 16 bits checksum = (~sum) & 0xffff; - printf("IP checksum is 0x%lx\n",checksum); + FILE_LOG(logINFO, ("IP checksum is 0x%lx\n",checksum)); return checksum; } -int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t sourceip, uint32_t udpport, uint32_t udpport2, int ival){ +int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t sourceip, uint32_t udpport, uint32_t udpport2){ #ifdef VIRTUAL return 0; #endif - cprintf(BLUE, "\n*** Configuring MAC ***\n"); + FILE_LOG(logINFOBLUE, ("Configuring MAC\n")); uint32_t sourceport = DEFAULT_TX_UDP_PORT; - printf("Source IP : %d.%d.%d.%d \t\t(0x%08x)\n",(sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff, sourceip); - printf("Source MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n", + FILE_LOG(logINFO, ("\tSource IP : %d.%d.%d.%d \t\t(0x%08x)\n", + (sourceip>>24)&0xff,(sourceip>>16)&0xff,(sourceip>>8)&0xff,(sourceip)&0xff, sourceip)); + FILE_LOG(logINFO, ("\tSource MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n", (unsigned int)((sourcemac>>40)&0xFF), (unsigned int)((sourcemac>>32)&0xFF), (unsigned int)((sourcemac>>24)&0xFF), (unsigned int)((sourcemac>>16)&0xFF), (unsigned int)((sourcemac>>8)&0xFF), (unsigned int)((sourcemac>>0)&0xFF), - (long long unsigned int)sourcemac); - printf("Source Port : %d \t\t\t(0x%08x)\n",sourceport, sourceport); + (long long unsigned int)sourcemac)); + FILE_LOG(logINFO, ("\tSource Port : %d \t\t\t(0x%08x)\n",sourceport, sourceport)); - printf("Dest. IP : %d.%d.%d.%d \t\t(0x%08x)\n",(destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff, destip); - printf("Dest. MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n", + FILE_LOG(logINFO, ("\tDest. IP : %d.%d.%d.%d \t\t(0x%08x)\n", + (destip>>24)&0xff,(destip>>16)&0xff,(destip>>8)&0xff,(destip)&0xff, destip)); + FILE_LOG(logINFO, ("\tDest. MAC : %02x:%02x:%02x:%02x:%02x:%02x \t(0x%010llx)\n", (unsigned int)((destmac>>40)&0xFF), (unsigned int)((destmac>>32)&0xFF), (unsigned int)((destmac>>24)&0xFF), (unsigned int)((destmac>>16)&0xFF), (unsigned int)((destmac>>8)&0xFF), (unsigned int)((destmac>>0)&0xFF), - (long long unsigned int)destmac); - printf("Dest. Port : %d \t\t\t(0x%08x)\n",udpport, udpport); + (long long unsigned int)destmac)); + FILE_LOG(logINFO, ("\tDest. Port : %d \t\t\t(0x%08x)\n",udpport, udpport)); long int checksum=calcChecksum(sourceip, destip); bus_w(TX_IP_REG, sourceip); bus_w(RX_IP_REG, destip); -/* - bus_w(TX_MAC_LSB_REG,(destmac>>32)&0xFFFFFFFF);//rx_udpmacH_AReg_c - bus_w(TX_MAC_MSB_REG,(destmac)&0xFFFFFFFF);//rx_udpmacL_AReg_c - bus_w(RX_MAC_MSB_REG,(sourcemac>>32)&0xFFFFFFFF);//detectormacH_AReg_c - bus_w(RX_MAC_LSB_REG,(sourcemac)&0xFFFFFFFF);//detectormacL_AReg_c - bus_w(UDP_PORT_REG,((sourceport&0xFFFF)<<16)+(udpport&0xFFFF));//udpports_AReg_c -*/ uint32_t val = 0; val = ((sourcemac >> LSB_OF_64_BIT_REG_OFST) & BIT_32_MSK); bus_w(TX_MAC_LSB_REG, val); -#ifdef VERBOSE - printf("Read from TX_MAC_LSB_REG: 0x%08x\n", bus_r(TX_MAC_LSB_REG)); -#endif + FILE_LOG(logDEBUG1, ("Read from TX_MAC_LSB_REG: 0x%08x\n", bus_r(TX_MAC_LSB_REG))); val = ((sourcemac >> MSB_OF_64_BIT_REG_OFST) & BIT_32_MSK); bus_w(TX_MAC_MSB_REG,val); -#ifdef VERBOSE - printf("Read from TX_MAC_MSB_REG: 0x%08x\n", bus_r(TX_MAC_MSB_REG)); -#endif + FILE_LOG(logDEBUG1, ("Read from TX_MAC_MSB_REG: 0x%08x\n", bus_r(TX_MAC_MSB_REG))); val = ((destmac >> LSB_OF_64_BIT_REG_OFST) & BIT_32_MSK); bus_w(RX_MAC_LSB_REG, val); -#ifdef VERBOSE - printf("Read from RX_MAC_LSB_REG: 0x%08x\n", bus_r(RX_MAC_LSB_REG)); -#endif + FILE_LOG(logDEBUG1, ("Read from RX_MAC_LSB_REG: 0x%08x\n", bus_r(RX_MAC_LSB_REG))); val = ((destmac >> MSB_OF_64_BIT_REG_OFST) & BIT_32_MSK); bus_w(RX_MAC_MSB_REG, val); -#ifdef VERBOSE - printf("Read from RX_MAC_MSB_REG: 0x%08x\n", bus_r(RX_MAC_MSB_REG)); -#endif + FILE_LOG(logDEBUG1, ("Read from RX_MAC_MSB_REG: 0x%08x\n", bus_r(RX_MAC_MSB_REG))); val = (((sourceport << UDP_PORT_TX_OFST) & UDP_PORT_TX_MSK) | ((udpport << UDP_PORT_RX_OFST) & UDP_PORT_RX_MSK)); bus_w(UDP_PORT_REG, val); -#ifdef VERBOSE - printf("Read from UDP_PORT_REG: 0x%08x\n", bus_r(UDP_PORT_REG)); -#endif + FILE_LOG(logDEBUG1, ("Read from UDP_PORT_REG: 0x%08x\n", bus_r(UDP_PORT_REG))); bus_w(TX_IP_CHECKSUM_REG,(checksum << TX_IP_CHECKSUM_OFST) & TX_IP_CHECKSUM_MSK); -#ifdef VERBOSE - printf("Read from TX_IP_CHECKSUM_REG: 0x%08x\n", bus_r(TX_IP_CHECKSUM_REG)); -#endif + FILE_LOG(logDEBUG1, ("Read from TX_IP_CHECKSUM_REG: 0x%08x\n", bus_r(TX_IP_CHECKSUM_REG))); cleanFifos(); resetCore(); @@ -1295,7 +1285,7 @@ int configureMAC(uint32_t destip, uint64_t destmac, uint64_t sourcemac, uint32_t int setDetectorPosition(int pos[]) { int ret = OK; - + FILE_LOG(logDEBUG1, ("Setting detector position: (%d, %d), reserved: %d\n", pos[0], pos[1], pos[2])); bus_w(COORD_0_REG, bus_r(COORD_0_REG) | ((pos[0] << COORD_0_X_OFST) & COORD_0_X_MSK)); if ((bus_r(COORD_0_REG) & COORD_0_X_MSK) != ((pos[0] << COORD_0_X_OFST) & COORD_0_X_MSK)) ret = FAIL; @@ -1308,8 +1298,9 @@ int setDetectorPosition(int pos[]) { if ((bus_r(COORD_1_REG) & COORD_0_Z_MSK) != ((pos[2] << COORD_0_Z_OFST) & COORD_0_Z_MSK)) ret = FAIL; - if (ret == OK) - printf("Position set to [%d, %d, %d]\n", pos[0], pos[1], pos[2]); + if (ret == OK) { + FILE_LOG(logINFO, ("Position set to [%d, %d, %d]\n", pos[0], pos[1], pos[2])); + } return ret; } @@ -1323,6 +1314,7 @@ void resetPLL() { #ifdef VIRTUAL return; #endif + FILE_LOG(logINFO, ("Resetting PLL\n")); // reset PLL Reconfiguration and PLL bus_w(PLL_CONTROL_REG, bus_r(PLL_CONTROL_REG) | PLL_CTRL_RECONFIG_RST_MSK | PLL_CTRL_RST_MSK); usleep(100); @@ -1334,6 +1326,7 @@ u_int32_t setPllReconfigReg(u_int32_t reg, u_int32_t val) { #ifdef VIRTUAL return val; #endif + FILE_LOG(logINFO, ("Setting PLL Reconfig Reg\n")); // set parameter bus_w(PLL_PARAM_REG, val); @@ -1363,7 +1356,7 @@ void configurePll() { return; } - printf("Configuring PLL with phase in %d\n", clkPhase[1]); + FILE_LOG(logINFO, ("\tConfiguring PLL with phase in %d\n", clkPhase[1])); if (clkPhase[1]>0) { inv=0; phase=clkPhase[1]; @@ -1371,18 +1364,18 @@ void configurePll() { inv=1; phase=-1*clkPhase[1]; } - printf(" phase out %d (0x%08x)\n", phase, phase); + FILE_LOG(logDEBUG1, ("\tphase out %d (0x%08x)\n", phase, phase)); if (inv) { val = ((phase << PLL_SHIFT_NUM_SHIFTS_OFST) & PLL_SHIFT_NUM_SHIFTS_MSK) + PLL_SHIFT_CNT_SLCT_C1_VAL + PLL_SHIFT_UP_DOWN_NEG_VAL; - printf(" phase word 0x%08x\n", val); + FILE_LOG(logDEBUG1, ("\tphase word 0x%08x\n", val)); setPllReconfigReg(PLL_PHASE_SHIFT_REG, val); } else { val = ((phase << PLL_SHIFT_NUM_SHIFTS_OFST) & PLL_SHIFT_NUM_SHIFTS_MSK) + PLL_SHIFT_CNT_SLCT_C0_VAL + PLL_SHIFT_UP_DOWN_NEG_VAL; - printf(" phase word 0x%08x\n", val); + FILE_LOG(logDEBUG1, ("\tphase word 0x%08x\n", val)); setPllReconfigReg(PLL_PHASE_SHIFT_REG, val); - printf(" phase word 0x%08x\n", val); + FILE_LOG(logDEBUG1, ("\tphase word 0x%08x\n", val)); val = ((phase << PLL_SHIFT_NUM_SHIFTS_OFST) & PLL_SHIFT_NUM_SHIFTS_MSK) + PLL_SHIFT_CNT_SLCT_C2_VAL; setPllReconfigReg(PLL_PHASE_SHIFT_REG, val); } @@ -1394,23 +1387,21 @@ void configurePll() { int setThresholdTemperature(int val) { if (val >= 0) { - printf("\nThreshold Temperature: %d\n", val); - + FILE_LOG(logINFO, ("Setting Threshold Temperature: %f °C\n", val/1000.00)); val *= (10.0/625.0); -#ifdef VERBOSE - printf("Converted Threshold Temperature: %d\n", val); -#endif + FILE_LOG(logDEBUG1, ("Converted Threshold Temperature: %d\n", val)); bus_w(TEMP_CTRL_REG, (bus_r(TEMP_CTRL_REG) &~(TEMP_CTRL_PROTCT_THRSHLD_MSK) &~(TEMP_CTRL_OVR_TMP_EVNT_MSK)) | (((val << TEMP_CTRL_PROTCT_THRSHLD_OFST) & TEMP_CTRL_PROTCT_THRSHLD_MSK))); -#ifdef VERBOSE - printf("Converted Threshold Temperature set to %d\n", ((bus_r(TEMP_CTRL_REG) & TEMP_CTRL_PROTCT_THRSHLD_MSK) >> TEMP_CTRL_PROTCT_THRSHLD_OFST)); -#endif + FILE_LOG(logDEBUG1, ("Converted Threshold Temperature set to %d\n", + ((bus_r(TEMP_CTRL_REG) & TEMP_CTRL_PROTCT_THRSHLD_MSK) >> TEMP_CTRL_PROTCT_THRSHLD_OFST))); } uint32_t temp = ((bus_r(TEMP_CTRL_REG) & TEMP_CTRL_PROTCT_THRSHLD_MSK) >> TEMP_CTRL_PROTCT_THRSHLD_OFST); // conversion - temp *= (625.0/10.0); - printf("Threshold Temperature %f °C\n",(double)temp/1000.00); + temp = (temp * (625.0/10.0)); + + float ftemp = (double)temp/1000.00; + FILE_LOG(logDEBUG1, ("Threshold Temperature read %f °C\n",ftemp)); return temp; @@ -1421,12 +1412,11 @@ int setTemperatureControl(int val) { if (val >= 0) { // binary value if (val > 0 ) val = 1; - printf("\nTemperature control: %d\n", val); + FILE_LOG(logINFO, ("Setting Temperature control: %d\n", val)); bus_w(TEMP_CTRL_REG, (bus_r(TEMP_CTRL_REG) &~(TEMP_CTRL_PROTCT_ENABLE_MSK) &~(TEMP_CTRL_OVR_TMP_EVNT_MSK)) | (((val << TEMP_CTRL_PROTCT_ENABLE_OFST) & TEMP_CTRL_PROTCT_ENABLE_MSK))); -#ifdef VERBOSE - printf("Temperature control set to %d\n", ((bus_r(TEMP_CTRL_REG) & TEMP_CTRL_PROTCT_ENABLE_MSK) >> TEMP_CTRL_PROTCT_ENABLE_OFST)); -#endif + FILE_LOG(logDEBUG1, ("Temperature control read: %d\n", + ((bus_r(TEMP_CTRL_REG) & TEMP_CTRL_PROTCT_ENABLE_MSK) >> TEMP_CTRL_PROTCT_ENABLE_OFST))); } return ((bus_r(TEMP_CTRL_REG) & TEMP_CTRL_PROTCT_ENABLE_MSK) >> TEMP_CTRL_PROTCT_ENABLE_OFST); } @@ -1439,12 +1429,11 @@ int setTemperatureEvent(int val) { if (val >= 0) { // set bit to clear it val = 1; - printf("\nTemperature Event: %d\n", val); + FILE_LOG(logINFO, ("Setting Temperature Event (clearing): %d\n", val)); bus_w(TEMP_CTRL_REG, (bus_r(TEMP_CTRL_REG) &~TEMP_CTRL_OVR_TMP_EVNT_MSK) | (((val << TEMP_CTRL_OVR_TMP_EVNT_OFST) & TEMP_CTRL_OVR_TMP_EVNT_MSK))); -#ifdef VERBOSE - printf("Temperature Event set to %d\n", ((bus_r(TEMP_CTRL_REG) & TEMP_CTRL_OVR_TMP_EVNT_MSK) >> TEMP_CTRL_OVR_TMP_EVNT_OFST)); -#endif + FILE_LOG(logDEBUG1, ("Temperature Event read %d\n", + ((bus_r(TEMP_CTRL_REG) & TEMP_CTRL_OVR_TMP_EVNT_MSK) >> TEMP_CTRL_OVR_TMP_EVNT_OFST))); } return ((bus_r(TEMP_CTRL_REG) & TEMP_CTRL_OVR_TMP_EVNT_MSK) >> TEMP_CTRL_OVR_TMP_EVNT_OFST); } @@ -1456,16 +1445,15 @@ int setNetworkParameter(enum NETWORKINDEX mode, int value) { return -1; if (value >= 0) { - printf("\nSetting transmission delay: %d\n", value); + FILE_LOG(logINFO, ("Setting transmission delay: %d\n", value)); bus_w(CONFIG_REG, (bus_r(CONFIG_REG) &~CONFIG_TDMA_TIMESLOT_MSK) | (((value << CONFIG_TDMA_TIMESLOT_OFST) & CONFIG_TDMA_TIMESLOT_MSK))); if (value == 0) bus_w(CONFIG_REG, bus_r(CONFIG_REG) &~ CONFIG_TDMA_MSK); else bus_w(CONFIG_REG, bus_r(CONFIG_REG) | CONFIG_TDMA_MSK); -#ifdef VERBOSE - printf("Transmission delay set to %d\n", ((bus_r(CONFIG_REG) & CONFIG_TDMA_TIMESLOT_MSK) >> CONFIG_TDMA_TIMESLOT_OFST)); -#endif + FILE_LOG(logDEBUG1, ("Transmission delay read %d\n", + ((bus_r(CONFIG_REG) & CONFIG_TDMA_TIMESLOT_MSK) >> CONFIG_TDMA_TIMESLOT_OFST))); } return ((bus_r(CONFIG_REG) & CONFIG_TDMA_TIMESLOT_MSK) >> CONFIG_TDMA_TIMESLOT_OFST); @@ -1483,13 +1471,13 @@ int startStateMachine(){ virtual_stop = 0; if(pthread_create(&pthread_virtual_tid, NULL, &start_timer, NULL)) { virtual_status = 0; - cprintf(RED,"Could not start Virtual acquisition thread\n"); + FILE_LOG(logERROR, ("Could not start Virtual acquisition thread\n")); return FAIL; } - cprintf(GREEN,"***Virtual Acquisition started\n"); + FILE_LOG(logINFOGREEN, ("Virtual Acquisition started\n")); return OK; #endif - printf("*******Starting State Machine*******\n"); + FILE_LOG(logINFOBLUE, ("Starting State Machine\n")); cleanFifos(); @@ -1497,7 +1485,7 @@ int startStateMachine(){ bus_w(CONTROL_REG, bus_r(CONTROL_REG) | CONTROL_START_ACQ_MSK); bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_START_ACQ_MSK); - printf("Status Register: %08x\n",bus_r(STATUS_REG)); + FILE_LOG(logINFO, ("Status Register: %08x\n",bus_r(STATUS_REG))); return OK; } @@ -1508,12 +1496,12 @@ void* start_timer(void* arg) { setTimer(CYCLES_NUMBER, -1) * (setTimer(STORAGE_CELL_NUMBER, -1) + 1) * (setTimer(FRAME_PERIOD, -1)/(1E9))); - cprintf(GREEN,"going to wait for %d s\n", wait_in_s); + FILE_LOG(logDEBUG1, ("going to wait for %d s\n", wait_in_s)); while(!virtual_stop && (wait_in_s >= 0)) { usleep(1000 * 1000); wait_in_s--; } - cprintf(GREEN,"Virtual Timer Done***\n"); + FILE_LOG(logINFOGREEN, ("Virtual Timer Done\n")); virtual_status = 0; return NULL; @@ -1521,7 +1509,7 @@ void* start_timer(void* arg) { #endif int stopStateMachine(){ - cprintf(BG_RED,"*******Stopping State Machine*******\n"); + FILE_LOG(logINFORED, ("Stopping State Machine\n")); #ifdef VIRTUAL virtual_stop = 0; return OK; @@ -1531,7 +1519,7 @@ int stopStateMachine(){ usleep(100); bus_w(CONTROL_REG, bus_r(CONTROL_REG) & ~CONTROL_STOP_ACQ_MSK); - printf("Status Register: %08x\n",bus_r(STATUS_REG)); + FILE_LOG(logINFO, ("Status Register: %08x\n",bus_r(STATUS_REG))); return OK; } @@ -1542,47 +1530,45 @@ int stopStateMachine(){ enum runStatus getRunStatus(){ #ifdef VIRTUAL if(virtual_status == 0){ - printf("Status: IDLE\n"); + FILE_LOG(logINFOBLUE, ("Status: IDLE\n")); return IDLE; }else{ - printf("Status: RUNNING...\n"); + FILE_LOG(logINFOBLUE, ("Status: RUNNING\n")); return RUNNING; } #endif -#ifdef VERBOSE - printf("Getting status\n"); -#endif + FILE_LOG(logDEBUG1, ("Getting status\n")); enum runStatus s; u_int32_t retval = bus_r(STATUS_REG); - printf("Status Register: %08x\n",retval); + FILE_LOG(logINFO, ("Status Register: %08x\n",retval)); //running if(((retval & RUN_BUSY_MSK) >> RUN_BUSY_OFST)) { if ((retval & WAITING_FOR_TRIGGER_MSK) >> WAITING_FOR_TRIGGER_OFST) { - printf("-----------------------------------WAITING-----------------------------------\n"); - s=WAITING; + FILE_LOG(logINFOBLUE, ("Status: WAITING\n")); + s = WAITING; } else{ - printf("-----------------------------------RUNNING-----------------------------------\n"); - s=RUNNING; + FILE_LOG(logINFOBLUE, ("Status: RUNNING\n")); + s = RUNNING; } } //not running else { if ((retval & STOPPED_MSK) >> STOPPED_OFST) { - printf("-----------------------------------STOPPED--------------------------\n"); - s=STOPPED; + FILE_LOG(logINFOBLUE, ("Status: STOPPED\n")); + s = STOPPED; } else if ((retval & RUNMACHINE_BUSY_MSK) >> RUNMACHINE_BUSY_OFST) { - printf("-----------------------------------READ MACHINE BUSY--------------------------\n"); - s=TRANSMITTING; + FILE_LOG(logINFOBLUE, ("Status: READ MACHINE BUSY\n")); + s = TRANSMITTING; } else if (!retval) { - printf("-----------------------------------IDLE--------------------------------------\n"); - s=IDLE; + FILE_LOG(logINFOBLUE, ("Status: IDLE\n")); + s = IDLE; } else { - printf("-----------------------------------Unknown status %08x--------------------------------------\n", retval); - s=ERROR; + FILE_LOG(logERROR, ("Status: Unknown status %08x\n", retval)); + s = ERROR; } } @@ -1594,7 +1580,7 @@ enum runStatus getRunStatus(){ void readFrame(int *ret, char *mess){ #ifdef VIRTUAL while(virtual_status) { - //cprintf(RED,"Waiting for finished flag\n"); + //FILE_LOG(logERROR, ("Waiting for finished flag\n"); usleep(5000); } return; @@ -1608,11 +1594,11 @@ void readFrame(int *ret, char *mess){ int64_t retval = getTimeLeft(FRAME_NUMBER) + 1; if ( retval > 0) { *ret = (int)FAIL; - sprintf(mess,"no data and run stopped: %lld frames left\n",(long long int)retval); - cprintf(RED,"%s\n",mess); + sprintf(mess,"No data and run stopped: %lld frames left\n",(long long int)retval); + FILE_LOG(logERROR, (mess)); } else { *ret = (int)OK; - cprintf(GREEN, "acquisition successfully finished\n"); + FILE_LOG(logINFOGREEN, ("Acquisition successfully finished\n")); } } @@ -1623,9 +1609,7 @@ u_int32_t runBusy(void) { return virtual_status; #endif u_int32_t s = ((bus_r(STATUS_REG) & RUN_BUSY_MSK) >> RUN_BUSY_OFST); -#ifdef VERBOSE - printf("Status Register: %08x\n", s); -#endif + FILE_LOG(logDEBUG1, ("Status Register: %08x\n", s)); return s; } @@ -1644,51 +1628,40 @@ int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod){ int idac, iadc; int ret=OK; -#ifdef VERBOSE - printf("Copying module %x to module %x\n",srcMod,destMod); -#endif + FILE_LOG(logDEBUG1, ("Copying module\n")); if (srcMod->serialnumber>=0){ destMod->serialnumber=srcMod->serialnumber; } if ((srcMod->nchip)>(destMod->nchip)) { - printf("Number of chip of source is larger than number of chips of destination\n"); + FILE_LOG(logERROR, ("Number of chip of source is larger than number of chips of destination\n")); return FAIL; } if ((srcMod->nchan)>(destMod->nchan)) { - printf("Number of channels of source is larger than number of channels of destination\n"); + FILE_LOG(logERROR, ("Number of channels of source is larger than number of channels of destination\n")); return FAIL; } if ((srcMod->ndac)>(destMod->ndac)) { - printf("Number of dacs of source is larger than number of dacs of destination\n"); + FILE_LOG(logERROR, ("Number of dacs of source is larger than number of dacs of destination\n")); return FAIL; } if ((srcMod->nadc)>(destMod->nadc)) { - printf("Number of dacs of source is larger than number of dacs of destination\n"); + FILE_LOG(logERROR, ("Number of dacs of source is larger than number of dacs of destination\n")); return FAIL; } -#ifdef VERBOSE - printf("DACs: src %d, dest %d\n",srcMod->ndac,destMod->ndac); - printf("ADCs: src %d, dest %d\n",srcMod->nadc,destMod->nadc); - printf("Chips: src %d, dest %d\n",srcMod->nchip,destMod->nchip); - printf("Chans: src %d, dest %d\n",srcMod->nchan,destMod->nchan); - -#endif + FILE_LOG(logDEBUG1, ("DACs: src %d, dest %d\n",srcMod->ndac,destMod->ndac)); + FILE_LOG(logDEBUG1, ("ADCs: src %d, dest %d\n",srcMod->nadc,destMod->nadc)); + FILE_LOG(logDEBUG1, ("Chips: src %d, dest %d\n",srcMod->nchip,destMod->nchip)); + FILE_LOG(logDEBUG1, ("Chans: src %d, dest %d\n",srcMod->nchan,destMod->nchan)); destMod->ndac=srcMod->ndac; destMod->nadc=srcMod->nadc; destMod->nchip=srcMod->nchip; destMod->nchan=srcMod->nchan; if (srcMod->reg>=0) destMod->reg=srcMod->reg; -#ifdef VERBOSE - printf("Copying register %x (%x)\n",destMod->reg,srcMod->reg ); -#endif - if (srcMod->gain>=0) - destMod->gain=srcMod->gain; - if (srcMod->offset>=0) - destMod->offset=srcMod->offset; + FILE_LOG(logDEBUG1, ("Copying register %x (%x)\n",destMod->reg,srcMod->reg )); for (idac=0; idac<(srcMod->ndac); idac++) { if (*((srcMod->dacs)+idac)>=0) diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h index ef382ad5f..7911f0fa1 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h @@ -3,14 +3,14 @@ #include "sls_detector_defs.h" //default dynamicgain in settings #include "RegisterDefs.h" -#include - #define GOODBYE (-200) #define MIN_REQRD_VRSN_T_RD_API 0x171220 #define REQRD_FRMWR_VRSN 0x180615 +#define PROGRAMMING_MODE (0x2) +#define BOARD_JUNGFRAU_TYPE (8) /* Struct Definitions */ typedef struct ip_header_struct { diff --git a/slsDetectorServers/slsDetectorServer/AD9257.h b/slsDetectorServers/slsDetectorServer/AD9257.h index a716af64c..615fdb3c0 100755 --- a/slsDetectorServers/slsDetectorServer/AD9257.h +++ b/slsDetectorServers/slsDetectorServer/AD9257.h @@ -1,10 +1,7 @@ #ifndef AD9257_H #define AD9257_H -#include "ansi.h" - -#include "commonServerFunctions.h" -#include +#include "commonServerFunctions.h" // blackfin.h, ansi.h /* AD9257 ADC DEFINES */ #define AD9257_ADC_NUMBITS (24) @@ -81,36 +78,36 @@ void setAdc(int addr, int val) { u_int32_t codata; codata = val + (addr << 8); - printf(" Setting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr); + FILE_LOG(logINFO, ("\tSetting ADC SPI Register. Wrote 0x%04x at 0x%04x\n", val, addr)); serializeToSPI(ADC_SPI_REG, codata, ADC_SERIAL_CS_OUT_MSK, AD9257_ADC_NUMBITS, ADC_SERIAL_CLK_OUT_MSK, ADC_SERIAL_DATA_OUT_MSK, ADC_SERIAL_DATA_OUT_OFST); } void prepareADC(){ - printf("\n\nPreparing ADC ... \n"); + FILE_LOG(logINFOBLUE, ("Preparing ADC:\n")); //power mode reset - printf("power mode reset:\n"); + FILE_LOG(logINFO, ("\tPower mode reset\n")); setAdc(AD9257_POWER_MODE_REG, (AD9257_INT_RESET_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK); //power mode chip run - printf("power mode chip run:\n"); + FILE_LOG(logINFO, ("\tPower mode chip run\n")); setAdc(AD9257_POWER_MODE_REG, (AD9257_INT_CHIP_RUN_VAL << AD9257_POWER_INTERNAL_OFST) & AD9257_POWER_INTERNAL_MSK); //output clock phase - printf("output clock phase:\n"); + FILE_LOG(logINFO, ("\tOutput clock phase\n")); setAdc(AD9257_OUT_PHASE_REG, (AD9257_OUT_CLK_60_VAL << AD9257_OUT_CLK_OFST) & AD9257_OUT_CLK_MSK); // lvds-iee reduced , binary offset - printf("lvds-iee reduced, binary offset:\n"); + FILE_LOG(logINFO, ("\tLvds-iee reduced, binary offset\n")); setAdc(AD9257_OUT_MODE_REG, (AD9257_OUT_LVDS_IEEE_VAL << AD9257_OUT_LVDS_OPT_OFST) & AD9257_OUT_LVDS_OPT_MSK); // all devices on chip to receive next command - printf("all devices on chip to receive next command:\n"); + FILE_LOG(logINFO, ("\tAll devices on chip to receive next command\n")); setAdc(AD9257_DEV_IND_2_REG, AD9257_CHAN_H_MSK | AD9257_CHAN_G_MSK | AD9257_CHAN_F_MSK | AD9257_CHAN_E_MSK); setAdc(AD9257_DEV_IND_1_REG, @@ -118,21 +115,19 @@ void prepareADC(){ AD9257_CLK_CH_DCO_MSK | AD9257_CLK_CH_IFCO_MSK); // vref 1.33 - printf("vref 1.33:\n"); + FILE_LOG(logINFO, ("\tVref 1.33\n")); setAdc(AD9257_VREF_REG, (AD9257_VREF_1_33_VAL << AD9257_VREF_OFST) & AD9257_VREF_MSK); // no test mode - printf("no test mode:\n"); + FILE_LOG(logINFO, ("\tNo test mode\n")); setAdc(AD9257_TEST_MODE_REG, (AD9257_NONE_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK); #ifdef TESTADC - printf("***************************************** *******\n"); - printf("******* PUTTING ADC IN TEST MODE!!!!!!!!! *******\n"); - printf("***************************************** *******\n"); + FILE_LOG(logINFOBLUE, ("Putting ADC in Test Mode!\n"); // mixed bit frequency test mode - printf("mixed bit frequency test mode:\n"); + FILE_LOG(logINFO, ("\tMixed bit frequency test mode\n")); setAdc(AD9257_TEST_MODE_REG, (AD9257_MIXED_BIT_FREQ_VAL << AD9257_OUT_TEST_OFST) & AD9257_OUT_TEST_MSK); #endif diff --git a/slsDetectorServers/slsDetectorServer/blackfin.h b/slsDetectorServers/slsDetectorServer/blackfin.h index f95cd4ffe..e37dbf50f 100755 --- a/slsDetectorServers/slsDetectorServer/blackfin.h +++ b/slsDetectorServers/slsDetectorServer/blackfin.h @@ -1,9 +1,7 @@ -#ifndef BLACKFIN_H -#define BLACKFIN_H +#pragma once #include "ansi.h" -#include #include // open #include // mmap @@ -73,7 +71,7 @@ int64_t get64BitReg(int aLSB, int aMSB){ vMSB=bus_r(aMSB); v64=vMSB; v64=(v64<<32) | vLSB; - printf(" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64); + FILE_LOG(logDEBUG1, (" reg64(%x,%x) %x %x %llx\n", aLSB, aMSB, vLSB, vMSB, (long long unsigned int)v64)); return v64; } @@ -124,39 +122,33 @@ u_int32_t writeRegister(u_int32_t offset, u_int32_t data) { int mapCSP0(void) { // if not mapped if (CSP0BASE == 0) { - printf("Mapping memory\n"); + FILE_LOG(logINFO, ("Mapping memory\n")); #ifdef VIRTUAL CSP0BASE = malloc(MEM_SIZE); if (CSP0BASE == NULL) { - cprintf(BG_RED, "Error: Could not allocate virtual memory.\n"); + FILE_LOG(logERROR, ("Could not allocate virtual memory.\n")); return FAIL; } - printf("memory allocated\n"); + FILE_LOG(logINFO, (("memory allocated\n")); #else int fd; fd = open("/dev/mem", O_RDWR | O_SYNC, 0); if (fd == -1) { - cprintf(BG_RED, "Error: Can't find /dev/mem\n"); + FILE_LOG(logERROR, ("Can't find /dev/mem\n")); return FAIL; } -#ifdef VERBOSE - printf("/dev/mem opened\n"); -#endif + FILE_LOG(logDEBUG1, ("/dev/mem opened\n")); CSP0BASE = mmap(0, MEM_SIZE, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, CSP0); if (CSP0BASE == MAP_FAILED) { - cprintf(BG_RED, "Error: Can't map memmory area\n"); + FILE_LOG(logERROR, ("Can't map memmory area\n")); return FAIL; } #endif - printf("CSPOBASE mapped from 0x%llx to 0x%llx\n", + FILE_LOG(logINFO, ("CSPOBASE mapped from 0x%llx to 0x%llx\n", (long long unsigned int)CSP0BASE, - (long long unsigned int)(CSP0BASE+MEM_SIZE)); - printf("Status Register: %08x\n",bus_r(STATUS_REG)); - + (long long unsigned int)(CSP0BASE+MEM_SIZE))); + FILE_LOG(logINFO, ("Status Register: %08x\n", bus_r(STATUS_REG))); }else - printf("Memory already mapped before\n"); + FILE_LOG(logINFO, ("Memory already mapped before\n")); return OK; } - - -#endif //BLACKFIN_H diff --git a/slsDetectorServers/slsDetectorServer/commonServerFunctions.h b/slsDetectorServers/slsDetectorServer/commonServerFunctions.h index 55d30b8c4..67651e487 100755 --- a/slsDetectorServers/slsDetectorServer/commonServerFunctions.h +++ b/slsDetectorServers/slsDetectorServer/commonServerFunctions.h @@ -3,6 +3,8 @@ #ifndef GOTTHARDD //gotthard already had bus_w etc defined in its firmware_funcs.c (not yet made with common files) #include "blackfin.h" +#else +#include "ansi.h" #endif /* global variables */ @@ -54,13 +56,11 @@ void sendDataToSPI (u_int32_t* valw, u_int32_t addr, u_int32_t val, int numbitst void serializeToSPI(u_int32_t addr, u_int32_t val, u_int32_t csmask, int numbitstosend, u_int32_t clkmask, u_int32_t digoutmask, int digofset) { -#ifdef VERBOSE - if (numbitstosend == 16) - printf("Writing to SPI Register: 0x%04x\n",val); - else - printf("Writing to SPI Register: 0x%08x\n", val); -#endif - + if (numbitstosend == 16) { + FILE_LOG(logDEBUG1, ("Writing to SPI Register: 0x%04x\n", val)); + } else { + FILE_LOG(logDEBUG1, ("Writing to SPI Register: 0x%08x\n", val)); + } u_int32_t valw; SPIChipSelect (&valw, addr, csmask); diff --git a/slsDetectorServers/slsDetectorServer/communication_funcs.c b/slsDetectorServers/slsDetectorServer/communication_funcs.c index ea89d2747..1a4e7dcaf 100755 --- a/slsDetectorServers/slsDetectorServer/communication_funcs.c +++ b/slsDetectorServers/slsDetectorServer/communication_funcs.c @@ -1,14 +1,15 @@ - - #include "communication_funcs.h" #include "logger.h" -//#include /* for TCP_NODELAY */ -#include #include -#include #include -#include +#include +#include + +#define SEND_REC_MAX_SIZE 4096 +#define DEFAULT_PORTNO 1952 +#define DEFAULT_BACKLOG 5 + // Global variables from errno.h extern int errno; @@ -25,7 +26,6 @@ char mess[MAX_STR_LENGTH]; // Local variables char dummyClientIP[INET_ADDRSTRLEN] = ""; -const int send_rec_max_size = SEND_REC_MAX_SIZE; int myport = -1; // socket descriptor set fd_set readset, tempset; @@ -36,10 +36,6 @@ int isock = 0; int maxfd = 0; - - -#define DEFAULT_BACKLOG 5 - int bindSocket(unsigned short int port_number) { ret = FAIL; int socketDescriptor = -1; @@ -324,7 +320,7 @@ int receiveDataOnly(int file_des, void* buf,int length) { length, (isControlServer ? "control":"stop"))); while(length > 0) { - nreceiving = (length>send_rec_max_size) ? send_rec_max_size:length; // (condition) ? if_true : if_false + nreceiving = (length>SEND_REC_MAX_SIZE) ? SEND_REC_MAX_SIZE:length; // (condition) ? if_true : if_false nreceived = read(file_des,(char*)buf+total_received,nreceiving); if(!nreceived){ if(!total_received) { diff --git a/slsDetectorServers/slsDetectorServer/communication_funcs.h b/slsDetectorServers/slsDetectorServer/communication_funcs.h index 25cb8ef9a..cfe6806bc 100755 --- a/slsDetectorServers/slsDetectorServer/communication_funcs.h +++ b/slsDetectorServers/slsDetectorServer/communication_funcs.h @@ -1,21 +1,9 @@ #ifndef COMMUNICATION_FUNCS_H #define COMMUNICATION_FUNCS_H -#define SEND_REC_MAX_SIZE 4096 -#define DEFAULT_PORTNO 1952 -#include -#include - - -#include -#include -#include -#include #include "sls_detector_defs.h" - - typedef enum{ INT16, INT32, diff --git a/slsDetectorServers/slsDetectorServer/logger.h b/slsDetectorServers/slsDetectorServer/logger.h index 2bf350b2c..1d6d44a79 100644 --- a/slsDetectorServers/slsDetectorServer/logger.h +++ b/slsDetectorServers/slsDetectorServer/logger.h @@ -20,7 +20,7 @@ #endif typedef enum { -logERROR, logWARNING, logINFOBLUE, logINFOGREEN, logINFO, +logERROR, logWARNING, logINFOBLUE, logINFOGREEN, logINFORED, logINFO, logDEBUG, logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4, logDEBUG5 }TLogLevel; @@ -36,6 +36,7 @@ static inline void FILELOG_PrintLog(TLogLevel level, char* m) { case logWARNING: cprintf(YELLOW BOLD, "WARNING: %s", m); break; case logINFOBLUE: cprintf(BLUE, "INFO: %s", m); break; case logINFOGREEN: cprintf(GREEN, "INFO: %s", m); break; + case logINFORED: cprintf(RED, "INFO: %s", m); break; case logINFO: cprintf(RESET, "INFO: %s", m); break; case logDEBUG: cprintf(MAGENTA, "DEBUG: %s", m); break; case logDEBUG1: cprintf(MAGENTA, "DEBUG1: %s", m); break; diff --git a/slsDetectorServers/slsDetectorServer/programfpga.h b/slsDetectorServers/slsDetectorServer/programfpga.h index b37f521de..1b23c0b8a 100755 --- a/slsDetectorServers/slsDetectorServer/programfpga.h +++ b/slsDetectorServers/slsDetectorServer/programfpga.h @@ -1,19 +1,17 @@ -#ifndef PROGRAM_FPGA_H -#define PROGRAM_FPGA_H +#pragma once #include "ansi.h" -#include #include // usleep #include /* global variables */ #define CTRL_SRVR_INIT_TIME_US (300 * 1000) -int gpioDefined=0; -#define MTDSIZE 10 -char mtdvalue[MTDSIZE]; +#define MTDSIZE 10 +int gpioDefined = 0; +char mtdvalue[MTDSIZE] = {0}; /** @@ -27,9 +25,9 @@ void defineGPIOpins(){ //define their direction system("echo in > /sys/class/gpio/gpio7/direction"); system("echo out > /sys/class/gpio/gpio9/direction"); - printf("gpio pins defined\n"); + FILE_LOG(logINFO, ("gpio pins defined\n")); gpioDefined = 1; - }else printf("gpio pins already defined earlier\n"); + }else FILE_LOG(logDEBUG1, ("gpio pins already defined earlier\n")); } /** @@ -54,7 +52,7 @@ void FPGATouchFlash(){ * Reset FPGA */ void resetFPGA(){ - cprintf(BLUE,"\n*** Reseting FPGA ***\n"); + FILE_LOG(logINFOBLUE, ("Reseting FPGA\n")); FPGAdontTouchFlash(); FPGATouchFlash(); usleep(CTRL_SRVR_INIT_TIME_US); @@ -64,14 +62,12 @@ void resetFPGA(){ * Erasing flash */ void eraseFlash(){ -#ifdef VERY_VERBOSE - printf("\nErasing Flash\n"); -#endif + FILE_LOG(logDEBUG1, ("Erasing Flash\n")); char command[255]; memset(command, 0, 255); sprintf(command,"flash_eraseall %s",mtdvalue); system(command); - printf("Flash erased\n"); + FILE_LOG(logINFO, ("Flash erased\n")); } /** @@ -81,43 +77,40 @@ void eraseFlash(){ * @return 0 for success, 1 for fail (cannot open file for writing program) */ int startWritingFPGAprogram(FILE** filefp){ -#ifdef VERY_VERBOSE - printf("\nStart Writing of FPGA program\n"); -#endif + FILE_LOG(logDEBUG1, ("Start Writing of FPGA program\n")); //getting the drive char output[255]; memset(output, 0, 255); FILE* fp = popen("awk \'$4== \"\\\"bitfile(spi)\\\"\" {print $1}\' /proc/mtd", "r"); if (fp == NULL) { - cprintf(RED,"popen returned NULL. Need that to get mtd drive.\n"); + FILE_LOG(logERROR, ("popen returned NULL. Need that to get mtd drive.\n")); return 1; } if (fgets(output, sizeof(output), fp) == NULL) { - cprintf(RED,"fgets returned NULL. Need that to get mtd drive.\n"); + FILE_LOG(logERROR, ("fgets returned NULL. Need that to get mtd drive.\n")); return 1; } pclose(fp); - //cprintf(RED,"output: %s\n", output); memset(mtdvalue, 0, MTDSIZE); strcpy(mtdvalue,"/dev/"); char* pch = strtok(output,":"); if(pch == NULL){ - cprintf(RED,"Could not get mtd value\n"); + FILE_LOG(logERROR, ("Could not get mtd value\n")); return 1; } strcat(mtdvalue,pch); - printf ("\nFlash drive found: %s\n",mtdvalue); + FILE_LOG(logINFO, ("Flash drive found: %s\n", mtdvalue)); FPGAdontTouchFlash(); //writing the program to flash *filefp = fopen(mtdvalue, "w"); if(*filefp == NULL){ - cprintf(RED,"Unable to open %s in write mode\n",mtdvalue); + FILE_LOG(logERROR, ("Unable to open %s in write mode\n", mtdvalue)); return 1; } - printf("Flash ready for writing\n"); + FILE_LOG(logINFO, ("Flash ready for writing\n")); return 0; } @@ -128,9 +121,7 @@ int startWritingFPGAprogram(FILE** filefp){ * @param filefp pointer to flash */ void stopWritingFPGAprogram(FILE* filefp){ -#ifdef VERY_VERBOSE - printf("\nStopping of writing FPGA program\n"); -#endif + FILE_LOG(logDEBUG1, ("Stopping of writing FPGA program\n")); int wait = 0; if(filefp!= NULL){ @@ -142,9 +133,7 @@ void stopWritingFPGAprogram(FILE* filefp){ FPGATouchFlash(); if(wait){ -#ifdef VERY_VERBOSE - printf("Waiting for FPGA to program from flash\n"); -#endif + FILE_LOG(logDEBUG1, ("Waiting for FPGA to program from flash\n")); //waiting for success or done char output[255]; int res=0; @@ -153,12 +142,10 @@ void stopWritingFPGAprogram(FILE* filefp){ fgets(output, sizeof(output), sysFile); pclose(sysFile); sscanf(output,"%d",&res); -#ifdef VERY_VERBOSE - printf("gpi07 returned %d\n",res); -#endif + FILE_LOG(logDEBUG1, ("gpi07 returned %d\n", res)); } } - printf("FPGA has picked up the program from flash\n\n"); + FILE_LOG(logINFO, ("FPGA has picked up the program from flash\n")); } @@ -170,21 +157,15 @@ void stopWritingFPGAprogram(FILE* filefp){ * @return 0 for success, 1 for fail (cannot write) */ int writeFPGAProgram(char* fpgasrc, size_t fsize, FILE* filefp){ -#ifdef VERY_VERBOSE - printf("\nWriting of FPGA Program\n"); - cprintf(BLUE,"address of fpgasrc:%p\n",(void *)fpgasrc); - cprintf(BLUE,"fsize:%lu\n",fsize); - cprintf(BLUE,"pointer:%p\n",(void*)filefp); -#endif + FILE_LOG(logDEBUG1, ("Writing of FPGA Program\n" + "\taddress of fpgasrc:%p\n" + "\tfsize:%lu\n\tpointer:%p\n", + (void *)fpgasrc, fsize, (void*)filefp)); if(fwrite((void*)fpgasrc , sizeof(char) , fsize , filefp )!= fsize){ - cprintf(RED,"Could not write FPGA source to flash (size:%lu)\n", fsize); + FILE_LOG(logERROR, ("Could not write FPGA source to flash (size:%lu)\n", fsize)); return 1; } -#ifdef VERY_VERBOSE - cprintf(BLUE, "program written to flash\n"); -#endif + FILE_LOG(logDEBUG1, ("program written to flash\n")); return 0; } - -#endif //PROGRAM_FPGA_H diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h index 592083234..65c931855 100644 --- a/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/slsDetectorFunctionList.h @@ -37,9 +37,7 @@ u_int64_t getFirmwareAPIVersion(); u_int16_t getHardwareVersionNumber(); u_int16_t getHardwareSerialNumber(); #endif -#ifdef EIGERD u_int32_t getDetectorNumber(); -#endif u_int64_t getDetectorMAC(); u_int32_t getDetectorIP(); diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c index 3dd67b651..9758aee4e 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c @@ -2,16 +2,15 @@ The port number is passed as an argument */ #include "sls_detector_defs.h" -#include "slsDetectorServer_defs.h" #include "logger.h" #include "communication_funcs.h" #include "slsDetectorServer_funcs.h" +#include "slsDetectorServer_defs.h" -#include -#include #include #include + // Global variables from communication_funcs extern int isControlServer; extern int ret; diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index c9cb8d366..cdb4a79e1 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -3,19 +3,19 @@ #include "communication_funcs.h" #include "logger.h" -#include #include #include +#include //defined in the detector specific Makefile #ifdef GOTTHARDD -const enum detectorType myDetectorType=GOTTHARD; +const enum detectorType myDetectorType = GOTTHARD; #elif EIGERD -const enum detectorType myDetectorType=EIGER; +const enum detectorType myDetectorType = EIGER; #elif JUNGFRAUD -const enum detectorType myDetectorType=JUNGFRAU; +const enum detectorType myDetectorType = JUNGFRAU; #else -const enum detectorType myDetectorType=GENERIC; +const enum detectorType myDetectorType = GENERIC; #endif // Global variables from communication_funcs @@ -64,7 +64,7 @@ void init_detector() { if (isControlServer) { basictests(); #ifdef JUNGFRAUD - if (debugflag == PROGRAMMING_MODE) + if (debugflag != PROGRAMMING_MODE) #endif initControlServer(); #ifdef EIGERD @@ -1331,53 +1331,54 @@ int set_timer(int file_des) { int get_time_left(int file_des) { - ret = OK; - memset(mess, 0, sizeof(mess)); - enum timerIndex ind = -1; - int64_t retval = -1; + ret = OK; + memset(mess, 0, sizeof(mess)); + enum timerIndex ind = -1; + int64_t retval = -1; - if (receiveData(file_des, &ind, sizeof(ind), INT32) < 0) - return printSocketReadError(); - FILE_LOG(logDEBUG1, ("Getting timer left index %d\n", ind)); + if (receiveData(file_des, &ind, sizeof(ind), INT32) < 0) + return printSocketReadError(); + FILE_LOG(logDEBUG1, ("Getting timer left index %d\n", ind)); - // only get - // check index - switch(ind) { + // only get + // check index +#ifdef JUNGFRAUD + if (ind == DELAY_AFTER_TRIGGER) { + ret = FAIL; + sprintf(mess,"Timer Left Index (%d) is not implemented for this release.\n", (int)ind); + FILE_LOG(logERROR,(mess)); + } +#endif + if (ret == OK) { + switch(ind) { #ifdef EIGERD - case MEASURED_PERIOD: - case MEASURED_SUBPERIOD: + case MEASURED_PERIOD: + case MEASURED_SUBPERIOD: #elif JUNGFRAUD - case FRAMES_FROM_START: - case FRAMES_FROM_START_PG: + case FRAMES_FROM_START: + case FRAMES_FROM_START_PG: #elif GOTTHARDD - case GATES_NUMBER: + case GATES_NUMBER: #endif #if defined(GOTTHARDD) || defined(JUNGFRAUD) - case FRAME_NUMBER: - case ACQUISITION_TIME: - case FRAME_PERIOD: - case DELAY_AFTER_TRIGGER: - case CYCLES_NUMBER: - case PROGRESS: - case ACTUAL_TIME: - case MEASUREMENT_TIME: + case FRAME_NUMBER: + case ACQUISITION_TIME: + case FRAME_PERIOD: + case DELAY_AFTER_TRIGGER: + case CYCLES_NUMBER: + case PROGRESS: + case ACTUAL_TIME: + case MEASUREMENT_TIME: #endif - retval = getTimeLeft(ind); - FILE_LOG(logDEBUG1, ("Timer left index %d: %lld\n", ind, retval)); - break; -#ifdef JUNGFRAUD - case DELAY_AFTER_TRIGGER: - ret = FAIL; - sprintf(mess,"Timer Left Index (%d) is not implemented for this release.\n", (int)ind); - FILE_LOG(logERROR,(mess)); - break; -#endif - - default: - modeNotImplemented("Timer left index", (int)ind); - break; - } - return Server_SendResult(file_des, INT64, 1, &retval, sizeof(retval)); + retval = getTimeLeft(ind); + FILE_LOG(logDEBUG1, ("Timer left index %d: %lld\n", ind, retval)); + break; + default: + modeNotImplemented("Timer left index", (int)ind); + break; + } + } + return Server_SendResult(file_des, INT64, 1, &retval, sizeof(retval)); } @@ -1692,9 +1693,16 @@ int set_port(int file_des) { int update_client(int file_des) { - ret = OK; + ret = FORCE_UPDATE; memset(mess, 0, sizeof(mess)); +#ifdef JUNGFRAUD + if (debugflag == PROGRAMMING_MODE) { + ret = OK; + } +#endif Server_SendResult(file_des, INT32, 0, NULL, 0); + if (ret == OK) + return ret; return send_update(file_des); } @@ -1702,6 +1710,7 @@ int update_client(int file_des) { int send_update(int file_des) { + ret = OK; int n = 0; int i32 = -1; int64_t i64 = -1; @@ -1769,7 +1778,7 @@ int send_update(int file_des) { strcpy(lastClientIP,thisClientIP); } - return OK; + return ret; } @@ -2369,7 +2378,6 @@ int program_fpga(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - FILE_LOG(logDEBUG1, ("Programming FPGA\n")); #ifndef JUNGFRAUD //to receive any arguments int n = 1; @@ -2405,7 +2413,7 @@ int program_fpga(int file_des) { if (receiveData(file_des,&filesize,sizeof(filesize),INT32) < 0) return printSocketReadError(); totalsize = filesize; - FILE_LOG(logDEBUG1, ("Total program size is: %d\n", totalsize); + FILE_LOG(logDEBUG1, ("Total program size is: %d\n", totalsize)); // opening file pointer to flash and telling FPGA to not touch flash if (startWritingFPGAprogram(&fp) != OK) { @@ -2430,8 +2438,7 @@ int program_fpga(int file_des) { if (unitprogramsize > filesize) //less than 2mb unitprogramsize = filesize; FILE_LOG(logDEBUG1, ("unit size to receive is:%d\n" - "filesize:%d currentpointer:%d\n", - unitprogramsize, filesize, currentPointer)); + "filesize:%d\n", unitprogramsize, filesize)); //receive part of program @@ -2462,8 +2469,8 @@ int program_fpga(int file_des) { fflush(stdout); } } - - FILE_LOG(logINFO("\nDone copying program\n")); + printf("\n"); + FILE_LOG(logINFO, ("Done copying program\n")); // closing file pointer to flash and informing FPGA stopWritingFPGAprogram(fp); @@ -2712,29 +2719,30 @@ int auto_comp_disable(int file_des) { int storage_cell_start(int file_des) { - ret = OK; - memset(mess, 0, sizeof(mess)); - int arg = -1; - int retval = -1; + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = -1; + int retval = -1; - if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) - return printSocketReadError(); - FILE_LOG(logDEBUG1, ("Setting Storage cell start to %d\n", arg)); + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + FILE_LOG(logDEBUG1, ("Setting Storage cell start to %d\n", arg)); #ifndef JUNGFRAUD - functionNotImplemented(); + functionNotImplemented(); #else - // set & get - 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"); - FILE_LOG(logERROR, (mess)); - } else { - retval = selectStoragecellStart(arg); - FILE_LOG(logDEBUG1, ("Storage cell start: %d\n", retval)); - validate(arg, retval, "set storage cell start", 0); - } + // set & get + 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"); + FILE_LOG(logERROR, (mess)); + } else { + retval = selectStoragecellStart(arg); + FILE_LOG(logDEBUG1, ("Storage cell start: %d\n", retval)); + validate(arg, retval, "set storage cell start", 0); + } + } #endif return Server_SendResult(file_des, INT32, 1, &retval, sizeof(retval)); } diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h index 72829ec43..b37bf5aa7 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h @@ -1,6 +1,5 @@ #pragma once #include "sls_detector_defs.h" -#include // initialization functions int printSocketReadError(); diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index 6f3358e70..e0f5a2744 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -1430,8 +1430,9 @@ int slsDetector::updateDetector() { if (thisDetector->onlineFlag == ONLINE_FLAG && connectControl() == OK) { ret = thisDetectorControl->Client_Send(fnum, NULL, 0, NULL, 0); - // no ret handling as ret never fail - updateDetectorNoWait(); + // if it returns ok (jungfrau in programming mode), dont update + if (ret == FORCE_UPDATE) + ret = updateDetectorNoWait(); disconnectControl(); } return ret; @@ -4122,7 +4123,8 @@ int slsDetector::programFPGA(std::string fname) { //erasing flash if (ret != FAIL) { FILE_LOG(logINFO) << "This can take awhile. Please be patient..."; - printf("Erasing Flash: %d%%\r", 0); + FILE_LOG(logINFO) << "Erasing Flash:"; + printf("%d%%\r", 0); std::cout << std::flush; //erasing takes 65 seconds, printing here (otherwise need threads //in server-unnecessary) @@ -4131,12 +4133,13 @@ int slsDetector::programFPGA(std::string fname) { while(count > 0) { usleep(1 * 1000 * 1000); --count; - printf("Erasing Flash:%d%%\r", + printf("%d%%\r", (int) (((double)(ERASE_TIME - count) / ERASE_TIME) * 100)); std::cout << std::flush; } - std::cout << std::endl; - printf("Writing to Flash:%d%%\r", 0); + printf("\n"); + FILE_LOG(logINFO) << "Writing to Flash:"; + printf("%d%%\r", 0); std::cout << std::flush; } @@ -4160,16 +4163,17 @@ int slsDetector::programFPGA(std::string fname) { currentPointer += unitprogramsize; //print progress - printf("Writing to Flash:%d%%\r", + printf("%d%%\r", (int) (((double)(totalsize - filesize) / totalsize) * 100)); std::cout << std::flush; } else { + printf("\n"); controlSocket->ReceiveDataOnly(mess,sizeof(mess)); FILE_LOG(logERROR) << "Detector returned error: " << mess; setErrorMask((getErrorMask())|(PROGRAMMING_ERROR)); } } - std::cout << std::endl; + printf("\n"); //check ending error if ((ret == FAIL) && diff --git a/slsReceiverSoftware/CMakeLists.txt b/slsReceiverSoftware/CMakeLists.txt index ed85f8a98..f659522ce 100644 --- a/slsReceiverSoftware/CMakeLists.txt +++ b/slsReceiverSoftware/CMakeLists.txt @@ -31,9 +31,9 @@ if (USE_HDF5) endif (USE_HDF5) -add_definitions( - -DDACS_INT -DSLS_RECEIVER_UDP_FUNCTIONS -) +#add_definitions( +# -DVERBOSE +#) include_directories( include diff --git a/slsReceiverSoftware/src/slsReceiverImplementation.cpp b/slsReceiverSoftware/src/slsReceiverImplementation.cpp index b50b400dd..7d000290b 100644 --- a/slsReceiverSoftware/src/slsReceiverImplementation.cpp +++ b/slsReceiverSoftware/src/slsReceiverImplementation.cpp @@ -82,7 +82,7 @@ void slsReceiverImplementation::InitializeMembers() { //***connection parameters*** strcpy(eth,""); - for(int i=0;iGetMeasurementStartedFlag(); sum += it->GetNumTotalFramesCaught(); } @@ -220,7 +220,7 @@ uint64_t slsReceiverImplementation::getFramesCaught() const { uint64_t sum = 0; uint32_t flagsum = 0; - for (const auto& it : dataProcessor){ + for (const auto& it : dataProcessor) { flagsum += it->GetMeasurementStartedFlag(); sum += it->GetNumFramesCaught(); } @@ -235,7 +235,7 @@ int64_t slsReceiverImplementation::getAcquisitionIndex() const { uint64_t sum = 0; uint32_t flagsum = 0; - for (const auto& it : dataProcessor){ + for (const auto& it : dataProcessor) { flagsum += it->GetMeasurementStartedFlag(); sum += it->GetActualProcessedAcquisitionIndex(); } @@ -385,7 +385,7 @@ uint32_t slsReceiverImplementation::getActualUDPSocketBufferSize() const { /**initial parameters***/ -void slsReceiverImplementation::setDetectorHostname(const char *c){ +void slsReceiverImplementation::setDetectorHostname(const char *c) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; if(strlen(c)) @@ -411,7 +411,7 @@ void slsReceiverImplementation::setMultiDetectorSize(const int* size) { } -void slsReceiverImplementation::setFlippedData(int axis, int enable){ +void slsReceiverImplementation::setFlippedData(int axis, int enable) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; if(axis<0 || axis>1) return; @@ -436,8 +436,8 @@ int slsReceiverImplementation::setGapPixelsEnable(const bool b) { } -void slsReceiverImplementation::setFileFormat(const fileFormat f){ - switch(f){ +void slsReceiverImplementation::setFileFormat(const fileFormat f) { + switch(f) { #ifdef HDF5C case HDF5: fileFormatType = HDF5; @@ -455,7 +455,7 @@ void slsReceiverImplementation::setFileFormat(const fileFormat f){ } -void slsReceiverImplementation::setFileName(const char c[]){ +void slsReceiverImplementation::setFileName(const char c[]) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; if(strlen(c)) @@ -464,11 +464,11 @@ void slsReceiverImplementation::setFileName(const char c[]){ } -void slsReceiverImplementation::setFilePath(const char c[]){ +void slsReceiverImplementation::setFilePath(const char c[]) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - if(strlen(c)){ + if(strlen(c)) { //check if filepath exists struct stat st; if(stat(c,&st) == 0) @@ -480,7 +480,7 @@ void slsReceiverImplementation::setFilePath(const char c[]){ } -void slsReceiverImplementation::setFileIndex(const uint64_t i){ +void slsReceiverImplementation::setFileIndex(const uint64_t i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; fileIndex = i; @@ -488,7 +488,7 @@ void slsReceiverImplementation::setFileIndex(const uint64_t i){ } -void slsReceiverImplementation::setFramesPerFile(const uint32_t i){ +void slsReceiverImplementation::setFramesPerFile(const uint32_t i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; framesPerFile = i; @@ -496,7 +496,7 @@ void slsReceiverImplementation::setFramesPerFile(const uint32_t i){ } -void slsReceiverImplementation::setFrameDiscardPolicy(const frameDiscardPolicy i){ +void slsReceiverImplementation::setFrameDiscardPolicy(const frameDiscardPolicy i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; if (i >= 0 && i < NUM_DISCARD_POLICIES) @@ -506,7 +506,7 @@ void slsReceiverImplementation::setFrameDiscardPolicy(const frameDiscardPolicy i } -void slsReceiverImplementation::setFramePaddingEnable(const bool i){ +void slsReceiverImplementation::setFramePaddingEnable(const bool i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; framePadding = i; @@ -514,8 +514,8 @@ void slsReceiverImplementation::setFramePaddingEnable(const bool i){ } -void slsReceiverImplementation::setFileWriteEnable(const bool b){ - if (fileWriteEnable != b){ +void slsReceiverImplementation::setFileWriteEnable(const bool b) { + if (fileWriteEnable != b) { fileWriteEnable = b; for (unsigned int i = 0; i < dataProcessor.size(); ++i) { dataProcessor[i]->SetupFileWriter(fileWriteEnable, (int*)numDet, @@ -529,7 +529,7 @@ void slsReceiverImplementation::setFileWriteEnable(const bool b){ } -void slsReceiverImplementation::setOverwriteEnable(const bool b){ +void slsReceiverImplementation::setOverwriteEnable(const bool b) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; overwriteEnable = b; @@ -538,21 +538,21 @@ void slsReceiverImplementation::setOverwriteEnable(const bool b){ /***connection parameters***/ -void slsReceiverImplementation::setUDPPortNumber(const uint32_t i){ +void slsReceiverImplementation::setUDPPortNumber(const uint32_t i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; udpPortNum[0] = i; FILE_LOG(logINFO) << "UDP Port Number[0]: " << udpPortNum[0]; } -void slsReceiverImplementation::setUDPPortNumber2(const uint32_t i){ +void slsReceiverImplementation::setUDPPortNumber2(const uint32_t i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; udpPortNum[1] = i; FILE_LOG(logINFO) << "UDP Port Number[1]: " << udpPortNum[1]; } -void slsReceiverImplementation::setEthernetInterface(const char* c){ +void slsReceiverImplementation::setEthernetInterface(const char* c) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; strcpy(eth, c); @@ -635,7 +635,7 @@ int slsReceiverImplementation::setStreamingFrequency(const uint32_t freq) { return OK; } -void slsReceiverImplementation::setStreamingTimer(const uint32_t time_in_ms){ +void slsReceiverImplementation::setStreamingTimer(const uint32_t time_in_ms) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; streamingTimerInMs = time_in_ms; @@ -680,21 +680,21 @@ void slsReceiverImplementation::setStreamingPort(const uint32_t i) { } -void slsReceiverImplementation::setStreamingSourceIP(const char c[]){ +void slsReceiverImplementation::setStreamingSourceIP(const char c[]) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; strcpy(streamingSrcIP, c); FILE_LOG(logINFO) << "Streaming Source IP: " << streamingSrcIP; } -void slsReceiverImplementation::setAdditionalJsonHeader(const char c[]){ +void slsReceiverImplementation::setAdditionalJsonHeader(const char c[]) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; strcpy(additionalJsonHeader, c); FILE_LOG(logINFO) << "Additional JSON Header: " << additionalJsonHeader; } -int slsReceiverImplementation::setAcquisitionPeriod(const uint64_t i){ +int slsReceiverImplementation::setAcquisitionPeriod(const uint64_t i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; acquisitionPeriod = i; @@ -704,7 +704,7 @@ int slsReceiverImplementation::setAcquisitionPeriod(const uint64_t i){ return OK; } -int slsReceiverImplementation::setAcquisitionTime(const uint64_t i){ +int slsReceiverImplementation::setAcquisitionTime(const uint64_t i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; acquisitionTime = i; @@ -714,21 +714,21 @@ int slsReceiverImplementation::setAcquisitionTime(const uint64_t i){ return OK; } -void slsReceiverImplementation::setSubExpTime(const uint64_t i){ +void slsReceiverImplementation::setSubExpTime(const uint64_t i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; subExpTime = i; FILE_LOG(logINFO) << "Sub Exposure Time: " << (double)subExpTime/(1E9) << "s"; } -void slsReceiverImplementation::setSubPeriod(const uint64_t i){ +void slsReceiverImplementation::setSubPeriod(const uint64_t i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; subPeriod = i; FILE_LOG(logINFO) << "Sub Exposure Period: " << (double)subPeriod/(1E9) << "s"; } -int slsReceiverImplementation::setNumberOfFrames(const uint64_t i){ +int slsReceiverImplementation::setNumberOfFrames(const uint64_t i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; numberOfFrames = i; @@ -794,7 +794,7 @@ int slsReceiverImplementation::setFifoDepth(const uint32_t i) { /***receiver parameters***/ -bool slsReceiverImplementation::setActivate(bool enable){ +bool slsReceiverImplementation::setActivate(bool enable) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; activated = enable; FILE_LOG(logINFO) << "Activation: " << stringEnable(activated); @@ -802,14 +802,14 @@ bool slsReceiverImplementation::setActivate(bool enable){ } -bool slsReceiverImplementation::setDeactivatedPadding(bool enable){ +bool slsReceiverImplementation::setDeactivatedPadding(bool enable) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; deactivatedPaddingEnable = enable; FILE_LOG(logINFO) << "Deactivated Padding Enable: " << stringEnable(deactivatedPaddingEnable); return deactivatedPaddingEnable; } -void slsReceiverImplementation::setSilentMode(const bool i){ +void slsReceiverImplementation::setSilentMode(const bool i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; silentMode = i; @@ -902,7 +902,7 @@ int slsReceiverImplementation::setDetectorType(const detectorType d) { -void slsReceiverImplementation::setDetectorPositionId(const int i){ +void slsReceiverImplementation::setDetectorPositionId(const int i) { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; detID = i; FILE_LOG(logINFO) << "Detector Position Id:" << detID; @@ -983,7 +983,7 @@ int slsReceiverImplementation::startReceiver(char *c) { -void slsReceiverImplementation::stopReceiver(){ +void slsReceiverImplementation::stopReceiver() { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; FILE_LOG(logINFO) << "Stopping Receiver"; @@ -1061,9 +1061,9 @@ void slsReceiverImplementation::stopReceiver(){ -void slsReceiverImplementation::startReadout(){ +void slsReceiverImplementation::startReadout() { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - if(status == RUNNING){ + if(status == RUNNING) { // wait for incoming delayed packets int totalPacketsReceived = 0; int previousValue=-1; @@ -1071,9 +1071,9 @@ void slsReceiverImplementation::startReadout(){ totalPacketsReceived += it->GetPacketsCaught(); //wait for all packets - const auto numPacketsToReceive = numberOfFrames * generalData->packetsPerFrame * listener.size(); - if(totalPacketsReceived != numPacketsToReceive){ - while(totalPacketsReceived != previousValue){ + const int numPacketsToReceive = numberOfFrames * generalData->packetsPerFrame * listener.size(); + if(totalPacketsReceived != numPacketsToReceive) { + while(totalPacketsReceived != previousValue) { FILE_LOG(logDEBUG3) << "waiting for all packets, previousValue:" << previousValue << " totalPacketsReceived: " << totalPacketsReceived; usleep(5*1000);/* TODO! Need to find optimal time **/ @@ -1119,7 +1119,7 @@ void slsReceiverImplementation::closeFiles() { int slsReceiverImplementation::restreamStop() { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; bool ret = OK; - for (const auto& it : dataStreamer){ + for (const auto& it : dataStreamer) { if (it->RestreamStop() == FAIL) ret = FAIL; } @@ -1134,24 +1134,24 @@ int slsReceiverImplementation::restreamStop() { /***callback functions***/ -void slsReceiverImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg){ +void slsReceiverImplementation::registerCallBackStartAcquisition(int (*func)(char*, char*, uint64_t, uint32_t, void*),void *arg) { startAcquisitionCallBack=func; pStartAcquisition=arg; } -void slsReceiverImplementation::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg){ +void slsReceiverImplementation::registerCallBackAcquisitionFinished(void (*func)(uint64_t, void*),void *arg) { acquisitionFinishedCallBack=func; pAcquisitionFinished=arg; } void slsReceiverImplementation::registerCallBackRawDataReady(void (*func)(char* , - char*, uint32_t, void*),void *arg){ + char*, uint32_t, void*),void *arg) { rawDataReadyCallBack=func; pRawDataReady=arg; } void slsReceiverImplementation::registerCallBackRawDataModifyReady(void (*func)(char* , - char*, uint32_t&, void*),void *arg){ + char*, uint32_t&, void*),void *arg) { rawDataModifyReadyCallBack=func; pRawDataReady=arg; } @@ -1187,7 +1187,7 @@ void slsReceiverImplementation::SetLocalNetworkParameters() { void slsReceiverImplementation::SetThreadPriorities() { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; - for (const auto& it : listener){ + for (const auto& it : listener) { if (it->SetThreadPriority(LISTENER_PRIORITY) == FAIL) { FILE_LOG(logWARNING) << "Could not prioritize listener threads. (No Root Privileges?)"; return; @@ -1288,15 +1288,15 @@ int slsReceiverImplementation::SetupWriter() { void slsReceiverImplementation::StartRunning() { FILE_LOG(logDEBUG3) << __SHORT_AT__ << " called"; //set running mask and post semaphore to start the inner loop in execution thread - for (const auto& it : listener){ + for (const auto& it : listener) { it->StartRunning(); it->Continue(); } - for (const auto& it : dataProcessor){ + for (const auto& it : dataProcessor) { it->StartRunning(); it->Continue(); } - for (const auto& it : dataStreamer){ + for (const auto& it : dataStreamer) { it->StartRunning(); it->Continue(); } diff --git a/slsSupportLib/include/genericSocket.h b/slsSupportLib/include/genericSocket.h index e405abb90..32bb9230c 100644 --- a/slsSupportLib/include/genericSocket.h +++ b/slsSupportLib/include/genericSocket.h @@ -689,8 +689,9 @@ public: if(nsent == header_packet_size) continue; if(nsent != nsending){ - if(nsent && (nsent != -1)) + if(nsent && (nsent != -1)) { FILE_LOG(logERROR) << "Incomplete Packet size " << nsent; + } break; } length-=nsent; @@ -707,8 +708,9 @@ public: if(nsent<=0 || nsent == packet_size) break; //incomplete packets or header packets ignored and read buffer again - if(nsent != packet_size && nsent != header_packet_size) + if(nsent != packet_size && nsent != header_packet_size) { FILE_LOG(logERROR) << portno << ": Incomplete Packet size " << nsent; + } } //nsent = 1040; if(nsent > 0)total_sent+=nsent; diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index 080d2def9..fd098d0b9 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -1,6 +1,6 @@ /** API versions */ #define APIRECEIVER 0x180927 -#define APIEIGER 0x181008 -#define APIJUNGFRAU 0x181008 +#define APIEIGER 0x181031 +#define APIJUNGFRAU 0x181102 #define APIGOTTHARD 0x181009