altoslib: Don't store computed telemetry fields
authorKeith Packard <keithp@keithp.com>
Tue, 23 May 2017 21:53:55 +0000 (14:53 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 23 May 2017 22:15:21 +0000 (15:15 -0700)
These values are only needed once, so there's no reason to save them.

Signed-off-by: Keith Packard <keithp@keithp.com>
16 files changed:
altoslib/AltosTelemetry.java
altoslib/AltosTelemetryCompanion.java
altoslib/AltosTelemetryConfiguration.java
altoslib/AltosTelemetryIterable.java
altoslib/AltosTelemetryLegacy.java
altoslib/AltosTelemetryLocation.java
altoslib/AltosTelemetryMegaData.java
altoslib/AltosTelemetryMegaSensor.java
altoslib/AltosTelemetryMetrumData.java
altoslib/AltosTelemetryMetrumSensor.java
altoslib/AltosTelemetryMini2.java
altoslib/AltosTelemetryMini3.java
altoslib/AltosTelemetryRaw.java
altoslib/AltosTelemetrySatellite.java
altoslib/AltosTelemetrySensor.java
altoslib/AltosTelemetryStandard.java

index f830bf3582a0a452f24facbda8671e45019d642b..5600e7beb3f19b31620d8217d9e239d8d0eda054 100644 (file)
@@ -25,12 +25,15 @@ import java.text.*;
  */
 
 public abstract class AltosTelemetry implements AltosStateUpdate {
+       int[]   bytes;
 
        /* All telemetry packets have these fields */
-       public int      tick;
-       public int      serial;
-       public int      rssi;
-       public int      status;
+       public int rssi() { return AltosConvert.telem_to_rssi(AltosLib.int8(bytes, bytes.length - 3)); }
+       public int status() { return AltosLib.uint8(bytes, bytes.length - 2); }
+
+       /* All telemetry packets report these fields in some form */
+       public abstract int serial();
+       public abstract int tick();
 
        /* Mark when we received the packet */
        long            received_time;
@@ -44,11 +47,11 @@ public abstract class AltosTelemetry implements AltosStateUpdate {
        }
 
        public void update_state(AltosState state) {
-               state.set_serial(serial);
+               state.set_serial(serial());
                if (state.state() == AltosLib.ao_flight_invalid)
                        state.set_state(AltosLib.ao_flight_startup);
-               state.set_tick(tick);
-               state.set_rssi(rssi, status);
+               state.set_tick(tick());
+               state.set_rssi(rssi(), status());
                state.set_received_time(received_time);
        }
 
@@ -88,12 +91,6 @@ public abstract class AltosTelemetry implements AltosStateUpdate {
                if (!cksum(bytes))
                        throw new ParseException(String.format("invalid line \"%s\"", hex), 0);
 
-               int     rssi = AltosLib.int8(bytes, bytes.length - 3) / 2 - 74;
-               int     status = AltosLib.uint8(bytes, bytes.length - 2);
-
-               if ((status & PKT_APPEND_STATUS_1_CRC_OK) == 0)
-                       throw new AltosCRCException(rssi);
-
                /* length, data ..., rssi, status, checksum -- 4 bytes extra */
                switch (bytes.length) {
                case AltosLib.ao_telemetry_standard_len + 4:
@@ -108,11 +105,6 @@ public abstract class AltosTelemetry implements AltosStateUpdate {
                default:
                        throw new ParseException(String.format("Invalid packet length %d", bytes.length), 0);
                }
-               if (telem != null) {
-                       telem.received_time = System.currentTimeMillis();
-                       telem.rssi = rssi;
-                       telem.status = status;
-               }
                return telem;
        }
 
@@ -139,6 +131,17 @@ public abstract class AltosTelemetry implements AltosStateUpdate {
                return height;
        }
 
+       public AltosTelemetry() {
+               this.received_time = System.currentTimeMillis();
+       }
+
+       public AltosTelemetry(int[] bytes) throws AltosCRCException {
+               this();
+               this.bytes = bytes;
+               if ((status() & PKT_APPEND_STATUS_1_CRC_OK) == 0)
+                       throw new AltosCRCException(rssi());
+       }
+
        public static AltosTelemetry parse(String line) throws ParseException, AltosCRCException {
                String[] word = line.split("\\s+");
                int i =0;
@@ -149,7 +152,7 @@ public abstract class AltosTelemetry implements AltosStateUpdate {
                        throw new AltosCRCException(AltosParse.parse_int(word[i++]));
                }
 
-               AltosTelemetry telem;
+               AltosTelemetry telem = null;
 
                if (word[i].equals("TELEM")) {
                        telem = parse_hex(word[i+1]);
index a97fda2d0cbb5135601cafddba6aafe431cb21c7..2c05e245c85131a8e6cc0b5e5c57cbcd97d7ee55 100644 (file)
 package org.altusmetrum.altoslib_11;
 
 public class AltosTelemetryCompanion extends AltosTelemetryStandard {
-       AltosCompanion  companion;
-
-       static final public int max_channels = 12;
-
-       public AltosTelemetryCompanion(int[] bytes) {
-               super(bytes);
 
+       AltosCompanion  companion() {
                int     channels = uint8(7);
 
                if (channels > max_channels)
                        channels = max_channels;
 
-               companion = new AltosCompanion(channels);
+               AltosCompanion companion = new AltosCompanion(channels);
 
-               companion.tick = tick;
+               companion.tick = tick();
                companion.board_id = uint8(5);
                companion.update_period = uint8(6);
 
@@ -45,11 +40,17 @@ public class AltosTelemetryCompanion extends AltosTelemetryStandard {
                        for (int i = 0; i < channels; i++)
                                companion.companion_data[i] = uint16(8 + i * 2);
                }
+               return companion;
+       }
+
+       static final public int max_channels = 12;
+
+       public AltosTelemetryCompanion(int[] bytes) throws AltosCRCException {
+               super(bytes);
        }
 
        public void update_state(AltosState state) {
                super.update_state(state);
-
-               state.set_companion(companion);
+               state.set_companion(companion());
        }
 }
index 6ded5461c93c80926e9494a32965c625d3abc609..d91a03fc5f8caefe8abfe9b7d395eb8ca8728318 100644 (file)
@@ -20,43 +20,32 @@ package org.altusmetrum.altoslib_11;
 
 
 public class AltosTelemetryConfiguration extends AltosTelemetryStandard {
-       int     device_type;
-       int     flight;
-       int     config_major;
-       int     config_minor;
-       int     apogee_delay;
-       int     main_deploy;
-       int     v_batt;
-       int     flight_log_max;
-       String  callsign;
-       String  version;
+       int     device_type() { return uint8(5); }
+       int     flight() { return uint16(6); }
+       int     config_major() { return uint8(8); }
+       int     config_minor() { return uint8(9); }
+       int     apogee_delay() { return uint16(10); }
+       int     main_deploy() { return uint16(12); }
+       int     v_batt() { return uint16(10); }
+       int     flight_log_max() { return uint16(14); }
+       String  callsign() { return string(16, 8); }
+       String  version() { return string(24, 8); }
 
-       public AltosTelemetryConfiguration(int[] bytes) {
+       public AltosTelemetryConfiguration(int[] bytes) throws AltosCRCException {
                super(bytes);
-
-               device_type    = uint8(5);
-               flight         = uint16(6);
-               config_major   = uint8(8);
-               config_minor   = uint8(9);
-               v_batt         = uint16(10);
-               apogee_delay   = uint16(10);
-               main_deploy    = uint16(12);
-               flight_log_max = uint16(14);
-               callsign       = string(16, 8);
-               version        = string(24, 8);
        }
 
        public void update_state(AltosState state) {
                super.update_state(state);
-               state.set_device_type(device_type);
-               state.set_flight(flight);
-               state.set_config(config_major, config_minor, flight_log_max);
-               if (device_type == AltosLib.product_telegps)
-                       state.set_battery_voltage(AltosConvert.tele_gps_voltage(v_batt));
+               state.set_device_type(device_type());
+               state.set_flight(flight());
+               state.set_config(config_major(), config_minor(), flight_log_max());
+               if (device_type() == AltosLib.product_telegps)
+                       state.set_battery_voltage(AltosConvert.tele_gps_voltage(v_batt()));
                else
-                       state.set_flight_params(apogee_delay, main_deploy);
+                       state.set_flight_params(apogee_delay(), main_deploy());
 
-               state.set_callsign(callsign);
-               state.set_firmware_version(version);
+               state.set_callsign(callsign());
+               state.set_firmware_version(version());
        }
 }
index 0cba86a31c5712e28e96cdc0ffdbf7f8ae363806..402bbf4f4276b89992fc092a0abd6d1faf257616 100644 (file)
@@ -67,7 +67,7 @@ public class AltosTelemetryIterable implements Iterable<AltosTelemetry> {
        int index;
 
        public void add (AltosTelemetry telem) {
-               int     t = telem.tick;
+               int     t = telem.tick();
                if (!telems.isEmpty()) {
                        while (t < tick - 1000)
                                t += 65536;
index 08c529860bd6da4f4985b903a3420a5c3ec1e55d..2907f11195aea8f7e351a881b35f5b3777e66031 100644 (file)
@@ -233,6 +233,17 @@ public class AltosTelemetryLegacy extends AltosTelemetry {
        final static String AO_TELEM_SAT_SVID   = "s_v";
        final static String AO_TELEM_SAT_C_N_0  = "s_c";
 
+       public int      tick;
+       public int      serial;
+       public int      rssi;
+       public int      status;
+
+       public int tick() { return tick; }
+       public int serial() { return serial; }
+
+       public int rssi() { return rssi; }
+       public int status() { return status; }
+
        public int      version;
        public String   callsign;
        public int      flight;
@@ -271,7 +282,6 @@ public class AltosTelemetryLegacy extends AltosTelemetry {
                flight = map.get_int(AO_TELEM_FLIGHT, AltosLib.MISSING);
                rssi = map.get_int(AO_TELEM_RSSI, AltosLib.MISSING);
                state = AltosLib.state(map.get_string(AO_TELEM_STATE, "invalid"));
-               tick = map.get_int(AO_TELEM_TICK, 0);
 
                /* raw sensor values */
                accel = map.get_int(AO_TELEM_RAW_ACCEL, AltosLib.MISSING);
@@ -420,7 +430,6 @@ public class AltosTelemetryLegacy extends AltosTelemetry {
         * Given a hex dump of a legacy telemetry line, construct an AltosRecordTM from that
         */
 
-       int[]   bytes;
        int     adjust;
 
        /*
@@ -452,8 +461,9 @@ public class AltosTelemetryLegacy extends AltosTelemetry {
        static final int AO_GPS_DATE_VALID      = (1 << 6);
        static final int AO_GPS_COURSE_VALID    = (1 << 7);
 
-       public AltosTelemetryLegacy(int[] in_bytes) {
-               bytes = in_bytes;
+       public AltosTelemetryLegacy(int[] in_bytes) throws AltosCRCException {
+               super(in_bytes);
+
                version = 4;
                adjust = 0;
 
@@ -463,6 +473,7 @@ public class AltosTelemetryLegacy extends AltosTelemetry {
                } else
                        serial = uint16(0);
 
+               rssi = super.rssi();
                callsign = string(62, 8);
                flight = uint16(2);
                state = uint8(4);
index 1199564020bbf57173443dad3e3d340a4d1712ba..8ad23ab6396fe69ebdd5ed078ee279f30f8fdd38 100644 (file)
@@ -20,76 +20,60 @@ package org.altusmetrum.altoslib_11;
 
 
 public class AltosTelemetryLocation extends AltosTelemetryStandard {
-       int     flags;
-       int     altitude;
-       int     latitude;
-       int     longitude;
-       int     year;
-       int     month;
-       int     day;
-       int     hour;
-       int     minute;
-       int     second;
-       int     pdop;
-       int     hdop;
-       int     vdop;
-       int     mode;
-       int     ground_speed;
-       int     climb_rate;
-       int     course;
+       int     flags() { return uint8(5); }
+       int     altitude() {
+               if ((mode() & AO_GPS_MODE_ALTITUDE_24) != 0)
+                       return (int8(31) << 16) | uint16(6);
+               else
+                       return int16(6);
+       }
+       int     latitude() { return uint32(8); }
+       int     longitude() { return uint32(12); }
+       int     year() { return uint8(16); }
+       int     month() { return uint8(17); }
+       int     day() { return uint8(18); }
+       int     hour() { return uint8(19); }
+       int     minute() { return uint8(20); }
+       int     second() { return uint8(21); }
+       int     pdop() { return uint8(22); }
+       int     hdop() { return uint8(23); }
+       int     vdop() { return uint8(24); }
+       int     mode() { return uint8(25); }
+       int     ground_speed() { return uint16(26); }
+       int     climb_rate() { return int16(28); }
+       int     course() { return uint8(30); }
 
        public static final int AO_GPS_MODE_ALTITUDE_24 = (1 << 0);     /* Reports 24-bits of altitude */
 
-       public AltosTelemetryLocation(int[] bytes) {
+       public AltosTelemetryLocation(int[] bytes) throws AltosCRCException {
                super(bytes);
-
-               flags          = uint8(5);
-               latitude       = uint32(8);
-               longitude      = uint32(12);
-               year           = uint8(16);
-               month          = uint8(17);
-               day            = uint8(18);
-               hour           = uint8(19);
-               minute         = uint8(20);
-               second         = uint8(21);
-               pdop           = uint8(22);
-               hdop           = uint8(23);
-               vdop           = uint8(24);
-               mode           = uint8(25);
-               ground_speed   = uint16(26);
-               climb_rate     = int16(28);
-               course         = uint8(30);
-
-               if ((mode & AO_GPS_MODE_ALTITUDE_24) != 0) {
-                       altitude = (int8(31) << 16) | uint16(6);
-               } else
-                       altitude = int16(6);
        }
 
        public void update_state(AltosState state) {
                super.update_state(state);
                AltosGPS        gps = state.make_temp_gps(false);
 
+               int flags = flags();
                gps.nsat = flags & 0xf;
                gps.locked = (flags & (1 << 4)) != 0;
                gps.connected = (flags & (1 << 5)) != 0;
 
                if (gps.locked) {
-                       gps.lat = latitude * 1.0e-7;
-                       gps.lon = longitude * 1.0e-7;
-                       gps.alt = altitude;
-                       gps.year = 2000 + year;
-                       gps.month = month;
-                       gps.day = day;
-                       gps.hour = hour;
-                       gps.minute = minute;
-                       gps.second = second;
-                       gps.ground_speed = ground_speed * 1.0e-2;
-                       gps.course = course * 2;
-                       gps.climb_rate = climb_rate * 1.0e-2;
-                       gps.pdop = pdop / 10.0;
-                       gps.hdop = hdop / 10.0;
-                       gps.vdop = vdop / 10.0;
+                       gps.lat = latitude() * 1.0e-7;
+                       gps.lon = longitude() * 1.0e-7;
+                       gps.alt = altitude();
+                       gps.year = 2000 + year();
+                       gps.month = month();
+                       gps.day = day();
+                       gps.hour = hour();
+                       gps.minute = minute();
+                       gps.second = second();
+                       gps.ground_speed = ground_speed() * 1.0e-2;
+                       gps.course = course() * 2;
+                       gps.climb_rate = climb_rate() * 1.0e-2;
+                       gps.pdop = pdop() / 10.0;
+                       gps.hdop = hdop() / 10.0;
+                       gps.vdop = vdop() / 10.0;
                }
                state.set_temp_gps();
        }
index 6ea5ec89897ab541bf1a2c7ca85328f806f65163..916f1e9447a6ca0214fc4a58f2d16ea1aefc8ea4 100644 (file)
 package org.altusmetrum.altoslib_11;
 
 public class AltosTelemetryMegaData extends AltosTelemetryStandard {
-       int     state;
 
-       int     v_batt;
-       int     v_pyro;
-       int     sense[];
+       int     state() { return uint8(5); }
 
-       int     ground_pres;
-       int     ground_accel;
-       int     accel_plus_g;
-       int     accel_minus_g;
+       int     v_batt() { return int16(6); }
+       int     v_pyro() { return int16(8); }
+       int     sense(int i) { int v = uint8(10+i); return v << 4 | v >> 8; }
 
-       int     acceleration;
-       int     speed;
-       int     height_16;
+       int     ground_pres() { return int32(16); }
+       int     ground_accel() { return int16(20); }
+       int     accel_plus_g() { return int16(22); }
+       int     accel_minus_g() { return int16(24);}
 
-       public AltosTelemetryMegaData(int[] bytes) {
-               super(bytes);
-
-               state = uint8(5);
-
-               v_batt = int16(6);
-               v_pyro = int16(8);
-
-               sense = new int[6];
+       int     acceleration() { return int16(26); }
+       int     speed() { return int16(28); }
+       int     height_16() { return int16(30); }
 
-               for (int i = 0; i < 6; i++) {
-                       sense[i] = uint8(10 + i) << 4;
-                       sense[i] |= sense[i] >> 8;
-               }
-
-               ground_pres = int32(16);
-               ground_accel = int16(20);
-               accel_plus_g = int16(22);
-               accel_minus_g = int16(24);
-
-               acceleration = int16(26);
-               speed = int16(28);
-
-               height_16 = int16(30);
+       public AltosTelemetryMegaData(int[] bytes) throws AltosCRCException {
+               super(bytes);
        }
 
        public void update_state(AltosState state) {
                super.update_state(state);
 
-               state.set_state(this.state);
+               state.set_state(state());
 
-               state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt));
-               state.set_pyro_voltage(AltosConvert.mega_pyro_voltage(v_pyro));
+               state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
+               state.set_pyro_voltage(AltosConvert.mega_pyro_voltage(v_pyro()));
 
-               state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense[4]));
-               state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense[5]));
+               state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense(4)));
+               state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense(5)));
 
                double voltages[] = new double[4];
                for (int i = 0; i < 4; i++)
-                       voltages[i] = AltosConvert.mega_pyro_voltage(sense[i]);
+                       voltages[i] = AltosConvert.mega_pyro_voltage(sense(i));
 
                state.set_ignitor_voltage(voltages);
 
-               state.set_ground_accel(ground_accel);
-               state.set_ground_pressure(ground_pres);
-               state.set_accel_g(accel_plus_g, accel_minus_g);
+               state.set_ground_accel(ground_accel());
+               state.set_ground_pressure(ground_pres());
+               state.set_accel_g(accel_plus_g(), accel_minus_g());
 
                /* Fill in the high bits of height from recent GPS
                 * data if available, otherwise guess using the
                 * previous kalman height
                 */
 
-               state.set_kalman(extend_height(state, height_16),
-                                speed/16.0, acceleration / 16.0);
+               state.set_kalman(extend_height(state, height_16()),
+                                speed()/16.0, acceleration() / 16.0);
        }
 }
 
index 2dfc455aa5ca0d09adf7859d1581e6344ddfc405..bf560e9257abfe9116d310bf4dd77811f28bf674 100644 (file)
 package org.altusmetrum.altoslib_11;
 
 public class AltosTelemetryMegaSensor extends AltosTelemetryStandard {
-       int     accel;
-       int     pres;
-       int     temp;
+       int     orient() { return int8(5); }
 
-       int     accel_x;
-       int     accel_y;
-       int     accel_z;
+       int     accel() { return int16(6); }
+       int     pres() { return int32(8); }
+       int     temp() { return int16(12); }
 
-       int     gyro_x;
-       int     gyro_y;
-       int     gyro_z;
+       int     accel_x() { return int16(14); }
+       int     accel_y() { return int16(16); }
+       int     accel_z() { return int16(18); }
 
-       int     mag_x;
-       int     mag_y;
-       int     mag_z;
+       int     gyro_x() { return int16(20); }
+       int     gyro_y() { return int16(22); }
+       int     gyro_z() { return int16(24); }
 
-       int     orient;
+       int     mag_x() { return int16(26); }
+       int     mag_y() { return int16(28); }
+       int     mag_z() { return int16(30); }
 
-       public AltosTelemetryMegaSensor(int[] bytes) {
+       public AltosTelemetryMegaSensor(int[] bytes) throws AltosCRCException {
                super(bytes);
-
-               orient        = int8(5);
-               accel         = int16(6);
-               pres          = int32(8);
-               temp          = int16(12);
-
-               accel_x       = int16(14);
-               accel_y       = int16(16);
-               accel_z       = int16(18);
-
-               gyro_x        = int16(20);
-               gyro_y        = int16(22);
-               gyro_z        = int16(24);
-
-               mag_x         = int16(26);
-               mag_y         = int16(28);
-               mag_z         = int16(30);
        }
 
        public void update_state(AltosState state) {
                super.update_state(state);
 
-               state.set_accel(accel);
-               state.set_pressure(pres);
-               state.set_temperature(temp / 100.0);
+               state.set_accel(accel());
+               state.set_pressure(pres());
+               state.set_temperature(temp() / 100.0);
 
-               state.set_orient(orient);
+               state.set_orient(orient());
 
-               state.set_imu(new AltosIMU(accel_y,     /* along */
-                                          accel_x,     /* across */
-                                          accel_z,     /* through */
-                                          gyro_y,      /* along */
-                                          gyro_x,      /* across */
-                                          gyro_z));    /* through */
+               state.set_imu(new AltosIMU(accel_y(),   /* along */
+                                          accel_x(),   /* across */
+                                          accel_z(),   /* through */
+                                          gyro_y(),    /* along */
+                                          gyro_x(),    /* across */
+                                          gyro_z()));  /* through */
 
-               state.set_mag(new AltosMag(mag_x, mag_y, mag_z));
+               state.set_mag(new AltosMag(mag_x(), mag_y(), mag_z()));
        }
 }
index 53a10cc41ea6ed9a91b09083693a300d8ccd4442..7ba591ed43a08db917bf3c7c7d0dd318ce21944b 100644 (file)
@@ -21,23 +21,18 @@ package org.altusmetrum.altoslib_11;
 
 public class AltosTelemetryMetrumData extends AltosTelemetryStandard {
 
-       int     ground_pres;
-       int     ground_accel;
-       int     accel_plus_g;
-       int     accel_minus_g;
+       int     ground_pres() { return int32(8); }
+       int     ground_accel() { return int16(12); }
+       int     accel_plus_g() { return int16(14); }
+       int     accel_minus_g() { return int16(16); }
 
-       public AltosTelemetryMetrumData(int[] bytes) {
+       public AltosTelemetryMetrumData(int[] bytes) throws AltosCRCException {
                super(bytes);
-
-               ground_pres = int32(8);
-               ground_accel = int16(12);
-               accel_plus_g = int16(14);
-               accel_minus_g = int16(16);
        }
 
        public void update_state(AltosState state) {
-               state.set_ground_accel(ground_accel);
-               state.set_accel_g(accel_plus_g, accel_minus_g);
-               state.set_ground_pressure(ground_pres);
+               state.set_ground_accel(ground_accel());
+               state.set_accel_g(accel_plus_g(), accel_minus_g());
+               state.set_ground_pressure(ground_pres());
        }
 }
index e15043b4add4862724d6d7a8b184c5625864046b..e666f4ec29939c85c2d2e948e53636df5c9e56fc 100644 (file)
@@ -20,52 +20,39 @@ package org.altusmetrum.altoslib_11;
 
 
 public class AltosTelemetryMetrumSensor extends AltosTelemetryStandard {
-       int     state;
+       int     state() { return uint8(5); }
 
-       int     accel;
-       int     pres;
-       int     temp;
+       int     accel() { return int16(6); }
+       int     pres() { return int32(8); }
+       int     temp() { return int16(12); }
 
-       int     acceleration;
-       int     speed;
-       int     height_16;
+       int     acceleration() { return int16(14); }
+       int     speed() { return int16(16); }
+       int     height_16() { return int16(18); }
 
-       int     v_batt;
-       int     sense_a;
-       int     sense_m;
+       int     v_batt() { return int16(20); }
+       int     sense_a() { return int16(22); }
+       int     sense_m() { return int16(24); }
 
-       public AltosTelemetryMetrumSensor(int[] bytes) {
+       public AltosTelemetryMetrumSensor(int[] bytes) throws AltosCRCException {
                super(bytes);
-
-               state         = int8(5);
-               accel         = int16(6);
-               pres          = int32(8);
-               temp          = int16(12);
-
-               acceleration  = int16(14);
-               speed         = int16(16);
-               height_16     = int16(18);
-
-               v_batt        = int16(20);
-               sense_a       = int16(22);
-               sense_m       = int16(24);
        }
 
        public void update_state(AltosState state) {
                super.update_state(state);
 
-               state.set_state(this.state);
+               state.set_state(state());
 
-               state.set_accel(accel);
-               state.set_pressure(pres);
-               state.set_temperature(temp/100.0);
+               state.set_accel(accel());
+               state.set_pressure(pres());
+               state.set_temperature(temp()/100.0);
 
-               state.set_kalman(extend_height(state, height_16),
-                                speed/16.0, acceleration/16.0);
+               state.set_kalman(extend_height(state, height_16()),
+                                speed()/16.0, acceleration()/16.0);
 
-               state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt));
+               state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
 
-               state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense_a));
-               state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m));
+               state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense_a()));
+               state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense_m()));
        }
 }
