27namespace cameraSimTest
34 cameraSim_test(
const std::string device )
36 m_configName = device;
39 m_indiP_focus = pcf::IndiProperty( pcf::IndiProperty::Switch );
40 m_indiP_focus.setDevice( m_configName );
41 m_indiP_focus.setName(
"focus" );
43 m_indiP_focus.add( pcf::IndiElement(
"state", pcf::IndiElement::Off ) );
74 void configureFocusHelper(
const std::string &device,
75 const std::string &property,
76 const std::string &element,
79 m_focusStateHelperConfigured =
true;
80 m_focusStateSource = device +
"." + property;
81 m_focusStateElement = element;
82 m_focusStateOnMeansInFocus = onMeansInFocus;
83 m_focusStateSourceIndex = 0;
84 m_focusMonitoredPropertyKeys = { m_focusStateSource };
85 m_indiP_focusMonitoredProperties.resize( 1 );
86 m_indiP_focusMonitoredProperties[0].setDevice( device );
87 m_indiP_focusMonitoredProperties[0].setName( property );
90 int cacheFocusProperty(
const pcf::IndiProperty &
ipRecv )
92 return setCallBack_focusMonitored(
ipRecv );
95 bool helperFocusState()
97 return checkFocusSwitchState();
100 pcf::IndiElement::SwitchStateType publishedFocusState()
102 return m_indiP_focus[
"state"].getSwitchState();
111 static constexpr bool c_stdCamera_hasFocus =
true;
112 static constexpr bool c_stdCamera_tempControl =
false;
113 static constexpr bool c_stdCamera_readoutSpeed =
false;
114 static constexpr bool c_stdCamera_vShiftSpeed =
false;
115 static constexpr bool c_stdCamera_emGain =
false;
116 static constexpr bool c_stdCamera_usesModes =
false;
117 static constexpr bool c_stdCamera_usesROI =
false;
120 pcf::IndiProperty m_lastSentProperty;
122 int m_sendNewPropertyResult{ 0 };
125 focusHelper_test() :
MagAOXApp<>( MAGAOX_CURRENT_SHA1, MAGAOX_REPO_MODIFIED )
127 m_configName =
"camtest";
130 m_indiP_focus = pcf::IndiProperty( pcf::IndiProperty::Switch );
131 m_indiP_focus.setDevice( m_configName );
132 m_indiP_focus.setName(
"focus" );
134 m_indiP_focus.add( pcf::IndiElement(
"state", pcf::IndiElement::Off ) );
137 ~focusHelper_test()
noexcept override =
default;
139 void configureGotoFocusHelper(
const std::vector<std::string> &properties,
140 const std::string &format,
141 const std::string &targetProperty )
143 m_focusGotoHelperConfigured =
true;
144 m_focusGotoSourceProperties = properties;
145 m_focusGotoFormat = format;
146 m_focusGotoTargetProperty = targetProperty;
147 m_focusGotoSourceIndices.clear();
148 m_focusMonitoredPropertyKeys.clear();
149 m_indiP_focusMonitoredProperties.clear();
151 REQUIRE(
indi::parseIndiKey( m_focusGotoTargetDevice, m_focusGotoTargetName, m_focusGotoTargetProperty ) == 0 );
153 for(
size_t n = 0; n < properties.size(); ++n )
156 std::string propName;
160 m_focusGotoSourceIndices.push_back(
static_cast<int>( n ) );
161 m_focusMonitoredPropertyKeys.push_back( properties[n] );
162 m_indiP_focusMonitoredProperties.emplace_back();
163 m_indiP_focusMonitoredProperties[n].setDevice( devName );
164 m_indiP_focusMonitoredProperties[n].setName( propName );
168 void configureFocusHelper(
const std::string &device,
169 const std::string &property,
170 const std::string &element,
171 bool onMeansInFocus )
173 m_focusStateHelperConfigured =
true;
174 m_focusStateSource = device +
"." + property;
175 m_focusStateElement = element;
176 m_focusStateOnMeansInFocus = onMeansInFocus;
177 m_focusStateSourceIndex = 0;
178 m_focusMonitoredPropertyKeys = { m_focusStateSource };
179 m_indiP_focusMonitoredProperties.resize( 1 );
180 m_indiP_focusMonitoredProperties[0].setDevice( device );
181 m_indiP_focusMonitoredProperties[0].setName( property );
185 int cacheFocusProperty(
const pcf::IndiProperty &
ipRecv )
187 return setCallBack_focusMonitored(
ipRecv );
193 return checkFocusSwitchState();
203 int sendNewProperty(
const pcf::IndiProperty &ipSend )
205 m_lastSentProperty = ipSend;
206 return m_sendNewPropertyResult;
210 void setSendNewPropertyResult(
int result )
212 m_sendNewPropertyResult = result;
215 int appStartup()
override
220 int appLogic()
override
225 int appShutdown()
override
230 pcf::IndiElement::SwitchStateType publishedFocusState()
232 return m_indiP_focus[
"state"].getSwitchState();
236 const pcf::IndiProperty &lastSentProperty()
const
238 return m_lastSentProperty;
242 const std::string &gotoFocusFormat()
const
244 return m_focusGotoFormat;
248 int setupConfig( mx::app::appConfigurator &config )
254 int loadConfig( mx::app::appConfigurator &config )
265TEST_CASE(
"cameraSim INDI callbacks validate device and property names",
"[cameraSim]" )
268 #ifdef CAMERASIM_TEST_DOXYGEN_REF
269 cameraSim::newCallBack_stdCamera( pcf::IndiProperty() );
304TEST_CASE(
"cameraSim stdCamera focus helper tracks monitored switch properties",
"[cameraSim]" )
306 SECTION(
"configured element On means out of focus" )
308 focusHelper_test app;
309 app.configureFocusHelper(
"sre",
"caution",
"focus-mismatch",
false );
311 pcf::IndiProperty focusProp( pcf::IndiProperty::Switch );
312 focusProp.setDevice(
"sre" );
313 focusProp.setName(
"caution" );
314 focusProp.add( pcf::IndiElement(
"focus-mismatch", pcf::IndiElement::On ) );
316 REQUIRE( app.cacheFocusProperty( focusProp ) == 0 );
317 REQUIRE( app.publishedFocusState() == pcf::IndiElement::Off );
319 focusProp[
"focus-mismatch"].setSwitchState( pcf::IndiElement::Off );
321 REQUIRE( app.cacheFocusProperty( focusProp ) == 0 );
322 REQUIRE( app.publishedFocusState() == pcf::IndiElement::On );
325 SECTION(
"configured element On means in focus" )
327 focusHelper_test app;
328 app.configureFocusHelper(
"sre",
"caution",
"focus-ok",
true );
330 pcf::IndiProperty focusProp( pcf::IndiProperty::Switch );
331 focusProp.setDevice(
"sre" );
332 focusProp.setName(
"caution" );
333 focusProp.add( pcf::IndiElement(
"focus-ok", pcf::IndiElement::On ) );
335 REQUIRE( app.cacheFocusProperty( focusProp ) == 0 );
336 REQUIRE( app.publishedFocusState() == pcf::IndiElement::On );
338 focusProp[
"focus-ok"].setSwitchState( pcf::IndiElement::Off );
340 REQUIRE( app.cacheFocusProperty( focusProp ) == 0 );
341 REQUIRE( app.publishedFocusState() == pcf::IndiElement::Off );
349TEST_CASE(
"cameraSim stdCamera goto-focus helper dispatches preset commands",
"[cameraSim]" )
351 focusHelper_test app;
352 app.configureGotoFocusHelper(
353 {
"stagebs.presetName",
"fwfpm.filterName",
"stagescibs.presetName" },
"{}-{}-{}",
"stagesci1.presetName" );
355 pcf::IndiProperty prop1( pcf::IndiProperty::Switch );
356 prop1.setDevice(
"stagebs" );
357 prop1.setName(
"presetName" );
358 prop1.add( pcf::IndiElement(
"65-35", pcf::IndiElement::On ) );
359 prop1.add( pcf::IndiElement(
"ha-ir", pcf::IndiElement::Off ) );
361 pcf::IndiProperty prop2( pcf::IndiProperty::Switch );
362 prop2.setDevice(
"fwfpm" );
363 prop2.setName(
"filterName" );
364 prop2.add( pcf::IndiElement(
"open", pcf::IndiElement::On ) );
365 prop2.add( pcf::IndiElement(
"lyotsm", pcf::IndiElement::Off ) );
367 pcf::IndiProperty prop3( pcf::IndiProperty::Switch );
368 prop3.setDevice(
"stagescibs" );
369 prop3.setName(
"presetName" );
370 prop3.add( pcf::IndiElement(
"ri", pcf::IndiElement::On ) );
371 prop3.add( pcf::IndiElement(
"out", pcf::IndiElement::Off ) );
373 REQUIRE( app.cacheFocusProperty( prop1 ) == 0 );
374 REQUIRE( app.cacheFocusProperty( prop2 ) == 0 );
375 REQUIRE( app.cacheFocusProperty( prop3 ) == 0 );
377 SECTION(
"successful dispatch sends the formatted preset selection" )
379 REQUIRE( app.sendGotoFocusCommand() == 0 );
380 REQUIRE( app.lastSentProperty().getDevice() ==
"stagesci1" );
381 REQUIRE( app.lastSentProperty().getName() ==
"presetName" );
382 REQUIRE( app.lastSentProperty().find(
"65-35-open-ri" ) );
383 REQUIRE( app.lastSentProperty()[
"65-35-open-ri"].getSwitchState() == pcf::IndiElement::On );
386 SECTION(
"dispatch failures are propagated to the caller" )
388 app.setSendNewPropertyResult( -1 );
389 REQUIRE( app.sendGotoFocusCommand() == -1 );
397TEST_CASE(
"cameraSim stdCamera goto-focus helper strips quoted format strings",
"[cameraSim]" )
399 mx::app::writeConfigFile(
"/tmp/cameraSim_focusHelper.conf",
406 {
"numSwitches",
"property1",
"property2",
"property3",
"format",
"targetProperty" },
408 "stagebs.presetName",
410 "stagescibs.presetName",
412 "stagesci1.presetName" } );
414 mx::app::appConfigurator config;
415 focusHelper_test app;
417 REQUIRE( app.setupConfig( config ) == 0 );
418 config.readConfig(
"/tmp/cameraSim_focusHelper.conf" );
419 REQUIRE( app.loadConfig( config ) == 0 );
420 REQUIRE( app.gotoFocusFormat() ==
"{}-{}-{}" );
421 REQUIRE_FALSE( app.gotoFocusFormat().find(
'\"' ) != std::string::npos );