Instrument Neutral Distributed Interface INDI  1.9.2
defaultdevice.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2011 Jasem Mutlaq. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 *******************************************************************************/
18 
19 #pragma once
20 
21 #include "basedevice.h"
22 #include "indidriver.h"
23 #include "indilogger.h"
24 
25 #include <stdint.h>
26 
27 namespace Connection
28 {
29 class Interface;
30 class Serial;
31 class TCP;
32 }
38 extern const char *COMMUNICATION_TAB;
39 
43 extern const char *MAIN_CONTROL_TAB;
44 
48 extern const char *CONNECTION_TAB;
49 
53 extern const char *MOTION_TAB;
54 
58 extern const char *DATETIME_TAB;
59 
63 extern const char *SITE_TAB;
64 
69 extern const char *OPTIONS_TAB;
70 
74 extern const char *FILTER_TAB;
75 
79 extern const char *FOCUS_TAB;
80 
84 extern const char *GUIDE_TAB;
85 
89 extern const char *ALIGNMENT_TAB;
90 
94 extern const char *SATELLITE_TAB;
95 
99 extern const char *INFO_TAB;
100 
114 namespace INDI
115 {
116 
117 class DefaultDevicePrivate;
118 class DefaultDevice : public BaseDevice
119 {
120  DECLARE_PRIVATE(DefaultDevice)
121 
122  public:
123  DefaultDevice();
124  virtual ~DefaultDevice() override = default;
125 
126  public:
128  void addAuxControls();
129 
131  void addDebugControl();
132 
134  void addSimulationControl();
135 
138 
140  void addPollPeriodControl();
141 
142  public:
144  void resetProperties();
145 
152  void defineNumber(INumberVectorProperty *nvp) __attribute__((deprecated));
153  void defineProperty(INumberVectorProperty *property);
154 
161  void defineText(ITextVectorProperty *tvp) __attribute__((deprecated));
162  void defineProperty(ITextVectorProperty *property);
163 
170  void defineSwitch(ISwitchVectorProperty *svp) __attribute__((deprecated));
171  void defineProperty(ISwitchVectorProperty *property);
172 
179  void defineLight(ILightVectorProperty *lvp) __attribute__((deprecated));
180  void defineProperty(ILightVectorProperty *property);
181 
188  void defineBLOB(IBLOBVectorProperty *bvp) __attribute__((deprecated));
189  void defineProperty(IBLOBVectorProperty *property);
190 
191  void defineProperty(INDI::Property &property);
196  virtual bool deleteProperty(const char *propertyName);
197 
198  public:
205  virtual void setConnected(bool status, IPState state = IPS_OK, const char *msg = nullptr);
206 
212  int SetTimer(uint32_t ms);
213 
218  void RemoveTimer(int id);
219 
221  virtual void TimerHit();
222 
224  virtual const char *getDriverExec();
225 
227  virtual const char *getDriverName();
228 
234  void setVersion(uint16_t vMajor, uint16_t vMinor);
235 
237  uint16_t getMajorVersion() const;
238 
240  uint16_t getMinorVersion() const;
241 
242  public:
257  virtual void ISGetProperties(const char *dev);
258 
264  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n);
265 
271  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n);
272 
278  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n);
279 
285  virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
286  char *formats[], char *names[], int n);
287 
294  virtual bool ISSnoopDevice(XMLEle *root);
295 
299  virtual uint16_t getDriverInterface() override;
300 
308  void setDriverInterface(uint16_t value);
309 
310  protected:
325  void setDynamicPropertiesBehavior(bool defineEnabled, bool deleteEnabled);
326 
327  // Configuration
328 
336  virtual bool loadConfig(bool silent = false, const char *property = nullptr);
337 
345  virtual bool saveConfig(bool silent = false, const char *property = nullptr);
346 
351  virtual bool purgeConfig();
352 
361  virtual bool saveConfigItems(FILE *fp);
362 
368  virtual bool saveAllConfigItems(FILE *fp);
369 
374  virtual bool loadDefaultConfig();
375 
376  // Simulatin & Debug
377 
383  void setDebug(bool enable);
384 
390  void setSimulation(bool enable);
391 
399  virtual void debugTriggered(bool enable);
400 
408  virtual void simulationTriggered(bool enable);
409 
411  bool isDebug() const;
412 
414  bool isSimulation() const;
415 
420  virtual bool initProperties();
421 
429  virtual bool updateProperties();
430 
438  virtual bool Connect();
439 
444  virtual bool Disconnect();
445 
451  void registerConnection(Connection::Interface *newConnection);
452 
458  bool unRegisterConnection(Connection::Interface *existingConnection);
459 
462 
467  void setActiveConnection(Connection::Interface *existingConnection);
468 
469  protected: // polling
475  void setDefaultPollingPeriod(uint32_t msec);
476 
482  void setPollingPeriodRange(uint32_t minimum, uint32_t maximum);
483 
488  uint32_t getPollingPeriod() const;
489 
495  void setCurrentPollingPeriod(uint32_t msec);
496 
501  uint32_t getCurrentPollingPeriod() const;
502 
503  /* direct access to POLLMS is deprecated, please use setCurrentPollingPeriod/getCurrentPollingPeriod */
504  uint32_t &refCurrentPollingPeriod() __attribute__((deprecated));
505  uint32_t refCurrentPollingPeriod() const __attribute__((deprecated));
506 #define POLLMS refCurrentPollingPeriod()
507 
508  protected:
513  bool isConfigLoading() const;
514 
516  void syncDriverInfo();
517 
518 
520  virtual const char *getDefaultName() = 0;
521 
522  private:
523  // Connection Plugins
524  friend class Connection::Serial;
525  friend class Connection::TCP;
526  friend class FilterInterface;
527 
528  protected:
530 
531 };
532 
533 }
INDI::DefaultDevice::simulationTriggered
virtual void simulationTriggered(bool enable)
Inform driver that the simulation option was triggered. This function is called after setSimulation i...
Definition: defaultdevice.cpp:745
INDI::DefaultDevice::resetProperties
void resetProperties()
Set all properties to IDLE state.
Definition: defaultdevice.cpp:838
ALIGNMENT_TAB
const char * ALIGNMENT_TAB
ALIGNMENT_TAB Where all the properties for guiding are located.
Definition: defaultdevice.cpp:43
COMMUNICATION_TAB
const char * COMMUNICATION_TAB
COMMUNICATION_TAB Where all the properties required to connect/disconnect from a device are located....
Definition: defaultdevice.cpp:33
basedevice.h
INDI::DefaultDevice::addAuxControls
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
Definition: defaultdevice.cpp:665
INDI::DefaultDevice::loadDefaultConfig
virtual bool loadDefaultConfig()
Load the default configuration file.
Definition: defaultdevice.cpp:386
IPState
IPState
Property state.
Definition: indiapi.h:158
IPS_OK
@ IPS_OK
Definition: indiapi.h:161
INDI::DefaultDevice::setConnected
virtual void setConnected(bool status, IPState state=IPS_OK, const char *msg=nullptr)
Set connection switch status in the client.
Definition: defaultdevice.cpp:847
_ILightVectorProperty
Light vector property descriptor.
Definition: indiapi.h:415
INDI::DefaultDevice::~DefaultDevice
virtual ~DefaultDevice() override=default
indidriver.h
INDI::DefaultDevice::DefaultDevice
DefaultDevice()
Definition: defaultdevice.cpp:134
Connection::Serial
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Definition: connectionserial.h:56
INDI::DefaultDevice::isSimulation
bool isSimulation() const
Definition: defaultdevice.cpp:734
Connection::TCP
The TCP class manages connection with devices over the network via TCP/IP. Upon successfull connectio...
Definition: connectiontcp.h:55
INDI::DefaultDevice::defineProperty
void defineProperty(INumberVectorProperty *property)
Definition: defaultdevice.cpp:997
_IBLOBVectorProperty
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:469
INDI::DefaultDevice::setDefaultPollingPeriod
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
Definition: defaultdevice.cpp:1157
FOCUS_TAB
const char * FOCUS_TAB
FOCUS_TAB Where all the properties for focuser are located.
Definition: defaultdevice.cpp:41
INDI::DefaultDevice::setVersion
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
Definition: defaultdevice.cpp:1219
INDI::DefaultDevice::purgeConfig
virtual bool purgeConfig()
purgeConfig Remove config file from disk.
Definition: defaultdevice.cpp:208
MOTION_TAB
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
Definition: defaultdevice.cpp:36
INDI::DefaultDevice::getDefaultName
virtual const char * getDefaultName()=0
INDI::DefaultDevice::addPollPeriodControl
void addPollPeriodControl()
Add Polling period control to the driver.
Definition: defaultdevice.cpp:659
INDI::DefaultDevice::setPollingPeriodRange
void setPollingPeriodRange(uint32_t minimum, uint32_t maximum)
setPollingPeriodRange Set the range permitted by the polling range in milliseconds
Definition: defaultdevice.cpp:1164
INDI::DefaultDevice::getDriverExec
virtual const char * getDriverExec()
Definition: defaultdevice.cpp:1209
INDI::DefaultDevice::defineLight
void defineLight(ILightVectorProperty *lvp) __attribute__((deprecated))
Define light vector to client & register it. Alternatively, IDDeflight can be used but the property w...
Definition: defaultdevice.cpp:1048
INDI::DefaultDevice::unRegisterConnection
bool unRegisterConnection(Connection::Interface *existingConnection)
unRegisterConnection Remove connection from existing pool
Definition: defaultdevice.cpp:1113
INDI::DefaultDevice::TimerHit
virtual void TimerHit()
Callback function to be called once SetTimer duration elapses.
Definition: defaultdevice.cpp:885
INDI::DefaultDevice::initProperties
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
Definition: defaultdevice.cpp:917
INDI::DefaultDevice::isConfigLoading
bool isConfigLoading() const
isConfigLoading Check if driver configuration is currently in the process of getting loaded.
Definition: defaultdevice.cpp:1257
INDI::Property
Provides generic container for INDI properties.
Definition: indiproperty.h:43
indilogger.h
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
INDI::DefaultDevice::getCurrentPollingPeriod
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
Definition: defaultdevice.cpp:1139
INDI::FilterInterface
Definition: indifilterinterface.h:45
INDI::DefaultDevice::addConfigurationControl
void addConfigurationControl()
Add Configuration control to the driver.
Definition: defaultdevice.cpp:653
INDI::DefaultDevice::defineSwitch
void defineSwitch(ISwitchVectorProperty *svp) __attribute__((deprecated))
Define switch vector to client & register it. Alternatively, IDDefswitch can be used but the property...
Definition: defaultdevice.cpp:1043
INDI::DefaultDevice::ISSnoopDevice
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: defaultdevice.cpp:633
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
INDI::DefaultDevice::SetTimer
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
Definition: defaultdevice.cpp:865
INDI::DefaultDevice::debugTriggered
virtual void debugTriggered(bool enable)
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
Definition: defaultdevice.cpp:740
INDI::DefaultDevice::Connect
virtual bool Connect()
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: defaultdevice.cpp:1058
INDI::DefaultDevice::getMajorVersion
uint16_t getMajorVersion() const
Definition: defaultdevice.cpp:1226
INDI::DefaultDevice::getDriverInterface
virtual uint16_t getDriverInterface() override
Definition: defaultdevice.cpp:896
INDI::DefaultDevice::getPollingPeriod
uint32_t getPollingPeriod() const
getPollingPeriod Return the polling period.
Definition: defaultdevice.cpp:1251
INDI::DefaultDevice::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition: defaultdevice.cpp:593
INDI::DefaultDevice::syncDriverInfo
void syncDriverInfo()
syncDriverInfo sends the current driver information to the client.
Definition: defaultdevice.cpp:911
INDI::DefaultDevicePrivate
Definition: defaultdevice_p.h:51
INDI::DefaultDevice::defineNumber
void defineNumber(INumberVectorProperty *nvp) __attribute__((deprecated))
Define number vector to client & register it. Alternatively, IDDefNumber can be used but the property...
Definition: defaultdevice.cpp:1033
INDI::DefaultDevice::registerConnection
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
Definition: defaultdevice.cpp:1107
xml_ele_
Definition: lilxml.c:105
INDI::DefaultDevice::getDriverName
virtual const char * getDriverName()
Definition: defaultdevice.cpp:1214
INDI::DefaultDevice::loadConfig
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
Definition: defaultdevice.cpp:147
DATETIME_TAB
const char * DATETIME_TAB
DATETIME_TAB Where all date and time setting properties are located.
Definition: defaultdevice.cpp:37
INDI::DefaultDevice::isDebug
bool isDebug() const
Definition: defaultdevice.cpp:728
INDI::DefaultDevice::setSimulation
void setSimulation(bool enable)
Toggle driver simulation status A driver can run in simulation mode if Simulation option is enabled b...
Definition: defaultdevice.cpp:703
INDI::DefaultDevice::setDebug
void setDebug(bool enable)
Toggle driver debug status A driver can be more verbose if Debug option is enabled by the client.
Definition: defaultdevice.cpp:673
FILTER_TAB
const char * FILTER_TAB
FILTER_TAB Where all the properties for filter wheels are located.
Definition: defaultdevice.cpp:40
INFO_TAB
const char * INFO_TAB
INFO_TAB Where all the properties for general information are located.
Definition: defaultdevice.cpp:45
INDI::DefaultDevice::setActiveConnection
void setActiveConnection(Connection::Interface *existingConnection)
setActiveConnection Switch the active connection to the passed connection plugin
Definition: defaultdevice.cpp:1172
Connection
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:33
INDI::DefaultDevice::ISGetProperties
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition: defaultdevice.cpp:750
OPTIONS_TAB
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
Definition: defaultdevice.cpp:39
INDI::DefaultDevice::saveConfig
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
Definition: defaultdevice.cpp:221
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
INDI::DefaultDevice::getMinorVersion
uint16_t getMinorVersion() const
Definition: defaultdevice.cpp:1232
INDI::DefaultDevice::ISNewBLOB
virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Process the client newBLOB command.
Definition: defaultdevice.cpp:623
INDI::DefaultDevice::saveConfigItems
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: defaultdevice.cpp:175
INDI::DefaultDevice::defineBLOB
void defineBLOB(IBLOBVectorProperty *bvp) __attribute__((deprecated))
Define BLOB vector to client & register it. Alternatively, IDDefBLOB can be used but the property wil...
Definition: defaultdevice.cpp:1053
GUIDE_TAB
const char * GUIDE_TAB
GUIDE_TAB Where all the properties for guiding are located.
Definition: defaultdevice.cpp:42
INDI::DefaultDevice::setCurrentPollingPeriod
void setCurrentPollingPeriod(uint32_t msec)
setCurrentPollingPeriod Change the current polling period to call TimerHit() function in the driver.
Definition: defaultdevice.cpp:1133
INDI::DefaultDevice::saveAllConfigItems
virtual bool saveAllConfigItems(FILE *fp)
saveAllConfigItems Save all the drivers' properties in the configuration file
Definition: defaultdevice.cpp:189
INDI::DefaultDevice::RemoveTimer
void RemoveTimer(int id)
Remove timer added with SetTimer.
Definition: defaultdevice.cpp:874
ISState
ISState
Switch state.
Definition: indiapi.h:148
Connection::Interface
The Interface class is the base class for all INDI connection plugins.
Definition: connectioninterface.h:51
INDI::DefaultDevice::defineText
void defineText(ITextVectorProperty *tvp) __attribute__((deprecated))
Define text vector to client & register it. Alternatively, IDDefText can be used but the property wil...
Definition: defaultdevice.cpp:1038
INDI::DefaultDevice::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition: defaultdevice.cpp:409
__attribute__
enum @207 __attribute__
INDI::DefaultDevice::addSimulationControl
void addSimulationControl()
Add Simulation control to the driver.
Definition: defaultdevice.cpp:646
SITE_TAB
const char * SITE_TAB
SITE_TAB Where all site information setting are located.
Definition: defaultdevice.cpp:38
INDI::DefaultDevice::refCurrentPollingPeriod
uint32_t & refCurrentPollingPeriod() __attribute__((deprecated))
Definition: defaultdevice.cpp:1145
INDI::DefaultDevice::addDebugControl
void addDebugControl()
Add Debug control to the driver.
Definition: defaultdevice.cpp:639
INDI::DefaultDevice::Disconnect
virtual bool Disconnect()
Disconnect from device.
Definition: defaultdevice.cpp:1083
INDI::DefaultDevice
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
Definition: defaultdevice.h:118
INDI::DefaultDevice::deleteProperty
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
Definition: defaultdevice.cpp:965
INDI::DefaultDevice::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
Definition: defaultdevice.cpp:614
INDI::BaseDevice
Class to provide basic INDI device functionality.
Definition: basedevice.h:45
CONNECTION_TAB
const char * CONNECTION_TAB
CONNECTION_TAB Where all device connection settings (serial, usb, ethernet) are defined and controlle...
Definition: connectioninterface.cpp:41
INDI::DefaultDevice::setDriverInterface
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
Definition: defaultdevice.cpp:902
SATELLITE_TAB
const char * SATELLITE_TAB
SATELLITE_TAB.
Definition: defaultdevice.cpp:44
INDI::DefaultDevice::updateProperties
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: defaultdevice.cpp:890
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
INDI::DefaultDevice::getActiveConnection
Connection::Interface * getActiveConnection()
Definition: defaultdevice.cpp:1245
MAIN_CONTROL_TAB
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
Definition: defaultdevice.cpp:34
INDI::DefaultDevice::setDynamicPropertiesBehavior
void setDynamicPropertiesBehavior(bool defineEnabled, bool deleteEnabled)
setDynamicPropertiesBehavior controls handling of dynamic properties. Dyanmic properties are those ge...
Definition: defaultdevice.cpp:1238