Instrument Neutral Distributed Interface INDI 2.2.5
skycommander.c
Go to the documentation of this file.
1#if 0
2 Sky Commander INDI driver
3 Copyright (C) 2005 Jasem Mutlaq ([email protected])
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19#endif
20
21#include "lx200driver.h"
22
23#include "indidevapi.h"
24#include "indicom.h"
25
26#ifndef _WIN32
27#include <termios.h>
28#endif
29
30#define mydev "Sky Commander"
31#define BASIC_GROUP "Main Control"
32#define POLLMS_OVERRIDE 1000
33#define currentRA eq[0].value
34#define currentDEC eq[1].value
35#define SKYCOMMANDER_TIMEOUT 5
36
37static void ISPoll(void *);
38static void ISInit(void);
39static void connectTelescope(void);
40
41int fd;
42
43static ISwitch PowerS[] = { { "CONNECT", "Connect", ISS_OFF, 0, 0 }, { "DISCONNECT", "Disconnect", ISS_ON, 0, 0 } };
45 0, IPS_IDLE, PowerS, NARRAY(PowerS), "", 0 };
46
47static IText PortT[] = { { "PORT", "Port", 0, 0, 0, 0 } };
48static ITextVectorProperty PortTP = { mydev, "DEVICE_PORT", "Ports", BASIC_GROUP, IP_RW, 0,
49 IPS_IDLE, PortT, NARRAY(PortT), "", 0 };
50
51/* equatorial position */
53 { "RA", "RA H:M:S", "%10.6m", 0., 24., 0., 0., 0, 0, 0 },
54 { "DEC", "Dec D:M:S", "%10.6m", -90., 90., 0., 0., 0, 0, 0 },
55};
57 mydev, "EQUATORIAL_EOD_COORD", "Equatorial JNow", BASIC_GROUP, IP_RO, 0, IPS_IDLE, eq, NARRAY(eq), "", 0
58};
59
60void ISInit(void)
61{
62 static int isInit = 0;
63
64 if (isInit)
65 return;
66
67 isInit = 1;
68 fd = -1;
69
70 IEAddTimer(POLLMS_OVERRIDE, ISPoll, NULL);
71}
72
73void ISGetProperties(const char *dev)
74{
75 ISInit();
76
77 dev = dev;
78
79 IDDefSwitch(&PowerSP, NULL);
80 IDDefText(&PortTP, NULL);
81 IDDefNumber(&eqNum, NULL);
82}
83
84void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
85{
86 ISInit();
87
88 dev = dev;
89
90 if (!strcmp(name, PowerSP.name))
91 {
93 IUUpdateSwitch(&PowerSP, states, names, n);
94 connectTelescope();
95 return;
96 }
97}
98
99void ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
100{
101 ISInit();
102
103 dev = dev;
104 names = names;
105 n = n;
106
107 if (!strcmp(name, PortTP.name))
108 {
109 IUSaveText(&PortT[0], texts[0]);
110 PortTP.s = IPS_OK;
111 IDSetText(&PortTP, NULL);
112 return;
113 }
114}
115void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
116{
117 dev = dev;
118 name = name;
119 values = values;
120 names = names;
121 n = n;
122}
123
124void ISNewBLOB(const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[],
125 char *names[], int n)
126{
127 INDI_UNUSED(dev);
128 INDI_UNUSED(name);
129 INDI_UNUSED(sizes);
130 INDI_UNUSED(blobsizes);
131 INDI_UNUSED(blobs);
132 INDI_UNUSED(formats);
133 INDI_UNUSED(names);
134 INDI_UNUSED(n);
135}
137{
138 INDI_UNUSED(root);
139}
140
141int updateSkyCommanderCoord(int fd, double *ra, double *dec)
142{
143 char coords[16];
144 char CR[1] = { (char)0x0D };
145 float RA = 0.0, DEC = 0.0;
146 int error_type;
147 int nbytes_read = 0;
148
149 error_type = write(fd, CR, 1);
150
151 error_type = tty_read(fd, coords, 16, SKYCOMMANDER_TIMEOUT, &nbytes_read);
152 /*read_ret = portRead(coords, 16, LX200_TIMEOUT);*/
153 tcflush(fd, TCIFLUSH);
154
155 nbytes_read = sscanf(coords, " %g %g", &RA, &DEC);
156
157 if (nbytes_read < 2)
158 {
159 IDLog("Error in Sky commander number format [%s], exiting.\n", coords);
160 return error_type;
161 }
162
163 *ra = RA;
164 *dec = DEC;
165
166 return 0;
167}
168
169void ISPoll(void *p)
170{
171 p = p;
172
173 if (PowerS[0].s == ISS_ON)
174 {
175 switch (eqNum.s)
176 {
177 case IPS_IDLE:
178 case IPS_OK:
179 case IPS_BUSY:
181 {
182 eqNum.s = IPS_ALERT;
183 IDSetNumber(&eqNum, "Unknown error while reading telescope coordinates");
184 IDLog("Unknown error while reading telescope coordinates\n");
185 break;
186 }
187
188 IDSetNumber(&eqNum, NULL);
189 break;
190
191 case IPS_ALERT:
192 break;
193 }
194 }
195
196 IEAddTimer(POLLMS_OVERRIDE, ISPoll, NULL);
197}
198
199void connectTelescope(void)
200{
201 switch (PowerS[0].s)
202 {
203 case ISS_ON:
204 if (tty_connect(PortT[0].text, 9600, 8, 0, 1, &fd) != TTY_OK)
205 {
208 IDSetSwitch(&PowerSP, "Error connecting to port %s", PortT[0].text);
209 return;
210 }
211
212 PowerSP.s = IPS_OK;
213 IDSetSwitch(&PowerSP, "Sky Commander is online.");
214 break;
215
216 case ISS_OFF:
220 IDSetSwitch(&PowerSP, "Sky Commander is offline.");
221 IDSetText(&PortTP, NULL);
222 IDSetNumber(&eqNum, NULL);
223 break;
224 }
225}
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,...)
ITextVectorProperty PortTP
Definition magellan1.cpp:65
Namespace to encapsulate INDI client, drivers, and mediator classes.
#define currentDEC
#define SKYCOMMANDER_TIMEOUT
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.
int updateSkyCommanderCoord(int fd, double *ra, double *dec)
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
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