1 | /******************************************************************************* |
---|
2 | Copyright(c) 2010 Gerry Rozema. All rights reserved. |
---|
3 | |
---|
4 | This library is free software; you can redistribute it and/or |
---|
5 | modify it under the terms of the GNU Library General Public |
---|
6 | License version 2 as published by the Free Software Foundation. |
---|
7 | |
---|
8 | This library is distributed in the hope that it will be useful, |
---|
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
11 | Library General Public License for more details. |
---|
12 | |
---|
13 | You should have received a copy of the GNU Library General Public License |
---|
14 | along with this library; see the file COPYING.LIB. If not, write to |
---|
15 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
---|
16 | Boston, MA 02110-1301, USA. |
---|
17 | *******************************************************************************/ |
---|
18 | |
---|
19 | #include "synscanmount.h" |
---|
20 | #include "libs/indicom.h" |
---|
21 | |
---|
22 | #include <stdio.h> |
---|
23 | #include <stdlib.h> |
---|
24 | #include <string.h> |
---|
25 | #include <stdarg.h> |
---|
26 | #include <math.h> |
---|
27 | #include <unistd.h> |
---|
28 | #include <time.h> |
---|
29 | #include <memory> |
---|
30 | |
---|
31 | #include <string.h> |
---|
32 | #include <sys/stat.h> |
---|
33 | |
---|
34 | // We declare an auto pointer to Synscan. |
---|
35 | std::auto_ptr<SynscanMount> synscan(0); |
---|
36 | |
---|
37 | void ISPoll(void *p); |
---|
38 | |
---|
39 | #define isDebug() true |
---|
40 | |
---|
41 | void ISInit() |
---|
42 | { |
---|
43 | static int isInit =0; |
---|
44 | |
---|
45 | if (isInit == 1) |
---|
46 | return; |
---|
47 | |
---|
48 | isInit = 1; |
---|
49 | if(synscan.get() == 0) synscan.reset(new SynscanMount()); |
---|
50 | //IEAddTimer(POLLMS, ISPoll, NULL); |
---|
51 | |
---|
52 | } |
---|
53 | |
---|
54 | void ISGetProperties(const char *dev) |
---|
55 | { |
---|
56 | ISInit(); |
---|
57 | synscan->ISGetProperties(dev); |
---|
58 | } |
---|
59 | |
---|
60 | void ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int num) |
---|
61 | { |
---|
62 | ISInit(); |
---|
63 | synscan->ISNewSwitch(dev, name, states, names, num); |
---|
64 | } |
---|
65 | |
---|
66 | void ISNewText( const char *dev, const char *name, char *texts[], char *names[], int num) |
---|
67 | { |
---|
68 | ISInit(); |
---|
69 | synscan->ISNewText(dev, name, texts, names, num); |
---|
70 | } |
---|
71 | |
---|
72 | void ISNewNumber(const char *dev, const char *name, double values[], char *names[], int num) |
---|
73 | { |
---|
74 | ISInit(); |
---|
75 | synscan->ISNewNumber(dev, name, values, names, num); |
---|
76 | } |
---|
77 | |
---|
78 | void ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n) |
---|
79 | { |
---|
80 | INDI_UNUSED(dev); |
---|
81 | INDI_UNUSED(name); |
---|
82 | INDI_UNUSED(sizes); |
---|
83 | INDI_UNUSED(blobsizes); |
---|
84 | INDI_UNUSED(blobs); |
---|
85 | INDI_UNUSED(formats); |
---|
86 | INDI_UNUSED(names); |
---|
87 | INDI_UNUSED(n); |
---|
88 | } |
---|
89 | void ISSnoopDevice (XMLEle *root) |
---|
90 | { |
---|
91 | INDI_UNUSED(root); |
---|
92 | } |
---|
93 | |
---|
94 | SynscanMount::SynscanMount() |
---|
95 | { |
---|
96 | //ctor |
---|
97 | } |
---|
98 | |
---|
99 | SynscanMount::~SynscanMount() |
---|
100 | { |
---|
101 | //dtor |
---|
102 | } |
---|
103 | |
---|
104 | const char * SynscanMount::getDefaultName() |
---|
105 | { |
---|
106 | return "SynScan"; |
---|
107 | } |
---|
108 | |
---|
109 | bool SynscanMount::initProperties() |
---|
110 | { |
---|
111 | //if (isDebug()) |
---|
112 | IDLog("Synscan::init_properties\n"); |
---|
113 | |
---|
114 | //setDeviceName("Synscan"); |
---|
115 | INDI::Telescope::initProperties(); |
---|
116 | |
---|
117 | return true; |
---|
118 | } |
---|
119 | void SynscanMount::ISGetProperties (const char *dev) |
---|
120 | { |
---|
121 | //if (isDebug()) |
---|
122 | IDLog("Enter SynscanMount::ISGetProperties %s\n",dev); |
---|
123 | |
---|
124 | // First we let our parent class do it's thing |
---|
125 | INDI::Telescope::ISGetProperties(dev); |
---|
126 | |
---|
127 | // Now we add anything that's specific to this telescope |
---|
128 | // or we could just load from a skeleton file too |
---|
129 | return; |
---|
130 | } |
---|
131 | |
---|
132 | bool SynscanMount::ReadScopeStatus() |
---|
133 | { |
---|
134 | char str[20]; |
---|
135 | int bytesWritten, bytesRead; |
---|
136 | int numread; |
---|
137 | double ra,dec; |
---|
138 | int n1,n2; |
---|
139 | |
---|
140 | //IDLog("SynScan Read Status\n"); |
---|
141 | //tty_write(PortFD,(unsigned char *)"Ka",2, &bytesWritten); // test for an echo |
---|
142 | |
---|
143 | tty_write(PortFD,"Ka",2, &bytesWritten); // test for an echo |
---|
144 | tty_read(PortFD,str,2,2, &bytesRead); // Read 2 bytes of response |
---|
145 | if(str[1] != '#') |
---|
146 | { |
---|
147 | // this is not a correct echo |
---|
148 | //if (isDebug()) |
---|
149 | IDLog("ReadStatus Echo Fail\n"); |
---|
150 | IDMessage(deviceName(),"Mount Not Responding"); |
---|
151 | return false; |
---|
152 | } |
---|
153 | |
---|
154 | if(TrackState==SCOPE_SLEWING) |
---|
155 | { |
---|
156 | // We have a slew in progress |
---|
157 | // lets see if it's complete |
---|
158 | // This only works for ra/dec goto commands |
---|
159 | // The goto complete flag doesn't trip for ALT/AZ commands |
---|
160 | memset(str,0,3); |
---|
161 | tty_write(PortFD,"L",1, &bytesWritten); |
---|
162 | numread=tty_read(PortFD,str,2,3, &bytesRead); |
---|
163 | if(str[0]!=48) |
---|
164 | { |
---|
165 | // Nothing to do here |
---|
166 | } else |
---|
167 | { |
---|
168 | if(TrackState==SCOPE_PARKING) TrackState=SCOPE_PARKED; |
---|
169 | else TrackState=SCOPE_TRACKING; |
---|
170 | } |
---|
171 | } |
---|
172 | if(TrackState==SCOPE_PARKING) |
---|
173 | { |
---|
174 | // ok, lets try read where we are |
---|
175 | // and see if we have reached the park position |
---|
176 | memset(str,0,20); |
---|
177 | tty_write(PortFD,"Z",1, &bytesWritten); |
---|
178 | numread=tty_read(PortFD,str,10,2, &bytesRead); |
---|
179 | //IDLog("PARK READ %s\n",str); |
---|
180 | if(strncmp((char *)str,"0000,4000",9)==0) |
---|
181 | { |
---|
182 | TrackState=SCOPE_PARKED; |
---|
183 | ParkSV->s=IPS_OK; |
---|
184 | IDSetSwitch(ParkSV,NULL); |
---|
185 | IDMessage(deviceName(),"Telescope is Parked."); |
---|
186 | } |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | memset(str,0,20); |
---|
191 | tty_write(PortFD,"e",1, &bytesWritten); |
---|
192 | numread=tty_read(PortFD,str,18,1, &bytesRead); |
---|
193 | if (bytesRead!=18) |
---|
194 | //if(str[17] != '#') |
---|
195 | { |
---|
196 | IDLog("read status bytes didn't get a full read\n"); |
---|
197 | return false; |
---|
198 | } |
---|
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; |
---|
204 | NewRaDec(ra,dec); |
---|
205 | return true; |
---|
206 | } |
---|
207 | |
---|
208 | bool SynscanMount::Goto(double ra,double dec) |
---|
209 | { |
---|
210 | char str[20]; |
---|
211 | int n1,n2; |
---|
212 | int numread, bytesWritten, bytesRead; |
---|
213 | |
---|
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 |
---|
217 | if(str[1] != '#') { |
---|
218 | // this is not a correct echo |
---|
219 | // so we are not talking to a mount properly |
---|
220 | return false; |
---|
221 | } |
---|
222 | // Ok, mount is alive and well |
---|
223 | // so, lets format up a goto command |
---|
224 | n1=ra*0x1000000/24; |
---|
225 | n2=dec*0x1000000/360; |
---|
226 | n1=n1<<8; |
---|
227 | n2=n2<<8; |
---|
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 (bytesRead!=1||str[0]!='#') |
---|
233 | { |
---|
234 | if (isDebug()) |
---|
235 | IDLog("Timeout waiting for scope to complete slewing."); |
---|
236 | return false; |
---|
237 | } |
---|
238 | |
---|
239 | return true; |
---|
240 | } |
---|
241 | |
---|
242 | bool SynscanMount::Park() |
---|
243 | { |
---|
244 | char str[20]; |
---|
245 | int numread, bytesWritten, bytesRead; |
---|
246 | |
---|
247 | |
---|
248 | memset(str,0,3); |
---|
249 | tty_write(PortFD,"Ka",2, &bytesWritten); // test for an echo |
---|
250 | tty_read(PortFD,str,2,2, &bytesRead); // Read 2 bytes of response |
---|
251 | if(str[1] != '#') |
---|
252 | { |
---|
253 | // this is not a correct echo |
---|
254 | // so we are not talking to a mount properly |
---|
255 | return false; |
---|
256 | } |
---|
257 | // Now we stop tracking |
---|
258 | tty_write(PortFD,"T0",2, &bytesWritten); |
---|
259 | numread=tty_read(PortFD,str,1,60, &bytesRead); |
---|
260 | if (bytesRead!=1||str[0]!='#') |
---|
261 | { |
---|
262 | if (isDebug()) |
---|
263 | IDLog("Timeout waiting for scope to stop tracking."); |
---|
264 | return false; |
---|
265 | } |
---|
266 | |
---|
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 (bytesRead!=1||str[0]!='#') |
---|
271 | { |
---|
272 | if (isDebug()) |
---|
273 | IDLog("Timeout waiting for scope to respond to park."); |
---|
274 | return false; |
---|
275 | } |
---|
276 | |
---|
277 | TrackState=SCOPE_PARKING; |
---|
278 | IDMessage(deviceName(),"Parking Telescope..."); |
---|
279 | return true; |
---|
280 | } |
---|