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_2;
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); }
63 /* AO_LOG_GPS_SAT elements */
64 public int nsat() { return data8(0); }
65 public int more() { return data8(1); }
66 public int svid(int n) { return data8(2 + n * 2); }
67 public int c_n(int n) { return data8(2 + n * 2 + 1); }
69 public AltosEepromMetrum2 (AltosEepromChunk chunk, int start) throws ParseException {
70 parse_chunk(chunk, start);
73 public void update_state(AltosState state) {
74 super.update_state(state);
78 /* Flush any pending GPS changes */
79 if (state.gps_pending) {
81 case AltosLib.AO_LOG_GPS_POS:
82 case AltosLib.AO_LOG_GPS_LAT:
83 case AltosLib.AO_LOG_GPS_LON:
84 case AltosLib.AO_LOG_GPS_ALT:
85 case AltosLib.AO_LOG_GPS_SAT:
86 case AltosLib.AO_LOG_GPS_DATE:
95 case AltosLib.AO_LOG_FLIGHT:
96 state.set_flight(flight());
97 state.set_ground_accel(ground_accel());
98 state.set_ground_pressure(ground_pres());
99 // state.set_temperature(ground_temp() / 100.0);
101 case AltosLib.AO_LOG_STATE:
102 state.set_state(state());
104 case AltosLib.AO_LOG_SENSOR:
105 state.set_ms5607(pres(), temp());
106 state.set_accel(accel());
109 case AltosLib.AO_LOG_TEMP_VOLT:
110 state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
112 state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense_a()));
113 state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m()));
116 case AltosLib.AO_LOG_GPS_POS:
117 gps = state.make_temp_gps(false);
118 gps.lat = latitude() / 1e7;
119 gps.lon = longitude() / 1e7;
120 gps.alt = altitude();
122 case AltosLib.AO_LOG_GPS_TIME:
123 gps = state.make_temp_gps(false);
126 gps.minute = minute();
127 gps.second = second();
131 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
132 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
133 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
134 AltosLib.AO_GPS_NUM_SAT_SHIFT;
136 gps.year = 2000 + year();
140 case AltosLib.AO_LOG_GPS_SAT:
141 gps = state.make_temp_gps(true);
144 for (int i = 0; i < n; i++)
145 gps.add_sat(svid(i), c_n(i));
150 public AltosEepromMetrum2 (String line) {
154 static public LinkedList<AltosEeprom> read(FileInputStream input) {
155 LinkedList<AltosEeprom> metrums = new LinkedList<AltosEeprom>();
159 String line = AltosLib.gets(input);
163 AltosEepromMetrum2 metrum = new AltosEepromMetrum2(line);
165 if (metrum.cmd != AltosLib.AO_LOG_INVALID)
167 } catch (Exception e) {
168 System.out.printf ("exception\n");
170 } catch (IOException ie) {