source: BAORadio/libindi/libindi/examples/tutorial_four.cpp @ 504

Last change on this file since 504 was 504, checked in by frichard, 13 years ago

-Version 0.8 de libini
-Formule de Marc
-Nouvelles fonctionnalités (goto nom-de l'objet etc...)

File size: 8.0 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**************************************************************************************/
150bool MyScope::initProperties()
151{
152    DefaultDriver::initProperties();
153    // This is the default driver skeleton file location
154    // Convention is: drivername_sk_xml
155    // Default location is /usr/share/indi
156    const char *skelFileName = "/usr/share/indi/tutorial_four_sk.xml";
157    struct stat st;
158
159
160    char *skel = getenv("INDISKEL");
161    if (skel)
162        buildSkeleton(skel);
163    else if (stat(skelFileName,&st) == 0)
164        buildSkeleton(skelFileName);
165    else
166        IDLog("No skeleton file was specified. Set environment variable INDISKEL to the skeleton path and try again.\n");
167
168    // Optional: Add aux controls for configuration, debug & simulation that get added in the Options tab
169    //           of the driver.
170    addAuxControls();
171
172    return true;
173
174}
175
176/**************************************************************************************
177** Define Basic properties to clients.
178***************************************************************************************/
179void MyScope::ISGetProperties(const char *dev)
180{
181    static int configLoaded = 0;
182
183    // Ask the default driver first to send properties.
184    INDI::DefaultDriver::ISGetProperties(dev);
185
186    // If no configuration is load before, then load it now.
187    if (configLoaded == 0)
188    {
189      loadConfig();
190      configLoaded = 1;
191    }
192
193}
194
195/**************************************************************************************
196** Process Text properties
197***************************************************************************************/
198bool MyScope::ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n)
199{
200        // Ignore if not ours
201        if (strcmp (dev, deviceID))
202            return false;
203
204        return false;
205}
206
207/**************************************************************************************
208**
209***************************************************************************************/
210bool MyScope::ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
211{
212       
213        // Ignore if not ours
214        if (strcmp (dev, deviceID))
215            return false;
216
217        INumberVectorProperty *nvp = getNumber(name);
218
219        if (!nvp)
220            return false;
221
222        // Are we updating Slew Accuracy?
223        if (!strcmp(nvp->name, "Slew Accuracy"))
224        {
225            IUUpdateNumber(nvp, values, names, n);
226            nvp->s = IPS_OK;
227            IDSetNumber(nvp, NULL);
228
229            return true;
230        }
231
232        return false;
233}
234
235/**************************************************************************************
236**
237***************************************************************************************/
238bool MyScope::ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
239{
240        // ignore if not ours //
241        if (strcmp (dev, deviceID))
242            return false;
243
244        if (INDI::DefaultDriver::ISNewSwitch(dev, name, states, names, n) == true)
245            return true;
246
247        ISwitchVectorProperty *svp = getSwitch(name);
248
249        if (!svp)
250            return false;
251
252        /* Are we update CONNECTION?
253        if (!strcmp(svp->name, "CONNECTION"))
254        {
255            IUUpdateSwitch(svp, states, names, n);
256            connect_telescope();
257            return true;
258        }*/
259
260
261}
262
263
264/**************************************************************************************
265**
266***************************************************************************************/
267bool MyScope::Connect()
268{
269    return true;
270}
271
272bool MyScope::Disconnect()
273{
274    return true;
275}
276
277const char * MyScope::getDefaultName()
278{
279    return "My Scope";
280}
281
282
283
284
285
286
287
Note: See TracBrowser for help on using the repository browser.