Merge branch 'developer' into gui

This commit is contained in:
maliakal_d 2019-06-25 10:51:17 +02:00
commit bd3e439d87
11 changed files with 117 additions and 52 deletions

View File

@ -313,14 +313,14 @@ TEST_CASE(
CHECK(m.getRateCorrection() == ratecorr); CHECK(m.getRateCorrection() == ratecorr);
// ratecorr fail with dr 4 or 8 // ratecorr fail with dr 4 or 8
CHECK_THROWS_AS(m.setDynamicRange(8), sls::NonCriticalError); CHECK_THROWS_AS(m.setDynamicRange(8), sls::RuntimeError);
CHECK(m.getRateCorrection() == 0); CHECK(m.getRateCorrection() == 0);
m.setDynamicRange(16); m.setDynamicRange(16);
m.setDynamicRange(16); m.setDynamicRange(16);
m.setRateCorrection(ratecorr); m.setRateCorrection(ratecorr);
m.setDynamicRange(16); m.setDynamicRange(16);
m.setRateCorrection(ratecorr); m.setRateCorrection(ratecorr);
CHECK_THROWS_AS(m.setDynamicRange(4), sls::NonCriticalError); CHECK_THROWS_AS(m.setDynamicRange(4), sls::RuntimeError);
CHECK(m.getRateCorrection() == 0); CHECK(m.getRateCorrection() == 0);
} }
@ -360,11 +360,11 @@ TEST_CASE("Chiptestboard Loading Patterns", "[.ctbintegration]") {
m.setPatternWord(addr, word); m.setPatternWord(addr, word);
CHECK(m.setPatternWord(addr, -1) == word); CHECK(m.setPatternWord(addr, -1) == word);
addr = MAX_ADDR; addr = MAX_ADDR;
CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::NonCriticalError); CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::RuntimeError);
CHECK_THROWS_WITH(m.setPatternWord(addr, word), CHECK_THROWS_WITH(m.setPatternWord(addr, word),
Catch::Matchers::Contains("be between 0 and")); Catch::Matchers::Contains("be between 0 and"));
addr = -1; addr = -1;
CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::NonCriticalError); CHECK_THROWS_AS(m.setPatternWord(addr, word), sls::RuntimeError);
CHECK_THROWS_WITH(m.setPatternWord(addr, word), CHECK_THROWS_WITH(m.setPatternWord(addr, word),
Catch::Matchers::Contains("be between 0 and")); Catch::Matchers::Contains("be between 0 and"));

View File

@ -1021,6 +1021,11 @@ class Detector:
self._api.setNetworkParameter('rx_zmqip', ip, -1) self._api.setNetworkParameter('rx_zmqip', ip, -1)
@property
def syncclk(self):
return self._api.getSyncClkSpeed(-1)
@property @property
def detectormac(self): def detectormac(self):
""" """

View File

@ -214,6 +214,10 @@ class Detector {
det.setSpeed(slsDetectorDefs::CLOCK_DIVIDER, speed); det.setSpeed(slsDetectorDefs::CLOCK_DIVIDER, speed);
} }
int getSyncClkSpeed(int det_id=-1){
return det.setSpeed(slsDetectorDefs::SYNC_CLOCK, -1, 0, det_id);
}
void setDbitPipeline(const int value) { void setDbitPipeline(const int value) {
det.setSpeed(slsDetectorDefs::DBIT_PIPELINE, value); det.setSpeed(slsDetectorDefs::DBIT_PIPELINE, value);
} }

View File

