2 * Copyright © 2017 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.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altoslib_11;
25 public class AltosEepromFireTwo extends AltosEeprom {
26 public static final int record_length = 32;
28 public int record_length() { return record_length; }
30 /* AO_LOG_FLIGHT elements */
31 public int flight() { return data16(0); }
33 /* AO_LOG_STATE elements */
34 public int state() { return data16(0); }
35 public int reason() { return data16(2); }
37 /* AO_LOG_SENSOR elements */
38 public int pres() { return data16(0); }
39 public int thrust() { return data16(2); }
40 public int temp(int i) { return data16(4+i*2); }
42 public AltosEepromFireTwo (AltosEepromChunk chunk, int start) throws ParseException {
43 parse_chunk(chunk, start);
46 private static final double r_above = 5600.0;
47 private static final double r_below = 10000.0;
48 private static final double v_adc = 3.3;
51 firetwo_adc(int raw) {
58 /* raw adc to processor voltage, then back through the
59 * voltage divider to the sensor voltage
62 double v = firetwo_adc(adc) * v_adc * (r_above + r_below) / r_below;
64 /* Bound to ranges provided in sensor */
68 double psi = (v - 0.5) / 4.0 * 2500.0;
69 return AltosConvert.psi_to_pa(psi);
72 public void update_state(AltosState state) {
73 super.update_state(state);
76 case AltosLib.AO_LOG_FLIGHT:
77 state.set_flight(flight());
78 state.set_ground_pressure(0.0);
79 state.set_accel_g(0, -1);
81 case AltosLib.AO_LOG_STATE:
82 state.set_state(state());
84 case AltosLib.AO_LOG_SENSOR:
85 state.set_pressure(adc_to_pa(pres()));
86 state.set_accel(firetwo_adc(thrust()) * 100);
91 public AltosEepromFireTwo (String line) {
95 static public LinkedList<AltosEeprom> read(FileInputStream input) {
96 LinkedList<AltosEeprom> firetwos = new LinkedList<AltosEeprom>();
100 String line = AltosLib.gets(input);
104 AltosEepromFireTwo firetwo = new AltosEepromFireTwo(line);
106 if (firetwo.cmd != AltosLib.AO_LOG_INVALID)
107 firetwos.add(firetwo);
108 } catch (Exception e) {
109 System.out.printf ("exception\n");
111 } catch (IOException ie) {