18ffd988299a63cb2821d1c0eae5df6221f016dd
[fw/altos] / altoslib / AltosDataListener.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_14;
16
17 public abstract class AltosDataListener {
18
19         private AltosCalData    cal_data = null;
20
21         public double           time = AltosLib.MISSING;
22         public double           frequency = AltosLib.MISSING;
23
24         public int              raw_tick = AltosLib.MISSING;
25
26         public int tick() {
27                 return raw_tick;
28         }
29
30         public void set_tick(int tick) {
31                 raw_tick = tick;
32                 cal_data.set_tick(tick);
33                 set_time(cal_data.time());
34         }
35
36         public AltosCalData cal_data() {
37                 if (cal_data == null)
38                         cal_data = new AltosCalData();
39                 return cal_data;
40         }
41
42         public AltosConfigData config_data() {
43                 return null;
44         }
45
46         public void set_time(double time) {
47                 if (time != AltosLib.MISSING)
48                         this.time = time;
49         }
50
51         public void set_serial(int serial) {
52                 cal_data().set_serial(serial);
53         }
54
55         public void set_device_type(int device_type) {
56                 cal_data().set_device_type(device_type);
57                 switch (device_type) {
58                 case AltosLib.product_telegps:
59                         set_state(AltosLib.ao_flight_stateless);
60                         break;
61                 }
62         }
63
64         public void set_log_format(int log_format) {
65                 cal_data().set_log_format(log_format);
66                 if (cal_data().device_type == AltosLib.MISSING)
67                         cal_data().set_device_type(AltosLib.product_id_from_log_format(log_format));
68                 switch (log_format) {
69                 case AltosLib.AO_LOG_FORMAT_TELEGPS:
70                         set_state(AltosLib.ao_flight_stateless);
71                         break;
72                 }
73         }
74
75         public double time() {
76                 return time;
77         }
78
79         public String state_name() {
80                 return cal_data().state_name();
81         }
82
83         public void set_state(int state) {
84                 cal_data().set_state(state);
85         }
86
87         public int state() {
88                 return cal_data().state;
89         }
90
91         public void set_flight(int flight) {
92                 cal_data().set_flight(flight);
93         }
94
95         public void set_frequency(double frequency) {
96                 this.frequency = frequency;
97         }
98
99         public void set_avoid_duplicate_files() {
100         }
101
102         /* Called after all records are captured */
103         public void finish() {
104         }
105
106         public void init() {
107                 set_state(AltosLib.ao_flight_invalid);
108                 time = AltosLib.MISSING;
109                 frequency = AltosLib.MISSING;
110         }
111
112         public abstract void set_rssi(int rssi, int status);
113         public abstract void set_received_time(long received_time);
114
115         public abstract void set_acceleration(double accel);
116         public abstract void set_pressure(double pa);
117         public abstract void set_thrust(double N);
118
119         public abstract void set_kalman(double height, double speed, double accel);
120
121         public abstract void set_temperature(double deg_c);
122         public abstract void set_battery_voltage(double volts);
123
124         public abstract void set_apogee_voltage(double volts);
125         public abstract void set_main_voltage(double volts);
126
127         public void set_gps(AltosGPS gps, boolean set_location, boolean set_sats) {
128                 AltosCalData cal_data = cal_data();
129                 cal_data.set_cal_gps(gps);
130         }
131
132         public AltosGPS make_temp_gps(boolean sats) {
133                 return cal_data().make_temp_cal_gps(tick(), sats);
134         }
135
136         public AltosGPS temp_gps() {
137                 return cal_data().temp_cal_gps();
138         }
139
140         public abstract void set_orient(double orient);
141         public abstract void set_gyro(double roll, double pitch, double yaw);
142         public abstract void set_accel_ground(double along, double across, double through);
143         public abstract void set_accel(double along, double across, double through);
144         public abstract void set_mag(double along, double across, double through);
145         public abstract void set_pyro_voltage(double volts);
146         public abstract void set_igniter_voltage(double[] voltage);
147         public abstract void set_pyro_fired(int pyro_mask);
148         public abstract void set_companion(AltosCompanion companion);
149         public abstract void set_motor_pressure(double motor_pressure);
150
151         public AltosDataListener() {
152         }
153
154         public AltosDataListener(AltosCalData cal_data) {
155                 this.cal_data = cal_data;
156         }
157 }