mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-15 06:17:12 +02:00
WIP
This commit is contained in:
@ -16,6 +16,7 @@
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
namespace sls {
|
||||
@ -1746,19 +1747,116 @@ void Module::setLEDEnable(bool enable) {
|
||||
// Pattern
|
||||
|
||||
void Module::setPattern(const std::string &fname) {
|
||||
uint64_t word;
|
||||
uint64_t addr = 0;
|
||||
FILE *fd = fopen(fname.c_str(), "r");
|
||||
if (fd != nullptr) {
|
||||
while (fread(&word, sizeof(word), 1, fd) != 0U) {
|
||||
setPatternWord(addr, word); // TODO! (Erik) do we need to send
|
||||
// pattern in 64bit chunks?
|
||||
++addr;
|
||||
}
|
||||
fclose(fd);
|
||||
} else {
|
||||
throw RuntimeError("Could not open file to set pattern");
|
||||
patternParameters pat;
|
||||
memset(&pat, 0, sizeof(pat));
|
||||
std::ifstream input_file;
|
||||
input_file.open(fname.c_str(), std::ios_base::in);
|
||||
if (!input_file.is_open()) {
|
||||
throw RuntimeError("Could not open pattern file " + fname +
|
||||
" for reading");
|
||||
}
|
||||
std::string current_line;
|
||||
while (input_file.good()) {
|
||||
getline(input_file, current_line);
|
||||
if (current_line.find('#') != std::string::npos) {
|
||||
current_line.erase(current_line.find('#'));
|
||||
}
|
||||
LOG(logDEBUG1) << "current_line after removing comments:\n\t"
|
||||
<< current_line;
|
||||
if (current_line.length() > 1) {
|
||||
|
||||
// convert command and string to a vector
|
||||
std::istringstream iss(current_line);
|
||||
auto it = std::istream_iterator<std::string>(iss);
|
||||
std::vector<std::string> args = std::vector<std::string>(
|
||||
it, std::istream_iterator<std::string>());
|
||||
|
||||
std::string cmd = args[0];
|
||||
int nargs = args.size() - 1;
|
||||
|
||||
if (cmd == "patword") {
|
||||
if (nargs != 2) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
uint32_t addr = StringTo<uint32_t>(args[1]);
|
||||
if (addr >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid address for " + ToString(args));
|
||||
}
|
||||
pat.word[addr] = StringTo<uint64_t>(args[2]);
|
||||
} else if (cmd == "patioctrl") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
pat.patioctrl = StringTo<uint64_t>(args[1]);
|
||||
} else if (cmd == "patclkctrl") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
pat.patclkctrl = StringTo<uint64_t>(args[1]);
|
||||
} else if (cmd == "patlimits") {
|
||||
if (nargs != 2) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
pat.patlimits[0] = StringTo<uint32_t>(args[1]);
|
||||
pat.patlimits[1] = StringTo<uint32_t>(args[2]);
|
||||
if (pat.patlimits[0] >= MAX_PATTERN_LENGTH ||
|
||||
pat.patlimits[1] >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid address for " + ToString(args));
|
||||
}
|
||||
} else if (cmd == "patloop0" || cmd == "patloop1" ||
|
||||
cmd == "patloop2") {
|
||||
if (nargs != 2) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
int patloop1 = StringTo<uint32_t>(args[1]);
|
||||
int patloop2 = StringTo<uint32_t>(args[2]);
|
||||
pat.patloop[level * 2 + 0] = patloop1;
|
||||
pat.patloop[level * 2 + 1] = patloop2;
|
||||
if (patloop1 >= MAX_PATTERN_LENGTH ||
|
||||
patloop2 >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid address for " + ToString(args));
|
||||
}
|
||||
} else if (cmd == "patnloop0" || cmd == "patnloop1" ||
|
||||
cmd == "patnloop2") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
pat.patnloop[level] = StringTo<uint32_t>(args[1]);
|
||||
} else if (cmd == "patwait0" || cmd == "patwait1" ||
|
||||
cmd == "patwait2") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
pat.patwait[level] = StringTo<uint32_t>(args[1]);
|
||||
if (pat.patwait[level] >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid address for " + ToString(args));
|
||||
}
|
||||
} else if (cmd == "patwaittime0" || cmd == "patwaittime1" ||
|
||||
cmd == "patwaittime2") {
|
||||
if (nargs != 1) {
|
||||
throw RuntimeError("Invalid arguments for " +
|
||||
ToString(args));
|
||||
}
|
||||
int level = cmd[cmd.find_first_of("012")] - '0';
|
||||
pat.patwaittime[level] = StringTo<uint64_t>(args[1]);
|
||||
} else {
|
||||
throw RuntimeError("Unknown command in pattern file " + cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
input_file.close();
|
||||
std::cout << "sizeof pat:" << sizeof(pat) << std::endl;
|
||||
sendToDetector<uint64_t>(F_SET_PATTERN, pat);
|
||||
}
|
||||
|
||||
uint64_t Module::getPatternIOControl() {
|
||||
|
Reference in New Issue
Block a user