Instrument Neutral Distributed Interface INDI  1.9.5
skycommander.c
Go to the documentation of this file.
1 #if 0
2  Sky Commander INDI driver
3  Copyright (C) 2005 Jasem Mutlaq (mutlaqja@ikarustech.com)
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 
37 static void ISPoll(void *);
38 static void ISInit(void);
39 static void connectTelescope(void);
40 
41 int fd;
42 
43 static ISwitch PowerS[] = { { "CONNECT", "Connect", ISS_OFF, 0, 0 }, { "DISCONNECT", "Disconnect", ISS_ON, 0, 0 } };
44 ISwitchVectorProperty PowerSP = { mydev, "CONNECTION", "Connection", BASIC_GROUP, IP_RW, ISR_1OFMANY,
45  0, IPS_IDLE, PowerS, NARRAY(PowerS), "", 0 };
46 
47 static IText PortT[] = { { "PORT", "Port", 0, 0, 0, 0 } };
48 static ITextVectorProperty PortTP = { mydev, "DEVICE_PORT", "Ports", BASIC_GROUP, IP_RW, 0,
49  IPS_IDLE, PortT, NARRAY(PortT), "", 0 };
50 
51 /* equatorial position */
52 INumber eq[] = {
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 
60 void 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 
73 void 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 
84 void 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 
99 void 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 }
115 void 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 
124 void 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 
141 int 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 
169 void 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 
199 void 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  {
206  PowerSP.s = IPS_ALERT;
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:
219  eqNum.s = PortTP.s = PowerSP.s = IPS_IDLE;
220  IDSetSwitch(&PowerSP, "Sky Commander is offline.");
221  IDSetText(&PortTP, NULL);
222  IDSetNumber(&eqNum, NULL);
223  break;
224  }
225 }
ISInit
void ISInit(void)
Definition: fli_wheel.c:121
IP_RO
@ IP_RO
Definition: indiapi.h:183
POLLMS_OVERRIDE
#define POLLMS_OVERRIDE
Definition: skycommander.c:32
Aux::ANY
@ ANY
Definition: celestronauxpacket.h:86
IPS_OK
@ IPS_OK
Definition: indiapi.h:161
_INumberVectorProperty::s
IPState s
Definition: indiapi.h:332
ISwitch
One switch descriptor.
ISS_OFF
@ ISS_OFF
Definition: indiapi.h:150
indicom.h
Implementations for common driver routines.
fd
int fd
Definition: skycommander.c:41
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
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:1137
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
lx200driver.h
ISSnoopDevice
void ISSnoopDevice(XMLEle *root)
Function defined by Drivers that is called when another Driver it is snooping (by having previously c...
Definition: skycommander.c:136
IUResetSwitch
void IUResetSwitch(ISwitchVectorProperty *svp)
Reset all switches in a switch vector property to OFF.
Definition: indicom.c:1442
IDLog
void void void void void IDLog(const char *msg,...) ATTRIBUTE_FORMAT_PRINTF(1
Function Drivers call to log a message locally.
updateSkyCommanderCoord
int updateSkyCommanderCoord(int fd, double *ra, double *dec)
Definition: skycommander.c:141
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
tty_read
int tty_read(int fd, char *buf, int nbytes, int timeout, int *nbytes_read)
read buffer from terminal
Definition: indicom.c:473
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
ISGetProperties
void ISGetProperties(const char *dev)
Get Device Properties.
Definition: skycommander.c:73
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
eq
INumber eq[]
Definition: skycommander.c:52
ra
double ra
Definition: ieqprolegacydriver.cpp:43
IText
One text descriptor.
ISNewNumber
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Definition: skycommander.c:115
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
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:937
dec
double dec
Definition: ieqprolegacydriver.cpp:44
xml_ele_
Definition: lilxml.c:105
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: skycommander.c:99
BASIC_GROUP
#define BASIC_GROUP
Definition: skycommander.c:31
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
currentRA
#define currentRA
Definition: skycommander.c:33
currentDEC
#define currentDEC
Definition: skycommander.c:34
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:1449
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.
name
const char * name
Definition: indiserver.c:116
_ISwitchVectorProperty::s
IPState s
Definition: indiapi.h:382
SKYCOMMANDER_TIMEOUT
#define SKYCOMMANDER_TIMEOUT
Definition: skycommander.c:35
_ITextVectorProperty::s
IPState s
Definition: indiapi.h:259
PowerSP
ISwitchVectorProperty PowerSP
Definition: skycommander.c:44
INDI
Namespace to encapsulate INDI client, drivers, and mediator classes.
Definition: AlignmentSubsystemForClients.cpp:11
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: skycommander.c:124
ISPoll
void ISPoll(void *p)
Definition: fli_wheel.c:393
IP_RW
@ IP_RW
Definition: indiapi.h:185
ISState
ISState
Switch state.
Definition: indiapi.h:148
mydev
#define mydev
Definition: skycommander.c:30
eqNum
INumberVectorProperty eqNum
Definition: skycommander.c:56
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.
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: skycommander.c:84
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
_ISwitchVectorProperty::name
char name[MAXINDINAME]
Definition: indiapi.h:370
ISS_ON
@ ISS_ON
Definition: indiapi.h:151