Instrument Neutral Distributed Interface INDI  2.0.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 "parentdevice.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;
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  INDI_DEPRECATED("Use defineProperty(INDI::Property &).")
154  void defineProperty(INumberVectorProperty *property);
155 
163  void defineText(ITextVectorProperty *tvp);
164  void defineProperty(ITextVectorProperty *property);
165 
174  void defineProperty(ISwitchVectorProperty *property);
175 
184  void defineProperty(ILightVectorProperty *property);
185 
193  void defineBLOB(IBLOBVectorProperty *bvp);
194  void defineProperty(IBLOBVectorProperty *property);
195 
196  void defineProperty(INDI::Property &property);
201  virtual bool deleteProperty(const char *propertyName);
202 
209  bool deleteProperty(INDI::Property &property);
210 
211  public:
218  virtual void setConnected(bool status, IPState state = IPS_OK, const char *msg = nullptr);
219 
225  int SetTimer(uint32_t ms);
226 
231  void RemoveTimer(int id);
232 
234  virtual void TimerHit();
235 
237  virtual const char *getDriverExec();
238 
240  virtual const char *getDriverName();
241 
247  void setVersion(uint16_t vMajor, uint16_t vMinor);
248 
250  uint16_t getMajorVersion() const;
251 
253  uint16_t getMinorVersion() const;
254 
255  public:
270  virtual void ISGetProperties(const char *dev);
271 
277  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n);
278 
284  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n);
285 
291  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n);
292 
298  virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
299  char *formats[], char *names[], int n);
300 
307  virtual bool ISSnoopDevice(XMLEle *root);
308 
312  uint16_t getDriverInterface() const;
313 
321  void setDriverInterface(uint16_t value);
322 
323  public:
328  void watchDevice(const char *deviceName, const std::function<void (INDI::BaseDevice)> &callback);
329 
330  protected:
345  void setDynamicPropertiesBehavior(bool defineEnabled, bool deleteEnabled);
346 
347  // Configuration
348 
356  virtual bool loadConfig(bool silent = false, const char *property = nullptr);
357 
365  bool loadConfig(INDI::Property &property);
366 
374  virtual bool saveConfig(bool silent = false, const char *property = nullptr);
375 
382  bool saveConfig(INDI::Property &property);
383 
388  virtual bool purgeConfig();
389 
398  virtual bool saveConfigItems(FILE *fp);
399 
405  virtual bool saveAllConfigItems(FILE *fp);
406 
411  virtual bool loadDefaultConfig();
412 
413  // Simulatin & Debug
414 
420  void setDebug(bool enable);
421 
427  void setSimulation(bool enable);
428 
436  virtual void debugTriggered(bool enable);
437 
445  virtual void simulationTriggered(bool enable);
446 
448  bool isDebug() const;
449 
451  bool isSimulation() const;
452 
457  virtual bool initProperties();
458 
466  virtual bool updateProperties();
467 
475  virtual bool Connect();
476 
481  virtual bool Disconnect();
482 
488  void registerConnection(Connection::Interface *newConnection);
489 
495  bool unRegisterConnection(Connection::Interface *existingConnection);
496 
498  Connection::Interface *getActiveConnection();
499 
504  void setActiveConnection(Connection::Interface *existingConnection);
505 
506  protected: // polling
512  void setDefaultPollingPeriod(uint32_t msec);
513 
519  void setPollingPeriodRange(uint32_t minimum, uint32_t maximum);
520 
525  uint32_t getPollingPeriod() const;
526 
532  void setCurrentPollingPeriod(uint32_t msec);
533 
538  uint32_t getCurrentPollingPeriod() const;
539 
540  /* direct access to POLLMS is deprecated, please use setCurrentPollingPeriod/getCurrentPollingPeriod */
541  uint32_t &refCurrentPollingPeriod() __attribute__((deprecated));
542  uint32_t refCurrentPollingPeriod() const __attribute__((deprecated));
543 #define POLLMS refCurrentPollingPeriod()
544 
545  protected:
550  bool isConfigLoading() const;
551 
557  bool isInitializationComplete() const;
558 
560  void syncDriverInfo();
561 
562 
564  virtual const char *getDefaultName() = 0;
565 
566  private:
567  // Connection Plugins
568  friend class Connection::Serial;
569  friend class Connection::TCP;
570  friend class FilterInterface;
571  friend class FocuserInterface;
572 
573  protected:
574  DefaultDevice(const std::shared_ptr<DefaultDevicePrivate> &dd);
575 };
576 
577 }
__attribute__((__format__(__printf__, 2, 0))) void CelestronDriver
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
The TCP class manages connection with devices over the network via TCP/IP. Upon successfull connectio...
Definition: connectiontcp.h:38
Class to provide basic INDI device functionality.
Definition: basedevice.h:52
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
void defineSwitch(ISwitchVectorProperty *svp)
Define switch vector to client & register it. Alternatively, IDDefswitch can be used but the property...
void addPollPeriodControl()
Add Polling period control to the driver.
virtual bool purgeConfig()
purgeConfig Remove config file from disk.
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
void setSimulation(bool enable)
Toggle driver simulation status A driver can run in simulation mode if Simulation option is enabled b...
void defineBLOB(IBLOBVectorProperty *bvp)
Define BLOB vector to client & register it. Alternatively, IDDefBLOB can be used but the property wil...
void setDynamicPropertiesBehavior(bool defineEnabled, bool deleteEnabled)
setDynamicPropertiesBehavior controls handling of dynamic properties. Dyanmic properties are those ge...
bool isInitializationComplete() const
isInitializationComplete Check if driver initialization is complete.
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
virtual const char * getDefaultName()=0
void setCurrentPollingPeriod(uint32_t msec)
setCurrentPollingPeriod Change the current polling period to call TimerHit() function in the driver.
void addConfigurationControl()
Add Configuration control to the driver.
virtual ~DefaultDevice() override=default
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
uint16_t getMajorVersion() const
void addSimulationControl()
Add Simulation control to the driver.
virtual bool Disconnect()
Disconnect from device.
void setPollingPeriodRange(uint32_t minimum, uint32_t maximum)
setPollingPeriodRange Set the range permitted by the polling range in milliseconds
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
void setDefaultPollingPeriod(uint32_t msec)
setDefaultPollingPeriod Change the default polling period to call TimerHit() function in the driver.
void defineNumber(INumberVectorProperty *nvp)
Define number vector to client & register it. Alternatively, IDDefNumber can be used but the property...
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
void setActiveConnection(Connection::Interface *existingConnection)
setActiveConnection Switch the active connection to the passed connection plugin
bool isConfigLoading() const
isConfigLoading Check if driver configuration is currently in the process of getting loaded.
virtual void setConnected(bool status, IPState state=IPS_OK, const char *msg=nullptr)
Set connection switch status in the client.
uint32_t & refCurrentPollingPeriod() __attribute__((deprecated))
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool loadConfig(bool silent=false, const char *property=nullptr)
Load the last saved configuration file.
bool unRegisterConnection(Connection::Interface *existingConnection)
unRegisterConnection Remove connection from existing pool
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.
uint32_t getPollingPeriod() const
getPollingPeriod Return the polling period.
virtual void simulationTriggered(bool enable)
Inform driver that the simulation option was triggered. This function is called after setSimulation i...
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual void TimerHit()
Callback function to be called once SetTimer duration elapses.
uint32_t getCurrentPollingPeriod() const
getCurrentPollingPeriod Return the current polling period.
void defineText(ITextVectorProperty *tvp)
Define text vector to client & register it. Alternatively, IDDefText can be used but the property wil...
void setDebug(bool enable)
Toggle driver debug status A driver can be more verbose if Debug option is enabled by the client.
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
bool isSimulation() const
void syncDriverInfo()
syncDriverInfo sends the current driver information to the client.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
virtual bool saveAllConfigItems(FILE *fp)
saveAllConfigItems Save all the drivers' properties in the configuration file
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.
virtual const char * getDriverName()
virtual bool loadDefaultConfig()
Load the default configuration file.
void defineLight(ILightVectorProperty *lvp)
Define light vector to client & register it. Alternatively, IDDeflight can be used but the property w...
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void resetProperties()
Set all properties to IDLE state.
virtual void debugTriggered(bool enable)
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
void RemoveTimer(int id)
Remove timer added with SetTimer.
Connection::Interface * getActiveConnection()
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
DefaultDevice(const std::shared_ptr< DefaultDevicePrivate > &dd)
virtual const char * getDriverExec()
uint16_t getMinorVersion() const
virtual bool Connect()
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
uint16_t getDriverInterface() const
void addDebugControl()
Add Debug control to the driver.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
Provides interface to implement focuser functionality.
The class is used to create device instances. Class copying is not allowed. When an object is destroy...
Definition: parentdevice.h:18
Provides generic container for INDI properties.
Definition: indiproperty.h:48
const char * GUIDE_TAB
GUIDE_TAB Where all the properties for guiding are located.
const char * CONNECTION_TAB
CONNECTION_TAB Where all device connection settings (serial, usb, ethernet) are defined and controlle...
const char * FILTER_TAB
FILTER_TAB Where all the properties for filter wheels are located.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
const char * DATETIME_TAB
DATETIME_TAB Where all date and time setting properties are located.
const char * SATELLITE_TAB
SATELLITE_TAB.
const char * COMMUNICATION_TAB
COMMUNICATION_TAB Where all the properties required to connect/disconnect from a device are located....
const char * INFO_TAB
INFO_TAB Where all the properties for general information are located.
const char * MOTION_TAB
MOTION_TAB Where all the motion control properties of the device are located.
const char * ALIGNMENT_TAB
ALIGNMENT_TAB Where all the properties for guiding are located.
const char * SITE_TAB
SITE_TAB Where all site information setting are located.
const char * FOCUS_TAB
FOCUS_TAB Where all the properties for focuser are located.
const char * OPTIONS_TAB
OPTIONS_TAB Where all the driver's options are located. Those may include auxiliary controls,...
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
@ IPS_OK
Definition: indiapi.h:162
#define INDI_DEPRECATED(message)
Definition: indimacros.h:162
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition: arduino_st4.h:34
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: json.h:4973
BLOB (Binary Large Object) vector property descriptor.
Definition: indiapi.h:471
Light vector property descriptor.
Definition: indiapi.h:417
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246