diff --git a/slsDetectorSoftware/include/CmdProxy.h b/slsDetectorSoftware/include/CmdProxy.h index 05a39bed8..149d0cd4c 100644 --- a/slsDetectorSoftware/include/CmdProxy.h +++ b/slsDetectorSoftware/include/CmdProxy.h @@ -721,6 +721,13 @@ class CmdProxy { {"patnloop0", &CmdProxy::PatternLoopCycles}, {"patnloop1", &CmdProxy::PatternLoopCycles}, {"patnloop2", &CmdProxy::PatternLoopCycles}, + {"patwait0", &CmdProxy::PatternWaitAddress}, + {"patwait1", &CmdProxy::PatternWaitAddress}, + {"patwait2", &CmdProxy::PatternWaitAddress}, + {"patwaittime0", &CmdProxy::PatternWaitTime}, + {"patwaittime1", &CmdProxy::PatternWaitTime}, + {"patwaittime2", &CmdProxy::PatternWaitTime}, + @@ -783,6 +790,8 @@ class CmdProxy { std::string PatternWord(int action); std::string PatternLoopAddresses(int action); std::string PatternLoopCycles(int action); + std::string PatternWaitAddress(int action); + std::string PatternWaitTime(int action); diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index 88e5c460b..3b6bf43a7 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1153,4 +1153,91 @@ std::string CmdProxy::PatternLoopCycles(int action) { return os.str(); } +std::string CmdProxy::PatternWaitAddress(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + if (cmd == "patwait0") { + os << "[addr] \n\t[Ctb] Wait 0 address." << '\n'; + } else if (cmd == "patwait1") { + os << "[addr] \n\t[Ctb] Wait 1 address." << '\n'; + } else if (cmd == "patwait2") { + os << "[addr] \n\t[Ctb] Wait 2 address." << '\n'; + } else { + throw sls::RuntimeError("Unknown command, use list to list all commands"); + } + } else { + int level = -1; + if (cmd == "patwait0") { + level = 0; + } else if (cmd == "patwait1") { + level = 1; + } else if (cmd == "patwait2") { + level = 2; + } else{ + throw sls::RuntimeError("Unknown command, use list to list all commands"); + } + if (action == defs::GET_ACTION) { + if (args.size() != 0) { + WrongNumberOfParameters(0); + } + auto t = det->getPatternWaitAddr(level, {det_id}); + os << OutStringHex(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + det->setPatternWaitAddr(level, stoiHex(args[0]), {det_id}); + os << args.front() << '\n'; + } else { + throw sls::RuntimeError("Unknown action"); + } + } + return os.str(); +} + +std::string CmdProxy::PatternWaitTime(int action) { + std::ostringstream os; + os << cmd << ' '; + if (action == defs::HELP_ACTION) { + if (cmd == "patwaittime0") { + os << "[n_clk] \n\t[Ctb] Wait 0 time in clock cycles." << '\n'; + } else if (cmd == "patwaittime1") { + os << "[n_clk] \n\t[Ctb] Wait 1 time in clock cycles." << '\n'; + } else if (cmd == "patwaittime2") { + os << "[n_clk] \n\t[Ctb] Wait 2 time in clock cycles." << '\n'; + } else { + throw sls::RuntimeError("Unknown command, use list to list all commands"); + } + } else { + int level = -1; + if (cmd == "patwaittime0") { + level = 0; + } else if (cmd == "patwaittime1") { + level = 1; + } else if (cmd == "patwaittime2") { + level = 2; + } else{ + throw sls::RuntimeError("Unknown command, use list to list all commands"); + } + if (action == defs::GET_ACTION) { + if (args.size() != 0) { + WrongNumberOfParameters(0); + } + auto t = det->getPatternWaitTime(level, {det_id}); + os << OutString(t) << '\n'; + } else if (action == defs::PUT_ACTION) { + if (args.size() != 1) { + WrongNumberOfParameters(1); + } + det->setPatternWaitTime(level, std::stoul(args[0]), {det_id}); + os << args.front() << '\n'; + } else { + throw sls::RuntimeError("Unknown action"); + } + } + return os.str(); +} + + } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index 2878f31c3..40a6bed4c 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -978,48 +978,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdProcessor; ++i; - /*! \page prototype - - patwait0 [addr] sets/gets the address of the level 0 wait point. hex format. Advanced! - */ - descrToFuncMap[i].m_pFuncName = "patwait0"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; - ++i; - - /*! \page prototype - - patwaittime0 [n] sets/gets the duration of the witing of the 0 waiting point in clock cycles (int). - */ - descrToFuncMap[i].m_pFuncName = "patwaittime0"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; - ++i; - - /*! \page prototype - - patwait1 [addr] sets/gets the address of the level 1 wait point. hex format. Advanced! - */ - descrToFuncMap[i].m_pFuncName = "patwait1"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; - ++i; - - /*! \page prototype - - patwaittime1 [n] sets/gets the duration of the witing of the 1 waiting point in clock cycles (int). - */ - descrToFuncMap[i].m_pFuncName = "patwaittime1"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; - ++i; - - /*! \page prototype - - patwait2 [addr] sets/gets the address of the level 2 wait point. hex format. Advanced! - */ - descrToFuncMap[i].m_pFuncName = "patwait2"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; - ++i; - - /*! \page prototype - - patwaittime2 [n] sets/gets the duration of the waiting of the 2 waiting point in clock cycles (int). - */ - descrToFuncMap[i].m_pFuncName = "patwaittime2"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdPattern; - ++i; - /*! \page prototype - patmask [m] sets/gets the 64 bit mask (hex) applied to every pattern. Only the bits from \c patsetbit are selected to mask for the corresponding bit value from \c m mask. Returns \c (uint64_t). */ @@ -2171,22 +2129,10 @@ std::string slsDetectorCommand::helpPattern(int action) { std::ostringstream os; if (action == PUT_ACTION || action == HELP_ACTION) { - os << "patwait0 addr \t configures pattern wait 0 address " << std::endl; - os << "patwait1 addr \t configures pattern wait 1 address " << std::endl; - os << "patwait2 addr \t configures pattern wait 2 address " << std::endl; - os << "patwaittime0 nclk \t sets wait 0 waiting time in clock number " << std::endl; - os << "patwaittime1 nclk \t sets wait 1 waiting time in clock number " << std::endl; - os << "patwaittime2 nclk \t sets wait 2 waiting time in clock number " << std::endl; os << "patmask m \t sets the 64 bit mask (hex) applied to every pattern. Only the bits from patsetbit are selected to mask for the corresponding bit value from m mask" << std::endl; os << "patsetbit m \t selects bits (hex) of the 64 bits that the patmask will be applied to every pattern. Only the bits from m mask are selected to mask for the corresponding bit value from patmask." << std::endl; } if (action == GET_ACTION || action == HELP_ACTION) { - os << "patwait0 \t returns the pattern wait 0 address " << std::endl; - os << "patwait1 \t returns the pattern wait 1 address " << std::endl; - os << "patwait2 \t returns the pattern wait 2 address " << std::endl; - os << "patwaittime0 \t returns the wait 0 waiting time in clock number " << std::endl; - os << "patwaittime1 \t returns the wait 1 waiting time in clock number " << std::endl; - os << "patwaittime2 \t returns the wait 2 waiting time in clock number " << std::endl; os << "patmask \t gets the 64 bit mask (hex) applied to every pattern." << std::endl; os << "patsetbit \t gets 64 bit mask (hex) of the selected bits that the patmask will be applied to every pattern. " << std::endl; @@ -2204,95 +2150,11 @@ std::string slsDetectorCommand::cmdPattern(int narg, const char * const args[], **********/ std::string fname; - int addr, start, stop, n; - uint64_t word, t; + uint64_t word; std::ostringstream os; - if (cmd == "patwait0") { - - if (action == PUT_ACTION) { - - if (sscanf(args[1], "%x", &addr)) - ; - else - return std::string("Could not scan wait address (hex format)") + std::string(args[1]); - - myDet->setPatternWaitAddr(0, addr, detPos); - } - - os << "0x" << std::setw(4) << std::setfill('0') << std::hex << myDet->setPatternWaitAddr(0, -1, detPos) << std::dec; - - } else if (cmd == "patwait1") { - - if (action == PUT_ACTION) { - - if (sscanf(args[1], "%x", &addr)) - ; - else - return std::string("Could not scan wait address (hex format)") + std::string(args[1]); - - myDet->setPatternWaitAddr(1, addr, detPos); - } - - os << "0x" << std::setw(4) << std::setfill('0') << std::hex << myDet->setPatternWaitAddr(1, -1, detPos) << std::dec; - - } else if (cmd == "patwait2") { - - if (action == PUT_ACTION) { - - if (sscanf(args[1], "%x", &addr)) - ; - else - return std::string("Could not scan wait address (hex format)") + std::string(args[1]); - - myDet->setPatternWaitAddr(2, addr, detPos); - } - - os << "0x" << std::setw(4) << std::setfill('0') << std::hex << myDet->setPatternWaitAddr(2, -1, detPos) << std::dec; - - } else if (cmd == "patwaittime0") { - - if (action == PUT_ACTION) { - - if (sscanf(args[1], "%ld", &t)) - ; - else - return std::string("Could not scan wait time") + std::string(args[1]); - - myDet->setPatternWaitTime(0, t, detPos); - } - - os << myDet->setPatternWaitTime(0, -1, detPos); - - } else if (cmd == "patwaittime1") { - - if (action == PUT_ACTION) { - - if (sscanf(args[1], "%ld", &t)) - ; - else - return std::string("Could not scan wait time ") + std::string(args[1]); - - myDet->setPatternWaitTime(1, t, detPos); - } - - os << myDet->setPatternWaitTime(1, -1, detPos); - - } else if (cmd == "patwaittime2") { - if (action == PUT_ACTION) { - - if (sscanf(args[1], "%ld", &t)) - ; - else - return std::string("Could not scan wait time ") + std::string(args[1]); - - myDet->setPatternWaitTime(2, t, detPos); - } - - os << myDet->setPatternWaitTime(2, -1, detPos); - - } else if (cmd == "patmask") { + if (cmd == "patmask") { if (action == PUT_ACTION) { if (sscanf(args[1], "%lx", &word)) diff --git a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp index 6d8f2cf6d..dc102b6f0 100644 --- a/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp +++ b/slsDetectorSoftware/tests/test-multiSlsDetectorClient.cpp @@ -9,6 +9,51 @@ auto GET = slsDetectorDefs::GET_ACTION; auto PUT = slsDetectorDefs::PUT_ACTION; +TEST_CASE("patwaittime", "[.cmd][.ctb]") { + for (int loop = 0; loop < 3; ++loop) { + if (test::type == slsDetectorDefs::CHIPTESTBOARD) { + uint64_t val = 0; + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("patwaittime" + std::to_string(loop), GET, nullptr, oss)); + std::string s = (oss.str()).erase (0, strlen("patwaittime") + 2); + val = std::stoul(s); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("patwaittime" + std::to_string(loop) + " 8589936640", PUT, nullptr, oss)); + REQUIRE(oss.str() == "patwaittime" + std::to_string(loop) + " 8589936640\n"); + } + REQUIRE_NOTHROW(multiSlsDetectorClient("patwaittime" + std::to_string(loop) + ' ' + std::to_string(val), PUT)); + } else { + REQUIRE_THROWS(multiSlsDetectorClient("patwaittime" + std::to_string(loop), GET)); + } + } +} + + +TEST_CASE("patwait", "[.cmd][.ctb]") { + for (int loop = 0; loop < 3; ++loop) { + if (test::type == slsDetectorDefs::CHIPTESTBOARD) { + int val = 0; + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("patwait" + std::to_string(loop), GET, nullptr, oss)); + std::string s = (oss.str()).erase (0, strlen("patwait") + 2); + val = stoul(s, 0, 16); + } + { + std::ostringstream oss; + REQUIRE_NOTHROW(multiSlsDetectorClient("patwait" + std::to_string(loop) + " 0x5c", PUT, nullptr, oss)); + REQUIRE(oss.str() == "patwait" + std::to_string(loop) + " 0x5c\n"); + } + REQUIRE_NOTHROW(multiSlsDetectorClient("patwait" + std::to_string(loop) + ' ' + sls::ToStringHex(val), PUT)); + } else { + REQUIRE_THROWS(multiSlsDetectorClient("patwait" + std::to_string(loop), GET)); + } + } +} + TEST_CASE("patnloop", "[.cmd][.ctb]") { for (int loop = 0; loop < 3; ++loop) { if (test::type == slsDetectorDefs::CHIPTESTBOARD) {