diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index f1787db77..cf63098fd 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -999,6 +999,9 @@ class Detector { /** [CTB] */ void setPattern(const std::string &fname, Positions pos = {}); + /** [CTB] */ + void savePattern(const std::string &fname); + /** [CTB] */ Result getPatternIOControl(Positions pos = {}) const; diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index c19242091..0b901e111 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -1862,6 +1862,12 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ void setPattern(const std::string &fname, int detPos = -1); // + /** + * Executes and saves pattern to file (CTB/ Moench) + * @param fname pattern file to save to + */ + void savePattern(const std::string &fname); // + /** * Sets pattern IO control (CTB/ Moench) * @param word 64bit word to be written, -1 gets diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 80a1a980f..d33133da2 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -25,6 +25,10 @@ void Detector::loadParameters(const std::string &fname) { pimpl->retrieveDetectorSetup(fname, 0); } +void Detector::savePattern(const std::string &fname) { + pimpl->savePattern(fname); +} + Result Detector::getHostname(Positions pos) const { return pimpl->Parallel(&slsDetector::getHostname, pos); } diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 8454bfaf7..57ab00c81 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -3282,6 +3282,45 @@ void multiSlsDetector::setPattern(const std::string &fname, int detPos) { parallelCall(&slsDetector::setPattern, fname); } +void multiSlsDetector::savePattern(const std::string &fname) { + std::ofstream outfile; + outfile.open(fname.c_str(), std::ios_base::out); + if (!outfile.is_open()) { + throw RuntimeError("Could not create file to save pattern"); + } + // get pattern limits + auto r = getPatternLoops(-1); + // pattern words + for (int i = r[0]; i <= r[1]; ++i) { + std::ostringstream os; + os << "patword 0x" << std::hex << i; + std::string cmd = os.str(); + multiSlsDetectorClient(cmd, GET_ACTION, this, outfile); + } + // rest of pattern file + const std::vector commands{ + "patioctrl", + "patclkctrl", + "patlimits", + "patloop0", + "patnloop0", + "patloop1", + "patnloop1", + "patloop2", + "patnloop2", + "patwait0", + "patwaittime0", + "patwait1", + "patwaittime1", + "patwait2", + "patwaittime2", + "patmask", + "patsetbit", + }; + for (const auto &cmd : commands) + multiSlsDetectorClient(cmd, GET_ACTION, this, outfile); +} + uint64_t multiSlsDetector::setPatternIOControl(uint64_t word, int detPos) { // single if (detPos >= 0) { diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index 5a980398c..4c42f8b51 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -1846,6 +1846,13 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; ++i; + /*! \page prototype + - savepattern fn save pattern to file (ascii). This also executes the pattern. + */ + descrToFuncMap[i].m_pFuncName = "savepattern"; + descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; + ++i; + /*! \page prototype - patword addr [word] sets/gets 64 bit word at address addr of pattern memory. Both address and word in hex format. Advanced! */ @@ -4834,6 +4841,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], os << "successful"; } else if (action == GET_ACTION) os << "Cannot get"; + } else if (cmd == "savepattern") { + if (narg < 2) { + return helpPattern(action); + } + fname = std::string(args[1]); + myDet->savePattern(args[1]); + os << "Pattern executed and saved to " << fname; } else if (cmd == "patword") { if (action == PUT_ACTION) { @@ -4852,10 +4866,14 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], else return std::string("Could not scan value (hexadecimal fomat) ") + std::string(args[2]); - os << std::hex << myDet->setPatternWord(addr, word, detPos) << std::dec; - } else if (action == GET_ACTION) - os << "Cannot get"; - + os << "0x" << std::setw(4) << std::setfill('0') << std::hex << addr << " 0x" << std::setw(16) << myDet->setPatternWord(addr, word, detPos) << std::dec; + } else if (action == GET_ACTION) { + if (narg < 2) + return std::string("wrong usage: should specify address (hexadecimal fomat) "); + if (!sscanf(args[1], "%x", &addr)) + return std::string("Could not scan address (hexadecimal fomat) ") + std::string(args[1]); + os << "0x" << std::setw(4) << std::setfill('0') << std::hex << addr << " 0x" << std::setw(16) << myDet->setPatternWord(addr, -1, detPos) << std::dec; + } } else if (cmd == "patioctrl") { //get word from stdin @@ -4869,7 +4887,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], myDet->setPatternIOControl(word, detPos); } - os << std::hex << myDet->setPatternIOControl(-1, detPos) << std::dec; + os << "0x" << std::setw(16) << std::setfill('0') << std::hex << myDet->setPatternIOControl(-1, detPos) << std::dec; } else if (cmd == "patclkctrl") { //get word from stdin @@ -4883,7 +4901,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], myDet->setPatternClockControl(word, detPos); } - os << std::hex << myDet->setPatternClockControl(-1, detPos) << std::dec; + os << "0x" << std::setw(16) << std::setfill('0') << std::hex << myDet->setPatternClockControl(-1, detPos) << std::dec; } else if (cmd == "patlimits") { //get start, stop from stdin @@ -4905,7 +4923,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], } auto r = myDet->getPatternLoops(-1, detPos); - os << std::hex << r[0] << " " << r[1]; + os << "0x" << std::setw(4) << std::setfill('0') << std::hex << r[0] << " 0x" << std::setw(4) << std::setfill('0') << r[1]; } else if (cmd == "patloop0") { //get start, stop from stdin @@ -4928,7 +4946,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], } auto r = myDet->getPatternLoops(0, detPos); - os << std::hex << r[0] << " " << r[1]; + os << "0x" << std::setw(4) << std::setfill('0') << std::hex << r[0] << " 0x" << std::setw(4) << std::setfill('0') << r[1]; } else if (cmd == "patloop1") { @@ -4951,7 +4969,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], } auto r = myDet->getPatternLoops(1, detPos); - os << std::hex << r[0] << " " << r[1]; + os << "0x" << std::setw(4) << std::setfill('0') << std::hex << r[0] << " 0x" << std::setw(4) << std::setfill('0') << r[1]; } else if (cmd == "patloop2") { @@ -4974,7 +4992,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], } auto r = myDet->getPatternLoops(2, detPos); - os << std::hex << r[0] << " " << r[1]; + os << "0x" << std::setw(4) << std::setfill('0') << std::hex << r[0] << " 0x" << std::setw(4) << std::setfill('0') << r[1]; } else if (cmd == "patnloop0") { start = -1; stop = -1; @@ -5039,7 +5057,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], myDet->setPatternWaitAddr(0, addr, detPos); } - os << std::hex << myDet->setPatternWaitAddr(0, -1, detPos) << std::dec ; + os << "0x" << std::setw(4) << std::setfill('0') << std::hex << myDet->setPatternWaitAddr(0, -1, detPos) << std::dec; } else if (cmd == "patwait1") { @@ -5053,7 +5071,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], myDet->setPatternWaitAddr(1, addr, detPos); } - os << std::hex << myDet->setPatternWaitAddr(1, -1, detPos) << std::dec ; + os << "0x" << std::setw(4) << std::setfill('0') << std::hex << myDet->setPatternWaitAddr(1, -1, detPos) << std::dec; } else if (cmd == "patwait2") { @@ -5067,7 +5085,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], myDet->setPatternWaitAddr(2, addr, detPos); } - os << std::hex << myDet->setPatternWaitAddr(2, -1, detPos) << std::dec ; + os << "0x" << std::setw(4) << std::setfill('0') << std::hex << myDet->setPatternWaitAddr(2, -1, detPos) << std::dec; } else if (cmd == "patwaittime0") { @@ -5121,7 +5139,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], myDet->setPatternMask(word, detPos); } - os << "0x" << std::hex << myDet->getPatternMask(detPos) << std::dec; + os << "0x" << std::setw(16) << std::setfill('0') << std::hex << myDet->getPatternMask(detPos) << std::dec; } else if (cmd == "patsetbit") { if (action == PUT_ACTION) { @@ -5134,7 +5152,7 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], myDet->setPatternBitMask(word, detPos); } - os << "0x" << std::hex << myDet->getPatternBitMask(detPos) << std::dec; + os << "0x" << std::setw(16) << std::setfill('0') << std::hex << myDet->getPatternBitMask(detPos) << std::dec; } else if (cmd == "adcenable") {