2#include "../../../../tests/catch2/catch.hpp"
6#include "../../../../libMagAOX/libMagAOX.hpp"
8#define XWC_XIGNODE_TEST
9#include "../fsmNode.hpp"
13 std::ofstream fout(
"/tmp/xigNode_test.xml");
14 fout <<
"<mxfile host=\"test\">\n";
15 fout <<
" <diagram id=\"test\" name=\"test\">\n";
16 fout <<
" <mxGraphModel>\n";
18 fout <<
" <mxCell id=\"0\"/>\n";
19 fout <<
" <mxCell id=\"1\" parent=\"0\"/>\n";
20 fout <<
" <mxCell id=\"node:ttmpupil\">\n";
21 fout <<
"</mxCell>\n";
23 fout <<
" </mxGraphModel>\n";
24 fout <<
" </diagram>\n";
25 fout <<
"</mxfile>\n";
29SCENARIO(
"Creating and configuring an fsmNode",
"[instGraph::fsmNode]" )
31 GIVEN(
"a valid XML file, a valid config file")
33 WHEN(
"node is in file, default config")
35 ingr::instGraphXML parentGraph;
37 mx::app::writeConfigFile(
"/tmp/fsmNode_test.conf", {
"ttmpupil"},
40 mx::app::appConfigurator config;
41 config.readConfig(
"/tmp/fsmNode_test.conf");
45 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
54 tsn =
new fsmNode(
"ttmpupil", &parentGraph);
57 catch(
const std::exception & e)
59 std::cerr << e.what() <<
"\n";
62 REQUIRE(pass ==
true);
63 REQUIRE(tsn !=
nullptr);
65 REQUIRE( tsn->
name() ==
"ttmpupil");
66 REQUIRE( tsn->
node()->name() ==
"ttmpupil");
74 catch(
const std::exception & e)
76 std::cerr << e.what() <<
"\n";
79 REQUIRE(pass ==
true);
82 REQUIRE(tsn->
device() ==
"ttmpupil");
83 REQUIRE(tsn->
fsmKey() ==
"ttmpupil.fsm");
87 WHEN(
"node is in file, setting action to threshOff for two states")
89 ingr::instGraphXML parentGraph;
91 mx::app::writeConfigFile(
"/tmp/fsmNode_test.conf", {
"ttmpupil",
"ttmpupil",
"ttmpupil"},
92 {
"type",
"fsmAction",
"targetStates"},
93 {
"fsm",
"threshOff",
"READY,OPERATING"} );
94 mx::app::appConfigurator config;
95 config.readConfig(
"/tmp/fsmNode_test.conf");
99 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
108 tsn =
new fsmNode(
"ttmpupil", &parentGraph);
111 catch(
const std::exception & e)
113 std::cerr << e.what() <<
"\n";
116 REQUIRE(pass ==
true);
117 REQUIRE(tsn !=
nullptr);
119 REQUIRE( tsn->
name() ==
"ttmpupil");
120 REQUIRE( tsn->
node()->name() ==
"ttmpupil");
128 catch(
const std::exception & e)
130 std::cerr << e.what() <<
"\n";
133 REQUIRE(pass ==
true);
136 REQUIRE(tsn->
device() ==
"ttmpupil");
137 REQUIRE(tsn->
fsmKey() ==
"ttmpupil.fsm");
143 WHEN(
"node is in file, setting action to active for one state")
145 ingr::instGraphXML parentGraph;
147 mx::app::writeConfigFile(
"/tmp/fsmNode_test.conf", {
"ttmpupil",
"ttmpupil",
"ttmpupil"},
148 {
"type",
"fsmAction",
"targetStates"},
149 {
"fsm",
"active",
"OPERATING"} );
150 mx::app::appConfigurator config;
151 config.readConfig(
"/tmp/fsmNode_test.conf");
155 int rv = parentGraph.loadXMLFile(emsg,
"/tmp/xigNode_test.xml");
164 tsn =
new fsmNode(
"ttmpupil", &parentGraph);
167 catch(
const std::exception & e)
169 std::cerr << e.what() <<
"\n";
172 REQUIRE(pass ==
true);
173 REQUIRE(tsn !=
nullptr);
175 REQUIRE( tsn->
name() ==
"ttmpupil");
176 REQUIRE( tsn->
node()->name() ==
"ttmpupil");
184 catch(
const std::exception & e)
186 std::cerr << e.what() <<
"\n";
189 REQUIRE(pass ==
true);
192 REQUIRE(tsn->
device() ==
"ttmpupil");
193 REQUIRE(tsn->
fsmKey() ==
"ttmpupil.fsm");
Implementation of an instGraph node interface for a MagAO-X Finite State Machine (FSM)
const std::vector< stateCodeT > & targetStates() const
Get the target states.
virtual void device(const std::string &dev)
Set the device name.
fsmNodeActionT fsmAction() const
Get the action.
void loadConfig(mx::app::appConfigurator &config)
Load this specific node's settings from an application configuration.
const std::string & fsmKey() const
Get the FSM unique key.
ingr::instNode * node()
Get the pointer to the underlying node.
std::string name()
Get the name of this node.
SCENARIO("Creating and configuring an fsmNode", "[instGraph::fsmNode]")
@ OPERATING
The device is operating, other than homing.
@ READY
The device is ready for operation, but is not operating.