From fac03ae9762f2af95b1ce5d99894173f9d9146f0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 18 Aug 2014 10:53:04 -0700 Subject: Add ao-tools/ao-cal-accel This C version may be more reliable than the nickle version Signed-off-by: Keith Packard --- ao-tools/Makefile.am | 2 +- ao-tools/ao-cal-accel/.gitignore | 1 + ao-tools/ao-cal-accel/Makefile.am | 11 ++ ao-tools/ao-cal-accel/ao-cal-accel.1 | 58 +++++++ ao-tools/ao-cal-accel/ao-cal-accel.c | 284 +++++++++++++++++++++++++++++++++++ configure.ac | 1 + 6 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 ao-tools/ao-cal-accel/.gitignore create mode 100644 ao-tools/ao-cal-accel/Makefile.am create mode 100644 ao-tools/ao-cal-accel/ao-cal-accel.1 create mode 100644 ao-tools/ao-cal-accel/ao-cal-accel.c diff --git a/ao-tools/Makefile.am b/ao-tools/Makefile.am index 4526f514..2d873e50 100644 --- a/ao-tools/Makefile.am +++ b/ao-tools/Makefile.am @@ -2,7 +2,7 @@ SUBDIRS=lib ao-rawload ao-dbg ao-bitbang ao-eeprom ao-list \ ao-load ao-telem ao-send-telem ao-sky-flash \ ao-dumpflash ao-edit-telem ao-dump-up ao-elftohex \ ao-flash ao-usbload ao-test-igniter ao-test-baro \ - ao-test-flash + ao-test-flash ao-cal-accel if LIBSTLINK SUBDIRS += ao-stmload endif diff --git a/ao-tools/ao-cal-accel/.gitignore b/ao-tools/ao-cal-accel/.gitignore new file mode 100644 index 00000000..73402b2b --- /dev/null +++ b/ao-tools/ao-cal-accel/.gitignore @@ -0,0 +1 @@ +ao-cal-accel diff --git a/ao-tools/ao-cal-accel/Makefile.am b/ao-tools/ao-cal-accel/Makefile.am new file mode 100644 index 00000000..d278097a --- /dev/null +++ b/ao-tools/ao-cal-accel/Makefile.am @@ -0,0 +1,11 @@ +bin_PROGRAMS=ao-cal-accel + +AM_CFLAGS=-I$(top_srcdir)/ao-tools/lib $(LIBUSB_CFLAGS) + +ao_cal_accel_DEPENDENCIES = $(top_builddir)/ao-tools/lib/libao-tools.a + +ao_cal_accel_LDADD=$(top_builddir)/ao-tools/lib/libao-tools.a $(LIBUSB_LIBS) + +ao_cal_accel_SOURCES=ao-cal-accel.c + +man_MANS = ao-cal-accel.1 diff --git a/ao-tools/ao-cal-accel/ao-cal-accel.1 b/ao-tools/ao-cal-accel/ao-cal-accel.1 new file mode 100644 index 00000000..eb75d7c7 --- /dev/null +++ b/ao-tools/ao-cal-accel/ao-cal-accel.1 @@ -0,0 +1,58 @@ +.\" +.\" Copyright © 2009 Keith Packard +.\" +.\" 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; either version 2 of the License, or +.\" (at your option) any later version. +.\" +.\" 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. +.\" +.\" +.TH AO-LOAD 1 "ao-cal-accel" "" +.SH NAME +ao-cal-accel \- Calibrate AltOS flight computer accelerometers +.SH SYNOPSIS +.B "ao-cal-accel" +[\-T \fItty-device\fP] +[\--tty \fItty-device\fP] +[\-D \fIaltos-device\fP] +[\--device \fIaltos-device\fP] +.SH DESCRIPTION +.I ao-cal-accel +drives the built-in accelerometer calibration and validates the results. +.SH OPTIONS +.TP +\-T tty-device | --tty tty-device +This selects which tty device the debugger uses to communicate with +the target device. The special name 'BITBANG' directs ao-dbg to use +the cp2103 connection, otherwise this should be a usb serial port +connected to a suitable cc1111 debug node. +.TP +\-D AltOS-device | --device AltOS-device +Search for a connected device. This requires an argument of one of the +following forms: +.IP +TeleMega:2 +.br +TeleMega +.br +2 +.IP +Leaving out the product name will cause the tool to select a suitable +product, leaving out the serial number will cause the tool to match +one of the available devices. +.SH USAGE +.I ao-cal-accel +opens the target device, executes the accelerometer calibration +command, verifies that it executed correctly, then shows the resulting +calibration values and saves them to configuration memory. +.SH AUTHOR +Keith Packard diff --git a/ao-tools/ao-cal-accel/ao-cal-accel.c b/ao-tools/ao-cal-accel/ao-cal-accel.c new file mode 100644 index 00000000..9a988648 --- /dev/null +++ b/ao-tools/ao-cal-accel/ao-cal-accel.c @@ -0,0 +1,284 @@ +/* + * Copyright © 2014 Keith Packard + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ao-elf.h" +#include "ccdbg.h" +#include "cc-usb.h" +#include "cc.h" +#include "ao-verbose.h" + +static const struct option options[] = { + { .name = "tty", .has_arg = 1, .val = 'T' }, + { .name = "device", .has_arg = 1, .val = 'D' }, + { .name = "raw", .has_arg = 0, .val = 'r' }, + { .name = "verbose", .has_arg = 1, .val = 'v' }, + { 0, 0, 0, 0}, +}; + +static void usage(char *program) +{ + fprintf(stderr, "usage: %s [--verbose=] [--device=] [-tty=]\n", program); + exit(1); +} + +void +done(struct cc_usb *cc, int code) +{ + cc_usb_close(cc); + exit (code); +} + +static int +ends_with(char *whole, char *suffix) +{ + int whole_len = strlen(whole); + int suffix_len = strlen(suffix); + + if (suffix_len > whole_len) + return 0; + return strcmp(whole + whole_len - suffix_len, suffix) == 0; +} + +static int +starts_with(char *whole, char *prefix) +{ + int whole_len = strlen(whole); + int prefix_len = strlen(prefix); + + if (prefix_len > whole_len) + return 0; + return strncmp(whole, prefix, prefix_len) == 0; +} + +static char ** +tok(char *line) { + char **strs = malloc (sizeof (char *)), *str; + int n = 0; + + while ((str = strtok(line, " \t"))) { + line = NULL; + strs = realloc(strs, (n + 2) * sizeof (char *)); + strs[n] = strdup(str); + n++; + } + strs[n] = '\0'; + return strs; +} + +static void +free_strs(char **strs) { + char *str; + int i; + + for (i = 0; (str = strs[i]) != NULL; i++) + free(str); + free(strs); +} + +struct flash { + struct flash *next; + char line[512]; + char **strs; +}; + +static struct flash * +flash(struct cc_usb *usb) +{ + struct flash *head = NULL, **tail = &head; + cc_usb_printf(usb, "c s\nv\n"); + for (;;) { + char line[512]; + struct flash *b; + + cc_usb_getline(usb, line, sizeof (line)); + b = malloc (sizeof (struct flash)); + strcpy(b->line, line); + b->strs = tok(line); + b->next = NULL; + *tail = b; + tail = &b->next; + if (strstr(line, "software-version")) + break; + } + return head; +} + +static void +free_flash(struct flash *b) { + struct flash *n; + + while (b) { + n = b->next; + free_strs(b->strs); + free(b); + b = n; + } +} + +char ** +find_flash(struct flash *b, char *word0) { + int i; + for (;b; b = b->next) { + if (strstr(b->line, word0)) + return b->strs; + } + return NULL; +} + +void +await_key(void) +{ + struct termios termios, termios_save; + char buf[512]; + + tcgetattr(0, &termios); + termios_save = termios; + cfmakeraw(&termios); + tcsetattr(0, TCSAFLUSH, &termios); + read(0, buf, sizeof (buf)); + tcsetattr(0, TCSAFLUSH, &termios_save); +} + +int +do_cal(struct cc_usb *usb) { + struct flash *b; + char **accel; + char line[1024]; + int l; + int running = 0; + int worked = 1; + + cc_usb_printf(usb, "E 1\nc a 0\n"); + + for (;;) { + int c = cc_usb_getchar_timeout(usb, 20*1000); + + if (c == '\n') + l = 0; + else if (l < sizeof (line) - 1) + line[l++] = c; + line[l] = '\0'; + putchar(c); fflush(stdout); + if (strstr(line, "press a key...")) { + await_key(); + cc_usb_printf(usb, " "); + l = 0; + running = 1; + } + else if (strstr(line, "Invalid")) + worked = 0; + if (running && strstr(line, ">")) { + printf("\n"); + break; + } + } + cc_usb_printf(usb, "E 0\n"); + + if (!worked) { + printf("Calibration failed\n"); + return 0; + } + + b = flash(usb); + + accel = find_flash(b, "Accel cal"); + if (!accel) { + printf("no response\n"); + return 0; + } + + printf ("Accel cal +1g: %s -1g: %s\n", + accel[3], accel[5]); + + printf ("Saving..."); fflush(stdout); + cc_usb_printf (usb, "c w\n"); + cc_usb_sync(usb); + b = flash(usb); + printf ("done\n"); + + return worked; +} + +int +main (int argc, char **argv) +{ + char *device = NULL; + char *filename; + Elf *e; + unsigned int s; + int i; + int c; + int tries; + struct cc_usb *cc = NULL; + char *tty = NULL; + int success; + int verbose = 0; + int ret = 0; + int expected_size; + + while ((c = getopt_long(argc, argv, "rT:D:c:s:v:", options, NULL)) != -1) { + switch (c) { + case 'T': + tty = optarg; + break; + case 'D': + device = optarg; + break; + case 'v': + verbose++; + break; + default: + usage(argv[0]); + break; + } + } + + ao_verbose = verbose; + + if (verbose > 1) + ccdbg_add_debug(CC_DEBUG_BITBANG); + + if (!tty) + tty = cc_usbdevs_find_by_arg(device, "AltosFlash"); + if (!tty) + tty = cc_usbdevs_find_by_arg(device, "TeleMega"); + if (!tty) + tty = getenv("ALTOS_TTY"); + if (!tty) + tty="/dev/ttyACM0"; + + cc = cc_usb_open(tty); + + if (!cc) + exit(1); + + if (!do_cal(cc)) + ret = 1; + done(cc, ret); +} diff --git a/configure.ac b/configure.ac index 38bab8e1..683da846 100644 --- a/configure.ac +++ b/configure.ac @@ -537,6 +537,7 @@ ao-tools/ao-flash/Makefile ao-tools/ao-test-igniter/Makefile ao-tools/ao-test-baro/Makefile ao-tools/ao-test-flash/Makefile +ao-tools/ao-cal-accel/Makefile ao-utils/Makefile src/Version ]) -- cgit v1.2.3 From 3c9cb4836edd4811fcdbb6ebbd25eb507a2ef5b1 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 18 Aug 2014 10:57:26 -0700 Subject: ao-bringup: Use ao-cal-accel instead of cal-accel in turnon scripts Signed-off-by: Keith Packard --- ao-bringup/turnon_easymega | 2 +- ao-bringup/turnon_telemega | 2 +- ao-bringup/turnon_telemetrum | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ao-bringup/turnon_easymega b/ao-bringup/turnon_easymega index 7d23f5f7..3fdb942d 100755 --- a/ao-bringup/turnon_easymega +++ b/ao-bringup/turnon_easymega @@ -52,6 +52,6 @@ esac echo 'E 0' > $dev -./cal-accel $dev +../ao-tools/ao-cal-accel/ao-cal-accel $dev echo 'E 1' > $dev diff --git a/ao-bringup/turnon_telemega b/ao-bringup/turnon_telemega index 39a63642..9705798a 100755 --- a/ao-bringup/turnon_telemega +++ b/ao-bringup/turnon_telemega @@ -54,4 +54,4 @@ echo 'E 0' > $dev SERIAL=$SERIAL ./cal-freq $dev -./cal-accel $dev +../ao-tools/ao-cal-accel/ao-cal-accel $dev diff --git a/ao-bringup/turnon_telemetrum b/ao-bringup/turnon_telemetrum index c6e7d1cc..48ff1e27 100755 --- a/ao-bringup/turnon_telemetrum +++ b/ao-bringup/turnon_telemetrum @@ -20,7 +20,7 @@ echo "TeleMetrum v$VERSION Turn-On and Calibration Program" echo "Copyright 2014 by Bdale Garbee. Released under GPL v2" echo echo "Expectations:" -echo "\tTeleMetrum v$VERSIOn powered from USB" +echo "\tTeleMetrum v$VERSION powered from USB" echo "\t\twith ST-Link-V2 cabled to debug header" echo "\t\twith coax from UHF to frequency counter" echo @@ -53,6 +53,6 @@ echo 'E 0' > $dev SERIAL=$SERIAL ./cal-freq $dev -./cal-accel $dev +../ao-tools/ao-cal-accel/ao-cal-accel $dev echo 'E 1' > $dev -- cgit v1.2.3 From 54994d02a5ca5bb91512f31748a48a0140d3a640 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 28 Aug 2014 19:52:30 -0700 Subject: ao-bringup: Test EasyMega boards --- ao-bringup/test-easymega | 68 ++++++++++++++++++++++++++++++++++++++++++++++ ao-bringup/turnon_easymega | 4 +++ 2 files changed, 72 insertions(+) create mode 100755 ao-bringup/test-easymega diff --git a/ao-bringup/test-easymega b/ao-bringup/test-easymega new file mode 100755 index 00000000..eabe1ee5 --- /dev/null +++ b/ao-bringup/test-easymega @@ -0,0 +1,68 @@ +#!/bin/sh + +VERSION=1.0 +PRODUCT=EasyMega +BASE=`echo $PRODUCT | tr 'A-Z' 'a-z'` + +echo "$PRODUCT-v$VERSION Test Program" +echo "Copyright 2014 by Keith Packard. Released under GPL v2" +echo +echo "Expectations:" +echo "\t$PRODUCT v$VERSION powered from USB" +echo + +ret=1 +ao-list | while read product serial dev; do + case "$product" in + "$PRODUCT-v$VERSION") + + echo "Testing $product $serial $dev" + + for igniter in drogue main 0 1 2 3; do + echo "Testing $igniter igniter." + echo -n "Press enter to continue..." + read foo < /dev/tty + ../ao-tools/ao-test-igniter/ao-test-igniter --tty="$dev" $igniter + + case $? in + 0) + ;; + *) + echo "failed" + exit 1 + ;; + esac + done + + echo "Testing baro sensor" + ../ao-tools/ao-test-baro/ao-test-baro --tty="$dev" + + case $? in + 0) + ;; + *) + echo "failed" + exit 1 + esac + + FLASHSIZE=8388608 + + echo "Testing flash" + ../ao-tools/ao-test-flash/ao-test-flash --tty="$dev" "$FLASHSIZE" + + case $? in + 0) + ;; + *) + echo "failed" + exit 1 + esac + + echo "$PRODUCT-v$VERSION" serial "$serial" is ready to ship + ret=0 + ;; + *) + echo "Skipping $product $serial $dev" + ;; + esac +done diff --git a/ao-bringup/turnon_easymega b/ao-bringup/turnon_easymega index 3fdb942d..b313e162 100755 --- a/ao-bringup/turnon_easymega +++ b/ao-bringup/turnon_easymega @@ -55,3 +55,7 @@ echo 'E 0' > $dev ../ao-tools/ao-cal-accel/ao-cal-accel $dev echo 'E 1' > $dev + +./test-easymega + +exit $? -- cgit v1.2.3 From 5872bd10df14b47de0e541bff16d9220af0558aa Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 29 Aug 2014 15:12:38 -0500 Subject: altos: Make sure pyro remains valid during delay Keep checking pyro status while waiting for delay to expire to make sure nothing changes. Disable pyro channel if something does. Signed-off-by: Keith Packard --- src/kernel/ao_pyro.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/kernel/ao_pyro.c b/src/kernel/ao_pyro.c index 0b286466..154edad5 100644 --- a/src/kernel/ao_pyro.c +++ b/src/kernel/ao_pyro.c @@ -252,7 +252,7 @@ ao_pyro_check(void) struct ao_pyro *pyro; uint8_t p, any_waiting; uint16_t fire = 0; - + any_waiting = 0; for (p = 0; p < AO_PYRO_NUM; p++) { pyro = &ao_config.pyro[p]; @@ -288,6 +288,16 @@ ao_pyro_check(void) * the delay to expire */ if (pyro->delay_done) { + + /* Check to make sure the required conditions + * remain valid. If not, inhibit the channel + * by setting the fired bit + */ + if (!ao_pyro_ready(pyro)) { + pyro->fired = 1; + continue; + } + if ((int16_t) (ao_time() - pyro->delay_done) < 0) continue; } @@ -465,7 +475,7 @@ ao_pyro_set(void) printf ("invalid pyro channel %d\n", p); return; } - pyro_tmp.flags = 0; + memset(&pyro_tmp, '\0', sizeof (pyro_tmp)); for (;;) { ao_cmd_white(); if (ao_cmd_lex_c == '\n') -- cgit v1.2.3 From 810f9a4f79b0480973d84595140d3f8948ce26d9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 29 Aug 2014 15:22:43 -0500 Subject: altosdroid: start restoring from log data on startup Remember which flight was last being received and reload that file Signed-off-by: Keith Packard --- .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 16 ++-- .../AltosDroid/AltosDroidPreferences.java | 89 +++++----------------- altoslib/AltosFlightReader.java | 8 +- altoslib/AltosLog.java | 1 + altoslib/AltosPreferences.java | 27 +++++++ altoslib/AltosReplayReader.java | 11 ++- altoslib/AltosStateIterable.java | 14 ++++ altoslib/AltosTelemetryReader.java | 31 +++++++- 8 files changed, 111 insertions(+), 86 deletions(-) diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index c9c38d98..c94f36fd 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -101,9 +101,6 @@ public class AltosDroid extends FragmentActivity { private Messenger mService = null; final Messenger mMessenger = new Messenger(new IncomingHandler(this)); - // Preferences - private AltosDroidPreferences prefs = null; - // TeleBT Config data private AltosConfigData mConfigData = null; // Local Bluetooth adapter @@ -343,8 +340,7 @@ public class AltosDroid extends FragmentActivity { } // Initialise preferences - prefs = new AltosDroidPreferences(this); - AltosPreferences.init(prefs); + AltosDroidPreferences.init(this); // Set up the window layout requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); @@ -480,9 +476,7 @@ public class AltosDroid extends FragmentActivity { } } - private void connectDevice(Intent data) { - // Get the device MAC address - String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); + private void connectDevice(String address) { // Get the BLuetoothDevice object BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); // Attempt to connect to the device @@ -493,6 +487,12 @@ public class AltosDroid extends FragmentActivity { } } + private void connectDevice(Intent data) { + // Get the device MAC address + String address = data.getExtras().getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); + connectDevice(address); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java index 70d7def8..7c12c9a0 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java @@ -1,5 +1,5 @@ /* - * Copyright © 2012 Mike Beattie + * Copyright © 2014 Keith Packard * * 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 @@ -14,88 +14,35 @@ * 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.io.File; -import java.util.Map; import android.content.Context; -import android.content.SharedPreferences; -import android.os.Environment; - import org.altusmetrum.altoslib_5.*; -public class AltosDroidPreferences implements AltosPreferencesBackend { - public final static String NAME = "org.altusmetrum.AltosDroid"; - private Context context = null; - private SharedPreferences prefs = null; - private SharedPreferences.Editor editor = null; +public class AltosDroidPreferences extends AltosPreferences { - public AltosDroidPreferences(Context in_context) { - this(in_context, NAME); - } + /* Active device preference name */ + final static String activeDevicePreference = "ACTIVE-DEVICE"; - public AltosDroidPreferences(Context in_context, String in_prefs) { - context = in_context; - prefs = context.getSharedPreferences(in_prefs, 0); - editor = prefs.edit(); - } + static String active_device_address; - public String[] keys() { - Map all = prefs.getAll(); - return (String[])all.keySet().toArray(); - } - - public AltosPreferencesBackend node(String key) { - return new AltosDroidPreferences(context, key); - } - - public boolean nodeExists(String key) { - return prefs.contains(key); - } - - public boolean getBoolean(String key, boolean def) { - return prefs.getBoolean(key, def); - } - - public double getDouble(String key, double def) { - Float f = Float.valueOf(prefs.getFloat(key, (float)def)); - return f.doubleValue(); - } - - public int getInt(String key, int def) { - return prefs.getInt(key, def); - } - - public String getString(String key, String def) { - return prefs.getString(key, def); - } - - public void putBoolean(String key, boolean value) { - editor.putBoolean(key, value); - } - - public void putDouble(String key, double value) { - editor.putFloat(key, (float)value); - } - - public void putInt(String key, int value) { - editor.putInt(key, value); - } - - public void putString(String key, String value) { - editor.putString(key, value); - } + public static void init(Context context) { + AltosPreferences.init(new AltosDroidPreferencesBackend(context)); - public void remove(String key) { - editor.remove(key); + active_device_address = backend.getGetString(activeDevicePreference, null); } - public void flush() { - editor.apply(); + public static void set_active_device(String address) { + synchronized(backend) { + active_device_address = address; + backend.putString(activeDevicePreference, active_device_address); + flush_preferences(); + } } - public File homeDirectory() { - return Environment.getExternalStorageDirectory(); + public static String active_device() { + synchronized(backend) { + return active_device_address; + } } } diff --git a/altoslib/AltosFlightReader.java b/altoslib/AltosFlightReader.java index c0565e88..be103838 100644 --- a/altoslib/AltosFlightReader.java +++ b/altoslib/AltosFlightReader.java @@ -21,16 +21,16 @@ import java.text.*; import java.io.*; import java.util.concurrent.*; -public class AltosFlightReader { +public abstract class AltosFlightReader { public String name; public int serial; - public void init() { } + public void init() {} - public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; } + public abstract AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException; - public void close(boolean interrupted) { } + public abstract void close(boolean interrupted); public void set_frequency(double frequency) throws InterruptedException, TimeoutException { } diff --git a/altoslib/AltosLog.java b/altoslib/AltosLog.java index 1cac6b52..28116e3d 100644 --- a/altoslib/AltosLog.java +++ b/altoslib/AltosLog.java @@ -72,6 +72,7 @@ public class AltosLog implements Runnable { } log_file.flush(); file = a; + AltosPreferences.set_logfile(link.serial, file); } return log_file != null; } diff --git a/altoslib/AltosPreferences.java b/altoslib/AltosPreferences.java index 72cfeb4b..0e91e4f4 100644 --- a/altoslib/AltosPreferences.java +++ b/altoslib/AltosPreferences.java @@ -38,6 +38,9 @@ public class AltosPreferences { /* telemetry rate format preference name */ public final static String telemetryRatePreferenceFormat = "RATE-%d"; + /* log file format preference name */ + public final static String logfilePreferenceFormat = "LOGFILE-%d"; + /* voice preference name */ public final static String voicePreference = "VOICE"; @@ -83,6 +86,9 @@ public class AltosPreferences { /* Telemetry rate (map serial to telemetry format) */ public static Hashtable telemetry_rates; + /* Log file (map serial to logfile name) */ + public static Hashtable logfiles; + /* Voice preference */ public static boolean voice; @@ -300,6 +306,27 @@ public class AltosPreferences { } } + public static void set_logfile(int serial, File new_logfile) { + synchronized(backend) { + logfiles.put(serial, new_logfile); + backend.putString(String.format(logfilePreferenceFormat, serial), new_logfile.getPath()); + flush_preferences(); + } + } + + public static File logfile(int serial) { + synchronized(backend) { + if (logfiles.containsKey(serial)) + return logfiles.get(serial); + String logfile_string = backend.getString(String.format(logfilePreferenceFormat, serial), null); + if (logfile_string == null) + return null; + File logfile = new File(logfile_string); + logfiles.put(serial, logfile); + return logfile; + } + } + public static void set_scanning_telemetry(int new_scanning_telemetry) { synchronized (backend) { scanning_telemetry = new_scanning_telemetry; diff --git a/altoslib/AltosReplayReader.java b/altoslib/AltosReplayReader.java index 15093af1..2864e02a 100644 --- a/altoslib/AltosReplayReader.java +++ b/altoslib/AltosReplayReader.java @@ -27,6 +27,7 @@ import java.util.*; public class AltosReplayReader extends AltosFlightReader { Iterator iterator; File file; + boolean real_time; public AltosState read() { if (iterator.hasNext()) @@ -39,16 +40,22 @@ public class AltosReplayReader extends AltosFlightReader { public void update(AltosState state) throws InterruptedException { /* Make it run in realtime after the rocket leaves the pad */ - if (state.state > AltosLib.ao_flight_pad && state.time_change > 0) + if (real_time && state.state > AltosLib.ao_flight_pad && state.time_change > 0) 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 in_iterator, File in_file) { + public AltosReplayReader(Iterator in_iterator, File in_file, + boolean in_real_time) { iterator = in_iterator; file = in_file; + real_time = in_real_time; name = file.getName(); } + + public AltosReplayReader(Iterator in_iterator, File in_file) { + this(in_iterator, in_file, false); + } } diff --git a/altoslib/AltosStateIterable.java b/altoslib/AltosStateIterable.java index f7cd424d..4154b71c 100644 --- a/altoslib/AltosStateIterable.java +++ b/altoslib/AltosStateIterable.java @@ -26,4 +26,18 @@ public abstract class AltosStateIterable implements Iterable { } public abstract void write(PrintStream out); + + public static AltosStateIterable iterable(File file) { + FileInputStream in; + try { + in = new FileInputStream(file); + } catch (Exception e) { + System.out.printf("Failed to open file '%s'\n", file); + return null; + } + if (file.getName().endsWith("telem")) + return new AltosTelemetryFile(in); + else + return new AltosEepromFile(in); + } } diff --git a/altoslib/AltosTelemetryReader.java b/altoslib/AltosTelemetryReader.java index 5ed50134..8803e19f 100644 --- a/altoslib/AltosTelemetryReader.java +++ b/altoslib/AltosTelemetryReader.java @@ -28,10 +28,17 @@ public class AltosTelemetryReader extends AltosFlightReader { int telemetry; int telemetry_rate; AltosState state = null; + AltosFlightReader stacked; LinkedBlockingQueue telem; public AltosState read() throws InterruptedException, ParseException, AltosCRCException, IOException { + if (stacked != null) { + state = stacked.read(); + if (state != null) + return state; + stacked = null; + } AltosLine l = telem.take(); if (l.line == null) throw new IOException("IO error"); @@ -53,6 +60,12 @@ public class AltosTelemetryReader extends AltosFlightReader { } public void close(boolean interrupted) { + + if (stacked != null) { + stacked.close(interrupted); + stacked = null; + } + link.remove_monitor(telem); log.close(); try { @@ -148,9 +161,10 @@ public class AltosTelemetryReader extends AltosFlightReader { return link.monitor_battery(); } - public AltosTelemetryReader (AltosLink in_link) + public AltosTelemetryReader (AltosLink in_link, AltosFlightReader in_stacked) throws IOException, InterruptedException, TimeoutException { link = in_link; + stacked = in_stacked; boolean success = false; try { log = new AltosLog(link); @@ -169,4 +183,19 @@ public class AltosTelemetryReader extends AltosFlightReader { close(true); } } + + private static AltosFlightReader existing_data(AltosLink link) { + File file = AltosPreferences.logfile(link.serial); + if (file != null) { + AltosStateIterable iterable = AltosStateIterable.iterable(file); + if (iterable != null) + return new AltosReplayReader(iterable.iterator(), file, false); + } + return null; + } + + public AltosTelemetryReader(AltosLink link) + throws IOException, InterruptedException, TimeoutException { + this(link, existing_data(link)); + } } -- cgit v1.2.3 From 0014addf3356bad1eff76cffc396fb120308646c Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 29 Aug 2014 22:08:43 -0500 Subject: altoslib: TeleMega telemetry pyro voltages are uint8 Using int8 means that voltages over about 6V are reported incorrectly. Signed-off-by: Keith Packard --- altoslib/AltosTelemetryMegaData.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/altoslib/AltosTelemetryMegaData.java b/altoslib/AltosTelemetryMegaData.java index 8b1869bb..d949c02f 100644 --- a/altoslib/AltosTelemetryMegaData.java +++ b/altoslib/AltosTelemetryMegaData.java @@ -36,7 +36,7 @@ public class AltosTelemetryMegaData extends AltosTelemetryStandard { public AltosTelemetryMegaData(int[] bytes) { super(bytes); - state = int8(5); + state = uint8(5); v_batt = int16(6); v_pyro = int16(8); @@ -44,7 +44,7 @@ public class AltosTelemetryMegaData extends AltosTelemetryStandard { sense = new int[6]; for (int i = 0; i < 6; i++) { - sense[i] = int8(10 + i) << 4; + sense[i] = uint8(10 + i) << 4; sense[i] |= sense[i] >> 8; } -- cgit v1.2.3 From 0b70ea04e807c69a987d5976ab217f9f65fb1e09 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 29 Aug 2014 22:33:36 -0500 Subject: altosdroid: fixup fetching active device address Signed-off-by: Keith Packard --- altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java index 7c12c9a0..72b8488b 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroidPreferences.java @@ -29,7 +29,7 @@ public class AltosDroidPreferences extends AltosPreferences { public static void init(Context context) { AltosPreferences.init(new AltosDroidPreferencesBackend(context)); - active_device_address = backend.getGetString(activeDevicePreference, null); + active_device_address = backend.getString(activeDevicePreference, null); } public static void set_active_device(String address) { -- cgit v1.2.3 From bc3fbcb35090be3856284ccf4d908ebf39d02bec Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 31 Aug 2014 00:08:33 -0500 Subject: altosdroid: Add quit. Restart. Show freq in title. Add a quit button to menu. When restarting, reconnect to previous device. When connecting, set the freq/rate to previous values. Signed-off-by: Keith Packard --- altosdroid/res/layout/device_list.xml | 30 ++++---- altosdroid/res/menu/option_menu.xml | 3 + altosdroid/res/values/strings.xml | 1 + .../org/altusmetrum/AltosDroid/AltosBluetooth.java | 17 +++++ .../src/org/altusmetrum/AltosDroid/AltosDroid.java | 79 +++++++++++++++++++--- .../org/altusmetrum/AltosDroid/GoNoGoLights.java | 14 ++++ .../src/org/altusmetrum/AltosDroid/TabLanded.java | 5 +- .../src/org/altusmetrum/AltosDroid/TabPad.java | 26 +++++-- .../altusmetrum/AltosDroid/TelemetryReader.java | 11 ++- .../altusmetrum/AltosDroid/TelemetryService.java | 36 ++++++++-- 10 files changed, 188 insertions(+), 34 deletions(-) diff --git a/altosdroid/res/layout/device_list.xml b/altosdroid/res/layout/device_list.xml index 395695f8..93d65517 100644 --- a/altosdroid/res/layout/device_list.xml +++ b/altosdroid/res/layout/device_list.xml @@ -18,39 +18,39 @@ android:layout_width="match_parent" android:layout_height="match_parent" > - + - - - -