mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
refactoring
This commit is contained in:
parent
adc6cf214a
commit
5190e2ab30
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2933,26 +2933,37 @@ std::string CmdProxy::UpdateFirmwareAndDetectorServer(int action) {
|
|||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << cmd << ' ';
|
os << cmd << ' ';
|
||||||
if (action == defs::HELP_ACTION) {
|
if (action == defs::HELP_ACTION) {
|
||||||
os << "[server_name (in tftp folder)] [pc_host_name] [fname.pof (incl "
|
os << "\n\tDeprecated!! Replaced without using tftp (as shown next)[server_name"
|
||||||
"full path)]\n\t[Jungfrau][Gotthard][CTB][Moench] Updates the "
|
" (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 "
|
"firmware, detector server, creates the symbolic link and then "
|
||||||
"reboots detector controller. \n\t[Mythen3][Gotthard2] will "
|
"reboots detector controller. \n\t[Mythen3][Gotthard2] will "
|
||||||
"require a script to start up the shorter named server link at "
|
"require a script to start up the shorter named server link at "
|
||||||
"start up. \n\tsname is name of detector server binary found on "
|
"start up. \n\t\tsname is full path name of detector server binary"
|
||||||
"tftp folder of host pc \n\thostname is name of pc to tftp from "
|
"\n\t\tfname is full path of programming file"
|
||||||
"\n\tfname is programming file name"
|
|
||||||
<< '\n';
|
<< '\n';
|
||||||
} else if (action == defs::GET_ACTION) {
|
} else if (action == defs::GET_ACTION) {
|
||||||
throw sls::RuntimeError("Cannot get");
|
throw sls::RuntimeError("Cannot get");
|
||||||
} else if (action == defs::PUT_ACTION) {
|
} else if (action == defs::PUT_ACTION) {
|
||||||
if (args.size() != 3) {
|
if (args.size() != 3 && args.size() != 2) {
|
||||||
WrongNumberOfParameters(3);
|
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.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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],
|
det->updateFirmwareAndServer(args[0], args[1], args[2],
|
||||||
std::vector<int>{det_id});
|
std::vector<int>{det_id});
|
||||||
|
} else {
|
||||||
|
det->updateFirmwareAndServer(args[0], args[1],
|
||||||
|
std::vector<int>{det_id});
|
||||||
|
}
|
||||||
os << "successful\n";
|
os << "successful\n";
|
||||||
} else {
|
} else {
|
||||||
throw sls::RuntimeError("Unknown action");
|
throw sls::RuntimeError("Unknown action");
|
||||||
|
@ -2154,18 +2154,9 @@ void Detector::copyDetectorServer(const std::string &fname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Detector::updateDetectorServer(const std::string &fname, Positions pos) {
|
void Detector::updateDetectorServer(const std::string &fname, Positions pos) {
|
||||||
LOG(logINFO) << "Updating Detector Server...";
|
LOG(logINFO) << "Updating Detector Server (no tftp)...";
|
||||||
|
std::vector<char> buffer = readBinaryFile(fname, "Update Detector Server");
|
||||||
std::vector<char> buffer =
|
std::string filename = sls::getFileNameFromFilePath(fname);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
pimpl->Parallel(&Module::updateDetectorServer, pos, buffer, filename);
|
pimpl->Parallel(&Module::updateDetectorServer, pos, buffer, filename);
|
||||||
if (getDetectorType().squash() != defs::EIGER) {
|
if (getDetectorType().squash() != defs::EIGER) {
|
||||||
rebootController(pos);
|
rebootController(pos);
|
||||||
@ -2174,7 +2165,7 @@ void Detector::updateDetectorServer(const std::string &fname, Positions pos) {
|
|||||||
|
|
||||||
void Detector::updateKernel(const std::string &fname, Positions pos) {
|
void Detector::updateKernel(const std::string &fname, Positions pos) {
|
||||||
LOG(logINFO) << "Updating Kernel...";
|
LOG(logINFO) << "Updating Kernel...";
|
||||||
std::vector<char> buffer = readBinaryFile(fname, "Update Kernel");
|
std::vector<char> buffer = sls::readBinaryFile(fname, "Update Kernel");
|
||||||
pimpl->Parallel(&Module::updateKernel, pos, buffer);
|
pimpl->Parallel(&Module::updateKernel, pos, buffer);
|
||||||
rebootController(pos);
|
rebootController(pos);
|
||||||
}
|
}
|
||||||
@ -2187,7 +2178,8 @@ void Detector::updateFirmwareAndServer(const std::string &sname,
|
|||||||
const std::string &hostname,
|
const std::string &hostname,
|
||||||
const std::string &fname,
|
const std::string &fname,
|
||||||
Positions pos) {
|
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);
|
pimpl->Parallel(&Module::copyDetectorServer, pos, sname, hostname);
|
||||||
programFPGA(fname, pos);
|
programFPGA(fname, pos);
|
||||||
}
|
}
|
||||||
@ -2196,7 +2188,10 @@ void Detector::updateFirmwareAndServer(const std::string &sname,
|
|||||||
const std::string &fname,
|
const std::string &fname,
|
||||||
Positions pos) {
|
Positions pos) {
|
||||||
LOG(logINFO) << "Updating Firmware and Detector Server (no tftp)...";
|
LOG(logINFO) << "Updating Firmware and Detector Server (no tftp)...";
|
||||||
updateDetectorServer(sname, pos);
|
LOG(logINFO) << "Updating Detector Server (no tftp)...";
|
||||||
|
std::vector<char> buffer = readBinaryFile(fname, "Update Detector Server");
|
||||||
|
std::string filename = sls::getFileNameFromFilePath(fname);
|
||||||
|
pimpl->Parallel(&Module::updateDetectorServer, pos, buffer, filename);
|
||||||
programFPGA(fname, pos);
|
programFPGA(fname, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1280,14 +1280,7 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get srcSize to print progress
|
// get srcSize to print progress
|
||||||
if (fseek(src, 0, SEEK_END) != 0) {
|
ssize_t srcSize = sls::getFileSize(src, "Program FPGA");
|
||||||
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);
|
|
||||||
|
|
||||||
// create temp destination file
|
// create temp destination file
|
||||||
char destfname[] = "/tmp/SLS_DET_MCB.XXXXXX";
|
char destfname[] = "/tmp/SLS_DET_MCB.XXXXXX";
|
||||||
|
@ -355,7 +355,7 @@ std::string Implementation::getFilePath() const { return filePath; }
|
|||||||
|
|
||||||
void Implementation::setFilePath(const std::string &c) {
|
void Implementation::setFilePath(const std::string &c) {
|
||||||
if (!c.empty()) {
|
if (!c.empty()) {
|
||||||
mkdir_p(c); // throws if it can't create
|
sls::mkdir_p(c); // throws if it can't create
|
||||||
filePath = c;
|
filePath = c;
|
||||||
}
|
}
|
||||||
LOG(logINFO) << "File path: " << filePath;
|
LOG(logINFO) << "File path: " << filePath;
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param data array of data values
|
* @param data array of data values
|
||||||
* @param nch number of channels
|
* @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);
|
int readDataFile(std::string fname, short int *data, int nch);
|
||||||
|
|
||||||
|
|
||||||
std::vector<char> readBinaryFile(const std::string &fname,
|
std::vector<char> readBinaryFile(const std::string &fname,
|
||||||
const std::string &errorPrefix);
|
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
|
// mkdir -p path implemented by recursive calls
|
||||||
void mkdir_p(const std::string &path, std::string dir = "");
|
void mkdir_p(const std::string &path, std::string dir = "");
|
||||||
|
|
||||||
namespace sls {
|
|
||||||
int getFileSize(std::ifstream &ifs);
|
int getFileSize(std::ifstream &ifs);
|
||||||
|
ssize_t getFileSize(FILE* fd, const std::string &prependErrorString);
|
||||||
|
|
||||||
|
std::string getFileNameFromFilePath(const std::string &fpath);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#define APICTB 0x211110
|
#define APICTB 0x211110
|
||||||
#define APIGOTTHARD 0x211110
|
#define APIGOTTHARD 0x211110
|
||||||
#define APIGOTTHARD2 0x211110
|
#define APIGOTTHARD2 0x211110
|
||||||
|
#define APIJUNGFRAU 0x211110
|
||||||
#define APIMYTHEN3 0x211110
|
#define APIMYTHEN3 0x211110
|
||||||
#define APIMOENCH 0x211110
|
#define APIMOENCH 0x211110
|
||||||
#define APIEIGER 0x211110
|
#define APIEIGER 0x211110
|
||||||
#define APIJUNGFRAU 0x211110
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
namespace sls {
|
||||||
|
|
||||||
int readDataFile(std::ifstream &infile, short int *data, int nch, int offset) {
|
int readDataFile(std::ifstream &infile, short int *data, int nch, int offset) {
|
||||||
int ichan, iline = 0;
|
int ichan, iline = 0;
|
||||||
short int idata;
|
short int idata;
|
||||||
@ -59,36 +61,27 @@ std::vector<char> readBinaryFile(const std::string &fname,
|
|||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(fname.c_str(), &st) != 0) {
|
if (stat(fname.c_str(), &st) != 0) {
|
||||||
throw sls::RuntimeError(errorPrefix +
|
throw sls::RuntimeError(errorPrefix +
|
||||||
std::string(": file does not exist"));
|
std::string(" (file does not exist)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *fp = fopen(fname.c_str(), "rb");
|
FILE *fp = fopen(fname.c_str(), "rb");
|
||||||
if (fp == nullptr) {
|
if (fp == nullptr) {
|
||||||
throw sls::RuntimeError(errorPrefix +
|
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
|
// get file size to print progress
|
||||||
if (fseek(fp, 0, SEEK_END) != 0) {
|
ssize_t filesize = sls::getFileSize(fp, errorPrefix);
|
||||||
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);
|
|
||||||
|
|
||||||
std::vector<char> buffer(filesize, 0);
|
std::vector<char> 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 +
|
throw sls::RuntimeError(errorPrefix +
|
||||||
std::string(": Could not read file"));
|
std::string(" (Could not read file)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fclose(fp) != 0) {
|
if (fclose(fp) != 0) {
|
||||||
throw sls::RuntimeError(errorPrefix +
|
throw sls::RuntimeError(errorPrefix +
|
||||||
std::string(": Could not close file"));
|
std::string(" (Could not close file)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG(logDEBUG1) << "Read file into memory";
|
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);
|
mkdir_p(path.substr(i + 1), dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace sls {
|
|
||||||
int getFileSize(std::ifstream &ifs) {
|
int getFileSize(std::ifstream &ifs) {
|
||||||
auto current_pos = ifs.tellg();
|
auto current_pos = ifs.tellg();
|
||||||
ifs.seekg(0, std::ios::end);
|
ifs.seekg(0, std::ios::end);
|
||||||
@ -146,4 +138,27 @@ int getFileSize(std::ifstream &ifs) {
|
|||||||
ifs.seekg(current_pos);
|
ifs.seekg(current_pos);
|
||||||
return file_size;
|
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
|
} // namespace sls
|
||||||
|
Loading…
x
Reference in New Issue
Block a user