mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-20 08:38:00 +02:00
updating kernel like program fpga, execute command to print which module failed, unlinking temporary file while programming bug fix
This commit is contained in:
@ -1386,8 +1386,70 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
||||
"Program FPGA: Could not close destination file after converting");
|
||||
}
|
||||
|
||||
// unlink(destfname); // delete temporary file
|
||||
LOG(logDEBUG1) << "Successfully loaded the rawbin file to program memory";
|
||||
unlink(destfname); // delete temporary file
|
||||
LOG(logDEBUG1) << "Read file into memory";
|
||||
return buffer;
|
||||
}
|
||||
|
||||
std::vector<char> DetectorImpl::readKernelFile(const std::string &fname) {
|
||||
// validate type of file
|
||||
bool isPof = false;
|
||||
switch (shm()->detType) {
|
||||
case JUNGFRAU:
|
||||
case CHIPTESTBOARD:
|
||||
case MOENCH:
|
||||
if (fname.find(".lzma") == std::string::npos) {
|
||||
throw RuntimeError("Kernel image file must be a lzma file.");
|
||||
}
|
||||
isPof = true;
|
||||
break;
|
||||
case MYTHEN3:
|
||||
case GOTTHARD2:
|
||||
if (fname.find(".bin") == std::string::npos) {
|
||||
throw RuntimeError("Kernel image file must be an bin file.");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw RuntimeError("Programming kernel image via the package is not implemented for this detector");
|
||||
}
|
||||
|
||||
LOG(logINFO)
|
||||
<< "Updating Kernel...";
|
||||
LOG(logDEBUG1) << "Programming kernel image with file name:" << fname;
|
||||
|
||||
// check if it exists
|
||||
struct stat st;
|
||||
if (stat(fname.c_str(), &st) != 0) {
|
||||
throw RuntimeError("Program kernel: file does not exist");
|
||||
}
|
||||
|
||||
FILE *fp = fopen(fname.c_str(), "rb");
|
||||
if (fp == nullptr) {
|
||||
throw RuntimeError(
|
||||
"Program kernel: Could not open file: " +
|
||||
fname);
|
||||
}
|
||||
|
||||
// get file size to print progress
|
||||
if (fseek(fp, 0, SEEK_END) != 0) {
|
||||
throw RuntimeError("Program kernel: Seek error in src file");
|
||||
}
|
||||
size_t filesize = ftell(fp);
|
||||
if (filesize <= 0) {
|
||||
throw RuntimeError("Program kernel: Could not get length of file");
|
||||
}
|
||||
rewind(fp);
|
||||
|
||||
std::vector<char> buffer(filesize, 0);
|
||||
if (fread(buffer.data(), sizeof(char), filesize, fp) != filesize) {
|
||||
throw RuntimeError("Program kernel: Could not read file");
|
||||
}
|
||||
|
||||
if (fclose(fp) != 0) {
|
||||
throw RuntimeError(
|
||||
"Program kernel: Could not close file");
|
||||
}
|
||||
|
||||
LOG(logDEBUG1) << "Read file into memory";
|
||||
return buffer;
|
||||
}
|
||||
|
Reference in New Issue
Block a user