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_4;
24 public class AltosEepromMega extends AltosEeprom {
25 public static final int record_length = 32;
27 public static final int max_sat = 12;
29 public int record_length() { return record_length; }
31 /* AO_LOG_FLIGHT elements */
32 public int flight() { return data16(0); }
33 public int ground_accel() { return data16(2); }
34 public int ground_pres() { return data32(4); }
35 public int ground_accel_along() { return data16(8); }
36 public int ground_accel_across() { return data16(10); }
37 public int ground_accel_through() { return data16(12); }
38 public int ground_roll() { return data16(14); }
39 public int ground_pitch() { return data16(16); }
40 public int ground_yaw() { return data16(18); }
42 /* AO_LOG_STATE elements */
43 public int state() { return data16(0); }
44 public int reason() { return data16(2); }
46 /* AO_LOG_SENSOR elements */
47 public int pres() { return data32(0); }
48 public int temp() { return data32(4); }
49 public int accel_x() { return data16(8); }
50 public int accel_y() { return data16(10); }
51 public int accel_z() { return data16(12); }
52 public int gyro_x() { return data16(14); }
53 public int gyro_y() { return data16(16); }
54 public int gyro_z() { return data16(18); }
55 public int mag_x() { return data16(20); }
56 public int mag_y() { return data16(22); }
57 public int mag_z() { return data16(24); }
58 public int accel() { return data16(26); }
60 /* AO_LOG_TEMP_VOLT elements */
61 public int v_batt() { return data16(0); }
62 public int v_pbatt() { return data16(2); }
63 public int nsense() { return data16(4); }
64 public int sense(int i) { return data16(6 + i * 2); }
65 public int pyro() { return data16(26); }
67 /* AO_LOG_GPS_TIME elements */
68 public int latitude() { return data32(0); }
69 public int longitude() { return data32(4); }
70 public int altitude() { return data16(8); }
71 public int hour() { return data8(10); }
72 public int minute() { return data8(11); }
73 public int second() { return data8(12); }
74 public int flags() { return data8(13); }
75 public int year() { return data8(14); }
76 public int month() { return data8(15); }
77 public int day() { return data8(16); }
78 public int course() { return data8(17); }
79 public int ground_speed() { return data16(18); }
80 public int climb_rate() { return data16(20); }
81 public int pdop() { return data8(22); }
82 public int hdop() { return data8(23); }
83 public int vdop() { return data8(24); }
84 public int mode() { return data8(25); }
86 /* AO_LOG_GPS_SAT elements */
87 public int nsat() { return data16(0); }
88 public int svid(int n) { return data8(2 + n * 2); }
89 public int c_n(int n) { return data8(2 + n * 2 + 1); }
91 public AltosEepromMega (AltosEepromChunk chunk, int start) throws ParseException {
92 parse_chunk(chunk, start);
95 public void update_state(AltosState state) {
96 super.update_state(state);
100 /* Flush any pending GPS changes */
101 if (state.gps_pending) {
103 case AltosLib.AO_LOG_GPS_LAT:
104 case AltosLib.AO_LOG_GPS_LON:
105 case AltosLib.AO_LOG_GPS_ALT:
106 case AltosLib.AO_LOG_GPS_SAT:
107 case AltosLib.AO_LOG_GPS_DATE:
110 state.set_temp_gps();
116 case AltosLib.AO_LOG_FLIGHT:
117 state.set_boost_tick(tick);
118 state.set_flight(flight());
119 state.set_ground_accel(ground_accel());
120 state.set_ground_pressure(ground_pres());
122 case AltosLib.AO_LOG_STATE:
123 state.set_tick(tick);
124 state.set_state(state());
126 case AltosLib.AO_LOG_SENSOR:
127 state.set_tick(tick);
128 state.set_ms5607(pres(), temp());
130 AltosIMU imu = new AltosIMU();
131 imu.accel_x = AltosIMU.convert_accel(accel_x());
132 imu.accel_y = AltosIMU.convert_accel(accel_y());
133 imu.accel_z = AltosIMU.convert_accel(accel_z());
135 imu.gyro_x = AltosIMU.convert_gyro(gyro_x());
136 imu.gyro_y = AltosIMU.convert_gyro(gyro_y());
137 imu.gyro_z = AltosIMU.convert_gyro(gyro_z());
140 AltosMag mag = new AltosMag();
141 mag.x = AltosMag.convert_gauss(mag_x());
142 mag.y = AltosMag.convert_gauss(mag_y());
143 mag.z = AltosMag.convert_gauss(mag_z());
147 state.set_accel(accel());
150 case AltosLib.AO_LOG_TEMP_VOLT:
151 state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
152 state.set_pyro_voltage(AltosConvert.mega_pyro_voltage(v_pbatt()));
154 int nsense = nsense();
156 state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-2)));
157 state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-1)));
159 double voltages[] = new double[nsense-2];
160 for (int i = 0; i < nsense-2; i++)
161 voltages[i] = AltosConvert.mega_pyro_voltage(sense(i));
163 state.set_ignitor_voltage(voltages);
164 state.set_pyro_fired(pyro());
166 case AltosLib.AO_LOG_GPS_TIME:
167 state.set_tick(tick);
168 gps = state.make_temp_gps(false);
169 gps.lat = latitude() / 1e7;
170 gps.lon = longitude() / 1e7;
171 gps.alt = altitude();
174 gps.minute = minute();
175 gps.second = second();
179 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
180 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
181 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
182 AltosLib.AO_GPS_NUM_SAT_SHIFT;
184 gps.year = 2000 + year();
187 gps.ground_speed = ground_speed() * 1.0e-2;
188 gps.course = course() * 2;
189 gps.climb_rate = climb_rate() * 1.0e-2;
193 case AltosLib.AO_LOG_GPS_SAT:
194 state.set_tick(tick);
195 gps = state.make_temp_gps(true);
200 for (int i = 0; i < n; i++)
201 gps.add_sat(svid(i), c_n(i));
206 public AltosEepromMega (String line) {
210 static public LinkedList<AltosEeprom> read(FileInputStream input) {
211 LinkedList<AltosEeprom> megas = new LinkedList<AltosEeprom>();
215 String line = AltosLib.gets(input);
219 AltosEepromMega mega = new AltosEepromMega(line);
220 if (mega.cmd != AltosLib.AO_LOG_INVALID)
222 } catch (Exception e) {
223 System.out.printf ("exception\n");
225 } catch (IOException ie) {