altoslib: Fix parsing of old TM log GPS sat data
[fw/altos] / altoslib / AltosEepromRecordFull.java
1 /*
2  * Copyright © 2017 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, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  */
14
15 package org.altusmetrum.altoslib_12;
16
17 public class AltosEepromRecordFull extends AltosEepromRecord {
18         public static final int record_length = 8;
19
20         public static final int max_sat = 12;
21
22         public static final int two_g_default = 16294 - 15758;
23
24         public void provide_data(AltosDataListener listener, AltosCalData cal_data) {
25
26                 super.provide_data(listener, cal_data);
27                 AltosGPS        gps;
28
29                 switch (cmd()) {
30                 case AltosLib.AO_LOG_FLIGHT:
31                         listener.set_state(AltosLib.ao_flight_pad);
32                         cal_data.set_ground_accel(data16(0));
33                         cal_data.set_flight(data16(2));
34                         if (cal_data.accel_plus_g == AltosLib.MISSING)
35                                 cal_data.set_accel_plus_minus(data16(0), data16(0) + two_g_default);
36                         break;
37                 case AltosLib.AO_LOG_SENSOR:
38                         listener.set_acceleration(cal_data.acceleration(data16(0)));
39                         listener.set_pressure(AltosConvert.barometer_to_pressure(data16(2)));
40                         break;
41                 case AltosLib.AO_LOG_PRESSURE:
42                         listener.set_pressure(AltosConvert.barometer_to_pressure(data16(2)));
43                         break;
44                 case AltosLib.AO_LOG_TEMP_VOLT:
45                         listener.set_temperature(AltosConvert.thermometer_to_temperature(data16(0)));
46                         listener.set_battery_voltage(AltosConvert.cc_battery_to_voltage(data16(2)));
47                         break;
48                 case AltosLib.AO_LOG_DEPLOY:
49                         listener.set_apogee_voltage(AltosConvert.cc_igniter_to_voltage(data16(0)));
50                         listener.set_main_voltage(AltosConvert.cc_igniter_to_voltage(data16(2)));
51                         break;
52                 case AltosLib.AO_LOG_STATE:
53                         listener.set_state(data16(0));
54                         break;
55                 case AltosLib.AO_LOG_GPS_TIME:
56                         gps = cal_data.make_temp_gps(tick(),false);
57
58                         gps.hour = data8(0);
59                         gps.minute = data8(1);
60                         gps.second = data8(2);
61
62                         int flags = data8(3);
63
64                         gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
65                         gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
66                         gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
67                                 AltosLib.AO_GPS_NUM_SAT_SHIFT;
68                         break;
69                 case AltosLib.AO_LOG_GPS_LAT:
70                         gps = cal_data.make_temp_gps(tick(),false);
71
72                         int lat32 = data32(0);
73                         gps.lat = (double) lat32 / 1e7;
74                         break;
75                 case AltosLib.AO_LOG_GPS_LON:
76                         gps = cal_data.make_temp_gps(tick(),false);
77
78                         int lon32 = data32(0);
79                         gps.lon = (double) lon32 / 1e7;
80                         break;
81                 case AltosLib.AO_LOG_GPS_ALT:
82                         gps = cal_data.make_temp_gps(tick(),false);
83                         gps.alt = data16(0);
84                         break;
85                 case AltosLib.AO_LOG_GPS_SAT:
86                         gps = cal_data.make_temp_gps(tick(),true);
87                         int svid = data16(0);
88                         int c_n0 = data16(2);
89                         gps.add_sat(svid, c_n0);
90                         break;
91                 case AltosLib.AO_LOG_GPS_DATE:
92                         gps = cal_data.make_temp_gps(tick(),false);
93                         gps.year = data8(0) + 2000;
94                         gps.month = data8(1);
95                         gps.day = data8(2);
96                         break;
97                 }
98         }
99
100         public AltosEepromRecord next() {
101                 int     s = next_start();
102                 if (s < 0)
103                         return null;
104                 return new AltosEepromRecordFull(eeprom, s);
105         }
106
107         public AltosEepromRecordFull(AltosEeprom eeprom, int start) {
108                 super(eeprom, start, record_length);
109         }
110
111         public AltosEepromRecordFull(AltosEeprom eeprom) {
112                 this(eeprom, 0);
113         }
114 }