Instrument Neutral Distributed Interface INDI  2.0.2
dome.cpp

The dome driver snoops on the rain detector signal and watches whether rain is detected or not. If it is detector and the dome is closed, it performs no action, but it also prevents you from opening the dome due to rain. If the dome is open, it will automatically starts closing the shutter. In order snooping to work, both drivers must be started by the same indiserver (or chained INDI servers):

indiserver tutorial_dome tutorial_rain

The dome driver keeps a copy of RainL light property from the rain driver. This makes it easy to parse the property status once an update from the rain driver arrives in the dome driver. Alternatively, you can directly parse the XML root element in ISSnoopDevice(XMLEle *root) to extract the required data.

/*
INDI Developers Manual
Tutorial #5 - Snooping
Dome
Refer to README, which contains instruction on how to build this driver, and use it
with an INDI-compatible client.
*/
#include "dome.h"
#include <inditimer.h>
#include <memory>
#include <cstring>
#include <unistd.h>
std::unique_ptr<Dome> dome(new Dome());
/**************************************************************************************
** Client is asking us to establish connection to the device
***************************************************************************************/
{
IDMessage(getDeviceName(), "Dome connected successfully!");
return true;
}
/**************************************************************************************
** Client is asking us to terminate connection to the device
***************************************************************************************/
{
IDMessage(getDeviceName(), "Dome disconnected successfully!");
return true;
}
/**************************************************************************************
** INDI is asking us for our default device name
***************************************************************************************/
const char *Dome::getDefaultName()
{
return "Dome";
}
/**************************************************************************************
** INDI is asking us to init our properties.
***************************************************************************************/
{
// Must init parent properties first!
mShutterSwitch[0].fill("Open", "", ISS_ON);
mShutterSwitch[1].fill("Close", "", ISS_OFF);
mShutterSwitch.fill(getDeviceName(), "Shutter Door", "", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE);
mShutterSwitch.onUpdate([this]()
{
if (mShutterSwitch[0].getState() == ISS_ON)
else
});
// We init here the property we wish to "snoop" from the target device
mRainLight[0].fill("Status", "", IPS_IDLE);
// wait for "Rain Detector" driver
watchDevice("Rain Detector", [this](INDI::BaseDevice device)
{
// wait for "Rain Alert" property available
device.watchProperty("Rain Alert", [this](INDI::PropertyLight rain)
{
mRainLight = rain; // we have real rainLight property, override mRainLight
static IPState oldRainState = rain[0].getState();
IPState newRainState = rain[0].getState();
if (newRainState == IPS_ALERT)
{
// If dome is open, then close it */
if (mShutterSwitch[0].getState() == ISS_ON)
else
IDMessage(getDeviceName(), "Rain Alert Detected! Dome is already closed.");
}
if (newRainState != IPS_ALERT && oldRainState == IPS_ALERT)
{
IDMessage(getDeviceName(), "Rain threat passed. Opening the dome is now safe.");
}
oldRainState = newRainState;
}, BaseDevice::WATCH_NEW_OR_UPDATE);
});
return true;
}
/********************************************************************************************
** INDI is asking us to update the properties because there is a change in CONNECTION status
** This fucntion is called whenever the device is connected or disconnected.
*********************************************************************************************/
{
// Call parent update properties first
if (isConnected())
defineProperty(mShutterSwitch);
else
// We're disconnected
deleteProperty(mShutterSwitch);
return true;
}
/********************************************************************************************
** Close shutter
*********************************************************************************************/
{
mShutterSwitch.setState(IPS_BUSY);
mShutterSwitch.apply("Shutter is closing...");
INDI::Timer::singleShot(5000 /* ms */, [this](){
mShutterSwitch[0].setState(ISS_OFF);
mShutterSwitch[1].setState(ISS_ON);
mShutterSwitch.setState(IPS_OK);
mShutterSwitch.apply("Shutter is closed.");
});
}
/********************************************************************************************
** Open shutter
*********************************************************************************************/
{
if (mRainLight[0].getState() == IPS_ALERT)
{
mShutterSwitch.setState(IPS_ALERT);
mShutterSwitch[0].setState(ISS_OFF);
mShutterSwitch[1].setState(ISS_ON);
mShutterSwitch.apply("It is raining, cannot open Shutter.");
return;
}
mShutterSwitch.setState(IPS_BUSY);
mShutterSwitch.apply("Shutter is opening...");
INDI::Timer::singleShot(5000 /* ms */, [this](){
mShutterSwitch[0].setState(ISS_ON);
mShutterSwitch[1].setState(ISS_OFF);
mShutterSwitch.setState(IPS_OK);
mShutterSwitch.apply("Shutter is open.");
});
}
hid_device * device
Definition: dome.h:33
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: dome.cpp:38
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: dome.cpp:64
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: dome.cpp:118
void openShutter()
Definition: dome.cpp:152
bool Disconnect() override
Disconnect from device.
Definition: dome.cpp:47
const char * getDefaultName() override
Definition: dome.cpp:56
void closeShutter()
Definition: dome.cpp:135
Class to provide basic INDI device functionality.
Definition: basedevice.h:52
bool isConnected() const
Definition: basedevice.cpp:520
const char * getDeviceName() const
Definition: basedevice.cpp:821
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void watchDevice(const char *deviceName, const std::function< void(INDI::BaseDevice)> &callback)
Add a device to the watch list.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
IPState getState() const
void fill(const char *device, const char *name, const char *label, const char *group, IPState state)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, ISRule rule, double timeout, IPState state)
void onUpdate(const std::function< void()> &callback)
static void singleShot(int msec, const std::function< void()> &callback)
This static function calls a the given function after a given time interval.
Definition: inditimer.cpp:146
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
std::unique_ptr< Dome > dome(new Dome())
Construct a dome device that the user may operate to open or close the dome shutter door....
@ ISS_OFF
Definition: indiapi.h:151
@ ISS_ON
Definition: indiapi.h:152
@ IP_RW
Definition: indiapi.h:186
IPState
Property state.
Definition: indiapi.h:160
@ IPS_BUSY
Definition: indiapi.h:163
@ IPS_ALERT
Definition: indiapi.h:164
@ IPS_IDLE
Definition: indiapi.h:161
@ IPS_OK
Definition: indiapi.h:162
@ ISR_1OFMANY
Definition: indiapi.h:173
void IDMessage(const char *dev, const char *fmt,...)
Definition: indidriver.c:960