altosui: Support gps receiver setting
[fw/altos] / altoslib / AltosLib.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.altoslib_14;
20
21 import java.util.*;
22 import java.io.*;
23 import java.nio.charset.Charset;
24
25 public class AltosLib {
26         /* EEProm command letters */
27         public static final int AO_LOG_FLIGHT = 'F';
28         public static final int AO_LOG_SENSOR = 'A';
29         public static final int AO_LOG_TEMP_VOLT = 'T';
30         public static final int AO_LOG_DEPLOY = 'D';
31         public static final int AO_LOG_STATE = 'S';
32         public static final int AO_LOG_GPS_POS = 'P';
33         public static final int AO_LOG_GPS_TIME = 'G';
34         public static final int AO_LOG_GPS_LAT = 'N';
35         public static final int AO_LOG_GPS_LON = 'W';
36         public static final int AO_LOG_GPS_ALT = 'H';
37         public static final int AO_LOG_GPS_SAT = 'V';
38         public static final int AO_LOG_GPS_DATE = 'Y';
39         public static final int AO_LOG_PRESSURE = 'P';
40
41         public static boolean is_gps_cmd(int cmd) {
42                 switch (cmd) {
43                 case AltosLib.AO_LOG_GPS_POS:
44                 case AltosLib.AO_LOG_GPS_TIME:
45                 case AltosLib.AO_LOG_GPS_LAT:
46                 case AltosLib.AO_LOG_GPS_LON:
47                 case AltosLib.AO_LOG_GPS_ALT:
48                 case AltosLib.AO_LOG_GPS_SAT:
49                 case AltosLib.AO_LOG_GPS_DATE:
50                         return true;
51                 }
52                 return false;
53         }
54
55         /* Added for header fields in eeprom files */
56         public static final int AO_LOG_CONFIG_VERSION = 1000;
57         public static final int AO_LOG_MAIN_DEPLOY = 1001;
58         public static final int AO_LOG_APOGEE_DELAY = 1002;
59         public static final int AO_LOG_RADIO_CHANNEL = 1003;
60         public static final int AO_LOG_CALLSIGN = 1004;
61         public static final int AO_LOG_ACCEL_CAL = 1005;
62         public static final int AO_LOG_RADIO_CAL = 1006;
63         public static final int AO_LOG_MAX_FLIGHT_LOG = 1007;
64         public static final int AO_LOG_MANUFACTURER = 2000;
65         public static final int AO_LOG_PRODUCT = 2001;
66         public static final int AO_LOG_SERIAL_NUMBER = 2002;
67         public static final int AO_LOG_LOG_FORMAT = 2003;
68
69         public static final int AO_LOG_FREQUENCY = 2004;
70         public static final int AO_LOG_APOGEE_LOCKOUT = 2005;
71         public static final int AO_LOG_RADIO_RATE = 2006;
72         public static final int AO_LOG_IGNITE_MODE = 2007;
73         public static final int AO_LOG_PAD_ORIENTATION = 2008;
74         public static final int AO_LOG_RADIO_ENABLE = 2009;
75         public static final int AO_LOG_AES_KEY = 2010;
76         public static final int AO_LOG_APRS = 2011;
77         public static final int AO_LOG_BEEP_SETTING = 2012;
78         public static final int AO_LOG_TRACKER_SETTING = 2013;
79         public static final int AO_LOG_PYRO_TIME = 2014;
80         public static final int AO_LOG_APRS_ID = 2015;
81         public static final int AO_LOG_ALTITUDE_32 = 2016;
82
83         /* Added for header fields in telemega files */
84         public static final int AO_LOG_BARO_RESERVED = 3000;
85         public static final int AO_LOG_BARO_SENS = 3001;
86         public static final int AO_LOG_BARO_OFF = 3002;
87         public static final int AO_LOG_BARO_TCS = 3004;
88         public static final int AO_LOG_BARO_TCO = 3005;
89         public static final int AO_LOG_BARO_TREF = 3006;
90         public static final int AO_LOG_BARO_TEMPSENS = 3007;
91         public static final int AO_LOG_BARO_CRC = 3008;
92         public static final int AO_LOG_IMU_CAL = 3009;
93
94         public static final int AO_LOG_SOFTWARE_VERSION = 9999;
95
96         public final static int MISSING = 0x7fffffff;
97
98         /* Added to flag invalid records */
99         public static final int AO_LOG_INVALID = -1;
100
101         /* Flight state numbers and names */
102         public static final int ao_flight_startup = 0;
103         public static final int ao_flight_idle = 1;
104         public static final int ao_flight_pad = 2;
105         public static final int ao_flight_boost = 3;
106         public static final int ao_flight_fast = 4;
107         public static final int ao_flight_coast = 5;
108         public static final int ao_flight_drogue = 6;
109         public static final int ao_flight_main = 7;
110         public static final int ao_flight_landed = 8;
111         public static final int ao_flight_invalid = 9;
112         public static final int ao_flight_stateless = 10;
113
114         /* USB product IDs */
115         public final static int vendor_altusmetrum = 0xfffe;
116
117         public final static int product_altusmetrum = 0x000a;
118         public final static int product_telemetrum = 0x000b;
119         public final static int product_teledongle = 0x000c;
120         public final static int product_easytimer = 0x000d;
121         public final static int product_telebt = 0x000e;
122         public final static int product_telelaunch = 0x000f;
123         public final static int product_telelco = 0x0010;
124         public final static int product_telescience = 0x0011;
125         public final static int product_telepyro =0x0012;
126         public final static int product_telemega = 0x0023;
127         public final static int product_megadongle = 0x0024;
128         public final static int product_telegps = 0x0025;
129         public final static int product_easymini = 0x0026;
130         public final static int product_telemini = 0x0027;
131         public final static int product_easymega = 0x0028;
132         public final static int product_usbtrng = 0x0029;
133         public final static int product_usbrelay = 0x002a;
134         public final static int product_mpusb = 0x002b;
135         public final static int product_easymotor = 0x002c;
136         public final static int product_altusmetrum_min = 0x000a;
137         public final static int product_altusmetrum_max = 0x002c;
138
139         public final static int product_any = 0x10000;
140         public final static int product_basestation = 0x10000 + 1;
141         public final static int product_altimeter = 0x10000 + 2;
142
143         public final static int gps_builtin = 0;
144         public final static int gps_mosaic = 1;
145
146         public final static String[] gps_receiver_names = {
147                 "Builtin", "Mosaic-X5"
148         };
149
150         private static class Product {
151                 final String    name;
152                 final int       product;
153
154                 Product (String name, int product) {
155                         this.name = name;
156                         this.product = product;
157                 }
158         }
159
160         private static Product[] products = {
161                 new Product("telemetrum", product_telemetrum),
162                 new Product("teleballoon", product_telemetrum),
163                 new Product("teledongle", product_teledongle),
164                 new Product("easytimer", product_easytimer),
165                 new Product("telebt", product_telebt),
166                 new Product("telelaunch", product_telelaunch),
167                 new Product("telelco", product_telelco),
168                 new Product("telescience", product_telescience),
169                 new Product("telepyro", product_telepyro),
170                 new Product("telemega", product_telemega),
171                 new Product("megadongle", product_megadongle),
172                 new Product("telegps", product_telegps),
173                 new Product("easymini", product_easymini),
174                 new Product("telemini", product_telemini),
175                 new Product("easymega", product_easymega),
176                 new Product("easymotor", product_easymotor)
177         };
178
179         public static int name_to_product(String name) {
180                 String low = name.toLowerCase();
181
182                 for (int i = 0; i < products.length; i++)
183                         if (low.startsWith(products[i].name))
184                                 return products[i].product;
185                 return product_any;
186         }
187
188         public static boolean has_9dof(int device_type) {
189                 return device_type == product_telemega || device_type == product_easymega;
190         }
191
192         public static boolean has_radio(int device_type) {
193                 return device_type != product_easymini && device_type != product_easymega;
194         }
195
196         public static boolean has_gps(int device_type) {
197                 return device_type == product_telemetrum ||
198                         device_type == product_telemega ||
199                         device_type == product_telegps;
200         }
201
202         /* Bluetooth "identifier" (bluetooth sucks) */
203         public final static String bt_product_telebt = "TeleBT";
204
205         /* "good" voltages */
206
207         public final static double ao_battery_good = 3.8;
208         public final static double ao_igniter_good = 3.5;
209
210         /* Telemetry modes */
211         public static final int ao_telemetry_off = 0;
212         public static final int ao_telemetry_min = 1;
213         public static final int ao_telemetry_standard = 1;
214         public static final int ao_telemetry_0_9 = 2;
215         public static final int ao_telemetry_0_8 = 3;
216         public static final int ao_telemetry_max = 3;
217
218         private static final String[] ao_telemetry_name = {
219                 "Off", "Standard Telemetry", "TeleMetrum v0.9", "TeleMetrum v0.8"
220         };
221
222         public static final int ao_telemetry_rate_38400 = 0;
223         public static final int ao_telemetry_rate_9600 = 1;
224         public static final int ao_telemetry_rate_2400 = 2;
225         public static final int ao_telemetry_rate_max = 2;
226
227         public static final Integer[] ao_telemetry_rate_values = {
228                 38400, 9600, 2400
229         };
230
231         public static final int ao_aprs_format_compressed = 0;
232         public static final int ao_aprs_format_uncompressed = 1;
233
234         public static final String[] ao_aprs_format_name = {
235                 "Compressed", "Uncompressed"
236         };
237
238         public static final String launch_sites_url = "https://maps.altusmetrum.org/launch-sites.txt";
239         public static final String launch_sites_env = "LAUNCH_SITES";
240 //      public static final String launch_sites_url = "file:///home/keithp/misc/text/altusmetrum/AltOS/launch-sites.txt";
241
242         public static final String unit_info_url = "https://altusmetrum.org/cgi-bin/unitinfo.cgi?sn=%d";
243         public static final String unit_info_env = "UNIT_INFO";
244
245         public static final int ao_telemetry_standard_len = 32;
246         public static final int ao_telemetry_0_9_len = 95;
247         public static final int ao_telemetry_0_8_len = 94;
248
249         private static final int[] ao_telemetry_len = {
250                 0, 32, 95, 94
251         };
252
253         private static HashMap<String,Integer>  string_to_state = new HashMap<String,Integer>();
254
255         private static boolean map_initialized = false;
256
257         public static void initialize_map()
258         {
259                 string_to_state.put("startup", ao_flight_startup);
260                 string_to_state.put("idle", ao_flight_idle);
261                 string_to_state.put("pad", ao_flight_pad);
262                 string_to_state.put("boost", ao_flight_boost);
263                 string_to_state.put("fast", ao_flight_fast);
264                 string_to_state.put("coast", ao_flight_coast);
265                 string_to_state.put("drogue", ao_flight_drogue);
266                 string_to_state.put("apogee", ao_flight_coast);
267                 string_to_state.put("main", ao_flight_main);
268                 string_to_state.put("landed", ao_flight_landed);
269                 string_to_state.put("invalid", ao_flight_invalid);
270                 string_to_state.put("stateless", ao_flight_stateless);
271                 map_initialized = true;
272         }
273
274         public static int telemetry_len(int telemetry) {
275                 if (telemetry <= ao_telemetry_max)
276                         return ao_telemetry_len[telemetry];
277                 throw new IllegalArgumentException(String.format("Invalid telemetry %d",
278                                                                  telemetry));
279         }
280
281         public static String telemetry_name(int telemetry) {
282                 if (telemetry <= ao_telemetry_max)
283                         return ao_telemetry_name[telemetry];
284                 throw new IllegalArgumentException(String.format("Invalid telemetry %d",
285                                                                  telemetry));
286         }
287
288         private static int[] split_version(String version) {
289                 String[] tokens = version.split("\\.");
290                 int[] ret = new int[tokens.length];
291                 for (int i = 0; i < tokens.length; i++)
292                         ret[i] = Integer.parseInt(tokens[i]);
293                 return ret;
294         }
295
296         public static int compare_version(String version_a, String version_b) {
297                 int[] a = split_version(version_a);
298                 int[] b = split_version(version_b);
299
300                 for (int i = 0; i < Math.min(a.length, b.length); i++) {
301                         if (a[i] < b[i])
302                                 return -1;
303                         if (a[i] > b[i])
304                                 return 1;
305                 }
306                 if (a.length < b.length)
307                         return -1;
308                 if (a.length > b.length)
309                         return 1;
310                 return 0;
311         }
312
313         private static String[] state_to_string = {
314                 "startup",
315                 "idle",
316                 "pad",
317                 "boost",
318                 "fast",
319                 "coast",
320                 "drogue",
321                 "main",
322                 "landed",
323                 "invalid",
324                 "stateless",
325         };
326
327         private static String[] state_to_string_capital = {
328                 "Startup",
329                 "Idle",
330                 "Pad",
331                 "Boost",
332                 "Fast",
333                 "Coast",
334                 "Drogue",
335                 "Main",
336                 "Landed",
337                 "Invalid",
338                 "Stateless",
339         };
340
341         public static int state(String state) {
342                 if (!map_initialized)
343                         initialize_map();
344                 if (string_to_state.containsKey(state))
345                         return string_to_state.get(state);
346                 return ao_flight_invalid;
347         }
348
349         public static String state_name(int state) {
350                 if (state < 0 || state_to_string.length <= state)
351                         return "invalid";
352                 return state_to_string[state];
353         }
354
355         public static String state_name_capital(int state) {
356                 if (state < 0 || state_to_string.length <= state)
357                         return "Invalid";
358                 return state_to_string_capital[state];
359         }
360
361         public static final int AO_GPS_VALID = (1 << 4);
362         public static final int AO_GPS_RUNNING = (1 << 5);
363         public static final int AO_GPS_DATE_VALID = (1 << 6);
364         public static final int AO_GPS_NUM_SAT_SHIFT = 0;
365         public static final int AO_GPS_NUM_SAT_MASK = 0xf;
366
367         public static final int AO_PAD_ORIENTATION_ANTENNA_UP = 0;
368         public static final int AO_PAD_ORIENTATION_ANTENNA_DOWN = 1;
369         public static final int AO_PAD_ORIENTATION_WORDS_UPRIGHT = 2;
370         public static final int AO_PAD_ORIENTATION_WORDS_UPSIDEDOWN = 3;
371         public static final int AO_PAD_ORIENTATION_BIG_PARTS_UP = 4;
372         public static final int AO_PAD_ORIENTATION_BIG_PARTS_DOWN = 5;
373
374         public static final int AO_LOG_FORMAT_UNKNOWN = 0;
375         public static final int AO_LOG_FORMAT_FULL = 1;
376         public static final int AO_LOG_FORMAT_TINY = 2;
377         public static final int AO_LOG_FORMAT_TELEMETRY = 3;
378         public static final int AO_LOG_FORMAT_TELESCIENCE = 4;
379         public static final int AO_LOG_FORMAT_TELEMEGA_OLD = 5;
380         public static final int AO_LOG_FORMAT_EASYMINI1 = 6;
381         public static final int AO_LOG_FORMAT_TELEMETRUM = 7;
382         public static final int AO_LOG_FORMAT_TELEMINI2 = 8;
383         public static final int AO_LOG_FORMAT_TELEGPS = 9;
384         public static final int AO_LOG_FORMAT_TELEMEGA = 10;
385         public static final int AO_LOG_FORMAT_DETHERM = 11;
386         public static final int AO_LOG_FORMAT_TELEMINI3 = 12;
387         public static final int AO_LOG_FORMAT_TELEFIRETWO = 13;
388         public static final int AO_LOG_FORMAT_EASYMINI2 = 14;
389         public static final int AO_LOG_FORMAT_TELEMEGA_3 = 15;
390         public static final int AO_LOG_FORMAT_EASYMEGA_2 = 16;
391         public static final int AO_LOG_FORMAT_TELESTATIC = 17;
392         public static final int AO_LOG_FORMAT_MICROPEAK2 = 18;
393         public static final int AO_LOG_FORMAT_TELEMEGA_4 = 19;
394         public static final int AO_LOG_FORMAT_EASYMOTOR = 20;
395         public static final int AO_LOG_FORMAT_TELEMEGA_5 = 21;
396         public static final int AO_LOG_FORMAT_TELEMEGA_6 = 22;
397         public static final int AO_LOG_FORMAT_NONE = 127;
398
399         public static final int model_mpu6000 = 0;
400         public static final int model_mpu9250 = 1;
401         public static final int model_adxl375 = 2;
402         public static final int model_bmx160 = 3;
403         public static final int model_hmc5883 = 4;
404         public static final int model_mmc5983 = 5;
405         public static final int model_bmi088 = 6;
406
407         public static boolean isspace(int c) {
408                 switch (c) {
409                 case ' ':
410                 case '\t':
411                         return true;
412                 }
413                 return false;
414         }
415
416         public static final boolean ishex(int c) {
417                 if ('0' <= c && c <= '9')
418                         return true;
419                 if ('a' <= c && c <= 'f')
420                         return true;
421                 if ('A' <= c && c <= 'F')
422                         return true;
423                 return false;
424         }
425
426         public static final boolean ishex(String s) {
427                 for (int i = 0; i < s.length(); i++)
428                         if (!ishex(s.charAt(i)))
429                                 return false;
430                 return true;
431         }
432
433         public static int fromhex(int c) {
434                 if ('0' <= c && c <= '9')
435                         return c - '0';
436                 if ('a' <= c && c <= 'f')
437                         return c - 'a' + 10;
438                 if ('A' <= c && c <= 'F')
439                         return c - 'A' + 10;
440                 return -1;
441         }
442
443         public static int fromhex(String s) throws NumberFormatException {
444                 int c, v = 0;
445                 for (int i = 0; i < s.length(); i++) {
446                         c = s.charAt(i);
447                         if (!ishex(c)) {
448                                 if (i == 0)
449                                         throw new NumberFormatException(String.format("invalid hex \"%s\"", s));
450                                 return v;
451                         }
452                         v = v * 16 + fromhex(c);
453                 }
454                 return v;
455         }
456
457         public static boolean isdec(int c) {
458                 if ('0' <= c && c <= '9')
459                         return true;
460                 return false;
461         }
462
463         public static boolean isdec(String s) {
464                 for (int i = 0; i < s.length(); i++)
465                         if (!isdec(s.charAt(i)))
466                                 return false;
467                 return true;
468         }
469
470         public static int fromdec(int c) {
471                 if ('0' <= c && c <= '9')
472                         return c - '0';
473                 return -1;
474         }
475
476         public static int int8(int[] bytes, int i) {
477                 return (int) (byte) bytes[i];
478         }
479
480         public static int uint8(int[] bytes, int i) {
481                 return bytes[i];
482         }
483
484         public static int int16(int[] bytes, int i) {
485                 return (int) (short) (bytes[i] + (bytes[i+1] << 8));
486         }
487
488         public static int uint16(int[] bytes, int i) {
489                 return bytes[i] + (bytes[i+1] << 8);
490         }
491
492         public static int uint32(int[] bytes, int i) {
493                 return bytes[i] +
494                         (bytes[i+1] << 8) +
495                         (bytes[i+2] << 16) +
496                         (bytes[i+3] << 24);
497         }
498
499         public static int int32(int[] bytes, int i) {
500                 return (int) uint32(bytes, i);
501         }
502
503         public static final Charset     unicode_set = Charset.forName("UTF-8");
504
505         public static String string(int[] bytes, int s, int l) {
506                 if (s + l > bytes.length) {
507                         if (s > bytes.length) {
508                                 s = bytes.length;
509                                 l = 0;
510                         } else {
511                                 l = bytes.length - s;
512                         }
513                 }
514
515                 int i;
516                 for (i = l - 1; i >= 0; i--)
517                         if (bytes[s+i] != 0)
518                                 break;
519
520                 l = i + 1;
521                 byte[]  b = new byte[l];
522
523                 for (i = 0; i < l; i++)
524                         b[i] = (byte) bytes[s+i];
525                 String n = new String(b, unicode_set);
526                 return n;
527         }
528
529         public static int hexbyte(String s, int i) {
530                 int c0, c1;
531
532                 if (s.length() < i + 2)
533                         throw new NumberFormatException(String.format("invalid hex \"%s\"", s));
534                 c0 = s.charAt(i);
535                 if (!ishex(c0))
536                         throw new NumberFormatException(String.format("invalid hex \"%c\"", c0));
537                 c1 = s.charAt(i+1);
538                 if (!ishex(c1))
539                         throw new NumberFormatException(String.format("invalid hex \"%c\"", c1));
540                 return fromhex(c0) * 16 + fromhex(c1);
541         }
542
543         public static int[] hexbytes(String s) {
544                 int     n;
545                 int[]   r;
546                 int     i;
547
548                 if ((s.length() & 1) != 0)
549                         throw new NumberFormatException(String.format("invalid line \"%s\"", s));
550                 byte[] bytes = s.getBytes(unicode_set);
551                 n = bytes.length / 2;
552                 r = new int[n];
553                 for (i = 0; i < n; i++) {
554                         int h = fromhex(bytes[(i << 1)]);
555                         int l = fromhex(bytes[(i << 1) + 1]);
556                         if (h < 0 || l < 0)
557                                 throw new NumberFormatException(String.format("invalid hex \"%c%c\"",
558                                                                               bytes[(i<<1)], bytes[(i<<1) + 1]));
559                         r[i] = (h << 4) + l;
560                 }
561                 return r;
562         }
563
564         public static long fromdec(String s) throws NumberFormatException {
565                 int c;
566                 long v = 0;
567                 long sign = 1;
568                 for (int i = 0; i < s.length(); i++) {
569                         c = s.charAt(i);
570                         if (i == 0 && c == '-') {
571                                 sign = -1;
572                         } else if (!isdec(c)) {
573                                 if (i == 0)
574                                         throw new NumberFormatException(String.format("invalid number \"%s\"", s));
575                                 return v;
576                         } else
577                                 v = v * 10 + fromdec(c);
578                 }
579                 return v * sign;
580         }
581
582         public static String gets(FileInputStream s) throws IOException {
583                 int c;
584                 String  line = "";
585
586                 while ((c = s.read()) != -1) {
587                         if (c == '\r')
588                                 continue;
589                         if (c == '\n') {
590                                 return line;
591                         }
592                         line = line + (char) c;
593                 }
594                 return null;
595         }
596
597         public static String replace_extension(String input, String extension) {
598                 int dot = input.lastIndexOf(".");
599                 if (dot > 0)
600                         input = input.substring(0,dot);
601                 return input.concat(extension);
602         }
603
604         public static File replace_extension(File input, String extension) {
605                 return new File(replace_extension(input.getPath(), extension));
606         }
607
608         public static String product_name(int product_id) {
609                 switch (product_id) {
610                 case product_altusmetrum: return "AltusMetrum";
611                 case product_telemetrum: return "TeleMetrum";
612                 case product_teledongle: return "TeleDongle";
613                 case product_easytimer: return "EasyTimer";
614                 case product_telebt: return "TeleBT";
615                 case product_telelaunch: return "TeleLaunch";
616                 case product_telelco: return "TeleLco";
617                 case product_telescience: return "Telescience";
618                 case product_telepyro: return "TelePyro";
619                 case product_telemega: return "TeleMega";
620                 case product_megadongle: return "MegaDongle";
621                 case product_telegps: return "TeleGPS";
622                 case product_easymini: return "EasyMini";
623                 case product_telemini: return "TeleMini";
624                 case product_easymotor: return "EasyMotor";
625                 default: return "unknown";
626                 }
627         }
628
629         public static int product_id_from_log_format(int log_format) {
630                 switch (log_format){
631                 case AO_LOG_FORMAT_UNKNOWN:
632                         return product_altusmetrum;
633                 case AO_LOG_FORMAT_FULL:
634                         return product_telemetrum;
635                 case AO_LOG_FORMAT_TINY:
636                         return product_telemini;
637                 case AO_LOG_FORMAT_TELEMETRY:
638                         return product_altusmetrum;
639                 case AO_LOG_FORMAT_TELESCIENCE:
640                         return product_telescience;
641                 case AO_LOG_FORMAT_TELEMEGA_OLD:
642                         return product_telemega;
643                 case AO_LOG_FORMAT_EASYMINI1:
644                         return product_easymini;
645                 case AO_LOG_FORMAT_TELEMETRUM:
646                         return product_telemetrum;
647                 case AO_LOG_FORMAT_TELEMINI2:
648                         return product_telemini;
649                 case AO_LOG_FORMAT_TELEGPS:
650                         return product_telegps;
651                 case AO_LOG_FORMAT_TELEMEGA:
652                         return product_telemega;
653                 case AO_LOG_FORMAT_DETHERM:
654                         return product_altusmetrum;
655                 case AO_LOG_FORMAT_TELEMINI3:
656                         return product_telemini;
657                 case AO_LOG_FORMAT_TELEFIRETWO:
658                         return product_altusmetrum;
659                 case AO_LOG_FORMAT_EASYMINI2:
660                         return product_easymini;
661                 case AO_LOG_FORMAT_TELEMEGA_3:
662                         return product_telemega;
663                 case AO_LOG_FORMAT_EASYMEGA_2:
664                         return product_easymega;
665                 case AO_LOG_FORMAT_TELESTATIC:
666                         return product_altusmetrum;
667                 case AO_LOG_FORMAT_MICROPEAK2:
668                         return product_altusmetrum;
669                 case AO_LOG_FORMAT_TELEMEGA_4:
670                         return product_telemega;
671                 case AO_LOG_FORMAT_EASYMOTOR:
672                         return product_easymotor;
673                 case AO_LOG_FORMAT_TELEMEGA_5:
674                         return product_telemega;
675                 case AO_LOG_FORMAT_TELEMEGA_6:
676                         return product_telemega;
677                 case AO_LOG_FORMAT_NONE:
678                         return product_altusmetrum;
679                 default:
680                         return product_altusmetrum;
681                 }
682         }
683
684         public static String igniter_name(int i) {
685                 return String.format("Igniter %c", 'A' + i);
686         }
687
688         public static String igniter_short_name(int i) {
689                 return String.format("igniter_%c", 'a' + i);
690         }
691
692         public static AltosRecordSet record_set(File file) throws FileNotFoundException, IOException {
693                 FileInputStream in;
694                 in = new FileInputStream(file);
695                 if (file.getName().endsWith("telem")) {
696                         return new AltosTelemetryFile(in);
697                 } else if (file.getName().endsWith("eeprom")) {
698                         return new AltosEepromFile(in);
699                 } else {
700                         String  name = file.getName();
701                         int     dot = name.lastIndexOf('.');
702                         String  extension;
703
704                         if (dot == -1)
705                                 throw new IOException(String.format("%s (Missing extension)", file.toString()));
706                         else {
707                                 extension = name.substring(dot);
708                                 throw new IOException(String.format("%s (Invalid extension '%s')",
709                                                                     file.toString(),
710                                                                     extension));
711                         }
712                 }
713         }
714
715 }