diff --git a/slsDetectorServers/ctbDetectorServer/gitInfo.txt b/slsDetectorServers/ctbDetectorServer/gitInfo.txt index 8b4e37cab..23624f0bb 100644 --- a/slsDetectorServers/ctbDetectorServer/gitInfo.txt +++ b/slsDetectorServers/ctbDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorPackage/slsDetectorServers/ctbDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: 5a4122ae7c8dae1572e9db336de70183956e58c7 -Revision: 50 -Branch: refactor +Repsitory UUID: 45b837b42a9f190cb68688fd2b1a8d77c3050578 +Revision: 52 +Branch: program2 Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4481 -Last Changed Date: 2019-03-28 08:18:03.000000002 +0100 ../slsDetectorServer/slsDetectorFunctionList.h +Last Changed Rev: 4490 +Last Changed Date: 2019-04-02 17:21:25.000000002 +0200 ./slsDetectorServer_defs.h diff --git a/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h b/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h index b7b7c4d4f..7cb23e08f 100644 --- a/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h +++ b/slsDetectorServers/ctbDetectorServer/gitInfoCtb.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "5a4122ae7c8dae1572e9db336de70183956e58c7" +#define GITREPUUID "45b837b42a9f190cb68688fd2b1a8d77c3050578" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4481 -#define GITDATE 0x20190328 -#define GITBRANCH "refactor" +#define GITREV 0x4490 +#define GITDATE 0x20190402 +#define GITBRANCH "program2" diff --git a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h index 3a2f65da0..82ba1a85e 100644 --- a/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/ctbDetectorServer/slsDetectorServer_defs.h @@ -3,11 +3,9 @@ #include "RegisterDefs.h" -#define GOODBYE (-200) #define MIN_REQRD_VRSN_T_RD_API 0x181130 #define REQRD_FRMWR_VRSN 0x190310 -#define PROGRAMMING_MODE (0x2) #define CTRL_SRVR_INIT_TIME_US (1 * 1000 * 1000) /* Struct Definitions */ diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_refactor b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_refactor index 320b35969..bba1d168c 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_refactor and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_refactor differ diff --git a/slsDetectorServers/eigerDetectorServer/gitInfo.txt b/slsDetectorServers/eigerDetectorServer/gitInfo.txt index dc8fa658b..3390e70c3 100644 --- a/slsDetectorServers/eigerDetectorServer/gitInfo.txt +++ b/slsDetectorServers/eigerDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorPackage/slsDetectorServers/eigerDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: c7ad548e4c2026a826b9f269f32d9970ce0a44e8 -Revision: 31 -Branch: refactor +Repsitory UUID: 45b837b42a9f190cb68688fd2b1a8d77c3050578 +Revision: 33 +Branch: program2 Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4478 -Last Changed Date: 2019-03-27 08:46:12.000000002 +0100 ./Beb.c +Last Changed Rev: 4490 +Last Changed Date: 2019-04-02 14:46:09.000000002 +0200 ../slsDetectorServer/slsDetectorServer_funcs.c diff --git a/slsDetectorServers/eigerDetectorServer/gitInfoEiger.h b/slsDetectorServers/eigerDetectorServer/gitInfoEiger.h index d215e992d..7cb23e08f 100644 --- a/slsDetectorServers/eigerDetectorServer/gitInfoEiger.h +++ b/slsDetectorServers/eigerDetectorServer/gitInfoEiger.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "c7ad548e4c2026a826b9f269f32d9970ce0a44e8" +#define GITREPUUID "45b837b42a9f190cb68688fd2b1a8d77c3050578" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4478 -#define GITDATE 0x20190327 -#define GITBRANCH "refactor" +#define GITREV 0x4490 +#define GITDATE 0x20190402 +#define GITBRANCH "program2" diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h index fd208555a..3ab0c42f6 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h @@ -1,7 +1,6 @@ #pragma once #include "sls_detector_defs.h" -#define GOODBYE (-200) #define REQUIRED_FIRMWARE_VERSION (22) #define IDFILECOMMAND "more /home/root/executables/detid.txt" diff --git a/slsDetectorServers/gotthardDetectorServer/gitInfo.txt b/slsDetectorServers/gotthardDetectorServer/gitInfo.txt index 5fbf2fea2..5c32dd9cb 100644 --- a/slsDetectorServers/gotthardDetectorServer/gitInfo.txt +++ b/slsDetectorServers/gotthardDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorPackage/slsDetectorServers/gotthardDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: cd5aea895b07b7af25e3fb74a341a861f9aa291c -Revision: 26 -Branch: jungfrau +Repsitory UUID: 45b837b42a9f190cb68688fd2b1a8d77c3050578 +Revision: 28 +Branch: program2 Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4473 -Last Changed Date: 2019-03-22 17:13:44.000000002 +0100 ../slsDetectorServer/slsDetectorServer_funcs.c +Last Changed Rev: 4490 +Last Changed Date: 2019-04-02 17:21:48.000000002 +0200 ./slsDetectorServer_defs.h diff --git a/slsDetectorServers/gotthardDetectorServer/gitInfoGotthard.h b/slsDetectorServers/gotthardDetectorServer/gitInfoGotthard.h index 540b4d733..7cb23e08f 100644 --- a/slsDetectorServers/gotthardDetectorServer/gitInfoGotthard.h +++ b/slsDetectorServers/gotthardDetectorServer/gitInfoGotthard.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "cd5aea895b07b7af25e3fb74a341a861f9aa291c" +#define GITREPUUID "45b837b42a9f190cb68688fd2b1a8d77c3050578" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4473 -#define GITDATE 0x20190322 -#define GITBRANCH "jungfrau" +#define GITREV 0x4490 +#define GITDATE 0x20190402 +#define GITBRANCH "program2" diff --git a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_defs.h index 54bac869a..6c037e852 100644 --- a/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/gotthardDetectorServer/slsDetectorServer_defs.h @@ -2,8 +2,6 @@ #include "sls_detector_defs.h" #include -#define GOODBYE (-200) - /* Enums */ enum ADCINDEX {TEMP_FPGA, TEMP_ADC}; enum DACINDEX {VREF_DS, VCASCN_PB, VCASCP_PB, VOUT_CM, VCASC_OUT, VIN_CM, VREF_COMP, IB_TESTC}; diff --git a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_refactor b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_refactor index b5d37dcd8..ab33ee121 100755 Binary files a/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_refactor and b/slsDetectorServers/jungfrauDetectorServer/bin/jungfrauDetectorServer_refactor differ diff --git a/slsDetectorServers/jungfrauDetectorServer/gitInfo.txt b/slsDetectorServers/jungfrauDetectorServer/gitInfo.txt index 73b8cb909..b08798871 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: 969551ae373167dcfc28466f19e53a349da70f67 -Revision: 33 -Branch: program +Repsitory UUID: 45b837b42a9f190cb68688fd2b1a8d77c3050578 +Revision: 34 +Branch: program2 Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4489 -Last Changed Date: 2019-04-01 09:39:27.000000002 +0200 ../slsDetectorServer/slsDetectorServer_funcs.c +Last Changed Rev: 4490 +Last Changed Date: 2019-04-02 08:57:37.000000002 +0200 ../slsDetectorServer/slsDetectorServer_funcs.c diff --git a/slsDetectorServers/jungfrauDetectorServer/gitInfoJungfrau.h b/slsDetectorServers/jungfrauDetectorServer/gitInfoJungfrau.h index f12356498..7cb23e08f 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 "969551ae373167dcfc28466f19e53a349da70f67" +#define GITREPUUID "45b837b42a9f190cb68688fd2b1a8d77c3050578" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4489 -#define GITDATE 0x20190401 -#define GITBRANCH "program" +#define GITREV 0x4490 +#define GITDATE 0x20190402 +#define GITBRANCH "program2" diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h index 8cc2c51ff..f90873e5e 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h @@ -3,11 +3,9 @@ #include "RegisterDefs.h" -#define GOODBYE (-200) #define MIN_REQRD_VRSN_T_RD_API 0x171220 #define REQRD_FRMWR_VRSN 0x181206 // temp bug fix from last version, timing mode is backwards compatible -#define PROGRAMMING_MODE (0x2) #define BOARD_JUNGFRAU_TYPE (8) #define CTRL_SRVR_INIT_TIME_US (300 * 1000) diff --git a/slsDetectorServers/moenchDetectorServer/gitInfo.txt b/slsDetectorServers/moenchDetectorServer/gitInfo.txt index 847d6065c..9ac1e348e 100644 --- a/slsDetectorServers/moenchDetectorServer/gitInfo.txt +++ b/slsDetectorServers/moenchDetectorServer/gitInfo.txt @@ -1,9 +1,9 @@ Path: slsDetectorPackage/slsDetectorServers/moenchDetectorServer URL: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git Repository Root: origin git@github.com:slsdetectorgroup/slsDetectorPackage.git -Repsitory UUID: 5a4122ae7c8dae1572e9db336de70183956e58c7 -Revision: 26 -Branch: refactor +Repsitory UUID: 45b837b42a9f190cb68688fd2b1a8d77c3050578 +Revision: 28 +Branch: program2 Last Changed Author: Dhanya_Thattil -Last Changed Rev: 4481 -Last Changed Date: 2019-03-28 09:08:53.000000002 +0100 ./slsDetectorFunctionList.c +Last Changed Rev: 4490 +Last Changed Date: 2019-04-02 17:21:40.000000002 +0200 ./slsDetectorServer_defs.h diff --git a/slsDetectorServers/moenchDetectorServer/gitInfoMoench.h b/slsDetectorServers/moenchDetectorServer/gitInfoMoench.h index b7b7c4d4f..7cb23e08f 100644 --- a/slsDetectorServers/moenchDetectorServer/gitInfoMoench.h +++ b/slsDetectorServers/moenchDetectorServer/gitInfoMoench.h @@ -1,6 +1,6 @@ #define GITURL "git@github.com:slsdetectorgroup/slsDetectorPackage.git" -#define GITREPUUID "5a4122ae7c8dae1572e9db336de70183956e58c7" +#define GITREPUUID "45b837b42a9f190cb68688fd2b1a8d77c3050578" #define GITAUTH "Dhanya_Thattil" -#define GITREV 0x4481 -#define GITDATE 0x20190328 -#define GITBRANCH "refactor" +#define GITREV 0x4490 +#define GITDATE 0x20190402 +#define GITBRANCH "program2" diff --git a/slsDetectorServers/moenchDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/moenchDetectorServer/slsDetectorServer_defs.h index 9e512eb0b..c9ab6eb48 100644 --- a/slsDetectorServers/moenchDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/moenchDetectorServer/slsDetectorServer_defs.h @@ -3,11 +3,9 @@ #include "RegisterDefs.h" -#define GOODBYE (-200) #define MIN_REQRD_VRSN_T_RD_API 0x180314 #define REQRD_FRMWR_VRSN 0x180314 -#define PROGRAMMING_MODE (0x2) #define CTRL_SRVR_INIT_TIME_US (300 * 1000) /* Struct Definitions */ diff --git a/slsDetectorServers/slsDetectorServer/communication_funcs.c b/slsDetectorServers/slsDetectorServer/communication_funcs.c index 386e7a79e..9dbfbacee 100755 --- a/slsDetectorServers/slsDetectorServer/communication_funcs.c +++ b/slsDetectorServers/slsDetectorServer/communication_funcs.c @@ -245,9 +245,10 @@ void closeConnection(int file_des) { void exitServer(int socketDescriptor) { if (socketDescriptor >= 0) close(socketDescriptor); - FILE_LOG(logDEBUG3, ("Closing %s server\n", (isControlServer ? "control":"stop"))); + FILE_LOG(logINFO, ("Closing %s server\n", (isControlServer ? "control":"stop"))); FD_CLR(socketDescriptor, &readset); isock--; + fflush(stdout); } diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c index 4bd9e1233..e98af35a4 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer.c @@ -37,7 +37,6 @@ int main(int argc, char *argv[]){ // subsequent read/write to socket gives error - must handle locally signal(SIGPIPE, SIG_IGN); - // circumvent the basic tests { int i; @@ -63,16 +62,6 @@ int main(int argc, char *argv[]){ FILE_LOG(logINFO, ("Detected phase shift of %d\n", phaseShift)); } #endif -#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) - else if(!strcasecmp(argv[i],"-update")){ - FILE_LOG(logINFO, ("Detected update mode\n")); - debugflag = PROGRAMMING_MODE; - } -#endif - else if(strchr(argv[i],'-') != NULL) { - FILE_LOG(logERROR, ("cannot scan program argument %s\n", argv[1])); - return -1; - } } } @@ -116,7 +105,7 @@ int main(int argc, char *argv[]){ } // waits for connection - while(retval != GOODBYE) { + while(retval != GOODBYE && retval != REBOOT) { fd = acceptConnection(sockfd); if (fd > 0) { retval = decode_function(fd); @@ -125,8 +114,13 @@ int main(int argc, char *argv[]){ } exitServer(sockfd); - FILE_LOG(logINFO,("Goodbye!\n")); + if (retval == REBOOT) { + FILE_LOG(logINFOBLUE,("Rebooting!\n")); + fflush(stdout); + system("reboot"); + } + FILE_LOG(logINFO,("Goodbye!\n")); return 0; } diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index 4bc04c5d0..f8c294343 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -58,9 +58,6 @@ void init_detector() { #endif if (isControlServer) { basictests(); -#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) - if (debugflag != PROGRAMMING_MODE) -#endif initControlServer(); #ifdef EIGERD dhcpipad = getDetectorIP(); @@ -85,18 +82,6 @@ int decode_function(int file_des) { } else FILE_LOG(logDEBUG3, ("Received %d bytes\n", n )); - // jungfrau in programming mode -#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) - if ((debugflag == PROGRAMMING_MODE) && - (fnum != F_PROGRAM_FPGA) && - (fnum != F_GET_DETECTOR_TYPE) && - (fnum != F_RESET_FPGA) && - (fnum != F_UPDATE_CLIENT) && - (fnum != F_CHECK_VERSION)) { - ret = (M_nofuncMode)(file_des); - } - else -#endif if (fnum < 0 || fnum >= NUM_DET_FUNCTIONS) { FILE_LOG(logERROR, ("Unknown function enum %d\n", fnum)); ret=(M_nofunc)(file_des); @@ -109,11 +94,22 @@ int decode_function(int file_des) { FILE_LOG(logDEBUG1, ("Error executing the function = %d (%s)\n", fnum, getFunctionName((enum detFuncs)fnum))); } else FILE_LOG(logDEBUG1, ("Function (%s) executed %s\n", - getFunctionName((enum detFuncs)fnum), (ret == OK)?"OK":"FORCE_UPDATE")); + getFunctionName((enum detFuncs)fnum), getRetName())); } return ret; } +const char* getRetName() { + switch(ret) { + case OK: return "OK"; + case FAIL: return "FAIL"; + case FORCE_UPDATE: return "FORCE_UPDATE"; + case GOODBYE: return "GOODBYE"; + case REBOOT: return "REBOOT"; + default: return "unknown"; + } +} + const char* getTimerName(enum timerIndex ind) { switch (ind) { case FRAME_NUMBER: return "frame_number"; @@ -137,6 +133,7 @@ const char* getTimerName(enum timerIndex ind) { } } + const char* getSpeedName(enum speedVariable ind) { switch (ind) { case CLOCK_DIVIDER: return "clock_divider"; @@ -231,6 +228,8 @@ const char* getFunctionName(enum detFuncs func) { case F_SOFTWARE_TRIGGER: return "F_SOFTWARE_TRIGGER"; case F_LED: return "F_LED"; case F_DIGITAL_IO_DELAY: return "F_DIGITAL_IO_DELAY"; + case F_COPY_DET_SERVER: return "F_COPY_DET_SERVER"; + case F_REBOOT_CONTROLLER: return "F_REBOOT_CONTROLLER"; default: return "Unknown Function"; } @@ -301,6 +300,8 @@ void function_table() { flist[F_SOFTWARE_TRIGGER] = &software_trigger; flist[F_LED] = &led; flist[F_DIGITAL_IO_DELAY] = &digital_io_delay; + flist[F_COPY_DET_SERVER] = ©_detector_server; + flist[F_REBOOT_CONTROLLER] = &reboot_controller; // check if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { @@ -354,6 +355,39 @@ void validate64(int64_t arg, int64_t retval, char* modename, enum numberMode num } } +int executeCommand(char* command, char* result, enum TLogLevel level) { + const size_t tempsize = 256; + char temp[tempsize]; + memset(temp, 0, tempsize); + memset(result, 0, MAX_STR_LENGTH); + + FILE_LOG(level, ("Executing command:\n[%s]\n", command)); + strcat(command, " 2>&1"); + + fflush(stdout); + FILE* sysFile = popen(command, "r"); + while(fgets(temp, tempsize, sysFile) != NULL) { + // size left excludes terminating character + size_t sizeleft = MAX_STR_LENGTH - strlen(result) - 1; + // more than the command + if (tempsize > sizeleft) { + strncat(result, temp, sizeleft); + break; + } + strncat(result, temp, tempsize); + memset(temp, 0, tempsize); + } + int sucess = pclose(sysFile); + if (strlen(result)) { + if (sucess) { + sucess = FAIL; + FILE_LOG(logERROR, ("%s\n", result)); + } else { + FILE_LOG(level, ("Result:\n[%s]\n", result)); + } + } + return sucess; +} int M_nofunc(int file_des) { ret = FAIL; @@ -399,27 +433,10 @@ int exec_command(int file_des) { if (receiveData(file_des, cmd, MAX_STR_LENGTH, OTHER) < 0) return printSocketReadError(); - FILE_LOG(logINFO, ("Executing command (%s)\n", cmd)); // set if (Server_VerifyLock() == OK) { - FILE* sysFile = popen(cmd, "r"); - const size_t tempsize = 256; - char temp[tempsize]; - memset(temp, 0, tempsize); - while(fgets(temp, tempsize, sysFile) != NULL) { - // size left excludes terminating character - size_t sizeleft = MAX_STR_LENGTH - strlen(retval) - 1; - // more than the command - if (tempsize > sizeleft) { - strncat(retval, temp, sizeleft); - break; - } - strncat(retval, temp, tempsize); - memset(temp, 0, tempsize); - } - pclose(sysFile); - FILE_LOG(logINFO, ("Result of cmd (%s):\n%s\n", cmd, retval)); + ret = executeCommand(cmd, retval, logINFO); } return Server_SendResult(file_des, OTHER, NO_UPDATE, retval, sizeof(retval)); } @@ -2017,14 +2034,14 @@ int set_speed(int file_des) { sprintf(validateName, "set %s", speedName); #ifndef GOTTHARDD #if defined(CHIPTESTBOARDD) || defined(MOENCHD) || defined(JUNGFRAUD) - if (ind == ADC_PHASE || ind == DBIT_PHASE && mode == 1) { + if ((ind == ADC_PHASE || ind == DBIT_PHASE) && mode == 1) { #if defined(CHIPTESTBOARDD) || defined(MOENCHD) ret = validatePhaseinDegrees(ind, val, retval); #else ret = validatePhaseinDegrees(val, retval); #endif if (ret == FAIL) { - sprintf(mess, "Could not set %s. Set %s, got %s\n", validateName); + sprintf(mess, "Could not set %s. Set %d, got %d\n", validateName, val, retval); FILE_LOG(logERROR,(mess)); } } else @@ -2138,14 +2155,7 @@ int set_port(int file_des) { int update_client(int file_des) { ret = FORCE_UPDATE; memset(mess, 0, sizeof(mess)); -#if defined(JUNGFRAUD) || defined(CHIPTESTBOARDD) || defined(MOENCHD) - if (debugflag == PROGRAMMING_MODE) { - ret = OK; - } -#endif Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0); - if (ret == OK) - return ret; return send_update(file_des); } @@ -3293,39 +3303,30 @@ int program_fpga(int file_des) { totalsize = filesize; FILE_LOG(logDEBUG1, ("Total program size is: %d\n", totalsize)); - // not in programming mode - /*if (debugflag != PROGRAMMING_MODE) { - ret = FAIL; - sprintf(mess,"FPGA cannot be programmed in this mode. " - "Restart on-board detector server with -update for programming mode.\n"); - FILE_LOG(logERROR,(mess)); - }*/ // opening file pointer to flash and telling FPGA to not touch flash - if (ret != FAIL && startWritingFPGAprogram(&fp) != OK) { + if (startWritingFPGAprogram(&fp) != OK) { ret = FAIL; sprintf(mess,"Could not write to flash. Error at startup.\n"); FILE_LOG(logERROR,(mess)); } - - //---------------- first ret ---------------- Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0); + + //erasing flash if (ret != FAIL) { - //erasing flash eraseFlash(); fpgasrc = (char*)malloc(MAX_FPGAPROGRAMSIZE); } + //writing to flash part by part while(ret != FAIL && filesize) { unitprogramsize = MAX_FPGAPROGRAMSIZE; //2mb if (unitprogramsize > filesize) //less than 2mb unitprogramsize = filesize; - FILE_LOG(logDEBUG1, ("unit size to receive is:%d\n" - "filesize:%d\n", unitprogramsize, filesize)); - + FILE_LOG(logDEBUG1, ("unit size to receive is:%d\nfilesize:%d\n", unitprogramsize, filesize)); //receive part of program if (receiveData(file_des,fpgasrc,unitprogramsize,OTHER) < 0) @@ -3340,12 +3341,7 @@ int program_fpga(int file_des) { // write part to flash ret = writeFPGAProgram(fpgasrc, unitprogramsize, fp); - - //---------------- middle rets ---------------- Server_SendResult(file_des, INT32, NO_UPDATE, NULL, 0); - - - if (ret == FAIL) { FILE_LOG(logERROR, ("Failure: Breaking out of program receiving\n")); } else { @@ -3356,7 +3352,9 @@ int program_fpga(int file_des) { } } printf("\n"); - FILE_LOG(logINFO, ("Done copying program or due to failure earlier\n")); + if (ret == OK) { + FILE_LOG(logINFO, ("Done copying program\n")); + } // closing file pointer to flash and informing FPGA stopWritingFPGAprogram(fp); @@ -3367,17 +3365,11 @@ int program_fpga(int file_des) { if (fp != NULL) fclose(fp); - FILE_LOG(logDEBUG1, ("Done with program receiving command\n")); - - if (ret != FAIL && isControlServer) { - basictests(); - initControlServer(); - } - + FILE_LOG(logINFO, ("Completed program fpga command with %s\n", (ret == OK ? "success" : "fail"))); } #endif #endif - return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); + return ret; } @@ -3396,8 +3388,7 @@ int reset_fpga(int file_des) { if (Server_VerifyLock() == OK) { if (isControlServer) { basictests(); // mapping of control server at least - if (debugflag != PROGRAMMING_MODE) - initControlServer(); + initControlServer(); } else initStopServer(); //remapping of stop server ret = FORCE_UPDATE; @@ -3781,6 +3772,83 @@ int digital_io_delay(int file_des) { return Server_SendResult(file_des, INT32, UPDATE, NULL, 0); } +int copy_detector_server(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); + char args[2][MAX_STR_LENGTH]; + char retvals[MAX_STR_LENGTH] = {0}; + + memset(args, 0, sizeof(args)); + memset(retvals, 0, sizeof(retvals)); + + if (receiveData(file_des, args, sizeof(args), OTHER) < 0) + return printSocketReadError(); + +#ifdef EIGERD + functionNotImplemented(); +#else + + // only set + if (Server_VerifyLock() == OK) { + char* sname = args[0]; + char* hostname = args[1]; + FILE_LOG(logINFOBLUE, ("Copying server %s from host %s\n", sname, hostname)); + + char cmd[MAX_STR_LENGTH]; + memset(cmd, 0, MAX_STR_LENGTH); + + // copy server + sprintf(cmd, "tftp %s -r %s -g", hostname, sname); + int success = executeCommand(cmd, retvals, logDEBUG1); + if (success == FAIL) { + ret = FAIL; + strcpy(mess, retvals); + //FILE_LOG(logERROR, (mess)); already printed in executecommand + } + + // success + else { + FILE_LOG(logINFO, ("Server copied successfully\n")); + // give permissions + sprintf(cmd, "chmod 777 %s", sname); + executeCommand(cmd, retvals, logDEBUG1); + + // edit /etc/inittab + // find line numbers in /etc/inittab where DetectorServer + strcpy(cmd, "sed -n '/DetectorServer/=' /etc/inittab"); + executeCommand(cmd, retvals, logDEBUG1); + while (strlen(retvals)) { + // get first linen number + int lineNumber = atoi(retvals); + // delete that line + sprintf(cmd, "sed -i \'%dd\' /etc/inittab", lineNumber); + executeCommand(cmd, retvals, logDEBUG1); + // find line numbers again + strcpy(cmd, "sed -n '/DetectorServer/=' /etc/inittab"); + executeCommand(cmd, retvals, logDEBUG1); + } + FILE_LOG(logINFO, ("Deleted all lines containing DetectorServer in /etc/inittab\n")); + + // append line + sprintf(cmd, "echo \"ttyS0::respawn:/./%s\" >> /etc/inittab", sname); + executeCommand(cmd, retvals, logDEBUG1); + + FILE_LOG(logINFO, ("/etc/inittab modified to have %s\n", sname)); + } + } +#endif + return Server_SendResult(file_des, OTHER, NO_UPDATE, retvals, sizeof(retvals)); +} - +int reboot_controller(int file_des) { + ret = OK; + memset(mess, 0, sizeof(mess)); +#ifdef EIGERD + functionNotImplemented(); + return ret; +#else + FILE_LOG(logINFORED, ("Rebooting controller\n")); + return REBOOT; +#endif +} diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h index c61a7c824..da2e28d66 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.h @@ -1,12 +1,16 @@ #pragma once #include "sls_detector_defs.h" +#include "logger.h" enum numberMode {DEC, HEX}; +#define GOODBYE (-200) +#define REBOOT (-400) // initialization functions int printSocketReadError(); void init_detector(); int decode_function(int); +const char* getRetName(); const char* getTimerName(enum timerIndex ind); const char* getSpeedName(enum speedVariable ind); const char* getFunctionName(enum detFuncs func); @@ -15,6 +19,7 @@ void functionNotImplemented(); void modeNotImplemented(char* modename, int mode); void validate(int arg, int retval, char* modename, enum numberMode nummode); void validate64(int64_t arg, int64_t retval, char* modename, enum numberMode nummode); +int executeCommand(char* command, char* result, enum TLogLevel level); int M_nofunc(int); int M_nofuncMode(int); @@ -85,3 +90,6 @@ int check_version(int); int software_trigger(int); int led(int); int digital_io_delay(int); +int copy_detector_server(int); +int reboot_controller(int); + diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index ee860a66f..120fb859a 100644 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -1419,7 +1419,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { int setStoragecellStart(int pos = -1, int detPos = -1); /** - * Programs FPGA with pof file (Jungfrau) + * Programs FPGA with pof file (Not Eiger) * @param fname file name * @param detPos -1 for all detectors in list or specific detector position * @returns OK or FAIL @@ -1427,12 +1427,38 @@ class multiSlsDetector : public virtual slsDetectorDefs { int programFPGA(const std::string &fname, int detPos = -1); /** - * Resets FPGA (Jungfrau) + * Resets FPGA (Not Eiger) * @param detPos -1 for all detectors in list or specific detector position * @returns OK or FAIL */ int resetFPGA(int detPos = -1); + /** + * Copies detector server from tftp and changes respawn server (Not Eiger) + * @param fname name of detector server binary + * @param hostname name of pc to tftp from + * @param detPos -1 for all detectors in list or specific detector position + * @returns OK or FAIL + */ + int copyDetectorServer(const std::string &fname, const std::string &hostname, int detPos = -1); + + /** + * Reboot detector controller (Not Eiger) + * @param detPos -1 for all detectors in list or specific detector position + * @returns OK or FAIL + */ + int rebootController(int detPos = -1); + + /** + * Updates the firmware, detector server and then reboots detector controller blackfin. (Not Eiger) + * @param sname name of detector server binary + * @param hostname name of pc to tftp from + * @param fname programming file name + * @param detPos -1 for all detectors in list or specific detector position + * @returns OK or FAIL + */ + int update(const std::string &sname, const std::string &hostname, const std::string &fname, int detPos = -1); + /** * Power on/off Chip (Jungfrau) * @param ival on is 1, off is 0, -1 to get diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 9f32780a5..342792e2c 100644 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -1291,6 +1291,20 @@ class slsDetector : public virtual slsDetectorDefs{ int resetFPGA(); /** + * Copies detector server from tftp and changes respawn server (Not Eiger) + * @param fname name of detector server binary + * @param hostname name of pc to tftp from + * @returns OK or FAIL + */ + int copyDetectorServer(const std::string &fname, const std::string &hostname); + + /** + * Reboot detector controller (blackfin/ powerpc) + * @returns OK or FAIL + */ + int rebootController(); + + /** * Power on/off Chip (Jungfrau) * @param ival on is 1, off is 0, -1 to get * @returns OK or FAIL diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 1b67f7fbd..4cd8fa706 100644 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -2597,12 +2597,13 @@ int multiSlsDetector::setStoragecellStart(int pos, int detPos) { } int multiSlsDetector::programFPGA(const std::string &fname, int detPos) { + FILE_LOG(logINFO) << "This can take awhile. Please be patient..."; // read pof file std::vector buffer = readPofFile(fname); // single if (detPos >= 0) { - return detectors[detPos]->programFPGA(buffer); + return detectors[detPos]->programFPGA(buffer); } // multi @@ -2621,6 +2622,47 @@ int multiSlsDetector::resetFPGA(int detPos) { return sls::allEqualTo(r, static_cast(OK)) ? OK : FAIL; } +int multiSlsDetector::copyDetectorServer(const std::string &fname, const std::string &hostname, int detPos) { + // single + if (detPos >= 0) { + detectors[detPos]->copyDetectorServer(fname, hostname); + return detectors[detPos]->rebootController(); // reboot and copy should be independant for update command + } + + // multi + parallelCall(&slsDetector::copyDetectorServer,fname, hostname); + auto r = parallelCall(&slsDetector::rebootController); + return sls::allEqualTo(r, static_cast(OK)) ? OK : FAIL; +} + +int multiSlsDetector::rebootController(int detPos) { + // single + if (detPos >= 0) { + return detectors[detPos]->rebootController(); + } + + // multi + auto r = parallelCall(&slsDetector::rebootController); + return sls::allEqualTo(r, static_cast(OK)) ? OK : FAIL; +} + +int multiSlsDetector::update(const std::string &sname, const std::string &hostname, const std::string &fname, int detPos) { + FILE_LOG(logINFO) << "This can take awhile. Please be patient..."; + // read pof file + std::vector buffer = readPofFile(fname); + + // single + if (detPos >= 0) { + detectors[detPos]->copyDetectorServer(sname, hostname); + return detectors[detPos]->programFPGA(buffer); + } + + // multi + parallelCall(&slsDetector::copyDetectorServer,sname, hostname); + auto r = parallelCall(&slsDetector::programFPGA, buffer); + return sls::allEqualTo(r, static_cast(OK)) ? OK : FAIL; +} + int multiSlsDetector::powerChip(int ival, int detPos) { // single if (detPos >= 0) { diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 2773e7ca7..49e334b86 100644 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -848,7 +848,9 @@ int slsDetector::execCommand(const std::string &cmd) { if (detector_shm()->onlineFlag == ONLINE_FLAG) { auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); ret = client.sendCommandThenRead(fnum, arg, sizeof(arg), retval, sizeof(retval)); - FILE_LOG(logINFO) << "Detector " << detId << " returned:\n" << retval; + if (strlen(retval)) { + FILE_LOG(logINFO) << "Detector " << detId << " returned:\n" << retval; + } } return ret; } @@ -3410,7 +3412,7 @@ int slsDetector::programFPGA(std::vector buffer) { client.sendData(&fnum, sizeof(fnum)); client.sendData(&filesize, sizeof(filesize)); client.receiveData(&ret, sizeof(ret)); - // opening error + // error in detector at opening file pointer to flash if (ret == FAIL) { client.receiveData(mess, sizeof(mess)); std::ostringstream os; @@ -3421,12 +3423,10 @@ int slsDetector::programFPGA(std::vector buffer) { // erasing flash if (ret != FAIL) { - FILE_LOG(logINFO) << "This can take awhile. Please be patient..."; FILE_LOG(logINFO) << "Erasing Flash for detector " << detId << " (" << detector_shm()->hostname << ")"; printf("%d%%\r", 0); std::cout << std::flush; - // erasing takes 65 seconds, printing here (otherwise need threads - // in server-unnecessary) + // erasing takes 65 seconds, printing here (otherwise need threads in server-unnecessary) const int ERASE_TIME = 65; int count = ERASE_TIME + 1; while (count > 0) { @@ -3473,43 +3473,10 @@ int slsDetector::programFPGA(std::vector buffer) { } } printf("\n"); - - // check ending error - if ((ret == FAIL) && (strstr(mess, "not implemented") == nullptr) && - (strstr(mess, "locked") == nullptr) && (strstr(mess, "-update") == nullptr)) { - client.receiveData(&ret, sizeof(ret)); - if (ret == FAIL) { - client.receiveData(mess, sizeof(mess)); - std::ostringstream os; - os << "Detector " << detId << " (" << detector_shm()->hostname << ")" << - " returned error: " << mess; - throw RuntimeError(os.str()); - } - } - - if (ret == FORCE_UPDATE) { - updateDetector(); - } - - // remapping stop server - if ((ret == FAIL) && (strstr(mess, "not implemented") == nullptr) && - (strstr(mess, "locked") == nullptr) && (strstr(mess, "-update") == nullptr)) { - fnum = F_RESET_FPGA; - int stopret = FAIL; - auto stop = DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort); - stop.sendData(&fnum, sizeof(fnum)); - stop.receiveData(&stopret, sizeof(stopret)); - if (stopret == FAIL) { - client.receiveData(mess, sizeof(mess)); - std::ostringstream os; - os << "Detector " << detId << " (" << detector_shm()->hostname << ")" << - " returned error: " << mess; - throw RuntimeError(os.str()); - } - } } - FILE_LOG(logINFO) << "You can now restart the detector " + std::to_string(detId) + - " in normal mode."; + if (ret != FAIL) { + ret = rebootController(); + } return ret; } @@ -3528,6 +3495,37 @@ int slsDetector::resetFPGA() { return ret; } +int slsDetector::copyDetectorServer(const std::string &fname, const std::string &hostname) { + int fnum = F_COPY_DET_SERVER; + int ret = FAIL; + char args[2][MAX_STR_LENGTH] = {}; + sls::strcpy_safe(args[0], fname.c_str()); + sls::strcpy_safe(args[1], hostname.c_str()); + FILE_LOG(logINFO) << "Sending detector server " << args[0] << " from host " << args[1]; + if (detector_shm()->onlineFlag == ONLINE_FLAG) { + auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); + ret = client.sendCommandThenRead(fnum, args, sizeof(args), nullptr, 0); + } + return ret; +} + +int slsDetector::rebootController() { + if (detector_shm()->myDetectorType == EIGER) { + throw RuntimeError("Reboot controller not implemented for this detector"); + } + + int fnum = F_REBOOT_CONTROLLER; + int ret = FAIL; + FILE_LOG(logINFO) << "Sending reboot controller to detector " << detId << " (" << detector_shm()->hostname << ")"; + if (detector_shm()->onlineFlag == ONLINE_FLAG) { + auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); + client.sendData(&fnum, sizeof(fnum)); + ret = OK; + } + return ret; +} + + int slsDetector::powerChip(int ival) { int fnum = F_POWER_CHIP; int ret = FAIL; diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index e6922e3cf..4cb797258 100644 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -405,6 +405,27 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAdvanced; ++i; + /*! \page config + - copydetectorserver [sname] [phost] copies the detector server sname via tftp from pc with hostname phost and changes respawn server for all detector. Not for Eiger. Only put! \c Returns \c ("successful", "failed") + */ + descrToFuncMap[i].m_pFuncName = "copydetectorserver"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAdvanced; + ++i; + + /*! \page config + - rebootdetpc reboot detector controller blackfin. Only put! Not for Eiger. \c Returns \c ("successful", "failed") + */ + descrToFuncMap[i].m_pFuncName = "rebootcontroller"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAdvanced; + ++i; + + /*! \page config + - update [sname] [phost] [file] updates the firmware to file and detector server to sname from phost via tftp and then reboots controller (blackfin). Only put! Not for Eiger. \c Returns \c ("successful", "failed") + */ + descrToFuncMap[i].m_pFuncName = "update"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdAdvanced; + ++i; + /* chip */ /*! \page config \section configchip Chip @@ -4753,9 +4774,6 @@ std::string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action, if (strstr(args[1], ".pof") == nullptr) return std::string("wrong usage: programming file should have .pof extension"); std::string sval = std::string(args[1]); -#ifdef VERBOSE - std::cout << " programming file " << sval << std::endl; -#endif myDet->setOnline(ONLINE_FLAG, detPos); if (myDet->programFPGA(sval, detPos) == OK) return std::string("successful"); @@ -4765,15 +4783,51 @@ std::string slsDetectorCommand::cmdAdvanced(int narg, char *args[], int action, else if (cmd == "resetfpga") { if (action == GET_ACTION) return std::string("cannot get"); -#ifdef VERBOSE - std::cout << " resetting fpga " << std::endl; -#endif myDet->setOnline(ONLINE_FLAG, detPos); if (myDet->resetFPGA(detPos) == OK) return std::string("successful"); return std::string("failed"); } + else if (cmd == "copydetectorserver") { + if (action == GET_ACTION) + return std::string("cannot get"); + if (narg < 3) + return ("wrong usage." + helpAdvanced(PUT_ACTION)); + std::string sval = std::string(args[1]); + std::string pval = std::string(args[2]); + myDet->setOnline(ONLINE_FLAG, detPos); + if (myDet->copyDetectorServer(sval, pval, detPos) == OK) + return std::string("successful"); + return std::string("failed"); + } + + else if (cmd == "rebootcontroller") { + if (action == GET_ACTION) + return std::string("cannot get"); + myDet->setOnline(ONLINE_FLAG, detPos); + if (myDet->rebootController(detPos) == OK) + return std::string("successful"); + return std::string("failed"); + } + + else if (cmd == "update") { + if (action == GET_ACTION) + return std::string("cannot get"); + if (narg < 4) + return ("wrong usage." + helpAdvanced(PUT_ACTION)); + // pof + if (strstr(args[3], ".pof") == nullptr) + return std::string("wrong usage: programming file should have .pof extension"); + std::string sval = std::string(args[1]); + std::string pval = std::string(args[2]); + std::string fval = std::string(args[3]); + myDet->setOnline(ONLINE_FLAG, detPos); + if (myDet->update(sval, pval, fval, detPos) == OK) + return std::string("successful"); + return std::string("failed"); + } + else if (cmd == "powerchip") { char ans[100]; myDet->setOnline(ONLINE_FLAG, detPos); @@ -4842,7 +4896,9 @@ std::string slsDetectorCommand::helpAdvanced(int action) { os << "programfpga f \t programs the fpga with file f (with .pof extension)." << std::endl; os << "resetfpga f \t resets fpga, f can be any value" << std::endl; - + os << "copydetectorserver s p \t copies the detector server s via tftp from pc with hostname p and changes respawn server. Not for Eiger. " << std::endl; + os << "rebootcontroller \t reboot controler blackfin of the detector. Not for Eiger." << std::endl; + os << "update s p f \t updates the firmware to f and detector server to f from host p via tftp and then reboots controller (blackfin). Not for Eiger. " << std::endl; os << "led s \t sets led status (0 off, 1 on)" << std::endl; os << "diodelay m v \tsets the delay for the digital IO pins selected by mask m and delay set by v. mask is upto 64 bits in hex, delay max is 775ps, and set in steps of 25 ps. Used for MOENCH/CTB only." << std::endl; os << "powerchip i \t powers on or off the chip. i = 1 for on, i = 0 for off" << std::endl; diff --git a/slsSupportLib/include/sls_detector_funcs.h b/slsSupportLib/include/sls_detector_funcs.h index e20f45371..4179a1536 100644 --- a/slsSupportLib/include/sls_detector_funcs.h +++ b/slsSupportLib/include/sls_detector_funcs.h @@ -74,6 +74,8 @@ enum detFuncs{ F_SOFTWARE_TRIGGER,/** < software trigger */ F_LED, /** < switch on/off led */ F_DIGITAL_IO_DELAY, /** < digital IO delay */ + F_COPY_DET_SERVER, /** < copy detector server & respawn */ + F_REBOOT_CONTROLLER, /** < reboot detector controller (blackfin/ powerpc) */ NUM_DET_FUNCTIONS, RECEIVER_ENUM_START = 128, /**< detector function should not exceed this (detector server should not compile anyway) */