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 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_low() { 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); }
85 public int altitude_high() { return data16(26); }
87 /* AO_LOG_GPS_SAT elements */
88 public int nsat() { return data16(0); }
89 public int svid(int n) { return data8(2 + n * 2); }
90 public int c_n(int n) { return data8(2 + n * 2 + 1); }
92 public AltosEepromMega (AltosEepromChunk chunk, int start) throws ParseException {
93 parse_chunk(chunk, start);
96 public void update_state(AltosState state) {
97 super.update_state(state);
101 /* Flush any pending GPS changes */
102 if (state.gps_pending) {
104 case AltosLib.AO_LOG_GPS_LAT:
105 case AltosLib.AO_LOG_GPS_LON:
106 case AltosLib.AO_LOG_GPS_ALT:
107 case AltosLib.AO_LOG_GPS_SAT:
108 case AltosLib.AO_LOG_GPS_DATE:
111 state.set_temp_gps();
117 case AltosLib.AO_LOG_FLIGHT:
118 state.set_boost_tick(tick);
119 state.set_flight(flight());
120 state.set_ground_accel(ground_accel());
121 state.set_ground_pressure(ground_pres());
123 case AltosLib.AO_LOG_STATE:
124 state.set_tick(tick);
125 state.set_state(state());
127 case AltosLib.AO_LOG_SENSOR:
128 state.set_tick(tick);
129 state.set_ms5607(pres(), temp());
131 AltosIMU imu = new AltosIMU();
132 imu.accel_x = AltosIMU.convert_accel(accel_x());
133 imu.accel_y = AltosIMU.convert_accel(accel_y());
134 imu.accel_z = AltosIMU.convert_accel(accel_z());
136 imu.gyro_x = AltosIMU.convert_gyro(gyro_x());
137 imu.gyro_y = AltosIMU.convert_gyro(gyro_y());
138 imu.gyro_z = AltosIMU.convert_gyro(gyro_z());
141 AltosMag mag = new AltosMag();
142 mag.x = AltosMag.convert_gauss(mag_x());
143 mag.y = AltosMag.convert_gauss(mag_y());
144 mag.z = AltosMag.convert_gauss(mag_z());
148 state.set_accel(accel());
151 case AltosLib.AO_LOG_TEMP_VOLT:
152 state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
153 state.set_pyro_voltage(AltosConvert.mega_pyro_voltage(v_pbatt()));
155 int nsense = nsense();
157 state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-2)));
158 state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-1)));
160 double voltages[] = new double[nsense-2];
161 for (int i = 0; i < nsense-2; i++)
162 voltages[i] = AltosConvert.mega_pyro_voltage(sense(i));
164 state.set_ignitor_voltage(voltages);
165 state.set_pyro_fired(pyro());
167 case AltosLib.AO_LOG_GPS_TIME:
168 state.set_tick(tick);
169 gps = state.make_temp_gps(false);
170 gps.lat = latitude() / 1e7;
171 gps.lon = longitude() / 1e7;
173 if (state.altitude_32())
174 gps.alt = (altitude_low() & 0xffff) | (altitude_high() << 16);
176 gps.alt = altitude_low();
179 gps.minute = minute();
180 gps.second = second();
184 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
185 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
186 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
187 AltosLib.AO_GPS_NUM_SAT_SHIFT;
189 gps.year = 2000 + year();
192 gps.ground_speed = ground_speed() * 1.0e-2;
193 gps.course = course() * 2;
194 gps.climb_rate = climb_rate() * 1.0e-2;
195 if (state.compare_version("1.4.9") >= 0) {
196 gps.pdop = pdop() / 10.0;
197 gps.hdop = hdop() / 10.0;
198 gps.vdop = vdop() / 10.0;
200 gps.pdop = pdop() / 100.0;
203 gps.hdop = hdop() / 100.0;
206 gps.vdop = vdop() / 100.0;
211 case AltosLib.AO_LOG_GPS_SAT:
212 state.set_tick(tick);
213 gps = state.make_temp_gps(true);
218 for (int i = 0; i < n; i++)
219 gps.add_sat(svid(i), c_n(i));
224 public AltosEepromMega (String line) {
228 static public LinkedList<AltosEeprom> read(FileInputStream input) {
229 LinkedList<AltosEeprom> megas = new LinkedList<AltosEeprom>();
233 String line = AltosLib.gets(input);
237 AltosEepromMega mega = new AltosEepromMega(line);
238 if (mega.cmd != AltosLib.AO_LOG_INVALID)
240 } catch (Exception e) {
241 System.out.printf ("exception\n");
243 } catch (IOException ie) {