Instrument Neutral Distributed Interface INDI  1.9.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 }
ISInit
void ISInit(void)
Definition: fli_wheel.c:121
IP_RO
@ IP_RO
Definition: indiapi.h:183
Aux::ANY
@ ANY
Definition: celestronauxpacket.h:86
ISNewNumber
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Definition: intelliscope.c:117
IPS_OK
@ IPS_OK
Definition: indiapi.h:161
_INumberVectorProperty::s
IPState s
Definition: indiapi.h:332
mydev
#define mydev
Definition: intelliscope.c:32
ISwitch
One switch descriptor.
ISS_OFF
@ ISS_OFF
Definition: indiapi.h:150
indicom.h
Implementations for common driver routines.
NARRAY
#define NARRAY(a)
Handy macro to find the number of elements in array a[]. Must be used with actual array,...
Definition: indiapi.h:499
PowerSP
ISwitchVectorProperty PowerSP
Definition: intelliscope.c:46
IDSetText
void IDSetText(const ITextVectorProperty *t, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing text vector property.
tty_disconnect
int tty_disconnect(int fd)
Closes a tty connection and flushes the bus.
Definition: indicom.c:1116
IPS_ALERT
@ IPS_ALERT
Definition: indiapi.h:163
INumber
One number descriptor.
IDDefText
void IDDefText(const ITextVectorProperty *t, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to create a text vector property.
INDI_UNUSED
#define INDI_UNUSED(x)
Definition: indidevapi.h:799
ISSnoopDevice
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
BASIC_GROUP
#define BASIC_GROUP
Definition: intelliscope.c:33
IUResetSwitch
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition: indicom.c:1421
IDLog
void void void void void IDLog(const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(1
Function Drivers call to log a message locally.
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
ISNewBLOB
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
tty_read
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition: indicom.c:462
IEAddTimer
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:525
eq
INumber eq[]
Definition: intelliscope.c:54
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
ra
double ra
Definition: ieqprolegacydriver.cpp:43
IText
One text descriptor.
indidevapi.h
Interface to the reference INDI C API device implementation on the Device Driver side.
IPS_BUSY
@ IPS_BUSY
Definition: indiapi.h:162
ISR_1OFMANY
@ ISR_1OFMANY
Definition: indiapi.h:172
IPS_IDLE
@ IPS_IDLE
Definition: indiapi.h:160
INTELLISCOPE_TIMEOUT
#define INTELLISCOPE_TIMEOUT
Definition: intelliscope.c:37
tty_connect
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:916
dec
double dec
Definition: ieqprolegacydriver.cpp:44
xml_ele_
Definition: lilxml.c:105
IUUpdateSwitch
int IUUpdateSwitch(ISwitchVectorProperty *svp, ISState *states, char *names[], int n)
Update all switches in a switch vector property.
Definition: indidriver.c:171
_ITextVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:249
eqNum
INumberVectorProperty eqNum
Definition: intelliscope.c:58
currentDEC
#define currentDEC
Definition: intelliscope.c:36
ISNewText
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
fd
int fd
Definition: intelliscope.c:43
IDDefNumber
void void void IDDefNumber(const INumberVectorProperty *n, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to create a number number property.
IUSaveText
void IUSaveText(IText *tp, const char *newtext)
Function to reliably save new text in a IText.
Definition: indicom.c:1428
IDDefSwitch
void void void void void IDDefSwitch(const ISwitchVectorProperty *s, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to create a switch vector property.
_ISwitchVectorProperty::s
IPState s
Definition: indiapi.h:382
_ITextVectorProperty::s
IPState s
Definition: indiapi.h:259
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
ISGetProperties
void ISGetProperties(const char *dev)
Get Device Properties.
Definition: intelliscope.c:75
ISPoll
void ISPoll(void *p)
Definition: fli_wheel.c:393
IP_RW
@ IP_RW
Definition: indiapi.h:185
updateIntelliscopeCoord
int updateIntelliscopeCoord(int fd, double *ra, double *dec)
Definition: intelliscope.c:143
POLLMS_OVERRIDE
#define POLLMS_OVERRIDE
Definition: intelliscope.c:34
ISState
ISState
Switch state.
Definition: indiapi.h:148
TTY_OK
@ TTY_OK
Definition: indicom.h:94
PortTP
ITextVectorProperty PortTP
Definition: magellan1.cpp:64
IDSetNumber
void void void IDSetNumber(const INumberVectorProperty *n, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing number vector property.
IDSetSwitch
void void void void void IDSetSwitch(const ISwitchVectorProperty *s, const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(2
Tell client to update an existing switch vector property.
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
currentRA
#define currentRA
Definition: intelliscope.c:35
_ISwitchVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:370
ISS_ON
@ ISS_ON
Definition: indiapi.h:151
ISNewSwitch
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