set clock divider, phase and get clock freq for gotthard2, priliminary

This commit is contained in:
2019-10-17 16:39:41 +02:00
parent 0a3905802f
commit be50344b45
21 changed files with 1119 additions and 54 deletions

View File

@@ -181,4 +181,110 @@ std::string CmdProxy::ListCommands(int action) {
}
}
std::string CmdProxy::ClockFrequency(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_clock (0-8)] [freq_in_Hz]\n\t[Gotthard2] Frequency of clock n_clock in Hz. Use clkdiv to set frequency." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getClockFrequency(std::stoi(args[0]), {det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setClockFrequency(std::stoi(args[0]), std::stoi(args[1]));
//TODO print args
os << std::stoi(args[1]) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::ClockPhase(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_clock (0-8)] [phase] [deg (optional)]\n\t[Gotthard2] Phase of clock n_clock. If deg, then phase shift in degrees, else absolute phase shift values." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() == 1) {
auto t = det->getClockPhase(std::stoi(args[0]), {det_id});
os << OutString(t) << '\n';
} else if (args.size() == 2) {
if (args[1] != "deg") {
throw sls::RuntimeError("Cannot scan argument" + args[1] + ". Did you mean deg?");
}
auto t = det->getClockPhaseinDegrees(std::stoi(args[0]), {det_id});
os << OutString(t) << '\n';
} else {
WrongNumberOfParameters(1);
}
} else if (action == defs::PUT_ACTION) {
if (args.size() == 2) {
det->setClockPhase(std::stoi(args[0]), std::stoi(args[1]), {det_id});
os << args[1] << '\n';
} else if (args.size() == 3) {
if (args[2] != "deg") {
throw sls::RuntimeError("Cannot scan argument" + args[2] + ". Did you mean deg?");
}
det->setClockPhaseinDegrees(std::stoi(args[0]), std::stoi(args[1]), {det_id});
os << std::stoi(args[1]) << '\n';
} else {
WrongNumberOfParameters(1);
}
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::MaxClockPhaseShift(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_clock (0-8)]\n\t[Gotthard2] Absolute Maximum Phase shift of clock n_clock." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getMaxClockPhaseShift(std::stoi(args[0]), {det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("Cannot put");
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::ClockDivider(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[n_clock (0-8)] [n_divider]\n\t[Gotthard2] Clock Divider of clock n_clock. Must be greater than 1." << '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getClockDivider(std::stoi(args[0]), {det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setClockDivider(std::stoi(args[0]), std::stoi(args[1]));
//TODO print args
os << std::stoi(args[1]) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
} // namespace sls

View File

@@ -1544,6 +1544,42 @@ Result<uint64_t> Detector::getRxCurrentFrameIndex(Positions pos) const {
return pimpl->Parallel(&slsDetector::getReceiverCurrentFrameIndex, pos);
}
Result<int> Detector::getClockFrequency(int clkIndex, Positions pos) {
return pimpl->Parallel(&slsDetector::getClockFrequency, pos, clkIndex);
}
void Detector::setClockFrequency(int clkIndex, int value, Positions pos) {
pimpl->Parallel(&slsDetector::setClockFrequency, pos, clkIndex, value);
}
Result<int> Detector::getClockPhase(int clkIndex, Positions pos) {
return pimpl->Parallel(&slsDetector::getClockPhase, pos, clkIndex, false);
}
void Detector::setClockPhase(int clkIndex, int value, Positions pos) {
pimpl->Parallel(&slsDetector::setClockPhase, pos, clkIndex, value, false);
}
Result<int> Detector::getMaxClockPhaseShift(int clkIndex, Positions pos) {
return pimpl->Parallel(&slsDetector::getMaxClockPhaseShift, pos, clkIndex);
}
Result<int> Detector::getClockPhaseinDegrees(int clkIndex, Positions pos) {
return pimpl->Parallel(&slsDetector::getClockPhase, pos, clkIndex, true);
}
void Detector::setClockPhaseinDegrees(int clkIndex, int value, Positions pos) {
pimpl->Parallel(&slsDetector::setClockPhase, pos, clkIndex, value, true);
}
Result<int> Detector::getClockDivider(int clkIndex, Positions pos) {
return pimpl->Parallel(&slsDetector::getClockDivider, pos, clkIndex);
}
void Detector::setClockDivider(int clkIndex, int value, Positions pos) {
pimpl->Parallel(&slsDetector::setClockDivider, pos, clkIndex, value);
}
std::vector<int> Detector::getPortNumbers(int start_port) {
int num_sockets_per_detector = 1;
switch (getDetectorType({}).squash()) {

View File

@@ -3425,6 +3425,57 @@ void slsDetector::setDigitalIODelay(uint64_t pinMask, int delay) {
FILE_LOG(logDEBUG1) << "Digital IO Delay successful";
}
int slsDetector::getClockFrequency(int clkIndex) {
int retval = -1;
FILE_LOG(logDEBUG1) << "Getting Clock " << clkIndex << " frequency";
sendToDetector(F_GET_CLOCK_FREQUENCY, clkIndex, retval);
FILE_LOG(logDEBUG1) << "Clock " << clkIndex << " frequency: " << retval;
return retval;
}
void slsDetector::setClockFrequency(int clkIndex, int value) {
int args[]{clkIndex, value};
FILE_LOG(logDEBUG1) << "Setting Clock " << clkIndex << " frequency to " << value;
sendToDetector(F_SET_CLOCK_FREQUENCY, args, nullptr);
}
int slsDetector::getClockPhase(int clkIndex, bool inDegrees) {
int args[]{clkIndex, static_cast<int>(inDegrees)};
int retval = -1;
FILE_LOG(logDEBUG1) << "Getting Clock " << clkIndex << " phase " << (inDegrees ? "in degrees" : "");
sendToDetector(F_GET_CLOCK_PHASE, args, retval);
FILE_LOG(logDEBUG1) << "Clock " << clkIndex << " frequency: " << retval << (inDegrees ? "degrees" : "");
return retval;
}
void slsDetector::setClockPhase(int clkIndex, int value, bool inDegrees) {
int args[]{clkIndex, value, static_cast<int>(inDegrees)};
FILE_LOG(logDEBUG1) << "Setting Clock " << clkIndex << " phase to " << value << (inDegrees ? "degrees" : "");
sendToDetector(F_SET_CLOCK_PHASE, args, nullptr);
}
int slsDetector::getMaxClockPhaseShift(int clkIndex) {
int retval = -1;
FILE_LOG(logDEBUG1) << "Getting Max Phase Shift for Clock " << clkIndex;
sendToDetector(F_GET_MAX_CLOCK_PHASE_SHIFT, clkIndex, retval);
FILE_LOG(logDEBUG1) << "Max Phase Shift for Clock " << clkIndex << ": " << retval;
return retval;
}
int slsDetector::getClockDivider(int clkIndex) {
int retval = -1;
FILE_LOG(logDEBUG1) << "Getting Clock " << clkIndex << " divider";
sendToDetector(F_GET_CLOCK_DIVIDER, clkIndex, retval);
FILE_LOG(logDEBUG1) << "Clock " << clkIndex << " divider: " << retval;
return retval;
}
void slsDetector::setClockDivider(int clkIndex, int value) {
int args[]{clkIndex, value};
FILE_LOG(logDEBUG1) << "Setting Clock " << clkIndex << " divider to " << value;
sendToDetector(F_SET_CLOCK_DIVIDER, args, nullptr);
}
sls_detector_module slsDetector::interpolateTrim(sls_detector_module *a,
sls_detector_module *b,
const int energy, const int e1,