source: BAORadio/libindi/libindi/libs/indibase/defaultdriver.h @ 642

Last change on this file since 642 was 642, checked in by frichard, 12 years ago

-Alignement des antennes
-Version 0.0.9 de libindi

File size: 9.4 KB
Line 
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#ifndef INDIDEFAULTDRIVER_H
20#define INDIDEFAULTDRIVER_H
21
22#include "basedriver.h"
23#include "indidriver.h"
24
25#include <auto_ptr.h>
26
27extern const char *COMMUNICATION_TAB;
28extern const char *MAIN_CONTROL_TAB;
29extern const char *MOTION_TAB;
30extern const char *DATETIME_TAB;
31extern const char *SITE_TAB;
32extern const char *OPTIONS_TAB;
33extern const char *FILTER_TAB;
34extern const char *GUIDER_TAB;
35
36/**
37 * \class INDI::DefaultDriver
38   \brief Class to provide extended functionality for drivers in addition
39to the functionality provided by INDI::BaseDriver. This class should \e only be subclassed by
40drivers directly as it is linked with main(). Virtual drivers cannot employ INDI::DefaultDriver.
41
42   INDI::DefaultDriver provides capability to add Debug, Simulation, and Configuration controls. These controls (switches) are
43   defined to the client. Configuration options permit saving and loading of AS-IS property values.
44
45\see <a href='tutorial__four_8h_source.html'>Tutorial Four</a>
46\author Jasem Mutlaq
47 */
48class INDI::DefaultDriver : public INDI::BaseDriver
49{
50public:
51    DefaultDriver();
52    virtual ~DefaultDriver();
53
54    /** \brief Add Debug, Simulation, and Configuration options to the driver */
55    void addAuxControls();
56
57    /** \brief Add Debug control to the driver */
58    void addDebugControl();
59
60    /** \brief Add Simulation control to the driver */
61    void addSimulationControl();
62
63    /** \brief Add Configuration control to the driver */
64    void addConfigurationControl();
65
66    /** \brief Set all properties to IDLE state */
67    void resetProperties();
68
69    /** \brief Define number vector to client & register it. Alternatively, IDDefNumber can be used but the property will not
70               get registered and the driver will not be able to save configuration files.
71         \param nvp The number vector property to be defined
72    */
73    void defineNumber(INumberVectorProperty *nvp);
74
75    /** \brief Define text vector to client & register it. Alternatively, IDDefText can be used but the property will not
76               get registered and the driver will not be able to save configuration files.
77         \param tvp The text vector property to be defined
78    */
79    void defineText(ITextVectorProperty *tvp);
80
81    /** \brief Define switch vector to client & register it. Alternatively, IDDefswitch can be used but the property will not
82               get registered and the driver will not be able to save configuration files.
83         \param svp The switch vector property to be defined
84    */
85    void defineSwitch(ISwitchVectorProperty *svp);
86
87    /** \brief Define light vector to client & register it. Alternatively, IDDeflight can be used but the property will not
88               get registered and the driver will not be able to save configuration files.
89         \param lvp The light vector property to be defined
90    */
91    void defineLight(ILightVectorProperty *lvp);
92
93    /** \brief Define BLOB vector to client & register it. Alternatively, IDDefBLOB can be used but the property will not
94               get registered and the driver will not be able to save configuration files.
95         \param bvp The BLOB vector property to be defined
96    */
97    void defineBLOB(IBLOBVectorProperty *bvp);
98
99
100    /** \brief Delete a property and unregister it. It will also be deleted from all clients.
101        \param propertyName name of property to be deleted.
102    */
103    virtual bool deleteProperty(const char *propertyName);
104
105
106    /** \brief Set connection switch status in the client.
107      \param status If true, the driver will attempt to connect to the device (CONNECT=ON). If false, it will attempt
108to disconnect the device.
109      \param status True to set CONNECT on, false to set DISCONNECT on.
110      \param state State of CONNECTION properti, by default IPS_OK.
111      \param msg A message to be sent along with connect/disconnect command, by default NULL.
112    */
113    virtual void setConnected(bool status, IPState state=IPS_OK, const char *msg = NULL);
114
115    /** \brief Set a timer to call the function TimerHit after ms milliseconds
116        \param ms timer duration in milliseconds.
117        \return id of the timer to be used with RemoveTimer
118   */
119    int SetTimer(int ms);
120
121    /** \brief Remove timer added with SetTimer
122        \param id ID of the timer as returned from SetTimer
123   */
124    void RemoveTimer(int id);
125
126    /** \brief Callback function to be called once SetTimer duration elapses. */
127    virtual void TimerHit();
128
129protected:
130
131    /** \brief define the driver's properties to the client.
132      \param dev name of the device
133      \note This function is called by the INDI framework, do not call it directly.
134    */
135    virtual void ISGetProperties (const char *dev);
136
137    /** \brief Process the client newSwitch command
138      \note This function is called by the INDI framework, do not call it directly.
139      \returns True if any property was successfully processed, false otherwise.
140    */
141    virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
142
143    /** \brief Process the client newNumber command
144      \note This function is called by the INDI framework, do not call it directly.
145      \returns True if any property was successfully processed, false otherwise.
146    */
147    virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n) {return false;}
148
149    /** \brief Process the client newSwitch command
150      \note This function is called by the INDI framework, do not call it directly.
151      \returns True if any property was successfully processed, false otherwise.
152    */
153    virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n) {return false;}
154
155    // Configuration
156
157    /** \brief Load the last saved configuration file
158        \return True if successful, false otherwise.
159    */
160    virtual bool loadConfig();
161
162    /** \brief Save the current properties in a configuration file
163        \return True if successful, false otherwise.
164    */
165    virtual bool saveConfig();
166    virtual bool saveConfigItems(FILE *fp);
167
168    /** \brief Load the default configuration file
169        \return True if successful, false otherwise.
170    */
171    virtual bool loadDefaultConfig();
172
173
174    // Simulatin & Debug
175
176    /** \brief Toggle driver debug status
177
178      A driver can be more verbose if Debug option is enabled by the client.
179
180      \param enable If true, the Debug option is set to ON.
181    */
182    void setDebug(bool enable);
183
184    /** \brief Toggle driver simulation status
185
186      A driver can run in simulation mode if Simulation option is enabled by the client.
187
188      \param enable If true, the Simulation option is set to ON.
189    */
190    void setSimulation(bool enable);
191
192    /** \return True if Debug is on, False otherwise. */
193    bool isDebug();
194
195    /** \return True if Simulation is on, False otherwise. */
196    bool isSimulation();
197
198    //  These are the properties we define, that are generic to pretty much all devices
199    //  They are public to make them available to all dervied classes and thier children
200    ISwitchVectorProperty *ConnectionSP;
201    ISwitch ConnectionS[2];
202
203
204    /** \brief Initilize properties initial state and value. The child class must implement this function.
205        \return True if initilization is successful, false otherwise.
206    */
207    virtual bool initProperties();
208
209    /** \brief updateProperties is called whenever there is a change in the CONNECTION status of the driver.
210        This will enable the driver to react to changes of switching ON/OFF a device. For example, a driver
211        may only define a set of properties after a device is connected, but not before.
212        \return True if update is successful, false otherwise.
213    */
214    virtual bool updateProperties();
215
216    /** \brief Connect to a device. Child classes must implement this function and perform the connection
217        routine in the function.
218        \return True if connection to device is successful, false otherwise.
219    */
220    virtual bool Connect()=0;
221
222    /** \brief Disconnect from a device. Child classes must implement this function and perform the disconnection
223        routine in the function.
224        \return True if disconnection from a device is successful, false otherwise.
225    */
226    virtual bool Disconnect()=0;
227
228    /** \return Default name of the device. */
229    virtual const char *getDefaultName()=0;
230
231
232
233private:
234
235    bool pDebug;
236    bool pSimulation;
237
238    ISwitch DebugS[2];
239    ISwitch SimulationS[2];
240    ISwitch ConfigProcessS[3];
241
242    ISwitchVectorProperty *DebugSP;
243    ISwitchVectorProperty *SimulationSP;
244    ISwitchVectorProperty *ConfigProcessSP;
245
246
247};
248
249#endif // INDIDEFAULTDRIVER_H
Note: See TracBrowser for help on using the repository browser.