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

TestFacility: fix initial for bidirectional variables

The default value was properly propagated but not visible to the test until a value was sent through the return channel.
parent 378a0c18
No related branches found
Tags 01.10.00
No related merge requests found
...@@ -41,7 +41,10 @@ namespace ChimeraTK { ...@@ -41,7 +41,10 @@ namespace ChimeraTK {
// send default values for all control system variables // send default values for all control system variables
for(auto& pv : pvManager->getAllProcessVariables()) { for(auto& pv : pvManager->getAllProcessVariables()) {
callForType(pv->getValueType(), [&pv, this](auto arg) { callForType(pv->getValueType(), [&pv, this](auto arg) {
// Applies only to writeable variables. @todo FIXME It should also NOT apply for application-to-controlsystem
// variables with a return channel, despite being writeable here!
if(!pv->isWriteable()) return; if(!pv->isWriteable()) return;
// Safety check against incorrect usage
if(pv->getVersionNumber() != VersionNumber(nullptr)) { if(pv->getVersionNumber() != VersionNumber(nullptr)) {
throw ChimeraTK::logic_error("The variable '" + pv->getName() + throw ChimeraTK::logic_error("The variable '" + pv->getName() +
"' has been written before TestFacility::runApplication() was called. Instead use " "' has been written before TestFacility::runApplication() was called. Instead use "
...@@ -50,9 +53,25 @@ namespace ChimeraTK { ...@@ -50,9 +53,25 @@ namespace ChimeraTK {
typedef decltype(arg) T; typedef decltype(arg) T;
auto pv_casted = boost::dynamic_pointer_cast<NDRegisterAccessor<T>>(pv); auto pv_casted = boost::dynamic_pointer_cast<NDRegisterAccessor<T>>(pv);
auto table = boost::fusion::at_key<T>(defaults.table); auto table = boost::fusion::at_key<T>(defaults.table);
// If default value has been stored, copy the default value to the PV.
if(table.find(pv->getName()) != table.end()) { if(table.find(pv->getName()) != table.end()) {
/// Since pv_casted is the undecorated PV (lacking the TestableModeAccessorDecorator), we need to copy the
/// value also to the decorator. We still have to write through the undecorated PV, otherwise the tests are
/// stalled. @todo It is not understood why this happens!
/// Decorated accessors are stored in different maps for scalars are arrays...
if(pv_casted->getNumberOfSamples() == 1) { // scalar
auto accessor = this->getScalar<T>(pv->getName());
accessor = table.at(pv->getName())[0];
}
else { // array
auto accessor = this->getArray<T>(pv->getName());
accessor = table.at(pv->getName());
}
// copy value also to undecorated PV
pv_casted->accessChannel(0) = table.at(pv->getName()); pv_casted->accessChannel(0) = table.at(pv->getName());
} }
// Write the initial value. This must be done even if no default value has been stored, since it is expected
// by the application.
pv_casted->write(); pv_casted->write();
}); });
} }
......
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