1
/*******************************************************************************
2
Copyright(c) 2010 Gerry Rozema. All rights reserved.
4
This program is free software; you can redistribute it and/or modify it
5
under the terms of the GNU General Public License as published by the Free
6
Software Foundation; either version 2 of the License, or (at your option)
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14
You should have received a copy of the GNU General Public License along with
15
this program; if not, write to the Free Software Foundation, Inc., 59
16
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
The full GNU General Public License is included in this distribution in the
20
*******************************************************************************/
21
#include "synscanmount.h"
22
#include "libs/indicom.h"
36
// We declare an auto pointer to Synscan.
37
std::auto_ptr<SynscanMount> synscan(0);
50
if(synscan.get() == 0) synscan.reset(new SynscanMount());
51
//IEAddTimer(POLLMS, ISPoll, NULL);
55
void ISGetProperties(const char *dev)
58
synscan->ISGetProperties(dev);
61
void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int num)
64
synscan->ISNewSwitch(dev, name, states, names, num);
67
void ISNewText( const char *dev, const char *name, char *texts[], char *names[], int num)
70
synscan->ISNewText(dev, name, texts, names, num);
73
void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int num)
76
synscan->ISNewNumber(dev, name, values, names, num);
79
void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
84
INDI_UNUSED(blobsizes);
90
void ISSnoopDevice (XMLEle *root)
95
SynscanMount::SynscanMount()
100
SynscanMount::~SynscanMount()
105
const char * SynscanMount::getDefaultName()
110
bool SynscanMount::initProperties()
113
IDLog("Synscan::init_properties\n");
115
//setDeviceName("Synscan");
116
INDI::Telescope::initProperties();
120
void SynscanMount::ISGetProperties (const char *dev)
123
IDLog("Enter SynscanMount::ISGetProperties %s\n",dev);
125
// First we let our parent class do it's thing
126
INDI::Telescope::ISGetProperties(dev);
128
// Now we add anything that's specific to this telescope
129
// or we could just load from a skeleton file too
133
bool SynscanMount::ReadScopeStatus()
136
int bytesWritten, bytesRead;
141
//IDLog("Read Status\n");
142
//tty_write(PortFD,(unsigned char *)"Ka",2, &bytesWritten); // test for an echo
144
tty_write(PortFD,"Ka",2, &bytesWritten); // test for an echo
145
tty_read(PortFD,str,2,2, &bytesRead); // Read 2 bytes of response
148
// this is not a correct echo
150
IDLog("ReadStatus Echo Fail\n");
151
IDMessage(deviceName(),"Mount Not Responding");
155
if(TrackState==SCOPE_SLEWING)
157
// We have a slew in progress
158
// lets see if it's complete
159
// This only works for ra/dec goto commands
160
// The goto complete flag doesn't trip for ALT/AZ commands
162
tty_write(PortFD,"L",1, &bytesWritten);
163
numread=tty_read(PortFD,str,2,3, &bytesRead);
166
// Nothing to do here
169
if(TrackState==SCOPE_PARKING) TrackState=SCOPE_PARKED;
170
else TrackState=SCOPE_TRACKING;
173
if(TrackState==SCOPE_PARKING)
175
// ok, lets try read where we are
176
// and see if we have reached the park position
178
tty_write(PortFD,"Z",1, &bytesWritten);
179
numread=tty_read(PortFD,str,10,2, &bytesRead);
180
//IDLog("PARK READ %s\n",str);
181
if(strncmp((char *)str,"0000,4000",9)==0)
183
TrackState=SCOPE_PARKED;
185
IDSetSwitch(ParkSV,NULL);
186
IDMessage(deviceName(),"Telescope is Parked.");
192
tty_write(PortFD,"e",1, &bytesWritten);
193
numread=tty_read(PortFD,str,18,1, &bytesRead);
196
IDLog("read status bytes didn't get a full read\n");
199
// bytes read is as expected
200
sscanf((char *)str,"%x",&n1);
201
sscanf((char *)&str[9],"%x",&n2);
202
ra=(double)n1/0x100000000*24.0;
203
dec=(double)n2/0x100000000*360.0;
208
bool SynscanMount::Goto(double ra,double dec)
212
int numread, bytesWritten, bytesRead;
214
// not fleshed in yet
215
tty_write(PortFD,"Ka",2, &bytesWritten); // test for an echo
216
tty_read(PortFD,str,2,2, &bytesRead); // Read 2 bytes of response
218
// this is not a correct echo
219
// so we are not talking to a mount properly
222
// Ok, mount is alive and well
223
// so, lets format up a goto command
225
n2=dec*0x1000000/360;
228
sprintf((char *)str,"r%08X,%08X",n1,n2);
229
tty_write(PortFD,str,18, &bytesWritten);
230
TrackState=SCOPE_SLEWING;
231
numread=tty_read(PortFD,str,1,60, &bytesRead);
232
if (numread!=1||str[0]!='#')
235
IDLog("Timeout waiting for scope to complete slewing.");
242
bool SynscanMount::Park()
245
int numread, bytesWritten, bytesRead;
249
tty_write(PortFD,"Ka",2, &bytesWritten); // test for an echo
250
tty_read(PortFD,str,2,2, &bytesRead); // Read 2 bytes of response
253
// this is not a correct echo
254
// so we are not talking to a mount properly
257
// Now we stop tracking
258
tty_write(PortFD,"T0",2, &bytesWritten);
259
numread=tty_read(PortFD,str,1,60, &bytesRead);
260
if (numread!=1||str[0]!='#')
263
IDLog("Timeout waiting for scope to stop tracking.");
267
//sprintf((char *)str,"b%08X,%08X",0x0,0x40000000);
268
tty_write(PortFD,"B0000,4000",10, &bytesWritten);
269
numread=tty_read(PortFD,str,1,60, &bytesRead);
270
if (numread!=1||str[0]!='#')
273
IDLog("Timeout waiting for scope to respond to park.");
277
TrackState=SCOPE_PARKING;
278
IDMessage(deviceName(),"Parking Telescope...");