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

A DeviceModule now returns the same VariableNetworkNode when asked for the...

A DeviceModule now returns the same VariableNetworkNode when asked for the same register multiple times. This leads to a new restriction that registers can now only be either read or written. This restriction can be mitigated by using the logical name mapper to create an alias of the register. This has been implemented for the tests and the demo application.
parent 71fafbdc
No related branches found
No related tags found
No related merge requests found
......@@ -102,10 +102,10 @@ struct MyApp : public ctk::Application {
cs("setpoint") >> automation.operatorSetpoint;
automation.loopSetpoint >> controlLoop.setpoint >> cs("setpoint_automation");
controlLoop.actuator >> dev("Variable") >> cs("actuatorLoop");
controlLoop.actuator >> dev("actuator") >> cs("actuatorLoop");
dev("Variable") [ controlLoop.actuator ] >> simulator.actuator >> cs("actuatorSimulator");
dev("Variable", typeid(double), 1) [ controlLoop.actuator ] >> cs("actuatorSimulator_direct");
dev("readBack") [ controlLoop.actuator ] >> simulator.actuator >> cs("actuatorSimulator");
dev("anotherReadBack", typeid(double), 1) [ controlLoop.actuator ] >> cs("actuatorSimulator_direct");
simulator.readback >> controlLoop.readback >> cs("readback") >> cs("readback_another_time");
......
<logicalNameMap>
<module name="MyModule">
<constant name="Constant">
<type>integer</type>
<value>42</value>
</constant>
<constant name="Constant2">
<type>integer</type>
<value>666</value>
</constant>
<variable name="Variable">
<type>integer</type>
<value>2</value>
</variable>
</module>
<module name="MyModule">
<variable name="actuator">
<value>2</value>
<type>integer</type>
</variable>
<redirectedRegister name="readBack">
<targetDevice>this</targetDevice>
<targetRegister>MyModule/actuator</targetRegister>
</redirectedRegister>
<redirectedRegister name="anotherReadBack">
<targetDevice>this</targetDevice>
<targetRegister>MyModule/actuator</targetRegister>
</redirectedRegister>
</module>
</logicalNameMap>
......@@ -53,6 +53,10 @@ namespace ChimeraTK {
// List of sub modules accessed through the operator[]. This is mutable since it is little more than a cache and
// thus does not change the logical state of this module
mutable std::list<DeviceModule> subModules;
// List of variables accessed through the operator(). This is mutable since it is little more than a cache and
// thus does not change the logical state of this module
mutable std::map<std::string, VariableNetworkNode> variables;
};
......
......@@ -22,7 +22,10 @@ namespace ChimeraTK {
VariableNetworkNode DeviceModule::operator()(const std::string& registerName, UpdateMode mode,
const std::type_info &valueType, size_t nElements) const {
return{deviceAliasOrURI, registerNamePrefix/registerName, mode, VariableDirection::invalid, valueType, nElements};
if(variables.count(registerName) == 0) {
variables[registerName] = {deviceAliasOrURI, registerNamePrefix/registerName, mode, VariableDirection::invalid, valueType, nElements};
}
return variables[registerName];
}
/*********************************************************************************************************************/
......
......@@ -71,11 +71,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testFeedToDevice, T, test_types ) {
TestApplication<T> app;
app.testModule.feedingToDevice >> app.devMymodule("Variable");
app.testModule.feedingToDevice >> app.devMymodule("actuator");
app.initialise();
boost::shared_ptr<mtca4u::DeviceBackend> backend = app.deviceMap["Dummy0"];
auto regacc = backend->getRegisterAccessor<int>("/MyModule/Variable",1,0,{});
auto regacc = backend->getRegisterAccessor<int>("/MyModule/actuator",1,0,{});
regacc->accessData(0) = 0;
app.testModule.feedingToDevice = 42;
......@@ -101,11 +101,11 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testConsumeFromDevice, T, test_types ) {
TestApplication<T> app;
app.dev("/MyModule/Variable") >> app.testModule.consumingPoll;
app.dev("/MyModule/actuator") >> app.testModule.consumingPoll;
app.initialise();
boost::shared_ptr<mtca4u::DeviceBackend> backend = app.deviceMap["Dummy0"];
auto regacc = backend->getRegisterAccessor<int>("/MyModule/Variable",1,0,{});
auto regacc = backend->getRegisterAccessor<int>("/MyModule/actuator",1,0,{});
// single theaded test only, since read() does not block in this case
app.testModule.consumingPoll = 0;
......
......@@ -127,9 +127,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testTriggerDevToApp, T, test_types ) {
TestApplication<T> app;
app.testModule.feedingToDevice >> app.dev("/MyModule/Variable");
app.testModule.feedingToDevice >> app.dev("/MyModule/actuator");
app.dev("/MyModule/Variable") [ app.testModule.theTrigger ] >> app.testModule.consumingPush;
app.dev("/MyModule/readBack") [ app.testModule.theTrigger ] >> app.testModule.consumingPush;
app.initialise();
app.run();
......@@ -178,9 +178,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testTriggerDevToCS, T, test_types ) {
auto pvManagers = ctk::createPVManager();
app.setPVManager(pvManagers.second);
app.testModule.feedingToDevice >> app.dev("/MyModule/Variable");
app.testModule.feedingToDevice >> app.dev("/MyModule/actuator");
app.dev("/MyModule/Variable", typeid(T), 1) [ app.testModule.theTrigger ] >> app.cs("myCSVar");
app.dev("/MyModule/readBack", typeid(T), 1) [ app.testModule.theTrigger ] >> app.cs("myCSVar");
app.initialise();
app.run();
......@@ -224,9 +224,9 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testTriggerByCS, T, test_types ) {
auto pvManagers = ctk::createPVManager();
app.setPVManager(pvManagers.second);
app.testModule.feedingToDevice >> app.dev("/MyModule/Variable");
app.testModule.feedingToDevice >> app.dev("/MyModule/actuator");
app.dev("/MyModule/Variable", typeid(T), 1) [ app.cs("theTrigger", typeid(T), 1) ] >> app.cs("myCSVar");
app.dev("/MyModule/readBack", typeid(T), 1) [ app.cs("theTrigger", typeid(T), 1) ] >> app.cs("myCSVar");
app.initialise();
app.run();
......
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