mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 18:17:59 +02:00
moduleid for eiger m3 and g2, but set only for g2
This commit is contained in:
@ -28,3 +28,6 @@ void validate(int *ret, char *mess, int arg, int retval, char *modename,
|
||||
enum numberMode nummode);
|
||||
void validate64(int *ret, char *mess, int64_t arg, int64_t retval,
|
||||
char *modename, enum numberMode nummode);
|
||||
|
||||
int getModuleIdInFile(int *ret, char *mess, char *fileName);
|
||||
int setModuleIdInFile(char *mess, int arg, char *fileName);
|
@ -89,14 +89,14 @@ u_int16_t getHardwareSerialNumber();
|
||||
int isHardwareVersion2();
|
||||
int getChipVersion();
|
||||
#endif
|
||||
#if defined(EIGERD) || defined(MYTHEN3D)
|
||||
void readDetectorNumber();
|
||||
#endif
|
||||
#ifndef EIGERD
|
||||
u_int32_t getDetectorNumber();
|
||||
#endif
|
||||
#if defined(GOTTHARD2D) || defined(EIGERD) || defined(MYTHEN3D)
|
||||
int getModuleId(int *ret, char *mess);
|
||||
#endif
|
||||
#ifdef GOTTHARD2D
|
||||
int getModuleId();
|
||||
void setModuleId(int arg);
|
||||
int getMaxModuleId();
|
||||
void setModuleId(int *ret, char *mess, int arg);
|
||||
#endif
|
||||
u_int64_t getDetectorMAC();
|
||||
u_int32_t getDetectorIP();
|
||||
|
@ -7,9 +7,6 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h> // readlink
|
||||
|
||||
extern int ret;
|
||||
extern char mess[MAX_STR_LENGTH];
|
||||
|
||||
int ConvertToDifferentRange(int inputMin, int inputMax, int outputMin,
|
||||
int outputMax, int inputValue, int *outputValue) {
|
||||
LOG(logDEBUG1, (" Input Value: %d (Input:(%d - %d), Output:(%d - %d))\n",
|
||||
@ -102,4 +99,82 @@ void validate64(int *ret, char *mess, int64_t arg, int64_t retval,
|
||||
(long long unsigned int)retval);
|
||||
LOG(logERROR, (mess));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int getModuleIdInFile(int *ret, char *mess, char *fileName) {
|
||||
const int fileNameSize = 128;
|
||||
char fname[fileNameSize];
|
||||
if (getAbsPath(fname, fileNameSize, fileName) == FAIL) {
|
||||
*ret = FAIL;
|
||||
strcpy(mess, "Could not find detid file\n");
|
||||
LOG(logERROR, ("%s\n\n", mess));
|
||||
return -1;
|
||||
}
|
||||
|
||||
// open id file
|
||||
FILE *fd = fopen(fname, "r");
|
||||
if (fd == NULL) {
|
||||
*ret = FAIL;
|
||||
strcpy(mess, "Could not find detid file\n");
|
||||
LOG(logERROR, ("%s\n\n", mess));
|
||||
return -1;
|
||||
}
|
||||
LOG(logDEBUG1, ("Reading det id file %s\n", fileName));
|
||||
|
||||
// read line
|
||||
const size_t len = 256;
|
||||
char line[len];
|
||||
memset(line, 0, len);
|
||||
if (NULL == fgets(line, len, fd)) {
|
||||
*ret = FAIL;
|
||||
strcpy(mess, "Could not find detid file\n");
|
||||
LOG(logERROR, ("%s\n\n", mess));
|
||||
return -1;
|
||||
}
|
||||
// read id
|
||||
int retval = 0;
|
||||
if (sscanf(line, "%x", &retval) != 1) {
|
||||
*ret = FAIL;
|
||||
sprintf(mess,
|
||||
"Could not scan det id from on-board server "
|
||||
"id file. Line:[%s].\n",
|
||||
line);
|
||||
LOG(logERROR, ("%s\n\n", mess));
|
||||
return -1;
|
||||
}
|
||||
LOG(logINFOBLUE, ("Module Id: 0x%x (File)\n", retval));
|
||||
return retval;
|
||||
}
|
||||
|
||||
int setModuleIdInFile(char *mess, int arg, char *fileName) {
|
||||
LOG(logINFOBLUE, ("Setting Module Id: 0x%x (File)\n", arg));
|
||||
|
||||
const int fileNameSize = 128;
|
||||
char fname[fileNameSize];
|
||||
if (getAbsPath(fname, fileNameSize, fileName) == FAIL) {
|
||||
strcpy(mess, "Could not find detid file\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// open id file
|
||||
FILE *fd = fopen(fname, "r");
|
||||
if (fd == NULL) {
|
||||
strcpy(mess, "Could not find detid file\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
LOG(logDEBUG1, ("Writing det id to file %s\n", fileName));
|
||||
|
||||
// write id
|
||||
const size_t len = 256;
|
||||
char line[len];
|
||||
memset(line, 0, len);
|
||||
sprintf(line, "%x", arg);
|
||||
if (EOF == fputs(line, fd)) {
|
||||
strcpy(mess, "Could not write to detid file\n");
|
||||
LOG(logERROR, (mess));
|
||||
return FAIL;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
@ -684,8 +684,12 @@ int get_serial_number(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int64_t retval = -1;
|
||||
#ifdef EIGERD
|
||||
functionNotImplemented();
|
||||
#else
|
||||
retval = getDetectorNumber();
|
||||
LOG(logDEBUG1, ("detector number retval: 0x%llx\n", (long long int)retval));
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
@ -9016,12 +9020,12 @@ int get_module_id(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int retval = -1;
|
||||
#ifndef GOTTHARD2D
|
||||
#if !(defined(GOTTHARD2D) || defined(EIGERD) || defined(MYTHEN3D))
|
||||
functionNotImplemented();
|
||||
#else
|
||||
retval = getModuleId();
|
||||
#endif
|
||||
retval = getModuleId(&ret, mess);
|
||||
LOG(logDEBUG1, ("module id retval: 0x%x\n", retval));
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
|
||||
}
|
||||
|
||||
@ -9037,16 +9041,17 @@ int set_module_id(int file_des) {
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
if (arg > getMaxModuleId()) {
|
||||
if (arg > 0xFFFF) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not set module id. Max value: 0x%x\n",
|
||||
getMaxModuleId());
|
||||
sprintf(mess, "Could not set module id. Max value: 0x%x\n", 0xFFFF);
|
||||
LOG(logERROR, (mess));
|
||||
} else {
|
||||
setModuleId(arg);
|
||||
int retval = getModuleId();
|
||||
LOG(logDEBUG1, ("retval module id: %d\n", retval));
|
||||
validate(&ret, mess, arg, retval, "set module id", DEC);
|
||||
setModuleId(&ret, mess, arg);
|
||||
if (ret != FAIL) {
|
||||
int retval = getModuleId(&ret, mess);
|
||||
LOG(logDEBUG1, ("retval module id: %d\n", retval));
|
||||
validate(&ret, mess, arg, retval, "set module id", DEC);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, NULL, 0);
|
||||
|
Reference in New Issue
Block a user