Merge remote-tracking branch 'origin/master'
authorKeith Packard <keithp@keithp.com>
Tue, 8 Oct 2013 16:26:41 +0000 (09:26 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 8 Oct 2013 16:26:41 +0000 (09:26 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
Conflicts:
configure.ac

264 files changed:
altosdroid/src/org/altusmetrum/AltosDroid/AltosBluetooth.java
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidTab.java
altosdroid/src/org/altusmetrum/AltosDroid/AltosVoice.java
altosdroid/src/org/altusmetrum/AltosDroid/Dumper.java
altosdroid/src/org/altusmetrum/AltosDroid/TabAscent.java
altosdroid/src/org/altusmetrum/AltosDroid/TabDescent.java
altosdroid/src/org/altusmetrum/AltosDroid/TabLanded.java
altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java
altosdroid/src/org/altusmetrum/AltosDroid/TabPad.java
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryLogger.java
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryReader.java
altosdroid/src/org/altusmetrum/AltosDroid/TelemetryService.java
altoslib/AltosAccel.java
altoslib/AltosCRCException.java
altoslib/AltosCompanion.java [new file with mode: 0644]
altoslib/AltosConfigData.java
altoslib/AltosConfigValues.java
altoslib/AltosConvert.java
altoslib/AltosDebug.java
altoslib/AltosDistance.java
altoslib/AltosEeprom.java [new file with mode: 0644]
altoslib/AltosEepromChunk.java
altoslib/AltosEepromFile.java [new file with mode: 0644]
altoslib/AltosEepromHeader.java [new file with mode: 0644]
altoslib/AltosEepromIterable.java
altoslib/AltosEepromLog.java
altoslib/AltosEepromMega.java
altoslib/AltosEepromMegaIterable.java [deleted file]
altoslib/AltosEepromMetrum2.java [new file with mode: 0644]
altoslib/AltosEepromMini.java
altoslib/AltosEepromMiniIterable.java [deleted file]
altoslib/AltosEepromRecord.java [deleted file]
altoslib/AltosEepromTM.java [new file with mode: 0644]
altoslib/AltosEepromTeleScience.java [deleted file]
altoslib/AltosEepromTm.java [new file with mode: 0644]
altoslib/AltosFile.java
altoslib/AltosFlash.java
altoslib/AltosFlashListener.java
altoslib/AltosFlightReader.java
altoslib/AltosFrequency.java
altoslib/AltosGPS.java
altoslib/AltosGPSQuery.java [deleted file]
altoslib/AltosGPSSat.java
altoslib/AltosGreatCircle.java
altoslib/AltosHeight.java
altoslib/AltosHexfile.java
altoslib/AltosIMU.java
altoslib/AltosIMUQuery.java [deleted file]
altoslib/AltosIdle.java [new file with mode: 0644]
altoslib/AltosIdleFetch.java [new file with mode: 0644]
altoslib/AltosIdleMonitor.java
altoslib/AltosIdleMonitorListener.java
altoslib/AltosIgnite.java
altoslib/AltosLib.java
altoslib/AltosLine.java
altoslib/AltosLink.java
altoslib/AltosListenerState.java
altoslib/AltosLog.java
altoslib/AltosMag.java
altoslib/AltosMma655x.java [new file with mode: 0644]
altoslib/AltosMs5607.java
altoslib/AltosMs5607Query.java [deleted file]
altoslib/AltosOrderedMegaRecord.java [deleted file]
altoslib/AltosOrderedMiniRecord.java [deleted file]
altoslib/AltosOrderedRecord.java [deleted file]
altoslib/AltosParse.java
altoslib/AltosPreferences.java
altoslib/AltosPreferencesBackend.java
altoslib/AltosPyro.java
altoslib/AltosRecord.java [deleted file]
altoslib/AltosRecordCompanion.java [deleted file]
altoslib/AltosRecordIterable.java [deleted file]
altoslib/AltosRecordMM.java [deleted file]
altoslib/AltosRecordMini.java [deleted file]
altoslib/AltosRecordNone.java [deleted file]
altoslib/AltosRecordTM.java [deleted file]
altoslib/AltosReplayReader.java
altoslib/AltosRomconfig.java
altoslib/AltosSelfFlash.java [new file with mode: 0644]
altoslib/AltosSensorEMini.java [new file with mode: 0644]
altoslib/AltosSensorMM.java
altoslib/AltosSensorMega.java [new file with mode: 0644]
altoslib/AltosSensorMetrum.java [new file with mode: 0644]
altoslib/AltosSensorTM.java
altoslib/AltosSensorTMini.java [new file with mode: 0644]
altoslib/AltosSpeed.java
altoslib/AltosState.java
altoslib/AltosStateIterable.java [new file with mode: 0644]
altoslib/AltosStateUpdate.java [new file with mode: 0644]
altoslib/AltosTelemetry.java
altoslib/AltosTelemetryConfiguration.java [new file with mode: 0644]
altoslib/AltosTelemetryFile.java [new file with mode: 0644]
altoslib/AltosTelemetryIterable.java
altoslib/AltosTelemetryLegacy.java [new file with mode: 0644]
altoslib/AltosTelemetryLocation.java [new file with mode: 0644]
altoslib/AltosTelemetryMap.java
altoslib/AltosTelemetryMegaData.java [new file with mode: 0644]
altoslib/AltosTelemetryMegaSensor.java [new file with mode: 0644]
altoslib/AltosTelemetryMetrumData.java [new file with mode: 0644]
altoslib/AltosTelemetryMetrumSensor.java [new file with mode: 0644]
altoslib/AltosTelemetryMini.java [new file with mode: 0644]
altoslib/AltosTelemetryRaw.java [new file with mode: 0644]
altoslib/AltosTelemetryReader.java
altoslib/AltosTelemetryRecord.java [deleted file]
altoslib/AltosTelemetryRecordCompanion.java [deleted file]
altoslib/AltosTelemetryRecordConfiguration.java [deleted file]
altoslib/AltosTelemetryRecordGeneral.java [deleted file]
altoslib/AltosTelemetryRecordLegacy.java [deleted file]
altoslib/AltosTelemetryRecordLocation.java [deleted file]
altoslib/AltosTelemetryRecordMegaData.java [deleted file]
altoslib/AltosTelemetryRecordMegaSensor.java [deleted file]
altoslib/AltosTelemetryRecordRaw.java [deleted file]
altoslib/AltosTelemetryRecordSatellite.java [deleted file]
altoslib/AltosTelemetryRecordSensor.java [deleted file]
altoslib/AltosTelemetrySatellite.java [new file with mode: 0644]
altoslib/AltosTelemetrySensor.java [new file with mode: 0644]
altoslib/AltosTelemetryStandard.java [new file with mode: 0644]
altoslib/AltosTemperature.java
altoslib/AltosUnits.java
altoslib/AltosUnitsListener.java
altoslib/Makefile.am
altosui/Altos.java
altosui/AltosAscent.java
altosui/AltosBTKnown.java
altosui/AltosCSV.java
altosui/AltosCSVUI.java
altosui/AltosCompanionInfo.java
altosui/AltosConfig.java
altosui/AltosConfigFreqUI.java
altosui/AltosConfigPyroUI.java
altosui/AltosConfigTD.java
altosui/AltosConfigTDUI.java
altosui/AltosConfigUI.java
altosui/AltosDataChooser.java
altosui/AltosDescent.java
altosui/AltosDisplayThread.java
altosui/AltosEepromDelete.java
altosui/AltosEepromDownload.java
altosui/AltosEepromList.java
altosui/AltosEepromManage.java
altosui/AltosEepromSelect.java
altosui/AltosFlashUI.java
altosui/AltosFlightDisplay.java
altosui/AltosFlightStats.java
altosui/AltosFlightStatsTable.java
altosui/AltosFlightStatus.java
altosui/AltosFlightStatusTableModel.java
altosui/AltosFlightStatusUpdate.java
altosui/AltosFlightUI.java
altosui/AltosFreqList.java
altosui/AltosGraph.java
altosui/AltosGraphDataPoint.java
altosui/AltosGraphDataSet.java
altosui/AltosGraphUI.java
altosui/AltosIdleMonitorUI.java
altosui/AltosIgniteUI.java
altosui/AltosInfoTable.java
altosui/AltosKML.java
altosui/AltosLanded.java
altosui/AltosPad.java
altosui/AltosRomconfigUI.java
altosui/AltosScanUI.java
altosui/AltosSerial.java
altosui/AltosSiteMap.java
altosui/AltosSiteMapTile.java
altosui/AltosUI.java
altosui/AltosUIPreferencesBackend.java
altosui/AltosWriter.java
altosuilib/AltosUIAxis.java
altosuilib/AltosUIEnable.java
altosuilib/AltosUIGraph.java
altosuilib/AltosUIGrapher.java
altosuilib/AltosUILib.java
altosuilib/AltosUIMarker.java
altosuilib/AltosUIPreferences.java
altosuilib/AltosUIPreferencesBackend.java
altosuilib/AltosUISeries.java
ao-tools/ao-telem/ao-telem.c
ao-tools/lib/cc-telemetry.h
configure.ac
micropeak/MicroData.java
micropeak/MicroDownload.java
micropeak/MicroExport.java
micropeak/MicroFile.java
micropeak/MicroFileChooser.java
micropeak/MicroGraph.java
micropeak/MicroPeak.java
micropeak/MicroRaw.java
micropeak/MicroSave.java
micropeak/MicroStats.java
micropeak/MicroStatsTable.java
src/Makedefs.in [new file with mode: 0644]
src/Makefile
src/attiny/ao_async.c [new file with mode: 0644]
src/attiny/ao_async.h [new file with mode: 0644]
src/avr-demo/Makefile
src/avr/Makefile.defs [new file with mode: 0644]
src/cc1111/Makefile.cc1111
src/core/ao_flight.c
src/core/ao_log.h
src/core/ao_log_micro.c [new file with mode: 0644]
src/core/ao_log_micro.h [new file with mode: 0644]
src/core/ao_log_mini.c
src/core/ao_microflight.c [new file with mode: 0644]
src/core/ao_microkalman.c [new file with mode: 0644]
src/core/ao_report_micro.c [new file with mode: 0644]
src/core/ao_telemetry.c
src/easymini-v0.1/.gitignore [deleted file]
src/easymini-v0.1/Makefile [deleted file]
src/easymini-v0.1/ao_easymini.c [deleted file]
src/easymini-v0.1/ao_pins.h [deleted file]
src/easymini-v0.1/flash-loader/Makefile [deleted file]
src/easymini-v0.1/flash-loader/ao_pins.h [deleted file]
src/easymini-v1.0/.gitignore [new file with mode: 0644]
src/easymini-v1.0/Makefile [new file with mode: 0644]
src/easymini-v1.0/ao_easymini.c [new file with mode: 0644]
src/easymini-v1.0/ao_pins.h [new file with mode: 0644]
src/easymini-v1.0/flash-loader/Makefile [new file with mode: 0644]
src/easymini-v1.0/flash-loader/ao_pins.h [new file with mode: 0644]
src/lpc/Makefile-flash.defs
src/lpc/Makefile.defs
src/lpc/ao_arch_funcs.h
src/micropeak/Makefile
src/micropeak/ao_async.c [deleted file]
src/micropeak/ao_async.h [deleted file]
src/micropeak/ao_log_micro.c [deleted file]
src/micropeak/ao_log_micro.h [deleted file]
src/micropeak/ao_microflight.c [deleted file]
src/micropeak/ao_microkalman.c [deleted file]
src/micropeak/ao_micropeak.c [deleted file]
src/micropeak/ao_micropeak.h [deleted file]
src/micropeak/ao_report_tiny.c [deleted file]
src/nanopeak-v0.1/.gitignore [new file with mode: 0644]
src/nanopeak-v0.1/Makefile [new file with mode: 0644]
src/nanopeak-v0.1/ao_pins.h [new file with mode: 0644]
src/product/Makefile.teledongle
src/product/Makefile.telelaunch
src/product/Makefile.telemetrum
src/product/Makefile.telemini
src/product/Makefile.telenano
src/product/ao_flash_pins.h
src/product/ao_micropeak.c [new file with mode: 0644]
src/product/ao_micropeak.h [new file with mode: 0644]
src/spiradio-v0.1/Makefile
src/stm/Makefile-flash.defs
src/stm/Makefile.defs
src/stm/ao_arch_funcs.h
src/teleballoon-v1.1/Makefile
src/telebt-v1.0/Makefile
src/telefire-v0.1/Makefile
src/telefire-v0.2/Makefile
src/telegps-v0.3/ao_telegps.c
src/telemetrum-v2.0/ao_telemetrum.c
src/telemini-v2.0/Makefile
src/telemini-v2.0/ao_pins.h
src/telemini-v2.0/ao_telemini.c
src/telepyro-v0.1/Makefile
src/telescience-pwm/Makefile
src/telescience-v0.1/Makefile
src/teleshield-v0.1/Makefile
src/teleterra-v0.2/Makefile
src/tidongle/Makefile

index 0aea06f1cf22a242cf89489768070522caafdf15..0ed314375eb55ccc20957a145a82a606a78a0a58 100644 (file)
@@ -31,7 +31,7 @@ import android.os.Handler;
 //import android.os.Message;
 import android.util.Log;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosBluetooth extends AltosLink {
 
index e10982f7cc8873832c99fa21e2937c260deab64f..92287476b7dbf56fc654c408e5ddeb8c5ba41fd4 100644 (file)
@@ -49,7 +49,7 @@ import android.widget.Toast;
 import android.app.AlertDialog;
 import android.location.Location;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosDroid extends FragmentActivity {
        // Debugging
@@ -147,7 +147,7 @@ public class AltosDroid extends FragmentActivity {
                        case MSG_CRC_ERROR:
                        case MSG_UPDATE_AGE:
                                if (ad.saved_state != null) {
-                                       ad.mAgeView.setText(String.format("%d", (System.currentTimeMillis() - ad.saved_state.report_time + 500) / 1000));
+                                       ad.mAgeView.setText(String.format("%d", (System.currentTimeMillis() - ad.saved_state.received_time + 500) / 1000));
                                }
                                break;
                        }
@@ -243,11 +243,11 @@ public class AltosDroid extends FragmentActivity {
                }
 
                if (state != null) {
-                       mCallsignView.setText(state.data.callsign);
-                       mSerialView.setText(String.format("%d", state.data.serial));
-                       mFlightView.setText(String.format("%d", state.data.flight));
-                       mStateView.setText(state.data.state());
-                       mRSSIView.setText(String.format("%d", state.data.rssi));
+                       mCallsignView.setText(state.callsign);
+                       mSerialView.setText(String.format("%d", state.serial));
+                       mFlightView.setText(String.format("%d", state.flight));
+                       mStateView.setText(state.state_name());
+                       mRSSIView.setText(String.format("%d", state.rssi));
                }
 
                for (AltosDroidTab mTab : mTabs)
@@ -266,7 +266,7 @@ public class AltosDroid extends FragmentActivity {
 
        static String pos(double p, String pos, String neg) {
                String  h = pos;
-               if (p == AltosRecord.MISSING)
+               if (p == AltosLib.MISSING)
                        return "";
                if (p < 0) {
                        h = neg;
@@ -278,13 +278,13 @@ public class AltosDroid extends FragmentActivity {
        }
 
        static String number(String format, double value) {
-               if (value == AltosRecord.MISSING)
+               if (value == AltosLib.MISSING)
                        return "";
                return String.format(format, value);
        }
 
        static String integer(String format, int value) {
-               if (value == AltosRecord.MISSING)
+               if (value == AltosLib.MISSING)
                        return "";
                return String.format(format, value);
        }
index fd4b0768ac33f8d60e55946be7f0d6bb1ad39d09..59fef84279d6c2b6985f9d192e05fd69e894dd48 100644 (file)
@@ -23,7 +23,7 @@ import android.content.Context;
 import android.content.SharedPreferences;
 import android.os.Environment;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosDroidPreferences implements AltosPreferencesBackend {
        public final static String        NAME    = "org.altusmetrum.AltosDroid";
index 6ebb47f74e3b1ff9f3218f5655c5e1d43d6e2237..c652a1694f24b62df27f2ca829f0868ac79b0265 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import android.location.Location;
 
 public interface AltosDroidTab {
index b3dba62693714403f95f0b312beeb890f6e88b1a..f17cb82171e2f54e34eca4cd799677a95bdc1d2c 100644 (file)
-/*\r
- * Copyright © 2011 Keith Packard <keithp@keithp.com>\r
- * Copyright © 2012 Mike Beattie <mike@ethernal.org>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; version 2 of the License.\r
- *\r
- * This program is distributed in the hope that it will be useful, but\r
- * WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
- * General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.\r
- */\r
-\r
-package org.altusmetrum.AltosDroid;\r
-\r
-import android.speech.tts.TextToSpeech;\r
-import android.speech.tts.TextToSpeech.OnInitListener;\r
-\r
-import org.altusmetrum.altoslib_1.*;\r
-\r
-public class AltosVoice {\r
-\r
-       private TextToSpeech tts         = null;\r
-       private boolean      tts_enabled = false;\r
-\r
-       private IdleThread   idle_thread = null;\r
-\r
-       private AltosState   old_state   = null;\r
-\r
-       public AltosVoice(AltosDroid a) {\r
-\r
-               tts = new TextToSpeech(a, new OnInitListener() {\r
-                       public void onInit(int status) {\r
-                               if (status == TextToSpeech.SUCCESS) tts_enabled = true;\r
-                               if (tts_enabled) {\r
-                                       idle_thread = new IdleThread();\r
-                               }\r
-                       }\r
-               });\r
-\r
-       }\r
-\r
-       public void speak(String s) {\r
-               if (!tts_enabled) return;\r
-               tts.speak(s, TextToSpeech.QUEUE_ADD, null);\r
-       }\r
-\r
-       public void stop() {\r
-               if (tts != null) tts.shutdown();\r
-               if (idle_thread != null) {\r
-                       idle_thread.interrupt();\r
-                       idle_thread = null;\r
-               }\r
-       }\r
-\r
-       public void tell(AltosState state) {\r
-               if (!tts_enabled) return;\r
-\r
-               boolean spoke = false;\r
-               if (old_state == null || old_state.state != state.state) {\r
-                       speak(state.data.state());\r
-                       if ((old_state == null || old_state.state <= AltosLib.ao_flight_boost) &&\r
-                           state.state > AltosLib.ao_flight_boost) {\r
-                               speak(String.format("max speed: %d meters per second.", (int) (state.max_speed() + 0.5)));\r
-                               spoke = true;\r
-                       } else if ((old_state == null || old_state.state < AltosLib.ao_flight_drogue) &&\r
-                                  state.state >= AltosLib.ao_flight_drogue) {\r
-                               speak(String.format("max height: %d meters.", (int) (state.max_height + 0.5)));\r
-                               spoke = true;\r
-                       }\r
-               }\r
-               if (old_state == null || old_state.gps_ready != state.gps_ready) {\r
-                       if (state.gps_ready) {\r
-                               speak("GPS ready");\r
-                               spoke = true;\r
-                       } else if (old_state != null) {\r
-                               speak("GPS lost");\r
-                               spoke = true;\r
-                       }\r
-               }\r
-               old_state = state;\r
-               idle_thread.notice(state, spoke);\r
-       }\r
-\r
-\r
-       class IdleThread extends Thread {\r
-               boolean            started;\r
-               private AltosState state;\r
-               int                reported_landing;\r
-               int                report_interval;\r
-               long               report_time;\r
-\r
-               public synchronized void report(boolean last) {\r
-                       if (state == null)\r
-                               return;\r
-\r
-                       /* reset the landing count once we hear about a new flight */\r
-                       if (state.state < AltosLib.ao_flight_drogue)\r
-                               reported_landing = 0;\r
-\r
-                       /* Shut up once the rocket is on the ground */\r
-                       if (reported_landing > 2) {\r
-                               return;\r
-                       }\r
-\r
-                       /* If the rocket isn't on the pad, then report height */\r
-                       if (AltosLib.ao_flight_drogue <= state.state &&\r
-                           state.state < AltosLib.ao_flight_landed &&\r
-                           state.range >= 0)\r
-                       {\r
-                               speak(String.format("Height %d, bearing %s %d, elevation %d, range %d.\n",\r
-                                                   (int) (state.height + 0.5),\r
-                                       state.from_pad.bearing_words(\r
-                                             AltosGreatCircle.BEARING_VOICE),\r
-                                                   (int) (state.from_pad.bearing + 0.5),\r
-                                                   (int) (state.elevation + 0.5),\r
-                                                   (int) (state.range + 0.5)));\r
-                       } else if (state.state > AltosLib.ao_flight_pad) {\r
-                               speak(String.format("%d meters", (int) (state.height + 0.5)));\r
-                       } else {\r
-                               reported_landing = 0;\r
-                       }\r
-\r
-                       /* If the rocket is coming down, check to see if it has landed;\r
-                        * either we've got a landed report or we haven't heard from it in\r
-                        * a long time\r
-                        */\r
-                       if (state.state >= AltosLib.ao_flight_drogue &&\r
-                           (last ||\r
-                            System.currentTimeMillis() - state.report_time >= 15000 ||\r
-                            state.state == AltosLib.ao_flight_landed))\r
-                       {\r
-                               if (Math.abs(state.baro_speed) < 20 && state.height < 100)\r
-                                       speak("rocket landed safely");\r
-                               else\r
-                                       speak("rocket may have crashed");\r
-                               if (state.from_pad != null)\r
-                                       speak(String.format("Bearing %d degrees, range %d meters.",\r
-                                                           (int) (state.from_pad.bearing + 0.5),\r
-                                                           (int) (state.from_pad.distance + 0.5)));\r
-                               ++reported_landing;\r
-                       }\r
-               }\r
-\r
-               long now () {\r
-                       return System.currentTimeMillis();\r
-               }\r
-\r
-               void set_report_time() {\r
-                       report_time = now() + report_interval;\r
-               }\r
-\r
-               public void run () {\r
-                       try {\r
-                               for (;;) {\r
-                                       set_report_time();\r
-                                       for (;;) {\r
-                                               synchronized (this) {\r
-                                                       long sleep_time = report_time - now();\r
-                                                       if (sleep_time <= 0)\r
-                                                               break;\r
-                                                       wait(sleep_time);\r
-                                               }\r
-                                       }\r
-                                       report(false);\r
-                               }\r
-                       } catch (InterruptedException ie) {\r
-                       }\r
-               }\r
-\r
-               public synchronized void notice(AltosState new_state, boolean spoken) {\r
-                       AltosState old_state = state;\r
-                       state = new_state;\r
-                       if (!started && state.state > AltosLib.ao_flight_pad) {\r
-                               started = true;\r
-                               start();\r
-                       }\r
-\r
-                       if (state.state < AltosLib.ao_flight_drogue)\r
-                               report_interval = 10000;\r
-                       else\r
-                               report_interval = 20000;\r
-                       if (old_state != null && old_state.state != state.state) {\r
-                               report_time = now();\r
-                               this.notify();\r
-                       } else if (spoken)\r
-                               set_report_time();\r
-               }\r
-\r
-               public IdleThread() {\r
-                       state = null;\r
-                       reported_landing = 0;\r
-                       report_interval = 10000;\r
-               }\r
-       }\r
-\r
-}\r
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ * Copyright © 2012 Mike Beattie <mike@ethernal.org>
+ *
+ * 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 org.altusmetrum.AltosDroid;
+
+import android.speech.tts.TextToSpeech;
+import android.speech.tts.TextToSpeech.OnInitListener;
+
+import org.altusmetrum.altoslib_2.*;
+
+public class AltosVoice {
+
+       private TextToSpeech tts         = null;
+       private boolean      tts_enabled = false;
+
+       private IdleThread   idle_thread = null;
+
+       private AltosState   old_state   = null;
+
+       public AltosVoice(AltosDroid a) {
+
+               tts = new TextToSpeech(a, new OnInitListener() {
+                       public void onInit(int status) {
+                               if (status == TextToSpeech.SUCCESS) tts_enabled = true;
+                               if (tts_enabled) {
+                                       idle_thread = new IdleThread();
+                               }
+                       }
+               });
+
+       }
+
+       public void speak(String s) {
+               if (!tts_enabled) return;
+               tts.speak(s, TextToSpeech.QUEUE_ADD, null);
+       }
+
+       public void stop() {
+               if (tts != null) tts.shutdown();
+               if (idle_thread != null) {
+                       idle_thread.interrupt();
+                       idle_thread = null;
+               }
+       }
+
+       public void tell(AltosState state) {
+               if (!tts_enabled) return;
+
+               boolean spoke = false;
+               if (old_state == null || old_state.state != state.state) {
+                       speak(state.state_name());
+                       if ((old_state == null || old_state.state <= AltosLib.ao_flight_boost) &&
+                           state.state > AltosLib.ao_flight_boost) {
+                               speak(String.format("max speed: %d meters per second.", (int) (state.max_speed() + 0.5)));
+                               spoke = true;
+                       } else if ((old_state == null || old_state.state < AltosLib.ao_flight_drogue) &&
+                                  state.state >= AltosLib.ao_flight_drogue) {
+                               speak(String.format("max height: %d meters.", (int) (state.max_height() + 0.5)));
+                               spoke = true;
+                       }
+               }
+               if (old_state == null || old_state.gps_ready != state.gps_ready) {
+                       if (state.gps_ready) {
+                               speak("GPS ready");
+                               spoke = true;
+                       } else if (old_state != null) {
+                               speak("GPS lost");
+                               spoke = true;
+                       }
+               }
+               old_state = state;
+               idle_thread.notice(state, spoke);
+       }
+
+
+       class IdleThread extends Thread {
+               boolean            started;
+               private AltosState state;
+               int                reported_landing;
+               int                report_interval;
+               long               report_time;
+
+               public synchronized void report(boolean last) {
+                       if (state == null)
+                               return;
+
+                       /* reset the landing count once we hear about a new flight */
+                       if (state.state < AltosLib.ao_flight_drogue)
+                               reported_landing = 0;
+
+                       /* Shut up once the rocket is on the ground */
+                       if (reported_landing > 2) {
+                               return;
+                       }
+
+                       /* If the rocket isn't on the pad, then report height */
+                       if (AltosLib.ao_flight_drogue <= state.state &&
+                           state.state < AltosLib.ao_flight_landed &&
+                           state.range >= 0)
+                       {
+                               speak(String.format("Height %d, bearing %s %d, elevation %d, range %d.\n",
+                                                   (int) (state.height() + 0.5),
+                                       state.from_pad.bearing_words(
+                                             AltosGreatCircle.BEARING_VOICE),
+                                                   (int) (state.from_pad.bearing + 0.5),
+                                                   (int) (state.elevation + 0.5),
+                                                   (int) (state.range + 0.5)));
+                       } else if (state.state > AltosLib.ao_flight_pad) {
+                               speak(String.format("%d meters", (int) (state.height() + 0.5)));
+                       } else {
+                               reported_landing = 0;
+                       }
+
+                       /* If the rocket is coming down, check to see if it has landed;
+                        * either we've got a landed report or we haven't heard from it in
+                        * a long time
+                        */
+                       if (state.state >= AltosLib.ao_flight_drogue &&
+                           (last ||
+                            System.currentTimeMillis() - state.received_time >= 15000 ||
+                            state.state == AltosLib.ao_flight_landed))
+                       {
+                               if (Math.abs(state.speed()) < 20 && state.height() < 100)
+                                       speak("rocket landed safely");
+                               else
+                                       speak("rocket may have crashed");
+                               if (state.from_pad != null)
+                                       speak(String.format("Bearing %d degrees, range %d meters.",
+                                                           (int) (state.from_pad.bearing + 0.5),
+                                                           (int) (state.from_pad.distance + 0.5)));
+                               ++reported_landing;
+                       }
+               }
+
+               long now () {
+                       return System.currentTimeMillis();
+               }
+
+               void set_report_time() {
+                       report_time = now() + report_interval;
+               }
+
+               public void run () {
+                       try {
+                               for (;;) {
+                                       set_report_time();
+                                       for (;;) {
+                                               synchronized (this) {
+                                                       long sleep_time = report_time - now();
+                                                       if (sleep_time <= 0)
+                                                               break;
+                                                       wait(sleep_time);
+                                               }
+                                       }
+                                       report(false);
+                               }
+                       } catch (InterruptedException ie) {
+                       }
+               }
+
+               public synchronized void notice(AltosState new_state, boolean spoken) {
+                       AltosState old_state = state;
+                       state = new_state;
+                       if (!started && state.state > AltosLib.ao_flight_pad) {
+                               started = true;
+                               start();
+                       }
+
+                       if (state.state < AltosLib.ao_flight_drogue)
+                               report_interval = 10000;
+                       else
+                               report_interval = 20000;
+                       if (old_state != null && old_state.state != state.state) {
+                               report_time = now();
+                               this.notify();
+                       } else if (spoken)
+                               set_report_time();
+               }
+
+               public IdleThread() {
+                       state = null;
+                       reported_landing = 0;
+                       report_interval = 10000;
+               }
+       }
+
+}
index 17e4cf5b4c4497fc11b53bdaedd3311005d28e8f..2797fc5ee32f22d490aec5e21c5c7f5426dc1ab0 100644 (file)
-package org.altusmetrum.AltosDroid;\r
-\r
-       import java.lang.reflect.Array;\r
-       import java.lang.reflect.Field;\r
-       import java.util.HashMap;\r
-\r
-       public class Dumper {\r
-               private static Dumper instance = new Dumper();\r
-\r
-               protected static Dumper getInstance() {\r
-                       return instance;\r
-               }\r
-\r
-               class DumpContext {\r
-                       int maxDepth = 0;\r
-                       int maxArrayElements = 0;\r
-                       int callCount = 0;\r
-                       HashMap<String, String> ignoreList = new HashMap<String, String>();\r
-                       HashMap<Object, Integer> visited = new HashMap<Object, Integer>();\r
-               }\r
-\r
-               public static String dump(Object o) {\r
-                       return dump(o, 0, 0, null);\r
-               }\r
-\r
-               public static String dump(Object o, int maxDepth, int maxArrayElements, String[] ignoreList) {\r
-                       DumpContext ctx = Dumper.getInstance().new DumpContext();\r
-                       ctx.maxDepth = maxDepth;\r
-                       ctx.maxArrayElements = maxArrayElements;\r
-\r
-                       if (ignoreList != null) {\r
-                               for (int i = 0; i < Array.getLength(ignoreList); i++) {\r
-                                       int colonIdx = ignoreList[i].indexOf(':');\r
-                                       if (colonIdx == -1)\r
-                                               ignoreList[i] = ignoreList[i] + ":";\r
-                                       ctx.ignoreList.put(ignoreList[i], ignoreList[i]);\r
-                               }\r
-                       }\r
-\r
-                       return dump(o, ctx);\r
-               }\r
-\r
-               protected static String dump(Object o, DumpContext ctx) {\r
-                       if (o == null) {\r
-                               return "<null>";\r
-                       }\r
-\r
-                       ctx.callCount++;\r
-                       StringBuffer tabs = new StringBuffer();\r
-                       for (int k = 0; k < ctx.callCount; k++) {\r
-                               tabs.append("\t");\r
-                       }\r
-                       StringBuffer buffer = new StringBuffer();\r
-                       @SuppressWarnings("rawtypes")\r
-                       Class oClass = o.getClass();\r
-\r
-                       String oSimpleName = getSimpleNameWithoutArrayQualifier(oClass);\r
-\r
-                       if (ctx.ignoreList.get(oSimpleName + ":") != null)\r
-                               return "<Ignored>";\r
-\r
-                       if (oClass.isArray()) {\r
-                               buffer.append("\n");\r
-                               buffer.append(tabs.toString().substring(1));\r
-                               buffer.append("[\n");\r
-                               int rowCount = ctx.maxArrayElements == 0 ? Array.getLength(o) : Math.min(ctx.maxArrayElements, Array.getLength(o));\r
-                               for (int i = 0; i < rowCount; i++) {\r
-                                       buffer.append(tabs.toString());\r
-                                       try {\r
-                                               Object value = Array.get(o, i);\r
-                                               buffer.append(dumpValue(value, ctx));\r
-                                       } catch (Exception e) {\r
-                                               buffer.append(e.getMessage());\r
-                                       }\r
-                                       if (i < Array.getLength(o) - 1)\r
-                                               buffer.append(",");\r
-                                       buffer.append("\n");\r
-                               }\r
-                               if (rowCount < Array.getLength(o)) {\r
-                                       buffer.append(tabs.toString());\r
-                                       buffer.append(Array.getLength(o) - rowCount + " more array elements...");\r
-                                       buffer.append("\n");\r
-                               }\r
-                               buffer.append(tabs.toString().substring(1));\r
-                               buffer.append("]");\r
-                       } else {\r
-                               buffer.append("\n");\r
-                               buffer.append(tabs.toString().substring(1));\r
-                               buffer.append("{\n");\r
-                               buffer.append(tabs.toString());\r
-                               buffer.append("hashCode: " + o.hashCode());\r
-                               buffer.append("\n");\r
-                               while (oClass != null && oClass != Object.class) {\r
-                                       Field[] fields = oClass.getDeclaredFields();\r
-\r
-                                       if (ctx.ignoreList.get(oClass.getSimpleName()) == null) {\r
-                                               if (oClass != o.getClass()) {\r
-                                                       buffer.append(tabs.toString().substring(1));\r
-                                                       buffer.append("  Inherited from superclass " + oSimpleName + ":\n");\r
-                                               }\r
-\r
-                                               for (int i = 0; i < fields.length; i++) {\r
-\r
-                                                       String fSimpleName = getSimpleNameWithoutArrayQualifier(fields[i].getType());\r
-                                                       String fName = fields[i].getName();\r
-\r
-                                                       fields[i].setAccessible(true);\r
-                                                       buffer.append(tabs.toString());\r
-                                                       buffer.append(fName + "(" + fSimpleName + ")");\r
-                                                       buffer.append("=");\r
-\r
-                                                       if (ctx.ignoreList.get(":" + fName) == null &&\r
-                                                               ctx.ignoreList.get(fSimpleName + ":" + fName) == null &&\r
-                                                               ctx.ignoreList.get(fSimpleName + ":") == null) {\r
-\r
-                                                               try {\r
-                                                                       Object value = fields[i].get(o);\r
-                                                                       buffer.append(dumpValue(value, ctx));\r
-                                                               } catch (Exception e) {\r
-                                                                       buffer.append(e.getMessage());\r
-                                                               }\r
-                                                               buffer.append("\n");\r
-                                                       } else {\r
-                                                               buffer.append("<Ignored>");\r
-                                                               buffer.append("\n");\r
-                                                       }\r
-                                               }\r
-                                               oClass = oClass.getSuperclass();\r
-                                               oSimpleName = oClass.getSimpleName();\r
-                                       } else {\r
-                                               oClass = null;\r
-                                               oSimpleName = "";\r
-                                       }\r
-                               }\r
-                               buffer.append(tabs.toString().substring(1));\r
-                               buffer.append("}");\r
-                       }\r
-                       ctx.callCount--;\r
-                       return buffer.toString();\r
-               }\r
-\r
-               protected static String dumpValue(Object value, DumpContext ctx) {\r
-                       if (value == null) {\r
-                               return "<null>";\r
-                       }\r
-                       if (value.getClass().isPrimitive() ||\r
-                               value.getClass() == java.lang.Short.class ||\r
-                               value.getClass() == java.lang.Long.class ||\r
-                               value.getClass() == java.lang.String.class ||\r
-                               value.getClass() == java.lang.Integer.class ||\r
-                               value.getClass() == java.lang.Float.class ||\r
-                               value.getClass() == java.lang.Byte.class ||\r
-                               value.getClass() == java.lang.Character.class ||\r
-                               value.getClass() == java.lang.Double.class ||\r
-                               value.getClass() == java.lang.Boolean.class) {\r
-\r
-                               return value.toString();\r
-\r
-                       } else {\r
-\r
-                               Integer visitedIndex = ctx.visited.get(value);\r
-                               if (visitedIndex == null) {\r
-                                       ctx.visited.put(value, ctx.callCount);\r
-                                       if (ctx.maxDepth == 0 || ctx.callCount < ctx.maxDepth) {\r
-                                               return dump(value, ctx);\r
-                                       } else {\r
-                                               return "<Reached max recursion depth>";\r
-                                       }\r
-                               } else {\r
-                                       return "<Previously visited - see hashCode " + value.hashCode() + ">";\r
-                               }\r
-                       }\r
-               }\r
-\r
-\r
-               private static String getSimpleNameWithoutArrayQualifier(@SuppressWarnings("rawtypes") Class clazz) {\r
-                       String simpleName = clazz.getSimpleName();\r
-                       int indexOfBracket = simpleName.indexOf('['); \r
-                       if (indexOfBracket != -1)\r
-                               return simpleName.substring(0, indexOfBracket);\r
-                       return simpleName;\r
-               }\r
-}\r
+package org.altusmetrum.AltosDroid;
+
+       import java.lang.reflect.Array;
+       import java.lang.reflect.Field;
+       import java.util.HashMap;
+
+       public class Dumper {
+               private static Dumper instance = new Dumper();
+
+               protected static Dumper getInstance() {
+                       return instance;
+               }
+
+               class DumpContext {
+                       int maxDepth = 0;
+                       int maxArrayElements = 0;
+                       int callCount = 0;
+                       HashMap<String, String> ignoreList = new HashMap<String, String>();
+                       HashMap<Object, Integer> visited = new HashMap<Object, Integer>();
+               }
+
+               public static String dump(Object o) {
+                       return dump(o, 0, 0, null);
+               }
+
+               public static String dump(Object o, int maxDepth, int maxArrayElements, String[] ignoreList) {
+                       DumpContext ctx = Dumper.getInstance().new DumpContext();
+                       ctx.maxDepth = maxDepth;
+                       ctx.maxArrayElements = maxArrayElements;
+
+                       if (ignoreList != null) {
+                               for (int i = 0; i < Array.getLength(ignoreList); i++) {
+                                       int colonIdx = ignoreList[i].indexOf(':');
+                                       if (colonIdx == -1)
+                                               ignoreList[i] = ignoreList[i] + ":";
+                                       ctx.ignoreList.put(ignoreList[i], ignoreList[i]);
+                               }
+                       }
+
+                       return dump(o, ctx);
+               }
+
+               protected static String dump(Object o, DumpContext ctx) {
+                       if (o == null) {
+                               return "<null>";
+                       }
+
+                       ctx.callCount++;
+                       StringBuffer tabs = new StringBuffer();
+                       for (int k = 0; k < ctx.callCount; k++) {
+                               tabs.append("\t");
+                       }
+                       StringBuffer buffer = new StringBuffer();
+                       @SuppressWarnings("rawtypes")
+                       Class oClass = o.getClass();
+
+                       String oSimpleName = getSimpleNameWithoutArrayQualifier(oClass);
+
+                       if (ctx.ignoreList.get(oSimpleName + ":") != null)
+                               return "<Ignored>";
+
+                       if (oClass.isArray()) {
+                               buffer.append("\n");
+                               buffer.append(tabs.toString().substring(1));
+                               buffer.append("[\n");
+                               int rowCount = ctx.maxArrayElements == 0 ? Array.getLength(o) : Math.min(ctx.maxArrayElements, Array.getLength(o));
+                               for (int i = 0; i < rowCount; i++) {
+                                       buffer.append(tabs.toString());
+                                       try {
+                                               Object value = Array.get(o, i);
+                                               buffer.append(dumpValue(value, ctx));
+                                       } catch (Exception e) {
+                                               buffer.append(e.getMessage());
+                                       }
+                                       if (i < Array.getLength(o) - 1)
+                                               buffer.append(",");
+                                       buffer.append("\n");
+                               }
+                               if (rowCount < Array.getLength(o)) {
+                                       buffer.append(tabs.toString());
+                                       buffer.append(Array.getLength(o) - rowCount + " more array elements...");
+                                       buffer.append("\n");
+                               }
+                               buffer.append(tabs.toString().substring(1));
+                               buffer.append("]");
+                       } else {
+                               buffer.append("\n");
+                               buffer.append(tabs.toString().substring(1));
+                               buffer.append("{\n");
+                               buffer.append(tabs.toString());
+                               buffer.append("hashCode: " + o.hashCode());
+                               buffer.append("\n");
+                               while (oClass != null && oClass != Object.class) {
+                                       Field[] fields = oClass.getDeclaredFields();
+
+                                       if (ctx.ignoreList.get(oClass.getSimpleName()) == null) {
+                                               if (oClass != o.getClass()) {
+                                                       buffer.append(tabs.toString().substring(1));
+                                                       buffer.append("  Inherited from superclass " + oSimpleName + ":\n");
+                                               }
+
+                                               for (int i = 0; i < fields.length; i++) {
+
+                                                       String fSimpleName = getSimpleNameWithoutArrayQualifier(fields[i].getType());
+                                                       String fName = fields[i].getName();
+
+                                                       fields[i].setAccessible(true);
+                                                       buffer.append(tabs.toString());
+                                                       buffer.append(fName + "(" + fSimpleName + ")");
+                                                       buffer.append("=");
+
+                                                       if (ctx.ignoreList.get(":" + fName) == null &&
+                                                               ctx.ignoreList.get(fSimpleName + ":" + fName) == null &&
+                                                               ctx.ignoreList.get(fSimpleName + ":") == null) {
+
+                                                               try {
+                                                                       Object value = fields[i].get(o);
+                                                                       buffer.append(dumpValue(value, ctx));
+                                                               } catch (Exception e) {
+                                                                       buffer.append(e.getMessage());
+                                                               }
+                                                               buffer.append("\n");
+                                                       } else {
+                                                               buffer.append("<Ignored>");
+                                                               buffer.append("\n");
+                                                       }
+                                               }
+                                               oClass = oClass.getSuperclass();
+                                               oSimpleName = oClass.getSimpleName();
+                                       } else {
+                                               oClass = null;
+                                               oSimpleName = "";
+                                       }
+                               }
+                               buffer.append(tabs.toString().substring(1));
+                               buffer.append("}");
+                       }
+                       ctx.callCount--;
+                       return buffer.toString();
+               }
+
+               protected static String dumpValue(Object value, DumpContext ctx) {
+                       if (value == null) {
+                               return "<null>";
+                       }
+                       if (value.getClass().isPrimitive() ||
+                               value.getClass() == java.lang.Short.class ||
+                               value.getClass() == java.lang.Long.class ||
+                               value.getClass() == java.lang.String.class ||
+                               value.getClass() == java.lang.Integer.class ||
+                               value.getClass() == java.lang.Float.class ||
+                               value.getClass() == java.lang.Byte.class ||
+                               value.getClass() == java.lang.Character.class ||
+                               value.getClass() == java.lang.Double.class ||
+                               value.getClass() == java.lang.Boolean.class) {
+
+                               return value.toString();
+
+                       } else {
+
+                               Integer visitedIndex = ctx.visited.get(value);
+                               if (visitedIndex == null) {
+                                       ctx.visited.put(value, ctx.callCount);
+                                       if (ctx.maxDepth == 0 || ctx.callCount < ctx.maxDepth) {
+                                               return dump(value, ctx);
+                                       } else {
+                                               return "<Reached max recursion depth>";
+                                       }
+                               } else {
+                                       return "<Previously visited - see hashCode " + value.hashCode() + ">";
+                               }
+                       }
+               }
+
+
+               private static String getSimpleNameWithoutArrayQualifier(@SuppressWarnings("rawtypes") Class clazz) {
+                       String simpleName = clazz.getSimpleName();
+                       int indexOfBracket = simpleName.indexOf('['); 
+                       if (indexOfBracket != -1)
+                               return simpleName.substring(0, indexOfBracket);
+                       return simpleName;
+               }
+}
index 0e141ae47e942e2983333a1ef526c79b67b13c2d..3eaf12dbd1f53ca0124794c5ebb52990d1136132 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import android.app.Activity;
 import android.os.Bundle;
@@ -87,12 +87,12 @@ public class TabAscent extends Fragment implements AltosDroidTab {
 
        public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
                if (state != null) {
-                       mHeightView.setText(AltosDroid.number("%6.0f m", state.height));
-                       mMaxHeightView.setText(AltosDroid.number("%6.0f m", state.max_height));
+                       mHeightView.setText(AltosDroid.number("%6.0f m", state.height()));
+                       mMaxHeightView.setText(AltosDroid.number("%6.0f m", state.max_height()));
                        mSpeedView.setText(AltosDroid.number("%6.0f m/s", state.speed()));
                        mMaxSpeedView.setText(AltosDroid.number("%6.0f m/s", state.max_speed()));
-                       mAccelView.setText(AltosDroid.number("%6.0f m/s²", state.acceleration));
-                       mMaxAccelView.setText(AltosDroid.number("%6.0f m/s²", state.max_acceleration));
+                       mAccelView.setText(AltosDroid.number("%6.0f m/s²", state.acceleration()));
+                       mMaxAccelView.setText(AltosDroid.number("%6.0f m/s²", state.max_acceleration()));
 
                        if (state.gps != null) {
                                mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
@@ -102,11 +102,11 @@ public class TabAscent extends Fragment implements AltosDroidTab {
                                mLongitudeView.setText("");
                        }
 
-                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense));
-                       mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING);
+                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.apogee_voltage));
+                       mApogeeLights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
 
-                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense));
-                       mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING);
+                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_voltage));
+                       mMainLights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
                }
        }
 }
index 09e7169b229ff1c126405ac9f8fe8a3fdbedabc6..e4a954ca1603e7fc38d9ffd46558fe597463f082 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import android.app.Activity;
 import android.os.Bundle;
@@ -92,7 +92,7 @@ public class TabDescent extends Fragment implements AltosDroidTab {
        public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
                if (state != null) {
                        mSpeedView.setText(AltosDroid.number("%6.0f m/s", state.speed()));
-                       mHeightView.setText(AltosDroid.number("%6.0f m", state.height));
+                       mHeightView.setText(AltosDroid.number("%6.0f m", state.height()));
                        if (from_receiver != null) {
                                mElevationView.setText(AltosDroid.number("%3.0f°", from_receiver.elevation));
                                mRangeView.setText(AltosDroid.number("%6.0f m", from_receiver.range));
@@ -111,11 +111,11 @@ public class TabDescent extends Fragment implements AltosDroidTab {
                                mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
                        }
 
-                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense));
-                       mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING);
+                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.apogee_voltage));
+                       mApogeeLights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
 
-                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense));
-                       mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING);
+                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_voltage));
+                       mMainLights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
                }
        }
 
index f42b46b55520d7fbf8551e676ddda47dfebafe41..40399f2aed0df4d0fe31ad6e5fec78c0fb814d45 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import android.app.Activity;
 import android.os.Bundle;
@@ -89,8 +89,8 @@ public class TabLanded extends Fragment implements AltosDroidTab {
                }
               
                if (state != null) {
-                       mMaxHeightView.setText(String.format("%6.0f m", state.max_height));
-                       mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration));
+                       mMaxHeightView.setText(String.format("%6.0f m", state.max_height()));
+                       mMaxAccelView.setText(String.format("%6.0f m/s²", state.max_acceleration()));
                        mMaxSpeedView.setText(String.format("%6.0f m/s", state.max_speed()));
                }
        }
index d831f1172761cfabf52a5b404a8b1ba585d200c9..a4e224aad486ac6f3216f728868c5ce3b00d53c0 100644 (file)
@@ -19,7 +19,7 @@ package org.altusmetrum.AltosDroid;
 
 import java.util.Arrays;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import com.google.android.gms.maps.CameraUpdateFactory;
 import com.google.android.gms.maps.GoogleMap;
index 066c1353ef792a87896a18a3522d9623725a0e2d..2c6732e52e9765ec34df56a3f1b1ffeeaff31971 100644 (file)
@@ -17,7 +17,7 @@
 
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import android.app.Activity;
 import android.os.Bundle;
@@ -103,26 +103,26 @@ public class TabPad extends Fragment implements AltosDroidTab {
 
        public void update_ui(AltosState state, AltosGreatCircle from_receiver, Location receiver) {
                if (state != null) {
-                       mBatteryVoltageView.setText(AltosDroid.number("%4.2f V", state.battery));
-                       mBatteryLights.set(state.battery > 3.7, state.battery == AltosRecord.MISSING);
+                       mBatteryVoltageView.setText(AltosDroid.number("%4.2f V", state.battery_voltage));
+                       mBatteryLights.set(state.battery_voltage > 3.7, state.battery_voltage == AltosLib.MISSING);
 
-                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.drogue_sense));
-                       mApogeeLights.set(state.drogue_sense > 3.2, state.drogue_sense == AltosRecord.MISSING);
+                       mApogeeVoltageView.setText(AltosDroid.number("%4.2f V", state.apogee_voltage));
+                       mApogeeLights.set(state.apogee_voltage > 3.2, state.apogee_voltage == AltosLib.MISSING);
 
-                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_sense));
-                       mMainLights.set(state.main_sense > 3.2, state.main_sense == AltosRecord.MISSING);
+                       mMainVoltageView.setText(AltosDroid.number("%4.2f V", state.main_voltage));
+                       mMainLights.set(state.main_voltage > 3.2, state.main_voltage == AltosLib.MISSING);
 
-                       if (state.data.flight != 0) {
-                               if (state.data.state <= AltosLib.ao_flight_pad)
+                       if (state.flight != 0) {
+                               if (state.state <= AltosLib.ao_flight_pad)
                                        mDataLoggingView.setText("Ready to record");
-                               else if (state.data.state < AltosLib.ao_flight_landed)
+                               else if (state.state < AltosLib.ao_flight_landed)
                                        mDataLoggingView.setText("Recording data");
                                else
                                        mDataLoggingView.setText("Recorded data");
                        } else {
                                mDataLoggingView.setText("Storage full");
                        }
-                       mDataLoggingLights.set(state.data.flight != 0, state.data.flight == AltosRecord.MISSING);
+                       mDataLoggingLights.set(state.flight != 0, state.flight == AltosLib.MISSING);
 
                        if (state.gps != null) {
                                mGPSLockedView.setText(AltosDroid.integer("%4d sats", state.gps.nsat));
index 3ece04ac3e8596b0ef1f64b40f430e5280c13d74..4d793413a8983e3403775b1e6217d03b034c0435 100644 (file)
@@ -1,6 +1,6 @@
 package org.altusmetrum.AltosDroid;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import android.content.BroadcastReceiver;
 import android.content.Context;
index 716ec5894c9df42c5e0a975591ba8464c42e91bd..45604284e0767a405de80b2f5d6b8c66d77cb24a 100644 (file)
@@ -1,94 +1,95 @@
-/*\r
- * Copyright © 2011 Keith Packard <keithp@keithp.com>\r
- * Copyright © 2012 Mike Beattie <mike@ethernal.org>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; version 2 of the License.\r
- *\r
- * This program is distributed in the hope that it will be useful, but\r
- * WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
- * General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.\r
- */\r
-\r
-\r
-package org.altusmetrum.AltosDroid;\r
-\r
-import java.text.*;\r
-import java.io.*;\r
-import java.util.concurrent.*;\r
-import android.util.Log;\r
-import android.os.Handler;\r
-\r
-import org.altusmetrum.altoslib_1.*;\r
-\r
-\r
-public class TelemetryReader extends Thread {\r
-\r
-       private static final String TAG = "TelemetryReader";\r
-\r
-       int         crc_errors;\r
-\r
-       Handler     handler;\r
-\r
-       AltosLink   link;\r
-       AltosRecord previous;\r
-\r
-       LinkedBlockingQueue<AltosLine> telem;\r
-\r
-       public AltosRecord read() throws ParseException, AltosCRCException, InterruptedException, IOException {\r
-               AltosLine l = telem.take();\r
-               if (l.line == null)\r
-                       throw new IOException("IO error");\r
-               AltosRecord     next = AltosTelemetry.parse(l.line, previous);\r
-               previous = next;\r
-               return next;\r
-       }\r
-\r
-       public void close() {\r
-               previous = null;\r
-               link.remove_monitor(telem);\r
-               link = null;\r
-               telem.clear();\r
-               telem = null;\r
-       }\r
-\r
-       public void run() {\r
-               AltosState  state = null;\r
-\r
-               try {\r
-                       for (;;) {\r
-                               try {\r
-                                       AltosRecord record = read();\r
-                                       if (record == null)\r
-                                               break;\r
-                                       state = new AltosState(record, state);\r
-                                       handler.obtainMessage(TelemetryService.MSG_TELEMETRY, state).sendToTarget();\r
-                               } catch (ParseException pp) {\r
-                                       Log.e(TAG, String.format("Parse error: %d \"%s\"", pp.getErrorOffset(), pp.getMessage()));\r
-                               } catch (AltosCRCException ce) {\r
-                                       ++crc_errors;\r
-                                       handler.obtainMessage(TelemetryService.MSG_CRC_ERROR, new Integer(crc_errors)).sendToTarget();\r
-                               }\r
-                       }\r
-               } catch (InterruptedException ee) {\r
-               } catch (IOException ie) {\r
-               } finally {\r
-                       close();\r
-               }\r
-       }\r
-\r
-       public TelemetryReader (AltosLink in_link, Handler in_handler) {\r
-               link    = in_link;\r
-               handler = in_handler;\r
-\r
-               previous = null;\r
-               telem = new LinkedBlockingQueue<AltosLine>();\r
-               link.add_monitor(telem);\r
-       }\r
-}\r
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ * Copyright © 2012 Mike Beattie <mike@ethernal.org>
+ *
+ * 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 org.altusmetrum.AltosDroid;
+
+import java.text.*;
+import java.io.*;
+import java.util.concurrent.*;
+import android.util.Log;
+import android.os.Handler;
+
+import org.altusmetrum.altoslib_2.*;
+
+
+public class TelemetryReader extends Thread {
+
+       private static final String TAG = "TelemetryReader";
+
+       int         crc_errors;
+
+       Handler     handler;
+
+       AltosLink   link;
+       AltosState  state = null;
+
+       LinkedBlockingQueue<AltosLine> telemQueue;
+
+       public AltosState read() throws ParseException, AltosCRCException, InterruptedException, IOException {
+               AltosLine l = telemQueue.take();
+               if (l.line == null)
+                       throw new IOException("IO error");
+               AltosTelemetry telem = AltosTelemetryLegacy.parse(l.line);
+               if (state == null)
+                       state = new AltosState();
+               else
+                       state = state.clone();
+               telem.update_state(state);
+               return state;
+       }
+
+       public void close() {
+               state = null;
+               link.remove_monitor(telemQueue);
+               link = null;
+               telemQueue.clear();
+               telemQueue = null;
+       }
+
+       public void run() {
+               AltosState  state = null;
+
+               try {
+                       for (;;) {
+                               try {
+                                       state = read();
+                                       handler.obtainMessage(TelemetryService.MSG_TELEMETRY, state).sendToTarget();
+                               } catch (ParseException pp) {
+                                       Log.e(TAG, String.format("Parse error: %d \"%s\"", pp.getErrorOffset(), pp.getMessage()));
+                               } catch (AltosCRCException ce) {
+                                       ++crc_errors;
+                                       handler.obtainMessage(TelemetryService.MSG_CRC_ERROR, new Integer(crc_errors)).sendToTarget();
+                               }
+                       }
+               } catch (InterruptedException ee) {
+               } catch (IOException ie) {
+               } finally {
+                       close();
+               }
+       }
+
+       public TelemetryReader (AltosLink in_link, Handler in_handler) {
+               link    = in_link;
+               handler = in_handler;
+
+               state = null;
+               telemQueue = new LinkedBlockingQueue<AltosLine>();
+               link.add_monitor(telemQueue);
+       }
+}
index 940ad792df17ff35e6532123d2450ad41481782b..76efa74968ca557627ce2cf5495e7dbecd5b4645 100644 (file)
@@ -44,7 +44,7 @@ import android.location.LocationManager;
 import android.location.LocationListener;
 import android.location.Criteria;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 
 public class TelemetryService extends Service implements LocationListener {
index d02b32385f348e1dfdf28eabb5afd1219dbcf07b..08eba359c9f6bfb4622be0344d2b957390c8aead 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosAccel extends AltosUnits {
 
index 76e79add1255c1cb9157564c59ae7851d15a5864..be2ec4fec48e0bd00e311ea7b6c410718e07c4ac 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosCRCException extends Exception {
        public int rssi;
diff --git a/altoslib/AltosCompanion.java b/altoslib/AltosCompanion.java
new file mode 100644 (file)
index 0000000..57bb21a
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+public class AltosCompanion {
+       public final static int board_id_telescience = 0x0a;
+       public final static int MAX_CHANNELS = 12;
+
+       public int      tick;
+       public int      board_id;
+       public int      update_period;
+       public int      channels;
+       public int[]    companion_data;
+
+       public AltosCompanion(int in_channels) {
+               channels = in_channels;
+               if (channels < 0)
+                       channels = 0;
+               if (channels > MAX_CHANNELS)
+                       channels = MAX_CHANNELS;
+               companion_data = new int[channels];
+       }
+}
index 2ca5a7a56f74093227285d72176f62b51307e304..d92f42c3aeb9b43006784f9375303e4d7f3fe2e3 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.util.*;
 import java.text.*;
index 027d10f4dfb92be98d04d41a5a161b2d48c64dbb..fd5584c2422b0552bc4dfa4086bf288354dd69c3 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public interface AltosConfigValues {
        /* set and get all of the dialog values */
index 8cd478e2bd5ff6820bc0e5432deb1d8ad70a4082..760d9eb98c273a0501f15aad1e09b4dc6a6dca67 100644 (file)
@@ -18,7 +18,7 @@
 /*
  * Sensor data conversion functions
  */
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosConvert {
        /*
@@ -190,6 +190,46 @@ public class AltosConvert {
                return ignite / 32767 * 15.0;
        }
 
+       public static double
+       barometer_to_pressure(double count)
+       {
+               return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
+       }
+
+       static double
+       thermometer_to_temperature(double thermo)
+       {
+               return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
+       }
+
+       static double mega_adc(int raw) {
+               return raw / 4095.0;
+       }
+
+       static public double mega_battery_voltage(int v_batt) {
+               if (v_batt != AltosLib.MISSING)
+                       return 3.3 * mega_adc(v_batt) * (15.0 + 27.0) / 27.0;
+               return AltosLib.MISSING;
+       }
+
+       static double mega_pyro_voltage(int raw) {
+               if (raw != AltosLib.MISSING)
+                       return 3.3 * mega_adc(raw) * (100.0 + 27.0) / 27.0;
+               return AltosLib.MISSING;
+       }
+
+       static double tele_mini_voltage(int sensor) {
+               double  supply = 3.3;
+
+               return sensor / 32767.0 * supply * 127/27;
+       }
+
+       static double easy_mini_voltage(int sensor) {
+               double  supply = 3.0;
+
+               return sensor / 32767.0 * supply * 127/27;
+       }
+
        public static double radio_to_frequency(int freq, int setting, int cal, int channel) {
                double  f;
 
index 4d8e3ae7cfa994bb7718ac41bbf0691a98111c76..76c13d57a399187079d9d4f0820eaedf4a36fa22 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 
index 25028ac79a2ae255717c901ef41f0460dbdca71c..562571657370a81be5a4d28fb620985e6995e06d 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosDistance extends AltosUnits {
 
diff --git a/altoslib/AltosEeprom.java b/altoslib/AltosEeprom.java
new file mode 100644 (file)
index 0000000..dd5993c
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+
+public abstract class AltosEeprom implements AltosStateUpdate {
+       public int      cmd;
+       public int      tick;
+       public int      data8[];
+       public boolean  valid;
+
+       public int data8(int i) {
+               return data8[i];
+       }
+
+       public int data16(int i) {
+               return ((data8[i] | (data8[i+1] << 8)) << 16) >> 16;
+       }
+
+       public int data24(int i) {
+               return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16);
+       }
+
+       public int data32(int i) {
+               return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16) | (data8[i+3] << 24);
+       }
+
+       public final static int header_length = 4;
+
+       public abstract int record_length();
+
+       public void update_state(AltosState state) {
+               if (cmd == AltosLib.AO_LOG_FLIGHT)
+                       state.set_boost_tick(tick);
+               else
+                       state.set_tick(tick);
+       }
+
+       public void write(PrintStream out) {
+               out.printf("%c %04x", cmd, tick);
+               if (data8 != null) {
+                       for (int i = 0; i < data8.length; i++)
+                               out.printf (" %02x", data8[i]);
+               }
+               out.printf ("\n");
+       }
+
+       public String string() {
+               String  s;
+
+               s = String.format("%c %04x", cmd, tick);
+               if (data8 != null) {
+                       for (int i = 0; i < data8.length; i++) {
+                               String  d = String.format(" %02x", data8[i]);
+                               s = s.concat(d);
+                       }
+               }
+               s = s.concat("\n");
+               return s;
+       }
+
+       void parse_chunk(AltosEepromChunk chunk, int start) throws ParseException {
+               cmd = chunk.data(start);
+
+               int data_length = record_length() - header_length;
+
+               valid = !chunk.erased(start, record_length());
+               if (valid) {
+                       if (AltosConvert.checksum(chunk.data, start, record_length()) != 0)
+                               throw new ParseException(String.format("invalid checksum at 0x%x",
+                                                                      chunk.address + start), 0);
+               } else {
+                       cmd = AltosLib.AO_LOG_INVALID;
+               }
+
+               tick = chunk.data16(start+2);
+
+               data8 = new int[data_length];
+               for (int i = 0; i < data_length; i++)
+                       data8[i] = chunk.data(start + header_length + i);
+       }
+
+       void parse_string(String line) {
+               valid = false;
+               tick = 0;
+               cmd = AltosLib.AO_LOG_INVALID;
+
+               int data_length = record_length() - header_length;
+
+               if (line == null)
+                       return;
+               try {
+                       String[] tokens = line.split("\\s+");
+
+                       if (tokens[0].length() == 1) {
+                               if (tokens.length == 2 + data_length) {
+                                       cmd = tokens[0].codePointAt(0);
+                                       tick = Integer.parseInt(tokens[1],16);
+                                       valid = true;
+                                       data8 = new int[data_length];
+
+                                       for (int i = 0; i < data_length; i++)
+                                               data8[i] = Integer.parseInt(tokens[2 + i],16);
+                               }
+                       }
+               } catch (NumberFormatException ne) {
+               }
+       }
+}
index b1bba3bb56d67154c8cc49f23e3ab76c6cd84c02..48d29e1b603e9a9d8fdf558602e226d2495d7e3a 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.text.*;
 import java.util.concurrent.*;
@@ -62,6 +62,35 @@ public class AltosEepromChunk {
                return true;
        }
 
+       public AltosEeprom eeprom(int offset, int log_format, AltosState state) {
+               AltosEeprom     eeprom = null;
+               try {
+                       switch (log_format) {
+                       case AltosLib.AO_LOG_FORMAT_FULL:
+                               eeprom = new AltosEepromTM(this, offset);
+                               break;
+                       case AltosLib.AO_LOG_FORMAT_TINY:
+                               eeprom = new AltosEepromTm(this, offset, state);
+                               break;
+                       case AltosLib.AO_LOG_FORMAT_TELEMETRY:
+                       case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
+                               break;
+                       case AltosLib.AO_LOG_FORMAT_TELEMEGA:
+                               eeprom = new AltosEepromMega(this, offset);
+                               break;
+                       case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
+                               eeprom = new AltosEepromMetrum2(this, offset);
+                               break;
+                       case AltosLib.AO_LOG_FORMAT_TELEMINI:
+                       case AltosLib.AO_LOG_FORMAT_EASYMINI:
+                               eeprom = new AltosEepromMini(this, offset);
+                               break;
+                       }
+               } catch (ParseException e) {
+               }
+               return eeprom;
+       }
+
        public AltosEepromChunk(AltosLink link, int block, boolean flush)
                throws TimeoutException, InterruptedException {
 
diff --git a/altoslib/AltosEepromFile.java b/altoslib/AltosEepromFile.java
new file mode 100644 (file)
index 0000000..60ab257
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+
+class AltosEepromIterator implements Iterator<AltosState> {
+       AltosState              state;
+       Iterator<AltosEeprom>   body;
+       AltosEeprom             next;
+       boolean                 seen;
+
+       public boolean hasNext() {
+               return !seen || body.hasNext();
+       }
+
+       public AltosState next() {
+               if (seen) {
+                       AltosState      n = state.clone();
+                       AltosEeprom     e = body.next();
+
+                       e.update_state(n);
+                       state = n;
+               }
+               seen = true;
+               return state;
+       }
+
+       public void remove () {
+       }
+
+       public AltosEepromIterator(AltosState start, Iterator<AltosEeprom> body) {
+               this.state = start;
+               this.body = body;
+               this.seen = false;
+       }
+}
+
+public class AltosEepromFile extends AltosStateIterable {
+
+       AltosEepromIterable     headers;
+       AltosEepromIterable     body;
+       AltosState              start;
+
+       public void write_comments(PrintStream out) {
+               headers.write(out);
+       }
+
+       public void write(PrintStream out) {
+               headers.write(out);
+               body.write(out);
+       }
+
+       public AltosEepromFile(FileInputStream input) {
+               headers = new AltosEepromIterable(AltosEepromHeader.read(input));
+
+               start = headers.state();
+               start.set_state(AltosLib.ao_flight_pad);
+
+               switch (start.log_format) {
+               case AltosLib.AO_LOG_FORMAT_FULL:
+                       body = new AltosEepromIterable(AltosEepromTM.read(input));
+                       break;
+               case AltosLib.AO_LOG_FORMAT_TINY:
+                       body = new AltosEepromIterable(AltosEepromTm.read(input));
+                       break;
+               case AltosLib.AO_LOG_FORMAT_TELEMETRY:
+               case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
+               case AltosLib.AO_LOG_FORMAT_TELEMEGA:
+                       body = new AltosEepromIterable(AltosEepromMega.read(input));
+                       break;
+               case AltosLib.AO_LOG_FORMAT_TELEMETRUM:
+                       body = new AltosEepromIterable(AltosEepromMetrum2.read(input));
+                       break;
+               case AltosLib.AO_LOG_FORMAT_TELEMINI:
+               case AltosLib.AO_LOG_FORMAT_EASYMINI:
+                       body = new AltosEepromIterable(AltosEepromMini.read(input));
+                       break;
+               default:
+                       body = new AltosEepromIterable(new LinkedList<AltosEeprom>());
+                       break;
+               }
+
+               /* Find boost tick */
+               AltosState      state = start.clone();
+               for (AltosEeprom eeprom : body) {
+                       eeprom.update_state(state);
+                       state.finish_update();
+                       if (state.state >= AltosLib.ao_flight_boost) {
+                               start.set_boost_tick(state.tick);
+                               break;
+                       }
+               }
+       }
+
+       public Iterator<AltosState> iterator() {
+               AltosState              state = start.clone();
+               Iterator<AltosEeprom>   i = body.iterator();
+
+               while (i.hasNext() && !state.valid()) {
+                       i.next().update_state(state);
+                       state.finish_update();
+               }
+               return new AltosEepromIterator(state, i);
+       }
+}
\ No newline at end of file
diff --git a/altoslib/AltosEepromHeader.java b/altoslib/AltosEepromHeader.java
new file mode 100644 (file)
index 0000000..0aeb78d
--- /dev/null
@@ -0,0 +1,278 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+
+public class AltosEepromHeader extends AltosEeprom {
+
+       public int      cmd;
+       public String   data;
+       public int      config_a, config_b;
+       public boolean  last;
+       public boolean  valid;
+
+       public int record_length () { return 0; }
+
+       /* XXX pull rest of config data to state */
+       public void update_state(AltosState state) {
+               switch (cmd) {
+               case AltosLib.AO_LOG_CONFIG_VERSION:
+                       break;
+               case AltosLib.AO_LOG_MAIN_DEPLOY:
+                       break;
+               case AltosLib.AO_LOG_APOGEE_DELAY:
+                       break;
+               case AltosLib.AO_LOG_RADIO_CHANNEL:
+                       break;
+               case AltosLib.AO_LOG_CALLSIGN:
+                       state.set_callsign(data);
+                       break;
+               case AltosLib.AO_LOG_ACCEL_CAL:
+                       state.set_accel_g(config_a, config_b);
+                       break;
+               case AltosLib.AO_LOG_RADIO_CAL:
+                       break;
+               case AltosLib.AO_LOG_MANUFACTURER:
+                       break;
+               case AltosLib.AO_LOG_PRODUCT:
+                       break;
+               case AltosLib.AO_LOG_LOG_FORMAT:
+                       state.log_format = config_a;
+                       break;
+               case AltosLib.AO_LOG_SERIAL_NUMBER:
+                       state.set_serial(config_a);
+                       break;
+               case AltosLib.AO_LOG_BARO_RESERVED:
+                       state.make_baro();
+                       state.baro.reserved = config_a;
+                       break;
+               case AltosLib.AO_LOG_BARO_SENS:
+                       state.make_baro();
+                       state.baro.sens = config_a;
+                       break;
+               case AltosLib.AO_LOG_BARO_OFF:
+                       state.make_baro();
+                       state.baro.off = config_a;
+                       break;
+               case AltosLib.AO_LOG_BARO_TCS:
+                       state.make_baro();
+                       state.baro.tcs = config_a;
+                       break;
+               case AltosLib.AO_LOG_BARO_TCO:
+                       state.make_baro();
+                       state.baro.tco = config_a;
+                       break;
+               case AltosLib.AO_LOG_BARO_TREF:
+                       state.make_baro();
+                       state.baro.tref = config_a;
+                       break;
+               case AltosLib.AO_LOG_BARO_TEMPSENS:
+                       state.make_baro();
+                       state.baro.tempsens = config_a;
+                       break;
+               case AltosLib.AO_LOG_BARO_CRC:
+                       state.make_baro();
+                       state.baro.crc = config_a;
+                       break;
+               case AltosLib.AO_LOG_SOFTWARE_VERSION:
+                       state.set_firmware_version(data);
+                       break;
+               }
+       }
+
+       public void write(PrintStream out) {
+               switch (cmd) {
+               case AltosLib.AO_LOG_CONFIG_VERSION:
+                       out.printf("# Config version: %s\n", data);
+                       break;
+               case AltosLib.AO_LOG_MAIN_DEPLOY:
+                       out.printf("# Main deploy: %s\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_APOGEE_DELAY:
+                       out.printf("# Apogee delay: %s\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_RADIO_CHANNEL:
+                       out.printf("# Radio channel: %s\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_CALLSIGN:
+                       out.printf("# Callsign: %s\n", data);
+                       break;
+               case AltosLib.AO_LOG_ACCEL_CAL:
+                       out.printf ("# Accel cal: %d %d\n", config_a, config_b);
+                       break;
+               case AltosLib.AO_LOG_RADIO_CAL:
+                       out.printf ("# Radio cal: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_MAX_FLIGHT_LOG:
+                       out.printf ("# Max flight log: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_MANUFACTURER:
+                       out.printf ("# Manufacturer: %s\n", data);
+                       break;
+               case AltosLib.AO_LOG_PRODUCT:
+                       out.printf ("# Product: %s\n", data);
+                       break;
+               case AltosLib.AO_LOG_SERIAL_NUMBER:
+                       out.printf ("# Serial number: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_SOFTWARE_VERSION:
+                       out.printf ("# Software version: %s\n", data);
+                       break;
+               case AltosLib.AO_LOG_BARO_RESERVED:
+                       out.printf ("# Baro reserved: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_BARO_SENS:
+                       out.printf ("# Baro sens: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_BARO_OFF:
+                       out.printf ("# Baro off: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_BARO_TCS:
+                       out.printf ("# Baro tcs: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_BARO_TCO:
+                       out.printf ("# Baro tco: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_BARO_TREF:
+                       out.printf ("# Baro tref: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_BARO_TEMPSENS:
+                       out.printf ("# Baro tempsens: %d\n", config_a);
+                       break;
+               case AltosLib.AO_LOG_BARO_CRC:
+                       out.printf ("# Baro crc: %d\n", config_a);
+                       break;
+               }
+       }
+       
+       public AltosEepromHeader (String[] tokens) {
+               last = false;
+               valid = true;
+               try {
+                       if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
+                               cmd = AltosLib.AO_LOG_CONFIG_VERSION;
+                               data = tokens[2];
+                       } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
+                               cmd = AltosLib.AO_LOG_MAIN_DEPLOY;
+                               config_a = Integer.parseInt(tokens[2]);
+                       } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
+                               cmd = AltosLib.AO_LOG_APOGEE_DELAY;
+                               config_a = Integer.parseInt(tokens[2]);
+                       } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
+                               cmd = AltosLib.AO_LOG_RADIO_CHANNEL;
+                               config_a = Integer.parseInt(tokens[2]);
+                       } else if (tokens[0].equals("Callsign:")) {
+                               cmd = AltosLib.AO_LOG_CALLSIGN;
+                               data = tokens[1].replaceAll("\"","");
+                       } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
+                               cmd = AltosLib.AO_LOG_ACCEL_CAL;
+                               config_a = Integer.parseInt(tokens[3]);
+                               config_b = Integer.parseInt(tokens[5]);
+                       } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
+                               cmd = AltosLib.AO_LOG_RADIO_CAL;
+                               config_a = Integer.parseInt(tokens[2]);
+                       } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) {
+                               cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG;
+                               config_a = Integer.parseInt(tokens[3]);
+                       } else if (tokens[0].equals("manufacturer")) {
+                               cmd = AltosLib.AO_LOG_MANUFACTURER;
+                               data = tokens[1];
+                       } else if (tokens[0].equals("product")) {
+                               cmd = AltosLib.AO_LOG_PRODUCT;
+                               data = tokens[1];
+                       } else if (tokens[0].equals("serial-number")) {
+                               cmd = AltosLib.AO_LOG_SERIAL_NUMBER;
+                               config_a = Integer.parseInt(tokens[1]);
+                       } else if (tokens[0].equals("log-format")) {
+                               cmd = AltosLib.AO_LOG_LOG_FORMAT;
+                               config_a = Integer.parseInt(tokens[1]);
+                       } else if (tokens[0].equals("software-version")) {
+                               cmd = AltosLib.AO_LOG_SOFTWARE_VERSION;
+                               data = tokens[1];
+                               last = true;
+                       } else if (tokens[0].equals("ms5607")) {
+                               if (tokens[1].equals("reserved:")) {
+                                       cmd = AltosLib.AO_LOG_BARO_RESERVED;
+                                       config_a = Integer.parseInt(tokens[2]);
+                               } else if (tokens[1].equals("sens:")) {
+                                       cmd = AltosLib.AO_LOG_BARO_SENS;
+                                       config_a = Integer.parseInt(tokens[2]);
+                               } else if (tokens[1].equals("off:")) {
+                                       cmd = AltosLib.AO_LOG_BARO_OFF;
+                                       config_a = Integer.parseInt(tokens[2]);
+                               } else if (tokens[1].equals("tcs:")) {
+                                       cmd = AltosLib.AO_LOG_BARO_TCS;
+                                       config_a = Integer.parseInt(tokens[2]);
+                               } else if (tokens[1].equals("tco:")) {
+                                       cmd = AltosLib.AO_LOG_BARO_TCO;
+                                       config_a = Integer.parseInt(tokens[2]);
+                               } else if (tokens[1].equals("tref:")) {
+                                       cmd = AltosLib.AO_LOG_BARO_TREF;
+                                       config_a = Integer.parseInt(tokens[2]);
+                               } else if (tokens[1].equals("tempsens:")) {
+                                       cmd = AltosLib.AO_LOG_BARO_TEMPSENS;
+                                       config_a = Integer.parseInt(tokens[2]);
+                               } else if (tokens[1].equals("crc:")) {
+                                       cmd = AltosLib.AO_LOG_BARO_CRC;
+                                       config_a = Integer.parseInt(tokens[2]);
+                               } else {
+                                       cmd = AltosLib.AO_LOG_INVALID;
+                                       data = tokens[2];
+                               }
+                       } else
+                               valid = false;
+               } catch (Exception e) {
+                       valid = false;
+               }
+       }
+
+       static public LinkedList<AltosEeprom> read(FileInputStream input) {
+               LinkedList<AltosEeprom> headers = new LinkedList<AltosEeprom>();
+
+               for (;;) {
+                       try {
+                               String line = AltosLib.gets(input);
+                               if (line == null)
+                                       break;
+                               AltosEepromHeader header = new AltosEepromHeader(line);
+                               headers.add(header);
+                               if (header.last)
+                                       break;
+                       } catch (IOException ie) {
+                               break;
+                       }
+               }
+
+               return headers;
+       }
+
+       static public void write (PrintStream out, LinkedList<AltosEepromHeader> headers) {
+               out.printf("# Comments\n");
+               for (AltosEepromHeader header : headers) {
+                       header.write(out);
+               }
+               
+       }
+
+       public AltosEepromHeader (String line) {
+               this(line.split("\\s+"));
+       }
+}
index b84574ef9647261ea724d9510f0946f03469f544..fc793579f41837469a54c8924a6b85025d9c23e9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2010 Keith Packard <keithp@keithp.com>
+ * Copyright © 2013 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
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 import java.util.*;
 import java.text.*;
 
-public class AltosEepromIterable extends AltosRecordIterable {
+class AltosEepromOrdered implements Comparable<AltosEepromOrdered> {
+       AltosEeprom     eeprom;
+       int             index;
+       int             tick;
 
-       static final int        seen_basic = AltosRecord.seen_flight|AltosRecord.seen_sensor;
-
-       boolean                 has_accel;
-       boolean                 has_gps;
-       boolean                 has_ignite;
-
-       AltosEepromRecord       flight_record;
-       AltosEepromRecord       gps_date_record;
-
-       TreeSet<AltosOrderedRecord>     records;
-
-       LinkedList<AltosRecord> list;
-
-       class EepromState {
-               int     seen;
-               int     n_pad_samples;
-               double  ground_pres;
-               int     gps_tick;
-               int     boost_tick;
-               int     sensor_tick;
-
-               EepromState() {
-                       seen = 0;
-                       n_pad_samples = 0;
-                       ground_pres = 0.0;
-                       gps_tick = 0;
-               }
+       int cmdi() {
+               if (eeprom.cmd == AltosLib.AO_LOG_FLIGHT)
+                       return 0;
+               return 1;
        }
 
-       void update_state(AltosRecordTM state, AltosEepromRecord record, EepromState eeprom) {
-               state.tick = record.tick;
-               switch (record.cmd) {
-               case AltosLib.AO_LOG_FLIGHT:
-                       eeprom.seen |= AltosRecord.seen_flight;
-                       state.ground_accel = record.a;
-                       state.flight_accel = record.a;
-                       state.flight = record.b;
-                       eeprom.boost_tick = record.tick;
-                       break;
-               case AltosLib.AO_LOG_SENSOR:
-                       state.accel = record.a;
-                       state.pres = record.b;
-                       if (state.state < AltosLib.ao_flight_boost) {
-                               eeprom.n_pad_samples++;
-                               eeprom.ground_pres += state.pres;
-                               state.ground_pres = (int) (eeprom.ground_pres / eeprom.n_pad_samples);
-                               state.flight_pres = state.ground_pres;
-                       } else {
-                               state.flight_pres = (state.flight_pres * 15 + state.pres) / 16;
-                       }
-                       state.flight_accel = (state.flight_accel * 15 + state.accel) / 16;
-                       if ((eeprom.seen & AltosRecord.seen_sensor) == 0)
-                               eeprom.sensor_tick = record.tick - 1;
-                       state.flight_vel += (state.accel_plus_g - state.accel) * (record.tick - eeprom.sensor_tick);
-                       eeprom.seen |= AltosRecord.seen_sensor;
-                       eeprom.sensor_tick = record.tick;
-                       has_accel = true;
-                       break;
-               case AltosLib.AO_LOG_PRESSURE:
-                       state.pres = record.b;
-                       state.flight_pres = state.pres;
-                       if (eeprom.n_pad_samples == 0) {
-                               eeprom.n_pad_samples++;
-                               state.ground_pres = state.pres;
-                       }
-                       eeprom.seen |= AltosRecord.seen_sensor;
-                       break;
-               case AltosLib.AO_LOG_TEMP_VOLT:
-                       state.temp = record.a;
-                       state.batt = record.b;
-                       eeprom.seen |= AltosRecord.seen_temp_volt;
-                       break;
-               case AltosLib.AO_LOG_DEPLOY:
-                       state.drogue = record.a;
-                       state.main = record.b;
-                       eeprom.seen |= AltosRecord.seen_deploy;
-                       has_ignite = true;
-                       break;
-               case AltosLib.AO_LOG_STATE:
-                       state.state = record.a;
-                       break;
-               case AltosLib.AO_LOG_GPS_TIME:
-                       eeprom.gps_tick = state.tick;
-                       eeprom.seen |= AltosRecord.seen_gps_time;
-                       AltosGPS old = state.gps;
-                       state.gps = new AltosGPS();
+       public int compareTo(AltosEepromOrdered o) {
+               int     cmd_diff = cmdi() - o.cmdi();
 
-                       /* GPS date doesn't get repeated through the file */
-                       if (old != null) {
-                               state.gps.year = old.year;
-                               state.gps.month = old.month;
-                               state.gps.day = old.day;
-                       }
-                       state.gps.hour = (record.a & 0xff);
-                       state.gps.minute = (record.a >> 8);
-                       state.gps.second = (record.b & 0xff);
+               if (cmd_diff != 0)
+                       return cmd_diff;
 
-                       int flags = (record.b >> 8);
-                       state.gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
-                       state.gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
-                       state.gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
-                               AltosLib.AO_GPS_NUM_SAT_SHIFT;
-                       state.gps_sequence++;
-                       has_gps = true;
-                       break;
-               case AltosLib.AO_LOG_GPS_LAT:
-                       eeprom.seen |= AltosRecord.seen_gps_lat;
-                       int lat32 = record.a | (record.b << 16);
-                       if (state.gps == null)
-                               state.gps = new AltosGPS();
-                       state.gps.lat = (double) lat32 / 1e7;
-                       break;
-               case AltosLib.AO_LOG_GPS_LON:
-                       eeprom.seen |= AltosRecord.seen_gps_lon;
-                       int lon32 = record.a | (record.b << 16);
-                       if (state.gps == null)
-                               state.gps = new AltosGPS();
-                       state.gps.lon = (double) lon32 / 1e7;
-                       break;
-               case AltosLib.AO_LOG_GPS_ALT:
-                       if (state.gps == null)
-                               state.gps = new AltosGPS();
-                       state.gps.alt = record.a;
-                       break;
-               case AltosLib.AO_LOG_GPS_SAT:
-                       if (state.tick == eeprom.gps_tick) {
-                               int svid = record.a;
-                               int c_n0 = record.b >> 8;
-                               if (state.gps == null)
-                                       state.gps = new AltosGPS();
-                               state.gps.add_sat(svid, c_n0);
-                       }
-                       break;
-               case AltosLib.AO_LOG_GPS_DATE:
-                       if (state.gps == null)
-                               state.gps = new AltosGPS();
-                       state.gps.year = (record.a & 0xff) + 2000;
-                       state.gps.month = record.a >> 8;
-                       state.gps.day = record.b & 0xff;
-                       break;
+               int     tick_diff = tick - o.tick;
 
-               case AltosLib.AO_LOG_CONFIG_VERSION:
-                       break;
-               case AltosLib.AO_LOG_MAIN_DEPLOY:
-                       break;
-               case AltosLib.AO_LOG_APOGEE_DELAY:
-                       break;
-               case AltosLib.AO_LOG_RADIO_CHANNEL:
-                       break;
-               case AltosLib.AO_LOG_CALLSIGN:
-                       state.callsign = record.data;
-                       break;
-               case AltosLib.AO_LOG_ACCEL_CAL:
-                       state.accel_plus_g = record.a;
-                       state.accel_minus_g = record.b;
-                       break;
-               case AltosLib.AO_LOG_RADIO_CAL:
-                       break;
-               case AltosLib.AO_LOG_MANUFACTURER:
-                       break;
-               case AltosLib.AO_LOG_PRODUCT:
-                       break;
-               case AltosLib.AO_LOG_SERIAL_NUMBER:
-                       state.serial = record.a;
-                       break;
-               case AltosLib.AO_LOG_SOFTWARE_VERSION:
-                       break;
-               }
-               state.seen |= eeprom.seen;
+               if (tick_diff != 0)
+                       return tick_diff;
+               return index - o.index;
        }
 
-       LinkedList<AltosRecord> make_list() {
-               LinkedList<AltosRecord>         list = new LinkedList<AltosRecord>();
-               Iterator<AltosOrderedRecord>    iterator = records.iterator();
-               AltosOrderedRecord              record = null;
-               AltosRecordTM                   state = new AltosRecordTM();
-               //boolean                               last_reported = false;
-               EepromState                     eeprom = new EepromState();
-
-               state.state = AltosLib.ao_flight_pad;
-               state.accel_plus_g = 15758;
-               state.accel_minus_g = 16294;
-               state.flight_vel = 0;
-
-               /* Pull in static data from the flight and gps_date records */
-               if (flight_record != null)
-                       update_state(state, flight_record, eeprom);
-               if (gps_date_record != null)
-                       update_state(state, gps_date_record, eeprom);
+       AltosEepromOrdered (AltosEeprom eeprom, int index, int tick) {
+               this.eeprom = eeprom;
+               this.index = index;
+               this.tick = tick;
+       }
+}
 
-               while (iterator.hasNext()) {
-                       record = iterator.next();
-                       if ((eeprom.seen & seen_basic) == seen_basic && record.tick != state.tick) {
-                               AltosRecordTM r = state.clone();
-                               r.time = (r.tick - eeprom.boost_tick) / 100.0;
-                               list.add(r);
+class AltosEepromOrderedIterator implements Iterator<AltosEeprom> {
+       TreeSet<AltosEepromOrdered>     olist;
+       Iterator<AltosEepromOrdered>    oiterator;
+
+       public AltosEepromOrderedIterator(Iterable<AltosEeprom> eeproms) {
+               olist = new TreeSet<AltosEepromOrdered>();
+
+               int     tick = 0;
+               int     index = 0;
+               boolean first = true;
+
+               for (AltosEeprom e : eeproms) {
+                       int     t = e.tick;
+                       if (first)
+                               tick = t;
+                       else {
+                               while (t < tick - 32767)
+                                       t += 65536;
+                               tick = t;
                        }
-                       update_state(state, record, eeprom);
+                       olist.add(new AltosEepromOrdered(e, index++, tick));
+                       first = false;
                }
-               AltosRecordTM r = state.clone();
-               r.time = (r.tick - eeprom.boost_tick) / 100.0;
-               list.add(r);
-       return list;
-       }
 
-       public Iterator<AltosRecord> iterator() {
-               if (list == null)
-                       list = make_list();
-               return list.iterator();
+               oiterator = olist.iterator();
        }
 
-       public boolean has_gps() { return has_gps; }
-       public boolean has_accel() { return has_accel; }
-       public boolean has_ignite() { return has_ignite; }
-
-       public void write_comments(PrintStream out) {
-               Iterator<AltosOrderedRecord>    iterator = records.iterator();
-               out.printf("# Comments\n");
-               while (iterator.hasNext()) {
-                       AltosOrderedRecord      record = iterator.next();
-                       switch (record.cmd) {
-                       case AltosLib.AO_LOG_CONFIG_VERSION:
-                               out.printf("# Config version: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_MAIN_DEPLOY:
-                               out.printf("# Main deploy: %s\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_APOGEE_DELAY:
-                               out.printf("# Apogee delay: %s\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_RADIO_CHANNEL:
-                               out.printf("# Radio channel: %s\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_CALLSIGN:
-                               out.printf("# Callsign: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_ACCEL_CAL:
-                               out.printf ("# Accel cal: %d %d\n", record.a, record.b);
-                               break;
-                       case AltosLib.AO_LOG_RADIO_CAL:
-                               out.printf ("# Radio cal: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_MAX_FLIGHT_LOG:
-                               out.printf ("# Max flight log: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_MANUFACTURER:
-                               out.printf ("# Manufacturer: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_PRODUCT:
-                               out.printf ("# Product: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_SERIAL_NUMBER:
-                               out.printf ("# Serial number: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_SOFTWARE_VERSION:
-                               out.printf ("# Software version: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_BARO_RESERVED:
-                               out.printf ("# Baro reserved: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_SENS:
-                               out.printf ("# Baro sens: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_OFF:
-                               out.printf ("# Baro off: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TCS:
-                               out.printf ("# Baro tcs: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TCO:
-                               out.printf ("# Baro tco: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TREF:
-                               out.printf ("# Baro tref: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TEMPSENS:
-                               out.printf ("# Baro tempsens: %d\n", record.a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_CRC:
-                               out.printf ("# Baro crc: %d\n", record.a);
-                               break;
-                       }
-               }
+       public boolean hasNext() {
+               return oiterator.hasNext();
        }
 
-       /*
-        * Given an AO_LOG_GPS_TIME record with correct time, and one
-        * missing time, rewrite the missing time values with the good
-        * ones, assuming that the difference between them is 'diff' seconds
-        */
-       void update_time(AltosOrderedRecord good, AltosOrderedRecord bad) {
-
-               int diff = (bad.tick - good.tick + 50) / 100;
-
-               int hour = (good.a & 0xff);
-               int minute = (good.a >> 8);
-               int second = (good.b & 0xff);
-               int flags = (good.b >> 8);
-               int seconds = hour * 3600 + minute * 60 + second;
-
-               /* Make sure this looks like a good GPS value */
-               if ((flags & AltosLib.AO_GPS_NUM_SAT_MASK) >> AltosLib.AO_GPS_NUM_SAT_SHIFT < 4)
-                       flags = (flags & ~AltosLib.AO_GPS_NUM_SAT_MASK) | (4 << AltosLib.AO_GPS_NUM_SAT_SHIFT);
-               flags |= AltosLib.AO_GPS_RUNNING;
-               flags |= AltosLib.AO_GPS_VALID;
-
-               int new_seconds = seconds + diff;
-               if (new_seconds < 0)
-                       new_seconds += 24 * 3600;
-               int new_second = (new_seconds % 60);
-               int new_minutes = (new_seconds / 60);
-               int new_minute = (new_minutes % 60);
-               int new_hours = (new_minutes / 60);
-               int new_hour = (new_hours % 24);
-
-               bad.a = new_hour + (new_minute << 8);
-               bad.b = new_second + (flags << 8);
+       public AltosEeprom next() {
+               return oiterator.next().eeprom;
        }
 
-       /*
-        * Read the whole file, dumping records into a RB tree so
-        * we can enumerate them in time order -- the eeprom data
-        * are sometimes out of order with GPS data getting timestamps
-        * matching the first packet out of the GPS unit but not
-        * written until the final GPS packet has been received.
-        */
-       public AltosEepromIterable (FileInputStream input) {
-               records = new TreeSet<AltosOrderedRecord>();
-
-               AltosOrderedRecord last_gps_time = null;
-
-               int index = 0;
-               int prev_tick = 0;
-               boolean prev_tick_valid = false;
-               boolean missing_time = false;
+       public void remove () {
+       }
+}
 
-               try {
-                       for (;;) {
-                               String line = AltosLib.gets(input);
-                               if (line == null)
-                                       break;
-                               AltosOrderedRecord record = new AltosOrderedRecord(line, index++, prev_tick, prev_tick_valid);
-                               if (record.cmd == AltosLib.AO_LOG_INVALID)
-                                       continue;
-                               prev_tick = record.tick;
-                               if (record.cmd < AltosLib.AO_LOG_CONFIG_VERSION)
-                                       prev_tick_valid = true;
-                               if (record.cmd == AltosLib.AO_LOG_FLIGHT) {
-                                       flight_record = record;
-                                       continue;
-                               }
+public class AltosEepromIterable implements Iterable<AltosEeprom> {
+       public LinkedList<AltosEeprom> eeproms;
 
-                               /* Two firmware bugs caused the loss of some GPS data.
-                                * The flight date would never be recorded, and often
-                                * the flight time would get overwritten by another
-                                * record. Detect the loss of the GPS date and fix up the
-                                * missing time records
-                                */
-                               if (record.cmd == AltosLib.AO_LOG_GPS_DATE) {
-                                       gps_date_record = record;
-                                       continue;
-                               }
+       public void write(PrintStream out) {
+               for (AltosEeprom eeprom : eeproms)
+                       eeprom.write(out);
+       }
 
-                               /* go back and fix up any missing time values */
-                               if (record.cmd == AltosLib.AO_LOG_GPS_TIME) {
-                                       last_gps_time = record;
-                                       if (missing_time) {
-                                               Iterator<AltosOrderedRecord> iterator = records.iterator();
-                                               while (iterator.hasNext()) {
-                                                       AltosOrderedRecord old = iterator.next();
-                                                       if (old.cmd == AltosLib.AO_LOG_GPS_TIME &&
-                                                           old.a == -1 && old.b == -1)
-                                                       {
-                                                               update_time(record, old);
-                                                       }
-                                               }
-                                               missing_time = false;
-                                       }
-                               }
+       public AltosState state() {
+               AltosState      state = new AltosState();
 
-                               if (record.cmd == AltosLib.AO_LOG_GPS_LAT) {
-                                       if (last_gps_time == null || last_gps_time.tick != record.tick) {
-                                               AltosOrderedRecord add_gps_time = new AltosOrderedRecord(AltosLib.AO_LOG_GPS_TIME,
-                                                                                                        record.tick,
-                                                                                                        -1, -1, index-1);
-                                               if (last_gps_time != null)
-                                                       update_time(last_gps_time, add_gps_time);
-                                               else
-                                                       missing_time = true;
+               for (AltosEeprom header : eeproms)
+                       header.update_state(state);
+               return state;
+       }
 
-                                               records.add(add_gps_time);
-                                               record.index = index++;
-                                       }
-                               }
-                               records.add(record);
+       public AltosEepromIterable(LinkedList<AltosEeprom> eeproms) {
+               this.eeproms = eeproms;
+       }
 
-                               /* Bail after reading the 'landed' record; we're all done */
-                               if (record.cmd == AltosLib.AO_LOG_STATE &&
-                                   record.a == AltosLib.ao_flight_landed)
-                                       break;
-                       }
-               } catch (IOException io) {
-               } catch (ParseException pe) {
-               }
-               try {
-                       input.close();
-               } catch (IOException ie) {
-               }
+       public Iterator<AltosEeprom> iterator() {
+               if (eeproms == null)
+                       eeproms = new LinkedList<AltosEeprom>();
+               return new AltosEepromOrderedIterator(eeproms);
        }
-}
+}
\ No newline at end of file
index 20026c6d33139a76b4c8014f15e284defd0c3b48..95c0c3f6c5bcb272ba8db7b8cfbd89b8640d198c 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.text.*;
 import java.util.concurrent.*;
@@ -72,9 +72,9 @@ public class AltosEepromLog {
                        for (block = in_start_block; block < in_end_block; block++) {
                                AltosEepromChunk eechunk = new AltosEepromChunk(link, block, block == in_start_block);
 
-                               for (int i = 0; i < AltosEepromChunk.chunk_size; i += AltosEepromRecord.record_length) {
+                               for (int i = 0; i < AltosEepromChunk.chunk_size; i += AltosEepromTM.record_length) {
                                        try {
-                                               AltosEepromRecord r = new AltosEepromRecord(eechunk, i);
+                                               AltosEepromTM r = new AltosEepromTM(eechunk, i);
 
                                                if (r.cmd == AltosLib.AO_LOG_FLIGHT) {
                                                        flight = r.b;
index 0804c3924516f0ed6f8b38e099e930d39fabe1a2..7a4ee52d10680e1e61c3289bb029a12e079b444c 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
+import java.io.*;
+import java.util.*;
 import java.text.*;
 
-public class AltosEepromMega {
-       public int      cmd;
-       public int      tick;
-       public boolean  valid;
-       public String   data;
-       public int      config_a, config_b;
-
-       public int      data8[];
-
+public class AltosEepromMega extends AltosEeprom {
        public static final int record_length = 32;
-       static final int        header_length = 4;
-       static final int        data_length = record_length - header_length;
-
-       public int data8(int i) {
-               return data8[i];
-       }
 
-       public int data16(int i) {
-               return ((data8[i] | (data8[i+1] << 8)) << 16) >> 16;
-       }
-
-       public int data32(int i) {
-               return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16) | (data8[i+3] << 24);
-       }
+       public int record_length() { return record_length; }
 
        /* AO_LOG_FLIGHT elements */
        public int flight() { return data16(0); }
@@ -68,7 +50,7 @@ public class AltosEepromMega {
        public int mag_z() { return data16(24); }
        public int accel() { return data16(26); }
 
-       /* AO_LOG_VOLT elements */
+       /* AO_LOG_TEMP_VOLT elements */
        public int v_batt() { return data16(0); }
        public int v_pbatt() { return data16(2); }
        public int nsense() { return data16(4); }
@@ -91,131 +73,139 @@ public class AltosEepromMega {
        public int nsat() { return data16(0); }
        public int svid(int n) { return data8(2 + n * 2); }
        public int c_n(int n) { return data8(2 + n * 2 + 1); }
+
        public AltosEepromMega (AltosEepromChunk chunk, int start) throws ParseException {
-               cmd = chunk.data(start);
-
-               valid = !chunk.erased(start, record_length);
-               if (valid) {
-                       if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
-                               throw new ParseException(String.format("invalid checksum at 0x%x",
-                                                                      chunk.address + start), 0);
-               } else {
-                       cmd = AltosLib.AO_LOG_INVALID;
-               }
+               parse_chunk(chunk, start);
+       }
 
-               tick = chunk.data16(start+2);
+       public void update_state(AltosState state) {
+               super.update_state(state);
+
+               AltosGPS        gps;
+
+               /* Flush any pending GPS changes */
+               if (state.gps_pending) {
+                       switch (cmd) {
+                       case AltosLib.AO_LOG_GPS_LAT:
+                       case AltosLib.AO_LOG_GPS_LON:
+                       case AltosLib.AO_LOG_GPS_ALT:
+                       case AltosLib.AO_LOG_GPS_SAT:
+                       case AltosLib.AO_LOG_GPS_DATE:
+                               break;
+                       default:
+                               state.set_temp_gps();
+                               break;
+                       }
+               }
 
-               data8 = new int[data_length];
-               for (int i = 0; i < data_length; i++)
-                       data8[i] = chunk.data(start + header_length + i);
+               switch (cmd) {
+               case AltosLib.AO_LOG_FLIGHT:
+                       state.set_boost_tick(tick);
+                       state.set_flight(flight());
+                       state.set_ground_accel(ground_accel());
+                       state.set_ground_pressure(ground_pres());
+                       state.set_temperature(ground_temp() / 100.0);
+                       break;
+               case AltosLib.AO_LOG_STATE:
+                       state.set_tick(tick);
+                       state.set_state(state());
+                       break;
+               case AltosLib.AO_LOG_SENSOR:
+                       state.set_tick(tick);
+                       state.set_ms5607(pres(), temp());
+
+                       AltosIMU imu = new AltosIMU();
+                       imu.accel_x = accel_x();
+                       imu.accel_y = accel_y();
+                       imu.accel_z = accel_z();
+
+                       imu.gyro_x = gyro_x();
+                       imu.gyro_y = gyro_y();
+                       imu.gyro_z = gyro_z();
+                       state.imu = imu;
+
+                       AltosMag mag = new AltosMag();
+                       mag.x = mag_x();
+                       mag.y = mag_y();
+                       mag.z = mag_z();
+
+                       state.mag = mag;
+
+                       state.set_accel(accel());
+
+                       break;
+               case AltosLib.AO_LOG_TEMP_VOLT:
+                       state.set_battery_voltage(AltosConvert.mega_battery_voltage(v_batt()));
+                       state.set_pyro_voltage(AltosConvert.mega_pyro_voltage(v_pbatt()));
+
+                       int nsense = nsense();
+
+                       state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-2)));
+                       state.set_main_voltage(AltosConvert.mega_pyro_voltage(sense(nsense-1)));
+
+                       double voltages[] = new double[nsense-2];
+                       for (int i = 0; i < nsense-2; i++)
+                               voltages[i] = AltosConvert.mega_pyro_voltage(sense(i));
+
+                       state.set_ignitor_voltage(voltages);
+                       break;
+               case AltosLib.AO_LOG_GPS_TIME:
+                       state.set_tick(tick);
+                       gps = state.make_temp_gps(false);
+                       gps.lat = latitude() / 1e7;
+                       gps.lon = longitude() / 1e7;
+                       gps.alt = altitude();
+
+                       gps.hour = hour();
+                       gps.minute = minute();
+                       gps.second = second();
+
+                       int flags = flags();
+
+                       gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
+                       gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
+                       gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
+                               AltosLib.AO_GPS_NUM_SAT_SHIFT;
+
+                       gps.year = 2000 + year();
+                       gps.month = month();
+                       gps.day = day();
+                       break;
+               case AltosLib.AO_LOG_GPS_SAT:
+                       state.set_tick(tick);
+                       gps = state.make_temp_gps(true);
+
+                       int n = nsat();
+                       for (int i = 0; i < n; i++)
+                               gps.add_sat(svid(i), c_n(i));
+                       break;
+               }
        }
 
        public AltosEepromMega (String line) {
-               valid = false;
-               tick = 0;
+               parse_string(line);
+       }
 
-               if (line == null) {
-                       cmd = AltosLib.AO_LOG_INVALID;
-                       line = "";
-               } else {
+       static public LinkedList<AltosEeprom> read(FileInputStream input) {
+               LinkedList<AltosEeprom> megas = new LinkedList<AltosEeprom>();
+
+               for (;;) {
                        try {
-                               String[] tokens = line.split("\\s+");
-
-                               if (tokens[0].length() == 1) {
-                                       if (tokens.length != 2 + data_length) {
-                                               cmd = AltosLib.AO_LOG_INVALID;
-                                               data = line;
-                                       } else {
-                                               cmd = tokens[0].codePointAt(0);
-                                               tick = Integer.parseInt(tokens[1],16);
-                                               valid = true;
-                                               data8 = new int[data_length];
-                                               for (int i = 0; i < data_length; i++)
-                                                       data8[i] = Integer.parseInt(tokens[2 + i],16);
-                                       }
-                               } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
-                                       cmd = AltosLib.AO_LOG_CONFIG_VERSION;
-                                       data = tokens[2];
-                               } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
-                                       cmd = AltosLib.AO_LOG_MAIN_DEPLOY;
-                                       config_a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
-                                       cmd = AltosLib.AO_LOG_APOGEE_DELAY;
-                                       config_a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
-                                       cmd = AltosLib.AO_LOG_RADIO_CHANNEL;
-                                       config_a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Callsign:")) {
-                                       cmd = AltosLib.AO_LOG_CALLSIGN;
-                                       data = tokens[1].replaceAll("\"","");
-                               } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
-                                       cmd = AltosLib.AO_LOG_ACCEL_CAL;
-                                       config_a = Integer.parseInt(tokens[3]);
-                                       config_b = Integer.parseInt(tokens[5]);
-                               } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
-                                       cmd = AltosLib.AO_LOG_RADIO_CAL;
-                                       config_a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) {
-                                       cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG;
-                                       config_a = Integer.parseInt(tokens[3]);
-                               } else if (tokens[0].equals("manufacturer")) {
-                                       cmd = AltosLib.AO_LOG_MANUFACTURER;
-                                       data = tokens[1];
-                               } else if (tokens[0].equals("product")) {
-                                       cmd = AltosLib.AO_LOG_PRODUCT;
-                                       data = tokens[1];
-                               } else if (tokens[0].equals("serial-number")) {
-                                       cmd = AltosLib.AO_LOG_SERIAL_NUMBER;
-                                       config_a = Integer.parseInt(tokens[1]);
-                               } else if (tokens[0].equals("log-format")) {
-                                       cmd = AltosLib.AO_LOG_LOG_FORMAT;
-                                       config_a = Integer.parseInt(tokens[1]);
-                               } else if (tokens[0].equals("software-version")) {
-                                       cmd = AltosLib.AO_LOG_SOFTWARE_VERSION;
-                                       data = tokens[1];
-                               } else if (tokens[0].equals("ms5607")) {
-                                       if (tokens[1].equals("reserved:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_RESERVED;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("sens:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_SENS;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("off:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_OFF;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("tcs:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_TCS;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("tco:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_TCO;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("tref:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_TREF;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("tempsens:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_TEMPSENS;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("crc:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_CRC;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else {
-                                               cmd = AltosLib.AO_LOG_INVALID;
-                                               data = line;
-                                       }
-                               } else {
-                                       cmd = AltosLib.AO_LOG_INVALID;
-                                       data = line;
+                               String line = AltosLib.gets(input);
+                               if (line == null)
+                                       break;
+                               try {
+                                       AltosEepromMega mega = new AltosEepromMega(line);
+                                       if (mega.cmd != AltosLib.AO_LOG_INVALID)
+                                               megas.add(mega);
+                               } catch (Exception e) {
+                                       System.out.printf ("exception\n");
                                }
-                       } catch (NumberFormatException ne) {
-                               cmd = AltosLib.AO_LOG_INVALID;
-                               data = line;
+                       } catch (IOException ie) {
+                               break;
                        }
                }
-       }
 
-       public AltosEepromMega(int in_cmd, int in_tick) {
-               cmd = in_cmd;
-               tick = in_tick;
-               valid = true;
+               return megas;
        }
 }
diff --git a/altoslib/AltosEepromMegaIterable.java b/altoslib/AltosEepromMegaIterable.java
deleted file mode 100644 (file)
index 5736f93..0000000
+++ /dev/null
@@ -1,367 +0,0 @@
-/*
- * 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 org.altusmetrum.altoslib_1;
-
-import java.io.*;
-import java.util.*;
-import java.text.*;
-
-public class AltosEepromMegaIterable extends AltosRecordIterable {
-
-       static final int        seen_flight = 1;
-       static final int        seen_sensor = 2;
-       static final int        seen_temp_volt = 4;
-       static final int        seen_deploy = 8;
-       static final int        seen_gps_time = 16;
-       static final int        seen_gps_lat = 32;
-       static final int        seen_gps_lon = 64;
-
-       static final int        seen_basic = seen_flight|seen_sensor;
-
-       boolean                 has_accel;
-       boolean                 has_gps;
-       boolean                 has_ignite;
-
-       AltosEepromMega flight_record;
-       AltosEepromMega gps_date_record;
-
-       TreeSet<AltosOrderedMegaRecord> records;
-
-       AltosMs5607             baro;
-
-       LinkedList<AltosRecord> list;
-
-       class EepromState {
-               int     seen;
-               int     n_pad_samples;
-               double  ground_pres;
-               int     gps_tick;
-               int     boost_tick;
-               int     sensor_tick;
-
-               EepromState() {
-                       seen = 0;
-                       n_pad_samples = 0;
-                       ground_pres = 0.0;
-                       gps_tick = 0;
-               }
-       }
-
-       void update_state(AltosRecordMM state, AltosEepromMega record, EepromState eeprom) {
-               state.tick = record.tick;
-               switch (record.cmd) {
-               case AltosLib.AO_LOG_FLIGHT:
-                       eeprom.seen |= seen_flight;
-                       state.ground_accel = record.ground_accel();
-                       state.flight_accel = record.ground_accel();
-                       state.ground_pres = baro.set(record.ground_pres(), record.ground_temp());
-                       state.flight_pres = state.ground_pres;
-                       state.flight = record.data16(0);
-                       eeprom.boost_tick = record.tick;
-                       break;
-               case AltosLib.AO_LOG_SENSOR:
-                       state.accel = record.accel();
-                       baro.set(record.pres(), record.temp());
-                       state.pres = baro.pa;
-                       state.temp = baro.cc;
-                       state.imu = new AltosIMU();
-                       state.imu.accel_x = record.accel_x();
-                       state.imu.accel_y = record.accel_y();
-                       state.imu.accel_z = record.accel_z();
-                       state.imu.gyro_x = record.gyro_x();
-                       state.imu.gyro_y = record.gyro_y();
-                       state.imu.gyro_z = record.gyro_z();
-                       state.mag = new AltosMag();
-                       state.mag.x = record.mag_x();
-                       state.mag.y = record.mag_y();
-                       state.mag.z = record.mag_z();
-                       if (state.state < AltosLib.ao_flight_boost) {
-                               eeprom.n_pad_samples++;
-                               eeprom.ground_pres += state.pres;
-                               state.ground_pres = (int) (eeprom.ground_pres / eeprom.n_pad_samples);
-                               state.flight_pres = state.ground_pres;
-                       } else {
-                               state.flight_pres = (state.flight_pres * 15 + state.pres) / 16;
-                       }
-                       state.flight_accel = (state.flight_accel * 15 + state.accel) / 16;
-                       if ((eeprom.seen & seen_sensor) == 0)
-                               eeprom.sensor_tick = record.tick - 1;
-                       state.flight_vel += (state.accel_plus_g - state.accel) * (record.tick - eeprom.sensor_tick);
-                       eeprom.seen |= seen_sensor;
-                       eeprom.sensor_tick = record.tick;
-                       has_accel = true;
-                       break;
-               case AltosLib.AO_LOG_TEMP_VOLT:
-                       state.v_batt = record.v_batt();
-                       state.v_pyro = record.v_pbatt();
-                       for (int i = 0; i < record.nsense(); i++)
-                               state.sense[i] = record.sense(i);
-                       eeprom.seen |= seen_temp_volt;
-                       break;
-               case AltosLib.AO_LOG_STATE:
-                       state.state = record.state();
-                       break;
-               case AltosLib.AO_LOG_GPS_TIME:
-                       eeprom.gps_tick = state.tick;
-                       state.gps = new AltosGPS();
-
-                       state.gps.lat = record.latitude() / 1e7;
-                       state.gps.lon = record.longitude() / 1e7;
-                       state.gps.alt = record.altitude();
-                       state.gps.year = record.year() + 2000;
-                       state.gps.month = record.month();
-                       state.gps.day = record.day();
-
-                       state.gps.hour = record.hour();
-                       state.gps.minute = record.minute();
-                       state.gps.second = record.second();
-
-                       int flags = record.flags();
-                       state.gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
-                       state.gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
-                       state.gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
-                               AltosLib.AO_GPS_NUM_SAT_SHIFT;
-                       state.gps_sequence++;
-                       has_gps = true;
-                       eeprom.seen |= seen_gps_time | seen_gps_lat | seen_gps_lon;
-                       break;
-               case AltosLib.AO_LOG_GPS_SAT:
-                       if (state.tick == eeprom.gps_tick) {
-                               int nsat = record.nsat();
-                               for (int i = 0; i < nsat; i++)
-                                       state.gps.add_sat(record.svid(i), record.c_n(i));
-                       }
-                       break;
-               case AltosLib.AO_LOG_CONFIG_VERSION:
-                       break;
-               case AltosLib.AO_LOG_MAIN_DEPLOY:
-                       break;
-               case AltosLib.AO_LOG_APOGEE_DELAY:
-                       break;
-               case AltosLib.AO_LOG_RADIO_CHANNEL:
-                       break;
-               case AltosLib.AO_LOG_CALLSIGN:
-                       state.callsign = record.data;
-                       break;
-               case AltosLib.AO_LOG_ACCEL_CAL:
-                       state.accel_plus_g = record.config_a;
-                       state.accel_minus_g = record.config_b;
-                       break;
-               case AltosLib.AO_LOG_RADIO_CAL:
-                       break;
-               case AltosLib.AO_LOG_MANUFACTURER:
-                       break;
-               case AltosLib.AO_LOG_PRODUCT:
-                       break;
-               case AltosLib.AO_LOG_SERIAL_NUMBER:
-                       state.serial = record.config_a;
-                       break;
-               case AltosLib.AO_LOG_SOFTWARE_VERSION:
-                       break;
-               case AltosLib.AO_LOG_BARO_RESERVED:
-                       baro.reserved = record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_SENS:
-                       baro.sens =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_OFF:
-                       baro.off =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_TCS:
-                       baro.tcs =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_TCO:
-                       baro.tco =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_TREF:
-                       baro.tref =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_TEMPSENS:
-                       baro.tempsens =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_CRC:
-                       baro.crc =record.config_a;
-                       break;
-               }
-               state.seen |= eeprom.seen;
-       }
-
-       LinkedList<AltosRecord> make_list() {
-               LinkedList<AltosRecord>         list = new LinkedList<AltosRecord>();
-               Iterator<AltosOrderedMegaRecord>        iterator = records.iterator();
-               AltosOrderedMegaRecord          record = null;
-               AltosRecordMM                   state = new AltosRecordMM();
-               //boolean                               last_reported = false;
-               EepromState                     eeprom = new EepromState();
-
-               state.state = AltosLib.ao_flight_pad;
-               state.accel_plus_g = 15758;
-               state.accel_minus_g = 16294;
-
-               /* Pull in static data from the flight and gps_date records */
-               if (flight_record != null)
-                       update_state(state, flight_record, eeprom);
-               if (gps_date_record != null)
-                       update_state(state, gps_date_record, eeprom);
-
-               while (iterator.hasNext()) {
-                       record = iterator.next();
-                       if ((eeprom.seen & seen_basic) == seen_basic && record.tick != state.tick) {
-                               AltosRecordMM r = state.clone();
-                               r.time = (r.tick - eeprom.boost_tick) / 100.0;
-                               list.add(r);
-                       }
-                       update_state(state, record, eeprom);
-               }
-               AltosRecordMM r = state.clone();
-               r.time = (r.tick - eeprom.boost_tick) / 100.0;
-               list.add(r);
-               return list;
-       }
-
-       public Iterator<AltosRecord> iterator() {
-               if (list == null)
-                       list = make_list();
-               return list.iterator();
-       }
-
-       public boolean has_gps() { return has_gps; }
-       public boolean has_accel() { return has_accel; }
-       public boolean has_ignite() { return has_ignite; }
-
-       public void write_comments(PrintStream out) {
-               Iterator<AltosOrderedMegaRecord>        iterator = records.iterator();
-               out.printf("# Comments\n");
-               while (iterator.hasNext()) {
-                       AltosOrderedMegaRecord  record = iterator.next();
-                       switch (record.cmd) {
-                       case AltosLib.AO_LOG_CONFIG_VERSION:
-                               out.printf("# Config version: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_MAIN_DEPLOY:
-                               out.printf("# Main deploy: %s\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_APOGEE_DELAY:
-                               out.printf("# Apogee delay: %s\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_RADIO_CHANNEL:
-                               out.printf("# Radio channel: %s\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_CALLSIGN:
-                               out.printf("# Callsign: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_ACCEL_CAL:
-                               out.printf ("# Accel cal: %d %d\n", record.config_a, record.config_b);
-                               break;
-                       case AltosLib.AO_LOG_RADIO_CAL:
-                               out.printf ("# Radio cal: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_MAX_FLIGHT_LOG:
-                               out.printf ("# Max flight log: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_MANUFACTURER:
-                               out.printf ("# Manufacturer: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_PRODUCT:
-                               out.printf ("# Product: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_SERIAL_NUMBER:
-                               out.printf ("# Serial number: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_SOFTWARE_VERSION:
-                               out.printf ("# Software version: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_BARO_RESERVED:
-                               out.printf ("# Baro reserved: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_SENS:
-                               out.printf ("# Baro sens: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_OFF:
-                               out.printf ("# Baro off: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TCS:
-                               out.printf ("# Baro tcs: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TCO:
-                               out.printf ("# Baro tco: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TREF:
-                               out.printf ("# Baro tref: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TEMPSENS:
-                               out.printf ("# Baro tempsens: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_CRC:
-                               out.printf ("# Baro crc: %d\n", record.config_a);
-                               break;
-                       }
-               }
-       }
-
-       /*
-        * Read the whole file, dumping records into a RB tree so
-        * we can enumerate them in time order -- the eeprom data
-        * are sometimes out of order with GPS data getting timestamps
-        * matching the first packet out of the GPS unit but not
-        * written until the final GPS packet has been received.
-        */
-       public AltosEepromMegaIterable (FileInputStream input) {
-               records = new TreeSet<AltosOrderedMegaRecord>();
-
-               AltosOrderedMegaRecord last_gps_time = null;
-
-               baro = new AltosMs5607();
-
-               int index = 0;
-               int prev_tick = 0;
-               boolean prev_tick_valid = false;
-               boolean missing_time = false;
-
-               try {
-                       for (;;) {
-                               String line = AltosLib.gets(input);
-                               if (line == null)
-                                       break;
-                               AltosOrderedMegaRecord record = new AltosOrderedMegaRecord(line, index++, prev_tick, prev_tick_valid);
-                               if (record.cmd == AltosLib.AO_LOG_INVALID)
-                                       continue;
-                               prev_tick = record.tick;
-                               if (record.cmd < AltosLib.AO_LOG_CONFIG_VERSION)
-                                       prev_tick_valid = true;
-                               if (record.cmd == AltosLib.AO_LOG_FLIGHT) {
-                                       flight_record = record;
-                                       continue;
-                               }
-
-                               records.add(record);
-
-                               /* Bail after reading the 'landed' record; we're all done */
-                               if (record.cmd == AltosLib.AO_LOG_STATE &&
-                                   record.state() == AltosLib.ao_flight_landed)
-                                       break;
-                       }
-               } catch (IOException io) {
-               } catch (ParseException pe) {
-               }
-               try {
-                       input.close();
-               } catch (IOException ie) {
-               }
-       }
-}
diff --git a/altoslib/AltosEepromMetrum2.java b/altoslib/AltosEepromMetrum2.java
new file mode 100644 (file)
index 0000000..c1d62c0
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+
+public class AltosEepromMetrum2 extends AltosEeprom {
+       public static final int record_length = 16;
+
+       public int record_length() { return record_length; }
+
+       /* AO_LOG_FLIGHT elements */
+       public int flight() { return data16(0); }
+       public int ground_accel() { return data16(2); }
+       public int ground_pres() { return data32(4); }
+       public int ground_temp() { return data32(8); }
+
+       /* AO_LOG_STATE elements */
+       public int state() { return data16(0); }
+       public int reason() { return data16(2); }
+
+       /* AO_LOG_SENSOR elements */
+       public int pres() { return data32(0); }
+       public int temp() { return data32(4); }
+       public int accel() { return data16(8); }
+
+       /* AO_LOG_TEMP_VOLT elements */
+       public int v_batt() { return data16(0); }
+       public int sense_a() { return data16(2); }
+       public int sense_m() { return data16(4); }
+
+       /* AO_LOG_GPS_POS elements */
+       public int latitude() { return data32(0); }
+       public int longitude() { return data32(4); }
+       public int altitude() { return data16(8); }
+
+       /* AO_LOG_GPS_TIME elements */
+       public int hour() { return data8(0); }
+       public int minute() { return data8(1); }
+       public int second() { return data8(2); }
+       public int flags() { return data8(3); }
+       public int year() { return data8(4); }
+       public int month() { return data8(5); }
+       public int day() { return data8(6); }
+       
+       /* AO_LOG_GPS_SAT elements */
+       public int nsat() { return data8(0); }
+       public int more() { return data8(1); }
+       public int svid(int n) { return data8(2 + n * 2); }
+       public int c_n(int n) { return data8(2 + n * 2 + 1); }
+
+       public AltosEepromMetrum2 (AltosEepromChunk chunk, int start) throws ParseException {
+               parse_chunk(chunk, start);
+       }
+
+       public void update_state(AltosState state) {
+               super.update_state(state);
+
+               AltosGPS        gps;
+
+               /* Flush any pending GPS changes */
+               if (state.gps_pending) {
+                       switch (cmd) {
+                       case AltosLib.AO_LOG_GPS_POS:
+                       case AltosLib.AO_LOG_GPS_LAT:
+                       case AltosLib.AO_LOG_GPS_LON:
+                       case AltosLib.AO_LOG_GPS_ALT:
+                       case AltosLib.AO_LOG_GPS_SAT:
+                       case AltosLib.AO_LOG_GPS_DATE:
+                               break;
+                       default:
+                               state.set_temp_gps();
+                               break;
+                       }
+               }
+
+               switch (cmd) {
+               case AltosLib.AO_LOG_FLIGHT:
+                       state.set_flight(flight());
+                       state.set_ground_accel(ground_accel());
+                       state.set_ground_pressure(ground_pres());
+//                     state.set_temperature(ground_temp() / 100.0);
+                       break;
+               case AltosLib.AO_LOG_STATE:
+                       state.set_state(state());
+                       break;
+               case AltosLib.AO_LOG_SENSOR:
+                       state.set_ms5607(pres(), temp());
+                       state.set_accel(accel());
+
+                       break;
+               case AltosLib.AO_LOG_TEMP_VOLT:
+                       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()));
+
+                       break;
+               case AltosLib.AO_LOG_GPS_POS:
+                       gps = state.make_temp_gps(false);
+                       gps.lat = latitude() / 1e7;
+                       gps.lon = longitude() / 1e7;
+                       gps.alt = altitude();
+                       break;
+               case AltosLib.AO_LOG_GPS_TIME:
+                       gps = state.make_temp_gps(false);
+
+                       gps.hour = hour();
+                       gps.minute = minute();
+                       gps.second = second();
+
+                       int flags = flags();
+
+                       gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
+                       gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
+                       gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
+                               AltosLib.AO_GPS_NUM_SAT_SHIFT;
+
+                       gps.year = 2000 + year();
+                       gps.month = month();
+                       gps.day = day();
+                       break;
+               case AltosLib.AO_LOG_GPS_SAT:
+                       gps = state.make_temp_gps(true);
+
+                       int n = nsat();
+                       for (int i = 0; i < n; i++)
+                               gps.add_sat(svid(i), c_n(i));
+                       break;
+               }
+       }
+
+       public AltosEepromMetrum2 (String line) {
+               parse_string(line);
+       }
+
+       static public LinkedList<AltosEeprom> read(FileInputStream input) {
+               LinkedList<AltosEeprom> metrums = new LinkedList<AltosEeprom>();
+
+               for (;;) {
+                       try {
+                               String line = AltosLib.gets(input);
+                               if (line == null)
+                                       break;
+                               try {
+                                       AltosEepromMetrum2 metrum = new AltosEepromMetrum2(line);
+                                       
+                                       if (metrum.cmd != AltosLib.AO_LOG_INVALID)
+                                               metrums.add(metrum);
+                               } catch (Exception e) {
+                                       System.out.printf ("exception\n");
+                               }
+                       } catch (IOException ie) {
+                               break;
+                       }
+               }
+
+               return metrums;
+       }
+}
index 215cd3d9a99eeb2461cbdf377a07890df55dfe9b..a09a62ceb6adfd4e24e95733a773c672f82367dc 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
+import java.io.*;
+import java.util.*;
 import java.text.*;
 
-public class AltosEepromMini {
-       public int      cmd;
-       public int      tick;
-       public boolean  valid;
-       public String   data;
-       public int      config_a, config_b;
-
-       public int      data8[];
-
+public class AltosEepromMini extends AltosEeprom {
        public static final int record_length = 16;
-       static final int        header_length = 4;
-       static final int        data_length = record_length - header_length;
-
-       public int data8(int i) {
-               return data8[i];
-       }
 
-       public int data16(int i) {
-               return ((data8[i] | (data8[i+1] << 8)) << 16) >> 16;
-       }
-
-       public int data24(int i) {
-               return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16);
-       }
-
-       public int data32(int i) {
-               return data8[i] | (data8[i+1] << 8) | (data8[i+2] << 16) | (data8[i+3] << 24);
-       }
+       public int record_length() { return record_length; }
 
        /* AO_LOG_FLIGHT elements */
        public int flight() { return data16(0); }
@@ -63,126 +41,39 @@ public class AltosEepromMini {
        public int sense_m() { return data16(8); }
        public int v_batt() { return data16(10); }
 
-       public AltosEepromMini (AltosEepromChunk chunk, int start) throws ParseException {
-               cmd = chunk.data(start);
-
-               valid = !chunk.erased(start, record_length);
-               if (valid) {
-                       if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
-                               throw new ParseException(String.format("invalid checksum at 0x%x",
-                                                                      chunk.address + start), 0);
-               } else {
-                       cmd = AltosLib.AO_LOG_INVALID;
-               }
+       double voltage(AltosState state, int sensor) {
+               if (state.log_format == AltosLib.AO_LOG_FORMAT_EASYMINI)
+                       return AltosConvert.easy_mini_voltage(sensor);
+               else
+                       return AltosConvert.tele_mini_voltage(sensor);
+       }
 
-               tick = chunk.data16(start+2);
+       public void update_state(AltosState state) {
+               super.update_state(state);
+
+               switch (cmd) {
+               case AltosLib.AO_LOG_FLIGHT:
+                       state.set_flight(flight());
+                       state.set_ground_pressure(ground_pres());
+                       break;
+               case AltosLib.AO_LOG_STATE:
+                       state.set_state(state());
+                       break;
+               case AltosLib.AO_LOG_SENSOR:
+                       state.set_ms5607(pres(), temp());
+                       state.set_apogee_voltage(voltage(state, sense_a()));
+                       state.set_main_voltage(voltage(state, sense_m()));
+                       state.set_battery_voltage(voltage(state, v_batt()));
+                       break;
+               }
+       }
 
-               data8 = new int[data_length];
-               for (int i = 0; i < data_length; i++)
-                       data8[i] = chunk.data(start + header_length + i);
+       public AltosEepromMini (AltosEepromChunk chunk, int start) throws ParseException {
+               parse_chunk(chunk, start);
        }
 
        public AltosEepromMini (String line) {
-               valid = false;
-               tick = 0;
-
-               if (line == null) {
-                       cmd = AltosLib.AO_LOG_INVALID;
-                       line = "";
-               } else {
-                       try {
-                               String[] tokens = line.split("\\s+");
-
-                               if (tokens[0].length() == 1) {
-                                       if (tokens.length != 2 + data_length) {
-                                               cmd = AltosLib.AO_LOG_INVALID;
-                                               data = line;
-                                       } else {
-                                               cmd = tokens[0].codePointAt(0);
-                                               tick = Integer.parseInt(tokens[1],16);
-                                               valid = true;
-                                               data8 = new int[data_length];
-                                               for (int i = 0; i < data_length; i++)
-                                                       data8[i] = Integer.parseInt(tokens[2 + i],16);
-                                       }
-                               } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
-                                       cmd = AltosLib.AO_LOG_CONFIG_VERSION;
-                                       data = tokens[2];
-                               } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
-                                       cmd = AltosLib.AO_LOG_MAIN_DEPLOY;
-                                       config_a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
-                                       cmd = AltosLib.AO_LOG_APOGEE_DELAY;
-                                       config_a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
-                                       cmd = AltosLib.AO_LOG_RADIO_CHANNEL;
-                                       config_a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Callsign:")) {
-                                       cmd = AltosLib.AO_LOG_CALLSIGN;
-                                       data = tokens[1].replaceAll("\"","");
-                               } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
-                                       cmd = AltosLib.AO_LOG_ACCEL_CAL;
-                                       config_a = Integer.parseInt(tokens[3]);
-                                       config_b = Integer.parseInt(tokens[5]);
-                               } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
-                                       cmd = AltosLib.AO_LOG_RADIO_CAL;
-                                       config_a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) {
-                                       cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG;
-                                       config_a = Integer.parseInt(tokens[3]);
-                               } else if (tokens[0].equals("manufacturer")) {
-                                       cmd = AltosLib.AO_LOG_MANUFACTURER;
-                                       data = tokens[1];
-                               } else if (tokens[0].equals("product")) {
-                                       cmd = AltosLib.AO_LOG_PRODUCT;
-                                       data = tokens[1];
-                               } else if (tokens[0].equals("serial-number")) {
-                                       cmd = AltosLib.AO_LOG_SERIAL_NUMBER;
-                                       config_a = Integer.parseInt(tokens[1]);
-                               } else if (tokens[0].equals("log-format")) {
-                                       cmd = AltosLib.AO_LOG_LOG_FORMAT;
-                                       config_a = Integer.parseInt(tokens[1]);
-                               } else if (tokens[0].equals("software-version")) {
-                                       cmd = AltosLib.AO_LOG_SOFTWARE_VERSION;
-                                       data = tokens[1];
-                               } else if (tokens[0].equals("ms5607")) {
-                                       if (tokens[1].equals("reserved:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_RESERVED;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("sens:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_SENS;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("off:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_OFF;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("tcs:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_TCS;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("tco:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_TCO;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("tref:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_TREF;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("tempsens:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_TEMPSENS;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else if (tokens[1].equals("crc:")) {
-                                               cmd = AltosLib.AO_LOG_BARO_CRC;
-                                               config_a = Integer.parseInt(tokens[2]);
-                                       } else {
-                                               cmd = AltosLib.AO_LOG_INVALID;
-                                               data = line;
-                                       }
-                               } else {
-                                       cmd = AltosLib.AO_LOG_INVALID;
-                                       data = line;
-                               }
-                       } catch (NumberFormatException ne) {
-                               cmd = AltosLib.AO_LOG_INVALID;
-                               data = line;
-                       }
-               }
+               parse_string(line);
        }
 
        public AltosEepromMini(int in_cmd, int in_tick) {
@@ -190,4 +81,22 @@ public class AltosEepromMini {
                tick = in_tick;
                valid = true;
        }
+
+       static public LinkedList<AltosEeprom> read(FileInputStream input) {
+               LinkedList<AltosEeprom> minis = new LinkedList<AltosEeprom>();
+
+               for (;;) {
+                       try {
+                               String line = AltosLib.gets(input);
+                               if (line == null)
+                                       break;
+                               AltosEepromMini mini = new AltosEepromMini(line);
+                               minis.add(mini);
+                       } catch (IOException ie) {
+                               break;
+                       }
+               }
+
+               return minis;
+       }
 }
diff --git a/altoslib/AltosEepromMiniIterable.java b/altoslib/AltosEepromMiniIterable.java
deleted file mode 100644 (file)
index 1f22118..0000000
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * 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 org.altusmetrum.altoslib_1;
-
-import java.io.*;
-import java.util.*;
-import java.text.*;
-
-public class AltosEepromMiniIterable extends AltosRecordIterable {
-
-       static final int        seen_flight = 1;
-       static final int        seen_sensor = 2;
-
-       static final int        seen_basic = seen_flight|seen_sensor;
-
-       boolean                 has_accel;
-       boolean                 has_gps;
-       boolean                 has_ignite;
-
-       AltosEepromMini flight_record;
-
-       TreeSet<AltosOrderedMiniRecord> records;
-
-       AltosMs5607             baro;
-
-       LinkedList<AltosRecord> list;
-
-       class EepromState {
-               int     seen;
-               int     n_pad_samples;
-               double  ground_pres;
-               int     boost_tick;
-               int     sensor_tick;
-
-               EepromState() {
-                       seen = 0;
-                       n_pad_samples = 0;
-                       ground_pres = 0.0;
-               }
-       }
-
-       void update_state(AltosRecordMini state, AltosEepromMini record, EepromState eeprom) {
-               state.tick = record.tick;
-               switch (record.cmd) {
-               case AltosLib.AO_LOG_FLIGHT:
-                       eeprom.seen |= seen_flight;
-                       state.ground_pres = record.ground_pres();
-                       state.flight_pres = state.ground_pres;
-                       state.flight = record.data16(0);
-                       eeprom.boost_tick = record.tick;
-                       break;
-               case AltosLib.AO_LOG_SENSOR:
-                       baro.set(record.pres(), record.temp());
-                       state.pres = baro.pa;
-                       state.temp = baro.cc;
-                       state.sense_m = record.sense_m();
-                       state.sense_a = record.sense_a();
-                       state.v_batt = record.v_batt();
-                       if (state.state < AltosLib.ao_flight_boost) {
-                               eeprom.n_pad_samples++;
-                               eeprom.ground_pres += state.pres;
-                               state.ground_pres = (int) (eeprom.ground_pres / eeprom.n_pad_samples);
-                               state.flight_pres = state.ground_pres;
-                       } else {
-                               state.flight_pres = (state.flight_pres * 15 + state.pres) / 16;
-                       }
-                       if ((eeprom.seen & seen_sensor) == 0)
-                               eeprom.sensor_tick = record.tick - 1;
-                       eeprom.seen |= seen_sensor;
-                       eeprom.sensor_tick = record.tick;
-                       break;
-               case AltosLib.AO_LOG_STATE:
-                       state.state = record.state();
-                       break;
-               case AltosLib.AO_LOG_CONFIG_VERSION:
-                       break;
-               case AltosLib.AO_LOG_MAIN_DEPLOY:
-                       break;
-               case AltosLib.AO_LOG_APOGEE_DELAY:
-                       break;
-               case AltosLib.AO_LOG_RADIO_CHANNEL:
-                       break;
-               case AltosLib.AO_LOG_CALLSIGN:
-                       state.callsign = record.data;
-                       break;
-               case AltosLib.AO_LOG_RADIO_CAL:
-                       break;
-               case AltosLib.AO_LOG_MANUFACTURER:
-                       break;
-               case AltosLib.AO_LOG_PRODUCT:
-                       break;
-               case AltosLib.AO_LOG_SERIAL_NUMBER:
-                       state.serial = record.config_a;
-                       break;
-               case AltosLib.AO_LOG_SOFTWARE_VERSION:
-                       break;
-               case AltosLib.AO_LOG_BARO_RESERVED:
-                       baro.reserved = record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_SENS:
-                       baro.sens =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_OFF:
-                       baro.off =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_TCS:
-                       baro.tcs =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_TCO:
-                       baro.tco =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_TREF:
-                       baro.tref =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_TEMPSENS:
-                       baro.tempsens =record.config_a;
-                       break;
-               case AltosLib.AO_LOG_BARO_CRC:
-                       baro.crc =record.config_a;
-                       break;
-               }
-               state.seen |= eeprom.seen;
-       }
-
-       LinkedList<AltosRecord> make_list() {
-               LinkedList<AltosRecord>         list = new LinkedList<AltosRecord>();
-               Iterator<AltosOrderedMiniRecord> iterator = records.iterator();
-               AltosOrderedMiniRecord          record = null;
-               AltosRecordMini                 state = new AltosRecordMini();
-               //boolean                       last_reported = false;
-               EepromState                     eeprom = new EepromState();
-
-               state.state = AltosLib.ao_flight_pad;
-
-               /* Pull in static data from the flight records */
-               if (flight_record != null)
-                       update_state(state, flight_record, eeprom);
-
-               while (iterator.hasNext()) {
-                       record = iterator.next();
-                       if ((eeprom.seen & seen_basic) == seen_basic && record.tick != state.tick) {
-                               AltosRecordMini r = state.clone();
-                               r.time = (r.tick - eeprom.boost_tick) / 100.0;
-                               list.add(r);
-                       }
-                       update_state(state, record, eeprom);
-               }
-               AltosRecordMini r = state.clone();
-               r.time = (r.tick - eeprom.boost_tick) / 100.0;
-               list.add(r);
-               return list;
-       }
-
-       public Iterator<AltosRecord> iterator() {
-               if (list == null)
-                       list = make_list();
-               return list.iterator();
-       }
-
-       public boolean has_gps() { return has_gps; }
-       public boolean has_accel() { return has_accel; }
-       public boolean has_ignite() { return has_ignite; }
-
-       public void write_comments(PrintStream out) {
-               Iterator<AltosOrderedMiniRecord>        iterator = records.iterator();
-               out.printf("# Comments\n");
-               while (iterator.hasNext()) {
-                       AltosOrderedMiniRecord  record = iterator.next();
-                       switch (record.cmd) {
-                       case AltosLib.AO_LOG_CONFIG_VERSION:
-                               out.printf("# Config version: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_MAIN_DEPLOY:
-                               out.printf("# Main deploy: %s\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_APOGEE_DELAY:
-                               out.printf("# Apogee delay: %s\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_RADIO_CHANNEL:
-                               out.printf("# Radio channel: %s\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_CALLSIGN:
-                               out.printf("# Callsign: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_ACCEL_CAL:
-                               out.printf ("# Accel cal: %d %d\n", record.config_a, record.config_b);
-                               break;
-                       case AltosLib.AO_LOG_RADIO_CAL:
-                               out.printf ("# Radio cal: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_MAX_FLIGHT_LOG:
-                               out.printf ("# Max flight log: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_MANUFACTURER:
-                               out.printf ("# Manufacturer: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_PRODUCT:
-                               out.printf ("# Product: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_SERIAL_NUMBER:
-                               out.printf ("# Serial number: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_SOFTWARE_VERSION:
-                               out.printf ("# Software version: %s\n", record.data);
-                               break;
-                       case AltosLib.AO_LOG_BARO_RESERVED:
-                               out.printf ("# Baro reserved: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_SENS:
-                               out.printf ("# Baro sens: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_OFF:
-                               out.printf ("# Baro off: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TCS:
-                               out.printf ("# Baro tcs: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TCO:
-                               out.printf ("# Baro tco: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TREF:
-                               out.printf ("# Baro tref: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_TEMPSENS:
-                               out.printf ("# Baro tempsens: %d\n", record.config_a);
-                               break;
-                       case AltosLib.AO_LOG_BARO_CRC:
-                               out.printf ("# Baro crc: %d\n", record.config_a);
-                               break;
-                       }
-               }
-       }
-
-       /*
-        * Read the whole file, dumping records into a RB tree so
-        * we can enumerate them in time order -- the eeprom data
-        * are sometimes out of order
-        */
-       public AltosEepromMiniIterable (FileInputStream input) {
-               records = new TreeSet<AltosOrderedMiniRecord>();
-
-               AltosOrderedMiniRecord last_gps_time = null;
-
-               baro = new AltosMs5607();
-
-               int index = 0;
-               int prev_tick = 0;
-               boolean prev_tick_valid = false;
-               boolean missing_time = false;
-
-               try {
-                       for (;;) {
-                               String line = AltosLib.gets(input);
-                               if (line == null)
-                                       break;
-                               AltosOrderedMiniRecord record = new AltosOrderedMiniRecord(line, index++, prev_tick, prev_tick_valid);
-                               if (record.cmd == AltosLib.AO_LOG_INVALID)
-                                       continue;
-                               prev_tick = record.tick;
-                               if (record.cmd < AltosLib.AO_LOG_CONFIG_VERSION)
-                                       prev_tick_valid = true;
-                               if (record.cmd == AltosLib.AO_LOG_FLIGHT) {
-                                       flight_record = record;
-                                       continue;
-                               }
-
-                               records.add(record);
-
-                               /* Bail after reading the 'landed' record; we're all done */
-                               if (record.cmd == AltosLib.AO_LOG_STATE &&
-                                   record.state() == AltosLib.ao_flight_landed)
-                                       break;
-                       }
-               } catch (IOException io) {
-               } catch (ParseException pe) {
-               }
-               try {
-                       input.close();
-               } catch (IOException ie) {
-               }
-       }
-}
diff --git a/altoslib/AltosEepromRecord.java b/altoslib/AltosEepromRecord.java
deleted file mode 100644 (file)
index 70ac111..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * 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 org.altusmetrum.altoslib_1;
-
-import java.text.*;
-
-public class AltosEepromRecord {
-       public int      cmd;
-       public int      tick;
-       public int      a;
-       public int      b;
-       public String   data;
-       public boolean  tick_valid;
-
-       public static final int record_length = 8;
-
-       public AltosEepromRecord (AltosEepromChunk chunk, int start) throws ParseException {
-
-               cmd = chunk.data(start);
-               tick_valid = true;
-
-               tick_valid = !chunk.erased(start, record_length);
-               if (tick_valid) {
-                       if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
-                               throw new ParseException(String.format("invalid checksum at 0x%x",
-                                                                      chunk.address + start), 0);
-               } else {
-                       cmd = AltosLib.AO_LOG_INVALID;
-               }
-
-               tick = chunk.data16(start + 2);
-               a = chunk.data16(start + 4);
-               b = chunk.data16(start + 6);
-
-               data = null;
-       }
-
-       public AltosEepromRecord (String line) {
-               tick_valid = false;
-               tick = 0;
-               a = 0;
-               b = 0;
-               data = null;
-               if (line == null) {
-                       cmd = AltosLib.AO_LOG_INVALID;
-                       data = "";
-               } else {
-                       try {
-                               String[] tokens = line.split("\\s+");
-
-                               if (tokens[0].length() == 1) {
-                                       if (tokens.length != 4) {
-                                               cmd = AltosLib.AO_LOG_INVALID;
-                                               data = line;
-                                       } else {
-                                               cmd = tokens[0].codePointAt(0);
-                                               tick = Integer.parseInt(tokens[1],16);
-                                               tick_valid = true;
-                                               a = Integer.parseInt(tokens[2],16);
-                                               b = Integer.parseInt(tokens[3],16);
-                                       }
-                               } else if (tokens[0].equals("Config") && tokens[1].equals("version:")) {
-                                       cmd = AltosLib.AO_LOG_CONFIG_VERSION;
-                                       data = tokens[2];
-                               } else if (tokens[0].equals("Main") && tokens[1].equals("deploy:")) {
-                                       cmd = AltosLib.AO_LOG_MAIN_DEPLOY;
-                                       a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Apogee") && tokens[1].equals("delay:")) {
-                                       cmd = AltosLib.AO_LOG_APOGEE_DELAY;
-                                       a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Radio") && tokens[1].equals("channel:")) {
-                                       cmd = AltosLib.AO_LOG_RADIO_CHANNEL;
-                                       a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Callsign:")) {
-                                       cmd = AltosLib.AO_LOG_CALLSIGN;
-                                       data = tokens[1].replaceAll("\"","");
-                               } else if (tokens[0].equals("Accel") && tokens[1].equals("cal")) {
-                                       cmd = AltosLib.AO_LOG_ACCEL_CAL;
-                                       a = Integer.parseInt(tokens[3]);
-                                       b = Integer.parseInt(tokens[5]);
-                               } else if (tokens[0].equals("Radio") && tokens[1].equals("cal:")) {
-                                       cmd = AltosLib.AO_LOG_RADIO_CAL;
-                                       a = Integer.parseInt(tokens[2]);
-                               } else if (tokens[0].equals("Max") && tokens[1].equals("flight") && tokens[2].equals("log:")) {
-                                       cmd = AltosLib.AO_LOG_MAX_FLIGHT_LOG;
-                                       a = Integer.parseInt(tokens[3]);
-                               } else if (tokens[0].equals("manufacturer")) {
-                                       cmd = AltosLib.AO_LOG_MANUFACTURER;
-                                       data = tokens[1];
-                               } else if (tokens[0].equals("product")) {
-                                       cmd = AltosLib.AO_LOG_PRODUCT;
-                                       data = tokens[1];
-                               } else if (tokens[0].equals("serial-number")) {
-                                       cmd = AltosLib.AO_LOG_SERIAL_NUMBER;
-                                       a = Integer.parseInt(tokens[1]);
-                               } else if (tokens[0].equals("log-format")) {
-                                       cmd = AltosLib.AO_LOG_LOG_FORMAT;
-                                       a = Integer.parseInt(tokens[1]);
-                               } else if (tokens[0].equals("software-version")) {
-                                       cmd = AltosLib.AO_LOG_SOFTWARE_VERSION;
-                                       data = tokens[1];
-                               } else {
-                                       cmd = AltosLib.AO_LOG_INVALID;
-                                       data = line;
-                               }
-                       } catch (NumberFormatException ne) {
-                               cmd = AltosLib.AO_LOG_INVALID;
-                               data = line;
-                       }
-               }
-       }
-
-       public AltosEepromRecord(int in_cmd, int in_tick, int in_a, int in_b) {
-               tick_valid = true;
-               cmd = in_cmd;
-               tick = in_tick;
-               a = in_a;
-               b = in_b;
-       }
-}
diff --git a/altoslib/AltosEepromTM.java b/altoslib/AltosEepromTM.java
new file mode 100644 (file)
index 0000000..3680391
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+
+public class AltosEepromTM extends AltosEeprom {
+       public int      a;
+       public int      b;
+
+       public static final int record_length = 8;
+
+       public void write(PrintStream out) {
+               out.printf("%c %4x %4x %4x\n", cmd, tick, a, b);
+       }
+
+       public int record_length() { return record_length; }
+
+       public String string() {
+               return String.format("%c %4x %4x %4x\n", cmd, tick, a, b);
+       }
+
+       public void update_state(AltosState state) {
+               super.update_state(state);
+
+               AltosGPS        gps;
+
+               /* Flush any pending GPS changes */
+               if (state.gps_pending) {
+                       switch (cmd) {
+                       case AltosLib.AO_LOG_GPS_LAT:
+                       case AltosLib.AO_LOG_GPS_LON:
+                       case AltosLib.AO_LOG_GPS_ALT:
+                       case AltosLib.AO_LOG_GPS_SAT:
+                       case AltosLib.AO_LOG_GPS_DATE:
+                               break;
+                       default:
+                               state.set_temp_gps();
+                               break;
+                       }
+               }
+
+               switch (cmd) {
+               case AltosLib.AO_LOG_FLIGHT:
+                       state.set_state(AltosLib.ao_flight_pad);
+                       state.set_ground_accel(a);
+                       state.set_flight(b);
+                       state.set_boost_tick(tick);
+                       break;
+               case AltosLib.AO_LOG_SENSOR:
+                       state.set_accel(a);
+                       state.set_pressure(AltosConvert.barometer_to_pressure(b));
+                       break;
+               case AltosLib.AO_LOG_PRESSURE:
+                       state.set_pressure(AltosConvert.barometer_to_pressure(b));
+                       break;
+               case AltosLib.AO_LOG_TEMP_VOLT:
+                       state.set_temperature(AltosConvert.thermometer_to_temperature(a));
+                       state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(b));
+                       break;
+               case AltosLib.AO_LOG_DEPLOY:
+                       state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(a));
+                       state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(b));
+                       break;
+               case AltosLib.AO_LOG_STATE:
+                       state.set_state(a);
+                       break;
+               case AltosLib.AO_LOG_GPS_TIME:
+                       gps = state.make_temp_gps(false);
+
+                       gps.hour = (a & 0xff);
+                       gps.minute = (a >> 8);
+                       gps.second = (b & 0xff);
+
+                       int flags = (b >> 8);
+
+                       gps.connected = (flags & AltosLib.AO_GPS_RUNNING) != 0;
+                       gps.locked = (flags & AltosLib.AO_GPS_VALID) != 0;
+                       gps.nsat = (flags & AltosLib.AO_GPS_NUM_SAT_MASK) >>
+                               AltosLib.AO_GPS_NUM_SAT_SHIFT;
+                       break;
+               case AltosLib.AO_LOG_GPS_LAT:
+                       gps = state.make_temp_gps(false);
+
+                       int lat32 = a | (b << 16);
+                       gps.lat = (double) lat32 / 1e7;
+                       break;
+               case AltosLib.AO_LOG_GPS_LON:
+                       gps = state.make_temp_gps(false);
+
+                       int lon32 = a | (b << 16);
+                       gps.lon = (double) lon32 / 1e7;
+                       break;
+               case AltosLib.AO_LOG_GPS_ALT:
+                       gps = state.make_temp_gps(false);
+                       gps.alt = a;
+                       break;
+               case AltosLib.AO_LOG_GPS_SAT:
+                       gps = state.make_temp_gps(true);
+                       int svid = a;
+                       int c_n0 = b >> 8;
+                       gps.add_sat(svid, c_n0);
+                       break;
+               case AltosLib.AO_LOG_GPS_DATE:
+                       gps = state.make_temp_gps(false);
+                       gps.year = (a & 0xff) + 2000;
+                       gps.month = a >> 8;
+                       gps.day = b & 0xff;
+                       break;
+               }
+       }
+
+       public AltosEepromTM (AltosEepromChunk chunk, int start) throws ParseException {
+
+               cmd = chunk.data(start);
+               valid = true;
+
+               valid = !chunk.erased(start, record_length);
+               if (valid) {
+                       if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
+                               throw new ParseException(String.format("invalid checksum at 0x%x",
+                                                                      chunk.address + start), 0);
+               } else {
+                       cmd = AltosLib.AO_LOG_INVALID;
+               }
+
+               tick = chunk.data16(start + 2);
+               a = chunk.data16(start + 4);
+               b = chunk.data16(start + 6);
+       }
+
+       public AltosEepromTM (String line) {
+               valid = false;
+               tick = 0;
+               a = 0;
+               b = 0;
+               if (line == null) {
+                       cmd = AltosLib.AO_LOG_INVALID;
+               } else {
+                       try {
+                               String[] tokens = line.split("\\s+");
+
+                               if (tokens[0].length() == 1) {
+                                       if (tokens.length != 4) {
+                                               cmd = AltosLib.AO_LOG_INVALID;
+                                       } else {
+                                               cmd = tokens[0].codePointAt(0);
+                                               tick = Integer.parseInt(tokens[1],16);
+                                               valid = true;
+                                               a = Integer.parseInt(tokens[2],16);
+                                               b = Integer.parseInt(tokens[3],16);
+                                       }
+                               } else {
+                                       cmd = AltosLib.AO_LOG_INVALID;
+                               }
+                       } catch (NumberFormatException ne) {
+                               cmd = AltosLib.AO_LOG_INVALID;
+                       }
+               }
+       }
+
+       public AltosEepromTM(int in_cmd, int in_tick, int in_a, int in_b) {
+               valid = true;
+               cmd = in_cmd;
+               tick = in_tick;
+               a = in_a;
+               b = in_b;
+       }
+
+       static public LinkedList<AltosEeprom> read(FileInputStream input) {
+               LinkedList<AltosEeprom> tms = new LinkedList<AltosEeprom>();
+
+               for (;;) {
+                       try {
+                               String line = AltosLib.gets(input);
+                               if (line == null)
+                                       break;
+                               AltosEepromTM tm = new AltosEepromTM(line);
+                               tms.add(tm);
+                       } catch (IOException ie) {
+                               break;
+                       }
+               }
+
+               return tms;
+       }
+
+}
diff --git a/altoslib/AltosEepromTeleScience.java b/altoslib/AltosEepromTeleScience.java
deleted file mode 100644 (file)
index 2a828cf..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-import java.text.*;
-
-public class AltosEepromTeleScience {
-       public int      type;
-       public int      tick;
-       public int      tm_state;
-       public int      tm_tick;
-       public int[]    data;
-       public boolean  valid;
-
-       public static final int AO_LOG_TELESCIENCE_START = 's';
-       public static final int AO_LOG_TELESCIENCE_DATA = 'd';
-
-       static final int        max_data = 12;
-       public static final int record_length = 32;
-
-       public AltosEepromTeleScience (AltosEepromChunk chunk, int start) throws ParseException {
-               type = chunk.data(start);
-
-               valid = !chunk.erased(start, record_length);
-               if (valid) {
-                       if (AltosConvert.checksum(chunk.data, start, record_length) != 0)
-                               throw new ParseException(String.format("invalid checksum at 0x%x",
-                                                                      chunk.address + start), 0);
-               } else {
-                       type = AltosLib.AO_LOG_INVALID;
-               }
-
-               tick = chunk.data16(start+2);
-               tm_tick = chunk.data16(start+4);
-               tm_state = chunk.data(start+6);
-               data = new int[max_data];
-               for (int i = 0; i < max_data; i++)
-                       data[i] = chunk.data16(start + 8 + i * 2);
-       }
-}
diff --git a/altoslib/AltosEepromTm.java b/altoslib/AltosEepromTm.java
new file mode 100644 (file)
index 0000000..b891413
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ * 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+
+public class AltosEepromTm extends AltosEeprom {
+       public int      i;
+       public int      a;
+       public int      b;
+
+       public static final int record_length = 2;
+
+       public void write(PrintStream out) {
+               out.printf("%c %4x %4x %4x\n", cmd, tick, a, b);
+       }
+
+       public int record_length() { return record_length; }
+
+       public String string() {
+               return String.format("%c %4x %4x %4x\n", cmd, tick, a, b);
+       }
+
+       public void update_state(AltosState state) {
+               super.update_state(state);
+
+               switch (cmd) {
+               case AltosLib.AO_LOG_FLIGHT:
+                       state.set_state(AltosLib.ao_flight_boost);
+                       state.set_flight(b);
+                       break;
+               case AltosLib.AO_LOG_PRESSURE:
+                       if (tick == 0)
+                               state.set_ground_pressure(AltosConvert.barometer_to_pressure(b));
+                       else
+                               state.set_pressure(AltosConvert.barometer_to_pressure(b));
+                       break;
+               case AltosLib.AO_LOG_STATE:
+                       state.set_state(a);
+                       break;
+               }
+       }
+
+       public AltosEepromTm (AltosEepromChunk chunk, int start, AltosState state) throws ParseException {
+               int     value = chunk.data16(start);
+
+               int     i = (chunk.address + start) / record_length;
+
+               cmd = chunk.data(start);
+               valid = true;
+
+               valid = !chunk.erased(start, record_length);
+
+               switch (i) {
+               case 0:
+                       cmd = AltosLib.AO_LOG_FLIGHT;
+                       tick = 0;
+                       a = 0;
+                       b = value;
+                       break;
+               case 1:
+                       cmd = AltosLib.AO_LOG_PRESSURE;
+                       tick = 0;
+                       a = 0;
+                       b = value;
+                       break;
+               default:
+                       if ((value & 0x8000) != 0) {
+                               cmd = AltosLib.AO_LOG_STATE;
+                               tick = state.tick;
+                               a = value & 0x7fff;
+                               b = 0;
+                       } else {
+                               if (state.ascent)
+                                       tick = state.tick + 10;
+                               else
+                                       tick = state.tick + 100;
+                               cmd = AltosLib.AO_LOG_PRESSURE;
+                               a = 0;
+                               b = value;
+                       }
+                       break;
+               }
+       }
+
+       public AltosEepromTm (String line) {
+               valid = false;
+               tick = 0;
+               a = 0;
+               b = 0;
+               if (line == null) {
+                       cmd = AltosLib.AO_LOG_INVALID;
+               } else {
+                       try {
+                               String[] tokens = line.split("\\s+");
+
+                               if (tokens[0].length() == 1) {
+                                       if (tokens.length != 4) {
+                                               cmd = AltosLib.AO_LOG_INVALID;
+                                       } else {
+                                               cmd = tokens[0].codePointAt(0);
+                                               tick = Integer.parseInt(tokens[1],16);
+                                               valid = true;
+                                               a = Integer.parseInt(tokens[2],16);
+                                               b = Integer.parseInt(tokens[3],16);
+                                       }
+                               } else {
+                                       cmd = AltosLib.AO_LOG_INVALID;
+                               }
+                       } catch (NumberFormatException ne) {
+                               cmd = AltosLib.AO_LOG_INVALID;
+                       }
+               }
+       }
+
+       public AltosEepromTm(int in_cmd, int in_tick, int in_a, int in_b) {
+               valid = true;
+               cmd = in_cmd;
+               tick = in_tick;
+               a = in_a;
+               b = in_b;
+       }
+
+       static public LinkedList<AltosEeprom> read(FileInputStream input) {
+               LinkedList<AltosEeprom> tms = new LinkedList<AltosEeprom>();
+
+               for (;;) {
+                       try {
+                               String line = AltosLib.gets(input);
+                               if (line == null)
+                                       break;
+                               AltosEepromTm tm = new AltosEepromTm(line);
+                               tms.add(tm);
+                       } catch (IOException ie) {
+                               break;
+                       }
+               }
+
+               return tms;
+       }
+
+}
index 90dbc6dbea8ecf069dbedbf530b88e33ee865ea3..f39c3962a3f42b7e56dd2510a9c05dee871ff2b6 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1
+package org.altusmetrum.altoslib_2
 
 import java.io.File;
 import java.util.*;
 
 public class AltosFile extends File {
 
-       public AltosFile(int year, int month, int day, int serial, int flight, String extension) {
+       static String number(int n) {
+               if (n == AltosLib.MISSING)
+                       return "unkn";
+               else
+                       return String.format("%04d", n);
+       }
+
+       static String receiver(int receiver) {
+               if (receiver == AltosLib.MISSING)
+                       return "";
+               return String.format("-via-%04d", receiver);
+       }
+
+       public AltosFile(int year, int month, int day, int serial, int flight, int receiver, String extension) {
                super (AltosPreferences.logdir(),
-                      String.format("%04d-%02d-%02d-serial-%03d-flight-%03d.%s",
-                                    year, month, day, serial, flight, extension));
+                      String.format("%04d-%02d-%02d-serial-%s-flight-%s%s.%s",
+                                    year, month, day, number(serial), number(flight), receiver(receiver), extension));
+       }
+
+       public AltosFile(int year, int month, int day, int serial, int flight, String extension) {
+               this(year, month, day, serial, flight, AltosLib.MISSING, extension);
+       }
+
+       public AltosFile(int serial, int flight, int receiver, String extension) {
+               this(Calendar.getInstance().get(Calendar.YEAR),
+                    Calendar.getInstance().get(Calendar.MONTH) + 1,
+                    Calendar.getInstance().get(Calendar.DAY_OF_MONTH),
+                    serial,
+                    flight,
+                    receiver,
+                    extension);
        }
 
        public AltosFile(int serial, int flight, String extension) {
@@ -34,10 +61,11 @@ public class AltosFile extends File {
                     Calendar.getInstance().get(Calendar.DAY_OF_MONTH),
                     serial,
                     flight,
+                    AltosLib.MISSING,
                     extension);
        }
 
-       public AltosFile(AltosRecord telem) {
-               this(telem.serial, telem.flight, "telem");
+       public AltosFile(AltosState state) {
+               this(state.serial, state.flight, state.receiver_serial, "telem");
        }
 }
index 010274b944884ecf1e3339aad5f72a3e3221d18d..d806915797b7362512e5bd0d6643def2b9b0f342 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 
index ab50b74a6093799f9322071cf9dc1475fe32b8c4..777ae635bf3ec24475ec3bda2b80d44df98fd941 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public interface AltosFlashListener {
        public void position(String label, int percent);
index 345266588f5b16e75ff5d73b9b93761ececbf9d5..4a722e42ac5b0e6f27c1b96e9de484e14cc43029 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.text.*;
 import java.io.*;
@@ -28,7 +28,7 @@ public class AltosFlightReader {
 
        public void init() { }
 
-       public AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; }
+       public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; }
 
        public void close(boolean interrupted) { }
 
@@ -48,5 +48,5 @@ public class AltosFlightReader {
 
        public boolean has_monitor_battery() { return false; }
 
-       public double monitor_battery() { return AltosRecord.MISSING; }
+       public double monitor_battery() { return AltosLib.MISSING; }
 }
index 484a2fd9d56e084f99c130185bf33fb2ad21711a..ece7525ad848d78408d432c328dac7235c6d3ece 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosFrequency {
        public double   frequency;
index f23842f3d947c09b135bbfabef197111a1ab9a71..1d5b0755982a0d9a194d492dd6d22ec4322d7308 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.text.*;
+import java.util.concurrent.*;
 
-public class AltosGPS {
+public class AltosGPS implements Cloneable {
 
-       public final static int MISSING = AltosRecord.MISSING;
+       public final static int MISSING = AltosLib.MISSING;
 
        public int      nsat;
        public boolean  locked;
        public boolean  connected;
        public double   lat;            /* degrees (+N -S) */
        public double   lon;            /* degrees (+E -W) */
-       public int      alt;            /* m */
+       public double   alt;            /* m */
        public int      year;
        public int      month;
        public int      day;
@@ -65,40 +66,40 @@ public class AltosGPS {
        }
 
        public void ClearGPSTime() {
-               year = month = day = 0;
-               hour = minute = second = 0;
+               year = month = day = AltosLib.MISSING;
+               hour = minute = second = AltosLib.MISSING;
        }
 
        public AltosGPS(AltosTelemetryMap map) throws ParseException {
-               String  state = map.get_string(AltosTelemetry.AO_TELEM_GPS_STATE,
-                                              AltosTelemetry.AO_TELEM_GPS_STATE_ERROR);
+               String  state = map.get_string(AltosTelemetryLegacy.AO_TELEM_GPS_STATE,
+                                              AltosTelemetryLegacy.AO_TELEM_GPS_STATE_ERROR);
 
-               nsat = map.get_int(AltosTelemetry.AO_TELEM_GPS_NUM_SAT, 0);
-               if (state.equals(AltosTelemetry.AO_TELEM_GPS_STATE_LOCKED)) {
+               nsat = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_NUM_SAT, 0);
+               if (state.equals(AltosTelemetryLegacy.AO_TELEM_GPS_STATE_LOCKED)) {
                        connected = true;
                        locked = true;
-                       lat = map.get_double(AltosTelemetry.AO_TELEM_GPS_LATITUDE, MISSING, 1.0e-7);
-                       lon = map.get_double(AltosTelemetry.AO_TELEM_GPS_LONGITUDE, MISSING, 1.0e-7);
-                       alt = map.get_int(AltosTelemetry.AO_TELEM_GPS_ALTITUDE, MISSING);
-                       year = map.get_int(AltosTelemetry.AO_TELEM_GPS_YEAR, MISSING);
+                       lat = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_LATITUDE, MISSING, 1.0e-7);
+                       lon = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_LONGITUDE, MISSING, 1.0e-7);
+                       alt = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_ALTITUDE, MISSING);
+                       year = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_YEAR, MISSING);
                        if (year != MISSING)
                                year += 2000;
-                       month = map.get_int(AltosTelemetry.AO_TELEM_GPS_MONTH, MISSING);
-                       day = map.get_int(AltosTelemetry.AO_TELEM_GPS_DAY, MISSING);
-
-                       hour = map.get_int(AltosTelemetry.AO_TELEM_GPS_HOUR, 0);
-                       minute = map.get_int(AltosTelemetry.AO_TELEM_GPS_MINUTE, 0);
-                       second = map.get_int(AltosTelemetry.AO_TELEM_GPS_SECOND, 0);
-
-                       ground_speed = map.get_double(AltosTelemetry.AO_TELEM_GPS_HORIZONTAL_SPEED,
-                                                     AltosRecord.MISSING, 1/100.0);
-                       course = map.get_int(AltosTelemetry.AO_TELEM_GPS_COURSE,
-                                            AltosRecord.MISSING);
-                       hdop = map.get_double(AltosTelemetry.AO_TELEM_GPS_HDOP, MISSING, 1.0);
-                       vdop = map.get_double(AltosTelemetry.AO_TELEM_GPS_VDOP, MISSING, 1.0);
-                       h_error = map.get_int(AltosTelemetry.AO_TELEM_GPS_HERROR, MISSING);
-                       v_error = map.get_int(AltosTelemetry.AO_TELEM_GPS_VERROR, MISSING);
-               } else if (state.equals(AltosTelemetry.AO_TELEM_GPS_STATE_UNLOCKED)) {
+                       month = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_MONTH, MISSING);
+                       day = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_DAY, MISSING);
+
+                       hour = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_HOUR, 0);
+                       minute = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_MINUTE, 0);
+                       second = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_SECOND, 0);
+
+                       ground_speed = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_HORIZONTAL_SPEED,
+                                                     AltosLib.MISSING, 1/100.0);
+                       course = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_COURSE,
+                                            AltosLib.MISSING);
+                       hdop = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_HDOP, MISSING, 1.0);
+                       vdop = map.get_double(AltosTelemetryLegacy.AO_TELEM_GPS_VDOP, MISSING, 1.0);
+                       h_error = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_HERROR, MISSING);
+                       v_error = map.get_int(AltosTelemetryLegacy.AO_TELEM_GPS_VERROR, MISSING);
+               } else if (state.equals(AltosTelemetryLegacy.AO_TELEM_GPS_STATE_UNLOCKED)) {
                        connected = true;
                        locked = false;
                } else {
@@ -107,6 +108,62 @@ public class AltosGPS {
                }
        }
 
+       public boolean parse_string (String line, boolean says_done) {
+               String[] bits = line.split("\\s+");
+               if (bits.length == 0)
+                       return false;
+               if (line.startsWith("Date:")) {
+                       if (bits.length < 2)
+                               return false;
+                       String[] d = bits[1].split("/");
+                       if (d.length < 3)
+                               return false;
+                       year = Integer.parseInt(d[0]) + 2000;
+                       month = Integer.parseInt(d[1]);
+                       day = Integer.parseInt(d[2]);
+               } else if (line.startsWith("Time:")) {
+                       if (bits.length < 2)
+                               return false;
+                       String[] d = bits[1].split(":");
+                       if (d.length < 3)
+                               return false;
+                       hour = Integer.parseInt(d[0]);
+                       minute = Integer.parseInt(d[1]);
+                       second = Integer.parseInt(d[2]);
+               } else if (line.startsWith("Lat/Lon:")) {
+                       if (bits.length < 3)
+                               return false;
+                       lat = Integer.parseInt(bits[1]) * 1.0e-7;
+                       lon = Integer.parseInt(bits[2]) * 1.0e-7;
+               } else if (line.startsWith("Alt:")) {
+                       if (bits.length < 2)
+                               return false;
+                       alt = Integer.parseInt(bits[1]);
+               } else if (line.startsWith("Flags:")) {
+                       if (bits.length < 2)
+                               return false;
+                       int status = Integer.decode(bits[1]);
+                       connected = (status & AltosLib.AO_GPS_RUNNING) != 0;
+                       locked = (status & AltosLib.AO_GPS_VALID) != 0;
+                       if (!says_done)
+                               return false;
+               } else if (line.startsWith("Sats:")) {
+                       if (bits.length < 2)
+                               return false;
+                       nsat = Integer.parseInt(bits[1]);
+                       cc_gps_sat = new AltosGPSSat[nsat];
+                       for (int i = 0; i < nsat; i++) {
+                               int     svid = Integer.parseInt(bits[2+i*2]);
+                               int     cc_n0 = Integer.parseInt(bits[3+i*2]);
+                               cc_gps_sat[i] = new AltosGPSSat(svid, cc_n0);
+                       }
+               } else if (line.startsWith("done")) {
+                       return false;
+               } else
+                       return false;
+               return true;
+       }
+
        public AltosGPS(String[] words, int i, int version) throws ParseException {
                AltosParse.word(words[i++], "GPS");
                nsat = AltosParse.parse_int(words[i++]);
@@ -212,10 +269,46 @@ public class AltosGPS {
        }
 
        public AltosGPS() {
+               lat = AltosLib.MISSING;
+               lon = AltosLib.MISSING;
+               alt = AltosLib.MISSING;
                ClearGPSTime();
                cc_gps_sat = null;
        }
 
+       public AltosGPS clone() {
+               AltosGPS        g = new AltosGPS();
+
+               g.nsat = nsat;
+               g.locked = locked;
+               g.connected = connected;
+               g.lat = lat;            /* degrees (+N -S) */
+               g.lon = lon;            /* degrees (+E -W) */
+               g.alt = alt;            /* m */
+               g.year = year;
+               g.month = month;
+               g.day = day;
+               g.hour = hour;
+               g.minute = minute;
+               g.second = second;
+
+               g.ground_speed = ground_speed;  /* m/s */
+               g.course = course;              /* degrees */
+               g.climb_rate = climb_rate;      /* m/s */
+               g.hdop = hdop;          /* unitless? */
+               g.h_error = h_error;    /* m */
+               g.v_error = v_error;    /* m */
+
+               if (cc_gps_sat != null) {
+                       g.cc_gps_sat = new AltosGPSSat[cc_gps_sat.length];
+                       for (int i = 0; i < cc_gps_sat.length; i++) {
+                               g.cc_gps_sat[i] = new AltosGPSSat(cc_gps_sat[i].svid,
+                                                                 cc_gps_sat[i].c_n0);
+                       }
+               }
+               return g;
+       }
+
        public AltosGPS(AltosGPS old) {
                if (old != null) {
                        nsat = old.nsat;
@@ -247,8 +340,37 @@ public class AltosGPS {
                                }
                        }
                } else {
+                       lat = AltosLib.MISSING;
+                       lon = AltosLib.MISSING;
+                       alt = AltosLib.MISSING;
                        ClearGPSTime();
                        cc_gps_sat = null;
                }
        }
+
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosGPS        gps = new AltosGPS(link, config_data);
+
+                       if (gps != null) {
+                               state.set_gps(gps, state.gps_sequence++);
+                               return;
+                       }
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+               state.set_gps(null, 0);
+       }
+
+       public AltosGPS (AltosLink link, AltosConfigData config_data) throws TimeoutException, InterruptedException {
+               boolean says_done = config_data.compare_version("1.0") >= 0;
+               link.printf("g\n");
+               for (;;) {
+                       String line = link.get_reply_no_dialog(5000);
+                       if (line == null)
+                               throw new TimeoutException();
+                       if (!parse_string(line, says_done))
+                               break;
+               }
+       }
 }
diff --git a/altoslib/AltosGPSQuery.java b/altoslib/AltosGPSQuery.java
deleted file mode 100644 (file)
index deb9d20..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright © 2012 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 org.altusmetrum.altoslib_1;
-
-import java.util.concurrent.*;
-
-class AltosGPSQuery extends AltosGPS {
-       public AltosGPSQuery (AltosLink link, AltosConfigData config_data)
-               throws TimeoutException, InterruptedException {
-               boolean says_done = config_data.compare_version("1.0") >= 0;
-               link.printf("g\n");
-               for (;;) {
-                       String line = link.get_reply_no_dialog(5000);
-                       if (line == null)
-                               throw new TimeoutException();
-                       String[] bits = line.split("\\s+");
-                       if (bits.length == 0)
-                               continue;
-                       if (line.startsWith("Date:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               String[] d = bits[1].split(":");
-                               if (d.length < 3)
-                                       continue;
-                               year = Integer.parseInt(d[0]) + 2000;
-                               month = Integer.parseInt(d[1]);
-                               day = Integer.parseInt(d[2]);
-                               continue;
-                       }
-                       if (line.startsWith("Time:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               String[] d = bits[1].split("/");
-                               if (d.length < 3)
-                                       continue;
-                               hour = Integer.parseInt(d[0]);
-                               minute = Integer.parseInt(d[1]);
-                               second = Integer.parseInt(d[2]);
-                               continue;
-                       }
-                       if (line.startsWith("Lat/Lon:")) {
-                               if (bits.length < 3)
-                                       continue;
-                               lat = Integer.parseInt(bits[1]) * 1.0e-7;
-                               lon = Integer.parseInt(bits[2]) * 1.0e-7;
-                               continue;
-                       }
-                       if (line.startsWith("Alt:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               alt = Integer.parseInt(bits[1]);
-                               continue;
-                       }
-                       if (line.startsWith("Flags:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               int status = Integer.decode(bits[1]);
-                               connected = (status & AltosLib.AO_GPS_RUNNING) != 0;
-                               locked = (status & AltosLib.AO_GPS_VALID) != 0;
-                               if (!says_done)
-                                       break;
-                               continue;
-                       }
-                       if (line.startsWith("Sats:")) {
-                               if (bits.length < 2)
-                                       continue;
-                               nsat = Integer.parseInt(bits[1]);
-                               cc_gps_sat = new AltosGPSSat[nsat];
-                               for (int i = 0; i < nsat; i++) {
-                                       int     svid = Integer.parseInt(bits[2+i*2]);
-                                       int     cc_n0 = Integer.parseInt(bits[3+i*2]);
-                                       cc_gps_sat[i] = new AltosGPSSat(svid, cc_n0);
-                               }
-                       }
-                       if (line.startsWith("done"))
-                               break;
-                       if (line.startsWith("Syntax error"))
-                               break;
-               }
-       }
-}
-
index 8714dd8aa42f98e217764fc80c3c8718f8be9e05..0e17d7f24d9eca661543f1ce3eeb56f17f8fd129 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosGPSSat {
        public int      svid;
index f1cf0ae9089173de180b9b0e39108379ed807a53..2c84bf4a27534c607f0c517215e41f354fc0000d 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.lang.Math;
 
-public class AltosGreatCircle {
+public class AltosGreatCircle implements Cloneable {
        public double   distance;
        public double   bearing;
        public double   range;
@@ -95,6 +95,16 @@ public class AltosGreatCircle {
                elevation = Math.atan2(height_diff, distance) * 180 / Math.PI;
        }
 
+       public AltosGreatCircle clone() {
+               AltosGreatCircle n = new AltosGreatCircle();
+
+               n.distance = distance;
+               n.bearing = bearing;
+               n.range = range;
+               n.elevation = elevation;
+               return n;
+       }
+
        public AltosGreatCircle (double start_lat, double start_lon,
                                 double end_lat, double end_lon) {
                this(start_lat, start_lon, 0, end_lat, end_lon, 0);
index 96f5722bde80bcca8b3a33d32b3d32b345d2acd4..1d2e4dbce499562d9db2a4d73df41efed1454d70 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosHeight extends AltosUnits {
 
index 2140228a179f44acf126c5f3288a438a9bd6464f..90352927433f219e1a79c359554c84b2e40009d7 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 import java.util.LinkedList;
index 8f6731faa5a9bebbbbf1712d0502a4bf4d471042..c231dda74c6f8f9cc2a76c1a8e123478e2d9a232 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
-public class AltosIMU {
+import java.util.concurrent.*;
+
+public class AltosIMU implements Cloneable {
        public int              accel_x;
        public int              accel_y;
        public int              accel_z;
@@ -25,5 +27,68 @@ public class AltosIMU {
        public int              gyro_x;
        public int              gyro_y;
        public int              gyro_z;
+
+       public boolean parse_string(String line) {
+               if (!line.startsWith("Accel:"))
+                       return false;
+
+               String[] items = line.split("\\s+");
+
+               if (items.length >= 8) {
+                       accel_x = Integer.parseInt(items[1]);
+                       accel_y = Integer.parseInt(items[2]);
+                       accel_z = Integer.parseInt(items[3]);
+                       gyro_x = Integer.parseInt(items[5]);
+                       gyro_y = Integer.parseInt(items[6]);
+                       gyro_z = Integer.parseInt(items[7]);
+               }
+               return true;
+       }
+
+       public AltosIMU clone() {
+               AltosIMU        n = new AltosIMU();
+
+               n.accel_x = accel_x;
+               n.accel_y = accel_y;
+               n.accel_z = accel_z;
+
+               n.gyro_x = gyro_x;
+               n.gyro_y = gyro_y;
+               n.gyro_z = gyro_z;
+               return n;
+       }
+
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosIMU        imu = new AltosIMU(link);
+
+                       if (imu != null)
+                               state.set_imu(imu);
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+       }
+
+       public AltosIMU() {
+               accel_x = AltosLib.MISSING;
+               accel_y = AltosLib.MISSING;
+               accel_z = AltosLib.MISSING;
+
+               gyro_x = AltosLib.MISSING;
+               gyro_y = AltosLib.MISSING;
+               gyro_z = AltosLib.MISSING;
+       }
+
+       public AltosIMU(AltosLink link) throws InterruptedException, TimeoutException {
+               this();
+               link.printf("I\n");
+               for (;;) {
+                       String line = link.get_reply_no_dialog(5000);
+                       if (line == null) {
+                               throw new TimeoutException();
+                       }
+                       if (parse_string(line))
+                               break;
+               }
+       }
 }
-       
\ No newline at end of file
diff --git a/altoslib/AltosIMUQuery.java b/altoslib/AltosIMUQuery.java
deleted file mode 100644 (file)
index 4ea5d96..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright © 2012 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 org.altusmetrum.altoslib_1;
-
-import java.util.concurrent.TimeoutException;
-
-class AltosIMUQuery extends AltosIMU {
-
-       public AltosIMUQuery (AltosLink link) throws InterruptedException, TimeoutException {
-               link.printf("I\n");
-               for (;;) {
-                       String line = link.get_reply_no_dialog(5000);
-                       if (line == null) {
-                               throw new TimeoutException();
-                       }
-                       if (!line.startsWith("Accel:"))
-                               continue;
-                       String[] items = line.split("\\s+");
-                       if (items.length >= 8) {
-                               accel_x = Integer.parseInt(items[1]);
-                               accel_y = Integer.parseInt(items[2]);
-                               accel_z = Integer.parseInt(items[3]);
-                               gyro_x = Integer.parseInt(items[5]);
-                               gyro_y = Integer.parseInt(items[6]);
-                               gyro_z = Integer.parseInt(items[7]);
-                       }
-                       break;
-               }
-       }
-}
-
diff --git a/altoslib/AltosIdle.java b/altoslib/AltosIdle.java
new file mode 100644 (file)
index 0000000..456a924
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+import java.util.concurrent.*;
+
+public abstract class AltosIdle {
+       AltosLink       link;
+       AltosConfigData config_data;
+
+       public void printf(String format, Object ... arguments) {
+               link.printf(format, arguments);
+       }
+
+       public abstract void update_state(AltosState state) throws InterruptedException, TimeoutException;
+
+       public AltosIdle(AltosLink link, AltosConfigData config_data) {
+               this.link = link;
+               this.config_data = config_data;
+       }
+}
diff --git a/altoslib/AltosIdleFetch.java b/altoslib/AltosIdleFetch.java
new file mode 100644 (file)
index 0000000..64c421f
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+import java.util.concurrent.*;
+
+class AltosIdler {
+       String  prefix;
+       int[]   idlers;
+
+       static final int        idle_gps = 0;
+       static final int        idle_imu = 1;
+       static final int        idle_mag = 2;
+       static final int        idle_ms5607 = 3;
+       static final int        idle_mma655x = 4;
+
+
+       static final int        idle_sensor_tm = 10;
+       static final int        idle_sensor_metrum = 11;
+       static final int        idle_sensor_mega = 12;
+       static final int        idle_sensor_emini = 13;
+       static final int        idle_sensor_tmini = 14;
+
+       public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
+               for (int idler : idlers) {
+                       AltosIdle idle = null;
+                       switch (idler) {
+                       case idle_gps:
+                               AltosGPS.update_state(state, link, config_data);
+                               break;
+                       case idle_imu:
+                               AltosIMU.update_state(state, link, config_data);
+                               break;
+                       case idle_mag:
+                               AltosMag.update_state(state, link, config_data);
+                               break;
+                       case idle_ms5607:
+                               AltosMs5607.update_state(state, link, config_data);
+                               break;
+                       case idle_mma655x:
+                               AltosMma655x.update_state(state, link, config_data);
+                               break;
+                       case idle_sensor_tm:
+                               AltosSensorTM.update_state(state, link, config_data);
+                               break;
+                       case idle_sensor_metrum:
+                               AltosSensorMetrum.update_state(state, link, config_data);
+                               break;
+                       case idle_sensor_mega:
+                               AltosSensorMega.update_state(state, link, config_data);
+                               break;
+                       case idle_sensor_emini:
+                               AltosSensorEMini.update_state(state, link, config_data);
+                               break;
+                       case idle_sensor_tmini:
+                               AltosSensorTMini.update_state(state, link, config_data);
+                       }
+                       if (idle != null)
+                               idle.update_state(state);
+               }
+       }
+
+       public boolean matches(AltosConfigData config_data) {
+               return config_data.product.startsWith(prefix);
+       }
+
+       public AltosIdler(String prefix, int ... idlers) {
+               this.prefix = prefix;
+               this.idlers = idlers;
+       }
+}
+
+
+public class AltosIdleFetch implements AltosStateUpdate {
+
+       static final AltosIdler[] idlers = {
+
+               new AltosIdler("EasyMini",
+                              AltosIdler.idle_ms5607,
+                              AltosIdler.idle_sensor_emini),
+
+               new AltosIdler("TeleMini-v1",
+                              AltosIdler.idle_sensor_tm),
+
+               new AltosIdler("TeleMini-v2",
+                              AltosIdler.idle_ms5607,
+                              AltosIdler.idle_sensor_tmini),
+
+               new AltosIdler("TeleMetrum-v1",
+                              AltosIdler.idle_gps,
+                              AltosIdler.idle_sensor_tm),
+
+               new AltosIdler("TeleMetrum-v2",
+                              AltosIdler.idle_gps,
+                              AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
+                              AltosIdler.idle_sensor_metrum),
+
+               new AltosIdler("TeleMega",
+                              AltosIdler.idle_gps,
+                              AltosIdler.idle_ms5607, AltosIdler.idle_mma655x,
+                              AltosIdler.idle_imu, AltosIdler.idle_mag,
+                              AltosIdler.idle_sensor_mega),
+       };
+
+       AltosLink               link;
+
+       double                  frequency;
+       String                  callsign;
+
+       public void update_state(AltosState state) {
+               try {
+                       AltosConfigData config_data = new AltosConfigData(link);
+                       state.set_state(AltosLib.ao_flight_startup);
+                       state.set_serial(config_data.serial);
+                       state.set_callsign(config_data.callsign);
+                       state.set_ground_accel(config_data.accel_cal_plus);
+                       state.set_accel_g(config_data.accel_cal_plus, config_data.accel_cal_minus);
+                       for (AltosIdler idler : idlers) {
+                               if (idler.matches(config_data)) {
+                                       idler.update_state(state, link, config_data);
+                                       break;
+                               }
+                       }
+                       state.set_received_time(System.currentTimeMillis());
+               } catch (InterruptedException ie) {
+               } catch (TimeoutException te) {
+               }
+               
+       }
+
+       public AltosIdleFetch(AltosLink link) {
+               this.link = link;
+       }
+}
index b3ce5b204a8774976f9764fb2d738d37de99fdf1..d858845a1af0dbe0ea10837191cfa053507439d7 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 import java.util.concurrent.*;
@@ -24,11 +24,13 @@ import java.util.concurrent.*;
 public class AltosIdleMonitor extends Thread {
        AltosLink               link;
        AltosIdleMonitorListener        listener;
-       AltosState              state;
+
+       AltosIdleFetch          fetch;
+
        boolean                 remote;
        double                  frequency;
        String                  callsign;
-       AltosState              previous_state;
+
        AltosListenerState      listener_state;
        AltosConfigData         config_data;
        AltosGPS                gps;
@@ -47,86 +49,35 @@ public class AltosIdleMonitor extends Thread {
                return rssi;
        }
 
-       boolean has_sensor_tm(AltosConfigData config_data) {
-               return config_data.product.startsWith("TeleMetrum") || config_data.product.startsWith("TeleMini");
-       }
-
-       boolean has_sensor_mm(AltosConfigData config_data) {
-               return config_data.product.startsWith("TeleMega");
-       }
-
-       boolean has_gps(AltosConfigData config_data) {
-               return config_data.product.startsWith("TeleMetrum") || config_data.product.startsWith("TeleMega");
+       void start_link() throws InterruptedException, TimeoutException {
+               if (remote) {
+                       link.set_radio_frequency(frequency);
+                       link.set_callsign(callsign);
+                       link.start_remote();
+               } else
+                       link.flush_input();
        }
 
-       AltosRecord sensor_mm(AltosConfigData config_data) throws InterruptedException, TimeoutException {
-               AltosRecordMM record_mm = new AltosRecordMM();
-               AltosSensorMM sensor = new AltosSensorMM(link);
-               AltosMs5607 ms5607 = new AltosMs5607Query(link);
-               AltosIMU imu = new AltosIMUQuery(link);
-
-               record_mm.accel_plus_g = config_data.accel_cal_plus;
-               record_mm.accel_minus_g = config_data.accel_cal_minus;
-
-               record_mm.ground_accel = sensor.accel;
-               record_mm.accel = sensor.accel;
-               record_mm.ground_pres = ms5607.pa;
-               record_mm.pres = ms5607.pa;
-               record_mm.temp = ms5607.cc;
-
-               record_mm.v_batt = sensor.v_batt;
-               record_mm.v_pyro = sensor.v_pyro;
-               record_mm.sense = sensor.sense;
-
-               record_mm.imu = imu;
-
-               return record_mm;
+       void stop_link() throws InterruptedException, TimeoutException {
+               if (remote)
+                       link.stop_remote();
        }
 
-       void update_state() throws InterruptedException, TimeoutException {
-               AltosRecord     record = null;
+       void update_state(AltosState state) throws InterruptedException, TimeoutException {
+               boolean         worked = false;
 
                try {
-                       if (remote) {
-                               link.set_radio_frequency(frequency);
-                               link.set_callsign(callsign);
-                               link.start_remote();
-                       } else
-                               link.flush_input();
-                       config_data = new AltosConfigData(link);
-
-                       if (has_sensor_tm(config_data))
-                               record = new AltosSensorTM(link, config_data);
-                       else if (has_sensor_mm(config_data))
-                               record = sensor_mm(config_data);
-                       else
-                               record = new AltosRecordNone();
-
-                       if (has_gps(config_data))
-                               gps = new AltosGPSQuery(link, config_data);
-
-                       record.version = 0;
-                       record.callsign = config_data.callsign;
-                       record.serial = config_data.serial;
-                       record.flight = config_data.log_available() > 0 ? 255 : 0;
-                       record.status = 0;
-                       record.state = AltosLib.ao_flight_idle;
-                       record.gps = gps;
-                       record.gps_sequence++;
-                       state = new AltosState (record, state);
+                       start_link();
+                       fetch.update_state(state);
+                       worked = true;
                } finally {
-                       if (remote) {
-                               link.stop_remote();
-                               if (record != null) {
-                                       record.rssi = link.rssi();
-                                       listener_state.battery = link.monitor_battery();
-                               }
-                       } else {
-                               if (record != null)
-                                       record.rssi = 0;
+                       stop_link();
+                       if (worked) {
+                               if (remote)
+                                       state.set_rssi(link.rssi(), 0);
+                               listener_state.battery = link.monitor_battery();
                        }
                }
-
        }
 
        public void set_frequency(double in_frequency) {
@@ -139,10 +90,6 @@ public class AltosIdleMonitor extends Thread {
                link.abort_reply();
        }
 
-       public void post_state() {
-               listener.update(state, listener_state);
-       }
-
        public void abort() {
                if (isAlive()) {
                        interrupt();
@@ -155,18 +102,20 @@ public class AltosIdleMonitor extends Thread {
        }
 
        public void run() {
+               AltosState state = new AltosState();
                try {
-                       for (;;) {
+                       while (!link.has_error) {
                                try {
-                                       update_state();
-                                       post_state();
+                                       link.config_data();
+                                       update_state(state);
+                                       listener.update(state, listener_state);
                                } catch (TimeoutException te) {
                                }
                                Thread.sleep(1000);
                        }
                } catch (InterruptedException ie) {
-                       link.close();
                }
+               link.close();
        }
 
        public AltosIdleMonitor(AltosIdleMonitorListener in_listener, AltosLink in_link, boolean in_remote)
@@ -174,7 +123,7 @@ public class AltosIdleMonitor extends Thread {
                listener = in_listener;
                link = in_link;
                remote = in_remote;
-               state = null;
                listener_state = new AltosListenerState();
+               fetch = new AltosIdleFetch(link);
        }
 }
index 27e36dea2ce6b4f673bc47f3623c4e0e0d07810b..0b03b897ae3139ebb27ef7c12a26976e61885aaa 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public interface AltosIdleMonitorListener {
        public void update(AltosState state, AltosListenerState listener_state);
index 859059008cbfd838e8c9ff3aadd0704c8fe230f1..42169989b00eb797b307df5d7ebca671ed160933 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 import java.util.concurrent.*;
index d60ef492ccffeb38d89f70d0b02b89e8306e4426..46031912858b4950de3876b0956ab4fe43b3d2a6 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.util.*;
 import java.io.*;
@@ -28,6 +28,7 @@ public class AltosLib {
        public static final int AO_LOG_TEMP_VOLT = 'T';
        public static final int AO_LOG_DEPLOY = 'D';
        public static final int AO_LOG_STATE = 'S';
+       public static final int AO_LOG_GPS_POS = 'P';
        public static final int AO_LOG_GPS_TIME = 'G';
        public static final int AO_LOG_GPS_LAT = 'N';
        public static final int AO_LOG_GPS_LON = 'W';
@@ -62,6 +63,8 @@ public class AltosLib {
 
        public static final int AO_LOG_SOFTWARE_VERSION = 9999;
 
+       public final static int MISSING = 0x7fffffff;
+
        /* Added to flag invalid records */
        public static final int AO_LOG_INVALID = -1;
 
@@ -218,7 +221,9 @@ public class AltosLib {
        public static final int AO_LOG_FORMAT_TELEMETRY = 3;
        public static final int AO_LOG_FORMAT_TELESCIENCE = 4;
        public static final int AO_LOG_FORMAT_TELEMEGA = 5;
-       public static final int AO_LOG_FORMAT_MINI = 6;
+       public static final int AO_LOG_FORMAT_EASYMINI = 6;
+       public static final int AO_LOG_FORMAT_TELEMETRUM = 7;
+       public static final int AO_LOG_FORMAT_TELEMINI = 8;
        public static final int AO_LOG_FORMAT_NONE = 127;
 
        public static boolean isspace(int c) {
@@ -413,4 +418,24 @@ public class AltosLib {
        public static File replace_extension(File input, String extension) {
                return new File(replace_extension(input.getPath(), extension));
        }
+
+       public static String product_name(int product_id) {
+               switch (product_id) {
+               case product_altusmetrum: return "AltusMetrum";
+               case product_telemetrum: return "TeleMetrum";
+               case product_teledongle: return "TeleDongle";
+               case product_teleterra: return "TeleTerra";
+               case product_telebt: return "TeleBT";
+               case product_telelaunch: return "TeleLaunch";
+               case product_telelco: return "TeleLco";
+               case product_telescience: return "Telescience";
+               case product_telepyro: return "TelePyro";
+               case product_telemega: return "TeleMega";
+               case product_megadongle: return "MegaDongle";
+               case product_telegps: return "TeleGPS";
+               case product_easymini: return "EasyMini";
+               case product_telemini: return "TeleMini";
+               default: return "unknown";
+               }
+       }
 }
index b3bd20f97bc71071ddf49d751ae1101012a56afe..e5dd13fc2901c7d582be2c937ea7560409454e75 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosLine {
        public String   line;
index 159ebfe19c234b34b423a6619e56d18f7ca6f433..4823a986011c1ec80f443bfc16c6cc0e24458ce3 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 import java.util.concurrent.*;
@@ -32,17 +32,20 @@ public abstract class AltosLink implements Runnable {
 
        public static boolean debug = false;
        public static void set_debug(boolean in_debug) { debug = in_debug; }
+
+       public boolean has_error;
+
        LinkedList<String> pending_output = new LinkedList<String>();
 
        public LinkedList<LinkedBlockingQueue<AltosLine>> monitors = new LinkedList<LinkedBlockingQueue<AltosLine>> ();;
        public LinkedBlockingQueue<AltosLine> reply_queue = new LinkedBlockingQueue<AltosLine>();
 
-       public void add_monitor(LinkedBlockingQueue<AltosLine> q) {
+       public synchronized void add_monitor(LinkedBlockingQueue<AltosLine> q) {
                set_monitor(true);
                monitors.add(q);
        }
 
-       public void remove_monitor(LinkedBlockingQueue<AltosLine> q) {
+       public synchronized void remove_monitor(LinkedBlockingQueue<AltosLine> q) {
                monitors.remove(q);
                if (monitors.isEmpty())
                        set_monitor(false);
@@ -107,6 +110,7 @@ public abstract class AltosLink implements Runnable {
                                if (c == ERROR) {
                                        if (debug)
                                                System.out.printf("ERROR\n");
+                                       has_error = true;
                                        add_telem (new AltosLine());
                                        add_reply (new AltosLine());
                                        break;
@@ -252,6 +256,8 @@ public abstract class AltosLink implements Runnable {
        public String callsign;
        AltosConfigData config_data;
 
+       private Object config_data_lock = new Object();
+
        private int telemetry_len() {
                return AltosLib.telemetry_len(telemetry);
        }
@@ -325,9 +331,11 @@ public abstract class AltosLink implements Runnable {
        }
 
        public AltosConfigData config_data() throws InterruptedException, TimeoutException {
-               if (config_data == null)
-                       config_data = new AltosConfigData(this);
-               return config_data;
+               synchronized(config_data_lock) {
+                       if (config_data == null)
+                               config_data = new AltosConfigData(this);
+                       return config_data;
+               }
        }
 
        public void set_callsign(String callsign) {
@@ -399,7 +407,7 @@ public abstract class AltosLink implements Runnable {
        }
 
        public double monitor_battery() {
-               int monitor_batt = AltosRecord.MISSING;
+               int monitor_batt = AltosLib.MISSING;
 
                if (config_data.has_monitor_battery()) {
                        try {
@@ -416,12 +424,13 @@ public abstract class AltosLink implements Runnable {
                        } catch (TimeoutException te) {
                        }
                }
-               if (monitor_batt == AltosRecord.MISSING)
-                       return AltosRecord.MISSING;
+               if (monitor_batt == AltosLib.MISSING)
+                       return AltosLib.MISSING;
                return AltosConvert.cc_battery_to_voltage(monitor_batt);
        }
 
        public AltosLink() {
                callsign = "";
+               has_error = false;
        }
 }
index 2fb4673edcc5c87885f6ae03328959f9f8cd9502..01dd7afb4e6f7b9a6c7e52adec741584d0c1a31c 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosListenerState {
        public int      crc_errors;
@@ -23,6 +23,6 @@ public class AltosListenerState {
 
        public AltosListenerState() {
                crc_errors = 0;
-               battery = AltosRecord.MISSING;
+               battery = AltosLib.MISSING;
        }
 }
index 974c9f0f90ab6c189c1dbb718a6d0e02af809207..015d9f65aa13ad28ef3aadef04bcf044becabf12 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
-import java.text.ParseException;
-import java.util.concurrent.LinkedBlockingQueue;
+import java.text.*;
+import java.util.concurrent.*;
 
 /*
  * This creates a thread to capture telemetry data and write it to
@@ -31,9 +31,11 @@ public class AltosLog implements Runnable {
        LinkedBlockingQueue<String>     pending_queue;
        int                             serial;
        int                             flight;
+       int                             receiver_serial;
        FileWriter                      log_file;
        Thread                          log_thread;
        AltosFile                       file;
+       AltosLink                       link;
 
        private void close_log_file() {
                if (log_file != null) {
@@ -57,8 +59,8 @@ public class AltosLog implements Runnable {
                return file;
        }
 
-       boolean open (AltosRecord telem) throws IOException {
-               AltosFile       a = new AltosFile(telem);
+       boolean open (AltosState state) throws IOException {
+               AltosFile       a = new AltosFile(state);
 
                log_file = new FileWriter(a, true);
                if (log_file != null) {
@@ -78,22 +80,25 @@ public class AltosLog implements Runnable {
 
        public void run () {
                try {
-                       AltosRecord     previous = null;
+                       AltosState      state = new AltosState();
+                       AltosConfigData receiver_config = link.config_data();
+                       state.set_receiver_serial(receiver_config.serial);
                        for (;;) {
                                AltosLine       line = input_queue.take();
                                if (line.line == null)
                                        continue;
                                try {
-                                       AltosRecord     telem = AltosTelemetry.parse(line.line, previous);
-                                       if ((telem.seen & AltosRecord.seen_flight) != 0 &&
-                                           (telem.serial != serial || telem.flight != flight || log_file == null))
+                                       AltosTelemetry  telem = AltosTelemetry.parse(line.line);
+                                       state = state.clone();
+                                       telem.update_state(state);
+                                       if (state.serial != serial || state.flight != flight || log_file == null)
                                        {
                                                close_log_file();
-                                               serial = telem.serial;
-                                               flight = telem.flight;
-                                               open(telem);
+                                               serial = state.serial;
+                                               flight = state.flight;
+                                               if (state.serial != AltosLib.MISSING && state.flight != AltosLib.MISSING)
+                                                       open(state);
                                        }
-                                       previous = telem;
                                } catch (ParseException pe) {
                                } catch (AltosCRCException ce) {
                                }
@@ -105,6 +110,7 @@ public class AltosLog implements Runnable {
                                        pending_queue.put(line.line);
                        }
                } catch (InterruptedException ie) {
+               } catch (TimeoutException te) {
                } catch (IOException ie) {
                }
                close();
@@ -116,6 +122,7 @@ public class AltosLog implements Runnable {
                link.add_monitor(input_queue);
                serial = -1;
                flight = -1;
+               this.link = link;
                log_file = null;
                log_thread = new Thread(this);
                log_thread.start();
index b3bbd92fa9843acbcbdf633489e7c0c741357af2..56add8f3445da8d0de9fee7d2ec2f5150d4ee739 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
-public class AltosMag {
+import java.util.concurrent.*;
+
+public class AltosMag implements Cloneable {
        public int              x;
        public int              y;
        public int              z;
+
+       public boolean parse_string(String line) {
+               if (!line.startsWith("X:"))
+                       return false;
+
+               String[] items = line.split("\\s+");
+
+               if (items.length >= 6) {
+                       x = Integer.parseInt(items[1]);
+                       y = Integer.parseInt(items[3]);
+                       z = Integer.parseInt(items[5]);
+               }
+               return true;
+       }
+
+       public AltosMag clone() {
+               AltosMag n = new AltosMag();
+
+               n.x = x;
+               n.y = y;
+               n.z = z;
+               return n;
+       }
+
+       public AltosMag() {
+               x = AltosLib.MISSING;
+               y = AltosLib.MISSING;
+               z = AltosLib.MISSING;
+       }
+
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosMag        mag = new AltosMag(link);
+
+                       if (mag != null)
+                               state.set_mag(mag);
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+       }
+
+       public AltosMag(AltosLink link) throws InterruptedException, TimeoutException {
+               this();
+               link.printf("M\n");
+               for (;;) {
+                       String line = link.get_reply_no_dialog(5000);
+                       if (line == null) {
+                               throw new TimeoutException();
+                       }
+                       if (parse_string(line))
+                               break;
+               }
+       }
 }
        
\ No newline at end of file
diff --git a/altoslib/AltosMma655x.java b/altoslib/AltosMma655x.java
new file mode 100644 (file)
index 0000000..8dc947d
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2012 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 org.altusmetrum.altoslib_2;
+
+import java.util.concurrent.*;
+
+public class AltosMma655x implements Cloneable {
+
+       int     accel;
+
+       public boolean parse_line(String line) {
+               String[] items = line.split("\\s+");
+               if (line.startsWith("MMA655X value:")) {
+                       if (items.length >= 3)
+                               accel = Integer.parseInt(items[1]);
+               } else
+                       return false;
+               return true;
+       }
+
+       public AltosMma655x() {
+               accel = AltosLib.MISSING;
+       }
+
+       public AltosMma655x clone() {
+               AltosMma655x    n = new AltosMma655x();
+
+               n.accel = accel;
+               return n;
+       }
+
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosMma655x    mma655x = new AltosMma655x(link);
+
+                       if (mma655x != null)
+                               state.set_accel(mma655x.accel);
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+       }
+
+       public AltosMma655x(AltosLink link) throws InterruptedException, TimeoutException {
+               this();
+               link.printf("A\n");
+               for (;;) {
+                       String line = link.get_reply_no_dialog(5000);
+                       if (line == null)
+                               throw new TimeoutException();
+                       if (!parse_line(line))
+                               break;
+               }
+       }
+}
index 606916b7b46ec84f14de302b2d7e2a011056c5f2..b29fa9ae845d11ad4652448f4627587ae062027e 100644 (file)
@@ -15,7 +15,9 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
+
+import java.util.concurrent.*;
 
 public class AltosMs5607 {
        public int      reserved;
@@ -83,10 +85,13 @@ public class AltosMs5607 {
        }
 
        public boolean parse_line(String line) {
+               System.out.printf ("parse %s\n", line);
                String[] items = line.split("\\s+");
                if (line.startsWith("Pressure:")) {
-                       if (items.length >= 2)
+                       if (items.length >= 2) {
                                raw_pres = Integer.parseInt(items[1]);
+                               System.out.printf ("raw_pres %d\n", raw_pres);
+                       }
                } else if (line.startsWith("Temperature:")) {
                        if (items.length >= 2)
                                raw_temp = Integer.parseInt(items[1]);
@@ -94,8 +99,11 @@ public class AltosMs5607 {
                        if (items.length >= 3)
                                reserved = Integer.parseInt(items[2]);
                } else if (line.startsWith("ms5607 sens:")) {
-                       if (items.length >= 3)
+                       System.out.printf ("found sens length %d\n", items.length);
+                       if (items.length >= 3) {
                                sens = Integer.parseInt(items[2]);
+                               System.out.printf ("sens %d\n", sens);
+                       }
                } else if (line.startsWith("ms5607 off:")) {
                        if (items.length >= 3)
                                off = Integer.parseInt(items[2]);
@@ -114,15 +122,48 @@ public class AltosMs5607 {
                } else if (line.startsWith("ms5607 crc:")) {
                        if (items.length >= 3)
                                crc = Integer.parseInt(items[2]);
-               } else if (line.startsWith("Altitude"))
+               } else if (line.startsWith("Altitude:")) {
                        return false;
+               }
                return true;
        }
 
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosMs5607     ms5607 = new AltosMs5607(link);
+
+                       if (ms5607 != null) {
+                               state.set_ms5607(ms5607);
+                               return;
+                       }
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+       }
+
        public AltosMs5607() {
-               raw_pres = AltosRecord.MISSING;
-               raw_temp = AltosRecord.MISSING;
-               pa = AltosRecord.MISSING;
-               cc = AltosRecord.MISSING;
+               raw_pres = AltosLib.MISSING;
+               raw_temp = AltosLib.MISSING;
+               pa = AltosLib.MISSING;
+               cc = AltosLib.MISSING;
+       }
+
+       public AltosMs5607 (AltosLink link) throws InterruptedException, TimeoutException {
+               this();
+               link.printf("c s\nB\n");
+               for (;;) {
+                       String line = link.get_reply_no_dialog(5000);
+                       if (line == null) {
+                               throw new TimeoutException();
+                       }
+                       if (!parse_line(line)) {
+                               System.out.printf ("stop parsing at %s\n", line);
+                               break;
+                       }
+               }
+               System.out.printf ("sens %d off %d tcs %d tco %d tref %d tempsens %d crc %d pres %d temp %d\n",
+                                  sens, off, tcs, tco, tref, tempsens, crc, raw_pres, raw_temp);
+               convert();
+               System.out.printf ("pa %d cc %d\n", pa, cc);
        }
 }
diff --git a/altoslib/AltosMs5607Query.java b/altoslib/AltosMs5607Query.java
deleted file mode 100644 (file)
index d39dbf2..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright © 2012 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 org.altusmetrum.altoslib_1;
-
-import java.util.concurrent.TimeoutException;
-
-class AltosMs5607Query extends AltosMs5607 {
-       public AltosMs5607Query (AltosLink link) throws InterruptedException, TimeoutException {
-               link.printf("v\nB\n");
-               for (;;) {
-                       String line = link.get_reply_no_dialog(5000);
-                       if (line == null) {
-                               throw new TimeoutException();
-                       }
-                       if (!parse_line(line))
-                               break;
-               }
-               convert();
-       }
-}
-
diff --git a/altoslib/AltosOrderedMegaRecord.java b/altoslib/AltosOrderedMegaRecord.java
deleted file mode 100644 (file)
index b20a5bb..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 org.altusmetrum.altoslib_1;
-
-import java.text.ParseException;
-
-/*
- * AltosRecords with an index field so they can be sorted by tick while preserving
- * the original ordering for elements with matching ticks
- */
-class AltosOrderedMegaRecord extends AltosEepromMega implements Comparable<AltosOrderedMegaRecord> {
-
-       public int      index;
-
-       public AltosOrderedMegaRecord(String line, int in_index, int prev_tick, boolean prev_tick_valid)
-               throws ParseException {
-               super(line);
-               if (prev_tick_valid) {
-                       tick |= (prev_tick & ~0xffff);
-                       if (tick < prev_tick) {
-                               if (prev_tick - tick > 0x8000)
-                                       tick += 0x10000;
-                       } else {
-                               if (tick - prev_tick > 0x8000)
-                                       tick -= 0x10000;
-                       }
-               }
-               index = in_index;
-       }
-
-       public int compareTo(AltosOrderedMegaRecord o) {
-               int     tick_diff = tick - o.tick;
-               if (tick_diff != 0)
-                       return tick_diff;
-               return index - o.index;
-       }
-}
diff --git a/altoslib/AltosOrderedMiniRecord.java b/altoslib/AltosOrderedMiniRecord.java
deleted file mode 100644 (file)
index 9688894..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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 org.altusmetrum.altoslib_1;
-
-import java.text.ParseException;
-
-/*
- * AltosRecords with an index field so they can be sorted by tick while preserving
- * the original ordering for elements with matching ticks
- */
-class AltosOrderedMiniRecord extends AltosEepromMini implements Comparable<AltosOrderedMiniRecord> {
-
-       public int      index;
-
-       public AltosOrderedMiniRecord(String line, int in_index, int prev_tick, boolean prev_tick_valid)
-               throws ParseException {
-               super(line);
-               if (prev_tick_valid) {
-                       tick |= (prev_tick & ~0xffff);
-                       if (tick < prev_tick) {
-                               if (prev_tick - tick > 0x8000)
-                                       tick += 0x10000;
-                       } else {
-                               if (tick - prev_tick > 0x8000)
-                                       tick -= 0x10000;
-                       }
-               }
-               index = in_index;
-       }
-
-       public int compareTo(AltosOrderedMiniRecord o) {
-               int     tick_diff = tick - o.tick;
-               if (tick_diff != 0)
-                       return tick_diff;
-               return index - o.index;
-       }
-}
diff --git a/altoslib/AltosOrderedRecord.java b/altoslib/AltosOrderedRecord.java
deleted file mode 100644 (file)
index 63507d3..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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 org.altusmetrum.altoslib_1;
-
-import java.text.ParseException;
-
-/*
- * AltosRecords with an index field so they can be sorted by tick while preserving
- * the original ordering for elements with matching ticks
- */
-class AltosOrderedRecord extends AltosEepromRecord implements Comparable<AltosOrderedRecord> {
-
-       public int      index;
-
-       public AltosOrderedRecord(String line, int in_index, int prev_tick, boolean prev_tick_valid)
-               throws ParseException {
-               super(line);
-               if (prev_tick_valid) {
-                       tick |= (prev_tick & ~0xffff);
-                       if (tick < prev_tick) {
-                               if (prev_tick - tick > 0x8000)
-                                       tick += 0x10000;
-                       } else {
-                               if (tick - prev_tick > 0x8000)
-                                       tick -= 0x10000;
-                       }
-               }
-               index = in_index;
-       }
-
-       public AltosOrderedRecord(int in_cmd, int in_tick, int in_a, int in_b, int in_index) {
-               super(in_cmd, in_tick, in_a, in_b);
-               index = in_index;
-       }
-
-       public String toString() {
-               return String.format("%d.%d %04x %04x %04x",
-                                    cmd, index, tick, a, b);
-       }
-
-       public int compareTo(AltosOrderedRecord o) {
-               int     tick_diff = tick - o.tick;
-               if (tick_diff != 0)
-                       return tick_diff;
-               return index - o.index;
-       }
-}
-
index 66bbeed5eb185f5b101b54a1bfad369d1fb44a0b..ca96a8f94385aeb3877458628b33afb1293d48e0 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.text.*;
 
index 088ca3d7589c7507c1e17afb090158043737a218..c4051f9b58e2155a56a5a81e8ebf7d186d7f87fb 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 import java.util.*;
index fb8a235a8d5ede79f5b13f2019e2a897bc2e2808..1ea28b0131ab11510ea7fe719680036e3fc1cb81 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.File;
 
index 4dbb42234a346c1806d606b70bad05e5a079ffcd..0142eac825a1dcca84b7a3660cc74baeca9162ed 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.util.*;
 import java.text.*;
diff --git a/altoslib/AltosRecord.java b/altoslib/AltosRecord.java
deleted file mode 100644 (file)
index 5e4ed92..0000000
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * 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 org.altusmetrum.altoslib_1;
-
-public class AltosRecord implements Comparable <AltosRecord>, Cloneable {
-
-       public static final int seen_flight = 1;
-       public static final int seen_sensor = 2;
-       public static final int seen_temp_volt = 4;
-       public static final int seen_deploy = 8;
-       public static final int seen_gps_time = 16;
-       public static final int seen_gps_lat = 32;
-       public static final int seen_gps_lon = 64;
-       public static final int seen_companion = 128;
-
-       public int      seen;
-       
-       public final static int MISSING = 0x7fffffff;
-
-       /* Every AltosRecord implementation provides these fields */
-       
-       public int      version;
-       public String   callsign;
-       public int      serial;
-       public int      flight;
-       public int      rssi;
-       public int      status;
-       public int      state;
-       public int      tick;
-
-       public AltosGPS gps;
-       public int      gps_sequence;
-
-       public double   time;   /* seconds since boost */
-
-       public int      device_type;
-       public int      config_major;
-       public int      config_minor;
-       public int      apogee_delay;
-       public int      main_deploy;
-       public int      flight_log_max;
-       public String   firmware_version;
-
-       public AltosRecordCompanion companion;
-
-       /* Telemetry sources have these values recorded from the flight computer */
-       public double   kalman_height;
-       public double   kalman_speed;
-       public double   kalman_acceleration;
-
-       /*
-        * Abstract methods that convert record data
-        * to standard units:
-        *
-        *      pressure:       Pa
-        *      voltage:        V
-        *      acceleration:   m/s²
-        *      speed:          m/s
-        *      height:         m
-        *      temperature:    °C
-        */
-
-       public double pressure() { return MISSING; }
-       public double ground_pressure() { return MISSING; }
-       public double acceleration() { return MISSING; }
-
-       public double altitude() {
-               double  p = pressure();
-
-               if (p == MISSING)
-                       return MISSING;
-               return AltosConvert.pressure_to_altitude(p);
-       }
-
-       public double ground_altitude() {
-               double  p = ground_pressure();
-
-               if (p == MISSING)
-                       return MISSING;
-               return AltosConvert.pressure_to_altitude(p);
-       }
-
-       public double height() {
-               double  g = ground_altitude();
-               double  a = altitude();
-
-               if (g == MISSING)
-                       return MISSING;
-               if (a == MISSING)
-                       return MISSING;
-               return a - g;
-       }
-
-       public double battery_voltage() { return MISSING; }
-
-       public double main_voltage() { return MISSING; }
-
-       public double drogue_voltage() { return MISSING; }
-
-       public double temperature() { return MISSING; }
-       
-       public AltosIMU imu() { return null; }
-
-       public AltosMag mag() { return null; }
-
-       public String state() {
-               return AltosLib.state_name(state);
-       }
-
-       public int compareTo(AltosRecord o) {
-               return tick - o.tick;
-       }
-
-       public AltosRecord clone() {
-               AltosRecord n = new AltosRecord();
-               n.copy(this);
-               return n;
-       }
-
-       public void copy(AltosRecord old) {
-               seen = old.seen;
-               version = old.version;
-               callsign = old.callsign;
-               serial = old.serial;
-               flight = old.flight;
-               rssi = old.rssi;
-               status = old.status;
-               state = old.state;
-               tick = old.tick;
-               gps = new AltosGPS(old.gps);
-               gps_sequence = old.gps_sequence;
-               companion = old.companion;
-               kalman_acceleration = old.kalman_acceleration;
-               kalman_speed = old.kalman_speed;
-               kalman_height = old.kalman_height;
-       }
-
-       public AltosRecord() {
-               seen = 0;
-               version = 0;
-               callsign = "N0CALL";
-               serial = MISSING;
-               flight = MISSING;
-               rssi = 0;
-               status = 0;
-               state = AltosLib.ao_flight_startup;
-               tick = 0;
-               gps = null;
-               gps_sequence = 0;
-               companion = null;
-
-               kalman_acceleration = MISSING;
-               kalman_speed = MISSING;
-               kalman_height = MISSING;
-       }
-}
diff --git a/altoslib/AltosRecordCompanion.java b/altoslib/AltosRecordCompanion.java
deleted file mode 100644 (file)
index b153fb5..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-public class AltosRecordCompanion {
-       public final static int board_id_telescience = 0x0a;
-       public final static int MAX_CHANNELS = 12;
-
-       public int      tick;
-       public int      board_id;
-       public int      update_period;
-       public int      channels;
-       public int[]    companion_data;
-
-       public AltosRecordCompanion(int in_channels) {
-               channels = in_channels;
-               if (channels < 0)
-                       channels = 0;
-               if (channels > MAX_CHANNELS)
-                       channels = MAX_CHANNELS;
-               companion_data = new int[channels];
-       }
-}
diff --git a/altoslib/AltosRecordIterable.java b/altoslib/AltosRecordIterable.java
deleted file mode 100644 (file)
index 62dbdfe..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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 org.altusmetrum.altoslib_1;
-
-import java.io.*;
-import java.util.*;
-
-public abstract class AltosRecordIterable implements Iterable<AltosRecord> {
-       public abstract Iterator<AltosRecord> iterator();
-       public void write_comments(PrintStream out) { }
-       public boolean has_accel() { return false; }
-       public boolean has_gps() { return false; }
-       public boolean has_ignite() { return false; };
-}
diff --git a/altoslib/AltosRecordMM.java b/altoslib/AltosRecordMM.java
deleted file mode 100644 (file)
index d697111..0000000
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright © 2012 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 org.altusmetrum.altoslib_1;
-
-public class AltosRecordMM extends AltosRecord {
-
-       /* Sensor values */
-       public int      accel;
-       public int      pres;
-       public int      temp;
-       
-       public int      v_batt;
-       public int      v_pyro;
-       public int      sense[];
-
-       public int      ground_accel;
-       public int      ground_pres;
-       public int      accel_plus_g;
-       public int      accel_minus_g;
-
-       public int      flight_accel;
-       public int      flight_vel;
-       public int      flight_pres;
-
-       public final static int num_sense = 6;
-
-       public AltosIMU imu;
-       public AltosMag mag;
-
-       static double adc(int raw) {
-               return raw / 4095.0;
-       }
-
-       public double pressure() {
-               if (pres != MISSING)
-                       return pres;
-               return MISSING;
-       }
-
-       public double ground_pressure() {
-               if (ground_pres != MISSING)
-                       return ground_pres;
-               return MISSING;
-       }
-
-       public double battery_voltage() {
-               if (v_batt != MISSING)
-                       return 3.3 * adc(v_batt) * (15.0 + 27.0) / 27.0;
-               return MISSING;
-       }
-
-       static double pyro(int raw) {
-               if (raw != MISSING)
-                       return 3.3 * adc(raw) * (100.0 + 27.0) / 27.0;
-               return MISSING;
-       }
-
-       public double main_voltage() {
-               return pyro(sense[5]);
-       }
-
-       public double drogue_voltage() {
-               return pyro(sense[4]);
-       }
-
-       public double temperature() {
-               if (temp != MISSING)
-                       return temp / 100.0;
-               return MISSING;
-       }
-       
-       public AltosIMU imu() { return imu; }
-
-       public AltosMag mag() { return mag; }
-
-       double accel_counts_per_mss() {
-               double  counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
-
-               return counts_per_g / 9.80665;
-       }
-
-       public double acceleration() {
-               if (ground_accel == MISSING || accel == MISSING)
-                       return MISSING;
-
-               if (accel_minus_g == MISSING || accel_plus_g == MISSING)
-                       return MISSING;
-
-               return (ground_accel - accel) / accel_counts_per_mss();
-       }
-
-       public void copy (AltosRecordMM old) {
-               super.copy(old);
-
-               accel = old.accel;
-               pres = old.pres;
-               temp = old.temp;
-
-               v_batt = old.v_batt;
-               v_pyro = old.v_pyro;
-               sense = new int[num_sense];
-               
-               for (int i = 0; i < num_sense; i++)
-                       sense[i] = old.sense[i];
-
-               ground_accel = old.ground_accel;
-               ground_pres = old.ground_pres;
-               accel_plus_g = old.accel_plus_g;
-               accel_minus_g = old.accel_minus_g;
-               
-               flight_accel = old.flight_accel;
-               flight_vel = old.flight_vel;
-               flight_pres = old.flight_pres;
-
-               imu = old.imu;
-               mag = old.mag;
-       }
-
-
-
-       public AltosRecordMM clone() {
-               return new AltosRecordMM(this);
-       }
-
-       void make_missing() {
-
-               accel = MISSING;
-               pres = MISSING;
-               temp = MISSING;
-
-               v_batt = MISSING;
-               v_pyro = MISSING;
-               sense = new int[num_sense];
-               for (int i = 0; i < num_sense; i++)
-                       sense[i] = MISSING;
-
-               ground_accel = MISSING;
-               ground_pres = MISSING;
-               accel_plus_g = MISSING;
-               accel_minus_g = MISSING;
-
-               flight_accel = 0;
-               flight_vel = 0;
-               flight_pres = 0;
-
-               imu = new AltosIMU();
-               mag = new AltosMag();
-       }
-
-       public AltosRecordMM(AltosRecord old) {
-               super.copy(old);
-               make_missing();
-       }
-
-       public AltosRecordMM(AltosRecordMM old) {
-               copy(old);
-       }
-
-       public AltosRecordMM() {
-               super();
-               make_missing();
-       }
-}
diff --git a/altoslib/AltosRecordMini.java b/altoslib/AltosRecordMini.java
deleted file mode 100644 (file)
index 253f380..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright © 2012 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 org.altusmetrum.altoslib_1;
-
-public class AltosRecordMini extends AltosRecord {
-
-       /* Sensor values */
-       public int      pres;
-       public int      temp;
-       
-       public int      sense_a;
-       public int      sense_m;
-       public int      v_batt;
-
-       public int      ground_pres;
-
-       public int      flight_accel;
-       public int      flight_vel;
-       public int      flight_pres;
-
-       static double adc(int raw) {
-               return raw / 4095.0;
-       }
-
-       public double pressure() {
-               if (pres != MISSING)
-                       return pres;
-               return MISSING;
-       }
-
-       public double temperature() {
-               if (temp != MISSING)
-                       return temp;
-               return MISSING;
-       }
-
-       public double ground_pressure() {
-               if (ground_pres != MISSING)
-                       return ground_pres;
-               return MISSING;
-       }
-
-       public double battery_voltage() {
-               if (v_batt != MISSING)
-                       return 3.3 * adc(v_batt) * (15.0 + 27.0) / 27.0;
-               return MISSING;
-       }
-
-       static double pyro(int raw) {
-               if (raw != MISSING)
-                       return 3.3 * adc(raw) * (100.0 + 27.0) / 27.0;
-               return MISSING;
-       }
-
-       public double main_voltage() {
-               return pyro(sense_m);
-       }
-
-       public double apogee_voltage() {
-               return pyro(sense_a);
-       }
-
-       public void copy (AltosRecordMini old) {
-               super.copy(old);
-
-               pres = old.pres;
-               temp = old.temp;
-
-               sense_a = old.sense_a;
-               sense_m = old.sense_m;
-               v_batt = old.v_batt;
-
-               ground_pres = old.ground_pres;
-               
-               flight_accel = old.flight_accel;
-               flight_vel = old.flight_vel;
-               flight_pres = old.flight_pres;
-       }
-
-
-
-       public AltosRecordMini clone() {
-               return new AltosRecordMini(this);
-       }
-
-       void make_missing() {
-
-               pres = MISSING;
-
-               sense_a = MISSING;
-               sense_m = MISSING;
-               v_batt = MISSING;
-
-               ground_pres = MISSING;
-
-               flight_accel = 0;
-               flight_vel = 0;
-               flight_pres = 0;
-       }
-
-       public AltosRecordMini(AltosRecord old) {
-               super.copy(old);
-               make_missing();
-       }
-
-       public AltosRecordMini(AltosRecordMini old) {
-               copy(old);
-       }
-
-       public AltosRecordMini() {
-               super();
-               make_missing();
-       }
-}
diff --git a/altoslib/AltosRecordNone.java b/altoslib/AltosRecordNone.java
deleted file mode 100644 (file)
index a95b6a9..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright © 2012 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 org.altusmetrum.altoslib_1;
-
-public class AltosRecordNone extends AltosRecord {
-
-       public double pressure() { return MISSING; }
-       public double ground_pressure() { return MISSING; }
-       public double temperature() { return MISSING; }
-       public double acceleration() { return MISSING; }
-
-       public AltosRecordNone(AltosRecord old) {
-               super.copy(old);
-       }
-
-       public AltosRecordNone clone() {
-               return new AltosRecordNone(this);
-       }
-
-       public AltosRecordNone() {
-               super();
-       }
-}
diff --git a/altoslib/AltosRecordTM.java b/altoslib/AltosRecordTM.java
deleted file mode 100644 (file)
index c6cf364..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright © 2012 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 org.altusmetrum.altoslib_1;
-
-public class AltosRecordTM extends AltosRecord {
-
-       /* Sensor values */
-       public int      accel;
-       public int      pres;
-       public int      temp;
-       public int      batt;
-       public int      drogue;
-       public int      main;
-
-       public int      ground_accel;
-       public int      ground_pres;
-       public int      accel_plus_g;
-       public int      accel_minus_g;
-
-       public int      flight_accel;
-       public int      flight_vel;
-       public int      flight_pres;
-
-       /*
-        * Values for our MP3H6115A pressure sensor
-        *
-        * From the data sheet:
-        *
-        * Pressure range: 15-115 kPa
-        * Voltage at 115kPa: 2.82
-        * Output scale: 27mV/kPa
-        *
-        *
-        * 27 mV/kPa * 2047 / 3300 counts/mV = 16.75 counts/kPa
-        * 2.82V * 2047 / 3.3 counts/V = 1749 counts/115 kPa
-        */
-
-       static final double counts_per_kPa = 27 * 2047 / 3300;
-       static final double counts_at_101_3kPa = 1674.0;
-
-       static double
-       barometer_to_pressure(double count)
-       {
-               return ((count / 16.0) / 2047.0 + 0.095) / 0.009 * 1000.0;
-       }
-
-       public double pressure() {
-               if (pres == MISSING)
-                       return MISSING;
-               return barometer_to_pressure(pres);
-       }
-
-       public double ground_pressure() {
-               if (ground_pres == MISSING)
-                       return MISSING;
-               return barometer_to_pressure(ground_pres);
-       }
-
-       public double battery_voltage() {
-               if (batt == MISSING)
-                       return MISSING;
-               return AltosConvert.cc_battery_to_voltage(batt);
-       }
-
-       public double main_voltage() {
-               if (main == MISSING)
-                       return MISSING;
-               return AltosConvert.cc_ignitor_to_voltage(main);
-       }
-
-       public double drogue_voltage() {
-               if (drogue == MISSING)
-                       return MISSING;
-               return AltosConvert.cc_ignitor_to_voltage(drogue);
-       }
-
-       /* Value for the CC1111 built-in temperature sensor
-        * Output voltage at 0°C = 0.755V
-        * Coefficient = 0.00247V/°C
-        * Reference voltage = 1.25V
-        *
-        * temp = ((value / 32767) * 1.25 - 0.755) / 0.00247
-        *      = (value - 19791.268) / 32768 * 1.25 / 0.00247
-        */
-
-       static double
-       thermometer_to_temperature(double thermo)
-       {
-               return (thermo - 19791.268) / 32728.0 * 1.25 / 0.00247;
-       }
-
-       public double temperature() {
-               if (temp == MISSING)
-                       return MISSING;
-               return thermometer_to_temperature(temp);
-       }
-
-       double accel_counts_per_mss() {
-               double  counts_per_g = Math.abs(accel_minus_g - accel_plus_g) / 2;
-
-               return counts_per_g / 9.80665;
-       }
-
-       public double acceleration() {
-               if (ground_accel == MISSING || accel == MISSING)
-                       return MISSING;
-               return (ground_accel - accel) / accel_counts_per_mss();
-       }
-
-       public void copy(AltosRecordTM old) {
-               super.copy(old);
-
-               version = old.version;
-               callsign = old.callsign;
-               serial = old.serial;
-               flight = old.flight;
-               rssi = old.rssi;
-               status = old.status;
-               state = old.state;
-               tick = old.tick;
-               accel = old.accel;
-               pres = old.pres;
-               temp = old.temp;
-               batt = old.batt;
-               drogue = old.drogue;
-               main = old.main;
-               flight_accel = old.flight_accel;
-               ground_accel = old.ground_accel;
-               flight_vel = old.flight_vel;
-               flight_pres = old.flight_pres;
-               ground_pres = old.ground_pres;
-               accel_plus_g = old.accel_plus_g;
-               accel_minus_g = old.accel_minus_g;
-       }
-
-       public AltosRecordTM clone() {
-               return new AltosRecordTM(this);
-       }
-
-       void make_missing() {
-               accel = MISSING;
-               pres = MISSING;
-               temp = MISSING;
-               batt = MISSING;
-               drogue = MISSING;
-               main = MISSING;
-
-               flight_accel = MISSING;
-               flight_vel = MISSING;
-               flight_pres = MISSING;
-
-               ground_accel = MISSING;
-               ground_pres = MISSING;
-               accel_plus_g = MISSING;
-               accel_minus_g = MISSING;
-       }
-
-       public AltosRecordTM(AltosRecord old) {
-               super.copy(old);
-               make_missing();
-       }
-
-       public AltosRecordTM(AltosRecordTM old) {
-               copy(old);
-       }
-       
-       public AltosRecordTM() {
-               super();
-               make_missing();
-       }
-}
index a7e30370d2696da8db29aedbdb461e3808a332ac..19091d3dfd22cea4055948b566e6548f61689c0c 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 import java.util.*;
@@ -25,10 +25,10 @@ import java.util.*;
  */
 
 public class AltosReplayReader extends AltosFlightReader {
-       Iterator<AltosRecord>   iterator;
+       Iterator<AltosState>    iterator;
        File    file;
 
-       public AltosRecord read() {
+       public AltosState read() {
                if (iterator.hasNext())
                        return iterator.next();
                return null;
@@ -41,11 +41,12 @@ public class AltosReplayReader extends AltosFlightReader {
                /* Make it run in realtime after the rocket leaves the pad */
                if (state.state > AltosLib.ao_flight_pad)
                        Thread.sleep((int) (Math.min(state.time_change,10) * 1000));
+               state.set_received_time(System.currentTimeMillis());
        }
 
        public File backing_file() { return file; }
 
-       public AltosReplayReader(Iterator<AltosRecord> in_iterator, File in_file) {
+       public AltosReplayReader(Iterator<AltosState> in_iterator, File in_file) {
                iterator = in_iterator;
                file = in_file;
                name = file.getName();
index 0800a2c4da1e405abad6d9686cfb76514d6355ff..e9d3147eeb30d1d7654845df6e75a1976c2aeda5 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 
diff --git a/altoslib/AltosSelfFlash.java b/altoslib/AltosSelfFlash.java
new file mode 100644 (file)
index 0000000..0ae797a
--- /dev/null
@@ -0,0 +1,149 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+
+public class AltosSelfFlash {
+       File                    file;
+       FileInputStream         input;
+       AltosHexfile            image;
+       AltosLink               link;
+       boolean                 aborted;
+       AltosFlashListener      listener;
+       byte[]                  read_block, write_block;
+
+       void action(String s, int percent) {
+               if (listener != null && !aborted)
+                       listener.position(s, percent);
+       }
+
+       void action(int part, int total) {
+               int percent = 100 * part / total;
+               action(String.format("%d/%d (%d%%)",
+                                    part, total, percent),
+                      percent);
+       }
+
+       void read_block(long addr) {
+               link.printf("R %x\n", addr);
+               
+       }
+
+       void read_memory(long addr, int len) {
+       }
+               
+       void write_memory(long addr, byte[] data, int start, int len) {
+               
+       }
+
+       void reboot() {
+       }
+
+       public void flash() {
+               try {
+                       int remain = image.data.length;
+                       long flash_addr = image.address;
+                       int image_start = 0;
+
+                       action("start", 0);
+                       action(0, image.data.length);
+                       while (remain > 0 && !aborted) {
+                               int this_time = remain;
+                               if (this_time > 0x100)
+                                       this_time = 0x100;
+
+                               if (link != null) {
+                                       /* write the data */
+                                       write_memory(flash_addr, image.data, image_start, this_time);
+
+                                       byte[] check = read_memory(flash_addr, this_time);
+                                       for (int i = 0; i < this_time; i++)
+                                               if (check[i] != image.data[image_start + i])
+                                                       throw new IOException(String.format("Flash write failed at 0x%x (%02x != %02x)",
+                                                                                           image.address + image_start + i,
+                                                                                           check[i], image.data[image_start + i]));
+                               } else {
+                                       Thread.sleep(100);
+                               }
+
+                               remain -= this_time;
+                               flash_addr += this_time;
+                               image_start += this_time;
+
+                               action(image.data.length - remain, image.data.length);
+                       }
+                       if (!aborted) {
+                               action("done", 100);
+                               if (link != null) {
+                                       reboot();
+                               }
+                       }
+                       if (link != null)
+                               link.close();
+               } catch (IOException ie) {
+                       action(ie.getMessage(), -1);
+                       abort();
+               } catch (InterruptedException ie) {
+                       abort();
+               }
+       }
+
+       public void close() {
+               if (link != null)
+                       link.close();
+       }
+
+       synchronized public void abort() {
+               aborted = true;
+               close();
+       }
+
+       public boolean check_rom_config() {
+               if (link == null)
+                       return true;
+               if (rom_config == null)
+                       rom_config = debug.romconfig();
+               return rom_config != null && rom_config.valid();
+       }
+
+       public void set_romconfig (AltosRomconfig romconfig) {
+               rom_config = romconfig;
+       }
+
+       public AltosRomconfig romconfig() {
+               if (!check_rom_config())
+                       return null;
+               return rom_config;
+       }
+
+       public AltosFlash(File file, AltosLink link, AltosFlashListener listener)
+               throws IOException, FileNotFoundException, InterruptedException {
+               this.file = file;
+               this.link = link;
+               this.listener = listener;
+               this.read_block = new byte[256];
+               this.write_block = new byte[256];
+               input = new FileInputStream(file);
+               image = new AltosHexfile(input);
+               if (link != null) {
+                       debug.close();
+                       throw new IOException("Debug port not connected");
+               }
+       }
+}
\ No newline at end of file
diff --git a/altoslib/AltosSensorEMini.java b/altoslib/AltosSensorEMini.java
new file mode 100644 (file)
index 0000000..cbc6514
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2012 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 org.altusmetrum.altoslib_2;
+
+import java.util.concurrent.TimeoutException;
+
+public class AltosSensorEMini {
+       public int      tick;
+       public int      apogee;
+       public int      main;
+       public int      batt;
+
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosSensorEMini        sensor_emini = new AltosSensorEMini(link);
+
+                       if (sensor_emini == null)
+                               return;
+                       state.set_battery_voltage(AltosConvert.easy_mini_voltage(sensor_emini.batt));
+                       state.set_apogee_voltage(AltosConvert.easy_mini_voltage(sensor_emini.apogee));
+                       state.set_main_voltage(AltosConvert.easy_mini_voltage(sensor_emini.main));
+                       
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+       }
+
+       public AltosSensorEMini(AltosLink link) throws InterruptedException, TimeoutException {
+               String[] items = link.adc();
+               for (int i = 0; i < items.length;) {
+                       if (items[i].equals("tick:")) {
+                               tick = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("apogee:")) {
+                               apogee = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("main:")) {
+                               main = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("batt:")) {
+                               batt = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       i++;
+               }
+       }
+}
+
index 6d1b61c079fa3d9305a661f871da2122651ffe1d..0ef42cf683e372938d951ddd788ec0dad0c7f4c9 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.util.concurrent.TimeoutException;
 
diff --git a/altoslib/AltosSensorMega.java b/altoslib/AltosSensorMega.java
new file mode 100644 (file)
index 0000000..3afb8a6
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.util.concurrent.TimeoutException;
+
+class AltosSensorMega {
+       int             tick;
+       int[]           sense;
+       int             v_batt;
+       int             v_pbatt;
+       int             temp;
+
+       public AltosSensorMega() {
+               sense = new int[6];
+       }
+
+       public AltosSensorMega(AltosLink link) throws InterruptedException, TimeoutException {
+               this();
+               String[] items = link.adc();
+               for (int i = 0; i < items.length;) {
+                       if (items[i].equals("tick:")) {
+                               tick = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("A:")) {
+                               sense[0] = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("B:")) {
+                               sense[1] = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("C:")) {
+                               sense[2] = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("D:")) {
+                               sense[3] = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("drogue:")) {
+                               sense[4] = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("main:")) {
+                               sense[5] = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("batt:")) {
+                               v_batt = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("pbatt:")) {
+                               v_pbatt = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("temp:")) {
+                               temp = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       i++;
+               }
+       }
+
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosSensorMega sensor_mega = new AltosSensorMega(link);
+
+                       state.set_battery_voltage(AltosConvert.mega_battery_voltage(sensor_mega.v_batt));
+                       state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sensor_mega.sense[4]));
+                       state.set_main_voltage(AltosConvert.mega_pyro_voltage(sensor_mega.sense[5]));
+
+                       double[]        ignitor_voltage = new double[4];
+                       for (int i = 0; i < 4; i++)
+                               ignitor_voltage[i] = AltosConvert.mega_pyro_voltage(sensor_mega.sense[i]);
+                       state.set_ignitor_voltage(ignitor_voltage);
+
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+       }
+}
+
diff --git a/altoslib/AltosSensorMetrum.java b/altoslib/AltosSensorMetrum.java
new file mode 100644 (file)
index 0000000..4a51d49
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.util.concurrent.TimeoutException;
+
+class AltosSensorMetrum {
+       int             tick;
+       int             sense_a;
+       int             sense_m;
+       int             v_batt;
+
+       public AltosSensorMetrum(AltosLink link) throws InterruptedException, TimeoutException {
+               String[] items = link.adc();
+               for (int i = 0; i < items.length;) {
+                       if (items[i].equals("tick:")) {
+                               tick = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("drogue:")) {
+                               sense_a = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("main:")) {
+                               sense_m = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("batt:")) {
+                               v_batt = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       i++;
+               }
+       }
+
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosSensorMetrum       sensor_metrum = new AltosSensorMetrum(link);
+                       state.set_battery_voltage(AltosConvert.mega_battery_voltage(sensor_metrum.v_batt));
+                       state.set_apogee_voltage(AltosConvert.mega_pyro_voltage(sensor_metrum.sense_a));
+                       state.set_main_voltage(AltosConvert.mega_pyro_voltage(sensor_metrum.sense_m));
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+       }
+}
+
index 754dc5bbbc85cec8d762a5ec8fc5be1da31b9fde..2696a3080a252c68f10f43e1b0d49c75f82f5e20 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.util.concurrent.TimeoutException;
 
-class AltosSensorTM extends AltosRecordTM {
+public class AltosSensorTM {
+       public int      tick;
+       public int      accel;
+       public int      pres;
+       public int      temp;
+       public int      batt;
+       public int      drogue;
+       public int      main;
 
-       public AltosSensorTM(AltosLink link, AltosConfigData config_data) throws InterruptedException, TimeoutException {
-               super();
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosSensorTM   sensor_tm = new AltosSensorTM(link);
+
+                       if (sensor_tm == null)
+                               return;
+                       state.set_accel(sensor_tm.accel);
+                       state.set_pressure(AltosConvert.barometer_to_pressure(sensor_tm.pres));
+                       state.set_temperature(AltosConvert.thermometer_to_temperature(sensor_tm.temp));
+                       state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(sensor_tm.batt));
+                       state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(sensor_tm.drogue));
+                       state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(sensor_tm.main));
+                       
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+       }
+
+       public AltosSensorTM(AltosLink link) throws InterruptedException, TimeoutException {
                String[] items = link.adc();
                for (int i = 0; i < items.length;) {
                        if (items[i].equals("tick:")) {
@@ -62,10 +86,6 @@ class AltosSensorTM extends AltosRecordTM {
                        }
                        i++;
                }
-               ground_accel = config_data.accel_cal_plus;
-               ground_pres = pres;
-               accel_plus_g = config_data.accel_cal_plus;
-               accel_minus_g = config_data.accel_cal_minus;
        }
 }
 
diff --git a/altoslib/AltosSensorTMini.java b/altoslib/AltosSensorTMini.java
new file mode 100644 (file)
index 0000000..be071e5
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2012 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 org.altusmetrum.altoslib_2;
+
+import java.util.concurrent.TimeoutException;
+
+public class AltosSensorTMini {
+       public int      tick;
+       public int      apogee;
+       public int      main;
+       public int      batt;
+
+       static public void update_state(AltosState state, AltosLink link, AltosConfigData config_data) {
+               try {
+                       AltosSensorTMini        sensor_tmini = new AltosSensorTMini(link);
+
+                       if (sensor_tmini == null)
+                               return;
+                       state.set_battery_voltage(AltosConvert.easy_mini_voltage(sensor_tmini.batt));
+                       state.set_apogee_voltage(AltosConvert.easy_mini_voltage(sensor_tmini.apogee));
+                       state.set_main_voltage(AltosConvert.easy_mini_voltage(sensor_tmini.main));
+                       
+               } catch (TimeoutException te) {
+               } catch (InterruptedException ie) {
+               }
+       }
+
+       public AltosSensorTMini(AltosLink link) throws InterruptedException, TimeoutException {
+               String[] items = link.adc();
+               for (int i = 0; i < items.length;) {
+                       if (items[i].equals("tick:")) {
+                               tick = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("apogee:")) {
+                               apogee = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("main:")) {
+                               main = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       if (items[i].equals("batt:")) {
+                               batt = Integer.parseInt(items[i+1]);
+                               i += 2;
+                               continue;
+                       }
+                       i++;
+               }
+       }
+}
+
index 6fb624fb664bbab32511848765e54dccb566f77a..9b9f7240e781e4b0e8f3568c3b44b7b51158e722 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosSpeed extends AltosUnits {
 
index e0d9bb1fc394dc1cb42b495bc03e755d135968bb..a01cddb774d1a5a567d10869a80ee669fe783938 100644 (file)
  * Track flight state from telemetry or eeprom data stream
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
-public class AltosState {
-       public AltosRecord data;
+public class AltosState implements Cloneable {
+
+       public static final int set_position = 1;
+       public static final int set_gps = 2;
+       public static final int set_data = 4;
+
+       public int set;
+
+       static final double ascent_filter_len = 0.5;
+       static final double descent_filter_len = 0.5;
 
        /* derived data */
 
-       public long     report_time;
+       public long     received_time;
 
        public double   time;
+       public double   prev_time;
        public double   time_change;
        public int      tick;
+       private int     prev_tick;
+       public int      boost_tick;
+
+       class AltosValue {
+               private double  value;
+               private double  prev_value;
+               private double  max_value;
+               private double  set_time;
+               private double  prev_set_time;
+
+               void set(double new_value, double time) {
+                       if (new_value != AltosLib.MISSING) {
+                               value = new_value;
+                               if (max_value == AltosLib.MISSING || value > max_value) {
+                                       max_value = value;
+                               }
+                               set_time = time;
+                       }
+               }
+
+               void set_filtered(double new_value, double time) {
+                       if (prev_value != AltosLib.MISSING)
+                               new_value = (prev_value * 15.0 + new_value) / 16.0;
+                       set(new_value, time);
+               }
+
+               double value() {
+                       return value;
+               }
+
+               double max() {
+                       return max_value;
+               }
+
+               double prev() {
+                       return prev_value;
+               }
+
+               double change() {
+                       if (value != AltosLib.MISSING && prev_value != AltosLib.MISSING)
+                               return value - prev_value;
+                       return AltosLib.MISSING;
+               }
+
+               double rate() {
+                       double c = change();
+                       double t = set_time - prev_set_time;
+
+                       if (c != AltosLib.MISSING && t != 0)
+                               return c / t;
+                       return AltosLib.MISSING;
+               }
+
+               double integrate() {
+                       if (value == AltosLib.MISSING)
+                               return AltosLib.MISSING;
+                       if (prev_value == AltosLib.MISSING)
+                               return AltosLib.MISSING;
+
+                       return (value + prev_value) / 2 * (set_time - prev_set_time);
+               }
+
+               double time() {
+                       return set_time;
+               }
+
+               void set_derivative(AltosValue in) {
+                       double  n = in.rate();
+                       
+                       if (n == AltosLib.MISSING)
+                               return;
+
+                       double  p = prev_value;
+                       double  pt = prev_set_time;
+
+                       if (p == AltosLib.MISSING) {
+                               p = 0;
+                               pt = in.time() - 0.01;
+                       }
+
+                       /* Clip changes to reduce noise */
+                       double  ddt = in.time() - pt;
+                       double  ddv = (n - p) / ddt;
+                               
+                       final double max = 100000;
+
+                       /* 100gs */
+                       if (Math.abs(ddv) > max) {
+                               if (n > p)
+                                       n = p + ddt * max;
+                               else
+                                       n = p - ddt * max;
+                       }
+
+                       double filter_len;
+
+                       if (ascent)
+                               filter_len = ascent_filter_len;
+                       else
+                               filter_len = descent_filter_len;
+
+                       double f = 1/Math.exp(ddt/ filter_len);
+                       n = p * f + n * (1-f);
+
+                       set(n, in.time());
+               }
+
+               void set_integral(AltosValue in) {
+                       double  change = in.integrate();
+
+                       if (change != AltosLib.MISSING) {
+                               double  prev = prev_value;
+                               if (prev == AltosLib.MISSING)
+                                       prev = 0;
+                               set(prev + change, in.time());
+                       }
+               }
+
+               void copy(AltosValue old) {
+                       value = old.value;
+                       set_time = old.set_time;
+                       prev_value = old.value;
+                       prev_set_time = old.set_time;
+                       max_value = old.max_value;
+               }
+
+               void finish_update() {
+                       prev_value = value;
+                       prev_set_time = set_time;
+               }
+
+               AltosValue() {
+                       value = AltosLib.MISSING;
+                       prev_value = AltosLib.MISSING;
+                       max_value = AltosLib.MISSING;
+               }
+       }
+
+       class AltosCValue {
+               AltosValue      measured;
+               AltosValue      computed;
+
+               double value() {
+                       double v = measured.value();
+                       if (v != AltosLib.MISSING)
+                               return v;
+                       return computed.value();
+               }
+
+               boolean is_measured() {
+                       return measured.value() != AltosLib.MISSING;
+               }
+
+               double max() {
+                       double m = measured.max();
+
+                       if (m != AltosLib.MISSING)
+                               return m;
+                       return computed.max();
+               }
+
+               double prev_value() {
+                       if (measured.value != AltosLib.MISSING && measured.prev_value != AltosLib.MISSING)
+                               return measured.prev_value;
+                       return computed.prev_value;
+               }
+
+               AltosValue altos_value() {
+                       if (measured.value() != AltosLib.MISSING)
+                               return measured;
+                       return computed;
+               }
+
+               double change() {
+                       double c = measured.change();
+                       if (c == AltosLib.MISSING)
+                               c = computed.change();
+                       return c;
+               }
+
+               double rate() {
+                       double r = measured.rate();
+                       if (r == AltosLib.MISSING)
+                               r = computed.rate();
+                       return r;
+               }
+
+               void set_measured(double new_value, double time) {
+                       measured.set(new_value, time);
+               }
+
+               void set_computed(double new_value, double time) {
+                       computed.set(new_value, time);
+               }
+
+               void set_derivative(AltosValue in) {
+                       computed.set_derivative(in);
+               }
+
+               void set_derivative(AltosCValue in) {
+                       set_derivative(in.altos_value());
+               }
+
+               void set_integral(AltosValue in) {
+                       computed.set_integral(in);
+               }
+               
+               void set_integral(AltosCValue in) {
+                       set_integral(in.altos_value());
+               }
+               
+               void copy(AltosCValue old) {
+                       measured.copy(old.measured);
+                       computed.copy(old.computed);
+               }
+
+               void finish_update() {
+                       measured.finish_update();
+                       computed.finish_update();
+               }
+
+               AltosCValue() {
+                       measured = new AltosValue();
+                       computed = new AltosValue();
+               }
+       }
 
        public int      state;
+       public int      flight;
+       public int      serial;
+       public int      receiver_serial;
        public boolean  landed;
        public boolean  ascent; /* going up? */
-       public boolean boost;   /* under power */
-
-       public double   ground_altitude;
-       public double   altitude;
-       public double   height;
-       public double   pressure;
-       public double   acceleration;
-       public double   battery;
+       public boolean  boost;  /* under power */
+       public int      rssi;
+       public int      status;
+       public int      device_type;
+       public int      config_major;
+       public int      config_minor;
+       public int      apogee_delay;
+       public int      main_deploy;
+       public int      flight_log_max;
+
+       private double pressure_to_altitude(double p) {
+               if (p == AltosLib.MISSING)
+                       return AltosLib.MISSING;
+               return AltosConvert.pressure_to_altitude(p);
+       }
+
+       private AltosCValue ground_altitude;
+
+       public double ground_altitude() {
+               return ground_altitude.value();
+       }
+
+       public void set_ground_altitude(double a) {
+               ground_altitude.set_measured(a, time);
+       }
+
+       class AltosGroundPressure extends AltosCValue {
+               void set_filtered(double p, double time) {
+                       computed.set_filtered(p, time);
+                       if (!is_measured())
+                               ground_altitude.set_computed(pressure_to_altitude(computed.value()), time);
+               }
+
+               void set_measured(double p, double time) {
+                       super.set_measured(p, time);
+                       ground_altitude.set_computed(pressure_to_altitude(p), time);
+               }
+       }
+
+       private AltosGroundPressure ground_pressure;
+               
+       public double ground_pressure() {
+               return ground_pressure.value();
+       }
+
+       public void set_ground_pressure (double pressure) {
+               ground_pressure.set_measured(pressure, time);
+       }
+
+       class AltosAltitude extends AltosCValue {
+
+               private void set_speed(AltosValue v) {
+                       if (!acceleration.is_measured() || !ascent)
+                               speed.set_derivative(this);
+               }
+
+               void set_computed(double a, double time) {
+                       super.set_computed(a,time);
+                       set_speed(computed);
+                       set |= set_position;
+               }
+
+               void set_measured(double a, double time) {
+                       super.set_measured(a,time);
+                       set_speed(measured);
+                       set |= set_position;
+               }
+       }
+
+       private AltosAltitude   altitude;
+
+       public double altitude() {
+               double a = altitude.value();
+               if (a != AltosLib.MISSING)
+                       return a;
+               if (gps != null)
+                       return gps.alt;
+               return AltosLib.MISSING;
+       }
+
+       public double max_altitude() {
+               double a = altitude.max();
+               if (a != AltosLib.MISSING)
+                       return a;
+               return AltosLib.MISSING;
+       }
+
+       public void set_altitude(double new_altitude) {
+               altitude.set_measured(new_altitude, time);
+       }
+
+       class AltosPressure extends AltosValue {
+               void set(double p, double time) {
+                       super.set(p, time);
+                       if (state == AltosLib.ao_flight_pad)
+                               ground_pressure.set_filtered(p, time);
+                       double a = pressure_to_altitude(p);
+                       altitude.set_computed(a, time);
+               }
+       }
+
+       private AltosPressure   pressure;
+
+       public double pressure() {
+               return pressure.value();
+       }
+
+       public void set_pressure(double p) {
+               pressure.set(p, time);
+       }
+
+       public double height() {
+               double k = kalman_height.value();
+               if (k != AltosLib.MISSING)
+                       return k;
+
+               double a = altitude();
+               double g = ground_altitude();
+               if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+                       return a - g;
+               return AltosLib.MISSING;
+       }
+
+       public double max_height() {
+               double  k = kalman_height.max();
+               if (k != AltosLib.MISSING)
+                       return k;
+
+               double a = altitude.max();
+               double g = ground_altitude();
+               if (a != AltosLib.MISSING && g != AltosLib.MISSING)
+                       return a - g;
+               return AltosLib.MISSING;
+       }
+
+       class AltosSpeed extends AltosCValue {
+               
+               void set_accel() {
+                       acceleration.set_derivative(this);
+               }
+
+               void set_derivative(AltosCValue in) {
+                       super.set_derivative(in);
+                       set_accel();
+               }
+
+               void set_computed(double new_value, double time) {
+                       super.set_computed(new_value, time);
+                       set_accel();
+               }
+
+               void set_measured(double new_value, double time) {
+                       super.set_measured(new_value, time);
+                       set_accel();
+               }
+       }
+
+       private AltosSpeed speed;
+
+       public double speed() {
+               double v = kalman_speed.value();
+               if (v != AltosLib.MISSING)
+                       return v;
+               return speed.value();
+       }
+
+       public double max_speed() {
+               double v = kalman_speed.max();
+               if (v != AltosLib.MISSING)
+                       return v;
+               return speed.max();
+       }
+
+       class AltosAccel extends AltosCValue {
+               void set_measured(double a, double time) {
+                       super.set_measured(a, time);
+                       if (ascent)
+                               speed.set_integral(this.measured);
+               }
+       }
+
+       AltosAccel acceleration;
+
+       public double acceleration() {
+               return acceleration.value();
+       }
+
+       public double max_acceleration() {
+               return acceleration.max();
+       }
+
+       public AltosValue       kalman_height, kalman_speed, kalman_acceleration;
+
+       public void set_kalman(double height, double speed, double acceleration) {
+               kalman_height.set(height, time);
+               kalman_speed.set(speed, time);
+               kalman_acceleration.set(acceleration, time);
+       }
+
+       public double   battery_voltage;
+       public double   pyro_voltage;
        public double   temperature;
-       public double   main_sense;
-       public double   drogue_sense;
-       public double   accel_speed;
-       public double   baro_speed;
+       public double   apogee_voltage;
+       public double   main_voltage;
 
-       public double   max_height;
-       public double   max_acceleration;
-       public double   max_accel_speed;
-       public double   max_baro_speed;
+       public double   ignitor_voltage[];
 
        public AltosGPS gps;
+       public AltosGPS temp_gps;
+       public int temp_gps_sat_tick;
+       public boolean  gps_pending;
        public int gps_sequence;
 
        public AltosIMU imu;
@@ -63,10 +492,11 @@ public class AltosState {
        public static final int MIN_PAD_SAMPLES = 10;
 
        public int      npad;
-       public int      ngps;
        public int      gps_waiting;
        public boolean  gps_ready;
 
+       public int      ngps;
+
        public AltosGreatCircle from_pad;
        public double   elevation;      /* from pad */
        public double   range;          /* total distance */
@@ -78,203 +508,551 @@ public class AltosState {
        public int      speak_tick;
        public double   speak_altitude;
 
-       public double speed() {
-               if (ascent)
-                       return accel_speed;
-               else
-                       return baro_speed;
+       public String   callsign;
+       public String   firmware_version;
+
+       public double   accel_plus_g;
+       public double   accel_minus_g;
+       public double   accel;
+       public double   ground_accel;
+       public double   ground_accel_avg;
+
+       public int      log_format;
+
+       public AltosMs5607      baro;
+
+       public AltosCompanion   companion;
+
+       public void set_npad(int npad) {
+               this.npad = npad;
+               gps_waiting = MIN_PAD_SAMPLES - npad;
+               if (this.gps_waiting < 0)
+                       gps_waiting = 0;
+               gps_ready = gps_waiting == 0;
        }
 
-       public double max_speed() {
-               if (max_accel_speed != 0)
-                       return max_accel_speed;
-               return max_baro_speed;
-       }
-
-       public void init (AltosRecord cur, AltosState prev_state) {
-               data = cur;
-
-               /* Discard previous state if it was for a different board */
-               if (prev_state != null && prev_state.data.serial != data.serial)
-                       prev_state = null;
-               ground_altitude = data.ground_altitude();
-
-               altitude = data.altitude();
-               if (altitude == AltosRecord.MISSING && data.gps != null)
-                       altitude = data.gps.alt;
-
-               height = AltosRecord.MISSING;
-               if (data.kalman_height != AltosRecord.MISSING)
-                       height = data.kalman_height;
-               else {
-                       if (altitude != AltosRecord.MISSING && ground_altitude != AltosRecord.MISSING) {
-                               double  cur_height = altitude - ground_altitude;
-                               if (prev_state == null || prev_state.height == AltosRecord.MISSING)
-                                       height = cur_height;
-                               else
-                                       height = (prev_state.height * 15 + cur_height) / 16.0;
-                       }
+       public void init() {
+               set = 0;
+
+               received_time = System.currentTimeMillis();
+               time = AltosLib.MISSING;
+               time_change = AltosLib.MISSING;
+               prev_time = AltosLib.MISSING;
+               tick = AltosLib.MISSING;
+               prev_tick = AltosLib.MISSING;
+               boost_tick = AltosLib.MISSING;
+               state = AltosLib.ao_flight_invalid;
+               flight = AltosLib.MISSING;
+               landed = false;
+               boost = false;
+               rssi = AltosLib.MISSING;
+               status = 0;
+               device_type = AltosLib.MISSING;
+               config_major = AltosLib.MISSING;
+               config_minor = AltosLib.MISSING;
+               apogee_delay = AltosLib.MISSING;
+               main_deploy = AltosLib.MISSING;
+               flight_log_max = AltosLib.MISSING;
+
+               ground_altitude = new AltosCValue();
+               ground_pressure = new AltosGroundPressure();
+               altitude = new AltosAltitude();
+               pressure = new AltosPressure();
+               speed = new AltosSpeed();
+               acceleration = new AltosAccel();
+
+               temperature = AltosLib.MISSING;
+               battery_voltage = AltosLib.MISSING;
+               pyro_voltage = AltosLib.MISSING;
+               apogee_voltage = AltosLib.MISSING;
+               main_voltage = AltosLib.MISSING;
+               ignitor_voltage = null;
+
+               kalman_height = new AltosValue();
+               kalman_speed = new AltosValue();
+               kalman_acceleration = new AltosValue();
+
+               gps = null;
+               temp_gps = null;
+               temp_gps_sat_tick = 0;
+               gps_sequence = 0;
+               gps_pending = false;
+
+               imu = null;
+               mag = null;
+
+               set_npad(0);
+               ngps = 0;
+
+               from_pad = null;
+               elevation = AltosLib.MISSING;
+               range = AltosLib.MISSING;
+               gps_height = AltosLib.MISSING;
+
+               pad_lat = AltosLib.MISSING;
+               pad_lon = AltosLib.MISSING;
+               pad_alt = AltosLib.MISSING;
+
+               speak_tick = AltosLib.MISSING;
+               speak_altitude = AltosLib.MISSING;
+
+               callsign = null;
+
+               accel_plus_g = AltosLib.MISSING;
+               accel_minus_g = AltosLib.MISSING;
+               accel = AltosLib.MISSING;
+
+               ground_accel = AltosLib.MISSING;
+               ground_accel_avg = AltosLib.MISSING;
+
+               log_format = AltosLib.MISSING;
+               serial = AltosLib.MISSING;
+               receiver_serial = AltosLib.MISSING;
+
+               baro = null;
+               companion = null;
+       }
+
+       void finish_update() {
+               prev_tick = tick;
+
+               ground_altitude.finish_update();
+               altitude.finish_update();
+               pressure.finish_update();
+               speed.finish_update();
+               acceleration.finish_update();
+
+               kalman_height.finish_update();
+               kalman_speed.finish_update();
+               kalman_acceleration.finish_update();
+       }
+
+       void copy(AltosState old) {
+
+               if (old == null) {
+                       init();
+                       return;
                }
 
-               report_time = System.currentTimeMillis();
+               received_time = old.received_time;
+               time = old.time;
+               time_change = old.time_change;
+               prev_time = old.time;
+               
+               tick = old.tick;
+               prev_tick = old.tick;
+               boost_tick = old.boost_tick;
+
+               state = old.state;
+               flight = old.flight;
+               landed = old.landed;
+               ascent = old.ascent;
+               boost = old.boost;
+               rssi = old.rssi;
+               status = old.status;
+               device_type = old.device_type;
+               config_major = old.config_major;
+               config_minor = old.config_minor;
+               apogee_delay = old.apogee_delay;
+               main_deploy = old.main_deploy;
+               flight_log_max = old.flight_log_max;
+               
+               set = 0;
+
+               ground_pressure.copy(old.ground_pressure);
+               ground_altitude.copy(old.ground_altitude);
+               altitude.copy(old.altitude);
+               pressure.copy(old.pressure);
+               speed.copy(old.speed);
+               acceleration.copy(old.acceleration);
+
+               battery_voltage = old.battery_voltage;
+               pyro_voltage = old.pyro_voltage;
+               temperature = old.temperature;
+               apogee_voltage = old.apogee_voltage;
+               main_voltage = old.main_voltage;
+               ignitor_voltage = old.ignitor_voltage;
+
+               kalman_height.copy(old.kalman_height);
+               kalman_speed.copy(old.kalman_speed);
+               kalman_acceleration.copy(old.kalman_acceleration);
 
-               if (data.kalman_acceleration != AltosRecord.MISSING)
-                       acceleration = data.kalman_acceleration;
+               if (old.gps != null)
+                       gps = old.gps.clone();
                else
-                       acceleration = data.acceleration();
-               temperature = data.temperature();
-               drogue_sense = data.drogue_voltage();
-               main_sense = data.main_voltage();
-               battery = data.battery_voltage();
-               pressure = data.pressure();
-               tick = data.tick;
-               state = data.state;
-
-               if (prev_state != null) {
-
-                       /* Preserve any existing gps data */
-                       npad = prev_state.npad;
-                       ngps = prev_state.ngps;
-                       gps = prev_state.gps;
-                       gps_sequence = prev_state.gps_sequence;
-                       pad_lat = prev_state.pad_lat;
-                       pad_lon = prev_state.pad_lon;
-                       pad_alt = prev_state.pad_alt;
-                       max_height = prev_state.max_height;
-                       max_acceleration = prev_state.max_acceleration;
-                       max_accel_speed = prev_state.max_accel_speed;
-                       max_baro_speed = prev_state.max_baro_speed;
-                       imu = prev_state.imu;
-                       mag = prev_state.mag;
-
-                       /* make sure the clock is monotonic */
-                       while (tick < prev_state.tick)
-                               tick += 65536;
-
-                       time_change = (tick - prev_state.tick) / 100.0;
-
-                       if (data.kalman_speed != AltosRecord.MISSING) {
-                               baro_speed = accel_speed = data.kalman_speed;
-                       } else {
-                               /* compute barometric speed */
-
-                               double height_change = height - prev_state.height;
-
-                               double prev_baro_speed = prev_state.baro_speed;
-                               if (prev_baro_speed == AltosRecord.MISSING)
-                                       prev_baro_speed = 0;
-
-                               if (time_change > 0)
-                                       baro_speed = (prev_baro_speed * 3 + (height_change / time_change)) / 4.0;
-                               else
-                                       baro_speed = prev_state.baro_speed;
+                       gps = null;
+               if (old.temp_gps != null)
+                       temp_gps = old.temp_gps.clone();
+               else
+                       temp_gps = null;
+               temp_gps_sat_tick = old.temp_gps_sat_tick;
+               gps_sequence = old.gps_sequence;
+               gps_pending = old.gps_pending;
 
-                               double prev_accel_speed = prev_state.accel_speed;
+               if (old.imu != null)
+                       imu = old.imu.clone();
+               else
+                       imu = null;
 
-                               if (prev_accel_speed == AltosRecord.MISSING)
-                                       prev_accel_speed = 0;
+               if (old.mag != null)
+                       mag = old.mag.clone();
+               else
+                       mag = null;
 
-                               if (acceleration == AltosRecord.MISSING) {
-                                       /* Fill in mising acceleration value */
-                                       accel_speed = baro_speed;
+               npad = old.npad;
+               gps_waiting = old.gps_waiting;
+               gps_ready = old.gps_ready;
+               ngps = old.ngps;
 
-                                       if (time_change > 0 && accel_speed != AltosRecord.MISSING)
-                                               acceleration = (accel_speed - prev_accel_speed) / time_change;
-                                       else
-                                               acceleration = prev_state.acceleration;
-                               } else {
-                                       /* compute accelerometer speed */
-                                       accel_speed = prev_accel_speed + acceleration * time_change;
+               if (old.from_pad != null)
+                       from_pad = old.from_pad.clone();
+               else
+                       from_pad = null;
+
+               elevation = old.elevation;
+               range = old.range;
+
+               gps_height = old.gps_height;
+               pad_lat = old.pad_lat;
+               pad_lon = old.pad_lon;
+               pad_alt = old.pad_alt;
+
+               speak_tick = old.speak_tick;
+               speak_altitude = old.speak_altitude;
+
+               callsign = old.callsign;
+
+               accel_plus_g = old.accel_plus_g;
+               accel_minus_g = old.accel_minus_g;
+               accel = old.accel;
+               ground_accel = old.ground_accel;
+               ground_accel_avg = old.ground_accel_avg;
+
+               log_format = old.log_format;
+               serial = old.serial;
+               receiver_serial = old.receiver_serial;
+
+               baro = old.baro;
+               companion = old.companion;
+       }
+       
+       void update_time() {
+       }
+
+       void update_gps() {
+               elevation = 0;
+               range = -1;
+               gps_height = 0;
+
+               if (gps == null)
+                       return;
+
+               if (gps.locked && gps.nsat >= 4) {
+                       /* Track consecutive 'good' gps reports, waiting for 10 of them */
+                       if (state == AltosLib.ao_flight_pad) {
+                               set_npad(npad+1);
+                               if (pad_lat != AltosLib.MISSING) {
+                                       pad_lat = (pad_lat * 31 + gps.lat) / 32;
+                                       pad_lon = (pad_lon * 31 + gps.lon) / 32;
+                                       pad_alt = (pad_alt * 31 + gps.alt) / 32;
                                }
                        }
-               } else {
-                       npad = 0;
-                       ngps = 0;
-                       gps = null;
-                       gps_sequence = 0;
-                       baro_speed = AltosRecord.MISSING;
-                       accel_speed = AltosRecord.MISSING;
-                       pad_alt = AltosRecord.MISSING;
-                       max_baro_speed = 0;
-                       max_accel_speed = 0;
-                       max_height = 0;
-                       max_acceleration = 0;
-                       time_change = 0;
+                       if (pad_lat == AltosLib.MISSING) {
+                               pad_lat = gps.lat;
+                               pad_lon = gps.lon;
+                               pad_alt = gps.alt;
+                       }
                }
+               if (gps.lat != 0 && gps.lon != 0 &&
+                   pad_lat != AltosLib.MISSING &&
+                   pad_lon != AltosLib.MISSING)
+               {
+                       double h = height();
 
-               time = tick / 100.0;
-
-               if (data.gps != null && data.gps_sequence != gps_sequence && (state < AltosLib.ao_flight_boost)) {
+                       if (h == AltosLib.MISSING)
+                               h = 0;
+                       from_pad = new AltosGreatCircle(pad_lat, pad_lon, 0, gps.lat, gps.lon, h);
+                       elevation = from_pad.elevation;
+                       range = from_pad.range;
+                       gps_height = gps.alt - pad_alt;
+               }
+       }
 
-                       /* Track consecutive 'good' gps reports, waiting for 10 of them */
-                       if (data.gps != null && data.gps.locked && data.gps.nsat >= 4)
-                               npad++;
-                       else
-                               npad = 0;
-
-                       /* Average GPS data while on the pad */
-                       if (data.gps != null && data.gps.locked && data.gps.nsat >= 4) {
-                               if (ngps > 1 && state == AltosLib.ao_flight_pad) {
-                                       /* filter pad position */
-                                       pad_lat = (pad_lat * 31.0 + data.gps.lat) / 32.0;
-                                       pad_lon = (pad_lon * 31.0 + data.gps.lon) / 32.0;
-                                       pad_alt = (pad_alt * 31.0 + data.gps.alt) / 32.0;
-                               } else {
-                                       pad_lat = data.gps.lat;
-                                       pad_lon = data.gps.lon;
-                                       pad_alt = data.gps.alt;
+       public void set_tick(int new_tick) {
+               if (new_tick != AltosLib.MISSING) {
+                       if (prev_tick != AltosLib.MISSING) {
+                               while (new_tick < prev_tick - 1000) {
+                                       new_tick += 65536;
                                }
-                               ngps++;
                        }
-               } else {
-                       if (ngps == 0 && ground_altitude != AltosRecord.MISSING)
-                               pad_alt = ground_altitude;
+                       tick = new_tick;
+                       time = tick / 100.0;
+                       time_change = time - prev_time;
                }
+       }
 
-               gps_sequence = data.gps_sequence;
+       public void set_boost_tick(int boost_tick) {
+               if (boost_tick != AltosLib.MISSING)
+                       this.boost_tick = boost_tick;
+       }
 
-               gps_waiting = MIN_PAD_SAMPLES - npad;
-               if (gps_waiting < 0)
-                       gps_waiting = 0;
+       public String state_name() {
+               return AltosLib.state_name(state);
+       }
 
-               gps_ready = gps_waiting == 0;
+       public void set_state(int state) {
+               if (state != AltosLib.ao_flight_invalid) {
+                       this.state = state;
+                       ascent = (AltosLib.ao_flight_boost <= state &&
+                                 state <= AltosLib.ao_flight_coast);
+                       boost = (AltosLib.ao_flight_boost == state);
+               }
 
-               ascent = (AltosLib.ao_flight_boost <= state &&
-                         state <= AltosLib.ao_flight_coast);
-               boost = (AltosLib.ao_flight_boost == state);
+       }
 
-               /* Only look at accelerometer data under boost */
-               if (boost && acceleration != AltosRecord.MISSING && (max_acceleration == AltosRecord.MISSING || acceleration > max_acceleration))
-                       max_acceleration = acceleration;
-               if (boost && accel_speed != AltosRecord.MISSING && accel_speed > max_accel_speed)
-                       max_accel_speed = accel_speed;
-               if (boost && baro_speed != AltosRecord.MISSING && baro_speed > max_baro_speed)
-                       max_baro_speed = baro_speed;
+       public void set_device_type(int device_type) {
+               this.device_type = device_type;
+       }
 
-               if (height != AltosRecord.MISSING && height > max_height)
-                       max_height = height;
-               elevation = 0;
-               range = -1;
-               gps_height = 0;
-               if (data.gps != null) {
-                       gps = data.gps;
-                       if (ngps > 0 && gps.locked) {
-                               double h = height;
-
-                               if (h == AltosRecord.MISSING) h = 0;
-                               from_pad = new AltosGreatCircle(pad_lat, pad_lon, 0, gps.lat, gps.lon, h);
-                               elevation = from_pad.elevation;
-                               range = from_pad.range;
-                               gps_height = gps.alt - pad_alt;
+       public void set_config(int major, int minor, int apogee_delay, int main_deploy, int flight_log_max) {
+               config_major = major;
+               config_minor = minor;
+               this.apogee_delay = apogee_delay;
+               this.main_deploy = main_deploy;
+               this.flight_log_max = flight_log_max;
+       }
+
+       public void set_callsign(String callsign) {
+               this.callsign = callsign;
+       }
+
+       public void set_firmware_version(String version) {
+               firmware_version = version;
+       }
+
+       public void set_flight(int flight) {
+
+               /* When the flight changes, reset the state */
+               if (flight != AltosLib.MISSING && flight != 0) {
+                       if (this.flight != AltosLib.MISSING &&
+                           this.flight != flight) {
+                               init();
                        }
+                       this.flight = flight;
                }
        }
 
-       public AltosState(AltosRecord cur) {
-               init(cur, null);
+       public void set_serial(int serial) {
+               /* When the serial changes, reset the state */
+               if (serial != AltosLib.MISSING) {
+                       if (this.serial != AltosLib.MISSING &&
+                           this.serial != serial) {
+                               init();
+                       }
+                       this.serial = serial;
+               }
+       }
+
+       public void set_receiver_serial(int serial) {
+               if (serial != AltosLib.MISSING)
+                       receiver_serial = serial;
+       }
+
+       public int rssi() {
+               if (rssi == AltosLib.MISSING)
+                       return 0;
+               return rssi;
+       }
+
+       public void set_rssi(int rssi, int status) {
+               if (rssi != AltosLib.MISSING) {
+                       this.rssi = rssi;
+                       this.status = status;
+               }
+       }
+
+       public void set_received_time(long ms) {
+               received_time = ms;
+       }
+
+       public void set_gps(AltosGPS gps, int sequence) {
+               if (gps != null) {
+                       this.gps = gps.clone();
+                       gps_sequence = sequence;
+                       update_gps();
+                       set |= set_gps;
+               }
+       }
+
+       public void set_imu(AltosIMU imu) {
+               if (imu != null)
+                       imu = imu.clone();
+               this.imu = imu;
+       }
+
+       public void set_mag(AltosMag mag) {
+               this.mag = mag.clone();
+       }
+
+       public AltosMs5607 make_baro() {
+               if (baro == null)
+                       baro = new AltosMs5607();
+               return baro;
+       }
+
+       public void set_ms5607(AltosMs5607 ms5607) {
+               baro = ms5607;
+
+               if (baro != null) {
+                       set_pressure(baro.pa);
+                       set_temperature(baro.cc / 100.0);
+               }
+       }
+
+       public void set_ms5607(int pres, int temp) {
+               if (baro != null) {
+                       baro.set(pres, temp);
+
+                       set_pressure(baro.pa);
+                       set_temperature(baro.cc / 100.0);
+               }
+       }
+
+       public void make_companion (int nchannels) {
+               if (companion == null)
+                       companion = new AltosCompanion(nchannels);
+       }
+
+       public void set_companion(AltosCompanion companion) {
+               this.companion = companion;
+       }
+
+       void update_accel() {
+               double  ground = ground_accel;
+
+               if (ground == AltosLib.MISSING)
+                       ground = ground_accel_avg;
+               if (accel == AltosLib.MISSING)
+                       return;
+               if (ground == AltosLib.MISSING)
+                       return;
+               if (accel_plus_g == AltosLib.MISSING)
+                       return;
+               if (accel_minus_g == AltosLib.MISSING)
+                       return;
+
+               double counts_per_g = (accel_minus_g - accel_plus_g) / 2.0;
+               double counts_per_mss = counts_per_g / 9.80665;
+               acceleration.set_measured((ground - accel) / counts_per_mss, time);
+       }
+
+       public void set_accel_g(double accel_plus_g, double accel_minus_g) {
+               if (accel_plus_g != AltosLib.MISSING) {
+                       this.accel_plus_g = accel_plus_g;
+                       this.accel_minus_g = accel_minus_g;
+                       update_accel();
+               }
+       }
+
+       public void set_ground_accel(double ground_accel) {
+               if (ground_accel != AltosLib.MISSING) {
+                       this.ground_accel = ground_accel;
+                       update_accel();
+               }
+       }
+
+       public void set_accel(double accel) {
+               if (accel != AltosLib.MISSING) {
+                       this.accel = accel;
+                       if (state == AltosLib.ao_flight_pad) {
+                               if (ground_accel_avg == AltosLib.MISSING)
+                                       ground_accel_avg = accel;
+                               else
+                                       ground_accel_avg = (ground_accel_avg * 7 + accel) / 8;
+                       }
+               }
+               update_accel();
+       }
+
+       public void set_temperature(double temperature) {
+               if (temperature != AltosLib.MISSING) {
+                       this.temperature = temperature;
+                       set |= set_data;
+               }
+       }
+
+       public void set_battery_voltage(double battery_voltage) {
+               if (battery_voltage != AltosLib.MISSING) {
+                       this.battery_voltage = battery_voltage;
+                       set |= set_data;
+               }
+       }
+
+       public void set_pyro_voltage(double pyro_voltage) {
+               if (pyro_voltage != AltosLib.MISSING) {
+                       this.pyro_voltage = pyro_voltage;
+                       set |= set_data;
+               }
+       }
+
+       public void set_apogee_voltage(double apogee_voltage) {
+               if (apogee_voltage != AltosLib.MISSING) {
+                       this.apogee_voltage = apogee_voltage;
+                       set |= set_data;
+               }
+       }
+
+       public void set_main_voltage(double main_voltage) {
+               if (main_voltage != AltosLib.MISSING) {
+                       this.main_voltage = main_voltage;
+                       set |= set_data;
+               }
+       }
+
+       public void set_ignitor_voltage(double[] voltage) {
+               this.ignitor_voltage = voltage;
+       }
+
+       public double time_since_boost() {
+               if (tick == AltosLib.MISSING)
+                       return 0.0;
+
+               if (boost_tick != AltosLib.MISSING) {
+                       return (tick - boost_tick) / 100.0;
+               }
+               return tick / 100.0;
+       }
+
+       public boolean valid() {
+               return tick != AltosLib.MISSING && serial != AltosLib.MISSING;
+       }
+
+       public AltosGPS make_temp_gps(boolean sats) {
+               if (temp_gps == null) {
+                       temp_gps = new AltosGPS(gps);
+               }
+               gps_pending = true;
+               if (sats) {
+                       if (tick != temp_gps_sat_tick)
+                               temp_gps.cc_gps_sat = null;
+                       temp_gps_sat_tick = tick;
+               }
+               return temp_gps;
+       }
+
+       public void set_temp_gps() {
+               set_gps(temp_gps, gps_sequence + 1);
+               gps_pending = false;
+               temp_gps = null;
+       }
+
+       public AltosState clone() {
+               AltosState s = new AltosState();
+               s.copy(this);
+               return s;
        }
 
-       public AltosState (AltosRecord cur, AltosState prev) {
-               init(cur, prev);
+       public AltosState () {
+               init();
        }
 }
diff --git a/altoslib/AltosStateIterable.java b/altoslib/AltosStateIterable.java
new file mode 100644 (file)
index 0000000..6d63741
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+
+public abstract class AltosStateIterable implements Iterable<AltosState> {
+
+       public void write_comments (PrintStream out) {
+       }
+       
+       public abstract void write(PrintStream out);
+}
diff --git a/altoslib/AltosStateUpdate.java b/altoslib/AltosStateUpdate.java
new file mode 100644 (file)
index 0000000..ec4f760
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+public interface AltosStateUpdate {
+       public void     update_state(AltosState state);
+}
\ No newline at end of file
index e73223499a2f42ed91950b0a70e778e3541b3a12..03ca9f80504bafa4b3b418bf43924a6b36686b14 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.text.*;
 
@@ -23,217 +23,114 @@ import java.text.*;
  * Telemetry data contents
  */
 
+public abstract class AltosTelemetry implements AltosStateUpdate {
 
-/*
- * The packet format is a simple hex dump of the raw telemetry frame.
- * It starts with 'TELEM', then contains hex digits with a checksum as the last
- * byte on the line.
- *
- * Version 4 is a replacement with consistent syntax. Each telemetry line
- * contains a sequence of space-separated names and values, the values are
- * either integers or strings. The names are all unique. All values are
- * optional
- *
- * VERSION 4 c KD7SQG n 236 f 18 r -25 s pad t 513 r_a 15756 r_b 26444 r_t 20944
- *   r_v 26640 r_d 512 r_m 208 c_a 15775 c_b 26439 c_p 15749 c_m 16281 a_a 15764
- *   a_s 0 a_b 26439 g_s u g_n 0 s_n 0
- *
- * VERSION 4 c KD7SQG n 19 f 0 r -23 s pad t 513 r_b 26372 r_t 21292 r_v 26788
- *   r_d 136 r_m 140 c_b 26370 k_h 0 k_s 0 k_a 0
- *
- * General header fields
- *
- *     Name            Value
- *
- *     VERSION         Telemetry version number (4 or more). Must be first.
- *     c               Callsign (string, no spaces allowed)
- *     n               Flight unit serial number (integer)
- *     f               Flight number (integer)
- *     r               Packet RSSI value (integer)
- *     s               Flight computer state (string, no spaces allowed)
- *     t               Flight computer clock (integer in centiseconds)
- *
- * Version 3 is Version 2 with fixed RSSI numbers -- the radio reports
- * in 1/2dB increments while this protocol provides only integers. So,
- * the syntax didn't change just the interpretation of the RSSI
- * values.
- *
- * Version 2 of the telemetry data stream is a bit of a mess, with no
- * consistent formatting. In particular, the GPS data is formatted for
- * viewing instead of parsing.  However, the key feature is that every
- * telemetry line contains all of the information necessary to
- * describe the current rocket state, including the calibration values
- * for accelerometer and barometer.
- *
- * GPS unlocked:
- *
- * VERSION 2 CALL KB0G SERIAL  51 FLIGHT     2 RSSI  -68 STATUS ff STATE     pad  1001 \
- *    a: 16032 p: 21232 t: 20284 v: 25160 d:   204 m:   204 fa: 16038 ga: 16032 fv:       0 \
- *    fp: 21232 gp: 21230 a+: 16049 a-: 16304 GPS  0 sat unlocked SAT 1   15  30
- *
- * GPS locked:
- *
- * VERSION 2 CALL KB0G SERIAL  51 FLIGHT     2 RSSI  -71 STATUS ff STATE     pad  2504 \
- *     a: 16028 p: 21220 t: 20360 v: 25004 d:   208 m:   200 fa: 16031 ga: 16032 fv:     330 \
- *     fp: 21231 gp: 21230 a+: 16049 a-: 16304 \
- *     GPS  9 sat 2010-02-13 17:16:51 35°20.0803'N 106°45.2235'W  1790m  \
- *     0.00m/s(H) 0°     0.00m/s(V) 1.0(hdop)     0(herr)     0(verr) \
- *     SAT 10   29  30  24  28   5  25  21  20  15  33   1  23  30  24  18  26  10  29   2  26
- *
- */
+       /* All telemetry packets have these fields */
+       public int      tick;
+       public int      serial;
+       public int      rssi;
+       public int      status;
+
+       /* Mark when we received the packet */
+       long            received_time;
+
+       static boolean cksum(int[] bytes) {
+               int     sum = 0x5a;
+               for (int i = 1; i < bytes.length - 1; i++)
+                       sum += bytes[i];
+               sum &= 0xff;
+               return sum == bytes[bytes.length - 1];
+       }
+
+       public void update_state(AltosState state) {
+               if (state.state == AltosLib.ao_flight_invalid)
+                       state.set_state(AltosLib.ao_flight_startup);
+               state.set_serial(serial);
+               state.set_tick(tick);
+               state.set_rssi(rssi, status);
+               state.set_received_time(received_time);
+       }
+
+       final static int PKT_APPEND_STATUS_1_CRC_OK             = (1 << 7);
+       final static int PKT_APPEND_STATUS_1_LQI_MASK           = (0x7f);
+       final static int PKT_APPEND_STATUS_1_LQI_SHIFT          = 0;
+
+       final static int packet_type_TM_sensor = 0x01;
+       final static int packet_type_Tm_sensor = 0x02;
+       final static int packet_type_Tn_sensor = 0x03;
+       final static int packet_type_configuration = 0x04;
+       final static int packet_type_location = 0x05;
+       final static int packet_type_satellite = 0x06;
+       final static int packet_type_companion = 0x07;
+       final static int packet_type_mega_sensor = 0x08;
+       final static int packet_type_mega_data = 0x09;
+       final static int packet_type_metrum_sensor = 0x0a;
+       final static int packet_type_metrum_data = 0x0b;
+       final static int packet_type_mini = 0x10;
+       
+       static AltosTelemetry parse_hex(String hex)  throws ParseException, AltosCRCException {
+               AltosTelemetry  telem = null;
+
+               int[] bytes;
+               try {
+                       bytes = AltosLib.hexbytes(hex);
+               } catch (NumberFormatException ne) {
+                       throw new ParseException(ne.getMessage(), 0);
+               }
+
+               /* one for length, one for checksum */
+               if (bytes[0] != bytes.length - 2)
+                       throw new ParseException(String.format("invalid length %d != %d\n",
+                                                              bytes[0],
+                                                              bytes.length - 2), 0);
+               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:
+                       telem = AltosTelemetryStandard.parse_hex(bytes);
+                       break;
+               case AltosLib.ao_telemetry_0_9_len + 4:
+                       telem = new AltosTelemetryLegacy(bytes);
+                       break;
+               case AltosLib.ao_telemetry_0_8_len + 4:
+                       telem = new AltosTelemetryLegacy(bytes);
+                       break;
+               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;
+       }
+
+       public static AltosTelemetry parse(String line) throws ParseException, AltosCRCException {
+               String[] word = line.split("\\s+");
+               int i =0;
+
+               if (word[i].equals("CRC") && word[i+1].equals("INVALID")) {
+                       i += 2;
+                       AltosParse.word(word[i++], "RSSI");
+                       throw new AltosCRCException(AltosParse.parse_int(word[i++]));
+               }
+
+               AltosTelemetry telem;
 
-public abstract class AltosTelemetry extends AltosRecord {
-
-       /*
-        * General header fields
-        *
-        *      Name            Value
-        *
-        *      VERSION         Telemetry version number (4 or more). Must be first.
-        *      c               Callsign (string, no spaces allowed)
-        *      n               Flight unit serial number (integer)
-        *      f               Flight number (integer)
-        *      r               Packet RSSI value (integer)
-        *      s               Flight computer state (string, no spaces allowed)
-        *      t               Flight computer clock (integer in centiseconds)
-        */
-
-       final static String AO_TELEM_VERSION    = "VERSION";
-       final static String AO_TELEM_CALL       = "c";
-       final static String AO_TELEM_SERIAL     = "n";
-       final static String AO_TELEM_FLIGHT     = "f";
-       final static String AO_TELEM_RSSI       = "r";
-       final static String AO_TELEM_STATE      = "s";
-       final static String AO_TELEM_TICK       = "t";
-
-       /*
-        * Raw sensor values
-        *
-        *      Name            Value
-        *      r_a             Accelerometer reading (integer)
-        *      r_b             Barometer reading (integer)
-        *      r_t             Thermometer reading (integer)
-        *      r_v             Battery reading (integer)
-        *      r_d             Drogue continuity (integer)
-        *      r_m             Main continuity (integer)
-        */
-
-       final static String AO_TELEM_RAW_ACCEL  = "r_a";
-       final static String AO_TELEM_RAW_BARO   = "r_b";
-       final static String AO_TELEM_RAW_THERMO = "r_t";
-       final static String AO_TELEM_RAW_BATT   = "r_v";
-       final static String AO_TELEM_RAW_DROGUE = "r_d";
-       final static String AO_TELEM_RAW_MAIN   = "r_m";
-
-       /*
-        * Sensor calibration values
-        *
-        *      Name            Value
-        *      c_a             Ground accelerometer reading (integer)
-        *      c_b             Ground barometer reading (integer)
-        *      c_p             Accelerometer reading for +1g
-        *      c_m             Accelerometer reading for -1g
-        */
-
-       final static String AO_TELEM_CAL_ACCEL_GROUND   = "c_a";
-       final static String AO_TELEM_CAL_BARO_GROUND    = "c_b";
-       final static String AO_TELEM_CAL_ACCEL_PLUS     = "c_p";
-       final static String AO_TELEM_CAL_ACCEL_MINUS    = "c_m";
-
-       /*
-        * Kalman state values
-        *
-        *      Name            Value
-        *      k_h             Height above pad (integer, meters)
-        *      k_s             Vertical speeed (integer, m/s * 16)
-        *      k_a             Vertical acceleration (integer, m/s² * 16)
-        */
-
-       final static String AO_TELEM_KALMAN_HEIGHT      = "k_h";
-       final static String AO_TELEM_KALMAN_SPEED       = "k_s";
-       final static String AO_TELEM_KALMAN_ACCEL       = "k_a";
-
-       /*
-        * Ad-hoc flight values
-        *
-        *      Name            Value
-        *      a_a             Acceleration (integer, sensor units)
-        *      a_s             Speed (integer, integrated acceleration value)
-        *      a_b             Barometer reading (integer, sensor units)
-        */
-
-       final static String AO_TELEM_ADHOC_ACCEL        = "a_a";
-       final static String AO_TELEM_ADHOC_SPEED        = "a_s";
-       final static String AO_TELEM_ADHOC_BARO         = "a_b";
-
-       /*
-        * GPS values
-        *
-        *      Name            Value
-        *      g_s             GPS state (string):
-        *                              l       locked
-        *                              u       unlocked
-        *                              e       error (missing or broken)
-        *      g_n             Number of sats used in solution
-        *      g_ns            Latitude (degrees * 10e7)
-        *      g_ew            Longitude (degrees * 10e7)
-        *      g_a             Altitude (integer meters)
-        *      g_Y             GPS year (integer)
-        *      g_M             GPS month (integer - 1-12)
-        *      g_D             GPS day (integer - 1-31)
-        *      g_h             GPS hour (integer - 0-23)
-        *      g_m             GPS minute (integer - 0-59)
-        *      g_s             GPS second (integer - 0-59)
-        *      g_v             GPS vertical speed (integer, cm/sec)
-        *      g_s             GPS horizontal speed (integer, cm/sec)
-        *      g_c             GPS course (integer, 0-359)
-        *      g_hd            GPS hdop (integer * 10)
-        *      g_vd            GPS vdop (integer * 10)
-        *      g_he            GPS h error (integer)
-        *      g_ve            GPS v error (integer)
-        */
-
-       final static String AO_TELEM_GPS_STATE                  = "g";
-       final static String AO_TELEM_GPS_STATE_LOCKED           = "l";
-       final static String AO_TELEM_GPS_STATE_UNLOCKED         = "u";
-       final static String AO_TELEM_GPS_STATE_ERROR            = "e";
-       final static String AO_TELEM_GPS_NUM_SAT                = "g_n";
-       final static String AO_TELEM_GPS_LATITUDE               = "g_ns";
-       final static String AO_TELEM_GPS_LONGITUDE              = "g_ew";
-       final static String AO_TELEM_GPS_ALTITUDE               = "g_a";
-       final static String AO_TELEM_GPS_YEAR                   = "g_Y";
-       final static String AO_TELEM_GPS_MONTH                  = "g_M";
-       final static String AO_TELEM_GPS_DAY                    = "g_D";
-       final static String AO_TELEM_GPS_HOUR                   = "g_h";
-       final static String AO_TELEM_GPS_MINUTE                 = "g_m";
-       final static String AO_TELEM_GPS_SECOND                 = "g_s";
-       final static String AO_TELEM_GPS_VERTICAL_SPEED         = "g_v";
-       final static String AO_TELEM_GPS_HORIZONTAL_SPEED       = "g_g";
-       final static String AO_TELEM_GPS_COURSE                 = "g_c";
-       final static String AO_TELEM_GPS_HDOP                   = "g_hd";
-       final static String AO_TELEM_GPS_VDOP                   = "g_vd";
-       final static String AO_TELEM_GPS_HERROR                 = "g_he";
-       final static String AO_TELEM_GPS_VERROR                 = "g_ve";
-
-       /*
-        * GPS satellite values
-        *
-        *      Name            Value
-        *      s_n             Number of satellites reported (integer)
-        *      s_v0            Space vehicle ID (integer) for report 0
-        *      s_c0            C/N0 number (integer) for report 0
-        *      s_v1            Space vehicle ID (integer) for report 1
-        *      s_c1            C/N0 number (integer) for report 1
-        *      ...
-        */
-
-       final static String AO_TELEM_SAT_NUM    = "s_n";
-       final static String AO_TELEM_SAT_SVID   = "s_v";
-       final static String AO_TELEM_SAT_C_N_0  = "s_c";
-
-       static public AltosRecord parse(String line, AltosRecord previous) throws ParseException, AltosCRCException {
-               AltosTelemetryRecord    r = AltosTelemetryRecord.parse(line);
-
-               return r.update_state(previous);
+               if (word[i].equals("TELEM")) {
+                       telem = parse_hex(word[i+1]);
+               } else {
+                       telem = new AltosTelemetryLegacy(line);
+               }
+               return telem;
        }
 }
diff --git a/altoslib/AltosTelemetryConfiguration.java b/altoslib/AltosTelemetryConfiguration.java
new file mode 100644 (file)
index 0000000..e5d444d
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+
+public class AltosTelemetryConfiguration extends AltosTelemetryStandard {
+       int     device_type;
+       int     flight;
+       int     config_major;
+       int     config_minor;
+       int     apogee_delay;
+       int     main_deploy;
+       int     flight_log_max;
+       String  callsign;
+       String  version;
+
+       public AltosTelemetryConfiguration(int[] bytes) {
+               super(bytes);
+
+               device_type    = uint8(5);
+               flight         = uint16(6);
+               config_major   = uint8(8);
+               config_minor   = uint8(9);
+               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, apogee_delay, main_deploy, flight_log_max);
+
+               state.set_callsign(callsign);
+               state.set_firmware_version(version);
+       }
+}
diff --git a/altoslib/AltosTelemetryFile.java b/altoslib/AltosTelemetryFile.java
new file mode 100644 (file)
index 0000000..7566d94
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright © 2013 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 org.altusmetrum.altoslib_2;
+
+import java.io.*;
+import java.util.*;
+import java.text.*;
+
+class AltosTelemetryIterator implements Iterator<AltosState> {
+       AltosState                      state;
+       Iterator<AltosTelemetry>        telems;
+       AltosTelemetry                  next;
+       boolean                         seen;
+
+       public boolean hasNext() {
+               return !seen || telems.hasNext();
+       }
+
+       public AltosState next() {
+               if (seen) {
+                       AltosState      n = state.clone();
+                       AltosTelemetry  t = telems.next();
+
+                       t.update_state(n);
+                       state = n;
+               }
+               seen = true;
+               return state;
+       }
+
+       public void remove () {
+       }
+
+       public AltosTelemetryIterator(AltosState start, Iterator<AltosTelemetry> telems) {
+               this.state = start;
+               this.telems = telems;
+               this.seen = false;
+       }
+}
+
+public class AltosTelemetryFile extends AltosStateIterable {
+
+       AltosTelemetryIterable  telems;
+       AltosState              start;
+
+       public void write_comments(PrintStream out) {
+       }
+
+       public void write(PrintStream out) {
+               
+       }
+
+       public AltosTelemetryFile(FileInputStream input) {
+               telems = new AltosTelemetryIterable(input);
+               start = new AltosState();
+
+               /* Find boost tick */
+               AltosState      state = start.clone();
+
+               for (AltosTelemetry telem : telems) {
+                       telem.update_state(state);
+                       state.finish_update();
+                       if (state.state != AltosLib.ao_flight_invalid && state.state >= AltosLib.ao_flight_boost) {
+                               start.set_boost_tick(state.tick);
+                               break;
+                       }
+               }
+       }
+
+       public Iterator<AltosState> iterator() {
+               AltosState                      state = start.clone();
+               Iterator<AltosTelemetry>        i = telems.iterator();
+
+               while (i.hasNext() && !state.valid()) {
+                       AltosTelemetry  t = i.next();
+                       t.update_state(state);
+                       state.finish_update();
+               }
+               return new AltosTelemetryIterator(state, i);
+       }
+}
\ No newline at end of file
index 570336387640c1ae77560e4dcf038967e3c08465..9da3b0e6b91b824982abb464bb61663790ffe33e 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.io.*;
 import java.util.*;
 import java.text.*;
 
-public class AltosTelemetryIterable extends AltosRecordIterable {
-       TreeSet<AltosRecord>    records;
+class AltosTelemetryOrdered implements Comparable<AltosTelemetryOrdered> {
+       AltosTelemetry  telem;
+       int             index;
+       int             tick;
 
-       public Iterator<AltosRecord> iterator () {
-               return records.iterator();
+       public int compareTo(AltosTelemetryOrdered o) {
+               int     tick_diff = tick - o.tick;
+
+               if (tick_diff != 0)
+                       return tick_diff;
+               return index - o.index;
        }
 
-       boolean has_gps = false;
-       boolean has_accel = false;
-       boolean has_ignite = false;
-       public boolean has_gps() { return has_gps; }
-       public boolean has_accel() { return has_accel; }
-       public boolean has_ignite() { return has_ignite; };
+       AltosTelemetryOrdered (AltosTelemetry telem, int index, int tick) {
+               this.telem = telem;
+               this.index = index;
+               this.tick = tick;
+       }
+}
 
-       public AltosTelemetryIterable (FileInputStream input) {
-               boolean saw_boost = false;
-               int     current_tick = 0;
-               int     boost_tick = 0;
+class AltosTelemetryOrderedIterator implements Iterator<AltosTelemetry> {
+       Iterator<AltosTelemetryOrdered> iterator;
+
+       public AltosTelemetryOrderedIterator(TreeSet<AltosTelemetryOrdered> telems) {
+               iterator = telems.iterator();
+       }
+
+       public boolean hasNext() {
+               return iterator.hasNext();
+       }
 
-               AltosRecord     previous = null;
-               records = new TreeSet<AltosRecord> ();
+       public AltosTelemetry next() {
+               return iterator.next().telem;
+       }
+
+       public void remove () {
+       }
+}
+
+public class AltosTelemetryIterable implements Iterable<AltosTelemetry> {
+       TreeSet<AltosTelemetryOrdered>  telems;
+       int tick;
+       int index;
+
+       public void add (AltosTelemetry telem) {
+               int     t = telem.tick;
+               if (!telems.isEmpty()) {
+                       while (t < tick - 32767)
+                               t += 65536;
+               }
+               tick = t;
+               telems.add(new AltosTelemetryOrdered(telem, index++, tick));
+       }
+
+       public Iterator<AltosTelemetry> iterator () {
+               return new AltosTelemetryOrderedIterator(telems);
+       }
+
+       public AltosTelemetryIterable (FileInputStream input) {
+               telems = new TreeSet<AltosTelemetryOrdered> ();
+               tick = 0;
+               index = 0;
 
                try {
                        for (;;) {
@@ -50,32 +91,10 @@ public class AltosTelemetryIterable extends AltosRecordIterable {
                                        break;
                                }
                                try {
-                                       AltosRecord record = AltosTelemetry.parse(line, previous);
-                                       if (record == null)
+                                       AltosTelemetry telem = AltosTelemetry.parse(line);
+                                       if (telem == null)
                                                break;
-                                       if (records.isEmpty()) {
-                                               current_tick = record.tick;
-                                       } else {
-                                               int tick = record.tick;
-                                               while (tick < current_tick - 0x1000)
-                                                       tick += 0x10000;
-                                               current_tick = tick;
-                                               record.tick = current_tick;
-                                       }
-                                       if (!saw_boost && record.state >= AltosLib.ao_flight_boost)
-                                       {
-                                               saw_boost = true;
-                                               boost_tick = record.tick;
-                                       }
-                                       if (record.acceleration() != AltosRecord.MISSING)
-                                               has_accel = true;
-                                       if (record.gps != null)
-                                               has_gps = true;
-                                       if (record.main_voltage() != AltosRecord.MISSING)
-                                               has_ignite = true;
-                                       if (previous != null && previous.tick != record.tick)
-                                               records.add(previous);
-                                       previous = record;
+                                       add(telem);
                                } catch (ParseException pe) {
                                        System.out.printf("parse exception %s\n", pe.getMessage());
                                } catch (AltosCRCException ce) {
@@ -84,26 +103,5 @@ public class AltosTelemetryIterable extends AltosRecordIterable {
                } catch (IOException io) {
                        System.out.printf("io exception\n");
                }
-
-               if (previous != null)
-                       records.add(previous);
-
-               /* Adjust all tick counts to match expected eeprom values,
-                * which starts with a 16-bit tick count 16 samples before boost
-                */
-
-               int tick_adjust = (boost_tick - 16) & 0xffff0000;
-               for (AltosRecord r : this)
-                       r.tick -= tick_adjust;
-               boost_tick -= tick_adjust;
-
-               /* adjust all tick counts to be relative to boost time */
-               for (AltosRecord r : this)
-                       r.time = (r.tick - boost_tick) / 100.0;
-
-               try {
-                       input.close();
-               } catch (IOException ie) {
-               }
        }
 }
diff --git a/altoslib/AltosTelemetryLegacy.java b/altoslib/AltosTelemetryLegacy.java
new file mode 100644 (file)
index 0000000..132b9e8
--- /dev/null
@@ -0,0 +1,556 @@
+/*
+ * 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 org.altusmetrum.altoslib_2;
+
+import java.text.*;
+
+/*
+ * Telemetry data contents
+ */
+
+
+/*
+ * The packet format is a simple hex dump of the raw telemetry frame.
+ * It starts with 'TELEM', then contains hex digits with a checksum as the last
+ * byte on the line.
+ *
+ * Version 4 is a replacement with consistent syntax. Each telemetry line
+ * contains a sequence of space-separated names and values, the values are
+ * either integers or strings. The names are all unique. All values are
+ * optional
+ *
+ * VERSION 4 c KD7SQG n 236 f 18 r -25 s pad t 513 r_a 15756 r_b 26444 r_t 20944
+ *   r_v 26640 r_d 512 r_m 208 c_a 15775 c_b 26439 c_p 15749 c_m 16281 a_a 15764
+ *   a_s 0 a_b 26439 g_s u g_n 0 s_n 0
+ *
+ * VERSION 4 c KD7SQG n 19 f 0 r -23 s pad t 513 r_b 26372 r_t 21292 r_v 26788
+ *   r_d 136 r_m 140 c_b 26370 k_h 0 k_s 0 k_a 0
+ *
+ * General header fields
+ *
+ *     Name            Value
+ *
+ *     VERSION         Telemetry version number (4 or more). Must be first.
+ *     c               Callsign (string, no spaces allowed)
+ *     n               Flight unit serial number (integer)
+ *     f               Flight number (integer)
+ *     r               Packet RSSI value (integer)
+ *     s               Flight computer state (string, no spaces allowed)
+ *     t               Flight computer clock (integer in centiseconds)
+ *
+ * Version 3 is Version 2 with fixed RSSI numbers -- the radio reports
+ * in 1/2dB increments while this protocol provides only integers. So,
+ * the syntax didn't change just the interpretation of the RSSI
+ * values.
+ *
+ * Version 2 of the telemetry data stream is a bit of a mess, with no
+ * consistent formatting. In particular, the GPS data is formatted for
+ * viewing instead of parsing.  However, the key feature is that every
+ * telemetry line contains all of the information necessary to
+ * describe the current rocket state, including the calibration values
+ * for accelerometer and barometer.
+ *
+ * GPS unlocked:
+ *
+ * VERSION 2 CALL KB0G SERIAL  51 FLIGHT     2 RSSI  -68 STATUS ff STATE     pad  1001 \
+ *    a: 16032 p: 21232 t: 20284 v: 25160 d:   204 m:   204 fa: 16038 ga: 16032 fv:       0 \
+ *    fp: 21232 gp: 21230 a+: 16049 a-: 16304 GPS  0 sat unlocked SAT 1   15  30
+ *
+ * GPS locked:
+ *
+ * VERSION 2 CALL KB0G SERIAL  51 FLIGHT     2 RSSI  -71 STATUS ff STATE     pad  2504 \
+ *     a: 16028 p: 21220 t: 20360 v: 25004 d:   208 m:   200 fa: 16031 ga: 16032 fv:     330 \
+ *     fp: 21231 gp: 21230 a+: 16049 a-: 16304 \
+ *     GPS  9 sat 2010-02-13 17:16:51 35°20.0803'N 106°45.2235'W  1790m  \
+ *     0.00m/s(H) 0°     0.00m/s(V) 1.0(hdop)     0(herr)     0(verr) \
+ *     SAT 10   29  30  24  28   5  25  21  20  15  33   1  23  30  24  18  26  10  29   2  26
+ *
+ */
+
+public class AltosTelemetryLegacy extends AltosTelemetry {
+       /*
+        * General header fields
+        *
+        *      Name            Value
+        *
+        *      VERSION         Telemetry version number (4 or more). Must be first.
+        *      c               Callsign (string, no spaces allowed)
+        *      n               Flight unit serial number (integer)
+        *      f               Flight number (integer)
+        *      r               Packet RSSI value (integer)
+        *      s               Flight computer state (string, no spaces allowed)
+        *      t               Flight computer clock (integer in centiseconds)
+        */
+
+       final static String AO_TELEM_VERSION    = "VERSION";
+       final static String AO_TELEM_CALL       = "c";
+       final static String AO_TELEM_SERIAL     = "n";
+       final static String AO_TELEM_FLIGHT     = "f";
+       final static String AO_TELEM_RSSI       = "r";
+       final static String AO_TELEM_STATE      = "s";
+       final static String AO_TELEM_TICK       = "t";
+
+       /*
+        * Raw sensor values
+        *
+        *      Name            Value
+        *      r_a             Accelerometer reading (integer)
+        *      r_b             Barometer reading (integer)
+        *      r_t             Thermometer reading (integer)
+        *      r_v             Battery reading (integer)
+        *      r_d             Drogue continuity (integer)
+        *      r_m             Main continuity (integer)
+        */
+
+       final static String AO_TELEM_RAW_ACCEL  = "r_a";
+       final static String AO_TELEM_RAW_BARO   = "r_b";
+       final static String AO_TELEM_RAW_THERMO = "r_t";
+       final static String AO_TELEM_RAW_BATT   = "r_v";
+       final static String AO_TELEM_RAW_DROGUE = "r_d";
+       final static String AO_TELEM_RAW_MAIN   = "r_m";
+
+       /*
+        * Sensor calibration values
+        *
+        *      Name            Value
+        *      c_a             Ground accelerometer reading (integer)
+        *      c_b             Ground barometer reading (integer)
+        *      c_p             Accelerometer reading for +1g
+        *      c_m             Accelerometer reading for -1g
+        */
+
+       final static String AO_TELEM_CAL_ACCEL_GROUND   = "c_a";
+       final static String AO_TELEM_CAL_BARO_GROUND    = "c_b";
+       final static String AO_TELEM_CAL_ACCEL_PLUS     = "c_p";
+       final static String AO_TELEM_CAL_ACCEL_MINUS    = "c_m";
+
+       /*
+        * Kalman state values
+        *
+        *      Name            Value
+        *      k_h             Height above pad (integer, meters)
+        *      k_s             Vertical speeed (integer, m/s * 16)
+        *      k_a             Vertical acceleration (integer, m/s² * 16)
+        */
+
+       final static String AO_TELEM_KALMAN_HEIGHT      = "k_h";
+       final static String AO_TELEM_KALMAN_SPEED       = "k_s";
+       final static String AO_TELEM_KALMAN_ACCEL       = "k_a";
+
+       /*
+        * Ad-hoc flight values
+        *
+        *      Name            Value
+        *      a_a             Acceleration (integer, sensor units)
+        *      a_s             Speed (integer, integrated acceleration value)
+        *      a_b             Barometer reading (integer, sensor units)
+        */
+
+       final static String AO_TELEM_ADHOC_ACCEL        = "a_a";
+       final static String AO_TELEM_ADHOC_SPEED        = "a_s";
+       final static String AO_TELEM_ADHOC_BARO         = "a_b";
+
+       /*
+        * GPS values
+        *
+        *      Name            Value
+        *      g_s             GPS state (string):
+        *                              l       locked
+        *                              u       unlocked
+        *                              e       error (missing or broken)
+        *      g_n             Number of sats used in solution
+        *      g_ns            Latitude (degrees * 10e7)
+        *      g_ew            Longitude (degrees * 10e7)
+        *      g_a             Altitude (integer meters)
+        *      g_Y             GPS year (integer)
+        *      g_M             GPS month (integer - 1-12)
+        *      g_D             GPS day (integer - 1-31)
+        *      g_h             GPS hour (integer - 0-23)
+        *      g_m             GPS minute (integer - 0-59)
+        *      g_s             GPS second (integer - 0-59)
+        *      g_v             GPS vertical speed (integer, cm/sec)
+        *      g_s             GPS horizontal speed (integer, cm/sec)
+        *      g_c             GPS course (integer, 0-359)
+        *      g_hd            GPS hdop (integer * 10)
+        *      g_vd            GPS vdop (integer * 10)
+        *      g_he            GPS h error (integer)
+        *      g_ve            GPS v error (integer)
+        */
+
+       final static String AO_TELEM_GPS_STATE                  = "g";
+       final static String AO_TELEM_GPS_STATE_LOCKED           = "l";
+       final static String AO_TELEM_GPS_STATE_UNLOCKED         = "u";
+       final static String AO_TELEM_GPS_STATE_ERROR            = "e";
+       final static String AO_TELEM_GPS_NUM_SAT                = "g_n";
+       final static String AO_TELEM_GPS_LATITUDE               = "g_ns";
+       final static String AO_TELEM_GPS_LONGITUDE              = "g_ew";
+       final static String AO_TELEM_GPS_ALTITUDE               = "g_a";
+       final static String AO_TELEM_GPS_YEAR                   = "g_Y";
+       final static String AO_TELEM_GPS_MONTH                  = "g_M";
+       final static String AO_TELEM_GPS_DAY                    = "g_D";
+       final static String AO_TELEM_GPS_HOUR                   = "g_h";
+       final static String AO_TELEM_GPS_MINUTE                 = "g_m";
+       final static String AO_TELEM_GPS_SECOND                 = "g_s";
+       final static String AO_TELEM_GPS_VERTICAL_SPEED         = "g_v";
+       final static String AO_TELEM_GPS_HORIZONTAL_SPEED       = "g_g";
+       final static String AO_TELEM_GPS_COURSE                 = "g_c";
+       final static String AO_TELEM_GPS_HDOP                   = "g_hd";
+       final static String AO_TELEM_GPS_VDOP                   = "g_vd";
+       final static String AO_TELEM_GPS_HERROR                 = "g_he";
+       final static String AO_TELEM_GPS_VERROR                 = "g_ve";
+
+       /*
+        * GPS satellite values
+        *
+        *      Name            Value
+        *      s_n             Number of satellites reported (integer)
+        *      s_v0            Space vehicle ID (integer) for report 0
+        *      s_c0            C/N0 number (integer) for report 0
+        *      s_v1            Space vehicle ID (integer) for report 1
+        *      s_c1            C/N0 number (integer) for report 1
+        *      ...
+        */
+
+       final static String AO_TELEM_SAT_NUM    = "s_n";
+       final static String AO_TELEM_SAT_SVID   = "s_v";
+       final static String AO_TELEM_SAT_C_N_0  = "s_c";
+
+       public int      version;
+       public String   callsign;
+       public int      flight;
+       public int      state;
+
+       public AltosGPS gps;
+       public int      gps_sequence;
+
+       /* Telemetry sources have these values recorded from the flight computer */
+       public double   kalman_height;
+       public double   kalman_speed;
+       public double   kalman_acceleration;
+
+       /* Sensor values */
+       public int      accel;
+       public int      pres;
+       public int      temp;
+       public int      batt;
+       public int      apogee;
+       public int      main;
+
+       public int      ground_accel;
+       public int      ground_pres;
+       public int      accel_plus_g;
+       public int      accel_minus_g;
+
+       public int      flight_accel;
+       public int      flight_vel;
+       public int      flight_pres;
+
+       private void parse_v4(String[] words, int i) throws ParseException {
+               AltosTelemetryMap       map = new AltosTelemetryMap(words, i);
+
+               callsign = map.get_string(AO_TELEM_CALL, "N0CALL");
+               serial = map.get_int(AO_TELEM_SERIAL, AltosLib.MISSING);
+               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);
+               pres = map.get_int(AO_TELEM_RAW_BARO, AltosLib.MISSING);
+               temp = map.get_int(AO_TELEM_RAW_THERMO, AltosLib.MISSING);
+               batt = map.get_int(AO_TELEM_RAW_BATT, AltosLib.MISSING);
+               apogee = map.get_int(AO_TELEM_RAW_DROGUE, AltosLib.MISSING);
+               main = map.get_int(AO_TELEM_RAW_MAIN, AltosLib.MISSING);
+
+               /* sensor calibration information */
+               ground_accel = map.get_int(AO_TELEM_CAL_ACCEL_GROUND, AltosLib.MISSING);
+               ground_pres = map.get_int(AO_TELEM_CAL_BARO_GROUND, AltosLib.MISSING);
+               accel_plus_g = map.get_int(AO_TELEM_CAL_ACCEL_PLUS, AltosLib.MISSING);
+               accel_minus_g = map.get_int(AO_TELEM_CAL_ACCEL_MINUS, AltosLib.MISSING);
+
+               /* flight computer values */
+               kalman_acceleration = map.get_double(AO_TELEM_KALMAN_ACCEL, AltosLib.MISSING, 1/16.0);
+               kalman_speed = map.get_double(AO_TELEM_KALMAN_SPEED, AltosLib.MISSING, 1/16.0);
+               kalman_height = map.get_int(AO_TELEM_KALMAN_HEIGHT, AltosLib.MISSING);
+
+               flight_accel = map.get_int(AO_TELEM_ADHOC_ACCEL, AltosLib.MISSING);
+               flight_vel = map.get_int(AO_TELEM_ADHOC_SPEED, AltosLib.MISSING);
+               flight_pres = map.get_int(AO_TELEM_ADHOC_BARO, AltosLib.MISSING);
+
+               if (map.has(AO_TELEM_GPS_STATE))
+                       gps = new AltosGPS(map);
+               else
+                       gps = null;
+       }
+
+       private void parse_legacy(String[] words, int i) throws ParseException {
+
+               AltosParse.word (words[i++], "CALL");
+               callsign = words[i++];
+
+               AltosParse.word (words[i++], "SERIAL");
+               serial = AltosParse.parse_int(words[i++]);
+
+               if (version >= 2) {
+                       AltosParse.word (words[i++], "FLIGHT");
+                       flight = AltosParse.parse_int(words[i++]);
+               } else
+                       flight = 0;
+
+               AltosParse.word(words[i++], "RSSI");
+               rssi = AltosParse.parse_int(words[i++]);
+
+               /* Older telemetry data had mis-computed RSSI value */
+               if (version <= 2)
+                       rssi = (rssi + 74) / 2 - 74;
+
+               AltosParse.word(words[i++], "STATUS");
+               status = AltosParse.parse_hex(words[i++]);
+
+               AltosParse.word(words[i++], "STATE");
+               state = AltosLib.state(words[i++]);
+
+               tick = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "a:");
+               accel = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "p:");
+               pres = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "t:");
+               temp = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "v:");
+               batt = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "d:");
+               apogee = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "m:");
+               main = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "fa:");
+               flight_accel = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "ga:");
+               ground_accel = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "fv:");
+               flight_vel = AltosParse.parse_int(words[i++]);
+
+               AltosParse.word(words[i++], "fp:");
+               flight_pres = AltosParse.parse_int(words[i++]);
+
+               /* Old TeleDongle code with kalman-reporting TeleMetrum code */
+               if ((flight_vel & 0xffff0000) == 0x80000000) {
+                       kalman_speed = ((short) flight_vel) / 16.0;
+                       kalman_acceleration = flight_accel / 16.0;
+                       kalman_height = flight_pres;
+                       flight_vel = AltosLib.MISSING;
+                       flight_pres = AltosLib.MISSING;
+                       flight_accel = AltosLib.MISSING;
+               } else {
+                       kalman_speed = AltosLib.MISSING;
+                       kalman_acceleration = AltosLib.MISSING;
+                       kalman_height = AltosLib.MISSING;
+               }
+
+               AltosParse.word(words[i++], "gp:");
+               ground_pres = AltosParse.parse_int(words[i++]);
+
+               if (version >= 1) {
+                       AltosParse.word(words[i++], "a+:");
+                       accel_plus_g = AltosParse.parse_int(words[i++]);
+
+                       AltosParse.word(words[i++], "a-:");
+                       accel_minus_g = AltosParse.parse_int(words[i++]);
+               } else {
+                       accel_plus_g = ground_accel;
+                       accel_minus_g = ground_accel + 530;
+               }
+
+               gps = new AltosGPS(words, i, version);
+               gps_sequence++;
+       }
+
+       public AltosTelemetryLegacy(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 {
+                       AltosParse.word (words[i++], "VERSION");
+                       version = AltosParse.parse_int(words[i++]);
+               }
+
+               if (version < 4)
+                       parse_legacy(words, i);
+               else
+                       parse_v4(words, i);
+       }
+
+       /*
+        * Given a hex dump of a legacy telemetry line, construct an AltosRecordTM from that
+        */
+
+       int[]   bytes;
+       int     adjust;
+
+       /*
+       private int int8(int i) {
+               return AltosLib.int8(bytes, i + 1 + adjust);
+       }
+       */
+       private int uint8(int i) {
+               return AltosLib.uint8(bytes, i + 1 + adjust);
+       }
+       private int int16(int i) {
+               return AltosLib.int16(bytes, i + 1 + adjust);
+       }
+       private int uint16(int i) {
+               return AltosLib.uint16(bytes, i + 1 + adjust);
+       }
+       private int uint32(int i) {
+               return AltosLib.uint32(bytes, i + 1 + adjust);
+       }
+       private String string(int i, int l) {
+               return AltosLib.string(bytes, i + 1 + adjust, l);
+       }
+
+       static final int AO_GPS_NUM_SAT_MASK    = (0xf << 0);
+       static final int AO_GPS_NUM_SAT_SHIFT   = (0);
+
+       static final int AO_GPS_VALID           = (1 << 4);
+       static final int AO_GPS_RUNNING         = (1 << 5);
+       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;
+               version = 4;
+               adjust = 0;
+
+               if (bytes.length == AltosLib.ao_telemetry_0_8_len + 4) {
+                       serial = uint8(0);
+                       adjust = -1;
+               } else
+                       serial = uint16(0);
+
+               callsign = string(62, 8);
+               flight = uint16(2);
+               state = uint8(4);
+               tick = uint16(21);
+               accel = int16(23);
+               pres = int16(25);
+               temp = int16(27);
+               batt = int16(29);
+               apogee = int16(31);
+               main = int16(33);
+               
+               ground_accel = int16(7);
+               ground_pres = int16(15);
+               accel_plus_g = int16(17);
+               accel_minus_g = int16(19);
+
+               if (uint16(11) == 0x8000) {
+                       kalman_acceleration = int16(5);
+                       kalman_speed = int16(9);
+                       kalman_height = int16(13);
+                       flight_accel = AltosLib.MISSING;
+                       flight_vel = AltosLib.MISSING;
+                       flight_pres = AltosLib.MISSING;
+               } else {
+                       flight_accel = int16(5);
+                       flight_vel = uint32(9);
+                       flight_pres = int16(13);
+                       kalman_acceleration = AltosLib.MISSING;
+                       kalman_speed = AltosLib.MISSING;
+                       kalman_height = AltosLib.MISSING;
+               }
+
+               gps = null;
+
+               int gps_flags = uint8(41);
+
+               if ((gps_flags & (AO_GPS_VALID|AO_GPS_RUNNING)) != 0) {
+                       gps = new AltosGPS();
+                       gps_sequence++;
+
+                       gps.nsat = (gps_flags & AO_GPS_NUM_SAT_MASK);
+                       gps.locked = (gps_flags & AO_GPS_VALID) != 0;
+                       gps.connected = true;
+                       gps.lat = uint32(42) / 1.0e7;
+                       gps.lon = uint32(46) / 1.0e7;
+                       gps.alt = int16(50);
+                       gps.ground_speed = uint16(52) / 100.0;
+                       gps.course = uint8(54) * 2;
+                       gps.hdop = uint8(55) / 5.0;
+                       gps.h_error = uint16(58);
+                       gps.v_error = uint16(60);
+
+                       int     n_tracking_reported = uint8(70);
+                       if (n_tracking_reported > 12)
+                               n_tracking_reported = 12;
+                       int     n_tracking_actual = 0;
+                       for (int i = 0; i < n_tracking_reported; i++) {
+                               if (uint8(71 + i*2) != 0)
+                                       n_tracking_actual++;
+                       }
+                       if (n_tracking_actual > 0) {
+                               gps.cc_gps_sat = new AltosGPSSat[n_tracking_actual];
+
+                               n_tracking_actual = 0;
+                               for (int i = 0; i < n_tracking_reported; i++) {
+                                       int     svid = uint8(71 + i*2);
+                                       int     c_n0 = uint8(72 + i*2);
+                                       if (svid != 0)
+                                               gps.cc_gps_sat[n_tracking_actual++] = new AltosGPSSat(svid, c_n0);
+                               }
+                       }
+               }
+       }
+
+       public void update_state(AltosState state) {
+               state.set_tick(tick);
+               state.set_state(this.state);
+               state.set_flight(flight);
+               state.set_serial(serial);
+               state.set_rssi(rssi, status);
+
+               state.set_pressure(AltosConvert.barometer_to_pressure(pres));
+               state.set_accel_g(accel_plus_g, accel_minus_g);
+               state.set_accel(accel);
+               if (kalman_height != AltosLib.MISSING)
+                       state.set_kalman(kalman_height, kalman_speed, kalman_acceleration);
+               state.set_temperature(AltosConvert.thermometer_to_temperature(temp));
+               state.set_battery_voltage(AltosConvert.cc_battery_to_voltage(batt));
+               state.set_apogee_voltage(AltosConvert.cc_ignitor_to_voltage(apogee));
+               state.set_main_voltage(AltosConvert.cc_ignitor_to_voltage(main));
+               if (gps != null)
+                       state.set_gps(gps, gps_sequence);
+       }
+}
diff --git a/altoslib/AltosTelemetryLocation.java b/altoslib/AltosTelemetryLocation.java
new file mode 100644 (file)
index 0000000..6e88091
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+
+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;
+
+       public AltosTelemetryLocation(int[] bytes) {
+               super(bytes);
+
+               flags          = uint8(5);
+               altitude       = int16(6);
+               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);
+       }
+
+       public void update_state(AltosState state) {
+               super.update_state(state);
+               AltosGPS        gps = state.make_temp_gps(false);
+
+               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.hdop = hdop;
+                       gps.vdop = vdop;
+               }
+               state.set_temp_gps();
+       }
+}
index 7cca98b09acc39e46c9cf0091434c679541bbcb6..37883a1c47e838b19cf5e562eed21e220142edef 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 import java.text.*;
 import java.util.HashMap;
 
diff --git a/altoslib/AltosTelemetryMegaData.java b/altoslib/AltosTelemetryMegaData.java
new file mode 100644 (file)
index 0000000..f5cc01d
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+public class AltosTelemetryMegaData extends AltosTelemetryStandard {
+       int     state;
+       
+       int     v_batt;
+       int     v_pyro;
+       int     sense[];
+
+       int     ground_pres;
+       int     ground_accel;
+       int     accel_plus_g;
+       int     accel_minus_g;
+
+       int     acceleration;
+       int     speed;
+       int     height;
+
+       public AltosTelemetryMegaData(int[] bytes) {
+               super(bytes);
+
+               state = int8(5);
+
+               v_batt = int16(6);
+               v_pyro = int16(8);
+
+               sense = new int[6];     
+
+               for (int i = 0; i < 6; i++) {
+                       sense[i] = int8(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 = int16(30);
+       }
+
+       public void update_state(AltosState state) {
+               super.update_state(state);
+
+               state.set_state(this.state);
+                       
+               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]));
+
+               double voltages[] = new double[4];
+               for (int i = 0; i < 4; 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_kalman(height, speed/16.0, acceleration / 16.0);
+       }
+}
+
diff --git a/altoslib/AltosTelemetryMegaSensor.java b/altoslib/AltosTelemetryMegaSensor.java
new file mode 100644 (file)
index 0000000..23b67af
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+public class AltosTelemetryMegaSensor extends AltosTelemetryStandard {
+       int     accel;
+       int     pres;
+       int     temp;
+
+       int     accel_x;
+       int     accel_y;
+       int     accel_z;
+
+       int     gyro_x;
+       int     gyro_y;
+       int     gyro_z;
+
+       int     mag_x;
+       int     mag_y;
+       int     mag_z;
+
+       public AltosTelemetryMegaSensor(int[] bytes) {
+               super(bytes);
+
+               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);
+
+               AltosIMU imu = new AltosIMU();
+               
+               imu.accel_x = accel_x;
+               imu.accel_y = accel_y;
+               imu.accel_z = accel_z;
+
+               imu.gyro_x = gyro_x;
+               imu.gyro_y = gyro_y;
+               imu.gyro_z = gyro_z;
+
+               state.imu = imu;
+
+               AltosMag mag = new AltosMag();
+
+               mag.x = mag_x;
+               mag.y = mag_y;
+               mag.z = mag_z;
+
+               state.mag = mag;
+       }
+}
diff --git a/altoslib/AltosTelemetryMetrumData.java b/altoslib/AltosTelemetryMetrumData.java
new file mode 100644 (file)
index 0000000..b623997
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+
+public class AltosTelemetryMetrumData extends AltosTelemetryStandard {
+
+       int     ground_pres;
+       int     ground_accel;
+       int     accel_plus_g;
+       int     accel_minus_g;
+
+       public AltosTelemetryMetrumData(int[] bytes) {
+               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);
+       }
+}
diff --git a/altoslib/AltosTelemetryMetrumSensor.java b/altoslib/AltosTelemetryMetrumSensor.java
new file mode 100644 (file)
index 0000000..fc047af
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+
+public class AltosTelemetryMetrumSensor extends AltosTelemetryStandard {
+       int     state;
+
+       int     accel;
+       int     pres;
+       int     temp;
+
+       int     acceleration;
+       int     speed;
+       int     height;
+
+       int     v_batt;
+       int     sense_a;
+       int     sense_m;
+
+       public AltosTelemetryMetrumSensor(int[] bytes) {
+               super(bytes);
+
+               state         = int8(5);
+               accel         = int16(6);
+               pres          = int32(8);
+               temp          = int16(12);
+
+               acceleration  = int16(14);
+               speed         = int16(16);
+               height        = 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_accel(accel);
+               state.set_pressure(pres);
+               state.set_temperature(temp/100.0);
+
+               state.set_kalman(height, speed/16.0, acceleration/16.0);
+
+               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));
+       }
+}
diff --git a/altoslib/AltosTelemetryMini.java b/altoslib/AltosTelemetryMini.java
new file mode 100644 (file)
index 0000000..e710946
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+
+public class AltosTelemetryMini extends AltosTelemetryStandard {
+       int     state;
+
+       int     v_batt;
+       int     sense_a;
+       int     sense_m;
+
+       int     pres;
+       int     temp;
+
+       int     acceleration;
+       int     speed;
+       int     height;
+
+       int     ground_pres;
+
+       public AltosTelemetryMini(int[] bytes) {
+               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        = int16(22);
+
+               ground_pres   = int32(24);
+       }
+
+       public void update_state(AltosState state) {
+               super.update_state(state);
+
+               state.set_state(this.state);
+
+               state.set_battery_voltage(AltosConvert.tele_mini_voltage(v_batt));
+               state.set_apogee_voltage(AltosConvert.tele_mini_voltage(sense_a));
+               state.set_main_voltage(AltosConvert.tele_mini_voltage(sense_m));
+
+               state.set_ground_pressure(ground_pres);
+
+               state.set_pressure(pres);
+               state.set_temperature(temp/100.0);
+
+               state.set_kalman(height, speed/16.0, acceleration/16.0);
+       }
+}
diff --git a/altoslib/AltosTelemetryRaw.java b/altoslib/AltosTelemetryRaw.java
new file mode 100644 (file)
index 0000000..dbe70fe
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+public class AltosTelemetryRaw extends AltosTelemetryStandard {
+       public AltosTelemetryRaw(int[] bytes) {
+               super(bytes);
+       }
+
+       public void update_state(AltosState state) {
+               super.update_state(state);
+       }
+}
index b4293c7349d2d9fda70bd03942aa91c37e0ac031..aea978445578e536b3daf3a5b1ffc73ffaf3675d 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 import java.text.*;
 import java.io.*;
@@ -24,19 +24,23 @@ import java.util.concurrent.*;
 public class AltosTelemetryReader extends AltosFlightReader {
        AltosLink       link;
        AltosLog        log;
-       AltosRecord     previous;
        double          frequency;
        int             telemetry;
+       AltosState      state = null;
 
        LinkedBlockingQueue<AltosLine> telem;
 
-       public AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException {
+       public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException {
                AltosLine l = telem.take();
                if (l.line == null)
                        throw new IOException("IO error");
-               AltosRecord     next = AltosTelemetry.parse(l.line, previous);
-               previous = next;
-               return next;
+               AltosTelemetry  telem = AltosTelemetry.parse(l.line);
+               if (state == null)
+                       state = new AltosState();
+               else
+                       state = state.clone();
+               telem.update_state(state);
+               return state;
        }
 
        public void flush() {
@@ -44,7 +48,6 @@ public class AltosTelemetryReader extends AltosFlightReader {
        }
 
        public void reset() {
-               previous = null;
                flush();
        }
 
@@ -121,7 +124,6 @@ public class AltosTelemetryReader extends AltosFlightReader {
                try {
                        log = new AltosLog(link);
                        name = link.name;
-                       previous = null;
                        telem = new LinkedBlockingQueue<AltosLine>();
                        frequency = AltosPreferences.frequency(link.serial);
                        set_frequency(frequency);
diff --git a/altoslib/AltosTelemetryRecord.java b/altoslib/AltosTelemetryRecord.java
deleted file mode 100644 (file)
index fdc3c88..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-import java.text.*;
-
-public abstract class AltosTelemetryRecord {
-
-       long    received_time;
-       abstract public AltosRecord update_state(AltosRecord previous);
-
-       static boolean cksum(int[] bytes) {
-               int     sum = 0x5a;
-               for (int i = 1; i < bytes.length - 1; i++)
-                       sum += bytes[i];
-               sum &= 0xff;
-               return sum == bytes[bytes.length - 1];
-       }
-
-       final static int PKT_APPEND_STATUS_1_CRC_OK             = (1 << 7);
-       final static int PKT_APPEND_STATUS_1_LQI_MASK           = (0x7f);
-       final static int PKT_APPEND_STATUS_1_LQI_SHIFT          = 0;
-
-       final static int packet_type_TM_sensor = 0x01;
-       final static int packet_type_Tm_sensor = 0x02;
-       final static int packet_type_Tn_sensor = 0x03;
-       final static int packet_type_configuration = 0x04;
-       final static int packet_type_location = 0x05;
-       final static int packet_type_satellite = 0x06;
-       final static int packet_type_companion = 0x07;
-       final static int packet_type_MM_sensor = 0x08;
-       final static int packet_type_MM_data = 0x09;
-       
-       static AltosTelemetryRecord parse_hex(String hex)  throws ParseException, AltosCRCException {
-               AltosTelemetryRecord    r;
-
-               int[] bytes;
-               try {
-                       bytes = AltosLib.hexbytes(hex);
-               } catch (NumberFormatException ne) {
-                       throw new ParseException(ne.getMessage(), 0);
-               }
-
-               /* one for length, one for checksum */
-               if (bytes[0] != bytes.length - 2)
-                       throw new ParseException(String.format("invalid length %d != %d\n",
-                                                              bytes[0],
-                                                              bytes.length - 2), 0);
-               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:
-                       int     type = AltosLib.uint8(bytes, 4 + 1);
-                       switch (type) {
-                       case packet_type_TM_sensor:
-                       case packet_type_Tm_sensor:
-                       case packet_type_Tn_sensor:
-                               r = new AltosTelemetryRecordSensor(bytes, rssi);
-                               break;
-                       case packet_type_configuration:
-                               r = new AltosTelemetryRecordConfiguration(bytes, rssi);
-                               break;
-                       case packet_type_location:
-                               r = new AltosTelemetryRecordLocation(bytes, rssi);
-                               break;
-                       case packet_type_satellite:
-                               r = new AltosTelemetryRecordSatellite(bytes, rssi);
-                               break;
-                       case packet_type_companion:
-                               r = new AltosTelemetryRecordCompanion(bytes, rssi);
-                               break;
-                       case packet_type_MM_sensor:
-                               r = new AltosTelemetryRecordMegaSensor(bytes, rssi);
-                               break;
-                       case packet_type_MM_data:
-                               r = new AltosTelemetryRecordMegaData(bytes, rssi);
-                               break;
-                       default:
-                               r = new AltosTelemetryRecordRaw(bytes, rssi);
-                               break;
-                       }
-                       break;
-               case AltosLib.ao_telemetry_0_9_len + 4:
-                       r = new AltosTelemetryRecordLegacy(bytes, rssi, status);
-                       break;
-               case AltosLib.ao_telemetry_0_8_len + 4:
-                       r = new AltosTelemetryRecordLegacy(bytes, rssi, status);
-                       break;
-               default:
-                       throw new ParseException(String.format("Invalid packet length %d", bytes.length), 0);
-               }
-               r.received_time = System.currentTimeMillis();
-               return r;
-       }
-
-       public static AltosTelemetryRecord parse(String line) throws ParseException, AltosCRCException {
-               AltosTelemetryRecord    r;
-
-               String[] word = line.split("\\s+");
-               int i =0;
-               if (word[i].equals("CRC") && word[i+1].equals("INVALID")) {
-                       i += 2;
-                       AltosParse.word(word[i++], "RSSI");
-                       throw new AltosCRCException(AltosParse.parse_int(word[i++]));
-               }
-
-               if (word[i].equals("TELEM"))
-                       r = parse_hex(word[i+1]);
-               else
-                       r = new AltosTelemetryRecordLegacy(line);
-               return r;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordCompanion.java b/altoslib/AltosTelemetryRecordCompanion.java
deleted file mode 100644 (file)
index 2231df1..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-public class AltosTelemetryRecordCompanion extends AltosTelemetryRecordRaw {
-
-       AltosRecordCompanion    companion;
-
-       public AltosTelemetryRecordCompanion(int[] in_bytes, int rssi) {
-               super(in_bytes, rssi);
-
-               int     off = 0;
-               if (uint8(6) == 0)
-                       off = 1;
-               int channels = uint8(7+off);
-
-               if (off != 0 && channels >= 12)
-                       channels = 11;
-
-               companion = new AltosRecordCompanion(channels);
-               companion.tick          = tick;
-               companion.board_id      = uint8(5);
-               companion.update_period = uint8(6+off);
-               for (int i = 0; i < companion.companion_data.length; i++)
-                       companion.companion_data[i] = uint16(8 + off + i * 2);
-       }
-
-       public AltosRecord update_state(AltosRecord previous) {
-               AltosRecord     next = super.update_state(previous);
-
-               next.companion = companion;
-               next.seen |= AltosRecord.seen_sensor | AltosRecord.seen_temp_volt;
-
-               companion.tick = tick;
-               return next;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordConfiguration.java b/altoslib/AltosTelemetryRecordConfiguration.java
deleted file mode 100644 (file)
index 47fc348..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-
-public class AltosTelemetryRecordConfiguration extends AltosTelemetryRecordRaw {
-       int     device_type;
-       int     flight;
-       int     config_major;
-       int     config_minor;
-       int     apogee_delay;
-       int     main_deploy;
-       int     flight_log_max;
-       String  callsign;
-       String  version;
-
-       public AltosTelemetryRecordConfiguration(int[] in_bytes, int rssi) {
-               super(in_bytes, rssi);
-
-               device_type    = uint8(5);
-               flight         = uint16(6);
-               config_major   = uint8(8);
-               config_minor   = uint8(9);
-               apogee_delay   = uint16(10);
-               main_deploy    = uint16(12);
-               flight_log_max = uint16(14);
-               callsign       = string(16, 8);
-               version        = string(24, 8);
-       }
-
-       public AltosRecord update_state(AltosRecord previous) {
-               AltosRecord     next = super.update_state(previous);
-
-               next.device_type = device_type;
-               next.flight = flight;
-               next.config_major = config_major;
-               next.config_minor = config_minor;
-               next.apogee_delay = apogee_delay;
-               next.main_deploy = main_deploy;
-               next.flight_log_max = flight_log_max;
-
-               next.callsign = callsign;
-               next.firmware_version = version;
-
-               next.seen |= AltosRecord.seen_deploy | AltosRecord.seen_flight;
-
-               return next;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordGeneral.java b/altoslib/AltosTelemetryRecordGeneral.java
deleted file mode 100644 (file)
index 08cd606..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-import java.text.*;
-
-public class AltosTelemetryRecordGeneral {
-
-       static AltosTelemetryRecord parse(String line) throws ParseException, AltosCRCException {
-               AltosTelemetryRecord    r;
-
-               String[] word = line.split("\\s+");
-               int i =0;
-               if (word[i].equals("CRC") && word[i+1].equals("INVALID")) {
-                       i += 2;
-                       AltosParse.word(word[i++], "RSSI");
-                       throw new AltosCRCException(AltosParse.parse_int(word[i++]));
-               }
-
-               if (word[i].equals("TELEM"))
-                       r = AltosTelemetryRecordRaw.parse(word[i+1]);
-               else
-                       r = new AltosTelemetryRecordLegacy(line);
-               return r;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordLegacy.java b/altoslib/AltosTelemetryRecordLegacy.java
deleted file mode 100644 (file)
index f2d3f86..0000000
+++ /dev/null
@@ -1,521 +0,0 @@
-/*
- * 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 org.altusmetrum.altoslib_1;
-
-import java.text.*;
-
-/*
- * Telemetry data contents
- */
-
-
-/*
- * The packet format is a simple hex dump of the raw telemetry frame.
- * It starts with 'TELEM', then contains hex digits with a checksum as the last
- * byte on the line.
- *
- * Version 4 is a replacement with consistent syntax. Each telemetry line
- * contains a sequence of space-separated names and values, the values are
- * either integers or strings. The names are all unique. All values are
- * optional
- *
- * VERSION 4 c KD7SQG n 236 f 18 r -25 s pad t 513 r_a 15756 r_b 26444 r_t 20944
- *   r_v 26640 r_d 512 r_m 208 c_a 15775 c_b 26439 c_p 15749 c_m 16281 a_a 15764
- *   a_s 0 a_b 26439 g_s u g_n 0 s_n 0
- *
- * VERSION 4 c KD7SQG n 19 f 0 r -23 s pad t 513 r_b 26372 r_t 21292 r_v 26788
- *   r_d 136 r_m 140 c_b 26370 k_h 0 k_s 0 k_a 0
- *
- * General header fields
- *
- *     Name            Value
- *
- *     VERSION         Telemetry version number (4 or more). Must be first.
- *     c               Callsign (string, no spaces allowed)
- *     n               Flight unit serial number (integer)
- *     f               Flight number (integer)
- *     r               Packet RSSI value (integer)
- *     s               Flight computer state (string, no spaces allowed)
- *     t               Flight computer clock (integer in centiseconds)
- *
- * Version 3 is Version 2 with fixed RSSI numbers -- the radio reports
- * in 1/2dB increments while this protocol provides only integers. So,
- * the syntax didn't change just the interpretation of the RSSI
- * values.
- *
- * Version 2 of the telemetry data stream is a bit of a mess, with no
- * consistent formatting. In particular, the GPS data is formatted for
- * viewing instead of parsing.  However, the key feature is that every
- * telemetry line contains all of the information necessary to
- * describe the current rocket state, including the calibration values
- * for accelerometer and barometer.
- *
- * GPS unlocked:
- *
- * VERSION 2 CALL KB0G SERIAL  51 FLIGHT     2 RSSI  -68 STATUS ff STATE     pad  1001 \
- *    a: 16032 p: 21232 t: 20284 v: 25160 d:   204 m:   204 fa: 16038 ga: 16032 fv:       0 \
- *    fp: 21232 gp: 21230 a+: 16049 a-: 16304 GPS  0 sat unlocked SAT 1   15  30
- *
- * GPS locked:
- *
- * VERSION 2 CALL KB0G SERIAL  51 FLIGHT     2 RSSI  -71 STATUS ff STATE     pad  2504 \
- *     a: 16028 p: 21220 t: 20360 v: 25004 d:   208 m:   200 fa: 16031 ga: 16032 fv:     330 \
- *     fp: 21231 gp: 21230 a+: 16049 a-: 16304 \
- *     GPS  9 sat 2010-02-13 17:16:51 35°20.0803'N 106°45.2235'W  1790m  \
- *     0.00m/s(H) 0°     0.00m/s(V) 1.0(hdop)     0(herr)     0(verr) \
- *     SAT 10   29  30  24  28   5  25  21  20  15  33   1  23  30  24  18  26  10  29   2  26
- *
- */
-
-public class AltosTelemetryRecordLegacy extends AltosTelemetryRecord {
-       /*
-        * General header fields
-        *
-        *      Name            Value
-        *
-        *      VERSION         Telemetry version number (4 or more). Must be first.
-        *      c               Callsign (string, no spaces allowed)
-        *      n               Flight unit serial number (integer)
-        *      f               Flight number (integer)
-        *      r               Packet RSSI value (integer)
-        *      s               Flight computer state (string, no spaces allowed)
-        *      t               Flight computer clock (integer in centiseconds)
-        */
-
-       final static String AO_TELEM_VERSION    = "VERSION";
-       final static String AO_TELEM_CALL       = "c";
-       final static String AO_TELEM_SERIAL     = "n";
-       final static String AO_TELEM_FLIGHT     = "f";
-       final static String AO_TELEM_RSSI       = "r";
-       final static String AO_TELEM_STATE      = "s";
-       final static String AO_TELEM_TICK       = "t";
-
-       /*
-        * Raw sensor values
-        *
-        *      Name            Value
-        *      r_a             Accelerometer reading (integer)
-        *      r_b             Barometer reading (integer)
-        *      r_t             Thermometer reading (integer)
-        *      r_v             Battery reading (integer)
-        *      r_d             Drogue continuity (integer)
-        *      r_m             Main continuity (integer)
-        */
-
-       final static String AO_TELEM_RAW_ACCEL  = "r_a";
-       final static String AO_TELEM_RAW_BARO   = "r_b";
-       final static String AO_TELEM_RAW_THERMO = "r_t";
-       final static String AO_TELEM_RAW_BATT   = "r_v";
-       final static String AO_TELEM_RAW_DROGUE = "r_d";
-       final static String AO_TELEM_RAW_MAIN   = "r_m";
-
-       /*
-        * Sensor calibration values
-        *
-        *      Name            Value
-        *      c_a             Ground accelerometer reading (integer)
-        *      c_b             Ground barometer reading (integer)
-        *      c_p             Accelerometer reading for +1g
-        *      c_m             Accelerometer reading for -1g
-        */
-
-       final static String AO_TELEM_CAL_ACCEL_GROUND   = "c_a";
-       final static String AO_TELEM_CAL_BARO_GROUND    = "c_b";
-       final static String AO_TELEM_CAL_ACCEL_PLUS     = "c_p";
-       final static String AO_TELEM_CAL_ACCEL_MINUS    = "c_m";
-
-       /*
-        * Kalman state values
-        *
-        *      Name            Value
-        *      k_h             Height above pad (integer, meters)
-        *      k_s             Vertical speeed (integer, m/s * 16)
-        *      k_a             Vertical acceleration (integer, m/s² * 16)
-        */
-
-       final static String AO_TELEM_KALMAN_HEIGHT      = "k_h";
-       final static String AO_TELEM_KALMAN_SPEED       = "k_s";
-       final static String AO_TELEM_KALMAN_ACCEL       = "k_a";
-
-       /*
-        * Ad-hoc flight values
-        *
-        *      Name            Value
-        *      a_a             Acceleration (integer, sensor units)
-        *      a_s             Speed (integer, integrated acceleration value)
-        *      a_b             Barometer reading (integer, sensor units)
-        */
-
-       final static String AO_TELEM_ADHOC_ACCEL        = "a_a";
-       final static String AO_TELEM_ADHOC_SPEED        = "a_s";
-       final static String AO_TELEM_ADHOC_BARO         = "a_b";
-
-       /*
-        * GPS values
-        *
-        *      Name            Value
-        *      g_s             GPS state (string):
-        *                              l       locked
-        *                              u       unlocked
-        *                              e       error (missing or broken)
-        *      g_n             Number of sats used in solution
-        *      g_ns            Latitude (degrees * 10e7)
-        *      g_ew            Longitude (degrees * 10e7)
-        *      g_a             Altitude (integer meters)
-        *      g_Y             GPS year (integer)
-        *      g_M             GPS month (integer - 1-12)
-        *      g_D             GPS day (integer - 1-31)
-        *      g_h             GPS hour (integer - 0-23)
-        *      g_m             GPS minute (integer - 0-59)
-        *      g_s             GPS second (integer - 0-59)
-        *      g_v             GPS vertical speed (integer, cm/sec)
-        *      g_s             GPS horizontal speed (integer, cm/sec)
-        *      g_c             GPS course (integer, 0-359)
-        *      g_hd            GPS hdop (integer * 10)
-        *      g_vd            GPS vdop (integer * 10)
-        *      g_he            GPS h error (integer)
-        *      g_ve            GPS v error (integer)
-        */
-
-       final static String AO_TELEM_GPS_STATE                  = "g";
-       final static String AO_TELEM_GPS_STATE_LOCKED           = "l";
-       final static String AO_TELEM_GPS_STATE_UNLOCKED         = "u";
-       final static String AO_TELEM_GPS_STATE_ERROR            = "e";
-       final static String AO_TELEM_GPS_NUM_SAT                = "g_n";
-       final static String AO_TELEM_GPS_LATITUDE               = "g_ns";
-       final static String AO_TELEM_GPS_LONGITUDE              = "g_ew";
-       final static String AO_TELEM_GPS_ALTITUDE               = "g_a";
-       final static String AO_TELEM_GPS_YEAR                   = "g_Y";
-       final static String AO_TELEM_GPS_MONTH                  = "g_M";
-       final static String AO_TELEM_GPS_DAY                    = "g_D";
-       final static String AO_TELEM_GPS_HOUR                   = "g_h";
-       final static String AO_TELEM_GPS_MINUTE                 = "g_m";
-       final static String AO_TELEM_GPS_SECOND                 = "g_s";
-       final static String AO_TELEM_GPS_VERTICAL_SPEED         = "g_v";
-       final static String AO_TELEM_GPS_HORIZONTAL_SPEED       = "g_g";
-       final static String AO_TELEM_GPS_COURSE                 = "g_c";
-       final static String AO_TELEM_GPS_HDOP                   = "g_hd";
-       final static String AO_TELEM_GPS_VDOP                   = "g_vd";
-       final static String AO_TELEM_GPS_HERROR                 = "g_he";
-       final static String AO_TELEM_GPS_VERROR                 = "g_ve";
-
-       /*
-        * GPS satellite values
-        *
-        *      Name            Value
-        *      s_n             Number of satellites reported (integer)
-        *      s_v0            Space vehicle ID (integer) for report 0
-        *      s_c0            C/N0 number (integer) for report 0
-        *      s_v1            Space vehicle ID (integer) for report 1
-        *      s_c1            C/N0 number (integer) for report 1
-        *      ...
-        */
-
-       final static String AO_TELEM_SAT_NUM    = "s_n";
-       final static String AO_TELEM_SAT_SVID   = "s_v";
-       final static String AO_TELEM_SAT_C_N_0  = "s_c";
-
-       AltosRecordTM   record;
-
-       private void parse_v4(String[] words, int i) throws ParseException {
-               AltosTelemetryMap       map = new AltosTelemetryMap(words, i);
-
-               record.callsign = map.get_string(AO_TELEM_CALL, "N0CALL");
-               record.serial = map.get_int(AO_TELEM_SERIAL, AltosRecord.MISSING);
-               record.flight = map.get_int(AO_TELEM_FLIGHT, AltosRecord.MISSING);
-               record.rssi = map.get_int(AO_TELEM_RSSI, AltosRecord.MISSING);
-               record.state = AltosLib.state(map.get_string(AO_TELEM_STATE, "invalid"));
-               record.tick = map.get_int(AO_TELEM_TICK, 0);
-
-               /* raw sensor values */
-               record.accel = map.get_int(AO_TELEM_RAW_ACCEL, AltosRecord.MISSING);
-               record.pres = map.get_int(AO_TELEM_RAW_BARO, AltosRecord.MISSING);
-               record.temp = map.get_int(AO_TELEM_RAW_THERMO, AltosRecord.MISSING);
-               record.batt = map.get_int(AO_TELEM_RAW_BATT, AltosRecord.MISSING);
-               record.drogue = map.get_int(AO_TELEM_RAW_DROGUE, AltosRecord.MISSING);
-               record.main = map.get_int(AO_TELEM_RAW_MAIN, AltosRecord.MISSING);
-
-               /* sensor calibration information */
-               record.ground_accel = map.get_int(AO_TELEM_CAL_ACCEL_GROUND, AltosRecord.MISSING);
-               record.ground_pres = map.get_int(AO_TELEM_CAL_BARO_GROUND, AltosRecord.MISSING);
-               record.accel_plus_g = map.get_int(AO_TELEM_CAL_ACCEL_PLUS, AltosRecord.MISSING);
-               record.accel_minus_g = map.get_int(AO_TELEM_CAL_ACCEL_MINUS, AltosRecord.MISSING);
-
-               /* flight computer values */
-               record.kalman_acceleration = map.get_double(AO_TELEM_KALMAN_ACCEL, AltosRecord.MISSING, 1/16.0);
-               record.kalman_speed = map.get_double(AO_TELEM_KALMAN_SPEED, AltosRecord.MISSING, 1/16.0);
-               record.kalman_height = map.get_int(AO_TELEM_KALMAN_HEIGHT, AltosRecord.MISSING);
-
-               record.flight_accel = map.get_int(AO_TELEM_ADHOC_ACCEL, AltosRecord.MISSING);
-               record.flight_vel = map.get_int(AO_TELEM_ADHOC_SPEED, AltosRecord.MISSING);
-               record.flight_pres = map.get_int(AO_TELEM_ADHOC_BARO, AltosRecord.MISSING);
-
-               if (map.has(AO_TELEM_GPS_STATE)) {
-               record.gps = new AltosGPS(map);
-               record.gps_sequence++;
-               }
-               else
-               record.gps = null;
-       }
-
-       private void parse_legacy(String[] words, int i) throws ParseException {
-
-               AltosParse.word (words[i++], "CALL");
-               record.callsign = words[i++];
-
-               AltosParse.word (words[i++], "SERIAL");
-               record.serial = AltosParse.parse_int(words[i++]);
-
-               if (record.version >= 2) {
-                       AltosParse.word (words[i++], "FLIGHT");
-                       record.flight = AltosParse.parse_int(words[i++]);
-               } else
-                       record.flight = 0;
-
-               AltosParse.word(words[i++], "RSSI");
-               record.rssi = AltosParse.parse_int(words[i++]);
-
-               /* Older telemetry data had mis-computed RSSI value */
-               if (record.version <= 2)
-                       record.rssi = (record.rssi + 74) / 2 - 74;
-
-               AltosParse.word(words[i++], "STATUS");
-               record.status = AltosParse.parse_hex(words[i++]);
-
-               AltosParse.word(words[i++], "STATE");
-               record.state = AltosLib.state(words[i++]);
-
-               record.tick = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "a:");
-               record.accel = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "p:");
-               record.pres = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "t:");
-               record.temp = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "v:");
-               record.batt = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "d:");
-               record.drogue = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "m:");
-               record.main = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "fa:");
-               record.flight_accel = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "ga:");
-               record.ground_accel = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "fv:");
-               record.flight_vel = AltosParse.parse_int(words[i++]);
-
-               AltosParse.word(words[i++], "fp:");
-               record.flight_pres = AltosParse.parse_int(words[i++]);
-
-               /* Old TeleDongle code with kalman-reporting TeleMetrum code */
-               if ((record.flight_vel & 0xffff0000) == 0x80000000) {
-                       record.kalman_speed = ((short) record.flight_vel) / 16.0;
-                       record.kalman_acceleration = record.flight_accel / 16.0;
-                       record.kalman_height = record.flight_pres;
-                       record.flight_vel = AltosRecord.MISSING;
-                       record.flight_pres = AltosRecord.MISSING;
-                       record.flight_accel = AltosRecord.MISSING;
-               }
-
-               AltosParse.word(words[i++], "gp:");
-               record.ground_pres = AltosParse.parse_int(words[i++]);
-
-               if (record.version >= 1) {
-                       AltosParse.word(words[i++], "a+:");
-                       record.accel_plus_g = AltosParse.parse_int(words[i++]);
-
-                       AltosParse.word(words[i++], "a-:");
-                       record.accel_minus_g = AltosParse.parse_int(words[i++]);
-               } else {
-                       record.accel_plus_g = record.ground_accel;
-                       record.accel_minus_g = record.ground_accel + 530;
-               }
-
-               record.gps = new AltosGPS(words, i, record.version);
-               record.gps_sequence++;
-       }
-
-       public AltosTelemetryRecordLegacy(String line) throws ParseException, AltosCRCException {
-               String[] words = line.split("\\s+");
-               int     i = 0;
-
-               record = new AltosRecordTM();
-
-               if (words[i].equals("CRC") && words[i+1].equals("INVALID")) {
-                       i += 2;
-                       AltosParse.word(words[i++], "RSSI");
-                       record.rssi = AltosParse.parse_int(words[i++]);
-                       throw new AltosCRCException(record.rssi);
-               }
-               if (words[i].equals("CALL")) {
-                       record.version = 0;
-               } else {
-                       AltosParse.word (words[i++], "VERSION");
-                       record.version = AltosParse.parse_int(words[i++]);
-               }
-
-               if (record.version < 4)
-                       parse_legacy(words, i);
-               else
-                       parse_v4(words, i);
-       }
-
-       /*
-        * Given a hex dump of a legacy telemetry line, construct an AltosRecordTM from that
-        */
-
-       int[]   bytes;
-       int     adjust;
-
-       /*
-       private int int8(int i) {
-               return AltosLib.int8(bytes, i + 1 + adjust);
-       }
-       */
-       private int uint8(int i) {
-               return AltosLib.uint8(bytes, i + 1 + adjust);
-       }
-       private int int16(int i) {
-               return AltosLib.int16(bytes, i + 1 + adjust);
-       }
-       private int uint16(int i) {
-               return AltosLib.uint16(bytes, i + 1 + adjust);
-       }
-       private int uint32(int i) {
-               return AltosLib.uint32(bytes, i + 1 + adjust);
-       }
-       private String string(int i, int l) {
-               return AltosLib.string(bytes, i + 1 + adjust, l);
-       }
-
-       static final int AO_GPS_NUM_SAT_MASK    = (0xf << 0);
-       static final int AO_GPS_NUM_SAT_SHIFT   = (0);
-
-       static final int AO_GPS_VALID           = (1 << 4);
-       static final int AO_GPS_RUNNING         = (1 << 5);
-       static final int AO_GPS_DATE_VALID      = (1 << 6);
-       static final int AO_GPS_COURSE_VALID    = (1 << 7);
-
-       public AltosTelemetryRecordLegacy(int[] in_bytes, int in_rssi, int in_status) {
-               record = new AltosRecordTM();
-
-               bytes = in_bytes;
-               record.version = 4;
-               adjust = 0;
-
-               if (bytes.length == AltosLib.ao_telemetry_0_8_len + 4) {
-                       record.serial = uint8(0);
-                       adjust = -1;
-               } else
-                       record.serial = uint16(0);
-
-               record.seen = AltosRecord.seen_flight | AltosRecord.seen_sensor | AltosRecord.seen_temp_volt | AltosRecord.seen_deploy;
-
-               record.callsign = string(62, 8);
-               record.flight = uint16(2);
-               record.rssi = in_rssi;
-               record.status = in_status;
-               record.state = uint8(4);
-               record.tick = uint16(21);
-               record.accel = int16(23);
-               record.pres = int16(25);
-               record.temp = int16(27);
-               record.batt = int16(29);
-               record.drogue = int16(31);
-               record.main = int16(33);
-               
-               record.ground_accel = int16(7);
-               record.ground_pres = int16(15);
-               record.accel_plus_g = int16(17);
-               record.accel_minus_g = int16(19);
-
-               if (uint16(11) == 0x8000) {
-                       record.kalman_acceleration = int16(5);
-                       record.kalman_speed = int16(9);
-                       record.kalman_height = int16(13);
-                       record.flight_accel = AltosRecord.MISSING;
-                       record.flight_vel = AltosRecord.MISSING;
-                       record.flight_pres = AltosRecord.MISSING;
-               } else {
-                       record.flight_accel = int16(5);
-                       record.flight_vel = uint32(9);
-                       record.flight_pres = int16(13);
-                       record.kalman_acceleration = AltosRecord.MISSING;
-                       record.kalman_speed = AltosRecord.MISSING;
-                       record.kalman_height = AltosRecord.MISSING;
-               }
-
-               record.gps = null;
-
-               int gps_flags = uint8(41);
-
-               if ((gps_flags & (AO_GPS_VALID|AO_GPS_RUNNING)) != 0) {
-                       record.gps = new AltosGPS();
-                       record.gps_sequence++;
-
-                       record.seen |= AltosRecord.seen_gps_time | AltosRecord.seen_gps_lat | AltosRecord.seen_gps_lon;
-                       record.gps.nsat = (gps_flags & AO_GPS_NUM_SAT_MASK);
-                       record.gps.locked = (gps_flags & AO_GPS_VALID) != 0;
-                       record.gps.connected = true;
-                       record.gps.lat = uint32(42) / 1.0e7;
-                       record.gps.lon = uint32(46) / 1.0e7;
-                       record.gps.alt = int16(50);
-                       record.gps.ground_speed = uint16(52) / 100.0;
-                       record.gps.course = uint8(54) * 2;
-                       record.gps.hdop = uint8(55) / 5.0;
-                       record.gps.h_error = uint16(58);
-                       record.gps.v_error = uint16(60);
-
-                       int     n_tracking_reported = uint8(70);
-                       if (n_tracking_reported > 12)
-                               n_tracking_reported = 12;
-                       int     n_tracking_actual = 0;
-                       for (int i = 0; i < n_tracking_reported; i++) {
-                               if (uint8(71 + i*2) != 0)
-                                       n_tracking_actual++;
-                       }
-                       if (n_tracking_actual > 0) {
-                               record.gps.cc_gps_sat = new AltosGPSSat[n_tracking_actual];
-
-                               n_tracking_actual = 0;
-                               for (int i = 0; i < n_tracking_reported; i++) {
-                                       int     svid = uint8(71 + i*2);
-                                       int     c_n0 = uint8(72 + i*2);
-                                       if (svid != 0)
-                                               record.gps.cc_gps_sat[n_tracking_actual++] = new AltosGPSSat(svid, c_n0);
-                               }
-                       }
-               }
-
-               record.time = 0.0;
-       }
-
-       public AltosRecord update_state(AltosRecord previous) {
-               return record;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordLocation.java b/altoslib/AltosTelemetryRecordLocation.java
deleted file mode 100644 (file)
index 0236d29..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-
-public class AltosTelemetryRecordLocation extends AltosTelemetryRecordRaw {
-       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;
-
-       public AltosTelemetryRecordLocation(int[] in_bytes, int rssi) {
-               super(in_bytes, rssi);
-
-               flags          = uint8(5);
-               altitude       = int16(6);
-               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);
-       }
-
-       public AltosRecord update_state(AltosRecord previous) {
-               AltosRecord     next = super.update_state(previous);
-
-               if (next.gps == null)
-                       next.gps = new AltosGPS();
-
-               next.gps.nsat = flags & 0xf;
-               next.gps.locked = (flags & (1 << 4)) != 0;
-               next.gps.connected = (flags & (1 << 5)) != 0;
-
-               if (next.gps.locked) {
-                       next.gps.lat = latitude * 1.0e-7;
-                       next.gps.lon = longitude * 1.0e-7;
-                       next.gps.alt = altitude;
-                       next.gps.year = 2000 + year;
-                       next.gps.month = month;
-                       next.gps.day = day;
-                       next.gps.hour = hour;
-                       next.gps.minute = minute;
-                       next.gps.second = second;
-                       next.gps.ground_speed = ground_speed * 1.0e-2;
-                       next.gps.course = course * 2;
-                       next.gps.climb_rate = climb_rate * 1.0e-2;
-                       next.gps.hdop = hdop;
-                       next.gps.vdop = vdop;
-                       next.seen |= AltosRecord.seen_gps_time | AltosRecord.seen_gps_lat | AltosRecord.seen_gps_lon;
-                       next.gps_sequence++;
-               }
-
-               return next;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordMegaData.java b/altoslib/AltosTelemetryRecordMegaData.java
deleted file mode 100644 (file)
index a484ef4..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-
-public class AltosTelemetryRecordMegaData extends AltosTelemetryRecordRaw {
-
-       int     state;
-       
-       int     v_batt;
-       int     v_pyro;
-       int     sense[];
-
-       int     ground_pres;
-       int     ground_accel;
-       int     accel_plus_g;
-       int     accel_minus_g;
-
-       int     acceleration;
-       int     speed;
-       int     height;
-
-       public AltosTelemetryRecordMegaData(int[] in_bytes, int rssi) {
-               super(in_bytes, rssi);
-
-               state = int8(5);
-
-               v_batt = int16(6);
-               v_pyro = int16(8);
-
-               sense = new int[6];     
-
-               for (int i = 0; i < 6; i++) {
-                       sense[i] = int8(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 = int16(30);
-       }
-
-       public AltosRecord update_state(AltosRecord previous) {
-               AltosRecord     n = super.update_state(previous);
-
-               AltosRecordMM   next;
-               if (!(n instanceof AltosRecordMM)) {
-                       next = new AltosRecordMM(n);
-               } else {
-                       next = (AltosRecordMM) n;
-               }
-
-               next.state = state;
-
-               next.v_batt = v_batt;
-               next.v_pyro = v_pyro;
-
-               for (int i = 0; i < 6; i++)
-                       next.sense[i] = sense[i];
-
-               next.ground_accel = ground_accel;
-               next.ground_pres = ground_pres;
-               next.accel_plus_g = accel_plus_g;
-               next.accel_minus_g = accel_minus_g;
-
-               next.kalman_acceleration = acceleration / 16.0;
-               next.kalman_speed = speed / 16.0;
-               next.kalman_height = height;
-
-               next.seen |= AltosRecord.seen_sensor | AltosRecord.seen_temp_volt;
-
-               return next;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordMegaSensor.java b/altoslib/AltosTelemetryRecordMegaSensor.java
deleted file mode 100644 (file)
index 2a4b17a..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-
-public class AltosTelemetryRecordMegaSensor extends AltosTelemetryRecordRaw {
-       int     accel;
-       int     pres;
-       int     temp;
-
-       int     accel_x;
-       int     accel_y;
-       int     accel_z;
-
-       int     gyro_x;
-       int     gyro_y;
-       int     gyro_z;
-
-       int     mag_x;
-       int     mag_y;
-       int     mag_z;
-
-       public AltosTelemetryRecordMegaSensor(int[] in_bytes, int rssi) {
-               super(in_bytes, rssi);
-
-               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 AltosRecord update_state(AltosRecord previous) {
-               AltosRecord     n = super.update_state(previous);
-
-               AltosRecordMM   next;
-               if (!(n instanceof AltosRecordMM)) {
-                       next = new AltosRecordMM(n);
-               } else {
-                       next = (AltosRecordMM) n;
-               }
-
-               next.accel = accel;
-               next.pres = pres;
-               next.temp = temp;
-
-               next.imu.accel_x = accel_x;
-               next.imu.accel_y = accel_y;
-               next.imu.accel_z = accel_z;
-
-               next.imu.gyro_x = gyro_x;
-               next.imu.gyro_y = gyro_y;
-               next.imu.gyro_z = gyro_z;
-
-               next.mag.x = mag_x;
-               next.mag.y = mag_y;
-               next.mag.z = mag_z;
-
-               next.seen |= AltosRecord.seen_sensor;
-
-               return next;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordRaw.java b/altoslib/AltosTelemetryRecordRaw.java
deleted file mode 100644 (file)
index f94789b..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-public class AltosTelemetryRecordRaw extends AltosTelemetryRecord {
-       int[]   bytes;
-       int     serial;
-       int     tick;
-       int     type;
-       int     rssi;
-
-       long    received_time;
-
-       public int int8(int off) {
-               return AltosLib.int8(bytes, off + 1);
-       }
-
-       public int uint8(int off) {
-               return AltosLib.uint8(bytes, off + 1);
-       }
-
-       public int int16(int off) {
-               return AltosLib.int16(bytes, off + 1);
-       }
-
-       public int uint16(int off) {
-               return AltosLib.uint16(bytes, off + 1);
-       }
-
-       public int uint32(int off) {
-               return AltosLib.uint32(bytes, off + 1);
-       }
-
-       public int int32(int off) {
-               return AltosLib.int32(bytes, off + 1);
-       }
-
-       public String string(int off, int l) {
-               return AltosLib.string(bytes, off + 1, l);
-       }
-
-       public AltosTelemetryRecordRaw(int[] in_bytes, int in_rssi) {
-               bytes = in_bytes;
-               serial = uint16(0);
-               tick   = uint16(2);
-               type   = uint8(4);
-               rssi   = in_rssi;
-       }
-
-       public AltosRecord update_state(AltosRecord previous) {
-               AltosRecord     next;
-
-               if (previous != null && previous.serial == serial)
-                       next = previous.clone();
-               else
-                       next = new AltosRecordNone();
-               next.serial = serial;
-               next.tick = tick;
-               next.rssi = rssi;
-               return next;
-       }
-
-       public long received_time() {
-               return received_time;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordSatellite.java b/altoslib/AltosTelemetryRecordSatellite.java
deleted file mode 100644 (file)
index 9835389..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-public class AltosTelemetryRecordSatellite extends AltosTelemetryRecordRaw {
-       int             channels;
-       AltosGPSSat[]   sats;
-
-       public AltosTelemetryRecordSatellite(int[] in_bytes, int rssi) {
-               super(in_bytes, rssi);
-
-               channels = uint8(5);
-               if (channels > 12)
-                       channels = 12;
-               if (channels == 0)
-                       sats = null;
-               else {
-                       sats = new AltosGPSSat[channels];
-                       for (int i = 0; i < channels; i++) {
-                               int     svid =  uint8(6 + i * 2 + 0);
-                               int     c_n_1 = uint8(6 + i * 2 + 1);
-                               sats[i] = new AltosGPSSat(svid, c_n_1);
-                       }
-               }
-       }
-
-       public AltosRecord update_state(AltosRecord previous) {
-               AltosRecord     next = super.update_state(previous);
-
-               if (next.gps == null)
-                       next.gps = new AltosGPS();
-
-               next.gps.cc_gps_sat = sats;
-
-               return next;
-       }
-}
diff --git a/altoslib/AltosTelemetryRecordSensor.java b/altoslib/AltosTelemetryRecordSensor.java
deleted file mode 100644 (file)
index e0e92c1..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright © 2011 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 org.altusmetrum.altoslib_1;
-
-
-public class AltosTelemetryRecordSensor extends AltosTelemetryRecordRaw {
-       int     state;
-       int     accel;
-       int     pres;
-       int     temp;
-       int     v_batt;
-       int     sense_d;
-       int     sense_m;
-
-       int     acceleration;
-       int     speed;
-       int     height;
-
-       int     ground_accel;
-       int     ground_pres;
-       int     accel_plus_g;
-       int     accel_minus_g;
-
-       public AltosTelemetryRecordSensor(int[] in_bytes, int rssi) {
-               super(in_bytes, rssi);
-               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 AltosRecord update_state(AltosRecord prev) {
-               AltosRecord     n = super.update_state(prev);
-
-               AltosRecordTM   next;
-               if (!(n instanceof AltosRecordTM))
-                       next = new AltosRecordTM(n);
-               else
-                       next = (AltosRecordTM) n;
-
-               next.state = state;
-               if (type == packet_type_TM_sensor)
-                       next.accel = accel;
-               else
-                       next.accel = AltosRecord.MISSING;
-               next.pres = pres;
-               next.temp = temp;
-               next.batt = v_batt;
-               if (type == packet_type_TM_sensor || type == packet_type_Tm_sensor) {
-                       next.drogue = sense_d;
-                       next.main = sense_m;
-               } else {
-                       next.drogue = AltosRecord.MISSING;
-                       next.main = AltosRecord.MISSING;
-               }
-
-               next.kalman_acceleration = acceleration / 16.0;
-               next.kalman_speed = speed / 16.0;
-               next.kalman_height = height;
-
-               next.ground_pres = ground_pres;
-               if (type == packet_type_TM_sensor) {
-                       next.ground_accel = ground_accel;
-                       next.accel_plus_g = accel_plus_g;
-                       next.accel_minus_g = accel_minus_g;
-               } else {
-                       next.ground_accel = AltosRecord.MISSING;
-                       next.accel_plus_g = AltosRecord.MISSING;
-                       next.accel_minus_g = AltosRecord.MISSING;
-               }
-
-               next.seen |= AltosRecord.seen_sensor | AltosRecord.seen_temp_volt;
-
-               return next;
-       }
-}
diff --git a/altoslib/AltosTelemetrySatellite.java b/altoslib/AltosTelemetrySatellite.java
new file mode 100644 (file)
index 0000000..fde3d86
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+public class AltosTelemetrySatellite extends AltosTelemetryStandard {
+       int             channels;
+       AltosGPSSat[]   sats;
+
+       public AltosTelemetrySatellite(int[] bytes) {
+               super(bytes);
+
+               channels = uint8(5);
+               if (channels > 12)
+                       channels = 12;
+               if (channels == 0)
+                       sats = null;
+               else {
+                       sats = new AltosGPSSat[channels];
+                       for (int i = 0; i < channels; i++) {
+                               int     svid =  uint8(6 + i * 2 + 0);
+                               int     c_n_1 = uint8(6 + i * 2 + 1);
+                               sats[i] = new AltosGPSSat(svid, c_n_1);
+                       }
+               }
+       }
+
+       public void update_state(AltosState state) {
+               super.update_state(state);
+
+               AltosGPS        gps = state.make_temp_gps(true);
+               
+               gps.cc_gps_sat = sats;
+               state.set_temp_gps();
+       }
+}
diff --git a/altoslib/AltosTelemetrySensor.java b/altoslib/AltosTelemetrySensor.java
new file mode 100644 (file)
index 0000000..e110644
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+
+public class AltosTelemetrySensor extends AltosTelemetryStandard {
+       int     state;
+       int     accel;
+       int     pres;
+       int     temp;
+       int     v_batt;
+       int     sense_d;
+       int     sense_m;
+
+       int     acceleration;
+       int     speed;
+       int     height;
+
+       int     ground_accel;
+       int     ground_pres;
+       int     accel_plus_g;
+       int     accel_minus_g;
+
+       public AltosTelemetrySensor(int[] bytes) {
+               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_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);
+       }
+}
diff --git a/altoslib/AltosTelemetryStandard.java b/altoslib/AltosTelemetryStandard.java
new file mode 100644 (file)
index 0000000..3186ae0
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright © 2011 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 org.altusmetrum.altoslib_2;
+
+public abstract class AltosTelemetryStandard extends AltosTelemetry {
+       int[]   bytes;
+       int     type;
+
+       public int int8(int off) {
+               return AltosLib.int8(bytes, off + 1);
+       }
+
+       public int uint8(int off) {
+               return AltosLib.uint8(bytes, off + 1);
+       }
+
+       public int int16(int off) {
+               return AltosLib.int16(bytes, off + 1);
+       }
+
+       public int uint16(int off) {
+               return AltosLib.uint16(bytes, off + 1);
+       }
+
+       public int uint32(int off) {
+               return AltosLib.uint32(bytes, off + 1);
+       }
+
+       public int int32(int off) {
+               return AltosLib.int32(bytes, off + 1);
+       }
+
+       public String string(int off, int l) {
+               return AltosLib.string(bytes, off + 1, l);
+       }
+
+       public static AltosTelemetry parse_hex(int[] bytes) {
+               int     type = AltosLib.uint8(bytes, 4 + 1);
+
+               AltosTelemetry  telem;
+               switch (type) {
+               case packet_type_TM_sensor:
+               case packet_type_Tm_sensor:
+               case packet_type_Tn_sensor:
+                       telem = new AltosTelemetrySensor(bytes);
+                       break;
+               case packet_type_configuration:
+                       telem = new AltosTelemetryConfiguration(bytes);
+                       break;
+               case packet_type_location:
+                       telem = new AltosTelemetryLocation(bytes);
+                       break;
+               case packet_type_satellite:
+                       telem = new AltosTelemetrySatellite(bytes);
+                       break;
+/*
+               case packet_type_companion:
+                       telem = new AltosTelemetryCompanion(bytes);
+                       break;
+*/
+               case packet_type_mega_sensor:
+                       telem = new AltosTelemetryMegaSensor(bytes);
+                       break;
+               case packet_type_mega_data:
+                       telem = new AltosTelemetryMegaData(bytes);
+                       break;
+               case packet_type_metrum_sensor:
+                       telem = new AltosTelemetryMetrumSensor(bytes);
+                       break;
+               case packet_type_metrum_data:
+                       telem = new AltosTelemetryMetrumData(bytes);
+                       break;
+               case packet_type_mini:
+                       telem = new AltosTelemetryMini(bytes);
+                       break;
+               default:
+                       telem = new AltosTelemetryRaw(bytes);
+                       break;
+               }
+               return telem;
+       }
+
+       public AltosTelemetryStandard(int[] bytes) {
+               this.bytes = bytes;
+
+               serial = uint16(0);
+               tick   = uint16(2);
+               type   = uint8(4);
+       }
+
+       public void update_state(AltosState state) {
+               super.update_state(state);
+       }
+}
index 2749eac09dfdbd08ffc538be1097e1247b821fec..0105fe539f6f992e4e5f8820cd6b748e6d2acc5d 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public class AltosTemperature extends AltosUnits {
 
index b8b3254cc4e80394e6a996d51f622bf46b58ddda..ee74f916f373342f8d0f72664598f8d1fbe91d1f 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public abstract class AltosUnits {
 
index 61a181a4da7853b9d9e80767ff8841b6fe381342..1e3ad6556888b4881c6a6bcbc32aa9066aa14ea0 100644 (file)
@@ -15,7 +15,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_1;
+package org.altusmetrum.altoslib_2;
 
 public interface AltosUnitsListener {
        public void units_changed(boolean imperial_units);
index 8c1cf2add83c615b6899d4a147a199ed797b559e..c1cf053cc257aaaa0ddafef3ecb86e06f61a368c 100644 (file)
@@ -9,77 +9,93 @@ CLASSPATH_ENV=mkdir -p $(JAVAROOT); CLASSPATH="bin:$(FREETTS)/*:/usr/share/java/
 SRC=.
 
 altoslibdir = $(datadir)/java
+record_files = \
+       AltosEepromRecord.java \
+       AltosEepromTeleScience.java \
+       AltosRecordCompanion.java \
+       AltosRecordIterable.java \
+       AltosOrderedRecord.java \
+       AltosOrderedMegaRecord.java \
+       AltosOrderedMiniRecord.java \
+       AltosRecord.java \
+       AltosRecordNone.java \
+       AltosRecordTM.java \
+       AltosRecordMM.java \
+       AltosRecordMini.java
+
 
 altoslib_JAVA = \
        AltosLib.java \
+       AltosCompanion.java \
        AltosConfigData.java \
        AltosConfigValues.java \
        AltosConvert.java \
        AltosCRCException.java \
        AltosDebug.java \
+       AltosEeprom.java \
        AltosEepromChunk.java \
+       AltosEepromFile.java \
+       AltosEepromTM.java \
+       AltosEepromTm.java \
+       AltosEepromHeader.java \
        AltosEepromIterable.java \
        AltosEepromLog.java \
        AltosEepromMega.java \
-       AltosEepromMegaIterable.java \
-       AltosEepromRecord.java \
-       AltosEepromTeleScience.java \
+       AltosEepromMetrum2.java \
        AltosEepromMini.java \
-       AltosEepromMiniIterable.java \
        AltosFile.java \
        AltosFlash.java \
        AltosFlashListener.java \
        AltosFlightReader.java \
        AltosFrequency.java \
        AltosGPS.java \
-       AltosGPSQuery.java \
        AltosGPSSat.java \
        AltosGreatCircle.java \
        AltosHexfile.java \
+       AltosIdle.java \
+       AltosIdleFetch.java \
        AltosIdleMonitor.java \
        AltosIdleMonitorListener.java \
        AltosIgnite.java \
        AltosIMU.java \
-       AltosIMUQuery.java \
        AltosLine.java \
        AltosLink.java \
        AltosListenerState.java \
        AltosLog.java \
+       AltosMag.java \
+       AltosMma655x.java \
        AltosMs5607.java \
-       AltosMs5607Query.java \
-       AltosOrderedRecord.java \
-       AltosOrderedMegaRecord.java \
-       AltosOrderedMiniRecord.java \
        AltosParse.java \
        AltosPreferences.java \
        AltosPreferencesBackend.java \
-       AltosRecordCompanion.java \
-       AltosRecordIterable.java \
-       AltosRecord.java \
-       AltosRecordNone.java \
-       AltosRecordTM.java \
-       AltosRecordMM.java \
-       AltosRecordMini.java \
        AltosReplayReader.java \
        AltosRomconfig.java \
        AltosSensorMM.java \
+       AltosSensorEMini.java \
        AltosSensorTM.java \
+       AltosSensorTMini.java \
+       AltosSensorMega.java \
+       AltosSensorMetrum.java \
        AltosState.java \
+       AltosStateIterable.java \
+       AltosStateUpdate.java \
        AltosTelemetry.java \
+       AltosTelemetryConfiguration.java \
+       AltosTelemetryFile.java \
        AltosTelemetryIterable.java \
+       AltosTelemetryLegacy.java \
+       AltosTelemetryLocation.java \
        AltosTelemetryMap.java \
+       AltosTelemetryMegaSensor.java \
+       AltosTelemetryMegaData.java \
+       AltosTelemetryMini.java \
+       AltosTelemetryMetrumSensor.java \
+       AltosTelemetryMetrumData.java \
        AltosTelemetryReader.java \
-       AltosTelemetryRecordCompanion.java \
-       AltosTelemetryRecordConfiguration.java \
-       AltosTelemetryRecordGeneral.java \
-       AltosTelemetryRecord.java \
-       AltosTelemetryRecordLegacy.java \
-       AltosTelemetryRecordLocation.java \
-       AltosTelemetryRecordRaw.java \
-       AltosTelemetryRecordSatellite.java \
-       AltosTelemetryRecordSensor.java \
-       AltosTelemetryRecordMegaSensor.java \
-       AltosTelemetryRecordMegaData.java \
+       AltosTelemetryRaw.java \
+       AltosTelemetrySensor.java \
+       AltosTelemetrySatellite.java \
+       AltosTelemetryStandard.java \
        AltosUnitsListener.java \
        AltosMs5607.java \
        AltosIMU.java \
index d25736bf36da3d77134663a27ce6fe6d8d6744dc..07280b4ae1c5af8e776c6a288aef54b42294b8da 100644 (file)
@@ -20,7 +20,7 @@ package altosui;
 import java.awt.*;
 import libaltosJNI.*;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class Altos extends AltosUILib {
index 4da4d591d70edaf06a2921a734cb9af616d8b40f..1d9af54679d4f637a82aadb7d32306eed069337d 100644 (file)
@@ -19,7 +19,7 @@ package altosui;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosAscent extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
@@ -179,7 +179,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                void reset() {
                        value.setText("");
                        max_value.setText("");
-                       max = AltosRecord.MISSING;
+                       max = AltosLib.MISSING;
                }
 
                void set_font() {
@@ -189,12 +189,12 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                }
 
                void show(AltosUnits units, double v) {
-                       if (v == AltosRecord.MISSING) {
+                       if (v == AltosLib.MISSING) {
                                value.setText("Missing");
                                max_value.setText("Missing");
                        } else {
                                value.setText(units.show(8, v));
-                               if (v > max || max == AltosRecord.MISSING) {
+                               if (v > max || max == AltosLib.MISSING) {
                                        max_value.setText(units.show(8, v));
                                        max = v;
                                }
@@ -240,7 +240,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Height extends AscentValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.height, state.height);
+                       show(AltosConvert.height, state.height());
                }
                public Height (GridBagLayout layout, int y) {
                        super (layout, y, "Height");
@@ -251,10 +251,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Speed extends AscentValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       double speed = state.accel_speed;
-                       if (!state.ascent)
-                               speed = state.baro_speed;
-                       show(AltosConvert.speed, speed);
+                       show(AltosConvert.speed, state.speed());
                }
                public Speed (GridBagLayout layout, int y) {
                        super (layout, y, "Speed");
@@ -265,7 +262,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Accel extends AscentValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.accel, state.acceleration);
+                       show(AltosConvert.accel, state.acceleration());
                }
                public Accel (GridBagLayout layout, int y) {
                        super (layout, y, "Acceleration");
@@ -287,8 +284,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Apogee extends AscentStatus {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show("%4.2f V", state.drogue_sense);
-                       lights.set(state.drogue_sense > 3.2);
+                       show("%4.2f V", state.apogee_voltage);
+                       lights.set(state.apogee_voltage > 3.7);
                }
                public Apogee (GridBagLayout layout, int y) {
                        super(layout, y, "Apogee Igniter Voltage");
@@ -299,8 +296,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Main extends AscentStatus {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show("%4.2f V", state.main_sense);
-                       lights.set(state.main_sense > 3.2);
+                       show("%4.2f V", state.main_voltage);
+                       lights.set(state.main_voltage > 3.7);
                }
                public Main (GridBagLayout layout, int y) {
                        super(layout, y, "Main Igniter Voltage");
@@ -311,7 +308,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Lat extends AscentValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state.gps != null)
+                       if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
                                show(pos(state.gps.lat,"N", "S"));
                        else
                                show("???");
@@ -325,7 +322,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Lon extends AscentValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state.gps != null)
+                       if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
                                show(pos(state.gps.lon,"E", "W"));
                        else
                                show("???");
@@ -368,11 +365,11 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        lon.hide();
                }
                height.show(state, listener_state);
-               if (state.main_sense != AltosRecord.MISSING)
+               if (state.main_voltage != AltosLib.MISSING)
                        main.show(state, listener_state);
                else
                        main.hide();
-               if (state.drogue_sense != AltosRecord.MISSING)
+               if (state.apogee_voltage != AltosLib.MISSING)
                        apogee.show(state, listener_state);
                else
                        apogee.hide();
index 1d42365ba858281e82ca43eb2914cd33a962a046..a1652ec4e0a6a893d53b96a4009fc20ea5f5c04b 100644 (file)
@@ -17,7 +17,7 @@
 
 package altosui;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosBTKnown implements Iterable<AltosBTDevice> {
index 0676f99d38fb63478f4da9c32f5a9535e02743d1..7598eca00ffce570a58fcb30e8103228fb626e48 100644 (file)
@@ -19,7 +19,7 @@ package altosui;
 
 import java.io.*;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosCSV implements AltosWriter {
        File                    name;
@@ -27,7 +27,7 @@ public class AltosCSV implements AltosWriter {
        boolean                 header_written;
        boolean                 seen_boost;
        int                     boost_tick;
-       LinkedList<AltosRecord> pad_records;
+       LinkedList<AltosState>  pad_states;
        AltosState              state;
 
        static final int ALTOS_CSV_VERSION = 5;
@@ -105,47 +105,47 @@ public class AltosCSV implements AltosWriter {
                out.printf("version,serial,flight,call,time,clock,rssi,lqi");
        }
 
-       void write_general(AltosRecord record) {
+       void write_general(AltosState state) {
                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.tick / 100.0,
-                          record.rssi,
-                          record.status & 0x7f);
+                          ALTOS_CSV_VERSION, state.serial, state.flight, state.callsign,
+                          (double) state.time, (double) state.tick / 100.0,
+                          state.rssi,
+                          state.status & 0x7f);
        }
 
        void write_flight_header() {
                out.printf("state,state_name");
        }
 
-       void write_flight(AltosRecord record) {
-               out.printf("%d,%8s", record.state, record.state());
+       void write_flight(AltosState state) {
+               out.printf("%d,%8s", state.state, state.state_name());
        }
 
        void write_basic_header() {
                out.printf("acceleration,pressure,altitude,height,accel_speed,baro_speed,temperature,battery_voltage,drogue_voltage,main_voltage");
        }
 
-       void write_basic(AltosRecord record) {
+       void write_basic(AltosState state) {
                out.printf("%8.2f,%10.2f,%8.2f,%8.2f,%8.2f,%8.2f,%5.1f,%5.2f,%5.2f,%5.2f",
-                          record.acceleration(),
-                          record.pressure(),
-                          record.altitude(),
-                          record.height(),
-                          state.accel_speed,
-                          state.baro_speed,
-                          record.temperature(),
-                          record.battery_voltage(),
-                          record.drogue_voltage(),
-                          record.main_voltage());
+                          state.acceleration(),
+                          state.pressure(),
+                          state.altitude(),
+                          state.height(),
+                          state.speed(),
+                          state.speed(),
+                          state.temperature,
+                          state.battery_voltage,
+                          state.apogee_voltage,
+                          state.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();
+       void write_advanced(AltosState state) {
+               AltosIMU        imu = state.imu;
+               AltosMag        mag = state.mag;
 
                if (imu == null)
                        imu = new AltosIMU();
@@ -161,8 +161,8 @@ public class AltosCSV implements AltosWriter {
                out.printf("connected,locked,nsat,latitude,longitude,altitude,year,month,day,hour,minute,second,pad_dist,pad_range,pad_az,pad_el,hdop");
        }
 
-       void write_gps(AltosRecord record) {
-               AltosGPS        gps = record.gps;
+       void write_gps(AltosState state) {
+               AltosGPS        gps = state.gps;
                if (gps == null)
                        gps = new AltosGPS();
 
@@ -170,7 +170,7 @@ public class AltosCSV implements AltosWriter {
                if (from_pad == null)
                        from_pad = new AltosGreatCircle();
 
-               out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%6d,%5d,%3d,%3d,%3d,%3d,%3d,%9.0f,%9.0f,%4.0f,%4.0f,%6.1f",
+               out.printf("%2d,%2d,%3d,%12.7f,%12.7f,%8.1f,%5d,%3d,%3d,%3d,%3d,%3d,%9.0f,%9.0f,%4.0f,%4.0f,%6.1f",
                           gps.connected?1:0,
                           gps.locked?1:0,
                           gps.nsat,
@@ -198,8 +198,8 @@ public class AltosCSV implements AltosWriter {
                }
        }
 
-       void write_gps_sat(AltosRecord record) {
-               AltosGPS        gps = record.gps;
+       void write_gps_sat(AltosState state) {
+               AltosGPS        gps = state.gps;
                for(int i = 1; i <= 32; i++) {
                        int     c_n0 = 0;
                        if (gps != null && gps.cc_gps_sat != null) {
@@ -221,8 +221,8 @@ public class AltosCSV implements AltosWriter {
                        out.printf(",companion_%02d", i);
        }
 
-       void write_companion(AltosRecord record) {
-               AltosRecordCompanion companion = record.companion;
+       void write_companion(AltosState state) {
+               AltosCompanion companion = state.companion;
 
                int     channels_written = 0;
                if (companion == null) {
@@ -256,50 +256,49 @@ public class AltosCSV implements AltosWriter {
                out.printf ("\n");
        }
 
-       void write_one(AltosRecord record) {
-               state = new AltosState(record, state);
-               write_general(record); out.printf(",");
-               write_flight(record); out.printf(",");
-               write_basic(record); out.printf(",");
-               if (record.imu() != null || record.mag() != null)
-                       write_advanced(record);
-               if (record.gps != null) {
+       void write_one(AltosState state) {
+               write_general(state); out.printf(",");
+               write_flight(state); out.printf(",");
+               write_basic(state); out.printf(",");
+               if (state.imu != null || state.mag != null)
+                       write_advanced(state);
+               if (state.gps != null) {
                        out.printf(",");
-                       write_gps(record); out.printf(",");
-                       write_gps_sat(record);
+                       write_gps(state); out.printf(",");
+                       write_gps_sat(state);
                }
-               if (record.companion != null) {
+               if (state.companion != null) {
                        out.printf(",");
-                       write_companion(record);
+                       write_companion(state);
                }
                out.printf ("\n");
        }
 
        void flush_pad() {
-               while (!pad_records.isEmpty()) {
-                       write_one (pad_records.remove());
+               while (!pad_states.isEmpty()) {
+                       write_one (pad_states.remove());
                }
        }
 
-       public void write(AltosRecord record) {
-               if (record.state == Altos.ao_flight_startup)
+       public void write(AltosState state) {
+               if (state.state == Altos.ao_flight_startup)
                        return;
                if (!header_written) {
-                       write_header(record.imu() != null || record.mag() != null,
-                                    record.gps != null, record.companion != null);
+                       write_header(state.imu != null || state.mag != null,
+                                    state.gps != null, state.companion != null);
                        header_written = true;
                }
                if (!seen_boost) {
-                       if (record.state >= Altos.ao_flight_boost) {
+                       if (state.state >= Altos.ao_flight_boost) {
                                seen_boost = true;
-                               boost_tick = record.tick;
+                               boost_tick = state.tick;
                                flush_pad();
                        }
                }
                if (seen_boost)
-                       write_one(record);
+                       write_one(state);
                else
-                       pad_records.add(record);
+                       pad_states.add(state);
        }
 
        public PrintStream out() {
@@ -307,23 +306,23 @@ public class AltosCSV implements AltosWriter {
        }
 
        public void close() {
-               if (!pad_records.isEmpty()) {
-                       boost_tick = pad_records.element().tick;
+               if (!pad_states.isEmpty()) {
+                       boost_tick = pad_states.element().tick;
                        flush_pad();
                }
                out.close();
        }
 
-       public void write(AltosRecordIterable iterable) {
-               iterable.write_comments(out());
-               for (AltosRecord r : iterable)
-                       write(r);
+       public void write(AltosStateIterable states) {
+               states.write_comments(out());
+               for (AltosState state : states)
+                       write(state);
        }
 
        public AltosCSV(PrintStream in_out, File in_name) {
                name = in_name;
                out = in_out;
-               pad_records = new LinkedList<AltosRecord>();
+               pad_states = new LinkedList<AltosState>();
        }
 
        public AltosCSV(File in_name) throws FileNotFoundException {
index 4250834691755ad725dd948d98deedb7b6030a38..c41ea74b5190dba3a7c5868db374cfec20db9613 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.io.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosCSVUI
@@ -31,7 +31,7 @@ public class AltosCSVUI
        JFileChooser            csv_chooser;
        JPanel                  accessory;
        JComboBox               combo_box;
-       AltosRecordIterable     iterable;
+       Iterable<AltosState>    states;
        AltosWriter             writer;
 
        static String[]         combo_box_items = { "Comma Separated Values (.CSV)", "Googleearth Data (.KML)" };
@@ -55,8 +55,8 @@ public class AltosCSVUI
                        set_default_file();
        }
 
-       public AltosCSVUI(JFrame frame, AltosRecordIterable in_iterable, File source_file) {
-               iterable = in_iterable;
+       public AltosCSVUI(JFrame frame, AltosStateIterable states, File source_file) {
+               this.states = states;
                csv_chooser = new JFileChooser(source_file);
 
                accessory = new JPanel();
@@ -91,7 +91,7 @@ public class AltosCSVUI
                                        writer = new AltosCSV(file);
                                else
                                        writer = new AltosKML(file);
-                               writer.write(iterable);
+                               writer.write(states);
                                writer.close();
                        } catch (FileNotFoundException ee) {
                                JOptionPane.showMessageDialog(frame,
index ebe1d1f9826612cf004d23d224010da50d515aef..1f446700218827c64ff1ff6673df8cf1654f2156 100644 (file)
@@ -19,7 +19,7 @@ package altosui;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosCompanionInfo extends JTable {
        private AltosFlightInfoTableModel model;
@@ -70,13 +70,13 @@ public class AltosCompanionInfo extends JTable {
                model.clear();
        }
 
-       AltosRecordCompanion    companion;
+       AltosCompanion  companion;
 
        public String board_name() {
                if (companion == null)
                        return "None";
                switch (companion.board_id) {
-               case AltosRecordCompanion.board_id_telescience:
+               case AltosCompanion.board_id_telescience:
                        return "TeleScience";
                default:
                        return String.format("%02x\n", companion.board_id);
@@ -86,8 +86,8 @@ public class AltosCompanionInfo extends JTable {
        public void show(AltosState state, AltosListenerState listener_state) {
                if (state == null)
                        return;
-               if (state.data.companion != null)
-                       companion = state.data.companion;
+               if (state.companion != null)
+                       companion = state.companion;
                info_reset();
                info_add_row(0, "Companion board", "%s", board_name());
                if (companion != null) {
index 4927d3f822e0ad9b73fc2cf6c1fab9c9137eb456..a6e6094fc1acbc21fb23dc5ca3de8e60ff612843 100644 (file)
@@ -22,7 +22,7 @@ import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
 import java.text.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosConfig implements ActionListener {
index c90b168f3359ff236f368d08564f0d97e83f6dcd..555af3b6b69ffdc8c12abd03f4dcbd8de98a384e 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 class AltosEditFreqUI extends AltosUIDialog implements ActionListener {
index 3cac56c3a576425f2d826c43bf9e3e91aebe21fc..2f5c199dbd5616c24f68c006c32ad3ea9857c7ea 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import javax.swing.event.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosConfigPyroUI
index 16c9e357134c58ded5f2a8e545c3f902781669ac..f879ff88bcdef1324db4714e8e16a7a0c9487cd1 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.event.*;
 import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosConfigTD implements ActionListener {
index 125780a99f9813c723677080e4802c8b383eb36e..b5a6cd7c3fdd8ee6a355bb3d5daeea882722ac98 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import javax.swing.event.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosConfigTDUI
index 9723e6600141549237244cac29c878787df9ae1a..a6d27977cd5d41b211f6c1d511adf8e8287b2633 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import javax.swing.event.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosConfigUI
index c7b561d5a809c5eda48f5045a1234c438fe02079..c0d6668279574e051dfafdf0dce2e097b12016f4 100644 (file)
@@ -20,7 +20,7 @@ package altosui;
 import javax.swing.*;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import java.io.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosDataChooser extends JFileChooser {
@@ -36,7 +36,7 @@ public class AltosDataChooser extends JFileChooser {
                return file;
        }
 
-       public AltosRecordIterable runDialog() {
+       public AltosStateIterable runDialog() {
                int     ret;
 
                ret = showOpenDialog(frame);
@@ -48,16 +48,10 @@ public class AltosDataChooser extends JFileChooser {
                        try {
                                if (filename.endsWith("eeprom")) {
                                        FileInputStream in = new FileInputStream(file);
-                                       return new AltosEepromIterable(in);
+                                       return new AltosEepromFile(in);
                                } else if (filename.endsWith("telem")) {
                                        FileInputStream in = new FileInputStream(file);
-                                       return new AltosTelemetryIterable(in);
-                               } else if (filename.endsWith("mega")) {
-                                       FileInputStream in = new FileInputStream(file);
-                                       return new AltosEepromMegaIterable(in);
-                               } else if (filename.endsWith("mini")) {
-                                       FileInputStream in = new FileInputStream(file);
-                                       return new AltosEepromMiniIterable(in);
+                                       return new AltosTelemetryFile(in);
                                } else {
                                        throw new FileNotFoundException();
                                }
index 29d33ddc9afac6085b9426bb8b37928274892987..77776ff2ce3417d8b847874505dd1c8572228dc3 100644 (file)
@@ -19,7 +19,7 @@ package altosui;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosDescent extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
@@ -245,7 +245,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
        class Height extends DescentValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.height, state.height);
+                       show(AltosConvert.height, state.height());
                }
                public Height (GridBagLayout layout, int x, int y) {
                        super (layout, x, y, "Height");
@@ -256,10 +256,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
        class Speed extends DescentValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       double speed = state.accel_speed;
-                       if (!state.ascent)
-                               speed = state.baro_speed;
-                       show(AltosConvert.speed, speed);
+                       show(AltosConvert.speed, state.speed());
                }
                public Speed (GridBagLayout layout, int x, int y) {
                        super (layout, x, y, "Speed");
@@ -281,7 +278,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
        class Lat extends DescentValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state.gps != null && state.gps.connected)
+                       if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
                                show(pos(state.gps.lat,"N", "S"));
                        else
                                show("???");
@@ -295,7 +292,7 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
        class Lon extends DescentValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state.gps != null && state.gps.connected)
+                       if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
                                show(pos(state.gps.lon,"W", "E"));
                        else
                                show("???");
@@ -325,8 +322,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
        class Apogee extends DescentStatus {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show("%4.2f V", state.drogue_sense);
-                       lights.set(state.drogue_sense > 3.2);
+                       show("%4.2f V", state.apogee_voltage);
+                       lights.set(state.apogee_voltage > 3.7);
                }
                public Apogee (GridBagLayout layout, int y) {
                        super(layout, y, "Apogee Igniter Voltage");
@@ -337,8 +334,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
        class Main extends DescentStatus {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show("%4.2f V", state.main_sense);
-                       lights.set(state.main_sense > 3.2);
+                       show("%4.2f V", state.main_voltage);
+                       lights.set(state.main_voltage > 3.7);
                }
                public Main (GridBagLayout layout, int y) {
                        super(layout, y, "Main Igniter Voltage");
@@ -430,11 +427,11 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                        lat.hide();
                        lon.hide();
                }
-               if (state.main_sense != AltosRecord.MISSING)
+               if (state.main_voltage != AltosLib.MISSING)
                        main.show(state, listener_state);
                else
                        main.hide();
-               if (state.drogue_sense != AltosRecord.MISSING)
+               if (state.apogee_voltage != AltosLib.MISSING)
                        apogee.show(state, listener_state);
                else
                        apogee.hide();
index 095bed992c08c524d5718e21066ece2b20ad5df6..37f6adf9051613ec0686b0564dacfc442e128024 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.*;
 import javax.swing.*;
 import java.io.*;
 import java.text.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosDisplayThread extends Thread {
 
@@ -92,14 +92,14 @@ public class AltosDisplayThread extends Thread {
                            state.range >= 0)
                        {
                                voice.speak("Height %s, bearing %s %d, elevation %d, range %s.\n",
-                                           AltosConvert.height.say(state.height),
+                                           AltosConvert.height.say(state.height()),
                                            state.from_pad.bearing_words(
                                                    AltosGreatCircle.BEARING_VOICE),
                                            (int) (state.from_pad.bearing + 0.5),
                                            (int) (state.elevation + 0.5),
                                            AltosConvert.distance.say(state.range));
                        } else if (state.state > Altos.ao_flight_pad) {
-                               voice.speak(AltosConvert.height.say_units(state.height));
+                               voice.speak(AltosConvert.height.say_units(state.height()));
                        } else {
                                reported_landing = 0;
                        }
@@ -110,10 +110,10 @@ public class AltosDisplayThread extends Thread {
                         */
                        if (state.state >= Altos.ao_flight_drogue &&
                            (last ||
-                            System.currentTimeMillis() - state.report_time >= 15000 ||
+                            System.currentTimeMillis() - state.received_time >= 15000 ||
                             state.state == Altos.ao_flight_landed))
                        {
-                               if (Math.abs(state.baro_speed) < 20 && state.height < 100)
+                               if (Math.abs(state.speed()) < 20 && state.height() < 100)
                                        voice.speak("rocket landed safely");
                                else
                                        voice.speak("rocket may have crashed");
@@ -181,16 +181,16 @@ public class AltosDisplayThread extends Thread {
        synchronized boolean tell() {
                boolean ret = false;
                if (old_state == null || old_state.state != state.state) {
-                       voice.speak(state.data.state());
+                       voice.speak(state.state_name());
                        if ((old_state == null || old_state.state <= Altos.ao_flight_boost) &&
                            state.state > Altos.ao_flight_boost) {
                                voice.speak("max speed: %s.",
-                                           AltosConvert.speed.say_units(state.max_accel_speed + 0.5));
+                                           AltosConvert.speed.say_units(state.max_speed() + 0.5));
                                ret = true;
                        } else if ((old_state == null || old_state.state < Altos.ao_flight_drogue) &&
                                   state.state >= Altos.ao_flight_drogue) {
                                voice.speak("max height: %s.",
-                                           AltosConvert.height.say_units(state.max_height + 0.5));
+                                           AltosConvert.height.say_units(state.max_height() + 0.5));
                                ret = true;
                        }
                }
@@ -218,11 +218,9 @@ public class AltosDisplayThread extends Thread {
                try {
                        for (;;) {
                                try {
-                                       AltosRecord record = reader.read();
-                                       if (record == null)
+                                       state = reader.read();
+                                       if (state == null)
                                                break;
-                                       old_state = state;
-                                       state = new AltosState(record, state);
                                        reader.update(state);
                                        show_safely();
                                        told = tell();
index e81a35d1133fd0249581fced0298b2780f18dc0b..9984d1a2420d37fe247688ab0c735e853967b26b 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.event.*;
 import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosEepromDelete implements Runnable {
        AltosEepromList         flights;
index 46715db64100a8a4a111edc9e448d329df83f640..6e2fd061b1cbef6afe1f6ef223a118b95a57782c 100644 (file)
@@ -23,7 +23,7 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosEepromDownload implements Runnable {
 
@@ -33,9 +33,6 @@ public class AltosEepromDownload implements Runnable {
        Thread                  eeprom_thread;
        AltosEepromMonitor      monitor;
 
-       int                     flight;
-       int                     serial;
-       int                     year, month, day;
        boolean                 want_file;
        FileWriter              eeprom_file;
        LinkedList<String>      eeprom_pending;
@@ -44,7 +41,7 @@ public class AltosEepromDownload implements Runnable {
        ActionListener          listener;
        boolean                 success;
        ParseException          parse_exception;
-       String                  extension;
+       AltosState              state;
 
        private void FlushPending() throws IOException {
                for (String s : flights.config_data) {
@@ -59,15 +56,19 @@ public class AltosEepromDownload implements Runnable {
        private void CheckFile(boolean force) throws IOException {
                if (eeprom_file != null)
                        return;
-               if (force || (flight != 0 && want_file)) {
+               if (force || (state.flight != 0 && want_file)) {
                        AltosFile               eeprom_name;
-
-                       if (extension == null)
-                               extension = "data";
-                       if (year != 0 && month != 0 && day != 0)
-                               eeprom_name = new AltosFile(year, month, day, serial, flight, extension);
-                       else
-                               eeprom_name = new AltosFile(serial, flight, extension);
+                       AltosGPS                gps = state.gps;
+
+                       if (gps != null &&
+                           gps.year != AltosLib.MISSING &&
+                           gps.month != AltosLib.MISSING &&
+                           gps.day != AltosLib.MISSING)
+                       {
+                               eeprom_name = new AltosFile(gps.year, gps.month, gps.day,
+                                                           state.serial, state.flight, "eeprom");
+                       } else
+                               eeprom_name = new AltosFile(state.serial, state.flight, "eeprom");
 
                        eeprom_file = new FileWriter(eeprom_name);
                        if (eeprom_file != null) {
@@ -78,270 +79,57 @@ public class AltosEepromDownload implements Runnable {
                }
        }
 
-       void Log(AltosEepromRecord r) throws IOException {
+       boolean                 done;
+       boolean                 start;
+
+       void LogEeprom(AltosEeprom r) throws IOException {
                if (r.cmd != Altos.AO_LOG_INVALID) {
-                       String log_line = String.format("%c %4x %4x %4x\n",
-                                                       r.cmd, r.tick, r.a, r.b);
+                       String line = r.string();
                        if (eeprom_file != null)
-                               eeprom_file.write(log_line);
+                               eeprom_file.write(line);
                        else
-                               eeprom_pending.add(log_line);
+                               eeprom_pending.add(line);
                }
        }
 
-       void set_serial(int in_serial) {
-               serial = in_serial;
-               monitor.set_serial(serial);
-       }
-
-       void set_flight(int in_flight) {
-               flight = in_flight;
-               monitor.set_flight(flight);
-       }
-               
-       boolean                 done;
-       int                     state;
-
-       void CaptureFull(AltosEepromChunk eechunk) throws IOException {
-               boolean any_valid = false;
-
-               extension = "eeprom";
-               set_serial(flights.config_data.serial);
-               for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromRecord.record_length) {
-                       try {
-                               AltosEepromRecord r = new AltosEepromRecord(eechunk, i);
-                               if (r.cmd == Altos.AO_LOG_FLIGHT)
-                                       set_flight(r.b);
-
-                               /* Monitor state transitions to update display */
-                               if (r.cmd == Altos.AO_LOG_STATE && r.a <= Altos.ao_flight_landed) {
-                                       state = r.a;
-                                       if (state > Altos.ao_flight_pad)
-                                               want_file = true;
-                               }
-
-                               if (r.cmd == Altos.AO_LOG_GPS_DATE) {
-                                       year = 2000 + (r.a & 0xff);
-                                       month = (r.a >> 8) & 0xff;
-                                       day = (r.b & 0xff);
-                                       want_file = true;
-                               }
-                               if (r.cmd == Altos.AO_LOG_STATE && r.a == Altos.ao_flight_landed)
-                                       done = true;
-                               if (r.cmd != AltosLib.AO_LOG_INVALID)
-                                       any_valid = true;
-                               Log(r);
-                       } catch (ParseException pe) {
-                               if (parse_exception == null)
-                                       parse_exception = pe;
-                       }
-               }
-
-               if (!any_valid)
-                       done = true;
-
-               CheckFile(false);
-       }
-
-       boolean start;
-       int     tiny_tick;
-
-       void CaptureTiny (AltosEepromChunk eechunk) throws IOException {
+       void CaptureEeprom(AltosEepromChunk eechunk, int log_format) throws IOException {
                boolean any_valid = false;
+               boolean got_flight = false;
 
-               extension = "eeprom";
-               set_serial(flights.config_data.serial);
-               for (int i = 0; i < eechunk.data.length && !done; i += 2) {
-                       int                     v = eechunk.data16(i);
-                       AltosEepromRecord       r;
-
-                       if (i == 0 && start) {
-                               tiny_tick = 0;
-                               start = false;
-                               set_flight(v);
-                               r = new AltosEepromRecord(Altos.AO_LOG_FLIGHT, tiny_tick, 0, v);
-                               any_valid = true;
-                       } else {
-                               int     s = v ^ 0x8000;
-
-                               if (Altos.ao_flight_startup <= s && s <= Altos.ao_flight_invalid) {
-                                       state = s;
-                                       r = new AltosEepromRecord(Altos.AO_LOG_STATE, tiny_tick, state, 0);
-                                       if (state == Altos.ao_flight_landed)
-                                               done = true;
-                                       state = s;
-                                       any_valid = true;
-                               } else {
-                                       if (v != 0xffff)
-                                               any_valid = true;
-
-                                       r = new AltosEepromRecord(Altos.AO_LOG_PRESSURE, tiny_tick, 0, v);
-
-                                       /*
-                                        * The flight software records ascent data every 100ms, and descent
-                                        * data every 1s.
-                                        */
-                                       if (state < Altos.ao_flight_drogue)
-                                               tiny_tick += 10;
-                                       else
-                                               tiny_tick += 100;
-                               }
-                       }
-                       Log(r);
-               }
-               CheckFile(false);
-               if (!any_valid)
-                       done = true;
-       }
+               int record_length = 8;
 
-       void LogTeleScience(AltosEepromTeleScience r) throws IOException {
-               if (r.type != Altos.AO_LOG_INVALID) {
-                       String log_line = String.format("%c %4x %4x %d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n",
-                                                       r.type, r.tick, r.tm_tick, r.tm_state,
-                                                       r.data[0], r.data[1], r.data[2], r.data[3], 
-                                                       r.data[4], r.data[5], r.data[6], r.data[7], 
-                                                       r.data[8], r.data[9], r.data[10], r.data[11]);
-                       if (eeprom_file != null)
-                               eeprom_file.write(log_line);
-                       else
-                               eeprom_pending.add(log_line);
-               }
-       }
-       
-       boolean telescience_start;
-
-       void CaptureTeleScience (AltosEepromChunk eechunk) throws IOException {
-               boolean any_valid = false;
-
-               extension = "science";
-               for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromTeleScience.record_length) {
-                       try {
-                               AltosEepromTeleScience r = new AltosEepromTeleScience(eechunk, i);
-                               if (r.type == AltosEepromTeleScience.AO_LOG_TELESCIENCE_START) {
-                                       if (telescience_start) {
-                                               done = true;
-                                               break;
-                                       }
-                                       set_serial(r.data[0]);
-                                       set_flight(r.data[1]);
-                                       telescience_start = true;
-                               } else {
-                                       if (!telescience_start)
-                                               break;
-                               }
-                               state = r.tm_state;
-                               want_file =true;
-                               any_valid = true;
-                               LogTeleScience(r);
-                       } catch (ParseException pe) {
-                               if (parse_exception == null)
-                                       parse_exception = pe;
-                       }
-               }
+               state.set_serial(flights.config_data.serial);
+               monitor.set_serial(flights.config_data.serial);
 
-               CheckFile(false);
-               if (!any_valid)
-                       done = true;
-       }
+               for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += record_length) {
+                       AltosEeprom r = eechunk.eeprom(i, log_format, state);
 
-       void LogMega(AltosEepromMega r) throws IOException {
-               if (r.cmd != Altos.AO_LOG_INVALID) {
-                       String log_line = String.format("%c %4x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n",
-                                                       r.cmd, r.tick,
-                                                       r.data8[0], r.data8[1], r.data8[2], r.data8[3],
-                                                       r.data8[4], r.data8[5], r.data8[6], r.data8[7],
-                                                       r.data8[8], r.data8[9], r.data8[10], r.data8[11],
-                                                       r.data8[12], r.data8[13], r.data8[14], r.data8[15],
-                                                       r.data8[16], r.data8[17], r.data8[18], r.data8[19],
-                                                       r.data8[20], r.data8[21], r.data8[22], r.data8[23],
-                                                       r.data8[24], r.data8[25], r.data8[26], r.data8[27]);
-                       if (eeprom_file != null)
-                               eeprom_file.write(log_line);
-                       else
-                               eeprom_pending.add(log_line);
-               }
-       }
+                       if (r == null)
+                               continue;
 
-       void CaptureMega(AltosEepromChunk eechunk) throws IOException {
-               boolean any_valid = false;
+                       record_length = r.record_length();
 
-               extension = "mega";
-               set_serial(flights.config_data.serial);
-               for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromMega.record_length) {
-                       try {
-                               AltosEepromMega r = new AltosEepromMega(eechunk, i);
-                               if (r.cmd == Altos.AO_LOG_FLIGHT)
-                                       set_flight(r.data16(0));
-
-                               /* Monitor state transitions to update display */
-                               if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) <= Altos.ao_flight_landed) {
-                                       state = r.data16(0);
-                                       if (state > Altos.ao_flight_pad)
-                                               want_file = true;
-                               }
+                       r.update_state(state);
 
-                               if (r.cmd == Altos.AO_LOG_GPS_TIME) {
-                                       year = 2000 + r.data8(14);
-                                       month = r.data8(15);
-                                       day = r.data8(16);
-                                       want_file = true;
-                               }
+                       if (!got_flight && state.flight != AltosLib.MISSING)
+                               monitor.set_flight(state.flight);
 
-                               if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) == Altos.ao_flight_landed)
+                       /* Monitor state transitions to update display */
+                       if (state.state != AltosLib.ao_flight_invalid &&
+                           state.state <= AltosLib.ao_flight_landed)
+                       {
+                               if (state.state > Altos.ao_flight_pad)
+                                       want_file = true;
+                               if (state.state == AltosLib.ao_flight_landed)
                                        done = true;
-                               if (r.cmd != AltosLib.AO_LOG_INVALID)
-                                       any_valid = true;
-                               LogMega(r);
-                       } catch (ParseException pe) {
-                               if (parse_exception == null)
-                                       parse_exception = pe;
                        }
-               }
-               if (!any_valid)
-                       done = true;
 
-               CheckFile(false);
-       }
-       
-       void LogMini(AltosEepromMini r) throws IOException {
-               if (r.cmd != Altos.AO_LOG_INVALID) {
-                       String log_line = String.format("%c %4x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n",
-                                                       r.cmd, r.tick,
-                                                       r.data8[0], r.data8[1], r.data8[2], r.data8[3],
-                                                       r.data8[4], r.data8[5], r.data8[6], r.data8[7],
-                                                       r.data8[8], r.data8[9], r.data8[10], r.data8[11]);
-                       if (eeprom_file != null)
-                               eeprom_file.write(log_line);
-                       else
-                               eeprom_pending.add(log_line);
-               }
-       }
-
-       void CaptureMini(AltosEepromChunk eechunk) throws IOException {
-               boolean any_valid = false;
+                       if (state.gps != null)
+                               want_file = true;
 
-               extension = "mini";
-               set_serial(flights.config_data.serial);
-               for (int i = 0; i < AltosEepromChunk.chunk_size && !done; i += AltosEepromMini.record_length) {
-                       try {
-                               AltosEepromMini r = new AltosEepromMini(eechunk, i);
-                               if (r.cmd == Altos.AO_LOG_FLIGHT)
-                                       set_flight(r.data16(0));
-
-                               /* Monitor state transitions to update display */
-                               if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) <= Altos.ao_flight_landed) {
-                                       state = r.data16(0);
-                                       if (state > Altos.ao_flight_pad)
-                                               want_file = true;
-                               }
-
-                               if (r.cmd == Altos.AO_LOG_STATE && r.data16(0) == Altos.ao_flight_landed)
-                                       done = true;
+                       if (r.valid) {
                                any_valid = true;
-                               LogMini(r);
-                       } catch (ParseException pe) {
-                               if (parse_exception == null)
-                                       parse_exception = pe;
+                               LogEeprom(r);
                        }
                }
                if (!any_valid)
@@ -350,15 +138,12 @@ public class AltosEepromDownload implements Runnable {
                CheckFile(false);
        }
        
-       void CaptureTelemetry(AltosEepromChunk eechunk) throws IOException {
-               
-       }
-
        void CaptureLog(AltosEepromLog log) throws IOException, InterruptedException, TimeoutException {
                int                     block, state_block = 0;
                int                     log_format = flights.config_data.log_format;
 
-               state = 0;
+               state = new AltosState();
+
                done = false;
                start = true;
 
@@ -366,10 +151,6 @@ public class AltosEepromDownload implements Runnable {
                        throw new IOException("no serial number found");
 
                /* Reset per-capture variables */
-               flight = 0;
-               year = 0;
-               month = 0;
-               day = 0;
                want_file = false;
                eeprom_file = null;
                eeprom_pending = new LinkedList<String>();
@@ -377,9 +158,12 @@ public class AltosEepromDownload implements Runnable {
                /* Set serial number in the monitor dialog window */
                /* Now scan the eeprom, reading blocks of data and converting to .eeprom file form */
 
-               state = 0; state_block = log.start_block;
+               state_block = log.start_block;
                for (block = log.start_block; !done && block < log.end_block; block++) {
-                       monitor.set_value(AltosLib.state_name(state), state, block - state_block, block - log.start_block);
+                       monitor.set_value(state.state_name(),
+                                         state.state,
+                                         block - state_block,
+                                         block - log.start_block);
 
                        AltosEepromChunk        eechunk = new AltosEepromChunk(serial_line, block, block == log.start_block);
 
@@ -397,32 +181,7 @@ public class AltosEepromDownload implements Runnable {
                                }
                        }
 
-                       switch (log_format) {
-                       case AltosLib.AO_LOG_FORMAT_FULL:
-                               extension = "eeprom";
-                               CaptureFull(eechunk);
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_TINY:
-                               extension = "eeprom";
-                               CaptureTiny(eechunk);
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_TELEMETRY:
-                               extension = "telem";
-                               CaptureTelemetry(eechunk);
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_TELESCIENCE:
-                               extension = "science";
-                               CaptureTeleScience(eechunk);
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_TELEMEGA:
-                               extension = "mega";
-                               CaptureMega(eechunk);
-                               break;
-                       case AltosLib.AO_LOG_FORMAT_MINI:
-                               extension = "mini";
-                               CaptureMini(eechunk);
-                               break;
-                       }
+                       CaptureEeprom (eechunk, log_format);
                }
                CheckFile(true);
                if (eeprom_file != null) {
@@ -480,7 +239,10 @@ public class AltosEepromDownload implements Runnable {
                                     serial_line.device.toShortString(),
                                     JOptionPane.ERROR_MESSAGE);
                } catch (InterruptedException ie) {
-                       System.out.printf("download interrupted\n");
+                       show_message(String.format("Connection to \"%s\" interrupted",
+                                                  serial_line.device.toShortString()),
+                                    "Connection Interrupted",
+                                    JOptionPane.ERROR_MESSAGE);
                } catch (TimeoutException te) {
                        show_message(String.format("Connection to \"%s\" failed",
                                                   serial_line.device.toShortString()),
index a63d173de36f275dc69bdf3b7b326cbd95e7c39d..258c421a5b4b67c3e7d9f6e8755ab910115af0fd 100644 (file)
@@ -21,7 +21,7 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 /*
  * Temporary structure to hold the list of stored flights;
index 7a7211960b02545b197b238ebb9229a4c20f2df4..b2d8a130fba1bbe11db4c1ec0a349c726e7e4e34 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.event.*;
 import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosEepromManage implements ActionListener {
index a451aa3afbbe8b88793f77675e15dc1ed8b1cbe9..8f86eebff55436ec04e8cf7bfbb4349af0b2bf07 100644 (file)
@@ -21,7 +21,7 @@ import javax.swing.*;
 import javax.swing.border.*;
 import java.awt.*;
 import java.awt.event.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 class AltosEepromItem implements ActionListener {
index f4e522181b8f95419d0094f0881cb84a72b22f02..6eccface19815f29c00a2ef4ddd366d3545aee0e 100644 (file)
@@ -23,7 +23,7 @@ import javax.swing.*;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import java.io.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosFlashUI
index 4f4c158e8e08aad3105165ca36b5865cde53163a..289ddd01b66ac9a87bd4d351c638f38e2c59bfb3 100644 (file)
@@ -17,7 +17,7 @@
 
 package altosui;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public interface AltosFlightDisplay {
        void reset();
index dee31a8d3bcf6f8d3005803b110ead9cb6595236..11a3f1a95614029008db612121b670a1919263d9 100644 (file)
 package altosui;
 
 import java.io.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosFlightStats {
        double          max_height;
        double          max_speed;
        double          max_acceleration;
-       double[]        state_accel_speed = new double[Altos.ao_flight_invalid + 1];
-       double[]        state_baro_speed = new double[Altos.ao_flight_invalid + 1];
+       double[]        state_speed = new double[Altos.ao_flight_invalid + 1];
        double[]        state_accel = new double[Altos.ao_flight_invalid + 1];
        int[]           state_count = new int[Altos.ao_flight_invalid + 1];
        double[]        state_start = new double[Altos.ao_flight_invalid + 1];
@@ -40,16 +39,19 @@ public class AltosFlightStats {
        boolean         has_other_adc;
        boolean         has_rssi;
 
-       double landed_time(AltosRecordIterable iterable) {
-               AltosState      state = null;
-               for (AltosRecord record : iterable) {
-                       state = new AltosState(record, state);
+       double landed_time(AltosStateIterable states) {
+               AltosState state = null;
 
+               for (AltosState s : states) {
+                       state = s;
                        if (state.state == Altos.ao_flight_landed)
                                break;
                }
 
-               double  landed_height = state.height;
+               if (state == null)
+                       return 0;
+
+               double  landed_height = state.height();
 
                state = null;
 
@@ -57,13 +59,13 @@ public class AltosFlightStats {
 
                double  landed_time = -1000;
 
-               for (AltosRecord record : iterable) {
-                       state = new AltosState(record, state);
+               for (AltosState s : states) {
+                       state = s;
 
-                       if (state.height > landed_height + 10) {
+                       if (state.height() > landed_height + 10) {
                                above = true;
                        } else {
-                               if (above && state.height < landed_height + 2) {
+                               if (above && state.height() < landed_height + 2) {
                                        above = false;
                                        landed_time = state.time;
                                }
@@ -74,81 +76,71 @@ public class AltosFlightStats {
                return landed_time;
        }
 
-       double boost_time(AltosRecordIterable iterable) {
-               double boost_time = -1000;
-
-               AltosState state = null;
+       double boost_time(AltosStateIterable states) {
+               double boost_time = AltosLib.MISSING;
+               AltosState      state = null;
 
-               for (AltosRecord record : iterable) {
-                       state = new AltosState(record, state);
-                       
-                       if (state.acceleration < 1)
+               for (AltosState s : states) {
+                       state = s;
+                       if (state.acceleration() < 1)
                                boost_time = state.time;
                        if (state.state >= Altos.ao_flight_boost)
                                break;
                }
-               if (boost_time == -1000)
+               if (state == null)
+                       return 0;
+
+               if (boost_time == AltosLib.MISSING)
                        boost_time = state.time;
                return boost_time;
        }
 
 
-       public AltosFlightStats(AltosRecordIterable iterable) throws InterruptedException, IOException {
-               AltosState      state = null;
-               AltosState      new_state = null;
-               double          boost_time = boost_time(iterable);
+       public AltosFlightStats(AltosStateIterable states) throws InterruptedException, IOException {
+               double          boost_time = boost_time(states);
                double          end_time = 0;
-               double          landed_time = landed_time(iterable);
+               double          landed_time = landed_time(states);
 
-               year = month = day = -1;
-               hour = minute = second = -1;
-               serial = flight = -1;
-               lat = lon = -1;
+               year = month = day = AltosLib.MISSING;
+               hour = minute = second = AltosLib.MISSING;
+               serial = flight = AltosLib.MISSING;
+               lat = lon = AltosLib.MISSING;
                has_gps = false;
                has_other_adc = false;
                has_rssi = false;
-               for (AltosRecord record : iterable) {
-                       if (serial < 0)
-                               serial = record.serial;
-                       if ((record.seen & AltosRecord.seen_flight) != 0 && flight < 0)
-                               flight = record.flight;
-                       if ((record.seen & AltosRecord.seen_temp_volt) != 0)
+               for (AltosState state : states) {
+                       if (serial == AltosLib.MISSING && state.serial != AltosLib.MISSING)
+                               serial = state.serial;
+                       if (flight == AltosLib.MISSING && state.flight != AltosLib.MISSING)
+                               flight = state.flight;
+                       if (state.battery_voltage != AltosLib.MISSING)
                                has_other_adc = true;
-                       if (record.rssi != 0)
+                       if (state.rssi != AltosLib.MISSING)
                                has_rssi = true;
-                       new_state = new AltosState(record, state);
-                       end_time = new_state.time;
-                       state = new_state;
+                       end_time = state.time;
                        if (state.time >= boost_time && state.state < Altos.ao_flight_boost)
                                state.state = Altos.ao_flight_boost;
                        if (state.time >= landed_time && state.state < Altos.ao_flight_landed)
                                state.state = Altos.ao_flight_landed;
+                       if (state.gps != null && state.gps.locked) {
+                               year = state.gps.year;
+                               month = state.gps.month;
+                               day = state.gps.day;
+                               hour = state.gps.hour;
+                               minute = state.gps.minute;
+                               second = state.gps.second;
+                       }
                        if (0 <= state.state && state.state < Altos.ao_flight_invalid) {
-                               if (state.state >= Altos.ao_flight_boost) {
-                                       if (state.gps != null && state.gps.locked &&
-                                           year < 0) {
-                                               year = state.gps.year;
-                                               month = state.gps.month;
-                                               day = state.gps.day;
-                                               hour = state.gps.hour;
-                                               minute = state.gps.minute;
-                                               second = state.gps.second;
-                                       }
-                               }
-                               state_accel[state.state] += state.acceleration;
-                               state_accel_speed[state.state] += state.accel_speed;
-                               state_baro_speed[state.state] += state.baro_speed;
+                               state_accel[state.state] += state.acceleration();
+                               state_speed[state.state] += state.speed();
                                state_count[state.state]++;
                                if (state_start[state.state] == 0.0)
                                        state_start[state.state] = state.time;
                                if (state_end[state.state] < state.time)
                                        state_end[state.state] = state.time;
-                               max_height = state.max_height;
-                               if (state.max_accel_speed != 0)
-                                       max_speed = state.max_accel_speed;
-                               else
-                                       max_speed = state.max_baro_speed;
-                               max_acceleration = state.max_acceleration;
+                               max_height = state.max_height();
+                               max_speed = state.max_speed();
+                               max_acceleration = state.max_acceleration();
                        }
                        if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) {
                                if (state.state <= Altos.ao_flight_pad) {
@@ -162,8 +154,7 @@ public class AltosFlightStats {
                }
                for (int s = Altos.ao_flight_startup; s <= Altos.ao_flight_landed; s++) {
                        if (state_count[s] > 0) {
-                               state_accel_speed[s] /= state_count[s];
-                               state_baro_speed[s] /= state_count[s];
+                               state_speed[s] /= state_count[s];
                                state_accel[s] /= state_count[s];
                        }
                        if (state_start[s] == 0)
index a35b5f637e71e1daf269d824d2a4bd5673ef1867..db875b3bb70fac4bc9cc10a8e14fedfa24725fe9 100644 (file)
@@ -19,7 +19,7 @@ package altosui;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosFlightStatsTable extends JComponent {
        GridBagLayout   layout;
@@ -76,15 +76,15 @@ public class AltosFlightStatsTable extends JComponent {
                int y = 0;
                new FlightStat(layout, y++, "Serial", String.format("%d", stats.serial));
                new FlightStat(layout, y++, "Flight", String.format("%d", stats.flight));
-               if (stats.year > 0 && stats.hour > 0)
+               if (stats.year != AltosLib.MISSING && stats.hour != AltosLib.MISSING)
                        new FlightStat(layout, y++, "Date/Time",
                                       String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day),
                                       String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second));
                else {
-                       if (stats.year > 0)
+                       if (stats.year != AltosLib.MISSING)
                                new FlightStat(layout, y++, "Date",
                                               String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day));
-                       if (stats.hour > 0)
+                       if (stats.hour != AltosLib.MISSING)
                                new FlightStat(layout, y++, "Time",
                                               String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second));
                }
@@ -95,7 +95,7 @@ public class AltosFlightStatsTable extends JComponent {
                               String.format("%5.0f m/s", stats.max_speed),
                               String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)),
                               String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed)));
-               if (stats.max_acceleration != AltosRecord.MISSING) {
+               if (stats.max_acceleration != AltosLib.MISSING) {
                        new FlightStat(layout, y++, "Maximum boost acceleration",
                                       String.format("%5.0f m/s²", stats.max_acceleration),
                                       String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_acceleration)),
@@ -106,11 +106,11 @@ public class AltosFlightStatsTable extends JComponent {
                                       String.format("%5.0f G", AltosConvert.meters_to_g(stats.state_accel[Altos.ao_flight_boost])));
                }
                new FlightStat(layout, y++, "Drogue descent rate",
-                              String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_drogue]),
-                              String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_drogue])));
+                              String.format("%5.0f m/s", stats.state_speed[Altos.ao_flight_drogue]),
+                              String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_drogue])));
                new FlightStat(layout, y++, "Main descent rate",
-                              String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_main]),
-                              String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main])));
+                              String.format("%5.0f m/s", stats.state_speed[Altos.ao_flight_main]),
+                              String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_main])));
                new FlightStat(layout, y++, "Ascent time",
                               String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_boost] - stats.state_start[AltosLib.ao_flight_boost],
                                             AltosLib.state_name(Altos.ao_flight_boost)),
index d2910414dec132af46e4fecb4e168052068073af..9d575e4c8897ebb8c14e651ca94e5c64712348d7 100644 (file)
@@ -19,7 +19,7 @@ package altosui;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosFlightStatus extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
@@ -65,7 +65,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
        class Call extends FlightValue {
                void show(AltosState state, AltosListenerState listener_state) {
-                       value.setText(state.data.callsign);
+                       value.setText(state.callsign);
                }
                public Call (GridBagLayout layout, int x) {
                        super (layout, x, "Callsign");
@@ -76,10 +76,10 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
        class Serial extends FlightValue {
                void show(AltosState state, AltosListenerState listener_state) {
-                       if (state.data.serial == AltosRecord.MISSING)
+                       if (state.serial == AltosLib.MISSING)
                                value.setText("none");
                        else
-                               value.setText(String.format("%d", state.data.serial));
+                               value.setText(String.format("%d", state.serial));
                }
                public Serial (GridBagLayout layout, int x) {
                        super (layout, x, "Serial");
@@ -90,10 +90,10 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
        class Flight extends FlightValue {
                void show(AltosState state, AltosListenerState listener_state) {
-                       if (state.data.flight == AltosRecord.MISSING)
+                       if (state.flight == AltosLib.MISSING)
                                value.setText("none");
                        else
-                               value.setText(String.format("%d", state.data.flight));
+                               value.setText(String.format("%d", state.flight));
                }
                public Flight (GridBagLayout layout, int x) {
                        super (layout, x, "Flight");
@@ -104,7 +104,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
        class FlightState extends FlightValue {
                void show(AltosState state, AltosListenerState listener_state) {
-                       value.setText(state.data.state());
+                       value.setText(state.state_name());
                }
                public FlightState (GridBagLayout layout, int x) {
                        super (layout, x, "State");
@@ -115,7 +115,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
        class RSSI extends FlightValue {
                void show(AltosState state, AltosListenerState listener_state) {
-                       value.setText(String.format("%d", state.data.rssi));
+                       value.setText(String.format("%d", state.rssi()));
                }
                public RSSI (GridBagLayout layout, int x) {
                        super (layout, x, "RSSI");
@@ -126,7 +126,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
        class LastPacket extends FlightValue {
                void show(AltosState state, AltosListenerState listener_state) {
-                       long secs = (System.currentTimeMillis() - state.report_time + 500) / 1000;
+                       long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
                        value.setText(String.format("%d", secs));
                }
                public LastPacket(GridBagLayout layout, int x) {
index 6a327841bf10553b63e8ecaab258a3af83394580..08154fdadd1cc76cd052dd4b52a04fe4ecebda70 100644 (file)
@@ -27,7 +27,7 @@ import java.util.*;
 import java.text.*;
 import java.util.prefs.*;
 import java.util.concurrent.LinkedBlockingQueue;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosFlightStatusTableModel extends AbstractTableModel {
        private String[] columnNames = {
index 962a08f7821d3b88df57130eebd4679983ef9d6e..7821a77709a90fd32b9f58621998334fd5ceb947 100644 (file)
@@ -18,7 +18,7 @@
 package altosui;
 
 import java.awt.event.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosFlightStatusUpdate implements ActionListener {
 
index 6d010d23c14129ae53bc42ddc5149757d51e8db7..c151177e73e1915fae355b66fc9939ff33507b56 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener {
@@ -102,7 +102,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A
                status_update.saved_state = state;
 
                if (state == null)
-                       state = new AltosState(new AltosRecord());
+                       state = new AltosState();
 
                pad.show(state, listener_state);
 
@@ -130,7 +130,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A
                flightStatus.show(state, listener_state);
                flightInfo.show(state, listener_state);
 
-               if (state.data.companion != null) {
+               if (state.companion != null) {
                        if (!has_companion) {
                                pane.add("Companion", companion);
                                has_companion= true;
index 7464ac3ee5f244c67e7fec24ca535a2231ea8c5c..917ac364b7a09a8925e575172179fc1d641085c2 100644 (file)
@@ -18,7 +18,7 @@
 package altosui;
 
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosFreqList extends JComboBox {
index a73e3fd8ee2837e67df4e23e02ba86543afb6386..e6cd7bd840c301683e0720ee1c0fcd8446225489 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 import org.jfree.ui.*;
index 7454f447948e897b2a468af31820f0ee42df8593..d8191f5d35199ab378188c5e071885031db2d47e 100644 (file)
@@ -18,7 +18,7 @@
 package altosui;
 
 import org.altusmetrum.altosuilib_1.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosGraphDataPoint implements AltosUIDataPoint {
 
@@ -42,37 +42,38 @@ public class AltosGraphDataPoint implements AltosUIDataPoint {
        public static final int data_pressure = 15;
 
        public double x() throws AltosUIDataMissing {
-               if (state.data.time < -2)
+               double  time = state.time_since_boost();
+               if (time < -2)
                        throw new AltosUIDataMissing(-1);
-               return state.data.time;
+               return time;
        }
 
        public double y(int index) throws AltosUIDataMissing {
-               double y = AltosRecord.MISSING;
+               double y = AltosLib.MISSING;
                switch (index) {
                case data_height:
-                       y = state.height;
+                       y = state.height();
                        break;
                case data_speed:
                        y = state.speed();
                        break;
                case data_accel:
-                       y = state.acceleration;
+                       y = state.acceleration();
                        break;
                case data_temp:
                        y = state.temperature;
                        break;
                case data_battery_voltage:
-                       y = state.battery;
+                       y = state.battery_voltage;
                        break;
                case data_drogue_voltage:
-                       y = state.drogue_sense;
+                       y = state.apogee_voltage;
                        break;
                case data_main_voltage:
-                       y = state.main_sense;
+                       y = state.main_voltage;
                        break;
                case data_rssi:
-                       y = state.data.rssi;
+                       y = state.rssi;
                        break;
                case data_gps_height:
                        y = state.gps_height;
@@ -96,17 +97,17 @@ public class AltosGraphDataPoint implements AltosUIDataPoint {
                                y = state.from_pad.distance;
                        break;
                case data_pressure:
-                       y = state.pressure;
+                       y = state.pressure();
                        break;
                }
-               if (y == AltosRecord.MISSING)
+               if (y == AltosLib.MISSING)
                        throw new AltosUIDataMissing(index);
                return y;
        }
 
        public int id(int index) {
                if (index == data_state) {
-                       int s = state.data.state;
+                       int s = state.state;
                        if (s < Altos.ao_flight_boost || s > Altos.ao_flight_landed)
                                return -1;
                        return s;
@@ -116,7 +117,7 @@ public class AltosGraphDataPoint implements AltosUIDataPoint {
 
        public String id_name(int index) {
                if (index == data_state)
-                       return state.data.state();
+                       return state.state_name();
                return "";
        }
 
index dc047e9aeebb5a0bd4c8fdb9ba2c89bf5103908d..4e6c46d1605a3d2bd840792a6cc447c4b10adae3 100644 (file)
@@ -20,39 +20,36 @@ package altosui;
 import java.lang.*;
 import java.io.*;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 class AltosGraphIterator implements Iterator<AltosUIDataPoint> {
        AltosGraphDataSet       dataSet;
-       Iterator<AltosRecord>   iterator;
-
-       AltosState      state;
+       Iterator<AltosState>    iterator;
 
        public boolean hasNext() {
                return iterator.hasNext();
        }
 
        public AltosUIDataPoint next() {
-               state = new AltosState(iterator.next(), state);
+               AltosState      state = iterator.next();
 
-               if ((state.data.seen & AltosRecord.seen_flight) != 0) {
-                       if (dataSet.callsign == null && state.data.callsign != null)
-                               dataSet.callsign = state.data.callsign;
+               if (state.flight != AltosLib.MISSING) {
+                       if (dataSet.callsign == null && state.callsign != null)
+                               dataSet.callsign = state.callsign;
 
-                       if (dataSet.serial == 0 && state.data.serial != 0)
-                               dataSet.serial = state.data.serial;
+                       if (dataSet.serial == 0 && state.serial != 0)
+                               dataSet.serial = state.serial;
 
-                       if (dataSet.flight == 0 && state.data.flight != 0)
-                               dataSet.flight = state.data.flight;
+                       if (dataSet.flight == 0 && state.flight != 0)
+                               dataSet.flight = state.flight;
                }
 
                return new AltosGraphDataPoint(state);
        }
 
-       public AltosGraphIterator (Iterator<AltosRecord> iterator, AltosGraphDataSet dataSet) {
+       public AltosGraphIterator (Iterator<AltosState> iterator, AltosGraphDataSet dataSet) {
                this.iterator = iterator;
-               this.state = null;
                this.dataSet = dataSet;
        }
 
@@ -64,7 +61,7 @@ class AltosGraphIterable implements Iterable<AltosUIDataPoint> {
        AltosGraphDataSet       dataSet;
 
        public Iterator<AltosUIDataPoint> iterator() {
-               return new AltosGraphIterator(dataSet.records.iterator(), dataSet);
+               return new AltosGraphIterator(dataSet.states.iterator(), dataSet);
        }
 
        public AltosGraphIterable(AltosGraphDataSet dataSet) {
@@ -76,7 +73,7 @@ public class AltosGraphDataSet implements AltosUIDataSet {
        String                  callsign;
        int                     serial;
        int                     flight;
-       AltosRecordIterable     records;
+       AltosStateIterable      states;
 
        public String name() {
                if (callsign != null)
@@ -89,8 +86,8 @@ public class AltosGraphDataSet implements AltosUIDataSet {
                return new AltosGraphIterable(this);
        }
 
-       public AltosGraphDataSet (AltosRecordIterable records) {
-               this.records = records;
+       public AltosGraphDataSet (AltosStateIterable states) {
+               this.states = states;
                this.callsign = null;
                this.serial = 0;
                this.flight = 0;
index d8b8f6dd282d41b1bbce8b4724f7dac3212714a5..c42f7b5f89d4f346517fad948c5b3ec6a86229d4 100644 (file)
@@ -9,7 +9,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 import org.jfree.chart.ChartPanel;
@@ -28,10 +28,9 @@ public class AltosGraphUI extends AltosUIFrame
        AltosFlightStatsTable   statsTable;
        boolean                 has_gps;
 
-       void fill_map(AltosRecordIterable records) {
+       void fill_map(AltosStateIterable states) {
                boolean         any_gps = false;
-               for (AltosRecord record : records) {
-                       state = new AltosState(record, state);
+               for (AltosState state : states) {
                        if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) {
                                if (map == null)
                                        map = new AltosSiteMap();
@@ -41,7 +40,7 @@ public class AltosGraphUI extends AltosUIFrame
                }
        }
 
-       AltosGraphUI(AltosRecordIterable records, File file) throws InterruptedException, IOException {
+       AltosGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException {
                super(file.getName());
                state = null;
 
@@ -49,8 +48,8 @@ public class AltosGraphUI extends AltosUIFrame
 
                enable = new AltosUIEnable();
 
-               stats = new AltosFlightStats(records);
-               graphDataSet = new AltosGraphDataSet(records);
+               stats = new AltosFlightStats(states);
+               graphDataSet = new AltosGraphDataSet(states);
 
                graph = new AltosGraph(enable, stats, graphDataSet);
 
@@ -61,7 +60,7 @@ public class AltosGraphUI extends AltosUIFrame
                pane.add("Flight Statistics", statsTable);
 
                has_gps = false;
-               fill_map(records);
+               fill_map(states);
                if (has_gps)
                        pane.add("Map", map);
 
index bbab017f1c525779c622e1623f1db541c8d72fba..f4e16243cd4b05e1cbe66c8623a8dd7f1e5d05b2 100644 (file)
@@ -23,7 +23,7 @@ import javax.swing.*;
 import javax.swing.event.*;
 import java.io.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener, DocumentListener {
@@ -65,13 +65,13 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl
 
        public void show(AltosState state, AltosListenerState listener_state) {
                status_update.saved_state = state;
-               try {
+//             try {
                        pad.show(state, listener_state);
                        flightStatus.show(state, listener_state);
                        flightInfo.show(state, listener_state);
-               } catch (Exception e) {
-                       System.out.print("Show exception" + e);
-               }
+//             } catch (Exception e) {
+//                     System.out.print("Show exception " + e);
+//             }
        }
 
        public void update(final AltosState state, final AltosListenerState listener_state) {
index 14d4eebcbaf210013215e704ae3b7849613a2161..c8024aaedacf2773338179443abdd98b6c753008 100644 (file)
@@ -23,7 +23,7 @@ import javax.swing.*;
 import java.io.*;
 import java.text.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosIgniteUI
index 3d16faf2cbf369f368563f8ce64dbd006015ccb5..feafed21f32a852e0ecf3d8cec954fe65a97ed21 100644 (file)
@@ -20,7 +20,7 @@ package altosui;
 import java.awt.*;
 import javax.swing.*;
 import javax.swing.table.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosInfoTable extends JTable {
        private AltosFlightInfoTableModel model;
@@ -107,35 +107,37 @@ public class AltosInfoTable extends JTable {
        public void show(AltosState state, AltosListenerState listener_state) {
                info_reset();
                if (state != null) {
-                       if (state.altitude != AltosRecord.MISSING)
-                               info_add_row(0, "Altitude", "%6.0f    m", state.altitude);
-                       if (state.ground_altitude != AltosRecord.MISSING)
-                               info_add_row(0, "Pad altitude", "%6.0f    m", state.ground_altitude);
-                       if (state.height != AltosRecord.MISSING)
-                               info_add_row(0, "Height", "%6.0f    m", state.height);
-                       if (state.height != AltosRecord.MISSING)
-                               info_add_row(0, "Max height", "%6.0f    m", state.max_height);
-                       if (state.acceleration != AltosRecord.MISSING)
-                               info_add_row(0, "Acceleration", "%8.1f  m/s²", state.acceleration);
-                       if (state.acceleration != AltosRecord.MISSING)
-                               info_add_row(0, "Max acceleration", "%8.1f  m/s²", state.max_acceleration);
-                       if (state.speed() != AltosRecord.MISSING)
+                       if (state.device_type != AltosLib.MISSING)
+                               info_add_row(0, "Device", "%s", AltosLib.product_name(state.device_type));
+                       if (state.altitude() != AltosLib.MISSING)
+                               info_add_row(0, "Altitude", "%6.0f    m", state.altitude());
+                       if (state.ground_altitude() != AltosLib.MISSING)
+                               info_add_row(0, "Pad altitude", "%6.0f    m", state.ground_altitude());
+                       if (state.height() != AltosLib.MISSING)
+                               info_add_row(0, "Height", "%6.0f    m", state.height());
+                       if (state.max_height() != AltosLib.MISSING)
+                               info_add_row(0, "Max height", "%6.0f    m", state.max_height());
+                       if (state.acceleration() != AltosLib.MISSING)
+                               info_add_row(0, "Acceleration", "%8.1f  m/s²", state.acceleration());
+                       if (state.max_acceleration() != AltosLib.MISSING)
+                               info_add_row(0, "Max acceleration", "%8.1f  m/s²", state.max_acceleration());
+                       if (state.speed() != AltosLib.MISSING)
                                info_add_row(0, "Speed", "%8.1f  m/s", state.speed());
-                       if (state.speed() != AltosRecord.MISSING)
-                               info_add_row(0, "Max Speed", "%8.1f  m/s", state.max_accel_speed);
-                       if (state.temperature != AltosRecord.MISSING)
+                       if (state.max_speed() != AltosLib.MISSING)
+                               info_add_row(0, "Max Speed", "%8.1f  m/s", state.max_speed());
+                       if (state.temperature != AltosLib.MISSING)
                                info_add_row(0, "Temperature", "%9.2f °C", state.temperature);
-                       if (state.battery != AltosRecord.MISSING)
-                               info_add_row(0, "Battery", "%9.2f V", state.battery);
-                       if (state.drogue_sense != AltosRecord.MISSING)
-                               info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense);
-                       if (state.main_sense != AltosRecord.MISSING)
-                               info_add_row(0, "Main", "%9.2f V", state.main_sense);
+                       if (state.battery_voltage != AltosLib.MISSING)
+                               info_add_row(0, "Battery", "%9.2f V", state.battery_voltage);
+                       if (state.apogee_voltage != AltosLib.MISSING)
+                               info_add_row(0, "Drogue", "%9.2f V", state.apogee_voltage);
+                       if (state.main_voltage != AltosLib.MISSING)
+                               info_add_row(0, "Main", "%9.2f V", state.main_voltage);
                }
                if (listener_state != null) {
                        info_add_row(0, "CRC Errors", "%6d", listener_state.crc_errors);
 
-                       if (listener_state.battery != AltosRecord.MISSING)
+                       if (listener_state.battery != AltosLib.MISSING)
                                info_add_row(0, "Receiver Battery", "%9.2f", listener_state.battery);
                }
 
@@ -148,17 +150,21 @@ public class AltosInfoTable extends JTable {
                                else
                                        info_add_row(1, "GPS state", "wait (%d)",
                                                     state.gps_waiting);
-                               if (state.data.gps.locked)
+                               if (state.gps.locked)
                                        info_add_row(1, "GPS", "   locked");
-                               else if (state.data.gps.connected)
+                               else if (state.gps.connected)
                                        info_add_row(1, "GPS", " unlocked");
                                else
                                        info_add_row(1, "GPS", "  missing");
-                               info_add_row(1, "Satellites", "%6d", state.data.gps.nsat);
-                               info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S');
-                               info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W');
-                               info_add_row(1, "GPS altitude", "%6d", state.gps.alt);
-                               info_add_row(1, "GPS height", "%6.0f", state.gps_height);
+                               info_add_row(1, "Satellites", "%6d", state.gps.nsat);
+                               if (state.gps.lat != AltosLib.MISSING)
+                                       info_add_deg(1, "Latitude", state.gps.lat, 'N', 'S');
+                               if (state.gps.lon != AltosLib.MISSING)
+                                       info_add_deg(1, "Longitude", state.gps.lon, 'E', 'W');
+                               if (state.gps.alt != AltosLib.MISSING)
+                                       info_add_row(1, "GPS altitude", "%8.1f", state.gps.alt);
+                               if (state.gps_height != AltosLib.MISSING)
+                                       info_add_row(1, "GPS height", "%8.1f", state.gps_height);
 
                                /* The SkyTraq GPS doesn't report these values */
                                /*
@@ -195,14 +201,16 @@ public class AltosInfoTable extends JTable {
                                        info_add_deg(1, "Pad longitude", state.pad_lon, 'E', 'W');
                                        info_add_row(1, "Pad GPS alt", "%6.0f m", state.pad_alt);
                                }
-                               info_add_row(1, "GPS date", "%04d-%02d-%02d",
-                                            state.gps.year,
-                                            state.gps.month,
-                                            state.gps.day);
-                               info_add_row(1, "GPS time", "  %02d:%02d:%02d",
-                                            state.gps.hour,
-                                            state.gps.minute,
-                                            state.gps.second);
+                               if (state.gps.year != AltosLib.MISSING) 
+                                       info_add_row(1, "GPS date", "%04d-%02d-%02d",
+                                                    state.gps.year,
+                                                    state.gps.month,
+                                                    state.gps.day);
+                               if (state.gps.hour != AltosLib.MISSING)
+                                       info_add_row(1, "GPS time", "  %02d:%02d:%02d",
+                                                    state.gps.hour,
+                                                    state.gps.minute,
+                                                    state.gps.second);
                                //int   nsat_vis = 0;
                                int     c;
 
index 140f3f0766b9bdb792a733c02d48dbf68f3fc869..fbb0ece41867319c95f15a3b5cf38fff9d2350f6 100644 (file)
 package altosui;
 
 import java.io.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosKML implements AltosWriter {
 
        File                    name;
        PrintStream             out;
-       int                     state = -1;
-       AltosRecord             prev = null;
+       int                     flight_state = -1;
+       AltosState              prev = null;
        double                  gps_start_altitude;
 
        static final String[] kml_state_colors = {
@@ -83,7 +83,7 @@ public class AltosKML implements AltosWriter {
                "</Document>\n" +
                "</kml>\n";
 
-       void start (AltosRecord record) {
+       void start (AltosState record) {
                out.printf(kml_header_start, record.flight, record.serial);
                out.printf("Date:   %04d-%02d-%02d\n",
                           record.gps.year, record.gps.month, record.gps.day);
@@ -94,30 +94,30 @@ public class AltosKML implements AltosWriter {
 
        boolean started = false;
 
-       void state_start(AltosRecord record) {
-               String  state_name = Altos.state_name(record.state);
-               out.printf(kml_style_start, state_name, kml_state_colors[record.state]);
+       void state_start(AltosState state) {
+               String  state_name = Altos.state_name(state.state);
+               out.printf(kml_style_start, state_name, kml_state_colors[state.state]);
                out.printf("\tState: %s\n", state_name);
                out.printf("%s", kml_style_end);
                out.printf(kml_placemark_start, state_name, state_name);
        }
 
-       void state_end(AltosRecord record) {
+       void state_end(AltosState state) {
                out.printf("%s", kml_placemark_end);
        }
 
-       void coord(AltosRecord record) {
-               AltosGPS        gps = record.gps;
+       void coord(AltosState state) {
+               AltosGPS        gps = state.gps;
                double          altitude;
 
-               if (record.height() != AltosRecord.MISSING)
-                       altitude = record.height() + gps_start_altitude;
+               if (state.height() != AltosLib.MISSING)
+                       altitude = state.height() + gps_start_altitude;
                else
                        altitude = gps.alt;
                out.printf(kml_coord_fmt,
                           gps.lon, gps.lat,
                           altitude, (double) gps.alt,
-                          record.time, gps.nsat);
+                          state.time, gps.nsat);
        }
 
        void end() {
@@ -132,38 +132,40 @@ public class AltosKML implements AltosWriter {
                }
        }
 
-       public void write(AltosRecord record) {
-               AltosGPS        gps = record.gps;
+       public void write(AltosState state) {
+               AltosGPS        gps = state.gps;
 
                if (gps == null)
                        return;
 
-               if ((record.seen & (AltosRecord.seen_gps_lat)) == 0)
+               if (gps.lat == AltosLib.MISSING)
                        return;
-               if ((record.seen & (AltosRecord.seen_gps_lon)) == 0)
+               if (gps.lon == AltosLib.MISSING)
                        return;
                if (!started) {
-                       start(record);
+                       start(state);
                        started = true;
                        gps_start_altitude = gps.alt;
                }
-               if (prev != null && prev.gps_sequence == record.gps_sequence)
+               if (prev != null && prev.gps_sequence == state.gps_sequence)
                        return;
-               if (record.state != state) {
-                       state = record.state;
+               if (state.state != flight_state) {
+                       flight_state = state.state;
                        if (prev != null) {
-                               coord(record);
+                               coord(state);
                                state_end(prev);
                        }
-                       state_start(record);
+                       state_start(state);
                }
-               coord(record);
-               prev = record;
+               coord(state);
+               prev = state;
        }
 
-       public void write(AltosRecordIterable iterable) {
-               for (AltosRecord record : iterable)
-                       write(record);
+       public void write(AltosStateIterable states) {
+               for (AltosState state : states) {
+                       if ((state.set & AltosState.set_gps) != 0)
+                               write(state);
+               }
        }
 
        public AltosKML(File in_name) throws FileNotFoundException {
index 9dab52c436098b8ea0f2a8a90bd5a8829d9276d3..cc2053e0ca5fe7896557241f31e9dc0bb2854424 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.io.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener {
        GridBagLayout   layout;
@@ -103,7 +103,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
 
        class Lat extends LandedValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state.gps != null && state.gps.connected)
+                       show();
+                       if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
                                show(pos(state.gps.lat,"N", "S"));
                        else
                                show("???");
@@ -118,7 +119,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
        class Lon extends LandedValue {
                void show (AltosState state, AltosListenerState listener_state) {
                        show();
-                       if (state.gps != null && state.gps.connected)
+                       if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
                                show(pos(state.gps.lon,"E", "W"));
                        else
                                show("???");
@@ -162,7 +163,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
 
        class Height extends LandedValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.height, state.max_height);
+                       show(AltosConvert.height, state.max_height());
                }
                public Height (GridBagLayout layout, int y) {
                        super (layout, y, "Maximum Height");
@@ -184,7 +185,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
 
        class Accel extends LandedValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.accel, state.max_acceleration);
+                       show(AltosConvert.accel, state.max_acceleration());
                }
                public Accel (GridBagLayout layout, int y) {
                        super (layout, y, "Maximum Acceleration");
@@ -243,24 +244,18 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
                        if (file != null) {
                                String  filename = file.getName();
                                try {
-                                       AltosRecordIterable records = null;
+                                       AltosStateIterable states = null;
                                        if (filename.endsWith("eeprom")) {
                                                FileInputStream in = new FileInputStream(file);
-                                               records = new AltosEepromIterable(in);
+                                               states = new AltosEepromFile(in);
                                        } else if (filename.endsWith("telem")) {
                                                FileInputStream in = new FileInputStream(file);
-                                               records = new AltosTelemetryIterable(in);
-                                       } else if (filename.endsWith("mega")) {
-                                               FileInputStream in = new FileInputStream(file);
-                                               records = new AltosEepromMegaIterable(in);
-                                       } else if (filename.endsWith("mini")) {
-                                               FileInputStream in = new FileInputStream(file);
-                                               records = new AltosEepromMiniIterable(in);
+                                               states = new AltosTelemetryFile(in);
                                        } else {
                                                throw new FileNotFoundException(filename);
                                        }
                                        try {
-                                               new AltosGraphUI(records, file);
+                                               new AltosGraphUI(states, file);
                                        } catch (InterruptedException ie) {
                                        } catch (IOException ie) {
                                        }
index e2316a13c813a26fd248f5bb0737040391dbde0e..b35bd23a8626f14032344b671dcd91575a385c1a 100644 (file)
@@ -19,7 +19,7 @@ package altosui;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosPad extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
@@ -176,11 +176,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
 
        class Battery extends LaunchStatus {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state == null || state.battery == AltosRecord.MISSING)
+                       if (state == null || state.battery_voltage == AltosLib.MISSING)
                                hide();
                        else {
-                               show("%4.2f V", state.battery);
-                               lights.set(state.battery > 3.7);
+                               show("%4.2f V", state.battery_voltage);
+                               lights.set(state.battery_voltage > 3.7);
                        }
                }
                public Battery (GridBagLayout layout, int y) {
@@ -192,11 +192,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
 
        class Apogee extends LaunchStatus {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state == null || state.drogue_sense == AltosRecord.MISSING)
+                       if (state == null || state.apogee_voltage == AltosLib.MISSING)
                                hide();
                        else {
-                               show("%4.2f V", state.drogue_sense);
-                               lights.set(state.drogue_sense > 3.2);
+                               show("%4.2f V", state.apogee_voltage);
+                               lights.set(state.apogee_voltage > 3.7);
                        }
                }
                public Apogee (GridBagLayout layout, int y) {
@@ -208,11 +208,11 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
 
        class Main extends LaunchStatus {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state == null || state.main_sense == AltosRecord.MISSING)
+                       if (state == null || state.main_voltage == AltosLib.MISSING)
                                hide();
                        else {
-                               show("%4.2f V", state.main_sense);
-                               lights.set(state.main_sense > 3.2);
+                               show("%4.2f V", state.main_voltage);
+                               lights.set(state.main_voltage > 3.7);
                        }
                }
                public Main (GridBagLayout layout, int y) {
@@ -224,19 +224,19 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
 
        class LoggingReady extends LaunchStatus {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state == null || state.data.flight == AltosRecord.MISSING) {
+                       if (state == null || state.flight == AltosLib.MISSING) {
                                hide();
                        } else {
-                               if (state.data.flight != 0) {
-                                       if (state.data.state <= Altos.ao_flight_pad)
+                               if (state.flight != 0) {
+                                       if (state.state <= Altos.ao_flight_pad)
                                                show("Ready to record");
-                                       else if (state.data.state < Altos.ao_flight_landed)
+                                       else if (state.state < Altos.ao_flight_landed)
                                                show("Recording data");
                                        else
                                                show("Recorded data");
                                } else
                                        show("Storage full");
-                               lights.set(state.data.flight != 0);
+                               lights.set(state.flight != 0);
                        }
                }
                public LoggingReady (GridBagLayout layout, int y) {
@@ -283,7 +283,7 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
 
        class ReceiverBattery extends LaunchStatus {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (listener_state == null || listener_state.battery == AltosRecord.MISSING)
+                       if (listener_state == null || listener_state.battery == AltosLib.MISSING)
                                hide();
                        else {
                                show("%4.2f V", listener_state.battery);
@@ -310,17 +310,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
 
        class PadLat extends LaunchValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state == null || state.gps == null) {
-                               hide();
-                       } else {
-                               if (state.state < AltosLib.ao_flight_pad) {
-                                       show(pos(state.gps.lat,"N", "S"));
-                                       set_label("Latitude");
-                               } else { 
-                                       show(pos(state.pad_lat,"N", "S"));
-                                       set_label("Pad Latitude");
+                       double lat = AltosLib.MISSING;
+                       String label = null;
+
+                       if (state != null) {
+                               if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lat != AltosLib.MISSING) {
+                                       lat = state.gps.lat;
+                                       label = "Latitude";
+                               } else {
+                                       lat = state.pad_lat;
+                                       label = "Pad Latitude";
                                }
                        }
+                       if (lat != AltosLib.MISSING) {
+                               show(pos(lat,"N", "S"));
+                               set_label(label);
+                       } else
+                               hide();
                }
                public PadLat (GridBagLayout layout, int y) {
                        super (layout, y, "Pad Latitude");
@@ -331,17 +337,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
 
        class PadLon extends LaunchValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state == null || state.gps == null) {
-                               hide();
-                       } else {
-                               if (state.state < AltosLib.ao_flight_pad) {
-                                       show(pos(state.gps.lon,"E", "W"));
-                                       set_label("Longitude");
-                               } else { 
-                                       show(pos(state.pad_lon,"E", "W"));
-                                       set_label("Pad Longitude");
+                       double lon = AltosLib.MISSING;
+                       String label = null;
+
+                       if (state != null) {
+                               if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.lon != AltosLib.MISSING) {
+                                       lon = state.gps.lon;
+                                       label = "Longitude";
+                               } else {
+                                       lon = state.pad_lon;
+                                       label = "Pad Longitude";
                                }
                        }
+                       if (lon != AltosLib.MISSING) {
+                               show(pos(lon,"E", "W"));
+                               set_label(label);
+                       } else
+                               hide();
                }
                public PadLon (GridBagLayout layout, int y) {
                        super (layout, y, "Pad Longitude");
@@ -352,21 +364,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
 
        class PadAlt extends LaunchValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       if (state == null)
-                               hide();
-                       else {
-                               if (state.state < AltosLib.ao_flight_pad && state.gps != null) {
-                                       show("%4.0f m", state.gps.alt);
-                                       set_label("Altitude");
+                       double alt = AltosLib.MISSING;
+                       String label = null;
+
+                       if (state != null) {
+                               if (state.state < AltosLib.ao_flight_pad && state.gps != null && state.gps.alt != AltosLib.MISSING) {
+                                       alt = state.gps.alt;
+                                       label = "Altitude";
                                } else {
-                                       if (state.pad_alt == AltosRecord.MISSING)
-                                               hide();
-                                       else {
-                                               show("%4.0f m", state.pad_alt);
-                                               set_label("Pad Altitude");
-                                       }
+                                       alt = state.pad_alt;
+                                       label = "Pad Altitude";
                                }
                        }
+                       if (alt != AltosLib.MISSING) {
+                               show("%4.0f m", state.gps.alt);
+                               set_label(label);
+                       } else
+                               hide();
                }
                public PadAlt (GridBagLayout layout, int y) {
                        super (layout, y, "Pad Altitude");
index 909e72a013af68eb735297f9de2cd73fd2d02a6e..6f9d9dc6eb034a64a1e00898dc945796a28debb2 100644 (file)
@@ -20,7 +20,7 @@ package altosui;
 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosRomconfigUI
index 0c903873b45fd69a9a8268e4ac9dc7cfd6814737..a5ccb15aac379a6d6cb82dc8a0a4850b8eb567f0 100644 (file)
@@ -25,7 +25,7 @@ import java.io.*;
 import java.util.*;
 import java.text.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 class AltosScanResult {
@@ -184,13 +184,13 @@ public class AltosScanUI
                        try {
                                for (;;) {
                                        try {
-                                               AltosRecord     record = reader.read();
-                                               if (record == null)
+                                               AltosState      state = reader.read();
+                                               if (state == null)
                                                        continue;
-                                               if ((record.seen & AltosRecord.seen_flight) != 0) {
-                                                       final AltosScanResult   result = new AltosScanResult(record.callsign,
-                                                                                                    record.serial,
-                                                                                                    record.flight,
+                                               if (state.flight != AltosLib.MISSING) {
+                                                       final AltosScanResult   result = new AltosScanResult(state.callsign,
+                                                                                                    state.serial,
+                                                                                                    state.flight,
                                                                                                     frequencies[frequency_index],
                                                                                                     telemetry);
                                                        Runnable r = new Runnable() {
index e869f1ab1ac3688a9eaa6c964c6cd64729af2e0b..697ad539877f78bf19da5ff657c5805713e86024 100644 (file)
@@ -25,7 +25,7 @@ import java.io.*;
 import java.util.*;
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 import libaltosJNI.*;
index 23085f3ec5e270645b8c44760c34fb9202d61271..9491ce2be4b95c4ddf5f400beda942a23a1294bf 100644 (file)
@@ -23,7 +23,7 @@ import java.io.*;
 import java.lang.Math;
 import java.awt.geom.Point2D;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
@@ -271,27 +271,34 @@ public class AltosSiteMap extends JScrollPane implements AltosFlightDisplay {
        int last_state = -1;
 
        public void show(double lat, double lon) {
-               initMaps(lat, lon);
-               scrollRocketToVisible(pt(lat, lon));
+               System.out.printf ("show %g %g\n", lat, lon);
+               return;
+//             initMaps(lat, lon);
+//             scrollRocketToVisible(pt(lat, lon));
        }
        public void show(final AltosState state, final AltosListenerState listener_state) {
                // if insufficient gps data, nothing to update
-               if (!state.gps.locked && state.gps.nsat < 4)
+               AltosGPS        gps = state.gps;
+
+               if (gps == null)
+                       return;
+
+               if (!gps.locked && gps.nsat < 4)
                        return;
 
                if (!initialised) {
-                       if (state.pad_lat != 0 || state.pad_lon != 0) {
+                       if (state.pad_lat != AltosLib.MISSING && state.pad_lon != AltosLib.MISSING) {
                                initMaps(state.pad_lat, state.pad_lon);
                                initialised = true;
-                       } else if (state.gps.lat != 0 || state.gps.lon != 0) {
-                               initMaps(state.gps.lat, state.gps.lon);
+                       } else if (gps.lat != AltosLib.MISSING && gps.lon != AltosLib.MISSING) {
+                               initMaps(gps.lat, gps.lon);
                                initialised = true;
                        } else {
                                return;
                        }
                }
 
-               final Point2D.Double pt = pt(state.gps.lat, state.gps.lon);
+               final Point2D.Double pt = pt(gps.lat, gps.lon);
                if (last_pt == pt && last_state == state.state)
                        return;
 
index 365e4b6c3c36846a96e9fdc91ffed0fec6e072af..172e6397c6fe9875d193940932e6037c7f10e0f0 100644 (file)
@@ -22,7 +22,7 @@ import java.awt.image.*;
 import javax.swing.*;
 import java.awt.geom.Point2D;
 import java.awt.geom.Line2D;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosSiteMapTile extends JLayeredPane {
        JLabel mapLabel;
index 4362e36c88e1575ee5167790a0d3c26427dcfa09..9dad8718507dd384c07a59c5506fb4d8234b2cc4 100644 (file)
@@ -22,7 +22,7 @@ import java.awt.event.*;
 import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class AltosUI extends AltosUIFrame {
@@ -290,9 +290,9 @@ public class AltosUI extends AltosUIFrame {
                AltosDataChooser chooser = new AltosDataChooser(
                        AltosUI.this);
 
-               AltosRecordIterable iterable = chooser.runDialog();
-               if (iterable != null) {
-                       AltosFlightReader reader = new AltosReplayReader(iterable.iterator(),
+               Iterable<AltosState> states = chooser.runDialog();
+               if (states != null) {
+                       AltosFlightReader reader = new AltosReplayReader(states.iterator(),
                                                                         chooser.file());
                        new AltosFlightUI(voice, reader);
                }
@@ -312,10 +312,10 @@ public class AltosUI extends AltosUIFrame {
        private void ExportData() {
                AltosDataChooser chooser;
                chooser = new AltosDataChooser(this);
-               AltosRecordIterable record_reader = chooser.runDialog();
-               if (record_reader == null)
+               AltosStateIterable states = chooser.runDialog();
+               if (states == null)
                        return;
-               new AltosCSVUI(AltosUI.this, record_reader, chooser.file());
+               new AltosCSVUI(AltosUI.this, states, chooser.file());
        }
 
        /* Load a flight log CSV file and display a pretty graph.
@@ -324,11 +324,11 @@ public class AltosUI extends AltosUIFrame {
        private void GraphData() {
                AltosDataChooser chooser;
                chooser = new AltosDataChooser(this);
-               AltosRecordIterable record_reader = chooser.runDialog();
-               if (record_reader == null)
+               AltosStateIterable states = chooser.runDialog();
+               if (states == null)
                        return;
                try {
-                       new AltosGraphUI(record_reader, chooser.file());
+                       new AltosGraphUI(states, chooser.file());
                } catch (InterruptedException ie) {
                } catch (IOException ie) {
                }
@@ -345,19 +345,15 @@ public class AltosUI extends AltosUIFrame {
                }
        }
 
-       static AltosRecordIterable open_logfile(File file) {
+       static AltosStateIterable open_logfile(File file) {
                try {
                        FileInputStream in;
 
                        in = new FileInputStream(file);
-                       if (file.getName().endsWith("eeprom"))
-                               return new AltosEepromIterable(in);
-                       else if (file.getName().endsWith("mega"))
-                               return new AltosEepromMegaIterable(in);
-                       else if (file.getName().endsWith("mini"))
-                               return new AltosEepromMiniIterable(in);
+                       if (file.getName().endsWith("telem"))
+                               return new AltosTelemetryFile(in);
                        else
-                               return new AltosTelemetryIterable(in);
+                               return new AltosEepromFile(in);
                } catch (FileNotFoundException fe) {
                        System.out.printf("%s\n", fe.getMessage());
                        return null;
@@ -388,10 +384,11 @@ public class AltosUI extends AltosUIFrame {
        static final int process_graph = 3;
        static final int process_replay = 4;
        static final int process_summary = 5;
+       static final int process_cat = 6;
 
        static boolean process_csv(File input) {
-               AltosRecordIterable iterable = open_logfile(input);
-               if (iterable == null)
+               AltosStateIterable states = open_logfile(input);
+               if (states == null)
                        return false;
 
                File output = Altos.replace_extension(input,".csv");
@@ -403,15 +400,15 @@ public class AltosUI extends AltosUIFrame {
                        AltosWriter writer = open_csv(output);
                        if (writer == null)
                                return false;
-                       writer.write(iterable);
+                       writer.write(states);
                        writer.close();
                }
                return true;
        }
 
        static boolean process_kml(File input) {
-               AltosRecordIterable iterable = open_logfile(input);
-               if (iterable == null)
+               AltosStateIterable states = open_logfile(input);
+               if (states == null)
                        return false;
 
                File output = Altos.replace_extension(input,".kml");
@@ -423,13 +420,13 @@ public class AltosUI extends AltosUIFrame {
                        AltosWriter writer = open_kml(output);
                        if (writer == null)
                                return false;
-                       writer.write(iterable);
+                       writer.write(states);
                        writer.close();
                        return true;
                }
        }
 
-       static AltosRecordIterable record_iterable(File file) {
+       static AltosStateIterable record_iterable(File file) {
                FileInputStream in;
                try {
                        in = new FileInputStream(file);
@@ -437,25 +434,17 @@ public class AltosUI extends AltosUIFrame {
                        System.out.printf("Failed to open file '%s'\n", file);
                        return null;
                }
-               AltosRecordIterable recs;
-               //AltosReplayReader reader;
-               if (file.getName().endsWith("eeprom")) {
-                       recs = new AltosEepromIterable(in);
-               } else if (file.getName().endsWith("mega")) {
-                       recs = new AltosEepromMegaIterable(in);
-               } else if (file.getName().endsWith("mini")) {
-                       recs = new AltosEepromMiniIterable(in);
-               } else {
-                       recs = new AltosTelemetryIterable(in);
-               }
-               return recs;
+               if (file.getName().endsWith("telem"))
+                       return new AltosTelemetryFile(in);
+               else
+                       return new AltosEepromFile(in);
        }
 
        static AltosReplayReader replay_file(File file) {
-               AltosRecordIterable recs = record_iterable(file);
-               if (recs == null)
+               AltosStateIterable states = record_iterable(file);
+               if (states == null)
                        return null;
-               return new AltosReplayReader(recs.iterator(), file);
+               return new AltosReplayReader(states.iterator(), file);
        }
 
        static boolean process_replay(File file) {
@@ -468,11 +457,11 @@ public class AltosUI extends AltosUIFrame {
        }
 
        static boolean process_graph(File file) {
-               AltosRecordIterable recs = record_iterable(file);
-               if (recs == null)
+               AltosStateIterable states = record_iterable(file);
+               if (states == null)
                        return false;
                try {
-                       new AltosGraphUI(recs, file);
+                       new AltosGraphUI(states, file);
                        return true;
                } catch (InterruptedException ie) {
                } catch (IOException ie) {
@@ -481,11 +470,11 @@ public class AltosUI extends AltosUIFrame {
        }
        
        static boolean process_summary(File file) {
-               AltosRecordIterable iterable = record_iterable(file);
-               if (iterable == null)
+               AltosStateIterable states = record_iterable(file);
+               if (states == null)
                        return false;
                try {
-                       AltosFlightStats stats = new AltosFlightStats(iterable);
+                       AltosFlightStats stats = new AltosFlightStats(states);
                        if (stats.serial > 0)
                                System.out.printf("Serial:       %5d\n", stats.serial);
                        if (stats.flight > 0)
@@ -503,18 +492,18 @@ public class AltosUI extends AltosUIFrame {
                                          stats.max_speed,
                                          AltosConvert.meters_to_feet(stats.max_speed),
                                          AltosConvert.meters_to_mach(stats.max_speed));
-                       if (stats.max_acceleration != AltosRecord.MISSING) {
+                       if (stats.max_acceleration != AltosLib.MISSING) {
                                System.out.printf("Max accel:   %6.0f m/s² %6.0f ft/s² %6.2f g\n",
                                                  stats.max_acceleration,
                                                  AltosConvert.meters_to_feet(stats.max_acceleration),
                                                  AltosConvert.meters_to_g(stats.max_acceleration));
                        }
                        System.out.printf("Drogue rate: %6.0f m/s  %6.0f ft/s\n",
-                                         stats.state_baro_speed[Altos.ao_flight_drogue],
-                                         AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_drogue]));
+                                         stats.state_speed[Altos.ao_flight_drogue],
+                                         AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_drogue]));
                        System.out.printf("Main rate:   %6.0f m/s  %6.0f ft/s\n",
-                                         stats.state_baro_speed[Altos.ao_flight_main],
-                                         AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main]));
+                                         stats.state_speed[Altos.ao_flight_main],
+                                         AltosConvert.meters_to_feet(stats.state_speed[Altos.ao_flight_main]));
                        System.out.printf("Flight time: %6.0f s\n",
                                          stats.state_end[Altos.ao_flight_main] -
                                          stats.state_start[Altos.ao_flight_boost]);
@@ -525,6 +514,29 @@ public class AltosUI extends AltosUIFrame {
                return false;
        }
 
+       static boolean process_cat(File file) {
+               try {
+                       AltosStateIterable eef = record_iterable(file);
+
+                       System.out.printf ("process cat\n");
+                       for (AltosState state : eef) {
+                               System.out.printf ("tick %d state %d height %g\n",
+                                                  state.tick, state.state, state.height());
+                               if ((state.set & AltosState.set_gps) != 0)
+                                       System.out.printf ("time %g lat %g lon %g alt %g\n",
+                                                          state.time_since_boost(),
+                                                          state.gps.lat,
+                                                          state.gps.lon,
+                                                          state.gps.alt);
+                       }
+
+               } catch (Exception e) {
+                       System.out.printf("Failed to open file '%s'\n", file);
+                       return false;
+               }
+               return true;
+       }
+
        public static void help(int code) {
                System.out.printf("Usage: altosui [OPTION]... [FILE]...\n");
                System.out.printf("  Options:\n");
@@ -574,6 +586,8 @@ public class AltosUI extends AltosUIFrame {
                                        process = process_graph;
                                else if (args[i].equals("--summary"))
                                        process = process_summary;
+                               else if (args[i].equals("--cat"))
+                                       process = process_cat;
                                else if (args[i].startsWith("--"))
                                        help(1);
                                else {
@@ -600,6 +614,9 @@ public class AltosUI extends AltosUIFrame {
                                                if (!process_summary(file))
                                                        ++errors;
                                                break;
+                                       case process_cat:
+                                               if (!process_cat(file))
+                                                       ++errors;
                                        }
                                }
                        }
index 0dac9fc74f3dc3dad4c222824eeb10b0fd1be77f..fb5f8520a2c5039d2f8eef6f31b88009ecb79299 100644 (file)
@@ -19,7 +19,7 @@ package altosui;
 
 import java.io.File;
 import java.util.prefs.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import javax.swing.filechooser.FileSystemView;
 
 public class AltosUIPreferencesBackend implements AltosPreferencesBackend {
index 2f70b472b8906a2030873a01c0f5f512851dca70..d664d6e825fe28c556a9b0725952f18fd8686b70 100644 (file)
 
 package altosui;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 
 public interface AltosWriter {
 
-       public void write(AltosRecord record);
+       public void write(AltosState state);
 
-       public void write(AltosRecordIterable iterable);
+       public void write(AltosStateIterable states);
 
        public void close();
 }
index 867b03841bb4100cfaf4298377cb55fd52a990e4..a38cba63e0f7913ce52e7cab49ca1cb4bb88d45e 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import org.jfree.ui.*;
 import org.jfree.chart.*;
index 55486dea1214a064c5a1d013c2d639bd361fce71..84803c0e916770af06b0fc627e040806f826cfe5 100644 (file)
@@ -23,7 +23,7 @@ import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import org.jfree.ui.*;
 import org.jfree.chart.*;
index 5f3a2eef30a8064936f4abc763160cd4298124e6..ef0cc6772daa8e80e8f06d216ddfdabed136c5fe 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import org.jfree.ui.*;
 import org.jfree.chart.*;
index 8f0ce8011d6595d7812d9b9888cfd8f2f7cc3fb1..d826072fee0eacd24c07e320a52663c2fbd7781d 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import org.jfree.ui.*;
 import org.jfree.chart.*;
index 1b1214052f8f9598f46b8895456d6a3f95a23b76..9fcaf6d4d636979ef4272b1171ff0a982f75a758 100644 (file)
@@ -20,7 +20,7 @@ package org.altusmetrum.altosuilib_1;
 import java.awt.*;
 import libaltosJNI.*;
 
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosUILib extends AltosLib {
 
index 0949be6f94af3122ed0b31d2643eb16754b40c9f..e4262abd3c77c47818301bdae7e6cce3e07ad0a8 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import org.jfree.ui.*;
 import org.jfree.chart.*;
index 49321bcec358500809bb9edd1ccfbd2f4871d71a..fc14f24b5a3417190ad4445d36f50cb861e386d8 100644 (file)
@@ -21,7 +21,7 @@ import java.io.*;
 import java.util.*;
 import java.awt.Component;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 public class AltosUIPreferences extends AltosPreferences {
 
index 8a5386c3328c0dd0bd3e9c66f811cf2ad2b5801c..55da8d480c6af10fab511dcbb378e760b4d09b1f 100644 (file)
@@ -19,7 +19,7 @@ package org.altusmetrum.altosuilib_1;
 
 import java.io.File;
 import java.util.prefs.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import javax.swing.filechooser.FileSystemView;
 
 public class AltosUIPreferencesBackend implements AltosPreferencesBackend {
index ac09a3cc04c9b6541eb3d95e18684c0d7bca3013..ff430d1a1384820983d3c2cade3fe9364af71a57 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 
 import org.jfree.ui.*;
 import org.jfree.chart.*;
@@ -34,6 +34,20 @@ import org.jfree.chart.labels.*;
 import org.jfree.data.xy.*;
 import org.jfree.data.*;
 
+class AltosUITime extends AltosUnits {
+       public double value(double v) { return v; }
+       public String show_units() { return "s"; }
+       public String say_units() { return "seconds"; }
+
+       public int show_fraction(int width) {
+               if (width < 5)
+                       return 0;
+               return width - 5;
+       }
+
+       public int say_fraction() { return 0; }
+}
+
 public class AltosUISeries extends XYSeries implements AltosUIGrapher {
        AltosUIAxis     axis;
        String          label;
@@ -47,11 +61,12 @@ public class AltosUISeries extends XYSeries implements AltosUIGrapher {
                axis.set_units();
                StandardXYToolTipGenerator      ttg;
 
-               String  example = units.graph_format(4);
+               String  time_example = (new AltosUITime()).graph_format(7);
+               String  example = units.graph_format(7);
 
                ttg = new StandardXYToolTipGenerator(String.format("{1}s: {2}%s ({0})",
                                                                   units.show_units()),
-                                                    new java.text.DecimalFormat(example),
+                                                    new java.text.DecimalFormat(time_example),
                                                     new java.text.DecimalFormat(example));
                renderer.setBaseToolTipGenerator(ttg);
        }
index d2dae5a7a14068cbdcc5e21552bc64e61f79b31e..f1755b824f82ef233a89d6ec9312bdea623700c9 100644 (file)
@@ -194,6 +194,39 @@ main (int argc, char **argv)
                                                telem.mega_data.height);
 
                                        break;
+                               case AO_TELEMETRY_METRUM_SENSOR:
+                                       printf ("state %1d accel %5d pres %9d temp %6.2f acceleration %6.2f speed %6.2f height %5d v_batt %5d sense_a %5d sense_m %5d\n",
+                                               telem.metrum_sensor.state,
+                                               telem.metrum_sensor.accel,
+                                               telem.metrum_sensor.pres,
+                                               telem.metrum_sensor.temp / 100.0,
+                                               telem.metrum_sensor.acceleration / 16.0,
+                                               telem.metrum_sensor.speed / 16.0,
+                                               telem.metrum_sensor.height,
+                                               telem.metrum_sensor.v_batt,
+                                               telem.metrum_sensor.sense_a,
+                                               telem.metrum_sensor.sense_m);
+                                       break;
+                               case AO_TELEMETRY_METRUM_DATA:
+                                       printf ("ground_pres %9d ground_accel %5d accel_plus %5d accel_minus %5d\n",
+                                               telem.metrum_data.ground_pres,
+                                               telem.metrum_data.ground_accel,
+                                               telem.metrum_data.accel_plus_g,
+                                               telem.metrum_data.accel_minus_g);
+                                       break;
+                               case AO_TELEMETRY_MINI:
+                                       printf ("state %1d v_batt %5d sense_a %5d sense_m %5d pres %9d temp %6.2f acceleration %6.2f speed %6.2f height %5d ground_pres %9d\n",
+                                               telem.mini.state,
+                                               telem.mini.v_batt,
+                                               telem.mini.sense_a,
+                                               telem.mini.sense_m,
+                                               telem.mini.pres,
+                                               telem.mini.temp / 100.0,
+                                               telem.mini.acceleration / 16.0,
+                                               telem.mini.speed / 16.0,
+                                               telem.mini.height,
+                                               telem.mini.ground_pres);
+                                       break;
                                default:
                                        printf("\n");
                                }
index 9a5be49f9a76d2e9cd2122e951838cf9d5e2eed7..c28aceb895d2385eef28bceb8a0ae1514398a2d3 100644 (file)
@@ -201,6 +201,72 @@ struct ao_telemetry_mega_data {
        /* 32 */
 };
 
+#define AO_TELEMETRY_METRUM_SENSOR     0x0A
+
+struct ao_telemetry_metrum_sensor {
+       uint16_t        serial;         /*  0 */
+       uint16_t        tick;           /*  2 */
+       uint8_t         type;           /*  4 */
+
+       uint8_t         state;          /*  5 flight state */
+       int16_t         accel;          /*  6 Z axis */
+
+       int32_t         pres;           /*  8 Pa * 10 */
+       int16_t         temp;           /* 12 °C * 100 */
+
+       int16_t         acceleration;   /* 14 m/s² * 16 */
+       int16_t         speed;          /* 16 m/s * 16 */
+       int16_t         height;         /* 18 m */
+
+       int16_t         v_batt;         /* 20 battery voltage */
+       int16_t         sense_a;        /* 22 apogee continuity sense */
+       int16_t         sense_m;        /* 24 main continuity sense */
+
+       uint8_t         pad[6];         /* 26 */
+       /* 32 */
+};
+       
+#define AO_TELEMETRY_METRUM_DATA       0x0B
+
+struct ao_telemetry_metrum_data {
+       uint16_t        serial;         /*  0 */
+       uint16_t        tick;           /*  2 */
+       uint8_t         type;           /*  4 */
+
+       int32_t         ground_pres;    /* 8 average pres on pad */
+       int16_t         ground_accel;   /* 12 average accel on pad */
+       int16_t         accel_plus_g;   /* 14 accel calibration at +1g */
+       int16_t         accel_minus_g;  /* 16 accel calibration at -1g */
+
+       uint8_t         pad[14];        /* 18 */
+       /* 32 */
+};
+
+#define AO_TELEMETRY_MINI              0x10
+
+struct ao_telemetry_mini {
+       uint16_t        serial;         /*  0 */
+       uint16_t        tick;           /*  2 */
+       uint8_t         type;           /*  4 */
+
+       uint8_t         state;          /*  5 flight state */
+       int16_t         v_batt;         /*  6 battery voltage */
+       int16_t         sense_a;        /*  8 apogee continuity */
+       int16_t         sense_m;        /* 10 main continuity */
+
+       int32_t         pres;           /* 12 Pa * 10 */
+       int16_t         temp;           /* 16 °C * 100 */
+
+       int16_t         acceleration;   /* 18 m/s² * 16 */
+       int16_t         speed;          /* 20 m/s * 16 */
+       int16_t         height;         /* 22 m */
+
+       int32_t         ground_pres;    /* 24 average pres on pad */
+
+       int32_t         pad28;          /* 28 */
+       /* 32 */
+};
+
 /* #define AO_SEND_ALL_BARO */
 
 #define AO_TELEMETRY_BARO              0x80
@@ -234,6 +300,9 @@ union ao_telemetry_all {
        struct ao_telemetry_companion           companion;
        struct ao_telemetry_mega_sensor         mega_sensor;
        struct ao_telemetry_mega_data           mega_data;
+       struct ao_telemetry_metrum_sensor       metrum_sensor;
+       struct ao_telemetry_metrum_data         metrum_data;
+       struct ao_telemetry_mini                mini;
        struct ao_telemetry_baro                baro;
 };
 
index 8f840cb29a0437b91e7e08cfc08e9bbf16ad6048..729149daf5cf2e26e7351bf62acefdad5b2ea52e 100644 (file)
@@ -31,7 +31,7 @@ dnl ==========================================================================
 dnl Java library versions
 
 ALTOSUILIB_VERSION=1
-ALTOSLIB_VERSION=1
+ALTOSLIB_VERSION=2
 
 AC_SUBST(ALTOSLIB_VERSION)
 AC_DEFINE(ALTOSLIB_VERSION,$ALTOSLIB_VERSION,[Version of the AltosLib package])
@@ -180,20 +180,150 @@ if test "x$GCC" = "xyes"; then
 fi
 AC_SUBST(WARN_CFLAGS)
 
-AC_CHECK_PROG([HAVE_SDCC], [sdcc], yes, no)
+#
+# Configure SDCC
+#
+
+AC_ARG_WITH([sdcc],
+           [AS_HELP_STRING([--with-sdcc],
+                           [Name of SDCC])],
+           [],
+           [with_sdcc=auto])
+
+if test "x$with_sdcc" != "xno"; then       
+       if test "x$with_sdcc" = "xauto"; then
+               with_sdcc="sdcc"
+               AC_CHECK_PROG([HAVE_SDCC],[$with_sdcc], yes, no)
+       else
+               HAVE_SDCC=yes
+       fi
+else
+       HAVE_SDCC=no
+fi
+
 if test "x$HAVE_SDCC" = "xno"; then
-       AC_MSG_WARN([No sdcc found, cc1111 binaries will not be built])
+       AC_MSG_WARN([SDCC not found, cc1111 binaries will not be built])
+else
+       SDCC=$with_sdcc
 fi
 
-AC_CHECK_PROG([HAVE_ARM_GCC],[arm-none-eabi-gcc], yes, no,[/usr/bin])
-if test "x$HAVE_ARM_GCC" = "xno"; then
-       AC_MSG_WARN([No summon toolchain arm compiler found, STM32L binaries will not be built])
+AC_SUBST(SDCC)
+AC_SUBST(HAVE_SDCC)
+
+#
+# Configure ARM compiler for STM32L and LPC11U14
+#
+
+AC_ARG_WITH([arm-cc],
+           [AS_HELP_STRING([--with-arm-cc],
+                           [Name of ARM C compiler])],
+           [],
+           [with_arm_cc=auto])
+
+if test "x$with_arm_cc" != "xno"; then     
+       if test "x$with_arm_cc" = "xauto"; then
+               with_arm_cc="arm-none-eabi-gcc"
+               AC_CHECK_PROG([HAVE_ARM_CC],[$with_arm_cc], yes, no)
+       else
+               HAVE_ARM_CC=yes
+       fi
+else
+       HAVE_ARM_CC=no
 fi
 
-AC_CHECK_PROG([HAVE_ARM_M0_GCC], [arm-none-eabi-gcc], yes, no,[/usr/bin])
-if test "x$HAVE_ARM_M0_GCC" = "xno"; then
-       AC_MSG_WARN([No linaro toolchain arm cortex-m0 compiler found, LPC11U14 binaries will not be built])
+if test "x$HAVE_ARM_CC" = "xno"; then
+       AC_MSG_WARN([Arm compiler not found, ARM binaries will not be built])
+else
+       ARM_CC=$with_arm_cc
 fi
+AC_SUBST(HAVE_ARM_CC)
+AC_SUBST(ARM_CC)
+
+if test "x$HAVE_ARM_CC" = "xyes"; then
+       save_CC="$CC"
+       save_CFLAGS="$CFLAGS"
+       CC="$ARM_CC"
+       CFLAGS="-mthumb -mcpu=cortex-m0"
+       AC_LANG_PUSH([C])
+
+       AC_MSG_CHECKING([if ]$ARM_CC[ supports cortex-m0])
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int i;])],
+                         [HAVE_ARM_M0_CC=yes],
+                         [HAVE_ARM_M0_CC=no])
+        AC_MSG_RESULT([$HAVE_ARM_M0])
+       CFLAGS="-mthumb -mcpu=cortex-m3"
+       AC_MSG_CHECKING([if ]$ARM_CC[ supports cortex-m3])
+       AC_COMPILE_IFELSE([AC_LANG_PROGRAM([int i;])],
+                         [HAVE_ARM_M3_CC=yes],
+                         [HAVE_ARM_M3_CC=no])
+        AC_MSG_RESULT([$HAVE_ARM_M3])
+       AC_LANG_POP([C])
+       CFLAGS="$save_CFLAGS"
+       CC="$save_CC"
+else
+       HAVE_ARM_M3_CC=no
+       HAVE_ARM_M0_CC=no
+fi
+AC_SUBST(HAVE_ARM_M3_CC)
+AC_SUBST(HAVE_ARM_M0_CC)
+       
+if test "x$HAVE_ARM_M3_CC" = "xno"; then
+       AC_MSG_WARN([No cortex-m3 arm compiler found, STM32L binaries will not be built])
+fi
+
+if test "x$HAVE_ARM_M0_CC" = "xno"; then
+       AC_MSG_WARN([No cortex-m0 arm compiler found, LPC11U14 binaries will not be built])
+fi
+
+#
+# Configure AVR compiler
+#
+
+AC_ARG_WITH([avr-cc],
+           [AS_HELP_STRING([--with-avr-cc],
+                           [Name of AVR C compiler])],
+           [],
+           [with_avr_cc=auto])
+
+if test "x$with_avr_cc" != "xno"; then     
+       if test "x$with_avr_cc" = "xauto"; then
+               with_avr_cc="avr-gcc"
+               AC_CHECK_PROG([HAVE_AVR_CC],[$with_avr_cc], yes, no)
+       else
+               HAVE_AVR_CC=yes
+       fi
+else
+       HAVE_AVR_CC=no
+fi
+
+AC_ARG_WITH([avr-objcopy],
+           [AS_HELP_STRING([--with-avr-objcopy],
+                           [Name of AVR objcopy])],
+           [],
+           [with_avr_objcopy=auto])
+
+if test "x$with_avr_objcopy" != "xno"; then        
+       if test "x$with_avr_objcopy" = "xauto"; then
+               with_avr_objcopy="avr-objcopy"
+               AC_CHECK_PROG([HAVE_AVR_OBJCOPY],[$with_avr_objcopy], yes, no)
+       else
+               HAVE_AVR_OBJCOPY=yes
+       fi
+else
+       HAVE_AVR_OBJCOPY=no
+fi
+
+if test "x$HAVE_AVR_CC" = "xno" -o "x$HAVE_AVR_OBJCOPY" = "xno"; then
+       AC_MSG_WARN([AVR compiler and objcopy not found, atmel binaries will not be built])
+       HAVE_AVR_CC=no
+else
+       AVR_CC=$with_avr_cc
+       AVR_OBJCOPY=$with_avr_objcopy
+fi
+
+AC_SUBST(AVR_CC)
+AC_SUBST(AVR_OBJCOPY)
+AC_SUBST(HAVE_AVR_CC)
 
 AC_CHECK_PROG([HAVE_NICKLE], [nickle], yes, no)
 if test "x$HAVE_NICKLE" = "xno"; then
@@ -213,6 +343,7 @@ AM_CONDITIONAL([LIBSTLINK], [test x$HAVE_STLINK != xno])
 
 AC_OUTPUT([
 Makefile
+src/Makedefs
 altoslib/Makefile
 altosuilib/Makefile
 altosuilib/AltosUIVersion.java
@@ -248,9 +379,13 @@ echo ""
 echo "  Package: ${PACKAGE_NAME} ${PACKAGE_VERSION}"
 echo ""
 echo "  Configuration"
-echo "    STM32L support..............: ${HAVE_ARM_GCC}"
-echo "    LPC11U14 support............: ${HAVE_ARM_M0_GCC}"
+echo "    Arm compiler................: ${ARM_CC}"
+echo "    STM32L support..............: ${HAVE_ARM_M3_CC}"
+echo "    LPC11U14 support............: ${HAVE_ARM_M0_CC}"
+echo "    SDCC........................: ${SDCC}"
 echo "    CC1111 support..............: ${HAVE_SDCC}"
+echo "    AVR compiler................: ${AVR_CC} ${AVR_OBJCOPY}"
+echo "    AVR support.................: ${HAVE_AVR_CC}"
 echo "    Android support.............: ${HAVE_ANDROID_SDK}"
 echo "    STlink support..............: ${HAVE_STLINK}"
 echo ""
index 4c0ed4c3312bf1de84e5a6947f5d1e1865e9837b..07806fa4bab465014f33cd7acfd41dabec606f2c 100644 (file)
@@ -20,7 +20,7 @@ package org.altusmetrum.micropeak;
 import java.lang.*;
 import java.io.*;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 class MicroIterator implements Iterator<MicroDataPoint> {
index bd6795f85f633fb8e573dac8eb02cbe3c444f472..a9095f9c6bc9ed5da1c5d21b9d9d5a4486f982d0 100644 (file)
@@ -23,7 +23,7 @@ import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class MicroDownload extends AltosUIDialog implements Runnable, ActionListener {
index 20a6f79a4cd2f5dde791f03ee116674b75283d49..5af767c6a92a3f5523285001ab649e1b67108497 100644 (file)
@@ -23,7 +23,7 @@ import java.util.ArrayList;
 import java.awt.*;
 import javax.swing.*;
 import javax.swing.filechooser.FileNameExtensionFilter;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class MicroExport extends JFileChooser {
index cdd42e667657d377334a5afe9ef309ab4ea78be9..2b02e20a5d0c9cb9dda54c53eb6243bcbf7da4c7 100644 (file)
@@ -19,7 +19,7 @@ package org.altusmetrum.micropeak;
 
 import java.io.*;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class MicroFile {
index d52eab2ccf830ead8d532f73ffcb0a7b1bb0e34f..3ca128ee97bfddc79cefd3f55ad77d2162b7b528 100644 (file)
@@ -20,7 +20,7 @@ package org.altusmetrum.micropeak;
 import javax.swing.*;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import java.io.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class MicroFileChooser extends JFileChooser {
index 50508a61b42cbcb0f46bf9fc45b685caba6c6e30..fba6290723a10449ab4a3e6119064c550407d6dc 100644 (file)
@@ -22,7 +22,7 @@ import java.util.ArrayList;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 import org.jfree.ui.*;
index cb1c68cbba2eb7afbc55fe3580a0ff5bce1f5d2f..27a8db02a262845ba2fb2feb5c0f3f763a62ccb3 100644 (file)
@@ -23,7 +23,7 @@ import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class MicroPeak extends MicroFrame implements ActionListener, ItemListener {
index 7337a1dec58b38f6ccdb75c87e402c297ca31e74..0520fa7145da1edd9ef81bd4e6eef5042d1f0b68 100644 (file)
@@ -20,7 +20,7 @@ package org.altusmetrum.micropeak;
 import java.awt.*;
 import java.io.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class MicroRaw extends JTextArea {
index 99f621ce8aa18269c408c14010838257c09a131c..1f1ef3cb86df99e779a7fa87ab3ab45548272ad7 100644 (file)
@@ -24,7 +24,7 @@ import javax.swing.filechooser.FileNameExtensionFilter;
 import java.io.*;
 import java.util.concurrent.*;
 import java.util.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class MicroSave extends JFileChooser {
index 99479cb4aeff3c69a1e69c71fdd2560608faad2a..32d944322caf76705fa3b31be602e4a9970d92e8 100644 (file)
@@ -18,7 +18,7 @@
 package org.altusmetrum.micropeak;
 
 import java.io.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class MicroStats {
index 145bb70ea6dd453ec9730beda5e0dde5615808b5..4400a317f193d78f1e6a17e439e7f1d0c427cdf9 100644 (file)
@@ -19,7 +19,7 @@ package org.altusmetrum.micropeak;
 
 import java.awt.*;
 import javax.swing.*;
-import org.altusmetrum.altoslib_1.*;
+import org.altusmetrum.altoslib_2.*;
 import org.altusmetrum.altosuilib_1.*;
 
 public class MicroStatsTable extends JComponent implements AltosFontListener {
diff --git a/src/Makedefs.in b/src/Makedefs.in
new file mode 100644 (file)
index 0000000..6dc9ab0
--- /dev/null
@@ -0,0 +1,10 @@
+ARM_CC=@ARM_CC@
+HAVE_ARM_M3_CC=@HAVE_ARM_M3_CC@
+HAVE_ARM_M0_CC=@HAVE_ARM_M0_CC@
+
+SDCC=@SDCC@
+HAVE_SDCC=@HAVE_SDCC@
+
+AVR_CC=@AVR_CC@
+AVR_OBJCOPY=@AVR_OBJCOPY@
+HAVE_AVR_CC=@HAVE_AVR_CC@
index af2630fc464f3e37de13087c2450b3902b4abb7d..ae231c64af20a19482965819a36a0ceb77f02223 100644 (file)
@@ -13,6 +13,7 @@ vpath load_csv.5c kalman
 vpath matrix.5c kalman
 
 include Version
+include Makedefs
 
 SDCCDIRS=\
        telemetrum-v1.2 telemetrum-v1.1 telemetrum-v1.0 \
@@ -23,39 +24,38 @@ SDCCDIRS=\
        telefire-v0.1 telefire-v0.2 \
        telemini-v2.0
 
-AVRDIRS=\
-       telescience-v0.1 telescience-pwm micropeak
-
-ARMDIRS=\
+ARMM3DIRS=\
        telemega-v0.1 telemega-v0.1/flash-loader \
        telemega-v0.3 telemega-v0.3/flash-loader \
        megadongle-v0.1 megadongle-v0.1/flash-loader \
        telegps-v0.3 telegps-v0.3/flash-loader \
        stm-bringup stm-demo \
        telelco-v0.2 telelco-v0.2/flash-loader \
-       telescience-v0.2 telescience-v0.2/flash-loader \
-       easymini-v0.1 easymini-v0.1/flash-loader
+       telescience-v0.2 telescience-v0.2/flash-loader
 
 ARMM0DIRS=\
-       easymini-v0.1
+       easymini-v1.0 easymini-v1.0/flash-loader
+
+AVRDIRS=\
+       telescience-v0.1 telescience-pwm micropeak nanopeak-v0.1
 
-ifneq ($(shell which sdcc),)
+ifeq ($(strip $(HAVE_SDCC)),yes)
        SUBDIRS += $(SDCCDIRS)
 endif
 
-ifneq ($(shell which avr-gcc),)
-       SUBDIRS += $(AVRDIRS)
+ifeq ($(strip ($HAVE_ARM_M3_CC)),yes)
+       SUBDIRS += $(ARMM3DIRS)
 endif
 
-ifneq ($(shell which /opt/cortex/bin/arm-none-eabi-gcc),)
-       SUBDIRS += $(ARMDIRS)
+ifneq ($(strip ($HAVE_ARM_M0_CC)),yes)
+       SUBDIRS += $(ARMM0DIRS)
 endif
 
-ifneq ($(shell which /usr/bin/arm-none-eabi-gcc),)
-       SUBDIRS += $(ARMM0DIRS)
+ifeq ($(strip $(HAVE_AVR_CC)),yes)
+       SUBDIRS += $(AVRDIRS)
 endif
 
-ALLDIRS=$(SDCCDIRS) $(AVRDIRS) $(ARMDIRS)
+ALLDIRS=$(SDCCDIRS) $(ARMM3DIRS) $(ARMM0DIRS) $(AVRDIRS)
 
 all: all-local all-recursive
 
diff --git a/src/attiny/ao_async.c b/src/attiny/ao_async.c
new file mode 100644 (file)
index 0000000..3556f54
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2012 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.
+ */
+
+#include <ao.h>
+#include <ao_async.h>
+
+#define AO_ASYNC_BAUD  38400l
+#define AO_ASYNC_DELAY (uint8_t) (1000000l / AO_ASYNC_BAUD)
+
+#define LED_PORT       PORTB
+
+void
+ao_async_start(void)
+{
+       LED_PORT |= (1 << AO_LED_SERIAL);
+}
+
+void
+ao_async_stop(void)
+{
+       LED_PORT &= ~(1 << AO_LED_SERIAL);
+}
+
+void
+ao_async_byte(uint8_t byte)
+{
+       uint8_t         b;
+       uint16_t        w;
+
+       /*    start           data           stop */
+       w = (0x000 << 0) | (byte << 1) | (0x001 << 9);
+
+       ao_arch_block_interrupts();
+       for (b = 0; b < 10; b++) {
+               uint8_t v = LED_PORT & ~(1 << AO_LED_SERIAL);
+               v |= (w & 1) << AO_LED_SERIAL;
+               LED_PORT = v;
+               w >>= 1;
+
+               /* Carefully timed to hit around 9600 baud */
+               asm volatile ("nop");
+               asm volatile ("nop");
+
+               asm volatile ("nop");
+               asm volatile ("nop");
+               asm volatile ("nop");
+               asm volatile ("nop");
+               asm volatile ("nop");
+
+               asm volatile ("nop");
+               asm volatile ("nop");
+               asm volatile ("nop");
+               asm volatile ("nop");
+               asm volatile ("nop");
+       }
+       ao_arch_release_interrupts();
+}
diff --git a/src/attiny/ao_async.h b/src/attiny/ao_async.h
new file mode 100644 (file)
index 0000000..1b23971
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright © 2012 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.
+ */
+
+#ifndef _AO_ASYNC_H_
+#define _AO_ASYNC_H_
+
+void
+ao_async_start(void);
+
+void
+ao_async_stop(void);
+
+void
+ao_async_byte(uint8_t byte);
+
+#endif /* _AO_ASYNC_H_ */
index 932951665d527caa90eb435309b6e09756c37732..6d9bfea2098f9102d4fff464f9f5760ec588a524 100644 (file)
@@ -11,18 +11,12 @@ vpath load_csv.5c ../kalman
 vpath matrix.5c ../kalman
 vpath ao-make-product.5c ../util
 
+include ../avr/Makefile.defs
+
 MCU=atmega32u4
 DUDECPUTYPE=m32u4
 #PROGRAMMER=stk500v2 -P usb
-PROGRAMMER=usbtiny
-LOADCMD=avrdude
 LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w:
-CC=avr-gcc
-OBJCOPY=avr-objcopy
-
-ifndef VERSION
-include ../Version
-endif
 
 INC = \
        ao.h \
diff --git a/src/avr/Makefile.defs b/src/avr/Makefile.defs
new file mode 100644 (file)
index 0000000..eeb9a88
--- /dev/null
@@ -0,0 +1,16 @@
+ifndef TOPDIR
+TOPDIR=..
+endif
+
+ifndef VERSION
+include $(TOPDIR)/Version
+endif
+
+include $(TOPDIR)/Makedefs
+
+CC=$(AVR_CC)
+OBJCOPY=$(AVR_OBJCOPY)
+LDSCRIPTS=/usr/lib/avr/lib/ldscripts
+
+PROGRAMMER=usbtiny
+LOADCMD=avrdude
index 0e19603b29429d4e8177f163ac05d7134dd9b421..78b653b3049abbbf5cd595802d67e5ced89755e1 100644 (file)
@@ -1,4 +1,5 @@
-CC=sdcc
+include ../Makedefs
+CC=$(SDCC)
 
 CFLAGS=--model-small --debug --opt-code-speed -DCODESIZE=$(CODESIZE)
 
index 1322195beb2ca4d0e1cb5ddab0c99580e7f2abe5..88dc816d25578858aa2c3e8c672cb414b0eb418e 100644 (file)
@@ -134,8 +134,10 @@ ao_flight(void)
                                ao_rdf_set(1);
                                ao_telemetry_set_interval(AO_TELEMETRY_INTERVAL_PAD);
 #endif
+#if HAS_LED
                                /* signal successful initialization by turning off the LED */
                                ao_led_off(AO_LED_RED);
+#endif
                        } else {
                                /* Set idle mode */
                                ao_flight_state = ao_flight_idle;
@@ -145,8 +147,10 @@ ao_flight(void)
                                ao_packet_slave_start();
 #endif
 
+#if HAS_LED
                                /* signal successful initialization by turning off the LED */
                                ao_led_off(AO_LED_RED);
+#endif
                        }
                        /* wakeup threads due to state change */
                        ao_wakeup(DATA_TO_XDATA(&ao_flight_state));
index f6ab45209913ed73a76c8185d5e9d2300b995e30..4b09faebe9ea9020f6c42abcb3492d025e41cb7c 100644 (file)
@@ -44,8 +44,9 @@ extern __pdata enum ao_flight_state ao_log_state;
 #define AO_LOG_FORMAT_TELEMETRY                3       /* 32 byte ao_telemetry records */
 #define AO_LOG_FORMAT_TELESCIENCE      4       /* 32 byte typed telescience records */
 #define AO_LOG_FORMAT_TELEMEGA         5       /* 32 byte typed telemega records */
-#define AO_LOG_FORMAT_MINI             6       /* 16-byte MS5607 baro only */
+#define AO_LOG_FORMAT_EASYMINI         6       /* 16-byte MS5607 baro only, 3.0V supply */
 #define AO_LOG_FORMAT_TELEMETRUM       7       /* 16-byte typed telemetrum records */
+#define AO_LOG_FORMAT_TELEMINI         8       /* 16-byte MS5607 baro only, 3.3V supply */
 #define AO_LOG_FORMAT_NONE             127     /* No log at all */
 
 extern __code uint8_t ao_log_format;
@@ -275,7 +276,8 @@ struct ao_log_metrum {
                        uint16_t        flight;         /* 4 */
                        int16_t         ground_accel;   /* 6 */
                        uint32_t        ground_pres;    /* 8 */
-               } flight;       /* 12 */
+                       uint32_t        ground_temp;    /* 12 */
+               } flight;       /* 16 */
                /* AO_LOG_STATE */
                struct {
                        uint16_t        state;          /* 4 */
diff --git a/src/core/ao_log_micro.c b/src/core/ao_log_micro.c
new file mode 100644 (file)
index 0000000..d665efb
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * Copyright © 2012 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.
+ */
+
+#include <ao.h>
+#include <ao_micropeak.h>
+#include <ao_log_micro.h>
+#include <ao_async.h>
+
+static uint16_t ao_log_offset = STARTING_LOG_OFFSET;
+
+void
+ao_log_micro_save(void)
+{
+       uint16_t        n_samples = (ao_log_offset - STARTING_LOG_OFFSET) / sizeof (uint16_t);
+       ao_eeprom_write(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground));
+       ao_eeprom_write(PA_MIN_OFFSET, &pa_min, sizeof (pa_min));
+       ao_eeprom_write(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
+}
+
+void
+ao_log_micro_restore(void)
+{
+       ao_eeprom_read(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground));
+       ao_eeprom_read(PA_MIN_OFFSET, &pa_min, sizeof (pa_min));
+}
+
+void
+ao_log_micro_data(void)
+{
+       uint16_t        low_bits = pa;
+
+       if (ao_log_offset < MAX_LOG_OFFSET) {
+               ao_eeprom_write(ao_log_offset, &low_bits, sizeof (low_bits));
+               ao_log_offset += sizeof (low_bits);
+       }
+}
+
+#define POLY 0x8408
+
+static uint16_t
+ao_log_micro_crc(uint16_t crc, uint8_t byte)
+{
+       uint8_t i;
+
+       for (i = 0; i < 8; i++) {
+               if ((crc & 0x0001) ^ (byte & 0x0001))
+                       crc = (crc >> 1) ^ POLY;
+               else
+                       crc = crc >> 1;
+               byte >>= 1;
+       }
+       return crc;
+}
+
+static void
+ao_log_hex_nibble(uint8_t b)
+{
+       if (b < 10)
+               ao_async_byte('0' + b);
+       else
+               ao_async_byte('a' - 10 + b);
+}
+
+static void
+ao_log_hex(uint8_t b)
+{
+       ao_log_hex_nibble(b>>4);
+       ao_log_hex_nibble(b&0xf);
+}
+
+static void
+ao_log_newline(void)
+{
+       ao_async_byte('\r');
+       ao_async_byte('\n');
+}
+
+void
+ao_log_micro_dump(void)
+{
+       uint16_t        n_samples;
+       uint16_t        nbytes;
+       uint8_t         byte;
+       uint16_t        b;
+       uint16_t        crc = 0xffff;
+
+       ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
+       if (n_samples == 0xffff)
+               n_samples = 0;
+       nbytes = STARTING_LOG_OFFSET + sizeof (uint16_t) * n_samples;
+       ao_async_start();
+       ao_async_byte('M');
+       ao_async_byte('P');
+       for (b = 0; b < nbytes; b++) {
+               if ((b & 0xf) == 0)
+                       ao_log_newline();
+               ao_eeprom_read(b, &byte, 1);
+               ao_log_hex(byte);
+               crc = ao_log_micro_crc(crc, byte);
+       }
+       ao_log_newline();
+       crc = ~crc;
+       ao_log_hex(crc >> 8);
+       ao_log_hex(crc);
+       ao_log_newline();
+       ao_async_stop();
+}
diff --git a/src/core/ao_log_micro.h b/src/core/ao_log_micro.h
new file mode 100644 (file)
index 0000000..976852e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2012 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.
+ */
+
+#ifndef _AO_LOG_MICRO_H_
+#define _AO_LOG_MICRO_H_
+
+#define PA_GROUND_OFFSET       0
+#define PA_MIN_OFFSET          4
+#define N_SAMPLES_OFFSET       8
+#define STARTING_LOG_OFFSET    10
+#define MAX_LOG_OFFSET         512
+
+void
+ao_log_micro_save(void);
+
+void
+ao_log_micro_restore(void);
+
+void
+ao_log_micro_data(void);
+
+void
+ao_log_micro_dump(void);
+
+#endif /* _AO_LOG_MICRO_H_ */
index 46b285f31868ab3ca84ac599c33f1ffdfcf3e559..99a85982042b676115b30dac7a5c1fbdd470fe95 100644 (file)
@@ -23,7 +23,7 @@
 static __xdata uint8_t ao_log_mutex;
 static __xdata struct ao_log_mini log;
 
-__code uint8_t ao_log_format = AO_LOG_FORMAT_MINI;
+__code uint8_t ao_log_format = AO_LOG_FORMAT;
 
 static uint8_t
 ao_log_csum(__xdata uint8_t *b) __reentrant
diff --git a/src/core/ao_microflight.c b/src/core/ao_microflight.c
new file mode 100644 (file)
index 0000000..714bb90
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright © 2013 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.
+ */
+
+#ifndef AO_FLIGHT_TEST
+#include <ao.h>
+#endif
+#include <ao_micropeak.h>
+#include <ao_log_micro.h>
+
+uint32_t       pa;
+uint32_t       pa_ground;
+uint32_t       pa_min;
+
+static void
+ao_microsample(void)
+{
+       ao_pa_get();
+       ao_microkalman_predict();
+       ao_microkalman_correct();
+}
+
+#define NUM_PA_HIST    16
+
+#define SKIP_PA_HIST(i,j)      (((i) + (j)) & (NUM_PA_HIST - 1))
+
+static uint32_t        pa_hist[NUM_PA_HIST];
+
+void
+ao_microflight(void)
+{
+       int16_t         sample_count;
+       uint16_t        time;
+       uint32_t        pa_interval_min, pa_interval_max;
+       int32_t         pa_diff;
+       uint8_t         h, i;
+       uint8_t         accel_lock = 0;
+       uint32_t        pa_sum = 0;
+
+       /* Wait for motion, averaging values to get ground pressure */
+
+       time = ao_time();
+       ao_pa_get();
+       ao_microkalman_init();
+       pa_ground = pa;
+       sample_count = 0;
+       h = 0;
+       for (;;) {
+               time += SAMPLE_SLEEP;
+               if (sample_count == 0)
+                       ao_led_on(AO_LED_REPORT);
+               ao_delay_until(time);
+               ao_microsample();
+               if (sample_count == 0)
+                       ao_led_off(AO_LED_REPORT);
+               pa_hist[h] = pa;
+               h = SKIP_PA_HIST(h,1);
+               pa_diff = pa_ground - ao_pa;
+
+               /* Check for a significant pressure change */
+               if (pa_diff > BOOST_DETECT)
+                       break;
+
+               if (sample_count < GROUND_AVG * 2) {
+                       if (sample_count < GROUND_AVG)
+                               pa_sum += pa;
+                       ++sample_count;
+               } else {
+                       pa_ground = pa_sum >> GROUND_AVG_SHIFT;
+                       pa_sum = 0;
+                       sample_count = 0;
+               }
+       }
+
+       /* Go back and find the first sample a decent interval above the ground */
+       pa_min = pa_ground - LAND_DETECT;
+       for (i = SKIP_PA_HIST(h,2); i != h; i = SKIP_PA_HIST(i,2)) {
+               if (pa_hist[i] < pa_min)
+                       break;
+       }
+
+       /* Log the remaining samples so we get a complete history since leaving the ground */
+       for (; i != h; i = SKIP_PA_HIST(i,2)) {
+               pa = pa_hist[i];
+               ao_log_micro_data();
+       }
+
+       /* Now sit around until the pressure is stable again and record the max */
+
+       sample_count = 0;
+       pa_min = ao_pa;
+       pa_interval_min = ao_pa;
+       pa_interval_max = ao_pa;
+       for (;;) {
+               time += SAMPLE_SLEEP;
+               ao_delay_until(time);
+               if ((sample_count & 3) == 0)
+                       ao_led_on(AO_LED_REPORT);
+               ao_microsample();
+               if ((sample_count & 3) == 0)
+                       ao_led_off(AO_LED_REPORT);
+               if (sample_count & 1)
+                       ao_log_micro_data();
+
+               /* If accelerating upwards, don't look for min pressure */
+               if (ao_pa_accel < ACCEL_LOCK_PA)
+                       accel_lock = ACCEL_LOCK_TIME;
+               else if (accel_lock)
+                       --accel_lock;
+               else if (ao_pa < pa_min)
+                       pa_min = ao_pa;
+
+               if (sample_count == (GROUND_AVG - 1)) {
+                       pa_diff = pa_interval_max - pa_interval_min;
+
+                       /* Check to see if the pressure is now stable */
+                       if (pa_diff < LAND_DETECT)
+                               break;
+                       sample_count = 0;
+                       pa_interval_min = ao_pa;
+                       pa_interval_max = ao_pa;
+               } else {
+                       if (ao_pa < pa_interval_min)
+                               pa_interval_min = ao_pa;
+                       if (ao_pa > pa_interval_max)
+                               pa_interval_max = ao_pa;
+                       ++sample_count;
+               }
+       }
+}
diff --git a/src/core/ao_microkalman.c b/src/core/ao_microkalman.c
new file mode 100644 (file)
index 0000000..0684ea2
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2013 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.
+ */
+
+#ifndef AO_FLIGHT_TEST
+#include <ao.h>
+#endif
+#include <ao_micropeak.h>
+
+#define FIX_BITS       16
+
+#define to_fix16(x) ((int16_t) ((x) * 65536.0 + 0.5))
+#define to_fix32(x) ((int32_t) ((x) * 65536.0 + 0.5))
+#define from_fix8(x)   ((x) >> 8)
+#define from_fix(x)    ((x) >> 16)
+#define fix8_to_fix16(x)       ((x) << 8)
+#define fix16_to_fix8(x)       ((x) >> 8)
+
+#include <ao_kalman.h>
+
+/* Basic time step (96ms) */
+#define AO_MK_STEP     to_fix16(0.096)
+/* step ** 2 / 2 */
+#define AO_MK_STEP_2_2 to_fix16(0.004608)
+
+uint32_t       ao_k_pa;                /* 24.8 fixed point */
+int32_t                ao_k_pa_speed;          /* 16.16 fixed point */
+int32_t                ao_k_pa_accel;          /* 16.16 fixed point */
+
+uint32_t       ao_pa;                  /* integer portion */
+int16_t                ao_pa_speed;            /* integer portion */
+int16_t                ao_pa_accel;            /* integer portion */
+
+void
+ao_microkalman_init(void)
+{
+       ao_pa = pa;
+       ao_k_pa = pa << 8;
+}      
+
+void
+ao_microkalman_predict(void)
+{
+       ao_k_pa       += fix16_to_fix8((int32_t) ao_pa_speed * AO_MK_STEP + (int32_t) ao_pa_accel * AO_MK_STEP_2_2);
+       ao_k_pa_speed += (int32_t) ao_pa_accel * AO_MK_STEP;
+}
+
+void
+ao_microkalman_correct(void)
+{
+       int16_t e;      /* Height error in Pa */
+
+       e = pa - from_fix8(ao_k_pa);
+
+       ao_k_pa       += fix16_to_fix8((int32_t) e * AO_MK_BARO_K0_10);
+       ao_k_pa_speed += (int32_t) e * AO_MK_BARO_K1_10;
+       ao_k_pa_accel += (int32_t) e * AO_MK_BARO_K2_10;
+       ao_pa = from_fix8(ao_k_pa);
+       ao_pa_speed = from_fix(ao_k_pa_speed);
+       ao_pa_accel = from_fix(ao_k_pa_accel);
+}
diff --git a/src/core/ao_report_micro.c b/src/core/ao_report_micro.c
new file mode 100644 (file)
index 0000000..0e8e287
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2012 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.
+ */
+
+#include <ao.h>
+
+#define mid(time)      ao_led_for(AO_LED_REPORT, time)
+#define pause(time)    ao_delay(time)
+
+static void
+ao_report_digit(uint8_t digit) __reentrant
+{
+       if (!digit) {
+               mid(AO_MS_TO_TICKS(1000));
+               pause(AO_MS_TO_TICKS(300));
+       } else {
+               while (digit--) {
+                       mid(AO_MS_TO_TICKS(300));
+                       pause(AO_MS_TO_TICKS(300));
+               }
+       }
+       pause(AO_MS_TO_TICKS(1000));
+}
+
+void
+ao_report_altitude(void)
+{
+       __pdata alt_t   agl = ao_max_height;
+       static __xdata uint8_t  digits[11];
+       __pdata uint8_t ndigits, i;
+
+       if (agl < 0)
+               agl = 0;
+       ndigits = 0;
+       do {
+               digits[ndigits++] = agl % 10;
+               agl /= 10;
+       } while (agl);
+
+       i = ndigits;
+       do
+               ao_report_digit(digits[--i]);
+       while (i != 0);
+}
index cd95aa6bce3d0a995d70b6fd30a90d49a75ca07a..6b47a06a1cbf42dec3a81d2cb105abf953cf55b4 100644 (file)
@@ -182,6 +182,7 @@ ao_send_metrum_sensor(void)
 {
        __xdata struct ao_data *packet = (__xdata struct ao_data *) &ao_data_ring[ao_data_ring_prev(ao_sample_data)];
 
+       telemetry.generic.tick = packet->tick;
        telemetry.generic.type = AO_TELEMETRY_METRUM_SENSOR;
 
        telemetry.metrum_sensor.state = ao_flight_state;
diff --git a/src/easymini-v0.1/.gitignore b/src/easymini-v0.1/.gitignore
deleted file mode 100644 (file)
index e5f7d58..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-ao_product.h
-*.elf
diff --git a/src/easymini-v0.1/Makefile b/src/easymini-v0.1/Makefile
deleted file mode 100644 (file)
index 9847656..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#
-# AltOS build
-#
-#
-
-include ../lpc/Makefile.defs
-
-INC = \
-       ao.h \
-       ao_arch.h \
-       ao_arch_funcs.h \
-       ao_pins.h \
-       ao_product.h \
-       lpc.h
-
-#
-# Common AltOS sources
-#
-ALTOS_SRC = \
-       ao_interrupt.c \
-       ao_boot_chain.c \
-       ao_romconfig.c \
-       ao_product.c \
-       ao_mutex.c \
-       ao_panic.c \
-       ao_stdio.c \
-       ao_storage.c \
-       ao_report.c \
-       ao_ignite.c \
-       ao_flight.c \
-       ao_kalman.c \
-       ao_sample.c \
-       ao_data.c \
-       ao_convert_pa.c \
-       ao_led_lpc.c \
-       ao_task.c \
-       ao_log.c \
-       ao_log_mini.c \
-       ao_cmd.c \
-       ao_config.c \
-       ao_timer_lpc.c \
-       ao_exti_lpc.c \
-       ao_usb_lpc.c \
-       ao_spi_lpc.c \
-       ao_adc_lpc.c \
-       ao_beep_lpc.c \
-       ao_m25.c \
-       ao_ms5607.c
-
-PRODUCT=EasyMini-v0.1
-PRODUCT_DEF=-DEASYMINI_V_0_1
-IDPRODUCT=0x0026
-
-CFLAGS = $(PRODUCT_DEF) $(LPC_CFLAGS) -g -Os
-
-PROGNAME=easymini-v0.1
-PROG=$(PROGNAME)-$(VERSION).elf
-
-SRC=$(ALTOS_SRC) ao_easymini.c
-OBJ=$(SRC:.c=.o)
-
-all: $(PROG)
-
-LDFLAGS=-L../lpc -Wl,-Taltos.ld
-
-$(PROG): Makefile $(OBJ) altos.ld
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(SAT_CLIB) -lgcc
-
-ao_product.h: ao-make-product.5c ../Version
-       $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@
-
-$(OBJ): $(INC)
-
-load: $(PROG)
-       lpc-load $(PROG)
-
-distclean:     clean
-
-clean:
-       rm -f *.o $(PROG)
-       rm -f ao_product.h
-
-install:
-
-uninstall:
diff --git a/src/easymini-v0.1/ao_easymini.c b/src/easymini-v0.1/ao_easymini.c
deleted file mode 100644 (file)
index 97230b6..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright © 2011 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.
- */
-
-#include <ao.h>
-#include <ao_exti.h>
-
-void
-main(void)
-{
-       ao_clock_init();
-       ao_task_init();
-       ao_timer_init();
-       ao_exti_init();
-
-       ao_beep_init();
-
-       ao_adc_init();
-       ao_spi_init();
-       ao_storage_init();
-
-       ao_usb_init();
-
-       ao_cmd_init();
-       ao_flight_init();
-       ao_ms5607_init();
-       ao_log_init();
-       ao_report_init();
-       ao_igniter_init();
-       ao_config_init();
-
-       ao_start_scheduler();
-}
diff --git a/src/easymini-v0.1/ao_pins.h b/src/easymini-v0.1/ao_pins.h
deleted file mode 100644 (file)
index c09fb4c..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright © 2013 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.
- */
-
-#define HAS_BEEP       1
-#define        HAS_LED         1
-
-#define AO_STACK_SIZE  384
-
-#define IS_FLASH_LOADER        0
-
-/* Crystal on the board */
-#define AO_LPC_CLKIN   12000000
-
-/* Main clock frequency. 48MHz for USB so we don't use the USB PLL */
-#define AO_LPC_CLKOUT  48000000
-
-/* System clock frequency */
-#define AO_LPC_SYSCLK  24000000
-
-#define LED_PORT       0
-#define LED_PIN_RED    7
-
-#define AO_LED_RED     (1 << LED_PIN_RED)
-
-#define LEDS_AVAILABLE AO_LED_RED
-
-#define HAS_USB                1
-
-#define HAS_USB_CONNECT        0
-#define HAS_USB_VBUS   0
-#define HAS_USB_PULLUP 1
-#define AO_USB_PULLUP_PORT     0
-#define AO_USB_PULLUP_PIN      20
-
-#define PACKET_HAS_SLAVE       0
-
-/* USART */
-
-#define HAS_SERIAL             0
-#define USE_SERIAL_0_STDIN     1
-#define SERIAL_0_18_19         1
-#define SERIAL_0_14_15         0
-#define SERIAL_0_17_18         0
-#define SERIAL_0_26_27         0
-
-/* SPI */
-
-#define HAS_SPI_0              1
-#define SPI_SCK0_P0_6          1
-#define HAS_SPI_1              1
-#define SPI_SCK1_P1_15         1
-#define SPI_MISO1_P0_22                1
-#define SPI_MOSI1_P0_21                1
-
-/* M25 */
-
-#define M25_MAX_CHIPS          1
-#define AO_M25_SPI_CS_PORT     0
-#define AO_M25_SPI_CS_MASK     (1 << 23)
-#define AO_M25_SPI_BUS         1
-
-/* MS5607 */
-
-#define HAS_MS5607             1
-#define HAS_MS5611             0
-#define AO_MS5607_PRIVATE_PINS 0
-#define AO_MS5607_CS_PORT      0
-#define AO_MS5607_CS_PIN       7
-#define AO_MS5607_CS_MASK      (1 << AO_MS5607_CS_PIN)
-#define AO_MS5607_MISO_PORT    0
-#define AO_MS5607_MISO_PIN     8
-#define AO_MS5607_MISO_MASK    (1 << AO_MS5607_MISO_PIN)
-#define AO_MS5607_SPI_INDEX    0
-
-#define HAS_ACCEL              0
-#define HAS_GPS                        0
-#define HAS_RADIO              0
-#define HAS_FLIGHT             1
-#define HAS_EEPROM             1
-#define HAS_TELEMETRY          0
-#define HAS_APRS               0
-#define HAS_LOG                        1
-#define USE_INTERNAL_FLASH     0
-#define HAS_IGNITE             1
-#define HAS_IGNITE_REPORT      1
-
-#define AO_DATA_RING           16
-
-/*
- * ADC
- */
-
-#define HAS_ADC                        1
-
-#define AO_NUM_ADC             3
-
-#define AO_ADC_0               1
-#define AO_ADC_1               1
-#define AO_ADC_2               1
-
-struct ao_adc {
-       int16_t         sense_a;
-       int16_t         sense_m;
-       int16_t         v_batt;
-};
-
-/*
- * Igniter
- */
-
-#define AO_IGNITER_CLOSED      400
-#define AO_IGNITER_OPEN                60
-
-#define AO_IGNITER_DROGUE_PORT 0
-#define AO_IGNITER_DROGUE_PIN  2
-#define AO_IGNITER_SET_DROGUE(v)       ao_gpio_set(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, AO_IGNITER_DROGUE, v)
-
-#define AO_IGNITER_MAIN_PORT   0
-#define AO_IGNITER_MAIN_PIN    3
-#define AO_IGNITER_SET_MAIN(v)         ao_gpio_set(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, AO_IGNITER_MAIN, v)
-
-#define AO_SENSE_DROGUE(p)     ((p)->adc.sense_a)
-#define AO_SENSE_MAIN(p)       ((p)->adc.sense_m)
-
-#define AO_ADC_DUMP(p) \
-       printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
-              (p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
diff --git a/src/easymini-v0.1/flash-loader/Makefile b/src/easymini-v0.1/flash-loader/Makefile
deleted file mode 100644 (file)
index ab828b2..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#
-# AltOS flash loader build
-#
-#
-
-TOPDIR=../..
-HARDWARE=easymini-v0.1
-include $(TOPDIR)/lpc/Makefile-flash.defs
diff --git a/src/easymini-v0.1/flash-loader/ao_pins.h b/src/easymini-v0.1/flash-loader/ao_pins.h
deleted file mode 100644 (file)
index 4330151..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright © 2013 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.
- */
-
-#ifndef _AO_PINS_H_
-#define _AO_PINS_H_
-
-#include <ao_flash_lpc_pins.h>
-
-#define AO_BOOT_PIN            1
-#define AO_BOOT_APPLICATION_GPIO       0
-#define AO_BOOT_APPLICATION_PIN                19
-#define AO_BOOT_APPLICATION_VALUE      1
-#define AO_BOOT_APPLICATION_MODE       AO_EXTI_MODE_PULL_UP
-
-#define HAS_USB_PULLUP 1
-#define AO_USB_PULLUP_PORT     0
-#define AO_USB_PULLUP_PIN      20
-
-#endif /* _AO_PINS_H_ */
diff --git a/src/easymini-v1.0/.gitignore b/src/easymini-v1.0/.gitignore
new file mode 100644 (file)
index 0000000..e5f7d58
--- /dev/null
@@ -0,0 +1,2 @@
+ao_product.h
+*.elf
diff --git a/src/easymini-v1.0/Makefile b/src/easymini-v1.0/Makefile
new file mode 100644 (file)
index 0000000..ec305c9
--- /dev/null
@@ -0,0 +1,84 @@
+#
+# AltOS build
+#
+#
+
+include ../lpc/Makefile.defs
+
+INC = \
+       ao.h \
+       ao_arch.h \
+       ao_arch_funcs.h \
+       ao_pins.h \
+       ao_product.h \
+       lpc.h
+
+#
+# Common AltOS sources
+#
+ALTOS_SRC = \
+       ao_interrupt.c \
+       ao_boot_chain.c \
+       ao_romconfig.c \
+       ao_product.c \
+       ao_mutex.c \
+       ao_panic.c \
+       ao_stdio.c \
+       ao_storage.c \
+       ao_report.c \
+       ao_ignite.c \
+       ao_flight.c \
+       ao_kalman.c \
+       ao_sample.c \
+       ao_data.c \
+       ao_convert_pa.c \
+       ao_task.c \
+       ao_log.c \
+       ao_log_mini.c \
+       ao_cmd.c \
+       ao_config.c \
+       ao_timer_lpc.c \
+       ao_exti_lpc.c \
+       ao_usb_lpc.c \
+       ao_spi_lpc.c \
+       ao_adc_lpc.c \
+       ao_beep_lpc.c \
+       ao_m25.c \
+       ao_ms5607.c
+
+PRODUCT=EasyMini-v1.0
+PRODUCT_DEF=-DEASYMINI_V_1_0
+IDPRODUCT=0x0026
+
+CFLAGS = $(PRODUCT_DEF) $(LPC_CFLAGS) -g -Os
+
+PROGNAME=easymini-v1.0
+PROG=$(PROGNAME)-$(VERSION).elf
+
+SRC=$(ALTOS_SRC) ao_easymini.c
+OBJ=$(SRC:.c=.o)
+
+all: $(PROG)
+
+LDFLAGS=-L../lpc -Wl,-Taltos.ld
+
+$(PROG): Makefile $(OBJ) altos.ld
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ) $(SAT_CLIB) -lgcc
+
+ao_product.h: ao-make-product.5c ../Version
+       $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@
+
+$(OBJ): $(INC)
+
+load: $(PROG)
+       lpc-load $(PROG)
+
+distclean:     clean
+
+clean:
+       rm -f *.o $(PROG)
+       rm -f ao_product.h
+
+install:
+
+uninstall:
diff --git a/src/easymini-v1.0/ao_easymini.c b/src/easymini-v1.0/ao_easymini.c
new file mode 100644 (file)
index 0000000..97230b6
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2011 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.
+ */
+
+#include <ao.h>
+#include <ao_exti.h>
+
+void
+main(void)
+{
+       ao_clock_init();
+       ao_task_init();
+       ao_timer_init();
+       ao_exti_init();
+
+       ao_beep_init();
+
+       ao_adc_init();
+       ao_spi_init();
+       ao_storage_init();
+
+       ao_usb_init();
+
+       ao_cmd_init();
+       ao_flight_init();
+       ao_ms5607_init();
+       ao_log_init();
+       ao_report_init();
+       ao_igniter_init();
+       ao_config_init();
+
+       ao_start_scheduler();
+}
diff --git a/src/easymini-v1.0/ao_pins.h b/src/easymini-v1.0/ao_pins.h
new file mode 100644 (file)
index 0000000..e721030
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * Copyright © 2013 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.
+ */
+
+#define HAS_BEEP       1
+#define        HAS_LED         0
+
+#define AO_STACK_SIZE  384
+
+#define IS_FLASH_LOADER        0
+
+/* Crystal on the board */
+#define AO_LPC_CLKIN   12000000
+
+/* Main clock frequency. 48MHz for USB so we don't use the USB PLL */
+#define AO_LPC_CLKOUT  48000000
+
+/* System clock frequency */
+#define AO_LPC_SYSCLK  24000000
+
+#define HAS_USB                1
+
+#define HAS_USB_CONNECT        0
+#define HAS_USB_VBUS   0
+#define HAS_USB_PULLUP 1
+#define AO_USB_PULLUP_PORT     0
+#define AO_USB_PULLUP_PIN      20
+
+#define PACKET_HAS_SLAVE       0
+
+#define AO_LOG_FORMAT          AO_LOG_FORMAT_EASYMINI
+
+/* USART */
+
+#define HAS_SERIAL             0
+#define USE_SERIAL_0_STDIN     1
+#define SERIAL_0_18_19         1
+#define SERIAL_0_14_15         0
+#define SERIAL_0_17_18         0
+#define SERIAL_0_26_27         0
+
+/* SPI */
+
+#define HAS_SPI_0              1
+#define SPI_SCK0_P0_6          1
+#define HAS_SPI_1              1
+#define SPI_SCK1_P1_15         1
+#define SPI_MISO1_P0_22                1
+#define SPI_MOSI1_P0_21                1
+
+/* M25 */
+
+#define M25_MAX_CHIPS          1
+#define AO_M25_SPI_CS_PORT     0
+#define AO_M25_SPI_CS_MASK     (1 << 23)
+#define AO_M25_SPI_BUS         1
+
+/* MS5607 */
+
+#define HAS_MS5607             1
+#define HAS_MS5611             0
+#define AO_MS5607_PRIVATE_PINS 0
+#define AO_MS5607_CS_PORT      0
+#define AO_MS5607_CS_PIN       7
+#define AO_MS5607_CS_MASK      (1 << AO_MS5607_CS_PIN)
+#define AO_MS5607_MISO_PORT    0
+#define AO_MS5607_MISO_PIN     8
+#define AO_MS5607_MISO_MASK    (1 << AO_MS5607_MISO_PIN)
+#define AO_MS5607_SPI_INDEX    0
+
+#define HAS_ACCEL              0
+#define HAS_GPS                        0
+#define HAS_RADIO              0
+#define HAS_FLIGHT             1
+#define HAS_EEPROM             1
+#define HAS_TELEMETRY          0
+#define HAS_APRS               0
+#define HAS_LOG                        1
+#define USE_INTERNAL_FLASH     0
+#define HAS_IGNITE             1
+#define HAS_IGNITE_REPORT      1
+
+#define AO_DATA_RING           16
+
+/*
+ * ADC
+ */
+
+#define HAS_ADC                        1
+
+#define AO_NUM_ADC             3
+
+#define AO_ADC_0               1
+#define AO_ADC_1               1
+#define AO_ADC_2               1
+
+struct ao_adc {
+       int16_t         sense_a;
+       int16_t         sense_m;
+       int16_t         v_batt;
+};
+
+/*
+ * Igniter
+ */
+
+#define AO_IGNITER_CLOSED      400
+#define AO_IGNITER_OPEN                60
+
+#define AO_IGNITER_DROGUE_PORT 0
+#define AO_IGNITER_DROGUE_PIN  2
+#define AO_IGNITER_SET_DROGUE(v)       ao_gpio_set(AO_IGNITER_DROGUE_PORT, AO_IGNITER_DROGUE_PIN, AO_IGNITER_DROGUE, v)
+
+#define AO_IGNITER_MAIN_PORT   0
+#define AO_IGNITER_MAIN_PIN    3
+#define AO_IGNITER_SET_MAIN(v)         ao_gpio_set(AO_IGNITER_MAIN_PORT, AO_IGNITER_MAIN_PIN, AO_IGNITER_MAIN, v)
+
+#define AO_SENSE_DROGUE(p)     ((p)->adc.sense_a)
+#define AO_SENSE_MAIN(p)       ((p)->adc.sense_m)
+
+#define AO_ADC_DUMP(p) \
+       printf("tick: %5u apogee: %5d main: %5d batt: %5d\n", \
+              (p)->tick, (p)->adc.sense_a, (p)->adc.sense_m, (p)->adc.v_batt)
diff --git a/src/easymini-v1.0/flash-loader/Makefile b/src/easymini-v1.0/flash-loader/Makefile
new file mode 100644 (file)
index 0000000..78bb409
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# AltOS flash loader build
+#
+#
+
+TOPDIR=../..
+HARDWARE=easymini-v1.0
+include $(TOPDIR)/lpc/Makefile-flash.defs
diff --git a/src/easymini-v1.0/flash-loader/ao_pins.h b/src/easymini-v1.0/flash-loader/ao_pins.h
new file mode 100644 (file)
index 0000000..4330151
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2013 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.
+ */
+
+#ifndef _AO_PINS_H_
+#define _AO_PINS_H_
+
+#include <ao_flash_lpc_pins.h>
+
+#define AO_BOOT_PIN            1
+#define AO_BOOT_APPLICATION_GPIO       0
+#define AO_BOOT_APPLICATION_PIN                19
+#define AO_BOOT_APPLICATION_VALUE      1
+#define AO_BOOT_APPLICATION_MODE       AO_EXTI_MODE_PULL_UP
+
+#define HAS_USB_PULLUP 1
+#define AO_USB_PULLUP_PORT     0
+#define AO_USB_PULLUP_PIN      20
+
+#endif /* _AO_PINS_H_ */
index 6bdd204c3949113af7f2eece2c90aeb495a1acfa..ab7181b9d2be86e1e03d3c58cb1d54563dfbf329 100644 (file)
@@ -6,14 +6,16 @@ vpath ao-make-product.5c $(TOPDIR)/util
 .elf.ihx:
        objcopy -O ihex $*.elf $@
 
-CC=arm-none-eabi-gcc
-SAT=/opt/cortex
-SAT_CLIB=$(SAT)/lib/pdclib-cortex-m0.a
-SAT_CFLAGS=-I$(SAT)/include
 
 ifndef VERSION
 include $(TOPDIR)/Version
 endif
+include $(TOPDIR)/Makedefs
+
+CC=$(ARM_CC)
+SAT=/opt/cortex
+SAT_CLIB=$(SAT)/lib/pdclib-cortex-m0.a
+SAT_CFLAGS=-I$(SAT)/include
 
 AO_CFLAGS=-I. -I$(TOPDIR)/lpc -I$(TOPDIR)/core -I$(TOPDIR)/drivers -I$(TOPDIR)/product -I$(TOPDIR)
 STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m0 -mthumb -ffreestanding -nostdlib $(AO_CFLAGS) $(SAT_CFLAGS)
index 9e87cee1c8e207ed5a2912d08dd9dcabaa85118f..d541230ac354c41dc520c34693baa8a5f7714e10 100644 (file)
@@ -7,21 +7,24 @@ vpath load_csv.5c ../kalman
 vpath matrix.5c ../kalman
 vpath ao-make-product.5c ../util
 
-CC=/usr/bin/arm-none-eabi-gcc
-SAT=/opt/cortex
-SAT_CLIB=$(SAT)/lib/pdclib-cortex-m0.a
-SAT_CFLAGS=-I$(SAT)/include
-
-#CC=/opt/arm-gcc-bits/bin/arm-none-eabi-gcc
+ifndef TOPDIR
+TOPDIR=..
+endif
 
 ifndef VERSION
-include ../Version
+include $(TOPDIR)/Version
 endif
+include $(TOPDIR)/Makedefs
+
+CC=$(ARM_CC)
+SAT=/opt/cortex
+SAT_CLIB=$(SAT)/lib/pdclib-cortex-m0.a
+SAT_CFLAGS=-I$(SAT)/include
 
-AO_CFLAGS=-I. -I../lpc -I../core -I../drivers -I..
+AO_CFLAGS=-I. -I$(TOPDIR)/lpc -I$(TOPDIR)/core -I$(TOPDIR)/drivers -I$(TOPDIR)
 LPC_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m0 -mthumb -ffreestanding -nostdlib $(AO_CFLAGS) $(SAT_CFLAGS)
 
-LDFLAGS=-L../stm -Wl,-Taltos.ld
+LDFLAGS=$(LPC_CFLAGS) -L$(TOPDIR)/stm -Wl,-Taltos.ld
 
 NICKLE=nickle
 
@@ -34,10 +37,10 @@ endif
 quiet ?= $($1)
 
 .c.o:
-       $(call quiet,CC) -c $(CFLAGS) -o $@ $<
+       $(call quiet,CC) -c $(CFLAGS) $<
 
-ao_serial_lpc.h: ../lpc/baud_rate ao_pins.h
-       nickle ../lpc/baud_rate `awk '/AO_LPC_CLKOUT/{print $$3}' ao_pins.h` > $@
+ao_serial_lpc.h: $(TOPDIR)/lpc/baud_rate ao_pins.h
+       nickle $(TOPDIR)/lpc/baud_rate `awk '/AO_LPC_CLKOUT/{print $$3}' ao_pins.h` > $@
 
 ao_serial_lpc.o: ao_serial_lpc.h
 
index 9a3219a2e6275e55a6972dcdf5fff53a390b75c5..0891903ea5f00cb2adae5dbf57506fcdcb81a5c5 100644 (file)
@@ -235,6 +235,7 @@ static inline void ao_arch_start_scheduler(void) {
        asm("mrs %0,control" : "=&r" (control));
        control |= (1 << 1);
        asm("msr control,%0" : : "r" (control));
+       asm("isb");
 }
 
 #endif /* _AO_ARCH_FUNCS_H_ */
index 44e0b873a14c76acb50af5597949f1e2ba2d8155..35dfaab8bb9c16ed518d275ad355b825a7b1de89 100644 (file)
@@ -2,25 +2,19 @@
 # Tiny AltOS build
 #
 #
-vpath % ../attiny:../drivers:../core:..
+vpath % ../attiny:../drivers:../core:../product:..
 vpath ao-make-product.5c ../util
 vpath make-altitude-pa ../util
 
+include ../avr/Makefile.defs
+
 MCU=attiny85
 DUDECPUTYPE=t85
 #PROGRAMMER=stk500v2 -P usb
-PROGRAMMER=usbtiny
-LOADCMD=avrdude
 LOADSLOW=-i 32 -B 32
 LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w:
-CC=avr-gcc
-OBJCOPY=avr-objcopy
-
-LDFLAGS=-L/usr/lib/ldscripts -Tavr25.x
 
-ifndef VERSION
-include ../Version
-endif
+LDFLAGS=-L$(LDSCRIPTS) -Tavr25.x
 
 ALTOS_SRC = \
        ao_micropeak.c \
@@ -30,7 +24,7 @@ ALTOS_SRC = \
        ao_ms5607.c \
        ao_exti.c \
        ao_convert_pa.c \
-       ao_report_tiny.c \
+       ao_report_micro.c \
        ao_notask.c \
        ao_eeprom_tiny.c \
        ao_panic.c \
@@ -53,7 +47,7 @@ INC=\
 IDPRODUCT=0
 PRODUCT=MicroPeak-v0.1
 PRODUCT_DEF=-DMICROPEAK
-CFLAGS = $(PRODUCT_DEF) -I. -I../attiny -I../core -I.. -I../drivers
+CFLAGS = $(PRODUCT_DEF) -I. -I../attiny -I../core -I.. -I../drivers -I../product
 CFLAGS += -g -mmcu=$(MCU) -Wall -Wstrict-prototypes -O2 -mcall-prologues -DATTINY
 
 NICKLE=nickle
diff --git a/src/micropeak/ao_async.c b/src/micropeak/ao_async.c
deleted file mode 100644 (file)
index 3556f54..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright © 2012 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.
- */
-
-#include <ao.h>
-#include <ao_async.h>
-
-#define AO_ASYNC_BAUD  38400l
-#define AO_ASYNC_DELAY (uint8_t) (1000000l / AO_ASYNC_BAUD)
-
-#define LED_PORT       PORTB
-
-void
-ao_async_start(void)
-{
-       LED_PORT |= (1 << AO_LED_SERIAL);
-}
-
-void
-ao_async_stop(void)
-{
-       LED_PORT &= ~(1 << AO_LED_SERIAL);
-}
-
-void
-ao_async_byte(uint8_t byte)
-{
-       uint8_t         b;
-       uint16_t        w;
-
-       /*    start           data           stop */
-       w = (0x000 << 0) | (byte << 1) | (0x001 << 9);
-
-       ao_arch_block_interrupts();
-       for (b = 0; b < 10; b++) {
-               uint8_t v = LED_PORT & ~(1 << AO_LED_SERIAL);
-               v |= (w & 1) << AO_LED_SERIAL;
-               LED_PORT = v;
-               w >>= 1;
-
-               /* Carefully timed to hit around 9600 baud */
-               asm volatile ("nop");
-               asm volatile ("nop");
-
-               asm volatile ("nop");
-               asm volatile ("nop");
-               asm volatile ("nop");
-               asm volatile ("nop");
-               asm volatile ("nop");
-
-               asm volatile ("nop");
-               asm volatile ("nop");
-               asm volatile ("nop");
-               asm volatile ("nop");
-               asm volatile ("nop");
-       }
-       ao_arch_release_interrupts();
-}
diff --git a/src/micropeak/ao_async.h b/src/micropeak/ao_async.h
deleted file mode 100644 (file)
index 1b23971..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright © 2012 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.
- */
-
-#ifndef _AO_ASYNC_H_
-#define _AO_ASYNC_H_
-
-void
-ao_async_start(void);
-
-void
-ao_async_stop(void);
-
-void
-ao_async_byte(uint8_t byte);
-
-#endif /* _AO_ASYNC_H_ */
diff --git a/src/micropeak/ao_log_micro.c b/src/micropeak/ao_log_micro.c
deleted file mode 100644 (file)
index d665efb..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright © 2012 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.
- */
-
-#include <ao.h>
-#include <ao_micropeak.h>
-#include <ao_log_micro.h>
-#include <ao_async.h>
-
-static uint16_t ao_log_offset = STARTING_LOG_OFFSET;
-
-void
-ao_log_micro_save(void)
-{
-       uint16_t        n_samples = (ao_log_offset - STARTING_LOG_OFFSET) / sizeof (uint16_t);
-       ao_eeprom_write(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground));
-       ao_eeprom_write(PA_MIN_OFFSET, &pa_min, sizeof (pa_min));
-       ao_eeprom_write(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
-}
-
-void
-ao_log_micro_restore(void)
-{
-       ao_eeprom_read(PA_GROUND_OFFSET, &pa_ground, sizeof (pa_ground));
-       ao_eeprom_read(PA_MIN_OFFSET, &pa_min, sizeof (pa_min));
-}
-
-void
-ao_log_micro_data(void)
-{
-       uint16_t        low_bits = pa;
-
-       if (ao_log_offset < MAX_LOG_OFFSET) {
-               ao_eeprom_write(ao_log_offset, &low_bits, sizeof (low_bits));
-               ao_log_offset += sizeof (low_bits);
-       }
-}
-
-#define POLY 0x8408
-
-static uint16_t
-ao_log_micro_crc(uint16_t crc, uint8_t byte)
-{
-       uint8_t i;
-
-       for (i = 0; i < 8; i++) {
-               if ((crc & 0x0001) ^ (byte & 0x0001))
-                       crc = (crc >> 1) ^ POLY;
-               else
-                       crc = crc >> 1;
-               byte >>= 1;
-       }
-       return crc;
-}
-
-static void
-ao_log_hex_nibble(uint8_t b)
-{
-       if (b < 10)
-               ao_async_byte('0' + b);
-       else
-               ao_async_byte('a' - 10 + b);
-}
-
-static void
-ao_log_hex(uint8_t b)
-{
-       ao_log_hex_nibble(b>>4);
-       ao_log_hex_nibble(b&0xf);
-}
-
-static void
-ao_log_newline(void)
-{
-       ao_async_byte('\r');
-       ao_async_byte('\n');
-}
-
-void
-ao_log_micro_dump(void)
-{
-       uint16_t        n_samples;
-       uint16_t        nbytes;
-       uint8_t         byte;
-       uint16_t        b;
-       uint16_t        crc = 0xffff;
-
-       ao_eeprom_read(N_SAMPLES_OFFSET, &n_samples, sizeof (n_samples));
-       if (n_samples == 0xffff)
-               n_samples = 0;
-       nbytes = STARTING_LOG_OFFSET + sizeof (uint16_t) * n_samples;
-       ao_async_start();
-       ao_async_byte('M');
-       ao_async_byte('P');
-       for (b = 0; b < nbytes; b++) {
-               if ((b & 0xf) == 0)
-                       ao_log_newline();
-               ao_eeprom_read(b, &byte, 1);
-               ao_log_hex(byte);
-               crc = ao_log_micro_crc(crc, byte);
-       }
-       ao_log_newline();
-       crc = ~crc;
-       ao_log_hex(crc >> 8);
-       ao_log_hex(crc);
-       ao_log_newline();
-       ao_async_stop();
-}
diff --git a/src/micropeak/ao_log_micro.h b/src/micropeak/ao_log_micro.h
deleted file mode 100644 (file)
index 976852e..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright © 2012 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.
- */
-
-#ifndef _AO_LOG_MICRO_H_
-#define _AO_LOG_MICRO_H_
-
-#define PA_GROUND_OFFSET       0
-#define PA_MIN_OFFSET          4
-#define N_SAMPLES_OFFSET       8
-#define STARTING_LOG_OFFSET    10
-#define MAX_LOG_OFFSET         512
-
-void
-ao_log_micro_save(void);
-
-void
-ao_log_micro_restore(void);
-
-void
-ao_log_micro_data(void);
-
-void
-ao_log_micro_dump(void);
-
-#endif /* _AO_LOG_MICRO_H_ */
diff --git a/src/micropeak/ao_microflight.c b/src/micropeak/ao_microflight.c
deleted file mode 100644 (file)
index 714bb90..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright © 2013 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.
- */
-
-#ifndef AO_FLIGHT_TEST
-#include <ao.h>
-#endif
-#include <ao_micropeak.h>
-#include <ao_log_micro.h>
-
-uint32_t       pa;
-uint32_t       pa_ground;
-uint32_t       pa_min;
-
-static void
-ao_microsample(void)
-{
-       ao_pa_get();
-       ao_microkalman_predict();
-       ao_microkalman_correct();
-}
-
-#define NUM_PA_HIST    16
-
-#define SKIP_PA_HIST(i,j)      (((i) + (j)) & (NUM_PA_HIST - 1))
-
-static uint32_t        pa_hist[NUM_PA_HIST];
-
-void
-ao_microflight(void)
-{
-       int16_t         sample_count;
-       uint16_t        time;
-       uint32_t        pa_interval_min, pa_interval_max;
-       int32_t         pa_diff;
-       uint8_t         h, i;
-       uint8_t         accel_lock = 0;
-       uint32_t        pa_sum = 0;
-
-       /* Wait for motion, averaging values to get ground pressure */
-
-       time = ao_time();
-       ao_pa_get();
-       ao_microkalman_init();
-       pa_ground = pa;
-       sample_count = 0;
-       h = 0;
-       for (;;) {
-               time += SAMPLE_SLEEP;
-               if (sample_count == 0)
-                       ao_led_on(AO_LED_REPORT);
-               ao_delay_until(time);
-               ao_microsample();
-               if (sample_count == 0)
-                       ao_led_off(AO_LED_REPORT);
-               pa_hist[h] = pa;
-               h = SKIP_PA_HIST(h,1);
-               pa_diff = pa_ground - ao_pa;
-
-               /* Check for a significant pressure change */
-               if (pa_diff > BOOST_DETECT)
-                       break;
-
-               if (sample_count < GROUND_AVG * 2) {
-                       if (sample_count < GROUND_AVG)
-                               pa_sum += pa;
-                       ++sample_count;
-               } else {
-                       pa_ground = pa_sum >> GROUND_AVG_SHIFT;
-                       pa_sum = 0;
-                       sample_count = 0;
-               }
-       }
-
-       /* Go back and find the first sample a decent interval above the ground */
-       pa_min = pa_ground - LAND_DETECT;
-       for (i = SKIP_PA_HIST(h,2); i != h; i = SKIP_PA_HIST(i,2)) {
-               if (pa_hist[i] < pa_min)
-                       break;
-       }
-
-       /* Log the remaining samples so we get a complete history since leaving the ground */
-       for (; i != h; i = SKIP_PA_HIST(i,2)) {
-               pa = pa_hist[i];
-               ao_log_micro_data();
-       }
-
-       /* Now sit around until the pressure is stable again and record the max */
-
-       sample_count = 0;
-       pa_min = ao_pa;
-       pa_interval_min = ao_pa;
-       pa_interval_max = ao_pa;
-       for (;;) {
-               time += SAMPLE_SLEEP;
-               ao_delay_until(time);
-               if ((sample_count & 3) == 0)
-                       ao_led_on(AO_LED_REPORT);
-               ao_microsample();
-               if ((sample_count & 3) == 0)
-                       ao_led_off(AO_LED_REPORT);
-               if (sample_count & 1)
-                       ao_log_micro_data();
-
-               /* If accelerating upwards, don't look for min pressure */
-               if (ao_pa_accel < ACCEL_LOCK_PA)
-                       accel_lock = ACCEL_LOCK_TIME;
-               else if (accel_lock)
-                       --accel_lock;
-               else if (ao_pa < pa_min)
-                       pa_min = ao_pa;
-
-               if (sample_count == (GROUND_AVG - 1)) {
-                       pa_diff = pa_interval_max - pa_interval_min;
-
-                       /* Check to see if the pressure is now stable */
-                       if (pa_diff < LAND_DETECT)
-                               break;
-                       sample_count = 0;
-                       pa_interval_min = ao_pa;
-                       pa_interval_max = ao_pa;
-               } else {
-                       if (ao_pa < pa_interval_min)
-                               pa_interval_min = ao_pa;
-                       if (ao_pa > pa_interval_max)
-                               pa_interval_max = ao_pa;
-                       ++sample_count;
-               }
-       }
-}
diff --git a/src/micropeak/ao_microkalman.c b/src/micropeak/ao_microkalman.c
deleted file mode 100644 (file)
index 0684ea2..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright © 2013 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.
- */
-
-#ifndef AO_FLIGHT_TEST
-#include <ao.h>
-#endif
-#include <ao_micropeak.h>
-
-#define FIX_BITS       16
-
-#define to_fix16(x) ((int16_t) ((x) * 65536.0 + 0.5))
-#define to_fix32(x) ((int32_t) ((x) * 65536.0 + 0.5))
-#define from_fix8(x)   ((x) >> 8)
-#define from_fix(x)    ((x) >> 16)
-#define fix8_to_fix16(x)       ((x) << 8)
-#define fix16_to_fix8(x)       ((x) >> 8)
-
-#include <ao_kalman.h>
-
-/* Basic time step (96ms) */
-#define AO_MK_STEP     to_fix16(0.096)
-/* step ** 2 / 2 */
-#define AO_MK_STEP_2_2 to_fix16(0.004608)
-
-uint32_t       ao_k_pa;                /* 24.8 fixed point */
-int32_t                ao_k_pa_speed;          /* 16.16 fixed point */
-int32_t                ao_k_pa_accel;          /* 16.16 fixed point */
-
-uint32_t       ao_pa;                  /* integer portion */
-int16_t                ao_pa_speed;            /* integer portion */
-int16_t                ao_pa_accel;            /* integer portion */
-
-void
-ao_microkalman_init(void)
-{
-       ao_pa = pa;
-       ao_k_pa = pa << 8;
-}      
-
-void
-ao_microkalman_predict(void)
-{
-       ao_k_pa       += fix16_to_fix8((int32_t) ao_pa_speed * AO_MK_STEP + (int32_t) ao_pa_accel * AO_MK_STEP_2_2);
-       ao_k_pa_speed += (int32_t) ao_pa_accel * AO_MK_STEP;
-}
-
-void
-ao_microkalman_correct(void)
-{
-       int16_t e;      /* Height error in Pa */
-
-       e = pa - from_fix8(ao_k_pa);
-
-       ao_k_pa       += fix16_to_fix8((int32_t) e * AO_MK_BARO_K0_10);
-       ao_k_pa_speed += (int32_t) e * AO_MK_BARO_K1_10;
-       ao_k_pa_accel += (int32_t) e * AO_MK_BARO_K2_10;
-       ao_pa = from_fix8(ao_k_pa);
-       ao_pa_speed = from_fix(ao_k_pa_speed);
-       ao_pa_accel = from_fix(ao_k_pa_accel);
-}
diff --git a/src/micropeak/ao_micropeak.c b/src/micropeak/ao_micropeak.c
deleted file mode 100644 (file)
index 10f0d19..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright © 2012 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.
- */
-
-#include <ao.h>
-#include <ao_micropeak.h>
-#include <ao_ms5607.h>
-#include <ao_log_micro.h>
-#include <ao_async.h>
-
-static struct ao_ms5607_sample sample;
-static struct ao_ms5607_value  value;
-
-alt_t          ground_alt, max_alt;
-alt_t          ao_max_height;
-
-void
-ao_pa_get(void)
-{
-       ao_ms5607_sample(&sample);
-       ao_ms5607_convert(&sample, &value);
-       pa = value.pres;
-}
-
-static void
-ao_compute_height(void)
-{
-       ground_alt = ao_pa_to_altitude(pa_ground);
-       max_alt = ao_pa_to_altitude(pa_min);
-       ao_max_height = max_alt - ground_alt;
-}
-
-static void
-ao_pips(void)
-{
-       uint8_t i;
-       for (i = 0; i < 10; i++) {
-               ao_led_toggle(AO_LED_REPORT);
-               ao_delay(AO_MS_TO_TICKS(80));
-       }
-       ao_delay(AO_MS_TO_TICKS(200));
-}
-
-int
-main(void)
-{
-       ao_led_init(LEDS_AVAILABLE);
-       ao_timer_init();
-
-       /* Init external hardware */
-       ao_spi_init();
-       ao_ms5607_init();
-       ao_ms5607_setup();
-
-       /* Give the person a second to get their finger out of the way */
-       ao_delay(AO_MS_TO_TICKS(1000));
-
-       ao_log_micro_restore();
-       ao_compute_height();
-       ao_report_altitude();
-       ao_pips();
-       ao_log_micro_dump();
-       
-       ao_delay(BOOST_DELAY);
-
-       ao_microflight();
-
-       ao_log_micro_save();
-       ao_compute_height();
-       ao_report_altitude();
-       for (;;) {
-               cli();
-               set_sleep_mode(SLEEP_MODE_PWR_DOWN);
-               sleep_mode();
-       }
-}
diff --git a/src/micropeak/ao_micropeak.h b/src/micropeak/ao_micropeak.h
deleted file mode 100644 (file)
index 382b98d..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright © 2012 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.
- */
-
-#ifndef _AO_MICROPEAK_H_
-#define _AO_MICROPEAK_H_
-
-#define SAMPLE_SLEEP           AO_MS_TO_TICKS(96)
-
-/* 16 sample, or about two seconds worth */
-#define GROUND_AVG_SHIFT       4
-#define GROUND_AVG             (1 << GROUND_AVG_SHIFT)
-
-/* Pressure change (in Pa) to detect boost */
-#define BOOST_DETECT           120     /* 10m at sea level, 12m at 2000m */
-
-/* Wait after power on before doing anything to give the user time to assemble the rocket */
-#define BOOST_DELAY            AO_SEC_TO_TICKS(30)
-
-/* Pressure change (in Pa) to detect landing */
-#define LAND_DETECT            24      /* 2m at sea level, 2.4m at 2000m */
-
-/* Current sensor pressure value */
-extern uint32_t        pa;
-
-/* Average pressure value on ground */
-extern uint32_t        pa_ground;
-
-/* Minimum recorded filtered pressure value */
-extern uint32_t        pa_min;
-
-/* Pressure values converted to altitudes */
-extern alt_t   ground_alt, max_alt;
-
-/* max_alt - ground_alt */
-extern alt_t   ao_max_height;
-
-void
-ao_pa_get(void);
-
-void
-ao_microflight(void);
-
-#define ACCEL_LOCK_PA          -20
-#define ACCEL_LOCK_TIME                10
-
-extern uint32_t        ao_k_pa;                /* 24.8 fixed point */
-extern int32_t ao_k_pa_speed;          /* 16.16 fixed point */
-extern int32_t ao_k_pa_accel;          /* 16.16 fixed point */
-
-extern uint32_t        ao_pa;                  /* integer portion */
-extern int16_t ao_pa_speed;            /* integer portion */
-extern int16_t ao_pa_accel;            /* integer portion */
-
-void
-ao_microkalman_init(void);
-
-void
-ao_microkalman_predict(void);
-
-void
-ao_microkalman_correct(void);
-       
-#endif
-
diff --git a/src/micropeak/ao_report_tiny.c b/src/micropeak/ao_report_tiny.c
deleted file mode 100644 (file)
index 0e8e287..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright © 2012 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.
- */
-
-#include <ao.h>
-
-#define mid(time)      ao_led_for(AO_LED_REPORT, time)
-#define pause(time)    ao_delay(time)
-
-static void
-ao_report_digit(uint8_t digit) __reentrant
-{
-       if (!digit) {
-               mid(AO_MS_TO_TICKS(1000));
-               pause(AO_MS_TO_TICKS(300));
-       } else {
-               while (digit--) {
-                       mid(AO_MS_TO_TICKS(300));
-                       pause(AO_MS_TO_TICKS(300));
-               }
-       }
-       pause(AO_MS_TO_TICKS(1000));
-}
-
-void
-ao_report_altitude(void)
-{
-       __pdata alt_t   agl = ao_max_height;
-       static __xdata uint8_t  digits[11];
-       __pdata uint8_t ndigits, i;
-
-       if (agl < 0)
-               agl = 0;
-       ndigits = 0;
-       do {
-               digits[ndigits++] = agl % 10;
-               agl /= 10;
-       } while (agl);
-
-       i = ndigits;
-       do
-               ao_report_digit(digits[--i]);
-       while (i != 0);
-}
diff --git a/src/nanopeak-v0.1/.gitignore b/src/nanopeak-v0.1/.gitignore
new file mode 100644 (file)
index 0000000..27cd0a7
--- /dev/null
@@ -0,0 +1,2 @@
+ao_product.h
+nanopeak-*
diff --git a/src/nanopeak-v0.1/Makefile b/src/nanopeak-v0.1/Makefile
new file mode 100644 (file)
index 0000000..154d78f
--- /dev/null
@@ -0,0 +1,108 @@
+#
+# Tiny AltOS build
+#
+#
+vpath % ../attiny:../drivers:../core:../product:..
+vpath ao-make-product.5c ../util
+vpath make-altitude-pa ../util
+
+include ../avr/Makefile.defs
+
+MCU=attiny85
+DUDECPUTYPE=t85
+#PROGRAMMER=stk500v2 -P usb
+LOADSLOW=-i 32 -B 32
+LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w:
+
+LDFLAGS=-L$(LDSCRIPTS) -Tavr25.x
+
+ALTOS_SRC = \
+       ao_micropeak.c \
+       ao_spi_attiny.c \
+       ao_led.c \
+       ao_clock.c \
+       ao_ms5607.c \
+       ao_exti.c \
+       ao_convert_pa.c \
+       ao_report_micro.c \
+       ao_notask.c \
+       ao_eeprom_tiny.c \
+       ao_panic.c \
+       ao_log_micro.c \
+       ao_async.c \
+       ao_microflight.c \
+       ao_microkalman.c
+
+INC=\
+       ao.h \
+       ao_pins.h \
+       ao_arch.h \
+       ao_arch_funcs.h \
+       ao_exti.h \
+       ao_ms5607.h \
+       ao_log_micro.h \
+       ao_micropeak.h \
+       altitude-pa.h
+
+IDPRODUCT=0
+PRODUCT=NanoPeak-v0.1
+PRODUCT_DEF=-DNANOPEAK
+CFLAGS = $(PRODUCT_DEF) -I. -I../attiny -I../core -I.. -I../drivers -I../product
+CFLAGS += -g -mmcu=$(MCU) -Wall -Wstrict-prototypes -O2 -mcall-prologues -DATTINY
+
+NICKLE=nickle
+
+PROG=nanopeak-v0.1
+
+SRC=$(ALTOS_SRC)
+OBJ=$(SRC:.c=.o)
+
+V=0
+# The user has explicitly enabled quiet compilation.
+ifeq ($(V),0)
+quiet = @printf "  $1 $2 $@\n"; $($1)
+endif
+# Otherwise, print the full command line.
+quiet ?= $($1)
+
+all: $(PROG) $(PROG).hex
+
+CHECK=sh ../util/check-avr-mem
+
+$(PROG): Makefile $(OBJ)
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(OBJ)
+       $(call quiet,CHECK) $(PROG) || ($(RM) -f $(PROG); exit 1)
+
+$(PROG).hex: $(PROG)
+       avr-size $(PROG)
+       $(OBJCOPY) -R .eeprom -O ihex $(PROG) $@
+
+
+load: $(PROG).hex
+       $(LOADCMD) $(LOADARG)$(PROG).hex
+
+load-slow: $(PROG).hex
+       $(LOADCMD) $(LOADSLOW) $(LOADARG)$(PROG).hex
+
+ao_product.h: ao-make-product.5c ../Version
+       $(call quiet,NICKLE,$<) $< -m altusmetrum.org -i $(IDPRODUCT) -p $(PRODUCT) -v $(VERSION) > $@
+
+ao_product.o: ao_product.c ao_product.h
+
+%.o : %.c $(INC)
+       $(call quiet,CC) -c $(CFLAGS) $<
+
+distclean:     clean
+
+clean:
+       rm -f *.o $(PROG) $(PROG).hex
+       rm -f ao_product.h
+
+../altitude-pa.h: make-altitude-pa
+       nickle $< > $@
+
+install:
+
+uninstall:
+
+$(OBJ): ao_product.h $(INC)
diff --git a/src/nanopeak-v0.1/ao_pins.h b/src/nanopeak-v0.1/ao_pins.h
new file mode 100644 (file)
index 0000000..bd4a06d
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2011 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.
+ */
+
+#ifndef _AO_PINS_H_
+#define _AO_PINS_H_
+#include <avr/pgmspace.h>
+
+#define AO_LED_ORANGE          (1<<3)
+#define AO_LED_SERIAL          3
+#define AO_LED_PANIC           AO_LED_ORANGE
+#define AO_LED_REPORT          AO_LED_ORANGE
+#define LEDS_AVAILABLE         (AO_LED_ORANGE)
+#define USE_SERIAL_1_STDIN     0
+#define HAS_USB                        0
+#define PACKET_HAS_SLAVE       0
+#define HAS_SERIAL_1           0
+#define HAS_TASK               0
+#define HAS_MS5607             1
+#define HAS_MS5611             0
+#define HAS_EEPROM             0
+#define HAS_BEEP               0
+#define AVR_CLOCK              250000UL
+
+/* SPI */
+#define SPI_PORT               PORTB
+#define SPI_PIN                        PINB
+#define SPI_DIR                        DDRB
+#define AO_MS5607_CS_PORT      PORTB
+#define AO_MS5607_CS_PIN       4
+
+/* MS5607 */
+#define AO_MS5607_SPI_INDEX    0
+#define AO_MS5607_MISO_PORT    PORTB
+#define AO_MS5607_MISO_PIN     0
+#define AO_MS5607_BARO_OVERSAMPLE      4096
+#define AO_MS5607_TEMP_OVERSAMPLE      1024
+
+/* I2C */
+#define I2C_PORT               PORTB
+#define I2C_PIN                        PINB
+#define I2C_DIR                        DDRB
+#define I2C_PIN_SCL            PINB2
+#define I2C_PIN_SDA            PINB0
+
+#define AO_CONST_ATTRIB                PROGMEM
+typedef int32_t alt_t;
+#define FETCH_ALT(o)           ((alt_t) pgm_read_dword(&altitude_table[o]))
+
+#define AO_ALT_VALUE(x)                ((x) * (alt_t) 10)
+
+#endif /* _AO_PINS_H_ */
index 3101b77706593c3f09350e71726ad05ff6bcb1b2..da9bcba04597487776c62fe6efd5ee444ba431a7 100644 (file)
@@ -80,9 +80,9 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
+$(PROG): $(REL) Makefile
        $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
index 1e55989c36e07eeb2acb8c9bf7d2717bfeceb38f..a5e2eb7fb12912afbcb7db443e2fccd57f78b8f4 100644 (file)
@@ -82,9 +82,9 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
+$(PROG): $(REL) Makefile
        $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM)  || rm $@
 
index 5e3eed7f96cdfb33eaae6f0d2075cb724bb5766d..c740a4831149325ca8bf67965847696de6150598 100644 (file)
@@ -94,10 +94,10 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+$(PROG): $(REL) Makefile
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index ef8906badf6d90417d8123b4afaae115bef08327..0884079eb701543cc090c3e0ea7358b0c4ac1123 100644 (file)
@@ -83,10 +83,10 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+$(PROG): $(REL) Makefile
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index 67410ae0bd5332b8f3e15840ca087b71c850fae6..c31989eedf2fa213837923961da8cb7604e2d777 100644 (file)
@@ -82,9 +82,9 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
+$(PROG): $(REL) Makefile
        $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
index 439ba75cecc8fe04fad50dc61e3cc1f7905d08b1..dd67d820ea0f99f7cae75873448f1c9bdf4d247b 100644 (file)
@@ -35,7 +35,6 @@
 #define HAS_VERSION            0
 
 #define AO_BOOT_CHAIN          1
-#define AO_BOOT_PIN            1
 
 #define IS_FLASH_LOADER                1
 
diff --git a/src/product/ao_micropeak.c b/src/product/ao_micropeak.c
new file mode 100644 (file)
index 0000000..10f0d19
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright © 2012 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.
+ */
+
+#include <ao.h>
+#include <ao_micropeak.h>
+#include <ao_ms5607.h>
+#include <ao_log_micro.h>
+#include <ao_async.h>
+
+static struct ao_ms5607_sample sample;
+static struct ao_ms5607_value  value;
+
+alt_t          ground_alt, max_alt;
+alt_t          ao_max_height;
+
+void
+ao_pa_get(void)
+{
+       ao_ms5607_sample(&sample);
+       ao_ms5607_convert(&sample, &value);
+       pa = value.pres;
+}
+
+static void
+ao_compute_height(void)
+{
+       ground_alt = ao_pa_to_altitude(pa_ground);
+       max_alt = ao_pa_to_altitude(pa_min);
+       ao_max_height = max_alt - ground_alt;
+}
+
+static void
+ao_pips(void)
+{
+       uint8_t i;
+       for (i = 0; i < 10; i++) {
+               ao_led_toggle(AO_LED_REPORT);
+               ao_delay(AO_MS_TO_TICKS(80));
+       }
+       ao_delay(AO_MS_TO_TICKS(200));
+}
+
+int
+main(void)
+{
+       ao_led_init(LEDS_AVAILABLE);
+       ao_timer_init();
+
+       /* Init external hardware */
+       ao_spi_init();
+       ao_ms5607_init();
+       ao_ms5607_setup();
+
+       /* Give the person a second to get their finger out of the way */
+       ao_delay(AO_MS_TO_TICKS(1000));
+
+       ao_log_micro_restore();
+       ao_compute_height();
+       ao_report_altitude();
+       ao_pips();
+       ao_log_micro_dump();
+       
+       ao_delay(BOOST_DELAY);
+
+       ao_microflight();
+
+       ao_log_micro_save();
+       ao_compute_height();
+       ao_report_altitude();
+       for (;;) {
+               cli();
+               set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+               sleep_mode();
+       }
+}
diff --git a/src/product/ao_micropeak.h b/src/product/ao_micropeak.h
new file mode 100644 (file)
index 0000000..3e3dec1
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright © 2012 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.
+ */
+
+#ifndef _AO_MICROPEAK_H_
+#define _AO_MICROPEAK_H_
+
+#define SAMPLE_SLEEP           AO_MS_TO_TICKS(96)
+
+/* 16 sample, or about two seconds worth */
+#define GROUND_AVG_SHIFT       4
+#define GROUND_AVG             (1 << GROUND_AVG_SHIFT)
+
+/* Pressure change (in Pa) to detect boost */
+#define BOOST_DETECT           120     /* 10m at sea level, 12m at 2000m */
+
+/* Wait after power on before doing anything to give the user time to assemble the rocket */
+#define BOOST_DELAY            AO_SEC_TO_TICKS(60)
+
+/* Pressure change (in Pa) to detect landing */
+#define LAND_DETECT            24      /* 2m at sea level, 2.4m at 2000m */
+
+/* Current sensor pressure value */
+extern uint32_t        pa;
+
+/* Average pressure value on ground */
+extern uint32_t        pa_ground;
+
+/* Minimum recorded filtered pressure value */
+extern uint32_t        pa_min;
+
+/* Pressure values converted to altitudes */
+extern alt_t   ground_alt, max_alt;
+
+/* max_alt - ground_alt */
+extern alt_t   ao_max_height;
+
+void
+ao_pa_get(void);
+
+void
+ao_microflight(void);
+
+#define ACCEL_LOCK_PA          -20
+#define ACCEL_LOCK_TIME                10
+
+extern uint32_t        ao_k_pa;                /* 24.8 fixed point */
+extern int32_t ao_k_pa_speed;          /* 16.16 fixed point */
+extern int32_t ao_k_pa_accel;          /* 16.16 fixed point */
+
+extern uint32_t        ao_pa;                  /* integer portion */
+extern int16_t ao_pa_speed;            /* integer portion */
+extern int16_t ao_pa_accel;            /* integer portion */
+
+void
+ao_microkalman_init(void);
+
+void
+ao_microkalman_predict(void);
+
+void
+ao_microkalman_correct(void);
+       
+#endif
+
index a207d34f50562b6470e9e2f1d7a8bec660b8dbee..e644bc49d64785798682282b804fa1dc984fa7ab 100644 (file)
@@ -73,10 +73,10 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+$(PROG): $(REL) Makefile
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM)  || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index 86f76d46e74f66b0e286ce0257436ab991b3f886..f429d9bda7663b1ab65c7975022cdfbb84d18177 100644 (file)
@@ -6,14 +6,15 @@ vpath ao-make-product.5c $(TOPDIR)/util
 .elf.ihx:
        objcopy -O ihex $*.elf $@
 
-CC=/opt/cortex/bin/arm-none-eabi-gcc
-SAT=/opt/cortex
-SAT_CLIB=$(SAT)/lib/pdclib-cortex-m3.a
-SAT_CFLAGS=-I$(SAT)/include
-
 ifndef VERSION
 include $(TOPDIR)/Version
 endif
+include $(TOPDIR)/Makedefs
+
+CC=$(ARM_CC)
+SAT=/opt/cortex
+SAT_CLIB=$(SAT)/lib/pdclib-cortex-m3.a
+SAT_CFLAGS=-I$(SAT)/include
 
 AO_CFLAGS=-I. -I$(TOPDIR)/stm -I$(TOPDIR)/core -I$(TOPDIR)/drivers -I$(TOPDIR)/product -I$(TOPDIR)
 STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb -ffreestanding -nostdlib $(AO_CFLAGS) $(SAT_CFLAGS)
index 8ef30521ee4645e63a60afc531ea5841d0abeaf8..ede75f80e4745eef929d70923203d631a3a52628 100644 (file)
@@ -12,14 +12,19 @@ vpath ao-make-product.5c ../util
 .elf.ihx:
        objcopy -O ihex $*.elf $@
 
-SAT=/opt/cortex
-CC=$(SAT)/bin/arm-none-eabi-gcc
-SAT_CLIB=$(SAT)/lib/pdclib-cortex-m3.a
-SAT_CFLAGS=-I$(SAT)/include
+ifndef TOPDIR
+TOPDIR=..
+endif
 
 ifndef VERSION
-include ../Version
+include $(TOPDIR)/Version
 endif
+include $(TOPDIR)/Makedefs
+
+CC=$(ARM_CC)
+SAT=/opt/cortex
+SAT_CLIB=$(SAT)/lib/pdclib-cortex-m3.a
+SAT_CFLAGS=-I$(SAT)/include
 
 AO_CFLAGS=-I. -I../stm -I../core -I../drivers -I..
 STM_CFLAGS=-std=gnu99 -mlittle-endian -mcpu=cortex-m3 -mthumb -ffreestanding -nostdlib $(AO_CFLAGS) $(SAT_CFLAGS)
index 9bb2d7cd5d830c158bd0dbbeb01ec3a39b63d64c..b461cd3fbf81dd9f32dac82894ea96d7c5bdaad7 100644 (file)
@@ -329,7 +329,7 @@ static inline void ao_arch_restore_stack(void) {
 
        /* Restore APSR */
        asm("pop {r0}");
-       asm("msr apsr,r0");
+       asm("msr apsr_nczvq,r0");
 
        /* Restore general registers */
        asm("pop {r0-r12,lr}\n");
@@ -354,6 +354,7 @@ static inline void ao_arch_start_scheduler(void) {
        asm("mrs %0,control" : "=&r" (control));
        control |= (1 << 1);
        asm("msr control,%0" : : "r" (control));
+       asm("isb");
 }
 #endif
 
index 2eea996e7166762202f8864e17afa10beb087efc..6ff076a9c8598a28b922b6a7b59c215fe6dc6e7b 100644 (file)
@@ -103,7 +103,7 @@ quiet ?= $($1)
 all: $(PROG)
 
 $(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index 911a8b09e11d06712c89ea6e4a49a898b3e42913..40853fc3cc04d083686fe4e54b46242ec5e0f778 100644 (file)
@@ -82,7 +82,7 @@ quiet ?= $($1)
 all: $(PROG)
 
 $(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index 712b2e8b8bfb57d1925a174989d9b609b10e1264..f9e116983bea0c26545a903c6861410125708627 100644 (file)
@@ -84,10 +84,10 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+$(PROG): $(REL) Makefile
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM)  || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index 3353bc1a47740ee5dc6064e5a4cbcfabb3363f46..a820990a6edd8663ca0657e083037067f9c01388 100644 (file)
@@ -84,10 +84,10 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+$(PROG): $(REL) Makefile
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM)  || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index f9f62316f0396ec7d602d5817eea3af010478f9b..608817e7601a788d2e7da1241a44faa91ffabfdd 100644 (file)
@@ -49,6 +49,7 @@ main(void)
        ao_gps_init();
 #if HAS_LOG
        ao_gps_report_mega_init();
+       ao_log_init();
 #endif
 
        ao_telemetry_init();
index e365417d348ba157765f96adcfd0b4e5704ce429..d79aba5405552666fda821b3b877b450f98c4d69 100644 (file)
@@ -42,7 +42,7 @@ main(void)
        ao_task_init();
        ao_serial_init();
        ao_led_init(LEDS_AVAILABLE);
-       ao_led_on(AO_LED_GREEN);
+       ao_led_on(AO_LED_RED);
        ao_timer_init();
 
        ao_spi_init();
index 40878778268af832cefd0aaa6030db6a286b6c9b..fcac2c48faeb657cf4eb5b35fb4f6de4568311bb 100644 (file)
@@ -81,7 +81,7 @@ PROGNAME = telemini-v$(TELEMINI_VER)
 PROG = $(PROGNAME)-$(VERSION).ihx
 PRODUCT=TeleMini-v$(TELEMINI_VER)
 PRODUCT_DEF=-DTELEMINI_V_$(TELEMINI_DEF)
-IDPRODUCT=0x000a
+IDPRODUCT=0x0027
 
 include ../cc1111/Makefile.cc1111
 
@@ -96,10 +96,10 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+$(PROG): $(REL) Makefile
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index 264ad16d9154172d65d544f5cf0e71da7d134d33..c4681ee28a90eb9049f3bfd38dfe7282435de8cd 100644 (file)
 #define AO_IGNITER_CHARGE_TIME AO_MS_TO_TICKS(2000)
 
 #define AO_SEND_MINI
+#define AO_LOG_FORMAT          AO_LOG_FORMAT_TELEMINI
 
 /*
  * ADC
index 294f768a5dd188ec8ce90acf050d79834e57a82d..0d8dd1cb637785bdffe8f7f4794e3c25ddba80b4 100644 (file)
@@ -24,36 +24,42 @@ __xdata uint8_t ao_force_freq;
 void
 main(void)
 {
-       /*
-        * Reduce the transient on the ignite pins at startup by
-        * pulling the pins low as soon as possible at power up
-        */
-       ao_ignite_set_pins();
-
        ao_clock_init();
 
+#if HAS_STACK_GUARD
+       ao_mpu_init();
+#endif
+       ao_task_init();
+
        /* Turn on the red LED until the system is stable */
        ao_led_init(LEDS_AVAILABLE);
        ao_led_on(AO_LED_RED);
 
-       ao_task_init();
-
        ao_timer_init();
+
+       ao_spi_init();
+       ao_exti_init();
        ao_adc_init();
+#if HAS_BEEP
        ao_beep_init();
+#endif
        ao_cmd_init();
-       ao_spi_init();
-       ao_exti_init();
+#if HAS_MS5607
        ao_ms5607_init();
+#endif
        ao_storage_init();
+
        ao_flight_init();
        ao_log_init();
        ao_report_init();
+
        ao_usb_init();
        ao_telemetry_init();
        ao_radio_init();
        ao_packet_slave_init(TRUE);
+
        ao_igniter_init();
+
        ao_config_init();
        ao_start_scheduler();
 }
index 6743ba66db37c9a30f2c690580dfa35611bd0d16..025b324a360833c6befa99fb84b4aab561713c5d 100644 (file)
@@ -5,18 +5,12 @@
 vpath % .:..:../core:../product:../drivers:../avr
 vpath ao-make-product.5c ../util
 
+include ../avr/Makefile.defs
+
 MCU=atmega32u4
 DUDECPUTYPE=m32u4
 #PROGRAMMER=stk500v2 -P usb
-PROGRAMMER=usbtiny
-LOADCMD=avrdude
 LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w:
-CC=avr-gcc
-OBJCOPY=avr-objcopy
-
-ifndef VERSION
-include ../Version
-endif
 
 INC = \
        ao.h \
index ce2a8fde70f957a168e6d3909c1880ba5c6bd563..7f39d3f1405aa90b5c0c1a4cfa8a80ef58b1f23d 100644 (file)
@@ -5,20 +5,14 @@
 vpath % ..:../core:../product:../drivers:../avr
 vpath ao-make-product.5c ../util
 
+include ../avr/Makefile.defs
+
 MCU=atmega32u4
 DUDECPUTYPE=m32u4
 #PROGRAMMER=stk500v2 -P usb
-PROGRAMMER=usbtiny
-LOADCMD=avrdude
 LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w:
-CC=avr-gcc
-OBJCOPY=avr-objcopy
-
-LDFLAGS=-L/usr/lib/ldscripts -Tavr5.x
 
-ifndef VERSION
-include ../Version
-endif
+LDFLAGS=-L$(LDSCRIPTS) -Tavr5.x
 
 INC = \
        ao.h \
index 81054a7531ffc7d20c3ae7a45603cd7406e419d9..a65b3ad0a2fda384b6ee4ae73f08dc2c4d2a9c53 100644 (file)
@@ -5,20 +5,14 @@
 vpath % ..:../core:../product:../drivers:../avr
 vpath ao-make-product.5c ../util
 
+include ../avr/Makefile.defs
+
 MCU=atmega32u4
 DUDECPUTYPE=m32u4
 #PROGRAMMER=stk500v2 -P usb
-PROGRAMMER=usbtiny
-LOADCMD=avrdude
 LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w:
-CC=avr-gcc
-OBJCOPY=avr-objcopy
-
-LDFLAGS=-L/usr/lib/ldscripts -Tavr5.x
 
-ifndef VERSION
-include ../Version
-endif
+LDFLAGS=-L$(LDSCRIPTS) -Tavr5.x
 
 INC = \
        ao.h \
index ab2a025f4004da4c60b077882f4d8c5a07b83776..e8b262efe25f224fde19d538fab2eeeb09122c75 100644 (file)
@@ -92,10 +92,10 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+$(PROG): $(REL) Makefile
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index 68a8d1b6c6c664d64efebe175abcd95f272db3d5..88637360d35f191be751c532af839a30d52d051e 100644 (file)
@@ -86,10 +86,10 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+$(PROG): $(REL) Makefile
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
 ao_product.h: ao-make-product.5c ../Version
index 1514c4dfe9f639fd43f59ab30f4058b16ec72b3f..b2ba537bfc36336e6fa82f18e489c4882fc95340 100644 (file)
@@ -72,10 +72,10 @@ endif
 # Otherwise, print the full command line.
 quiet ?= $($1)
 
-all: ../$(PROG)
+all: $(PROG)
 
-../$(PROG): $(REL) Makefile
-       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL) && cp $(PROG) $(PMAP) ..
+$(PROG): $(REL) Makefile
+       $(call quiet,CC) $(LDFLAGS) $(CFLAGS) -o $(PROG) $(REL)
        $(call quiet,CHECK_STACK) ../cc1111/ao_arch.h $(PMEM) || rm $@
 
 ao_product.h: ao-make-product.5c ../Version