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