View Javadoc
1 /* 2 * CelestronCommand.java 3 * 4 * Created on April 17, 2003, 11:12 AM 5 * 6 * Copyright (c) 2003, Raben Systems, Inc. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions are met: 11 * 12 * Redistributions of source code must retain the above copyright notice, 13 * this list of conditions and the following disclaimer. 14 * 15 * Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 19 * Neither the name of Raben Systems, Inc. nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGE.* 34 */ 35 36 package com.raben.telescope.comm; 37 import java.awt.geom.Point2D; 38 39 /*** 40 * Facade to generate command string for various Celestron telescope models 41 * @author Vern Raben 42 */ 43 public class CelestronCommand { 44 45 /*** Telescope model selected */ 46 private TelescopeModel telescopeModel = 47 TelescopeModel.CELESTRON_NEXSTAR_GPS; 48 49 /*** Adapter to encode/decode telescope commands */ 50 private CelestronCoordinateConverter coordinateConverter = 51 new CelestronCoordinateConverter(); 52 53 /*** Define null char */ 54 private static final char NULL_CHAR = Character.MIN_VALUE; 55 56 /*** Creates a new instance of CelestronCommandAdapter */ 57 public CelestronCommand() { 58 } 59 60 /*** 61 * Set telescope model 62 * @param model Telescope model 63 */ 64 public void setTelescopeModel(TelescopeModel model) { 65 this.telescopeModel = model; 66 coordinateConverter.setTelescopeModel(model); 67 } 68 69 /*** 70 * Get telescope model 71 * @return The telescope model 72 */ 73 public TelescopeModel getTelescopeModel() { 74 return this.telescopeModel; 75 } 76 77 /*** 78 * Set whether high precision mode should be used 79 * (ISSUE - what if high precision not available) 80 * @param highPrecision True if high precision coordinates 81 */ 82 public void setHighPrecision(boolean highPrecision) { 83 coordinateConverter.setHighPrecision(highPrecision); 84 } 85 86 /*** 87 * Check if high precision coordinates are set 88 * @return true if high precision (24 bit) mode 89 */ 90 public boolean isHighPrecision() { 91 return coordinateConverter.isHighPrecision(); 92 } 93 94 /*** 95 * Get goto azimuth and altitude command string 96 * @param azimuth in degress (0 to 360) 97 * @param altitude in degrees (0 to 90) 98 * @return Command string for selected telescope model 99 */ 100 public String goToAzimuthAltitude(double azimuth, double altitude) { 101 String cmdStr = ""; 102 103 if ((!Double.isNaN(azimuth)) && (!Double.isNaN(altitude))) { 104 String azStr = coordinateConverter.encodeHexadecimal(azimuth); 105 String altStr = coordinateConverter.encodeHexadecimal(altitude); 106 107 if ((telescopeModel.equals( 108 TelescopeModel.CELESTRON_NEXSTAR_5_8))) { 109 cmdStr = "B" + azStr + altStr; 110 } else if (telescopeModel.equals( 111 TelescopeModel.CELESTRON_NEXSTAR_OGT)) { 112 cmdStr = "B" + azStr + "X" + altStr + "X"; 113 cmdStr = cmdStr.replace('X', NULL_CHAR); 114 } else if ((telescopeModel.equals( 115 TelescopeModel.CELESTRON_NEXSTAR_GT)) 116 || (telescopeModel.equals( 117 TelescopeModel.CELESTRON_NEXSTAR_GPS)) 118 || (telescopeModel.equals( 119 TelescopeModel.CELESTRON_NEXSTAR_5I_8I)) 120 || (telescopeModel.equals(TelescopeModel.CELESTRON_ASC)) 121 || (telescopeModel.equals(TelescopeModel.CELESTRON_CGE))) { 122 123 if (coordinateConverter.isHighPrecision()) { 124 cmdStr = "b" + azStr + "," + altStr; 125 } else { 126 cmdStr = "B" + azStr + "," + altStr; 127 } 128 129 } 130 131 132 } 133 134 return cmdStr; 135 136 } 137 138 /*** 139 * Get GoTo right ascension declination command string 140 * @param ra Right ascension in hours (0 to 24) 141 * @param decl Declination in degrees (-90 to 90) 142 * @return Command string for selected telescope model 143 */ 144 public String goToRightAscensionDeclination(double ra, double decl) { 145 String cmdStr = ""; 146 147 if ((!Double.isNaN(ra)) && (!Double.isNaN(decl))) { 148 String raStr = coordinateConverter.encodeHexadecimal(ra); 149 String decStr = coordinateConverter.encodeHexadecimal(decl); 150 151 if ((telescopeModel.equals( 152 TelescopeModel.CELESTRON_NEXSTAR_5_8))) { 153 cmdStr = "R" + raStr + decStr; 154 } else if (telescopeModel.equals( 155 TelescopeModel.CELESTRON_NEXSTAR_OGT)) { 156 cmdStr = "R" + raStr + "X" + decStr + "X"; 157 cmdStr = cmdStr.replace('X', NULL_CHAR); 158 } else if ((telescopeModel.equals( 159 160 TelescopeModel.CELESTRON_NEXSTAR_GPS)) 161 || (telescopeModel.equals( 162 TelescopeModel.CELESTRON_NEXSTAR_5I_8I)) 163 || (telescopeModel.equals(TelescopeModel.CELESTRON_NEXSTAR_GT)) 164 || (telescopeModel.equals(TelescopeModel.CELESTRON_ASC)) 165 || (telescopeModel.equals(TelescopeModel.CELESTRON_CGE))) { 166 167 if (coordinateConverter.isHighPrecision()) { 168 cmdStr = "r" + raStr + "," + decStr; 169 } else { 170 cmdStr = "R" + raStr + "," + decStr; 171 } 172 173 } 174 175 176 } 177 178 return cmdStr; 179 180 } 181 182 /*** 183 * Get azimuth/altitude command 184 * @return String containing command to get azimuth/altitude 185 */ 186 public String getAzimuthAltitude() { 187 String cmdStr = "Z"; 188 189 if (isHighPrecision()) { 190 cmdStr = "z"; 191 } 192 193 return cmdStr; 194 } 195 196 /*** 197 * Get right ascension/declination command 198 * @return Command string 199 */ 200 public String getRightAscensionDeclination() { 201 String cmdStr = "E"; 202 203 if (isHighPrecision()) { 204 cmdStr = "e"; 205 } 206 207 return cmdStr; 208 } 209 210 /*** 211 * Decode hexadecimal string to coordinate 212 * @param str String to be decoded 213 * @param coord Coordinate whose values are to be set 214 */ 215 public void decodeHexadecimal(String str, Point2D coord) { 216 coordinateConverter.decodeHexadecimal(str, coord); 217 } 218 219 /*** 220 * Get hand control version command 221 * @return Command to get hand control version 222 */ 223 public String handControlVersion() { 224 String cmdStr = "V"; 225 return cmdStr; 226 } 227 228 /*** 229 * Get cancel goto command 230 * @return Command to cancel goto 231 */ 232 public String cancelGoTo() { 233 String cmdStr = "M"; 234 return cmdStr; 235 } 236 237 /*** Get alignment complete command 238 * @return Command to check if alignment complete 239 */ 240 public String alignmentComplete() { 241 String cmdStr = "J"; 242 return cmdStr; 243 } 244 245 /*** 246 * Get tracking mode command string 247 * @param mode 0=off,1=altaz,2=eq-n,3=eq-s 248 * @return command string 249 */ 250 public String trackingMode(int mode) { 251 String cmdStr = ""; 252 253 if ((mode >= 0) && (mode < 4)) { 254 cmdStr = "T" + (char) mode; 255 } 256 257 return cmdStr; 258 } 259 260 261 }

This page was automatically generated by Maven