diff --git a/python/src/detector.cpp b/python/src/detector.cpp index 82acb1eef..7677fbae4 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -1520,11 +1520,11 @@ void init_det(py::module &m) { (void (Detector::*)(const std::string &, const std::string &, sls::Positions)) & Detector::copyDetectorServer, - py::arg(), py::arg(), py::arg() = Positions{}) + py::arg(), py::arg(), py::arg() = Positions{}) .def("updateDetectorServer", (void (Detector::*)(const std::string &, sls::Positions)) & Detector::updateDetectorServer, - py::arg(), py::arg() = Positions{}) + py::arg(), py::arg() = Positions{}) .def("updateKernel", (void (Detector::*)(const std::string &, sls::Positions)) & Detector::updateKernel, @@ -1542,6 +1542,14 @@ void init_det(py::module &m) { sls::Positions)) & Detector::updateFirmwareAndServer, py::arg(), py::arg(), py::arg() = Positions{}) + .def("getUpdateMode", + (Result(Detector::*)(sls::Positions) const) & + Detector::getUpdateMode, + py::arg() = Positions{}) + .def("setUpdateMode", + (void (Detector::*)(bool, sls::Positions)) & + Detector::setUpdateMode, + py::arg(), py::arg() = Positions{}) .def("readRegister", (Result(Detector::*)(uint32_t, sls::Positions) const) & Detector::readRegister, diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index bd4da43da..117c6a449 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index 5a167a967..82723f581 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer differ diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h index 2711a76b5..3f0e5a288 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h @@ -3,7 +3,7 @@ #pragma once #include "sls/sls_detector_defs.h" -#define LINKED_SERVER_NAME "/home/root/executables/eigerDetectorServer" +#define LINKED_SERVER_NAME "eigerDetectorServer" #define REQUIRED_FIRMWARE_VERSION (29) // virtual ones renamed for consistency diff --git a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer index 35b3545c0..d3a614452 100755 Binary files a/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer and b/slsDetectorServers/gotthard2DetectorServer/bin/gotthard2DetectorServer_developer differ diff --git a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer index 004ff7e60..a31c817e7 100755 Binary files a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer and b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer differ diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer index 0b31a5ffb..cdc7854cd 100755 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer and b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_developer differ diff --git a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer index e936ffdbb..e74dfa6bc 100755 Binary files a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer and b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer differ diff --git a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer index 5f2bb2c8f..d742a99ae 100755 Binary files a/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer and b/slsDetectorServers/mythen3DetectorServer/bin/mythen3DetectorServer_developer differ diff --git a/slsDetectorServers/slsDetectorServer/include/common.h b/slsDetectorServers/slsDetectorServer/include/common.h index 821e28040..4b86f6dc9 100644 --- a/slsDetectorServers/slsDetectorServer/include/common.h +++ b/slsDetectorServers/slsDetectorServer/include/common.h @@ -8,9 +8,15 @@ #include #include +#define UPDATE_FILE "update.txt" +#ifdef VIRTUAL +#define TEMP_PROG_FOLDER_NAME "/tmp/" +#else #define TEMP_PROG_FOLDER_NAME "/var/tmp/" #define TEMP_PROG_FOLDER_NAME_ALL_FILES "/var/tmp/*" -#define TEMP_PROG_FILE_NAME TEMP_PROG_FOLDER_NAME "tmp.rawbin" +#endif + +#define TEMP_PROG_FILE_NAME TEMP_PROG_FOLDER_NAME "tmp.rawbin" enum numberMode { DEC, HEX }; enum PROGRAM_INDEX { PROGRAM_FPGA, PROGRAM_KERNEL, PROGRAM_SERVER }; @@ -57,3 +63,6 @@ int writeBinaryFile(char *mess, char *fname, char *buffer, const uint64_t filesize, char *errorPrefix); int moveBinaryFile(char *mess, char *dest, char *src, char *errorPrefix); + +int createEmptyFile(char *mess, char *fname, char *errorPrefix); +int deleteFile(char *mess, char *fname, char *errorPrefix); diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h index 679ac96fa..8948e19d4 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorServer_funcs.h @@ -9,6 +9,7 @@ #define REBOOT (-400) // initialization functions +int updateModeAllowedFunction(int file_des); int printSocketReadError(); void init_detector(); int decode_function(int); @@ -286,4 +287,6 @@ void receive_program_via_blackfin(int file_des, enum PROGRAM_INDEX index, char *checksum, char *serverName); void receive_program_default(int file_des, enum PROGRAM_INDEX index, char *functionType, uint64_t filesize, - char *checksum, char *serverName); \ No newline at end of file + char *checksum, char *serverName); +int get_update_mode(int); +int set_update_mode(int); \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/common.c b/slsDetectorServers/slsDetectorServer/src/common.c index 45ebc9413..629038a10 100644 --- a/slsDetectorServers/slsDetectorServer/src/common.c +++ b/slsDetectorServers/slsDetectorServer/src/common.c @@ -434,8 +434,19 @@ int setupDetectorServer(char *mess, char *sname) { LOG(logINFO, ("\tPermissions modified\n")); // symbolic link - if (snprintf(cmd, MAX_STR_LENGTH, "ln -sf %s %s", sname, - LINKED_SERVER_NAME) >= MAX_STR_LENGTH) { + const int fileNameSize = 128; + char linkname[fileNameSize]; + if (getAbsPath(linkname, fileNameSize, LINKED_SERVER_NAME) == FAIL) { + sprintf( + mess, + "Could not copy detector server. Could not get abs path of current " + "process\n"); + LOG(logERROR, (mess)); + return FAIL; + } + + if (snprintf(cmd, MAX_STR_LENGTH, "ln -sf %s %s", sname, linkname) >= + MAX_STR_LENGTH) { strcpy(mess, "Could not copy detector server. Command to " "create symbolic link too long\n"); LOG(logERROR, (mess)); @@ -451,6 +462,7 @@ int setupDetectorServer(char *mess, char *sname) { LOG(logINFO, ("\tSymbolic link created\n")); // blackfin boards (respawn) (only kept for backwards compatibility) +#ifndef VIRTUAL #if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) || \ defined(GOTTHARDD) // delete every line with DetectorServer in /etc/inittab @@ -467,7 +479,7 @@ int setupDetectorServer(char *mess, char *sname) { // add new link name to /etc/inittab if (snprintf(cmd, MAX_STR_LENGTH, "echo 'ttyS0::respawn:/./%s' >> /etc/inittab", - LINKED_SERVER_NAME) >= MAX_STR_LENGTH) { + linkname) >= MAX_STR_LENGTH) { strcpy(mess, "Could not copy detector server. Command " "to add new server for spawning is too long\n"); LOG(logERROR, (mess)); @@ -481,6 +493,7 @@ int setupDetectorServer(char *mess, char *sname) { } LOG(logINFO, ("\tinittab: updated for respawning\n")); +#endif #endif // sync @@ -554,6 +567,7 @@ int writeBinaryFile(char *mess, char *fname, char *buffer, } int moveBinaryFile(char *mess, char *dest, char *src, char *errorPrefix) { + char cmd[MAX_STR_LENGTH] = {0}; char retvals[MAX_STR_LENGTH] = {0}; @@ -567,6 +581,7 @@ int moveBinaryFile(char *mess, char *dest, char *src, char *errorPrefix) { LOG(logERROR, (mess)); return FAIL; } + if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) { snprintf(mess, MAX_STR_LENGTH, "Could not %s. (moving). %s\n", errorPrefix, retvals); @@ -576,3 +591,76 @@ int moveBinaryFile(char *mess, char *dest, char *src, char *errorPrefix) { LOG(logINFO, ("\tMoved file from %s to %s\n", src, dest)); return OK; } + +int createEmptyFile(char *mess, char *fname, char *errorPrefix) { + const int fileNameSize = 128; + char fullname[fileNameSize]; + if (getAbsPath(fullname, fileNameSize, fname) == FAIL) { + sprintf(mess, + "Could not %s. Could not get abs path of current " + "process\n", + errorPrefix); + LOG(logERROR, (mess)); + return FAIL; + } + + char cmd[MAX_STR_LENGTH] = {0}; + char retvals[MAX_STR_LENGTH] = {0}; + + char *format = "touch %s"; + if (snprintf(cmd, MAX_STR_LENGTH, format, fullname) >= MAX_STR_LENGTH) { + sprintf(mess, "Could not %s. Command to create is too long\n", + errorPrefix); + LOG(logERROR, (mess)); + return FAIL; + } + + if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) { + snprintf(mess, MAX_STR_LENGTH, + "Could not %s. (creating empty file %s): %s\n", errorPrefix, + fullname, retvals); + LOG(logERROR, (mess)); + return FAIL; + } + LOG(logINFO, ("\tEmpty file created: %s (%s)\n", fullname, errorPrefix)); + return OK; +} + +int deleteFile(char *mess, char *fname, char *errorPrefix) { + const int fileNameSize = 128; + char fullname[fileNameSize]; + if (getAbsPath(fullname, fileNameSize, fname) == FAIL) { + sprintf(mess, + "Could not %s. Could not get abs path of current " + "process\n", + errorPrefix); + LOG(logERROR, (mess)); + return FAIL; + } + + if (access(fullname, F_OK) == 0) { + char cmd[MAX_STR_LENGTH] = {0}; + char retvals[MAX_STR_LENGTH] = {0}; + char *format = "rm %s"; + + if (snprintf(cmd, MAX_STR_LENGTH, format, fullname) >= MAX_STR_LENGTH) { + sprintf(mess, "Could not %s. Command to delete is too long\n", + errorPrefix); + LOG(logERROR, (mess)); + return FAIL; + } + + if (executeCommand(cmd, retvals, logDEBUG1) == FAIL) { + snprintf(mess, MAX_STR_LENGTH, + "Could not %s. (deleting file %s). %s\n", errorPrefix, + fullname, retvals); + LOG(logERROR, (mess)); + return FAIL; + } + LOG(logINFO, ("\tDeleted file: %s (%s)\n", fullname, errorPrefix)); + } else { + LOG(logINFO, + ("\tFile does not exist anyway: %s (%s)\n", fullname, errorPrefix)); + } + return OK; +} \ No newline at end of file diff --git a/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c b/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c index a29215061..662de51e7 100644 --- a/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c +++ b/slsDetectorServers/slsDetectorServer/src/programViaBlackfin.c @@ -219,6 +219,9 @@ int resetFPGA(char *mess) { } int emptyTempFolder(char *mess) { +#ifdef VIRTUAL + return OK; +#else char cmd[MAX_STR_LENGTH] = {0}; char retvals[MAX_STR_LENGTH] = {0}; @@ -239,6 +242,7 @@ int emptyTempFolder(char *mess) { } LOG(logINFO, ("\tEmptied temp folder(%s)\n", TEMP_PROG_FOLDER_NAME)); return OK; +#endif } int preparetoCopyProgram(char *mess, char *functionType, FILE **fd, diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c index 0b8ada232..e11055123 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer.c @@ -4,6 +4,7 @@ The port number is passed as an argument */ #include "clogger.h" +#include "common.h" #include "communication_funcs.h" #include "sharedMemory.h" #include "sls/sls_detector_defs.h" @@ -150,7 +151,7 @@ int main(int argc, char *argv[]) { break; case 'u': - LOG(logINFO, ("Detected update mode\n")); + LOG(logINFO, ("Detected update mode from command line\n")); updateFlag = 1; break; @@ -185,6 +186,24 @@ int main(int argc, char *argv[]) { if (sharedMemory_create(portno) == FAIL) { return -1; } + + if (updateFlag == 0) { + // update flag if update file exists (command line arg overwrites) + const int fileNameSize = 128; + char fname[fileNameSize]; + if (getAbsPath(fname, fileNameSize, UPDATE_FILE) == FAIL) { + LOG(logERROR, + ("Could not get abs path to check if update file exists. " + "Will try current folder instead.\n")); + strcpy(fname, UPDATE_FILE); + } + if (access(fname, F_OK) == 0) { + updateFlag = 1; + LOG(logINFOBLUE, ("File Found: Update Mode enabled\n")); + } else { + LOG(logINFOBLUE, ("File not Found: Update Mode diabled\n")); + } + } #ifdef STOP_SERVER // start stop server process char cmd[MAX_STR_LENGTH]; diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 5a2976a8a..da7b40c10 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -77,6 +77,42 @@ char scanErrMessage[MAX_STR_LENGTH] = ""; /* initialization functions */ +int updateModeAllowedFunction(int file_des) { + unsigned int listsize = 19; + enum detFuncs list[] = {F_EXEC_COMMAND, + F_GET_DETECTOR_TYPE, + F_GET_FIRMWARE_VERSION, + F_GET_SERVER_VERSION, + F_GET_SERIAL_NUMBER, + F_WRITE_REGISTER, + F_READ_REGISTER, + F_LOCK_SERVER, + F_GET_LAST_CLIENT_IP, + F_PROGRAM_FPGA, + F_RESET_FPGA, + F_CHECK_VERSION, + F_COPY_DET_SERVER, + F_REBOOT_CONTROLLER, + F_GET_KERNEL_VERSION, + F_UPDATE_KERNEL, + F_UPDATE_DETECTOR_SERVER, + F_GET_UPDATE_MODE, + F_SET_UPDATE_MODE}; + for (unsigned int i = 0; i < listsize; ++i) { + if ((unsigned int)fnum == list[i]) { + return OK; + } + } + ret = FAIL; + sprintf(mess, + "Funcion (%s) cannot be executed in update mode. Please disable " + "update mode to continue.\n", + getFunctionNameFromEnum((enum detFuncs)fnum)); + LOG(logERROR, (mess)); + Server_SendResult(file_des, INT32, NULL, 0); + return FAIL; +} + int printSocketReadError() { LOG(logERROR, ("Error reading from socket. Possible socket crash.\n")); return FAIL; @@ -117,6 +153,13 @@ int decode_function(int file_des) { LOG(logERROR, ("Unknown function enum %d\n", fnum)); ret = (M_nofunc)(file_des); } else { + + // udpate mode restricted functions, send error (without waitin for + // arguments) + if (updateFlag && updateModeAllowedFunction(file_des) == FAIL) { + return FAIL; + } + LOG(logDEBUG1, (" calling function fnum=%d, (%s)\n", fnum, getFunctionNameFromEnum((enum detFuncs)fnum))); ret = (*flist[fnum])(file_des); @@ -416,6 +459,8 @@ void function_table() { flist[F_GET_KERNEL_VERSION] = &get_kernel_version; flist[F_UPDATE_KERNEL] = &update_kernel; flist[F_UPDATE_DETECTOR_SERVER] = &update_detector_server; + flist[F_GET_UPDATE_MODE] = &get_update_mode; + flist[F_SET_UPDATE_MODE] = &set_update_mode; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -445,6 +490,9 @@ void modeNotImplemented(char *modename, int mode) { } int executeCommand(char *command, char *result, enum TLogLevel level) { + ret = OK; + memset(mess, 0, sizeof(mess)); + const size_t tempsize = 256; char temp[tempsize]; memset(temp, 0, tempsize); @@ -469,18 +517,20 @@ int executeCommand(char *command, char *result, enum TLogLevel level) { memset(temp, 0, tempsize); } result[MAX_STR_LENGTH - 1] = '\0'; - int success = pclose(sysFile); - if (strlen(result)) { - if (success) { - success = FAIL; - LOG(logERROR, ("Executing cmd[%s]:%s\n", cmd, result)); - } else { - LOG(level, ("Result:\n[%s]\n", result)); - } - } else { - LOG(level, ("No result\n")); + if (strlen(result) == 0) { + strcpy(result, "No result"); } - return success; + + int retval = OK; + int success = pclose(sysFile); + if (success) { + retval = FAIL; + LOG(logERROR, ("Executing cmd[%s]:%s\n", cmd, result)); + } else { + LOG(level, ("Result:\n[%s]\n", result)); + } + + return retval; } int M_nofunc(int file_des) { @@ -9271,13 +9321,33 @@ int receive_program(int file_des, enum PROGRAM_INDEX index) { LOG(logINFO, ("\tServer Name: %s\n", serverName)); } + // in same folder as current process (will also work for virtual then + // with write permissions) + { + const int fileNameSize = 128; + char fname[fileNameSize]; + if (getAbsPath(fname, fileNameSize, serverName) == FAIL) { + ret = FAIL; + sprintf(mess, + "Could not %s. Could not get abs path of current " + "process\n", + functionType); + LOG(logERROR, (mess)); + Server_SendResult(file_des, INT32, NULL, 0); + } else { + strcpy(serverName, fname); + } + } + + if (ret == OK) { #if defined(GOTTHARD2D) || defined(MYTHEN3D) || defined(EIGERD) - receive_program_default(file_des, index, functionType, filesize, - checksum, serverName); + receive_program_default(file_des, index, functionType, filesize, + checksum, serverName); #else - receive_program_via_blackfin(file_des, index, functionType, filesize, - checksum, serverName); + receive_program_via_blackfin(file_des, index, functionType, + filesize, checksum, serverName); #endif + } if (ret == OK) { LOG(logINFOGREEN, ("%s completed successfully\n", functionType)); @@ -9475,20 +9545,16 @@ void receive_program_default(int file_des, enum PROGRAM_INDEX index, "update detector server"); // extra step to write to temp and move to real file as // fopen will give text busy if opening same name as process name - char dest[MAX_STR_LENGTH] = {0}; - sprintf(dest, "%s%s", - (myDetectorType == EIGER ? "/home/root/executables/" : ""), - serverName); - if (ret == OK) { - ret = moveBinaryFile(mess, dest, TEMP_PROG_FILE_NAME, + ret = moveBinaryFile(mess, serverName, TEMP_PROG_FILE_NAME, "update detector server"); } if (ret == OK) { - ret = verifyChecksumFromFile(mess, functionType, checksum, dest); + ret = verifyChecksumFromFile(mess, functionType, checksum, + serverName); } if (ret == OK) { - ret = setupDetectorServer(mess, dest); + ret = setupDetectorServer(mess, serverName); } break; #endif @@ -9502,4 +9568,42 @@ void receive_program_default(int file_des, enum PROGRAM_INDEX index, // free resources free(src); #endif +} + +int get_update_mode(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int retval = -1; + LOG(logDEBUG1, ("Getting update mode\n")); + + retval = updateFlag; + LOG(logDEBUG1, ("update mode retval: %d\n", retval)); + + return Server_SendResult(file_des, INT32, &retval, sizeof(retval)); +} + +int set_update_mode(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + int arg = -1; + + if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) + return printSocketReadError(); + LOG(logDEBUG1, ("Setting update mode to \n", arg)); + + switch (arg) { + case 0: + ret = deleteFile(mess, UPDATE_FILE, "unset update mode"); + break; + case 1: + ret = createEmptyFile(mess, UPDATE_FILE, "set update mode"); + break; + default: + ret = FAIL; + sprintf(mess, "Could not set updatemode. Options: 0 or 1\n"); + LOG(logERROR, (mess)); + break; + } + + return Server_SendResult(file_des, INT32, NULL, 0); } \ No newline at end of file diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 389fec128..b617eb33a 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -1733,8 +1733,8 @@ class Detector { /** [Jungfrau][CTB][Moench] Advanced user Function! */ void resetFPGA(Positions pos = {}); - /** [[deprecated ("Replaced by updateDetectorServer, which does not require tftp")]] - * [Jungfrau][Eiger][Gotthard][CTB][Moench][Mythen3][Gotthard2] + /** [[deprecated ("Replaced by updateDetectorServer, which does not require + * tftp")]] [Jungfrau][Eiger][Gotthard][CTB][Moench][Mythen3][Gotthard2] * Advanced user Function! \n * Copy detector server fname from tftp folder of hostname to detector. Also * creates a symbolic link to a shorter name (without vx.x.x). Then the @@ -1764,13 +1764,14 @@ class Detector { * Function! */ void rebootController(Positions pos = {}); - /** [[deprecated ("Replaced by overloaded updateDetectorServer, which does not require tftp and has one less argument")]] - * Advanced user Function!\n [Jungfrau][Gotthard][CTB][Moench] Updates the - * firmware, detector server, make a soft link and then reboots detector - * controller. \n [Mythen3][Gotthard2] Will require a script to start up the - * shorter named server link at start up \n sname is name of detector - * server binary found on tftp folder of host pc \n hostname is name of pc - * to tftp from \n fname is programming file name with full path to it + /** [[deprecated ("Replaced by overloaded updateDetectorServer, which does + * not require tftp and has one less argument")]] Advanced user Function!\n + * [Jungfrau][Gotthard][CTB][Moench] Updates the firmware, detector server, + * make a soft link and then reboots detector controller. \n + * [Mythen3][Gotthard2] Will require a script to start up the shorter named + * server link at start up \n sname is name of detector server binary found + * on tftp folder of host pc \n hostname is name of pc to tftp from \n fname + * is programming file name with full path to it */ void updateFirmwareAndServer(const std::string &sname, const std::string &hostname, @@ -1780,12 +1781,19 @@ class Detector { * Advanced user Function!\n [Jungfrau][Gotthard][CTB][Moench] Updates the * firmware, detector server, make a soft link and then reboots detector * controller. \n [Mythen3][Gotthard2] Will require a script to start up the - * shorter named server link at start up \n sname is full path name of detector - * server \n fname is programming file name with full path to it + * shorter named server link at start up \n sname is full path name of + * detector server \n fname is programming file name with full path to it */ void updateFirmwareAndServer(const std::string &sname, const std::string &fname, Positions pos = {}); + Result getUpdateMode(Positions pos = {}); + + /** Restarts detector server in update mode. This is useful when + * server-firmware compatibility is at its worst and server cannot start up + * normally */ + void setUpdateMode(const bool updatemode, Positions pos = {}); + /** Advanced user Function! \n * Goes to stop server. Hence, can be called while calling blocking * acquire(). \n [Eiger] Address is +0x100 for only left, +0x200 for only diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 84f485bee..4555a2437 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -2853,7 +2853,8 @@ std::string CmdProxy::CopyDetectorServer(int action) { std::ostringstream os; os << cmd << ' '; if (action == defs::HELP_ACTION) { - LOG(logWARNING) << "Deprecated! Replaced by updatedetectorserver that requires no tftp.\n"; + LOG(logWARNING) << "Deprecated! Replaced by updatedetectorserver that " + "requires no tftp.\n"; os << "[server_name (in tftp folder)] " "[pc_host_name]\n\t[Jungfrau][Eiger][Ctb][Moench][Mythen3][" "Gotthard2] Copies detector server via TFTP from pc. Ensure that " @@ -2933,15 +2934,17 @@ std::string CmdProxy::UpdateFirmwareAndDetectorServer(int action) { std::ostringstream os; os << cmd << ' '; if (action == defs::HELP_ACTION) { - os << "\n\tDeprecated!! Replaced without using tftp (as shown next)[server_name" - " (in tftp folder)] [pc_host_name] [fname.pof (incl full path)]"; - os << "\n\t[server_name (incl fullpath)] [fname.pof (incl full path)] " - "This does not use tftp." + os << "\n\tUsing tftp: Deprecated!! [server_name" + " (in tftp folder)] [pc_host_name] [fname.pof (incl full path)]" + "\n\tWithout tftp: Recommended [server_name (incl fullpath)] " + "[fname.pof (incl full path)] " + "This does not use tftp." "\n\t\t[Jungfrau][Gotthard][CTB][Moench] Updates the " "firmware, detector server, creates the symbolic link and then " - "reboots detector controller. \n\t[Mythen3][Gotthard2] will " + "reboots detector controller. \n\t\t[Mythen3][Gotthard2] will " "require a script to start up the shorter named server link at " - "start up. \n\t\tsname is full path name of detector server binary" + "start up. \n\t\tsname is full path name of detector server " + "binary" "\n\t\tfname is full path of programming file" << '\n'; } else if (action == defs::GET_ACTION) { @@ -2952,17 +2955,20 @@ std::string CmdProxy::UpdateFirmwareAndDetectorServer(int action) { } int fpos = args.size() - 1; - if (args[fpos].find(".pof") == std::string::npos && args[fpos].find(".rbf") == std::string::npos) { + if (args[fpos].find(".pof") == std::string::npos && + args[fpos].find(".rbf") == std::string::npos) { throw sls::RuntimeError("Programming file must be a pof/rbf file."); } if (args.size() == 3) { - LOG(logWARNING) << "Deprecated! Recommend to use same command without tftp (no pc name) and using full path to the server binary"; + LOG(logWARNING) + << "Deprecated! Recommend to use same command without tftp (no " + "pc name) and using full path to the server binary"; det->updateFirmwareAndServer(args[0], args[1], args[2], - std::vector{det_id}); + std::vector{det_id}); } else { det->updateFirmwareAndServer(args[0], args[1], - std::vector{det_id}); + std::vector{det_id}); } os << "successful\n"; } else { diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 2501e2e27..70b47cd0c 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -1063,6 +1063,7 @@ class CmdProxy { {"updatekernel", &CmdProxy::UpdateKernel}, {"rebootcontroller", &CmdProxy::rebootcontroller}, {"update", &CmdProxy::UpdateFirmwareAndDetectorServer}, + {"updatemode", &CmdProxy::updatemode}, {"reg", &CmdProxy::Register}, {"adcreg", &CmdProxy::AdcRegister}, {"setbit", &CmdProxy::BitOperations}, @@ -2184,6 +2185,12 @@ class CmdProxy { "\n\t[Jungfrau][Ctb][Moench][Gotthard][Mythen3][" "Gotthard2] Reboot controller of detector."); + INTEGER_COMMAND_VEC_ID( + updatemode, getUpdateMode, setUpdateMode, StringTo, + "[0|1]\n\tRestart the detector server in update mode or not. This is " + "useful when server-firmware compatibility is at its worst and server " + "cannot start up normally"); + EXECUTE_SET_COMMAND( firmwaretest, executeFirmwareTest, "\n\t[Jungfrau][Gotthard][Mythen3][Gotthard2][Ctb][Moench] Firmware " diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index a8f999713..b124dd23b 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -2195,6 +2195,17 @@ void Detector::updateFirmwareAndServer(const std::string &sname, programFPGA(fname, pos); } +Result Detector::getUpdateMode(Positions pos) { + return pimpl->Parallel(&Module::getUpdateMode, pos); +} + +void Detector::setUpdateMode(const bool updatemode, Positions pos) { + pimpl->Parallel(&Module::setUpdateMode, pos, updatemode); + if (getDetectorType().squash() != defs::EIGER) { + rebootController(pos); + } +} + Result Detector::readRegister(uint32_t addr, Positions pos) const { return pimpl->Parallel(&Module::readRegister, pos, addr); } diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 2d51e7b58..98c7e4748 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -338,7 +338,9 @@ void DetectorImpl::updateDetectorSize() { << shm()->numberOfChannels.y; for (auto &module : modules) { - module->updateNumberOfModule(shm()->numberOfModule); + if (module->getUpdateMode() == 0) { + module->updateNumberOfModule(shm()->numberOfModule); + } } } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index de0559d37..ce287feaf 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -2539,8 +2539,9 @@ void Module::updateDetectorServer(std::vector buffer, "Update Detector Server (no tftp)", serverName); break; default: - throw RuntimeError("Updating DetectorServer via the package is not implemented " - "for this detector"); + throw RuntimeError( + "Updating DetectorServer via the package is not implemented " + "for this detector"); } } @@ -2567,6 +2568,14 @@ void Module::rebootController() { << "): Controller rebooted successfully!"; } +bool Module::getUpdateMode() { return sendToDetector(F_GET_UPDATE_MODE); } + +void Module::setUpdateMode(const bool updatemode) { + sendToDetector(F_SET_UPDATE_MODE, static_cast(updatemode), nullptr); + LOG(logINFO) << "Module " << moduleIndex << " (" << shm()->hostname + << "): Update Mode set to " << updatemode << "!"; +} + uint32_t Module::readRegister(uint32_t addr) const { return sendToDetectorStop(F_READ_REGISTER, addr); } @@ -3566,7 +3575,7 @@ void Module::sendProgram(bool blackfin, std::vector buffer, throw DetectorError(os.str()); } LOG(logINFO) << "Module " << moduleIndex << " (" << shm()->hostname - << "): " << functionType << " udpated successfully"; + << "): " << functionType << " successful"; } void Module::simulatingActivityinDetector(const std::string &functionType, diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 0750fb941..a11de9065 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -545,6 +545,8 @@ class Module : public virtual slsDetectorDefs { const std::string &serverName); void updateKernel(std::vector buffer); void rebootController(); + bool getUpdateMode(); + void setUpdateMode(const bool updatemode); uint32_t readRegister(uint32_t addr) const; uint32_t writeRegister(uint32_t addr, uint32_t val); void setBit(uint32_t addr, int n); diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 8606c5f40..a0b3f71cb 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -256,6 +256,8 @@ enum detFuncs { F_GET_KERNEL_VERSION, F_UPDATE_KERNEL, F_UPDATE_DETECTOR_SERVER, + F_GET_UPDATE_MODE, + F_SET_UPDATE_MODE, NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 256, /**< detector function should not exceed this @@ -613,6 +615,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_SET_READOUT_SPEED: return "F_SET_READOUT_SPEED"; case F_GET_KERNEL_VERSION: return "F_GET_KERNEL_VERSION"; case F_UPDATE_DETECTOR_SERVER: return "F_UPDATE_DETECTOR_SERVER"; + case F_GET_UPDATE_MODE: return "F_GET_UPDATE_MODE"; + case F_SET_UPDATE_MODE: return "F_SET_UPDATE_MODE"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index 681ddae93..70144dce5 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -6,10 +6,10 @@ #define APILIB 0x211027 #define APIRECEIVER 0x211020 #define APIGUI 0x211021 -#define APICTB 0x211117 -#define APIGOTTHARD 0x211117 -#define APIGOTTHARD2 0x211117 -#define APIJUNGFRAU 0x211117 -#define APIMYTHEN3 0x211117 -#define APIMOENCH 0x211111 -#define APIEIGER 0x211117 +#define APICTB 0x211118 +#define APIGOTTHARD 0x211118 +#define APIGOTTHARD2 0x211118 +#define APIJUNGFRAU 0x211118 +#define APIMYTHEN3 0x211118 +#define APIMOENCH 0x211117 +#define APIEIGER 0x211118