1 /*
2 * CelestronAuxillaryCommand.java
3 *
4 * Copyright (c) 2003, Raben Systems, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
16 *
17 * Neither the name of Raben Systems, Inc. nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35 package com.raben.telescope.comm;
36
37 /***
38 * Celestron Auxillary Hand Controller Commands
39 * @author Vern Raben
40 * @version $Revision: 1.2 $ $Date: 2003/09/08 16:29:53 $
41 */
42 public class CelestronAuxillaryCommand {
43
44 /*** Auxillary command preamble for pc port */
45 private static final char PC_PORT_PREAMBLE = 0x3B;
46
47 /*** Auxillary command preamble for hand controller */
48 private static final char HC_PREAMBLE = 0x50;
49
50 /*** Auxillary address of main board */
51 private static final char MAIN_BOARD_ADDR = 0x01;
52
53 /*** Auxillary address of hand controller */
54 private static final char HAND_CONTROLLER_ADDR = 0x04;
55
56 /*** Auxillary address of azimuth controller */
57 private static final char AZM_CONTROLLER_ADDR = 0x10;
58
59 /*** Auxillary address of altitude controller */
60 private static final char ALT_CONTROLLER_ADDR = 0x11;
61
62 /*** Auxillary address of the GPS */
63 private static final char GPS_ADDR = 0xB0;
64
65 /*** GPS command to retrieve latitude */
66 private static final char[] GPS_GET_LATITUDE = { 0x01 };
67
68 /*** GPS command to retrieve longitude */
69 private static final char[] GPS_GET_LONGITUDE = { 0x02 };
70
71 /*** GPS command to retrieve month and date */
72 private static final char[] GPS_GET_DATE = { 0x03 };
73
74 /*** GPS commnand to retrieve year */
75 private static final char[] GPS_GET_YEAR = { 0x04 };
76
77 /*** GPS command to retrieve time in hours, minutes, and seconds */
78 private static final char[] GPS_GET_TIME = { 0x33 };
79
80 /*** GPS command to test if time is valid */
81 private static final char[] GPS_TIME_VALID = { 0x36 };
82
83 /*** GPS command to test if GPS is linked */
84 private static final char[] GPS_LINKED = { 0x37 };
85
86 /*** Motor control command to move positive (up or right) */
87 private static final char MC_MOVE_POS = 0x24;
88
89 /*** Motor control command to move negative (down or left) */
90 private static final char MC_MOVE_NEG = 0x25;
91
92 /*** Constant for 2 raised to 24th power */
93 private static final double TWO_EXP_24 = 16777216.0; // 2 ^ 24;
94
95 /*** LEFT arrow */
96 private static final int LEFT_ARROW = 0;
97
98 /*** Right arrow */
99 public static final int RIGHT_ARROW = 1;
100
101 /*** Up arrow */
102 public static final int UP_ARROW = 0;
103
104 /*** Down arrow */
105 public static final int DOWN_ARROW = 1;
106
107 /*** Creates a new instance of CelestronAuxillaryCommand */
108 public CelestronAuxillaryCommand() {
109 }
110
111 /***
112 * Create auxillary command for hand controller
113 * Packet format is
114 * 0x50, msglen, destId, msgId, data1, data2, data3, responseChars
115 * @param destId Address of device
116 * @param cmd Character array containg command
117 * @param responseChars of response chars expected
118 * @return char array containing command
119 */
120 public char[] createAuxillaryHandControllerCommand(char destId, char[] cmd,
121 int responseChars) {
122 char[] auxCmd = null;
123
124 if ((cmd != null) && cmd.length < 7) {
125 auxCmd = new char[8];
126 int k = 0;
127 auxCmd[k++] = HC_PREAMBLE;
128 auxCmd[k++] = (char) cmd.length;
129 auxCmd[k++] = destId;
130
131 for (int i = 0; i < cmd.length; i++) {
132 auxCmd[k++] = cmd[i];
133 }
134
135 auxCmd[7] = (char) responseChars;
136 }
137
138 return auxCmd;
139 }
140
141 /***
142 * Create auxillary command for pc port
143 * Packet format is
144 * 0x50, msglen, destId, msgId, data1, data2, data3, responseChars, checksum
145 * @param destId Address of device
146 * @param cmd Character array containg command
147 * @param responseChars of response chars expected
148 * @return char array containing command
149 */
150 public char[] createAuxillaryPcCommand(char destId, char[] cmd,
151 int responseChars) {
152 char[] auxCmd = null;
153 return auxCmd;
154 }
155
156 /***
157 * Get GPS year command
158 * @return char array containing command
159 */
160 public char[] gpsYearCommand() {
161 // Get year
162 return createAuxillaryHandControllerCommand(GPS_ADDR, GPS_GET_YEAR, 2);
163 }
164
165 /***
166 * Get GPS date command
167 * @return char array containing command
168 */
169 public char[] gpsDateCommand() {
170 // Get mo/da
171 return createAuxillaryHandControllerCommand(GPS_ADDR, GPS_GET_DATE, 2);
172 }
173
174 /***
175 * Get GPS time command
176 * @return char array containing command
177 */
178 public char[] gpsTimeCommand() {
179 // Get hr/min/sec
180 return createAuxillaryHandControllerCommand(GPS_ADDR, GPS_GET_TIME, 3);
181 }
182
183 /***
184 * Get GPS linked command
185 * @return char array containing command
186 */
187 public char[] gpsLinkedCommand() {
188 return createAuxillaryHandControllerCommand(GPS_ADDR, GPS_LINKED, 1);
189 }
190
191 /***
192 * Get GPS longitude command
193 * @return char array containing command
194 */
195 public char[] gpsLongitudeCommand() {
196 return createAuxillaryHandControllerCommand(GPS_ADDR,
197 GPS_GET_LONGITUDE, 3);
198 }
199
200 /***
201 * Get GPS latitude command
202 * @return char array containing command
203 */
204 public char[] gpsLatitudeCommand() {
205 return createAuxillaryHandControllerCommand(GPS_ADDR,
206 GPS_GET_LATITUDE, 3);
207 }
208
209 /***
210 * Decode chars from GPS containing coordinate response string
211 * @param chars array Containing response from GPS
212 * @return double angle in degrees
213 */
214 public double decodeGpsCoordinate(char[] chars) {
215 double coord = Double.NaN;
216
217 if ((chars != null) && (chars.length == 4)) {
218 long lcoord = (chars[0] << 16)
219 | (chars[1] << 8) | (chars[2]);
220 coord = lcoord * 360.0 / TWO_EXP_24;
221 }
222
223 if (coord > 180.0) {
224 coord -= 360.0;
225 }
226
227 return coord;
228 }
229
230 /***
231 * Get azimuth tracking rate command
232 * @param trackRate rate in arc seconds per second
233 * @return char array containing encoded command
234 */
235 public char[] azimuthTrackingRateCommand(int trackRate) {
236 int tracking = 4 * trackRate;
237 char[] cmd = new char[3];
238
239 if (trackRate >= 0) {
240 cmd[0] = (char) 6;
241 } else {
242 cmd[0] = (char) 7;
243 }
244
245 tracking = Math.abs(tracking);
246 cmd[1] = (char) (tracking >> 8);
247 cmd[2] = (char) (tracking & 0xFF);
248 return createAuxillaryHandControllerCommand(AZM_CONTROLLER_ADDR,
249 cmd, 1);
250 }
251
252 /***
253 * Get altitude tracking rate command
254 * @param trackRate in arc seconds per second
255 * @return char array containg the encoded command
256 */
257 public char[] altitudeTrackingRateCommand(int trackRate) {
258 int tracking = 4 * trackRate;
259 char[] cmd = new char[3];
260
261 if (trackRate >= 0) {
262 cmd[0] = (char) 6;
263 } else {
264 cmd[0] = (char) 7;
265 }
266
267 tracking = Math.abs(tracking);
268 cmd[1] = (char) (tracking >> 8);
269 cmd[2] = (char) (tracking & 0xFF);
270 return createAuxillaryHandControllerCommand(ALT_CONTROLLER_ADDR,
271 cmd, 1);
272 }
273
274 /*** Calculate check sum for command
275 * ISSUE - future, to be used for sending commands to pc port connection
276 * which not yet implemented
277 * @param val character array for which checksum is to be computed
278 * @return Value of check sum
279 */
280 private char calcCheckSum(char[] val) {
281 char checkSum = 0;
282 int j = val.length - 1;
283
284 while (j-- > 1) {
285 checkSum += val[j];
286 }
287
288 checkSum = (char) (-checkSum);
289 return (char) (checkSum & 0xFF);
290 }
291
292 /***
293 * Move telescope in azimuth (right ascension if on wedge)
294 * same action as as pressing left/right arrow key on hand
295 * controller
296 * @param direction false = left, true = right
297 * @param rate 0 = stop, 1 = slow, 9 = fast
298 */
299 public char[] azimuthMoveCommand(boolean direction, int rate) {
300 char[] cmd = new char[2];
301
302 if ((rate >= 0) && (rate <= 9)) {
303
304 if (direction) {
305 cmd[0] = MC_MOVE_POS;
306 } else {
307 cmd[0] = MC_MOVE_NEG;
308 }
309
310 cmd[1] = (char) rate;
311 } else {
312 return null;
313 }
314
315 // Create azimuth move command
316 return createAuxillaryHandControllerCommand(AZM_CONTROLLER_ADDR, cmd,1);
317 }
318
319 /***
320 * Move telescope in altitude
321 * same action as pressing up/down arrow on hand control
322 * @param direction true = up, false = down
323 * @param rate 0 = stop, 1 = slow, 9=fast
324 * @return char array containing command
325 */
326 public char[] altitudeMoveCommand(boolean direction, int rate) {
327 char[] cmd = new char[2];
328
329 if ((rate >= 0) && (rate <= 9)) {
330
331 if (direction) {
332 cmd[0] = MC_MOVE_POS;
333 } else {
334 cmd[0] = MC_MOVE_NEG;
335 }
336
337 cmd[1] = (char) rate;
338 return createAuxillaryHandControllerCommand(ALT_CONTROLLER_ADDR,
339 cmd, 1);
340 } else {
341 return null;
342 }
343
344
345 }
346
347
348 }
This page was automatically generated by Maven