From 2cb234a649cfcb670986d984107d6c6237430091 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 27 Jul 2026 17:03:27 +0200 Subject: [PATCH] scanning string instead of int from server config file for version --- .../config_jungfrau.txt | 18 ++-- .../slsDetectorFunctionList.c | 92 +++++++++++-------- .../include/slsDetectorFunctionList.h | 8 +- slsSupportLib/include/sls/sls_detector_defs.h | 5 +- 4 files changed, 69 insertions(+), 54 deletions(-) diff --git a/slsDetectorServers/jungfrauDetectorServer/config_jungfrau.txt b/slsDetectorServers/jungfrauDetectorServer/config_jungfrau.txt index e6c7f80a5..c0431f518 100755 --- a/slsDetectorServers/jungfrauDetectorServer/config_jungfrau.txt +++ b/slsDetectorServers/jungfrauDetectorServer/config_jungfrau.txt @@ -1,11 +1,9 @@ +#chipversion Options +#"v1.0" +#"v1.1" +#"v1.2 Normal" +#"v1.2 Low Noise" +#"v1.2 HDR" +#"v1.3 Burst Mode" - -#chipindex corresponding to chip version -#10 -> v1.0 -#11 -> v1.1 -#120 -> v1.2 Normal -#121 -> v1.2 Low Noise -#121 ->v1.2 HDR -#130 ->v1.3 Burst Mode - -chipindex 120 +chipindex "v1.2 Normal" diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 68fbda28a..b1a4448da 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -337,43 +337,55 @@ int getChipVersionInFPGA() { } } -int findChipIndex(enum CHIPINDEX *ind, int val, char *mess) { +int findChipIndex(enum CHIPINDEX *ind, char *cval, char *mess) { + if (cval == NULL) { + sprintf(mess, "String value is NULL. Cannot find chip version.\n"); + LOG(logERROR, (mess)); + return FAIL; + } const int vals[] = CHIP_VALS; + char *chip_names[] = {CHIP_NAMES}; for (enum CHIPINDEX ichip = v1_0; ichip != NUM_CHIP_INDICES; ++ichip) { - if (vals[ichip] == val) { + if (strcmp(chip_names[ichip], cval) == 0) { *ind = ichip; return OK; } } - sprintf(mess, "Unknown chip index value %d. Options: %s\n", val, + sprintf(mess, "Unknown chip version '%s'. Options: %s\n", cval, CHIP_VALS_HELP); LOG(logERROR, (mess)); return FAIL; } /** For backwards compatibility */ -int setChipVersionFromConfigFile(int val, char *mess) { +int setChipVersionIntFromConfigFile(int val, char *mess) { // validations const int vals[] = CHIP_VALS; int v1_0_val = vals[(int)v1_0]; int v1_1_val = vals[(int)v1_1]; - if (val != v1_0_val && val != v1_1_val) { + switch (val) { + case v1_0_val: + return setChipIndex(v1_0, mess); + case v1_1_val: + return setChipIndex(v1_1, mess); + default: sprintf(mess, "Invalid chip version %d. Options: %d and %d.\n", val, v1_0_val, v1_1_val); + LOG(logERROR, (mess)); return FAIL; } - - if (setChipIndexFromConfigFile(val, mess) == FAIL) { - return FAIL; - } - return OK; } -int setChipIndexFromConfigFile(int val, char *mess) { +int setChipVersionStringFromConfigFile(char *cval, char *mess) { + enum CHIPINDEX ind = NUM_CHIP_INDICES; - if (findChipIndex(&ind, val, mess) == FAIL) { + if (findChipIndex(&ind, cval, mess) == FAIL) { return FAIL; } + return setChipIndex(ind, mess); +} + +int setChipIndex(enum CHIPINDEX ind, char *mess) { if (validateChipIndex(ind, mess) == FAIL) { return FAIL; } @@ -887,41 +899,43 @@ int readConfigFile() { strlen(line) - 1, line)); memset(command, 0, LZ); - // chipversion command (backward compatibility) + // chipversion command if (!strncmp(line, "chipversion", strlen("chipversion"))) { int val = 0; - // cannot scan values - if (sscanf(line, "%s %d", command, &val) != 2) { - sprintf( - initErrorMessage, - "Could not scan chipversion command from on-board server " - "config file. Line:[%s].\n", - line); - break; + char chipversion[SHORT_STR_LENGTH] = {0}; + + // backward compatibility: takes an int + if (sscanf(line, "%s %d", command, &val) == 2) { + if (setChipVersionIntFromConfigFile(val, initErrorMessage) == + FAIL) { + strcat(initErrorMessage, + "Could not set chip version from on-board server " + "config " + "file. For higher chip versions, use 'chipindex' " + "command from example server config file. " + "Line:[%s].\n"); + break; + } } - if (setChipVersionFromConfigFile(val, initErrorMessage) == FAIL) { - strcat(initErrorMessage, - "Could not set chip version from on-board server config " - "file. For higher chip versions, use 'chipindex' " - "command from example server config file. Line:[%s].\n"); - break; + + // updated argument takes a string + else if (sscanf(line, "%s \"%[^\"]\"", command, chipversion) == 2) { + if (setChipVersionStringFromConfigFile( + chipversion, initErrorMessage) == FAIL) { + strcat(initErrorMessage, + "Could not set chip version from on-board server " + "config file. Line:[%s].\n"); + break; + } } - } else if (!strncmp(line, "chipindex", strlen("chipindex"))) { - int val = 0; - // cannot scan values - if (sscanf(line, "%s %d", command, &val) != 2) { + + else { sprintf(initErrorMessage, - "Could not scan chipindex command from on-board server " - "config file. Line:[%s].\n", + "Could not scan chipversion command from on-board " + "server config file. Line:[%s].\n", line); break; } - if (setChipIndexFromConfigFile(val, initErrorMessage) == FAIL) { - strcat(initErrorMessage, - "Could not set chip index from on-board server config " - "file. Line:[%s].\n"); - break; - } } // other commands diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 5afb904c9..46bd43586 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -96,9 +96,11 @@ int isHardwareVersion_1_0(); #endif #if defined(JUNGFRAUD) int getChipVersionInFPGA(); -int findChipIndex(enum CHIPINDEX *ind, int val, char *mess); -int setChipVersionFromConfigFile(int val, char *mess); -int setChipIndexFromConfigFile(int val, char *mess); +int findChipIndex(enum CHIPINDEX *ind, char *cval, char *mess); +int setChipVersionIntFromConfigFile(int val, + char *mess); // for backward compatibility +int setChipVersionStringFromConfigFile(char *cval, char *mess); +int setChipIndex(enum CHIPINDEX ind, char *mess); int validateChipIndex(enum CHIPINDEX ind, char *mess); int setChipVersionInFPGA(char *mess); #endif diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index d028d4238..ad792c294 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -70,8 +70,9 @@ #define LOCALHOST_IP "127.0.0.1" /** default maximum string length */ -#define MAX_STR_LENGTH 1000 -#define SHORT_STR_LENGTH 20 +#define MAX_STR_LENGTH 1000 +#define SHORT_STR_LENGTH 20 +#define SHORT_STR_SCAN_WIDTH 19 #define MAX_PATTERN_LENGTH 0x2000 #define MAX_PATTERN_LEVELS 6