diff --git a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer index 3629e9982..0052bfdd6 100755 Binary files a/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer and b/slsDetectorServers/ctbDetectorServer/bin/ctbDetectorServer_developer differ diff --git a/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer b/slsDetectorServers/gotthardDetectorServer/bin/gotthardDetectorServer_developer index 00342b76e..d1891609c 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 90439af52..a3892b752 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 c49a00c63..8e767afa9 100755 Binary files a/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer and b/slsDetectorServers/moenchDetectorServer/bin/moenchDetectorServer_developer differ diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index cd1c1bb68..84f485bee 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -2933,26 +2933,37 @@ std::string CmdProxy::UpdateFirmwareAndDetectorServer(int action) { std::ostringstream os; os << cmd << ' '; if (action == defs::HELP_ACTION) { - os << "[server_name (in tftp folder)] [pc_host_name] [fname.pof (incl " - "full path)]\n\t[Jungfrau][Gotthard][CTB][Moench] Updates the " + 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." + "\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 " "require a script to start up the shorter named server link at " - "start up. \n\tsname is name of detector server binary found on " - "tftp folder of host pc \n\thostname is name of pc to tftp from " - "\n\tfname is programming file name" + "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) { throw sls::RuntimeError("Cannot get"); } else if (action == defs::PUT_ACTION) { - if (args.size() != 3) { - WrongNumberOfParameters(3); + if (args.size() != 3 && args.size() != 2) { + WrongNumberOfParameters(2); } - if (args[2].find(".pof") == std::string::npos) { - throw sls::RuntimeError("Programming file must be a pof file."); + + int fpos = args.size() - 1; + 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."); } - det->updateFirmwareAndServer(args[0], args[1], args[2], + + 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"; + det->updateFirmwareAndServer(args[0], args[1], args[2], + std::vector{det_id}); + } else { + det->updateFirmwareAndServer(args[0], args[1], std::vector{det_id}); + } os << "successful\n"; } else { throw sls::RuntimeError("Unknown action"); diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 0d4e3ce26..c88634648 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -2154,18 +2154,9 @@ void Detector::copyDetectorServer(const std::string &fname, } void Detector::updateDetectorServer(const std::string &fname, Positions pos) { - LOG(logINFO) << "Updating Detector Server..."; - - std::vector buffer = - readBinaryFile(fname, "Update Detector Server"); - - // get only the file name - std::string filename(fname); - std::size_t slashPos = fname.rfind('/'); - if (slashPos != std::string::npos) { - filename = fname.substr(slashPos + 1, fname.size() - 1); - } - + LOG(logINFO) << "Updating Detector Server (no tftp)..."; + std::vector buffer = readBinaryFile(fname, "Update Detector Server"); + std::string filename = sls::getFileNameFromFilePath(fname); pimpl->Parallel(&Module::updateDetectorServer, pos, buffer, filename); if (getDetectorType().squash() != defs::EIGER) { rebootController(pos); @@ -2174,7 +2165,7 @@ void Detector::updateDetectorServer(const std::string &fname, Positions pos) { void Detector::updateKernel(const std::string &fname, Positions pos) { LOG(logINFO) << "Updating Kernel..."; - std::vector buffer = readBinaryFile(fname, "Update Kernel"); + std::vector buffer = sls::readBinaryFile(fname, "Update Kernel"); pimpl->Parallel(&Module::updateKernel, pos, buffer); rebootController(pos); } @@ -2187,7 +2178,8 @@ void Detector::updateFirmwareAndServer(const std::string &sname, const std::string &hostname, const std::string &fname, Positions pos) { - LOG(logINFO) << "Updating Firmware and Detector Server..."; + LOG(logINFO) << "Updating Firmware and Detector Server (with tftp)..."; + LOG(logINFO) << "Updating Detector Server (via tftp)..."; pimpl->Parallel(&Module::copyDetectorServer, pos, sname, hostname); programFPGA(fname, pos); } @@ -2196,7 +2188,10 @@ void Detector::updateFirmwareAndServer(const std::string &sname, const std::string &fname, Positions pos) { LOG(logINFO) << "Updating Firmware and Detector Server (no tftp)..."; - updateDetectorServer(sname, pos); + LOG(logINFO) << "Updating Detector Server (no tftp)..."; + std::vector buffer = readBinaryFile(fname, "Update Detector Server"); + std::string filename = sls::getFileNameFromFilePath(fname); + pimpl->Parallel(&Module::updateDetectorServer, pos, buffer, filename); programFPGA(fname, pos); } diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 3a9634f75..2d51e7b58 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1280,14 +1280,7 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { } // get srcSize to print progress - if (fseek(src, 0, SEEK_END) != 0) { - throw RuntimeError("Program FPGA: Seek error in src file"); - } - size_t srcSize = ftell(src); - if (srcSize <= 0) { - throw RuntimeError("Program FPGA: Could not get length of source file"); - } - rewind(src); + ssize_t srcSize = sls::getFileSize(src, "Program FPGA"); // create temp destination file char destfname[] = "/tmp/SLS_DET_MCB.XXXXXX"; diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 75d820c7f..371dc5b30 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -355,7 +355,7 @@ std::string Implementation::getFilePath() const { return filePath; } void Implementation::setFilePath(const std::string &c) { if (!c.empty()) { - mkdir_p(c); // throws if it can't create + sls::mkdir_p(c); // throws if it can't create filePath = c; } LOG(logINFO) << "File path: " << filePath; diff --git a/slsSupportLib/include/sls/file_utils.h b/slsSupportLib/include/sls/file_utils.h index 3e0cb3923..0959154d8 100644 --- a/slsSupportLib/include/sls/file_utils.h +++ b/slsSupportLib/include/sls/file_utils.h @@ -8,6 +8,9 @@ #include #include +namespace sls { + + /** * @param data array of data values * @param nch number of channels @@ -22,6 +25,7 @@ int readDataFile(std::ifstream &infile, short int *data, int nch, */ int readDataFile(std::string fname, short int *data, int nch); + std::vector readBinaryFile(const std::string &fname, const std::string &errorPrefix); @@ -42,6 +46,8 @@ int writeDataFile(std::string fname, int nch, short int *data); // mkdir -p path implemented by recursive calls void mkdir_p(const std::string &path, std::string dir = ""); -namespace sls { int getFileSize(std::ifstream &ifs); +ssize_t getFileSize(FILE* fd, const std::string &prependErrorString); + +std::string getFileNameFromFilePath(const std::string &fpath); } diff --git a/slsSupportLib/include/sls/versionAPI.h b/slsSupportLib/include/sls/versionAPI.h index b0cf7fa62..cb56b7807 100644 --- a/slsSupportLib/include/sls/versionAPI.h +++ b/slsSupportLib/include/sls/versionAPI.h @@ -9,7 +9,7 @@ #define APICTB 0x211110 #define APIGOTTHARD 0x211110 #define APIGOTTHARD2 0x211110 +#define APIJUNGFRAU 0x211110 #define APIMYTHEN3 0x211110 #define APIMOENCH 0x211110 #define APIEIGER 0x211110 -#define APIJUNGFRAU 0x211110 diff --git a/slsSupportLib/src/file_utils.cpp b/slsSupportLib/src/file_utils.cpp index 652e0749a..ee6c9e15f 100644 --- a/slsSupportLib/src/file_utils.cpp +++ b/slsSupportLib/src/file_utils.cpp @@ -11,6 +11,8 @@ #include #include +namespace sls { + int readDataFile(std::ifstream &infile, short int *data, int nch, int offset) { int ichan, iline = 0; short int idata; @@ -59,36 +61,27 @@ std::vector readBinaryFile(const std::string &fname, struct stat st; if (stat(fname.c_str(), &st) != 0) { throw sls::RuntimeError(errorPrefix + - std::string(": file does not exist")); + std::string(" (file does not exist)")); } FILE *fp = fopen(fname.c_str(), "rb"); if (fp == nullptr) { throw sls::RuntimeError(errorPrefix + - std::string(": Could not open file: ") + fname); + std::string(" (Could not open file: ") + fname + std::string(")")); } // get file size to print progress - if (fseek(fp, 0, SEEK_END) != 0) { - throw sls::RuntimeError(errorPrefix + - std::string(": Seek error in src file")); - } - size_t filesize = ftell(fp); - if (filesize <= 0) { - throw sls::RuntimeError(errorPrefix + - std::string(": Could not get length of file")); - } - rewind(fp); + ssize_t filesize = sls::getFileSize(fp, errorPrefix); std::vector buffer(filesize, 0); - if (fread(buffer.data(), sizeof(char), filesize, fp) != filesize) { + if ((ssize_t)fread(buffer.data(), sizeof(char), filesize, fp) != filesize) { throw sls::RuntimeError(errorPrefix + - std::string(": Could not read file")); + std::string(" (Could not read file)")); } if (fclose(fp) != 0) { throw sls::RuntimeError(errorPrefix + - std::string(": Could not close file")); + std::string(" (Could not close file)")); } LOG(logDEBUG1) << "Read file into memory"; @@ -138,7 +131,6 @@ void mkdir_p(const std::string &path, std::string dir) { mkdir_p(path.substr(i + 1), dir); } -namespace sls { int getFileSize(std::ifstream &ifs) { auto current_pos = ifs.tellg(); ifs.seekg(0, std::ios::end); @@ -146,4 +138,27 @@ int getFileSize(std::ifstream &ifs) { ifs.seekg(current_pos); return file_size; } + +std::string getFileNameFromFilePath(const std::string &fpath) { + std::string fname(fpath); + std::size_t slashPos = fpath.rfind('/'); + if (slashPos != std::string::npos) { + fname = fpath.substr(slashPos + 1, fpath.size() - 1); + } + return fname; +} + +ssize_t getFileSize(FILE* fd, const std::string &prependErrorString) { + if (fseek(fd, 0, SEEK_END) != 0) { + throw RuntimeError(prependErrorString + std::string(" (Seek error in src file)")); + } + size_t fileSize = ftell(fd); + if (fileSize <= 0) { + throw RuntimeError(prependErrorString + std::string(" (Could not get length of source file)")); + } + rewind(fd); + return fileSize; +} + + } // namespace sls