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
122class DefaultDevice : public ParentDevice
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
169 INDI_DEPRECATED("Use defineProperty(INDI::Property &).")
171 void defineProperty(ITextVectorProperty *property);
172
179 INDI_DEPRECATED("Use defineProperty(INDI::Property &).")
182
189 INDI_DEPRECATED("Use defineProperty(INDI::Property &).")
191 void defineProperty(ILightVectorProperty *property);
192
199 INDI_DEPRECATED("Use defineProperty(INDI::Property &).")
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
575 Connection::Interface *getActiveConnection();
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...
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.
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.
void defineBLOB(IBLOBVectorProperty *bvp)
Define BLOB vector to client & register it. Alternatively, IDDefBLOB can be used but the property wil...
virtual bool saveConfig(bool silent=false, const char *property=nullptr)
Save the current properties in a configuration file.
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.
friend class IMUInterface
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...
virtual void setConnected(bool status, IPState state=IPS_OK, const char *msg=nullptr)
Set connection switch status in the client.
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
friend class WeatherInterface
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
friend class FilterInterface
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
void saveNicknameId(const char *nickname, const char *identifier)
virtual void TimerHit()
Callback function to be called once SetTimer duration elapses.
void defineText(ITextVectorProperty *tvp)
Define text vector to client & register it. Alternatively, IDDefText can be used but the property wil...
friend class OutputInterface
virtual const char * getDefaultName()=0
friend class InputInterface
friend class FocuserInterface
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 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()
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.
void RemoveTimer(int id)
Remove timer added with SetTimer.
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.
friend class LightBoxInterface
DefaultDevice(const std::shared_ptr< DefaultDevicePrivate > &dd)
virtual const char * getDriverExec()
uint16_t getMinorVersion() const
virtual void nicknameSet(const char *nickname)
Inform driver that the nickname has been set.
friend class PowerInterface
void addDebugControl()
Add Debug control to the driver.
friend class PACInterface
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
Provides generic container for INDI properties.
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 * 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
struct _IBLOBVectorProperty IBLOBVectorProperty
IPState
Property state.
Definition indiapi.h:158
@ IPS_OK
Definition indiapi.h:160
struct _ISwitchVectorProperty ISwitchVectorProperty
struct _ITextVectorProperty ITextVectorProperty
struct _ILightVectorProperty ILightVectorProperty
struct _INumberVectorProperty INumberVectorProperty
*brief user defined string literal for JSON values *sa std::size_t n
#define INDI_DEPRECATED(message)
Definition indimacros.h:309
struct xml_ele_ XMLEle
Definition lilxml.h:81
#define ALIGNMENT_TAB
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.