mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-14 22:07:12 +02:00
Setting pattern from memory (#218)
* ToString accepts c-style arrays * added patternParameters to python * fixed patwait time bug in validation * moved load from file function to patterParameters * server using patternparamters structure to get pattern Co-authored-by: Erik Frojdh <erik.frojdh@gmail.com>
This commit is contained in:
@ -1915,104 +1915,35 @@ void Module::setLEDEnable(bool enable) {
|
||||
|
||||
void Module::setPattern(const std::string &fname) {
|
||||
auto pat = sls::make_unique<patternParameters>();
|
||||
std::ifstream input_file(fname);
|
||||
if (!input_file) {
|
||||
throw RuntimeError("Could not open pattern file " + fname +
|
||||
" for reading");
|
||||
pat->load(fname);
|
||||
setPatternStructure(pat.get());
|
||||
}
|
||||
|
||||
void Module::setPatternStructure(const defs::patternParameters *pat) {
|
||||
// verifications
|
||||
if (pat->patlimits[0] >= MAX_PATTERN_LENGTH ||
|
||||
pat->patlimits[1] >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid Pattern limits address [" +
|
||||
ToString(pat->patlimits[0]) + std::string(", ") +
|
||||
ToString(pat->patlimits[1]) + std::string("]"));
|
||||
}
|
||||
for (std::string line; std::getline(input_file, line);) {
|
||||
if (line.find('#') != std::string::npos) {
|
||||
line.erase(line.find('#'));
|
||||
for (int i = 0; i != 3; ++i) {
|
||||
if (pat->patloop[i * 2 + 0] >= MAX_PATTERN_LENGTH ||
|
||||
pat->patloop[i * 2 + 1] >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError(
|
||||
"Invalid Pattern loop address for level " + ToString(i) +
|
||||
std::string(" [") + ToString(pat->patloop[i * 2 + 0]) +
|
||||
std::string(", ") + ToString(pat->patloop[i * 2 + 1]) +
|
||||
std::string("]"));
|
||||
}
|
||||
LOG(logDEBUG1) << "line after removing comments:\n\t" << line;
|
||||
if (line.length() > 1) {
|
||||
|
||||
// convert command and string to a vector
|
||||
std::istringstream iss(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 == "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);
|
||||
}
|
||||
if (pat->patwait[i] >= MAX_PATTERN_LENGTH) {
|
||||
throw RuntimeError("Invalid Pattern wait address for level " +
|
||||
ToString(i) + std::string(" ") +
|
||||
ToString(pat->patwait[i]));
|
||||
}
|
||||
}
|
||||
LOG(logDEBUG1) << "Sending pattern from file to detector:" << *pat;
|
||||
sendToDetector(F_SET_PATTERN, pat.get(), sizeof(patternParameters), nullptr,
|
||||
0);
|
||||
sendToDetector(F_SET_PATTERN, pat, sizeof(patternParameters), nullptr, 0);
|
||||
}
|
||||
|
||||
uint64_t Module::getPatternIOControl() const {
|
||||
|
Reference in New Issue
Block a user