mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-11 23:20:30 +02:00
changed runclk command to use units and float, TODO: dbit, adcclk, why is everything called StringTo ?
This commit is contained in:
@@ -1622,8 +1622,8 @@ class Detector {
|
||||
/** [CTB] in MHz, [XCTB] in kHz */
|
||||
Result<int> getRUNClock(Positions pos = {}) const;
|
||||
|
||||
/** [CTB] in MHz, [XCTB] in kHz */
|
||||
void setRUNClock(int value_in_MHz, Positions pos = {});
|
||||
/** [CTB] in Hz, [XCTB] in Hz */
|
||||
void setRUNClock(int value_in_Hz, Positions pos = {});
|
||||
|
||||
/** [CTB] in MHZ */
|
||||
Result<int> getSYNCClock(Positions pos = {}) const;
|
||||
|
||||
@@ -10211,9 +10211,7 @@ std::string Caller::runclk(int action) {
|
||||
std::ostringstream os;
|
||||
// print help
|
||||
if (action == slsDetectorDefs::HELP_ACTION) {
|
||||
os << R"V0G0N([n_clk in MHz]
|
||||
[Ctb] Run clock in MHz.
|
||||
[xilinx Ctb] Run clock in kHz. )V0G0N"
|
||||
os << R"V0G0N([Run clock frequency] [(optional unit) MHz|kHz|Hz])V0G0N"
|
||||
<< std::endl;
|
||||
return os.str();
|
||||
}
|
||||
@@ -10230,15 +10228,25 @@ std::string Caller::runclk(int action) {
|
||||
}
|
||||
|
||||
else if (action == slsDetectorDefs::PUT_ACTION) {
|
||||
if (1 && args.size() != 1) {
|
||||
if (1 && args.size() != 1 && args.size() != 2) {
|
||||
throw RuntimeError("Wrong number of arguments for action PUT");
|
||||
}
|
||||
|
||||
if (args.size() == 1) {
|
||||
try {
|
||||
StringTo<int>(args[0]);
|
||||
std::string tmp_freq(args[0]);
|
||||
std::string unit = RemoveUnit(tmp_freq);
|
||||
StringToHz(tmp_freq, unit);
|
||||
} catch (...) {
|
||||
throw RuntimeError("Could not convert argument 0 to int");
|
||||
throw RuntimeError("Could not convert argument to frequency");
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
try {
|
||||
StringToHz(args[0], args[1]);
|
||||
} catch (...) {
|
||||
throw RuntimeError("Could not convert arguments to frequency");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10260,9 +10268,17 @@ std::string Caller::runclk(int action) {
|
||||
|
||||
if (action == slsDetectorDefs::PUT_ACTION) {
|
||||
if (args.size() == 1) {
|
||||
auto arg0 = StringTo<int>(args[0]);
|
||||
det->setRUNClock(arg0, std::vector<int>{det_id});
|
||||
os << args.front() << '\n';
|
||||
std::string tmp_freq(args[0]);
|
||||
std::string unit = RemoveUnit(tmp_freq);
|
||||
auto converted_freq_hz = StringToHz(tmp_freq, unit);
|
||||
det->setRUNClock(converted_freq_hz, std::vector<int>{det_id});
|
||||
os << args[0] << '\n';
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
auto converted_freq_hz = StringToHz(args[0], args[1]);
|
||||
det->setRUNClock(converted_freq_hz, std::vector<int>{det_id});
|
||||
os << args[0] << args[1] << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2157,9 +2157,9 @@ Result<int> Detector::getRUNClock(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getClockFrequency, pos, defs::RUN_CLOCK);
|
||||
}
|
||||
|
||||
void Detector::setRUNClock(int value_in_MHz, Positions pos) {
|
||||
void Detector::setRUNClock(int value_in_Hz, Positions pos) {
|
||||
pimpl->Parallel(&Module::setClockFrequency, pos, defs::RUN_CLOCK,
|
||||
value_in_MHz);
|
||||
value_in_Hz);
|
||||
}
|
||||
|
||||
Result<int> Detector::getSYNCClock(Positions pos) const {
|
||||
|
||||
@@ -353,4 +353,7 @@ std::vector<T> StringTo(const std::vector<std::string> &strings) {
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Convert frequency string with unit (MHz, kHz, Hz) to Hz */
|
||||
int StringToHz(const std::string &s, const std::string &unit);
|
||||
|
||||
} // namespace sls
|
||||
|
||||
@@ -1181,4 +1181,23 @@ template <> int64_t StringTo(const std::string &s) {
|
||||
return std::stol(s, nullptr, base);
|
||||
}
|
||||
|
||||
int StringToHz(const std::string &s, const std::string &unit) {
|
||||
double fval{0};
|
||||
try {
|
||||
fval = std::stod(s);
|
||||
} catch (const std::invalid_argument &e) {
|
||||
throw RuntimeError("Could not convert string to frequency");
|
||||
}
|
||||
if (unit.empty() || unit == "MHz") {
|
||||
return static_cast<int>(fval * 1000000.0);
|
||||
} else if (unit == "kHz") {
|
||||
return static_cast<int>(fval * 1000.0);
|
||||
} else if (unit == "Hz") {
|
||||
return static_cast<int>(fval);
|
||||
} else {
|
||||
throw RuntimeError("Unknown unit: " + unit +
|
||||
". Supported units: MHz, kHz, Hz");
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sls
|
||||
Reference in New Issue
Block a user