2 * Copyright © 2024 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, either version 2 of the License, or
7 * (at your option) any later version.
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.
15 package org.altusmetrum.altoslib_14;
17 public class AltosEepromRecordTimer extends AltosEepromRecord {
18 public static final int record_length = 32;
20 private int log_format;
22 private int imu_type() {
24 case AltosLib.AO_LOG_FORMAT_EASYTIMER_2:
25 return AltosIMU.imu_type_easytimer_v2;
27 return AltosLib.MISSING;
31 private int imu_model() {
33 case AltosLib.AO_LOG_FORMAT_EASYTIMER_2:
34 return AltosLib.model_bmi088;
36 return AltosLib.MISSING;
39 private boolean sensor_normalized() {
41 case AltosLib.AO_LOG_FORMAT_EASYTIMER_2:
47 private int mag_model() {
49 case AltosLib.AO_LOG_FORMAT_EASYTIMER_2:
50 return AltosLib.model_mmc5983;
52 return AltosLib.MISSING;
55 /* AO_LOG_FLIGHT elements */
56 private int flight() { return data16(0); }
57 private int ground_accel() { return data16(2); }
58 private int ground_pres() { return AltosLib.MISSING; }
59 private int ground_accel_along() { return data16(4); }
60 private int ground_accel_across() { return data16(6); }
61 private int ground_accel_through() { return data16(8); }
62 private int ground_roll() { return data32(12); }
63 private int ground_pitch() { return data32(16); }
64 private int ground_yaw() { return data32(20); }
66 /* AO_LOG_STATE elements */
67 private int state() { return data16(0); }
68 private int reason() { return data16(2); }
70 /* AO_LOG_SENSOR elements */
72 private int accel_along() { return data16(0); }
73 private int accel_across() { return data16(2); }
74 private int accel_through() { return data16(4); }
75 private int gyro_roll() { return data16(6); }
76 private int gyro_pitch() { return data16(8); }
77 private int gyro_yaw() { return data16(10); }
78 private int mag_along() { return data16(12); }
79 private int mag_across() { return data16(14); }
80 private int mag_through() { return data16(16); }
82 private int accel() { return -accel_along(); }
84 private int v_batt() { return data16(18); }
85 private int v_pbatt() { return data16(20); }
86 private int nsense() { return 2; }
87 private int sense(int i) { return data16(22 + i * 2); }
88 private int pyro() { return data16(26); }
90 public void provide_data(AltosDataListener listener, AltosCalData cal_data) {
91 super.provide_data(listener, cal_data);
93 cal_data.set_imu_type(imu_type());
94 cal_data.set_imu_model(imu_model());
95 cal_data.set_mag_model(mag_model());
98 case AltosLib.AO_LOG_FLIGHT:
99 cal_data.set_flight(flight());
100 cal_data.set_ground_accel(ground_accel());
101 listener.set_accel_ground(cal_data.accel_along(ground_accel_along()),
102 cal_data.accel_across(ground_accel_across()),
103 cal_data.accel_through(ground_accel_through()));
104 cal_data.set_gyro_zero(ground_roll() / 512.0,
105 ground_pitch() / 512.0,
106 ground_yaw() / 512.0);
108 case AltosLib.AO_LOG_STATE:
109 listener.set_state(state());
111 case AltosLib.AO_LOG_SENSOR:
112 AltosConfigData config_data = eeprom.config_data();
114 int accel_along = accel_along();
115 int accel_across = accel_across();
116 int accel_through = accel_through();
117 int gyro_roll = gyro_roll();
118 int gyro_pitch = gyro_pitch();
119 int gyro_yaw = gyro_yaw();
121 int mag_along = mag_along();
122 int mag_across = mag_across();
123 int mag_through = mag_through();
125 listener.set_accel(cal_data.accel_along(accel_along),
126 cal_data.accel_across(accel_across),
127 cal_data.accel_through(accel_through));
128 listener.set_gyro(cal_data.gyro_roll(gyro_roll),
129 cal_data.gyro_pitch(gyro_pitch),
130 cal_data.gyro_yaw(gyro_yaw));
132 listener.set_mag(cal_data.mag_along(mag_along),
133 cal_data.mag_across(mag_across),
134 cal_data.mag_through(mag_through));
136 listener.set_acceleration(cal_data.acceleration(accel()));
138 listener.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
139 listener.set_pyro_voltage(AltosConvert.mega_pyro_voltage(v_pbatt()));
141 int nsense = nsense();
143 listener.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-2)));
144 listener.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 listener.set_igniter_voltage(voltages);
151 listener.set_pyro_fired(pyro());
156 public AltosEepromRecord next() {
157 int s = next_start();
160 return new AltosEepromRecordTimer(eeprom, s);
163 public AltosEepromRecordTimer(AltosEeprom eeprom, int start) {
164 super(eeprom, start, record_length);
165 log_format = eeprom.config_data().log_format;
168 public AltosEepromRecordTimer(AltosEeprom eeprom) {