clean up telefireone name references
[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_11;
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 update_state(AltosState state) {
25                 super.update_state(state);
26                 AltosGPS        gps;
27
28                 /* Flush any pending GPS changes */
29                 if (state.gps_pending) {
30                         switch (cmd()) {
31                         case AltosLib.AO_LOG_GPS_LAT:
32                         case AltosLib.AO_LOG_GPS_LON:
33                         case AltosLib.AO_LOG_GPS_ALT:
34                         case AltosLib.AO_LOG_GPS_SAT:
35                         case AltosLib.AO_LOG_GPS_DATE:
36                                 break;
37                         default:
38                                 state.set_temp_gps();
39                                 break;
40                         }
41                 }
42
43                 switch (cmd()) {
44                 case AltosLib.AO_LOG_FLIGHT:
45                         state.set_state(AltosLib.ao_flight_pad);
46                         state.set_ground_accel(data16(0));
47                         state.set_flight(data16(2));
48                         if (state.accel_plus_g == AltosLib.MISSING)
49                                 state.set_accel_g(data16(0), data16(0) + two_g_default);
50                         break;
51                 case AltosLib.AO_LOG_SENSOR:
52                         state.set_accel(data16(0));
53                         state.set_pressure(AltosConvert.barometer_to_pressure(data16(2)));
54                         break;
55                 case AltosLib.AO_LOG_PRESSURE:
56                         state.set_pressure(AltosConvert.barometer_to_pressure(data16(2)));
57                         break;
58                 case AltosLib.AO_LOG_TEMP_VOLT:
59                         state.set_temperature(AltosConvert.thermometer_to_temperature(data16(0)));
60                         state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(data16(2)));
61                         break;
62                 case AltosLib.AO_LOG_DEPLOY:
63                         state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(data16(0)));
64                         state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(data16(2)));
65                         break;
66                 case AltosLib.AO_LOG_STATE:
67                         state.set_state(data16(0));
68                         break;
69                 case AltosLib.AO_LOG_GPS_TIME:
70                         gps = state.make_temp_gps(false);
71
72                         gps.hour = data8(0);
73                         gps.minute = data8(1);
74                         gps.second = data8(2);
75
76                         int flags = data8(3);
77
78                         gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
79                         gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
80                         gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
81                                 AltosLib.AO_GPS_NUM_SAT_SHIFT;
82                         break;
83                 case AltosLib.AO_LOG_GPS_LAT:
84                         gps = state.make_temp_gps(false);
85
86                         int lat32 = data32(0);
87                         gps.lat = (double) lat32 / 1e7;
88                         break;
89                 case AltosLib.AO_LOG_GPS_LON:
90                         gps = state.make_temp_gps(false);
91
92                         int lon32 = data32(0);
93                         gps.lon = (double) lon32 / 1e7;
94                         break;
95                 case AltosLib.AO_LOG_GPS_ALT:
96                         gps = state.make_temp_gps(false);
97                         gps.alt = data16(0);
98                         break;
99                 case AltosLib.AO_LOG_GPS_SAT:
100                         gps = state.make_temp_gps(true);
101                         int svid = data16(0);
102                         int c_n0 = data16(3);
103                         gps.add_sat(svid, c_n0);
104                         break;
105                 case AltosLib.AO_LOG_GPS_DATE:
106                         gps = state.make_temp_gps(false);
107                         gps.year = data8(0) + 2000;
108                         gps.month = data8(1);
109                         gps.day = data8(2);
110                         break;
111                 }
112         }
113
114         public AltosEepromRecord next() {
115                 int     s = next_start();
116                 if (s < 0)
117                         return null;
118                 return new AltosEepromRecordFull(eeprom, s);
119         }
120
121         public AltosEepromRecordFull(AltosEepromNew eeprom, int start) {
122                 super(eeprom, start, record_length);
123         }
124
125         public AltosEepromRecordFull(AltosEepromNew eeprom) {
126                 this(eeprom, 0);
127         }
128 }