altosdroid: Fix offline map messages to match new meanings
[fw/altos] / altoslib / AltosTelemetry.java
index 7d576942c22f6348cd2b804c9855d751f1745f69..a19e4226160a7e7d561a8c36a003191b26789419 100644 (file)
@@ -16,7 +16,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_12;
+package org.altusmetrum.altoslib_13;
 
 import java.text.*;
 
@@ -28,8 +28,11 @@ public abstract class AltosTelemetry implements AltosDataProvider {
        int[]   bytes;
 
        /* All telemetry packets have these fields */
-       public int rssi() { return AltosConvert.telem_to_rssi(AltosLib.int8(bytes, bytes.length - 3)); }
-       public int status() { return AltosLib.uint8(bytes, bytes.length - 2); }
+       static public int rssi(int[] bytes) { return AltosConvert.telem_to_rssi(AltosLib.int8(bytes, bytes.length - 3)); }
+       static public int status(int[] bytes) { return AltosLib.uint8(bytes, bytes.length - 2); }
+
+       public int rssi() { return rssi(bytes); }
+       public int status() { return status(bytes); }
 
        /* All telemetry packets report these fields in some form */
        public abstract int serial();
@@ -38,6 +41,9 @@ public abstract class AltosTelemetry implements AltosDataProvider {
        /* Mark when we received the packet */
        long            received_time;
 
+       /* Mark frequency packet was received on */
+       public double           frequency = AltosLib.MISSING;
+
        static boolean cksum(int[] bytes) {
                int     sum = 0x5a;
                for (int i = 1; i < bytes.length - 1; i++)
@@ -48,8 +54,10 @@ public abstract class AltosTelemetry implements AltosDataProvider {
 
        public void provide_data(AltosDataListener listener) {
                listener.set_serial(serial());
-               if (listener.state == AltosLib.ao_flight_invalid)
+               if (listener.state() == AltosLib.ao_flight_invalid)
                        listener.set_state(AltosLib.ao_flight_startup);
+               if (frequency != AltosLib.MISSING)
+                       listener.set_frequency(frequency);
                listener.set_tick(tick());
                listener.set_rssi(rssi(), status());
                listener.set_received_time(received_time);
@@ -91,6 +99,9 @@ public abstract class AltosTelemetry implements AltosDataProvider {
                if (!cksum(bytes))
                        throw new ParseException(String.format("invalid line \"%s\"", hex), 0);
 
+               if ((status(bytes) & PKT_APPEND_STATUS_1_CRC_OK) == 0)
+                       throw new AltosCRCException(rssi(bytes));
+
                /* length, data ..., rssi, status, checksum -- 4 bytes extra */
                switch (bytes.length) {
                case AltosLib.ao_telemetry_standard_len + 4:
@@ -108,6 +119,10 @@ public abstract class AltosTelemetry implements AltosDataProvider {
                return telem;
        }
 
+       public void set_frequency(double frequency) {
+               this.frequency = frequency;
+       }
+
        public AltosTelemetry() {
                this.received_time = System.currentTimeMillis();
        }