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 AltosEepromMega extends AltosEeprom {
25 public static final int record_length = 32;
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_x() { return data16(8); }
43 public int accel_y() { return data16(10); }
44 public int accel_z() { return data16(12); }
45 public int gyro_x() { return data16(14); }
46 public int gyro_y() { return data16(16); }
47 public int gyro_z() { return data16(18); }
48 public int mag_x() { return data16(20); }
49 public int mag_y() { return data16(22); }
50 public int mag_z() { return data16(24); }
51 public int accel() { return data16(26); }
53 /* AO_LOG_TEMP_VOLT elements */
54 public int v_batt() { return data16(0); }
55 public int v_pbatt() { return data16(2); }
56 public int nsense() { return data16(4); }
57 public int sense(int i) { return data16(6 + i * 2); }
58 public int pyro() { return data16(26); }
60 /* AO_LOG_GPS_TIME elements */
61 public int latitude() { return data32(0); }
62 public int longitude() { return data32(4); }
63 public int altitude() { return data16(8); }
64 public int hour() { return data8(10); }
65 public int minute() { return data8(11); }
66 public int second() { return data8(12); }
67 public int flags() { return data8(13); }
68 public int year() { return data8(14); }
69 public int month() { return data8(15); }
70 public int day() { return data8(16); }
72 /* AO_LOG_GPS_SAT elements */
73 public int nsat() { return data16(0); }
74 public int svid(int n) { return data8(2 + n * 2); }
75 public int c_n(int n) { return data8(2 + n * 2 + 1); }
77 public AltosEepromMega (AltosEepromChunk chunk, int start) throws ParseException {
78 parse_chunk(chunk, start);
81 public void update_state(AltosState state) {
82 super.update_state(state);
86 /* Flush any pending GPS changes */
87 if (state.gps_pending) {
89 case AltosLib.AO_LOG_GPS_LAT:
90 case AltosLib.AO_LOG_GPS_LON:
91 case AltosLib.AO_LOG_GPS_ALT:
92 case AltosLib.AO_LOG_GPS_SAT:
93 case AltosLib.AO_LOG_GPS_DATE:
102 case AltosLib.AO_LOG_FLIGHT:
103 state.set_boost_tick(tick);
104 state.set_flight(flight());
105 state.set_ground_accel(ground_accel());
106 state.set_ground_pressure(ground_pres());
107 state.set_temperature(ground_temp() / 100.0);
109 case AltosLib.AO_LOG_STATE:
110 state.set_tick(tick);
111 state.set_state(state());
113 case AltosLib.AO_LOG_SENSOR:
114 state.set_tick(tick);
115 state.set_ms5607(pres(), temp());
117 AltosIMU imu = new AltosIMU();
118 imu.accel_x = accel_x();
119 imu.accel_y = accel_y();
120 imu.accel_z = accel_z();
122 imu.gyro_x = gyro_x();
123 imu.gyro_y = gyro_y();
124 imu.gyro_z = gyro_z();
127 AltosMag mag = new AltosMag();
134 state.set_accel(accel());
137 case AltosLib.AO_LOG_TEMP_VOLT:
138 state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
139 state.set_pyro_voltage(AltosConvert.mega_pyro_voltage(v_pbatt()));
141 int nsense = nsense();
143 state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-2)));
144 state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-1)));
146 double voltages[] = new double[nsense-2];
147 for (int i = 0; i < nsense-2; i++)
148 voltages[i] = AltosConvert.mega_pyro_voltage(sense(i));
150 state.set_ignitor_voltage(voltages);
152 case AltosLib.AO_LOG_GPS_TIME:
153 state.set_tick(tick);
154 gps = state.make_temp_gps(false);
155 gps.lat = latitude() / 1e7;
156 gps.lon = longitude() / 1e7;
157 gps.alt = altitude();
160 gps.minute = minute();
161 gps.second = second();
165 gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
166 gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
167 gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
168 AltosLib.AO_GPS_NUM_SAT_SHIFT;
170 gps.year = 2000 + year();
174 case AltosLib.AO_LOG_GPS_SAT:
175 state.set_tick(tick);
176 gps = state.make_temp_gps(true);
179 for (int i = 0; i < n; i++)
180 gps.add_sat(svid(i), c_n(i));
185 public AltosEepromMega (String line) {
189 static public LinkedList<AltosEeprom> read(FileInputStream input) {
190 LinkedList<AltosEeprom> megas = new LinkedList<AltosEeprom>();
194 String line = AltosLib.gets(input);
198 AltosEepromMega mega = new AltosEepromMega(line);
199 if (mega.cmd != AltosLib.AO_LOG_INVALID)
201 } catch (Exception e) {
202 System.out.printf ("exception\n");
204 } catch (IOException ie) {