Instrument Neutral Distributed Interface INDI 2.2.5
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
INDI::BaseDevice Class Reference

Class to provide basic INDI device functionality. More...

#include <basedevice.h>

Inheritance diagram for INDI::BaseDevice:
INDI::ParentDevice INDI::DefaultDevice ALTO ArduinoST4 AstrometryDriver AvalonUPAS CelestronDewPower CheapoDC DeepSkyDadFP DeltaT Dome DragonLIGHT DustCoverSimulator Excalibur FlipFlat GIOTTO GPUSB GeminiFlatpanel GeminiPBH INDI::CCD INDI::Dome INDI::FilterWheel INDI::Focuser INDI::GPS INDI::IMU INDI::Rotator INDI::SensorInterface INDI::Telescope INDI::Weather INDIAlpacaServer IPX800 IPX800 Imager IndiAstroLink4mini2 IndiAstrolink4 JoyStick LPM LightPanelSimulator MLAstroRPA MyDCP4ESP OAPA PACSimulator PegasusFlatMaster PegasusFlatMasterNeo PegasusFlatMasterWifi PegasusPPB PegasusPPBA PegasusSPB PegasusUCH PegasusUPB PegasusUPB3 RainDetector SQM SQMSimulator STAR2000 SVBONYPowerBox SafetyMonitor ShelyakDriver SimpleDevice SimpleSkeleton SimulatorIO SkySafari SnapCap SpectraCyber StarTechHub TerransPowerBoxGoV2 TerransPowerBoxProV2 UPS USBDewpoint WakeOnLAN WandererBoxPlusV3 WandererBoxProV3 WandererCover WandererCoverV4EC WandererCoverV4ProEC WandererDewTerminator WandererETA WandererEclipse WatchDog WaveshareRelay WeatherMeta myDewControllerPro

Public Types

enum  INDI_ERROR { INDI_DEVICE_NOT_FOUND = -1 , INDI_PROPERTY_INVALID = -2 , INDI_PROPERTY_DUPLICATED = -3 , INDI_DISPATCH_ERROR = -4 }
 
enum  { INDI_ENABLED , INDI_DISABLED }
 
enum  WATCH { WATCH_NEW = 0 , WATCH_UPDATE , WATCH_NEW_OR_UPDATE }
 
enum  DRIVER_INTERFACE {
  GENERAL_INTERFACE = 0 , TELESCOPE_INTERFACE = (1 << 0) , CCD_INTERFACE = (1 << 1) , GUIDER_INTERFACE = (1 << 2) ,
  FOCUSER_INTERFACE = (1 << 3) , FILTER_INTERFACE = (1 << 4) , DOME_INTERFACE = (1 << 5) , GPS_INTERFACE = (1 << 6) ,
  WEATHER_INTERFACE = (1 << 7) , AO_INTERFACE = (1 << 8) , DUSTCAP_INTERFACE = (1 << 9) , LIGHTBOX_INTERFACE = (1 << 10) ,
  DETECTOR_INTERFACE = (1 << 11) , ROTATOR_INTERFACE = (1 << 12) , SPECTROGRAPH_INTERFACE = (1 << 13) , CORRELATOR_INTERFACE = (1 << 14) ,
  AUX_INTERFACE = (1 << 15) , OUTPUT_INTERFACE = (1 << 16) , INPUT_INTERFACE = (1 << 17) , POWER_INTERFACE = (1 << 18) ,
  IMU_INTERFACE = (1 << 19) , PAC_INTERFACE = (1 << 20) , SENSOR_INTERFACE = SPECTROGRAPH_INTERFACE | DETECTOR_INTERFACE | CORRELATOR_INTERFACE
}
 The DRIVER_INTERFACE enum defines the class of devices the driver implements. A driver may implement one or more interfaces. More...
 
typedef INDI::Properties Properties
 

Public Member Functions

 BaseDevice ()
 
virtual ~BaseDevice ()
 
