source: BAORadio/libindi/v1.0.1/examples/tutorial_four.cpp@ 674

Last change on this file since 674 was 501, checked in by frichard, 15 years ago

-BAOControl : petite interface permettant de contrôler les antennes via le pilote indi_BAO
-Le pilote indi_BAO utilise désormais libindi v 0.7

File size: 8.5 KB
Line 
1#if 0
2 MyScope - Tutorial Four
3 Demonstration of libindi v0.7 capabilities.
4
5 Copyright (C) 2010 Jasem Mutlaq (mutlaqja@ikarustech.com)
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
21#endif
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <stdarg.h>
27#include <math.h>
28#include <unistd.h>
29#include <time.h>
30#include <memory>
31#include <sys/types.h>
32#include <sys/stat.h>
33
34#include <config.h>
35
36#include "indibase/baseclient.h"
37
38/* INDI Common Library Routines */
39#include "indicom.h"
40
41/* Our driver header */
42#include "tutorial_four.h"
43
44using namespace std;
45
46/* Our telescope auto pointer */
47auto_ptr<MyScope> telescope(0);
48
49const int POLLMS = 1000; // Period of update, 1 second.
50
51/**************************************************************************************
52** Send client definitions of all properties.
53***************************************************************************************/
54void ISInit()
55{
56 static int isInit=0;
57
58 if (isInit)
59 return;
60
61 if (telescope.get() == 0)
62 {
63 isInit = 1;
64 telescope.reset(new MyScope());
65 }
66
67}
68
69/**************************************************************************************
70**
71***************************************************************************************/
72void ISGetProperties (const char *dev)
73{
74 ISInit();
75 telescope->ISGetProperties(dev);
76}
77
78/**************************************************************************************
79**
80***************************************************************************************/
81void ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
82{
83 ISInit();
84 telescope->ISNewSwitch(dev, name, states, names, n);
85}
86
87/**************************************************************************************
88**
89***************************************************************************************/
90void ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
91{
92 ISInit();
93 telescope->ISNewText(dev, name, texts, names, n);
94}
95
96/**************************************************************************************
97**
98***************************************************************************************/
99void ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
100{
101 ISInit();
102 telescope->ISNewNumber(dev, name, values, names, n);
103}
104
105/**************************************************************************************
106**
107***************************************************************************************/
108void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
109{
110 INDI_UNUSED(dev);
111 INDI_UNUSED(name);
112 INDI_UNUSED(sizes);
113 INDI_UNUSED(blobsizes);
114 INDI_UNUSED(blobs);
115 INDI_UNUSED(formats);
116 INDI_UNUSED(names);
117 INDI_UNUSED(n);
118}
119
120/**************************************************************************************
121**
122***************************************************************************************/
123void ISSnoopDevice (XMLEle *root)
124{
125 INDI_UNUSED(root);
126}
127
128/**************************************************************************************
129** LX200 Basic constructor
130***************************************************************************************/
131MyScope::MyScope()
132{
133 IDLog("Initilizing from My Scope device...\n");
134
135 init_properties();
136
137 }
138
139/**************************************************************************************
140**
141***************************************************************************************/
142MyScope::~MyScope()
143{
144
145}
146
147/**************************************************************************************
148** Initialize all properties & set default values.
149***************************************************************************************/
150void MyScope::init_properties()
151{
152 // This is the default driver skeleton file location
153 // Convention is: drivername_sk_xml
154 // Default location is /usr/share/indi
155 const char *skelFileName = "/usr/share/indi/tutorial_four_sk.xml";
156 struct stat st;
157
158
159 char *skel = getenv("INDISKEL");
160 if (skel)
161 buildSkeleton(skel);
162 else if (stat(skelFileName,&st) == 0)
163 buildSkeleton(skelFileName);
164 else
165 IDLog("No skeleton file was specified. Set environment variable INDISKEL to the skeleton path and try again.\n");
166
167 // Optional: Add aux controls for configuration, debug & simulation that get added in the Options tab
168 // of the driver.
169 addAuxControls();
170
171}
172
173/**************************************************************************************
174** Define Basic properties to clients.
175***************************************************************************************/
176void MyScope::ISGetProperties(const char *dev)
177{
178 static int configLoaded = 0;
179
180 // Ask the default driver first to send properties.
181 INDI::DefaultDriver::ISGetProperties(dev);
182
183 // If no configuration is load before, then load it now.
184 if (configLoaded == 0)
185 {
186 loadConfig();
187 configLoaded = 1;
188 }
189
190}
191
192/**************************************************************************************
193** Process Text properties
194***************************************************************************************/
195bool MyScope::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
196{
197 // Ignore if not ours
198 if (strcmp (dev, deviceID))
199 return false;
200
201 return false;
202}
203
204/**************************************************************************************
205**
206***************************************************************************************/
207bool MyScope::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
208{
209
210 // Ignore if not ours
211 if (strcmp (dev, deviceID))
212 return false;
213
214 INumberVectorProperty *nvp = getNumber(name);
215
216 if (!nvp)
217 return false;
218
219 // Are we updating Slew Accuracy?
220 if (!strcmp(nvp->name, "Slew Accuracy"))
221 {
222 IUUpdateNumber(nvp, values, names, n);
223 nvp->s = IPS_OK;
224 IDSetNumber(nvp, NULL);
225
226 return true;
227 }
228
229 return false;
230}
231
232/**************************************************************************************
233**
234***************************************************************************************/
235bool MyScope::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
236{
237 // ignore if not ours //
238 if (strcmp (dev, deviceID))
239 return false;
240
241 if (INDI::DefaultDriver::ISNewSwitch(dev, name, states, names, n) == true)
242 return true;
243
244 ISwitchVectorProperty *svp = getSwitch(name);
245
246 if (!svp)
247 return false;
248
249 // Are we update CONNECTION?
250 if (!strcmp(svp->name, "CONNECTION"))
251 {
252 IUUpdateSwitch(svp, states, names, n);
253 connect_telescope();
254 return true;
255 }
256
257
258}
259
260
261/**************************************************************************************
262**
263***************************************************************************************/
264void MyScope::connect_telescope()
265{
266 ISwitchVectorProperty *svp = getSwitch("CONNECTION");
267
268 ISwitch *sp = IUFindOnSwitch(svp);
269
270 if (!sp)
271 return;
272
273 // Are we connecting?
274 if (!strcmp(sp->name, "CONNECT"))
275 {
276 // Make sure to call setConnected(true) before informing client about successful connection
277 setConnected(true);
278 IDSetSwitch(svp, "Connecting.... telescope is online.");
279 IDLog("Connecting.... telescope is online.\n");
280
281
282 }
283 // Are we disconnecting?
284 else
285 {
286 setConnected(false);
287 IDSetSwitch(svp, "Disconnecting... telescope is offline.");
288 IDLog("Disconnecting... telescope is offline.\n");
289 }
290}
291
292
Note: See TracBrowser for help on using the repository browser.