altosui: Add EasyMini bits to fat distribution images. Update telemetrum.inf
[fw/altos] / altoslib / AltosEepromMega.java
1 /*
2  * Copyright © 2011 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package org.altusmetrum.altoslib_2;
19
20 import java.io.*;
21 import java.util.*;
22 import java.text.*;
23
24 public class AltosEepromMega extends AltosEeprom {
25         public static final int record_length = 32;
26
27         public int record_length() { return record_length; }
28
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); }
34
35         /* AO_LOG_STATE elements */
36         public int state() { return data16(0); }
37         public int reason() { return data16(2); }
38
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); }
52
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); }
59
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); }
71         
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); }
76
77         public AltosEepromMega (AltosEepromChunk chunk, int start) throws ParseException {
78                 parse_chunk(chunk, start);
79         }
80
81         public void update_state(AltosState state) {
82                 super.update_state(state);
83
84                 AltosGPS        gps;
85
86                 /* Flush any pending GPS changes */
87                 if (state.gps_pending) {
88                         switch (cmd) {
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:
94                                 break;
95                         default:
96                                 state.set_temp_gps();
97                                 break;
98                         }
99                 }
100
101                 switch (cmd) {
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);
108                         break;
109                 case AltosLib.AO_LOG_STATE:
110                         state.set_tick(tick);
111                         state.set_state(state());
112                         break;
113                 case AltosLib.AO_LOG_SENSOR:
114                         state.set_tick(tick);
115                         state.set_ms5607(pres(), temp());
116
117                         AltosIMU imu = new AltosIMU();
118                         imu.accel_x = accel_x();
119                         imu.accel_y = accel_y();
120                         imu.accel_z = accel_z();
121
122                         imu.gyro_x = gyro_x();
123                         imu.gyro_y = gyro_y();
124                         imu.gyro_z = gyro_z();
125                         state.imu = imu;
126
127                         AltosMag mag = new AltosMag();
128                         mag.x = mag_x();
129                         mag.y = mag_y();
130                         mag.z = mag_z();
131
132                         state.mag = mag;
133
134                         state.set_accel(accel());
135
136                         break;
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()));
140
141                         int nsense = nsense();
142
143                         state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-2)));
144                         state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-1)));
145
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));
149
150                         state.set_ignitor_voltage(voltages);
151                         break;
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();
158
159                         gps.hour = hour();
160                         gps.minute = minute();
161                         gps.second = second();
162
163                         int flags = flags();
164
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;
169
170                         gps.year = 2000 + year();
171                         gps.month = month();
172                         gps.day = day();
173                         break;
174                 case AltosLib.AO_LOG_GPS_SAT:
175                         state.set_tick(tick);
176                         gps = state.make_temp_gps(true);
177
178                         int n = nsat();
179                         for (int i = 0; i < n; i++)
180                                 gps.add_sat(svid(i), c_n(i));
181                         break;
182                 }
183         }
184
185         public AltosEepromMega (String line) {
186                 parse_string(line);
187         }
188
189         static public LinkedList<AltosEeprom> read(FileInputStream input) {
190                 LinkedList<AltosEeprom> megas = new LinkedList<AltosEeprom>();
191
192                 for (;;) {
193                         try {
194                                 String line = AltosLib.gets(input);
195                                 if (line == null)
196                                         break;
197                                 try {
198                                         AltosEepromMega mega = new AltosEepromMega(line);
199                                         if (mega.cmd != AltosLib.AO_LOG_INVALID)
200                                                 megas.add(mega);
201                                 } catch (Exception e) {
202                                         System.out.printf ("exception\n");
203                                 }
204                         } catch (IOException ie) {
205                                 break;
206                         }
207                 }
208
209                 return megas;
210         }
211 }