summaryrefslogtreecommitdiff
path: root/altoslib/AltosEepromRecordTiny.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2017-05-09 00:19:05 -0700
committerKeith Packard <keithp@keithp.com>2017-05-09 00:19:05 -0700
commite67a5c6ffa7174d66e985483fab4bf52ccaea5ca (patch)
tree2912ebc146cc792b7f93763fc20ca1b02e6d90a1 /altoslib/AltosEepromRecordTiny.java
parent44c0cecabb3a815dbf7f52e6b2dad364cc72b60c (diff)
altoslib: Add new eeprom management code
Generic .eeprom file parsing, simpler per-type eeprom data extraction. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosEepromRecordTiny.java')
-rw-r--r--altoslib/AltosEepromRecordTiny.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/altoslib/AltosEepromRecordTiny.java b/altoslib/AltosEepromRecordTiny.java
new file mode 100644
index 00000000..6c04bfee
--- /dev/null
+++ b/altoslib/AltosEepromRecordTiny.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright © 2017 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+package org.altusmetrum.altoslib_11;
+
+public class AltosEepromRecordTiny extends AltosEepromRecord {
+ public static final int record_length = 2;
+
+ private int value() {
+ return eeprom.data16(start);
+ }
+
+ public int cmd() {
+ if (start == 0)
+ return AltosLib.AO_LOG_FLIGHT;
+ if ((value() & 0x8000) != 0)
+ return AltosLib.AO_LOG_STATE;
+ return AltosLib.AO_LOG_SENSOR;
+ }
+
+ public int tick() {
+ int tick = 0;
+ int step = 10;
+ for (int i = 2; i < start; i += 2)
+ {
+ int v = eeprom.data16(i);
+
+ if ((v & 0x8000) != 0) {
+ if ((v & 0x7fff) >= AltosLib.ao_flight_drogue)
+ step = 100;
+ } else {
+ tick += step;
+ }
+ }
+ return tick;
+ }
+
+ public void update_state(AltosState state) {
+ int value = data16(-header_length);
+
+ state.set_tick(tick());
+ switch (cmd()) {
+ case AltosLib.AO_LOG_FLIGHT:
+ state.set_state(AltosLib.ao_flight_pad);
+ state.set_flight(value);
+ state.set_boost_tick(0);
+ break;
+ case AltosLib.AO_LOG_STATE:
+ state.set_state(value & 0x7fff);
+ break;
+ case AltosLib.AO_LOG_SENSOR:
+ state.set_pressure(AltosConvert.barometer_to_pressure(value));
+ break;
+ }
+ }
+
+ public AltosEepromRecord next() {
+ if (start + record_length * 2 < eeprom.data.size())
+ return new AltosEepromRecordTiny(eeprom, start + record_length);
+ return null;
+ }
+
+ public AltosEepromRecordTiny(AltosEepromNew eeprom, int start) {
+ super(eeprom, start, record_length);
+ }
+
+ public AltosEepromRecordTiny(AltosEepromNew eeprom) {
+ this(eeprom, 0);
+ }
+}