altosui: Report telemetry CRC errors in UI
authorKeith Packard <keithp@keithp.com>
Fri, 3 Sep 2010 08:12:24 +0000 (01:12 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 3 Sep 2010 14:04:28 +0000 (07:04 -0700)
Telemetry CRC errors can signal problems with TeleMetrum or TeleDongle
units, so report them in the UI.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosCRCException.java [new file with mode: 0644]
ao-tools/altosui/AltosLog.java
ao-tools/altosui/AltosSerial.java
ao-tools/altosui/AltosTelemetry.java
ao-tools/altosui/AltosTelemetryReader.java
ao-tools/altosui/AltosUI.java
ao-tools/altosui/Makefile

diff --git a/ao-tools/altosui/AltosCRCException.java b/ao-tools/altosui/AltosCRCException.java
new file mode 100644 (file)
index 0000000..4a529bc
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright © 2010 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; version 2 of the License.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package altosui;
+
+public class AltosCRCException extends Exception {
+       public int rssi;
+
+       public AltosCRCException (int in_rssi) {
+               rssi = in_rssi;
+       }
+}
index ec868b9c8dd2bcc078cf5b07541a07140e847c56..2c241771be6c3b3d95b6f8792a973a4ad84636ac 100644 (file)
@@ -74,6 +74,7 @@ class AltosLog implements Runnable {
                                                open(telem);
                                        }
                                } catch (ParseException pe) {
+                               } catch (AltosCRCException ce) {
                                }
                                if (log_file != null) {
                                        log_file.write(line);
index 99ba3324e623fbd3d3fe3c82c0323b6b3587c9f3..c3daf3b93cd8c00188ddff48563995d079b65cf0 100644 (file)
@@ -71,7 +71,7 @@ public class AltosSerial implements Runnable {
                                                                for (int i = 0; i < line_count; i++)
                                                                        line = line + line_bytes[i];
                                                        }
-                                                       if (line.startsWith("VERSION")) {
+                                                       if (line.startsWith("VERSION") || line.startsWith("CRC")) {
                                                                for (int e = 0; e < monitors.size(); e++) {
                                                                        LinkedBlockingQueue<String> q = monitors.get(e);
                                                                        q.put(line);
index bc62690b262874b4006ff723f208ae2a8daebfd2..be22dac60aa308c8e170f960b3718f79c6088bdd 100644 (file)
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import altosui.AltosConvert;
 import altosui.AltosRecord;
 import altosui.AltosGPS;
+import altosui.AltosCRCException;
 
 /*
  * Telemetry data contents
@@ -53,10 +54,16 @@ import altosui.AltosGPS;
  */
 
 public class AltosTelemetry extends AltosRecord {
-       public AltosTelemetry(String line) throws ParseException {
+       public AltosTelemetry(String line) throws ParseException, AltosCRCException {
                String[] words = line.split("\\s+");
                int     i = 0;
 
+               if (words[i].equals("CRC") && words[i+1].equals("INVALID")) {
+                       i += 2;
+                       AltosParse.word(words[i++], "RSSI");
+                       rssi = AltosParse.parse_int(words[i++]);
+                       throw new AltosCRCException(rssi);
+               }
                if (words[i].equals("CALL")) {
                        version = 0;
                } else {
index a3402f9c8b85a1756809ed2f879009fcb37b4294..fdedbde279345499e1ac926104478ade2106fa24 100644 (file)
@@ -62,6 +62,8 @@ public class AltosTelemetryReader extends AltosReader {
                                        records.add(record);
                                } catch (ParseException pe) {
                                        System.out.printf("parse exception %s\n", pe.getMessage());
+                               } catch (AltosCRCException ce) {
+                                       System.out.printf("crc error\n");
                                }
                        }
                } catch (IOException io) {
index 5b48e26f16fda3c6cec6044580c8654908272cf5..e3f613037dc61eab425d2a1becf9a0d735be0ce7 100644 (file)
@@ -168,21 +168,17 @@ public class AltosUI extends JFrame {
                        flightInfoModel[i].finish();
        }
 
-       public void show(AltosState state) {
+       public void show(AltosState state, int crc_errors) {
                flightStatusModel.set(state);
 
                info_reset();
-               if (state.gps_ready)
-                       info_add_row(0, "Ground state", "%s", "ready");
-               else
-                       info_add_row(0, "Ground state", "wait (%d)",
-                                    state.gps_waiting);
                info_add_row(0, "Rocket state", "%s", state.data.state());
                info_add_row(0, "Callsign", "%s", state.data.callsign);
                info_add_row(0, "Rocket serial", "%6d", state.data.serial);
                info_add_row(0, "Rocket flight", "%6d", state.data.flight);
 
                info_add_row(0, "RSSI", "%6d    dBm", state.data.rssi);
+               info_add_row(0, "CRC Errors", "%6d", crc_errors);
                info_add_row(0, "Height", "%6.0f    m", state.height);
                info_add_row(0, "Max height", "%6.0f    m", state.max_height);
                info_add_row(0, "Acceleration", "%8.1f  m/s²", state.acceleration);
@@ -197,6 +193,11 @@ public class AltosUI extends JFrame {
                if (state.gps == null) {
                        info_add_row(1, "GPS", "not available");
                } else {
+                       if (state.gps_ready)
+                               info_add_row(1, "GPS state", "%s", "ready");
+                       else
+                               info_add_row(1, "GPS state", "wait (%d)",
+                                            state.gps_waiting);
                        if (state.data.gps.locked)
                                info_add_row(1, "GPS", "   locked");
                        else if (state.data.gps.connected)
@@ -362,7 +363,11 @@ public class AltosUI extends JFrame {
 
                String          name;
 
-               AltosRecord read() throws InterruptedException, ParseException { return null; }
+               int             crc_errors;
+
+               void init() { }
+
+               AltosRecord read() throws InterruptedException, ParseException, AltosCRCException { return null; }
 
                void close() { }
 
@@ -387,11 +392,14 @@ public class AltosUI extends JFrame {
                                                old_state = state;
                                                state = new AltosState(record, state);
                                                update(state);
-                                               show(state);
+                                               show(state, crc_errors);
                                                tell(state, old_state);
                                                idle_thread.notice(state);
                                        } catch (ParseException pp) {
                                                System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage());
+                                       } catch (AltosCRCException ce) {
+                                               ++crc_errors;
+                                               show(state, crc_errors);
                                        }
                                }
                        } catch (InterruptedException ee) {
@@ -411,7 +419,7 @@ public class AltosUI extends JFrame {
                AltosSerial     serial;
                LinkedBlockingQueue<String> telem;
 
-               AltosRecord read() throws InterruptedException, ParseException {
+               AltosRecord read() throws InterruptedException, ParseException, AltosCRCException {
                        return new AltosTelemetry(telem.take());
                }
 
index 0f5d05c89bfba565599e6e06321bb1b10c45475e..8509391e8a3935c22ef6e24fad2619b48737dcde 100644 (file)
@@ -7,6 +7,7 @@ CLASSFILES=\
        AltosConfig.class \
        AltosConfigUI.class \
        AltosConvert.class \
+       AltosCRCException.class \
        AltosCSV.class \
        AltosCSVUI.class \
        AltosDebug.class \