This commit is contained in:
Erik Frojdh 2020-07-31 14:09:21 +02:00
parent d5b893e452
commit ec27d35d6d

View File

@ -24,8 +24,6 @@
namespace sls { namespace sls {
// Configuration
// creating new shm // creating new shm
Module::Module(detectorType type, int det_id, int module_id, bool verify) Module::Module(detectorType type, int det_id, int module_id, bool verify)
: moduleId(module_id), shm(det_id, module_id) { : moduleId(module_id), shm(det_id, module_id) {
@ -156,24 +154,21 @@ void Module::setSettings(detectorSettings isettings) {
} }
void Module::loadSettingsFile(const std::string &fname) { void Module::loadSettingsFile(const std::string &fname) {
std::string fn = fname;
std::ostringstream ostfn;
ostfn << fname;
// find specific file if it has detid in file name (.snxxx) // find specific file if it has detid in file name (.snxxx)
if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) { if (shm()->myDetectorType == EIGER || shm()->myDetectorType == MYTHEN3) {
std::ostringstream ostfn;
ostfn << fname;
if (fname.find(".sn") == std::string::npos && if (fname.find(".sn") == std::string::npos &&
fname.find(".trim") == std::string::npos && fname.find(".trim") == std::string::npos &&
fname.find(".settings") == std::string::npos) { fname.find(".settings") == std::string::npos) {
ostfn << ".sn" << std::setfill('0') << std::setw(3) << std::dec ostfn << ".sn" << std::setfill('0') << std::setw(3) << std::dec
<< getSerialNumber(); << getSerialNumber();
} }
auto myMod = readSettingsFile(ostfn.str());
setModule(myMod);
} else { } else {
throw RuntimeError("not implemented for this detector"); throw RuntimeError("not implemented for this detector");
} }
fn = ostfn.str();
auto myMod = readSettingsFile(fn);
setModule(myMod);
} }
int Module::getAllTrimbits() const { int Module::getAllTrimbits() const {
@ -447,10 +442,8 @@ std::vector<uint64_t> Module::getNumMissingPackets() const {
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_NUM_MISSING_PACKETS); client.Send(F_GET_NUM_MISSING_PACKETS);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Receiver " + std::to_string(moduleId) + throw RuntimeError("Receiver " + std::to_string(moduleId) +
" returned error: " + std::string(mess)); " returned error: " + client.readErrorMessage());
} else { } else {
auto nports = client.Receive<int>(); auto nports = client.Receive<int>();
std::vector<uint64_t> retval(nports); std::vector<uint64_t> retval(nports);
@ -727,14 +720,13 @@ std::string Module::getReceiverHostname() const {
void Module::setReceiverHostname(const std::string &receiverIP) { void Module::setReceiverHostname(const std::string &receiverIP) {
LOG(logDEBUG1) << "Setting up Receiver with " << receiverIP; LOG(logDEBUG1) << "Setting up Receiver with " << receiverIP;
// recieverIP is none
if (receiverIP == "none") { if (receiverIP == "none") {
memset(shm()->rxHostname, 0, MAX_STR_LENGTH); memset(shm()->rxHostname, 0, MAX_STR_LENGTH);
sls::strcpy_safe(shm()->rxHostname, "none"); sls::strcpy_safe(shm()->rxHostname, "none");
shm()->useReceiverFlag = false; shm()->useReceiverFlag = false;
} }
// stop acquisition if running
if (getRunStatus() == RUNNING) { if (getRunStatus() == RUNNING) {
LOG(logWARNING) << "Acquisition already running, Stopping it."; LOG(logWARNING) << "Acquisition already running, Stopping it.";
stopAcquisition(); stopAcquisition();
@ -779,7 +771,6 @@ void Module::setReceiverHostname(const std::string &receiverIP) {
sendToDetector(F_SET_DEST_UDP_MAC2, retvals[1], nullptr); sendToDetector(F_SET_DEST_UDP_MAC2, retvals[1], nullptr);
} }
// update numinterfaces if different
shm()->numUDPInterfaces = retval.udpInterfaces; shm()->numUDPInterfaces = retval.udpInterfaces;
if (shm()->myDetectorType == MOENCH) { if (shm()->myDetectorType == MOENCH) {
@ -899,9 +890,9 @@ void Module::setFilePath(const std::string &path) {
} }
std::string Module::getFileName() const { std::string Module::getFileName() const {
char retvals[MAX_STR_LENGTH]{}; char buff[MAX_STR_LENGTH]{};
sendToReceiver(F_GET_RECEIVER_FILE_NAME, nullptr, retvals); sendToReceiver(F_GET_RECEIVER_FILE_NAME, nullptr, buff);
return std::string(retvals); return buff;
} }
void Module::setFileName(const std::string &fname) { void Module::setFileName(const std::string &fname) {
@ -1803,8 +1794,7 @@ uint32_t Module::getTenGigaADCEnableMask() const {
void Module::setTenGigaADCEnableMask(uint32_t mask) { void Module::setTenGigaADCEnableMask(uint32_t mask) {
sendToDetector(F_SET_ADC_ENABLE_MASK_10G, mask, nullptr); sendToDetector(F_SET_ADC_ENABLE_MASK_10G, mask, nullptr);
// update #nchan, as it depends on #samples, adcmask, updateNumberOfChannels(); // depends on samples and adcmask
updateNumberOfChannels();
// send to processor // send to processor
if (shm()->myDetectorType == MOENCH) if (shm()->myDetectorType == MOENCH)
@ -1824,8 +1814,7 @@ int Module::getNumberOfDigitalSamples() const {
void Module::setNumberOfDigitalSamples(int value) { void Module::setNumberOfDigitalSamples(int value) {
LOG(logDEBUG1) << "Setting number of digital samples to " << value; LOG(logDEBUG1) << "Setting number of digital samples to " << value;
sendToDetector(F_SET_NUM_DIGITAL_SAMPLES, value, nullptr); sendToDetector(F_SET_NUM_DIGITAL_SAMPLES, value, nullptr);
// update #nchan, as it depends on #samples, adcmask updateNumberOfChannels(); // depends on samples and adcmask
updateNumberOfChannels();
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
LOG(logDEBUG1) << "Sending number of digital samples to Receiver: " LOG(logDEBUG1) << "Sending number of digital samples to Receiver: "
<< value; << value;
@ -2105,8 +2094,7 @@ std::map<std::string, std::string> Module::getAdditionalJsonHeader() const {
} }
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_ADDITIONAL_JSON_HEADER); client.Send(F_GET_ADDITIONAL_JSON_HEADER);
auto ret = client.Receive<int>(); if (client.Receive<int>() == FAIL) {
if (ret == FAIL) {
throw RuntimeError("Receiver " + std::to_string(moduleId) + throw RuntimeError("Receiver " + std::to_string(moduleId) +
" returned error: " + client.readErrorMessage()); " returned error: " + client.readErrorMessage());
} else { } else {
@ -2155,12 +2143,9 @@ void Module::setAdditionalJsonHeader(
if (size > 0) if (size > 0)
client.Send(&buff[0], buff.size()); client.Send(&buff[0], buff.size());
auto ret = client.Receive<int>(); if (client.Receive<int>() == FAIL) {
if (ret == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, MAX_STR_LENGTH);
throw RuntimeError("Receiver " + std::to_string(moduleId) + throw RuntimeError("Receiver " + std::to_string(moduleId) +
" returned error: " + std::string(mess)); " returned error: " + client.readErrorMessage());
} }
} }
@ -2863,8 +2848,6 @@ int Module::sendModule(sls_detector_module *myMod, sls::ClientSocket &client) {
} }
void Module::setModule(sls_detector_module &module, bool trimbits) { void Module::setModule(sls_detector_module &module, bool trimbits) {
int fnum = F_SET_MODULE;
int ret = FAIL;
LOG(logDEBUG1) << "Setting module with trimbits:" << trimbits; LOG(logDEBUG1) << "Setting module with trimbits:" << trimbits;
// to exclude trimbits // to exclude trimbits
if (!trimbits) { if (!trimbits) {
@ -2872,14 +2855,11 @@ void Module::setModule(sls_detector_module &module, bool trimbits) {
module.nchip = 0; module.nchip = 0;
} }
auto client = DetectorSocket(shm()->hostname, shm()->controlPort); auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(&fnum, sizeof(fnum)); client.Send(F_SET_MODULE);
sendModule(&module, client); sendModule(&module, client);
client.Receive(&ret, sizeof(ret)); if (client.Receive<int>() == FAIL) {
if (ret == FAIL) {
char mess[MAX_STR_LENGTH] = {0};
client.Receive(mess, sizeof(mess));
throw RuntimeError("Detector " + std::to_string(moduleId) + throw RuntimeError("Detector " + std::to_string(moduleId) +
" returned error: " + mess); " returned error: " + client.readErrorMessage());
} }
} }
@ -3120,24 +3100,17 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
void Module::programFPGAviaBlackfin(std::vector<char> buffer) { void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
uint64_t filesize = buffer.size(); uint64_t filesize = buffer.size();
// send program from memory to detector // send program from memory to detector
int fnum = F_PROGRAM_FPGA;
int ret = FAIL;
char mess[MAX_STR_LENGTH] = {0};
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(&fnum, sizeof(fnum)); client.Send(F_PROGRAM_FPGA);
client.Send(&filesize, sizeof(filesize)); client.Send(filesize);
client.Receive(&ret, sizeof(ret));
// error in detector at opening file pointer to flash // error in detector at opening file pointer to flash
if (ret == FAIL) { if (client.Receive<int>() == FAIL) {
client.Receive(mess, sizeof(mess));
std::ostringstream os; std::ostringstream os;
os << "Detector " << moduleId << " (" << shm()->hostname << ")" os << "Detector " << moduleId << " (" << shm()->hostname << ")"
<< " returned error: " << mess; << " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str()); throw RuntimeError(os.str());
} }
@ -3178,13 +3151,11 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
<< "\t filesize:" << filesize; << "\t filesize:" << filesize;
client.Send(&buffer[currentPointer], unitprogramsize); client.Send(&buffer[currentPointer], unitprogramsize);
client.Receive(&ret, sizeof(ret)); if (client.Receive<int>() == FAIL) {
if (ret == FAIL) { std::cout << '\n';
printf("\n");
client.Receive(mess, sizeof(mess));
std::ostringstream os; std::ostringstream os;
os << "Detector " << moduleId << " (" << shm()->hostname << ")" os << "Detector " << moduleId << " (" << shm()->hostname << ")"
<< " returned error: " << mess; << " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str()); throw RuntimeError(os.str());
} }
filesize -= unitprogramsize; filesize -= unitprogramsize;
@ -3197,7 +3168,7 @@ void Module::programFPGAviaBlackfin(std::vector<char> buffer) {
(static_cast<double>(totalsize - filesize) / totalsize) * 100)); (static_cast<double>(totalsize - filesize) / totalsize) * 100));
std::cout << std::flush; std::cout << std::flush;
} }
printf("\n"); std::cout << '\n';
LOG(logINFO) << "FPGA programmed successfully"; LOG(logINFO) << "FPGA programmed successfully";
rebootController(); rebootController();
} }
@ -3212,21 +3183,17 @@ void Module::programFPGAviaNios(std::vector<char> buffer) {
// filesize // filesize
client.Send(filesize); client.Send(filesize);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, sizeof(mess));
std::ostringstream os; std::ostringstream os;
os << "Detector " << moduleId << " (" << shm()->hostname << ")" os << "Detector " << moduleId << " (" << shm()->hostname << ")"
<< " returned error: " << mess; << " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str()); throw RuntimeError(os.str());
} }
// program // program
client.Send(buffer); client.Send(buffer);
if (client.Receive<int>() == FAIL) { if (client.Receive<int>() == FAIL) {
char mess[MAX_STR_LENGTH]{};
client.Receive(mess, sizeof(mess));
std::ostringstream os; std::ostringstream os;
os << "Detector " << moduleId << " (" << shm()->hostname << ")" os << "Detector " << moduleId << " (" << shm()->hostname << ")"
<< " returned error: " << mess; << " returned error: " << client.readErrorMessage();
throw RuntimeError(os.str()); throw RuntimeError(os.str());
} }
LOG(logINFO) << "FPGA programmed successfully"; LOG(logINFO) << "FPGA programmed successfully";