index 50ec504d6934b89a08cfa187e3ae074ad85734fc..bc151139e57e255999e6c2e2a58eba2d4877a9d8 100644 (file)
@@ -20,54 +20,40 @@ package org.altusmetrum.altoslib_11;
 
 
 public class AltosTelemetryMini2 extends AltosTelemetryStandard {
-       int     state;
 
-       int     v_batt;
-       int     sense_a;
-       int     sense_m;
+       int     state() { return uint8(5); }
 
-       int     pres;
-       int     temp;
+       int     v_batt() { return int16(6); }
+       int     sense_a() { return int16(8); }
+       int     sense_m() { return int16(10); }
 
-       int     acceleration;
-       int     speed;
-       int     height;
+       int     pres() { return int32(12); }
+       int     temp() { return int16(16); }
 
-       int     ground_pres;
+       int     acceleration() { return int16(18); }
+       int     speed() { return int16(20); }
+       int     height() { return int16(22); }
 
-       public AltosTelemetryMini2(int[] bytes) {
-               super(bytes);
-
-               state         = int8(5);
-
-               v_batt        = int16(6);
-               sense_a       = int16(8);
-               sense_m       = int16(10);
+       int     ground_pres() { return int32(24); }
 
-               pres          = int32(12);
-               temp          = int16(16);
-
-               acceleration  = int16(18);
-               speed         = int16(20);
-               height        = int16(22);
-
-               ground_pres   = int32(24);
+       public AltosTelemetryMini2(int[] bytes) throws AltosCRCException {
+               super(bytes);
        }
 
        public void update_state(AltosState state) {
                super.update_state(state);
 
-               state.set_state(this.state);
+               state.set_state(state());
 
-               state.set_battery_voltage(AltosConvert.tele_mini_2_voltage(v_batt));
-               state.set_apogee_voltage(AltosConvert.tele_mini_2_voltage(sense_a));
-               state.set_main_voltage(AltosConvert.tele_mini_2_voltage(sense_m));
+               state.set_battery_voltage(AltosConvert.tele_mini_2_voltage(v_batt()));
+               state.set_apogee_voltage(AltosConvert.tele_mini_2_voltage(sense_a()));
+               state.set_main_voltage(AltosConvert.tele_mini_2_voltage(sense_m()));
 
-               state.set_ground_pressure(ground_pres);
+               state.set_ground_pressure(ground_pres());
 
-               state.set_pressure(pres);
-               state.set_temperature(temp/100.0);
+               state.set_pressure(pres());
+               state.set_temperature(temp()/100.0);
 
-               state.set_kalman(height, speed/16.0, acceleration/16.0);
+               state.set_kalman(height(), speed()/16.0, acceleration()/16.0);
        }
 }
index 21f8c485d6d1781367563555a40e1482cdb6d88e..b8a507cc3d0f6d2b15a6a22fc714d0a420a9fe6f 100644 (file)
@@ -21,56 +21,41 @@ package org.altusmetrum.altoslib_11;
 
 public class AltosTelemetryMini3 extends AltosTelemetryStandard {
 
-       int     state;
+       int     state() { return uint8(5); }
 
-       int     v_batt;
-       int     sense_a;
-       int     sense_m;
+       int     v_batt() { return int16(6); }
+       int     sense_a() { return int16(8); }
+       int     sense_m() { return int16(10); }
 
-       int     pres;
-       int     temp;
+       int     pres() { return int32(12); }
+       int     temp() { return int16(16); }
 
-       int     acceleration;
-       int     speed;
-       int     height_16;
+       int     acceleration() { return int16(18); }
+       int     speed() { return int16(20); }
+       int     height_16() { return int16(22); }
 
-       int     ground_pres;
+       int     ground_pres() { return int32(24); }
 
-       public AltosTelemetryMini3(int[] bytes) {
+       public AltosTelemetryMini3(int[] bytes) throws AltosCRCException {
                super(bytes);
-
-               state         = int8(5);
-
-               v_batt        = int16(6);
-               sense_a       = int16(8);
-               sense_m       = int16(10);
-
-               pres          = int32(12);
-               temp          = int16(16);
-
-               acceleration  = int16(18);
-               speed         = int16(20);
-               height_16     = int16(22);
-
-               ground_pres   = int32(24);
        }
 
        public void update_state(AltosState state) {
                super.update_state(state);
 
-               state.set_state(this.state);
+               state.set_state(state());
 
-               state.set_battery_voltage(AltosConvert.tele_mini_3_battery_voltage(v_batt));
+               state.set_battery_voltage(AltosConvert.tele_mini_3_battery_voltage(v_batt()));
 
-               state.set_apogee_voltage(AltosConvert.tele_mini_3_pyro_voltage(sense_a));
-               state.set_main_voltage(AltosConvert.tele_mini_3_pyro_voltage(sense_m));
+               state.set_apogee_voltage(AltosConvert.tele_mini_3_pyro_voltage(sense_a()));
+               state.set_main_voltage(AltosConvert.tele_mini_3_pyro_voltage(sense_m()));
 
-               state.set_pressure(pres);
-               state.set_temperature(temp/100.0);
+               state.set_pressure(pres());
+               state.set_temperature(temp()/100.0);
 
-               state.set_kalman(extend_height(state, height_16),
-                                speed/16.0, acceleration/16.0);
+               state.set_kalman(extend_height(state, height_16()),
+                                speed()/16.0, acceleration()/16.0);
 
-               state.set_ground_pressure(ground_pres);
+               state.set_ground_pressure(ground_pres());
        }
 }
index 339043a66c3a3c0228471fb6a180ad46af5892db..12c4623bb44625144255d86bb992d15bf077c10f 100644 (file)
@@ -19,7 +19,7 @@
 package org.altusmetrum.altoslib_11;
 
 public class AltosTelemetryRaw extends AltosTelemetryStandard {
-       public AltosTelemetryRaw(int[] bytes) {
+       public AltosTelemetryRaw(int[] bytes) throws AltosCRCException {
                super(bytes);
        }
 
index 6897f0e6d4273e740a51ad98e2773d0c0072197b..ce12d32dd197233e1e2c4f9bada1fdc5d4bfa456 100644 (file)
 package org.altusmetrum.altoslib_11;
 
 public class AltosTelemetrySatellite extends AltosTelemetryStandard {
-       int             channels;
-       AltosGPSSat[]   sats;
+       int             channels() { return uint8(5); }
 
-       public AltosTelemetrySatellite(int[] bytes) {
-               super(bytes);
+       AltosGPSSat[]   sats() {
+               int             channels = channels();
+               AltosGPSSat[]   sats = null;
 
-               channels = uint8(5);
                if (channels > 12)
                        channels = 12;
                if (channels == 0)
@@ -38,6 +37,11 @@ public class AltosTelemetrySatellite extends AltosTelemetryStandard {
                                sats[i] = new AltosGPSSat(svid, c_n_1);
                        }
                }
+               return sats;
+       }
+
+       public AltosTelemetrySatellite(int[] bytes) throws AltosCRCException {
+               super(bytes);
        }
 
        public void update_state(AltosState state) {
@@ -45,7 +49,7 @@ public class AltosTelemetrySatellite extends AltosTelemetryStandard {
 
                AltosGPS        gps = state.make_temp_gps(true);
 
-               gps.cc_gps_sat = sats;
+               gps.cc_gps_sat = sats();
                state.set_temp_gps();
        }
 }
index 3c3e6a0104b6b24b5de437e0cc00f2b9a30c24e2..b669b9e6441e8db35bcb498284bba864a7ad3376 100644 (file)
@@ -20,62 +20,45 @@ package org.altusmetrum.altoslib_11;
 
 
 public class AltosTelemetrySensor extends AltosTelemetryStandard {
-       int     state;
-       int     accel;
-       int     pres;
-       int     temp;
-       int     v_batt;
-       int     sense_d;
-       int     sense_m;
+       int     state() { return uint8(5); }
+       int     accel() { return int16(6); }
+       int     pres() { return int16(8); }
+       int     temp() { return int16(10); }
+       int     v_batt() { return int16(12); }
+       int     sense_d() { return int16(14); }
+       int     sense_m() { return int16(16); }
 
-       int     acceleration;
-       int     speed;
-       int     height;
+       int     acceleration() { return int16(18); }
+       int     speed() { return int16(20); }
+       int     height_16() { return int16(22); }
 
-       int     ground_accel;
-       int     ground_pres;
-       int     accel_plus_g;
-       int     accel_minus_g;
+       int     ground_accel() { return int16(24); }
+       int     ground_pres() { return int16(26); }
+       int     accel_plus_g() { return int16(28); }
+       int     accel_minus_g() { return int16(30); }
 
-       public AltosTelemetrySensor(int[] bytes) {
+       public AltosTelemetrySensor(int[] bytes) throws AltosCRCException {
                super(bytes);
-               state         = uint8(5);
-
-               accel         = int16(6);
-               pres          = int16(8);
-               temp          = int16(10);
-               v_batt        = int16(12);
-               sense_d       = int16(14);
-               sense_m       = int16(16);
-
-               acceleration  = int16(18);
-               speed         = int16(20);
-               height        = int16(22);
-
-               ground_pres   = int16(24);
-               ground_accel  = int16(26);
-               accel_plus_g  = int16(28);
-               accel_minus_g = int16(30);
        }
 
        public void update_state(AltosState state) {
                super.update_state(state);
 
-               state.set_state(this.state);
-               if (type == packet_type_TM_sensor) {
-                       state.set_ground_accel(ground_accel);
-                       state.set_accel_g(accel_plus_g, accel_minus_g);
-                       state.set_accel(accel);
+               state.set_state(state());
+               if (type() == packet_type_TM_sensor) {
+                       state.set_ground_accel(ground_accel());
+                       state.set_accel_g(accel_plus_g(), accel_minus_g());
+                       state.set_accel(accel());
                }
-               state.set_ground_pressure(AltosConvert.barometer_to_pressure(ground_pres));
-               state.set_pressure(AltosConvert.barometer_to_pressure(pres));
-               state.set_temperature(AltosConvert.thermometer_to_temperature(temp));
-               state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(v_batt));
-               if (type == packet_type_TM_sensor || type == packet_type_Tm_sensor) {
-                       state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(sense_d));
-                       state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(sense_m));
+               state.set_ground_pressure(AltosConvert.barometer_to_pressure(ground_pres()));
+               state.set_pressure(AltosConvert.barometer_to_pressure(pres()));
+               state.set_temperature(AltosConvert.thermometer_to_temperature(temp()));
+               state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(v_batt()));
+               if (type() == packet_type_TM_sensor || type() == packet_type_Tm_sensor) {
+                       state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(sense_d()));
+                       state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(sense_m()));
                }
 
-               state.set_kalman(height, speed/16.0, acceleration / 16.0);
+               state.set_kalman(height_16(), speed()/16.0, acceleration()/16.0);
        }
 }
index 35d315c7972963b4b3ea1b9bfa447704c70e5d2a..1718e4b771d16f785caaca23abc453a990823064 100644 (file)
@@ -19,9 +19,6 @@
 package org.altusmetrum.altoslib_11;
 
 public abstract class AltosTelemetryStandard extends AltosTelemetry {
-       int[]   bytes;
-       int     type;
-
        public int int8(int off) {
                return AltosLib.int8(bytes, off + 1);
        }
@@ -50,10 +47,16 @@ public abstract class AltosTelemetryStandard extends AltosTelemetry {
                return AltosLib.string(bytes, off + 1, l);
        }
 
-       public static AltosTelemetry parse_hex(int[] bytes) {
-               int     type = AltosLib.uint8(bytes, 4 + 1);
+       public int type() { return uint8(4); }
+
+       public int serial() { return uint16(0); }
+
+       public int tick() { return uint16(2); }
 
+       public static AltosTelemetry parse_hex(int[] bytes) throws AltosCRCException {
                AltosTelemetry  telem;
+
+               int type = AltosLib.uint8(bytes, 4+1);
                switch (type) {
                case packet_type_TM_sensor:
                case packet_type_Tm_sensor:
@@ -97,12 +100,8 @@ public abstract class AltosTelemetryStandard extends AltosTelemetry {
                return telem;
        }
 
-       public AltosTelemetryStandard(int[] bytes) {
-               this.bytes = bytes;
-
-               serial = uint16(0);
-               tick   = uint16(2);
-               type   = uint8(4);
+       public AltosTelemetryStandard(int[] bytes) throws AltosCRCException {
+               super(bytes);
        }
 
        public void update_state(AltosState state) {