Instrument Neutral Distributed Interface INDI 2.2.5
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#include <any>
27#include <string>
28#include <functional>
29
30namespace Connection
31{
32class Interface;
33class Serial;
34class TCP;
35class I2C;
36}
42extern const char *COMMUNICATION_TAB;
43
47extern const char *MAIN_CONTROL_TAB;
48
52extern const char *CONNECTION_TAB;
53
57extern const char *MOTION_TAB;
58
62extern const char *DATETIME_TAB;
63
67extern const char *SITE_TAB;
68
73extern const char *OPTIONS_TAB;
74
78extern const char *FILTER_TAB;
79
83extern const char *FOCUS_TAB;
84
88extern const char *GUIDE_TAB;
89
93extern const char *ALIGNMENT_TAB;
94
98extern const char *SATELLITE_TAB;
99
103extern const char *INFO_TAB;
104
118namespace INDI
119{
120
121class DefaultDevicePrivate;
123{
124 DECLARE_PRIVATE(DefaultDevice)
125
126 public:
128 virtual ~DefaultDevice() override = default;
129
130 public:
132 void addAuxControls();
133
135 void addDebugControl();
136
139
142
145
147 void addNicknameControl();
148
149 public:
151 void resetProperties();
152
159 INDI_DEPRECATED("Use defineProperty(INDI::Property &).")
162
171 void defineProperty(ITextVectorProperty *property);
172
182
191 void defineProperty(ILightVectorProperty *property);
192
201 void defineProperty(IBLOBVectorProperty *property);
202
203 void defineProperty(INDI::Property &property);
208 virtual bool deleteProperty(const char *propertyName);
209
216 bool deleteProperty(INDI::Property &property);
217
218 public:
225 virtual void setConnected(bool status, IPState state = IPS_OK, const char *msg = nullptr);
226
232 int SetTimer(uint32_t ms);
233
238 void RemoveTimer(int id);
239
241 virtual void TimerHit();
242
244 virtual const char *getDriverExec();
245
247 virtual const char *getDriverName();
248
254 void setVersion(uint16_t vMajor, uint16_t vMinor);
255
257 uint16_t getMajorVersion() const;
258
260 uint16_t getMinorVersion() const;
261
262 public:
277 virtual void ISGetProperties(const char *dev);
278
284 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n);
285
291 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n);
292
298 virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n);
299
305 virtual bool ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[],
306 char *formats[], char *names[], int n);
307
314 virtual bool ISSnoopDevice(XMLEle *root);
315
334 bool ISNewProperty(INDI::Property &property, const std::string &elementName, const std::any &value);
335
355 template<typename PropertyType, typename ValueType>
356 bool updateProperty(PropertyType& property, ValueType* values, char* names[], int n,
357 std::function<bool()> updater, bool saveConfig = false)
358 {
359 if (property.isUpdated(values, names, n))
360 {
361 if (updater())
362 {
363 property.update(values, names, n);
364 property.setState(IPS_OK);
365 if (saveConfig)
366 this->saveConfig(property);
367 property.apply();
368 return true;
369 }
370 else
371 {
372 property.setState(IPS_ALERT);
373 property.apply();
374 return false;
375 }
376 }
377 else
378 {
379 // If nothing is updated, just accept as-is
380 property.setState(IPS_OK);
381 property.apply();
382 return false;
383 }
384 }
385
389 uint32_t getDriverInterface() const;
390
398 void setDriverInterface(uint32_t value);
399
400 public:
405 void watchDevice(const char *deviceName, const std::function<void (INDI::BaseDevice)> &callback);
406
407 protected:
422 void setDynamicPropertiesBehavior(bool defineEnabled, bool deleteEnabled);
423
424 // Configuration
425
433 virtual bool loadConfig(bool silent = false, const char *property = nullptr);
434
442 bool loadConfig(INDI::Property &property);
443
451 virtual bool saveConfig(bool silent = false, const char *property = nullptr);
452
459 bool saveConfig(INDI::Property &property);
460
465 virtual bool purgeConfig();
466
475 virtual bool saveConfigItems(FILE *fp);
476
482 virtual bool saveAllConfigItems(FILE *fp);
483
488 virtual bool loadDefaultConfig();
489
490 // Simulatin & Debug
491
497 void setDebug(bool enable);
498
504 void setSimulation(bool enable);
505
513 virtual void debugTriggered(bool enable);
514
522 virtual void simulationTriggered(bool enable);
523
525 bool isDebug() const;
526
528 bool isSimulation() const;
529
534 virtual bool initProperties();
535
543 virtual bool updateProperties();
544
552 virtual bool Connect();
553
558 virtual bool Disconnect();
559
565 void registerConnection(Connection::Interface *newConnection);
566
572 bool unRegisterConnection(Connection::Interface *existingConnection);
573
576
581 void setActiveConnection(Connection::Interface *existingConnection);
582
583 protected: // polling
589 void setDefaultPollingPeriod(uint32_t msec);
590
596 void setPollingPeriodRange(uint32_t minimum, uint32_t maximum);
597
602 uint32_t getPollingPeriod() const;
603
609 void setCurrentPollingPeriod(uint32_t msec);
610
615 uint32_t getCurrentPollingPeriod() const;
616
617 /* direct access to POLLMS is deprecated, please use setCurrentPollingPeriod/getCurrentPollingPeriod */
618 uint32_t &refCurrentPollingPeriod() __attribute__((deprecated));
619 uint32_t refCurrentPollingPeriod() const __attribute__((deprecated));
620#define POLLMS refCurrentPollingPeriod()
621
622 protected:
627 bool isConfigLoading() const;
628
634 bool isInitializationComplete() const;
635
637 void syncDriverInfo();
638
640 virtual const char *getDefaultName() = 0;
641
649 void setDeviceNickname(const char *nick);
650
652 const char *getDeviceNickname();
653
661 const char *lookupDeviceNicknameFromId(const char *identifier, const char *device = nullptr);
662
666 bool setDeviceNicknameFromId(const char *identifier);
667
668 void saveNicknameId(const char *nickname, const char *identifier);
669
677 virtual void nicknameSet(const char *nickname);
678
679 private:
680 // Connection Plugins
681 friend class Connection::Serial;
682 friend class Connection::TCP;
683 friend class Connection::I2C;
684 friend class FilterInterface;
685 friend class FocuserInterface;
686 friend class WeatherInterface;
687 friend class LightBoxInterface;
688 friend class OutputInterface;
689 friend class InputInterface;
690 friend class PowerInterface;
691 friend class IMUInterface;
692 friend class PACInterface;
693
694 protected:
695 DefaultDevice(const std::shared_ptr<DefaultDevicePrivate> &dd);
696};
697
698}
hid_device * device
__attribute__((__format__(__printf__, 2, 0))) void CelestronDriver
The I2C class manages connection with I2C devices on Linux systems. I2C communication is commonly use...
The Interface class is the base class for all INDI connection plugins.
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 successful connection...
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.
bool updateProperty(PropertyType &property, ValueType *values, char *names[], int n, std::function< bool()> updater, bool saveConfig=false)
Generic helper function to update an INDI property based on an external operation.
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. Dynamic 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.
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.
const char * lookupDeviceNicknameFromId(const char *identifier, const char *device=nullptr)
Lookup device nickname for an identifier.
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 setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
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)
void saveNicknameId(const char *nickname, const char *identifier)
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...
virtual const char * getDefaultName()=0
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()
Initialize 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.
void setDeviceNickname(const char *nick)
Set the device nickname.
bool ISNewProperty(INDI::Property &property, const std::string &elementName, const std::any &value)
Generic convenience function to update a property element as if by client request,...
virtual bool saveAllConfigItems(FILE *fp)
saveAllConfigItems Save all the drivers' properties in the configuration file
uint32_t getDriverInterface() const
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 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()
void addNicknameControl()
Add Nickname text property to the driver.
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
const char * getDeviceNickname()
bool setDeviceNicknameFromId(const char *identifier)
Set device nickname based on an identifier.
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...
virtual void nicknameSet(const char *nickname)
Inform driver that the nickname has been set.
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...
Provides generic container for INDI properties.
Provides interface to implement weather reporting and safety monitoring functionality.
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:148
IPState
Property state.
Definition indiapi.h:158
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_OK
Definition indiapi.h:160
#define INDI_DEPRECATED(message)
Definition indimacros.h:309
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.
BLOB (Binary Large Object) vector property descriptor.
Definition indiapi.h:469
Light vector property descriptor.
Definition indiapi.h:415
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365
Text vector property descriptor.
Definition indiapi.h:244