ctb patterns interface rewritten

This commit is contained in:
2019-04-18 15:29:43 +02:00
parent ff4ce48e5d
commit 266520741a
13 changed files with 404 additions and 354 deletions

View File

@ -1798,41 +1798,58 @@ class multiSlsDetector : public virtual slsDetectorDefs {
int setReceiverSilentMode(int i = -1, int detPos = -1);
/**
* Opens pattern file and sends pattern to CTB
* Opens pattern file and sends pattern (CTB/ Moench)
* @param fname pattern file to open
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK/FAIL
*/
int setPattern(const std::string &fname, int detPos = -1);
/**
* Sets pattern IO control (CTB/ Moench)
* @param word 64bit word to be written, -1 gets
* @param detPos -1 for all detectors in list or specific detector position
* @returns actual value
*/
uint64_t setPatternIOControl(uint64_t word = -1, int detPos = -1);
/**
* Sets pattern clock control (CTB/ Moench)
* @param word 64bit word to be written, -1 gets
* @param detPos -1 for all detectors in list or specific detector position
* @returns actual value
*/
uint64_t setPatternClockControl(uint64_t word = -1, int detPos = -1);
/**
* Writes a pattern word to the CTB
* @param addr address of the word, -1 is I/O control register,
* -2 is clk control register
* @param word 64bit word to be written, -1 gets
* Writes a pattern word (CTB/ Moench)
* @param addr address of the word
* @param word 64bit word to be written, -1 reads the addr (same as executing the pattern)
* @param detPos -1 for all detectors in list or specific detector position
* @returns actual value
*/
uint64_t setPatternWord(int addr, uint64_t word = -1, int detPos = -1);
uint64_t setPatternWord(int addr, uint64_t word, int detPos = -1);
/**
* Sets the pattern or loop limits in the CTB
* Sets the pattern or loop limits (CTB/ Moench)
* @param level -1 complete pattern, 0,1,2, loop level
* @param start start address if >=0
* @param stop stop address if >=0
* @param n number of loops (if level >=0)
* @param start start address for level 0-2, -1 gets
* @param stop stop address for level 0-2, -1 gets
* @param n number of loops for level 0-2, -1 gets
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK/FAIL
*/
int setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, uint64_t n,
int detPos = -1);
void setPatternLoops(int level, int start = -1, int stop = -1, int n = -1, int detPos = -1);
std::array<uint64_t, 3> getPatternLoops(uint64_t level, int detPos = -1);
/**
* Gets the pattern loop limits (CTB/ Moench)
* @param level -1 complete pattern, 0,1,2, loop level
* @param detPos -1 for all detectors in list or specific detector position
* @returns array of start address, stop address and number of loops
*/
std::array<int, 3> getPatternLoops(int level, int detPos = -1);
/**
* Sets the wait address in the CTB
* Sets the wait address (CTB/ Moench)
* @param level 0,1,2, wait level
* @param addr wait address, -1 gets
* @param detPos -1 for all detectors in list or specific detector position
@ -1841,7 +1858,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
int setPatternWaitAddr(int level, int addr = -1, int detPos = -1);
/**
* Sets the wait time in the CTB
* Sets the wait time (CTB/ Moench)
* @param level 0,1,2, wait level
* @param t wait time, -1 gets
* @param detPos -1 for all detectors in list or specific detector position
@ -1850,7 +1867,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
uint64_t setPatternWaitTime(int level, uint64_t t = -1, int detPos = -1);
/**
* Sets the mask applied to every pattern
* Sets the mask applied to every pattern (CTB/ Moench)
* @param mask mask to be applied
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
@ -1858,14 +1875,14 @@ class multiSlsDetector : public virtual slsDetectorDefs {
int setPatternMask(uint64_t mask, int detPos = -1);
/**
* Gets the mask applied to every pattern
* Gets the mask applied to every pattern (CTB/ Moench)
* @param detPos -1 for all detectors in list or specific detector position
* @returns mask set
*/
uint64_t getPatternMask(int detPos = -1);
/**
* Selects the bits that the mask will be applied to for every pattern
* Selects the bits that the mask will be applied to for every pattern (CTB/ Moench)
* @param mask mask to select bits
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK or FAIL
@ -1873,7 +1890,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
int setPatternBitMask(uint64_t mask, int detPos = -1);
/**
* Gets the bits that the mask will be applied to for every pattern
* Gets the bits that the mask will be applied to for every pattern (CTB/ Moench)
* @param detPos -1 for all detectors in list or specific detector position
* @returns mask of bits selected
*/

View File

