mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-26 16:20:03 +02:00
wip
This commit is contained in:
parent
0c7ff62d8d
commit
a718d69368
@ -1,6 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <openssl/md5.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
/**
|
/**
|
||||||
|
@ -3725,6 +3725,14 @@ int program_fpga(int file_des) {
|
|||||||
LOG(logDEBUG1,
|
LOG(logDEBUG1,
|
||||||
("Program size is: %lld\n", (long long unsigned int)filesize));
|
("Program size is: %lld\n", (long long unsigned int)filesize));
|
||||||
|
|
||||||
|
// checksum
|
||||||
|
uint16_t checksum = 0;
|
||||||
|
if (receiveData(file_des, &checksum, sizeof(filesize), INT32) < 0)
|
||||||
|
return printSocketReadError();
|
||||||
|
LOG(logINFOBLUE,
|
||||||
|
("checksum: %d\n", checksum));
|
||||||
|
|
||||||
|
|
||||||
// open file and allocate memory for part program
|
// open file and allocate memory for part program
|
||||||
FILE *fd = NULL;
|
FILE *fd = NULL;
|
||||||
ret = startCopyingFPGAProgram(&fd, filesize, mess);
|
ret = startCopyingFPGAProgram(&fd, filesize, mess);
|
||||||
|
@ -2140,8 +2140,9 @@ void Detector::setAdditionalJsonParameter(const std::string &key,
|
|||||||
// Advanced
|
// Advanced
|
||||||
|
|
||||||
void Detector::programFPGA(const std::string &fname, Positions pos) {
|
void Detector::programFPGA(const std::string &fname, Positions pos) {
|
||||||
std::vector<char> buffer = pimpl->readProgrammingFile(fname);
|
std::string checksum;
|
||||||
pimpl->Parallel(&Module::programFPGA, pos, buffer);
|
std::vector<char> buffer = pimpl->readProgrammingFile(fname, checksum);
|
||||||
|
pimpl->Parallel(&Module::programFPGA, pos, buffer, checksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Detector::resetFPGA(Positions pos) {
|
void Detector::resetFPGA(Positions pos) {
|
||||||
|
@ -1240,7 +1240,8 @@ int DetectorImpl::kbhit() {
|
|||||||
return FD_ISSET(STDIN_FILENO, &fds);
|
return FD_ISSET(STDIN_FILENO, &fds);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname,
|
||||||
|
std::string &checksum) {
|
||||||
// validate type of file
|
// validate type of file
|
||||||
bool isPof = false;
|
bool isPof = false;
|
||||||
switch (multi_shm()->multiDetectorType) {
|
switch (multi_shm()->multiDetectorType) {
|
||||||
@ -1384,12 +1385,39 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
|
|||||||
throw RuntimeError(
|
throw RuntimeError(
|
||||||
"Program FPGA: Could not close destination file after converting");
|
"Program FPGA: Could not close destination file after converting");
|
||||||
}
|
}
|
||||||
// unlink(destfname); // delete temporary file
|
|
||||||
|
// calculate checksum before deleting file
|
||||||
|
checksum = getMd5Checksum(destfname);
|
||||||
|
|
||||||
|
unlink(destfname); // delete temporary file
|
||||||
LOG(logDEBUG1) << "Successfully loaded the rawbin file to program memory";
|
LOG(logDEBUG1) << "Successfully loaded the rawbin file to program memory";
|
||||||
LOG(logINFO) << "Read file into memory";
|
LOG(logINFO) << "Read file into memory";
|
||||||
return buffer;
|
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);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
sls::Result<int> DetectorImpl::getNumberofUDPInterfaces(Positions pos) const {
|
sls::Result<int> DetectorImpl::getNumberofUDPInterfaces(Positions pos) const {
|
||||||
return Parallel(&Module::getNumberofUDPInterfaces, pos);
|
return Parallel(&Module::getNumberofUDPInterfaces, pos);
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,9 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
|||||||
* @param fname name of pof/rbf file
|
* @param fname name of pof/rbf file
|
||||||
* @returns binary of the program
|
* @returns binary of the program
|
||||||
*/
|
*/
|
||||||
std::vector<char> readProgrammingFile(const std::string &fname);
|
std::vector<char> readProgrammingFile(const std::string &fname,
|
||||||
|
std::string &checksum);
|
||||||
|
std::string getMd5Checksum(const std::string &fname);
|
||||||
|
|
||||||
sls::Result<int> getNumberofUDPInterfaces(Positions pos) const;
|
sls::Result<int> getNumberofUDPInterfaces(Positions pos) const;
|
||||||
void setNumberofUDPInterfaces(int n, Positions pos);
|
void setNumberofUDPInterfaces(int n, Positions pos);
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <openssl/md5.h>
|
|
||||||
|
|
||||||
namespace sls {
|
namespace sls {
|
||||||
|
|
||||||
@ -2486,12 +2485,13 @@ void Module::setAdditionalJsonParameter(const std::string &key,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Advanced
|
// Advanced
|
||||||
void Module::programFPGA(std::vector<char> buffer) {
|
void Module::programFPGA(std::vector<char> buffer,
|
||||||
|
const std::string &checksum) {
|
||||||
switch (shm()->myDetectorType) {
|
switch (shm()->myDetectorType) {
|
||||||
case JUNGFRAU:
|
case JUNGFRAU:
|
||||||
case CHIPTESTBOARD:
|
case CHIPTESTBOARD:
|
||||||
case MOENCH:
|
case MOENCH:
|
||||||
programFPGAviaBlackfin(buffer);
|
programFPGAviaBlackfin(buffer, checksum);
|
||||||
break;
|
break;
|
||||||
case MYTHEN3:
|
case MYTHEN3:
|
||||||
case GOTTHARD2:
|
case GOTTHARD2:
|
||||||
@ -3412,25 +3412,18 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
|
|||||||
return myMod;
|
return myMod;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Module::calculateChecksum(char *buffer, size_t bsize) {
|
void Module::programFPGAviaBlackfin(std::vector<char> buffer,
|
||||||
unsigned char checksum = 0;
|
const std::string &checksum) {
|
||||||
for(size_t i = 0; i != bsize; ++i)) {
|
|
||||||
checksum ^= fgetc(fp);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
|
|
||||||
// calculate checksum
|
|
||||||
uint64_t filesize = buffer.size();
|
uint64_t filesize = buffer.size();
|
||||||
int checksum = calculateChecksum(&buffer[0], filesize);
|
|
||||||
LOG(logINFOBLUE) << "checksum:" << checksum;
|
LOG(logINFOBLUE) << "checksum:" << checksum;
|
||||||
|
|
||||||
// send program from memory to detector
|
// send program from memory to detector
|
||||||
LOG(logINFO) << "Sending programming binary (from pof) to detector "
|
LOG(logINFO) << "Sending programming binary (from pof) to detector "
|
||||||
<< moduleId << " (" << shm()->hostname << ")";
|
<< moduleId << " (" << shm()->hostname << ")";
|
||||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||||
client.Send(F_PROGRAM_FPGA);
|
client.Send(F_PROGRAM_FPGA);
|
||||||
client.Send(filesize);
|
client.Send(filesize);
|
||||||
|
// client.Send(checksum);
|
||||||
|
|
||||||
// opening file fail
|
// opening file fail
|
||||||
if (client.Receive<int>() == FAIL) {
|
if (client.Receive<int>() == FAIL) {
|
||||||
|
@ -535,7 +535,7 @@ class Module : public virtual slsDetectorDefs {
|
|||||||
* Advanced *
|
* Advanced *
|
||||||
* *
|
* *
|
||||||
* ************************************************/
|
* ************************************************/
|
||||||
void programFPGA(std::vector<char> buffer);
|
void programFPGA(std::vector<char> buffer, const std::string &checksum);
|
||||||
void resetFPGA();
|
void resetFPGA();
|
||||||
void copyDetectorServer(const std::string &fname,
|
void copyDetectorServer(const std::string &fname,
|
||||||
const std::string &hostname);
|
const std::string &hostname);
|
||||||
@ -744,8 +744,8 @@ class Module : public virtual slsDetectorDefs {
|
|||||||
std::string getTrimbitFilename(detectorSettings settings, int e_eV);
|
std::string getTrimbitFilename(detectorSettings settings, int e_eV);
|
||||||
sls_detector_module readSettingsFile(const std::string &fname,
|
sls_detector_module readSettingsFile(const std::string &fname,
|
||||||
bool trimbits = true);
|
bool trimbits = true);
|
||||||
int calculateChecksum(char *buffer, size_t bsize);
|
void programFPGAviaBlackfin(std::vector<char> buffer,
|
||||||
void programFPGAviaBlackfin(std::vector<char> buffer);
|
const std::string &checksum);
|
||||||
void programFPGAviaNios(std::vector<char> buffer);
|
void programFPGAviaNios(std::vector<char> buffer);
|
||||||
|
|
||||||
const int moduleId;
|
const int moduleId;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user