altosui: remove un-used imports
[fw/altos] / altosui / AltosCSV.java
index df98b2b45f8f381bf22bf55e932dbf51c52dfafa..f8cc1ed6b1d12240a34ee74a7b28bfbc1018564c 100644 (file)
 
 package altosui;
 
-import java.lang.*;
 import java.io.*;
-import java.text.*;
 import java.util.*;
+import org.altusmetrum.AltosLib.*;
 
 public class AltosCSV implements AltosWriter {
        File                    name;
@@ -31,9 +30,9 @@ public class AltosCSV implements AltosWriter {
        LinkedList<AltosRecord> pad_records;
        AltosState              state;
 
-       static final int ALTOS_CSV_VERSION = 2;
+       static final int ALTOS_CSV_VERSION = 5;
 
-       /* Version 2 format:
+       /* Version 4 format:
         *
         * General info
         *      version number
@@ -41,6 +40,7 @@ public class AltosCSV implements AltosWriter {
         *      flight number
         *      callsign
         *      time (seconds since boost)
+        *      clock (tick count / 100)
         *      rssi
         *      link quality
         *
@@ -60,7 +60,18 @@ public class AltosCSV implements AltosWriter {
         *      drogue (V)
         *      main (V)
         *
-        * GPS data
+        * Advanced sensors (if available)
+        *      accel_x (m/s²)
+        *      accel_y (m/s²)
+        *      accel_z (m/s²)
+        *      gyro_x (d/s)
+        *      gyro_y (d/s)
+        *      gyro_z (d/s)
+        *      mag_x (g)
+        *      mag_y (g)
+        *      mag_z (g)
+        *
+        * GPS data (if available)
         *      connected (1/0)
         *      locked (1/0)
         *      nsat (used for solution)
@@ -81,16 +92,23 @@ public class AltosCSV implements AltosWriter {
         *
         * GPS Sat data
         *      C/N0 data for all 32 valid SDIDs
+        *
+        * Companion data
+        *      companion_id (1-255. 10 is TeleScience)
+        *      time of last companion data (seconds since boost)
+        *      update_period (0.1-2.55 minimum telemetry interval)
+        *      channels (0-12)
+        *      channel data for all 12 possible channels
         */
 
        void write_general_header() {
-               out.printf("version,serial,flight,call,time,rssi,lqi");
+               out.printf("version,serial,flight,call,time,clock,rssi,lqi");
        }
 
        void write_general(AltosRecord record) {
-               out.printf("%s, %d, %d, %s, %8.2f, %4d, %3d",
+               out.printf("%s, %d, %d, %s, %8.2f, %8.2f, %4d, %3d",
                           ALTOS_CSV_VERSION, record.serial, record.flight, record.callsign,
-                          (double) record.time,
+                          (double) record.time, (double) record.tick / 100.0,
                           record.rssi,
                           record.status & 0x7f);
        }
@@ -121,6 +139,24 @@ public class AltosCSV implements AltosWriter {
                           record.main_voltage());
        }
 
+       void write_advanced_header() {
+               out.printf("accel_x,accel_y,accel_z,gyro_x,gyro_y,gyro_z");
+       }
+
+       void write_advanced(AltosRecord record) {
+               AltosIMU        imu = record.imu();
+               AltosMag        mag = record.mag();
+
+               if (imu == null)
+                       imu = new AltosIMU();
+               if (mag == null)
+                       mag = new AltosMag();
+               out.printf("%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d,%6d",
+                          imu.accel_x, imu.accel_y, imu.accel_z,
+                          imu.gyro_x, imu.gyro_y, imu.gyro_z,
+                          mag.x, mag.y, mag.z);
+       }
+
        void write_gps_header() {
                out.printf("connected,locked,nsat,latitude,longitude,altitude,year,month,day,hour,minute,second,pad_dist,pad_range,pad_az,pad_el,hdop");
        }
@@ -179,12 +215,44 @@ public class AltosCSV implements AltosWriter {
                }
        }
 
-       void write_header() {
+       void write_companion_header() {
+               out.printf("companion_id,companion_time,companion_update,companion_channels");
+               for (int i = 0; i < 12; i++)
+                       out.printf(",companion_%02d", i);
+       }
+
+       void write_companion(AltosRecord record) {
+               AltosRecordCompanion companion = record.companion;
+
+               int     channels_written = 0;
+               if (companion == null) {
+                       out.printf("0,0,0,0");
+               } else {
+                       out.printf("%3d,%5.2f,%5.2f,%2d",
+                                  companion.board_id,
+                                  (companion.tick - boost_tick) / 100.0,
+                                  companion.update_period / 100.0,
+                                  companion.channels);
+                       for (; channels_written < companion.channels; channels_written++)
+                               out.printf(",%5d", companion.companion_data[channels_written]);
+               }
+               for (; channels_written < 12; channels_written++)
+                       out.printf(",0");
+       }
+
+       void write_header(boolean advanced, boolean gps, boolean companion) {
                out.printf("#"); write_general_header();
                out.printf(","); write_flight_header();
                out.printf(","); write_basic_header();
-               out.printf(","); write_gps_header();
-               out.printf(","); write_gps_sat_header();
+               if (advanced)
+                       out.printf(","); write_advanced_header();
+               if (gps) {
+                       out.printf(","); write_gps_header();
+                       out.printf(","); write_gps_sat_header();
+               }
+               if (companion) {
+                       out.printf(","); write_companion_header();
+               }
                out.printf ("\n");
        }
 
@@ -193,8 +261,17 @@ public class AltosCSV implements AltosWriter {
                write_general(record); out.printf(",");
                write_flight(record); out.printf(",");
                write_basic(record); out.printf(",");
-               write_gps(record); out.printf(",");
-               write_gps_sat(record);
+               if (record.imu() != null || record.mag() != null)
+                       write_advanced(record);
+               if (record.gps != null) {
+                       out.printf(",");
+                       write_gps(record); out.printf(",");
+                       write_gps_sat(record);
+               }
+               if (record.companion != null) {
+                       out.printf(",");
+                       write_companion(record);
+               }
                out.printf ("\n");
        }
 
@@ -205,8 +282,11 @@ public class AltosCSV implements AltosWriter {
        }
 
        public void write(AltosRecord record) {
+               if (record.state == Altos.ao_flight_startup)
+                       return;
                if (!header_written) {
-                       write_header();
+                       write_header(record.imu() != null || record.mag() != null,
+                                    record.gps != null, record.companion != null);
                        header_written = true;
                }
                if (!seen_boost) {
@@ -240,12 +320,16 @@ public class AltosCSV implements AltosWriter {
                        write(r);
        }
 
-       public AltosCSV(File in_name) throws FileNotFoundException {
+       public AltosCSV(PrintStream in_out, File in_name) {
                name = in_name;
-               out = new PrintStream(name);
+               out = in_out;
                pad_records = new LinkedList<AltosRecord>();
        }
 
+       public AltosCSV(File in_name) throws FileNotFoundException {
+               this(new PrintStream(in_name), in_name);
+       }
+
        public AltosCSV(String in_string) throws FileNotFoundException {
                this(new File(in_string));
        }