@ -93,6 +93,7 @@ PYBIND11_MODULE(_sls_detector, m) {
.def("checkOnline", &Detector::checkOnline) .def("checkOnline", &Detector::checkOnline)
.def("setReadoutClockSpeed", &Detector::setReadoutClockSpeed) .def("setReadoutClockSpeed", &Detector::setReadoutClockSpeed)
.def("getReadoutClockSpeed", &Detector::getReadoutClockSpeed) .def("getReadoutClockSpeed", &Detector::getReadoutClockSpeed)
.def("getSyncClkSpeed", &Detector::getSyncClkSpeed)
.def("getHostname", &Detector::getHostname) .def("getHostname", &Detector::getHostname)
.def("setHostname", &Detector::setHostname) .def("setHostname", &Detector::setHostname)

View File

@ -5,10 +5,10 @@
#include "CmdLineParser.h" #include "CmdLineParser.h"
#include "CmdProxy.h" #include "CmdProxy.h"
#include "container_utils.h" #include "container_utils.h"
#include "string_utils.h"
#include "multiSlsDetector.h" #include "multiSlsDetector.h"
#include "slsDetectorCommand.h" #include "slsDetectorCommand.h"
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
#include "string_utils.h"
#include <cstdlib> #include <cstdlib>
#include <memory> #include <memory>
@ -27,14 +27,17 @@ class multiSlsDetectorClient {
std::ostream &output = std::cout) std::ostream &output = std::cout)
: action_(action), detPtr(myDetector), os(output) { : action_(action), detPtr(myDetector), os(output) {
parser.Parse(argc, argv); parser.Parse(argc, argv);
if (parser.isHelp())
action_ = slsDetectorDefs::HELP_ACTION;
runCommand(); runCommand();
} }
multiSlsDetectorClient(const std::string &args, int action, multiSlsDetectorClient(const std::string &args, int action,
multiSlsDetector *myDetector = nullptr, multiSlsDetector *myDetector = nullptr,
std::ostream &output = std::cout) std::ostream &output = std::cout)
: action_(action), detPtr(myDetector), os(output) { : action_(action), detPtr(myDetector), os(output) {
parser.Parse(args); parser.Parse(args);
if (parser.isHelp())
action_ = slsDetectorDefs::HELP_ACTION;
runCommand(); runCommand();
} }
@ -108,7 +111,7 @@ class multiSlsDetectorClient {
if (action_ != slsDetectorDefs::READOUT_ACTION) { if (action_ != slsDetectorDefs::READOUT_ACTION) {
sls::CmdProxy<multiSlsDetector> proxy(detPtr); sls::CmdProxy<multiSlsDetector> proxy(detPtr);
auto cmd = proxy.Call(parser.command(), parser.arguments(), auto cmd = proxy.Call(parser.command(), parser.arguments(),
parser.detector_id()); parser.detector_id(), action_);
if (cmd.empty()) { if (cmd.empty()) {
return; return;
} else { } else {

View File

@ -3188,7 +3188,7 @@ void slsDetector::updateRateCorrection() {
break; break;
default: default:
setRateCorrection(0); setRateCorrection(0);
throw sls::NonCriticalError( throw sls::RuntimeError(
"Rate correction Deactivated, must be in 32 or 16 bit mode"); "Rate correction Deactivated, must be in 32 or 16 bit mode");
} }
} }

View File

@ -14,6 +14,7 @@ class CmdLineParser {
int detector_id() const { return detector_id_; }; int detector_id() const { return detector_id_; };
int n_arguments() const { return arguments_.size(); } int n_arguments() const { return arguments_.size(); }
const std::string &command() const { return command_; } const std::string &command() const { return command_; }
bool isHelp() const{return help_;}
void setCommand(std::string cmd){command_ = cmd;} void setCommand(std::string cmd){command_ = cmd;}
const std::string &executable() const { return executable_; } const std::string &executable() const { return executable_; }
const std::vector<std::string> &arguments() const { return arguments_; }; const std::vector<std::string> &arguments() const { return arguments_; };
@ -23,6 +24,7 @@ class CmdLineParser {
void DecodeIdAndPosition(const char *c); void DecodeIdAndPosition(const char *c);
int multi_id_ = 0; int multi_id_ = 0;
int detector_id_ = -1; int detector_id_ = -1;
bool help_{false};
std::string command_; std::string command_;
std::string executable_; std::string executable_;
std::vector<std::string> arguments_; std::vector<std::string> arguments_;

View File

@ -10,6 +10,7 @@
#include "logger.h" #include "logger.h"
#include "slsDetectorCommand.h" #include "slsDetectorCommand.h"
#include "sls_detector_exceptions.h" #include "sls_detector_exceptions.h"
#include "sls_detector_defs.h"
#include "string_utils.h" #include "string_utils.h"
namespace sls { namespace sls {
@ -20,7 +21,8 @@ template <typename T> class CmdProxy {
std::string Call(const std::string &command, std::string Call(const std::string &command,
const std::vector<std::string> &arguments, const std::vector<std::string> &arguments,
int detector_id) { int detector_id,
int action=-1) {
cmd = command; cmd = command;
args = arguments; args = arguments;
det_id = detector_id; det_id = detector_id;
@ -29,7 +31,7 @@ template <typename T> class CmdProxy {
auto it = functions.find(cmd); auto it = functions.find(cmd);
if (it != functions.end()) { if (it != functions.end()) {
std::cout << ((*this).*(it->second))(); std::cout << ((*this).*(it->second))(action);
return {}; return {};
} else { } else {
return cmd; return cmd;
@ -57,7 +59,7 @@ template <typename T> class CmdProxy {
std::vector<std::string> args; std::vector<std::string> args;
int det_id{-1}; int det_id{-1};
using FunctionMap = std::map<std::string, std::string (CmdProxy::*)()>; using FunctionMap = std::map<std::string, std::string (CmdProxy::*)(int)>;
using StringMap = std::map<std::string, std::string>; using StringMap = std::map<std::string, std::string>;
// Initialize maps for translating name and function // Initialize maps for translating name and function
@ -91,7 +93,10 @@ template <typename T> class CmdProxy {
// Mapped functions // Mapped functions
std::string ListCommands() { std::string ListCommands(int action) {
if (action==slsDetectorDefs::HELP_ACTION)
return "list - lists all available commands, list deprecated - list deprecated commands\n";
if (args.size() == 0) { if (args.size() == 0) {
auto commands = slsDetectorCommand(nullptr).getAllCommands(); auto commands = slsDetectorCommand(nullptr).getAllCommands();
for (const auto &it : functions) for (const auto &it : functions)

View File

@ -27,49 +27,39 @@ public:
} }
}; };
struct CriticalError : public RuntimeError { struct SharedMemoryError : public RuntimeError {
public: public:
CriticalError(std::string msg):RuntimeError(msg) {} SharedMemoryError(std::string msg):RuntimeError(msg) {}
}; };
struct SharedMemoryError : public CriticalError { struct SocketError : public RuntimeError {
public: public:
SharedMemoryError(std::string msg):CriticalError(msg) {} SocketError(std::string msg):RuntimeError(msg) {}
}; };
struct SocketError : public CriticalError { struct ZmqSocketError : public RuntimeError {
public: public:
SocketError(std::string msg):CriticalError(msg) {} ZmqSocketError(std::string msg):RuntimeError(msg) {}
}; };
struct ZmqSocketError : public CriticalError { struct NotImplementedError : public RuntimeError {
public: public:
ZmqSocketError(std::string msg):CriticalError(msg) {} NotImplementedError(std::string msg):RuntimeError(msg) {}
}; };
struct NonCriticalError : public RuntimeError { struct DetectorError : public RuntimeError {
public: public:
NonCriticalError(std::string msg):RuntimeError(msg) {} DetectorError(std::string msg):RuntimeError(msg) {}
}; };
struct NotImplementedError : public NonCriticalError { struct ReceiverError : public RuntimeError {
public: public:
NotImplementedError(std::string msg):NonCriticalError(msg) {} ReceiverError(std::string msg):RuntimeError(msg) {}
}; };
struct DetectorError : public NonCriticalError { struct GuiError : public RuntimeError {
public: public:
DetectorError(std::string msg):NonCriticalError(msg) {} GuiError(std::string msg):RuntimeError(msg) {}
};
struct ReceiverError : public NonCriticalError {
public:
ReceiverError(std::string msg):NonCriticalError(msg) {}
};
struct GuiError : public NonCriticalError {
public:
GuiError(std::string msg):NonCriticalError(msg) {}
}; };
} }

View File

@ -1,5 +1,6 @@
#include "CmdLineParser.h" #include "CmdLineParser.h"
#include "sls_detector_defs.h"
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
@ -23,19 +24,34 @@ void CmdLineParser::Print() {
void CmdLineParser::Parse(int argc, const char *const argv[]) { void CmdLineParser::Parse(int argc, const char *const argv[]) {
executable_ = argv[0]; // first arg is calling binary executable_ = argv[0]; // first arg is calling binary
if (argc > 1) { if (argc > 1) {
DecodeIdAndPosition(argv[1]); std::string s = argv[1];
for (int i = 2; i < argc; ++i) { for (int i = 2; i < argc; ++i) {
arguments_.emplace_back(argv[i]); s += " ";
s += argv[i];
} }
Parse(s);
} }
} }
void CmdLineParser::Parse(const std::string &s) { void CmdLineParser::Parse(const std::string &s) {
std::istringstream iss(s); std::istringstream iss(s);
auto it = std::istream_iterator<std::string>(iss); auto it = std::istream_iterator<std::string>(iss);
command_ = *it++;
arguments_ = arguments_ =
std::vector<std::string>(it, std::istream_iterator<std::string>()); std::vector<std::string>(it, std::istream_iterator<std::string>());
auto old_size = arguments_.size();
arguments_.erase(std::remove_if(begin(arguments_), end(arguments_),
[](const std::string &item) {
if (item == "-h" || item == "--help")
return true;
return false;
}),
end(arguments_));
if (old_size - arguments_.size() > 0)
help_ = true;
if(!arguments_.empty()){
command_ = arguments_[0];
arguments_.erase(begin(arguments_));
}
DecodeIdAndPosition(command_.c_str()); DecodeIdAndPosition(command_.c_str());
} }
@ -47,7 +63,7 @@ void CmdLineParser::DecodeIdAndPosition(const char *c) {
if (contains_id && contains_pos) { if (contains_id && contains_pos) {
int r = sscanf(c, "%d-%d:%s", &multi_id_, &detector_id_, tmp); int r = sscanf(c, "%d-%d:%s", &multi_id_, &detector_id_, tmp);
if (r != 3) { if (r != 3) {
throw(std::invalid_argument( throw(sls::RuntimeError(
"Cannot decode client or detector id from: \"" + "Cannot decode client or detector id from: \"" +
std::string(c) + "\"\n")); std::string(c) + "\"\n"));
} }
@ -55,14 +71,14 @@ void CmdLineParser::DecodeIdAndPosition(const char *c) {
} else if (contains_id && !contains_pos) { } else if (contains_id && !contains_pos) {
int r = sscanf(c, "%d-%s", &multi_id_, tmp); int r = sscanf(c, "%d-%s", &multi_id_, tmp);
if (r != 2) { if (r != 2) {
throw(std::invalid_argument("Cannot decode client id from: \"" + throw(sls::RuntimeError("Cannot decode client id from: \"" +
std::string(c) + "\"\n")); std::string(c) + "\"\n"));
} }
command_ = tmp; command_ = tmp;
} else if (!contains_id && contains_pos) { } else if (!contains_id && contains_pos) {
int r = sscanf(c, "%d:%s", &detector_id_, tmp); int r = sscanf(c, "%d:%s", &detector_id_, tmp);
if (r != 2) { if (r != 2) {
throw(std::invalid_argument("Cannot decode detector id from: \"" + throw(sls::RuntimeError("Cannot decode detector id from: \"" +
std::string(c) + "\"\n")); std::string(c) + "\"\n"));
} }
command_ = tmp; command_ = tmp;

View File

@ -116,6 +116,45 @@ SCENARIO("Parsing a string with the command line parser", "[support]") {
} }
} }
SCENARIO("Parsing strings with -h or --help", "[support]") {
GIVEN("A parser") {
CmdLineParser p;
WHEN("Parsing a string with a command and help ") {
std::string s = "-h list";
THEN("the command is correct and isHelp is set") {
p.Parse(s);
REQUIRE(p.detector_id() == -1);
REQUIRE(p.multi_id() == 0);
REQUIRE(p.command() == "list");
REQUIRE(p.isHelp());
REQUIRE(p.arguments().empty());
REQUIRE(p.argv().size() == 1);
}
}
WHEN("Parsing a string with -h at a different position"){
std::string s = "list -h something";
THEN("its also done right"){
p.Parse(s);
REQUIRE(p.isHelp());
REQUIRE(p.command() == "list");
REQUIRE(p.arguments().size() == 1);
REQUIRE(p.arguments().front() == "something");
}
}
WHEN("Parsing a string with -help at a different position"){
std::string s = "list --help something";
THEN("its also done right"){
p.Parse(s);
REQUIRE(p.isHelp());
REQUIRE(p.command() == "list");
REQUIRE(p.arguments().size() == 1);
REQUIRE(p.arguments().front() == "something");
}
}
}
}
TEST_CASE("Parse with no arguments results in no command and default id", TEST_CASE("Parse with no arguments results in no command and default id",
"[support]") { "[support]") {
// build up argc and argv // build up argc and argv