Instrument Neutral Distributed Interface INDI  2.0.2
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 (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 "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 
39 static void ISPoll(void *);
40 static void ISInit(void);
41 static void connectTelescope(void);
42 
43 int fd;
44 
45 static ISwitch PowerS[] = { { "CONNECT", "Connect", ISS_OFF, 0, 0 }, { "DISCONNECT", "Disconnect", ISS_ON, 0, 0 } };
46 ISwitchVectorProperty PowerSP = { mydev, "CONNECTION", "Connection", BASIC_GROUP, IP_RW, ISR_1OFMANY,
47  0, IPS_IDLE, PowerS, NARRAY(PowerS), "", 0 };
48 
49 static IText PortT[] = { { "PORT", "Port", 0, 0, 0, 0 } };
50 static ITextVectorProperty PortTP = { mydev, "DEVICE_PORT", "Ports", BASIC_GROUP, IP_RW, 0,
51  IPS_IDLE, PortT, NARRAY(PortT), "", 0 };
52 
53 /* equatorial position */
54 INumber eq[] = {
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 
62 void 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 
75 void 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 
86 void 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 
101 void 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 }
117 void 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 
126 void 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 
143 int 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 
187 void 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 
217 void 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  {
224  PowerSP.s = IPS_ALERT;
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 }
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:582
void ISInit(void)
Definition: fli_wheel.c:121
void ISPoll(void *)
Definition: fli_wheel.c:393
double ra
double dec
ISState
Switch state.
Definition: indiapi.h:150
@ ISS_OFF
Definition: indiapi.h:151
@ ISS_ON
Definition: indiapi.h:152
#define NARRAY(a)
Handy macro to find the number of elements in array a[]. Must be used with actual array,...
Definition: indiapi.h:500
@ IP_RW
Definition: indiapi.h:186
@ IP_RO
Definition: indiapi.h:184
@ IPS_BUSY
Definition: indiapi.h:163
@ IPS_ALERT
Definition: indiapi.h:164
@ IPS_IDLE
Definition: indiapi.h:161
@ IPS_OK
Definition: indiapi.h:162
@ ISR_1OFMANY
Definition: indiapi.h:173
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:946
int tty_disconnect(int fd)
Closes a tty connection and flushes the bus.
Definition: indicom.c:1148
void IDLog(const char *fmt,...)
Definition: indicom.c:316
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition: indicom.c:482
Implementations for common driver routines.
@ TTY_OK
Definition: indicom.h:150
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition: indidevapi.c:148
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
Definition: indidevapi.c:36
Interface to the reference INDI C API device implementation on the Device Driver side.
#define INDI_UNUSED(x)
Definition: indidevapi.h:131
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
Definition: indidriver.c:1308
void IDSetNumber(const INumberVectorProperty *nvp, const char *fmt,...)
Definition: indidriver.c:1211
void IDSetSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
Definition: indidriver.c:1231
void IDDefNumber(const INumberVectorProperty *nvp, const char *fmt,...)
Definition: indidriver.c:1104
void IDDefText(const ITextVectorProperty *tvp, const char *fmt,...)
Definition: indidriver.c:1081
void IDSetText(const ITextVectorProperty *tvp, const char *fmt,...)
Definition: indidriver.c:1191
void IDDefSwitch(const ISwitchVectorProperty *svp, const char *fmt,...)
Definition: indidriver.c:1127
#define currentDEC
Definition: intelliscope.c:36
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.
Definition: intelliscope.c:126
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Update the value of an existing switch vector property.
Definition: intelliscope.c:86
void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Update the value of an existing text vector property.
Definition: intelliscope.c:101
int fd
Definition: intelliscope.c:43
#define BASIC_GROUP
Definition: intelliscope.c:33
#define POLLMS_OVERRIDE
Definition: intelliscope.c:34
#define currentRA
Definition: intelliscope.c:35
void ISGetProperties(const char *dev)
Get Device Properties.
Definition: intelliscope.c:75
#define INTELLISCOPE_TIMEOUT
Definition: intelliscope.c:37
INumberVectorProperty eqNum
Definition: intelliscope.c:58
#define mydev
Definition: intelliscope.c:32
void ISSnoopDevice(XMLEle *root)
Function defined by Drivers that is called when another Driver it is snooping (by having previously c...
Definition: intelliscope.c:138
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Definition: intelliscope.c:117
INumber eq[]
Definition: intelliscope.c:54
ISwitchVectorProperty PowerSP
Definition: intelliscope.c:46
int updateIntelliscopeCoord(int fd, double *ra, double *dec)
Definition: intelliscope.c:143
ITextVectorProperty PortTP
Definition: magellan1.cpp:65
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:319
Switch vector property descriptor.
Definition: indiapi.h:367
char name[MAXINDINAME]
Definition: indiapi.h:371
Text vector property descriptor.
Definition: indiapi.h:246
char name[MAXINDINAME]
Definition: indiapi.h:250