2 * Copyright © 2011 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.
18 package org.altusmetrum.altoslib_5;
24 public class AltosEepromMetrum2 extends AltosEeprom {
25 public static final int record_length = 16;
27 public int record_length() { return record_length; }
29 /* AO_LOG_FLIGHT elements */
30 public int flight() { return data16(0); }
31 public int ground_accel() { return data16(2); }
32 public int ground_pres() { return data32(4); }
33 public int ground_temp() { return data32(8); }
35 /* AO_LOG_STATE elements */
36 public int state() { return data16(0); }
37 public int reason() { return data16(2); }
39 /* AO_LOG_SENSOR elements */
40 public int pres() { return data32(0); }
41 public int temp() { return data32(4); }
42 public int accel() { return data16(8); }
44 /* AO_LOG_TEMP_VOLT elements */
45 public int v_batt() { return data16(0); }
46 public int sense_a() { return data16(2); }
47 public int sense_m() { return data16(4); }
49 /* AO_LOG_GPS_POS elements */
50 public int latitude() { return data32(0); }
51 public int longitude() { return data32(4); }
52 public int altitude() { return data16(8); }
54 /* AO_LOG_GPS_TIME elements */
55 public int hour() { return data8(0); }
56 public int minute() { return data8(1); }
57 public int second() { return data8(2); }
58 public int flags() { return data8(3); }
59 public int year() { return data8(4); }
60 public int month() { return data8(5); }
61 public int day() { return data8(6); }
62 public int pdop() { return data8(7); }
64 /* AO_LOG_GPS_SAT elements */
65 public int nsat() { return data8(0); }
66 public int more() { return data8(1); }
67 public int svid(int n) { return data8(2 + n * 2); }
68 public int c_n(int n) { return data8(2 + n * 2 + 1); }
70 public AltosEepromMetrum2 (AltosEepromChunk chunk, int start) throws ParseException {
71 parse_chunk(chunk, start);
74 public void update_state(AltosState state) {
75 super.update_state(state);
79 /* Flush any pending GPS changes */
80 if (state.gps_pending) {
82 case AltosLib.AO_LOG_GPS_POS:
83 case AltosLib.AO_LOG_GPS_LAT:
84 case AltosLib.AO_LOG_GPS_LON:
85 case AltosLib.AO_LOG_GPS_ALT:
86 case AltosLib.AO_LOG_GPS_SAT:
87 case AltosLib.AO_LOG_GPS_DATE:
96 case AltosLib.AO_LOG_FLIGHT:
97 state.set_flight(flight());
98 state.set_ground_accel(ground_accel());
99 state.set_ground_pressure(ground_pres());
100 // state.set_temperature(ground_temp() / 100.0);
102 case AltosLib.AO_LOG_STATE:
103 state.set_state(state());
105 case AltosLib.AO_LOG_SENSOR:
106 state.set_ms5607(pres(), temp());
107 state.set_accel(accel());
110 case AltosLib.AO_LOG_TEMP_VOLT:
111 state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
113 state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense_a()));
114 state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m()));
117 case AltosLib.AO_LOG_GPS_POS:
118 gps = state.make_temp_gps(false);
119 gps.lat = latitude() / 1e7;
120 gps.lon = longitude() / 1e7;
121 gps.alt = altitude();
123 case AltosLib.AO_LOG_GPS_TIME:
124 gps = state.make_temp_gps(false);
127 gps.minute = minute();
128 gps.second = second();
132 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
133 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
134 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
135 AltosLib.AO_GPS_NUM_SAT_SHIFT;
137 gps.year = 2000 + year();
140 gps.pdop = pdop() / 10.0;
142 case AltosLib.AO_LOG_GPS_SAT:
143 gps = state.make_temp_gps(true);
146 for (int i = 0; i < n; i++)
147 gps.add_sat(svid(i), c_n(i));
152 public AltosEepromMetrum2 (String line) {
156 static public LinkedList<AltosEeprom> read(FileInputStream input) {
157 LinkedList<AltosEeprom> metrums = new LinkedList<AltosEeprom>();
161 String line = AltosLib.gets(input);
165 AltosEepromMetrum2 metrum = new AltosEepromMetrum2(line);
167 if (metrum.cmd != AltosLib.AO_LOG_INVALID)
169 } catch (Exception e) {
170 System.out.printf ("exception\n");
172 } catch (IOException ie) {