Skip to content
Snippets Groups Projects
Commit 4057cb57 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

allow setting startup values for control system variables through the TestFacility

parent 71dfcdac
No related branches found
No related tags found
No related merge requests found
......@@ -35,12 +35,26 @@ namespace ChimeraTK {
Application::getInstance().initialise();
}
/** Start the application. This simply calls Application::run(). Since the
* application is in testable mode, it
* will be ??? TODO define precisely what happens on start up */
/** Start the application in testable mode. */
void runApplication() const {
// send default values for all control system variables
for(auto& pv : pvManager->getAllProcessVariables()) {
callForType(pv->getValueType(), [&pv, this](auto arg) {
if(!pv->isWriteable()) return;
typedef decltype(arg) T;
auto pv_casted = boost::dynamic_pointer_cast<NDRegisterAccessor<T>>(pv);
auto table = boost::fusion::at_key<T>(defaults.table);
if(table.find(pv->getName()) != table.end()) {
pv_casted->accessChannel(0) = table.at(pv->getName());
}
pv_casted->write();
});
}
// start the application
Application::getInstance().run();
// set thread name
Application::registerThread("TestThread");
// wait until all devices are opened
Application::testableModeUnlock("waitDevicesToOpen");
while(true) {
boost::this_thread::yield();
......@@ -166,6 +180,26 @@ namespace ChimeraTK {
return acc;
}
/** Set default value for scalar process variable. */
template<typename T>
void setScalarDefault(const ChimeraTK::RegisterPath& name, const T& value) {
std::vector<T> vv;
vv.push_back(value);
setArrayDefaults(name, vv);
}
/** Set default value for array process variable. */
template<typename T>
void setArrayDefault(const ChimeraTK::RegisterPath& name, const std::vector<T>& value) {
// check if PV exists
auto pv = pvManager->getProcessArray<T>(name);
if(pv == nullptr) {
throw ChimeraTK::logic_error("Process variable '" + name + "' does not exist.");
}
// store default value in map
boost::fusion::at_key<T>(defaults.table)[name] = value;
}
protected:
boost::shared_ptr<ControlSystemPVManager> pvManager;
......@@ -182,6 +216,11 @@ namespace ChimeraTK {
template<typename UserType>
using ArrayMap = std::map<std::string, ChimeraTK::OneDRegisterAccessor<UserType>>;
mutable ChimeraTK::TemplateUserTypeMap<ArrayMap> arrayMap;
// default values for process variables
template<typename UserType>
using Defaults = std::map<std::string, std::vector<UserType>>;
ChimeraTK::TemplateUserTypeMap<Defaults> defaults;
};
} /* namespace ChimeraTK */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment