Instrument Neutral Distributed Interface INDI 2.2.5
intelliscope.c
Go to the documentation of this file.
1#if 0
2 Intelliscope INDI driver
3 Copyright (C) 2005 Douglas Philipson (dougp AT intermind DOT net)
4
5 Based on code by Jasem Mutlaq ([email protected])
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 "config.h"
24
25#include "indidevapi.h"
26#include "indicom.h"
27
28#ifndef _WIN32
29#include <termios.h>
30#endif
31
32#define mydev "Intelliscope"
33#define BASIC_GROUP "Main Control"
34#define POLLMS_OVERRIDE 1000
35#define currentRA eq[0].value
36#define currentDEC eq[1].value
37#define INTELLISCOPE_TIMEOUT 5
38
39static void ISPoll(void *);
40static void ISInit(void);
41static void connectTelescope(void);
42
43int fd;
44
45static ISwitch PowerS[] = { { "CONNECT", "Connect", ISS_OFF, 0, 0 }, { "DISCONNECT", "Disconnect", ISS_ON, 0, 0 } };
47 0, IPS_IDLE, PowerS, NARRAY(PowerS), "", 0 };
48
49static IText PortT[] = { { "PORT", "Port", 0, 0, 0, 0 } };
50static ITextVectorProperty PortTP = { mydev, "DEVICE_PORT", "Ports", BASIC_GROUP, IP_RW, 0,
51 IPS_IDLE, PortT, NARRAY(PortT), "", 0 };
52
53/* equatorial position */
55 { "RA", "RA H:M:S", "%10.6m", 0., 24., 0., 0., 0, 0, 0 },
56 { "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0., 0, 0, 0 },
57};
59 mydev, "EQUATORIAL_EOD_COORD", "Equatorial JNow", BASIC_GROUP, IP_RO, 0, IPS_IDLE, eq, NARRAY(eq), "", 0
60};
61
62void ISInit(void)
63{
64 static int isInit = 0;
65
66 if (isInit)
67 return;
68
69 isInit = 1;
70 fd = -1;
71
72 IEAddTimer(POLLMS_OVERRIDE, ISPoll, NULL);
73}
74
75void ISGetProperties(const char *dev)
76{
77 ISInit();
78
79 dev = dev;
80
81 IDDefSwitch(&PowerSP, NULL);
82 IDDefText(&PortTP, NULL);
83 IDDefNumber(&eqNum, NULL);
84}
85
86void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
87{
88 ISInit();
89
90 dev = dev;
91
92 if (!strcmp(name, PowerSP.name))
93 {
95 IUUpdateSwitch(&PowerSP, states, names, n);
96 connectTelescope();
97 return;
98 }
99}
100
101void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
102{
103 ISInit();
104
105 dev = dev;
106 names = names;
107 n = n;
108
109 if (!strcmp(name, PortTP.name))
110 {
111 IUSaveText(&PortT[0], texts[0]);
112 PortTP.s = IPS_OK;
113 IDSetText(&PortTP, NULL);
114 return;
115 }
116}
117void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
118{
119 dev = dev;
120 name = name;
121 values = values;
122 names = names;
123 n = n;
124}
125
126void ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[],
127 char *names[], int n)
128{
129 INDI_UNUSED(dev);
130 INDI_UNUSED(name);
131 INDI_UNUSED(sizes);
132 INDI_UNUSED(blobsizes);
133 INDI_UNUSED(blobs);
134 INDI_UNUSED(formats);
135 INDI_UNUSED(names);
136 INDI_UNUSED(n);
137}
139{
140 INDI_UNUSED(root);
141}
142
143int updateIntelliscopeCoord(int fd, double *ra, double *dec)
144{
145 char coords[16];
146 char CR[1] = { (char)0x51 }; /* "Q" */
147 float RA = 0.0, DEC = 0.0;
148 int error_type;
149 int nbytes_read = 0;
150
151 /*IDLog ("Sending a Q\n");*/
152 error_type = write(fd, CR, 1);
153 /* We start at 14 bytes in case its a Sky Wizard,
154 but read one more later it if it's a intelliscope */
155 /*read_ret = portRead (coords, 14, LX200_TIMEOUT);*/
156 error_type = tty_read(fd, coords, 14, INTELLISCOPE_TIMEOUT, &nbytes_read);
157 tcflush(fd, TCIFLUSH);
158 /*IDLog ("portRead() = [%s]\n", coords);*/
159
160 /* Remove the Q in the response from the Intelliscope but not the Sky Wizard */
161 if (coords[0] == 'Q')
162 {
163 coords[0] = ' ';
164 /* Read one more byte if Intelliscope to get the "CR" */
165 error_type = tty_read(fd, coords, 1, INTELLISCOPE_TIMEOUT, &nbytes_read);
166 /*read_ret = portRead (coords, 1, LX200_TIMEOUT);*/
167 }
168 nbytes_read = sscanf(coords, " %g %g", &RA, &DEC);
169 /*IDLog ("sscanf() RA = [%f]\n", RA * 0.0390625);*/
170 /*IDLog ("sscanf() DEC = [%f]\n", DEC * 0.0390625);*/
171
172 /*IDLog ("Intelliscope output [%s]", coords);*/
173 if (nbytes_read < 2)
174 {
175#ifdef INDI_DEBUG
176 IDLog("Error in Intelliscope number format [%s], exiting.\n", coords);
177#endif
178 return -1;
179 }
180
181 *ra = RA * 0.0390625;
182 *dec = DEC * 0.0390625;
183
184 return 0;
185}
186
187void ISPoll(void *p)
188{
189 p = p;
190
191 if (PowerS[0].s == ISS_ON)
192 {
193 switch (eqNum.s)
194 {
195 case IPS_IDLE:
196 case IPS_OK:
197 case IPS_BUSY:
199 {
200 eqNum.s = IPS_ALERT;
201 IDSetNumber(&eqNum, "Unknown error while reading telescope coordinates");
202 IDLog("Unknown error while reading telescope coordinates\n");
203 break;
204 }
205
206 IDSetNumber(&eqNum, NULL);
207 break;
208
209 case IPS_ALERT:
210 break;
211 }
212 }
213
214 IEAddTimer(POLLMS_OVERRIDE, ISPoll, NULL);
215}
216
217void connectTelescope(void)
218{
219 switch (PowerS[0].s)
220 {
221 case ISS_ON:
222 if (tty_connect(PortT[0].text, 9600, 8, 0, 1, &fd) != TTY_OK)
223 {
226 IDSetSwitch(&PowerSP, "Error connecting to port %s", PortT[0].text);
227 return;
228 }
229
230 PowerSP.s = IPS_OK;
231 IDSetSwitch(&PowerSP, "Intelliscope is online.");
232 break;
233
234 case ISS_OFF:
237 eqNum.s = PortTP.s = PowerSP.s = IPS_IDLE;
238 IDSetSwitch(&PowerSP, "Intelliscope is offline.");
239 IDSetText(&PortTP, NULL);
240 IDSetNumber(&eqNum, NULL);
241 break;
242 }
243}
void ISPoll(void *p)
Definition fli_wheel.c:393
int IEAddTimer(int millisecs, IE_TCF *fp, void *p)
Register a new single-shot timer function, fp, to be called with ud as argument after ms.
Definition eventloop.c:586
void ISInit(void)
Definition fli_wheel.c:121
double ra
double dec
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
#define NARRAY(a)
Handy macro to find the number of elements in array a[]. Must be used with actual array,...
Definition indiapi.h:498
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
int tty_connect(const char *device, int bit_rate, int word_size, int parity, int stop_bits, int *fd)
Establishes a tty connection to a terminal device.
Definition indicom.c:1022
int tty_disconnect(int fd)
Closes a tty connection and flushes the bus.
Definition indicom.c:1224
void IDLog(const char *fmt,...)
Definition indicom.c:305
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition indicom.c:548
Implementations for common driver routines.
@ TTY_OK
Definition indicom.h:54
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition indidevapi.c:366
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
Definition indidevapi.c:44
Interface to the reference INDI C API device implementation on the Device Driver side.
#define INDI_UNUSED(x)
Definition indidevapi.h:132
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
void IDDefNumber(const INumberVectorProperty *nvp, const char *fmt,...)
void IDDefText(const ITextVectorProperty *tvp, const char *fmt,...)
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
void IDDefSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
#define currentDEC
void ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
Update data of an existing blob vector property.
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Update the value of an existing text vector property.
int fd
#define BASIC_GROUP
#define POLLMS_OVERRIDE
#define currentRA
void ISGetProperties(const char *dev)
Get Device Properties.
#define INTELLISCOPE_TIMEOUT
INumberVectorProperty eqNum
#define mydev
void ISSnoopDevice(XMLEle *root)
Function defined by Drivers that is called when another Driver it is snooping (by having previously c...
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
INumber eq[]
ISwitchVectorProperty PowerSP
int updateIntelliscopeCoord(int fd, double *ra, double *dec)
Namespace to encapsulate INDI client, drivers, and mediator classes.
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365
char name[MAXINDINAME]
Definition indiapi.h:369
Text vector property descriptor.
Definition indiapi.h:244
char name[MAXINDINAME]
Definition indiapi.h:248