1 /*
2 * MeadeCoordinateConverter.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 package com.raben.telescope.comm;
35 import java.awt.geom.Point2D;
36 import java.util.Calendar;
37 /***
38 * Facade to encode and decode Meade coordinate formats
39 * @author Vern Raben
40 */
41 public class MeadeCoordinateConverter {
42 /*** Telescope model */
43 private TelescopeModel telescopeModel = TelescopeModel.MEADE_LX200;
44
45 /*** Flag to indicate whether coordinate is high precision */
46 private boolean highPrecision = false;
47
48 /*** Creates a new instance of MeadeCoordinateConverter */
49 public MeadeCoordinateConverter() {
50 }
51
52 /***
53 * Decode altitude or declination string in form of
54 * sDD*MM'SS# or sDD*MM
55 * @param alt or dec string
56 * @return altitude or declination in degrees
57 */
58 public double decodeAltitudeString(String alt) {
59 double retAlt = 0.0;
60 int min = 0;
61 double sec = 0.0;
62 int sgn = 1;
63
64 if ((alt != null) && (alt.length() > 6)) {
65 String sign = alt.substring(0, 1);
66 if ("-".equals(sign)) {
67 sgn = -1;
68 }
69
70 String degStr = alt.substring(1, 3);
71 int deg = Integer.parseInt(degStr);
72
73 int k = alt.indexOf("*", 4);
74
75 if (k != -1) {
76 String minStr = alt.substring(5, k);
77 min = Integer.parseInt(minStr);
78 int l = alt.indexOf("#", k + 1);
79 String secStr = alt.substring(k + 3, l);
80 sec = Double.parseDouble(secStr);
81 } else {
82 k = alt.indexOf("#");
83 String minStr = alt.substring(5, k);
84 min = Integer.parseInt(minStr);
85 }
86
87
88 retAlt = sgn * (deg + (min/ 60.0) + (sec/3600.0));
89 }
90
91 return retAlt;
92 }
93
94 public double decodeAzimuthString(String az) {
95 double retAz = 0.0;
96
97 if ((az != null) && (az.length() > 7)) {
98 String degStr = az.substring(0, 3);
99 int deg = Integer.parseInt(degStr);
100 String minStr = az.substring(5, 7);
101 int min = Integer.parseInt(minStr);
102 double sec = 0.0;
103 int j = az.indexOf("#");
104
105 if (j > 10) {
106 String secStr = az.substring(10, j);
107 sec = Double.parseDouble(secStr);
108 setHighPrecision(true);
109 }
110
111 retAz = deg + (min / 60.0) + (sec / 3600.0);
112 }
113
114 return retAz;
115 }
116
117
118 /*** Decode right ascension string
119 * @param str String to decode in format
120 * HH:MM.T# or HH:MM:SS#
121 * @return Angle in degres
122 *
123 */
124 public double decodeRightAscensionString(String str) {
125 // HH:MM.T# or HH:MM:SS#
126 double hrs = 0.0;
127 double min = 0.0;
128 double sec = 0.0;
129
130 if ((str != null) && (str.length() > 2)) {
131 hrs = Double.parseDouble(str.substring(0, 2));
132
133 if (str.length() == 8) {
134 min = Double.parseDouble(str.substring(3, 7));
135 }
136
137 if (str.length() == 9) {
138 setHighPrecision(true);
139 min = Double.parseDouble(str.substring(3, 5));
140 sec = Double.parseDouble(str.substring(6, 8));
141 }
142 }
143
144 return hrs + (min / 60.0) + (sec / 3600.0);
145 }
146
147 public String encodeAltitudeAsString(double altitude) {
148 return null;
149 }
150
151 public String encodeAzimuthAsString(double azimuth) {
152 return null;
153 }
154
155 public String encodeRightAscensionAsString(double ra) {
156 return null;
157 }
158
159 public String encodeDeclinationAsString(double decl) {
160 return null;
161 }
162
163 /*** Normalize angle to be in range 0 to 360
164 * @param val angle in degrees
165 * @return angle in range 0 to 360
166 *
167 */
168 private double normalizeAngle(double val) {
169
170 while (val >= 360.0) {
171 val -= 360.0;
172 }
173
174 while (val < 0) {
175 val += 360.0;
176 }
177
178 return val;
179 }
180
181 /*** Get the Telescope model
182 * @return Model of telescope
183 *
184 */
185 public TelescopeModel getTelescopeModel() {
186 return this.telescopeModel;
187 }
188
189 /*** Set the Telescope model
190 * @param telescopeModel to be used
191 *
192 */
193 public void setTelescopeModel(TelescopeModel telescopeModel) {
194 this.telescopeModel = telescopeModel;
195 }
196
197 /*** Set whether encode/decode should be high precision
198 * @param precision True if high precision is to be used
199 *
200 */
201 public void setHighPrecision(boolean precision) {
202 this.highPrecision = precision;
203 }
204
205 /*** Returns whether precision is high or not
206 * @return boolean true if high precision
207 *
208 */
209 public boolean isHighPrecision() {
210 return highPrecision;
211 }
212
213 /***
214 * Decode coordinates from GPS NEMA string
215 * @param nemaStr
216 * @return Geographic coordinate in degrees
217 */
218 public Point2D decodeCoordinatesFromNemaString(String nemaStr) {
219 return null;
220 }
221
222 /***
223 * Decode date and time from GPS NEMA string
224 * @param nemaStr
225 * @return Date/time UTC
226 */
227 public Calendar decodeTimeFromNemaString(String nemaStr) {
228 return null;
229 }
230
231 }
This page was automatically generated by Maven