void registerProperty (const INDI::Property &property)
 Register the property to be able to observe and update.
 
void registerProperty (const INDI::Property &property, INDI_PROPERTY_TYPE type)
 
int removeProperty (const char *name, char *errmsg)
 Remove a property.
 
void watchProperty (const char *name, const std::function< void(INDI::Property)> &callback, WATCH watch=WATCH_NEW)
 Call the callback function if property is available.
 
Property getProperty (const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
 Return a property and its type given its name.
 
Properties getProperties ()
 Return a list of all properties in the device.
 
const Properties getProperties () const
 
INDI::PropertyNumber getNumber (const char *name) const
 
INDI::PropertyText getText (const char *name) const
 
INDI::PropertySwitch getSwitch (const char *name) const
 
INDI::PropertyLight getLight (const char *name) const
 
INDI::PropertyBlob getBLOB (const char *name) const
 
IPState getPropertyState (const char *name) const
 
IPerm getPropertyPermission (const char *name) const
 
void * getRawProperty (const char *name, INDI_PROPERTY_TYPE type=INDI_UNKNOWN) const
 Return a property and its type given its name.
 
void addMessage (const std::string &msg)
 Add message to the driver's message queue.
 
void checkMessage (XMLEle *root)
 
void doMessage (XMLEle *msg)
 
const std::string & messageQueue (size_t index) const
 
const std::string & lastMessage () const
 
bool isValid () const
 
bool isSameDevice (const BaseDevice &other) const
 
bool isConnected () const
 
void attach ()
 indicates that the device is ready
 
void detach ()
 indicates that the device is being removed
 
void setMediator (INDI::BaseMediator *mediator)
 Set the driver's mediator to receive notification of news devices and updated property values.
 
INDI::BaseMediator * getMediator () const
 
void setDeviceName (const char *dev)
 Set the device name.
 
const char * getDeviceName () const
 
bool isDeviceNameMatch (const char *otherName) const
 Check that the device name matches the argument.
 
bool isDeviceNameMatch (const std::string &otherName) const
 Check that the device name matches the argument.
 
const char * getDriverName () const
 
const char * getDriverExec () const
 
const char * getDriverVersion () const
 
uint16_t getDriverInterface () const
 getDriverInterface returns ORed values of DRIVER_INTERFACE. It presents the device classes supported by the driver.
 
bool buildSkeleton (const char *filename)
 Build driver properties from a skeleton file.
 
int buildProp (const INDI::LilXmlElement &root, char *errmsg, bool isDynamic=false)
 Build a property given the supplied XML element (defXXX)
 
int setValue (const INDI::LilXmlElement &root, char *errmsg)
 handle SetXXX commands from client
 
 operator BaseDevice * ()
 
BaseDevice * operator-> ()
 
bool operator!= (std::nullptr_t) const
 
bool operator== (std::nullptr_t) const
 
 operator bool () const
 
 operator bool ()
 

Static Public Member Functions

static std::string getSharedFilePath (std::string fileName)
 

Protected Member Functions

 BaseDevice (BaseDevicePrivate &dd)
 
 BaseDevice (const std::shared_ptr< BaseDevicePrivate > &dd)
 

Protected Attributes

std::shared_ptr< BaseDevicePrivate > d_ptr
 

Friends

class AbstractBaseClientPrivate
 

Detailed Description

Class to provide basic INDI device functionality.

INDI::BaseDevice is the base device for all INDI devices and contains a list of all properties defined by the device either explicitly or via a skeleton file. You don't need to subclass INDI::BaseDevice class directly, it is inheritied by INDI::DefaultDevice which takes care of building a standard INDI device. Moreover, INDI::BaseClient maintains a list of INDI::BaseDevice objects as they get defined from the INDI server, and those objects may be accessed to retrieve information on the object properties or message log.

Author
Jasem Mutlaq
Examples
dome.cpp, tutorial_client.cpp, and tutorial_client.h.

Definition at line 51 of file basedevice.h.

Member Typedef Documentation

◆ Properties

Definition at line 55 of file basedevice.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Used for switch Enabled/Disabled or On/Off type properties

Enumerator
INDI_ENABLED 
INDI_DISABLED 

Definition at line 68 of file basedevice.h.

◆ DRIVER_INTERFACE

The DRIVER_INTERFACE enum defines the class of devices the driver implements. A driver may implement one or more interfaces.

Enumerator
GENERAL_INTERFACE 

Default interface for all INDI devices

TELESCOPE_INTERFACE 

Telescope interface, must subclass INDI::Telescope

CCD_INTERFACE 

CCD interface, must subclass INDI::CCD

GUIDER_INTERFACE 

Guider interface, must subclass INDI::GuiderInterface

FOCUSER_INTERFACE 

Focuser interface, must subclass INDI::FocuserInterface

FILTER_INTERFACE 

Filter interface, must subclass INDI::FilterInterface

DOME_INTERFACE 

Dome interface, must subclass INDI::Dome

GPS_INTERFACE 

GPS interface, must subclass INDI::GPS

WEATHER_INTERFACE 

Weather interface, must subclass INDI::Weather

AO_INTERFACE 

Adaptive Optics Interface

DUSTCAP_INTERFACE 

Dust Cap Interface

LIGHTBOX_INTERFACE 

Light Box Interface

DETECTOR_INTERFACE 

Detector interface, must subclass INDI::Detector

ROTATOR_INTERFACE 

Rotator interface, must subclass INDI::RotatorInterface

SPECTROGRAPH_INTERFACE 

Spectrograph interface

CORRELATOR_INTERFACE 

Correlators (interferometers) interface

AUX_INTERFACE 

Auxiliary interface

OUTPUT_INTERFACE 

Digital Output (e.g. Relay) interface

INPUT_INTERFACE 

Digital/Analog Input (e.g. GPIO) interface

POWER_INTERFACE 

Power Controller interface

IMU_INTERFACE 

Intertial Measurement Unit interface

PAC_INTERFACE 

Polar Alignment Correction interface, must subclass INDI::PACInterface

SENSOR_INTERFACE 

Definition at line 83 of file basedevice.h.

◆ INDI_ERROR

INDI error codes.

Enumerator
INDI_DEVICE_NOT_FOUND 

INDI Device was not found.

INDI_PROPERTY_INVALID 

Property has an invalid syntax or attribute.

INDI_PROPERTY_DUPLICATED 

INDI Device was not found.

INDI_DISPATCH_ERROR 

Dispatching command to driver failed.

Definition at line 59 of file basedevice.h.

◆ WATCH

Used for watchProperty callback method.

Enumerator
WATCH_NEW 

Applies to discovered properties only.

WATCH_UPDATE 

Applies to updated properties only.

WATCH_NEW_OR_UPDATE 

Applies when a property appears or is updated, i.e. both of the above.

Definition at line 75 of file basedevice.h.

Constructor & Destructor Documentation

◆ BaseDevice() [1/3]

INDI::BaseDevice::BaseDevice ( )

Definition at line 75 of file basedevice.cpp.

◆ ~BaseDevice()

INDI::BaseDevice::~BaseDevice ( )
virtual

Definition at line 79 of file basedevice.cpp.

◆ BaseDevice() [2/3]

INDI::BaseDevice::BaseDevice ( BaseDevicePrivate &  dd)
protected

Definition at line 82 of file basedevice.cpp.

◆ BaseDevice() [3/3]

INDI::BaseDevice::BaseDevice ( const std::shared_ptr< BaseDevicePrivate > &  dd)
protected

Definition at line 86 of file basedevice.cpp.

Member Function Documentation

◆ addMessage()

void INDI::BaseDevice::addMessage ( const std::string &  msg)

Add message to the driver's message queue.

Parameters
msgMessage to add.

Definition at line 888 of file basedevice.cpp.

◆ attach()

void INDI::BaseDevice::attach ( )

indicates that the device is ready

Note
the BaseMediator::newDevice method will be called

Definition at line 541 of file basedevice.cpp.

◆ buildProp()

int INDI::BaseDevice::buildProp ( const INDI::LilXmlElement &  root,
char *  errmsg,
bool  isDynamic = false 
)

Build a property given the supplied XML element (defXXX)

Parameters
rootXML element to parse and build.
errmsgbuffer to store error message in parsing fails.
isDynamicset to true if property is loaded from an XML file.
Returns
0 if parsing is successful, -1 otherwise and errmsg is set

Definition at line 325 of file basedevice.cpp.

◆ buildSkeleton()

bool INDI::BaseDevice::buildSkeleton ( const char *  filename)

Build driver properties from a skeleton file.

Parameters
filenamefull path name of the file.
Returns
true if successful, false otherwise.

A skeloton file defines the properties supported by this driver. It is a list of defXXX elements enclosed by <INDIDriver>@ and </INDIDriver>@ opening and closing tags. After the properties are created, they can be rerieved, manipulated, and defined to other clients.

See also
An example skeleton file can be found under examples/tutorial_four_sk.xml
Examples
simpleskeleton.cpp.

Definition at line 303 of file basedevice.cpp.

◆ checkMessage()

void INDI::BaseDevice::checkMessage ( XMLEle *  root)

Definition at line 852 of file basedevice.cpp.

◆ detach()

void INDI::BaseDevice::detach ( )

indicates that the device is being removed

Note
the BaseMediator::removeDevice method will be called

Definition at line 547 of file basedevice.cpp.

◆ doMessage()

void INDI::BaseDevice::doMessage ( XMLEle *  msg)

Definition at line 862 of file basedevice.cpp.

◆ getBLOB()

INDI::PropertyBlob INDI::BaseDevice::getBLOB ( const char *  name) const
Returns
Return vector BLOB property given its name
Examples
simpleskeleton.cpp.

Definition at line 110 of file basedevice.cpp.

◆ getDeviceName()

const char * INDI::BaseDevice::getDeviceName ( ) const
Returns
Returns the device name
Examples
dome.cpp.

Definition at line 831 of file basedevice.cpp.

◆ getDriverExec()

const char * INDI::BaseDevice::getDriverExec ( ) const
Returns
driver executable name
Note
This can only be valid if DRIVER_INFO is defined by the driver.

Definition at line 970 of file basedevice.cpp.

◆ getDriverInterface()

uint16_t INDI::BaseDevice::getDriverInterface ( ) const

getDriverInterface returns ORed values of DRIVER_INTERFACE. It presents the device classes supported by the driver.

Returns
driver device interface descriptor.
Note
For example, to know if the driver supports CCD interface, check the returned value:
if (device.getDriverInterface() & CCD_INTERFACE)
cout << "We received a camera!" << endl;
hid_device * device

Definition at line 982 of file basedevice.cpp.

◆ getDriverName()

const char * INDI::BaseDevice::getDriverName ( ) const
Returns
driver name
Note
This can only be valid if DRIVER_INFO is defined by the driver.

Definition at line 963 of file basedevice.cpp.

◆ getDriverVersion()

const char * INDI::BaseDevice::getDriverVersion ( ) const
Returns
driver version
Note
This can only be valid if DRIVER_INFO is defined by the driver.

Definition at line 976 of file basedevice.cpp.

◆ getLight()

INDI::PropertyLight INDI::BaseDevice::getLight ( const char *  name) const
Returns
Return vector light property given its name
Examples
simpleskeleton.cpp.

Definition at line 105 of file basedevice.cpp.

◆ getMediator()

INDI::BaseMediator * INDI::BaseDevice::getMediator ( ) const
Returns
Get the meditator assigned to this driver

Definition at line 994 of file basedevice.cpp.

◆ getNumber()

INDI::PropertyNumber INDI::BaseDevice::getNumber ( const char *  name) const
Returns
Return vector number property given its name
Examples
simpleskeleton.cpp.

Definition at line 90 of file basedevice.cpp.

◆ getProperties() [1/2]

BaseDevice::Properties INDI::BaseDevice::getProperties ( )

Return a list of all properties in the device.

Examples
simpleskeleton.cpp.

Definition at line 159 of file basedevice.cpp.

◆ getProperties() [2/2]

const BaseDevice::Properties INDI::BaseDevice::getProperties ( ) const

Definition at line 165 of file basedevice.cpp.

◆ getProperty()

INDI::Property INDI::BaseDevice::getProperty ( const char *  name,
INDI_PROPERTY_TYPE  type = INDI_UNKNOWN 
) const

Return a property and its type given its name.

Parameters
nameof property to be found.
typeof property found.
Returns
If property is found, it is returned. To be used you must use static_cast with given the type of property returned.
Examples
tutorial_client.cpp.

Definition at line 139 of file basedevice.cpp.

◆ getPropertyPermission()

IPerm INDI::BaseDevice::getPropertyPermission ( const char *  name) const
Returns
Return property permission

Definition at line 124 of file basedevice.cpp.

◆ getPropertyState()

IPState INDI::BaseDevice::getPropertyState ( const char *  name) const
Returns
Return property state

Definition at line 115 of file basedevice.cpp.

◆ getRawProperty()

void * INDI::BaseDevice::getRawProperty ( const char *  name,
INDI_PROPERTY_TYPE  type = INDI_UNKNOWN 
) const

Return a property and its type given its name.

Parameters
nameof property to be found.
typeof property found.
Returns
If property is found, the raw void * pointer to the IXXXVectorProperty is returned. To be used you must use static_cast with given the type of property returned. For example, INumberVectorProperty *num = static_cast<INumberVectorProperty> getRawProperty("FOO", INDI_NUMBER);
Note
This is a low-level function and should not be called directly unless necessary. Use getXXX instead where XXX is the property type (Number, Text, Switch..etc).

Definition at line 133 of file basedevice.cpp.

◆ getSharedFilePath()

std::string INDI::BaseDevice::getSharedFilePath ( std::string  fileName)
static

Definition at line 214 of file basedevice.cpp.

◆ getSwitch()

INDI::PropertySwitch INDI::BaseDevice::getSwitch ( const char *  name) const
Returns
Return vector switch property given its name
Examples
simpleskeleton.cpp.

Definition at line 100 of file basedevice.cpp.

◆ getText()

INDI::PropertyText INDI::BaseDevice::getText ( const char *  name) const
Returns
Return vector text property given its name

Definition at line 95 of file basedevice.cpp.

◆ isConnected()

bool INDI::BaseDevice::isConnected ( ) const
Returns
True if the device is connected (CONNECT=ON), False otherwise
Examples
dome.cpp, simpleccd.cpp, simpleskeleton.cpp, and tutorial_client.cpp.

Definition at line 530 of file basedevice.cpp.

◆ isDeviceNameMatch() [1/2]

bool INDI::BaseDevice::isDeviceNameMatch ( const char *  otherName) const

Check that the device name matches the argument.

Examples
tutorial_client.cpp.

Definition at line 837 of file basedevice.cpp.

◆ isDeviceNameMatch() [2/2]

bool INDI::BaseDevice::isDeviceNameMatch ( const std::string &  otherName) const

Check that the device name matches the argument.

Definition at line 843 of file basedevice.cpp.

◆ isSameDevice()

bool INDI::BaseDevice::isSameDevice ( const BaseDevice &  other) const
Returns
True if both handles refer to the same underlying device instance. Two devices can share the same name across a disconnect/reconnect (e.g. a driver restart replaces the device with a fresh instance under the same name), so name equality alone does not imply identity.

Definition at line 923 of file basedevice.cpp.

◆ isValid()

bool INDI::BaseDevice::isValid ( ) const
Returns
True if the device exists

Definition at line 917 of file basedevice.cpp.

◆ lastMessage()

const std::string & INDI::BaseDevice::lastMessage ( ) const
Returns
Returns last message message.

Definition at line 909 of file basedevice.cpp.

◆ messageQueue()

const std::string & INDI::BaseDevice::messageQueue ( size_t  index) const
Returns
Returns a specific message.
Examples
tutorial_client.cpp.

Definition at line 898 of file basedevice.cpp.

◆ operator BaseDevice *()

INDI::BaseDevice::operator BaseDevice * ( )

Definition at line 1006 of file basedevice.cpp.

◆ operator bool() [1/2]

INDI::BaseDevice::operator bool ( )
inline

Definition at line 312 of file basedevice.h.

◆ operator bool() [2/2]

INDI::BaseDevice::operator bool ( ) const
inline

Definition at line 308 of file basedevice.h.

◆ operator!=()

bool INDI::BaseDevice::operator!= ( std::nullptr_t  ) const
inline

Definition at line 297 of file basedevice.h.

◆ operator->()

BaseDevice * INDI::BaseDevice::operator-> ( )

Definition at line 1000 of file basedevice.cpp.

◆ operator==()

bool INDI::BaseDevice::operator== ( std::nullptr_t  ) const
inline

Definition at line 303 of file basedevice.h.

◆ registerProperty() [1/2]

void INDI::BaseDevice::registerProperty ( const INDI::Property &  property)

Register the property to be able to observe and update.

Parameters
propertyany property from the INDI::PropertyXXX family.

Definition at line 942 of file basedevice.cpp.

◆ registerProperty() [2/2]

void INDI::BaseDevice::registerProperty ( const INDI::Property &  property,
INDI_PROPERTY_TYPE  type 
)

Definition at line 958 of file basedevice.cpp.

◆ removeProperty()

int INDI::BaseDevice::removeProperty ( const char *  name,
char *  errmsg 
)

Remove a property.

Parameters
namename of property to be removed. Pass NULL to remove the whole device.
errmsgbuffer to store error message.
Returns
0 if successful, -1 otherwise.

Definition at line 171 of file basedevice.cpp.

◆ setDeviceName()

void INDI::BaseDevice::setDeviceName ( const char *  dev)

Set the device name.

Parameters
devnew device name

Definition at line 825 of file basedevice.cpp.

◆ setMediator()

void INDI::BaseDevice::setMediator ( INDI::BaseMediator *  mediator)

Set the driver's mediator to receive notification of news devices and updated property values.

Definition at line 988 of file basedevice.cpp.

◆ setValue()

int INDI::BaseDevice::setValue ( const INDI::LilXmlElement &  root,
char *  errmsg 
)

handle SetXXX commands from client

Definition at line 577 of file basedevice.cpp.

◆ watchProperty()

void INDI::BaseDevice::watchProperty ( const char *  name,
const std::function< void(INDI::Property)> &  callback,
WATCH  watch = WATCH_NEW 
)

Call the callback function if property is available.

Parameters
nameof property.
callbackas an argument of the function you can use INDI::PropertyNumber, INDI::PropertySwitch etc.
watchyou can decide whether the callback should be executed only once (WATCH_NEW) on discovery of the property or also on every change of the value (WATCH_UPDATE) or both (WATCH_NEW_OR_UPDATE)
Note
the behavior is analogous to BaseMediator::newProperty/updateProperty

Definition at line 928 of file basedevice.cpp.

Friends And Related Symbol Documentation

◆ AbstractBaseClientPrivate

friend class AbstractBaseClientPrivate
friend

Definition at line 318 of file basedevice.h.

Member Data Documentation

◆ d_ptr

std::shared_ptr<BaseDevicePrivate> INDI::BaseDevice::d_ptr
protected

Definition at line 319 of file basedevice.h.


The documentation for this class was generated from the following files: