2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 /* EEProm command letters */
28 static final int AO_LOG_FLIGHT = 'F';
29 static final int AO_LOG_SENSOR = 'A';
30 static final int AO_LOG_TEMP_VOLT = 'T';
31 static final int AO_LOG_DEPLOY = 'D';
32 static final int AO_LOG_STATE = 'S';
33 static final int AO_LOG_GPS_TIME = 'G';
34 static final int AO_LOG_GPS_LAT = 'N';
35 static final int AO_LOG_GPS_LON = 'W';
36 static final int AO_LOG_GPS_ALT = 'H';
37 static final int AO_LOG_GPS_SAT = 'V';
38 static final int AO_LOG_GPS_DATE = 'Y';
39 static final int AO_LOG_PRESSURE = 'P';
41 /* Added for header fields in eeprom files */
42 static final int AO_LOG_CONFIG_VERSION = 1000;
43 static final int AO_LOG_MAIN_DEPLOY = 1001;
44 static final int AO_LOG_APOGEE_DELAY = 1002;
45 static final int AO_LOG_RADIO_CHANNEL = 1003;
46 static final int AO_LOG_CALLSIGN = 1004;
47 static final int AO_LOG_ACCEL_CAL = 1005;
48 static final int AO_LOG_RADIO_CAL = 1006;
49 static final int AO_LOG_MAX_FLIGHT_LOG = 1007;
50 static final int AO_LOG_MANUFACTURER = 2000;
51 static final int AO_LOG_PRODUCT = 2001;
52 static final int AO_LOG_SERIAL_NUMBER = 2002;
53 static final int AO_LOG_SOFTWARE_VERSION = 9999;
55 /* Added to flag invalid records */
56 static final int AO_LOG_INVALID = -1;
58 /* Flight state numbers and names */
59 static final int ao_flight_startup = 0;
60 static final int ao_flight_idle = 1;
61 static final int ao_flight_pad = 2;
62 static final int ao_flight_boost = 3;
63 static final int ao_flight_fast = 4;
64 static final int ao_flight_coast = 5;
65 static final int ao_flight_drogue = 6;
66 static final int ao_flight_main = 7;
67 static final int ao_flight_landed = 8;
68 static final int ao_flight_invalid = 9;
71 static final int ao_telemetry_off = 0;
72 static final int ao_telemetry_full = 1;
73 static final int ao_telemetry_tiny = 2;
75 static HashMap<String,Integer> string_to_state = new HashMap<String,Integer>();
77 static boolean map_initialized = false;
79 static final int tab_elt_pad = 5;
81 static final Font label_font = new Font("Dialog", Font.PLAIN, 22);
82 static final Font value_font = new Font("Monospaced", Font.PLAIN, 22);
83 static final Font status_font = new Font("SansSerif", Font.BOLD, 24);
85 static final int text_width = 16;
87 static void initialize_map()
89 string_to_state.put("startup", ao_flight_startup);
90 string_to_state.put("idle", ao_flight_idle);
91 string_to_state.put("pad", ao_flight_pad);
92 string_to_state.put("boost", ao_flight_boost);
93 string_to_state.put("fast", ao_flight_fast);
94 string_to_state.put("coast", ao_flight_coast);
95 string_to_state.put("drogue", ao_flight_drogue);
96 string_to_state.put("main", ao_flight_main);
97 string_to_state.put("landed", ao_flight_landed);
98 string_to_state.put("invalid", ao_flight_invalid);
99 map_initialized = true;
102 static String[] state_to_string = {
115 static public int state(String state) {
116 if (!map_initialized)
118 if (string_to_state.containsKey(state))
119 return string_to_state.get(state);
120 return ao_flight_invalid;
123 static public String state_name(int state) {
124 if (state < 0 || state_to_string.length <= state)
126 return state_to_string[state];
129 static final int AO_GPS_VALID = (1 << 4);
130 static final int AO_GPS_RUNNING = (1 << 5);
131 static final int AO_GPS_DATE_VALID = (1 << 6);
132 static final int AO_GPS_NUM_SAT_SHIFT = 0;
133 static final int AO_GPS_NUM_SAT_MASK = 0xf;
135 static boolean isspace(int c) {
144 static boolean ishex(int c) {
145 if ('0' <= c && c <= '9')
147 if ('a' <= c && c <= 'f')
149 if ('A' <= c && c <= 'F')
154 static boolean ishex(String s) {
155 for (int i = 0; i < s.length(); i++)
156 if (!ishex(s.charAt(i)))
161 static int fromhex(int c) {
162 if ('0' <= c && c <= '9')
164 if ('a' <= c && c <= 'f')
166 if ('A' <= c && c <= 'F')
171 static int fromhex(String s) throws NumberFormatException {
173 for (int i = 0; i < s.length(); i++) {
177 throw new NumberFormatException(String.format("invalid hex \"%s\"", s));
180 v = v * 16 + fromhex(c);
185 static boolean isdec(int c) {
186 if ('0' <= c && c <= '9')
191 static boolean isdec(String s) {
192 for (int i = 0; i < s.length(); i++)
193 if (!isdec(s.charAt(i)))
198 static int fromdec(int c) {
199 if ('0' <= c && c <= '9')
204 static int fromdec(String s) throws NumberFormatException {
207 for (int i = 0; i < s.length(); i++) {
209 if (i == 0 && c == '-') {
211 } else if (!isdec(c)) {
213 throw new NumberFormatException(String.format("invalid number \"%s\"", s));
216 v = v * 10 + fromdec(c);
221 static String replace_extension(String input, String extension) {
222 int dot = input.lastIndexOf(".");
224 input = input.substring(0,dot);
225 return input.concat(extension);
228 static public boolean initialized = false;
229 static public boolean loaded_library = false;
231 public static boolean load_library() {
234 System.loadLibrary("altos");
235 libaltos.altos_init();
236 loaded_library = true;
237 } catch (UnsatisfiedLinkError e) {
238 loaded_library = false;
242 return loaded_library;
245 static int usb_vendor_altusmetrum() {
247 return libaltosConstants.USB_VENDOR_ALTUSMETRUM;
251 static int usb_product_altusmetrum() {
253 return libaltosConstants.USB_PRODUCT_ALTUSMETRUM;
257 static int usb_product_altusmetrum_min() {
259 return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MIN;
263 static int usb_product_altusmetrum_max() {
265 return libaltosConstants.USB_PRODUCT_ALTUSMETRUM_MAX;
269 static int usb_product_telemetrum() {
271 return libaltosConstants.USB_PRODUCT_TELEMETRUM;
275 static int usb_product_teledongle() {
277 return libaltosConstants.USB_PRODUCT_TELEDONGLE;
281 static int usb_product_teleterra() {
283 return libaltosConstants.USB_PRODUCT_TELETERRA;
287 static int usb_product_telebt() {
289 return libaltosConstants.USB_PRODUCT_TELEBT;
293 public final static int vendor_altusmetrum = usb_vendor_altusmetrum();
294 public final static int product_altusmetrum = usb_product_altusmetrum();
295 public final static int product_telemetrum = usb_product_telemetrum();
296 public final static int product_teledongle = usb_product_teledongle();
297 public final static int product_teleterra = usb_product_teleterra();
298 public final static int product_telebt = usb_product_telebt();
299 public final static int product_altusmetrum_min = usb_product_altusmetrum_min();
300 public final static int product_altusmetrum_max = usb_product_altusmetrum_max();
302 public final static int product_any = 0x10000;
303 public final static int product_basestation = 0x10000 + 1;
305 static String bt_product_telebt() {
307 return libaltosConstants.BLUETOOTH_PRODUCT_TELEBT;
311 public final static String bt_product_telebt = bt_product_telebt();
313 public static AltosBTKnown bt_known = new AltosBTKnown();