replaced md5 in client

This commit is contained in:
2021-09-07 14:10:50 +02:00
parent e8e76b6de2
commit b7f694142a
6 changed files with 217 additions and 47 deletions

View File

@ -2140,9 +2140,8 @@ void Detector::setAdditionalJsonParameter(const std::string &key,
// Advanced
void Detector::programFPGA(const std::string &fname, Positions pos) {
std::string checksum;
std::vector<char> buffer = pimpl->readProgrammingFile(fname, checksum);
pimpl->Parallel(&Module::programFPGA, pos, buffer, checksum);
std::vector<char> buffer = pimpl->readProgrammingFile(fname);
pimpl->Parallel(&Module::programFPGA, pos, buffer);
}
void Detector::resetFPGA(Positions pos) {

View File

@ -1240,8 +1240,7 @@ int DetectorImpl::kbhit() {
return FD_ISSET(STDIN_FILENO, &fds);
}
std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname,
std::string &checksum) {
std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
// validate type of file
bool isPof = false;
switch (multi_shm()->multiDetectorType) {
@ -1390,39 +1389,12 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname,
"Program FPGA: Could not close destination file after converting");
}
// calculate checksum before deleting file
checksum = getMd5Checksum(destfname);
unlink(destfname); // delete temporary file
LOG(logDEBUG1) << "Successfully loaded the rawbin file to program memory";
LOG(logINFO) << "Read file into memory";
return buffer;
}
std::string DetectorImpl::getMd5Checksum(const std::string &fname) {
std::string cmd = "md5sum " + fname;
FILE *pipe = popen(cmd.c_str(), "r");
if (!pipe) {
throw RuntimeError("Could not get md5 checksum to program fpga");
}
char buffer[256];
memset(buffer, 0, sizeof(buffer));
std::string result;
try {
while (fgets(buffer, sizeof buffer, pipe) != NULL) {
result += buffer;
}
} catch (std::exception &e) {
pclose(pipe);
throw RuntimeError(
std::string("Could not get md5 checsum to program fpga. Threw ") +
std::string(e.what()));
}
pclose(pipe);
auto list = sls::split(result, ' ');
return list[0];
}
sls::Result<int> DetectorImpl::getNumberofUDPInterfaces(Positions pos) const {
return Parallel(&Module::getNumberofUDPInterfaces, pos);
}

View File

@ -289,9 +289,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
* @param fname name of pof/rbf file
* @returns binary of the program
*/
std::vector<char> readProgrammingFile(const std::string &fname,
std::string &checksum);
std::string getMd5Checksum(const std::string &fname);
std::vector<char> readProgrammingFile(const std::string &fname);
sls::Result<int> getNumberofUDPInterfaces(Positions pos) const;
void setNumberofUDPInterfaces(int n, Positions pos);

View File

@ -2485,13 +2485,12 @@ void Module::setAdditionalJsonParameter(const std::string &key,
}
// Advanced
void Module::programFPGA(std::vector<char> buffer,
const std::string &checksum) {
void Module::programFPGA(std::vector<char> buffer) {
switch (shm()->myDetectorType) {
case JUNGFRAU:
case CHIPTESTBOARD:
case MOENCH:
programFPGAviaBlackfin(buffer, checksum);
programFPGAviaBlackfin(buffer);
break;
case MYTHEN3:
case GOTTHARD2:
@ -3418,15 +3417,16 @@ std::string Module::calculateChecksum(char *buffer, ssize_t bytes) {
MD5_Update(&c, buffer, bytes);
unsigned char out[MD5_DIGEST_LENGTH];
MD5_Final(out, &c);
return std::string(reinterpret_cast<char const *>(out));
std::ostringstream oss;
for (int i = 0; i != MD5_DIGEST_LENGTH; ++i)
oss << std::hex << std::setw(2) << std::setfill('0') << +out[i];
return oss.str();
}
void Module::programFPGAviaBlackfin(std::vector<char> buffer,
const std::string &checksum) {
void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
uint64_t filesize = buffer.size();
LOG(logINFOBLUE) << "checksum 1:" << checksum;
LOG(logINFOBLUE) << "checksum 2:"
<< calculateChecksum(buffer.data(), filesize);
std::string checksum = calculateChecksum(buffer.data(), filesize);
LOG(logDEBUG1) << "Checksum:" << checksum;
// send program from memory to detector
LOG(logINFO) << "Sending programming binary (from pof) to module "

View File

@ -535,7 +535,7 @@ class Module : public virtual slsDetectorDefs {
* Advanced *
* *
* ************************************************/
void programFPGA(std::vector<char> buffer, const std::string &checksum);
void programFPGA(std::vector<char> buffer);
void resetFPGA();
void copyDetectorServer(const std::string &fname,
const std::string &hostname);
@ -745,8 +745,7 @@ class Module : public virtual slsDetectorDefs {
sls_detector_module readSettingsFile(const std::string &fname,
bool trimbits = true);
std::string calculateChecksum(char *buffer, ssize_t bytes);
void programFPGAviaBlackfin(std::vector<char> buffer,
const std::string &checksum);
void programFPGAviaBlackfin(std::vector<char> buffer);
void programFPGAviaNios(std::vector<char> buffer);
const int moduleId;