@ -1641,65 +1641,77 @@ class slsDetector : public virtual slsDetectorDefs{
* @returns OK/FAIL
*/
int setPattern(const std::string &fname);
/**
* Writes a pattern word to the CTB
* @param addr address of the word, -1 is I/O control register, -2 is clk control register
/**
* Sets pattern IO control (CTB/ Moench)
* @param word 64bit word to be written, -1 gets
* @returns actual value
*/
uint64_t setPatternWord(uint64_t addr, uint64_t word = -1);
uint64_t setPatternIOControl(uint64_t word = -1);
/**
* Sets the pattern or loop limits in the CTB
* @param level -1 complete pattern, 0,1,2, loop level
* @param start start address if >=0
* @param stop stop address if >=0
* @param n number of loops (if level >=0)
* @returns OK/FAIL
* Sets pattern clock control (CTB/ Moench)
* @param word 64bit word to be written, -1 gets
* @returns actual value
*/
int setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, uint64_t n);
std::array<uint64_t, 3> getPatternLoops(uint64_t level);
uint64_t setPatternClockControl(uint64_t word = -1);
/**
* Sets the wait address in the CTB
* Writes a pattern word (CTB/ Moench)
* @param addr address of the word
* @param word 64bit word to be written, -1 reads the addr (same as executing the pattern)
* @returns actual value
*/
uint64_t setPatternWord(int addr, uint64_t word);
/**
* Sets the pattern or loop limits (CTB/ Moench)
* @param level -1 complete pattern, 0,1,2, loop level
* @param start start address for level 0-2, -1 gets
* @param stop stop address for level 0-2, -1 gets
* @param n number of loops for level 0-2, -1 gets
* @returns array of start addr, stop addr and number of loops
*/
std::array<int, 3> setPatternLoops(int level = -1, int start = -1, int stop = -1, int n = -1);
/**
* Sets the wait address (CTB/ Moench)
* @param level 0,1,2, wait level
* @param addr wait address, -1 gets
* @returns actual value
*/
int setPatternWaitAddr(uint64_t level, uint64_t addr = -1);
int setPatternWaitAddr(int level, int addr = -1);
/**
* Sets the wait time in the CTB
* Sets the wait time (CTB/ Moench)
* @param level 0,1,2, wait level
* @param t wait time, -1 gets
* @returns actual value
*/
uint64_t setPatternWaitTime(uint64_t level, uint64_t t = -1);
uint64_t setPatternWaitTime(int level, uint64_t t = -1);
/**
* Sets the mask applied to every pattern
* Sets the mask applied to every pattern (CTB/ Moench)
* @param mask mask to be applied
* @returns OK or FAIL
*/
int setPatternMask(uint64_t mask);
/**
* Gets the mask applied to every pattern
* Gets the mask applied to every pattern (CTB/ Moench)
* @returns mask set
*/
uint64_t getPatternMask();
/**
* Selects the bits that the mask will be applied to for every pattern
* Selects the bits that the mask will be applied to for every pattern (CTB/ Moench)
* @param mask mask to select bits
* @returns OK or FAIL
*/
int setPatternBitMask(uint64_t mask);
/**
* Gets the bits that the mask will be applied to for every pattern
* Gets the bits that the mask will be applied to for every pattern (CTB/ Moench)
* @returns mask of bits selected
*/
uint64_t getPatternBitMask();

View File

@ -3591,6 +3591,28 @@ int multiSlsDetector::setPattern(const std::string &fname, int detPos) {
}
}
uint64_t multiSlsDetector::setPatternIOControl(uint64_t word, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setPatternIOControl(word);
}
// multi
auto r = parallelCall(&slsDetector::setPatternIOControl, word);
return sls::minusOneIfDifferent(r);
}
uint64_t multiSlsDetector::setPatternClockControl(uint64_t word, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setPatternClockControl(word);
}
// multi
auto r = parallelCall(&slsDetector::setPatternClockControl, word);
return sls::minusOneIfDifferent(r);
}
uint64_t multiSlsDetector::setPatternWord(int addr, uint64_t word, int detPos) {
// single
if (detPos >= 0) {
@ -3602,25 +3624,24 @@ uint64_t multiSlsDetector::setPatternWord(int addr, uint64_t word, int detPos) {
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, uint64_t n, int detPos) {
void multiSlsDetector::setPatternLoops(int level, int start, int stop, int n, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setPatternLoops(level, start, stop, n);
detectors[detPos]->setPatternLoops(level, start, stop, n);
}
// multi
std::vector<int> r;
for (auto &d : detectors) {
r.push_back(d->setPatternLoops(level, start, stop, n));
}
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
parallelCall(&slsDetector::setPatternLoops, level, start, stop, n);
}
std::array<uint64_t, 3> multiSlsDetector::getPatternLoops(uint64_t level, int detPos){
if (detPos >= 0)
return detectors[detPos]->getPatternLoops(level);
auto r = parallelCall(&slsDetector::getPatternLoops, level);
std::array<int, 3> multiSlsDetector::getPatternLoops(int level, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setPatternLoops(level, -1, -1, -1);
}
// multi
auto r = parallelCall(&slsDetector::setPatternLoops, level, -1, -1, -1);
return sls::minusOneIfDifferent(r);
}

View File

@ -4477,11 +4477,46 @@ int slsDetector::setPattern(const std::string &fname) {
return addr;
}
uint64_t slsDetector::setPatternWord(uint64_t addr, uint64_t word) {
int fnum = F_SET_PATTERN;
uint64_t slsDetector::setPatternIOControl(uint64_t word) {
int fnum = F_SET_PATTERN_IO_CONTROL;
int ret = FAIL;
uint64_t mode = 0; // sets word
uint64_t args[]{mode, addr, word};
uint64_t arg = word;
uint64_t retval = -1;
FILE_LOG(logDEBUG1) << "Setting Pattern IO Control, word: 0x" << std::hex << word << std::dec;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Set Pattern IO Control: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
uint64_t slsDetector::setPatternClockControl(uint64_t word) {
int fnum = F_SET_PATTERN_CLOCK_CONTROL;
int ret = FAIL;
uint64_t arg = word;
uint64_t retval = -1;
FILE_LOG(logDEBUG1) << "Setting Pattern Clock Control, word: 0x" << std::hex << word << std::dec;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Set Pattern Clock Control: " << retval;
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return retval;
}
uint64_t slsDetector::setPatternWord(int addr, uint64_t word) {
int fnum = F_SET_PATTERN_WORD;
int ret = FAIL;
uint64_t args[]{static_cast<uint64_t>(addr), word};
uint64_t retval = -1;
FILE_LOG(logDEBUG1) << "Setting Pattern word, addr: 0x" << std::hex << addr
<< ", word: 0x" << word << std::dec;
@ -4498,16 +4533,15 @@ uint64_t slsDetector::setPatternWord(uint64_t addr, uint64_t word) {
return retval;
}
int slsDetector::setPatternLoops(uint64_t level, uint64_t start, uint64_t stop,
uint64_t n) {
int fnum = F_SET_PATTERN;
std::array<int, 3> slsDetector::setPatternLoops(int level, int start, int stop, int n) {
int fnum = F_SET_PATTERN_LOOP;
int ret = FAIL;
uint64_t mode = 1; // sets loop
uint64_t args[]{mode, level, start, stop, n};
int args[]{level, start, stop, n};
int retvals[3]{};
std::array<int, 3> r{};
FILE_LOG(logDEBUG1) << "Setting Pat Loops, level: " << level
<< ", start: " << start << ", stop: " << stop
<< ", n: " << n;
<< ", nloops: " << n;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
@ -4519,48 +4553,22 @@ int slsDetector::setPatternLoops(uint64_t level, uint64_t start, uint64_t stop,
assert(start == retvals[0]);
assert(stop == retvals[1]);
assert(n == retvals[2]);
r[0] = retvals[0];
r[1] = retvals[1];
r[2] = retvals[2];
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
return ret;
}
std::array<uint64_t, 3> slsDetector::getPatternLoops(uint64_t level) {
int fnum = F_SET_PATTERN;
int ret = FAIL;
uint64_t mode = 1; // sets loop
uint64_t args[]{mode, level, static_cast<uint64_t>(-1),
static_cast<uint64_t>(-1), static_cast<uint64_t>(-1)};
int retvals[3]{};
FILE_LOG(logDEBUG1) << "Setting Pat Loops, level: " << level
<< ", start: " << -1 << ", stop: " << -1
<< ", n: " << -1;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), retvals,
sizeof(retvals));
FILE_LOG(logDEBUG1) << "Get Pat Loops: " << retvals[0] << ", "
<< retvals[1] << ", " << retvals[2];
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
std::array<uint64_t, 3> r{};
r[0] = retvals[0];
r[1] = retvals[1];
r[2] = retvals[2];
return r;
}
int slsDetector::setPatternWaitAddr(uint64_t level, uint64_t addr) {
int fnum = F_SET_PATTERN;
int slsDetector::setPatternWaitAddr(int level, int addr) {
int fnum = F_SET_PATTERN_WAIT_ADDR;
int ret = FAIL;
uint64_t mode = 2; // sets loop
int retval = -1;
std::array<uint64_t, 3> args{mode, level, addr};
int args[]{level, addr};
FILE_LOG(logDEBUG1) << "Setting Pat Wait Addr, "
"level: "
<< level << ", addr: 0x" << std::hex << addr
@ -4569,7 +4577,7 @@ int slsDetector::setPatternWaitAddr(uint64_t level, uint64_t addr) {
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args.data(), sizeof(args),
ret = client.sendCommandThenRead(fnum, args, sizeof(args),
&retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Set Pat Wait Addr: " << retval;
}
@ -4579,18 +4587,17 @@ int slsDetector::setPatternWaitAddr(uint64_t level, uint64_t addr) {
return retval;
}
uint64_t slsDetector::setPatternWaitTime(uint64_t level, uint64_t t) {
int fnum = F_SET_PATTERN;
uint64_t slsDetector::setPatternWaitTime(int level, uint64_t t) {
int fnum = F_SET_PATTERN_WAIT_TIME;
int ret = FAIL;
uint64_t mode = 3; // sets loop
uint64_t retval = -1; // TODO! is this what we want?
std::array<uint64_t, 3> args{mode, level, t};
uint64_t retval = -1;
uint64_t args[]{static_cast<uint64_t>(level), t};
FILE_LOG(logDEBUG1) << "Setting Pat Wait Time, level: " << level
<< ", t: " << t;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args.data(), sizeof(args),
ret = client.sendCommandThenRead(fnum, args, sizeof(args),
&retval, sizeof(retval));
FILE_LOG(logDEBUG1) << "Set Pat Wait Time: " << retval;
}

View File

@ -5257,10 +5257,10 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
else
return std::string("Could not scan value (hexadecimal fomat) ") + std::string(args[1]);
myDet->setPatternWord(-1, word, detPos);
myDet->setPatternIOControl(word, detPos);
}
os << std::hex << myDet->setPatternWord(-1, -1, detPos) << std::dec;
os << std::hex << myDet->setPatternIOControl(-1, detPos) << std::dec;
} else if (cmd == "patclkctrl") {
//get word from stdin
@ -5271,10 +5271,10 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
else
return std::string("Could not scan value (hexadecimal fomat) ") + std::string(args[1]);
myDet->setPatternWord(-2, word, detPos);
myDet->setPatternClockControl(word, detPos);
}
os << std::hex << myDet->setPatternWord(-2, -1, detPos) << std::dec;
os << std::hex << myDet->setPatternClockControl(-1, detPos) << std::dec;
} else if (cmd == "patlimits") {
//get start, stop from stdin
@ -5295,13 +5295,8 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(-1, start, stop, n, detPos);
}
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(-1, start, stop, n, detPos);
auto r = myDet->getPatternLoops(-1, detPos);
os << std::hex << r[0] << " " << r[1];
// os << std::hex << start << " " << stop; // << " "<< std::dec << n ;
} else if (cmd == "patloop0") {
//get start, stop from stdin
@ -5323,11 +5318,6 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(0, start, stop, n, detPos);
}
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(0, start, stop, n, detPos);
// os << std::hex << start << " " << stop; // << " "<< std::dec << n ;
auto r = myDet->getPatternLoops(0, detPos);
os << std::hex << r[0] << " " << r[1];
@ -5351,11 +5341,6 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(1, start, stop, n, detPos);
}
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(1, start, stop, n, detPos);
// os << std::hex << start << " " << stop; // << " "<< std::dec << n ;
auto r = myDet->getPatternLoops(1, detPos);
os << std::hex << r[0] << " " << r[1];
@ -5379,11 +5364,6 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(2, start, stop, n, detPos);
}
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(2, start, stop, n, detPos);
// os << std::hex << start << " " << stop << std::dec; // << " "<< std::dec << n ;
auto r = myDet->getPatternLoops(2, detPos);
os << std::hex << r[0] << " " << r[1];
} else if (cmd == "patnloop0") {
@ -5400,11 +5380,6 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(0, start, stop, n, detPos);
}
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(0, start, stop, n, detPos);
// os << n;
auto r = myDet->getPatternLoops(0, detPos);
os << std::hex << r[2];
} else if (cmd == "patnloop1") {
@ -5422,11 +5397,6 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(1, start, stop, n, detPos);
}
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(1, start, stop, n, detPos);
// os << n;
auto r = myDet->getPatternLoops(1, detPos);
os << std::hex << r[2];
@ -5445,11 +5415,6 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(2, start, stop, n, detPos);
}
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(2, start, stop, n, detPos);
// os << n;
auto r = myDet->getPatternLoops(2, detPos);
os << std::hex << r[2];